50 explicit HEADLESS_GAL( KIGFX::GAL_DISPLAY_OPTIONS& aOptions ) :
60 TEST_PCB_GRID_HELPER( TOOL_MANAGER* aToolMgr, MAGNETIC_SETTINGS* aMagneticSettings ) :
61 PCB_GRID_HELPER( aToolMgr, aMagneticSettings )
65 SNAP_MANAGER& SnapManager() {
return getSnapManager(); }
66 int SnapRange()
const {
return computeSnapRanges( m_enableGrid ).range; }
67 int SnapIn()
const {
return computeSnapRanges( m_enableGrid ).in; }
68 int SnapOut()
const {
return computeSnapRanges( m_enableGrid ).out; }
69 int MarkerTypes()
const {
return m_viewSnapPoint.GetSnapTypes(); }
70 VECTOR2I MarkerPosition()
const {
return m_viewSnapPoint.GetPosition(); }
71 const std::optional<ANCHOR>& SnapItem()
const {
return m_snapItem; }
75struct PCB_SNAP_FIXTURE
77 KIGFX::GAL_DISPLAY_OPTIONS options;
80 KIGFX::PCB_PAINTER painter;
82 PCBNEW_SETTINGS settings;
84 MAGNETIC_SETTINGS magnetic;
85 PCB_TOOL_BASE* tool =
nullptr;
86 std::unique_ptr<TEST_PCB_GRID_HELPER> helper;
92 gal.SetGridSize( {
MM,
MM } );
93 gal.SetGridOrigin( { 0, 0 } );
94 gal.SetWorldUnitLength( 1e-9 / 0.0254 );
95 gal.SetScreenSize( { 2000, 1200 } );
97 view.SetPainter( &painter );
98 view.SetCenter( { 2 *
MM, 2 *
MM } );
99 view.SetScale( 10.0 );
106 manager.SetEnvironment( &board, &view,
nullptr, &settings,
nullptr );
107 tool =
new PCB_TOOL_BASE(
"qa.PcbSnapTool" );
108 manager.RegisterTool( tool );
109 manager.InvokeTool(
"qa.PcbSnapTool" );
113 magnetic.graphics =
true;
114 magnetic.allLayers =
true;
115 helper = std::make_unique<TEST_PCB_GRID_HELPER>( &manager, &magnetic );
124 board.Add( segment );
131 PCB_TRACK* track =
new PCB_TRACK( &board );
148 pad->SetPosition( aPosition );
150 pad->SetSize( aLayer, {
MM,
MM } );
151 pad->SetLayerSet( LSET( { aLayer } ) );
153 board.Add( footprint );
154 view.Add( footprint );
158 std::vector<PAD*> AddFootprintPads(
const std::vector<VECTOR2I>& aPositions )
164 std::vector<PAD*> pads;
166 for(
const VECTOR2I& position : aPositions )
169 pad->SetPosition( position );
172 pad->SetLayerSet( LSET( {
F_Cu } ) );
174 pads.push_back(
pad );
177 board.Add( footprint );
178 view.Add( footprint );
190 helper->SetSnap(
false );
191 helper->SetUseGrid(
true );
202 helper->SetSnap(
false );
203 helper->SetUseGrid(
false );
215 PCB_TRACK* track = AddTrack( { 1410000, 1590000 }, { 4 *
MM, 1590000 } );
216 std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> visible;
220 BOOST_REQUIRE_GT( visible.size(), 0 );
221 BOOST_REQUIRE_GT( helper->SnapRange(), 10000 );
232 helper->SetSnapLineDirections( { { 1, 0 } } );
233 helper->SetSnapLineOrigin( { 0, 1600000 } );
239 PCB_TRACK* track = AddTrack( { 1410000, 1590000 }, { 4 *
MM, 1590000 } );
250 helper->SetSnapLine(
false );
252 BOOST_REQUIRE_EQUAL( helper->GetSnapped(), track );
266 const VECTOR2I reference( 1410000, 1590000 );
267 AddTrack( reference, { 4 *
MM, 1590000 } );
268 helper->SnapManager().SetReferenceOnlyPoints( { reference } );
272 BOOST_CHECK_NE(
result.position, reference );
274 const OPT_VECTOR2I& origin = helper->SnapManager().GetSnapLineManager().GetSnapLineOrigin();
282 AddTrack( { 0, 1500000 }, { 4 *
MM, 1500000 } );
285 helper->SetUseGrid(
true );
295 AddSegment( { 2 *
MM, 40 *
MM }, { 3 *
MM, 40 *
MM } );
302 BOOST_CHECK( std::any_of(
result.accepted.begin(),
result.accepted.end(),
305 return aId.kind == SNAP_ID_KIND::BOUNDS_X;
307 BOOST_CHECK( std::any_of(
result.guides.begin(),
result.guides.end(),
310 return std::abs( aGuide.end.y - aGuide.start.y ) > 30 * MM;
317 AddSegment( { 2 *
MM, 2 *
MM }, { 3 *
MM, 3 *
MM } );
318 AddSegment( { 12 *
MM, 2 *
MM }, { 13 *
MM, 3 *
MM } );
324 moving->GetStart() );
326 BOOST_CHECK( std::any_of(
result.accepted.begin(),
result.accepted.end(),
329 return aId.kind == SNAP_ID_KIND::COPY_GAP_X;
336 std::vector<PAD*> pads = AddFootprintPads( { { 2 *
MM, 2 *
MM }, { 12 *
MM, 2 *
MM }, { 22 *
MM, 2 *
MM } } );
341 PAD* moving = pads.back();
345 BOOST_CHECK( std::any_of(
result.accepted.begin(),
result.accepted.end(),
348 return aId.kind == SNAP_ID_KIND::COPY_GAP_X
349 || aId.kind == SNAP_ID_KIND::EQUAL_GAP_X;
356 std::vector<PAD*> pads = AddFootprintPads( { { 2 *
MM, 2 *
MM }, { 12 *
MM, 2 *
MM }, { 22 *
MM, 2 *
MM } } );
360 PAD* moving = pads.back();
365 BOOST_CHECK( std::none_of(
result.accepted.begin(),
result.accepted.end(),
368 return aId.kind == SNAP_ID_KIND::COPY_GAP_X
369 || aId.kind == SNAP_ID_KIND::EQUAL_GAP_X;
378 std::vector<PAD*> pads = AddFootprintPads( { { 2 *
MM, 2 *
MM }, { 12 *
MM, 9 *
MM } } );
382 PAD* moving = pads.back();
384 std::vector<BOARD_ITEM*> dragged = { moving };
387 helper->BestDragOrigin( origin, dragged );
388 helper->SetUseGrid(
false );
393 BOOST_CHECK(
result.position.y != origin.
y );
399 AddTrack( { 0, 1500000 }, { 4 *
MM, 1500000 } );
403 helper->SetUseGrid(
true );
407 helper->SetUseGrid(
false );
475 const VECTOR2I firstSelfPoint( 1410000, 1590000 );
476 const VECTOR2I secondSelfPoint( 1420000, 1580000 );
477 PCB_SHAPE* moving = AddSegment( firstSelfPoint, secondSelfPoint );
478 helper->SetPointEditProfile(
true );
479 helper->SetStationarySelfGeometry( { moving->
GetStart(), moving->
GetEnd() }, {} );
480 helper->SetFeasibilityCallback(
481 [firstSelfPoint](
const SNAP_SOURCE_CONTEXT& aContext,
const std::vector<SNAP_CANDIDATE>& aTrial )
515 BOOST_REQUIRE_EQUAL(
result.accepted.size(), 1 );
521 std::vector<CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM_BATCH> batches;
522 helper->SnapManager().GetConstructionManager().GetPendingConstructionItems( batches );
523 BOOST_REQUIRE_EQUAL( batches.size(), 1 );
524 BOOST_REQUIRE_EQUAL( batches.front().size(), 1 );
529 helper->SnapManager().GetConstructionManager().GetPendingConstructionItems( batches );
530 BOOST_REQUIRE_EQUAL( batches.size(), 1 );
531 BOOST_REQUIRE_EQUAL( batches.front().size(), 1 );
542 helper->SetSnapLine(
false );
544 BOOST_REQUIRE_EQUAL( helper->GetSnapped(), retainedTrack );
545 BOOST_REQUIRE_EQUAL( retainedResult.
accepted.size(), 1 );
550 helper->SetUseGrid(
false );
552 helper->SetFeasibilityCallback(
553 [rejectedId](
const SNAP_SOURCE_CONTEXT& aContext,
const std::vector<SNAP_CANDIDATE>& aCandidates )
558 if( aCandidates.empty() )
561 if( aCandidates.back().id == rejectedId )
574 BOOST_REQUIRE_EQUAL(
result.accepted.size(), 1 );
575 BOOST_CHECK(
result.accepted.front() != rejectedId );
585 AddSegment( { 2 *
MM, 10 *
MM }, { 3 *
MM, 10 *
MM } );
590 const auto guideIt = std::find_if(
result.guides.begin(),
result.guides.end(),
593 return aGuide.style == SNAP_GUIDE_STYLE::SNAP_LINE;
608 helper->SetSnapLine(
false );
609 helper->SetUseGrid(
false );
611 for(
int i = 0; i < 8; ++i )
612 AddTrack(
anchor, { 4 *
MM, ( 3 + i ) *
MM } );
614 helper->SetFeasibilityCallback(
621 if( aCandidates.empty() )
624 std::this_thread::sleep_for( std::chrono::milliseconds( 12 ) );
635 BOOST_REQUIRE_EQUAL(
result.accepted.size(), 1 );
637 const auto& acceptedAnchor = *helper->SnapItem();
638 std::vector<SNAP_TARGET_ID> expectedTargets;
640 for(
EDA_ITEM* item : acceptedAnchor.items )
648 expectedTargets.push_back( pointId.
target );
649 BOOST_CHECK(
result.accepted.front()
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
A base class for most all the KiCad significant classes used in schematics and boards.
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Abstract interface for drawing on a 2D-surface.
void SetViewport(const BOX2D &aViewport)
Set the visible area of the VIEW.
int Query(const BOX2I &aRect, std::vector< LAYER_ITEM_PAIR > &aResult) const
Find all visible items that touch or are within the rectangle aRect.
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
std::array< uint8_t, 16 > AsBytes() const
LSET is a set of PCB_LAYER_IDs.
static const LSET & AllLayersMask()
VECTOR2I GetPosition() const override
SNAP_INFERENCE_SETTINGS m_SnapInference
void SetEnd(const VECTOR2I &aEnd) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetStart(const VECTOR2I &aStart) override
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
void SetEnd(const VECTOR2I &aEnd)
void SetStart(const VECTOR2I &aStart)
const VECTOR2I & GetStart() const
virtual void SetWidth(int aWidth)
bool HasCompleteSnapLine() const
const OPT_VECTOR2I & GetSnapLineOrigin() const
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
@ LAYER_PADS
Meta control for all pads opacity/visibility (color ignored).
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
PCB_LAYER_ID
A quick note on layer IDs:
@ PT_END
The point is at the end of a segment, arc, etc.
@ PT_ON_ELEMENT
The point is somewhere on another element, but not some specific point.
std::optional< VECTOR2I > OPT_VECTOR2I
SNAP_STABLE_ID MakePointSnapId(SNAP_ID_KIND aKind, const VECTOR2I &aPoint, int aFeatureIndex=0)
SNAP_STABLE_ID MakeCompositeSnapId(SNAP_ID_KIND aKind, const std::vector< SNAP_TARGET_ID > &aTargets, int aFeatureIndex=0)
@ CAPTURE_CURSOR_IN_TRACK_TOOL
bool constructionExtensions
bool alignmentDistribution
std::vector< SNAP_STABLE_ID > accepted
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()
static const long long MM
BOOST_FIXTURE_TEST_CASE(DisabledSnapUsesGridWhenEnabled, PCB_SNAP_FIXTURE)
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I