KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <array>
27#include <eda_draw_frame.h>
30#include <origin_viewitem.h>
31
32using namespace KIGFX;
33
34ORIGIN_VIEWITEM::ORIGIN_VIEWITEM( const COLOR4D& aColor, MARKER_STYLE aStyle, int aSize,
35 const VECTOR2D& aPosition ) :
36 EDA_ITEM( nullptr, NOT_USED ), // never added to a BOARD/SCHEMATIC so it needs no type
37 m_position( aPosition ),
38 m_size( aSize ),
39 m_color( aColor ),
40 m_style( aStyle ),
41 m_drawAtZero( false )
42{
43}
44
45
47 EDA_ITEM( nullptr, NOT_USED ), // never added to a BOARD/SCHEMATIC so it needs no type
48 m_position( aPosition ),
49 m_size( NOT_USED ),
50 m_color( UNSPECIFIED_COLOR ),
51 m_style( NO_GRAPHIC ),
52 m_drawAtZero( false )
53{
54 SetFlags( flags );
55}
56
57
59{
61}
62
63
65{
66 BOX2I bbox;
67 bbox.SetMaximum();
68 return bbox;
69}
70
71void ORIGIN_VIEWITEM::ViewDraw( int, VIEW* aView ) const
72{
73 GAL* gal = aView->GetGAL();
74
75 // Nothing to do if the target shouldn't be drawn at 0,0 and that's where the target is.
76 if( !m_drawAtZero && ( m_position.x == 0 ) && ( m_position.y == 0 ) )
77 return;
78
79 gal->SetIsStroke( true );
80 gal->SetIsFill( false );
81 gal->SetLineWidth( 1 );
82 gal->SetStrokeColor( m_color );
83 VECTOR2D scaledSize = aView->ToWorld( VECTOR2D( m_size, m_size ), false );
84
85 // Draw a circle around the marker's center point if the style demands it
87 gal->DrawCircle( m_position, fabs( scaledSize.x ) );
88
89 switch( m_style )
90 {
91 case NO_GRAPHIC:
92 break;
93
94 case CROSS:
95 case CIRCLE_CROSS:
96 gal->DrawLine( m_position - VECTOR2D( scaledSize.x, 0 ),
97 m_position + VECTOR2D( scaledSize.x, 0 ) );
98 gal->DrawLine( m_position - VECTOR2D( 0, scaledSize.y ),
99 m_position + VECTOR2D( 0, scaledSize.y ) );
100 break;
101
102 case CIRCLE_X:
103 gal->DrawLine( m_position - scaledSize, m_position + scaledSize );
104 scaledSize.y = -scaledSize.y;
105 gal->DrawLine( m_position - scaledSize, m_position + scaledSize );
106 break;
107 }
108}
constexpr void SetMaximum()
Definition: box2.h:80
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:98
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:142
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Abstract interface for drawing on a 2D-surface.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
ORIGIN_VIEWITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
COLOR4D m_color
(in pixels)
void ViewDraw(int aLayer, VIEW *aView) const override
Draw the parts of the object belonging to layer aLayer.
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))
MARKER_STYLE
Marker symbol styles.
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:66
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:202
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
Definition: view.cpp:467
@ UNSPECIFIED_COLOR
Definition: color4d.h:43
std::uint32_t EDA_ITEM_FLAGS
a few functions useful in geometry calculations.
The Cairo implementation of the graphics abstraction layer.
Definition: eda_group.h:33
@ NOT_USED
the 3d code uses this value
Definition: typeinfo.h:79
VECTOR2< double > VECTOR2D
Definition: vector2d.h:694