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.

915 lines
29 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
* 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
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
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-2020 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_i.h>
  26. #include <pgm_base.h>
  27. #include <bitmaps.h>
  28. #include <core/arraydim.h>
  29. #include <eda_item.h>
  30. #include <page_layout/ws_data_item.h>
  31. #include <page_layout/ws_data_model.h>
  32. #include <widgets/paged_dialog.h>
  33. #include <dialogs/panel_gal_display_options.h>
  34. #include <panel_hotkeys_editor.h>
  35. #include <confirm.h>
  36. #include <kiplatform/app.h>
  37. #include <painter.h>
  38. #include <tool/selection.h>
  39. #include <tool/action_toolbar.h>
  40. #include <tool/editor_conditions.h>
  41. #include <tool/tool_dispatcher.h>
  42. #include <tool/tool_manager.h>
  43. #include <tool/common_control.h>
  44. #include <tool/common_tools.h>
  45. #include <tool/picker_tool.h>
  46. #include <tool/zoom_tool.h>
  47. #include <widgets/infobar.h>
  48. #include <settings/settings_manager.h>
  49. #include "dialogs/panel_pl_editor_color_settings.h"
  50. #include "pl_editor_frame.h"
  51. #include "pl_editor_id.h"
  52. #include "pl_editor_settings.h"
  53. #include "properties_frame.h"
  54. #include "tools/pl_actions.h"
  55. #include "tools/pl_selection_tool.h"
  56. #include "tools/pl_drawing_tools.h"
  57. #include "tools/pl_edit_tool.h"
  58. #include "tools/pl_point_editor.h"
  59. #include "invoke_pl_editor_dialog.h"
  60. #include "tools/pl_editor_control.h"
  61. #include <zoom_defines.h>
  62. BEGIN_EVENT_TABLE( PL_EDITOR_FRAME, EDA_DRAW_FRAME )
  63. EVT_MENU( wxID_CLOSE, PL_EDITOR_FRAME::OnExit )
  64. EVT_MENU( wxID_EXIT, PL_EDITOR_FRAME::OnExit )
  65. EVT_MENU( wxID_FILE, PL_EDITOR_FRAME::Files_io )
  66. EVT_MENU_RANGE( ID_FILE1, ID_FILEMAX, PL_EDITOR_FRAME::OnFileHistory )
  67. EVT_MENU( ID_FILE_LIST_CLEAR, PL_EDITOR_FRAME::OnClearFileHistory )
  68. EVT_CHOICE( ID_SELECT_COORDINATE_ORIGIN, PL_EDITOR_FRAME::OnSelectCoordOriginCorner )
  69. EVT_CHOICE( ID_SELECT_PAGE_NUMBER, PL_EDITOR_FRAME::OnSelectPage )
  70. END_EVENT_TABLE()
  71. PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
  72. EDA_DRAW_FRAME( aKiway, aParent, FRAME_PL_EDITOR, wxT( "PlEditorFrame" ),
  73. wxDefaultPosition, wxDefaultSize,
  74. KICAD_DEFAULT_DRAWFRAME_STYLE, PL_EDITOR_FRAME_NAME ),
  75. m_propertiesFrameWidth( 200 ),
  76. m_originSelectBox( nullptr ),
  77. m_originSelectChoice( 0 ),
  78. m_pageSelectBox( nullptr ),
  79. m_propertiesPagelayout( nullptr )
  80. {
  81. m_maximizeByDefault = true;
  82. m_userUnits = EDA_UNITS::MILLIMETRES;
  83. m_showBorderAndTitleBlock = true; // true for reference drawings.
  84. WS_DATA_MODEL::GetTheInstance().m_EditMode = true;
  85. SetShowPageLimits( true );
  86. m_aboutTitle = _( "KiCad Worksheet Editor" );
  87. // Give an icon
  88. wxIcon icon;
  89. wxIconBundle icon_bundle;
  90. icon.CopyFromBitmap( KiBitmap( icon_pagelayout_editor_xpm ) );
  91. icon_bundle.AddIcon( icon );
  92. icon.CopyFromBitmap( KiBitmap( icon_pagelayout_editor_32_xpm ) );
  93. icon_bundle.AddIcon( icon );
  94. icon.CopyFromBitmap( KiBitmap( icon_pagelayout_editor_16_xpm ) );
  95. icon_bundle.AddIcon( icon );
  96. SetIcons( icon_bundle );
  97. // Create GAL canvas
  98. auto* drawPanel = new PL_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize,
  99. GetGalDisplayOptions(),
  100. EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE );
  101. SetCanvas( drawPanel );
  102. LoadSettings( config() );
  103. wxSize pageSizeIU = GetPageLayout().GetPageSettings().GetSizeIU();
  104. SetScreen( new BASE_SCREEN( pageSizeIU ) );
  105. setupTools();
  106. setupUIConditions();
  107. ReCreateMenuBar();
  108. ReCreateHToolbar();
  109. ReCreateVToolbar();
  110. ReCreateOptToolbar();
  111. wxWindow* stsbar = GetStatusBar();
  112. int dims[] = {
  113. // balance of status bar on far left is set to a default or whatever is left over.
  114. -1,
  115. // When using GetTextSize() remember the width of '1' is not the same
  116. // as the width of '0' unless the font is fixed width, and it usually won't be.
  117. // zoom:
  118. KIUI::GetTextSize( wxT( "Z 762000" ), stsbar ).x + 10,
  119. // cursor coords
  120. KIUI::GetTextSize( wxT( "X 0234.567 Y 0234.567" ), stsbar ).x + 10,
  121. // delta distances
  122. KIUI::GetTextSize( wxT( "dx 0234.567 dx 0234.567" ), stsbar ).x + 10,
  123. // grid size
  124. KIUI::GetTextSize( wxT( "grid 0234.567" ), stsbar ).x + 10,
  125. // Coord origin (use the bigger message)
  126. KIUI::GetTextSize( _( "coord origin: Right Bottom page corner" ), stsbar ).x + 10,
  127. // units display, Inches is bigger than mm
  128. KIUI::GetTextSize( _( "Inches" ), stsbar ).x + 20
  129. };
  130. SetStatusWidths( arrayDim( dims ), dims );
  131. m_auimgr.SetManagedWindow( this );
  132. CreateInfoBar();
  133. m_propertiesPagelayout = new PROPERTIES_FRAME( this );
  134. // Rows; layers 4 - 6
  135. m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" )
  136. .Top().Layer( 6 ) );
  137. m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" )
  138. .Left().Layer( 3 ) );
  139. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" )
  140. .Bottom().Layer( 6 ) );
  141. // Columns; layers 1 - 3
  142. m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" )
  143. .Right().Layer( 2 ) );
  144. m_auimgr.AddPane( m_propertiesPagelayout, EDA_PANE().Palette().Name( "Props" )
  145. .Right().Layer( 3 )
  146. .Caption( _( "Properties" ) )
  147. .MinSize( m_propertiesPagelayout->GetMinSize() )
  148. .BestSize( m_propertiesFrameWidth, -1 ) );
  149. // Center
  150. m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" )
  151. .Center() );
  152. FinishAUIInitialization();
  153. resolveCanvasType();
  154. SwitchCanvas( m_canvasType );
  155. // Add the exit key handler
  156. setupUnits( config() );
  157. wxPoint originCoord = ReturnCoordOriginCorner();
  158. SetGridOrigin( originCoord );
  159. // Initialize the current page layout
  160. WS_DATA_MODEL& pglayout = WS_DATA_MODEL::GetTheInstance();
  161. #if 0 //start with empty layout
  162. pglayout.AllowVoidList( true );
  163. pglayout.ClearList();
  164. #else // start with the default Kicad layout
  165. pglayout.SetPageLayout();
  166. #endif
  167. OnNewPageLayout();
  168. // Ensure the window is on top
  169. Raise();
  170. }
  171. PL_EDITOR_FRAME::~PL_EDITOR_FRAME()
  172. {
  173. // Shutdown all running tools
  174. if( m_toolManager )
  175. m_toolManager->ShutdownAllTools();
  176. }
  177. void PL_EDITOR_FRAME::setupTools()
  178. {
  179. // Create the manager and dispatcher & route draw panel events to the dispatcher
  180. m_toolManager = new TOOL_MANAGER;
  181. m_toolManager->SetEnvironment( nullptr, GetCanvas()->GetView(),
  182. GetCanvas()->GetViewControls(), config(), this );
  183. m_actions = new PL_ACTIONS();
  184. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions );
  185. GetCanvas()->SetEventDispatcher( m_toolDispatcher );
  186. // Register tools
  187. m_toolManager->RegisterTool( new COMMON_CONTROL );
  188. m_toolManager->RegisterTool( new COMMON_TOOLS );
  189. m_toolManager->RegisterTool( new ZOOM_TOOL );
  190. m_toolManager->RegisterTool( new PL_SELECTION_TOOL );
  191. m_toolManager->RegisterTool( new PL_EDITOR_CONTROL );
  192. m_toolManager->RegisterTool( new PL_DRAWING_TOOLS );
  193. m_toolManager->RegisterTool( new PL_EDIT_TOOL );
  194. m_toolManager->RegisterTool( new PL_POINT_EDITOR );
  195. m_toolManager->RegisterTool( new PICKER_TOOL );
  196. m_toolManager->InitTools();
  197. // Run the selection tool, it is supposed to be always active
  198. m_toolManager->InvokeTool( "plEditor.InteractiveSelection" );
  199. }
  200. void PL_EDITOR_FRAME::setupUIConditions()
  201. {
  202. EDA_DRAW_FRAME::setupUIConditions();
  203. ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
  204. EDITOR_CONDITIONS cond( this );
  205. wxASSERT( mgr );
  206. #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
  207. #define CHECK( x ) ACTION_CONDITIONS().Check( x )
  208. mgr->SetConditions( ACTIONS::save, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
  209. mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) );
  210. mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
  211. mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) );
  212. mgr->SetConditions( ACTIONS::toggleCursorStyle, CHECK( cond.FullscreenCursor() ) );
  213. mgr->SetConditions( ACTIONS::millimetersUnits, CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) );
  214. mgr->SetConditions( ACTIONS::inchesUnits, CHECK( cond.Units( EDA_UNITS::INCHES ) ) );
  215. mgr->SetConditions( ACTIONS::milsUnits, CHECK( cond.Units( EDA_UNITS::MILS ) ) );
  216. mgr->SetConditions( ACTIONS::acceleratedGraphics, CHECK( cond.CanvasType( EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL ) ) );
  217. mgr->SetConditions( ACTIONS::standardGraphics, CHECK( cond.CanvasType( EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO ) ) );
  218. mgr->SetConditions( ACTIONS::cut, ENABLE( SELECTION_CONDITIONS::NotEmpty ) );
  219. mgr->SetConditions( ACTIONS::copy, ENABLE( SELECTION_CONDITIONS::NotEmpty ) );
  220. mgr->SetConditions( ACTIONS::paste, ENABLE( SELECTION_CONDITIONS::Idle ) );
  221. mgr->SetConditions( ACTIONS::doDelete, ENABLE( SELECTION_CONDITIONS::NotEmpty ) );
  222. mgr->SetConditions( ACTIONS::zoomTool, CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) );
  223. mgr->SetConditions( ACTIONS::selectionTool, CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) );
  224. mgr->SetConditions( ACTIONS::deleteTool, CHECK( cond.CurrentTool( ACTIONS::deleteTool ) ) );
  225. mgr->SetConditions( PL_ACTIONS::drawLine, CHECK( cond.CurrentTool( PL_ACTIONS::drawLine ) ) );
  226. mgr->SetConditions( PL_ACTIONS::drawRectangle, CHECK( cond.CurrentTool( PL_ACTIONS::drawRectangle ) ) );
  227. mgr->SetConditions( PL_ACTIONS::placeText, CHECK( cond.CurrentTool( PL_ACTIONS::placeText ) ) );
  228. mgr->SetConditions( PL_ACTIONS::placeImage, CHECK( cond.CurrentTool( PL_ACTIONS::placeImage ) ) );
  229. // Not a tool, just a way to activate the action
  230. mgr->SetConditions( PL_ACTIONS::appendImportedWorksheet, CHECK( SELECTION_CONDITIONS::ShowNever ) );
  231. auto titleBlockNormalMode =
  232. [] ( const SELECTION& )
  233. {
  234. return WS_DATA_MODEL::GetTheInstance().m_EditMode == false;
  235. };
  236. auto titleBlockEditMode =
  237. [] ( const SELECTION& )
  238. {
  239. return WS_DATA_MODEL::GetTheInstance().m_EditMode == true;
  240. };
  241. mgr->SetConditions( PL_ACTIONS::layoutNormalMode, CHECK( titleBlockNormalMode ) );
  242. mgr->SetConditions( PL_ACTIONS::layoutEditMode, CHECK( titleBlockEditMode ) );
  243. #undef CHECK
  244. #undef ENABLE
  245. }
  246. bool PL_EDITOR_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
  247. {
  248. wxString fn = aFileSet[0];
  249. if( !LoadPageLayoutDescrFile( fn ) )
  250. {
  251. wxMessageBox( wxString::Format( _( "Error when loading file \"%s\"" ), fn ) );
  252. return false;
  253. }
  254. else
  255. {
  256. OnNewPageLayout();
  257. return true;
  258. }
  259. }
  260. bool PL_EDITOR_FRAME::IsContentModified()
  261. {
  262. return GetScreen() && GetScreen()->IsModify();
  263. }
  264. void PL_EDITOR_FRAME::OnExit( wxCommandEvent& aEvent )
  265. {
  266. if( aEvent.GetId() == wxID_EXIT )
  267. Kiway().OnKiCadExit();
  268. if( aEvent.GetId() == wxID_CLOSE || Kiface().IsSingle() )
  269. Close( false );
  270. }
  271. bool PL_EDITOR_FRAME::canCloseWindow( wxCloseEvent& aEvent )
  272. {
  273. // Shutdown blocks must be determined and vetoed as early as possible
  274. if( KIPLATFORM::APP::SupportsShutdownBlockReason()
  275. && aEvent.GetId() == wxEVT_QUERY_END_SESSION
  276. && IsContentModified() )
  277. {
  278. return false;
  279. }
  280. if( IsContentModified() )
  281. {
  282. wxFileName filename = GetCurrentFileName();
  283. wxString msg = _( "Save changes to \"%s\" before closing?" );
  284. if( !HandleUnsavedChanges( this, wxString::Format( msg, filename.GetFullName() ),
  285. [&]() -> bool
  286. {
  287. return saveCurrentPageLayout();
  288. } ) )
  289. {
  290. return false;
  291. }
  292. }
  293. return true;
  294. }
  295. void PL_EDITOR_FRAME::doCloseWindow()
  296. {
  297. // do not show the window because we do not want any paint event
  298. Show( false );
  299. // clean up the data before the view is destroyed
  300. WS_DATA_MODEL::GetTheInstance().ClearList();
  301. // On Linux, m_propertiesPagelayout must be destroyed
  302. // before deleting the main frame to avoid a crash when closing
  303. m_propertiesPagelayout->Destroy();
  304. Destroy();
  305. }
  306. /* Handles the selection of tools, menu, and popup menu commands.
  307. */
  308. void PL_EDITOR_FRAME::OnSelectPage( wxCommandEvent& event )
  309. {
  310. KIGFX::VIEW* view = GetCanvas()->GetView();
  311. view->SetLayerVisible( LAYER_WORKSHEET_PAGE1, m_pageSelectBox->GetSelection() == 0 );
  312. view->SetLayerVisible( LAYER_WORKSHEET_PAGEn, m_pageSelectBox->GetSelection() == 1 );
  313. GetCanvas()->Refresh();
  314. }
  315. /* called when the user select one of the 4 page corner as corner
  316. * reference (or the left top paper corner)
  317. */
  318. void PL_EDITOR_FRAME::OnSelectCoordOriginCorner( wxCommandEvent& event )
  319. {
  320. m_originSelectChoice = m_originSelectBox->GetSelection();
  321. UpdateStatusBar(); // Update grid origin
  322. GetCanvas()->DisplayWorksheet();
  323. GetCanvas()->Refresh();
  324. }
  325. void PL_EDITOR_FRAME::ToPrinter( bool doPreview )
  326. {
  327. // static print data and page setup data, to remember settings during the session
  328. static wxPrintData* s_PrintData;
  329. static wxPageSetupDialogData* s_pageSetupData = nullptr;
  330. const PAGE_INFO& pageInfo = GetPageSettings();
  331. if( s_PrintData == NULL ) // First print
  332. {
  333. s_PrintData = new wxPrintData();
  334. s_PrintData->SetQuality( wxPRINT_QUALITY_HIGH ); // Default resolution = HIGH;
  335. }
  336. if( !s_PrintData->Ok() )
  337. {
  338. wxMessageBox( _( "Error Init Printer info" ) );
  339. return;
  340. }
  341. if( s_pageSetupData == NULL )
  342. s_pageSetupData = new wxPageSetupDialogData( *s_PrintData );
  343. s_pageSetupData->SetPaperId( pageInfo.GetPaperId() );
  344. s_pageSetupData->GetPrintData().SetOrientation( pageInfo.GetWxOrientation() );
  345. if( pageInfo.IsCustom() )
  346. {
  347. if( pageInfo.IsPortrait() )
  348. s_pageSetupData->SetPaperSize( wxSize( Mils2mm( pageInfo.GetWidthMils() ),
  349. Mils2mm( pageInfo.GetHeightMils() ) ) );
  350. else
  351. s_pageSetupData->SetPaperSize( wxSize( Mils2mm( pageInfo.GetHeightMils() ),
  352. Mils2mm( pageInfo.GetWidthMils() ) ) );
  353. }
  354. *s_PrintData = s_pageSetupData->GetPrintData();
  355. if( doPreview )
  356. InvokeDialogPrintPreview( this, s_PrintData );
  357. else
  358. InvokeDialogPrint( this, s_PrintData, s_pageSetupData );
  359. }
  360. const BOX2I PL_EDITOR_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
  361. {
  362. BOX2I rv( VECTOR2I( 0, 0 ), GetPageLayout().GetPageSettings().GetSizeIU() );
  363. return rv;
  364. }
  365. void PL_EDITOR_FRAME::InstallPreferences( PAGED_DIALOG* aParent,
  366. PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
  367. {
  368. wxTreebook* book = aParent->GetTreebook();
  369. book->AddPage( new wxPanel( book ), _( "Worksheet Editor" ) );
  370. book->AddSubPage( new PANEL_GAL_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) );
  371. book->AddSubPage( new PANEL_PL_EDITOR_COLOR_SETTINGS( this, aParent->GetTreebook() ), _( "Colors" ) );
  372. aHotkeysPanel->AddHotKeys( GetToolManager() );
  373. }
  374. void PL_EDITOR_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  375. {
  376. EDA_DRAW_FRAME::LoadSettings( aCfg );
  377. if( aCfg->m_Window.grid.sizes.empty() )
  378. {
  379. aCfg->m_Window.grid.sizes = { "1.0 mm",
  380. "0.50 mm",
  381. "0.25 mm",
  382. "0.20 mm",
  383. "0.10 mm" };
  384. }
  385. // Currently values read from config file are not used because the user cannot
  386. // change this config
  387. // if( aCfg->m_Window.zoom_factors.empty() )
  388. {
  389. aCfg->m_Window.zoom_factors = { ZOOM_LIST_PL_EDITOR };
  390. }
  391. PL_EDITOR_SETTINGS* cfg = dynamic_cast<PL_EDITOR_SETTINGS*>( aCfg );
  392. wxCHECK( cfg, /*void*/ );
  393. m_propertiesFrameWidth = cfg->m_PropertiesFrameWidth;
  394. m_originSelectChoice = cfg->m_CornerOrigin;
  395. SetDrawBgColor( cfg->m_BlackBackground ? BLACK : WHITE );
  396. PAGE_INFO::SetCustomWidthMils( cfg->m_LastCustomWidth );
  397. PAGE_INFO::SetCustomHeightMils( cfg->m_LastCustomHeight );
  398. PAGE_INFO pageInfo = GetPageSettings();
  399. pageInfo.SetType( cfg->m_LastPaperSize, cfg->m_LastWasPortrait );
  400. SetPageSettings( pageInfo );
  401. }
  402. void PL_EDITOR_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  403. {
  404. EDA_DRAW_FRAME::SaveSettings( aCfg );
  405. auto cfg = static_cast<PL_EDITOR_SETTINGS*>( aCfg );
  406. m_propertiesFrameWidth = m_propertiesPagelayout->GetSize().x;
  407. cfg->m_PropertiesFrameWidth = m_propertiesFrameWidth;
  408. cfg->m_CornerOrigin = m_originSelectChoice;
  409. cfg->m_BlackBackground = GetDrawBgColor() == BLACK;
  410. cfg->m_LastPaperSize = GetPageSettings().GetType();
  411. cfg->m_LastWasPortrait = GetPageSettings().IsPortrait();
  412. cfg->m_LastCustomWidth = PAGE_INFO::GetCustomWidthMils();
  413. cfg->m_LastCustomHeight = PAGE_INFO::GetCustomHeightMils();
  414. }
  415. void PL_EDITOR_FRAME::UpdateTitleAndInfo()
  416. {
  417. wxString title;
  418. wxFileName file( GetCurrentFileName() );
  419. title.Printf( wxT( "%s \u2014 " ) + _( "Worksheet Editor" ),
  420. file.IsOk() ? file.GetName() : _( "no file selected" ) );
  421. SetTitle( title );
  422. }
  423. wxString PL_EDITOR_FRAME::GetCurrentFileName() const
  424. {
  425. return BASE_SCREEN::m_PageLayoutDescrFileName;
  426. }
  427. void PL_EDITOR_FRAME::SetCurrentFileName( const wxString& aName )
  428. {
  429. BASE_SCREEN::m_PageLayoutDescrFileName = aName;
  430. }
  431. void PL_EDITOR_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
  432. {
  433. m_pageLayout.SetPageSettings( aPageSettings );
  434. if( GetScreen() )
  435. GetScreen()->InitDataPoints( aPageSettings.GetSizeIU() );
  436. }
  437. const PAGE_INFO& PL_EDITOR_FRAME::GetPageSettings() const
  438. {
  439. return m_pageLayout.GetPageSettings();
  440. }
  441. const wxSize PL_EDITOR_FRAME::GetPageSizeIU() const
  442. {
  443. // this function is only needed because EDA_DRAW_FRAME is not compiled
  444. // with either -DPCBNEW or -DEESCHEMA, so the virtual is used to route
  445. // into an application specific source file.
  446. return m_pageLayout.GetPageSettings().GetSizeIU();
  447. }
  448. const TITLE_BLOCK& PL_EDITOR_FRAME::GetTitleBlock() const
  449. {
  450. return GetPageLayout().GetTitleBlock();
  451. }
  452. void PL_EDITOR_FRAME::SetTitleBlock( const TITLE_BLOCK& aTitleBlock )
  453. {
  454. m_pageLayout.SetTitleBlock( aTitleBlock );
  455. }
  456. void PL_EDITOR_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
  457. {
  458. EDA_DRAW_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
  459. SETTINGS_MANAGER& settingsManager = Pgm().GetSettingsManager();
  460. PL_EDITOR_SETTINGS* cfg = settingsManager.GetAppSettings<PL_EDITOR_SETTINGS>();
  461. COLOR_SETTINGS* colors = settingsManager.GetColorSettings( cfg->m_ColorTheme );
  462. GetCanvas()->GetView()->GetPainter()->GetSettings()->LoadColors( colors );
  463. GetCanvas()->GetView()->UpdateAllItems( KIGFX::COLOR );
  464. GetCanvas()->Refresh();
  465. RecreateToolbars();
  466. Layout();
  467. SendSizeEvent();
  468. }
  469. wxPoint PL_EDITOR_FRAME::ReturnCoordOriginCorner() const
  470. {
  471. // calculate the position (in page, in iu) of the corner used as coordinate origin
  472. // coordinate origin can be the paper Top Left corner, or each of 4 page corners
  473. wxPoint originCoord;
  474. // To avoid duplicate code, we use a dummy segment starting at 0,0 in relative coord
  475. WS_DATA_ITEM dummy( WS_DATA_ITEM::WS_SEGMENT );
  476. switch( m_originSelectChoice )
  477. {
  478. default:
  479. case 0: // Origin = paper Left Top corner
  480. break;
  481. case 1: // Origin = page Right Bottom corner
  482. dummy.SetStart( 0, 0, RB_CORNER );
  483. originCoord = dummy.GetStartPosUi();
  484. break;
  485. case 2: // Origin = page Left Bottom corner
  486. dummy.SetStart( 0, 0, LB_CORNER );
  487. originCoord = dummy.GetStartPosUi();
  488. break;
  489. case 3: // Origin = page Right Top corner
  490. dummy.SetStart( 0, 0, RT_CORNER );
  491. originCoord = dummy.GetStartPosUi();
  492. break;
  493. case 4: // Origin = page Left Top corner
  494. dummy.SetStart( 0, 0, LT_CORNER );
  495. originCoord = dummy.GetStartPosUi();
  496. break;
  497. }
  498. return originCoord;
  499. }
  500. /*
  501. * Display the grid status.
  502. */
  503. void PL_EDITOR_FRAME::DisplayGridMsg()
  504. {
  505. wxString line;
  506. wxString gridformatter;
  507. switch( m_userUnits )
  508. {
  509. case EDA_UNITS::INCHES: gridformatter = "grid %.3f"; break;
  510. case EDA_UNITS::MILLIMETRES: gridformatter = "grid %.4f"; break;
  511. default: gridformatter = "grid %f"; break;
  512. }
  513. double grid = To_User_Unit( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().x );
  514. line.Printf( gridformatter, grid );
  515. SetStatusText( line, 4 );
  516. }
  517. void PL_EDITOR_FRAME::UpdateStatusBar()
  518. {
  519. // Display Zoom level:
  520. SetStatusText( GetZoomLevelIndicator(), 1 );
  521. // coordinate origin can be the paper Top Left corner, or each of 4 page corners
  522. wxPoint originCoord = ReturnCoordOriginCorner();
  523. SetGridOrigin( originCoord );
  524. // We need the orientation of axis (sign of coordinates)
  525. int Xsign = 1;
  526. int Ysign = 1;
  527. switch( m_originSelectChoice )
  528. {
  529. default:
  530. case 0: // Origin = paper Left Top corner
  531. break;
  532. case 1: // Origin = page Right Bottom corner
  533. Xsign = -1;
  534. Ysign = -1;
  535. break;
  536. case 2: // Origin = page Left Bottom corner
  537. Ysign = -1;
  538. break;
  539. case 3: // Origin = page Right Top corner
  540. Xsign = -1;
  541. break;
  542. case 4: // Origin = page Left Top corner
  543. break;
  544. }
  545. // Display absolute coordinates:
  546. VECTOR2D cursorPos = GetCanvas()->GetViewControls()->GetCursorPosition();
  547. VECTOR2D coord = cursorPos - originCoord;
  548. double dXpos = To_User_Unit( GetUserUnits(), coord.x * Xsign );
  549. double dYpos = To_User_Unit( GetUserUnits(), coord.y * Ysign );
  550. wxString absformatter = wxT( "X %.4g Y %.4g" );
  551. wxString locformatter = wxT( "dx %.4g dy %.4g" );
  552. switch( GetUserUnits() )
  553. {
  554. case EDA_UNITS::INCHES: SetStatusText( _( "inches" ), 6 ); break;
  555. case EDA_UNITS::MILS: SetStatusText( _( "mils" ), 6 ); break;
  556. case EDA_UNITS::MILLIMETRES: SetStatusText( _( "mm" ), 6 ); break;
  557. case EDA_UNITS::UNSCALED: SetStatusText( wxEmptyString, 6 ); break;
  558. default: wxASSERT( false ); break;
  559. }
  560. wxString line;
  561. // Display abs coordinates
  562. line.Printf( absformatter, dXpos, dYpos );
  563. SetStatusText( line, 2 );
  564. // Display relative coordinates:
  565. if( GetScreen() )
  566. {
  567. double dx = cursorPos.x - GetScreen()->m_LocalOrigin.x;
  568. double dy = cursorPos.y - GetScreen()->m_LocalOrigin.y;
  569. dXpos = To_User_Unit( GetUserUnits(), dx * Xsign );
  570. dYpos = To_User_Unit( GetUserUnits(), dy * Ysign );
  571. line.Printf( locformatter, dXpos, dYpos );
  572. SetStatusText( line, 3 );
  573. }
  574. DisplayGridMsg();
  575. // Display corner reference for coord origin
  576. line.Printf( _("coord origin: %s"),
  577. m_originSelectBox->GetString( m_originSelectChoice ).GetData() );
  578. SetStatusText( line, 5 );
  579. // Display units
  580. }
  581. void PL_EDITOR_FRAME::PrintPage( const RENDER_SETTINGS* aSettings )
  582. {
  583. GetScreen()->SetVirtualPageNumber( GetPageNumberOption() ? 1 : 2 );
  584. WS_DATA_MODEL& model = WS_DATA_MODEL::GetTheInstance();
  585. for( WS_DATA_ITEM* dataItem : model.GetItems() )
  586. {
  587. // Ensure the scaling factor (used only in printing) of bitmaps is up to date
  588. if( dataItem->GetType() == WS_DATA_ITEM::WS_BITMAP )
  589. {
  590. BITMAP_BASE* bitmap = static_cast<WS_DATA_ITEM_BITMAP*>( dataItem )->m_ImageBitmap;
  591. bitmap->SetPixelSizeIu( IU_PER_MILS * 1000 / bitmap->GetPPI() );
  592. }
  593. }
  594. PrintWorkSheet( aSettings, GetScreen(), IU_PER_MILS, wxEmptyString );
  595. GetCanvas()->DisplayWorksheet();
  596. GetCanvas()->Refresh();
  597. }
  598. PL_DRAW_PANEL_GAL* PL_EDITOR_FRAME::GetCanvas() const
  599. {
  600. return static_cast<PL_DRAW_PANEL_GAL*>( EDA_DRAW_FRAME::GetCanvas() );
  601. }
  602. SELECTION& PL_EDITOR_FRAME::GetCurrentSelection()
  603. {
  604. return m_toolManager->GetTool<PL_SELECTION_TOOL>()->GetSelection();
  605. }
  606. void PL_EDITOR_FRAME::HardRedraw()
  607. {
  608. GetCanvas()->DisplayWorksheet();
  609. PL_SELECTION_TOOL* selTool = m_toolManager->GetTool<PL_SELECTION_TOOL>();
  610. PL_SELECTION& selection = selTool->GetSelection();
  611. WS_DATA_ITEM* item = nullptr;
  612. if( selection.GetSize() == 1 )
  613. item = static_cast<WS_DRAW_ITEM_BASE*>( selection.Front() )->GetPeer();
  614. m_propertiesPagelayout->CopyPrmsFromItemToPanel( item );
  615. m_propertiesPagelayout->CopyPrmsFromGeneralToPanel();
  616. GetCanvas()->Refresh();
  617. }
  618. WS_DATA_ITEM* PL_EDITOR_FRAME::AddPageLayoutItem( int aType )
  619. {
  620. WS_DATA_ITEM * item = NULL;
  621. switch( aType )
  622. {
  623. case WS_DATA_ITEM::WS_TEXT:
  624. item = new WS_DATA_ITEM_TEXT( wxT( "Text") );
  625. break;
  626. case WS_DATA_ITEM::WS_SEGMENT:
  627. item = new WS_DATA_ITEM( WS_DATA_ITEM::WS_SEGMENT );
  628. break;
  629. case WS_DATA_ITEM::WS_RECT:
  630. item = new WS_DATA_ITEM( WS_DATA_ITEM::WS_RECT );
  631. break;
  632. case WS_DATA_ITEM::WS_POLYPOLYGON:
  633. item = new WS_DATA_ITEM_POLYGONS();
  634. break;
  635. case WS_DATA_ITEM::WS_BITMAP:
  636. {
  637. wxFileDialog fileDlg( this, _( "Choose Image" ), wxEmptyString, wxEmptyString,
  638. _( "Image Files" ) + wxS( " " ) + wxImage::GetImageExtWildcard(),
  639. wxFD_OPEN );
  640. if( fileDlg.ShowModal() != wxID_OK )
  641. return NULL;
  642. wxString fullFilename = fileDlg.GetPath();
  643. if( !wxFileExists( fullFilename ) )
  644. {
  645. wxMessageBox( _( "Couldn't load image from \"%s\"" ), fullFilename );
  646. break;
  647. }
  648. BITMAP_BASE* image = new BITMAP_BASE();
  649. if( !image->ReadImageFile( fullFilename ) )
  650. {
  651. wxMessageBox( _( "Couldn't load image from \"%s\"" ), fullFilename );
  652. delete image;
  653. break;
  654. }
  655. // Set the scale factor for pl_editor (it is set for eeschema by default)
  656. image->SetPixelSizeIu( IU_PER_MILS * 1000.0 / image->GetPPI() );
  657. item = new WS_DATA_ITEM_BITMAP( image );
  658. }
  659. break;
  660. }
  661. if( item == NULL )
  662. return NULL;
  663. WS_DATA_MODEL::GetTheInstance().Append( item );
  664. item->SyncDrawItems( nullptr, GetCanvas()->GetView() );
  665. return item;
  666. }
  667. void PL_EDITOR_FRAME::OnNewPageLayout()
  668. {
  669. ClearUndoRedoList();
  670. GetScreen()->ClrModify();
  671. GetCanvas()->DisplayWorksheet();
  672. m_propertiesPagelayout->CopyPrmsFromItemToPanel( nullptr );
  673. m_propertiesPagelayout->CopyPrmsFromGeneralToPanel();
  674. UpdateTitleAndInfo();
  675. m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
  676. if( GetCurrentFileName().IsEmpty() )
  677. {
  678. // Default shutdown reason until a file is loaded
  679. KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New page layout file is unsaved" ) );
  680. }
  681. else
  682. {
  683. KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Page layout changes are unsaved" ) );
  684. }
  685. }
  686. void PL_EDITOR_FRAME::ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount )
  687. {
  688. if( aItemCount == 0 )
  689. return;
  690. UNDO_REDO_CONTAINER& list = whichList == UNDO_LIST ? m_undoList : m_redoList;
  691. unsigned icnt = list.m_CommandsList.size();
  692. if( aItemCount > 0 )
  693. icnt = aItemCount;
  694. for( unsigned ii = 0; ii < icnt; ii++ )
  695. {
  696. if( list.m_CommandsList.size() == 0 )
  697. break;
  698. PICKED_ITEMS_LIST* curr_cmd = list.m_CommandsList[0];
  699. list.m_CommandsList.erase( list.m_CommandsList.begin() );
  700. curr_cmd->ClearListAndDeleteItems();
  701. delete curr_cmd; // Delete command
  702. }
  703. }