KiCad PCB EDA Suite
sch_marker.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) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 1992-2017 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 
30 #include <fctsys.h>
31 #include <sch_draw_panel.h>
32 #include <trigo.h>
33 #include <msgpanel.h>
34 #include <bitmaps.h>
35 
36 #include <sch_marker.h>
37 #include <erc.h>
38 
39 
41 {
42  m_ScalingFactor = 8;
43 }
44 
45 
46 SCH_MARKER::SCH_MARKER( const wxPoint& pos, const wxString& text ) :
47  SCH_ITEM( NULL, SCH_MARKER_T ),
48  MARKER_BASE( 0, pos, text, pos )
49 {
50  m_ScalingFactor = 8;
51 }
52 
53 
55 {
56  return new SCH_MARKER( *this );
57 }
58 
59 
60 #if defined(DEBUG)
61 
62 void SCH_MARKER::Show( int nestLevel, std::ostream& os ) const
63 {
64  // for now, make it look like XML:
65  NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
66  << GetPos() << "/>\n";
67 }
68 
69 #endif
70 
71 
72 void SCH_MARKER::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
73  const wxPoint& aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor )
74 {
76  COLOR4D tmp = color;
77 
79  {
82  }
83 
84  if( aColor == COLOR4D::UNSPECIFIED )
85  m_Color = color;
86  else
87  m_Color = aColor;
88 
89  DrawMarker( aPanel, aDC, aDrawMode, aOffset );
90  m_Color = tmp;
91 }
92 
93 
94 bool SCH_MARKER::Matches( wxFindReplaceData& aSearchData, void* aAuxData,
95  wxPoint * aFindLocation )
96 {
97  if( SCH_ITEM::Matches( m_drc.GetErrorText(), aSearchData ) ||
98  SCH_ITEM::Matches( m_drc.GetMainText(), aSearchData ) ||
99  SCH_ITEM::Matches( m_drc.GetAuxiliaryText(), aSearchData ) )
100  {
101  if( aFindLocation )
102  *aFindLocation = m_Pos;
103 
104  return true;
105  }
106 
107  return false;
108 }
109 
110 
111 void SCH_MARKER::ViewGetLayers( int aLayers[], int& aCount ) const
112 {
113  aCount = 1;
115 }
116 
117 
119 {
120  return GetBoundingBoxMarker();
121 }
122 
123 
125 {
126  aList.push_back( MSG_PANEL_ITEM( _( "Electronics Rule Check Error" ),
127  GetReporter().GetErrorText(), DARKRED ) );
128 }
129 
130 
132 {
133  return erc_xpm;
134 }
135 
136 
137 void SCH_MARKER::Rotate( wxPoint aPosition )
138 {
139  RotatePoint( &m_Pos, aPosition, 900 );
140 }
141 
142 
143 void SCH_MARKER::MirrorX( int aXaxis_position )
144 {
145  m_Pos.y -= aXaxis_position;
146  m_Pos.y = -m_Pos.y;
147  m_Pos.y += aXaxis_position;
148 }
149 
150 
151 void SCH_MARKER::MirrorY( int aYaxis_position )
152 {
153  m_Pos.x -= aYaxis_position;
154  m_Pos.x = -m_Pos.x;
155  m_Pos.x += aYaxis_position;
156 }
157 
158 
159 bool SCH_MARKER::IsSelectStateChanged( const wxRect& aRect )
160 {
161  bool previousState = IsSelected();
162 
163  if( aRect.Contains( m_Pos ) )
164  SetFlags( SELECTED );
165  else
166  ClearFlags( SELECTED );
167 
168  return previousState != IsSelected();
169 }
170 
171 
172 bool SCH_MARKER::HitTest( const wxPoint& aPosition, int aAccuracy ) const
173 {
174  return HitTestMarker( aPosition );
175 }
void MirrorX(int aXaxis_position) override
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
Definition: sch_marker.cpp:143
EDA_RECT const GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Definition: sch_marker.cpp:118
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.
PNG memory record (file in memory).
Definition: bitmap_types.h:43
const wxPoint & GetPos() const
Function GetPos returns the position of this MARKER, const.
Definition: marker_base.h:130
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDraw_mode, COLOR4D aColor=COLOR4D::UNSPECIFIED) override
Function Draw Draw a schematic item.
Definition: sch_marker.cpp:72
bool HitTest(const wxPoint &aPosition, int aAccuracy) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item...
Definition: sch_marker.cpp:172
wxString GetErrorText() const
Function GetErrorText returns the string form of a drc error code.
Definition: drc_item.cpp:36
EDA_RECT GetBoundingBoxMarker() const
Function GetBoundingBoxMarker returns the orthogonal, bounding box of this object for display purpose...
void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it&#39;s internal state for displ...
Definition: sch_marker.cpp:124
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation)
Function Matches compares the item against the search criteria in aSearchData.
Definition: base_struct.h:420
int color
Definition: DXF_plotter.cpp:62
wxPoint m_Pos
position of the marker
Definition: marker_base.h:54
wxString GetMainText() const
Access to A and B texts.
Definition: drc_item.h:162
bool IsSelected() const
Definition: base_struct.h:224
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:174
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)...
Definition: colors.h:54
enum TYPEMARKER GetMarkerType() const
Definition: marker_base.h:164
void MirrorY(int aYaxis_position) override
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
Definition: sch_marker.cpp:151
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_marker.cpp:131
#define SELECTED
Definition: base_struct.h:121
MARKER_SEVERITY GetErrorLevel() const
Definition: marker_base.h:152
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:256
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
const DRC_ITEM & GetReporter() const
Function GetReporter returns the DRC_ITEM held within this MARKER so that its interface may be used...
Definition: marker_base.h:220
void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers returns the layers the item is drawn on (which may be more than its "home" lay...
Definition: sch_marker.cpp:111
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
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation) override
Compare DRC marker main and auxiliary text against search string.
Definition: sch_marker.cpp:94
wxString GetAuxiliaryText() const
Definition: drc_item.h:163
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_marker.cpp:137
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_marker.cpp:54
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
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:257
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_marker.h:50
bool IsSelectStateChanged(const wxRect &aRect) override
Function IsSelectStateChanged checks if the selection state of an item inside aRect has changed...
Definition: sch_marker.cpp:159
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
Message panel definition file.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
DRC_ITEM m_drc
Definition: marker_base.h:65
EDA_UNITS_T
Definition: common.h:159
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39