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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
20
22
23#include <reporter.h>
24#include <router/pns_item.h>
25
26
27#define VERBOSE // Sends PSN_DBG message output to the console
28
29
31{
32 m_iter = 0;
34 m_width = 10000;
35 m_name = "<unknown>";
36 m_parent = aParent;
37 m_visible = true;
38 m_selected = false;
39 m_level = 0;
40}
41
43{
44 for( SHAPE* shape : m_shapes )
45 delete shape;
46
47 for( PNS_DEBUG_SHAPE* child : m_children )
48 delete child;
49}
50
51
53{
54 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE( this );
55 m_children.push_back( ent );
56
57 return ent;
58}
59
60
62{
63 ent->m_parent = this;
64 m_children.push_back( ent );
65}
66
67
69{
70 if( m_visible )
71 return true;
72
73 PNS_DEBUG_SHAPE* parent = m_parent;
74
75 while( parent )
76 {
77 if( parent->m_visible )
78 return true;
79
80 parent = parent->m_parent;
81 }
82
83 return false;
84}
85
86void PNS_DEBUG_SHAPE::IterateTree( std::function<bool( PNS_DEBUG_SHAPE* )> visitor, int depth )
87{
88 if( !visitor( this ) )
89 return;
90
91
92 for( PNS_DEBUG_SHAPE* child : m_children )
93 child->IterateTree( visitor, depth + 1 );
94}
95
96
98{
99 m_name = "<unknown>";
100 m_iter = 0;
102 m_status = false;
103}
104
109
110
112 m_reporter( aReporter )
113{
114 m_iter = 0;
115 m_grouping = false;
116 m_activeEntry = nullptr;
117 SetDebugEnabled( true );
118}
119
120
122{
123 for( PNS_DEBUG_STAGE* stage : m_stages )
124 delete stage;
125 // fixme: I know it's a hacky tool but it should clean after itself at some point...
126}
127
128
130{
131 if( m_stages.empty() )
132 m_stages.push_back( new PNS_DEBUG_STAGE() );
133
134 return m_stages.back();
135}
136
137
138void PNS_TEST_DEBUG_DECORATOR::BeginGroup( const wxString& name, int aLevel,
139 const SRC_LOCATION_INFO& aSrcLoc )
140{
141 PNS_DEBUG_STAGE* stage = currentStage();
142 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
143
144 ent->m_name = name;
145 ent->m_iter = m_iter;
146 ent->m_level = aLevel;
147
148 if( m_activeEntry )
149 m_activeEntry->AddChild( ent );
150
151 m_activeEntry = ent;
152 m_grouping = true;
153}
154
155
157{
158 if( !m_activeEntry )
159 return;
160
161 m_activeEntry = m_activeEntry->m_parent;
162
163 if( !m_activeEntry )
164 m_grouping = false;
165}
166
167
169{
170 auto st = currentStage();
171 m_activeEntry->AddChild( ent );
172}
173
174
176 int aSize, const wxString& aName,
177 const SRC_LOCATION_INFO& aSrcLoc )
178{
180
181 sh->Append( aP.x - aSize, aP.y - aSize );
182 sh->Append( aP.x + aSize, aP.y + aSize );
183 sh->Append( aP.x, aP.y );
184 sh->Append( aP.x - aSize, aP.y + aSize );
185 sh->Append( aP.x + aSize, aP.y - aSize );
186
187 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
188
189 ent->m_shapes.push_back( sh );
190 ent->m_color = aColor;
191 ent->m_width = 30000;
192 ent->m_iter = m_iter;
193 ent->m_name = aName;
194 ent->m_hasLabels = false;
195 ent->m_srcLoc = aSrcLoc;
196
197 addEntry( ent );
198}
199
200
202 int aOverrideWidth, const wxString& aName,
203 const SRC_LOCATION_INFO& aSrcLoc )
204{
205 // TODO(JE) padstacks
206 SHAPE* sh = aItem->Shape( -1 )->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 printf("PNS: %s\n", msg.c_str().AsChar() );
246
247#ifdef VERBOSE
248 static wxString lastMsg;
249
250 if( msg != lastMsg )
251 {
252 m_reporter->Report( msg );
253 lastMsg = msg;
254 }
255#endif
256}
257
258
259void PNS_TEST_DEBUG_DECORATOR::NewStage( const wxString& name, int iter,
260 const SRC_LOCATION_INFO& aSrcLoc )
261{
262 PNS_DEBUG_STAGE* stage = new PNS_DEBUG_STAGE();
263 stage->m_name = name;
264 stage->m_iter = iter;
265
266 m_stages.push_back( stage );
267 m_activeEntry = m_stages.back()->m_entries;
268}
269
271{
272 if( m_stages.empty() )
273 return;
274
275 m_stages.back()->m_status = stat;
276}
277
278
280{
281 PNS_DEBUG_STAGE* st = m_stages[stage];
282 BOX2I bb;
283 bool first = true;
284
285 auto visitor =
286 [&]( PNS_DEBUG_SHAPE* ent ) -> bool
287 {
288 for( SHAPE* sh : ent->m_shapes )
289 {
290 if( first )
291 bb = sh->BBox();
292 else
293 bb.Merge( sh->BBox() );
294
295 first = false;
296 }
297
298 return true;
299 };
300
301 return bb;
302}
const char * name
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:654
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
static const COLOR4D WHITE
Definition color4d.h:401
void SetDebugEnabled(bool aEnabled)
Base class for PNS router board items.
Definition pns_item.h:98
virtual const SHAPE * Shape(int aLayer) const
Return the geometrical shape of the item.
Definition pns_item.h:242
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
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:124
virtual SHAPE * Clone() const
Return a dynamically allocated copy of the shape.
Definition shape.h:146
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
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683