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.

972 lines
31 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
5 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
5 years ago
5 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 CERN
  5. * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
  6. * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <kiface_base.h>
  26. #include <pgm_base.h>
  27. #include <bitmaps.h>
  28. #include <core/arraydim.h>
  29. #include <drawing_sheet/ds_data_item.h>
  30. #include <drawing_sheet/ds_data_model.h>
  31. #include <panel_hotkeys_editor.h>
  32. #include <confirm.h>
  33. #include <kiplatform/app.h>
  34. #include <painter.h>
  35. #include <wildcards_and_files_ext.h>
  36. #include <tool/selection.h>
  37. #include <tool/action_toolbar.h>
  38. #include <tool/editor_conditions.h>
  39. #include <tool/tool_dispatcher.h>
  40. #include <tool/tool_manager.h>
  41. #include <tool/common_control.h>
  42. #include <tool/common_tools.h>
  43. #include <tool/picker_tool.h>
  44. #include <tool/zoom_tool.h>
  45. #include <settings/settings_manager.h>
  46. #include "pl_editor_frame.h"
  47. #include "pl_editor_id.h"
  48. #include "pl_editor_settings.h"
  49. #include "properties_frame.h"
  50. #include "tools/pl_actions.h"
  51. #include "tools/pl_selection_tool.h"
  52. #include "tools/pl_drawing_tools.h"
  53. #include "tools/pl_edit_tool.h"
  54. #include "tools/pl_point_editor.h"
  55. #include "invoke_pl_editor_dialog.h"
  56. #include "tools/pl_editor_control.h"
  57. #include <zoom_defines.h>
  58. #include <wx/filedlg.h>
  59. #include <wx/print.h>
  60. #include <wx/treebook.h>
  61. BEGIN_EVENT_TABLE( PL_EDITOR_FRAME, EDA_DRAW_FRAME )
  62. EVT_MENU( wxID_CLOSE, PL_EDITOR_FRAME::OnExit )
  63. EVT_MENU( wxID_EXIT, PL_EDITOR_FRAME::OnExit )
  64. EVT_MENU( wxID_FILE, PL_EDITOR_FRAME::Files_io )
  65. EVT_MENU_RANGE( ID_FILE1, ID_FILEMAX, PL_EDITOR_FRAME::OnFileHistory )
  66. EVT_MENU( ID_FILE_LIST_CLEAR, PL_EDITOR_FRAME::OnClearFileHistory )
  67. EVT_MENU( ID_GRID_SETTINGS, PL_EDITOR_FRAME::OnGridSettings )
  68. EVT_CHOICE( ID_SELECT_COORDINATE_ORIGIN, PL_EDITOR_FRAME::OnSelectCoordOriginCorner )
  69. EVT_CHOICE( ID_SELECT_PAGE_NUMBER, PL_EDITOR_FRAME::OnSelectPage )
  70. // Drop files event
  71. EVT_DROP_FILES( PL_EDITOR_FRAME::OnDropFiles )
  72. END_EVENT_TABLE()
  73. PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
  74. EDA_DRAW_FRAME( aKiway, aParent, FRAME_PL_EDITOR, wxT( "PlEditorFrame" ),
  75. wxDefaultPosition, wxDefaultSize,
  76. KICAD_DEFAULT_DRAWFRAME_STYLE, PL_EDITOR_FRAME_NAME, drawSheetIUScale ),
  77. m_propertiesPagelayout( nullptr ),
  78. m_propertiesFrameWidth( 200 ),
  79. m_originSelectBox( nullptr ),
  80. m_originSelectChoice( 0 ),
  81. m_pageSelectBox( nullptr ),
  82. m_mruImagePath( wxEmptyString )
  83. {
  84. m_maximizeByDefault = true;
  85. SetUserUnits( EDA_UNITS::MILLIMETRES );
  86. m_showBorderAndTitleBlock = true; // true for reference drawings.
  87. DS_DATA_MODEL::GetTheInstance().m_EditMode = true;
  88. m_aboutTitle = _HKI( "KiCad Drawing Sheet Editor" );
  89. // Give an icon
  90. wxIcon icon;
  91. wxIconBundle icon_bundle;
  92. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor ) );
  93. icon_bundle.AddIcon( icon );
  94. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor_32 ) );
  95. icon_bundle.AddIcon( icon );
  96. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pagelayout_editor_16 ) );
  97. icon_bundle.AddIcon( icon );
  98. SetIcons( icon_bundle );
  99. // Create GAL canvas
  100. auto* drawPanel = new PL_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize,
  101. GetGalDisplayOptions(),
  102. EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE );
  103. SetCanvas( drawPanel );
  104. LoadSettings( config() );
  105. m_acceptedExts.emplace( DrawingSheetFileExtension, nullptr );
  106. DragAcceptFiles( true );
  107. VECTOR2I pageSizeIU = GetPageLayout().GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS );
  108. SetScreen( new BASE_SCREEN( pageSizeIU ) );
  109. setupTools();
  110. setupUIConditions();
  111. ReCreateMenuBar();
  112. ReCreateHToolbar();
  113. ReCreateVToolbar();
  114. ReCreateOptToolbar();
  115. wxWindow* stsbar = GetStatusBar();
  116. int spacer = KIUI::GetTextSize( wxT( "M" ), stsbar ).x * 2;
  117. int dims[] = {
  118. // balance of status bar on far left is set to a default or whatever is left over.
  119. -1,
  120. // When using GetTextSize() remember the width of '1' is not the same
  121. // as the width of '0' unless the font is fixed width, and it usually won't be.
  122. // zoom:
  123. KIUI::GetTextSize( wxT( "Z 762000" ), stsbar ).x + spacer,
  124. // cursor coords
  125. KIUI::GetTextSize( wxT( "X 0234.567 Y 0234.567" ), stsbar ).x + spacer,
  126. // delta distances
  127. KIUI::GetTextSize( wxT( "dx 0234.567 dx 0234.567" ), stsbar ).x + spacer,
  128. // grid size
  129. KIUI::GetTextSize( wxT( "grid 0234.567" ), stsbar ).x + spacer,
  130. // Coord origin (use the bigger message)
  131. KIUI::GetTextSize( _( "coord origin: Right Bottom page corner" ), stsbar ).x + spacer,
  132. // units display, Inches is bigger than mm
  133. KIUI::GetTextSize( _( "Inches" ), stsbar ).x + spacer,
  134. // constraint mode
  135. KIUI::GetTextSize( _( "Constrain to H, V, 45" ), stsbar ).x + spacer
  136. };
  137. SetStatusWidths( arrayDim( dims ), dims );
  138. m_auimgr.SetManagedWindow( this );
  139. CreateInfoBar();
  140. m_propertiesPagelayout = new PROPERTIES_FRAME( this );
  141. // Rows; layers 4 - 6
  142. m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" )
  143. .Top().Layer( 6 ) );
  144. m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" )
  145. .Left().Layer( 3 ) );
  146. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" )
  147. .Bottom().Layer( 6 ) );
  148. // Columns; layers 1 - 3
  149. m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" )
  150. .Right().Layer( 2 ) );
  151. m_auimgr.AddPane( m_propertiesPagelayout, EDA_PANE().Palette().Name( "Props" )
  152. .Right().Layer( 3 )
  153. .Caption( _( "Properties" ) )
  154. .MinSize( m_propertiesPagelayout->GetMinSize() )
  155. .BestSize( m_propertiesFrameWidth, -1 ) );
  156. // Center
  157. m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" )
  158. .Center() );
  159. FinishAUIInitialization();
  160. resolveCanvasType();
  161. SwitchCanvas( m_canvasType );
  162. // Add the exit key handler
  163. setupUnits( config() );
  164. VECTOR2I originCoord = ReturnCoordOriginCorner();
  165. SetGridOrigin( originCoord );
  166. // Initialize the current drawing sheet
  167. #if 0 //start with empty layout
  168. DS_DATA_MODEL::GetTheInstance().AllowVoidList( true );
  169. DS_DATA_MODEL::GetTheInstance().ClearList();
  170. #else // start with the default KiCad layout
  171. DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet();
  172. #endif
  173. OnNewDrawingSheet();
  174. // Ensure the window is on top
  175. Raise();
  176. // Register a call to update the toolbar sizes. It can't be done immediately because
  177. // it seems to require some sizes calculated that aren't yet (at least on GTK).
  178. CallAfter( [&]()
  179. {
  180. // Ensure the controls on the toolbars all are correctly sized
  181. UpdateToolbarControlSizes();
  182. } );
  183. }
  184. PL_EDITOR_FRAME::~PL_EDITOR_FRAME()
  185. {
  186. // Ensure m_canvasType is up to date, to save it in config
  187. m_canvasType = GetCanvas()->GetBackend();
  188. // Shutdown all running tools
  189. if( m_toolManager )
  190. m_toolManager->ShutdownAllTools();
  191. }
  192. void PL_EDITOR_FRAME::setupTools()
  193. {
  194. // Create the manager and dispatcher & route draw panel events to the dispatcher
  195. m_toolManager = new TOOL_MANAGER;
  196. m_toolManager->SetEnvironment( nullptr, GetCanvas()->GetView(),
  197. GetCanvas()->GetViewControls(), config(), this );
  198. m_actions = new PL_ACTIONS();
  199. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
  200. GetCanvas()->SetEventDispatcher( m_toolDispatcher );
  201. // Register tools
  202. m_toolManager->RegisterTool( new COMMON_CONTROL );
  203. m_toolManager->RegisterTool( new COMMON_TOOLS );
  204. m_toolManager->RegisterTool( new ZOOM_TOOL );
  205. m_toolManager->RegisterTool( new PL_SELECTION_TOOL );
  206. m_toolManager->RegisterTool( new PL_EDITOR_CONTROL );
  207. m_toolManager->RegisterTool( new PL_DRAWING_TOOLS );
  208. m_toolManager->RegisterTool( new PL_EDIT_TOOL );
  209. m_toolManager->RegisterTool( new PL_POINT_EDITOR );
  210. m_toolManager->RegisterTool( new PICKER_TOOL );
  211. m_toolManager->InitTools();
  212. // Run the selection tool, it is supposed to be always active
  213. m_toolManager->InvokeTool( "plEditor.InteractiveSelection" );
  214. }
  215. void PL_EDITOR_FRAME::setupUIConditions()
  216. {
  217. EDA_DRAW_FRAME::setupUIConditions();
  218. ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
  219. EDITOR_CONDITIONS cond( this );
  220. wxASSERT( mgr );
  221. #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
  222. #define CHECK( x ) ACTION_CONDITIONS().Check( x )
  223. mgr->SetConditions( ACTIONS::save, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
  224. mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) );
  225. mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
  226. mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) );
  227. mgr->SetConditions( ACTIONS::toggleCursorStyle, CHECK( cond.FullscreenCursor() ) );
  228. mgr->SetConditions( ACTIONS::millimetersUnits, CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) );
  229. mgr->SetConditions( ACTIONS::inchesUnits, CHECK( cond.Units( EDA_UNITS::INCHES ) ) );
  230. mgr->SetConditions( ACTIONS::milsUnits, CHECK( cond.Units( EDA_UNITS::MILS ) ) );
  231. mgr->SetConditions( ACTIONS::cut, ENABLE( SELECTION_CONDITIONS::NotEmpty ) );
  232. mgr->SetConditions( ACTIONS::copy, ENABLE( SELECTION_CONDITIONS::NotEmpty ) );
  233. mgr->SetConditions( ACTIONS::paste, ENABLE( SELECTION_CONDITIONS::Idle ) );
  234. mgr->SetConditions( ACTIONS::doDelete, ENABLE( SELECTION_CONDITIONS::NotEmpty ) );
  235. mgr->SetConditions( ACTIONS::zoomTool,
  236. CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) );
  237. mgr->SetConditions( ACTIONS::selectionTool,
  238. CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) );
  239. mgr->SetConditions( ACTIONS::deleteTool,
  240. CHECK( cond.CurrentTool( ACTIONS::deleteTool ) ) );
  241. mgr->SetConditions( PL_ACTIONS::drawLine,
  242. CHECK( cond.CurrentTool( PL_ACTIONS::drawLine ) ) );
  243. mgr->SetConditions( PL_ACTIONS::drawRectangle,
  244. CHECK( cond.CurrentTool( PL_ACTIONS::drawRectangle ) ) );
  245. mgr->SetConditions( PL_ACTIONS::placeText,
  246. CHECK( cond.CurrentTool( PL_ACTIONS::placeText ) ) );
  247. mgr->SetConditions( PL_ACTIONS::placeImage,
  248. CHECK( cond.CurrentTool( PL_ACTIONS::placeImage ) ) );
  249. // Not a tool, just a way to activate the action
  250. mgr->SetConditions( PL_ACTIONS::appendImportedDrawingSheet,
  251. CHECK( SELECTION_CONDITIONS::ShowNever ) );
  252. auto titleBlockNormalMode =
  253. [] ( const SELECTION& )
  254. {
  255. return DS_DATA_MODEL::GetTheInstance().m_EditMode == false;
  256. };
  257. auto titleBlockEditMode =
  258. [] ( const SELECTION& )
  259. {
  260. return DS_DATA_MODEL::GetTheInstance().m_EditMode == true;
  261. };
  262. mgr->SetConditions( PL_ACTIONS::layoutNormalMode, CHECK( titleBlockNormalMode ) );
  263. mgr->SetConditions( PL_ACTIONS::layoutEditMode, CHECK( titleBlockEditMode ) );
  264. #undef CHECK
  265. #undef ENABLE
  266. }
  267. bool PL_EDITOR_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
  268. {
  269. wxString fn = aFileSet[0];
  270. if( !LoadDrawingSheetFile( fn ) )
  271. {
  272. wxMessageBox( wxString::Format( _( "Error loading drawing sheet '%s'." ), fn ) );
  273. return false;
  274. }
  275. else
  276. {
  277. OnNewDrawingSheet();
  278. return true;
  279. }
  280. }
  281. void PL_EDITOR_FRAME::OnModify()
  282. {
  283. // Must be called after a change in order to set the "modify" flag and update
  284. // the frame title.
  285. EDA_BASE_FRAME::OnModify();
  286. GetScreen()->SetContentModified();
  287. UpdateTitleAndInfo();
  288. }
  289. bool PL_EDITOR_FRAME::IsContentModified() const
  290. {
  291. return GetScreen() && GetScreen()->IsContentModified();
  292. }
  293. void PL_EDITOR_FRAME::OnExit( wxCommandEvent& aEvent )
  294. {
  295. if( aEvent.GetId() == wxID_EXIT )
  296. Kiway().OnKiCadExit();
  297. if( aEvent.GetId() == wxID_CLOSE || Kiface().IsSingle() )
  298. Close( false );
  299. }
  300. bool PL_EDITOR_FRAME::canCloseWindow( wxCloseEvent& aEvent )
  301. {
  302. // Shutdown blocks must be determined and vetoed as early as possible
  303. if( KIPLATFORM::APP::SupportsShutdownBlockReason()
  304. && aEvent.GetId() == wxEVT_QUERY_END_SESSION
  305. && IsContentModified() )
  306. {
  307. return false;
  308. }
  309. if( IsContentModified() )
  310. {
  311. wxFileName filename = GetCurrentFileName();
  312. wxString msg = _( "Save changes to '%s' before closing?" );
  313. if( !HandleUnsavedChanges( this, wxString::Format( msg, filename.GetFullName() ),
  314. [&]() -> bool
  315. {
  316. return saveCurrentPageLayout();
  317. } ) )
  318. {
  319. return false;
  320. }
  321. }
  322. return true;
  323. }
  324. void PL_EDITOR_FRAME::doCloseWindow()
  325. {
  326. // do not show the window because we do not want any paint event
  327. Show( false );
  328. // clean up the data before the view is destroyed
  329. DS_DATA_MODEL::GetTheInstance().ClearList();
  330. // On Linux, m_propertiesPagelayout must be destroyed
  331. // before deleting the main frame to avoid a crash when closing
  332. m_propertiesPagelayout->Destroy();
  333. Destroy();
  334. }
  335. void PL_EDITOR_FRAME::OnSelectPage( wxCommandEvent& event )
  336. {
  337. KIGFX::VIEW* view = GetCanvas()->GetView();
  338. view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGE1, m_pageSelectBox->GetSelection() == 0 );
  339. view->SetLayerVisible( LAYER_DRAWINGSHEET_PAGEn, m_pageSelectBox->GetSelection() == 1 );
  340. GetCanvas()->Refresh();
  341. }
  342. void PL_EDITOR_FRAME::OnSelectCoordOriginCorner( wxCommandEvent& event )
  343. {
  344. m_originSelectChoice = m_originSelectBox->GetSelection();
  345. UpdateStatusBar(); // Update grid origin
  346. GetCanvas()->DisplayDrawingSheet();
  347. GetCanvas()->Refresh();
  348. }
  349. void PL_EDITOR_FRAME::ToPrinter( bool doPreview )
  350. {
  351. // static print data and page setup data, to remember settings during the session
  352. static wxPrintData* s_PrintData;
  353. static wxPageSetupDialogData* s_pageSetupData = nullptr;
  354. const PAGE_INFO& pageInfo = GetPageSettings();
  355. if( s_PrintData == nullptr ) // First print
  356. {
  357. s_PrintData = new wxPrintData();
  358. s_PrintData->SetQuality( wxPRINT_QUALITY_HIGH ); // Default resolution = HIGH;
  359. }
  360. if( !s_PrintData->Ok() )
  361. {
  362. wxMessageBox( _( "Error Init Printer info" ) );
  363. return;
  364. }
  365. if( s_pageSetupData == nullptr )
  366. s_pageSetupData = new wxPageSetupDialogData( *s_PrintData );
  367. s_pageSetupData->SetPaperId( pageInfo.GetPaperId() );
  368. s_pageSetupData->GetPrintData().SetOrientation( pageInfo.GetWxOrientation() );
  369. if( pageInfo.IsCustom() )
  370. {
  371. if( pageInfo.IsPortrait() )
  372. s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ),
  373. EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ) ) );
  374. else
  375. s_pageSetupData->SetPaperSize( wxSize( EDA_UNIT_UTILS::Mils2mm( pageInfo.GetHeightMils() ),
  376. EDA_UNIT_UTILS::Mils2mm( pageInfo.GetWidthMils() ) ) );
  377. }
  378. *s_PrintData = s_pageSetupData->GetPrintData();
  379. if( doPreview )
  380. InvokeDialogPrintPreview( this, s_PrintData );
  381. else
  382. InvokeDialogPrint( this, s_PrintData, s_pageSetupData );
  383. }
  384. const BOX2I PL_EDITOR_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
  385. {
  386. BOX2I rv( VECTOR2I( 0, 0 ), GetPageLayout().GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS ) );
  387. return rv;
  388. }
  389. void PL_EDITOR_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  390. {
  391. EDA_DRAW_FRAME::LoadSettings( aCfg );
  392. if( aCfg->m_Window.grid.sizes.empty() )
  393. {
  394. aCfg->m_Window.grid.sizes = { "5.00 mm",
  395. "2.50 mm",
  396. "2.00 mm",
  397. "1.00 mm",
  398. "0.50 mm",
  399. "0.25 mm",
  400. "0.20 mm",
  401. "0.10 mm" };
  402. }
  403. // Currently values read from config file are not used because the user cannot
  404. // change this config
  405. // if( aCfg->m_Window.zoom_factors.empty() )
  406. {
  407. aCfg->m_Window.zoom_factors = { ZOOM_LIST_PL_EDITOR };
  408. }
  409. PL_EDITOR_SETTINGS* cfg = dynamic_cast<PL_EDITOR_SETTINGS*>( aCfg );
  410. wxCHECK( cfg, /*void*/ );
  411. m_propertiesFrameWidth = cfg->m_PropertiesFrameWidth;
  412. m_originSelectChoice = cfg->m_CornerOrigin;
  413. SetDrawBgColor( cfg->m_BlackBackground ? BLACK : WHITE );
  414. PAGE_INFO::SetCustomWidthMils( cfg->m_LastCustomWidth );
  415. PAGE_INFO::SetCustomHeightMils( cfg->m_LastCustomHeight );
  416. PAGE_INFO pageInfo = GetPageSettings();
  417. pageInfo.SetType( cfg->m_LastPaperSize, cfg->m_LastWasPortrait );
  418. SetPageSettings( pageInfo );
  419. }
  420. void PL_EDITOR_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  421. {
  422. EDA_DRAW_FRAME::SaveSettings( aCfg );
  423. auto cfg = static_cast<PL_EDITOR_SETTINGS*>( aCfg );
  424. m_propertiesFrameWidth = m_propertiesPagelayout->GetSize().x;
  425. cfg->m_PropertiesFrameWidth = m_propertiesFrameWidth;
  426. cfg->m_CornerOrigin = m_originSelectChoice;
  427. cfg->m_BlackBackground = GetDrawBgColor() == BLACK;
  428. cfg->m_LastPaperSize = GetPageSettings().GetType();
  429. cfg->m_LastWasPortrait = GetPageSettings().IsPortrait();
  430. cfg->m_LastCustomWidth = PAGE_INFO::GetCustomWidthMils();
  431. cfg->m_LastCustomHeight = PAGE_INFO::GetCustomHeightMils();
  432. }
  433. void PL_EDITOR_FRAME::UpdateTitleAndInfo()
  434. {
  435. wxString title;
  436. wxFileName file( GetCurrentFileName() );
  437. if( IsContentModified() )
  438. title = wxT( "*" );
  439. if( file.IsOk() )
  440. title += file.GetName();
  441. else
  442. title += _( "[no drawing sheet loaded]" );
  443. title += wxT( " \u2014 " ) + _( "Drawing Sheet Editor" ),
  444. SetTitle( title );
  445. }
  446. wxString PL_EDITOR_FRAME::GetCurrentFileName() const
  447. {
  448. return BASE_SCREEN::m_DrawingSheetFileName;
  449. }
  450. void PL_EDITOR_FRAME::SetCurrentFileName( const wxString& aName )
  451. {
  452. BASE_SCREEN::m_DrawingSheetFileName = aName;
  453. }
  454. void PL_EDITOR_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
  455. {
  456. m_pageLayout.SetPageSettings( aPageSettings );
  457. if( GetScreen() )
  458. GetScreen()->InitDataPoints( aPageSettings.GetSizeIU( drawSheetIUScale.IU_PER_MILS ) );
  459. }
  460. const PAGE_INFO& PL_EDITOR_FRAME::GetPageSettings() const
  461. {
  462. return m_pageLayout.GetPageSettings();
  463. }
  464. const VECTOR2I PL_EDITOR_FRAME::GetPageSizeIU() const
  465. {
  466. // this function is only needed because EDA_DRAW_FRAME is not compiled
  467. // with either -DPCBNEW or -DEESCHEMA, so the virtual is used to route
  468. // into an application specific source file.
  469. return m_pageLayout.GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS );
  470. }
  471. const TITLE_BLOCK& PL_EDITOR_FRAME::GetTitleBlock() const
  472. {
  473. return GetPageLayout().GetTitleBlock();
  474. }
  475. void PL_EDITOR_FRAME::SetTitleBlock( const TITLE_BLOCK& aTitleBlock )
  476. {
  477. m_pageLayout.SetTitleBlock( aTitleBlock );
  478. }
  479. void PL_EDITOR_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
  480. {
  481. EDA_DRAW_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
  482. SETTINGS_MANAGER& settingsManager = Pgm().GetSettingsManager();
  483. PL_EDITOR_SETTINGS* cfg = settingsManager.GetAppSettings<PL_EDITOR_SETTINGS>();
  484. COLOR_SETTINGS* colors = settingsManager.GetColorSettings( cfg->m_ColorTheme );
  485. // Update gal display options like cursor shape, grid options:
  486. GetGalDisplayOptions().ReadWindowSettings( cfg->m_Window );
  487. GetCanvas()->GetView()->GetPainter()->GetSettings()->LoadColors( colors );
  488. GetCanvas()->GetView()->UpdateAllItems( KIGFX::COLOR );
  489. GetCanvas()->ForceRefresh();
  490. RecreateToolbars();
  491. Layout();
  492. SendSizeEvent();
  493. }
  494. VECTOR2I PL_EDITOR_FRAME::ReturnCoordOriginCorner() const
  495. {
  496. // calculate the position (in page, in iu) of the corner used as coordinate origin
  497. // coordinate origin can be the paper Top Left corner, or each of 4 page corners
  498. VECTOR2I originCoord;
  499. // To avoid duplicate code, we use a dummy segment starting at 0,0 in relative coord
  500. DS_DATA_ITEM dummy( DS_DATA_ITEM::DS_SEGMENT );
  501. switch( m_originSelectChoice )
  502. {
  503. default:
  504. case 0: // Origin = paper Left Top corner
  505. break;
  506. case 1: // Origin = page Right Bottom corner
  507. dummy.SetStart( 0, 0, RB_CORNER );
  508. originCoord = dummy.GetStartPosIU();
  509. break;
  510. case 2: // Origin = page Left Bottom corner
  511. dummy.SetStart( 0, 0, LB_CORNER );
  512. originCoord = dummy.GetStartPosIU();
  513. break;
  514. case 3: // Origin = page Right Top corner
  515. dummy.SetStart( 0, 0, RT_CORNER );
  516. originCoord = dummy.GetStartPosIU();
  517. break;
  518. case 4: // Origin = page Left Top corner
  519. dummy.SetStart( 0, 0, LT_CORNER );
  520. originCoord = dummy.GetStartPosIU();
  521. break;
  522. }
  523. return originCoord;
  524. }
  525. void PL_EDITOR_FRAME::DisplayGridMsg()
  526. {
  527. wxString line;
  528. wxString gridformatter;
  529. switch( GetUserUnits() )
  530. {
  531. case EDA_UNITS::INCHES: gridformatter = wxS( "grid %.3f" ); break;
  532. case EDA_UNITS::MILLIMETRES: gridformatter = wxS( "grid %.4f" ); break;
  533. default: gridformatter = wxS( "grid %f" ); break;
  534. }
  535. double grid = EDA_UNIT_UTILS::UI::ToUserUnit( drawSheetIUScale, GetUserUnits(),
  536. GetCanvas()->GetGAL()->GetGridSize().x );
  537. line.Printf( gridformatter, grid );
  538. SetStatusText( line, 4 );
  539. }
  540. void PL_EDITOR_FRAME::UpdateStatusBar()
  541. {
  542. // Display Zoom level:
  543. SetStatusText( GetZoomLevelIndicator(), 1 );
  544. // coordinate origin can be the paper Top Left corner, or each of 4 page corners
  545. VECTOR2I originCoord = ReturnCoordOriginCorner();
  546. SetGridOrigin( originCoord );
  547. // We need the orientation of axis (sign of coordinates)
  548. int Xsign = 1;
  549. int Ysign = 1;
  550. switch( m_originSelectChoice )
  551. {
  552. default:
  553. case 0: // Origin = paper Left Top corner
  554. break;
  555. case 1: // Origin = page Right Bottom corner
  556. Xsign = -1;
  557. Ysign = -1;
  558. break;
  559. case 2: // Origin = page Left Bottom corner
  560. Ysign = -1;
  561. break;
  562. case 3: // Origin = page Right Top corner
  563. Xsign = -1;
  564. break;
  565. case 4: // Origin = page Left Top corner
  566. break;
  567. }
  568. // Display absolute coordinates:
  569. VECTOR2D cursorPos = GetCanvas()->GetViewControls()->GetCursorPosition();
  570. VECTOR2D coord = cursorPos - originCoord;
  571. double dXpos =
  572. EDA_UNIT_UTILS::UI::ToUserUnit( drawSheetIUScale, GetUserUnits(), coord.x * Xsign );
  573. double dYpos =
  574. EDA_UNIT_UTILS::UI::ToUserUnit( drawSheetIUScale, GetUserUnits(), coord.y * Ysign );
  575. wxString absformatter = wxT( "X %.4g Y %.4g" );
  576. wxString locformatter = wxT( "dx %.4g dy %.4g" );
  577. switch( GetUserUnits() )
  578. {
  579. case EDA_UNITS::INCHES: SetStatusText( _( "inches" ), 6 ); break;
  580. case EDA_UNITS::MILS: SetStatusText( _( "mils" ), 6 ); break;
  581. case EDA_UNITS::MILLIMETRES: SetStatusText( _( "mm" ), 6 ); break;
  582. case EDA_UNITS::UNSCALED: SetStatusText( wxEmptyString, 6 ); break;
  583. default: wxASSERT( false ); break;
  584. }
  585. wxString line;
  586. // Display abs coordinates
  587. line.Printf( absformatter, dXpos, dYpos );
  588. SetStatusText( line, 2 );
  589. // Display relative coordinates:
  590. if( GetScreen() )
  591. {
  592. double dx = cursorPos.x - GetScreen()->m_LocalOrigin.x;
  593. double dy = cursorPos.y - GetScreen()->m_LocalOrigin.y;
  594. dXpos = EDA_UNIT_UTILS::UI::ToUserUnit( drawSheetIUScale, GetUserUnits(), dx * Xsign );
  595. dYpos = EDA_UNIT_UTILS::UI::ToUserUnit( drawSheetIUScale, GetUserUnits(), dy * Ysign );
  596. line.Printf( locformatter, dXpos, dYpos );
  597. SetStatusText( line, 3 );
  598. }
  599. DisplayGridMsg();
  600. // Display corner reference for coord origin
  601. line.Printf( _("coord origin: %s"),
  602. m_originSelectBox->GetString( m_originSelectChoice ).GetData() );
  603. SetStatusText( line, 5 );
  604. }
  605. void PL_EDITOR_FRAME::PrintPage( const RENDER_SETTINGS* aSettings )
  606. {
  607. GetScreen()->SetVirtualPageNumber( GetPageNumberOption() ? 1 : 2 );
  608. DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
  609. for( DS_DATA_ITEM* dataItem : model.GetItems() )
  610. {
  611. // Ensure the scaling factor (used only in printing) of bitmaps is up to date
  612. if( dataItem->GetType() == DS_DATA_ITEM::DS_BITMAP )
  613. {
  614. BITMAP_BASE* bitmap = static_cast<DS_DATA_ITEM_BITMAP*>( dataItem )->m_ImageBitmap;
  615. bitmap->SetPixelSizeIu( drawSheetIUScale.IU_PER_MILS * 1000 / bitmap->GetPPI() );
  616. }
  617. }
  618. PrintDrawingSheet( aSettings, GetScreen(), nullptr, drawSheetIUScale.IU_PER_MILS,
  619. wxEmptyString );
  620. GetCanvas()->DisplayDrawingSheet();
  621. GetCanvas()->Refresh();
  622. }
  623. PL_DRAW_PANEL_GAL* PL_EDITOR_FRAME::GetCanvas() const
  624. {
  625. return static_cast<PL_DRAW_PANEL_GAL*>( EDA_DRAW_FRAME::GetCanvas() );
  626. }
  627. SELECTION& PL_EDITOR_FRAME::GetCurrentSelection()
  628. {
  629. return m_toolManager->GetTool<PL_SELECTION_TOOL>()->GetSelection();
  630. }
  631. void PL_EDITOR_FRAME::HardRedraw()
  632. {
  633. GetCanvas()->DisplayDrawingSheet();
  634. PL_SELECTION_TOOL* selTool = m_toolManager->GetTool<PL_SELECTION_TOOL>();
  635. PL_SELECTION& selection = selTool->GetSelection();
  636. DS_DATA_ITEM* item = nullptr;
  637. if( selection.GetSize() == 1 )
  638. item = static_cast<DS_DRAW_ITEM_BASE*>( selection.Front() )->GetPeer();
  639. m_propertiesPagelayout->CopyPrmsFromItemToPanel( item );
  640. m_propertiesPagelayout->CopyPrmsFromGeneralToPanel();
  641. UpdateMsgPanelInfo();
  642. GetCanvas()->Refresh();
  643. }
  644. DS_DATA_ITEM* PL_EDITOR_FRAME::AddDrawingSheetItem( int aType )
  645. {
  646. DS_DATA_ITEM * item = nullptr;
  647. switch( aType )
  648. {
  649. case DS_DATA_ITEM::DS_TEXT:
  650. item = new DS_DATA_ITEM_TEXT( wxT( "Text") );
  651. break;
  652. case DS_DATA_ITEM::DS_SEGMENT:
  653. item = new DS_DATA_ITEM( DS_DATA_ITEM::DS_SEGMENT );
  654. break;
  655. case DS_DATA_ITEM::DS_RECT:
  656. item = new DS_DATA_ITEM( DS_DATA_ITEM::DS_RECT );
  657. break;
  658. case DS_DATA_ITEM::DS_POLYPOLYGON:
  659. item = new DS_DATA_ITEM_POLYGONS();
  660. break;
  661. case DS_DATA_ITEM::DS_BITMAP:
  662. {
  663. wxFileDialog fileDlg( this, _( "Choose Image" ), m_mruImagePath, wxEmptyString,
  664. _( "Image Files" ) + wxS( " " ) + wxImage::GetImageExtWildcard(),
  665. wxFD_OPEN );
  666. if( fileDlg.ShowModal() != wxID_OK )
  667. return nullptr;
  668. wxString fullFilename = fileDlg.GetPath();
  669. m_mruImagePath = wxPathOnly( fullFilename );
  670. if( !wxFileExists( fullFilename ) )
  671. {
  672. wxMessageBox( _( "Could not load image from '%s'." ), fullFilename );
  673. break;
  674. }
  675. BITMAP_BASE* image = new BITMAP_BASE();
  676. if( !image->ReadImageFile( fullFilename ) )
  677. {
  678. wxMessageBox( _( "Could not load image from '%s'." ), fullFilename );
  679. delete image;
  680. break;
  681. }
  682. // Set the scale factor for pl_editor (it is set for Eeschema by default)
  683. image->SetPixelSizeIu( drawSheetIUScale.IU_PER_MILS * 1000.0 / image->GetPPI() );
  684. item = new DS_DATA_ITEM_BITMAP( image );
  685. }
  686. break;
  687. }
  688. if( item == nullptr )
  689. return nullptr;
  690. DS_DATA_MODEL::GetTheInstance().Append( item );
  691. item->SyncDrawItems( nullptr, GetCanvas()->GetView() );
  692. return item;
  693. }
  694. void PL_EDITOR_FRAME::OnNewDrawingSheet()
  695. {
  696. ClearUndoRedoList();
  697. GetScreen()->SetContentModified( false );
  698. GetCanvas()->DisplayDrawingSheet();
  699. m_propertiesPagelayout->CopyPrmsFromItemToPanel( nullptr );
  700. m_propertiesPagelayout->CopyPrmsFromGeneralToPanel();
  701. UpdateTitleAndInfo();
  702. m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
  703. if( GetCurrentFileName().IsEmpty() )
  704. {
  705. // Default shutdown reason until a file is loaded
  706. KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New drawing sheet file is unsaved" ) );
  707. }
  708. else
  709. {
  710. KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Drawing sheet changes are unsaved" ) );
  711. }
  712. }
  713. void PL_EDITOR_FRAME::ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount )
  714. {
  715. if( aItemCount == 0 )
  716. return;
  717. UNDO_REDO_CONTAINER& list = whichList == UNDO_LIST ? m_undoList : m_redoList;
  718. unsigned icnt = list.m_CommandsList.size();
  719. if( aItemCount > 0 )
  720. icnt = aItemCount;
  721. for( unsigned ii = 0; ii < icnt; ii++ )
  722. {
  723. if( list.m_CommandsList.size() == 0 )
  724. break;
  725. PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0];
  726. list.m_CommandsList.erase( list.m_CommandsList.begin() );
  727. curr_cmd->ClearListAndDeleteItems( []( EDA_ITEM* aItem )
  728. {
  729. delete aItem;
  730. } );
  731. delete curr_cmd; // Delete command
  732. }
  733. }
  734. bool PL_EDITOR_FRAME::GetPageNumberOption() const
  735. {
  736. return m_pageSelectBox->GetSelection() == 0;
  737. }
  738. #if 1
  739. void PL_EDITOR_FRAME::UpdateMsgPanelInfo()
  740. {
  741. VECTOR2D size = GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS );
  742. std::vector<MSG_PANEL_ITEM> msgItems;
  743. msgItems.emplace_back( _( "Page Width" ), MessageTextFromValue( size.x ) );
  744. msgItems.emplace_back( _( "Page Height" ), MessageTextFromValue( size.y ) );
  745. SetMsgPanel( msgItems );
  746. }
  747. #endif