KiCad PCB EDA Suite
class_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) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2014 KiCad Developers, see CHANGELOG.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 
32 /* file class_marker_base.cpp
33  */
34 
35 #include "fctsys.h"
36 #include "gr_basic.h"
37 #include "class_base_screen.h"
38 #include "common.h"
39 #include "macros.h"
40 #include "class_drawpanel.h"
41 #include "class_marker_base.h"
43 
44 
45 // Default marquer shape:
46 const int M_SHAPE_SCALE = 6; // default scaling factor for MarkerShapeCorners coordinates
47 /* The graphic shape of markers is a polygon.
48  * MarkerShapeCorners contains the coordinates of corners of the polygonal default shape
49  * actual coordinates are these values * .m_ScalingFactor
50 */
51 static const wxPoint MarkerShapeCorners[] =
52 {
53  wxPoint( 0, 0 ),
54  wxPoint( 8, 1 ),
55  wxPoint( 4, 3 ),
56  wxPoint( 13, 8 ),
57  wxPoint( 9, 9 ),
58  wxPoint( 8, 13 ),
59  wxPoint( 3, 4 ),
60  wxPoint( 1, 8 )
61 };
62 const unsigned CORNERS_COUNT = DIM( MarkerShapeCorners );
63 
64 /*******************/
65 /* Classe MARKER_BASE */
66 /*******************/
67 
69 {
72  m_Color = RED;
73  wxPoint start = MarkerShapeCorners[0];
74  wxPoint end = MarkerShapeCorners[0];
75 
76  for( unsigned ii = 0; ii < CORNERS_COUNT; ii++ )
77  {
78  wxPoint corner = MarkerShapeCorners[ii];
79  start.x = std::min( start.x, corner.x);
80  start.y = std::min( start.y, corner.y);
81  end.x = std::max( end.x, corner.x);
82  end.y = std::max( end.y, corner.y);
83  }
84 
87 }
88 
89 
91 {
92  m_Pos = aMarker.m_Pos;
93  m_ErrorLevel = aMarker.m_ErrorLevel;
94  m_MarkerType = aMarker.m_MarkerType;
95  m_Color = aMarker.m_Color;
98 }
99 
100 
102 {
104  init();
105 }
106 
107 
108 MARKER_BASE::MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos,
109  const wxString& aText, const wxPoint& aPos,
110  const wxString& bText, const wxPoint& bPos )
111 {
113  init();
114 
115  SetData( aErrorCode, aMarkerPos,
116  aText, aPos,
117  bText, bPos );
118 }
119 
120 
121 MARKER_BASE::MARKER_BASE( int aErrorCode, const wxPoint& aMarkerPos,
122  const wxString& aText, const wxPoint& aPos )
123 {
125  init();
126  SetData( aErrorCode, aMarkerPos, aText, aPos );
127 }
128 
129 
131 {
132 }
133 
134 
135 void MARKER_BASE::SetData( int aErrorCode, const wxPoint& aMarkerPos,
136  const wxString& aText, const wxPoint& aPos,
137  const wxString& bText, const wxPoint& bPos )
138 {
139  m_Pos = aMarkerPos;
140  m_drc.SetData( aErrorCode,
141  aText, bText, aPos, bPos );
142 }
143 
144 
145 void MARKER_BASE::SetData( int aErrorCode, const wxPoint& aMarkerPos,
146  const wxString& aText, const wxPoint& aPos )
147 {
148  m_Pos = aMarkerPos;
149  m_drc.SetData( aErrorCode,
150  aText, aPos );
151 }
152 
153 
154 bool MARKER_BASE::HitTestMarker( const wxPoint& refPos ) const
155 {
156  wxPoint rel_pos = refPos - m_Pos;
157  rel_pos.x /= m_ScalingFactor;
158  rel_pos.y /= m_ScalingFactor;
159 
160  return m_ShapeBoundingBox.Contains( rel_pos );
161 }
162 
163 
165 {
166  wxSize realsize = m_ShapeBoundingBox.GetSize();
167  wxPoint realposition = m_ShapeBoundingBox.GetPosition();
168  realsize.x *= m_ScalingFactor;
169  realsize.y *= m_ScalingFactor;
170  realposition.x *= m_ScalingFactor;
171  realposition.y *= m_ScalingFactor;
172  realposition += m_Pos;
173  return EDA_RECT( m_Pos, realsize );
174 }
175 
176 void MARKER_BASE::DrawMarker( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDrawMode,
177  const wxPoint& aOffset )
178 {
179  wxPoint corners[CORNERS_COUNT];
180 
181  GRSetDrawMode( aDC, aDrawMode );
182 
183  for( unsigned ii = 0; ii < CORNERS_COUNT; ii++ )
184  {
185  corners[ii] = MarkerShapeCorners[ii];
186  corners[ii].x *= m_ScalingFactor;
187  corners[ii].y *= m_ScalingFactor;
188  corners[ii] += m_Pos + aOffset;
189  }
190 
191  GRClosedPoly( aPanel->GetClipBox(), aDC, CORNERS_COUNT, corners,
192  true, // = Filled
193  0, // outline width
194  m_Color, // outline color
195  m_Color // fill collor
196  );
197 }
198 
199 
201 {
202  wxString msg = m_drc.ShowHtml();
203  DIALOG_DISPLAY_HTML_TEXT_BASE infodisplay( (wxWindow*)aFrame, wxID_ANY, _( "Marker Info" ),
204  wxGetMousePosition(), wxSize( 550, 140 ) );
205 
206  infodisplay.m_htmlWindow->SetPage( msg );
207  infodisplay.ShowModal();
208 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
MARKER_SEVERITY m_ErrorLevel
Specify the severity of the error.
const unsigned CORNERS_COUNT
bool HitTestMarker(const wxPoint &ref_pos) const
Function HitTestMarker tests if the given wxPoint is within the bounds of this object.
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:290
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...
const int M_SHAPE_SCALE
wxPoint m_Pos
position of the marker
void SetOrigin(const wxPoint &pos)
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:53
void DrawMarker(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset)
Function DrawMarker draws the shape is the polygon defined in m_Corners (array of wxPoints)...
TYPEMARKER m_MarkerType
The type of marker (useful to filter markers)
void GRClosedPoly(EDA_RECT *ClipBox, wxDC *DC, int n, wxPoint Points[], bool Fill, COLOR4D Color, COLOR4D BgColor)
Function GRClosedPoly draws a closed polygon onto the drawing context aDC and optionally fills and/or...
Definition: gr_basic.cpp:777
void SetData(int aErrorCode, const wxPoint &aMarkerPos, const wxString &aText, const wxPoint &aPos, const wxString &bText, const wxPoint &bPos)
Function SetData fills in all the reportable data associated with a MARKER.
This file contains miscellaneous commonly used macros and functions.
void SetData(int aErrorCode, const wxString &aMainText, const wxPoint &aMainPos)
Function SetData initialize all data in item.
void DisplayMarkerInfo(EDA_DRAW_FRAME *aFrame)
Function DisplayMarkerInfo displays the full info of this marker, in a HTML window.
Class DIALOG_DISPLAY_HTML_TEXT_BASE.
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
void SetEnd(int x, int y)
COLOR4D m_Color
color
int m_ScalingFactor
Scaling factor for m_Size and m_Corners (can set the physical size.
EDA_RECT * GetClipBox()
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...
const wxPoint & GetPosition() const
BASE_SCREEN class implementation.
#define max(a, b)
Definition: auxiliary.h:86
Class EDA_RECT handles the component boundary box.
The common library.
wxString ShowHtml() const
Function ShowHtml translates this object into a fragment of HTML suitable for the wxWidget's wxHtmlLi...
static const wxPoint MarkerShapeCorners[]
const wxSize & GetSize() const
#define min(a, b)
Definition: auxiliary.h:85