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.

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