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 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 ()
 
ZONEGetZone () const
 
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< ZONEcreateNewZone (bool aKeepout)
 Function createNewZone() More...
 
std::unique_ptr< ZONEcreateZoneFromExisting (const ZONE &aSrcZone)
 Function createZoneFromExisting. More...
 
void performZoneCutout (ZONE &aZone, ZONE &aCutout)
 Function performZoneCutout() More...
 
void commitZone (std::unique_ptr< ZONE > 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< ZONEm_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 based on given parameters.

Definition at line 42 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:327

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:357
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:1459

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

194 {
195  switch ( m_params.m_mode )
196  {
197  case ZONE_MODE::CUTOUT:
198  // For cutouts, subtract from the source
200  break;
201 
202  case ZONE_MODE::ADD:
203  case ZONE_MODE::SIMILAR:
204  {
205  BOARD_COMMIT bCommit( &m_tool );
206 
207  aZone->HatchBorder();
208  bCommit.Add( aZone.get() );
209 
210  if( !m_params.m_keepout )
211  {
212  ZONE_FILLER filler( m_tool.getModel<BOARD>(), &bCommit );
213  std::vector<ZONE*> toFill = { aZone.get() };
214 
215  if( !filler.Fill( toFill ) )
216  {
217  bCommit.Revert();
218  break;
219  }
220  }
221 
222  bCommit.Push( _( "Add a zone" ) );
223  m_tool.GetManager()->RunAction( PCB_ACTIONS::selectItem, true, aZone.release() );
224  break;
225  }
226 
228  {
229  BOARD_COMMIT bCommit( &m_tool );
231  LSET graphicPolygonsLayers = LSET::AllLayersMask();
232 
233  graphicPolygonsLayers.reset( Edge_Cuts ).reset( F_CrtYd ).reset( B_CrtYd );
234 
235  if( graphicPolygonsLayers.Contains( m_params.m_layer ) )
236  {
237  auto poly = m_tool.m_isFootprintEditor ? new FP_SHAPE( (FOOTPRINT *) parent )
238  : new PCB_SHAPE();
239  poly->SetShape( S_POLYGON );
240  poly->SetFilled( m_params.m_layer != Edge_Cuts );
241  poly->SetLayer( m_params.m_layer );
242  poly->SetPolyShape ( *aZone->Outline() );
243  bCommit.Add( poly );
245  }
246  else
247  {
248  SHAPE_POLY_SET* outline = aZone->Outline();
249 
250  for( auto seg = outline->CIterateSegments( 0 ); seg; seg++ )
251  {
252  auto* new_seg = m_tool.m_isFootprintEditor ? new FP_SHAPE( (FOOTPRINT *) parent )
253  : new PCB_SHAPE();
254  new_seg->SetShape( S_SEGMENT );
255  new_seg->SetLayer( m_params.m_layer );
256  new_seg->SetStart( wxPoint( seg.Get().A.x, seg.Get().A.y ) );
257  new_seg->SetEnd( wxPoint( seg.Get().B.x, seg.Get().B.y ) );
258  bCommit.Add( new_seg );
259  }
260  }
261 
262  bCommit.Push( _( "Add a graphical polygon" ) );
263 
264  break;
265  }
266  }
267 }
Add a new zone with the same settings as an existing one.
T * getModel() const
Function getModel()
Definition: tool_base.h:201
ZONE * m_sourceZone
Zone settings source (for similar and cutout zones)
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)
Definition: board_item.h:56
void performZoneCutout(ZONE &aZone, ZONE &aCutout)
Function performZoneCutout()
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:141
usual segment : line with rounded ends
Definition: board_item.h:52
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:143
LSET is a set of PCB_LAYER_IDs.
void SetShape(PCB_SHAPE_TYPE_T aShape)
Definition: pcb_shape.h:128
SHAPE_POLY_SET.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
Add a new zone/keepout with fresh settings.
static LSET AllLayersMask()
Definition: lset.cpp:787
bool m_isFootprintEditor
Make a cutout to an existing zone.
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:229
PARAMS & m_params
Parameters of the zone to be drawn
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
Function GetModel()
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:186
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:65
CONST_SEGMENT_ITERATOR CIterateSegments(int aFirst, int aLast, bool aIterateHoles=false) const
Returns an iterator object, for iterating between aFirst and aLast outline, with or without holes (de...
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, SHAPE_POLY_SET::CIterateSegments(), LSET::Contains(), CUTOUT, Edge_Cuts, F_CrtYd, ZONE_FILLER::Fill(), TOOL_BASE::GetManager(), TOOL_BASE::getModel(), PCB_BASE_FRAME::GetModel(), GRAPHIC_POLYGON, DRAWING_TOOL::m_frame, PCB_TOOL_BASE::m_isFootprintEditor, 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, SHAPE_POLY_SET::Outline(), performZoneCutout(), BOARD_COMMIT::Push(), BOARD_COMMIT::Revert(), TOOL_MANAGER::RunAction(), S_POLYGON, S_SEGMENT, PCB_ACTIONS::selectItem, and SIMILAR.

Referenced by OnComplete().

◆ createNewZone()

std::unique_ptr< ZONE > 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 {
55  BOARD* board = frame->GetBoard();
58  std::set<int> highlightedNets = board->GetHighLightNetCodes();
59 
60  // Get the current default settings for zones
61  ZONE_SETTINGS zoneInfo = frame->GetZoneSettings();
62  zoneInfo.m_Layers.reset().set( m_params.m_layer ); // TODO(JE) multilayer defaults?
63  zoneInfo.m_NetcodeSelection = highlightedNets.empty() ? -1 : *highlightedNets.begin();
64  zoneInfo.SetIsRuleArea( 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 = InvokeRuleAreaEditor( 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 if created in the board editor and a FP_ZONE if created in the
104  // footprint editor
105  wxASSERT( !m_tool.m_isFootprintEditor || ( parent->Type() == PCB_FOOTPRINT_T ) );
106 
107  std::unique_ptr<ZONE> newZone = m_tool.m_isFootprintEditor ?
108  std::make_unique<FP_ZONE>( parent ) :
109  std::make_unique<ZONE>( parent );
110 
111  // Apply the selected settings
112  zoneInfo.ExportSetting( *newZone );
113 
114  return newZone;
115 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:750
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:58
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
Definition: zone_settings.h:93
virtual void WarpCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false)=0
Function WarpCursor() If enabled (.
Unconstrained point-to-point
void ExportSetting(ZONE &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
const ZONE_SETTINGS & GetZoneSettings() const
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:131
VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (such a...
ZONE handles a list of polygons defining a copper zone.
Definition: zone.h:57
void SetIsRuleArea(bool aEnable)
bool m_isFootprintEditor
int InvokeRuleAreaEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeRuleAreaEditor invokes up a modal dialog window for copper zone editing.
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:120
class FOOTPRINT, a footprint
Definition: typeinfo.h:89
PCB_BASE_EDIT_FRAME * m_frame
Definition: drawing_tool.h:229
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:292
Common, abstract interface for edit frames.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:186
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
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.
BOARD * GetBoard() const
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.
KICAD_T Type() const
Function Type()
Definition: eda_item.h:181

References LSET::AllCuMask(), POLYGON_GEOM_MANAGER::DEG45, SELECTION::Empty(), ZONE_SETTINGS::ExportSetting(), PCB_BASE_FRAME::GetBoard(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), TOOL_BASE::getEditFrame(), SELECTION::GetItems(), TOOL_BASE::GetManager(), PCB_BASE_FRAME::GetModel(), SELECTION_TOOL::GetSelection(), TOOL_MANAGER::GetTool(), TOOL_MANAGER::GetViewControls(), PCB_BASE_FRAME::GetZoneSettings(), GRAPHIC_POLYGON, InvokeCopperZonesEditor(), InvokeNonCopperZonesEditor(), InvokeRuleAreaEditor(), DRAWING_TOOL::m_frame, PCB_TOOL_BASE::m_isFootprintEditor, 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_FOOTPRINT_T, ZONE_SETTINGS::SetIsRuleArea(), EDA_ITEM::Type(), and KIGFX::VIEW_CONTROLS::WarpCursor().

Referenced by OnFirstPoint().

◆ createZoneFromExisting()

std::unique_ptr< ZONE > ZONE_CREATE_HELPER::createZoneFromExisting ( const ZONE 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.

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

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

Referenced by OnFirstPoint().

◆ GetZone()

ZONE* ZONE_CREATE_HELPER::GetZone ( ) const
inline

Definition at line 75 of file zone_create_helper.h.

75 { return m_zone.get(); }
std::unique_ptr< ZONE > m_zone
The zone-in-progress

References m_zone.

Referenced by DRAWING_TOOL::DrawZone().

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

312 {
313  auto& finalPoints = aMgr.GetLockedInPoints();
314 
315  if( finalPoints.PointCount() < 3 )
316  {
317  // just scrap the zone in progress
318  m_zone = nullptr;
319  }
320  else
321  {
322  // if m_params.m_mode == DRAWING_TOOL::ZONE_MODE::CUTOUT, m_zone
323  // will be merged to the existing zone as a new hole.
324  m_zone->Outline()->NewOutline();
325  auto* outline = m_zone->Outline();
326 
327  for( int i = 0; i < finalPoints.PointCount(); ++i )
328  outline->Append( finalPoints.CPoint( i ) );
329 
330  // In DEG45 mode, we may have intermediate points in the leader that should be
331  // included as they are shown in the preview. These typically maintain the
332  // 45 constraint
334  {
335  const auto& pts = aMgr.GetLeaderLinePoints();
336  for( int i = 1; i < pts.PointCount(); i++ )
337  outline->Append( pts.CPoint( i ) );
338  }
339 
340  outline->Outline( 0 ).SetClosed( true );
341  outline->RemoveNullSegments();
342  outline->Simplify( SHAPE_POLY_SET::PM_FAST );
343 
344  // hand the zone over to the committer
345  commitZone( std::move( m_zone ) );
346  m_zone = nullptr;
347  }
348 
350 }
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
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 commitZone(std::unique_ptr< ZONE > aZone)
Commit the current zone-in-progress to the BOARD.
std::unique_ptr< ZONE > m_zone
The zone-in-progress
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1459
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 270 of file zone_create_helper.cpp.

271 {
272  // if we don't have a zone, create one
273  // the user's choice here can affect things like the colour of the preview
274  if( !m_zone )
275  {
276  if( m_params.m_sourceZone )
278  else
280 
281  if( m_zone )
282  {
284 
285  // set up poperties from zone
286  const auto& settings = *m_parentView.GetPainter()->GetSettings();
287  COLOR4D color = settings.GetColor( nullptr, m_zone->GetLayer() );
288 
290  m_previewItem.SetFillColor( color.WithAlpha( 0.2 ) );
291 
293 
296  }
297  }
298 
299  return m_zone != nullptr;
300 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
ZONE * m_sourceZone
Zone settings source (for similar and cutout zones)
void SetStrokeColor(const COLOR4D &aNewColor)
Set the stroke colour to set before drawing preview
int color
Definition: DXF_plotter.cpp:60
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
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:201
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
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:49
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 > createZoneFromExisting(const ZONE &aSrcZone)
Function createZoneFromExisting.
std::unique_ptr< ZONE > m_zone
The zone-in-progress
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1459
std::unique_ptr< ZONE > createNewZone(bool aKeepout)
Function createNewZone()
bool m_keepout
Should create a keepout zone?
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100

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

304 {
305  // send the points to the preview item
308 }
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
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.
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1513
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().

Referenced by DRAWING_TOOL::DrawZone().

◆ performZoneCutout()

void ZONE_CREATE_HELPER::performZoneCutout ( ZONE aZone,
ZONE 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 133 of file zone_create_helper.cpp.

134 {
135  BOARD_COMMIT commit( &m_tool );
136  BOARD* board = m_tool.getModel<BOARD>();
137  std::vector<ZONE*> newZones;
138 
139  // Clear the selection before removing the old zone
140  auto toolMgr = m_tool.GetManager();
141  toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
142 
143  SHAPE_POLY_SET originalOutline( *aZone.Outline() );
144  originalOutline.BooleanSubtract( *aCutout.Outline(), SHAPE_POLY_SET::PM_FAST );
145 
146  // After substracting the hole, originalOutline can have more than one
147  // main outline.
148  // But a zone can have only one main outline, so create as many zones as
149  // originalOutline contains main outlines:
150  for( int outline = 0; outline < originalOutline.OutlineCount(); outline++ )
151  {
152  auto newZoneOutline = new SHAPE_POLY_SET;
153  newZoneOutline->AddOutline( originalOutline.Outline( outline ) );
154 
155  // Add holes (if any) to thez new zone outline:
156  for (int hole = 0; hole < originalOutline.HoleCount( outline ) ; hole++ )
157  newZoneOutline->AddHole( originalOutline.CHole( outline, hole ) );
158 
159  auto newZone = new ZONE( aZone );
160  newZone->SetOutline( newZoneOutline );
161  newZone->SetLocalFlags( 1 );
162  newZone->HatchBorder();
163  newZones.push_back( newZone );
164  commit.Add( newZone );
165  }
166 
167  commit.Remove( &aZone );
168 
169  ZONE_FILLER filler( board, &commit );
170 
171  if( !filler.Fill( newZones ) )
172  {
173  commit.Revert();
174  return;
175  }
176 
177  commit.Push( _( "Add a zone cutout" ) );
178 
179  // Select the new zone and set it as the source for the next cutout
180  if( newZones.empty() )
181  {
182  m_params.m_sourceZone = nullptr;
183  }
184  else
185  {
186  m_params.m_sourceZone = newZones[0];
187  toolMgr->RunAction( PCB_ACTIONS::selectItem, true, newZones[0] );
188  }
189 
190 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
T * getModel() const
Function getModel()
Definition: tool_base.h:201
ZONE * m_sourceZone
Zone settings source (for similar and cutout zones)
SHAPE_POLY_SET * Outline()
Definition: zone.h:318
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
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 handles a list of polygons defining a copper zone.
Definition: zone.h:57
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
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:186
#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::Outline(), SHAPE_POLY_SET::PM_FAST, BOARD_COMMIT::Push(), COMMIT::Remove(), BOARD_COMMIT::Revert(), 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 133 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 139 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 136 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> ZONE_CREATE_HELPER::m_zone
private

The zone-in-progress

Definition at line 142 of file zone_create_helper.h.

Referenced by GetZone(), OnComplete(), and OnFirstPoint().


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