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.

191 lines
5.2 KiB

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 <core/typeinfo.h>
  28. #include <memory>
  29. #include <view/view.h>
  30. #include <view/view_group.h>
  31. #include <view/view_rtree.h>
  32. #include <view/wx_view_controls.h>
  33. #include <page_layout/ws_proxy_view_item.h>
  34. #include <layers_id_colors_and_visibility.h>
  35. #include <sch_screen.h>
  36. #include <schematic.h>
  37. #include <sch_base_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
  45. // is acceptable for Pcbnew and Gerbview, but too large for Eeschema due to
  46. // very different internal units.
  47. // So we have to use a smaller value.
  48. // A full size = 3 * MAX_PAGE_SIZE_MILS size allows a wide margin
  49. // around the worksheet.
  50. double max_size = Mils2iu( MAX_PAGE_SIZE_MILS ) * 3.0;
  51. m_boundary.SetOrigin( -max_size/4, -max_size/4 );
  52. m_boundary.SetSize( max_size, max_size );
  53. }
  54. SCH_VIEW::~SCH_VIEW()
  55. {
  56. }
  57. void SCH_VIEW::Cleanup()
  58. {
  59. Clear();
  60. m_worksheet.reset();
  61. m_preview.reset();
  62. }
  63. void SCH_VIEW::SetScale( double aScale, VECTOR2D aAnchor )
  64. {
  65. VIEW::SetScale( aScale, aAnchor );
  66. //Redraw selection halos since their width is dependent on zoom
  67. if( m_frame )
  68. m_frame->RefreshSelection();
  69. }
  70. void SCH_VIEW::ResizeSheetWorkingArea( SCH_SCREEN* aScreen )
  71. {
  72. const PAGE_INFO& page_info = aScreen->GetPageSettings();
  73. double max_size_x = page_info.GetWidthIU() * 3.0;
  74. double max_size_y = page_info.GetHeightIU() * 3.0;
  75. m_boundary.SetOrigin( -max_size_x/4, -max_size_y/4 );
  76. m_boundary.SetSize( max_size_x, max_size_y );
  77. }
  78. void SCH_VIEW::DisplaySheet( SCH_SCREEN *aScreen )
  79. {
  80. for( auto item : aScreen->Items() )
  81. Add( item );
  82. m_worksheet.reset( new KIGFX::WS_PROXY_VIEW_ITEM( static_cast< int >( IU_PER_MILS ),
  83. &aScreen->GetPageSettings(),
  84. &aScreen->Schematic()->Prj(),
  85. &aScreen->GetTitleBlock() ) );
  86. m_worksheet->SetSheetNumber( aScreen->m_ScreenNumber );
  87. m_worksheet->SetSheetCount( aScreen->m_NumberOfScreens );
  88. m_worksheet->SetFileName( TO_UTF8( aScreen->GetFileName() ) );
  89. m_worksheet->SetColorLayer( LAYER_SCHEMATIC_WORKSHEET );
  90. m_worksheet->SetPageBorderColorLayer( LAYER_SCHEMATIC_GRID );
  91. if( m_frame && m_frame->IsType( FRAME_SCH ) )
  92. m_worksheet->SetSheetName( TO_UTF8( m_frame->GetScreenDesc() ) );
  93. else
  94. m_worksheet->SetSheetName( "" );
  95. ResizeSheetWorkingArea( aScreen );
  96. Add( m_worksheet.get() );
  97. InitPreview();
  98. }
  99. void SCH_VIEW::DisplaySheet( SCH_SHEET* aSheet )
  100. {
  101. DisplaySheet( aSheet->GetScreen() );
  102. }
  103. void SCH_VIEW::DisplayComponent( LIB_PART* aPart )
  104. {
  105. Clear();
  106. if( !aPart )
  107. return;
  108. std::shared_ptr< LIB_PART > parent;
  109. LIB_PART* drawnPart = aPart;
  110. // Draw the mandatory fields for aliases and parent symbols.
  111. for( auto& item : aPart->GetDrawItems() )
  112. {
  113. if( item.Type() != LIB_FIELD_T )
  114. continue;
  115. LIB_FIELD* field = static_cast< LIB_FIELD* >( &item );
  116. wxCHECK2( field, continue );
  117. if( field->GetText().IsEmpty() )
  118. continue;
  119. Add( &item );
  120. }
  121. // Draw the parent items if the symbol is inherited from another symbol.
  122. if( aPart->IsAlias() )
  123. {
  124. parent = aPart->GetParent().lock();
  125. wxCHECK( parent, /* void */ );
  126. drawnPart = parent.get();
  127. }
  128. for( auto& item : drawnPart->GetDrawItems() )
  129. {
  130. // Don't show parent symbol fields. Users may be confused by shown fields that can not
  131. // be edited.
  132. if( aPart->IsAlias() && item.Type() == LIB_FIELD_T )
  133. continue;
  134. Add( &item );
  135. }
  136. InitPreview();
  137. }
  138. void SCH_VIEW::ClearHiddenFlags()
  139. {
  140. for( auto item : *m_allItems )
  141. Hide( item, false );
  142. }
  143. void SCH_VIEW::HideWorksheet()
  144. {
  145. // SetVisible( m_worksheet.get(), false );
  146. }
  147. }; // namespace KIGFX