81 const auto record = [&](
SCH_ITEM* item )
91 record(
static_cast<SCH_ITEM*
>( item ) );
101 std::vector<COLLISION_MARKER> markers;
106 markers.push_back( *marker );
111 if( markers.empty() && disconnections.empty() )
119 markers.size(), disconnections.size() );
124 COLOR4D baseColor( 1.0, 0.0, 0.0, 0.8 );
131 baseColor = themeColor;
134 double baseAlpha = baseColor.
a;
136 if( baseAlpha <= 0.0 )
139 double fillAlpha = std::clamp( baseAlpha * 0.35, 0.05, 1.0 );
140 double strokeAlpha = std::clamp( baseAlpha, 0.05, 1.0 );
147 int lineWidthPixels = 4;
150 lineWidthPixels = std::max( cfg->m_Selection.drag_net_collision_width, 1 );
152 double lineWidth =
m_view->ToWorld( lineWidthPixels );
154 if( lineWidth <= 0.0 )
160 m_overlay->Circle( marker.position, marker.radius );
164 m_overlay->Circle( marker.pointA, marker.radius );
165 m_overlay->Circle( marker.pointB, marker.radius );
193std::optional<SCH_DRAG_NET_COLLISION_MONITOR::COLLISION_MARKER>
201 std::optional<int> firstNet;
202 bool differentNets =
false;
203 bool movedNet =
false;
204 const auto accumulate = [&](
SCH_ITEM* item )
211 if( !item->IsConnected( position )
212 && !( item->Type() ==
SCH_LINE_T && item->HitTest( position ) ) )
217 if( firstNet && firstNet != found->second )
218 differentNets =
true;
220 firstNet = found->second;
221 movedNet |= item->IsSelected() || aSelection.
Contains( item )
222 || aSelection.
Contains( item->GetParent() );
224 const auto visit = [&](
SCH_ITEM* item )
230 for(
SCH_ITEM* candidate :
m_frame->GetScreen()->Items().Overlapping( position ) )
234 for(
EDA_ITEM* selected : aSelection )
235 visit(
static_cast<SCH_ITEM*
>( selected ) );
237 if( !movedNet || !differentNets )
249 std::optional<int> netCode;
253 if( connection->IsNet() && !connection->IsUnconnected() && connection->NetCode() > 0 )
254 netCode = connection->NetCode();
268 bool hasNewOrPastedItems =
false;
270 for(
EDA_ITEM* edaItem : aSelection )
272 if( edaItem->IsNew() || ( edaItem->GetFlags() &
IS_PASTED ) )
274 hasNewOrPastedItems =
true;
279 if( hasNewOrPastedItems )
282 "recordOriginalConnections: Skipping - selection contains new or pasted items" );
288 for(
EDA_ITEM* edaItem : aSelection )
306 if( !candidate->CanConnect( item ) )
309 if( !candidate->IsConnected( point )
310 && !( candidate->IsType( { SCH_LINE_T } ) && candidate->HitTest( point ) ) )
315 std::vector<VECTOR2I> candidatePoints = candidate->GetConnectionPoints();
316 size_t candidateIndex = std::numeric_limits<size_t>::max();
318 for(
size_t candidatePos = 0; candidatePos < candidatePoints.size(); ++candidatePos )
320 if( candidatePoints[candidatePos] == point )
322 candidateIndex = candidatePos;
327 if( candidateIndex == std::numeric_limits<size_t>::max() )
331 size_t firstIndex =
index;
333 size_t secondIndex = candidateIndex;
335 if( secondItem < firstItem || ( secondItem == firstItem && secondIndex < firstIndex ) )
337 std::swap( firstItem, secondItem );
338 std::swap( firstIndex, secondIndex );
341 if( firstItem == secondItem )
347 if( !firstSelected && !secondSelected )
353 return connection.itemA == firstItem && connection.indexA == firstIndex
354 && connection.itemB == secondItem && connection.indexB == secondIndex;
370std::vector<SCH_DRAG_NET_COLLISION_MONITOR::DISCONNECTION_MARKER>
373 std::vector<DISCONNECTION_MARKER> markers;
380 if( !itemA || !itemB )
389 if( connection.indexA >= pointsA.size() || connection.indexB >= pointsB.size() )
392 VECTOR2I pointA = pointsA[ connection.indexA ];
393 VECTOR2I pointB = pointsB[ connection.indexB ];
396 bool stillConnected = ( pointA == pointB );
399 if( !stillConnected && itemB->
IsType( { SCH_LINE_T } ) && itemB->
HitTest( pointA, 0 ) )
400 stillConnected =
true;
402 if( !stillConnected && itemA->
IsType( { SCH_LINE_T } ) && itemA->
HitTest( pointB, 0 ) )
403 stillConnected =
true;
414 double radius = std::max( { 800.0,
420 marker.pointB = pointB;
422 markers.push_back( marker );
425 if( !markers.empty() )
428 "collectDisconnectedMarkers: Identified %zu disconnections", markers.size() );
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
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
PREVIEW_NET_CODES CapturePreviewNetCodes(const FACADE &aFacade, const SCH_SHEET_PATH &aPath)
Owned local net assignments for advisory drag feedback; unavailable rows remain unknown.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
wxLogTrace helper definitions.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D