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
28
30{
31 m_iter = 0;
33 m_width = 10000;
34 m_name = "<unknown>";
35 m_parent = aParent;
36 m_visible = true;
37 m_selected = false;
38 m_level = 0;
39}
40
42{
43 for( SHAPE* shape : m_shapes )
44 delete shape;
45
46 for( PNS_DEBUG_SHAPE* child : m_children )
47 delete child;
48}
49
50
52{
53 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE( this );
54 m_children.push_back( ent );
55
56 return ent;
57}
58
59
61{
62 ent->m_parent = this;
63 m_children.push_back( ent );
64}
65
66
68{
69 if( m_selected )
70 return true;
71
72 PNS_DEBUG_SHAPE* parent = m_parent;
73
74 while( parent )
75 {
76 if( parent->m_selected )
77 return true;
78
79 parent = parent->m_parent;
80 }
81
82 return false;
83}
84
85
87{
88 if( m_visible )
89 return true;
90
91 PNS_DEBUG_SHAPE* parent = m_parent;
92
93 while( parent )
94 {
95 if( parent->m_visible )
96 return true;
97
98 parent = parent->m_parent;
99 }
100
101 return false;
102}
103
104void PNS_DEBUG_SHAPE::IterateTree( std::function<bool( PNS_DEBUG_SHAPE* )> visitor, int depth )
105{
106 if( !visitor( this ) )
107 return;
108
109
110 for( PNS_DEBUG_SHAPE* child : m_children )
111 child->IterateTree( visitor, depth + 1 );
112}
113
114
116{
117 m_name = "<unknown>";
118 m_iter = 0;
120 m_status = false;
121}
122
127
128
130 m_reporter( aReporter )
131{
132 m_iter = 0;
133 m_grouping = false;
134 m_activeEntry = nullptr;
135 SetDebugEnabled( true );
136}
137
138
140{
141 for( PNS_DEBUG_STAGE* stage : m_stages )
142 delete stage;
143 // fixme: I know it's a hacky tool but it should clean after itself at some point...
144}
145
146
148{
149 if( m_stages.empty() )
150 m_stages.push_back( new PNS_DEBUG_STAGE() );
151
152 return m_stages.back();
153}
154
155
156void PNS_TEST_DEBUG_DECORATOR::BeginGroup( const wxString& name, int aLevel,
157 const SRC_LOCATION_INFO& aSrcLoc )
158{
159 PNS_DEBUG_STAGE* stage = currentStage();
160 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
161
162 ent->m_name = name;
163 ent->m_iter = m_iter;
164 ent->m_level = aLevel;
165
166 if( m_activeEntry )
167 m_activeEntry->AddChild( ent );
168
169 m_activeEntry = ent;
170 m_grouping = true;
171}
172
173
175{
176 if( !m_activeEntry )
177 return;
178
179 m_activeEntry = m_activeEntry->m_parent;
180
181 if( !m_activeEntry )
182 m_grouping = false;
183}
184
185
187{
188 auto st = currentStage();
189 m_activeEntry->AddChild( ent );
190}
191
192
194 int aSize, const wxString& aName,
195 const SRC_LOCATION_INFO& aSrcLoc )
196{
198
199 sh->Append( aP.x - aSize, aP.y - aSize );
200 sh->Append( aP.x + aSize, aP.y + aSize );
201 sh->Append( aP.x, aP.y );
202 sh->Append( aP.x - aSize, aP.y + aSize );
203 sh->Append( aP.x + aSize, aP.y - aSize );
204
205 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
206
207 ent->m_shapes.push_back( sh );
208 ent->m_color = aColor;
209 ent->m_width = 30000;
210 ent->m_iter = m_iter;
211 ent->m_name = aName;
212 ent->m_hasLabels = false;
213 ent->m_srcLoc = aSrcLoc;
214
215 addEntry( ent );
216}
217
218
220 int aOverrideWidth, const wxString& aName,
221 const SRC_LOCATION_INFO& aSrcLoc )
222{
223 // TODO(JE) padstacks
224 SHAPE* sh = aItem->Shape( -1 )->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::AddShape( const SHAPE* aShape, const KIGFX::COLOR4D& aColor,
239 int aOverrideWidth, const wxString& aName,
240 const SRC_LOCATION_INFO& aSrcLoc )
241{
242 SHAPE* sh = aShape->Clone();
243 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
244
245 ent->m_shapes.push_back( sh );
246 ent->m_color = aColor;
247 ent->m_width = aOverrideWidth;
248 ent->m_name = aName;
249 ent->m_iter = m_iter;
250 ent->m_srcLoc = aSrcLoc;
251
252 addEntry( ent );
253}
254
255
256void PNS_TEST_DEBUG_DECORATOR::Message( const wxString& msg, const SRC_LOCATION_INFO& aSrcLoc )
257{
258 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
259 ent->m_msg = msg.c_str();
260 ent->m_srcLoc = aSrcLoc;
261 addEntry( ent );
262
263 if( m_reporter )
264 m_reporter->Report( msg );
265}
266
267
268void PNS_TEST_DEBUG_DECORATOR::NewStage( const wxString& name, int iter,
269 const SRC_LOCATION_INFO& aSrcLoc )
270{
271 PNS_DEBUG_STAGE* stage = new PNS_DEBUG_STAGE();
272 stage->m_name = name;
273 stage->m_iter = iter;
274
275 m_stages.push_back( stage );
276 m_activeEntry = m_stages.back()->m_entries;
277}
278
280{
281 if( m_stages.empty() )
282 return;
283
284 m_stages.back()->m_status = stat;
285}
286
287
289{
290 PNS_DEBUG_STAGE* st = m_stages[stage];
291 BOX2I bb;
292 bool first = true;
293
294 auto visitor =
295 [&]( PNS_DEBUG_SHAPE* ent ) -> bool
296 {
297 for( SHAPE* sh : ent->m_shapes )
298 {
299 if( first )
300 bb = sh->BBox();
301 else
302 bb.Merge( sh->BBox() );
303
304 first = false;
305 }
306
307 return true;
308 };
309
310 return bb;
311}
const char * name
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:653
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
static const COLOR4D WHITE
Definition color4d.h:402
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:73
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