KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_test_debug_decorator.cpp
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 (C) 2020-2021 KiCad Developers.
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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24
26
27#include <reporter.h>
28#include <router/pns_item.h>
29
30
31#define VERBOSE // Sends PSN_DBG message output to the console
32
33
35{
36 m_iter = 0;
38 m_width = 10000;
39 m_name = "<unknown>";
40 m_parent = aParent;
41 m_visible = true;
42 m_selected = false;
43 m_level = 0;
44}
45
47{
48 for( SHAPE* shape : m_shapes )
49 delete shape;
50
51 for( PNS_DEBUG_SHAPE* child : m_children )
52 delete child;
53}
54
55
57{
58 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE( this );
59 m_children.push_back( ent );
60
61 return ent;
62}
63
64
66{
67 ent->m_parent = this;
68 m_children.push_back( ent );
69}
70
71
73{
74 if( m_visible )
75 return true;
76
77 PNS_DEBUG_SHAPE* parent = m_parent;
78
79 while( parent )
80 {
81 if( parent->m_visible )
82 return true;
83
84 parent = parent->m_parent;
85 }
86
87 return false;
88}
89
90void PNS_DEBUG_SHAPE::IterateTree( std::function<bool( PNS_DEBUG_SHAPE* )> visitor, int depth )
91{
92 if( !visitor( this ) )
93 return;
94
95
96 for( PNS_DEBUG_SHAPE* child : m_children )
97 child->IterateTree( visitor, depth + 1 );
98}
99
100
102{
103 m_name = "<unknown>";
104 m_iter = 0;
106 m_status = false;
107}
108
110{
111 delete m_entries;
112}
113
114
116 m_reporter( aReporter )
117{
118 m_iter = 0;
119 m_grouping = false;
120 m_activeEntry = nullptr;
121 SetDebugEnabled( true );
122}
123
124
126{
127 for( PNS_DEBUG_STAGE* stage : m_stages )
128 delete stage;
129 // fixme: I know it's a hacky tool but it should clean after itself at some point...
130}
131
132
134{
135 if( m_stages.empty() )
136 m_stages.push_back( new PNS_DEBUG_STAGE() );
137
138 return m_stages.back();
139}
140
141
142void PNS_TEST_DEBUG_DECORATOR::BeginGroup( const wxString& name, int aLevel,
143 const SRC_LOCATION_INFO& aSrcLoc )
144{
145 PNS_DEBUG_STAGE* stage = currentStage();
146 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
147
148 ent->m_name = name;
149 ent->m_iter = m_iter;
150 ent->m_level = aLevel;
151
152 if( m_activeEntry )
153 m_activeEntry->AddChild( ent );
154
155 m_activeEntry = ent;
156 m_grouping = true;
157}
158
159
161{
162 if( !m_activeEntry )
163 return;
164
166
167 if( !m_activeEntry )
168 m_grouping = false;
169}
170
171
173{
174 auto st = currentStage();
175 m_activeEntry->AddChild( ent );
176}
177
178
180 int aSize, const wxString& aName,
181 const SRC_LOCATION_INFO& aSrcLoc )
182{
184
185 sh->Append( aP.x - aSize, aP.y - aSize );
186 sh->Append( aP.x + aSize, aP.y + aSize );
187 sh->Append( aP.x, aP.y );
188 sh->Append( aP.x - aSize, aP.y + aSize );
189 sh->Append( aP.x + aSize, aP.y - aSize );
190
191 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
192
193 ent->m_shapes.push_back( sh );
194 ent->m_color = aColor;
195 ent->m_width = 30000;
196 ent->m_iter = m_iter;
197 ent->m_name = aName;
198 ent->m_hasLabels = false;
199 ent->m_srcLoc = aSrcLoc;
200
201 addEntry( ent );
202}
203
204
206 int aOverrideWidth, const wxString& aName,
207 const SRC_LOCATION_INFO& aSrcLoc )
208{
209 SHAPE* sh = aItem->Shape()->Clone();
210 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
211
212 ent->m_shapes.push_back( sh );
213 ent->m_color = aColor;
214 ent->m_width = aOverrideWidth;
215 ent->m_name = aName;
216 ent->m_iter = m_iter;
217 ent->m_srcLoc = aSrcLoc;
218
219 addEntry( ent );
220}
221
222
223void PNS_TEST_DEBUG_DECORATOR::AddShape( const SHAPE* aShape, const KIGFX::COLOR4D& aColor,
224 int aOverrideWidth, const wxString& aName,
225 const SRC_LOCATION_INFO& aSrcLoc )
226{
227 SHAPE* sh = aShape->Clone();
228 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
229
230 ent->m_shapes.push_back( sh );
231 ent->m_color = aColor;
232 ent->m_width = aOverrideWidth;
233 ent->m_name = aName;
234 ent->m_iter = m_iter;
235 ent->m_srcLoc = aSrcLoc;
236
237 addEntry( ent );
238}
239
240
241void PNS_TEST_DEBUG_DECORATOR::Message( const wxString& msg, const SRC_LOCATION_INFO& aSrcLoc )
242{
243 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
244 ent->m_msg = msg.c_str();
245 ent->m_srcLoc = aSrcLoc;
246 addEntry( ent );
247
248#ifdef VERBOSE
249 static wxString lastMsg;
250
251 if( msg != lastMsg )
252 {
253 m_reporter->Report( msg );
254 lastMsg = msg;
255 }
256#endif
257}
258
259
260void PNS_TEST_DEBUG_DECORATOR::NewStage( const wxString& name, int iter,
261 const SRC_LOCATION_INFO& aSrcLoc )
262{
263 PNS_DEBUG_STAGE* stage = new PNS_DEBUG_STAGE();
264 stage->m_name = name;
265 stage->m_iter = iter;
266
267 m_stages.push_back( stage );
268 m_activeEntry = m_stages.back()->m_entries;
269}
270
272{
273 if( m_stages.empty() )
274 return;
275
276 m_stages.back()->m_status = stat;
277}
278
279
281{
282 PNS_DEBUG_STAGE* st = m_stages[stage];
283 BOX2I bb;
284 bool first = true;
285
286 auto visitor =
287 [&]( PNS_DEBUG_SHAPE* ent ) -> bool
288 {
289 for( SHAPE* sh : ent->m_shapes )
290 {
291 if( first )
292 bb = sh->BBox();
293 else
294 bb.Merge( sh->BBox() );
295
296 first = false;
297 }
298
299 return true;
300 };
301
302 return bb;
303}
const char * name
Definition: DXF_plotter.cpp:57
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:589
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
static const COLOR4D WHITE
Definition: color4d.h:385
void SetDebugEnabled(bool aEnabled)
Base class for PNS router board items.
Definition: pns_item.h:97
virtual const SHAPE * Shape() const
Return the geometrical shape of the item.
Definition: pns_item.h:224
std::vector< SHAPE * > m_shapes
PNS_DEBUG_SHAPE * NewChild()
PNS_DEBUG_SHAPE(PNS_DEBUG_SHAPE *aParent=nullptr)
void IterateTree(std::function< bool(PNS_DEBUG_SHAPE *)> visitor, int depth=0)
void AddChild(PNS_DEBUG_SHAPE *ent)
PNS_DEBUG_SHAPE * m_parent
PNS::DEBUG_DECORATOR::SRC_LOCATION_INFO m_srcLoc
std::vector< PNS_DEBUG_SHAPE * > m_children
virtual void AddPoint(const VECTOR2I &aP, const KIGFX::COLOR4D &aColor, int aSize, const wxString &aName=wxT(""), const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
void addEntry(PNS_DEBUG_SHAPE *ent)
virtual void AddItem(const PNS::ITEM *aItem, const KIGFX::COLOR4D &aColor, int aOverrideWidth=0, const wxString &aName=wxT(""), const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
std::vector< PNS_DEBUG_STAGE * > m_stages
BOX2I GetStageExtents(int stage) const
virtual void Message(const wxString &msg, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
virtual void BeginGroup(const wxString &name, int aLevel=0, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
virtual void EndGroup(const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
virtual void AddShape(const SHAPE *aShape, const KIGFX::COLOR4D &aColor, int aOverrideWidth=0, const wxString &aName=wxT(""), const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
virtual void NewStage(const wxString &name, int iter, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO()) override
PNS_TEST_DEBUG_DECORATOR(REPORTER *aReporter)
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
An abstract shape on 2D plane.
Definition: shape.h:126
virtual SHAPE * Clone() const
Return a dynamically allocated copy of the shape.
Definition: shape.h:148
virtual const BOX2I BBox(int aClearance=0) const =0
Compute a bounding box of the shape, with a margin of aClearance a collision.
PNS_DEBUG_SHAPE * m_entries