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 <class_drawpanel.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 bool SCH_ITEM::IsConnected( const wxPoint& aPosition ) const
72 {
74  return false;
75 
76  return doIsConnected( aPosition );
77 }
78 
79 
81 {
82  wxFAIL_MSG( wxT( "SwapData() method not implemented for class " ) + GetClass() );
83 }
84 
85 
86 bool SCH_ITEM::operator < ( const SCH_ITEM& aItem ) const
87 {
88  wxCHECK_MSG( false, this->Type() < aItem.Type(),
89  wxT( "Less than operator not defined for " ) + GetClass() );
90 }
91 
92 
93 void SCH_ITEM::Plot( PLOTTER* aPlotter )
94 {
95  wxFAIL_MSG( wxT( "Plot() method not implemented for class " ) + GetClass() );
96 }
97 
98 
99 std::string SCH_ITEM::FormatInternalUnits( int aValue )
100 {
101  char buf[50];
102  double engUnits = aValue;
103  int len;
104 
105  if( engUnits != 0.0 && fabs( engUnits ) <= 0.0001 )
106  {
107  len = snprintf( buf, sizeof(buf), "%.10f", engUnits );
108 
109  while( --len > 0 && buf[len] == '0' )
110  buf[len] = '\0';
111 
112  ++len;
113  }
114  else
115  {
116  len = snprintf( buf, sizeof(buf), "%.10g", engUnits );
117  }
118 
119  return std::string( buf, len );
120 }
121 
122 
123 std::string SCH_ITEM::FormatAngle( double aAngle )
124 {
125  char temp[50];
126  int len;
127 
128  len = snprintf( temp, sizeof(temp), "%.10g", aAngle / 10.0 );
129 
130  return std::string( temp, len );
131 }
132 
133 
134 std::string SCH_ITEM::FormatInternalUnits( const wxPoint& aPoint )
135 {
136  return FormatInternalUnits( aPoint.x ) + " " + FormatInternalUnits( aPoint.y );
137 }
138 
139 
140 std::string SCH_ITEM::FormatInternalUnits( const wxSize& aSize )
141 {
142  return FormatInternalUnits( aSize.GetWidth() ) + " " + FormatInternalUnits( aSize.GetHeight() );
143 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
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:120
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:118
static std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file...
wxLogTrace helper definitions.
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:96
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:186
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:162
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)