KiCad PCB EDA Suite
sch_item_struct.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) 2006 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 1992-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 
29 #include <fctsys.h>
30 #include <common.h>
31 #include <gr_basic.h>
32 #include <base_struct.h>
33 #include <trace_helpers.h>
34 #include <sch_item_struct.h>
35 #include <sch_screen.h>
36 #include <sch_draw_panel.h>
37 #include <sch_edit_frame.h>
38 
39 #include <general.h>
40 
41 
42 /* Constructor and destructor for SCH_ITEM */
43 /* They are not inline because this creates problems with gcc at linking time
44  * in debug mode
45  */
46 
47 SCH_ITEM::SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType ) :
48  EDA_ITEM( aParent, aType )
49 {
50  m_Layer = LAYER_WIRE; // It's only a default, in fact
51 }
52 
53 
54 SCH_ITEM::SCH_ITEM( const SCH_ITEM& aItem ) :
55  EDA_ITEM( aItem )
56 {
57  m_Layer = aItem.m_Layer;
58 }
59 
60 
62 {
63  // Do not let the connections container go out of scope with any objects or they
64  // will be deleted by the container will cause the Eeschema to crash. These objects
65  // are owned by the sheet object container.
66  if( !m_connections.empty() )
67  m_connections.clear();
68 }
69 
70 
71 void SCH_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
72 {
73  // Basic fallback
74  aCount = 1;
75  aLayers[0] = LAYER_DEVICE;
76 }
77 
78 
79 bool SCH_ITEM::IsConnected( const wxPoint& aPosition ) const
80 {
82  return false;
83 
84  return doIsConnected( aPosition );
85 }
86 
87 
89 {
90  wxFAIL_MSG( wxT( "SwapData() method not implemented for class " ) + GetClass() );
91 }
92 
93 
94 bool SCH_ITEM::operator < ( const SCH_ITEM& aItem ) const
95 {
96  wxCHECK_MSG( false, this->Type() < aItem.Type(),
97  wxT( "Less than operator not defined for " ) + GetClass() );
98 }
99 
100 
101 void SCH_ITEM::Plot( PLOTTER* aPlotter )
102 {
103  wxFAIL_MSG( wxT( "Plot() method not implemented for class " ) + GetClass() );
104 }
105 
106 
107 std::string SCH_ITEM::FormatInternalUnits( int aValue )
108 {
109  char buf[50];
110  double engUnits = aValue;
111  int len;
112 
113  if( engUnits != 0.0 && fabs( engUnits ) <= 0.0001 )
114  {
115  len = snprintf( buf, sizeof(buf), "%.10f", engUnits );
116 
117  while( --len > 0 && buf[len] == '0' )
118  buf[len] = '\0';
119 
120  ++len;
121  }
122  else
123  {
124  len = snprintf( buf, sizeof(buf), "%.10g", engUnits );
125  }
126 
127  return std::string( buf, len );
128 }
129 
130 
131 std::string SCH_ITEM::FormatAngle( double aAngle )
132 {
133  char temp[50];
134  int len;
135 
136  len = snprintf( temp, sizeof(temp), "%.10g", aAngle / 10.0 );
137 
138  return std::string( temp, len );
139 }
140 
141 
142 std::string SCH_ITEM::FormatInternalUnits( const wxPoint& aPoint )
143 {
144  return FormatInternalUnits( aPoint.x ) + " " + FormatInternalUnits( aPoint.y );
145 }
146 
147 
148 std::string SCH_ITEM::FormatInternalUnits( const wxSize& aSize )
149 {
150  return FormatInternalUnits( aSize.GetWidth() ) + " " + FormatInternalUnits( aSize.GetHeight() );
151 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
SCH_LAYER_ID m_Layer
Base schematic object class definition.
virtual bool operator<(const SCH_ITEM &aItem) const
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: base_struct.h:125
EDA_ITEMS m_connections
List of items connected to this item.
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
virtual bool doIsConnected(const wxPoint &aPosition) const
Function doIsConnected provides the object specific test to see if it is connected to aPosition...
virtual void SwapData(SCH_ITEM *aItem)
Function SwapData swap the internal data structures aItem with the schematic item.
#define STRUCT_DELETED
flag indication structures to be erased
Definition: base_struct.h:123
static std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file...
wxLogTrace helper definitions.
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...
Definitions for the Eeschema program SCH_SCREEN class.
virtual void Plot(PLOTTER *aPlotter)
Function Plot plots the schematic item to aPlotter.
Base plotter engine class.
Definition: plotter.h:97
bool IsConnected(const wxPoint &aPoint) const
Function IsConnected tests the item to see if it is connected to aPoint.
STATUS_FLAGS m_Flags
Flag bits for editing and other uses.
Definition: base_struct.h:178
static std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from schematic internal units to a string appropriate fo...
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.
virtual wxString GetClass() const override
Function GetClass returns the class name.
Basic classes for most KiCad items.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType)