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-2015 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 <sch_item_struct.h>
34 #include <class_sch_screen.h>
35 #include <class_drawpanel.h>
36 #include <schframe.h>
37 
38 #include <general.h>
39 
40 
41 const wxString traceFindItem( wxT( "KicadFindItem" ) );
42 
43 
44 bool sort_schematic_items( const SCH_ITEM* aItem1, const SCH_ITEM* aItem2 )
45 {
46  return *aItem1 < *aItem2;
47 }
48 
49 
50 /* Constructor and destructor for SCH_ITEM */
51 /* They are not inline because this creates problems with gcc at linking time
52  * in debug mode
53  */
54 
55 SCH_ITEM::SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType ) :
56  EDA_ITEM( aParent, aType )
57 {
58  m_Layer = LAYER_WIRE; // It's only a default, in fact
59 }
60 
61 
62 SCH_ITEM::SCH_ITEM( const SCH_ITEM& aItem ) :
63  EDA_ITEM( aItem )
64 {
65  m_Layer = aItem.m_Layer;
66 }
67 
68 
70 {
71  // Do not let the connections container go out of scope with any objects or they
72  // will be deleted by the container will cause the Eeschema to crash. These objects
73  // are owned by the sheet object container.
74  if( !m_connections.empty() )
75  m_connections.clear();
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:198
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:124
EDA_ITEMS m_connections
List of items connected to this item.
const wxString traceFindItem(wxT("KicadFindItem"))
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:90
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.
Definitions for the Eeschema program SCH_SCREEN class.
bool sort_schematic_items(const SCH_ITEM *aItem1, const SCH_ITEM *aItem2)
#define STRUCT_DELETED
flag indication structures to be erased
Definition: base_struct.h:122
static std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file...
virtual void Plot(PLOTTER *aPlotter)
Function Plot plots the schematic item to aPlotter.
LAYERSCH_ID m_Layer
Base plotter engine class.
Definition: plot_common.h:86
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:175
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:151
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)