diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 0f58626603..fc6237cd6d 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -32,6 +32,7 @@ set( GAL_SRCS draw_panel_gal.cpp painter.cpp worksheet_viewitem.cpp + origin_viewitem.cpp gal/graphics_abstraction_layer.cpp gal/stroke_font.cpp gal/color4d.cpp diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index 71e27050e5..b7dcebfcc2 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -132,7 +132,7 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) ) // Grid has to be redrawn only when the NONCACHED target is redrawn if( m_view->IsTargetDirty( KIGFX::TARGET_NONCACHED ) ) - m_gal->DrawGrid(); + m_gal->DrawGrid(); m_view->Redraw(); } diff --git a/common/gal/graphics_abstraction_layer.cpp b/common/gal/graphics_abstraction_layer.cpp index c66ae92307..12e4502204 100644 --- a/common/gal/graphics_abstraction_layer.cpp +++ b/common/gal/graphics_abstraction_layer.cpp @@ -56,7 +56,6 @@ GAL::GAL() : // Set grid defaults SetGridVisibility( true ); SetGridStyle( GRID_STYLE_LINES ); - SetGridOriginMarkerSize( 15 ); SetGridDrawThreshold( 10 ); SetCoarseGrid( 10 ); SetGridLineWidth( 0.5 ); @@ -120,19 +119,6 @@ void GAL::DrawGrid() SetTarget( TARGET_NONCACHED ); - // Draw the origin marker - double originSize = gridOriginMarkerSize / worldScale; - SetLayerDepth( GAL::GRID_DEPTH ); - SetIsFill( false ); - SetIsStroke( true ); - SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) ); - SetLineWidth( gridLineWidth / worldScale ); - DrawLine( gridOrigin + VECTOR2D( -originSize, -originSize ), - gridOrigin + VECTOR2D( originSize, originSize ) ); - DrawLine( gridOrigin + VECTOR2D( -originSize, originSize ), - gridOrigin + VECTOR2D( originSize, -originSize ) ); - DrawCircle( gridOrigin, originSize * 0.7 ); - // Draw the grid // For the drawing the start points, end points and increments have // to be calculated in world coordinates diff --git a/common/origin_viewitem.cpp b/common/origin_viewitem.cpp new file mode 100644 index 0000000000..23feb054d7 --- /dev/null +++ b/common/origin_viewitem.cpp @@ -0,0 +1,79 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2015 CERN + * @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 + +using namespace KIGFX; + +ORIGIN_VIEWITEM::ORIGIN_VIEWITEM( const COLOR4D& aColor, MARKER_STYLE aStyle, int aSize, const VECTOR2D& aPosition ) : + EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type + m_position( aPosition ), m_size( aSize ), m_color( aColor ), m_style( aStyle ) +{ +} + + +const BOX2I ORIGIN_VIEWITEM::ViewBBox() const +{ + BOX2I bbox; + bbox.SetMaximum(); + return bbox; +} + + +void ORIGIN_VIEWITEM::ViewDraw( int, GAL* aGal ) const +{ + // Legacy canvas does not draw markers if they are located in the (0, 0) point + if( m_position.x == 0 && m_position.y == 0 ) + return; + + aGal->SetIsStroke( true ); + aGal->SetIsFill( false ); + aGal->SetLineWidth( 1 ); + aGal->SetStrokeColor( m_color ); + VECTOR2D scaledSize = m_view->ToWorld( VECTOR2D( m_size, m_size ), false ); + aGal->DrawCircle( m_position, scaledSize.x ); + + switch( m_style ) + { + case NONE: + break; + + case CROSS: + aGal->DrawLine( m_position - VECTOR2D( scaledSize.x, 0 ), m_position + VECTOR2D( scaledSize.x, 0 ) ); + aGal->DrawLine( m_position - VECTOR2D( 0, scaledSize.y ), m_position + VECTOR2D( 0, scaledSize.y ) ); + break; + + case X: + aGal->DrawLine( m_position - scaledSize, m_position + scaledSize ); + scaledSize.y = -scaledSize.y; + aGal->DrawLine( m_position - scaledSize, m_position + scaledSize ); + break; + + case DOT: + aGal->DrawCircle( m_position, scaledSize.x / 4 ); + break; + } +} diff --git a/common/view/view.cpp b/common/view/view.cpp index f694743300..f43d99253a 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -94,6 +94,9 @@ void VIEW::Add( VIEW_ITEM* aItem ) aItem->ViewGetLayers( layers, layers_count ); aItem->saveLayers( layers, layers_count ); + if( m_dynamic ) + aItem->viewAssign( this ); + for( int i = 0; i < layers_count; ++i ) { VIEW_LAYER& l = m_layers[layers[i]]; @@ -101,9 +104,6 @@ void VIEW::Add( VIEW_ITEM* aItem ) MarkTargetDirty( l.target ); } - if( m_dynamic ) - aItem->viewAssign( this ); - aItem->ViewUpdate( VIEW_ITEM::ALL ); } diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index 2637477244..6c478e8558 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -636,16 +636,6 @@ public: (long) gridOrigin.y % (long) gridSize.y ); } - /** - * @brief Sets the screen size of the grid origin marker - * - * @param aSize is the radius of the origin marker, in pixels. - */ - inline void SetGridOriginMarkerSize( int aSize ) - { - gridOriginMarkerSize = aSize; - } - /** * @brief Set the threshold for grid drawing. * @@ -875,7 +865,6 @@ protected: double gridLineWidth; ///< Line width of the grid int gridDrawThreshold; ///< Minimum screen size of the grid (pixels) ///< below which the grid is not drawn - int gridOriginMarkerSize; ///< Grid origin indicator size (pixels) // Cursor settings bool isCursorEnabled; ///< Is the cursor enabled? diff --git a/include/origin_viewitem.h b/include/origin_viewitem.h new file mode 100644 index 0000000000..d4e690486d --- /dev/null +++ b/include/origin_viewitem.h @@ -0,0 +1,130 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @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 __ORIGIN_VIEWITEM_H +#define __ORIGIN_VIEWITEM_H + +#include +#include +#include +#include +#include + +/** + * Class ORIGIN_VIEWITEM + * + * View item to draw an origin marker. + */ +namespace KIGFX { + +class ORIGIN_VIEWITEM : public EDA_ITEM +{ +public: + ///> Marker symbol styles + enum MARKER_STYLE { NONE, CROSS, X, DOT }; + + ORIGIN_VIEWITEM( const COLOR4D& aColor = COLOR4D( 1.0, 1.0, 1.0, 1.0 ), MARKER_STYLE aStyle = X, + int aSize = 16, const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) ); + + const BOX2I ViewBBox() const; + + void ViewDraw( int aLayer, KIGFX::GAL* aGal ) const; + + void ViewGetLayers( int aLayers[], int& aCount ) const + { + aLayers[0] = ITEM_GAL_LAYER( GP_OVERLAY ); + aCount = 1; + } + +#if defined(DEBUG) + void Show( int x, std::ostream& st ) const + { + } +#endif + + /** Get class name + * @return string "ORIGIN_VIEWITEM" + */ + wxString GetClass() const + { + return wxT( "ORIGIN_VIEWITEM" ); + } + + inline void SetPosition( const VECTOR2D& aPosition ) + { + m_position = aPosition; + } + + inline const VECTOR2D& GetPosition() const + { + return m_position; + } + + inline void SetSize( int aSize ) + { + m_size = aSize; + } + + inline int GetSize() const + { + return m_size; + } + + inline void SetColor( const KIGFX::COLOR4D& aColor ) + { + m_color = aColor; + } + + inline const KIGFX::COLOR4D& GetColor() const + { + return m_color; + } + + inline void SetStyle( MARKER_STYLE aStyle ) + { + m_style = aStyle; + } + + inline MARKER_STYLE GetStyle() const + { + return m_style; + } + +protected: + ///> Marker coordinates. + VECTOR2D m_position; + + ///> Marker size (in pixels). + int m_size; + + ///> Marker color. + COLOR4D m_color; + + ///> Marker symbol. + MARKER_STYLE m_style; +}; + +} // namespace KIGFX + +#endif diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index 97f93602c7..9e565bc301 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -188,7 +188,6 @@ private: LAYER m_Layer[LAYER_ID_COUNT]; - wxPoint m_grid_origin; // if true m_highLight_NetCode is used HIGH_LIGHT_INFO m_highLight; // current high light data HIGH_LIGHT_INFO m_highLightPrevious; // a previously stored high light data diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp index 62a07d3dd8..213bb02da1 100644 --- a/pcbnew/pcb_draw_panel_gal.cpp +++ b/pcbnew/pcb_draw_panel_gal.cpp @@ -165,7 +165,7 @@ EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aGalType ) m_view->SetLayerDisplayOnly( ITEM_GAL_LAYER( DRC_VISIBLE ) ); // Load display options (such as filled/outline display of items). - // Can be made only if the parent windos is a EDA_DRAW_FRAME (or a derived class) + // Can be made only if the parent window is an EDA_DRAW_FRAME (or a derived class) // which is not always the case (namely when it is used from a wxDialog like the pad editor) EDA_DRAW_FRAME* frame = dynamic_cast( aParentWindow ); @@ -212,12 +212,7 @@ void PCB_DRAW_PANEL_GAL::DisplayBoard( const BOARD* aBoard ) m_view->Add( zone ); // Ratsnest - if( m_ratsnest ) - { - m_view->Remove( m_ratsnest ); - delete m_ratsnest; - } - + delete m_ratsnest; m_ratsnest = new KIGFX::RATSNEST_VIEWITEM( aBoard->GetRatsnest() ); m_view->Add( m_ratsnest ); diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index edc597f20d..a1d8e9b9cc 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include @@ -49,12 +50,26 @@ PCBNEW_CONTROL::PCBNEW_CONTROL() : TOOL_INTERACTIVE( "pcbnew.Control" ), m_frame( NULL ) { + m_gridOrigin = new KIGFX::ORIGIN_VIEWITEM(); +} + + +PCBNEW_CONTROL::~PCBNEW_CONTROL() +{ + delete m_gridOrigin; } void PCBNEW_CONTROL::Reset( RESET_REASON aReason ) { m_frame = getEditFrame(); + + if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH ) + { + m_gridOrigin->SetPosition( getModel()->GetGridOrigin() ); + getView()->Remove( m_gridOrigin ); + getView()->Add( m_gridOrigin ); + } } @@ -443,10 +458,12 @@ int PCBNEW_CONTROL::GridPrev( const TOOL_EVENT& aEvent ) } -static bool setOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame, const VECTOR2D& aPoint ) +static bool setOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame, + KIGFX::ORIGIN_VIEWITEM* aItem, const VECTOR2D& aPoint ) { aFrame->SetGridOrigin( wxPoint( aPoint.x, aPoint.y ) ); aView->GetGAL()->SetGridOrigin( aPoint ); + aItem->SetPosition( aPoint ); aView->MarkDirty(); return true; @@ -460,7 +477,7 @@ int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent ) // TODO it will not check the toolbar button in module editor, as it uses a different ID.. m_frame->SetToolID( ID_PCB_PLACE_GRID_COORD_BUTT, wxCURSOR_PENCIL, _( "Adjust grid origin" ) ); - picker->SetClickHandler( boost::bind( setOrigin, getView(), m_frame, _1 ) ); + picker->SetClickHandler( boost::bind( setOrigin, getView(), m_frame, m_gridOrigin, _1 ) ); picker->Activate(); return 0; diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index e449eec0b2..ee95b67f7a 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -27,6 +27,9 @@ #include +namespace KIGFX { + class ORIGIN_VIEWITEM; +} class PCB_BASE_FRAME; /** @@ -39,6 +42,7 @@ class PCBNEW_CONTROL : public TOOL_INTERACTIVE { public: PCBNEW_CONTROL(); + ~PCBNEW_CONTROL(); /// @copydoc TOOL_INTERACTIVE::Reset() void Reset( RESET_REASON aReason ); @@ -90,6 +94,9 @@ private: ///> Pointer to the currently used edit frame. PCB_BASE_FRAME* m_frame; + ///> Grid origin marker. + KIGFX::ORIGIN_VIEWITEM* m_gridOrigin; + ///> Applies the legacy canvas grid settings for GAL. void updateGrid(); };