27 changed files with 883 additions and 487 deletions
-
6eeschema/CMakeLists.txt
-
20eeschema/cross-probing.cpp
-
14eeschema/eeschema_id.h
-
78eeschema/events_called_functions_for_edit.cpp
-
20eeschema/hierarch.cpp
-
154eeschema/highlight_connection.cpp
-
27eeschema/hotkeys.cpp
-
4eeschema/onleftclick.cpp
-
6eeschema/sch_edit_frame.cpp
-
30eeschema/sch_edit_frame.h
-
64eeschema/schedit.cpp
-
2eeschema/tool_sch.cpp
-
19eeschema/tools/sch_actions.cpp
-
18eeschema/tools/sch_actions.h
-
266eeschema/tools/sch_editor_control.cpp
-
95eeschema/tools/sch_editor_control.h
-
157eeschema/tools/sch_picker_tool.cpp
-
121eeschema/tools/sch_picker_tool.h
-
99eeschema/tools/selection.cpp
-
33eeschema/tools/tools_common.cpp
-
1pcbnew/CMakeLists.txt
-
41pcbnew/tools/pcb_actions.cpp
-
1pcbnew/tools/pcb_editor_control.cpp
-
1pcbnew/tools/pcbnew_control.cpp
-
3pcbnew/tools/picker_tool.cpp
-
21pcbnew/tools/picker_tool.h
-
69pcbnew/tools/tools_common.cpp
@ -1,78 +0,0 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2010 Jean-Pierre Charras, jp.charras at wanadoo.fr |
|||
* Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
/*
|
|||
* @file events_called_functions.cpp |
|||
*/ |
|||
|
|||
#include <fctsys.h>
|
|||
#include <gr_basic.h>
|
|||
#include <sch_draw_panel.h>
|
|||
#include <general.h>
|
|||
#include <kicad_device_context.h>
|
|||
#include <sch_edit_frame.h>
|
|||
#include <sch_component.h>
|
|||
#include <sch_text.h>
|
|||
#include <view/view_controls.h>
|
|||
|
|||
|
|||
void SCH_EDIT_FRAME::OnCopySchematicItemRequest( wxCommandEvent& event ) |
|||
{ |
|||
SCH_ITEM * curr_item = GetScreen()->GetCurItem(); |
|||
|
|||
if( !curr_item || curr_item->GetFlags() ) |
|||
return; |
|||
|
|||
GetCanvas()->GetViewControls()->SetCursorPosition( GetCrossHairPosition() ); |
|||
|
|||
switch( curr_item->Type() ) |
|||
{ |
|||
case SCH_COMPONENT_T: |
|||
{ |
|||
SCH_COMPONENT* newitem; |
|||
newitem = new SCH_COMPONENT( *( (SCH_COMPONENT*) curr_item ) ); |
|||
newitem->SetTimeStamp( GetNewTimeStamp() ); |
|||
newitem->ClearAnnotation( NULL ); |
|||
newitem->SetFlags( IS_NEW ); |
|||
// Draw the new part, MoveItem() expects it to be already on screen.
|
|||
PrepareMoveItem( newitem ); |
|||
} |
|||
break; |
|||
|
|||
case SCH_TEXT_T: |
|||
case SCH_LABEL_T: |
|||
case SCH_GLOBAL_LABEL_T: |
|||
case SCH_HIERARCHICAL_LABEL_T: |
|||
{ |
|||
SCH_TEXT* newitem = (SCH_TEXT*) curr_item->Clone(); |
|||
newitem->SetFlags( IS_NEW ); |
|||
// Draw the new item, MoveItem() expects it to be already on screen.
|
|||
PrepareMoveItem( newitem ); |
|||
} |
|||
break; |
|||
|
|||
default: |
|||
break; |
|||
} |
|||
} |
|||
@ -1,154 +0,0 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
/**
|
|||
* @file highlight_connection.cpp |
|||
* @brief This file contains basic functions related to the command to |
|||
* highlight a connection (wires and labels) in a schematic |
|||
* (that can be a simple or a complex hierarchy) |
|||
*/ |
|||
|
|||
#include <fctsys.h>
|
|||
#include <sch_view.h>
|
|||
#include <sch_draw_panel.h>
|
|||
#include <sch_edit_frame.h>
|
|||
#include <sch_component.h>
|
|||
#include <erc.h>
|
|||
|
|||
#include <netlist_object.h>
|
|||
#include <sch_component.h>
|
|||
#include <sch_sheet.h>
|
|||
|
|||
// List of items having the highlight option modified, therefore need to be redrawn
|
|||
|
|||
// TODO(JE) Probably use netcode rather than connection name here eventually
|
|||
bool SCH_EDIT_FRAME::HighlightConnectionAtPosition( wxPoint aPosition ) |
|||
{ |
|||
std::vector<EDA_ITEM*> itemsToRedraw; |
|||
m_SelectedNetName = ""; |
|||
bool buildNetlistOk = false; |
|||
|
|||
SetStatusText( "" ); |
|||
|
|||
// find which connected item is selected
|
|||
EDA_ITEMS nodeList; |
|||
wxPoint gridPosition = GetGridPosition( aPosition ); |
|||
|
|||
if( GetScreen()->GetNode( gridPosition, nodeList ) ) |
|||
{ |
|||
if( TestDuplicateSheetNames( false ) > 0 ) |
|||
wxMessageBox( _( "Error: duplicate sub-sheet names found in current sheet. Fix it" ) ); |
|||
else |
|||
{ |
|||
if( auto item = dynamic_cast<SCH_ITEM*>( nodeList[0] ) ) |
|||
{ |
|||
if( item->Connection( *g_CurrentSheet ) ) |
|||
{ |
|||
m_SelectedNetName = item->Connection( *g_CurrentSheet )->Name(); |
|||
SetStatusText( _( "Highlighted net: " ) + m_SelectedNetName ); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
SendCrossProbeNetName( m_SelectedNetName ); |
|||
SetStatusText( _( "Selected net: " ) + UnescapeString( m_SelectedNetName ) ); |
|||
SetCurrentSheetHighlightFlags( &itemsToRedraw ); |
|||
|
|||
// Be sure hightlight change will be redrawn
|
|||
KIGFX::VIEW* view = GetGalCanvas()->GetView(); |
|||
|
|||
for( auto item : itemsToRedraw ) |
|||
view->Update( (KIGFX::VIEW_ITEM*)item, KIGFX::VIEW_UPDATE_FLAGS::REPAINT ); |
|||
|
|||
//view->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
|
|||
GetGalCanvas()->Refresh(); |
|||
return buildNetlistOk; |
|||
} |
|||
|
|||
|
|||
bool SCH_EDIT_FRAME::SetCurrentSheetHighlightFlags( std::vector<EDA_ITEM*>* aItemsToRedrawList ) |
|||
{ |
|||
SCH_SCREEN* screen = g_CurrentSheet->LastScreen(); |
|||
|
|||
if( !screen ) |
|||
return true; |
|||
|
|||
for( SCH_ITEM* ptr = screen->GetDrawItems(); ptr; ptr = ptr->Next() ) |
|||
{ |
|||
auto conn = ptr->Connection( *g_CurrentSheet ); |
|||
bool redraw = ptr->GetState( BRIGHTENED ); |
|||
|
|||
ptr->SetState( BRIGHTENED, ( conn && conn->Name() == m_SelectedNetName ) ); |
|||
|
|||
redraw |= ptr->GetState( BRIGHTENED ); |
|||
|
|||
if( ptr->Type() == SCH_COMPONENT_T ) |
|||
{ |
|||
SCH_COMPONENT* comp = static_cast<SCH_COMPONENT*>( ptr ); |
|||
|
|||
redraw |= comp->HasBrightenedPins(); |
|||
|
|||
comp->ClearBrightenedPins(); |
|||
std::vector<LIB_PIN*> pins; |
|||
comp->GetPins( pins ); |
|||
|
|||
for( LIB_PIN* pin : pins ) |
|||
{ |
|||
auto pin_conn = comp->GetConnectionForPin( pin, *g_CurrentSheet ); |
|||
|
|||
if( pin_conn && pin_conn->Name( false ) == m_SelectedNetName ) |
|||
{ |
|||
comp->BrightenPin( pin ); |
|||
redraw = true; |
|||
} |
|||
} |
|||
} |
|||
else if( ptr->Type() == SCH_SHEET_T ) |
|||
{ |
|||
for( SCH_SHEET_PIN& pin : static_cast<SCH_SHEET*>( ptr )->GetPins() ) |
|||
{ |
|||
auto pin_conn = pin.Connection( *g_CurrentSheet ); |
|||
bool redrawPin = pin.GetState( BRIGHTENED ); |
|||
|
|||
pin.SetState( BRIGHTENED, ( pin_conn && pin_conn->Name() == m_SelectedNetName ) ); |
|||
|
|||
redrawPin |= pin.GetState( BRIGHTENED ); |
|||
|
|||
if( redrawPin && aItemsToRedrawList ) |
|||
aItemsToRedrawList->push_back( &pin ); |
|||
} |
|||
} |
|||
|
|||
if( redraw && aItemsToRedrawList ) |
|||
aItemsToRedrawList->push_back( ptr ); |
|||
} |
|||
|
|||
if( m_SelectedNetName == "" ) |
|||
return true; |
|||
|
|||
if( TestDuplicateSheetNames( false ) > 0 ) |
|||
return false; |
|||
|
|||
return true; |
|||
} |
|||
@ -0,0 +1,266 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#include <fctsys.h>
|
|||
#include <sch_view.h>
|
|||
#include <sch_draw_panel.h>
|
|||
#include <sch_edit_frame.h>
|
|||
#include <sch_component.h>
|
|||
#include <sch_sheet.h>
|
|||
#include <erc.h>
|
|||
#include <eeschema_id.h>
|
|||
#include <netlist_object.h>
|
|||
#include <tool/tool_manager.h>
|
|||
#include <tools/sch_actions.h>
|
|||
#include <tools/sch_picker_tool.h>
|
|||
|
|||
#include <tools/sch_editor_control.h>
|
|||
|
|||
|
|||
TOOL_ACTION SCH_ACTIONS::highlightNet( "eeschema.EditorControl.highlightNet", |
|||
AS_GLOBAL, 0, "", "" ); |
|||
|
|||
TOOL_ACTION SCH_ACTIONS::highlightNetSelection( "eeschema.EditorControl.highlightNetSelection", |
|||
AS_GLOBAL, 0, "", "" ); |
|||
|
|||
TOOL_ACTION SCH_ACTIONS::highlightNetCursor( "eeschema.EditorControl.highlightNetCursor", |
|||
AS_GLOBAL, 0, "", "" ); |
|||
|
|||
|
|||
SCH_EDITOR_CONTROL::SCH_EDITOR_CONTROL() : |
|||
TOOL_INTERACTIVE( "eeschema.EditorControl" ), |
|||
m_frame( nullptr ), |
|||
m_menu( *this ) |
|||
{ |
|||
} |
|||
|
|||
|
|||
SCH_EDITOR_CONTROL::~SCH_EDITOR_CONTROL() |
|||
{ |
|||
} |
|||
|
|||
|
|||
void SCH_EDITOR_CONTROL::Reset( RESET_REASON aReason ) |
|||
{ |
|||
m_frame = getEditFrame<SCH_EDIT_FRAME>(); |
|||
} |
|||
|
|||
|
|||
bool SCH_EDITOR_CONTROL::Init() |
|||
{ |
|||
auto activeToolCondition = [ this ] ( const SELECTION& aSel ) { |
|||
return ( m_frame->GetToolId() != ID_NO_TOOL_SELECTED ); |
|||
}; |
|||
|
|||
auto inactiveStateCondition = [ this ] ( const SELECTION& aSel ) { |
|||
return ( m_frame->GetToolId() == ID_NO_TOOL_SELECTED && aSel.Size() == 0 ); |
|||
}; |
|||
|
|||
auto& ctxMenu = m_menu.GetMenu(); |
|||
|
|||
// "Cancel" goes at the top of the context menu when a tool is active
|
|||
ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1000 ); |
|||
ctxMenu.AddSeparator( activeToolCondition, 1000 ); |
|||
|
|||
// Finally, add the standard zoom & grid items
|
|||
m_menu.AddStandardSubMenus( *getEditFrame<SCH_BASE_FRAME>() ); |
|||
|
|||
/*
|
|||
auto lockMenu = std::make_shared<LOCK_CONTEXT_MENU>(); |
|||
lockMenu->SetTool( this ); |
|||
|
|||
// Add the SCH control menus to relevant other tools
|
|||
SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>(); |
|||
|
|||
if( selTool ) |
|||
{ |
|||
auto& toolMenu = selTool->GetToolMenu(); |
|||
auto& menu = toolMenu.GetMenu(); |
|||
|
|||
menu.AddSeparator( inactiveStateCondition ); |
|||
toolMenu.AddSubMenu( lockMenu ); |
|||
|
|||
menu.AddMenu( lockMenu.get(), false, |
|||
SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::LockableItems ), 200 ); |
|||
} |
|||
*/ |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
// TODO(JE) Probably use netcode rather than connection name here eventually
|
|||
static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition ) |
|||
{ |
|||
SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( aToolMgr->GetEditFrame() ); |
|||
wxString netName; |
|||
EDA_ITEMS nodeList; |
|||
bool retVal = true; |
|||
|
|||
if( editFrame->GetScreen()->GetNode( wxPoint( aPosition.x, aPosition.y ), nodeList ) ) |
|||
{ |
|||
if( TestDuplicateSheetNames( false ) > 0 ) |
|||
{ |
|||
wxMessageBox( _( "Error: duplicate sub-sheet names found in current sheet." ) ); |
|||
retVal = false; |
|||
} |
|||
else |
|||
{ |
|||
if( auto item = dynamic_cast<SCH_ITEM*>( nodeList[0] ) ) |
|||
{ |
|||
if( item->Connection( *g_CurrentSheet ) ) |
|||
{ |
|||
netName = item->Connection( *g_CurrentSheet )->Name(); |
|||
editFrame->SetStatusText( _( "Highlighted net: " ) + UnescapeString( netName ) ); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
editFrame->SetSelectedNetName( netName ); |
|||
editFrame->SendCrossProbeNetName( netName ); |
|||
editFrame->SetStatusText( _( "Selected net: " ) + UnescapeString( netName ) ); |
|||
|
|||
aToolMgr->RunAction( SCH_ACTIONS::highlightNetSelection, true ); |
|||
|
|||
return retVal; |
|||
} |
|||
|
|||
|
|||
int SCH_EDITOR_CONTROL::HighlightNet( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
KIGFX::VIEW_CONTROLS* controls = getViewControls(); |
|||
VECTOR2I gridPosition = controls->GetCursorPosition( true ); |
|||
|
|||
highlightNet( m_toolMgr, gridPosition ); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int SCH_EDITOR_CONTROL::HighlightNetSelection( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
SCH_SCREEN* screen = g_CurrentSheet->LastScreen(); |
|||
std::vector<EDA_ITEM*> itemsToRedraw; |
|||
wxString selectedNetName = m_frame->GetSelectedNetName(); |
|||
|
|||
if( !screen ) |
|||
return 0; |
|||
|
|||
for( SCH_ITEM* ptr = screen->GetDrawItems(); ptr; ptr = ptr->Next() ) |
|||
{ |
|||
auto conn = ptr->Connection( *g_CurrentSheet ); |
|||
bool redraw = ptr->GetState( BRIGHTENED ); |
|||
|
|||
ptr->SetState( BRIGHTENED, ( conn && conn->Name() == selectedNetName ) ); |
|||
|
|||
redraw |= ptr->GetState( BRIGHTENED ); |
|||
|
|||
if( ptr->Type() == SCH_COMPONENT_T ) |
|||
{ |
|||
SCH_COMPONENT* comp = static_cast<SCH_COMPONENT*>( ptr ); |
|||
|
|||
redraw |= comp->HasBrightenedPins(); |
|||
|
|||
comp->ClearBrightenedPins(); |
|||
std::vector<LIB_PIN*> pins; |
|||
comp->GetPins( pins ); |
|||
|
|||
for( LIB_PIN* pin : pins ) |
|||
{ |
|||
auto pin_conn = comp->GetConnectionForPin( pin, *g_CurrentSheet ); |
|||
|
|||
if( pin_conn && pin_conn->Name( false ) == selectedNetName ) |
|||
{ |
|||
comp->BrightenPin( pin ); |
|||
redraw = true; |
|||
} |
|||
} |
|||
} |
|||
else if( ptr->Type() == SCH_SHEET_T ) |
|||
{ |
|||
for( SCH_SHEET_PIN& pin : static_cast<SCH_SHEET*>( ptr )->GetPins() ) |
|||
{ |
|||
auto pin_conn = pin.Connection( *g_CurrentSheet ); |
|||
bool redrawPin = pin.GetState( BRIGHTENED ); |
|||
|
|||
pin.SetState( BRIGHTENED, ( pin_conn && pin_conn->Name() == selectedNetName ) ); |
|||
|
|||
redrawPin |= pin.GetState( BRIGHTENED ); |
|||
|
|||
if( redrawPin ) |
|||
itemsToRedraw.push_back( &pin ); |
|||
} |
|||
} |
|||
|
|||
if( redraw ) |
|||
itemsToRedraw.push_back( ptr ); |
|||
} |
|||
|
|||
// Be sure hightlight change will be redrawn
|
|||
KIGFX::VIEW* view = getView(); |
|||
|
|||
for( auto item : itemsToRedraw ) |
|||
view->Update( (KIGFX::VIEW_ITEM*)item, KIGFX::VIEW_UPDATE_FLAGS::REPAINT ); |
|||
|
|||
m_frame->GetGalCanvas()->Refresh(); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
int SCH_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
Activate(); |
|||
|
|||
SCH_PICKER_TOOL* picker = m_toolMgr->GetTool<SCH_PICKER_TOOL>(); |
|||
assert( picker ); |
|||
|
|||
m_frame->SetToolID( ID_HIGHLIGHT_BUTT, wxCURSOR_HAND, _( "Highlight net" ) ); |
|||
picker->SetClickHandler( std::bind( highlightNet, m_toolMgr, std::placeholders::_1 ) ); |
|||
picker->Activate(); |
|||
Wait(); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
void SCH_EDITOR_CONTROL::setTransitions() |
|||
{ |
|||
/*
|
|||
Go( &SCH_EDITOR_CONTROL::ToggleLockSelected, SCH_ACTIONS::toggleLock.MakeEvent() ); |
|||
Go( &SCH_EDITOR_CONTROL::LockSelected, SCH_ACTIONS::lock.MakeEvent() ); |
|||
Go( &SCH_EDITOR_CONTROL::UnlockSelected, SCH_ACTIONS::unlock.MakeEvent() ); |
|||
*/ |
|||
|
|||
/*
|
|||
Go( &SCH_EDITOR_CONTROL::CrossProbeSchToPcb, SELECTION_TOOL::SelectedEvent ); |
|||
Go( &SCH_EDITOR_CONTROL::CrossProbeSchToPcb, SELECTION_TOOL::UnselectedEvent ); |
|||
Go( &SCH_EDITOR_CONTROL::CrossProbeSchToPcb, SELECTION_TOOL::ClearedEvent ); |
|||
Go( &SCH_EDITOR_CONTROL::CrossProbePcbToSch, SCH_ACTIONS::crossProbeSchToPcb.MakeEvent() ); |
|||
*/ |
|||
|
|||
Go( &SCH_EDITOR_CONTROL::HighlightNet, SCH_ACTIONS::highlightNet.MakeEvent() ); |
|||
Go( &SCH_EDITOR_CONTROL::HighlightNetCursor, SCH_ACTIONS::highlightNetCursor.MakeEvent() ); |
|||
Go( &SCH_EDITOR_CONTROL::HighlightNetSelection, SCH_ACTIONS::highlightNetSelection.MakeEvent() ); |
|||
} |
|||
@ -0,0 +1,95 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|||
* or you may search the http://www.gnu.org website for the version 2 license, |
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
|
|||
#ifndef SCH_EDITOR_CONTROL_H |
|||
#define SCH_EDITOR_CONTROL_H |
|||
|
|||
#include <tool/tool_interactive.h> |
|||
#include <tool/tool_event.h> |
|||
#include <tool/tool_menu.h> |
|||
|
|||
class SCH_EDIT_FRAME; |
|||
|
|||
/** |
|||
* Class SCH_EDITOR_CONTROL |
|||
* |
|||
* Handles actions specific to the schematic editor in eeschema. |
|||
*/ |
|||
class SCH_EDITOR_CONTROL : public wxEvtHandler, public TOOL_INTERACTIVE |
|||
{ |
|||
public: |
|||
SCH_EDITOR_CONTROL(); |
|||
~SCH_EDITOR_CONTROL(); |
|||
|
|||
/// @copydoc TOOL_INTERACTIVE::Reset() |
|||
void Reset( RESET_REASON aReason ) override; |
|||
|
|||
/// @copydoc TOOL_INTERACTIVE::Init() |
|||
bool Init() override; |
|||
|
|||
/** |
|||
* Function PlaceComponent() |
|||
* Displays a dialog to select a module to be added and allows the user to set its position. |
|||
*/ |
|||
int PlaceComponent( const TOOL_EVENT& aEvent ); |
|||
|
|||
///> Toggles 'lock' property for selected items. |
|||
int ToggleLockSelected( const TOOL_EVENT& aEvent ); |
|||
|
|||
///> Locks selected items. |
|||
int LockSelected( const TOOL_EVENT& aEvent ); |
|||
|
|||
///> Unlocks selected items. |
|||
int UnlockSelected( const TOOL_EVENT& aEvent ); |
|||
|
|||
///> Reacts to selection change in pcbnew. |
|||
int CrossProbePcbToSch( const TOOL_EVENT& aEvent ); |
|||
|
|||
///> Notifies pcbnew about the selected item. |
|||
int CrossProbeSchToPcb( const TOOL_EVENT& aEvent ); |
|||
|
|||
///> Highlights net belonging to the item under the cursor. |
|||
int HighlightNet( const TOOL_EVENT& aEvent ); |
|||
|
|||
///> Highlight all items which match the frame's SelectedNetName. |
|||
int HighlightNetSelection( const TOOL_EVENT& aEvent ); |
|||
|
|||
///> Launches a tool to pick the item whose net is going to be highlighted. |
|||
int HighlightNetCursor( const TOOL_EVENT& aEvent ); |
|||
|
|||
private: |
|||
|
|||
///> Sets up handlers for various events. |
|||
void setTransitions() override; |
|||
|
|||
///> Pointer to the currently used edit frame. |
|||
SCH_EDIT_FRAME* m_frame; |
|||
|
|||
/// Menu model displayed by the tool. |
|||
TOOL_MENU m_menu; |
|||
|
|||
}; |
|||
|
|||
|
|||
#endif // SCH_EDITOR_CONTROL_H |
|||
@ -0,0 +1,157 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#include <sch_picker_tool.h>
|
|||
#include <sch_actions.h>
|
|||
#include <view/view_controls.h>
|
|||
#include <tool/tool_manager.h>
|
|||
#include <sch_base_frame.h>
|
|||
|
|||
TOOL_ACTION SCH_ACTIONS::pickerTool( "eeschema.Picker", AS_GLOBAL, 0, "", "", NULL, AF_ACTIVATE ); |
|||
|
|||
|
|||
SCH_PICKER_TOOL::SCH_PICKER_TOOL() |
|||
: TOOL_INTERACTIVE( "eeschema.Picker" ) |
|||
{ |
|||
reset(); |
|||
} |
|||
|
|||
|
|||
int SCH_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) |
|||
{ |
|||
KIGFX::VIEW_CONTROLS* controls = getViewControls(); |
|||
int finalize_state = WAIT_CANCEL; |
|||
|
|||
setControls(); |
|||
|
|||
while( OPT_TOOL_EVENT evt = Wait() ) |
|||
{ |
|||
VECTOR2I cursorPos = controls->GetCursorPosition( true ); |
|||
|
|||
if( evt->IsClick( BUT_LEFT ) ) |
|||
{ |
|||
bool getNext = false; |
|||
|
|||
m_picked = cursorPos; |
|||
|
|||
if( m_clickHandler ) |
|||
{ |
|||
try |
|||
{ |
|||
getNext = (*m_clickHandler)( *m_picked ); |
|||
} |
|||
catch( std::exception& e ) |
|||
{ |
|||
std::cerr << "SCH_PICKER_TOOL click handler error: " << e.what() << std::endl; |
|||
finalize_state = EXCEPTION_CANCEL; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if( !getNext ) |
|||
{ |
|||
finalize_state = CLICK_CANCEL; |
|||
break; |
|||
} |
|||
else |
|||
setControls(); |
|||
} |
|||
|
|||
else if( evt->IsAction( &ACTIONS::cancelInteractive ) || evt->IsActivate() || evt->IsCancel() ) |
|||
{ |
|||
if( m_cancelHandler ) |
|||
{ |
|||
try |
|||
{ |
|||
(*m_cancelHandler)(); |
|||
} |
|||
catch( std::exception& e ) |
|||
{ |
|||
std::cerr << "SCH_PICKER_TOOL cancel handler error: " << e.what() << std::endl; |
|||
} |
|||
} |
|||
|
|||
// Activating a new tool may have alternate finalization from canceling the current tool
|
|||
if( evt->IsActivate() ) |
|||
finalize_state = END_ACTIVATE; |
|||
else |
|||
finalize_state = EVT_CANCEL; |
|||
|
|||
break; |
|||
} |
|||
else if( evt->IsClick( BUT_RIGHT ) ) |
|||
{ |
|||
// TODO...
|
|||
// m_menu.ShowContextMenu();
|
|||
} |
|||
else |
|||
{ |
|||
m_toolMgr->PassEvent(); |
|||
} |
|||
} |
|||
|
|||
if( m_finalizeHandler ) |
|||
{ |
|||
try |
|||
{ |
|||
(*m_finalizeHandler)( finalize_state ); |
|||
} |
|||
catch( std::exception& e ) |
|||
{ |
|||
std::cerr << "SCH_PICKER_TOOL finalize handler error: " << e.what() << std::endl; |
|||
} |
|||
} |
|||
|
|||
reset(); |
|||
controls->ForceCursorPosition( false ); |
|||
getEditFrame<SCH_BASE_FRAME>()->SetNoToolSelected(); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
|
|||
void SCH_PICKER_TOOL::setTransitions() |
|||
{ |
|||
Go( &SCH_PICKER_TOOL::Main, SCH_ACTIONS::pickerTool.MakeEvent() ); |
|||
} |
|||
|
|||
|
|||
void SCH_PICKER_TOOL::reset() |
|||
{ |
|||
m_cursorCapture = false; |
|||
m_autoPanning = false; |
|||
|
|||
m_picked = NULLOPT; |
|||
m_clickHandler = NULLOPT; |
|||
m_cancelHandler = NULLOPT; |
|||
m_finalizeHandler = NULLOPT; |
|||
} |
|||
|
|||
|
|||
void SCH_PICKER_TOOL::setControls() |
|||
{ |
|||
KIGFX::VIEW_CONTROLS* controls = getViewControls(); |
|||
|
|||
controls->CaptureCursor( m_cursorCapture ); |
|||
controls->SetAutoPan( m_autoPanning ); |
|||
} |
|||
@ -0,0 +1,121 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|||
* or you may search the http://www.gnu.org website for the version 2 license, |
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#ifndef SCH_PICKER_TOOL_H |
|||
#define SCH_PICKER_TOOL_H |
|||
|
|||
#include <boost/optional/optional.hpp> |
|||
|
|||
#include <tool/tool_interactive.h> |
|||
|
|||
|
|||
class SCH_PICKER_TOOL : public TOOL_INTERACTIVE |
|||
{ |
|||
public: |
|||
SCH_PICKER_TOOL(); |
|||
~SCH_PICKER_TOOL() {} |
|||
|
|||
///> Event handler types. |
|||
typedef std::function<bool(const VECTOR2D&)> CLICK_HANDLER; |
|||
typedef std::function<void(void)> CANCEL_HANDLER; |
|||
typedef std::function<void(const int&)> FINALIZE_HANDLER; |
|||
|
|||
enum pickerEndState |
|||
{ |
|||
WAIT_CANCEL, |
|||
CLICK_CANCEL, |
|||
END_ACTIVATE, |
|||
EVT_CANCEL, |
|||
EXCEPTION_CANCEL |
|||
}; |
|||
|
|||
///> @copydoc TOOL_INTERACTIVE::Reset() |
|||
void Reset( RESET_REASON aReason ) override {} |
|||
|
|||
///> Main event loop. |
|||
int Main( const TOOL_EVENT& aEvent ); |
|||
|
|||
/** |
|||
* Function SetAutoPanning() |
|||
* Sets autopanning mode for the period when the tool is active. |
|||
*/ |
|||
inline void SetAutoPanning( bool aEnable ) { m_autoPanning = aEnable; } |
|||
|
|||
/** |
|||
* Function SetAutoPanning() |
|||
* Toggles cursor capture mode for the period when the tool is active. |
|||
*/ |
|||
inline void SetCursorCapture( bool aEnable ) { m_cursorCapture = aEnable; } |
|||
|
|||
/** |
|||
* Function SetClickHandler() |
|||
* Sets a handler for mouse click event. Handler may decide to receive further click by |
|||
* returning true. |
|||
*/ |
|||
inline void SetClickHandler( CLICK_HANDLER aHandler ) |
|||
{ |
|||
assert( !m_clickHandler ); |
|||
m_clickHandler = aHandler; |
|||
} |
|||
|
|||
/** |
|||
* Function SetCancelHandler() |
|||
* Sets a handler for cancel events (ESC or context-menu Cancel). |
|||
*/ |
|||
inline void SetCancelHandler( CANCEL_HANDLER aHandler ) |
|||
{ |
|||
assert( !m_cancelHandler ); |
|||
m_cancelHandler = aHandler; |
|||
} |
|||
|
|||
/** |
|||
* Function SetFinalizeHandler() |
|||
* Sets a handler for the finalize event. Takes the state of the exit from the Main loop |
|||
*/ |
|||
inline void SetFinalizeHandler( FINALIZE_HANDLER aHandler ) |
|||
{ |
|||
assert( !m_finalizeHandler ); |
|||
m_finalizeHandler = aHandler; |
|||
} |
|||
|
|||
///> @copydoc TOOL_INTERACTIVE::setTransitions(); |
|||
void setTransitions() override; |
|||
|
|||
private: |
|||
bool m_cursorCapture; |
|||
bool m_autoPanning; |
|||
|
|||
OPT<CLICK_HANDLER> m_clickHandler; |
|||
OPT<CANCEL_HANDLER> m_cancelHandler; |
|||
OPT<FINALIZE_HANDLER> m_finalizeHandler; |
|||
|
|||
OPT<VECTOR2D> m_picked; |
|||
|
|||
///> Reinitializes tool to its initial state. |
|||
void reset(); |
|||
|
|||
///> Applies the requested VIEW_CONTROLS settings. |
|||
void setControls(); |
|||
}; |
|||
|
|||
#endif /* SCH_PICKER_TOOL_H */ |
|||
@ -0,0 +1,99 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2019 KiCad Developers, see CHANGELOG.TXT for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#include <limits>
|
|||
|
|||
#include <functional>
|
|||
#include <tool/selection.h>
|
|||
#include <sch_item_struct.h>
|
|||
|
|||
|
|||
VECTOR2I SELECTION::GetPosition() const |
|||
{ |
|||
return static_cast<VECTOR2I>( GetBoundingBox().GetPosition() ); |
|||
} |
|||
|
|||
|
|||
VECTOR2I SELECTION::GetCenter() const |
|||
{ |
|||
return static_cast<VECTOR2I>( GetBoundingBox().Centre() ); |
|||
} |
|||
|
|||
|
|||
EDA_RECT SELECTION::GetBoundingBox() const |
|||
{ |
|||
EDA_RECT bbox; |
|||
|
|||
bbox = Front()->GetBoundingBox(); |
|||
auto i = m_items.begin(); |
|||
++i; |
|||
|
|||
for( ; i != m_items.end(); ++i ) |
|||
bbox.Merge( (*i)->GetBoundingBox() ); |
|||
|
|||
return bbox; |
|||
} |
|||
|
|||
|
|||
EDA_ITEM* SELECTION::GetTopLeftItem( bool onlyModules ) const |
|||
{ |
|||
SCH_ITEM* topLeftItem = nullptr; |
|||
SCH_ITEM* currentItem; |
|||
|
|||
wxPoint pos; |
|||
|
|||
// find the leftmost (smallest x coord) and highest (smallest y with the smallest x) item in the selection
|
|||
for( auto item : m_items ) |
|||
{ |
|||
currentItem = static_cast<SCH_ITEM*>( item ); |
|||
pos = currentItem->GetPosition(); |
|||
|
|||
if( topLeftItem == nullptr ) |
|||
topLeftItem = currentItem; |
|||
else if( pos.x < topLeftItem->GetPosition().x ) |
|||
topLeftItem = currentItem; |
|||
else if( topLeftItem->GetPosition().x == pos.x && pos.y < topLeftItem->GetPosition().y ) |
|||
topLeftItem = currentItem; |
|||
} |
|||
|
|||
return static_cast<EDA_ITEM*>( topLeftItem ); |
|||
} |
|||
|
|||
|
|||
const BOX2I SELECTION::ViewBBox() const |
|||
{ |
|||
BOX2I r; |
|||
r.SetMaximum(); |
|||
return r; |
|||
} |
|||
|
|||
|
|||
const KIGFX::VIEW_GROUP::ITEMS SELECTION::updateDrawList() const |
|||
{ |
|||
std::vector<VIEW_ITEM*> items; |
|||
|
|||
for( auto item : m_items ) |
|||
items.push_back( item ); |
|||
|
|||
return items; |
|||
} |
|||
@ -1,33 +0,0 @@ |
|||
/*
|
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#include <tool/tool_manager.h>
|
|||
#include <tool/common_tools.h>
|
|||
|
|||
#include <tools/sch_actions.h>
|
|||
|
|||
|
|||
void SCH_ACTIONS::RegisterAllTools( TOOL_MANAGER* aToolManager ) |
|||
{ |
|||
aToolManager->RegisterTool( new COMMON_TOOLS ); |
|||
} |
|||
@ -1,69 +0,0 @@ |
|||
/*
|
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2015 CERN |
|||
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#include <io_mgr.h>
|
|||
|
|||
#include <tool/tool_manager.h>
|
|||
#include <tool/common_tools.h>
|
|||
#include <tool/zoom_tool.h>
|
|||
|
|||
#include <tools/selection_tool.h>
|
|||
#include <tools/picker_tool.h>
|
|||
#include <tools/edit_tool.h>
|
|||
#include <tools/drawing_tool.h>
|
|||
#include <tools/point_editor.h>
|
|||
#include <tools/pcbnew_control.h>
|
|||
#include <tools/pcb_editor_control.h>
|
|||
#include <tools/placement_tool.h>
|
|||
#include <tools/pad_tool.h>
|
|||
#include <tools/microwave_tool.h>
|
|||
#include <tools/position_relative_tool.h>
|
|||
#include <tools/zone_filler_tool.h>
|
|||
#include <tools/pcb_actions.h>
|
|||
|
|||
#include <router/router_tool.h>
|
|||
#include <router/length_tuner_tool.h>
|
|||
#include <autorouter/autoplacer_tool.h>
|
|||
|
|||
void PCB_ACTIONS::RegisterAllTools( TOOL_MANAGER* aToolManager ) |
|||
{ |
|||
aToolManager->RegisterTool( new COMMON_TOOLS ); |
|||
aToolManager->RegisterTool( new SELECTION_TOOL ); |
|||
aToolManager->RegisterTool( new ZOOM_TOOL ); |
|||
aToolManager->RegisterTool( new PICKER_TOOL ); |
|||
aToolManager->RegisterTool( new ROUTER_TOOL ); |
|||
aToolManager->RegisterTool( new LENGTH_TUNER_TOOL ); |
|||
aToolManager->RegisterTool( new EDIT_TOOL ); |
|||
aToolManager->RegisterTool( new PAD_TOOL ); |
|||
aToolManager->RegisterTool( new DRAWING_TOOL ); |
|||
aToolManager->RegisterTool( new POINT_EDITOR ); |
|||
aToolManager->RegisterTool( new PCBNEW_CONTROL ); |
|||
aToolManager->RegisterTool( new PCB_EDITOR_CONTROL ); |
|||
aToolManager->RegisterTool( new ALIGN_DISTRIBUTE_TOOL ); |
|||
aToolManager->RegisterTool( new MICROWAVE_TOOL ); |
|||
aToolManager->RegisterTool( new POSITION_RELATIVE_TOOL ); |
|||
aToolManager->RegisterTool( new ZONE_FILLER_TOOL ); |
|||
aToolManager->RegisterTool( new AUTOPLACE_TOOL ); |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue