43 std::function<void(
SCH_ITEM* )> changeHandler =
44 [&](
SCH_ITEM* aChangedItem ) ->
void
59 std::vector<SCH_LINE*> wires;
71 wires.push_back( line );
80 if( !
IsPointOnSegment( line->GetStartPoint(), line->GetEndPoint(), aStart ) ||
87 if( ( line->GetStartPoint() == aStart && line->GetEndPoint() == aEnd )
88 || ( line->GetStartPoint() == aEnd && line->GetEndPoint() == aStart ) )
96 BreakSegment( aCommit, line, aStart, &new_line, screen );
109 aCommit->
Removed( line, screen );
121 std::vector<SCH_LINE*> lines;
122 std::vector<SCH_JUNCTION*> junctions;
123 std::vector<SCH_NO_CONNECT*> ncs;
124 std::vector<SCH_ITEM*> items_to_remove;
127 if( aScreen ==
nullptr )
130 auto remove_item = [&](
SCH_ITEM* aItem ) ->
void
138 if( aItem->IsSelected() )
142 aCommit->
Removed( aItem, aScreen );
151 items_to_remove.push_back( item );
153 junctions.push_back(
static_cast<SCH_JUNCTION*
>( item ) );
156 for(
SCH_ITEM* item : items_to_remove )
165 if( ( aFirst->GetEditFlags() & STRUCT_DELETED )
166 || ( aSecond->GetEditFlags() & STRUCT_DELETED ) )
172 remove_item( aSecond );
178 if( ( aFirst->GetEditFlags() & STRUCT_DELETED )
179 || ( aSecond->GetEditFlags() & STRUCT_DELETED ) )
185 remove_item( aSecond );
191 return std::min( l->GetStartPoint().x, l->GetEndPoint().x );
196 return std::max( l->GetStartPoint().x, l->GetEndPoint().x );
201 return std::min( l->GetStartPoint().y, l->GetEndPoint().y );
206 return std::max( l->GetStartPoint().y, l->GetEndPoint().y );
219 lines.push_back(
static_cast<SCH_LINE*
>( item ) );
223 std::sort( lines.begin(), lines.end(),
226 return minX( a ) < minX( b );
229 for(
auto it1 = lines.begin(); it1 != lines.end(); ++it1 )
238 remove_item( firstLine );
242 int firstRightXEdge = maxX( firstLine );
245 for( ++it2; it2 != lines.end(); ++it2 )
248 int secondLeftXEdge = minX( secondLine );
251 if( secondLeftXEdge > firstRightXEdge )
255 if( !( std::max( minY( firstLine ), minY( secondLine ) )
256 <= std::min( maxY( firstLine ), maxY( secondLine ) ) ) )
275 remove_item( secondLine );
283 if( mergedLine !=
nullptr )
285 remove_item( firstLine );
286 remove_item( secondLine );
288 AddToScreen( mergedLine, aScreen );
289 aCommit->Added( mergedLine, aScreen );
292 selectionTool->AddItemToSel( mergedLine,
true );
306 aCommit->
Modify( aSegment, aScreen );
314 aCommit->
Added( newSegment, aScreen );
316 *aNewSegment = newSegment;
322 bool brokenSegments =
false;
327 BreakSegment( aCommit, wire, aPos, &new_line, aScreen );
328 brokenSegments =
true;
331 return brokenSegments;
337 bool brokenSegments =
false;
339 std::set<VECTOR2I> point_set;
342 point_set.insert( item->GetPosition() );
348 point_set.insert( entry->
GetEnd() );
351 for(
const VECTOR2I& pt : point_set )
354 brokenSegments =
true;
357 return brokenSegments;
369 aCommit->
Removed( aJunction, screen );
373 std::list<SCH_LINE*> lines;
383 lines.push_back( line );
390 if( ( firstLine->GetEditFlags() & STRUCT_DELETED )
391 || ( secondLine->GetEditFlags() & STRUCT_DELETED )
392 || !secondLine->IsParallel( firstLine ) )
401 firstLine->SetFlags( STRUCT_DELETED );
408 firstLine->SetFlags( STRUCT_DELETED );
409 secondLine->SetFlags( STRUCT_DELETED );
410 AddToScreen( new_line, screen );
411 aCommit->Added( new_line, screen );
413 if( new_line->IsSelected() )
414 selectionTool->AddItemToSel( new_line, true );
416 lines.push_back( new_line );
424 if( line->IsSelected() )
425 selectionTool->RemoveItemFromSel( line,
true );
427 RemoveFromScreen( line, screen );
428 aCommit->Removed( line, screen );
440 aCommit->
Added( junction, aScreen );
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
COMMIT & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
COMMIT & Removed(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Modify a given item in the model.
A base class for most all the KiCad significant classes used in schematics and boards.
virtual VECTOR2I GetPosition() const
EDA_ITEM_FLAGS GetEditFlags() const
void SetFlags(EDA_ITEM_FLAGS aMask)
EDA_ITEM_FLAGS GetFlags() const
EE_TYPE Overlapping(const BOX2I &aRect) const
EE_TYPE OfType(KICAD_T aType) const
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
A holder to handle information on schematic or board items.
void AddToScreen(EDA_ITEM *aItem, SCH_SCREEN *aScreen=nullptr)
Add an item to the screen (and view) aScreen is the screen the item is located on,...
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void RemoveFromScreen(EDA_ITEM *aItem, SCH_SCREEN *aScreen)
Remove an item from the screen (and view) aScreen is the screen the item is located on,...
VECTOR2I GetPosition() const override
Class for a wire to bus entry.
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
bool BreakSegmentsOnJunctions(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen)
Test all junctions and bus entries in the schematic for intersections with wires and buses and breaks...
void SchematicCleanUp(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen=nullptr)
Perform routine schematic cleaning including breaking wire and buses and deleting identical objects s...
bool BreakSegments(SCH_COMMIT *aCommit, const VECTOR2I &aPoint, SCH_SCREEN *aScreen)
Check every wire and bus for a intersection at aPoint and break into two segments at aPoint if an int...
void BreakSegment(SCH_COMMIT *aCommit, SCH_LINE *aSegment, const VECTOR2I &aPoint, SCH_LINE **aNewSegment, SCH_SCREEN *aScreen)
Break a single segment into two at the specified point.
bool TrimWire(SCH_COMMIT *aCommit, const VECTOR2I &aStart, const VECTOR2I &aEnd)
If any single wire passes through both points, remove the portion between the two points,...
void TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
void DeleteJunction(SCH_COMMIT *aCommit, SCH_ITEM *aItem)
Removes a given junction and heals any wire segments under the junction.
SCH_JUNCTION * AddJunction(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen, const VECTOR2I &aPos)
Base class for any item which can be embedded within the SCHEMATIC container class,...
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
VECTOR2I GetPosition() const override
Segment description base class to describe items which have 2 end points (track, wire,...
bool IsWire() const
Return true if the line is a wire.
bool IsParallel(const SCH_LINE *aLine) const
VECTOR2I GetEndPoint() const
VECTOR2I GetStartPoint() const
SCH_LINE * MergeOverlap(SCH_SCREEN *aScreen, SCH_LINE *aLine, bool aCheckJunctions)
Check line against aLine to see if it overlaps and merge if it does.
bool IsBus() const
Return true if the line is a bus.
bool IsEndPoint(const VECTOR2I &aPoint) const
bool IsStrokeEquivalent(const SCH_LINE *aLine)
SCH_LINE * BreakAt(const VECTOR2I &aPoint)
Break this segment into two at the specified point.
VECTOR2I GetPosition() const override
void TestDanglingEnds(const SCH_SHEET_PATH *aPath=nullptr, std::function< void(SCH_ITEM *)> *aChangedHandler=nullptr) const
Test all of the connectable objects in the schematic for unused connection points.
std::vector< SCH_LINE * > GetBusesAndWires(const VECTOR2I &aPosition, bool aIgnoreEndpoints=false) const
Return buses and wires passing through aPosition.
bool IsExplicitJunction(const VECTOR2I &aPosition) const
Indicates that a junction dot is necessary at the given location.
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
#define IS_CHANGED
Item was edited, and modified.
#define IS_NEW
New item, just created.
#define IS_BROKEN
Is a segment just broken by BreakSegment.
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
#define IS_MOVING
Item being moved.
@ REPAINT
Item needs to be redrawn.
void for_all_pairs(_InputIterator __first, _InputIterator __last, _Function __f)
Apply a function to every possible pair of elements of a sequence.
bool IsPointOnSegment(const VECTOR2I &aSegStart, const VECTOR2I &aSegEnd, const VECTOR2I &aTestPoint)
Test if aTestPoint is on line defined by aSegStart and aSegEnd.