You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
3.9 KiB

  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-2011 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. /**
  25. * @file sch_item_struct.cpp
  26. */
  27. #include <fctsys.h>
  28. #include <common.h>
  29. #include <gr_basic.h>
  30. #include <base_struct.h>
  31. #include <sch_item_struct.h>
  32. #include <class_sch_screen.h>
  33. #include <class_drawpanel.h>
  34. #include <wxEeschemaStruct.h>
  35. #include <general.h>
  36. #include <protos.h>
  37. const wxString traceFindReplace( wxT( "KicadFindReplace" ) );
  38. const wxString traceFindItem( wxT( "KicadFindItem" ) );
  39. bool sort_schematic_items( const SCH_ITEM* aItem1, const SCH_ITEM* aItem2 )
  40. {
  41. return *aItem1 < *aItem2;
  42. }
  43. /* Constructor and destructor for SCH_ITEM */
  44. /* They are not inline because this creates problems with gcc at linking time
  45. * in debug mode
  46. */
  47. SCH_ITEM::SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType ) :
  48. EDA_ITEM( aParent, aType )
  49. {
  50. m_Layer = 0;
  51. }
  52. SCH_ITEM::SCH_ITEM( const SCH_ITEM& aItem ) :
  53. EDA_ITEM( aItem )
  54. {
  55. m_Layer = aItem.m_Layer;
  56. }
  57. SCH_ITEM::~SCH_ITEM()
  58. {
  59. // Do not let the connections container go out of scope with any objects or they
  60. // will be deleted by the container will cause the Eeschema to crash. These objects
  61. // are owned by the sheet object container.
  62. if( !m_connections.empty() )
  63. m_connections.clear();
  64. }
  65. bool SCH_ITEM::IsConnected( const wxPoint& aPosition ) const
  66. {
  67. if( m_Flags & STRUCT_DELETED || m_Flags & SKIP_STRUCT )
  68. return false;
  69. return doIsConnected( aPosition );
  70. }
  71. void SCH_ITEM::SwapData( SCH_ITEM* aItem )
  72. {
  73. wxFAIL_MSG( wxT( "SwapData() method not implemented for class " ) + GetClass() );
  74. }
  75. bool SCH_ITEM::operator < ( const SCH_ITEM& aItem ) const
  76. {
  77. wxCHECK_MSG( false, this->Type() < aItem.Type(),
  78. wxT( "Less than operator not defined for " ) + GetClass() );
  79. }
  80. void SCH_ITEM::Plot( PLOTTER* aPlotter )
  81. {
  82. wxFAIL_MSG( wxT( "Plot() method not implemented for class " ) + GetClass() );
  83. }
  84. std::string SCH_ITEM::FormatInternalUnits( int aValue )
  85. {
  86. char buf[50];
  87. double engUnits = aValue;
  88. int len;
  89. if( engUnits != 0.0 && fabs( engUnits ) <= 0.0001 )
  90. {
  91. // printf( "f: " );
  92. len = snprintf( buf, 49, "%.10f", engUnits );
  93. while( --len > 0 && buf[len] == '0' )
  94. buf[len] = '\0';
  95. ++len;
  96. }
  97. else
  98. {
  99. // printf( "g: " );
  100. len = snprintf( buf, 49, "%.10g", engUnits );
  101. }
  102. return std::string( buf, len );
  103. }
  104. std::string SCH_ITEM::FormatAngle( double aAngle )
  105. {
  106. char temp[50];
  107. int len;
  108. len = snprintf( temp, 49, "%.10g", aAngle / 10.0 );
  109. return std::string( temp, len );
  110. }
  111. std::string SCH_ITEM::FormatInternalUnits( const wxPoint& aPoint )
  112. {
  113. return FormatInternalUnits( aPoint.x ) + " " + FormatInternalUnits( aPoint.y );
  114. }
  115. std::string SCH_ITEM::FormatInternalUnits( const wxSize& aSize )
  116. {
  117. return FormatInternalUnits( aSize.GetWidth() ) + " " + FormatInternalUnits( aSize.GetHeight() );
  118. }