KiCad PCB EDA Suite
ZONE_CREATE_HELPER Class Reference

This class is an adjuct helper to the DRAWING_TOOL interactive tool, which handles incoming geometry changes from a POLYGON_GEOM_MANAGER and translates that into a ZONE_CONTAINER based on given parameters. More...

#include <zone_create_helper.h>

Inheritance diagram for ZONE_CREATE_HELPER:
POLYGON_GEOM_MANAGER::CLIENT

Classes

struct  PARAMS
 Parameters used to fully describe a zone creation process. More...
 

Public Member Functions

 ZONE_CREATE_HELPER (DRAWING_TOOL &aTool, PARAMS &aParams)
 
virtual ~ZONE_CREATE_HELPER ()
 
void OnGeometryChange (const POLYGON_GEOM_MANAGER &aMgr) override
 

Sent when the polygon geometry changes

More...
 
bool OnFirstPoint (POLYGON_GEOM_MANAGER &aMgr) override
 Called before the first point is added - clients can do initialisation here, and can veto the start of the process (e.g. More...
 
void OnComplete (const POLYGON_GEOM_MANAGER &aMgr) override
 

Called when the polygon is complete

More...
 
std::unique_ptr< ZONE_CONTAINERcreateNewZone (bool aKeepout)
 Function createNewZone() More...
 
std::unique_ptr< ZONE_CONTAINERcreateZoneFromExisting (const ZONE_CONTAINER &aSrcZone)
 Function createZoneFromExisting. More...
 
void performZoneCutout (ZONE_CONTAINER &aZone, ZONE_CONTAINER &aCutout)
 Function performZoneCutout() More...
 
void commitZone (std::unique_ptr< ZONE_CONTAINER > aZone)
 Commit the current zone-in-progress to the BOARD. More...
 

Private Attributes

DRAWING_TOOLm_tool
 
PARAMSm_params
 

Parameters of the zone to be drawn

More...
 
KIGFX::PREVIEW::POLYGON_ITEM m_previewItem
 

The preview item to display

More...
 
KIGFX::VIEWm_parentView
 

view that show the preview item

More...
 
std::unique_ptr< ZONE_CONTAINERm_zone
 

The zone-in-progress

More...
 

Detailed Description

This class is an adjuct helper to the DRAWING_TOOL interactive tool, which handles incoming geometry changes from a POLYGON_GEOM_MANAGER and translates that into a ZONE_CONTAINER based on given parameters.

Definition at line 43 of file zone_create_helper.h.

Constructor & Destructor Documentation

◆ ZONE_CREATE_HELPER()

ZONE_CREATE_HELPER::ZONE_CREATE_HELPER ( DRAWING_TOOL aTool,
PARAMS aParams 
)
Parameters
aToolthe DRAWING_TOOL to provide the zone tool to
aParamsthe parameters to use to guide the zone creation

Definition at line 35 of file zone_create_helper.cpp.

35  :
36  m_tool( aTool ),
37  m_params( aParams ),
38  m_parentView( *aTool.getView() )
39 {
41 }
KIGFX::PREVIEW::POLYGON_ITEM m_previewItem
The preview item to display
KIGFX::VIEW & m_parentView
view that show the preview item
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
PARAMS & m_params
Parameters of the zone to be drawn
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:350

References KIGFX::VIEW::Add(), m_parentView, and m_previewItem.

◆ ~ZONE_CREATE_HELPER()

ZONE_CREATE_HELPER::~ZONE_CREATE_HELPER ( )
virtual

Definition at line 44 of file zone_create_helper.cpp.

45 {
46  // remove the preview from the view
49 }
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:380
KIGFX::PREVIEW::POLYGON_ITEM m_previewItem
The preview item to display
KIGFX::VIEW & m_parentView
view that show the preview item
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1490

References m_parentView, m_previewItem, KIGFX::VIEW::Remove(), and KIGFX::VIEW::SetVisible().

Member Function Documentation

◆ commitZone()

void ZONE_CREATE_HELPER::commitZone ( std::unique_ptr< ZONE_CONTAINER aZone)

Commit the current zone-in-progress to the BOARD.

This might be adding a new zone, or modifying an existing zone with a cutout, depending on parameters.

Parameters
aZone- the drawn zone outline to commit

Definition at line 181 of file zone_create_helper.cpp.

182 {
183  switch ( m_params.m_mode )
184  {
185  case ZONE_MODE::CUTOUT:
186  // For cutouts, subtract from the source
188  break;
189 
190  case ZONE_MODE::ADD:
191  case ZONE_MODE::SIMILAR:
192  {
193  BOARD_COMMIT bCommit( &m_tool );
194 
195  aZone->Hatch();
196 
197  if( !m_params.m_keepout )
198  {
199  ZONE_FILLER filler( m_tool.getModel<BOARD>() );
200  filler.Fill( { aZone.get() } );
201  }
202 
203  bCommit.Add( aZone.get() );
204  bCommit.Push( _( "Add a zone" ) );
205  m_tool.GetManager()->RunAction( PCB_ACTIONS::selectItem, true, aZone.release() );
206  break;
207  }
208 
210  {
211  BOARD_COMMIT bCommit( &m_tool );
213  LSET graphicPolygonsLayers = LSET::AllLayersMask();
214 
215  graphicPolygonsLayers.reset( Edge_Cuts ).reset( F_CrtYd ).reset( B_CrtYd );
216 
217  if( graphicPolygonsLayers.Contains( m_params.m_layer ) )
218  {
219  auto poly = m_tool.m_editModules ? new EDGE_MODULE( (MODULE *) parent )
220  : new DRAWSEGMENT();
221  poly->SetShape ( S_POLYGON );
222  poly->SetLayer( m_params.m_layer );
223  poly->SetPolyShape ( *aZone->Outline() );
224  bCommit.Add( poly );
226  }
227  else
228  {
229  auto outline = aZone->Outline();
230 
231  for( auto seg = outline->CIterateSegments( 0 ); seg; seg++ )
232  {
233  auto new_seg = m_tool.m_editModules ? new EDGE_MODULE( (MODULE *) parent )
234  : new DRAWSEGMENT();
235  new_seg->SetShape( S_SEGMENT );
236  new_seg->SetLayer( m_params.m_layer );
237  new_seg->SetStart( wxPoint( seg.Get().A.x, seg.Get().A.y ) );
238  new_seg->SetEnd( wxPoint( seg.Get().B.x, seg.Get().B.y ) );
239  bCommit.Add( new_seg );
240  }
241  }
242 
243  bCommit.Push( _( "Add a graphical polygon" ) );
244 
245  break;
246  }
247  }
248 }
void SetShape(STROKE_T aShape)
Add a new zone with the same settings as an existing one.
T * getModel() const
Function getModel()
Definition: tool_base.h:201
bool Contains(PCB_LAYER_ID aLayer)
See if the layer set contains a PCB layer.
polygon (not yet used for tracks, but could be in microwave apps)
PCB_LAYER_ID m_layer
Layer to begin drawing
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:140
usual segment : line with rounded ends
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:143
void performZoneCutout(ZONE_CONTAINER &aZone, ZONE_CONTAINER &aCutout)
Function performZoneCutout()
LSET is a set of PCB_LAYER_IDs.
ZONE_CONTAINER * m_sourceZone
Zone settings source (for similar and cutout zones)
Add a new zone/keepout with fresh settings.
static LSET AllLayersMask()
Definition: lset.cpp:749
Make a cutout to an existing zone.
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:230
PARAMS & m_params
Parameters of the zone to be drawn
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:65
Abstract interface for BOARD_ITEMs capable of storing other items inside.
bool m_keepout
Should create a keepout zone?
ZONE_MODE m_mode
The zone mode to operate in

References _, ADD, COMMIT::Add(), LSET::AllLayersMask(), B_CrtYd, LSET::Contains(), CUTOUT, Edge_Cuts, F_CrtYd, ZONE_FILLER::Fill(), TOOL_BASE::GetManager(), TOOL_BASE::getModel(), PCB_BASE_FRAME::GetModel(), GRAPHIC_POLYGON, PCB_TOOL_BASE::m_editModules, DRAWING_TOOL::m_frame, ZONE_CREATE_HELPER::PARAMS::m_keepout, ZONE_CREATE_HELPER::PARAMS::m_layer, ZONE_CREATE_HELPER::PARAMS::m_mode, m_params, ZONE_CREATE_HELPER::PARAMS::m_sourceZone, m_tool, performZoneCutout(), BOARD_COMMIT::Push(), TOOL_MANAGER::RunAction(), S_POLYGON, S_SEGMENT, PCB_ACTIONS::selectItem, and SIMILAR.

Referenced by OnComplete().

◆ createNewZone()

std::unique_ptr< ZONE_CONTAINER > ZONE_CREATE_HELPER::createNewZone ( bool  aKeepout)

Function createNewZone()

Prompt the user for new zone settings, and create a new zone with those settings

Parameters
aKeepoutshould the zone be a keepout
Returns
the new zone, can be null if the user aborted

Definition at line 52 of file zone_create_helper.cpp.

53 {
54  auto& frame = *m_tool.getEditFrame<PCB_BASE_EDIT_FRAME>();
55  auto& board = *m_tool.getModel<BOARD>();
58 
59  // Get the current default settings for zones
60  ZONE_SETTINGS zoneInfo = frame.GetZoneSettings();
61  zoneInfo.m_Layers.reset().set( m_params.m_layer ); // TODO(JE) multilayer defaults?
62  zoneInfo.m_NetcodeSelection =
63  board.GetHighLightNetCodes().empty() ? -1 : *board.GetHighLightNetCodes().begin();
64  zoneInfo.SetIsKeepout( m_params.m_keepout );
66 
67  // If we don't have a net from highlighing, maybe we can get one from the selection
68  SELECTION_TOOL* selectionTool = m_tool.GetManager()->GetTool<SELECTION_TOOL>();
69 
70  if( selectionTool && !selectionTool->GetSelection().Empty()
71  && zoneInfo.m_NetcodeSelection == -1 )
72  {
73  EDA_ITEM* item = *selectionTool->GetSelection().GetItems().begin();
74 
75  if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
76  zoneInfo.m_NetcodeSelection = bci->GetNetCode();
77  }
78 
80  {
81  // Get the current default settings for zones
82 
83  // Show options dialog
84  int dialogResult;
85 
86  if( m_params.m_keepout )
87  dialogResult = InvokeKeepoutAreaEditor( &frame, &zoneInfo );
88  else
89  {
90  // TODO(JE) combine these dialogs?
91  if( ( zoneInfo.m_Layers & LSET::AllCuMask() ).any() )
92  dialogResult = InvokeCopperZonesEditor( &frame, &zoneInfo );
93  else
94  dialogResult = InvokeNonCopperZonesEditor( &frame, &zoneInfo );
95  }
96 
97  if( dialogResult == wxID_CANCEL )
98  return nullptr;
99 
100  controls->WarpCursor( controls->GetCursorPosition(), true );
101  }
102 
103  // The new zone is a ZONE_CONTAINER if created in the board editor
104  // and a MODULE_ZONE_CONTAINER if created in the footprint editor
105  wxASSERT( !m_tool.m_editModules || ( parent->Type() == PCB_MODULE_T ) );
106 
107  auto newZone = m_tool.m_editModules ?
108  std::make_unique<MODULE_ZONE_CONTAINER>( parent ) :
109  std::make_unique<ZONE_CONTAINER>( parent );
110 
111  // Apply the selected settings
112  zoneInfo.ExportSetting( *newZone );
113 
114  return newZone;
115 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:712
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
int InvokeKeepoutAreaEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeKeepoutAreaEditor invokes up a modal dialog window for copper zone editing.
LSET m_Layers
Layers that this zone exists on.
Definition: zone_settings.h:97
T * getModel() const
Function getModel()
Definition: tool_base.h:201
SELECTION_TOOL.
int InvokeNonCopperZonesEditor(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings)
Function InvokeNonCopperZonesEditor invokes up a modal dialog window for non-copper zone editing.
PCB_LAYER_ID m_layer
Layer to begin drawing
Template specialization to enable wxStrings for certain containers (e.g. unordered_map)
Definition: bitmap.cpp:56
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:143
PCBNEW_SELECTION & GetSelection()
Function GetSelection()
int m_NetcodeSelection
Net code selection for the current zone.
Definition: zone_settings.h:93
class MODULE, a footprint
Definition: typeinfo.h:89
virtual void WarpCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false)=0
Function WarpCursor() If enabled (.
Unconstrained point-to-point
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:132
VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (such a...
void SetIsKeepout(bool aEnable)
void ExportSetting(ZONE_CONTAINER &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:121
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:230
ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:67
PARAMS & m_params
Parameters of the zone to be drawn
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
KIGFX::VIEW_CONTROLS * GetViewControls() const
Definition: tool_manager.h:286
Common, abstract interface for edit frames.
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
T * getEditFrame() const
Function getEditFrame()
Definition: tool_base.h:187
int InvokeCopperZonesEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeCopperZonesEditor invokes up a modal dialog window for copper zone editing.
Abstract interface for BOARD_ITEMs capable of storing other items inside.
POLYGON_GEOM_MANAGER::LEADER_MODE m_leaderMode
Zone leader mode
bool m_keepout
Should create a keepout zone?
ZONE_MODE m_mode
The zone mode to operate in
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.

References LSET::AllCuMask(), POLYGON_GEOM_MANAGER::DEG45, SELECTION::Empty(), ZONE_SETTINGS::ExportSetting(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), TOOL_BASE::getEditFrame(), SELECTION::GetItems(), TOOL_BASE::GetManager(), TOOL_BASE::getModel(), PCB_BASE_FRAME::GetModel(), SELECTION_TOOL::GetSelection(), TOOL_MANAGER::GetTool(), TOOL_MANAGER::GetViewControls(), GRAPHIC_POLYGON, InvokeCopperZonesEditor(), InvokeKeepoutAreaEditor(), InvokeNonCopperZonesEditor(), PCB_TOOL_BASE::m_editModules, DRAWING_TOOL::m_frame, ZONE_CREATE_HELPER::PARAMS::m_keepout, ZONE_CREATE_HELPER::PARAMS::m_layer, ZONE_SETTINGS::m_Layers, ZONE_CREATE_HELPER::PARAMS::m_leaderMode, ZONE_CREATE_HELPER::PARAMS::m_mode, ZONE_SETTINGS::m_NetcodeSelection, m_params, m_tool, ZONE_SETTINGS::m_Zone_45_Only, PCB_MODULE_T, ZONE_SETTINGS::SetIsKeepout(), and KIGFX::VIEW_CONTROLS::WarpCursor().

Referenced by OnFirstPoint().

◆ createZoneFromExisting()

std::unique_ptr< ZONE_CONTAINER > ZONE_CREATE_HELPER::createZoneFromExisting ( const ZONE_CONTAINER aSrcZone)

Function createZoneFromExisting.

Create a new zone with the settings from an existing zone

Parameters
aSrcZonethe zone to copy settings from
Returns
the new zone

Definition at line 118 of file zone_create_helper.cpp.

120 {
121  auto& board = *m_tool.getModel<BOARD>();
122 
123  auto newZone = std::make_unique<ZONE_CONTAINER>( &board );
124 
125  ZONE_SETTINGS zoneSettings;
126  zoneSettings << aSrcZone;
127 
128  zoneSettings.ExportSetting( *newZone );
129 
130  return newZone;
131 }
T * getModel() const
Function getModel()
Definition: tool_base.h:201
void ExportSetting(ZONE_CONTAINER &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:67
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180

References ZONE_SETTINGS::ExportSetting(), TOOL_BASE::getModel(), and m_tool.

Referenced by OnFirstPoint().

◆ OnComplete()

void ZONE_CREATE_HELPER::OnComplete ( const POLYGON_GEOM_MANAGER aMgr)
overridevirtual

Called when the polygon is complete

Implements POLYGON_GEOM_MANAGER::CLIENT.

Definition at line 292 of file zone_create_helper.cpp.

293 {
294  auto& finalPoints = aMgr.GetLockedInPoints();
295 
296  if( finalPoints.PointCount() < 3 )
297  {
298  // just scrap the zone in progress
299  m_zone = nullptr;
300  }
301  else
302  {
303  // if m_params.m_mode == DRAWING_TOOL::ZONE_MODE::CUTOUT, m_zone
304  // will be merged to the existing zone as a new hole.
305  m_zone->Outline()->NewOutline();
306  auto* outline = m_zone->Outline();
307 
308  for( int i = 0; i < finalPoints.PointCount(); ++i )
309  outline->Append( finalPoints.CPoint( i ) );
310 
311  // In DEG45 mode, we may have intermediate points in the leader that should be
312  // included as they are shown in the preview. These typically maintain the
313  // 45 constraint
315  {
316  const auto& pts = aMgr.GetLeaderLinePoints();
317  for( int i = 1; i < pts.PointCount(); i++ )
318  outline->Append( pts.CPoint( i ) );
319  }
320 
321  outline->Outline( 0 ).SetClosed( true );
322  outline->RemoveNullSegments();
323  outline->Simplify( SHAPE_POLY_SET::PM_FAST );
324 
325  // hand the zone over to the committer
326  commitZone( std::move( m_zone ) );
327  m_zone = nullptr;
328  }
329 
331 }
const SHAPE_LINE_CHAIN & GetLeaderLinePoints() const
Get the points comprising the leader line (the line from the last locked-in point to the current curs...
void commitZone(std::unique_ptr< ZONE_CONTAINER > aZone)
Commit the current zone-in-progress to the BOARD.
std::unique_ptr< ZONE_CONTAINER > m_zone
The zone-in-progress
KIGFX::PREVIEW::POLYGON_ITEM m_previewItem
The preview item to display
LEADER_MODE GetLeaderMode() const
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
Unconstrained point-to-point
KIGFX::VIEW & m_parentView
view that show the preview item
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1490
const SHAPE_LINE_CHAIN & GetLockedInPoints() const
Get the "locked-in" points that describe the polygon itself.

References SHAPE_LINE_CHAIN::Append(), commitZone(), POLYGON_GEOM_MANAGER::DEG45, POLYGON_GEOM_MANAGER::GetLeaderLinePoints(), POLYGON_GEOM_MANAGER::GetLeaderMode(), POLYGON_GEOM_MANAGER::GetLockedInPoints(), m_parentView, m_previewItem, m_zone, SHAPE_POLY_SET::PM_FAST, and KIGFX::VIEW::SetVisible().

◆ OnFirstPoint()

bool ZONE_CREATE_HELPER::OnFirstPoint ( POLYGON_GEOM_MANAGER aMgr)
overridevirtual

Called before the first point is added - clients can do initialisation here, and can veto the start of the process (e.g.

if user cancels a dialog)

Returns
false to veto start of new polygon

Implements POLYGON_GEOM_MANAGER::CLIENT.

Definition at line 251 of file zone_create_helper.cpp.

252 {
253  // if we don't have a zone, create one
254  // the user's choice here can affect things like the colour of the preview
255  if( !m_zone )
256  {
257  if( m_params.m_sourceZone )
259  else
261 
262  if( m_zone )
263  {
265 
266  // set up poperties from zone
267  const auto& settings = *m_parentView.GetPainter()->GetSettings();
268  COLOR4D color = settings.GetColor( nullptr, m_zone->GetLayer() );
269 
271  m_previewItem.SetFillColor( color.WithAlpha( 0.2 ) );
272 
274 
277  }
278  }
279 
280  return m_zone != nullptr;
281 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
std::unique_ptr< ZONE_CONTAINER > createZoneFromExisting(const ZONE_CONTAINER &aSrcZone)
Function createZoneFromExisting.
void SetStrokeColor(const COLOR4D &aNewColor)
Set the stroke colour to set before drawing preview
int color
Definition: DXF_plotter.cpp:61
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:140
std::unique_ptr< ZONE_CONTAINER > m_zone
The zone-in-progress
KIGFX::PREVIEW::POLYGON_ITEM m_previewItem
The preview item to display
void SetLeaderMode(LEADER_MODE aMode)
Set the leader mode to use when calculating the leader/returner lines.
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:143
Unconstrained point-to-point
ZONE_CONTAINER * m_sourceZone
Zone settings source (for similar and cutout zones)
KIGFX::VIEW & m_parentView
view that show the preview item
void SetFillColor(const COLOR4D &aNewColor)
Set the fill colour to set before drawing preview
PARAMS & m_params
Parameters of the zone to be drawn
Definition: color4d.h:48
virtual RENDER_SETTINGS * GetSettings()=0
Function GetAdapter Returns pointer to current settings that are going to be used when drawing items.
std::unique_ptr< ZONE_CONTAINER > createNewZone(bool aKeepout)
Function createNewZone()
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1490
bool m_keepout
Should create a keepout zone?
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99

References color, createNewZone(), createZoneFromExisting(), POLYGON_GEOM_MANAGER::DEG45, POLYGON_GEOM_MANAGER::DIRECT, TOOL_BASE::GetManager(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), ZONE_CREATE_HELPER::PARAMS::m_keepout, m_params, m_parentView, m_previewItem, ZONE_CREATE_HELPER::PARAMS::m_sourceZone, m_tool, m_zone, TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectionClear, KIGFX::PREVIEW::SIMPLE_OVERLAY_ITEM::SetFillColor(), POLYGON_GEOM_MANAGER::SetLeaderMode(), KIGFX::PREVIEW::SIMPLE_OVERLAY_ITEM::SetStrokeColor(), KIGFX::VIEW::SetVisible(), and WHITE.

◆ OnGeometryChange()

void ZONE_CREATE_HELPER::OnGeometryChange ( const POLYGON_GEOM_MANAGER aMgr)
overridevirtual

Sent when the polygon geometry changes

Implements POLYGON_GEOM_MANAGER::CLIENT.

Definition at line 284 of file zone_create_helper.cpp.

285 {
286  // send the points to the preview item
289 }
const SHAPE_LINE_CHAIN & GetLeaderLinePoints() const
Get the points comprising the leader line (the line from the last locked-in point to the current curs...
KIGFX::PREVIEW::POLYGON_ITEM m_previewItem
The preview item to display
KIGFX::VIEW & m_parentView
view that show the preview item
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1544
void SetPoints(const SHAPE_LINE_CHAIN &aLockedInPts, const SHAPE_LINE_CHAIN &aLeaderPts)
Set the polygon points.
const SHAPE_LINE_CHAIN & GetLockedInPoints() const
Get the "locked-in" points that describe the polygon itself.
Color has changed.
Definition: view_item.h:59

References KIGFX::GEOMETRY, POLYGON_GEOM_MANAGER::GetLeaderLinePoints(), POLYGON_GEOM_MANAGER::GetLockedInPoints(), m_parentView, m_previewItem, KIGFX::PREVIEW::POLYGON_ITEM::SetPoints(), and KIGFX::VIEW::Update().

◆ performZoneCutout()

void ZONE_CREATE_HELPER::performZoneCutout ( ZONE_CONTAINER aZone,
ZONE_CONTAINER aCutout 
)

Function performZoneCutout()

Cut one zone out of another one (i.e. subtraction) and update the zone.

Parameters
aZonethe zone to removed area from
aCutoutthe area to remove

Definition at line 134 of file zone_create_helper.cpp.

135 {
136  BOARD_COMMIT commit( &m_tool );
137  BOARD* board = m_tool.getModel<BOARD>();
138  std::vector<ZONE_CONTAINER*> newZones;
139 
140  // Clear the selection before removing the old zone
141  auto toolMgr = m_tool.GetManager();
142  toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
143 
144  SHAPE_POLY_SET originalOutline( *aZone.Outline() );
145  originalOutline.BooleanSubtract( *aCutout.Outline(), SHAPE_POLY_SET::PM_FAST );
146 
147  // After substracting the hole, originalOutline can have more than one
148  // main outline.
149  // But a zone can have only one main outline, so create as many zones as
150  // originalOutline contains main outlines:
151  for( int outline = 0; outline < originalOutline.OutlineCount(); outline++ )
152  {
153  auto newZoneOutline = new SHAPE_POLY_SET;
154  newZoneOutline->AddOutline( originalOutline.Outline( outline ) );
155 
156  // Add holes (if any) to thez new zone outline:
157  for (int hole = 0; hole < originalOutline.HoleCount( outline ) ; hole++ )
158  newZoneOutline->AddHole( originalOutline.CHole( outline, hole ) );
159 
160  auto newZone = new ZONE_CONTAINER( aZone );
161  newZone->SetOutline( newZoneOutline );
162  newZone->SetLocalFlags( 1 );
163  newZone->Hatch();
164  newZones.push_back( newZone );
165  commit.Add( newZone );
166  }
167 
168  commit.Remove( &aZone );
169  commit.Push( _( "Add a zone cutout" ) );
170 
171  ZONE_FILLER filler( board );
172  filler.Fill( newZones );
173 
174  // Select the new zone and set it as the source for the next cutout
175  toolMgr->RunAction( PCB_ACTIONS::selectItem, true, newZones[0] );
176  m_params.m_sourceZone = newZones[0];
177 
178 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
T * getModel() const
Function getModel()
Definition: tool_base.h:201
SHAPE_POLY_SET * Outline()
Definition: class_zone.h:276
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:140
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:143
SHAPE_POLY_SET.
ZONE_CONTAINER * m_sourceZone
Zone settings source (for similar and cutout zones)
PARAMS & m_params
Parameters of the zone to be drawn
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:65
void BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Performs boolean polyset difference For aFastMode meaning, see function booleanOp

References _, COMMIT::Add(), SHAPE_POLY_SET::AddOutline(), SHAPE_POLY_SET::BooleanSubtract(), ZONE_FILLER::Fill(), TOOL_BASE::GetManager(), TOOL_BASE::getModel(), m_params, ZONE_CREATE_HELPER::PARAMS::m_sourceZone, m_tool, ZONE_CONTAINER::Outline(), SHAPE_POLY_SET::PM_FAST, BOARD_COMMIT::Push(), COMMIT::Remove(), TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectionClear, and PCB_ACTIONS::selectItem.

Referenced by commitZone().

Member Data Documentation

◆ m_params

PARAMS& ZONE_CREATE_HELPER::m_params
private

Parameters of the zone to be drawn

Definition at line 132 of file zone_create_helper.h.

Referenced by commitZone(), createNewZone(), OnFirstPoint(), and performZoneCutout().

◆ m_parentView

KIGFX::VIEW& ZONE_CREATE_HELPER::m_parentView
private

view that show the preview item

Definition at line 138 of file zone_create_helper.h.

Referenced by OnComplete(), OnFirstPoint(), OnGeometryChange(), ZONE_CREATE_HELPER(), and ~ZONE_CREATE_HELPER().

◆ m_previewItem

KIGFX::PREVIEW::POLYGON_ITEM ZONE_CREATE_HELPER::m_previewItem
private

The preview item to display

Definition at line 135 of file zone_create_helper.h.

Referenced by OnComplete(), OnFirstPoint(), OnGeometryChange(), ZONE_CREATE_HELPER(), and ~ZONE_CREATE_HELPER().

◆ m_tool

DRAWING_TOOL& ZONE_CREATE_HELPER::m_tool
private

◆ m_zone

std::unique_ptr<ZONE_CONTAINER> ZONE_CREATE_HELPER::m_zone
private

The zone-in-progress

Definition at line 141 of file zone_create_helper.h.

Referenced by OnComplete(), and OnFirstPoint().


The documentation for this class was generated from the following files: