26#include <boost/random/mersenne_twister.hpp>
27#include <boost/random/uniform_real_distribution.hpp>
63 SetTitle(
_(
"Via Stitching Properties" ) );
73 [
this]( wxCommandEvent& aEvt )
106 view->
Remove( track.get() );
118 if( !DIALOG_VIA_STITCH_PROPERTIES_BASE::TransferDataToWindow() )
150 if( newNetCode >= 0 )
154 if( newGuardedNetCode >= 0 )
155 m_stitch->SetGuardedNetCode( newGuardedNetCode );
162 unsigned long seedVal = 0;
163 if(
m_seedCtrl->GetValue().ToULong( &seedVal ) )
164 m_stitch->SetSeed(
static_cast<uint32_t
>( seedVal ) );
174 m_stitch->SetTemplateItem( wxS(
"via" ),
175 std::make_unique<PCB_VIA>( *
m_workingCopy->ViaTemplate() ) );
236 if( newNetCode >= 0 )
240 if( newGuardedNetCode >= 0 )
248 unsigned long seedVal = 0;
249 if(
m_seedCtrl->GetValue().ToULong( &seedVal ) )
284 [
this]( wxSizeEvent& aEvt )
311 view->
Remove( track.get() );
322 std::vector<VECTOR2I> samples;
332 std::unique_ptr<PCB_VIA>
via(
334 via->ResetUuidDirect();
336 via->SetPosition( pt );
337 via->SetIsFree(
true );
364 const int numTiles = 2;
365 const int previewExtent = tileSize * numTiles;
368 boost::random::uniform_real_distribution<double> uniform( 0.0, 1.0 );
369 const double offsetX = uniform( seedRng ) * tileSize;
370 const double offsetY = uniform( seedRng ) * tileSize;
372 const int firstTileX = (int) std::floor( ( 0.0 - offsetX ) / (
double) tileSize );
373 const int firstTileY = (int) std::floor( ( 0.0 - offsetY ) / (
double) tileSize );
374 const int lastTileX = (int) std::floor( ( (
double) previewExtent - offsetX )
375 / (
double) tileSize );
376 const int lastTileY = (int) std::floor( ( (
double) previewExtent - offsetY )
377 / (
double) tileSize );
379 for(
int ty = firstTileY; ty <= lastTileY; ++ty )
381 for(
int tx = firstTileX; tx <= lastTileX; ++tx )
385 VECTOR2I pt( (
int) std::round( offsetX + ( tx + s.x ) * tileSize ),
386 (
int) std::round( offsetY + ( ty + s.y ) * tileSize ) );
390 if( pt.
x < 0 || pt.
x > previewExtent
391 || pt.
y < 0 || pt.
y > previewExtent )
394 aSamples.push_back( pt );
399 return previewExtent;
408 aSamples.emplace_back( col * pitch + xShift, row * pitch );
443 const std::vector<VECTOR2I> corners = {
444 { extent * 12 / 100, extent * 78 / 100 },
445 { extent * 38 / 100, extent * 78 / 100 },
446 { extent * 62 / 100, extent * 22 / 100 },
447 { extent * 88 / 100, extent * 22 / 100 },
451 const int safetyMargin = polyApproxError +
pcbIUScale.mmToIU( 0.002 );
452 const int margin = viaSize / 2 +
clearance + safetyMargin;
458 for(
size_t ii = 1; ii < corners.size(); ++ii )
460 std::unique_ptr<PCB_TRACK> track = std::make_unique<PCB_TRACK>( board );
461 track->SetLayer(
F_Cu );
462 track->SetWidth( trackWidth );
463 track->SetStart( corners[ii - 1] );
464 track->SetEnd( corners[ii] );
466 track->TransformShapeToPolygon( envelope,
F_Cu, margin, polyApproxError,
ERROR_OUTSIDE );
467 track->TransformShapeToPolygon( guarded,
F_Cu, 0, polyApproxError,
ERROR_OUTSIDE );
469 view->
Add( track.get() );
constexpr EDA_IU_SCALE pcbIUScale
@ NORMAL
Inactive layers are shown normally (no high-contrast mode)
Container for design settings for a BOARD object.
std::shared_ptr< NET_SETTINGS > m_NetSettings
int GetCurrentTrackWidth() const
Information pertinent to a Pcbnew printed circuit board.
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
wxStaticText * m_textSizeUnits
wxStaticText * m_patternLabel
wxStaticText * m_guardNet
wxStaticText * m_posXLabel
wxComboBox * m_patternCombo
NET_SELECTOR * m_netSelector
NET_SELECTOR * m_guardNetSelector
PCB_DRAW_PANEL_GAL * m_panelShowPreview
wxStaticText * m_posXUnits
wxStaticText * m_posYUnits
DIALOG_VIA_STITCH_PROPERTIES_BASE(wxWindow *parent, wxWindowID id=wxID_DIALOG_EDIT_PAD, const wxString &title=_("Via Stitch Properties"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxStaticText * m_pitchLabel
wxStaticText * m_seedLabel
wxStaticText * m_posYLabel
void OnCancel(wxCommandEvent &event) override
std::unique_ptr< UNIT_BINDER > m_posYBinder
std::vector< std::unique_ptr< PCB_VIA > > m_previewVias
Vias currently in the preview canvas, used for both Guard and Stitch mode previews.
KIGFX::ORIGIN_VIEWITEM * m_axisOrigin
DIALOG_VIA_STITCH_PROPERTIES(PCB_BASE_EDIT_FRAME *aFrame, PCB_VIA_STITCH *aStitch)
std::unique_ptr< PCB_VIA_STITCH > m_workingCopy
Off-board clone of m_stitch used to drive the preview without touching the board.
void OnUpdateUI(wxUpdateUIEvent &event) override
PCB_BASE_EDIT_FRAME * m_frame
int m_previewExtent
Side length of the tile drawn by the last redrawPreview(), in IU; 0 if nothing is currently drawn.
int buildStitchPreview(std::vector< VECTOR2I > &aSamples)
Builds a preview for stitch mode.
~DIALOG_VIA_STITCH_PROPERTIES() override
int buildGuardPreview(std::vector< VECTOR2I > &aSamples)
Builds a preview for guard mode.
void OnViaConfigureClicked(wxCommandEvent &event) override
std::vector< std::unique_ptr< PCB_TRACK > > m_previewTracks
Tracks currently in the preview canvas, only used for Guard mode preview.
void redrawPreview()
Push the GAL preview to reflect the current m_workingCopy state.
std::unique_ptr< UNIT_BINDER > m_pitchBinder
PCB_VIA_STITCH * m_stitch
The live generator being edited. Only written back on OK.
void OnValuesChanged(wxCommandEvent &event) override
void prepareCanvas()
First-time set-up of m_panelShowPreview — colors, view layers, board attachment.
void updateWorkingCopyFromUI()
Pull values out of UI controls into m_workingCopy, regenerate its children, and re-zoom the preview c...
bool TransferDataFromWindow() override
bool TransferDataToWindow() override
std::unique_ptr< UNIT_BINDER > m_posXBinder
void fitPreview()
Autozoom the preview canvas onto the last-rendered tile.
A color representation with 4 components: red, green, blue, alpha.
void SetAxesEnabled(bool aAxesEnabled)
Enable drawing the axes.
const VECTOR2I & GetScreenPixelSize() const
Return GAL canvas size in pixels.
void SetGridVisibility(bool aVisibility)
Set the visibility setting of the grid.
PCB specific render settings.
void SetHighContrast(bool aEnabled)
Turns on/off high contrast display mode.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
void SetViewport(const BOX2D &aViewport)
Set the visible area of the VIEW.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
bool HasClearance() const
Handle the data for a net.
std::shared_ptr< NETCLASS > GetDefaultNetclass() const
Gets the default netclass for the project.
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Common, abstract interface for edit frames.
static std::vector< VECTOR2I > SampleGuardEnvelope(const SHAPE_POLY_SET &aEnvelope, const SHAPE_POLY_SET &aGuarded, int aPitch, const std::function< bool(const VECTOR2I &)> &aIsValid)
Determine via positions around the perimeter of a guard envelope.
static const std::vector< VECTOR2D > & bakedPoissonTile()
Helper method to cache the poisson tile we pattern.
static constexpr int POISSON_TILE_PITCHES
Tile size for the POISSON layout, in units of pitch.
Represent a set of closed polygons.
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
static constexpr int PREVIEW_TILE_PITCHES
How many pitches to show on a side of the preview tile.
@ STITCH
Fill the outline with vias with a pattern.
@ GUARD
Place vias to guard a net contained within.
@ POISSON
Tiled poisson distribution.
@ STAGGERED
Odd rows shifted by half the pitch.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D