KiCad PCB EDA Suite
origin_viewitem.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <eda_draw_frame.h>
26 #include <origin_viewitem.h>
28 
29 using namespace KIGFX;
30 
31 ORIGIN_VIEWITEM::ORIGIN_VIEWITEM( const COLOR4D& aColor, MARKER_STYLE aStyle, int aSize, const VECTOR2D& aPosition ) :
32  BOARD_ITEM( nullptr, NOT_USED ), // this item is never added to a BOARD so it needs no type
33  m_position( aPosition ),
34  m_size( aSize ),
35  m_color( aColor ),
36  m_style( aStyle ),
37  m_drawAtZero( false )
38 {
39 }
40 
41 
43  BOARD_ITEM( nullptr, NOT_USED ), // this item is never added to a BOARD so it needs no type
44  m_position( aPosition ),
45  m_size( NOT_USED ),
46  m_color( UNSPECIFIED_COLOR ),
47  m_style( NO_GRAPHIC ),
48  m_drawAtZero( false )
49 {
50  SetFlags( flags );
51 }
52 
53 
55 {
57 }
58 
59 
61 {
62  BOX2I bbox;
63  bbox.SetMaximum();
64  return bbox;
65 }
66 
67 void ORIGIN_VIEWITEM::ViewDraw( int, VIEW* aView ) const
68 {
69  auto gal = aView->GetGAL();
70 
71  // Nothing to do if the target shouldn't be drawn at 0,0 and that's where the target is.
72  if( !m_drawAtZero && ( m_position.x == 0 ) && ( m_position.y == 0 ) )
73  return;
74 
75  gal->SetIsStroke( true );
76  gal->SetIsFill( false );
77  gal->SetLineWidth( 1 );
78  gal->SetStrokeColor( m_color );
79  VECTOR2D scaledSize = aView->ToWorld( VECTOR2D( m_size, m_size ), false );
80 
81  // Draw a circle around the marker's centre point if the style demands it
82  if( ( m_style == CIRCLE_CROSS ) || ( m_style == CIRCLE_DOT ) || ( m_style == CIRCLE_X ) )
83  gal->DrawCircle( m_position, fabs( scaledSize.x ) );
84 
85  switch( m_style )
86  {
87  case NO_GRAPHIC:
88  break;
89 
90  case CROSS:
91  case CIRCLE_CROSS:
92  gal->DrawLine( m_position - VECTOR2D( scaledSize.x, 0 ),
93  m_position + VECTOR2D( scaledSize.x, 0 ) );
94  gal->DrawLine( m_position - VECTOR2D( 0, scaledSize.y ),
95  m_position + VECTOR2D( 0, scaledSize.y ) );
96  break;
97 
98  case X:
99  case CIRCLE_X:
100  gal->DrawLine( m_position - scaledSize, m_position + scaledSize );
101  scaledSize.y = -scaledSize.y;
102  gal->DrawLine( m_position - scaledSize, m_position + scaledSize );
103  break;
104 
105  case DOT:
106  case CIRCLE_DOT:
107  gal->DrawCircle( m_position, scaledSize.x / 4 );
108  break;
109  }
110 }
ORIGIN_VIEWITEM(const COLOR4D &aColor=COLOR4D(1.0, 1.0, 1.0, 1.0), MARKER_STYLE aStyle=CIRCLE_X, int aSize=16, const VECTOR2D &aPosition=VECTOR2D(0, 0))
COLOR4D m_color
Marker color.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToWorld() Converts a screen space point/vector to a point/vector in world space coordinates.
Definition: view.cpp:475
the 3d code uses this value
Definition: typeinfo.h:80
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
VECTOR2D m_position
Marker coordinates.
void ViewDraw(int aLayer, VIEW *aView) const override
Function ViewDraw() Draws the parts of the object belonging to layer aLayer.
MARKER_STYLE m_style
Marker symbol.
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:265
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
void SetMaximum()
Definition: box2.h:71
unsigned STATUS_FLAGS
Definition: base_struct.h:156
const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
int m_size
Marker size (in pixels).
bool m_drawAtZero
If set, the marker will be drawn even if its position is 0,0
Class VIEW.
Definition: view.h:61
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
MARKER_STYLE
Marker symbol styles
ORIGIN_VIEWITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39