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}
112
113
115 m_reporter( aReporter )
116{
117 m_iter = 0;
118 m_grouping = false;
119 m_activeEntry = nullptr;
120 SetDebugEnabled( true );
121}
122
123
125{
126 // fixme: I know it's a hacky tool but it should clean after itself at some point...
127}
128
129
131{
132 if( m_stages.empty() )
133 m_stages.push_back( new PNS_DEBUG_STAGE() );
134
135 return m_stages.back();
136}
137
138
139void PNS_TEST_DEBUG_DECORATOR::BeginGroup( const wxString& name, int aLevel,
140 const SRC_LOCATION_INFO& aSrcLoc )
141{
142 PNS_DEBUG_STAGE* stage = currentStage();
143 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
144
145 ent->m_name = name;
146 ent->m_iter = m_iter;
147 ent->m_level = aLevel;
148
149 if( m_activeEntry )
150 m_activeEntry->AddChild( ent );
151
152 m_activeEntry = ent;
153 m_grouping = true;
154}
155
156
158{
159 if( !m_activeEntry )
160 return;
161
163
164 if( !m_activeEntry )
165 m_grouping = false;
166}
167
168
170{
171 auto st = currentStage();
172 m_activeEntry->AddChild( ent );
173}
174
175
177 int aSize, const wxString& aName,
178 const SRC_LOCATION_INFO& aSrcLoc )
179{
181
182 sh->Append( aP.x - aSize, aP.y - aSize );
183 sh->Append( aP.x + aSize, aP.y + aSize );
184 sh->Append( aP.x, aP.y );
185 sh->Append( aP.x - aSize, aP.y + aSize );
186 sh->Append( aP.x + aSize, aP.y - aSize );
187
188 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
189
190 ent->m_shapes.push_back( sh );
191 ent->m_color = aColor;
192 ent->m_width = 30000;
193 ent->m_iter = m_iter;
194 ent->m_name = aName;
195 ent->m_hasLabels = false;
196 ent->m_srcLoc = aSrcLoc;
197
198 addEntry( ent );
199}
200
201
203 int aOverrideWidth, const wxString& aName,
204 const SRC_LOCATION_INFO& aSrcLoc )
205{
206 SHAPE* sh = aItem->Shape()->Clone();
207 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
208
209 ent->m_shapes.push_back( sh );
210 ent->m_color = aColor;
211 ent->m_width = aOverrideWidth;
212 ent->m_name = aName;
213 ent->m_iter = m_iter;
214 ent->m_srcLoc = aSrcLoc;
215
216 addEntry( ent );
217}
218
219
220void PNS_TEST_DEBUG_DECORATOR::AddShape( const SHAPE* aShape, const KIGFX::COLOR4D& aColor,
221 int aOverrideWidth, const wxString& aName,
222 const SRC_LOCATION_INFO& aSrcLoc )
223{
224 SHAPE* sh = aShape->Clone();
225 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
226
227 ent->m_shapes.push_back( sh );
228 ent->m_color = aColor;
229 ent->m_width = aOverrideWidth;
230 ent->m_name = aName;
231 ent->m_iter = m_iter;
232 ent->m_srcLoc = aSrcLoc;
233
234 addEntry( ent );
235}
236
237
238void PNS_TEST_DEBUG_DECORATOR::Message( const wxString& msg, const SRC_LOCATION_INFO& aSrcLoc )
239{
240 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
241 ent->m_msg = msg.c_str();
242 ent->m_srcLoc = aSrcLoc;
243 addEntry( ent );
244
245#ifdef VERBOSE
246 static wxString lastMsg;
247
248 if( msg != lastMsg )
249 {
250 m_reporter->Report( msg );
251 lastMsg = msg;
252 }
253#endif
254}
255
256
257void PNS_TEST_DEBUG_DECORATOR::NewStage( const wxString& name, int iter,
258 const SRC_LOCATION_INFO& aSrcLoc )
259{
260 PNS_DEBUG_STAGE* stage = new PNS_DEBUG_STAGE();
261 stage->m_name = name;
262 stage->m_iter = iter;
263
264 m_stages.push_back( new PNS_DEBUG_STAGE );
265 m_activeEntry = m_stages.back()->m_entries;
266}
267
269{
270 if( m_stages.empty() )
271 return;
272
273 m_stages.back()->m_status = stat;
274}
275
276
278{
279 PNS_DEBUG_STAGE* st = m_stages[stage];
280 BOX2I bb;
281 bool first = true;
282
283 auto visitor =
284 [&]( PNS_DEBUG_SHAPE* ent ) -> bool
285 {
286 for( SHAPE* sh : ent->m_shapes )
287 {
288 if( first )
289 bb = sh->BBox();
290 else
291 bb.Merge( sh->BBox() );
292
293 first = false;
294 }
295
296 return true;
297 };
298
299 return bb;
300}
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