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.

261 lines
7.1 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013-2018 CERN
  5. * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  8. * @author Maciej Suminski <maciej.suminski@cern.ch>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, you may find one here:
  22. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  23. * or you may search the http://www.gnu.org website for the version 2 license,
  24. * or you may write to the Free Software Foundation, Inc.,
  25. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  26. */
  27. #include <memory>
  28. #include <view/view.h>
  29. #include <view/view_group.h>
  30. #include <view/view_rtree.h>
  31. #include <view/wx_view_controls.h>
  32. #include <ws_proxy_view_item.h>
  33. #include <layers_id_colors_and_visibility.h>
  34. #include <class_libentry.h>
  35. #include <sch_sheet.h>
  36. #include <sch_screen.h>
  37. #include <sch_component.h>
  38. #include <lib_pin.h>
  39. #include <preview_items/selection_area.h>
  40. #include <sch_edit_frame.h>
  41. #include "sch_view.h"
  42. namespace KIGFX {
  43. SCH_VIEW::SCH_VIEW( bool aIsDynamic, SCH_BASE_FRAME* aFrame ) :
  44. VIEW( aIsDynamic )
  45. {
  46. m_frame = aFrame;
  47. // Set m_boundary to define the max working area size. The default value
  48. // is acceptable for Pcbnew and Gerbview, but too large for Eeschema due to
  49. // very different internal units.
  50. // So we have to use a smaller value.
  51. // A full size = 3 * MAX_PAGE_SIZE_MILS size allows a wide margin
  52. // around the worksheet.
  53. double max_size = Mils2iu( MAX_PAGE_SIZE_MILS ) * 3.0;
  54. m_boundary.SetOrigin( -max_size/4, -max_size/4 );
  55. m_boundary.SetSize( max_size, max_size );
  56. m_selectionArea.reset( new KIGFX::PREVIEW::SELECTION_AREA() );
  57. m_preview.reset( new KIGFX::VIEW_GROUP() );
  58. }
  59. SCH_VIEW::~SCH_VIEW()
  60. {
  61. }
  62. void SCH_VIEW::SetScale( double aScale, VECTOR2D aAnchor )
  63. {
  64. VIEW::SetScale( aScale, aAnchor );
  65. //Redraw selection halos since their width is dependent on zoom
  66. if( m_frame )
  67. m_frame->RefreshSelection();
  68. }
  69. void SCH_VIEW::ResizeSheetWorkingArea( SCH_SCREEN* aScreen )
  70. {
  71. const PAGE_INFO& page_info = aScreen->GetPageSettings();
  72. double max_size_x = page_info.GetWidthIU() * 3.0;
  73. double max_size_y = page_info.GetHeightIU() * 3.0;
  74. m_boundary.SetOrigin( -max_size_x/4, -max_size_y/4 );
  75. m_boundary.SetSize( max_size_x, max_size_y );
  76. }
  77. void SCH_VIEW::DisplaySheet( SCH_SCREEN *aScreen )
  78. {
  79. for( auto item : aScreen->Items() )
  80. Add( item );
  81. m_worksheet.reset( new KIGFX::WS_PROXY_VIEW_ITEM( static_cast< int >( IU_PER_MILS ),
  82. &aScreen->GetPageSettings(),
  83. &aScreen->Prj(),
  84. &aScreen->GetTitleBlock() ) );
  85. m_worksheet->SetSheetNumber( aScreen->m_ScreenNumber );
  86. m_worksheet->SetSheetCount( aScreen->m_NumberOfScreens );
  87. m_worksheet->SetFileName( TO_UTF8( aScreen->GetFileName() ) );
  88. m_worksheet->SetColorLayer( LAYER_SCHEMATIC_WORKSHEET );
  89. if( m_frame && m_frame->IsType( FRAME_SCH ) )
  90. m_worksheet->SetSheetName( TO_UTF8( m_frame->GetScreenDesc() ) );
  91. else
  92. m_worksheet->SetSheetName( "" );
  93. ResizeSheetWorkingArea( aScreen );
  94. m_selectionArea.reset( new KIGFX::PREVIEW::SELECTION_AREA() );
  95. m_preview.reset( new KIGFX::VIEW_GROUP() );
  96. Add( m_worksheet.get() );
  97. Add( m_selectionArea.get() );
  98. Add( m_preview.get() );
  99. }
  100. void SCH_VIEW::DisplaySheet( SCH_SHEET* aSheet )
  101. {
  102. DisplaySheet( aSheet->GetScreen() );
  103. }
  104. void SCH_VIEW::DisplayComponent( LIB_PART* aPart )
  105. {
  106. Clear();
  107. if( !aPart )
  108. return;
  109. std::shared_ptr< LIB_PART > parent;
  110. LIB_PART* drawnPart = aPart;
  111. // Draw the mandatory fields for aliases and parent symbols.
  112. for( auto& item : aPart->GetDrawItems() )
  113. {
  114. if( item.Type() != LIB_FIELD_T )
  115. continue;
  116. if( static_cast< LIB_FIELD* >( &item )->IsMandatory() )
  117. Add( &item );
  118. }
  119. // Draw the parent items if the symbol is inherited from another symbol.
  120. if( aPart->IsAlias() )
  121. {
  122. parent = aPart->GetParent().lock();
  123. wxCHECK( parent, /* void */ );
  124. drawnPart = parent.get();
  125. }
  126. for( auto& item : drawnPart->GetDrawItems() )
  127. {
  128. // The mandatory fields are already in place so we only add user defined fields.
  129. if( item.Type() == LIB_FIELD_T )
  130. {
  131. if( static_cast< LIB_FIELD* >( &item )->IsMandatory() )
  132. continue;
  133. }
  134. Add( &item );
  135. }
  136. m_selectionArea.reset( new KIGFX::PREVIEW::SELECTION_AREA() );
  137. m_preview.reset( new KIGFX::VIEW_GROUP() );
  138. Add( m_selectionArea.get() );
  139. Add( m_preview.get() );
  140. }
  141. void SCH_VIEW::ClearPreview()
  142. {
  143. m_preview->Clear();
  144. for( auto item : m_ownedItems )
  145. delete item;
  146. m_ownedItems.clear();
  147. Update( m_preview.get() );
  148. }
  149. void SCH_VIEW::AddToPreview( EDA_ITEM* aItem, bool aTakeOwnership )
  150. {
  151. Hide( aItem, false );
  152. m_preview->Add( aItem );
  153. if( aTakeOwnership )
  154. m_ownedItems.push_back( aItem );
  155. SetVisible( m_preview.get(), true );
  156. Hide( m_preview.get(), false );
  157. Update( m_preview.get() );
  158. }
  159. void SCH_VIEW::ShowPreview( bool aShow )
  160. {
  161. SetVisible( m_preview.get(), aShow );
  162. }
  163. void SCH_VIEW::ClearHiddenFlags()
  164. {
  165. for( auto item : *m_allItems )
  166. Hide( item, false );
  167. }
  168. void SCH_VIEW::HideWorksheet()
  169. {
  170. // SetVisible( m_worksheet.get(), false );
  171. }
  172. void SCH_VIEW::HighlightItem( EDA_ITEM *aItem, LIB_PIN* aPin )
  173. {
  174. if( aItem && aItem->Type() == SCH_COMPONENT_T && aPin )
  175. {
  176. static_cast<SCH_COMPONENT*>( aItem )->HighlightPin( aPin );
  177. Update( aItem, REPAINT );
  178. }
  179. else if( aItem )
  180. {
  181. aItem->SetFlags( HIGHLIGHTED );
  182. Update( aItem, REPAINT );
  183. }
  184. else
  185. {
  186. for( auto item : *m_allItems )
  187. {
  188. // Not all view items can be highlighted, only EDA_ITEMs
  189. // So clear flag of only EDA_ITEMs.
  190. EDA_ITEM* eitem = dynamic_cast<EDA_ITEM*>( item );
  191. if( eitem )
  192. {
  193. if( eitem->IsHighlighted() )
  194. {
  195. eitem->ClearFlags( HIGHLIGHTED );
  196. Update( eitem, REPAINT );
  197. }
  198. if( eitem->Type() == SCH_COMPONENT_T )
  199. {
  200. // Items inside a component (pins, fields can be highlighted.
  201. static_cast<SCH_COMPONENT*>( eitem )->ClearAllHighlightFlags();
  202. }
  203. }
  204. }
  205. }
  206. }
  207. }; // namespace KIGFX