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.

147 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_sheet_path.h>
  35. #include <sch_draw_panel.h>
  36. #include <sch_edit_frame.h>
  37. #include <general.h>
  38. /* Constructor and destructor for SCH_ITEM */
  39. /* They are not inline because this creates problems with gcc at linking time
  40. * in debug mode
  41. */
  42. SCH_ITEM::SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType ) :
  43. EDA_ITEM( aParent, aType )
  44. {
  45. m_Layer = LAYER_WIRE; // It's only a default, in fact
  46. m_connectivity_dirty = true;
  47. }
  48. SCH_ITEM::SCH_ITEM( const SCH_ITEM& aItem ) :
  49. EDA_ITEM( aItem )
  50. {
  51. m_Layer = aItem.m_Layer;
  52. m_connectivity_dirty = true;
  53. }
  54. SCH_ITEM::~SCH_ITEM()
  55. {
  56. // Do not let the connections container go out of scope with any objects or they
  57. // will be deleted by the container will cause the Eeschema to crash. These objects
  58. // are owned by the sheet object container.
  59. if( !m_connections.empty() )
  60. m_connections.clear();
  61. }
  62. void SCH_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
  63. {
  64. // Basic fallback
  65. aCount = 1;
  66. aLayers[0] = LAYER_DEVICE;
  67. }
  68. bool SCH_ITEM::IsConnected( const wxPoint& aPosition ) const
  69. {
  70. if( ( m_Flags & STRUCT_DELETED ) || ( m_Flags & SKIP_STRUCT ) )
  71. return false;
  72. return doIsConnected( aPosition );
  73. }
  74. SCH_CONNECTION* SCH_ITEM::Connection( const SCH_SHEET_PATH& aSheet ) const
  75. {
  76. try
  77. {
  78. return m_connection_map.at( aSheet );
  79. }
  80. catch( ... )
  81. {
  82. return nullptr;
  83. }
  84. }
  85. std::unordered_set<SCH_ITEM*>& SCH_ITEM::ConnectedItems()
  86. {
  87. return m_connected_items;
  88. }
  89. void SCH_ITEM::AddConnectionTo( SCH_ITEM* aItem )
  90. {
  91. m_connected_items.insert( aItem );
  92. }
  93. SCH_CONNECTION* SCH_ITEM::InitializeConnection( const SCH_SHEET_PATH& aSheet )
  94. {
  95. if( Connection( aSheet ) )
  96. {
  97. Connection( aSheet )->Reset();
  98. return Connection( aSheet );
  99. }
  100. auto connection = new SCH_CONNECTION( this );
  101. connection->SetSheet( aSheet );
  102. m_connection_map.insert( std::make_pair( aSheet, connection ) );
  103. return connection;
  104. }
  105. void SCH_ITEM::SwapData( SCH_ITEM* aItem )
  106. {
  107. wxFAIL_MSG( wxT( "SwapData() method not implemented for class " ) + GetClass() );
  108. }
  109. bool SCH_ITEM::operator < ( const SCH_ITEM& aItem ) const
  110. {
  111. wxCHECK_MSG( false, this->Type() < aItem.Type(),
  112. wxT( "Less than operator not defined for " ) + GetClass() );
  113. }
  114. void SCH_ITEM::Plot( PLOTTER* aPlotter )
  115. {
  116. wxFAIL_MSG( wxT( "Plot() method not implemented for class " ) + GetClass() );
  117. }