KiCad PCB EDA Suite
marker_base.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) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
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 
33 #include "fctsys.h"
34 #include "gr_basic.h"
35 #include "base_screen.h"
36 #include "common.h"
37 #include "macros.h"
38 #include "marker_base.h"
40 
41 
42 // Default marquer shape:
43 const int M_SHAPE_SCALE = 6; // default scaling factor for MarkerShapeCorners coordinates
44 /* The graphic shape of markers is a polygon.
45  * MarkerShapeCorners contains the coordinates of corners of the polygonal default shape
46  * actual coordinates are these values * .m_ScalingFactor
47 */
48 static const wxPoint MarkerShapeCorners[] =
49 {
50  wxPoint( 0, 0 ),
51  wxPoint( 8, 1 ),
52  wxPoint( 4, 3 ),
53  wxPoint( 13, 8 ),
54  wxPoint( 9, 9 ),
55  wxPoint( 8, 13 ),
56  wxPoint( 3, 4 ),
57  wxPoint( 1, 8 )
58 };
59 const unsigned CORNERS_COUNT = DIM( MarkerShapeCorners );
60 
61 /*******************/
62 /* Classe MARKER_BASE */
63 /*******************/
64 
66 {
69  m_Color = RED;
70  wxPoint start = MarkerShapeCorners[0];
71  wxPoint end = MarkerShapeCorners[0];
72 
73  for( unsigned ii = 0; ii < CORNERS_COUNT; ii++ )
74  {
75  wxPoint corner = MarkerShapeCorners[ii];
76  start.x = std::min( start.x, corner.x);
77  start.y = std::min( start.y, corner.y);
78  end.x = std::max( end.x, corner.x);
79  end.y = std::max( end.y, corner.y);
80  }
81 
84 }
85 
86 
88 {
89  m_Pos = aMarker.m_Pos;
90  m_ErrorLevel = aMarker.m_ErrorLevel;
91  m_MarkerType = aMarker.m_MarkerType;
92  m_Color = aMarker.m_Color;
95 }
96 
97 
99 {
101  init();
102 }
103 
104 
105 MARKER_BASE::MARKER_BASE( EDA_UNITS_T aUnits, int aErrorCode, const wxPoint& aMarkerPos,
106  EDA_ITEM* aItem, const wxPoint& aPos,
107  EDA_ITEM* bItem, const wxPoint& bPos )
108 {
110  init();
111 
112  SetData( aUnits, aErrorCode, aMarkerPos, aItem, aPos, bItem, bPos );
113 }
114 
115 
116 MARKER_BASE::MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos,
117  const wxString& aText, const wxPoint& aPos,
118  const wxString& bText, const wxPoint& bPos )
119 {
121  init();
122 
123  SetData( aErrorCode, aMarkerPos, aText, aPos, bText, bPos );
124 }
125 
126 
127 MARKER_BASE::MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos,
128  const wxString& aText, const wxPoint& aPos )
129 {
131  init();
132 
133  SetData( aErrorCode, aMarkerPos, aText, aPos );
134 }
135 
136 
138 {
139 }
140 
141 
142 void MARKER_BASE::SetData( EDA_UNITS_T aUnits, int aErrorCode, const wxPoint& aMarkerPos,
143  EDA_ITEM* aItem, const wxPoint& aPos,
144  EDA_ITEM* bItem, const wxPoint& bPos )
145 {
146  m_Pos = aMarkerPos;
147  m_drc.SetData( aUnits, aErrorCode, aItem, aPos, bItem, bPos );
148  m_drc.SetParent( this );
149 }
150 
151 
152 void MARKER_BASE::SetData( int aErrorCode, const wxPoint& aMarkerPos,
153  const wxString& aText, const wxPoint& aPos,
154  const wxString& bText, const wxPoint& bPos )
155 {
156  m_Pos = aMarkerPos;
157  m_drc.SetData( aErrorCode, aText, aPos, bText, bPos );
158  m_drc.SetParent( this );
159 }
160 
161 
162 bool MARKER_BASE::HitTestMarker( const wxPoint& refPos ) const
163 {
164  wxPoint rel_pos = refPos - m_Pos;
165  rel_pos.x /= m_ScalingFactor;
166  rel_pos.y /= m_ScalingFactor;
167 
168  return m_ShapeBoundingBox.Contains( rel_pos );
169 }
170 
171 
173 {
174  wxSize realsize = m_ShapeBoundingBox.GetSize();
175  wxPoint realposition = m_ShapeBoundingBox.GetPosition();
176  realsize.x *= m_ScalingFactor;
177  realsize.y *= m_ScalingFactor;
178  realposition.x *= m_ScalingFactor;
179  realposition.y *= m_ScalingFactor;
180  realposition += m_Pos;
181  return EDA_RECT( m_Pos, realsize );
182 }
183 
184 
185 
187 {
188  wxString msg = m_drc.ShowHtml( aFrame->GetUserUnits() );
189  DIALOG_DISPLAY_HTML_TEXT_BASE infodisplay( (wxWindow*)aFrame, wxID_ANY, _( "Marker Info" ),
190  wxGetMousePosition(), wxSize( 550, 140 ) );
191 
192  infodisplay.m_htmlWindow->SetPage( msg );
193  infodisplay.ShowModal();
194 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
MARKER_SEVERITY m_ErrorLevel
Specify the severity of the error.
Definition: marker_base.h:60
bool HitTestMarker(const wxPoint &ref_pos) const
Function HitTestMarker tests if the given wxPoint is within the bounds of this object.
const wxSize GetSize() const
Definition: eda_rect.h:101
bool Contains(const wxPoint &aPoint) const
Function Contains.
EDA_RECT GetBoundingBoxMarker() const
Function GetBoundingBoxMarker returns the orthogonal, bounding box of this object for display purpose...
wxPoint m_Pos
position of the marker
Definition: marker_base.h:54
void SetData(EDA_UNITS_T aUnits, int aErrorCode, const wxPoint &aMarkerPos, EDA_ITEM *aItem, const wxPoint &aPos, EDA_ITEM *bItem=nullptr, const wxPoint &bPos=wxPoint())
Function SetData fills in all the reportable data associated with a MARKER.
void SetParent(MARKER_BASE *aMarker)
Definition: drc_item.h:151
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:124
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
TYPEMARKER m_MarkerType
The type of marker (useful to filter markers)
Definition: marker_base.h:59
This file contains miscellaneous commonly used macros and functions.
const int M_SHAPE_SCALE
Definition: marker_base.cpp:43
void DisplayMarkerInfo(EDA_DRAW_FRAME *aFrame)
Function DisplayMarkerInfo displays the full info of this marker, in a HTML window.
void SetData(EDA_UNITS_T aUnits, int aErrorCode, EDA_ITEM *aMainItem, const wxPoint &aMainPos, EDA_ITEM *bAuxiliaryItem=nullptr, const wxPoint &bAuxiliaryPos=wxPoint())
Function SetData initialize all data in item.
Definition: drc_item.h:91
static const wxPoint MarkerShapeCorners[]
Definition: marker_base.cpp:48
Class DIALOG_DISPLAY_HTML_TEXT_BASE.
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:284
const unsigned CORNERS_COUNT
Definition: marker_base.cpp:59
void SetEnd(int x, int y)
Definition: eda_rect.h:134
COLOR4D m_Color
color
Definition: marker_base.h:61
int m_ScalingFactor
Scaling factor for m_Size and m_Corners (can set the physical size)
Definition: marker_base.h:55
Definition: colors.h:60
EDA_RECT m_ShapeBoundingBox
Bounding box of the graphic symbol, relative to the position of the shape, used for Hit Tests...
Definition: marker_base.h:62
const wxPoint GetPosition() const
Definition: eda_rect.h:113
wxString ShowHtml(EDA_UNITS_T aUnits) const
Function ShowHtml translates this object into a fragment of HTML suitable for the wxWidget&#39;s wxHtmlLi...
Definition: drc_item.cpp:156
#define max(a, b)
Definition: auxiliary.h:86
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
The common library.
BASE_SCREEN class implementation.
DRC_ITEM m_drc
Definition: marker_base.h:65
EDA_UNITS_T
Definition: common.h:159
#define min(a, b)
Definition: auxiliary.h:85