Fix questionable code and memory leak.

This commit is contained in:
jean-pierre charras 2017-03-04 16:28:26 +01:00
parent 101a600be6
commit 5b3d7962bb
5 changed files with 36 additions and 31 deletions

View File

@ -88,6 +88,9 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateAndShowItem( const wxPoint& aPosition, const KIC
break; break;
case SCH_SHEET_T: case SCH_SHEET_T:
SendMessageToPCBNEW( item, nullptr );
break;
case SCH_COMPONENT_T: case SCH_COMPONENT_T:
component = (SCH_COMPONENT*) item; component = (SCH_COMPONENT*) item;
SendMessageToPCBNEW( item, component ); SendMessageToPCBNEW( item, component );

View File

@ -40,6 +40,7 @@
#include <lib_draw_item.h> #include <lib_draw_item.h>
#include <lib_pin.h> #include <lib_pin.h>
#include <sch_component.h> #include <sch_component.h>
#include <sch_sheet.h>
/** /**
@ -110,36 +111,34 @@ void SCH_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
} }
std::string FormatProbeItem( EDA_ITEM* aComponent, SCH_COMPONENT* aPart ) std::string FormatProbeItem( EDA_ITEM* aItem, SCH_COMPONENT* aPart )
{ {
// Cross probing to Pcbnew if a pin or a component is found // Cross probing to Pcbnew if a pin or a component is found
switch( aComponent->Type() ) switch( aItem->Type() )
{ {
case SCH_FIELD_T: case SCH_FIELD_T:
case LIB_FIELD_T: case LIB_FIELD_T:
{ if( aPart )
if( !aPart ) return StrPrintf( "$PART: %s",
break; TO_UTF8( aPart->GetField( REFERENCE )->GetText() ) );
return StrPrintf( "$PART: %s", TO_UTF8( aPart->GetField( REFERENCE )->GetText() ) );
}
break; break;
case SCH_COMPONENT_T: case SCH_COMPONENT_T:
aPart = (SCH_COMPONENT*) aComponent; aPart = (SCH_COMPONENT*) aItem;
return StrPrintf( "$PART: %s", TO_UTF8( aPart->GetField( REFERENCE )->GetText() ) ); return StrPrintf( "$PART: %s", TO_UTF8( aPart->GetField( REFERENCE )->GetText() ) );
case SCH_SHEET_T: case SCH_SHEET_T:
aPart = (SCH_COMPONENT*)aComponent; {
return StrPrintf( "$SHEET: %s", TO_UTF8( wxString::Format( wxT("%8.8lX"), SCH_SHEET* sheet = (SCH_SHEET*)aItem;
(unsigned long) aPart->GetTimeStamp() ) ) ); return StrPrintf( "$SHEET: %8.8lX", (unsigned long) sheet->GetTimeStamp() );
}
case LIB_PIN_T: case LIB_PIN_T:
{ {
if( !aPart ) if( !aPart )
break; break;
LIB_PIN* pin = (LIB_PIN*) aComponent; LIB_PIN* pin = (LIB_PIN*) aItem;
if( pin->GetNumber() ) if( pin->GetNumber() )
{ {
@ -165,17 +164,14 @@ std::string FormatProbeItem( EDA_ITEM* aComponent, SCH_COMPONENT* aPart )
} }
void SCH_EDIT_FRAME::SendMessageToPCBNEW( EDA_ITEM* aComponent, SCH_COMPONENT* aPart ) void SCH_EDIT_FRAME::SendMessageToPCBNEW( EDA_ITEM* aObjectToSync, SCH_COMPONENT* aLibItem )
{ {
#if 1 wxASSERT( aObjectToSync ); // fix the caller
wxASSERT( aComponent ); // fix the caller
#else // WTF? if( !aObjectToSync )
if( !aComponent ) // caller remains eternally stupid.
return; return;
#endif
std::string packet = FormatProbeItem( aComponent, aPart ); std::string packet = FormatProbeItem( aObjectToSync, aLibItem );
if( packet.size() ) if( packet.size() )
{ {

View File

@ -488,15 +488,17 @@ public:
/** /**
* Function SendMessageToPcbnew * Function SendMessageToPcbnew
* send a remote to Pcbnew via a socket connection. * send a remote to Pcbnew via a socket connection.
* @param objectToSync Item to be located on board (footprint, pad or text) * @param aObjectToSync = item to be located on board
* @param LibItem Component in library if objectToSync is a sub item of a component * (footprint, pad, text or schematic sheet)
* @param aPart = component if objectToSync is a sub item of a symbol (like a pin)
* <p> * <p>
* Commands are * Commands are
* $PART: reference put cursor on footprint anchor * $PART: reference put cursor on footprint anchor
* $PIN: number $PART: reference put cursor on the footprint pad * $PIN: number $PART: reference put cursor on the footprint pad
* $SHEET: time_stamp select all footprints of components is the schematic sheet path
* </p> * </p>
*/ */
void SendMessageToPCBNEW( EDA_ITEM* objectToSync, SCH_COMPONENT* LibItem ); void SendMessageToPCBNEW( EDA_ITEM* aObjectToSync, SCH_COMPONENT* aPart );
/** /**
* BuildNetListBase * BuildNetListBase

View File

@ -45,7 +45,6 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
char line[1024]; char line[1024];
wxString msg; wxString msg;
wxString modName; wxString modName;
wxString *sheetStamp;
char* idcmd; char* idcmd;
char* text; char* text;
MODULE* module = NULL; MODULE* module = NULL;
@ -81,11 +80,10 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
else if( strcmp( idcmd, "$SHEET:" ) == 0 ) else if( strcmp( idcmd, "$SHEET:" ) == 0 )
{ {
msg.Printf( _( "Selecting all from sheet '%s'" ), FROM_UTF8( text ) ); msg.Printf( _( "Selecting all from sheet '%s'" ), FROM_UTF8( text ) );
sheetStamp = new wxString( FROM_UTF8( text ) ); wxString sheetStamp( FROM_UTF8( text ) );
SetStatusText( msg ); SetStatusText( msg );
GetToolManager()->RunAction( PCB_ACTIONS::selectOnSheet, GetToolManager()->RunAction( PCB_ACTIONS::selectOnSheet, true,
true, static_cast<void*>( &sheetStamp ) );
static_cast<void*>( sheetStamp ) );
return; return;
} }
else if( strcmp( idcmd, "$PIN:" ) == 0 ) else if( strcmp( idcmd, "$PIN:" ) == 0 )

View File

@ -95,18 +95,19 @@ TOOL_ACTION PCB_ACTIONS::selectOnSheet( "pcbnew.InteractiveSelection.SelectOnShe
TOOL_ACTION PCB_ACTIONS::selectSameSheet( "pcbnew.InteractiveSelection.SelectSameSheet", TOOL_ACTION PCB_ACTIONS::selectSameSheet( "pcbnew.InteractiveSelection.SelectSameSheet",
AS_GLOBAL, 'P', AS_GLOBAL, 'P',
_( "Same Sheet" ), _( "Selects all modules and tracks in the same schematic sheet" ) ); _( "Items in Same Hierarchical Sheet" ),
_( "Selects all modules and tracks in the same schematic sheet" ) );
TOOL_ACTION PCB_ACTIONS::find( "pcbnew.InteractiveSelection.Find", TOOL_ACTION PCB_ACTIONS::find( "pcbnew.InteractiveSelection.Find",
AS_GLOBAL, 0, //TOOL_ACTION::LegacyHotKey( HK_FIND_ITEM ), // handled by wxWidgets AS_GLOBAL, 0, //TOOL_ACTION::LegacyHotKey( HK_FIND_ITEM ), // handled by wxWidgets
_( "Find Item" ), _( "Searches the document for an item" ), find_xpm ); _( "Find Item" ),_( "Searches the document for an item" ), find_xpm );
TOOL_ACTION PCB_ACTIONS::findMove( "pcbnew.InteractiveSelection.FindMove", TOOL_ACTION PCB_ACTIONS::findMove( "pcbnew.InteractiveSelection.FindMove",
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_GET_AND_MOVE_FOOTPRINT ) ); AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_GET_AND_MOVE_FOOTPRINT ) );
TOOL_ACTION PCB_ACTIONS::filterSelection( "pcbnew.InteractiveSelection.FilterSelection", TOOL_ACTION PCB_ACTIONS::filterSelection( "pcbnew.InteractiveSelection.FilterSelection",
AS_GLOBAL, MD_SHIFT + 'F', AS_GLOBAL, MD_SHIFT + 'F',
_( "Filter selection" ), _( "Filter the types of items in the selection" ), _( "Filter Selection" ), _( "Filter the types of items in the selection" ),
nullptr ); nullptr );
@ -775,6 +776,8 @@ int SELECTION_TOOL::selectNet( const TOOL_EVENT& aEvent )
return 0; return 0;
} }
void SELECTION_TOOL::selectAllItemsOnSheet( wxString& aSheetpath ) void SELECTION_TOOL::selectAllItemsOnSheet( wxString& aSheetpath )
{ {
auto modules = board()->m_Modules.GetFirst(); auto modules = board()->m_Modules.GetFirst();
@ -901,10 +904,13 @@ int SELECTION_TOOL::selectSameSheet( const TOOL_EVENT& aEvent )
// this function currently only supports modules since they are only // this function currently only supports modules since they are only
// on one sheet. // on one sheet.
auto item = m_selection.Front(); auto item = m_selection.Front();
if( item->Type() != PCB_MODULE_T ) if( item->Type() != PCB_MODULE_T )
return 0; return 0;
if( !item ) if( !item )
return 0; return 0;
auto mod = dynamic_cast<MODULE*>( item ); auto mod = dynamic_cast<MODULE*>( item );
clearSelection(); clearSelection();