KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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 m_debugEnabled( false )
42 {}
43
45 {
46 SRC_LOCATION_INFO( const std::string& aFileName = "", const std::string& aFuncName = "",
47 int aLine = 0 ) :
48 fileName( aFileName ),
49 funcName( aFuncName ),
50 line( aLine )
51 {
52 }
53
54 std::string fileName;
55 std::string funcName;
56 int line;
57 };
58
59 virtual ~DEBUG_DECORATOR() {}
60
61 void SetDebugEnabled( bool aEnabled ) { m_debugEnabled = aEnabled;}
62 bool IsDebugEnabled() const { return m_debugEnabled; }
63
64 virtual void SetIteration( int iter ) {};
65
66 virtual void Message( const wxString& msg,
67 const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
68
69 virtual void NewStage( const wxString& name, int iter,
70 const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
71
72 virtual void BeginGroup( const wxString& name, int aLevel = 0,
73 const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
74
75 virtual void EndGroup( const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
76
77 virtual void AddPoint( const VECTOR2I& aP, const KIGFX::COLOR4D& aColor, int aSize,
78 const wxString& aName = wxT( "" ),
79 const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
80
81 virtual void AddItem( const ITEM* aItem, const KIGFX::COLOR4D& aColor,
82 int aOverrideWidth = 0,
83 const wxString& aName = wxT( "" ),
84 const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) {};
85
86 virtual void AddShape( const SHAPE* aShape, const KIGFX::COLOR4D& aColor,
87 int aOverrideWidth = 0,
88 const wxString& aName = wxT( "" ),
89 const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) {};
90
91 virtual void AddShape( const BOX2I& aBox, const KIGFX::COLOR4D& aColor, int aOverrideWidth = 0,
92 const wxString& aName = wxT( "" ),
93 const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() )
94 {
95 SHAPE_RECT r( aBox );
96 AddShape( &r, aColor, aOverrideWidth, aName, aSrcLoc );
97 }
98
99 void AddShape( const SEG& aSeg, const KIGFX::COLOR4D& aColor,
100 int aOverrideWidth = 0,
101 const wxString& aName = wxT( "" ),
102 const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() )
103 {
105 lc.Append( aSeg.A );
106 lc.Append( aSeg.B );
107 AddShape( &lc, aColor, aOverrideWidth, aName, aSrcLoc );
108 }
109
110 virtual void Clear() {};
111
112private:
113
115};
116
117/* WARNING! The marco below is a remarkably ugly hack, intended to log the
118 call location of the debug calls without having to create the SRC_LOCATION_INFOs every time
119 DEBUG_DECORATOR::Something() is called.
120
121 Also checks if debug is enabled at all prior to calling decorator methods, thus saving some
122 time wasted otherwise for string formatting and copying the geometry. */
123
124#define PNS_DBG( dbg, method, ... ) \
125 if( dbg && dbg->IsDebugEnabled() ) \
126 dbg->method( __VA_ARGS__, PNS::DEBUG_DECORATOR::SRC_LOCATION_INFO( __FILE__, __FUNCTION__, \
127 __LINE__ ) );
128
129#define PNS_DBGN( dbg, method ) \
130 if( dbg && dbg->IsDebugEnabled() ) \
131 dbg->method( PNS::DEBUG_DECORATOR::SRC_LOCATION_INFO( __FILE__, __FUNCTION__, __LINE__ ) );
132
133} // namespace PNS
134
135#endif
const char * name
Definition: DXF_plotter.cpp:57
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
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:97
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:126
Push and Shove diff pair dimensions (gap) settings dialog.
SRC_LOCATION_INFO(const std::string &aFileName="", const std::string &aFuncName="", int aLine=0)