diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 85dea19ef1..f0138cd942 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -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 diff --git a/common/view/view.cpp b/common/view/view.cpp index df44d5c199..22fe7fe671 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -31,6 +31,8 @@ #include #include #include +#include + #include #include #include @@ -1546,6 +1548,16 @@ void VIEW::Update( VIEW_ITEM* aItem, int aUpdateFlags ) } + +std::shared_ptr VIEW::MakeOverlay() +{ + std::shared_ptr overlay( new VIEW_OVERLAY ); + + Add( overlay.get() ); + return overlay; +} + + const int VIEW::TOP_LAYER_MODIFIER = -VIEW_MAX_LAYERS; } diff --git a/common/view/view_overlay.cpp b/common/view/view_overlay.cpp new file mode 100644 index 0000000000..a097349852 --- /dev/null +++ b/common/view/view_overlay.cpp @@ -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 + * @author Maciej Suminski + * + * 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 +#include +#include +#include +#include + +#include +#include + +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& 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& 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 diff --git a/include/view/view.h b/include/view/view.h index ad8635fefd..35e917feab 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -28,10 +28,13 @@ #include #include #include +#include #include #include +#include + namespace KIGFX { class PAINTER; @@ -62,6 +65,8 @@ public: typedef std::pair 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 MakeOverlay(); private: struct VIEW_LAYER diff --git a/include/view/view_overlay.h b/include/view/view_overlay.h new file mode 100644 index 0000000000..7501041f9f --- /dev/null +++ b/include/view/view_overlay.h @@ -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 + * @author Maciej Suminski + * + * 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 +#include + +#include +#include + +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& 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& 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 m_commands; +}; + +} // namespace KIGFX + + +#endif