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 #include <class_track.h>
28 
29 using namespace KIGFX;
30 
31 ORIGIN_VIEWITEM::ORIGIN_VIEWITEM( const COLOR4D& aColor, MARKER_STYLE aStyle, int aSize, const VECTOR2D& aPosition ) :
32  EDA_ITEM( 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 {
40  BOX2I bbox;
41  bbox.SetMaximum();
42  return bbox;
43 }
44 
45 
46 void ORIGIN_VIEWITEM::ViewDraw( int, VIEW* aView ) const
47 {
48  auto gal = aView->GetGAL();
49  // Nothing to do if the target shouldn't be drawn at 0,0 and that's where the target is. This
50  // mimics the Legacy canvas that doesn't display most targets at 0,0
51  if( !m_drawAtZero && ( m_position.x == 0 ) && ( m_position.y == 0 ) )
52  return;
53 
54  gal->SetIsStroke( true );
55  gal->SetIsFill( false );
56  gal->SetLineWidth( 1 );
57  gal->SetStrokeColor( m_color );
58  VECTOR2D scaledSize = aView->ToWorld( VECTOR2D( m_size, m_size ), false );
59 
60  // Draw a circle around the marker's centre point if the style demands it
61  if( ( m_style == CIRCLE_CROSS ) || ( m_style == CIRCLE_DOT ) || ( m_style == CIRCLE_X ) )
62  gal->DrawCircle( m_position, fabs( scaledSize.x ) );
63 
64  switch( m_style )
65  {
66  case NONE:
67  break;
68 
69  case CROSS:
70  case CIRCLE_CROSS:
71  gal->DrawLine( m_position - VECTOR2D( scaledSize.x, 0 ),
72  m_position + VECTOR2D( scaledSize.x, 0 ) );
73  gal->DrawLine( m_position - VECTOR2D( 0, scaledSize.y ),
74  m_position + VECTOR2D( 0, scaledSize.y ) );
75  break;
76 
77  case X:
78  case CIRCLE_X:
79  gal->DrawLine( m_position - scaledSize, m_position + scaledSize );
80  scaledSize.y = -scaledSize.y;
81  gal->DrawLine( m_position - scaledSize, m_position + scaledSize );
82  break;
83 
84  case DOT:
85  case CIRCLE_DOT:
86  gal->DrawCircle( m_position, scaledSize.x / 4 );
87  break;
88  }
89 }
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:57
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.
Functions relatives to tracks, vias and segments used to fill zones.
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