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.

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