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,7 +59,9 @@ bool LIB_DRAWING_TOOLS::Init()
{ {
EE_TOOL_BASE::Init(); EE_TOOL_BASE::Init();
auto isDrawingCondition = [] ( const SELECTION& aSel ) { auto isDrawingCondition =
[] ( const SELECTION& aSel )
{
LIB_ITEM* item = (LIB_ITEM*) aSel.Front(); LIB_ITEM* item = (LIB_ITEM*) aSel.Front();
return item && item->IsNew(); return item && item->IsNew();
}; };
@ -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 );
@ -476,8 +480,10 @@ 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 );
return 0; return 0;

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,7 +312,7 @@ 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 ) if( m_pickerItem )
{ {
@ -325,13 +327,14 @@ int LIB_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
} ); } );
picker->SetMotionHandler( picker->SetMotionHandler(
[this] ( const VECTOR2D& aPos ) [this]( const VECTOR2D& aPos )
{ {
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>(); EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
EE_COLLECTOR collector; EE_COLLECTOR collector;
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
collector.Collect( m_frame->GetScreen(), nonFields, (wxPoint) aPos, m_frame->GetUnit(), collector.Collect( m_frame->GetScreen(), nonFields, (wxPoint) aPos,
m_frame->GetConvert() ); m_frame->GetUnit(), m_frame->GetConvert() );
// Remove unselectable items // Remove unselectable items
for( int i = collector.GetCount() - 1; i >= 0; --i ) for( int i = collector.GetCount() - 1; i >= 0; --i )
@ -358,7 +361,7 @@ int LIB_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
} ); } );
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 );

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

@ -207,25 +207,9 @@ bool SCH_EDIT_TOOL::Init()
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,7 +1049,7 @@ 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 ) if( m_pickerItem )
{ {
@ -1099,7 +1075,7 @@ int SCH_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
} ); } );
picker->SetMotionHandler( picker->SetMotionHandler(
[this] ( const VECTOR2D& aPos ) [this]( const VECTOR2D& aPos )
{ {
EE_COLLECTOR collector; EE_COLLECTOR collector;
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
@ -1123,7 +1099,7 @@ int SCH_EDIT_TOOL::DeleteItemCursor( const TOOL_EVENT& aEvent )
} ); } );
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 );

View File

@ -245,7 +245,8 @@ 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 ) )
{ {
@ -618,7 +619,7 @@ 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>(); EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
EDA_ITEM* item = nullptr; EDA_ITEM* item = nullptr;
@ -656,7 +657,7 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
} ); } );
picker->SetMotionHandler( picker->SetMotionHandler(
[this, picker] ( const VECTOR2D& aPos ) [this, picker]( const VECTOR2D& aPos )
{ {
EE_COLLECTOR collector; EE_COLLECTOR collector;
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
@ -703,7 +704,7 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
} ); } );
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 );
@ -737,7 +738,7 @@ 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>(); EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
EDA_ITEM* item; EDA_ITEM* item;
@ -764,7 +765,7 @@ int SCH_EDITOR_CONTROL::SimTune( const TOOL_EVENT& aEvent )
} ); } );
picker->SetMotionHandler( picker->SetMotionHandler(
[this] ( const VECTOR2D& aPos ) [this]( const VECTOR2D& aPos )
{ {
EE_COLLECTOR collector; EE_COLLECTOR collector;
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) ); collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
@ -788,7 +789,7 @@ int SCH_EDITOR_CONTROL::SimTune( const TOOL_EVENT& aEvent )
} ); } );
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 );
@ -844,10 +845,12 @@ 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();
} }
} }
} }
}
if( !conn ) if( !conn )
{ {
@ -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,13 +182,17 @@ bool SCH_LINE_WIRE_BUS_TOOL::Init()
{ {
EE_TOOL_BASE::Init(); EE_TOOL_BASE::Init();
auto wireOrBusTool = [ this ] ( const SELECTION& aSel ) { auto wireOrBusTool =
[this]( const SELECTION& aSel )
{
return ( m_frame->IsCurrentTool( EE_ACTIONS::drawWire ) return ( m_frame->IsCurrentTool( EE_ACTIONS::drawWire )
|| m_frame->IsCurrentTool( EE_ACTIONS::drawBus ) ); || 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 =
@ -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() )
{ {
@ -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 )
@ -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(),
[]( const wxPoint& a, const wxPoint& b ) -> bool
{
return a.x < b.x || ( a.x == b.x && a.y < b.y ); 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 );