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.

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