KiCad PCB EDA Suite
pns_debug_decorator.h
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2021 CERN
5 * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 * Author: Christian Gagneraud <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef __PNS_DEBUG_DECORATOR_H
23#define __PNS_DEBUG_DECORATOR_H
24
25#include <math/vector2d.h>
26#include <math/box2.h>
27#include <geometry/seg.h>
29#include <geometry/shape_rect.h>
30
31#include <gal/color4d.h>
32
33namespace PNS {
34
35class ITEM;
36
38{
39public:
41
43 {
44 SRC_LOCATION_INFO( const std::string& aFileName = "", const std::string& aFuncName = "",
45 int aLine = 0 ) :
46 fileName( aFileName ),
47 funcName( aFuncName ),
48 line( aLine )
49 {
50 }
51
52 std::string fileName;
53 std::string funcName;
54 int line;
55 };
56
57 virtual ~DEBUG_DECORATOR() {}
58
59 void SetDebugEnabled( bool aEnabled ) { m_debugEnabled = aEnabled;}
60 bool IsDebugEnabled() const { return m_debugEnabled; }
61
62 virtual void SetIteration( int iter ) {};
63
64 virtual void Message( const wxString& msg,
65 const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
66
67 virtual void NewStage( const wxString& name, int iter,
68 const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
69
70 virtual void BeginGroup( const wxString& name, int aLevel = 0,
71 const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
72
73 virtual void EndGroup( const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
74
75 virtual void AddPoint( const VECTOR2I& aP, const KIGFX::COLOR4D& aColor, int aSize,
76 const wxString& aName = wxT( "" ),
77 const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
78
79 virtual void AddItem( const ITEM* aItem, const KIGFX::COLOR4D& aColor,
80 int aOverrideWidth = 0,
81 const wxString& aName = wxT( "" ),
82 const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) {};
83
84 virtual void AddShape( const SHAPE* aShape, const KIGFX::COLOR4D& aColor,
85 int aOverrideWidth = 0,
86 const wxString& aName = wxT( "" ),
87 const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) {};
88
89 virtual void AddShape( const BOX2I& aBox, const KIGFX::COLOR4D& aColor, int aOverrideWidth = 0,
90 const wxString& aName = wxT( "" ),
91 const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() )
92 {
93 SHAPE_RECT r( aBox );
94 AddShape( &r, aColor, aOverrideWidth, aName, aSrcLoc );
95 }
96
97 void AddShape( const SEG& aSeg, const KIGFX::COLOR4D& aColor,
98 int aOverrideWidth = 0,
99 const wxString& aName = wxT( "" ),
100 const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() )
101 {
103 lc.Append( aSeg.A );
104 lc.Append( aSeg.B );
105 AddShape( &lc, aColor, aOverrideWidth, aName, aSrcLoc );
106 }
107
108 virtual void Clear() {};
109
110private:
111
113};
114
115/* WARNING! The marco below is a remarkably ugly hack, intended to log the
116 call location of the debug calls without having to create the SRC_LOCATION_INFOs every time
117 DEBUG_DECORATOR::Something() is called.
118
119 Also checks if debug is enabled at all prior to calling decorator methods, thus saving some
120 time wasted otherwise for string formatting and copying the geometry. */
121
122#define PNS_DBG( dbg, method, ... ) \
123 if( dbg && dbg->IsDebugEnabled() ) \
124 dbg->method( __VA_ARGS__, PNS::DEBUG_DECORATOR::SRC_LOCATION_INFO( __FILE__, __FUNCTION__, \
125 __LINE__ ) );
126
127#define PNS_DBGN( dbg, method ) \
128 if( dbg && dbg->IsDebugEnabled() ) \
129 dbg->method( PNS::DEBUG_DECORATOR::SRC_LOCATION_INFO( __FILE__, __FUNCTION__, __LINE__ ) );
130
131} // namespace PNS
132
133#endif
const char * name
Definition: DXF_plotter.cpp:56
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:102
virtual void BeginGroup(const wxString &name, int aLevel=0, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO())
virtual void NewStage(const wxString &name, int iter, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO())
void AddShape(const SEG &aSeg, const KIGFX::COLOR4D &aColor, int aOverrideWidth=0, const wxString &aName=wxT(""), const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO())
void SetDebugEnabled(bool aEnabled)
virtual void SetIteration(int iter)
virtual void EndGroup(const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO())
virtual void AddItem(const ITEM *aItem, const KIGFX::COLOR4D &aColor, int aOverrideWidth=0, const wxString &aName=wxT(""), const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO())
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())
virtual void Message(const wxString &msg, const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO())
virtual void AddPoint(const VECTOR2I &aP, const KIGFX::COLOR4D &aColor, int aSize, const wxString &aName=wxT(""), const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO())
virtual void AddShape(const BOX2I &aBox, const KIGFX::COLOR4D &aColor, int aOverrideWidth=0, const wxString &aName=wxT(""), const SRC_LOCATION_INFO &aSrcLoc=SRC_LOCATION_INFO())
Base class for PNS router board items.
Definition: pns_item.h:56
Definition: seg.h:42
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50
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
Push and Shove diff pair dimensions (gap) settings dialog.
SRC_LOCATION_INFO(const std::string &aFileName="", const std::string &aFuncName="", int aLine=0)