Pcbnew: minor bug fixes.

* Use case insensitive comparison to choose import plugin from the file extension.  The
  file extension is not always lower case especially on Windows.
* onleftclick.cpp: fix false warning message in the legacy canvas which happens afte
   switching from the GAL canvas when a board item is still selected.
This commit is contained in:
jean-pierre charras 2016-02-19 09:52:18 -05:00 committed by Wayne Stambaugh
parent fd009f924a
commit 9b0bd7ca1f
2 changed files with 110 additions and 98 deletions

View File

@ -369,21 +369,27 @@ IO_MGR::PCB_FILE_T plugin_type( const wxString& aFileName, int aCtl )
wxFileName fn = aFileName; wxFileName fn = aFileName;
if( fn.GetExt() == IO_MGR::GetFileExtension( IO_MGR::LEGACY ) ) // Note: file extensions are expected to be in ower case.
// This is not always true, especially when importing files, so the string
// comparisons are case insensitive to try to find the suitable plugin.
if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::LEGACY ) ) == 0 )
{ {
// both legacy and eagle share a common file extension. // both legacy and eagle share a common file extension.
pluginType = ( aCtl & KICTL_EAGLE_BRD ) ? IO_MGR::EAGLE : IO_MGR::LEGACY; pluginType = ( aCtl & KICTL_EAGLE_BRD ) ? IO_MGR::EAGLE : IO_MGR::LEGACY;
} }
else if( fn.GetExt() == IO_MGR::GetFileExtension( IO_MGR::LEGACY ) + backupSuffix ) else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::LEGACY ) + backupSuffix ) == 0 )
{ {
pluginType = IO_MGR::LEGACY; pluginType = IO_MGR::LEGACY;
} }
else if( fn.GetExt() == IO_MGR::GetFileExtension( IO_MGR::IO_MGR::PCAD ) ) else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::PCAD ) ) == 0 )
{ {
pluginType = IO_MGR::PCAD; pluginType = IO_MGR::PCAD;
} }
else else
{
pluginType = IO_MGR::KICAD; pluginType = IO_MGR::KICAD;
}
return pluginType; return pluginType;
} }

View File

@ -53,30 +53,30 @@
*/ */
void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
{ {
BOARD_ITEM* DrawStruct = GetCurItem(); BOARD_ITEM* curr_item = GetCurItem();
bool exit = false; bool exit = false;
bool no_tool = GetToolId() == ID_NO_TOOL_SELECTED; bool no_tool = GetToolId() == ID_NO_TOOL_SELECTED;
if( no_tool || ( DrawStruct && DrawStruct->GetFlags() ) ) if( no_tool || ( curr_item && curr_item->GetFlags() ) )
{ {
m_canvas->SetAutoPanRequest( false ); m_canvas->SetAutoPanRequest( false );
if( DrawStruct && DrawStruct->GetFlags() ) // Command in progress if( curr_item && curr_item->GetFlags() ) // Command in progress
{ {
m_canvas->SetIgnoreMouseEvents( true ); m_canvas->SetIgnoreMouseEvents( true );
m_canvas->CrossHairOff( aDC ); m_canvas->CrossHairOff( aDC );
switch( DrawStruct->Type() ) switch( curr_item->Type() )
{ {
case PCB_ZONE_AREA_T: case PCB_ZONE_AREA_T:
if( DrawStruct->IsNew() ) if( curr_item->IsNew() )
{ {
m_canvas->SetAutoPanRequest( true ); m_canvas->SetAutoPanRequest( true );
Begin_Zone( aDC ); Begin_Zone( aDC );
} }
else else
{ {
End_Move_Zone_Corner_Or_Outlines( aDC, static_cast<ZONE_CONTAINER*>( DrawStruct ) ); End_Move_Zone_Corner_Or_Outlines( aDC, static_cast<ZONE_CONTAINER*>( curr_item ) );
} }
exit = true; exit = true;
@ -84,60 +84,66 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
case PCB_TRACE_T: case PCB_TRACE_T:
case PCB_VIA_T: case PCB_VIA_T:
if( DrawStruct->IsDragging() ) if( curr_item->IsDragging() )
{ {
PlaceDraggedOrMovedTrackSegment( static_cast<TRACK*>( DrawStruct ), aDC ); PlaceDraggedOrMovedTrackSegment( static_cast<TRACK*>( curr_item ), aDC );
exit = true; exit = true;
} }
break; break;
case PCB_TEXT_T: case PCB_TEXT_T:
Place_Texte_Pcb( static_cast<TEXTE_PCB*>( DrawStruct ), aDC ); Place_Texte_Pcb( static_cast<TEXTE_PCB*>( curr_item ), aDC );
exit = true; exit = true;
break; break;
case PCB_MODULE_TEXT_T: case PCB_MODULE_TEXT_T:
PlaceTexteModule( static_cast<TEXTE_MODULE*>( DrawStruct ), aDC ); PlaceTexteModule( static_cast<TEXTE_MODULE*>( curr_item ), aDC );
exit = true; exit = true;
break; break;
case PCB_PAD_T: case PCB_PAD_T:
PlacePad( static_cast<D_PAD*>( DrawStruct ), aDC ); PlacePad( static_cast<D_PAD*>( curr_item ), aDC );
exit = true; exit = true;
break; break;
case PCB_MODULE_T: case PCB_MODULE_T:
PlaceModule( static_cast<MODULE*>( DrawStruct ), aDC ); PlaceModule( static_cast<MODULE*>( curr_item ), aDC );
exit = true; exit = true;
break; break;
case PCB_TARGET_T: case PCB_TARGET_T:
PlaceTarget( static_cast<PCB_TARGET*>( DrawStruct ), aDC ); PlaceTarget( static_cast<PCB_TARGET*>( curr_item ), aDC );
exit = true; exit = true;
break; break;
case PCB_LINE_T: case PCB_LINE_T:
if( no_tool ) // when no tools: existing item moving. if( no_tool ) // when no tools: existing item moving.
{ {
Place_DrawItem( static_cast<DRAWSEGMENT*>( DrawStruct ), aDC ); Place_DrawItem( static_cast<DRAWSEGMENT*>( curr_item ), aDC );
exit = true; exit = true;
} }
break; break;
case PCB_DIMENSION_T: case PCB_DIMENSION_T:
if( ! DrawStruct->IsNew() ) if( ! curr_item->IsNew() )
{ // We are moving the text of an existing dimension. Place it { // We are moving the text of an existing dimension. Place it
PlaceDimensionText( static_cast<DIMENSION*>( DrawStruct ), aDC ); PlaceDimensionText( static_cast<DIMENSION*>( curr_item ), aDC );
exit = true; exit = true;
} }
break; break;
case PCB_MARKER_T: // MARKER_PCB, a marker used to show something
curr_item->ClearFlags(); // Not reason to have flags set
exit = true;
break;
default: default:
DisplayError( this, DisplayError( this,
wxT( "PCB_EDIT_FRAME::OnLeftClick() err: DrawType %d m_Flags != 0" ), wxString::Format(
DrawStruct->Type() ); "PCB_EDIT_FRAME::OnLeftClick() err: curr_item type %d m_Flags != 0 (%X)",
curr_item->Type(), curr_item->GetFlags() ) );
exit = true; exit = true;
break; break;
} }
@ -151,23 +157,23 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
else if( !wxGetKeyState( WXK_SHIFT ) && !wxGetKeyState( WXK_ALT ) else if( !wxGetKeyState( WXK_SHIFT ) && !wxGetKeyState( WXK_ALT )
&& !wxGetKeyState( WXK_CONTROL ) ) && !wxGetKeyState( WXK_CONTROL ) )
{ {
DrawStruct = PcbGeneralLocateAndDisplay(); curr_item = PcbGeneralLocateAndDisplay();
if( DrawStruct ) if( curr_item )
SendMessageToEESCHEMA( DrawStruct ); SendMessageToEESCHEMA( curr_item );
} }
} }
if( DrawStruct ) // display netclass info for zones, tracks and pads if( curr_item ) // display netclass info for zones, tracks and pads
{ {
switch( DrawStruct->Type() ) switch( curr_item->Type() )
{ {
case PCB_ZONE_AREA_T: case PCB_ZONE_AREA_T:
case PCB_TRACE_T: case PCB_TRACE_T:
case PCB_VIA_T: case PCB_VIA_T:
case PCB_PAD_T: case PCB_PAD_T:
SetCurrentNetClass( SetCurrentNetClass(
((BOARD_CONNECTED_ITEM*)DrawStruct)->GetNetClassName() ); ((BOARD_CONNECTED_ITEM*)curr_item)->GetNetClassName() );
break; break;
default: default:
@ -210,23 +216,23 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break; break;
case ID_PCB_SHOW_1_RATSNEST_BUTT: case ID_PCB_SHOW_1_RATSNEST_BUTT:
DrawStruct = PcbGeneralLocateAndDisplay(); curr_item = PcbGeneralLocateAndDisplay();
Show_1_Ratsnest( DrawStruct, aDC ); Show_1_Ratsnest( curr_item, aDC );
if( DrawStruct ) if( curr_item )
SendMessageToEESCHEMA( DrawStruct ); SendMessageToEESCHEMA( curr_item );
break; break;
case ID_PCB_MIRE_BUTT: case ID_PCB_MIRE_BUTT:
if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) if( (curr_item == NULL) || (curr_item->GetFlags() == 0) )
{ {
SetCurItem( (BOARD_ITEM*) CreateTarget( aDC ) ); SetCurItem( (BOARD_ITEM*) CreateTarget( aDC ) );
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
} }
else if( DrawStruct->Type() == PCB_TARGET_T ) else if( curr_item->Type() == PCB_TARGET_T )
{ {
PlaceTarget( (PCB_TARGET*) DrawStruct, aDC ); PlaceTarget( (PCB_TARGET*) curr_item, aDC );
} }
else else
{ {
@ -253,18 +259,18 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break; break;
} }
if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) if( (curr_item == NULL) || (curr_item->GetFlags() == 0) )
{ {
DrawStruct = (BOARD_ITEM*) Begin_DrawSegment( NULL, shape, aDC ); curr_item = (BOARD_ITEM*) Begin_DrawSegment( NULL, shape, aDC );
SetCurItem( DrawStruct ); SetCurItem( curr_item );
m_canvas->SetAutoPanRequest( true ); m_canvas->SetAutoPanRequest( true );
} }
else if( DrawStruct else if( curr_item
&& (DrawStruct->Type() == PCB_LINE_T) && (curr_item->Type() == PCB_LINE_T)
&& DrawStruct->IsNew() ) && curr_item->IsNew() )
{ {
DrawStruct = (BOARD_ITEM*) Begin_DrawSegment( (DRAWSEGMENT*) DrawStruct, shape, aDC ); curr_item = (BOARD_ITEM*) Begin_DrawSegment( (DRAWSEGMENT*) curr_item, shape, aDC );
SetCurItem( DrawStruct ); SetCurItem( curr_item );
m_canvas->SetAutoPanRequest( true ); m_canvas->SetAutoPanRequest( true );
} }
} }
@ -277,22 +283,22 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break; break;
} }
if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) if( (curr_item == NULL) || (curr_item->GetFlags() == 0) )
{ {
DrawStruct = (BOARD_ITEM*) Begin_Route( NULL, aDC ); curr_item = (BOARD_ITEM*) Begin_Route( NULL, aDC );
SetCurItem( DrawStruct ); SetCurItem( curr_item );
if( DrawStruct ) if( curr_item )
m_canvas->SetAutoPanRequest( true ); m_canvas->SetAutoPanRequest( true );
} }
else if( DrawStruct && DrawStruct->IsNew() ) else if( curr_item && curr_item->IsNew() )
{ {
TRACK* track = Begin_Route( (TRACK*) DrawStruct, aDC ); TRACK* track = Begin_Route( (TRACK*) curr_item, aDC );
// SetCurItem() must not write to the msg panel // SetCurItem() must not write to the msg panel
// because a track info is displayed while moving the mouse cursor // because a track info is displayed while moving the mouse cursor
if( track ) // A new segment was created if( track ) // A new segment was created
SetCurItem( DrawStruct = (BOARD_ITEM*) track, false ); SetCurItem( curr_item = (BOARD_ITEM*) track, false );
m_canvas->SetAutoPanRequest( true ); m_canvas->SetAutoPanRequest( true );
} }
@ -305,21 +311,21 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
* this can be start a new zone or select and move an existing zone outline corner * this can be start a new zone or select and move an existing zone outline corner
* if found near the mouse cursor * if found near the mouse cursor
*/ */
if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) if( (curr_item == NULL) || (curr_item->GetFlags() == 0) )
{ {
if( Begin_Zone( aDC ) ) if( Begin_Zone( aDC ) )
{ {
m_canvas->SetAutoPanRequest( true ); m_canvas->SetAutoPanRequest( true );
DrawStruct = GetBoard()->m_CurrentZoneContour; curr_item = GetBoard()->m_CurrentZoneContour;
GetScreen()->SetCurItem( DrawStruct ); GetScreen()->SetCurItem( curr_item );
} }
} }
else if( DrawStruct && (DrawStruct->Type() == PCB_ZONE_AREA_T) && DrawStruct->IsNew() ) else if( curr_item && (curr_item->Type() == PCB_ZONE_AREA_T) && curr_item->IsNew() )
{ // Add a new corner to the current outline being created: { // Add a new corner to the current outline being created:
m_canvas->SetAutoPanRequest( true ); m_canvas->SetAutoPanRequest( true );
Begin_Zone( aDC ); Begin_Zone( aDC );
DrawStruct = GetBoard()->m_CurrentZoneContour; curr_item = GetBoard()->m_CurrentZoneContour;
GetScreen()->SetCurItem( DrawStruct ); GetScreen()->SetCurItem( curr_item );
} }
else else
{ {
@ -336,15 +342,15 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break; break;
} }
if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) if( (curr_item == NULL) || (curr_item->GetFlags() == 0) )
{ {
SetCurItem( CreateTextePcb( aDC ) ); SetCurItem( CreateTextePcb( aDC ) );
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
m_canvas->SetAutoPanRequest( true ); m_canvas->SetAutoPanRequest( true );
} }
else if( DrawStruct->Type() == PCB_TEXT_T ) else if( curr_item->Type() == PCB_TEXT_T )
{ {
Place_Texte_Pcb( (TEXTE_PCB*) DrawStruct, aDC ); Place_Texte_Pcb( (TEXTE_PCB*) curr_item, aDC );
m_canvas->SetAutoPanRequest( false ); m_canvas->SetAutoPanRequest( false );
} }
else else
@ -355,20 +361,20 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break; break;
case ID_PCB_MODULE_BUTT: case ID_PCB_MODULE_BUTT:
if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) if( (curr_item == NULL) || (curr_item->GetFlags() == 0) )
{ {
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
DrawStruct = (BOARD_ITEM*) LoadModuleFromLibrary( curr_item = (BOARD_ITEM*) LoadModuleFromLibrary(
wxEmptyString, Prj().PcbFootprintLibs(), true, aDC ); wxEmptyString, Prj().PcbFootprintLibs(), true, aDC );
SetCurItem( DrawStruct ); SetCurItem( curr_item );
if( DrawStruct ) if( curr_item )
StartMoveModule( (MODULE*) DrawStruct, aDC, false ); StartMoveModule( (MODULE*) curr_item, aDC, false );
} }
else if( DrawStruct->Type() == PCB_MODULE_T ) else if( curr_item->Type() == PCB_MODULE_T )
{ {
PlaceModule( (MODULE*) DrawStruct, aDC ); PlaceModule( (MODULE*) curr_item, aDC );
m_canvas->SetAutoPanRequest( false ); m_canvas->SetAutoPanRequest( false );
} }
else else
@ -385,16 +391,16 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break; break;
} }
if( !DrawStruct || !DrawStruct->GetFlags() ) if( !curr_item || !curr_item->GetFlags() )
{ {
DrawStruct = (BOARD_ITEM*) EditDimension( NULL, aDC ); curr_item = (BOARD_ITEM*) EditDimension( NULL, aDC );
SetCurItem( DrawStruct ); SetCurItem( curr_item );
m_canvas->SetAutoPanRequest( true ); m_canvas->SetAutoPanRequest( true );
} }
else if( DrawStruct && (DrawStruct->Type() == PCB_DIMENSION_T) && DrawStruct->IsNew() ) else if( curr_item && (curr_item->Type() == PCB_DIMENSION_T) && curr_item->IsNew() )
{ {
DrawStruct = (BOARD_ITEM*) EditDimension( (DIMENSION*) DrawStruct, aDC ); curr_item = (BOARD_ITEM*) EditDimension( (DIMENSION*) curr_item, aDC );
SetCurItem( DrawStruct ); SetCurItem( curr_item );
m_canvas->SetAutoPanRequest( true ); m_canvas->SetAutoPanRequest( true );
} }
else else
@ -406,14 +412,14 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break; break;
case ID_PCB_DELETE_ITEM_BUTT: case ID_PCB_DELETE_ITEM_BUTT:
if( !DrawStruct || !DrawStruct->GetFlags() ) if( !curr_item || !curr_item->GetFlags() )
{ {
DrawStruct = PcbGeneralLocateAndDisplay(); curr_item = PcbGeneralLocateAndDisplay();
if( DrawStruct && (DrawStruct->GetFlags() == 0) ) if( curr_item && (curr_item->GetFlags() == 0) )
{ {
RemoveStruct( DrawStruct, aDC ); RemoveStruct( curr_item, aDC );
SetCurItem( DrawStruct = NULL ); SetCurItem( curr_item = NULL );
} }
} }
@ -444,36 +450,36 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
*/ */
void PCB_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition ) void PCB_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition )
{ {
BOARD_ITEM* DrawStruct = GetCurItem(); BOARD_ITEM* curr_item = GetCurItem();
switch( GetToolId() ) switch( GetToolId() )
{ {
case ID_NO_TOOL_SELECTED: case ID_NO_TOOL_SELECTED:
if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) if( (curr_item == NULL) || (curr_item->GetFlags() == 0) )
{ {
DrawStruct = PcbGeneralLocateAndDisplay(); curr_item = PcbGeneralLocateAndDisplay();
} }
if( (DrawStruct == NULL) || (DrawStruct->GetFlags() != 0) ) if( (curr_item == NULL) || (curr_item->GetFlags() != 0) )
break; break;
SendMessageToEESCHEMA( DrawStruct ); SendMessageToEESCHEMA( curr_item );
// An item is found // An item is found
SetCurItem( DrawStruct ); SetCurItem( curr_item );
switch( DrawStruct->Type() ) switch( curr_item->Type() )
{ {
case PCB_TRACE_T: case PCB_TRACE_T:
case PCB_VIA_T: case PCB_VIA_T:
if( DrawStruct->IsNew() ) if( curr_item->IsNew() )
{ {
if( End_Route( (TRACK*) DrawStruct, aDC ) ) if( End_Route( (TRACK*) curr_item, aDC ) )
m_canvas->SetAutoPanRequest( false ); m_canvas->SetAutoPanRequest( false );
} }
else if( DrawStruct->GetFlags() == 0 ) else if( curr_item->GetFlags() == 0 )
{ {
Edit_TrackSegm_Width( aDC, (TRACK*) DrawStruct ); Edit_TrackSegm_Width( aDC, (TRACK*) curr_item );
} }
break; break;
@ -484,19 +490,19 @@ void PCB_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition )
case PCB_TARGET_T: case PCB_TARGET_T:
case PCB_DIMENSION_T: case PCB_DIMENSION_T:
case PCB_MODULE_TEXT_T: case PCB_MODULE_TEXT_T:
OnEditItemRequest( aDC, DrawStruct ); OnEditItemRequest( aDC, curr_item );
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
break; break;
case PCB_LINE_T: case PCB_LINE_T:
OnEditItemRequest( aDC, DrawStruct ); OnEditItemRequest( aDC, curr_item );
break; break;
case PCB_ZONE_AREA_T: case PCB_ZONE_AREA_T:
if( DrawStruct->GetFlags() ) if( curr_item->GetFlags() )
break; break;
OnEditItemRequest( aDC, DrawStruct ); OnEditItemRequest( aDC, curr_item );
break; break;
default: default:
@ -506,9 +512,9 @@ void PCB_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition )
break; // end case 0 break; // end case 0
case ID_TRACK_BUTT: case ID_TRACK_BUTT:
if( DrawStruct && DrawStruct->IsNew() ) if( curr_item && curr_item->IsNew() )
{ {
if( End_Route( (TRACK*) DrawStruct, aDC ) ) if( End_Route( (TRACK*) curr_item, aDC ) )
m_canvas->SetAutoPanRequest( false ); m_canvas->SetAutoPanRequest( false );
} }
@ -527,19 +533,19 @@ void PCB_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition )
case ID_PCB_ADD_LINE_BUTT: case ID_PCB_ADD_LINE_BUTT:
case ID_PCB_ARC_BUTT: case ID_PCB_ARC_BUTT:
case ID_PCB_CIRCLE_BUTT: case ID_PCB_CIRCLE_BUTT:
if( DrawStruct == NULL ) if( curr_item == NULL )
break; break;
if( DrawStruct->Type() != PCB_LINE_T ) if( curr_item->Type() != PCB_LINE_T )
{ {
DisplayError( this, wxT( "DrawStruct Type error" ) ); DisplayError( this, wxT( "curr_item Type error" ) );
m_canvas->SetAutoPanRequest( false ); m_canvas->SetAutoPanRequest( false );
break; break;
} }
if( DrawStruct->IsNew() ) if( curr_item->IsNew() )
{ {
End_Edge( (DRAWSEGMENT*) DrawStruct, aDC ); End_Edge( (DRAWSEGMENT*) curr_item, aDC );
m_canvas->SetAutoPanRequest( false ); m_canvas->SetAutoPanRequest( false );
SetCurItem( NULL ); SetCurItem( NULL );
} }