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.

180 lines
4.7 KiB

7 years ago
  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-2019 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. #include <fctsys.h>
  25. #include <common.h>
  26. #include <gr_basic.h>
  27. #include <base_struct.h>
  28. #include <trace_helpers.h>
  29. #include <sch_item.h>
  30. #include <sch_screen.h>
  31. #include <sch_sheet_path.h>
  32. #include <sch_draw_panel.h>
  33. #include <sch_edit_frame.h>
  34. #include <sch_component.h>
  35. #include <sch_sheet.h>
  36. #include <sch_pin.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. for( const auto& it : m_connection_map )
  62. delete it.second;
  63. }
  64. SCH_ITEM* SCH_ITEM::Duplicate( bool doClone )
  65. {
  66. SCH_ITEM* newItem = (SCH_ITEM*) Clone();
  67. if( doClone )
  68. newItem->SetTimeStamp( GetTimeStamp() );
  69. newItem->ClearFlags( SELECTED | HIGHLIGHTED | BRIGHTENED );
  70. if( newItem->Type() == SCH_COMPONENT_T )
  71. {
  72. SCH_COMPONENT* component = (SCH_COMPONENT*) newItem;
  73. for( SCH_PIN& pin : component->GetPins() )
  74. pin.ClearFlags( SELECTED | HIGHLIGHTED | BRIGHTENED );
  75. std::vector<SCH_FIELD*> fields;
  76. component->GetFields( fields, false );
  77. for( SCH_FIELD* field : fields )
  78. field->ClearFlags( SELECTED | HIGHLIGHTED | BRIGHTENED );
  79. }
  80. if( newItem->Type() == SCH_SHEET_T )
  81. {
  82. SCH_SHEET* sheet = (SCH_SHEET*) newItem;
  83. for( SCH_SHEET_PIN& pin : sheet->GetPins() )
  84. pin.ClearFlags( SELECTED | HIGHLIGHTED | BRIGHTENED );
  85. }
  86. return newItem;
  87. }
  88. void SCH_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
  89. {
  90. // Basic fallback
  91. aCount = 1;
  92. aLayers[0] = LAYER_DEVICE;
  93. }
  94. bool SCH_ITEM::IsConnected( const wxPoint& aPosition ) const
  95. {
  96. if( ( m_Flags & STRUCT_DELETED ) || ( m_Flags & SKIP_STRUCT ) )
  97. return false;
  98. return doIsConnected( aPosition );
  99. }
  100. SCH_CONNECTION* SCH_ITEM::Connection( const SCH_SHEET_PATH& aSheet ) const
  101. {
  102. if( m_connection_map.count( aSheet ) )
  103. return m_connection_map.at( aSheet );
  104. return nullptr;
  105. }
  106. std::unordered_set<SCH_ITEM*>& SCH_ITEM::ConnectedItems()
  107. {
  108. return m_connected_items;
  109. }
  110. void SCH_ITEM::AddConnectionTo( SCH_ITEM* aItem )
  111. {
  112. m_connected_items.insert( aItem );
  113. }
  114. SCH_CONNECTION* SCH_ITEM::InitializeConnection( const SCH_SHEET_PATH& aSheet )
  115. {
  116. if( Connection( aSheet ) )
  117. {
  118. Connection( aSheet )->Reset();
  119. Connection( aSheet )->SetSheet( aSheet );
  120. return Connection( aSheet );
  121. }
  122. auto connection = new SCH_CONNECTION( this );
  123. connection->SetSheet( aSheet );
  124. m_connection_map.insert( std::make_pair( aSheet, connection ) );
  125. return connection;
  126. }
  127. void SCH_ITEM::SwapData( SCH_ITEM* aItem )
  128. {
  129. wxFAIL_MSG( wxT( "SwapData() method not implemented for class " ) + GetClass() );
  130. }
  131. bool SCH_ITEM::operator < ( const SCH_ITEM& aItem ) const
  132. {
  133. wxCHECK_MSG( false, this->Type() < aItem.Type(),
  134. wxT( "Less than operator not defined for " ) + GetClass() );
  135. }
  136. void SCH_ITEM::Plot( PLOTTER* aPlotter )
  137. {
  138. wxFAIL_MSG( wxT( "Plot() method not implemented for class " ) + GetClass() );
  139. }