89 std::map<VECTOR2I, std::vector<SCH_LINE*>> positionToWires;
99 positionToWires[wire->
GetEndPoint()].push_back( wire );
102 return positionToWires;
115 const VECTOR2D& aGridSize,
const std::string& aTestName )
124 std::set<EDA_ITEM*> selectionSet( aSelection.begin(), aSelection.end() );
128 if( selectionSet.find( it ) == selectionSet.end() )
133 it->SetStoredPos( it->GetPosition() );
138 pin->SetStoredPos(
pin->GetPosition() );
153 auto it = positionToWires.find( aPoint );
155 if( it != positionToWires.end() )
165 if( std::find( aList.begin(), aList.end(), wire ) == aList.end() )
174 aList.push_back( wire );
184 std::set<VECTOR2I> pinPositions;
191 pinPositions.insert(
pin->GetPosition() );
195 bool allConnected =
true;
207 bool startConnected = pinPositions.count( start ) > 0;
208 bool endConnected = pinPositions.count(
end ) > 0;
210 if( !startConnected )
213 <<
") not connected to any pin" );
215 for(
const VECTOR2I& pinPos : pinPositions )
221 allConnected =
false;
227 <<
") not connected to any pin" );
229 for(
const VECTOR2I& pinPos : pinPositions )
235 allConnected =
false;
254 const VECTOR2D& aGridSize,
const std::string& aTestName )
256 std::set<EDA_ITEM*> selectionSet( aSelection.begin(), aSelection.end() );
259 std::map<SCH_LINE*, std::pair<VECTOR2I, VECTOR2I>> originalWireEndpoints;
270 std::map<VECTOR2I, std::vector<SCH_LINE*>> positionToWires =
275 if( selectionSet.find( it ) == selectionSet.end() )
280 it->SetStoredPos( it->GetPosition() );
285 pin->SetStoredPos(
pin->GetPosition() );
299 auto it = positionToWires.find( aPoint );
301 if( it != positionToWires.end() )
308 if( std::find( aList.begin(), aList.end(), wire ) == aList.end() )
317 aList.push_back( wire );
329 for(
const auto& [wire, origEndpoints] : originalWireEndpoints )
331 VECTOR2I origStart = origEndpoints.first;
332 VECTOR2I origEnd = origEndpoints.second;
333 VECTOR2I newStart = wire->GetStartPoint();
334 VECTOR2I newEnd = wire->GetEndPoint();
337 bool wasHorizontal = ( origStart.
y == origEnd.
y );
340 bool isHorizontal = ( newStart.
y == newEnd.
y );
342 if( wasHorizontal && !isHorizontal )
345 << origStart.
x <<
", " << origStart.
y <<
") to ("
346 << origEnd.
x <<
", " << origEnd.
y <<
"), Now: ("
347 << newStart.
x <<
", " << newStart.
y <<
") to ("
348 << newEnd.
x <<
", " << newEnd.
y <<
")" );
353 bool wasVertical = ( origStart.
x == origEnd.
x );
354 bool isVertical = ( newStart.
x == newEnd.
x );
356 if( wasVertical && !isVertical )
359 << origStart.
x <<
", " << origStart.
y <<
") to ("
360 << origEnd.
x <<
", " << origEnd.
y <<
"), Now: ("
361 << newStart.
x <<
", " << newStart.
y <<
") to ("
362 << newEnd.
x <<
", " << newEnd.
y <<
")" );
368 std::set<VECTOR2I> pinPositions;
375 pinPositions.insert(
pin->GetPosition() );
378 bool allConnected =
true;
380 for(
const auto& [wire, origEndpoints] : originalWireEndpoints )
382 VECTOR2I start = wire->GetStartPoint();
385 bool startConnected = pinPositions.count( start ) > 0;
386 bool endConnected = pinPositions.count(
end ) > 0;
388 if( !startConnected )
391 <<
") not connected to any pin" );
392 allConnected =
false;
398 <<
") not connected to any pin" );
399 allConnected =
false;
404 return noSkew && allConnected;
423 SCH_SCREEN* screen = m_schematic->RootScreen();
427 std::vector<EDA_ITEM*> selection;
430 selection.push_back( item );
432 BOOST_REQUIRE_EQUAL( selection.size(), 2 );
436 bool allConnected = RunAlignmentAndVerify( screen, selection, gridSize,
437 "AlignAllItemsStandardGrid" );
439 BOOST_CHECK_MESSAGE( allConnected,
"All wire endpoints should connect to pins after "
440 "aligning all items with 2.54mm grid" );
452 SCH_SCREEN* screen = m_schematic->RootScreen();
455 std::vector<EDA_ITEM*> selection;
458 selection.push_back( item );
462 bool allConnected = RunAlignmentAndVerify( screen, selection, gridSize,
463 "AlignAllItemsFineGrid" );
465 BOOST_CHECK_MESSAGE( allConnected,
"All wire endpoints should connect to pins after "
466 "aligning all items with 1.27mm grid" );
478 SCH_SCREEN* screen = m_schematic->RootScreen();
481 std::vector<EDA_ITEM*> selection;
484 selection.push_back( item );
488 bool allConnected = RunAlignmentAndVerify( screen, selection, gridSize,
489 "AlignAllItemsCoarseGrid" );
491 BOOST_CHECK_MESSAGE( allConnected,
"All wire endpoints should connect to pins after "
492 "aligning all items with 5.08mm grid" );
506 SCH_SCREEN* screen = m_schematic->RootScreen();
515 if( sheet->
GetName() ==
"sheet1" )
524 std::vector<EDA_ITEM*> selection{ sheet1 };
527 bool success = RunAlignmentAndVerifyNoSkew( screen, selection, gridSize,
"AlignSheet1Only" );
528 BOOST_CHECK_MESSAGE( success,
"Wires should remain straight and connected when aligning only sheet1" );
542 SCH_SCREEN* screen = m_schematic->RootScreen();
551 if( sheet->
GetName() ==
"sheet2" )
560 std::vector<EDA_ITEM*> selection{ sheet2 };
563 bool success = RunAlignmentAndVerifyNoSkew( screen, selection, gridSize,
"AlignSheet2Only" );
565 BOOST_CHECK_MESSAGE( success,
"Wires should remain straight and connected when aligning only sheet2" );
579 SCH_SCREEN* screen = m_schematic->RootScreen();
589 if( sheet->
GetName() ==
"sheet1" )
591 else if( sheet->
GetName() ==
"sheet2" )
601 std::vector<EDA_ITEM*> selection1{ sheet1 };
602 bool success1 = RunAlignmentAndVerifyNoSkew( screen, selection1, gridSize,
603 "AlignSheet1ThenSheet2 (step 1)" );
605 BOOST_CHECK_MESSAGE( success1,
"Wires should remain straight and connected after aligning sheet1" );
608 std::vector<EDA_ITEM*> selection2{ sheet2 };
609 bool success2 = RunAlignmentAndVerifyNoSkew( screen, selection2, gridSize,
610 "AlignSheet1ThenSheet2 (step 2)" );
612 BOOST_CHECK_MESSAGE( success2,
"Wires should remain straight and connected after aligning sheet2" );
626 SCH_SCREEN* screen = m_schematic->RootScreen();
636 if( sheet->
GetName() ==
"sheet1" )
638 else if( sheet->
GetName() ==
"sheet2" )
648 std::vector<EDA_ITEM*> selection2{ sheet2 };
649 bool success2 = RunAlignmentAndVerifyNoSkew( screen, selection2, gridSize,
650 "AlignSheet2ThenSheet1 (step 1)" );
652 BOOST_CHECK_MESSAGE( success2,
"Wires should remain straight and connected after aligning sheet2" );
655 std::vector<EDA_ITEM*> selection1{ sheet1 };
656 bool success1 = RunAlignmentAndVerifyNoSkew( screen, selection1, gridSize,
657 "AlignSheet2ThenSheet1 (step 2)" );
659 BOOST_CHECK_MESSAGE( success1,
"Wires should remain straight and connected after aligning sheet1" );
671 SCH_SCREEN* screen = m_schematic->RootScreen();
674 std::vector<EDA_ITEM*> selection;
677 selection.push_back( item );
680 std::vector<double> gridSizesMm = { 5.08, 2.54, 1.27, 0.635 };
682 for(
double gridMm : gridSizesMm )
686 screen = m_schematic->RootScreen();
690 selection.push_back( item );
694 std::stringstream testName;
695 testName <<
"AlignMultipleGridSizes (" << gridMm <<
"mm)";
697 bool allConnected = RunAlignmentAndVerify( screen, selection, gridSize, testName.str() );
699 BOOST_CHECK_MESSAGE( allConnected,
"All wire endpoints should connect to pins with "
700 << gridMm <<
"mm grid" );
713 SCH_SCREEN* screen = m_schematic->RootScreen();
716 std::vector<EDA_ITEM*> selection;
719 selection.push_back( item );
724 auto positionToWires = BuildPositionToWiresMap( screen );
731 static_cast<SCH_SHEET*
>( aItem )->Move( aDelta );
739 auto it = positionToWires.find( aPoint );
741 if( it != positionToWires.end() )
745 if( std::find( aList.begin(), aList.end(), wire ) == aList.end() )
754 aList.push_back( wire );
770 bool foundWire =
false;
786 BOOST_CHECK_MESSAGE( foundWire,
787 "Pin at (" << pinPos.
x <<
", " << pinPos.
y
788 <<
") should have a connected wire endpoint" );
804 SCH_SCREEN* screen = m_schematic->RootScreen();
808 std::vector<EDA_ITEM*> selection;
813 selection.push_back( item );
823 selection.push_back( wire );
827 BOOST_REQUIRE_GE( selection.size(), 4 );
831 bool allConnected = RunAlignmentAndVerify( screen, selection, gridSize,
832 "AlignSheetsAndWiresTogether" );
834 BOOST_CHECK_MESSAGE( allConnected,
835 "All wire endpoints should connect to pins after aligning "
836 "both sheets AND wires together (Select All scenario)" );
845 std::vector<double> gridSizesMm = { 5.08, 2.54, 1.27, 0.635 };
847 for(
double gridMm : gridSizesMm )
852 SCH_SCREEN* screen = m_schematic->RootScreen();
856 std::vector<EDA_ITEM*> selection;
861 selection.push_back( item );
871 selection.push_back( wire );
877 std::stringstream testName;
878 testName <<
"AlignSheetsAndWiresMultipleGrids (" << gridMm <<
"mm)";
880 bool allConnected = RunAlignmentAndVerify( screen, selection, gridSize, testName.str() );
882 BOOST_CHECK_MESSAGE( allConnected,
883 "All wire endpoints should connect to pins with "
884 << gridMm <<
"mm grid when sheets AND wires are selected" );
constexpr EDA_IU_SCALE schIUScale
A base class for most all the KiCad significant classes used in schematics and boards.
void SetFlags(EDA_ITEM_FLAGS aMask)
KICAD_T Type() const
Returns the type of object.
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
EE_TYPE OfType(KICAD_T aType) const
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
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.
Segment description base class to describe items which have 2 end points (track, wire,...
VECTOR2I GetEndPoint() const
VECTOR2I GetStartPoint() const
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
std::vector< SCH_SHEET_PIN * > & GetPins()
Helper class to test grid alignment with configurable grid size.
TEST_GRID_HELPER(const VECTOR2D &aGridSize)
VECTOR2D GetGridSize(GRID_HELPER_GRIDS aGrid) const override
Return the size of the specified grid.
#define SELECTED
Item was manually selected by the user.
#define ENDPOINT
ends. (Used to support dragging.)
#define STARTPOINT
When a line is selected, these flags indicate which.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
static void LoadSchematic(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const wxString &aFileName)
void MoveSchematicItem(EDA_ITEM *aItem, const VECTOR2I &aDelta)
Move a schematic item by a delta.
void AlignSchematicItemsToGrid(SCH_SCREEN *aScreen, const std::vector< EDA_ITEM * > &aItems, EE_GRID_HELPER &aGrid, GRID_HELPER_GRIDS aSelectionGrid, const SCH_ALIGNMENT_CALLBACKS &aCallbacks)
Align a set of schematic items to the grid.
std::vector< EDA_ITEM * > EDA_ITEMS
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
std::vector< FAB_LAYER_COLOR > dummy
std::unique_ptr< SCHEMATIC > m_schematic
std::map< VECTOR2I, std::vector< SCH_LINE * > > BuildPositionToWiresMap(SCH_SCREEN *aScreen)
Build a map of positions to connected wires for the callback.
SETTINGS_MANAGER m_settingsManager
bool RunAlignmentAndVerifyNoSkew(SCH_SCREEN *aScreen, const std::vector< EDA_ITEM * > &aSelection, const VECTOR2D &aGridSize, const std::string &aTestName)
Run alignment and verify that wires are not skewed.
bool RunAlignmentAndVerify(SCH_SCREEN *aScreen, std::vector< EDA_ITEM * > &aSelection, const VECTOR2D &aGridSize, const std::string &aTestName)
Run alignment on selected items and verify wire connectivity.
Callbacks for alignment operations.
std::function< void(SCH_ITEM *aItem, const VECTOR2I &aPoint, EDA_ITEMS &aList)> m_getConnectedDragItems
Callback to get items connected to a given item at a specific point.
std::function< void(EDA_ITEM *aItem, const VECTOR2I &aDelta)> m_doMoveItem
Callback to move an item by a delta.
BOOST_FIXTURE_TEST_CASE(BoardTypes, PROTO_TEST_FIXTURE)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_FIXTURE_TEST_CASE(AlignAllItemsStandardGrid, ISSUE22864_FIXTURE)
Test aligning all items with standard grid (2.54mm).
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D