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 <class_drawpanel.h>
26 #include <draw_frame.h>
27 #include <origin_viewitem.h>
29 
30 using namespace KIGFX;
31 
32 ORIGIN_VIEWITEM::ORIGIN_VIEWITEM( const COLOR4D& aColor, MARKER_STYLE aStyle, int aSize, const VECTOR2D& aPosition ) :
33  BOARD_ITEM( nullptr, NOT_USED ), // this item is never added to a BOARD so it needs no type
34  m_position( aPosition ), m_size( aSize ), m_color( aColor ), m_style( aStyle ), m_drawAtZero( false )
35 {
36 }
37 
38 
40  BOARD_ITEM( nullptr, NOT_USED ), // this item is never added to a BOARD so it needs no type
41  m_position( aPosition ), m_size( NOT_USED ), m_color( UNSPECIFIED_COLOR ), m_style( NONE ), m_drawAtZero( false )
42 {
43  SetFlags( flags );
44 }
45 
46 
48 {
50 }
51 
52 
54 {
55  BOX2I bbox;
56  bbox.SetMaximum();
57  return bbox;
58 }
59 
60 void ORIGIN_VIEWITEM::ViewDraw( int, VIEW* aView ) const
61 {
62  auto gal = aView->GetGAL();
63  // Nothing to do if the target shouldn't be drawn at 0,0 and that's where the target is. This
64  // mimics the Legacy canvas that doesn't display most targets at 0,0
65  if( !m_drawAtZero && ( m_position.x == 0 ) && ( m_position.y == 0 ) )
66  return;
67 
68  gal->SetIsStroke( true );
69  gal->SetIsFill( false );
70  gal->SetLineWidth( 1 );
71  gal->SetStrokeColor( m_color );
72  VECTOR2D scaledSize = aView->ToWorld( VECTOR2D( m_size, m_size ), false );
73 
74  // Draw a circle around the marker's centre point if the style demands it
75  if( ( m_style == CIRCLE_CROSS ) || ( m_style == CIRCLE_DOT ) || ( m_style == CIRCLE_X ) )
76  gal->DrawCircle( m_position, fabs( scaledSize.x ) );
77 
78  switch( m_style )
79  {
80  case NONE:
81  break;
82 
83  case CROSS:
84  case CIRCLE_CROSS:
85  gal->DrawLine( m_position - VECTOR2D( scaledSize.x, 0 ),
86  m_position + VECTOR2D( scaledSize.x, 0 ) );
87  gal->DrawLine( m_position - VECTOR2D( 0, scaledSize.y ),
88  m_position + VECTOR2D( 0, scaledSize.y ) );
89  break;
90 
91  case X:
92  case CIRCLE_X:
93  gal->DrawLine( m_position - scaledSize, m_position + scaledSize );
94  scaledSize.y = -scaledSize.y;
95  gal->DrawLine( m_position - scaledSize, m_position + scaledSize );
96  break;
97 
98  case DOT:
99  case CIRCLE_DOT:
100  gal->DrawCircle( m_position, scaledSize.x / 4 );
101  break;
102  }
103 }
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...
the 3d code uses this value
Definition: typeinfo.h:80
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:463
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:264
VECTOR2< double > VECTOR2D
Definition: vector2d.h:588
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:177
void SetMaximum()
Definition: box2.h:61
unsigned STATUS_FLAGS
Definition: base_struct.h:142
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:58
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