Refactored grid origin point drawing (GAL).
This commit is contained in:
parent
2ebacfa3c2
commit
28a270a328
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <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 <origin_viewitem.h>
|
||||
#include <gal/graphics_abstraction_layer.h>
|
||||
#include <class_track.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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 <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 __ORIGIN_VIEWITEM_H
|
||||
#define __ORIGIN_VIEWITEM_H
|
||||
|
||||
#include <math/box2.h>
|
||||
#include <view/view.h>
|
||||
#include <class_board_item.h>
|
||||
#include <layers_id_colors_and_visibility.h>
|
||||
#include <gal/color4d.h>
|
||||
|
||||
/**
|
||||
* 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
|
|
@ -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
|
||||
|
|
|
@ -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<EDA_DRAW_FRAME*>( 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 );
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include <gal/graphics_abstraction_layer.h>
|
||||
#include <view/view_controls.h>
|
||||
#include <pcb_painter.h>
|
||||
#include <origin_viewitem.h>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
|
@ -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<PCB_BASE_FRAME>();
|
||||
|
||||
if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH )
|
||||
{
|
||||
m_gridOrigin->SetPosition( getModel<BOARD>()->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;
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
|
||||
#include <tool/tool_interactive.h>
|
||||
|
||||
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();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue