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
32
43{
44public:
59 {
60 public:
61 virtual ~CHANGE_HANDLER() = default;
62
68 virtual void AddNewItem( std::unique_ptr<BOARD_ITEM> aItem ) = 0;
69
75 virtual void MarkItemModified( BOARD_ITEM& aItem ) = 0;
76
82 virtual void DeleteItem( BOARD_ITEM& aItem ) = 0;
83 };
84
90 {
91 public:
97 using CREATION_HANDLER = std::function<void( std::unique_ptr<BOARD_ITEM> )>;
98
104 using MODIFICATION_HANDLER = std::function<void( BOARD_ITEM& )>;
105
111 using DELETION_HANDLER = std::function<void( BOARD_ITEM& )>;
112
114 MODIFICATION_HANDLER aModificationHandler,
115 DELETION_HANDLER aDeletionHandler ) :
116 m_creationHandler( std::move( aCreationHandler ) ),
117 m_modificationHandler( std::move( aModificationHandler ) ),
118 m_deletionHandler( std::move( aDeletionHandler ) )
119 {
120 }
121
127 void AddNewItem( std::unique_ptr<BOARD_ITEM> aItem ) override
128 {
129 m_creationHandler( std::move( aItem ) );
130 }
131
137 void MarkItemModified( BOARD_ITEM& aItem ) override { m_modificationHandler( aItem ); }
138
144 void DeleteItem( BOARD_ITEM& aItem ) override { m_deletionHandler( aItem ); }
145
149 };
150
152 m_board( aBoard ),
153 m_handler( aHandler ),
154 m_numSuccesses( 0 ),
155 m_numFailures( 0 )
156 {
157 }
158
159 virtual ~ITEM_MODIFICATION_ROUTINE() = default;
160
161 unsigned GetSuccesses() const { return m_numSuccesses; }
162
163 unsigned GetFailures() const { return m_numFailures; }
164
165 virtual wxString GetCommitDescription() const = 0;
166
167protected:
171 BOARD_ITEM* GetBoard() const { return m_board; }
172
177
182
190 bool ModifyLineOrDeleteIfZeroLength( PCB_SHAPE& aItem, const std::optional<SEG>& aSeg );
191
196
197private:
200
203};
204
209{
210public:
212 ITEM_MODIFICATION_ROUTINE( aBoard, aHandler )
213 {
214 }
215
230 virtual void ProcessLinePair( PCB_SHAPE& aLineA, PCB_SHAPE& aLineB ) = 0;
231
237 virtual std::optional<wxString> GetStatusMessage( int aSegmentCount ) const = 0;
238};
239
244{
245public:
246 LINE_FILLET_ROUTINE( BOARD_ITEM* aBoard, CHANGE_HANDLER& aHandler, int filletRadiusIU ) :
247 PAIRWISE_LINE_ROUTINE( aBoard, aHandler ),
248 m_filletRadiusIU( filletRadiusIU )
249 {
250 }
251
252 wxString GetCommitDescription() const override;
253 std::optional<wxString> GetStatusMessage( int aSegmentCount ) const override;
254
255 void ProcessLinePair( PCB_SHAPE& aLineA, PCB_SHAPE& aLineB ) override;
256
257private:
259};
260
265{
266public:
268 CHAMFER_PARAMS aChamferParams ) :
269 PAIRWISE_LINE_ROUTINE( aBoard, aHandler ),
270 m_chamferParams( std::move( aChamferParams ) )
271 {
272 }
273
274 wxString GetCommitDescription() const override;
275 std::optional<wxString> GetStatusMessage( int aSegmentCount ) const override;
276
277 void ProcessLinePair( PCB_SHAPE& aLineA, PCB_SHAPE& aLineB ) override;
278
279private:
281};
282
287{
288public:
290 PAIRWISE_LINE_ROUTINE( aBoard, aHandler )
291 {
292 }
293
294 wxString GetCommitDescription() const override;
295 std::optional<wxString> GetStatusMessage( int aSegmentCount ) const override;
296
297 void ProcessLinePair( PCB_SHAPE& aLineA, PCB_SHAPE& aLineB ) override;
298};
299
304{
305public:
307 {
310 };
311
313 PAIRWISE_LINE_ROUTINE( aBoard, aHandler ),
314 m_params( std::move( aParams ) ),
315 m_haveNarrowMouths( false )
316 {
317 }
318
319 wxString GetCommitDescription() const override;
320 std::optional<wxString> GetStatusMessage( int aSegmentCount ) const override;
321
322 void ProcessLinePair( PCB_SHAPE& aLineA, PCB_SHAPE& aLineB ) override;
323
324private:
327};
328
329
334{
335public:
337 ITEM_MODIFICATION_ROUTINE( aBoard, aHandler )
338 {
339 }
340
344 virtual bool IsCommutative() const = 0;
345
346 void ProcessShape( PCB_SHAPE& aPcbShape );
347
351 void Finalize();
352
358 virtual std::optional<wxString> GetStatusMessage() const = 0;
359
360protected:
362
363 virtual bool ProcessSubsequentPolygon( const SHAPE_POLY_SET& aPolygon ) = 0;
364
365private:
368
369 bool m_firstPolygon = true;
370 int m_width = 0;
373};
374
376{
377public:
379 POLYGON_BOOLEAN_ROUTINE( aBoard, aHandler )
380 {
381 }
382
383 bool IsCommutative() const override { return true; }
384
385 wxString GetCommitDescription() const override;
386 std::optional<wxString> GetStatusMessage() const override;
387
388private:
389 bool ProcessSubsequentPolygon( const SHAPE_POLY_SET& aPolygon ) override;
390};
391
392
394{
395public:
397 POLYGON_BOOLEAN_ROUTINE( aBoard, aHandler )
398 {
399 }
400
401 bool IsCommutative() const override { return false; }
402
403 wxString GetCommitDescription() const override;
404 std::optional<wxString> GetStatusMessage() const override;
405
406private:
407 bool ProcessSubsequentPolygon( const SHAPE_POLY_SET& aPolygon ) override;
408};
409
410
412{
413public:
415 POLYGON_BOOLEAN_ROUTINE( aBoard, aHandler )
416 {
417 }
418
419 bool IsCommutative() const override { return true; }
420
421 wxString GetCommitDescription() const override;
422 std::optional<wxString> GetStatusMessage() const override;
423
424private:
425 bool ProcessSubsequentPolygon( const SHAPE_POLY_SET& aPolygon ) override;
426};
427
428
430{
431public:
443
444 OUTSET_ROUTINE( BOARD_ITEM* aBoard, CHANGE_HANDLER& aHandler, const PARAMETERS& aParams ) :
445 ITEM_MODIFICATION_ROUTINE( aBoard, aHandler ),
446 m_params( aParams )
447 {
448 }
449
450 wxString GetCommitDescription() const override;
451
452 std::optional<wxString> GetStatusMessage() const;
453
454 void ProcessItem( BOARD_ITEM& aItem );
455
456private:
458};
459
460#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:84
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 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.