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.

1218 lines
38 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
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation, either version 3 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <kiface_base.h>
  21. #include <pgm_base.h>
  22. #include <eda_base_frame.h>
  23. #include <base_units.h>
  24. #include <bitmaps.h>
  25. #include <wildcards_and_files_ext.h>
  26. #include <gerbview.h>
  27. #include <gerbview_frame.h>
  28. #include <gerbview_id.h>
  29. #include <gerber_file_image.h>
  30. #include <gerber_file_image_list.h>
  31. #include <gerbview_draw_panel_gal.h>
  32. #include <gerbview_settings.h>
  33. #include <gal/graphics_abstraction_layer.h>
  34. #include <drawing_sheet/ds_proxy_view_item.h>
  35. #include <settings/common_settings.h>
  36. #include <settings/settings_manager.h>
  37. #include <tool/tool_manager.h>
  38. #include <tool/action_toolbar.h>
  39. #include <tool/tool_dispatcher.h>
  40. #include <tool/common_control.h>
  41. #include <tool/common_tools.h>
  42. #include <tool/editor_conditions.h>
  43. #include <tool/zoom_tool.h>
  44. #include <tools/gerbview_actions.h>
  45. #include <tools/gerbview_inspection_tool.h>
  46. #include <tools/gerbview_selection.h>
  47. #include <tools/gerbview_selection_tool.h>
  48. #include <tools/gerbview_control.h>
  49. #include <trigo.h>
  50. #include <view/view.h>
  51. #include <base_screen.h>
  52. #include <gerbview_painter.h>
  53. #include <widgets/msgpanel.h>
  54. #include <widgets/paged_dialog.h>
  55. #include <dialogs/panel_gerbview_settings.h>
  56. #include <dialogs/panel_gerbview_display_options.h>
  57. #include <dialogs/panel_gerbview_excellon_settings.h>
  58. #include <panel_hotkeys_editor.h>
  59. #include <wx/wupdlock.h>
  60. #include <wx/treebook.h>
  61. #include "widgets/gbr_layer_box_selector.h"
  62. #include "widgets/gerbview_layer_widget.h"
  63. #include "widgets/dcode_selection_box.h"
  64. #include <zoom_defines.h>
  65. GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent )
  66. : EDA_DRAW_FRAME( aKiway, aParent, FRAME_GERBER, wxT( "GerbView" ), wxDefaultPosition,
  67. wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, GERBVIEW_FRAME_NAME ),
  68. m_TextInfo( nullptr ),
  69. m_zipFileHistory( DEFAULT_FILE_HISTORY_SIZE, ID_GERBVIEW_ZIP_FILE1,
  70. ID_GERBVIEW_ZIP_FILE_LIST_CLEAR, _( "Clear Recent Zip Files" ) ),
  71. m_drillFileHistory( DEFAULT_FILE_HISTORY_SIZE, ID_GERBVIEW_DRILL_FILE1,
  72. ID_GERBVIEW_DRILL_FILE_LIST_CLEAR, _( "Clear Recent Drill Files" ) ),
  73. m_jobFileHistory( DEFAULT_FILE_HISTORY_SIZE, ID_GERBVIEW_JOB_FILE1,
  74. ID_GERBVIEW_JOB_FILE_LIST_CLEAR, _( "Clear Recent Job Files" ) ),
  75. m_activeLayer( 0 )
  76. {
  77. m_maximizeByDefault = true;
  78. m_gerberLayout = nullptr;
  79. m_show_layer_manager_tools = true;
  80. m_showBorderAndTitleBlock = false; // true for reference drawings.
  81. m_SelLayerBox = nullptr;
  82. m_DCodeSelector = nullptr;
  83. m_SelComponentBox = nullptr;
  84. m_SelNetnameBox = nullptr;
  85. m_SelAperAttributesBox = nullptr;
  86. m_cmpText = nullptr;
  87. m_netText = nullptr;
  88. m_apertText = nullptr;
  89. m_dcodeText = nullptr;
  90. m_displayMode = 0;
  91. m_aboutTitle = _( "KiCad Gerber Viewer" );
  92. SHAPE_POLY_SET dummy; // A ugly trick to force the linker to include
  93. // some methods in code and avoid link errors
  94. int fileHistorySize = Pgm().GetCommonSettings()->m_System.file_history_size;
  95. m_drillFileHistory.SetMaxFiles( fileHistorySize );
  96. m_zipFileHistory.SetMaxFiles( fileHistorySize );
  97. m_jobFileHistory.SetMaxFiles( fileHistorySize );
  98. auto* galCanvas = new GERBVIEW_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize,
  99. GetGalDisplayOptions(),
  100. EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE );
  101. SetCanvas( galCanvas );
  102. // GerbView requires draw priority for rendering negative objects
  103. galCanvas->GetView()->UseDrawPriority( true );
  104. // Give an icon
  105. wxIcon icon;
  106. wxIconBundle icon_bundle;
  107. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_gerbview ) );
  108. icon_bundle.AddIcon( icon );
  109. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_gerbview_32 ) );
  110. icon_bundle.AddIcon( icon );
  111. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_gerbview_16 ) );
  112. icon_bundle.AddIcon( icon );
  113. SetIcons( icon_bundle );
  114. // Be sure a page info is set. this default value will be overwritten later.
  115. PAGE_INFO pageInfo( wxT( "GERBER" ) );
  116. SetLayout( new GBR_LAYOUT() );
  117. SetPageSettings( pageInfo );
  118. SetVisibleLayers( LSET::AllLayersMask() ); // All draw layers visible.
  119. SetScreen( new BASE_SCREEN( GetPageSettings().GetSizeIU() ) );
  120. // Create the PCB_LAYER_WIDGET *after* SetLayout():
  121. m_LayersManager = new GERBER_LAYER_WIDGET( this, GetCanvas() );
  122. // Update the minimum string length in the layer panel with the length of the last default layer
  123. wxString lyrName = GetImagesList()->GetDisplayName( GetImagesList()->ImagesMaxCount(),
  124. false, true );
  125. m_LayersManager->SetSmallestLayerString( lyrName );
  126. // LoadSettings() *after* creating m_LayersManager, because LoadSettings()
  127. // initialize parameters in m_LayersManager
  128. LoadSettings( config() );
  129. setupTools();
  130. setupUIConditions();
  131. ReCreateMenuBar();
  132. ReCreateHToolbar();
  133. ReCreateOptToolbar();
  134. ReCreateAuxiliaryToolbar();
  135. m_auimgr.SetManagedWindow( this );
  136. m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer( 6 ) );
  137. m_auimgr.AddPane( m_auxiliaryToolBar, EDA_PANE().HToolbar().Name( "AuxToolbar" ).Top()
  138. .Layer(4) );
  139. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom()
  140. .Layer( 6 ) );
  141. m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" ).Left()
  142. .Layer( 3 ) );
  143. m_auimgr.AddPane( m_LayersManager, EDA_PANE().Palette().Name( "LayersManager" ).Right()
  144. .Layer( 3 ).Caption( _( "Layers Manager" ) ).PaneBorder( false )
  145. .MinSize( 80, -1 ).BestSize( m_LayersManager->GetBestSize() ) );
  146. m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
  147. ReFillLayerWidget(); // this is near end because contents establish size
  148. m_auimgr.Update();
  149. SetActiveLayer( 0, true );
  150. GetToolManager()->RunAction( ACTIONS::zoomFitScreen, false );
  151. resolveCanvasType();
  152. SwitchCanvas( m_canvasType );
  153. setupUnits( config() );
  154. // Enable the axes to match legacy draw style
  155. auto& galOptions = GetGalDisplayOptions();
  156. galOptions.m_axesEnabled = true;
  157. galOptions.NotifyChanged();
  158. m_LayersManager->ReFill();
  159. m_LayersManager->ReFillRender(); // Update colors in Render after the config is read
  160. GetToolManager()->RunAction( ACTIONS::zoomFitScreen, true );
  161. // Ensure the window is on top
  162. Raise();
  163. // Register a call to update the toolbar sizes. It can't be done immediately because
  164. // it seems to require some sizes calculated that aren't yet (at least on GTK).
  165. CallAfter( [&]()
  166. {
  167. // Ensure the controls on the toolbars all are correctly sized
  168. UpdateToolbarControlSizes();
  169. } );
  170. }
  171. GERBVIEW_FRAME::~GERBVIEW_FRAME()
  172. {
  173. // Ensure m_canvasType is up to date, to save it in config
  174. m_canvasType = GetCanvas()->GetBackend();
  175. // Shutdown all running tools
  176. if( m_toolManager )
  177. m_toolManager->ShutdownAllTools();
  178. GetCanvas()->GetView()->Clear();
  179. GetGerberLayout()->GetImagesList()->DeleteAllImages();
  180. delete m_gerberLayout;
  181. }
  182. void GERBVIEW_FRAME::doCloseWindow()
  183. {
  184. // No more vetos
  185. m_isClosing = true;
  186. GetCanvas()->StopDrawing();
  187. GetCanvas()->GetView()->Clear();
  188. if( m_toolManager )
  189. m_toolManager->DeactivateTool();
  190. // Be sure any OpenGL event cannot be fired after frame deletion:
  191. GetCanvas()->SetEvtHandlerEnabled( false );
  192. Destroy();
  193. }
  194. bool GERBVIEW_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
  195. {
  196. // Ensure the frame is shown when opening the file(s), to avoid issues (crash) on GAL
  197. // when trying to change the view if it is not fully initialized.
  198. // It happens when starting GerbView with a gerber job file to load
  199. if( !IsShown() )
  200. Show();
  201. // The current project path is also a valid command parameter. Check if a single path
  202. // rather than a file name was passed to GerbView and use it as the initial MRU path.
  203. if( aFileSet.size() > 0 )
  204. {
  205. wxString path = aFileSet[0];
  206. // For some reason wxApp appears to leave the trailing double quote on quoted
  207. // parameters which are required for paths with spaces. Maybe this should be
  208. // pushed back into PGM_SINGLE_TOP::OnPgmInit() but that may cause other issues.
  209. // We can't buy a break!
  210. if( path.Last() == wxChar( '\"' ) )
  211. path.RemoveLast();
  212. if( !wxFileExists( path ) && wxDirExists( path ) )
  213. {
  214. m_mruPath = path;
  215. return true;
  216. }
  217. const unsigned limit = std::min( unsigned( aFileSet.size() ),
  218. unsigned( GERBER_DRAWLAYERS_COUNT ) );
  219. int layer = 0;
  220. for( unsigned i = 0; i < limit; ++i, ++layer )
  221. {
  222. SetActiveLayer( layer );
  223. // Try to guess the type of file by its ext
  224. // if it is .drl (KiCad files), .nc or .xnc it is a drill file
  225. wxFileName fn( aFileSet[i] );
  226. wxString ext = fn.GetExt();
  227. if( ext == DrillFileExtension || // our Excellon format
  228. ext == "nc" || ext == "xnc" ) // alternate ext for Excellon format
  229. LoadExcellonFiles( aFileSet[i] );
  230. else if( ext == GerberJobFileExtension )
  231. LoadGerberJobFile( aFileSet[i] );
  232. else
  233. LoadGerberFiles( aFileSet[i] );
  234. }
  235. }
  236. Zoom_Automatique( true ); // Zoom fit in frame
  237. return true;
  238. }
  239. void GERBVIEW_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  240. {
  241. EDA_DRAW_FRAME::LoadSettings( aCfg );
  242. if( aCfg->m_Window.grid.sizes.empty() )
  243. {
  244. aCfg->m_Window.grid.sizes = { "100 mil",
  245. "50 mil",
  246. "25 mil",
  247. "20 mil",
  248. "10 mil",
  249. "5 mil",
  250. "2.5 mil",
  251. "2 mil",
  252. "1 mil",
  253. "0.5 mil",
  254. "0.2 mil",
  255. "0.1 mil",
  256. "5.0 mm",
  257. "2.5 mm",
  258. "1.0 mm",
  259. "0.5 mm",
  260. "0.25 mm",
  261. "0.2 mm",
  262. "0.1 mm",
  263. "0.05 mm",
  264. "0.025 mm",
  265. "0.01 mm" };
  266. }
  267. if( aCfg->m_Window.zoom_factors.empty() )
  268. {
  269. aCfg->m_Window.zoom_factors = { ZOOM_LIST_GERBVIEW };
  270. }
  271. GERBVIEW_SETTINGS* cfg = dynamic_cast<GERBVIEW_SETTINGS*>( aCfg );
  272. wxCHECK( cfg, /*void*/ );
  273. SetElementVisibility( LAYER_GERBVIEW_DRAWINGSHEET,
  274. cfg->m_Appearance.show_border_and_titleblock );
  275. PAGE_INFO pageInfo( wxT( "GERBER" ) );
  276. pageInfo.SetType( cfg->m_Appearance.page_type );
  277. SetPageSettings( pageInfo );
  278. SetElementVisibility( LAYER_DCODES, cfg->m_Appearance.show_dcodes );
  279. SetElementVisibility( LAYER_NEGATIVE_OBJECTS, cfg->m_Appearance.show_negative_objects );
  280. m_drillFileHistory.Load( cfg->m_DrillFileHistory );
  281. m_zipFileHistory.Load( cfg->m_ZipFileHistory );
  282. m_jobFileHistory.Load( cfg->m_JobFileHistory );
  283. }
  284. void GERBVIEW_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  285. {
  286. EDA_DRAW_FRAME::SaveSettings( aCfg );
  287. GERBVIEW_SETTINGS* cfg = dynamic_cast<GERBVIEW_SETTINGS*>( aCfg );
  288. wxCHECK( cfg, /*void*/ );
  289. cfg->m_Appearance.page_type = GetPageSettings().GetType();
  290. cfg->m_Appearance.show_border_and_titleblock = m_showBorderAndTitleBlock;
  291. cfg->m_Appearance.show_dcodes = IsElementVisible( LAYER_DCODES );
  292. cfg->m_Appearance.show_negative_objects = IsElementVisible( LAYER_NEGATIVE_OBJECTS );
  293. m_drillFileHistory.Save( &cfg->m_DrillFileHistory );
  294. m_zipFileHistory.Save( &cfg->m_ZipFileHistory );
  295. m_jobFileHistory.Save( &cfg->m_JobFileHistory );
  296. COLOR_SETTINGS* cs = Pgm().GetSettingsManager().GetColorSettings();
  297. Pgm().GetSettingsManager().SaveColorSettings( cs, "gerbview" );
  298. }
  299. void GERBVIEW_FRAME::ReFillLayerWidget()
  300. {
  301. wxWindowUpdateLocker no_update( m_LayersManager );
  302. m_LayersManager->ReFill();
  303. m_SelLayerBox->Resync();
  304. ReCreateAuxiliaryToolbar();
  305. wxAuiPaneInfo& lyrs = m_auimgr.GetPane( m_LayersManager );
  306. wxSize bestz = m_LayersManager->GetBestSize();
  307. bestz.x += 5; // gives a little margin
  308. lyrs.MinSize( bestz );
  309. lyrs.BestSize( bestz );
  310. lyrs.FloatingSize( bestz );
  311. if( lyrs.IsDocked() )
  312. m_auimgr.Update();
  313. else
  314. m_LayersManager->SetSize( bestz );
  315. syncLayerWidget();
  316. }
  317. void GERBVIEW_FRAME::SetElementVisibility( int aLayerID, bool aNewState )
  318. {
  319. bool dcodes_changed = false;
  320. switch( aLayerID )
  321. {
  322. case LAYER_DCODES:
  323. dcodes_changed = m_DisplayOptions.m_DisplayDCodes != aNewState;
  324. m_DisplayOptions.m_DisplayDCodes = aNewState;
  325. break;
  326. case LAYER_NEGATIVE_OBJECTS:
  327. {
  328. m_DisplayOptions.m_DisplayNegativeObjects = aNewState;
  329. auto view = GetCanvas()->GetView();
  330. view->UpdateAllItemsConditionally( KIGFX::REPAINT, []( KIGFX::VIEW_ITEM* aItem )
  331. {
  332. auto item = dynamic_cast<GERBER_DRAW_ITEM*>( aItem );
  333. // GetLayerPolarity() returns true for negative items
  334. return ( item && item->GetLayerPolarity() );
  335. } );
  336. break;
  337. }
  338. case LAYER_GERBVIEW_DRAWINGSHEET:
  339. m_showBorderAndTitleBlock = aNewState;
  340. // NOTE: LAYER_DRAWINGSHEET always used for visibility, but the layer manager passes
  341. // LAYER_GERBVIEW_DRAWINGSHEET because of independent color control
  342. GetCanvas()->GetView()->SetLayerVisible( LAYER_DRAWINGSHEET, aNewState );
  343. break;
  344. case LAYER_GERBVIEW_GRID:
  345. SetGridVisibility( aNewState );
  346. break;
  347. default:
  348. wxFAIL_MSG( wxString::Format( "GERBVIEW_FRAME::SetElementVisibility(): bad arg %d",
  349. aLayerID ) );
  350. }
  351. if( dcodes_changed )
  352. {
  353. auto view = GetCanvas()->GetView();
  354. for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; i++ )
  355. {
  356. int layer = GERBER_DRAW_LAYER( i );
  357. int dcode_layer = GERBER_DCODE_LAYER( layer );
  358. view->SetLayerVisible( dcode_layer, aNewState && view->IsLayerVisible( layer ) );
  359. }
  360. }
  361. applyDisplaySettingsToGAL();
  362. m_LayersManager->SetRenderState( aLayerID, aNewState );
  363. }
  364. void GERBVIEW_FRAME::applyDisplaySettingsToGAL()
  365. {
  366. auto painter = static_cast<KIGFX::GERBVIEW_PAINTER*>( GetCanvas()->GetView()->GetPainter() );
  367. KIGFX::GERBVIEW_RENDER_SETTINGS* settings = painter->GetSettings();
  368. settings->LoadDisplayOptions( m_DisplayOptions );
  369. settings->LoadColors( Pgm().GetSettingsManager().GetColorSettings() );
  370. GetCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
  371. }
  372. int GERBVIEW_FRAME::getNextAvailableLayer( int aLayer ) const
  373. {
  374. int layer = aLayer;
  375. for( unsigned i = 0; i < ImagesMaxCount(); ++i )
  376. {
  377. const GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
  378. if( gerber == nullptr ) // this graphic layer is available: use it
  379. return layer;
  380. ++layer; // try next graphic layer
  381. if( layer >= (int)ImagesMaxCount() )
  382. layer = 0;
  383. }
  384. return NO_AVAILABLE_LAYERS;
  385. }
  386. void GERBVIEW_FRAME::syncLayerWidget()
  387. {
  388. m_LayersManager->SelectLayer( GetActiveLayer() );
  389. }
  390. void GERBVIEW_FRAME::syncLayerBox( bool aRebuildLayerBox )
  391. {
  392. if( aRebuildLayerBox )
  393. m_SelLayerBox->Resync();
  394. m_SelLayerBox->SetSelection( GetActiveLayer() );
  395. int dcodeSelected = -1;
  396. GERBER_FILE_IMAGE* gerber = GetGbrImage( GetActiveLayer() );
  397. if( gerber )
  398. dcodeSelected = gerber->m_Selected_Tool;
  399. if( m_DCodeSelector )
  400. {
  401. updateDCodeSelectBox();
  402. m_DCodeSelector->SetDCodeSelection( dcodeSelected );
  403. m_DCodeSelector->Enable( gerber != nullptr );
  404. }
  405. }
  406. void GERBVIEW_FRAME::SortLayersByX2Attributes()
  407. {
  408. auto remapping = GetImagesList()->SortImagesByZOrder();
  409. ReFillLayerWidget();
  410. syncLayerBox( true );
  411. std::unordered_map<int, int> view_remapping;
  412. for( auto it : remapping )
  413. {
  414. view_remapping[ GERBER_DRAW_LAYER( it.first) ] = GERBER_DRAW_LAYER( it.second );
  415. view_remapping[ GERBER_DCODE_LAYER( GERBER_DRAW_LAYER( it.first) ) ] =
  416. GERBER_DCODE_LAYER( GERBER_DRAW_LAYER( it.second ) );
  417. }
  418. GetCanvas()->GetView()->ReorderLayerData( view_remapping );
  419. GetCanvas()->Refresh();
  420. }
  421. void GERBVIEW_FRAME::UpdateDiffLayers()
  422. {
  423. auto target = GetCanvas()->GetBackend() == GERBVIEW_DRAW_PANEL_GAL::GAL_TYPE::GAL_TYPE_OPENGL
  424. ? KIGFX::TARGET_CACHED
  425. : KIGFX::TARGET_NONCACHED;
  426. auto view = GetCanvas()->GetView();
  427. int lastVisibleLayer = -1;
  428. for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; i++ )
  429. {
  430. view->SetLayerDiff( GERBER_DRAW_LAYER( i ), m_DisplayOptions.m_DiffMode );
  431. // Caching doesn't work with layered rendering of diff'd layers
  432. view->SetLayerTarget( GERBER_DRAW_LAYER( i ),
  433. m_DisplayOptions.m_DiffMode ? KIGFX::TARGET_NONCACHED : target );
  434. //We want the last visible layer, but deprioritize the active layer unless it's the only layer
  435. if( ( lastVisibleLayer == -1 )
  436. || ( view->IsLayerVisible( GERBER_DRAW_LAYER( i ) ) && i != GetActiveLayer() ) )
  437. lastVisibleLayer = i;
  438. }
  439. //We don't want to diff the last visible layer onto the background, etc.
  440. if( lastVisibleLayer != -1 )
  441. {
  442. view->SetLayerTarget( GERBER_DRAW_LAYER( lastVisibleLayer ), target );
  443. view->SetLayerDiff( GERBER_DRAW_LAYER( lastVisibleLayer ), false );
  444. }
  445. view->RecacheAllItems();
  446. view->MarkDirty();
  447. view->UpdateAllItems( KIGFX::ALL );
  448. }
  449. void GERBVIEW_FRAME::UpdateDisplayOptions( const GBR_DISPLAY_OPTIONS& aOptions )
  450. {
  451. bool update_flashed = ( m_DisplayOptions.m_DisplayFlashedItemsFill !=
  452. aOptions.m_DisplayFlashedItemsFill );
  453. bool update_lines = ( m_DisplayOptions.m_DisplayLinesFill !=
  454. aOptions.m_DisplayLinesFill );
  455. bool update_polygons = ( m_DisplayOptions.m_DisplayPolygonsFill !=
  456. aOptions.m_DisplayPolygonsFill );
  457. bool update_diff_mode = ( m_DisplayOptions.m_DiffMode != aOptions.m_DiffMode );
  458. auto view = GetCanvas()->GetView();
  459. m_DisplayOptions = aOptions;
  460. applyDisplaySettingsToGAL();
  461. if( update_diff_mode )
  462. UpdateDiffLayers();
  463. if( update_flashed )
  464. {
  465. view->UpdateAllItemsConditionally( KIGFX::REPAINT, []( KIGFX::VIEW_ITEM* aItem )
  466. {
  467. auto item = static_cast<GERBER_DRAW_ITEM*>( aItem );
  468. switch( item->m_Shape )
  469. {
  470. case GBR_SPOT_CIRCLE:
  471. case GBR_SPOT_RECT:
  472. case GBR_SPOT_OVAL:
  473. case GBR_SPOT_POLY:
  474. case GBR_SPOT_MACRO:
  475. return true;
  476. default:
  477. return false;
  478. }
  479. } );
  480. }
  481. else if( update_lines )
  482. {
  483. view->UpdateAllItemsConditionally( KIGFX::REPAINT, []( KIGFX::VIEW_ITEM* aItem )
  484. {
  485. auto item = static_cast<GERBER_DRAW_ITEM*>( aItem );
  486. switch( item->m_Shape )
  487. {
  488. case GBR_CIRCLE:
  489. case GBR_ARC:
  490. case GBR_SEGMENT:
  491. return true;
  492. default:
  493. return false;
  494. }
  495. } );
  496. }
  497. else if( update_polygons )
  498. {
  499. view->UpdateAllItemsConditionally( KIGFX::REPAINT, []( KIGFX::VIEW_ITEM* aItem )
  500. {
  501. auto item = static_cast<GERBER_DRAW_ITEM*>( aItem );
  502. return ( item->m_Shape == GBR_POLYGON );
  503. } );
  504. }
  505. view->UpdateAllItems( KIGFX::COLOR );
  506. GetCanvas()->Refresh();
  507. }
  508. void GERBVIEW_FRAME::UpdateTitleAndInfo()
  509. {
  510. GERBER_FILE_IMAGE* gerber = GetGbrImage( GetActiveLayer() );
  511. // Display the gerber filename
  512. if( gerber == nullptr )
  513. {
  514. SetTitle( _("Gerber Viewer") );
  515. SetStatusText( wxEmptyString, 0 );
  516. wxString info;
  517. info.Printf( _( "Drawing layer %d not in use" ), GetActiveLayer() + 1 );
  518. m_TextInfo->SetValue( info );
  519. if( KIUI::EnsureTextCtrlWidth( m_TextInfo, &info ) ) // Resized
  520. m_auimgr.Update();
  521. ClearMsgPanel();
  522. return;
  523. }
  524. else
  525. {
  526. wxString title;
  527. wxFileName filename( gerber->m_FileName );
  528. title = filename.GetFullName();
  529. if( gerber->m_IsX2_file )
  530. title += wxS( " " ) + _( "(with X2 attributes)" );
  531. title += wxT( " \u2014 " ) + _( "Gerber Viewer" );
  532. SetTitle( title );
  533. gerber->DisplayImageInfo( this );
  534. // Display Image Name and Layer Name (from the current gerber data):
  535. wxString status;
  536. status.Printf( _( "Image name: \"%s\" Layer name: \"%s\"" ),
  537. gerber->m_ImageName,
  538. gerber->GetLayerParams().m_LayerName );
  539. SetStatusText( status, 0 );
  540. // Display data format like fmt in X3.4Y3.4 no LZ or fmt mm X2.3 Y3.5 no TZ in main toolbar
  541. wxString info;
  542. info.Printf( wxT( "fmt: %s X%d.%d Y%d.%d no %cZ" ),
  543. gerber->m_GerbMetric ? wxT( "mm" ) : wxT( "in" ),
  544. gerber->m_FmtLen.x - gerber->m_FmtScale.x,
  545. gerber->m_FmtScale.x,
  546. gerber->m_FmtLen.y - gerber->m_FmtScale.y,
  547. gerber->m_FmtScale.y,
  548. gerber->m_NoTrailingZeros ? 'T' : 'L' );
  549. if( gerber->m_IsX2_file )
  550. info << wxT(" ") << _( "X2 attr" );
  551. m_TextInfo->SetValue( info );
  552. if( KIUI::EnsureTextCtrlWidth( m_TextInfo, &info ) ) // Resized
  553. m_auimgr.Update();
  554. }
  555. }
  556. bool GERBVIEW_FRAME::IsElementVisible( int aLayerID ) const
  557. {
  558. switch( aLayerID )
  559. {
  560. case LAYER_DCODES: return m_DisplayOptions.m_DisplayDCodes;
  561. case LAYER_NEGATIVE_OBJECTS: return m_DisplayOptions.m_DisplayNegativeObjects;
  562. case LAYER_GERBVIEW_GRID: return IsGridVisible();
  563. case LAYER_GERBVIEW_DRAWINGSHEET: return m_showBorderAndTitleBlock;
  564. case LAYER_GERBVIEW_BACKGROUND: return true;
  565. default:
  566. wxFAIL_MSG( wxString::Format( "GERBVIEW_FRAME::IsElementVisible(): bad arg %d",
  567. aLayerID ) );
  568. }
  569. return true;
  570. }
  571. LSET GERBVIEW_FRAME::GetVisibleLayers() const
  572. {
  573. LSET visible = LSET::AllLayersMask();
  574. if( GetCanvas() )
  575. {
  576. for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; i++ )
  577. visible[i] = GetCanvas()->GetView()->IsLayerVisible( GERBER_DRAW_LAYER( i ) );
  578. }
  579. return visible;
  580. }
  581. void GERBVIEW_FRAME::SetVisibleLayers( LSET aLayerMask )
  582. {
  583. if( GetCanvas() )
  584. {
  585. for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; i++ )
  586. {
  587. bool v = aLayerMask[i];
  588. int layer = GERBER_DRAW_LAYER( i );
  589. GetCanvas()->GetView()->SetLayerVisible( layer, v );
  590. GetCanvas()->GetView()->SetLayerVisible( GERBER_DCODE_LAYER( layer ),
  591. m_DisplayOptions.m_DisplayDCodes && v );
  592. }
  593. }
  594. }
  595. bool GERBVIEW_FRAME::IsLayerVisible( int aLayer ) const
  596. {
  597. return m_LayersManager->IsLayerVisible( aLayer );
  598. }
  599. COLOR4D GERBVIEW_FRAME::GetVisibleElementColor( int aLayerID )
  600. {
  601. COLOR4D color = COLOR4D::UNSPECIFIED;
  602. COLOR_SETTINGS* settings = Pgm().GetSettingsManager().GetColorSettings();
  603. switch( aLayerID )
  604. {
  605. case LAYER_NEGATIVE_OBJECTS:
  606. case LAYER_DCODES:
  607. case LAYER_GERBVIEW_DRAWINGSHEET:
  608. case LAYER_GERBVIEW_BACKGROUND:
  609. color = settings->GetColor( aLayerID );
  610. break;
  611. case LAYER_GERBVIEW_GRID:
  612. color = GetGridColor();
  613. break;
  614. default:
  615. wxFAIL_MSG( wxString::Format( "GERBVIEW_FRAME::GetVisibleElementColor(): bad arg %d",
  616. aLayerID ) );
  617. }
  618. return color;
  619. }
  620. void GERBVIEW_FRAME::SetGridVisibility( bool aVisible )
  621. {
  622. EDA_DRAW_FRAME::SetGridVisibility( aVisible );
  623. m_LayersManager->SetRenderState( LAYER_GERBVIEW_GRID, aVisible );
  624. }
  625. void GERBVIEW_FRAME::SetVisibleElementColor( int aLayerID, const COLOR4D& aColor )
  626. {
  627. COLOR_SETTINGS* settings = Pgm().GetSettingsManager().GetColorSettings();
  628. switch( aLayerID )
  629. {
  630. case LAYER_NEGATIVE_OBJECTS:
  631. case LAYER_DCODES:
  632. settings->SetColor( aLayerID, aColor );
  633. break;
  634. case LAYER_GERBVIEW_DRAWINGSHEET:
  635. settings->SetColor( LAYER_GERBVIEW_DRAWINGSHEET, aColor );
  636. // LAYER_DRAWINGSHEET color is also used to draw the drawing-sheet
  637. // FIX ME: why LAYER_DRAWINGSHEET must be set, although LAYER_GERBVIEW_DRAWINGSHEET
  638. // is used to initialize the drawing-sheet color layer.
  639. settings->SetColor( LAYER_DRAWINGSHEET, aColor );
  640. break;
  641. case LAYER_GERBVIEW_GRID:
  642. SetGridColor( aColor );
  643. settings->SetColor( aLayerID, aColor );
  644. break;
  645. case LAYER_GERBVIEW_BACKGROUND:
  646. SetDrawBgColor( aColor );
  647. settings->SetColor( aLayerID, aColor );
  648. break;
  649. default:
  650. wxFAIL_MSG( wxString::Format( "GERBVIEW_FRAME::SetVisibleElementColor(): bad arg %d",
  651. aLayerID ) );
  652. }
  653. }
  654. COLOR4D GERBVIEW_FRAME::GetNegativeItemsColor()
  655. {
  656. if( IsElementVisible( LAYER_NEGATIVE_OBJECTS ) )
  657. return GetVisibleElementColor( LAYER_NEGATIVE_OBJECTS );
  658. else
  659. return GetDrawBgColor();
  660. }
  661. COLOR4D GERBVIEW_FRAME::GetLayerColor( int aLayer ) const
  662. {
  663. return Pgm().GetSettingsManager().GetColorSettings()->GetColor( aLayer );
  664. }
  665. void GERBVIEW_FRAME::SetLayerColor( int aLayer, const COLOR4D& aColor )
  666. {
  667. Pgm().GetSettingsManager().GetColorSettings()->SetColor( aLayer, aColor );
  668. applyDisplaySettingsToGAL();
  669. }
  670. void GERBVIEW_FRAME::SetActiveLayer( int aLayer, bool doLayerWidgetUpdate )
  671. {
  672. m_activeLayer = aLayer;
  673. if( m_DisplayOptions.m_DiffMode )
  674. UpdateDiffLayers();
  675. if( doLayerWidgetUpdate )
  676. m_LayersManager->SelectLayer( aLayer );
  677. UpdateTitleAndInfo();
  678. m_toolManager->RunAction( GERBVIEW_ACTIONS::layerChanged ); // notify other tools
  679. GetCanvas()->SetFocus(); // otherwise hotkeys are stuck somewhere
  680. GetCanvas()->SetHighContrastLayer( GERBER_DRAW_LAYER( aLayer ) );
  681. GetCanvas()->Refresh();
  682. }
  683. void GERBVIEW_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
  684. {
  685. m_paper = aPageSettings;
  686. if( GetScreen() )
  687. GetScreen()->InitDataPoints( aPageSettings.GetSizeIU() );
  688. GERBVIEW_DRAW_PANEL_GAL* drawPanel = static_cast<GERBVIEW_DRAW_PANEL_GAL*>( GetCanvas() );
  689. // Prepare drawing-sheet template
  690. DS_PROXY_VIEW_ITEM* drawingSheet = new DS_PROXY_VIEW_ITEM( IU_PER_MILS, &GetPageSettings(),
  691. &Prj(), &GetTitleBlock() );
  692. if( GetScreen() )
  693. {
  694. drawingSheet->SetPageNumber( "1" );
  695. drawingSheet->SetSheetCount( 1 );
  696. }
  697. drawingSheet->SetColorLayer( LAYER_GERBVIEW_DRAWINGSHEET );
  698. // Draw panel takes ownership of the drawing-sheet
  699. drawPanel->SetDrawingSheet( drawingSheet );
  700. }
  701. const PAGE_INFO& GERBVIEW_FRAME::GetPageSettings() const
  702. {
  703. return m_paper;
  704. }
  705. const wxSize GERBVIEW_FRAME::GetPageSizeIU() const
  706. {
  707. // this function is only needed because EDA_DRAW_FRAME is not compiled
  708. // with either -DPCBNEW or -DEESCHEMA, so the virtual is used to route
  709. // into an application specific source file.
  710. return GetPageSettings().GetSizeIU();
  711. }
  712. const TITLE_BLOCK& GERBVIEW_FRAME::GetTitleBlock() const
  713. {
  714. wxASSERT( m_gerberLayout );
  715. return m_gerberLayout->GetTitleBlock();
  716. }
  717. void GERBVIEW_FRAME::SetTitleBlock( const TITLE_BLOCK& aTitleBlock )
  718. {
  719. wxASSERT( m_gerberLayout );
  720. m_gerberLayout->SetTitleBlock( aTitleBlock );
  721. }
  722. COLOR4D GERBVIEW_FRAME::GetGridColor()
  723. {
  724. return Pgm().GetSettingsManager().GetColorSettings()->GetColor( LAYER_GRID );
  725. }
  726. void GERBVIEW_FRAME::SetGridColor( const COLOR4D& aColor )
  727. {
  728. Pgm().GetSettingsManager().GetColorSettings()->SetColor( LAYER_GRID, aColor );
  729. GetCanvas()->GetGAL()->SetGridColor( aColor );
  730. m_gridColor = aColor;
  731. }
  732. void GERBVIEW_FRAME::DisplayGridMsg()
  733. {
  734. VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize();
  735. wxString line;
  736. line.Printf( "grid X %s Y %s",
  737. MessageTextFromValue( m_userUnits, gridSize.x, false ),
  738. MessageTextFromValue( m_userUnits, gridSize.y, false ) );
  739. SetStatusText( line, 4 );
  740. SetStatusText( line, 4 );
  741. }
  742. void GERBVIEW_FRAME::UpdateStatusBar()
  743. {
  744. EDA_DRAW_FRAME::UpdateStatusBar();
  745. if( !GetScreen() )
  746. return;
  747. wxString line;
  748. VECTOR2D cursorPos = GetCanvas()->GetViewControls()->GetCursorPosition();
  749. if( GetShowPolarCoords() ) // display relative polar coordinates
  750. {
  751. double dx = cursorPos.x - GetScreen()->m_LocalOrigin.x;
  752. double dy = cursorPos.y - GetScreen()->m_LocalOrigin.y;
  753. double theta = RAD2DEG( atan2( -dy, dx ) );
  754. double ro = hypot( dx, dy );
  755. line.Printf( wxT( "r %s theta %s" ),
  756. MessageTextFromValue( GetUserUnits(), ro, false ),
  757. MessageTextFromValue( EDA_UNITS::DEGREES, theta, false ) );
  758. SetStatusText( line, 3 );
  759. }
  760. // Display absolute coordinates:
  761. line.Printf( wxT( "X %s Y %s" ),
  762. MessageTextFromValue( GetUserUnits(), cursorPos.x, false ),
  763. MessageTextFromValue( GetUserUnits(), cursorPos.y, false ) );
  764. SetStatusText( line, 2 );
  765. if( !GetShowPolarCoords() )
  766. {
  767. // Display relative cartesian coordinates:
  768. double dXpos = cursorPos.x - GetScreen()->m_LocalOrigin.x;
  769. double dYpos = cursorPos.y - GetScreen()->m_LocalOrigin.y;
  770. line.Printf( wxT( "dx %s dy %s dist %s" ),
  771. MessageTextFromValue( GetUserUnits(), dXpos, false ),
  772. MessageTextFromValue( GetUserUnits(), dYpos, false ),
  773. MessageTextFromValue( GetUserUnits(), hypot( dXpos, dYpos ), false ) );
  774. SetStatusText( line, 3 );
  775. }
  776. DisplayGridMsg();
  777. }
  778. GERBER_FILE_IMAGE* GERBVIEW_FRAME::GetGbrImage( int aIdx ) const
  779. {
  780. return m_gerberLayout->GetImagesList()->GetGbrImage( aIdx );
  781. }
  782. unsigned GERBVIEW_FRAME::ImagesMaxCount() const
  783. {
  784. return m_gerberLayout->GetImagesList()->ImagesMaxCount();
  785. }
  786. void GERBVIEW_FRAME::unitsChangeRefresh()
  787. {
  788. // Called on units change (see EDA_DRAW_FRAME)
  789. EDA_DRAW_FRAME::unitsChangeRefresh();
  790. updateDCodeSelectBox();
  791. UpdateGridSelectBox();
  792. }
  793. void GERBVIEW_FRAME::ActivateGalCanvas()
  794. {
  795. EDA_DRAW_FRAME::ActivateGalCanvas();
  796. EDA_DRAW_PANEL_GAL* galCanvas = GetCanvas();
  797. if( m_toolManager )
  798. {
  799. m_toolManager->SetEnvironment( m_gerberLayout, GetCanvas()->GetView(),
  800. GetCanvas()->GetViewControls(), config(), this );
  801. m_toolManager->ResetTools( TOOL_BASE::GAL_SWITCH );
  802. }
  803. galCanvas->GetGAL()->SetGridColor( GetLayerColor( LAYER_GERBVIEW_GRID ) );
  804. SetPageSettings( GetPageSettings() );
  805. galCanvas->GetView()->RecacheAllItems();
  806. galCanvas->SetEventDispatcher( m_toolDispatcher );
  807. galCanvas->StartDrawing();
  808. m_LayersManager->ReFill();
  809. m_LayersManager->ReFillRender();
  810. ReCreateOptToolbar();
  811. ReCreateMenuBar();
  812. }
  813. void GERBVIEW_FRAME::InstallPreferences( PAGED_DIALOG* aParent,
  814. PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
  815. {
  816. wxTreebook* book = aParent->GetTreebook();
  817. book->AddPage( new wxPanel( book ), _( "GerbView" ) );
  818. book->AddSubPage( new PANEL_GERBVIEW_DISPLAY_OPTIONS( this, book ),
  819. _( "Display Options" ) );
  820. book->AddSubPage( new PANEL_GERBVIEW_SETTINGS( this, book ), _( "Editing Options" ) );
  821. book->AddSubPage( new PANEL_GERBVIEW_EXCELLON_SETTINGS( this, book ),
  822. _( "Excellon Options" ) );
  823. aHotkeysPanel->AddHotKeys( GetToolManager() );
  824. }
  825. void GERBVIEW_FRAME::setupTools()
  826. {
  827. // Create the manager and dispatcher & route draw panel events to the dispatcher
  828. m_toolManager = new TOOL_MANAGER;
  829. m_toolManager->SetEnvironment( m_gerberLayout, GetCanvas()->GetView(),
  830. GetCanvas()->GetViewControls(), config(), this );
  831. m_actions = new GERBVIEW_ACTIONS();
  832. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
  833. // Register tools
  834. m_toolManager->RegisterTool( new COMMON_CONTROL );
  835. m_toolManager->RegisterTool( new COMMON_TOOLS );
  836. m_toolManager->RegisterTool( new GERBVIEW_SELECTION_TOOL );
  837. m_toolManager->RegisterTool( new GERBVIEW_CONTROL );
  838. m_toolManager->RegisterTool( new GERBVIEW_INSPECTION_TOOL );
  839. m_toolManager->RegisterTool( new ZOOM_TOOL );
  840. m_toolManager->InitTools();
  841. // Run the selection tool, it is supposed to be always active
  842. m_toolManager->InvokeTool( "gerbview.InteractiveSelection" );
  843. }
  844. void GERBVIEW_FRAME::setupUIConditions()
  845. {
  846. EDA_DRAW_FRAME::setupUIConditions();
  847. ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
  848. EDITOR_CONDITIONS cond( this );
  849. wxASSERT( mgr );
  850. #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
  851. #define CHECK( x ) ACTION_CONDITIONS().Check( x )
  852. mgr->SetConditions( ACTIONS::zoomTool,
  853. CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) );
  854. mgr->SetConditions( ACTIONS::selectionTool,
  855. CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) );
  856. mgr->SetConditions( ACTIONS::measureTool,
  857. CHECK( cond.CurrentTool( ACTIONS::measureTool ) ) );
  858. mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) );
  859. mgr->SetConditions( ACTIONS::togglePolarCoords, CHECK( cond.PolarCoordinates() ) );
  860. mgr->SetConditions( ACTIONS::toggleCursorStyle, CHECK( cond.FullscreenCursor() ) );
  861. mgr->SetConditions( ACTIONS::millimetersUnits,
  862. CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) );
  863. mgr->SetConditions( ACTIONS::inchesUnits,
  864. CHECK( cond.Units( EDA_UNITS::INCHES ) ) );
  865. mgr->SetConditions( ACTIONS::milsUnits,
  866. CHECK( cond.Units( EDA_UNITS::MILS ) ) );
  867. auto flashedDisplayOutlinesCond =
  868. [this] ( const SELECTION& )
  869. {
  870. return !m_DisplayOptions.m_DisplayFlashedItemsFill;
  871. };
  872. auto linesFillCond =
  873. [this] ( const SELECTION& )
  874. {
  875. return !m_DisplayOptions.m_DisplayLinesFill;
  876. };
  877. auto polygonsFilledCond =
  878. [this] ( const SELECTION& )
  879. {
  880. return !m_DisplayOptions.m_DisplayPolygonsFill;
  881. };
  882. auto negativeObjectsCond =
  883. [this] ( const SELECTION& )
  884. {
  885. return IsElementVisible( LAYER_NEGATIVE_OBJECTS );
  886. };
  887. auto dcodeCond =
  888. [this] ( const SELECTION& )
  889. {
  890. return IsElementVisible( LAYER_DCODES );
  891. };
  892. auto diffModeCond =
  893. [this] ( const SELECTION& )
  894. {
  895. return m_DisplayOptions.m_DiffMode;
  896. };
  897. auto highContrastModeCond =
  898. [this] ( const SELECTION& )
  899. {
  900. return m_DisplayOptions.m_HighContrastMode;
  901. };
  902. auto flipGerberCond =
  903. [this] ( const SELECTION& )
  904. {
  905. return m_DisplayOptions.m_FlipGerberView;
  906. };
  907. auto layersManagerShownCondition =
  908. [this] ( const SELECTION& aSel )
  909. {
  910. return m_show_layer_manager_tools;
  911. };
  912. mgr->SetConditions( GERBVIEW_ACTIONS::flashedDisplayOutlines,
  913. CHECK( flashedDisplayOutlinesCond ) );
  914. mgr->SetConditions( GERBVIEW_ACTIONS::linesDisplayOutlines, CHECK( linesFillCond ) );
  915. mgr->SetConditions( GERBVIEW_ACTIONS::polygonsDisplayOutlines, CHECK( polygonsFilledCond ) );
  916. mgr->SetConditions( GERBVIEW_ACTIONS::negativeObjectDisplay, CHECK( negativeObjectsCond ) );
  917. mgr->SetConditions( GERBVIEW_ACTIONS::dcodeDisplay, CHECK( dcodeCond ) );
  918. mgr->SetConditions( GERBVIEW_ACTIONS::toggleDiffMode, CHECK( diffModeCond ) );
  919. mgr->SetConditions( GERBVIEW_ACTIONS::flipGerberView, CHECK( flipGerberCond ) );
  920. mgr->SetConditions( ACTIONS::highContrastMode, CHECK( highContrastModeCond ) );
  921. mgr->SetConditions( GERBVIEW_ACTIONS::toggleLayerManager,
  922. CHECK( layersManagerShownCondition ) );
  923. #undef CHECK
  924. #undef ENABLE
  925. }
  926. void GERBVIEW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
  927. {
  928. EDA_DRAW_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
  929. RecreateToolbars();
  930. Layout();
  931. SendSizeEvent();
  932. }
  933. SELECTION& GERBVIEW_FRAME::GetCurrentSelection()
  934. {
  935. return m_toolManager->GetTool<GERBVIEW_SELECTION_TOOL>()->GetSelection();
  936. }
  937. void GERBVIEW_FRAME::ToggleLayerManager()
  938. {
  939. m_show_layer_manager_tools = !m_show_layer_manager_tools;
  940. // show/hide auxiliary Vertical layers and visibility manager toolbar
  941. m_auimgr.GetPane( "LayersManager" ).Show( m_show_layer_manager_tools );
  942. m_auimgr.Update();
  943. }