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 <router/pns_item.h>
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( auto s : m_shapes )
44 {
45 delete s;
46 }
47
48 for( auto ch : m_children )
49 {
50 delete ch;
51 }
52}
53
55{
56 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE( this );
57 m_children.push_back( ent );
58
59 return ent;
60}
61
63{
64 ent->m_parent = this;
65 m_children.push_back( ent );
66}
67
69{
70 if( m_visible )
71 return true;
72
73 auto 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
87 std::function<bool( PNS_DEBUG_SHAPE* )> visitor, int depth )
88{
89 if( !visitor( this ) )
90 return;
91
92
93 for( auto child : m_children )
94 {
95 child->IterateTree( visitor, depth + 1 );
96 }
97}
98
100{
101 m_name = "<unknown>";
102 m_iter = 0;
104 m_status = false;
105}
106
108{
109}
110
111
113 {
114 m_iter = 0;
115 m_grouping = false;
116 m_activeEntry = nullptr;
117 SetDebugEnabled( true );
118 }
119
121 {
122 // fixme: I know it's a hacky tool but it should clean after itself at some point...
123
124 }
125
126
127
129{
130 if( m_stages.empty() )
131 m_stages.push_back( new PNS_DEBUG_STAGE() );
132
133 return m_stages.back();
134}
135
136
137void PNS_TEST_DEBUG_DECORATOR::BeginGroup( const wxString& name, int aLevel,
138 const SRC_LOCATION_INFO& aSrcLoc )
139{
140 PNS_DEBUG_STAGE* stage = currentStage();
141 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
142
143 ent->m_name = name;
144 ent->m_iter = m_iter;
145 ent->m_level = aLevel;
146
147 if( m_activeEntry )
148 {
149 m_activeEntry->AddChild( ent );
150 }
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
169{
170 auto st = currentStage();
171 m_activeEntry->AddChild( ent );
172}
173
175 int aSize, const wxString& aName,
176 const SRC_LOCATION_INFO& aSrcLoc )
177{
178 auto sh = new SHAPE_LINE_CHAIN;
179
180 sh->Append( aP.x - aSize, aP.y - aSize );
181 sh->Append( aP.x + aSize, aP.y + aSize );
182 sh->Append( aP.x, aP.y );
183 sh->Append( aP.x - aSize, aP.y + aSize );
184 sh->Append( aP.x + aSize, aP.y - aSize );
185
186 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
187
188 ent->m_shapes.push_back( sh );
189 ent->m_color = aColor;
190 ent->m_width = 30000;
191 ent->m_iter = m_iter;
192 ent->m_name = aName;
193 ent->m_hasLabels = false;
194 ent->m_srcLoc = aSrcLoc;
195
196 addEntry( ent );
197}
198
199
201 int aOverrideWidth, const wxString& aName,
202 const SRC_LOCATION_INFO& aSrcLoc )
203{
204 auto sh = aItem->Shape()->Clone();
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 = aOverrideWidth;
210 ent->m_name = aName;
211 ent->m_iter = m_iter;
212 ent->m_srcLoc = aSrcLoc;
213
214 addEntry( ent );
215}
216
217
218void PNS_TEST_DEBUG_DECORATOR::AddShape( const SHAPE* aShape, const KIGFX::COLOR4D& aColor,
219 int aOverrideWidth, const wxString& aName,
220 const SRC_LOCATION_INFO& aSrcLoc )
221{
222 auto sh = aShape->Clone();
223 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
224
225 ent->m_shapes.push_back( sh );
226 ent->m_color = aColor;
227 ent->m_width = aOverrideWidth;
228 ent->m_name = aName;
229 ent->m_iter = m_iter;
230 ent->m_srcLoc = aSrcLoc;
231
232 addEntry( ent );
233}
234
235
236void PNS_TEST_DEBUG_DECORATOR::Message( const wxString& msg, const SRC_LOCATION_INFO& aSrcLoc )
237{
238 PNS_DEBUG_SHAPE* ent = new PNS_DEBUG_SHAPE();
239 ent->m_msg = msg.c_str();
240 ent->m_srcLoc = aSrcLoc;
241 addEntry( ent );
242}
243
244
245void PNS_TEST_DEBUG_DECORATOR::NewStage( const wxString& name, int iter,
246 const SRC_LOCATION_INFO& aSrcLoc )
247{
248 PNS_DEBUG_STAGE* stage = new PNS_DEBUG_STAGE();
249 stage->m_name = name;
250 stage->m_iter = iter;
251
252 m_stages.push_back( new PNS_DEBUG_STAGE );
253 m_activeEntry = m_stages.back()->m_entries;
254}
255
257{
258 if( m_stages.empty() )
259 return;
260
261 m_stages.back()->m_status = stat;
262}
263
265{
266 PNS_DEBUG_STAGE* st = m_stages[stage];
267 BOX2I bb;
268 bool first = true;
269
270 auto visitor = [&]( PNS_DEBUG_SHAPE* ent ) -> bool {
271 for( auto sh : ent->m_shapes )
272 {
273 if( first )
274 bb = sh->BBox();
275 else
276 bb.Merge( sh->BBox() );
277
278 first = false;
279 }
280
281 return true;
282 };
283
284 return bb;
285}
const char * name
Definition: DXF_plotter.cpp:56
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:588
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
static const COLOR4D WHITE
Definition: color4d.h:384
void SetDebugEnabled(bool aEnabled)
Base class for PNS router board items.
Definition: pns_item.h:91
virtual const SHAPE * Shape() const
Return the geometrical shape of the item.
Definition: pns_item.h:220
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
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
PNS_DEBUG_SHAPE * m_entries