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.

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