VIEW: added support for VIEW_OVERLAYS (temporary overlays for drawing debug graphics)
x
This commit is contained in:
parent
33946ea92f
commit
2186db976b
|
@ -43,6 +43,7 @@ set( GAL_SRCS
|
|||
gal/stroke_font.cpp
|
||||
geometry/hetriang.cpp
|
||||
view/view_controls.cpp
|
||||
view/view_overlay.cpp
|
||||
view/wx_view_controls.cpp
|
||||
|
||||
# OpenGL GAL
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include <view/view_group.h>
|
||||
#include <view/view_item.h>
|
||||
#include <view/view_rtree.h>
|
||||
#include <view/view_overlay.h>
|
||||
|
||||
#include <gal/definitions.h>
|
||||
#include <gal/graphics_abstraction_layer.h>
|
||||
#include <painter.h>
|
||||
|
@ -1546,6 +1548,16 @@ void VIEW::Update( VIEW_ITEM* aItem, int aUpdateFlags )
|
|||
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<VIEW_OVERLAY> VIEW::MakeOverlay()
|
||||
{
|
||||
std::shared_ptr<VIEW_OVERLAY> overlay( new VIEW_OVERLAY );
|
||||
|
||||
Add( overlay.get() );
|
||||
return overlay;
|
||||
}
|
||||
|
||||
|
||||
const int VIEW::TOP_LAYER_MODIFIER = -VIEW_MAX_LAYERS;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,283 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2013-2017 CERN
|
||||
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
||||
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
||||
*
|
||||
* 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 2
|
||||
* 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, you may find one here:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <view/view.h>
|
||||
#include <view/view_item.h>
|
||||
#include <view/view_overlay.h>
|
||||
#include <gal/graphics_abstraction_layer.h>
|
||||
#include <painter.h>
|
||||
|
||||
#include <layers_id_colors_and_visibility.h>
|
||||
#include <geometry/seg.h>
|
||||
|
||||
namespace KIGFX {
|
||||
|
||||
struct VIEW_OVERLAY::COMMAND
|
||||
{
|
||||
virtual ~COMMAND() {};
|
||||
virtual void Execute( VIEW* aView ) const = 0;
|
||||
};
|
||||
|
||||
|
||||
struct VIEW_OVERLAY::COMMAND_LINE : public VIEW_OVERLAY::COMMAND
|
||||
{
|
||||
COMMAND_LINE( const VECTOR2D& aP0, const VECTOR2D& aP1 ) :
|
||||
m_p0( aP0 ),
|
||||
m_p1( aP1 ) {};
|
||||
|
||||
virtual void Execute( VIEW* aView ) const override
|
||||
{
|
||||
aView->GetGAL()->DrawLine( m_p0, m_p1 );
|
||||
}
|
||||
|
||||
VECTOR2D m_p0, m_p1;
|
||||
};
|
||||
|
||||
|
||||
struct VIEW_OVERLAY::COMMAND_CIRCLE : public VIEW_OVERLAY::COMMAND
|
||||
{
|
||||
COMMAND_CIRCLE( const VECTOR2D& aCenter, double aRadius ) :
|
||||
m_center(aCenter),
|
||||
m_radius(aRadius)
|
||||
{}
|
||||
|
||||
virtual void Execute( VIEW* aView ) const override
|
||||
{
|
||||
aView->GetGAL()->DrawCircle( m_center, m_radius );
|
||||
}
|
||||
|
||||
VECTOR2D m_center;
|
||||
double m_radius;
|
||||
};
|
||||
|
||||
|
||||
struct VIEW_OVERLAY::COMMAND_ARC : public VIEW_OVERLAY::COMMAND
|
||||
{
|
||||
COMMAND_ARC( const VECTOR2D& aCenter, double aRadius, double aStartAngle, double aEndAngle ) :
|
||||
m_center(aCenter),
|
||||
m_radius(aRadius),
|
||||
m_startAngle( aStartAngle ),
|
||||
m_endAngle( aEndAngle )
|
||||
{}
|
||||
|
||||
virtual void Execute( VIEW* aView ) const override
|
||||
{
|
||||
aView->GetGAL()->DrawArc( m_center, m_radius, m_startAngle, m_endAngle );
|
||||
}
|
||||
|
||||
VECTOR2D m_center;
|
||||
double m_startAngle, m_endAngle;
|
||||
double m_radius;
|
||||
};
|
||||
|
||||
|
||||
struct VIEW_OVERLAY::COMMAND_SET_STROKE : public VIEW_OVERLAY::COMMAND
|
||||
{
|
||||
COMMAND_SET_STROKE( bool aIsStroke ) :
|
||||
m_isStroke( aIsStroke ) {}
|
||||
|
||||
virtual void Execute( VIEW* aView ) const override
|
||||
{
|
||||
aView->GetGAL()->SetIsStroke( m_isStroke );
|
||||
}
|
||||
|
||||
bool m_isStroke;
|
||||
};
|
||||
|
||||
|
||||
struct VIEW_OVERLAY::COMMAND_SET_FILL : public VIEW_OVERLAY::COMMAND
|
||||
{
|
||||
COMMAND_SET_FILL( bool aIsFill ) :
|
||||
m_isFill( aIsFill ) {}
|
||||
|
||||
virtual void Execute( VIEW* aView ) const override
|
||||
{
|
||||
aView->GetGAL()->SetIsFill( m_isFill );
|
||||
}
|
||||
|
||||
bool m_isFill;
|
||||
};
|
||||
|
||||
|
||||
struct VIEW_OVERLAY::COMMAND_SET_COLOR : public VIEW_OVERLAY::COMMAND
|
||||
{
|
||||
COMMAND_SET_COLOR( bool aIsStroke, const COLOR4D& aColor ) :
|
||||
m_isStroke( aIsStroke ),
|
||||
m_color( aColor )
|
||||
{}
|
||||
|
||||
virtual void Execute( VIEW* aView ) const override
|
||||
{
|
||||
if( m_isStroke )
|
||||
aView->GetGAL()->SetStrokeColor( m_color );
|
||||
else
|
||||
aView->GetGAL()->SetFillColor( m_color );
|
||||
}
|
||||
|
||||
bool m_isStroke;
|
||||
COLOR4D m_color;
|
||||
};
|
||||
|
||||
|
||||
struct VIEW_OVERLAY::COMMAND_SET_WIDTH : public VIEW_OVERLAY::COMMAND
|
||||
{
|
||||
COMMAND_SET_WIDTH( double aWidth ) :
|
||||
m_width( aWidth )
|
||||
{}
|
||||
|
||||
virtual void Execute( VIEW* aView ) const override
|
||||
{
|
||||
aView->GetGAL()->SetLineWidth( m_width );
|
||||
}
|
||||
|
||||
double m_width;
|
||||
};
|
||||
|
||||
|
||||
VIEW_OVERLAY::VIEW_OVERLAY()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
VIEW_OVERLAY::~VIEW_OVERLAY()
|
||||
{
|
||||
releaseCommands();
|
||||
}
|
||||
|
||||
|
||||
void VIEW_OVERLAY::releaseCommands()
|
||||
{
|
||||
for( auto cmd : m_commands )
|
||||
delete cmd;
|
||||
|
||||
m_commands.clear();
|
||||
}
|
||||
|
||||
|
||||
void VIEW_OVERLAY::Clear()
|
||||
{
|
||||
releaseCommands();
|
||||
}
|
||||
|
||||
|
||||
const BOX2I VIEW_OVERLAY::ViewBBox() const
|
||||
{
|
||||
BOX2I maxBox;
|
||||
|
||||
maxBox.SetMaximum();
|
||||
return maxBox;
|
||||
}
|
||||
|
||||
|
||||
void VIEW_OVERLAY::ViewDraw( int aLayer, VIEW* aView ) const
|
||||
{
|
||||
for( const auto& cmd : m_commands )
|
||||
cmd->Execute( aView );
|
||||
}
|
||||
|
||||
|
||||
void VIEW_OVERLAY::ViewGetLayers( int aLayers[], int& aCount ) const
|
||||
{
|
||||
aLayers[0] = LAYER_GP_OVERLAY;
|
||||
aCount = 1;
|
||||
}
|
||||
|
||||
|
||||
void VIEW_OVERLAY::Line( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
|
||||
{
|
||||
m_commands.push_back( new COMMAND_LINE( aStartPoint, aEndPoint ) );
|
||||
}
|
||||
|
||||
|
||||
void VIEW_OVERLAY::Line( const SEG& aSeg )
|
||||
{
|
||||
Line( aSeg.A, aSeg.B );
|
||||
}
|
||||
|
||||
|
||||
void VIEW_OVERLAY::Segment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint, double aWidth )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void VIEW_OVERLAY::Polyline( std::deque<VECTOR2D>& aPointList )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void VIEW_OVERLAY::Circle( const VECTOR2D& aCenterPoint, double aRadius )
|
||||
{
|
||||
m_commands.push_back( new COMMAND_CIRCLE( aCenterPoint, aRadius ) );
|
||||
}
|
||||
|
||||
|
||||
void VIEW_OVERLAY::Arc( const VECTOR2D& aCenterPoint,
|
||||
double aRadius,
|
||||
double aStartAngle,
|
||||
double aEndAngle )
|
||||
{
|
||||
m_commands.push_back( new COMMAND_ARC( aCenterPoint, aRadius, aStartAngle, aEndAngle ) );
|
||||
}
|
||||
|
||||
|
||||
void VIEW_OVERLAY::Rectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void VIEW_OVERLAY::Polygon( const std::deque<VECTOR2D>& aPointList )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void VIEW_OVERLAY::SetIsFill( bool aIsFillEnabled )
|
||||
{
|
||||
m_commands.push_back( new COMMAND_SET_FILL( aIsFillEnabled ) );
|
||||
}
|
||||
|
||||
|
||||
void VIEW_OVERLAY::SetIsStroke( bool aIsStrokeEnabled )
|
||||
{
|
||||
m_commands.push_back( new COMMAND_SET_STROKE( aIsStrokeEnabled ) );
|
||||
}
|
||||
|
||||
|
||||
void VIEW_OVERLAY::SetFillColor( const COLOR4D& aColor )
|
||||
{
|
||||
m_commands.push_back( new COMMAND_SET_COLOR( false, aColor ) );
|
||||
}
|
||||
|
||||
|
||||
void VIEW_OVERLAY::SetStrokeColor( const COLOR4D& aColor )
|
||||
{
|
||||
m_commands.push_back( new COMMAND_SET_COLOR( true, aColor ) );
|
||||
}
|
||||
|
||||
void VIEW_OVERLAY::SetLineWidth( double aLineWidth )
|
||||
{
|
||||
m_commands.push_back( new COMMAND_SET_WIDTH( aLineWidth ) );
|
||||
}
|
||||
|
||||
} // namespace
|
|
@ -28,10 +28,13 @@
|
|||
#include <vector>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
#include <math/box2.h>
|
||||
#include <gal/definitions.h>
|
||||
|
||||
#include <view/view_overlay.h>
|
||||
|
||||
namespace KIGFX
|
||||
{
|
||||
class PAINTER;
|
||||
|
@ -62,6 +65,8 @@ public:
|
|||
|
||||
typedef std::pair<VIEW_ITEM*, int> LAYER_ITEM_PAIR;
|
||||
|
||||
static const int VIEW_MAX_LAYERS = 512; ///< maximum number of layers that may be shown
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param aIsDynamic decides whether we are creating a static or a dynamic VIEW.
|
||||
|
@ -681,8 +686,7 @@ public:
|
|||
m_reverseDrawOrder = aFlag;
|
||||
}
|
||||
|
||||
static const int VIEW_MAX_LAYERS = 512; ///< maximum number of layers that may be shown
|
||||
|
||||
std::shared_ptr<VIEW_OVERLAY> MakeOverlay();
|
||||
|
||||
private:
|
||||
struct VIEW_LAYER
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2013-2017 CERN
|
||||
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
||||
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
||||
*
|
||||
* 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 2
|
||||
* 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, you may find one here:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#ifndef __VIEW_OVERLAY_H
|
||||
#define __VIEW_OVERLAY_H
|
||||
|
||||
#include <view/view_item.h>
|
||||
#include <gal/graphics_abstraction_layer.h>
|
||||
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
|
||||
class SEG;
|
||||
|
||||
namespace KIGFX
|
||||
{
|
||||
class VIEW;
|
||||
|
||||
class VIEW_OVERLAY : public VIEW_ITEM
|
||||
{
|
||||
public:
|
||||
|
||||
VIEW_OVERLAY();
|
||||
virtual ~VIEW_OVERLAY();
|
||||
|
||||
struct COMMAND;
|
||||
struct COMMAND_ARC;
|
||||
struct COMMAND_LINE;
|
||||
struct COMMAND_CIRCLE;
|
||||
struct COMMAND_SET_STROKE;
|
||||
struct COMMAND_SET_FILL;
|
||||
struct COMMAND_SET_COLOR;
|
||||
struct COMMAND_SET_WIDTH;
|
||||
|
||||
void Clear();
|
||||
|
||||
virtual const BOX2I ViewBBox() const override;
|
||||
virtual void ViewDraw( int aLayer, VIEW *aView ) const override;
|
||||
virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
|
||||
|
||||
void Line( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint );
|
||||
void Line( const SEG& aSeg );
|
||||
void Segment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint, double aWidth );
|
||||
void Polyline( std::deque<VECTOR2D>& aPointList );
|
||||
void Circle( const VECTOR2D& aCenterPoint, double aRadius );
|
||||
void Arc( const VECTOR2D& aCenterPoint, double aRadius, double aStartAngle, double aEndAngle );
|
||||
void Rectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint );
|
||||
void Polygon( const std::deque<VECTOR2D>& aPointList );
|
||||
void SetIsFill( bool aIsFillEnabled );
|
||||
void SetIsStroke( bool aIsStrokeEnabled );
|
||||
void SetFillColor( const COLOR4D& aColor );
|
||||
void SetStrokeColor( const COLOR4D& aColor );
|
||||
|
||||
void SetLineWidth( double aLineWidth );
|
||||
|
||||
private:
|
||||
void releaseCommands();
|
||||
|
||||
std::vector<COMMAND*> m_commands;
|
||||
};
|
||||
|
||||
} // namespace KIGFX
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue