KiCad PCB EDA Suite
Loading...
Searching...
No Matches
item_modification_routine.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef ITEM_MODIFICATION_ROUTINE_H_
21#define ITEM_MODIFICATION_ROUTINE_H_
22
23#include <functional>
24#include <memory>
25#include <optional>
26#include <vector>
27
28#include <board_item.h>
29#include <pcb_shape.h>
30
33
44{
45public:
60 {
61 public:
62 virtual ~CHANGE_HANDLER() = default;
63
69 virtual void AddNewItem( std::unique_ptr<BOARD_ITEM> aItem ) = 0;
70
76 virtual void MarkItemModified( BOARD_ITEM& aItem ) = 0;
77
83 virtual void DeleteItem( BOARD_ITEM& aItem ) = 0;
84 };
85
91 {
92 public:
98 using CREATION_HANDLER = std::function<void( std::unique_ptr<BOARD_ITEM> )>;
99
105 using MODIFICATION_HANDLER = std::function<void( BOARD_ITEM& )>;
106
112 using DELETION_HANDLER = std::function<void( BOARD_ITEM& )>;
113
115 MODIFICATION_HANDLER aModificationHandler,
116 DELETION_HANDLER aDeletionHandler ) :
117 m_creationHandler( std::move( aCreationHandler ) ),
118 m_modificationHandler( std::move( aModificationHandler ) ),
119 m_deletionHandler( std::move( aDeletionHandler ) )
120 {
121 }
122
128 void AddNewItem( std::unique_ptr<BOARD_ITEM> aItem ) override
129 {
130 m_creationHandler( std::move( aItem ) );
131 }
132
138 void MarkItemModified( BOARD_ITEM& aItem ) override { m_modificationHandler( aItem ); }
139
145 void DeleteItem( BOARD_ITEM& aItem ) override { m_deletionHandler( aItem ); }
146
150 };
151
153 m_board( aBoard ),
154 m_handler( aHandler ),
155 m_numSuccesses( 0 ),
156 m_numFailures( 0 )
157 {
158 }
159
160 virtual ~ITEM_MODIFICATION_ROUTINE() = default;
161
162 unsigned GetSuccesses() const { return m_numSuccesses; }
163
164 unsigned GetFailures() const { return m_numFailures; }
165
166 virtual wxString GetCommitDescription() const = 0;
167
168protected:
172 BOARD_ITEM* GetBoard() const { return m_board; }
173
178
183
191 bool ModifyLineOrDeleteIfZeroLength( PCB_SHAPE& aItem, const std::optional<SEG>& aSeg );
192
198 void SplitCornerConstraint( const CONSTRAINT_MEMBER& aCornerA, const CONSTRAINT_MEMBER& aCornerB,
199 const CONSTRAINT_MEMBER& aInsertedForA, const CONSTRAINT_MEMBER& aInsertedForB );
200
205
206private:
209
212};
213
218{
219public:
221 ITEM_MODIFICATION_ROUTINE( aBoard, aHandler )
222 {
223 }
224
239 virtual void ProcessLinePair( PCB_SHAPE& aLineA, PCB_SHAPE& aLineB ) = 0;
240
246 virtual std::optional<wxString> GetStatusMessage( int aSegmentCount ) const = 0;
247};
248
253{
254public:
255 LINE_FILLET_ROUTINE( BOARD_ITEM* aBoard, CHANGE_HANDLER& aHandler, int filletRadiusIU ) :
256 PAIRWISE_LINE_ROUTINE( aBoard, aHandler ),
257 m_filletRadiusIU( filletRadiusIU )
258 {
259 }
260
261 wxString GetCommitDescription() const override;
262 std::optional<wxString> GetStatusMessage( int aSegmentCount ) const override;
263
264 void ProcessLinePair( PCB_SHAPE& aLineA, PCB_SHAPE& aLineB ) override;
265
266private:
268};
269
274{
275public:
277 CHAMFER_PARAMS aChamferParams ) :
278 PAIRWISE_LINE_ROUTINE( aBoard, aHandler ),
279 m_chamferParams( std::move( aChamferParams ) )
280 {
281 }
282
283 wxString GetCommitDescription() const override;
284 std::optional<wxString> GetStatusMessage( int aSegmentCount ) const override;
285
286 void ProcessLinePair( PCB_SHAPE& aLineA, PCB_SHAPE& aLineB ) override;
287
288private:
290};
291
296{
297public:
299 PAIRWISE_LINE_ROUTINE( aBoard, aHandler )
300 {
301 }
302
303 wxString GetCommitDescription() const override;
304 std::optional<wxString> GetStatusMessage( int aSegmentCount ) const override;
305
306 void ProcessLinePair( PCB_SHAPE& aLineA, PCB_SHAPE& aLineB ) override;
307};
308
313{
314public:
316 {
319 };
320
322 PAIRWISE_LINE_ROUTINE( aBoard, aHandler ),
323 m_params( std::move( aParams ) ),
324 m_haveNarrowMouths( false )
325 {
326 }
327
328 wxString GetCommitDescription() const override;
329 std::optional<wxString> GetStatusMessage( int aSegmentCount ) const override;
330
331 void ProcessLinePair( PCB_SHAPE& aLineA, PCB_SHAPE& aLineB ) override;
332
333private:
336};
337
338
343{
344public:
346 ITEM_MODIFICATION_ROUTINE( aBoard, aHandler )
347 {
348 }
349
353 virtual bool IsCommutative() const = 0;
354
355 void ProcessShape( PCB_SHAPE& aPcbShape );
356
360 void Finalize();
361
367 virtual std::optional<wxString> GetStatusMessage() const = 0;
368
369protected:
371
372 virtual bool ProcessSubsequentPolygon( const SHAPE_POLY_SET& aPolygon ) = 0;
373
374private:
377
378 bool m_firstPolygon = true;
379 int m_width = 0;
382};
383
385{
386public:
388 POLYGON_BOOLEAN_ROUTINE( aBoard, aHandler )
389 {
390 }
391
392 bool IsCommutative() const override { return true; }
393
394 wxString GetCommitDescription() const override;
395 std::optional<wxString> GetStatusMessage() const override;
396
397private:
398 bool ProcessSubsequentPolygon( const SHAPE_POLY_SET& aPolygon ) override;
399};
400
401
403{
404public:
406 POLYGON_BOOLEAN_ROUTINE( aBoard, aHandler )
407 {
408 }
409
410 bool IsCommutative() const override { return false; }
411
412 wxString GetCommitDescription() const override;
413 std::optional<wxString> GetStatusMessage() const override;
414
415private:
416 bool ProcessSubsequentPolygon( const SHAPE_POLY_SET& aPolygon ) override;
417};
418
419
421{
422public:
424 POLYGON_BOOLEAN_ROUTINE( aBoard, aHandler )
425 {
426 }
427
428 bool IsCommutative() const override { return true; }
429
430 wxString GetCommitDescription() const override;
431 std::optional<wxString> GetStatusMessage() const override;
432
433private:
434 bool ProcessSubsequentPolygon( const SHAPE_POLY_SET& aPolygon ) override;
435};
436
437
439{
440public:
452
453 OUTSET_ROUTINE( BOARD_ITEM* aBoard, CHANGE_HANDLER& aHandler, const PARAMETERS& aParams ) :
454 ITEM_MODIFICATION_ROUTINE( aBoard, aHandler ),
455 m_params( aParams )
456 {
457 }
458
459 wxString GetCommitDescription() const override;
460
461 std::optional<wxString> GetStatusMessage() const;
462
463 void ProcessItem( BOARD_ITEM& aItem );
464
465private:
467};
468
469#endif /* ITEM_MODIFICATION_ROUTINE_H_ */
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:85
std::optional< wxString > GetStatusMessage(int aSegmentCount) const override
Get a status message to show when the routine is complete.
DOGBONE_CORNER_ROUTINE(BOARD_ITEM *aBoard, CHANGE_HANDLER &aHandler, PARAMETERS aParams)
wxString GetCommitDescription() const override
void ProcessLinePair(PCB_SHAPE &aLineA, PCB_SHAPE &aLineB) override
Perform the action on the pair of lines given.
void MarkItemModified(BOARD_ITEM &aItem) override
Report that the tool has modified an item on the board.
std::function< void(BOARD_ITEM &)> MODIFICATION_HANDLER
Handler for modifying or deleting an existing item on the board.
std::function< void(std::unique_ptr< BOARD_ITEM >)> CREATION_HANDLER
Handler for creating a new item on the board.
CALLABLE_BASED_HANDLER(CREATION_HANDLER aCreationHandler, MODIFICATION_HANDLER aModificationHandler, DELETION_HANDLER aDeletionHandler)
void DeleteItem(BOARD_ITEM &aItem) override
Report that the tool has deleted an item on the board.
void AddNewItem(std::unique_ptr< BOARD_ITEM > aItem) override
Report that the tools wants to add a new item to the board.
std::function< void(BOARD_ITEM &)> DELETION_HANDLER
Handler for modifying or deleting an existing item on the board.
Handlers for receiving changes from the tool.
virtual void MarkItemModified(BOARD_ITEM &aItem)=0
Report that the tool has modified an item on the board.
virtual void DeleteItem(BOARD_ITEM &aItem)=0
Report that the tool has deleted an item on the board.
virtual void AddNewItem(std::unique_ptr< BOARD_ITEM > aItem)=0
Report that the tools wants to add a new item to the board.
ITEM_MODIFICATION_ROUTINE(BOARD_ITEM *aBoard, CHANGE_HANDLER &aHandler)
void SplitCornerConstraint(const CONSTRAINT_MEMBER &aCornerA, const CONSTRAINT_MEMBER &aCornerB, const CONSTRAINT_MEMBER &aInsertedForA, const CONSTRAINT_MEMBER &aInsertedForB)
Hold each line to a shape just inserted at their shared corner, in place of the coincident constraint...
void AddFailure()
Mark that one of the actions failed.
virtual wxString GetCommitDescription() const =0
void AddSuccess()
Mark that one of the actions succeeded.
bool ModifyLineOrDeleteIfZeroLength(PCB_SHAPE &aItem, const std::optional< SEG > &aSeg)
Helper function useful for multiple tools: modify a line or delete it if it has zero length.
BOARD_ITEM * GetBoard() const
The BOARD used when creating new shapes.
virtual ~ITEM_MODIFICATION_ROUTINE()=default
CHANGE_HANDLER & GetHandler()
Access the handler for making changes to the board.
std::optional< wxString > GetStatusMessage(int aSegmentCount) const override
Get a status message to show when the routine is complete.
wxString GetCommitDescription() const override
void ProcessLinePair(PCB_SHAPE &aLineA, PCB_SHAPE &aLineB) override
Perform the action on the pair of lines given.
const CHAMFER_PARAMS m_chamferParams
LINE_CHAMFER_ROUTINE(BOARD_ITEM *aBoard, CHANGE_HANDLER &aHandler, CHAMFER_PARAMS aChamferParams)
wxString GetCommitDescription() const override
std::optional< wxString > GetStatusMessage(int aSegmentCount) const override
Get a status message to show when the routine is complete.
LINE_EXTENSION_ROUTINE(BOARD_ITEM *aBoard, CHANGE_HANDLER &aHandler)
void ProcessLinePair(PCB_SHAPE &aLineA, PCB_SHAPE &aLineB) override
Perform the action on the pair of lines given.
std::optional< wxString > GetStatusMessage(int aSegmentCount) const override
Get a status message to show when the routine is complete.
wxString GetCommitDescription() const override
void ProcessLinePair(PCB_SHAPE &aLineA, PCB_SHAPE &aLineB) override
Perform the action on the pair of lines given.
LINE_FILLET_ROUTINE(BOARD_ITEM *aBoard, CHANGE_HANDLER &aHandler, int filletRadiusIU)
void ProcessItem(BOARD_ITEM &aItem)
OUTSET_ROUTINE(BOARD_ITEM *aBoard, CHANGE_HANDLER &aHandler, const PARAMETERS &aParams)
wxString GetCommitDescription() const override
std::optional< wxString > GetStatusMessage() const
PAIRWISE_LINE_ROUTINE(BOARD_ITEM *aBoard, CHANGE_HANDLER &aHandler)
virtual std::optional< wxString > GetStatusMessage(int aSegmentCount) const =0
Get a status message to show when the routine is complete.
virtual void ProcessLinePair(PCB_SHAPE &aLineA, PCB_SHAPE &aLineB)=0
Perform the action on the pair of lines given.
virtual bool IsCommutative() const =0
False if the order of the polygons matters.
SHAPE_POLY_SET m_workingPolygons
This can be disjoint, which will be fixed at the end.
void Finalize()
Clear up any outstanding work.
virtual std::optional< wxString > GetStatusMessage() const =0
Get a status message to show when the routine is complete.
POLYGON_BOOLEAN_ROUTINE(BOARD_ITEM *aBoard, CHANGE_HANDLER &aHandler)
void ProcessShape(PCB_SHAPE &aPcbShape)
virtual bool ProcessSubsequentPolygon(const SHAPE_POLY_SET &aPolygon)=0
bool IsCommutative() const override
False if the order of the polygons matters.
std::optional< wxString > GetStatusMessage() const override
Get a status message to show when the routine is complete.
wxString GetCommitDescription() const override
POLYGON_INTERSECT_ROUTINE(BOARD_ITEM *aBoard, CHANGE_HANDLER &aHandler)
bool ProcessSubsequentPolygon(const SHAPE_POLY_SET &aPolygon) override
bool ProcessSubsequentPolygon(const SHAPE_POLY_SET &aPolygon) override
wxString GetCommitDescription() const override
std::optional< wxString > GetStatusMessage() const override
Get a status message to show when the routine is complete.
POLYGON_MERGE_ROUTINE(BOARD_ITEM *aBoard, CHANGE_HANDLER &aHandler)
bool IsCommutative() const override
False if the order of the polygons matters.
bool IsCommutative() const override
False if the order of the polygons matters.
wxString GetCommitDescription() const override
POLYGON_SUBTRACT_ROUTINE(BOARD_ITEM *aBoard, CHANGE_HANDLER &aHandler)
std::optional< wxString > GetStatusMessage() const override
Get a status message to show when the routine is complete.
bool ProcessSubsequentPolygon(const SHAPE_POLY_SET &aPolygon) override
Represent a set of closed polygons.
FILL_T
Definition eda_fill.h:29
@ NO_FILL
Definition eda_fill.h:30
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
STL namespace.
Parameters that define a simple chamfer operation.
One participant in a constraint: a referenced board item plus the feature of that item that participa...