73 const auto record = [&](
SCH_ITEM* item )
83 record(
static_cast<SCH_ITEM*
>( item ) );
92 std::vector<COLLISION_MARKER> markers;
97 markers.push_back( *marker );
102 if( markers.empty() && disconnections.empty() )
110 markers.size(), disconnections.size() );
115 COLOR4D baseColor( 1.0, 0.0, 0.0, 0.8 );
122 baseColor = themeColor;
125 double baseAlpha = baseColor.
a;
127 if( baseAlpha <= 0.0 )
130 double fillAlpha = std::clamp( baseAlpha * 0.35, 0.05, 1.0 );
131 double strokeAlpha = std::clamp( baseAlpha, 0.05, 1.0 );
138 int lineWidthPixels = 4;
141 lineWidthPixels = std::max( cfg->m_Selection.drag_net_collision_width, 1 );
143 double lineWidth =
m_view->ToWorld( lineWidthPixels );
145 if( lineWidth <= 0.0 )
151 m_overlay->Circle( marker.position, marker.radius );
155 m_overlay->Circle( marker.pointA, marker.radius );
156 m_overlay->Circle( marker.pointB, marker.radius );
184std::optional<SCH_DRAG_NET_COLLISION_MONITOR::COLLISION_MARKER>
192 std::optional<int> firstNet;
193 bool differentNets =
false;
194 bool movedNet =
false;
195 const auto accumulate = [&](
SCH_ITEM* item )
202 if( !item->IsConnected( position )
203 && !( item->Type() ==
SCH_LINE_T && item->HitTest( position ) ) )
208 if( firstNet && firstNet != found->second )
209 differentNets =
true;
211 firstNet = found->second;
212 movedNet |= item->IsSelected() || aSelection.
Contains( item )
213 || aSelection.
Contains( item->GetParent() );
215 const auto visit = [&](
SCH_ITEM* item )
221 for(
SCH_ITEM* candidate :
m_frame->GetScreen()->Items().Overlapping( position ) )
225 for(
EDA_ITEM* selected : aSelection )
226 visit(
static_cast<SCH_ITEM*
>( selected ) );
228 if( !movedNet || !differentNets )
240 std::optional<int> netCode;
244 if( connection->IsNet() && !connection->IsUnconnected() && connection->NetCode() > 0 )
245 netCode = connection->NetCode();
259 bool hasNewOrPastedItems =
false;
261 for(
EDA_ITEM* edaItem : aSelection )
263 if( edaItem->IsNew() || ( edaItem->GetFlags() &
IS_PASTED ) )
265 hasNewOrPastedItems =
true;
270 if( hasNewOrPastedItems )
273 "recordOriginalConnections: Skipping - selection contains new or pasted items" );
279 for(
EDA_ITEM* edaItem : aSelection )
297 if( !candidate->CanConnect( item ) )
300 if( !candidate->IsConnected( point )
301 && !( candidate->IsType( { SCH_LINE_T } ) && candidate->HitTest( point ) ) )
306 std::vector<VECTOR2I> candidatePoints = candidate->GetConnectionPoints();
307 size_t candidateIndex = std::numeric_limits<size_t>::max();
309 for(
size_t candidatePos = 0; candidatePos < candidatePoints.size(); ++candidatePos )
311 if( candidatePoints[candidatePos] == point )
313 candidateIndex = candidatePos;
318 if( candidateIndex == std::numeric_limits<size_t>::max() )
322 size_t firstIndex =
index;
324 size_t secondIndex = candidateIndex;
326 if( secondItem < firstItem || ( secondItem == firstItem && secondIndex < firstIndex ) )
328 std::swap( firstItem, secondItem );
329 std::swap( firstIndex, secondIndex );
332 if( firstItem == secondItem )
338 if( !firstSelected && !secondSelected )
344 return connection.itemA == firstItem && connection.indexA == firstIndex
345 && connection.itemB == secondItem && connection.indexB == secondIndex;
361std::vector<SCH_DRAG_NET_COLLISION_MONITOR::DISCONNECTION_MARKER>
364 std::vector<DISCONNECTION_MARKER> markers;
371 if( !itemA || !itemB )
380 if( connection.indexA >= pointsA.size() || connection.indexB >= pointsB.size() )
383 VECTOR2I pointA = pointsA[ connection.indexA ];
384 VECTOR2I pointB = pointsB[ connection.indexB ];
387 bool stillConnected = ( pointA == pointB );
390 if( !stillConnected && itemB->
IsType( { SCH_LINE_T } ) && itemB->
HitTest( pointA, 0 ) )
391 stillConnected =
true;
393 if( !stillConnected && itemA->
IsType( { SCH_LINE_T } ) && itemA->
HitTest( pointB, 0 ) )
394 stillConnected =
true;
405 double radius = std::max( { 800.0,
411 marker.pointB = pointB;
413 markers.push_back( marker );
416 if( !markers.empty() )
419 "collectDisconnectedMarkers: Identified %zu disconnections", markers.size() );
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Color settings are a bit different than most of the settings objects in that there can be more than o...
A base class for most all the KiCad significant classes used in schematics and boards.
virtual bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const
Test if aPosition is inside or on the boundary of this item.
Implement an R-tree for fast spatial and type indexing of schematic items.
EE_TYPE Overlapping(const BOX2I &aRect) const
A color representation with 4 components: red, green, blue, alpha.
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
std::vector< ORIGINAL_CONNECTION > m_originalConnections
void recordItemNet(SCH_ITEM *aItem)
SCH_SHEET_PATH m_sheetPath
std::vector< DISCONNECTION_MARKER > collectDisconnectedMarkers(const SCH_SELECTION &aSelection) const
std::optional< COLLISION_MARKER > analyzeJunction(SCH_JUNCTION *aJunction, const SCH_SELECTION &aSelection) const
std::unordered_map< const SCH_ITEM *, std::optional< int > > m_itemNetCodes
bool Update(const std::vector< SCH_JUNCTION * > &aJunctions, const SCH_SELECTION &aSelection)
void recordOriginalConnections(const SCH_SELECTION &aSelection)
~SCH_DRAG_NET_COLLISION_MONITOR()
KICURSOR AdjustCursor(KICURSOR aBaseCursor) const
std::shared_ptr< KIGFX::VIEW_OVERLAY > m_overlay
SCH_DRAG_NET_COLLISION_MONITOR(SCH_EDIT_FRAME *aFrame, KIGFX::VIEW *aView)
void Initialize(const SCH_SELECTION &aSelection)
void clearOverlay() const
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
virtual bool IsConnectable() const
virtual int GetPenWidth() const
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
virtual std::vector< VECTOR2I > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
int GetEffectiveDiameter() const
VECTOR2I GetPosition() const override
virtual unsigned int GetSize() const override
Return the number of stored items.
bool Contains(EDA_ITEM *aItem) const
#define IS_PASTED
Modifier on IS_NEW which indicates it came from clipboard.
const wxChar *const traceSchDragNetCollision
Flag to enable debug output of schematic drag net collision detection.
@ LAYER_DRAG_NET_COLLISION
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
wxLogTrace helper definitions.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D