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.

198 lines
5.8 KiB

7 years ago
3 years ago
3 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-2022 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 <core/typeinfo.h>
  28. #include <memory>
  29. #include <view/view.h>
  30. #include <view/view_rtree.h>
  31. #include <view/wx_view_controls.h>
  32. #include <drawing_sheet/ds_proxy_view_item.h>
  33. #include <layer_ids.h>
  34. #include <sch_screen.h>
  35. #include <schematic.h>
  36. #include <sch_base_frame.h>
  37. #include <sch_edit_frame.h>
  38. #include "sch_view.h"
  39. namespace KIGFX {
  40. SCH_VIEW::SCH_VIEW( bool aIsDynamic, SCH_BASE_FRAME* aFrame ) :
  41. VIEW( aIsDynamic )
  42. {
  43. m_frame = aFrame;
  44. // Set m_boundary to define the max working area size. The default value is acceptable for
  45. // Pcbnew and Gerbview, but too large for Eeschema due to very different internal units.
  46. // A full size = 3 * MAX_PAGE_SIZE_MILS size allows a wide margin around the drawing-sheet.
  47. double max_size = schIUScale.MilsToIU( MAX_PAGE_SIZE_EESCHEMA_MILS ) * 3.0;
  48. m_boundary.SetOrigin( -max_size/4, -max_size/4 );
  49. m_boundary.SetSize( max_size, max_size );
  50. }
  51. SCH_VIEW::~SCH_VIEW()
  52. {
  53. }
  54. void SCH_VIEW::Cleanup()
  55. {
  56. Clear();
  57. m_drawingSheet.reset();
  58. m_preview.reset();
  59. }
  60. void SCH_VIEW::SetScale( double aScale, VECTOR2D aAnchor )
  61. {
  62. VIEW::SetScale( aScale, aAnchor );
  63. // Redraw items whose rendering is dependent on zoom
  64. if( m_frame )
  65. m_frame->RefreshZoomDependentItems();
  66. }
  67. void SCH_VIEW::ResizeSheetWorkingArea( const SCH_SCREEN* aScreen )
  68. {
  69. const PAGE_INFO& page_info = aScreen->GetPageSettings();
  70. double max_size_x = page_info.GetWidthIU( schIUScale.IU_PER_MILS ) * 3.0;
  71. double max_size_y = page_info.GetHeightIU( schIUScale.IU_PER_MILS ) * 3.0;
  72. m_boundary.SetOrigin( -max_size_x / 4, -max_size_y / 4 );
  73. m_boundary.SetSize( max_size_x, max_size_y );
  74. }
  75. void SCH_VIEW::DisplaySheet( const SCH_SCREEN *aScreen )
  76. {
  77. for( SCH_ITEM* item : aScreen->Items() )
  78. Add( item );
  79. m_drawingSheet.reset( new DS_PROXY_VIEW_ITEM( static_cast<int>( schIUScale.IU_PER_MILS ),
  80. &aScreen->GetPageSettings(),
  81. &aScreen->Schematic()->Prj(),
  82. &aScreen->GetTitleBlock(),
  83. aScreen->Schematic()->GetProperties() ) );
  84. m_drawingSheet->SetPageNumber( TO_UTF8( aScreen->GetPageNumber() ) );
  85. m_drawingSheet->SetSheetCount( aScreen->GetPageCount() );
  86. m_drawingSheet->SetFileName( TO_UTF8( aScreen->GetFileName() ) );
  87. m_drawingSheet->SetColorLayer( LAYER_SCHEMATIC_DRAWINGSHEET );
  88. m_drawingSheet->SetPageBorderColorLayer( LAYER_SCHEMATIC_PAGE_LIMITS );
  89. m_drawingSheet->SetIsFirstPage( aScreen->GetVirtualPageNumber() == 1 );
  90. if( m_frame && m_frame->IsType( FRAME_SCH ) )
  91. {
  92. SCH_EDIT_FRAME* editFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame );
  93. wxCHECK( editFrame, /* void */ );
  94. wxString sheetName = editFrame->GetCurrentSheet().Last()->GetName();
  95. wxString sheetPath = editFrame->GetCurrentSheet().PathHumanReadable();
  96. m_drawingSheet->SetSheetName( TO_UTF8( sheetName ) );
  97. m_drawingSheet->SetSheetPath( TO_UTF8( sheetPath ) );
  98. }
  99. else
  100. {
  101. m_drawingSheet->SetSheetName( "" );
  102. m_drawingSheet->SetSheetPath( "" );
  103. }
  104. ResizeSheetWorkingArea( aScreen );
  105. Add( m_drawingSheet.get() );
  106. InitPreview();
  107. }
  108. void SCH_VIEW::DisplaySymbol( LIB_SYMBOL* aSymbol )
  109. {
  110. Clear();
  111. if( !aSymbol )
  112. return;
  113. std::shared_ptr< LIB_SYMBOL > parent;
  114. LIB_SYMBOL* drawnSymbol = aSymbol;
  115. // Draw the mandatory fields for aliases and parent symbols.
  116. for( LIB_ITEM& item : aSymbol->GetDrawItems() )
  117. {
  118. if( item.Type() != LIB_FIELD_T )
  119. continue;
  120. LIB_FIELD* field = static_cast< LIB_FIELD* >( &item );
  121. wxCHECK2( field, continue );
  122. if( field->GetText().IsEmpty() )
  123. continue;
  124. Add( &item );
  125. }
  126. // Draw the parent items if the symbol is inherited from another symbol.
  127. if( aSymbol->IsAlias() )
  128. {
  129. parent = aSymbol->GetParent().lock();
  130. wxCHECK( parent, /* void */ );
  131. drawnSymbol = parent.get();
  132. }
  133. for( LIB_ITEM& item : drawnSymbol->GetDrawItems() )
  134. {
  135. // Don't show parent symbol fields. Users may be confused by shown fields that can not
  136. // be edited.
  137. if( aSymbol->IsAlias() && item.Type() == LIB_FIELD_T )
  138. continue;
  139. Add( &item );
  140. }
  141. InitPreview();
  142. }
  143. void SCH_VIEW::ClearHiddenFlags()
  144. {
  145. for( VIEW_ITEM* item : *m_allItems )
  146. Hide( item, false );
  147. }
  148. void SCH_VIEW::HideDrawingSheet()
  149. {
  150. // SetVisible( m_drawingSheet.get(), false );
  151. }
  152. }; // namespace KIGFX