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, const PARAMS &aParams)
 
 ~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 &aExistingZone, 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
 
const 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 ( DRAWING_TOOL aTool,
const PARAMS aParams 
)
Parameters
aToolthe DRAWING_TOOL to provide the zone tool to
aParamsthe parameters to use to guide the zone creation

Definition at line 39 of file zone_create_helper.cpp.

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

40  :
41  m_tool( aTool ),
42  m_params( aParams ),
43  m_parentView( *aTool.getView() )
44 {
46 }
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:35
const 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:334
ZONE_CREATE_HELPER::~ZONE_CREATE_HELPER ( )

Definition at line 49 of file zone_create_helper.cpp.

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

50 {
51  // remove the preview from the view
54 }
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:364
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:1445

Member Function Documentation

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 143 of file zone_create_helper.cpp.

References DRAWING_TOOL::ADD, DRAWING_TOOL::CUTOUT, ZONE_FILLER::Fill(), DRAWING_TOOL::getDrawingLayer(), TOOL_BASE::getEditFrame(), TOOL_BASE::getModel(), DRAWING_TOOL::GRAPHIC_POLYGON, ZONE_CONTAINER::Hatch(), PCB_TOOL::m_editModules, ZONE_CREATE_HELPER::PARAMS::m_keepout, ZONE_CREATE_HELPER::PARAMS::m_mode, m_params, ZONE_CREATE_HELPER::PARAMS::m_sourceZone, m_tool, performZoneCutout(), S_POLYGON, and DRAWING_TOOL::SIMILAR.

Referenced by OnComplete().

144 {
145  auto& frame = *m_tool.getEditFrame<PCB_EDIT_FRAME>();
146  auto board = m_tool.getModel<BOARD>();
147 
148  BOARD_COMMIT bCommit( &m_tool );
149 
150  switch ( m_params.m_mode )
151  {
153  // For cutouts, subtract from the source
154  bCommit.Modify( m_params.m_sourceZone );
156  bCommit.Push( _( "Add a zone cutout" ) );
158  break;
159 
162  aZone->Hatch();
163 
164  if( !m_params.m_keepout )
165  {
166  ZONE_FILLER filler( board );
167  filler.Fill( { aZone.get() } );
168  }
169 
170  bCommit.Add( aZone.release() );
171  bCommit.Push( _( "Add a zone" ) );
172  break;
173 
175  {
176  BOARD_ITEM_CONTAINER* parent = frame.GetModel();
177  auto poly = m_tool.m_editModules ? new EDGE_MODULE( (MODULE *) parent ) : new DRAWSEGMENT();
178 
179  poly->SetShape ( S_POLYGON );
180  poly->SetLayer( m_tool.getDrawingLayer() );
181  poly->SetPolyShape ( *aZone->Outline() );
182 
183  bCommit.Add( poly );
184  bCommit.Push( _( "Add a graphical polygon" ) );
185 
186  break;
187  }
188  }
189 }
void SetShape(STROKE_T aShape)
polygon (not yet used for tracks, but could be in microwave apps)
void performZoneCutout(ZONE_CONTAINER &aExistingZone, ZONE_CONTAINER &aCutout)
Function performZoneCutout()
Add a new zone with the same settings as an existing one.
T * getModel() const
Function getModel()
Definition: tool_base.h:199
ZONE_CONTAINER * m_sourceZone
Zone settings source (for similar and cutout zones)
DRAWING_TOOL::ZONE_MODE m_mode
The zone mode to operate in
bool m_editModules
Definition: pcb_tool.h:143
const PARAMS & m_params
Parameters of the zone to be drawn
PCB_LAYER_ID getDrawingLayer() const
Selects a non-copper layer for drawing
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
void Hatch()
Function Hatch computes the hatch lines depending on the hatch parameters and stores it in the zone&#39;s...
Abstract interface for BOARD_ITEMs capable of storing other items inside.
bool m_keepout
Should create a keepout zone?
Add a new zone/keepout with fresh settings.
Make a cutout to an existing zone.
T * getEditFrame() const
Function getEditFrame()
Definition: tool_base.h:188
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 57 of file zone_create_helper.cpp.

References TOOL_BASE::getEditFrame(), TOOL_BASE::getModel(), DRAWING_TOOL::GRAPHIC_POLYGON, InvokeCopperZonesEditor(), InvokeKeepoutAreaEditor(), InvokeNonCopperZonesEditor(), IsCopperLayer(), ZONE_SETTINGS::m_CurrentZone_Layer, ZONE_CREATE_HELPER::PARAMS::m_keepout, ZONE_CREATE_HELPER::PARAMS::m_mode, m_params, m_tool, and ZONE_ABORT.

Referenced by OnFirstPoint().

58 {
59  auto& frame = *m_tool.getEditFrame<PCB_BASE_EDIT_FRAME>();
60  auto& board = *m_tool.getModel<BOARD>();
61 
62  // Get the current default settings for zones
63  ZONE_SETTINGS zoneInfo = frame.GetZoneSettings();
64  zoneInfo.m_CurrentZone_Layer = frame.GetScreen()->m_Active_Layer;
65  zoneInfo.m_NetcodeSelection = board.GetHighLightNetCode();
66  zoneInfo.SetIsKeepout( m_params.m_keepout );
67 
69  {
70  // Get the current default settings for zones
71 
72  // Show options dialog
73  ZONE_EDIT_T dialogResult;
74 
75  if( m_params.m_keepout )
76  dialogResult = InvokeKeepoutAreaEditor( &frame, &zoneInfo );
77  else
78  {
79  if( IsCopperLayer( zoneInfo.m_CurrentZone_Layer ) )
80  dialogResult = InvokeCopperZonesEditor( &frame, &zoneInfo );
81  else
82  dialogResult = InvokeNonCopperZonesEditor( &frame, nullptr, &zoneInfo );
83  }
84 
85  if( dialogResult == ZONE_ABORT )
86  {
87  return nullptr;
88  }
89  }
90 
91  auto newZone = std::make_unique<ZONE_CONTAINER>( &board );
92 
93  // Apply the selected settings
94  zoneInfo.ExportSetting( *newZone );
95 
96  return newZone;
97 }
ZONE_EDIT_T
Exit codes for zone editing dialogs.
Definition: zones.h:47
T * getModel() const
Function getModel()
Definition: tool_base.h:199
if no change
Definition: zones.h:48
ZONE_EDIT_T InvokeNonCopperZonesEditor(PCB_BASE_FRAME *aParent, ZONE_CONTAINER *aZone, ZONE_SETTINGS *aSettings)
Function InvokeNonCopperZonesEditor invokes up a modal dialog window for non-copper zone editing...
DRAWING_TOOL::ZONE_MODE m_mode
The zone mode to operate in
Class ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:49
const PARAMS & m_params
Parameters of the zone to be drawn
Common, abstract interface for edit frames.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
ZONE_EDIT_T InvokeCopperZonesEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeCopperZonesEditor invokes up a modal dialog window for copper zone editing...
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
ZONE_EDIT_T InvokeKeepoutAreaEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeKeepoutAreaEditor invokes up a modal dialog window for copper zone editing...
bool m_keepout
Should create a keepout zone?
PCB_LAYER_ID m_CurrentZone_Layer
Layer used to create the current zone.
Definition: zone_settings.h:69
T * getEditFrame() const
Function getEditFrame()
Definition: tool_base.h:188
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 100 of file zone_create_helper.cpp.

References TOOL_BASE::getModel(), and m_tool.

Referenced by OnFirstPoint().

102 {
103  auto& board = *m_tool.getModel<BOARD>();
104 
105  auto newZone = std::make_unique<ZONE_CONTAINER>( &board );
106 
107  ZONE_SETTINGS zoneSettings;
108  zoneSettings << aSrcZone;
109 
110  zoneSettings.ExportSetting( *newZone );
111 
112  return newZone;
113 }
T * getModel() const
Function getModel()
Definition: tool_base.h:199
Class ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:49
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
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 238 of file zone_create_helper.cpp.

References commitZone(), POLYGON_GEOM_MANAGER::GetLockedInPoints(), i, m_parentView, m_previewItem, m_zone, and KIGFX::VIEW::SetVisible().

239 {
240  auto& finalPoints = aMgr.GetLockedInPoints();
241 
242  if( finalPoints.PointCount() < 3 )
243  {
244  // just scrap the zone in progress
245  m_zone = nullptr;
246  }
247  else
248  {
249  // if m_params.m_mode == DRAWING_TOOL::ZONE_MODE::CUTOUT, m_zone
250  // will be merged to the existing zone as a new hole.
251  m_zone->Outline()->NewOutline();
252  auto* outline = m_zone->Outline();
253 
254  for( int i = 0; i < finalPoints.PointCount(); ++i )
255  {
256  outline->Append( finalPoints.CPoint( i ) );
257  }
258 
259  outline->Outline( 0 ).SetClosed( true );
260  outline->RemoveNullSegments();
261 
262  // hand the zone over to the committer
263  commitZone( std::move( m_zone ) );
264  }
265 
267 }
const SHAPE_LINE_CHAIN & GetLockedInPoints() const
Get the "locked-in" points that describe the polygon itself.
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
KIGFX::VIEW & m_parentView
view that show the preview item
size_t i
Definition: json11.cpp:597
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1445
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 192 of file zone_create_helper.cpp.

References color, createNewZone(), createZoneFromExisting(), POLYGON_GEOM_MANAGER::DEG45, POLYGON_GEOM_MANAGER::DIRECT, 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_zone, KIGFX::PREVIEW::SIMPLE_OVERLAY_ITEM::SetFillColor(), POLYGON_GEOM_MANAGER::SetLeaderMode(), KIGFX::PREVIEW::SIMPLE_OVERLAY_ITEM::SetStrokeColor(), KIGFX::VIEW::SetVisible(), and KIGFX::COLOR4D::WithAlpha().

193 {
194  // if we don't have a zone, create one
195  // the user's choice here can affect things like the colour
196  // of the preview
197  if( !m_zone )
198  {
199  if( m_params.m_sourceZone )
201  else
203 
204  if( m_zone )
205  {
206  // set up poperties from zone
207  const auto& settings = *m_parentView.GetPainter()->GetSettings();
208  COLOR4D color = settings.GetColor( nullptr, m_zone->GetLayer() );
209 
210  m_previewItem.SetStrokeColor( color );
211  m_previewItem.SetFillColor( color.WithAlpha( 0.2 ) );
212 
214 
215  aMgr.SetLeaderMode( m_zone.get()->GetHV45()
218  }
219  }
220 
221  if( !m_zone )
222  {
223  return false;
224  }
225 
226  return true;
227 }
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:62
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.
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
COLOR4D WithAlpha(double aAlpha) const
Function WithAlpha Returns a colour with the same colour, but the given alpha.
Definition: color4d.h:237
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:196
void SetFillColor(const COLOR4D &aNewColor)
Set the fill colour to set before drawing preview
const PARAMS & m_params
Parameters of the zone to be drawn
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings 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:1445
bool m_keepout
Should create a keepout zone?
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
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 230 of file zone_create_helper.cpp.

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

231 {
232  // send the points to the preview item
235 }
const SHAPE_LINE_CHAIN & GetLockedInPoints() const
Get the "locked-in" points that describe the polygon itself.
KIGFX::PREVIEW::POLYGON_ITEM m_previewItem
The preview item to display
KIGFX::VIEW & m_parentView
view that show the preview item
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...
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:1499
void SetPoints(const SHAPE_LINE_CHAIN &aLockedInPts, const SHAPE_LINE_CHAIN &aLeaderPts)
Set the polygon points.
Color has changed.
Definition: view_item.h:57
void ZONE_CREATE_HELPER::performZoneCutout ( ZONE_CONTAINER aExistingZone,
ZONE_CONTAINER aCutout 
)

Function performZoneCutout()

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

Parameters
aExistingZonethe zone to removed area from
aCutoutthe area to remove

Definition at line 116 of file zone_create_helper.cpp.

References SHAPE_POLY_SET::Append(), ZONE_FILLER::Fill(), ZONE_CONTAINER::GetCornerPosition(), TOOL_BASE::getModel(), ZONE_CONTAINER::GetNumCorners(), SHAPE_POLY_SET::Hole(), ZONE_CONTAINER::IsFilled(), m_tool, SHAPE_POLY_SET::NewHole(), BOARD::OnAreaPolygonModified(), ZONE_CONTAINER::Outline(), and SHAPE_LINE_CHAIN::SetClosed().

Referenced by commitZone().

118 {
119  BOARD* board = m_tool.getModel<BOARD>();
120  int curr_hole = aExistingZone.Outline()->NewHole( 0 );
121 
122  // Copy cutout corners into existing zone, in the new hole
123  for( int ii = 0; ii < aCutout.GetNumCorners(); ii++ )
124  {
125  aExistingZone.Outline()->Append( aCutout.GetCornerPosition( ii ), 0, curr_hole );
126  }
127 
128  // Be sure the current corner list is closed
129  aExistingZone.Outline()->Hole( 0, curr_hole ).SetClosed( true );
130 
131  // Combine holes and simplify the new outline:
132  board->OnAreaPolygonModified( nullptr, &aExistingZone );
133 
134  // Re-fill if needed
135  if( aExistingZone.IsFilled() )
136  {
137  ZONE_FILLER filler( board );
138  filler.Fill( { &aExistingZone } );
139  }
140 }
int NewHole(int aOutline=-1)
Creates a new hole in a given outline
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition: class_zone.h:414
bool OnAreaPolygonModified(PICKED_ITEMS_LIST *aModifiedZonesList, ZONE_CONTAINER *modified_area)
Function OnAreaPolygonModified Process an area that has been modified, by normalizing its polygon and...
bool IsFilled() const
Definition: class_zone.h:189
SHAPE_POLY_SET * Outline()
Definition: class_zone.h:236
SHAPE_LINE_CHAIN & Hole(int aOutline, int aHole)
Returns the reference to aHole-th hole in the aIndex-th outline
const VECTOR2I & GetCornerPosition(int aCornerIndex) const
Definition: class_zone.h:454
void SetClosed(bool aClosed)
Function SetClosed()
T * getModel() const
Function getModel()
Definition: tool_base.h:199
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline) ...

Member Data Documentation

const PARAMS& ZONE_CREATE_HELPER::m_params
private

Parameters of the zone to be drawn

Definition at line 126 of file zone_create_helper.h.

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

KIGFX::VIEW& ZONE_CREATE_HELPER::m_parentView
private

view that show the preview item

Definition at line 132 of file zone_create_helper.h.

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

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

The preview item to display

Definition at line 129 of file zone_create_helper.h.

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

DRAWING_TOOL& ZONE_CREATE_HELPER::m_tool
private
std::unique_ptr<ZONE_CONTAINER> ZONE_CREATE_HELPER::m_zone
private

The zone-in-progress

Definition at line 135 of file zone_create_helper.h.

Referenced by OnComplete(), and OnFirstPoint().


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