2016-08-15 15:16:51 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
2021-05-28 22:09:21 +00:00
|
|
|
* Copyright (C) 2013-2021 CERN
|
2021-07-26 23:47:26 +00:00
|
|
|
* Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-08-15 15:16:51 +00:00
|
|
|
* Author: Christian Gagneraud <chgans@gna.org>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __PNS_DEBUG_DECORATOR_H
|
|
|
|
#define __PNS_DEBUG_DECORATOR_H
|
|
|
|
|
|
|
|
#include <math/vector2d.h>
|
|
|
|
#include <math/box2.h>
|
|
|
|
#include <geometry/seg.h>
|
|
|
|
#include <geometry/shape_line_chain.h>
|
2022-02-26 01:42:16 +00:00
|
|
|
#include <geometry/shape_rect.h>
|
2016-08-15 15:16:51 +00:00
|
|
|
|
2021-05-28 22:09:21 +00:00
|
|
|
#include <gal/color4d.h>
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
class ITEM;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
class DEBUG_DECORATOR
|
2016-08-15 15:16:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-05-28 22:09:21 +00:00
|
|
|
DEBUG_DECORATOR() : m_debugEnabled( false ) {}
|
|
|
|
|
|
|
|
struct SRC_LOCATION_INFO
|
|
|
|
{
|
2021-07-26 23:47:26 +00:00
|
|
|
SRC_LOCATION_INFO( const std::string& aFileName = "", const std::string& aFuncName = "",
|
|
|
|
int aLine = 0 ) :
|
|
|
|
fileName( aFileName ),
|
|
|
|
funcName( aFuncName ),
|
|
|
|
line( aLine )
|
2021-05-28 22:09:21 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string fileName;
|
|
|
|
std::string funcName;
|
|
|
|
int line;
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual ~DEBUG_DECORATOR() {}
|
|
|
|
|
|
|
|
void SetDebugEnabled( bool aEnabled ) { m_debugEnabled = aEnabled;}
|
|
|
|
bool IsDebugEnabled() const { return m_debugEnabled; }
|
|
|
|
|
2022-02-26 01:42:16 +00:00
|
|
|
virtual void SetIteration( int iter ) {};
|
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
virtual void Message( const wxString& msg,
|
2021-05-28 22:09:21 +00:00
|
|
|
const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
|
2022-02-26 01:42:16 +00:00
|
|
|
|
|
|
|
virtual void NewStage( const wxString& name, int iter,
|
2021-05-28 22:09:21 +00:00
|
|
|
const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
|
2022-02-26 01:42:16 +00:00
|
|
|
|
|
|
|
virtual void BeginGroup( const wxString& name, int aLevel = 0,
|
2021-05-28 22:09:21 +00:00
|
|
|
const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
|
2022-02-26 01:42:16 +00:00
|
|
|
|
2021-05-28 22:09:21 +00:00
|
|
|
virtual void EndGroup( const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
|
2022-02-26 01:42:16 +00:00
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
virtual void AddPoint( const VECTOR2I& aP, const KIGFX::COLOR4D& aColor, int aSize,
|
2022-02-26 01:42:16 +00:00
|
|
|
const wxString& aName = wxT( "" ),
|
2021-05-28 22:09:21 +00:00
|
|
|
const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
|
2022-02-26 01:42:16 +00:00
|
|
|
|
|
|
|
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() ) {};
|
|
|
|
|
|
|
|
void AddShape( const BOX2I& aBox, const KIGFX::COLOR4D& aColor,
|
|
|
|
int aOverrideWidth = 0,
|
|
|
|
const wxString& aName = wxT( "" ),
|
|
|
|
const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() )
|
|
|
|
{
|
|
|
|
SHAPE_RECT r( aBox );
|
|
|
|
AddShape( &r, aColor, aOverrideWidth, aName, aSrcLoc );
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddShape( const SEG& aSeg, const KIGFX::COLOR4D& aColor,
|
|
|
|
int aOverrideWidth = 0,
|
|
|
|
const wxString& aName = wxT( "" ),
|
|
|
|
const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN lc;
|
|
|
|
lc.Append( aSeg.A );
|
|
|
|
lc.Append( aSeg.B );
|
|
|
|
AddShape( &lc, aColor, aOverrideWidth, aName, aSrcLoc );
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Clear() {};
|
2021-05-28 22:09:21 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
bool m_debugEnabled;
|
2016-08-15 15:16:51 +00:00
|
|
|
};
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
/* WARNING! The marco below is a remarkably ugly hack, intended to log the
|
2021-05-28 22:09:21 +00:00
|
|
|
call location of the debug calls without having to create the SRC_LOCATION_INFOs every time
|
|
|
|
DEBUG_DECORATOR::Something() is called.
|
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
Also checks if debug is enabled at all prior to calling decorator methods, thus saving some
|
2021-05-28 22:09:21 +00:00
|
|
|
time wasted otherwise for string formatting and copying the geometry. */
|
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
#define PNS_DBG( dbg, method, ... ) \
|
|
|
|
if( dbg && dbg->IsDebugEnabled() ) \
|
|
|
|
dbg->method( __VA_ARGS__, PNS::DEBUG_DECORATOR::SRC_LOCATION_INFO( __FILE__, __FUNCTION__, \
|
|
|
|
__LINE__ ) );
|
2021-05-28 22:09:21 +00:00
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
#define PNS_DBGN( dbg, method ) \
|
|
|
|
if( dbg && dbg->IsDebugEnabled() ) \
|
2021-05-29 22:32:38 +00:00
|
|
|
dbg->method( PNS::DEBUG_DECORATOR::SRC_LOCATION_INFO( __FILE__, __FUNCTION__, __LINE__ ) );
|
|
|
|
|
2021-05-28 22:09:21 +00:00
|
|
|
} // namespace PNS
|
2016-08-29 14:38:11 +00:00
|
|
|
|
2016-08-15 15:16:51 +00:00
|
|
|
#endif
|