85 std::map<VECTOR2I, std::vector<SCH_LINE*>> positionToWires;
95 positionToWires[wire->
GetEndPoint()].push_back( wire );
98 return positionToWires;
111 const VECTOR2D& aGridSize,
const std::string& aTestName )
120 std::set<EDA_ITEM*> selectionSet( aSelection.begin(), aSelection.end() );
124 if( selectionSet.find( it ) == selectionSet.end() )
129 it->SetStoredPos( it->GetPosition() );
134 pin->SetStoredPos(
pin->GetPosition() );
149 auto it = positionToWires.find( aPoint );
151 if( it != positionToWires.end() )
161 if( std::find( aList.begin(), aList.end(), wire ) == aList.end() )
170 aList.push_back( wire );
180 std::set<VECTOR2I> pinPositions;
187 pinPositions.insert(
pin->GetPosition() );
191 bool allConnected =
true;
203 bool startConnected = pinPositions.count( start ) > 0;
204 bool endConnected = pinPositions.count(
end ) > 0;
206 if( !startConnected )
209 <<
") not connected to any pin" );
211 for(
const VECTOR2I& pinPos : pinPositions )
217 allConnected =
false;
223 <<
") not connected to any pin" );
225 for(
const VECTOR2I& pinPos : pinPositions )
231 allConnected =
false;
250 const VECTOR2D& aGridSize,
const std::string& aTestName )
252 std::set<EDA_ITEM*> selectionSet( aSelection.begin(), aSelection.end() );
255 std::map<SCH_LINE*, std::pair<VECTOR2I, VECTOR2I>> originalWireEndpoints;
266 std::map<VECTOR2I, std::vector<SCH_LINE*>> positionToWires =
271 if( selectionSet.find( it ) == selectionSet.end() )
276 it->SetStoredPos( it->GetPosition() );
281 pin->SetStoredPos(
pin->GetPosition() );
295 auto it = positionToWires.find( aPoint );
297 if( it != positionToWires.end() )
304 if( std::find( aList.begin(), aList.end(), wire ) == aList.end() )
313 aList.push_back( wire );
325 for(
const auto& [wire, origEndpoints] : originalWireEndpoints )
327 VECTOR2I origStart = origEndpoints.first;
328 VECTOR2I origEnd = origEndpoints.second;
329 VECTOR2I newStart = wire->GetStartPoint();
330 VECTOR2I newEnd = wire->GetEndPoint();
333 bool wasHorizontal = ( origStart.
y == origEnd.
y );
336 bool isHorizontal = ( newStart.
y == newEnd.
y );
338 if( wasHorizontal && !isHorizontal )
341 << origStart.
x <<
", " << origStart.
y <<
") to ("
342 << origEnd.
x <<
", " << origEnd.
y <<
"), Now: ("
343 << newStart.
x <<
", " << newStart.
y <<
") to ("
344 << newEnd.
x <<
", " << newEnd.
y <<
")" );
349 bool wasVertical = ( origStart.
x == origEnd.
x );
350 bool isVertical = ( newStart.
x == newEnd.
x );
352 if( wasVertical && !isVertical )
355 << origStart.
x <<
", " << origStart.
y <<
") to ("
356 << origEnd.
x <<
", " << origEnd.
y <<
"), Now: ("
357 << newStart.
x <<
", " << newStart.
y <<
") to ("
358 << newEnd.
x <<
", " << newEnd.
y <<
")" );
364 std::set<VECTOR2I> pinPositions;
371 pinPositions.insert(
pin->GetPosition() );
374 bool allConnected =
true;
376 for(
const auto& [wire, origEndpoints] : originalWireEndpoints )
378 VECTOR2I start = wire->GetStartPoint();
381 bool startConnected = pinPositions.count( start ) > 0;
382 bool endConnected = pinPositions.count(
end ) > 0;
384 if( !startConnected )
387 <<
") not connected to any pin" );
388 allConnected =
false;
394 <<
") not connected to any pin" );
395 allConnected =
false;
400 return noSkew && allConnected;
419 SCH_SCREEN* screen = m_schematic->RootScreen();
423 std::vector<EDA_ITEM*> selection;
426 selection.push_back( item );
428 BOOST_REQUIRE_EQUAL( selection.size(), 2 );
432 bool allConnected = RunAlignmentAndVerify( screen, selection, gridSize,
433 "AlignAllItemsStandardGrid" );
436 "aligning all items with 2.54mm grid" );
448 SCH_SCREEN* screen = m_schematic->RootScreen();
451 std::vector<EDA_ITEM*> selection;
454 selection.push_back( item );
458 bool allConnected = RunAlignmentAndVerify( screen, selection, gridSize,
459 "AlignAllItemsFineGrid" );
462 "aligning all items with 1.27mm grid" );
474 SCH_SCREEN* screen = m_schematic->RootScreen();
477 std::vector<EDA_ITEM*> selection;
480 selection.push_back( item );
484 bool allConnected = RunAlignmentAndVerify( screen, selection, gridSize,
485 "AlignAllItemsCoarseGrid" );
488 "aligning all items with 5.08mm grid" );
502 SCH_SCREEN* screen = m_schematic->RootScreen();
511 if( sheet->
GetName() ==
"sheet1" )
520 std::vector<EDA_ITEM*> selection{ sheet1 };
523 bool success = RunAlignmentAndVerifyNoSkew( screen, selection, gridSize,
"AlignSheet1Only" );
524 BOOST_CHECK_MESSAGE( success,
"Wires should remain straight and connected when aligning only sheet1" );
538 SCH_SCREEN* screen = m_schematic->RootScreen();
547 if( sheet->
GetName() ==
"sheet2" )
556 std::vector<EDA_ITEM*> selection{ sheet2 };
559 bool success = RunAlignmentAndVerifyNoSkew( screen, selection, gridSize,
"AlignSheet2Only" );
561 BOOST_CHECK_MESSAGE( success,
"Wires should remain straight and connected when aligning only sheet2" );
575 SCH_SCREEN* screen = m_schematic->RootScreen();
585 if( sheet->
GetName() ==
"sheet1" )
587 else if( sheet->
GetName() ==
"sheet2" )
597 std::vector<EDA_ITEM*> selection1{ sheet1 };
598 bool success1 = RunAlignmentAndVerifyNoSkew( screen, selection1, gridSize,
599 "AlignSheet1ThenSheet2 (step 1)" );
601 BOOST_CHECK_MESSAGE( success1,
"Wires should remain straight and connected after aligning sheet1" );
604 std::vector<EDA_ITEM*> selection2{ sheet2 };
605 bool success2 = RunAlignmentAndVerifyNoSkew( screen, selection2, gridSize,
606 "AlignSheet1ThenSheet2 (step 2)" );
608 BOOST_CHECK_MESSAGE( success2,
"Wires should remain straight and connected after aligning sheet2" );
622 SCH_SCREEN* screen = m_schematic->RootScreen();
632 if( sheet->
GetName() ==
"sheet1" )
634 else if( sheet->
GetName() ==
"sheet2" )
644 std::vector<EDA_ITEM*> selection2{ sheet2 };
645 bool success2 = RunAlignmentAndVerifyNoSkew( screen, selection2, gridSize,
646 "AlignSheet2ThenSheet1 (step 1)" );
648 BOOST_CHECK_MESSAGE( success2,
"Wires should remain straight and connected after aligning sheet2" );
651 std::vector<EDA_ITEM*> selection1{ sheet1 };
652 bool success1 = RunAlignmentAndVerifyNoSkew( screen, selection1, gridSize,
653 "AlignSheet2ThenSheet1 (step 2)" );
655 BOOST_CHECK_MESSAGE( success1,
"Wires should remain straight and connected after aligning sheet1" );
667 SCH_SCREEN* screen = m_schematic->RootScreen();
670 std::vector<EDA_ITEM*> selection;
673 selection.push_back( item );
676 std::vector<double> gridSizesMm = { 5.08, 2.54, 1.27, 0.635 };
678 for(
double gridMm : gridSizesMm )
682 screen = m_schematic->RootScreen();
686 selection.push_back( item );
690 std::stringstream testName;
691 testName <<
"AlignMultipleGridSizes (" << gridMm <<
"mm)";
693 bool allConnected = RunAlignmentAndVerify( screen, selection, gridSize, testName.str() );
696 << gridMm <<
"mm grid" );
709 SCH_SCREEN* screen = m_schematic->RootScreen();
712 std::vector<EDA_ITEM*> selection;
715 selection.push_back( item );
720 auto positionToWires = BuildPositionToWiresMap( screen );
727 static_cast<SCH_SHEET*
>( aItem )->Move( aDelta );
735 auto it = positionToWires.find( aPoint );
737 if( it != positionToWires.end() )
741 if( std::find( aList.begin(), aList.end(), wire ) == aList.end() )
750 aList.push_back( wire );
766 bool foundWire =
false;
783 "Pin at (" << pinPos.
x <<
", " << pinPos.
y
784 <<
") should have a connected wire endpoint" );
800 SCH_SCREEN* screen = m_schematic->RootScreen();
804 std::vector<EDA_ITEM*> selection;
809 selection.push_back( item );
819 selection.push_back( wire );
823 BOOST_REQUIRE_GE( selection.size(), 4 );
827 bool allConnected = RunAlignmentAndVerify( screen, selection, gridSize,
828 "AlignSheetsAndWiresTogether" );
831 "All wire endpoints should connect to pins after aligning "
832 "both sheets AND wires together (Select All scenario)" );
841 std::vector<double> gridSizesMm = { 5.08, 2.54, 1.27, 0.635 };
843 for(
double gridMm : gridSizesMm )
848 SCH_SCREEN* screen = m_schematic->RootScreen();
852 std::vector<EDA_ITEM*> selection;
857 selection.push_back( item );
867 selection.push_back( wire );
873 std::stringstream testName;
874 testName <<
"AlignSheetsAndWiresMultipleGrids (" << gridMm <<
"mm)";
876 bool allConnected = RunAlignmentAndVerify( screen, selection, gridSize, testName.str() );
879 "All wire endpoints should connect to pins with "
880 << 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(ServerStartsAndResponds, API_SERVER_E2E_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_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D