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 <origin_viewitem.h>
27 
28 using namespace KIGFX;
29 
30 ORIGIN_VIEWITEM::ORIGIN_VIEWITEM( const COLOR4D& aColor, MARKER_STYLE aStyle, int aSize, const VECTOR2D& aPosition ) :
31  EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type
32  m_position( aPosition ), m_size( aSize ), m_color( aColor ), m_style( aStyle ), m_drawAtZero( false )
33 {
34 }
35 
36 
38 {
39  BOX2I bbox;
40  bbox.SetMaximum();
41  return bbox;
42 }
43 
44 
45 void ORIGIN_VIEWITEM::ViewDraw( int, VIEW* aView ) const
46 {
47  auto gal = aView->GetGAL();
48  // Nothing to do if the target shouldn't be drawn at 0,0 and that's where the target is. This
49  // mimics the Legacy canvas that doesn't display most targets at 0,0
50  if( !m_drawAtZero && ( m_position.x == 0 ) && ( m_position.y == 0 ) )
51  return;
52 
53  gal->SetIsStroke( true );
54  gal->SetIsFill( false );
55  gal->SetLineWidth( 1 );
56  gal->SetStrokeColor( m_color );
57  VECTOR2D scaledSize = aView->ToWorld( VECTOR2D( m_size, m_size ), false );
58 
59  // Draw a circle around the marker's centre point if the style demands it
60  if( ( m_style == CIRCLE_CROSS ) || ( m_style == CIRCLE_DOT ) || ( m_style == CIRCLE_X ) )
61  gal->DrawCircle( m_position, fabs( scaledSize.x ) );
62 
63  switch( m_style )
64  {
65  case NONE:
66  break;
67 
68  case CROSS:
69  case CIRCLE_CROSS:
70  gal->DrawLine( m_position - VECTOR2D( scaledSize.x, 0 ),
71  m_position + VECTOR2D( scaledSize.x, 0 ) );
72  gal->DrawLine( m_position - VECTOR2D( 0, scaledSize.y ),
73  m_position + VECTOR2D( 0, scaledSize.y ) );
74  break;
75 
76  case X:
77  case CIRCLE_X:
78  gal->DrawLine( m_position - scaledSize, m_position + scaledSize );
79  scaledSize.y = -scaledSize.y;
80  gal->DrawLine( m_position - scaledSize, m_position + scaledSize );
81  break;
82 
83  case DOT:
84  case CIRCLE_DOT:
85  gal->DrawCircle( m_position, scaledSize.x / 4 );
86  break;
87  }
88 }
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
the 3d code uses this value
Definition: typeinfo.h:92
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:440
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.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
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
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).
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
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
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39