Cleanup and formatting.

This commit is contained in:
Jeff Young 2020-11-22 22:21:41 +00:00
parent f5e9a2a6da
commit dd60fd47b2
9 changed files with 317 additions and 351 deletions

View File

@ -59,10 +59,12 @@ bool LIB_DRAWING_TOOLS::Init()
{ {
EE_TOOL_BASE::Init(); EE_TOOL_BASE::Init();
auto isDrawingCondition = [] ( const SELECTION& aSel ) { auto isDrawingCondition =
LIB_ITEM* item = (LIB_ITEM*) aSel.Front(); [] ( const SELECTION& aSel )
return item && item->IsNew(); {
}; LIB_ITEM* item = (LIB_ITEM*) aSel.Front();
return item && item->IsNew();
};
m_menu.GetMenu().AddItem( EE_ACTIONS::finishDrawing, isDrawingCondition, 2 ); m_menu.GetMenu().AddItem( EE_ACTIONS::finishDrawing, isDrawingCondition, 2 );
@ -123,7 +125,9 @@ int LIB_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
if( evt->IsCancelInteractive() ) if( evt->IsCancelInteractive() )
{ {
if( item ) if( item )
{
cleanup(); cleanup();
}
else else
{ {
m_frame->PopTool( tool ); m_frame->PopTool( tool );
@ -261,7 +265,7 @@ int LIB_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent )
{ {
SYMBOL_EDITOR_SETTINGS* settings = Pgm().GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>(); SYMBOL_EDITOR_SETTINGS* settings = Pgm().GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
KICAD_T type = aEvent.Parameter<KICAD_T>(); KICAD_T type = aEvent.Parameter<KICAD_T>();
// We might be running as the same shape in another co-routine. Make sure that one // We might be running as the same shape in another co-routine. Make sure that one
// gets whacked. // gets whacked.
@ -476,7 +480,9 @@ int LIB_DRAWING_TOOLS::PlaceAnchor( const TOOL_EVENT& aEvent )
m_menu.ShowContextMenu( m_selectionTool->GetSelection() ); m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
} }
else else
{
evt->SetPassEvent(); evt->SetPassEvent();
}
} }
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW ); m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );

View File

@ -154,7 +154,9 @@ int LIB_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
} }
if( item->IsMoving() ) if( item->IsMoving() )
{
m_toolMgr->RunAction( ACTIONS::refreshPreview, true ); m_toolMgr->RunAction( ACTIONS::refreshPreview, true );
}
else else
{ {
m_toolMgr->PostEvent( EVENTS::SelectedItemsModified ); m_toolMgr->PostEvent( EVENTS::SelectedItemsModified );
@ -203,7 +205,9 @@ int LIB_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
m_toolMgr->PostEvent( EVENTS::SelectedItemsModified ); m_toolMgr->PostEvent( EVENTS::SelectedItemsModified );
if( item->IsMoving() ) if( item->IsMoving() )
{
m_toolMgr->RunAction( ACTIONS::refreshPreview, true ); m_toolMgr->RunAction( ACTIONS::refreshPreview, true );
}
else else
{ {
if( selection.IsHover() ) if( selection.IsHover() )
@ -281,10 +285,8 @@ int LIB_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent )
} }
} }
for( auto item : toDelete ) for( LIB_ITEM* item : toDelete )
{
part->RemoveDrawItem( item ); part->RemoveDrawItem( item );
}
m_frame->RebuildView(); m_frame->RebuildView();
m_frame->OnModify(); m_frame->OnModify();
@ -310,62 +312,63 @@ int LIB_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
picker->SetCursor( KICURSOR::REMOVE ); picker->SetCursor( KICURSOR::REMOVE );
picker->SetClickHandler( picker->SetClickHandler(
[this] ( const VECTOR2D& aPosition ) -> bool [this]( const VECTOR2D& aPosition ) -> bool
{
if( m_pickerItem )
{ {
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>(); if( m_pickerItem )
selectionTool->UnbrightenItem( m_pickerItem ); {
selectionTool->AddItemToSel( m_pickerItem, true /*quiet mode*/ ); EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
m_toolMgr->RunAction( ACTIONS::doDelete, true ); selectionTool->UnbrightenItem( m_pickerItem );
m_pickerItem = nullptr; selectionTool->AddItemToSel( m_pickerItem, true /*quiet mode*/ );
} m_toolMgr->RunAction( ACTIONS::doDelete, true );
m_pickerItem = nullptr;
}
return true; return true;
} ); } );
picker->SetMotionHandler( picker->SetMotionHandler(
[this] ( const VECTOR2D& aPos ) [this]( const VECTOR2D& aPos )
{
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
EE_COLLECTOR collector;
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
collector.Collect( m_frame->GetScreen(), nonFields, (wxPoint) aPos, m_frame->GetUnit(),
m_frame->GetConvert() );
// Remove unselectable items
for( int i = collector.GetCount() - 1; i >= 0; --i )
{ {
if( !selectionTool->Selectable( collector[ i ] ) ) EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
collector.Remove( i ); EE_COLLECTOR collector;
}
if( collector.GetCount() > 1 ) collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
selectionTool->GuessSelectionCandidates( collector, aPos ); collector.Collect( m_frame->GetScreen(), nonFields, (wxPoint) aPos,
m_frame->GetUnit(), m_frame->GetConvert() );
EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr; // Remove unselectable items
for( int i = collector.GetCount() - 1; i >= 0; --i )
{
if( !selectionTool->Selectable( collector[ i ] ) )
collector.Remove( i );
}
if( m_pickerItem != item ) if( collector.GetCount() > 1 )
{ selectionTool->GuessSelectionCandidates( collector, aPos );
if( m_pickerItem )
selectionTool->UnbrightenItem( m_pickerItem );
m_pickerItem = item; EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
if( m_pickerItem ) if( m_pickerItem != item )
selectionTool->BrightenItem( m_pickerItem ); {
} if( m_pickerItem )
} ); selectionTool->UnbrightenItem( m_pickerItem );
m_pickerItem = item;
if( m_pickerItem )
selectionTool->BrightenItem( m_pickerItem );
}
} );
picker->SetFinalizeHandler( picker->SetFinalizeHandler(
[this] ( const int& aFinalState ) [this]( const int& aFinalState )
{ {
if( m_pickerItem ) if( m_pickerItem )
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem ); m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
// Wake the selection tool after exiting to ensure the cursor gets updated // Wake the selection tool after exiting to ensure the cursor gets updated
m_toolMgr->RunAction( EE_ACTIONS::selectionActivate, false ); m_toolMgr->RunAction( EE_ACTIONS::selectionActivate, false );
} ); } );
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );

View File

@ -314,28 +314,6 @@ void LIB_MOVE_TOOL::moveItem( EDA_ITEM* aItem, VECTOR2I aDelta )
} }
bool LIB_MOVE_TOOL::updateModificationPoint( EE_SELECTION& aSelection )
{
if( m_moveInProgress && aSelection.HasReferencePoint() )
return false;
// When there is only one item selected, the reference point is its position...
if( aSelection.Size() == 1 )
{
LIB_ITEM* item = static_cast<LIB_ITEM*>( aSelection.Front() );
aSelection.SetReferencePoint( item->GetPosition() );
}
// ...otherwise modify items with regard to the grid-snapped cursor position
else
{
m_cursor = getViewControls()->GetCursorPosition( true );
aSelection.SetReferencePoint( m_cursor );
}
return true;
}
void LIB_MOVE_TOOL::setTransitions() void LIB_MOVE_TOOL::setTransitions()
{ {
Go( &LIB_MOVE_TOOL::Main, EE_ACTIONS::move.MakeEvent() ); Go( &LIB_MOVE_TOOL::Main, EE_ACTIONS::move.MakeEvent() );

View File

@ -54,10 +54,6 @@ public:
private: private:
void moveItem( EDA_ITEM* aItem, VECTOR2I aDelta ); void moveItem( EDA_ITEM* aItem, VECTOR2I aDelta );
///> Returns the right modification point (e.g. for rotation), depending on the number of
///> selected items.
bool updateModificationPoint( EE_SELECTION& aSelection );
///> Sets up handlers for various events. ///> Sets up handlers for various events.
void setTransitions() override; void setTransitions() override;

View File

@ -62,18 +62,17 @@ void ReannotateFromPCBNew( SCH_EDIT_FRAME* aFrame, std::string& aNetlist )
BACK_ANNOTATE backAnno( aFrame, BACK_ANNOTATE backAnno( aFrame,
reporter, reporter,
false, //aRelinkFootprints false, // aRelinkFootprints
false, //aProcessFootprints false, // aProcessFootprints
false, //aProcessValues false, // aProcessValues
true, //aProcessReferences true, // aProcessReferences
false, //aProcessNetNames false, // aProcessNetNames
false ); //aDryRun false ); // aDryRun
if( !backAnno.BackAnnotateSymbols( aNetlist ) ) if( !backAnno.BackAnnotateSymbols( aNetlist ) )
{ {
aNetlist = _( "Errors reported by Eeschema:\n" ) aNetlist = _( "Errors reported by Eeschema:\n" ) + reporter.m_string.ToStdString();
+ reporter.m_string.ToStdString(); //Assume the worst aNetlist += _( "\nAnnotation not performed!\n" ); // Assume the worst
aNetlist += _( "\nAnnotation not performed!\n" );
} }
else else
{ {

View File

@ -70,7 +70,7 @@ bool SCH_DRAWING_TOOLS::Init()
return m_frame->GetCurrentSheet().Last() != &m_frame->Schematic().Root(); return m_frame->GetCurrentSheet().Last() != &m_frame->Schematic().Root();
}; };
auto& ctxMenu = m_menu.GetMenu(); CONDITIONAL_MENU& ctxMenu = m_menu.GetMenu();
ctxMenu.AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition, 2 ); ctxMenu.AddItem( EE_ACTIONS::leaveSheet, belowRootSheetCondition, 2 );
return true; return true;
@ -126,7 +126,8 @@ int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent )
auto setCursor = auto setCursor =
[&]() [&]()
{ {
m_frame->GetCanvas()->SetCurrentCursor( component ? KICURSOR::MOVING : KICURSOR::COMPONENT ); m_frame->GetCanvas()->SetCurrentCursor( component ? KICURSOR::MOVING
: KICURSOR::COMPONENT );
}; };
// Set initial cursor // Set initial cursor
@ -293,7 +294,9 @@ int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent )
m_view->AddToPreview( component->Clone() ); m_view->AddToPreview( component->Clone() );
} }
else else
{
evt->SetPassEvent(); evt->SetPassEvent();
}
// Enable autopanning and cursor capture only when there is a footprint to be placed // Enable autopanning and cursor capture only when there is a footprint to be placed
getViewControls()->SetAutoPan( component != nullptr ); getViewControls()->SetAutoPan( component != nullptr );
@ -399,7 +402,8 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
{ {
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
wxFileDialog dlg( m_frame, _( "Choose Image" ), wxEmptyString, wxEmptyString, wxFileDialog dlg( m_frame, _( "Choose Image" ), wxEmptyString, wxEmptyString,
_( "Image Files" ) + wxS( " " ) + wxImage::GetImageExtWildcard(), wxFD_OPEN ); _( "Image Files" ) + wxS( " " ) + wxImage::GetImageExtWildcard(),
wxFD_OPEN );
if( dlg.ShowModal() != wxID_OK ) if( dlg.ShowModal() != wxID_OK )
continue; continue;
@ -464,7 +468,9 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
m_view->RecacheAllItems(); // Bitmaps are cached in Opengl m_view->RecacheAllItems(); // Bitmaps are cached in Opengl
} }
else else
{
evt->SetPassEvent(); evt->SetPassEvent();
}
// Enable autopanning and cursor capture only when there is a footprint to be placed // Enable autopanning and cursor capture only when there is a footprint to be placed
getViewControls()->SetAutoPan( image != nullptr ); getViewControls()->SetAutoPan( image != nullptr );

View File

@ -206,26 +206,10 @@ bool SCH_EDIT_TOOL::Init()
if( aSel.GetSize() == 0 ) if( aSel.GetSize() == 0 )
return true; // Show worksheet properties return true; // Show worksheet properties
SCH_ITEM* firstItem = dynamic_cast<SCH_ITEM*>( aSel.Front() ); SCH_ITEM* firstItem = dynamic_cast<SCH_ITEM*>( aSel.Front() );
wxCHECK( firstItem, false );
const EE_SELECTION* eeSelection = dynamic_cast<const EE_SELECTION*>( &aSel ); const EE_SELECTION* eeSelection = dynamic_cast<const EE_SELECTION*>( &aSel );
wxCHECK( eeSelection, false ); wxCHECK( firstItem, false );
if( aSel.GetSize() != 1
&& !( aSel.GetSize() >= 1
&& ( firstItem->Type() == SCH_LINE_T
|| firstItem->Type() == SCH_BUS_WIRE_ENTRY_T )
&& eeSelection->AllItemsHaveLineStroke() ) )
return false;
if( aSel.GetSize() != 1
&& !( aSel.GetSize() >= 1
&& ( firstItem->Type() == SCH_JUNCTION_T )
&& eeSelection->AreAllItemsIdentical() ) )
return false;
switch( firstItem->Type() ) switch( firstItem->Type() )
{ {
@ -242,18 +226,10 @@ bool SCH_EDIT_TOOL::Init()
case SCH_LINE_T: case SCH_LINE_T:
case SCH_BUS_WIRE_ENTRY_T: case SCH_BUS_WIRE_ENTRY_T:
for( EDA_ITEM* item : aSel.GetItems() ) return eeSelection->AllItemsHaveLineStroke();
{
SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( item );
if( !schItem || !schItem->HasLineStroke() )
return false;
}
return true;
case SCH_JUNCTION_T: case SCH_JUNCTION_T:
return true; return eeSelection->AreAllItemsIdentical();
default: default:
return false; return false;
@ -1073,64 +1049,64 @@ int SCH_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
picker->SetCursor( KICURSOR::REMOVE ); picker->SetCursor( KICURSOR::REMOVE );
picker->SetClickHandler( picker->SetClickHandler(
[this] ( const VECTOR2D& aPosition ) -> bool [this]( const VECTOR2D& aPosition ) -> bool
{
if( m_pickerItem )
{ {
SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( m_pickerItem ); if( m_pickerItem )
if( sch_item && sch_item->IsLocked() )
{ {
STATUS_TEXT_POPUP statusPopup( m_frame ); SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( m_pickerItem );
statusPopup.SetText( _( "Item locked." ) );
statusPopup.PopupFor( 2000 ); if( sch_item && sch_item->IsLocked() )
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) ); {
return true; STATUS_TEXT_POPUP statusPopup( m_frame );
statusPopup.SetText( _( "Item locked." ) );
statusPopup.PopupFor( 2000 );
statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
return true;
}
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
selectionTool->UnbrightenItem( m_pickerItem );
selectionTool->AddItemToSel( m_pickerItem, true /*quiet mode*/ );
m_toolMgr->RunAction( ACTIONS::doDelete, true );
m_pickerItem = nullptr;
} }
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>(); return true;
selectionTool->UnbrightenItem( m_pickerItem ); } );
selectionTool->AddItemToSel( m_pickerItem, true /*quiet mode*/ );
m_toolMgr->RunAction( ACTIONS::doDelete, true );
m_pickerItem = nullptr;
}
return true;
} );
picker->SetMotionHandler( picker->SetMotionHandler(
[this] ( const VECTOR2D& aPos ) [this]( const VECTOR2D& aPos )
{
EE_COLLECTOR collector;
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
collector.Collect( m_frame->GetScreen(), deletableItems, (wxPoint) aPos );
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
selectionTool->GuessSelectionCandidates( collector, aPos );
EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
if( m_pickerItem != item )
{ {
if( m_pickerItem ) EE_COLLECTOR collector;
selectionTool->UnbrightenItem( m_pickerItem ); collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
collector.Collect( m_frame->GetScreen(), deletableItems, (wxPoint) aPos );
m_pickerItem = item; EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
selectionTool->GuessSelectionCandidates( collector, aPos );
if( m_pickerItem ) EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
selectionTool->BrightenItem( m_pickerItem );
} if( m_pickerItem != item )
} ); {
if( m_pickerItem )
selectionTool->UnbrightenItem( m_pickerItem );
m_pickerItem = item;
if( m_pickerItem )
selectionTool->BrightenItem( m_pickerItem );
}
} );
picker->SetFinalizeHandler( picker->SetFinalizeHandler(
[this] ( const int& aFinalState ) [this]( const int& aFinalState )
{ {
if( m_pickerItem ) if( m_pickerItem )
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem ); m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
// Wake the selection tool after exiting to ensure the cursor gets updated // Wake the selection tool after exiting to ensure the cursor gets updated
m_toolMgr->RunAction( EE_ACTIONS::selectionActivate, false ); m_toolMgr->RunAction( EE_ACTIONS::selectionActivate, false );
} ); } );
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );

View File

@ -245,19 +245,20 @@ int SCH_EDITOR_CONTROL::UpdateFind( const TOOL_EVENT& aEvent )
{ {
wxFindReplaceData* data = m_frame->GetFindReplaceData(); wxFindReplaceData* data = m_frame->GetFindReplaceData();
auto visit = [&]( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheet ) auto visit =
{ [&]( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheet )
if( data && aItem->Matches( *data, aSheet ) ) {
{ if( data && aItem->Matches( *data, aSheet ) )
aItem->SetForceVisible( true ); {
m_selectionTool->BrightenItem( aItem ); aItem->SetForceVisible( true );
} m_selectionTool->BrightenItem( aItem );
else if( aItem->IsBrightened() ) }
{ else if( aItem->IsBrightened() )
aItem->SetForceVisible( false ); {
m_selectionTool->UnbrightenItem( aItem ); aItem->SetForceVisible( false );
} m_selectionTool->UnbrightenItem( aItem );
}; }
};
if( aEvent.IsAction( &ACTIONS::find ) || aEvent.IsAction( &ACTIONS::findAndReplace ) if( aEvent.IsAction( &ACTIONS::find ) || aEvent.IsAction( &ACTIONS::findAndReplace )
|| aEvent.IsAction( &ACTIONS::updateFind ) ) || aEvent.IsAction( &ACTIONS::updateFind ) )
@ -377,8 +378,8 @@ int SCH_EDITOR_CONTROL::FindNext( const TOOL_EVENT& aEvent )
} }
bool searchAllSheets = !( data->GetFlags() & FR_CURRENT_SHEET_ONLY ); bool searchAllSheets = !( data->GetFlags() & FR_CURRENT_SHEET_ONLY );
EE_SELECTION& selection = m_selectionTool->GetSelection(); EE_SELECTION& selection = m_selectionTool->GetSelection();
SCH_SCREEN* afterScreen = m_frame->GetScreen(); SCH_SCREEN* afterScreen = m_frame->GetScreen();
SCH_ITEM* afterItem = dynamic_cast<SCH_ITEM*>( selection.Front() ); SCH_ITEM* afterItem = dynamic_cast<SCH_ITEM*>( selection.Front() );
SCH_ITEM* item = nullptr; SCH_ITEM* item = nullptr;
@ -618,107 +619,107 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
picker->SetCursor( KICURSOR::VOLTAGE_PROBE ); picker->SetCursor( KICURSOR::VOLTAGE_PROBE );
picker->SetClickHandler( picker->SetClickHandler(
[this, simFrame] ( const VECTOR2D& aPosition ) [this, simFrame]( const VECTOR2D& aPosition )
{
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
EDA_ITEM* item = nullptr;
selTool->SelectPoint( aPosition, wiresAndPins, &item );
if( !item )
return false;
if( item->IsType( wires ) )
{ {
if( SCH_CONNECTION* conn = static_cast<SCH_ITEM*>( item )->Connection() ) EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
simFrame->AddVoltagePlot( UnescapeString( conn->Name() ) ); EDA_ITEM* item = nullptr;
} selTool->SelectPoint( aPosition, wiresAndPins, &item );
else if( item->Type() == SCH_PIN_T )
{
SCH_PIN* pin = (SCH_PIN*) item;
SCH_COMPONENT* comp = (SCH_COMPONENT*) item->GetParent();
wxString param;
wxString primitive;
primitive = NETLIST_EXPORTER_PSPICE::GetSpiceField( SF_PRIMITIVE, comp, 0 ); if( !item )
primitive.LowerCase(); return false;
if( primitive == "c" || primitive == "l" || primitive == "r" ) if( item->IsType( wires ) )
param = wxT( "I" ); {
else if( primitive == "d" ) if( SCH_CONNECTION* conn = static_cast<SCH_ITEM*>( item )->Connection() )
param = wxT( "Id" ); simFrame->AddVoltagePlot( UnescapeString( conn->Name() ) );
else }
param = wxString::Format( wxT( "I%s" ), pin->GetName().Lower() ); else if( item->Type() == SCH_PIN_T )
{
SCH_PIN* pin = (SCH_PIN*) item;
SCH_COMPONENT* comp = (SCH_COMPONENT*) item->GetParent();
wxString param;
wxString primitive;
simFrame->AddCurrentPlot( comp->GetRef( &m_frame->GetCurrentSheet() ), param ); primitive = NETLIST_EXPORTER_PSPICE::GetSpiceField( SF_PRIMITIVE, comp, 0 );
} primitive.LowerCase();
return true; if( primitive == "c" || primitive == "l" || primitive == "r" )
} ); param = wxT( "I" );
else if( primitive == "d" )
param = wxT( "Id" );
else
param = wxString::Format( wxT( "I%s" ), pin->GetName().Lower() );
simFrame->AddCurrentPlot( comp->GetRef( &m_frame->GetCurrentSheet() ), param );
}
return true;
} );
picker->SetMotionHandler( picker->SetMotionHandler(
[this, picker] ( const VECTOR2D& aPos ) [this, picker]( const VECTOR2D& aPos )
{
EE_COLLECTOR collector;
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
collector.Collect( m_frame->GetScreen(), wiresAndPins, (wxPoint) aPos );
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
selectionTool->GuessSelectionCandidates( collector, aPos );
EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
SCH_LINE* wire = dynamic_cast<SCH_LINE*>( item );
const SCH_CONNECTION* conn = nullptr;
if( wire )
{ {
item = nullptr; EE_COLLECTOR collector;
conn = wire->Connection(); collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
} collector.Collect( m_frame->GetScreen(), wiresAndPins, (wxPoint) aPos );
if( item && item->Type() == SCH_PIN_T ) EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
picker->SetCursor( KICURSOR::CURRENT_PROBE ); selectionTool->GuessSelectionCandidates( collector, aPos );
else
picker->SetCursor( KICURSOR::VOLTAGE_PROBE );
if( m_pickerItem != item ) EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
{ SCH_LINE* wire = dynamic_cast<SCH_LINE*>( item );
if( m_pickerItem ) const SCH_CONNECTION* conn = nullptr;
selectionTool->UnbrightenItem( m_pickerItem );
m_pickerItem = item; if( wire )
{
item = nullptr;
conn = wire->Connection();
}
if( m_pickerItem ) if( item && item->Type() == SCH_PIN_T )
selectionTool->BrightenItem( m_pickerItem ); picker->SetCursor( KICURSOR::CURRENT_PROBE );
} else
picker->SetCursor( KICURSOR::VOLTAGE_PROBE );
if( m_frame->GetHighlightedConnection() != conn ) if( m_pickerItem != item )
{ {
m_frame->SetHighlightedConnection( conn );
TOOL_EVENT dummyEvent; if( m_pickerItem )
UpdateNetHighlighting( dummyEvent ); selectionTool->UnbrightenItem( m_pickerItem );
}
} ); m_pickerItem = item;
if( m_pickerItem )
selectionTool->BrightenItem( m_pickerItem );
}
if( m_frame->GetHighlightedConnection() != conn )
{
m_frame->SetHighlightedConnection( conn );
TOOL_EVENT dummyEvent;
UpdateNetHighlighting( dummyEvent );
}
} );
picker->SetFinalizeHandler( picker->SetFinalizeHandler(
[this] ( const int& aFinalState ) [this]( const int& aFinalState )
{
if( m_pickerItem )
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
if( m_frame->GetHighlightedConnection() )
{ {
m_frame->SetHighlightedConnection( nullptr ); if( m_pickerItem )
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
TOOL_EVENT dummyEvent; if( m_frame->GetHighlightedConnection() )
UpdateNetHighlighting( dummyEvent ); {
} m_frame->SetHighlightedConnection( nullptr );
// Wake the selection tool after exiting to ensure the cursor gets updated TOOL_EVENT dummyEvent;
m_toolMgr->RunAction( EE_ACTIONS::selectionActivate, false ); UpdateNetHighlighting( dummyEvent );
} ); }
// Wake the selection tool after exiting to ensure the cursor gets updated
m_toolMgr->RunAction( EE_ACTIONS::selectionActivate, false );
} );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
@ -737,65 +738,65 @@ int SCH_EDITOR_CONTROL::SimTune( const TOOL_EVENT& aEvent )
picker->SetCursor( KICURSOR::TUNE ); picker->SetCursor( KICURSOR::TUNE );
picker->SetClickHandler( picker->SetClickHandler(
[this] ( const VECTOR2D& aPosition ) [this]( const VECTOR2D& aPosition )
{
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
EDA_ITEM* item;
selTool->SelectPoint( aPosition, fieldsAndComponents, &item );
if( !item )
return false;
if( item->Type() != SCH_COMPONENT_T )
{ {
item = item->GetParent(); EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
EDA_ITEM* item;
selTool->SelectPoint( aPosition, fieldsAndComponents, &item );
if( !item )
return false;
if( item->Type() != SCH_COMPONENT_T ) if( item->Type() != SCH_COMPONENT_T )
return false; {
} item = item->GetParent();
SIM_PLOT_FRAME* simFrame = if( item->Type() != SCH_COMPONENT_T )
(SIM_PLOT_FRAME*) m_frame->Kiway().Player( FRAME_SIMULATOR, false ); return false;
}
if( simFrame ) SIM_PLOT_FRAME* simFrame =
simFrame->AddTuner( static_cast<SCH_COMPONENT*>( item ) ); (SIM_PLOT_FRAME*) m_frame->Kiway().Player( FRAME_SIMULATOR, false );
return true; if( simFrame )
} ); simFrame->AddTuner( static_cast<SCH_COMPONENT*>( item ) );
return true;
} );
picker->SetMotionHandler( picker->SetMotionHandler(
[this] ( const VECTOR2D& aPos ) [this]( const VECTOR2D& aPos )
{
EE_COLLECTOR collector;
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
collector.Collect( m_frame->GetScreen(), fieldsAndComponents, (wxPoint) aPos );
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
selectionTool->GuessSelectionCandidates( collector, aPos );
EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
if( m_pickerItem != item )
{ {
if( m_pickerItem ) EE_COLLECTOR collector;
selectionTool->UnbrightenItem( m_pickerItem ); collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
collector.Collect( m_frame->GetScreen(), fieldsAndComponents, (wxPoint) aPos );
m_pickerItem = item; EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
selectionTool->GuessSelectionCandidates( collector, aPos );
if( m_pickerItem ) EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
selectionTool->BrightenItem( m_pickerItem );
} if( m_pickerItem != item )
} ); {
if( m_pickerItem )
selectionTool->UnbrightenItem( m_pickerItem );
m_pickerItem = item;
if( m_pickerItem )
selectionTool->BrightenItem( m_pickerItem );
}
} );
picker->SetFinalizeHandler( picker->SetFinalizeHandler(
[this] ( const int& aFinalState ) [this]( const int& aFinalState )
{ {
if( m_pickerItem ) if( m_pickerItem )
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem ); m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
// Wake the selection tool after exiting to ensure the cursor gets updated // Wake the selection tool after exiting to ensure the cursor gets updated
m_toolMgr->RunAction( EE_ACTIONS::selectionActivate, false ); m_toolMgr->RunAction( EE_ACTIONS::selectionActivate, false );
} ); } );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool ); m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
@ -844,7 +845,9 @@ static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition )
conn = pins[0]->Connection(); conn = pins[0]->Connection();
} }
else else
{
conn = item->Connection(); conn = item->Connection();
}
} }
} }
} }
@ -956,9 +959,7 @@ int SCH_EDITOR_CONTROL::AssignNetclass( const TOOL_EVENT& aEvent )
NETCLASSPTR newNetclass = netSettings.m_NetClasses.Find( netclassName ); NETCLASSPTR newNetclass = netSettings.m_NetClasses.Find( netclassName );
if( newNetclass ) if( newNetclass )
{
newNetclass->Add( netName ); newNetclass->Add( netName );
}
netSettings.m_NetClassAssignments[ netName ] = netclassName; netSettings.m_NetClassAssignments[ netName ] = netclassName;
netSettings.ResolveNetClassAssignments(); netSettings.ResolveNetClassAssignments();

View File

@ -182,14 +182,18 @@ bool SCH_LINE_WIRE_BUS_TOOL::Init()
{ {
EE_TOOL_BASE::Init(); EE_TOOL_BASE::Init();
auto wireOrBusTool = [ this ] ( const SELECTION& aSel ) { auto wireOrBusTool =
return ( m_frame->IsCurrentTool( EE_ACTIONS::drawWire ) [this]( const SELECTION& aSel )
|| m_frame->IsCurrentTool( EE_ACTIONS::drawBus ) ); {
}; return ( m_frame->IsCurrentTool( EE_ACTIONS::drawWire )
|| m_frame->IsCurrentTool( EE_ACTIONS::drawBus ) );
};
auto lineTool = [ this ] ( const SELECTION& aSel ) { auto lineTool =
return ( m_frame->IsCurrentTool( EE_ACTIONS::drawLines ) ); [this]( const SELECTION& aSel )
}; {
return m_frame->IsCurrentTool( EE_ACTIONS::drawLines );
};
auto belowRootSheetCondition = auto belowRootSheetCondition =
[&]( const SELECTION& aSel ) [&]( const SELECTION& aSel )
@ -386,9 +390,9 @@ const SCH_SHEET_PIN* SCH_LINE_WIRE_BUS_TOOL::getSheetPin( const wxPoint& aPositi
{ {
SCH_SCREEN* screen = m_frame->GetScreen(); SCH_SCREEN* screen = m_frame->GetScreen();
for( auto item : screen->Items().Overlapping( SCH_SHEET_T, aPosition ) ) for( SCH_ITEM* item : screen->Items().Overlapping( SCH_SHEET_T, aPosition ) )
{ {
auto sheet = static_cast<SCH_SHEET*>( item ); SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
for( SCH_SHEET_PIN* pin : sheet->GetPins() ) for( SCH_SHEET_PIN* pin : sheet->GetPins() )
{ {
@ -405,7 +409,7 @@ void SCH_LINE_WIRE_BUS_TOOL::computeBreakPoint( const std::pair<SCH_LINE*, SCH_L
wxPoint& aPosition ) wxPoint& aPosition )
{ {
wxCHECK_RET( aSegments.first && aSegments.second, wxCHECK_RET( aSegments.first && aSegments.second,
wxT( "Cannot compute break point of NULL line segment." ) ); wxT( "Cannot compute break point of NULL line segment." ) );
SCH_LINE* segment = aSegments.first; SCH_LINE* segment = aSegments.first;
SCH_LINE* next_segment = aSegments.second; SCH_LINE* next_segment = aSegments.second;
@ -415,7 +419,7 @@ void SCH_LINE_WIRE_BUS_TOOL::computeBreakPoint( const std::pair<SCH_LINE*, SCH_L
int iDy = segment->GetEndPoint().y - segment->GetStartPoint().y; int iDy = segment->GetEndPoint().y - segment->GetStartPoint().y;
const SCH_SHEET_PIN* connectedPin = getSheetPin( segment->GetStartPoint() ); const SCH_SHEET_PIN* connectedPin = getSheetPin( segment->GetStartPoint() );
auto force = connectedPin ? connectedPin->GetEdge() : SHEET_UNDEFINED_SIDE; SHEET_SIDE force = connectedPin ? connectedPin->GetEdge() : SHEET_UNDEFINED_SIDE;
if( force == SHEET_LEFT_SIDE || force == SHEET_RIGHT_SIDE ) if( force == SHEET_LEFT_SIDE || force == SHEET_RIGHT_SIDE )
{ {
@ -701,7 +705,7 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const std::string& aTool, int aType,
segment->SetEndPoint( cursorPos ); segment->SetEndPoint( cursorPos );
} }
for( auto wire : m_wires ) for( SCH_LINE* wire : m_wires )
{ {
if( !wire->IsNull() ) if( !wire->IsNull() )
m_view->AddToPreview( wire->Clone() ); m_view->AddToPreview( wire->Clone() );
@ -752,15 +756,9 @@ SCH_LINE* SCH_LINE_WIRE_BUS_TOOL::startSegments( int aType, const VECTOR2D& aPos
switch ( aType ) switch ( aType )
{ {
default: default: segment = new SCH_LINE( aPos, LAYER_NOTES ); break;
segment = new SCH_LINE( aPos, LAYER_NOTES ); case LAYER_WIRE: segment = new SCH_LINE( aPos, LAYER_WIRE ); break;
break; case LAYER_BUS: segment = new SCH_LINE( aPos, LAYER_BUS ); break;
case LAYER_WIRE:
segment = new SCH_LINE( aPos, LAYER_WIRE );
break;
case LAYER_BUS:
segment = new SCH_LINE( aPos, LAYER_BUS );
break;
} }
// Give segments a parent so they find the default line/wire/bus widths // Give segments a parent so they find the default line/wire/bus widths
@ -850,7 +848,7 @@ void SCH_LINE_WIRE_BUS_TOOL::finishSegments()
std::vector< wxPoint > new_ends; std::vector< wxPoint > new_ends;
// Check each new segment for possible junctions and add/split if needed // Check each new segment for possible junctions and add/split if needed
for( auto wire : m_wires ) for( SCH_LINE* wire : m_wires )
{ {
if( wire->HasFlag( SKIP_STRUCT ) ) if( wire->HasFlag( SKIP_STRUCT ) )
continue; continue;
@ -859,10 +857,10 @@ void SCH_LINE_WIRE_BUS_TOOL::finishSegments()
new_ends.insert( new_ends.end(), tmpends.begin(), tmpends.end() ); new_ends.insert( new_ends.end(), tmpends.begin(), tmpends.end() );
for( auto i : connections ) for( const wxPoint& pt : connections )
{ {
if( IsPointOnSegment( wire->GetStartPoint(), wire->GetEndPoint(), i ) ) if( IsPointOnSegment( wire->GetStartPoint(), wire->GetEndPoint(), pt ) )
new_ends.push_back( i ); new_ends.push_back( pt );
} }
itemList.PushItem( ITEM_PICKER( screen, wire, UNDO_REDO::NEWITEM ) ); itemList.PushItem( ITEM_PICKER( screen, wire, UNDO_REDO::NEWITEM ) );
} }
@ -881,7 +879,7 @@ void SCH_LINE_WIRE_BUS_TOOL::finishSegments()
m_frame->SaveCopyForRepeatItem( m_wires.back() ); m_frame->SaveCopyForRepeatItem( m_wires.back() );
// Add the new wires // Add the new wires
for( auto wire : m_wires ) for( SCH_LINE* wire : m_wires )
{ {
wire->ClearFlags( IS_NEW | IS_MOVED ); wire->ClearFlags( IS_NEW | IS_MOVED );
m_frame->AddToScreen( wire, screen ); m_frame->AddToScreen( wire, screen );
@ -899,24 +897,24 @@ void SCH_LINE_WIRE_BUS_TOOL::finishSegments()
// Correct and remove segments that need to be merged. // Correct and remove segments that need to be merged.
m_frame->SchematicCleanUp(); m_frame->SchematicCleanUp();
for( auto item : m_frame->GetScreen()->Items().OfType( SCH_COMPONENT_T ) ) for( SCH_ITEM* item : m_frame->GetScreen()->Items().OfType( SCH_COMPONENT_T ) )
{ {
std::vector< wxPoint > pts = item->GetConnectionPoints(); std::vector<wxPoint> pts = item->GetConnectionPoints();
if( pts.size() > 2 ) if( pts.size() > 2 )
continue; continue;
for( auto i = pts.begin(); i != pts.end(); i++ ) for( auto pt = pts.begin(); pt != pts.end(); pt++ )
{ {
for( auto j = i + 1; j != pts.end(); j++ ) for( auto secondPt = pt + 1; secondPt != pts.end(); secondPt++ )
m_frame->TrimWire( *i, *j ); m_frame->TrimWire( *pt, *secondPt );
} }
} }
for( auto i : new_ends ) for( const wxPoint& pt : new_ends )
{ {
if( m_frame->GetScreen()->IsJunctionNeeded( i, true ) ) if( m_frame->GetScreen()->IsJunctionNeeded( pt, true ) )
m_frame->AddJunction( m_frame->GetScreen(), i, true, false ); m_frame->AddJunction( m_frame->GetScreen(), pt, true, false );
} }
if( m_busUnfold.in_progress ) if( m_busUnfold.in_progress )
@ -938,7 +936,7 @@ int SCH_LINE_WIRE_BUS_TOOL::AddJunctionsIfNeeded( const TOOL_EVENT& aEvent )
for( unsigned ii = 0; ii < aSelection->GetSize(); ii++ ) for( unsigned ii = 0; ii < aSelection->GetSize(); ii++ )
{ {
SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aSelection->GetItem( ii ) ); SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aSelection->GetItem( ii ) );
if( !item || !item->IsConnectable() ) if( !item || !item->IsConnectable() )
continue; continue;
@ -951,31 +949,34 @@ int SCH_LINE_WIRE_BUS_TOOL::AddJunctionsIfNeeded( const TOOL_EVENT& aEvent )
if( item->Type() == SCH_LINE_T ) if( item->Type() == SCH_LINE_T )
{ {
SCH_LINE* line = (SCH_LINE*) item; SCH_LINE* line = (SCH_LINE*) item;
for( auto i : connections )
for( const wxPoint& pt : connections )
{ {
if( IsPointOnSegment( line->GetStartPoint(), line->GetEndPoint(), i ) ) if( IsPointOnSegment( line->GetStartPoint(), line->GetEndPoint(), pt ) )
pts.push_back( i ); pts.push_back( pt );
} }
} }
else else
{ {
// Clean up any wires that short non-wire connections in the list // Clean up any wires that short non-wire connections in the list
for( auto point = new_pts.begin(); point != new_pts.end(); point++ ) for( auto pt = new_pts.begin(); pt != new_pts.end(); pt++ )
{ {
for( auto second_point = point + 1; second_point != new_pts.end(); second_point++ ) for( auto secondPt = pt + 1; secondPt != new_pts.end(); secondPt++ )
m_frame->TrimWire( *point, *second_point ); m_frame->TrimWire( *pt, *secondPt );
} }
} }
} }
// We always have some overlapping connection points. Drop duplicates here // We always have some overlapping connection points. Drop duplicates here
std::sort( pts.begin(), pts.end(), []( const wxPoint& a, const wxPoint& b ) -> bool { std::sort( pts.begin(), pts.end(),
return a.x < b.x || ( a.x == b.x && a.y < b.y ); []( const wxPoint& a, const wxPoint& b ) -> bool
} ); {
return a.x < b.x || ( a.x == b.x && a.y < b.y );
} );
pts.erase( unique( pts.begin(), pts.end() ), pts.end() ); pts.erase( unique( pts.begin(), pts.end() ), pts.end() );
for( auto point : pts ) for( const wxPoint& point : pts )
{ {
if( m_frame->GetScreen()->IsJunctionNeeded( point, true ) ) if( m_frame->GetScreen()->IsJunctionNeeded( point, true ) )
m_frame->AddJunction( m_frame->GetScreen(), point, true, false ); m_frame->AddJunction( m_frame->GetScreen(), point, true, false );