From dda51ab550d34ba7d61ebb17e3e6889cc2121ddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20=C3=96dmark?= Date: Fri, 3 Mar 2017 00:42:23 +0100 Subject: [PATCH] CrossProbes Schematics from eeschema to pcbnew Adds a similar crossprobe as modules has in pcbnew. When clicking a sheet in eeschema, the items that are exclusive in that scheet will be selected in pcbnew if using the GAL canvas. --- eeschema/controle.cpp | 1 + eeschema/cross-probing.cpp | 5 +++ include/tool/selection.h | 2 + pcbnew/cross-probing.cpp | 12 ++++++ pcbnew/tools/pcb_actions.h | 3 ++ pcbnew/tools/selection_tool.cpp | 74 ++++++++++++++++++++++++++++++--- pcbnew/tools/selection_tool.h | 8 +++- 7 files changed, 99 insertions(+), 6 deletions(-) diff --git a/eeschema/controle.cpp b/eeschema/controle.cpp index a492b64080..af5c33ab73 100644 --- a/eeschema/controle.cpp +++ b/eeschema/controle.cpp @@ -87,6 +87,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateAndShowItem( const wxPoint& aPosition, const KIC SendMessageToPCBNEW( item, component ); break; + case SCH_SHEET_T: case SCH_COMPONENT_T: component = (SCH_COMPONENT*) item; SendMessageToPCBNEW( item, component ); diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp index 7bc8e63366..a08ec15272 100644 --- a/eeschema/cross-probing.cpp +++ b/eeschema/cross-probing.cpp @@ -129,6 +129,11 @@ std::string FormatProbeItem( EDA_ITEM* aComponent, SCH_COMPONENT* aPart ) aPart = (SCH_COMPONENT*) aComponent; return StrPrintf( "$PART: %s", TO_UTF8( aPart->GetField( REFERENCE )->GetText() ) ); + case SCH_SHEET_T: + aPart = (SCH_COMPONENT*)aComponent; + return StrPrintf( "$SHEET: %s", TO_UTF8( wxString::Format( wxT("%8.8lX"), + (unsigned long) aPart->GetTimeStamp() ) ) ); + case LIB_PIN_T: { if( !aPart ) diff --git a/include/tool/selection.h b/include/tool/selection.h index 9997812a6f..4e972b30c9 100644 --- a/include/tool/selection.h +++ b/include/tool/selection.h @@ -97,6 +97,8 @@ public: /// Returns the center point of the selection area bounding box. VECTOR2I GetCenter() const; + const BOX2I ViewBBox() const override; + EDA_ITEM* operator[]( const int index ) const { if( index < 0 || (unsigned int) index >= m_items.size() ) diff --git a/pcbnew/cross-probing.cpp b/pcbnew/cross-probing.cpp index be3e50472b..e7f63c9c47 100644 --- a/pcbnew/cross-probing.cpp +++ b/pcbnew/cross-probing.cpp @@ -30,6 +30,7 @@ #include #include +#include #include /* Execute a remote command send by Eeschema via a socket, @@ -44,6 +45,7 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) char line[1024]; wxString msg; wxString modName; + wxString *sheetStamp; char* idcmd; char* text; MODULE* module = NULL; @@ -76,6 +78,16 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) if( module ) pos = module->GetPosition(); } + else if( strcmp( idcmd, "$SHEET:" ) == 0 ) + { + msg.Printf( _( "Selecting all from sheet '%s'" ), FROM_UTF8( text ) ); + sheetStamp = new wxString( FROM_UTF8( text ) ); + SetStatusText( msg ); + GetToolManager()->RunAction( PCB_ACTIONS::selectOnSheet, + true, + static_cast( sheetStamp ) ); + return; + } else if( strcmp( idcmd, "$PIN:" ) == 0 ) { wxString pinName; diff --git a/pcbnew/tools/pcb_actions.h b/pcbnew/tools/pcb_actions.h index 1e8985fed4..0ebb9a5ab7 100644 --- a/pcbnew/tools/pcb_actions.h +++ b/pcbnew/tools/pcb_actions.h @@ -67,6 +67,9 @@ public: /// Selects all connections belonging to a single net. static TOOL_ACTION selectNet; + /// Selects all components on sheet. + static TOOL_ACTION selectOnSheet; + /// Selects all components on the same sheet. static TOOL_ACTION selectSameSheet; diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index ee28eb32e8..69678faf39 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -89,6 +89,10 @@ TOOL_ACTION PCB_ACTIONS::selectNet( "pcbnew.InteractiveSelection.SelectNet", AS_GLOBAL, 0, _( "Whole Net" ), _( "Selects all tracks & vias belonging to the same net." ) ); +TOOL_ACTION PCB_ACTIONS::selectOnSheet( "pcbnew.InteractiveSelection.SelectOnSheet", + AS_GLOBAL, 0, + _( "Sheet" ), _( "Selects all modules and tracks in the schematic sheet" ) ); + TOOL_ACTION PCB_ACTIONS::selectSameSheet( "pcbnew.InteractiveSelection.SelectSameSheet", AS_GLOBAL, 'P', _( "Same Sheet" ), _( "Selects all modules and tracks in the same schematic sheet" ) ); @@ -541,6 +545,7 @@ void SELECTION_TOOL::SetTransitions() Go( &SELECTION_TOOL::selectCopper, PCB_ACTIONS::selectCopper.MakeEvent() ); Go( &SELECTION_TOOL::selectNet, PCB_ACTIONS::selectNet.MakeEvent() ); Go( &SELECTION_TOOL::selectSameSheet, PCB_ACTIONS::selectSameSheet.MakeEvent() ); + Go( &SELECTION_TOOL::selectOnSheet, PCB_ACTIONS::selectOnSheet.MakeEvent() ); } @@ -681,7 +686,7 @@ int SELECTION_TOOL::selectConnection( const TOOL_EVENT& aEvent ) int SELECTION_TOOL::selectCopper( const TOOL_EVENT& aEvent ) { - if( !selectCursor( ) ) + if( !selectCursor() ) return 0; // copy the selection, since we're going to iterate and modify @@ -691,7 +696,7 @@ int SELECTION_TOOL::selectCopper( const TOOL_EVENT& aEvent ) { auto item = static_cast( i ); // only connected items can be traversed in the ratsnest - if ( item->IsConnected() ) + if( item->IsConnected() ) { auto& connItem = static_cast( *item ); @@ -770,7 +775,7 @@ int SELECTION_TOOL::selectNet( const TOOL_EVENT& aEvent ) return 0; } -void SELECTION_TOOL::selectAllItemsOnSheet( wxString sheet ) +void SELECTION_TOOL::selectAllItemsOnSheet( wxString aSheet ) { auto modules = board()->m_Modules.GetFirst(); std::list modList; @@ -778,7 +783,7 @@ void SELECTION_TOOL::selectAllItemsOnSheet( wxString sheet ) // store all modules that are on that sheet for( MODULE* mitem = modules; mitem; mitem = mitem->Next() ) { - if ( mitem != NULL && mitem->GetPath().Contains( sheet ) ) + if( mitem != NULL && mitem->GetPath().Contains( aSheet ) ) { modList.push_back( mitem ); } @@ -851,6 +856,43 @@ void SELECTION_TOOL::selectAllItemsOnSheet( wxString sheet ) } } +void SELECTION_TOOL::zoomFitSelection( void ) +{ + //Should recalculate the view to zoom in on the selection + auto selectionBox = m_selection.ViewBBox(); + auto canvas = m_frame->GetGalCanvas(); + auto view = getView(); + + VECTOR2D screenSize = view->ToWorld( canvas->GetClientSize(), false ); + + if( !( selectionBox.GetWidth() == 0 ) || !( selectionBox.GetHeight() == 0 ) ) + { + VECTOR2D vsize = selectionBox.GetSize(); + double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ), + fabs( vsize.y / screenSize.y ) ); + view->SetScale( scale ); + view->SetCenter( selectionBox.Centre() ); + view->Add( &m_selection ); + } + + m_frame->GetGalCanvas()->ForceRefresh(); +} + +int SELECTION_TOOL::selectOnSheet( const TOOL_EVENT& aEvent ) +{ + clearSelection(); + wxString* sheet = aEvent.Parameter(); + selectAllItemsOnSheet( *sheet ); + + zoomFitSelection(); + + if( m_selection.Size() > 0 ) + m_toolMgr->ProcessEvent( SelectedEvent ); + + + return 0; +} + int SELECTION_TOOL::selectSameSheet( const TOOL_EVENT& aEvent ) { if( !selectCursor( true ) ) @@ -872,7 +914,7 @@ int SELECTION_TOOL::selectSameSheet( const TOOL_EVENT& aEvent ) sheetPath = sheetPath.BeforeLast( '/' ); sheetPath = sheetPath.AfterLast( '/' ); - selectAllItemsOnSheet(sheetPath); + selectAllItemsOnSheet( sheetPath ); // Inform other potentially interested tools if( m_selection.Size() > 0 ) @@ -1782,6 +1824,28 @@ VECTOR2I SELECTION::GetCenter() const return centre; } +const BOX2I SELECTION::ViewBBox() const +{ + EDA_RECT eda_bbox; + + if( Size() == 1 ) + { + eda_bbox = Front()->GetBoundingBox(); + } + else if( Size() > 1 ) + { + eda_bbox = Front()->GetBoundingBox(); + auto i = m_items.begin(); + ++i; + + for( ; i != m_items.end(); ++i ) + { + eda_bbox.Merge( (*i)->GetBoundingBox() ); + } + } + return BOX2I( eda_bbox.GetOrigin(), eda_bbox.GetSize() ); +} + const KIGFX::VIEW_GROUP::ITEMS SELECTION::updateDrawList() const { diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index b0aeee22b2..47d822dd39 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -120,6 +120,9 @@ public: ///> Sets up handlers for various events. void SetTransitions() override; + ///> Zooms the screen to center and fit the current selection. + void zoomFitSelection( void ); + private: /** * Function selectPoint() @@ -180,7 +183,10 @@ private: /** * Selects all items with the given sheet timestamp name */ - void selectAllItemsOnSheet( wxString sheet ); + void selectAllItemsOnSheet( wxString aSheet ); + + ///> Selects all modules belonging to same sheet. + int selectOnSheet( const TOOL_EVENT& aEvent ); ///> Selects all modules belonging to same sheet. int selectSameSheet( const TOOL_EVENT& aEvent );