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