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.
This commit is contained in:
Kristoffer Ödmark 2017-03-03 00:42:23 +01:00 committed by Chris Pavlina
parent 69a649c093
commit dda51ab550
7 changed files with 99 additions and 6 deletions

View File

@ -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 );

View File

@ -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 )

View File

@ -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() )

View File

@ -30,6 +30,7 @@
#include <tools/pcb_actions.h>
#include <tool/tool_manager.h>
#include <tools/selection_tool.h>
#include <pcb_draw_panel_gal.h>
/* 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<void*>( sheetStamp ) );
return;
}
else if( strcmp( idcmd, "$PIN:" ) == 0 )
{
wxString pinName;

View File

@ -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;

View File

@ -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() );
}
@ -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<MODULE*> 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<wxString*>();
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 ) )
@ -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
{

View File

@ -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 );