KiCad PCB EDA Suite
footprint_edit_frame.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
25 #ifndef FOOTPRINT_EDIT_FRAME_H
26 #define FOOTPRINT_EDIT_FRAME_H
27 
28 #include <pcb_base_frame.h>
29 #include <pcb_base_edit_frame.h>
30 #include <io_mgr.h>
31 #include <config_params.h>
33 
34 class PCB_LAYER_WIDGET;
35 class FP_LIB_TABLE;
36 class EDGE_MODULE;
38 class LIB_MANAGER;
39 
40 namespace PCB { struct IFACE; } // A KIFACE_I coded in pcbnew.c
41 
42 
44 {
45  friend struct PCB::IFACE;
46 
49 
50  std::unique_ptr<MODULE> m_copiedModule;
51  std::unique_ptr<MODULE> m_revertModule;
53 
54 public:
55 
57 
63  static const wxChar* GetFootprintEditorFrameName();
64 
66  BOARD_ITEM_CONTAINER* GetModel() const override;
67 
68  bool IsCurrentFPFromBoard() const;
69 
70  BOARD_DESIGN_SETTINGS& GetDesignSettings() const override;
71  void SetDesignSettings( const BOARD_DESIGN_SETTINGS& aSettings ) override;
72 
73  const PCB_PLOT_PARAMS& GetPlotSettings() const override;
74  void SetPlotSettings( const PCB_PLOT_PARAMS& aSettings ) override;
75 
76  void LoadSettings( wxConfigBase* aCfg ) override;
77  void SaveSettings( wxConfigBase* aCfg ) override;
78 
79  double BestZoom() override;
80 
93 
94  void OnCloseWindow( wxCloseEvent& Event ) override;
95  void CloseModuleEditor( wxCommandEvent& Event );
96 
101  virtual void OnSwitchCanvas( wxCommandEvent& aEvent ) override;
102 
107  void UpdateUserInterface();
108 
109  void Process_Special_Functions( wxCommandEvent& event );
110 
111  void ProcessPreferences( wxCommandEvent& event );
112 
116  void RedrawActiveWindow( wxDC* DC, bool EraseBg ) override;
117 
121  void ReCreateHToolbar() override;
122 
123  void ReCreateVToolbar() override;
124  void ReCreateOptToolbar() override;
125  void OnLeftClick( wxDC* DC, const wxPoint& MousePos ) override;
126 
132  void OnLeftDClick( wxDC* DC, const wxPoint& MousePos ) override;
133 
139  bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) override;
140 
144  void ReCreateMenuBar() override;
145 
146  // The Tool Framework initalization, for GAL mode
147  void setupTools();
148 
149  void ToolOnRightClick( wxCommandEvent& event ) override;
150  void OnSelectOptionToolbar( wxCommandEvent& event );
151  void OnConfigurePaths( wxCommandEvent& aEvent );
152  void OnToggleSearchTree( wxCommandEvent& event );
153 
154  void OnSaveFootprintAsPng( wxCommandEvent& event );
155 
156  bool IsSearchTreeShown();
157 
164  bool SaveLibraryAs( const wxString& aLibraryPath );
165 
167  EDA_HOTKEY* GetHotKeyDescription( int aCommand ) const override;
168 
176  bool OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem = NULL ) override;
177 
178  BOARD_ITEM* PrepareItemForHotkey( bool failIfCurrentlyEdited );
179 
180  bool OnHotkeyEditItem( int aIdCommand );
181  bool OnHotkeyDeleteItem( int aIdCommand );
182  bool OnHotkeyMoveItem( int aIdCommand );
183  bool OnHotkeyMoveItemExact();
184  bool OnHotkeyRotateItem( int aIdCommand );
185  bool OnHotkeyDuplicateItem( int aIdCommand );
186 
190  void Show3D_Frame( wxCommandEvent& event ) override;
191 
192  bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ) override;
193  void OnVerticalToolbar( wxCommandEvent& aEvent );
194 
198  void OnUpdateSelectTool( wxUpdateUIEvent& aEvent );
199 
203  void OnUpdateVerticalToolbar( wxUpdateUIEvent& aEvent );
204 
205  void OnUpdateOptionsToolbar( wxUpdateUIEvent& aEvent );
206  void OnUpdateModuleSelected( wxUpdateUIEvent& aEvent );
207  void OnUpdateModuleTargeted( wxUpdateUIEvent& aEvent );
208  void OnUpdateSave( wxUpdateUIEvent& aEvent );
209  void OnUpdateSaveAs( wxUpdateUIEvent& aEvent );
210  void OnUpdateLoadModuleFromBoard( wxUpdateUIEvent& aEvent );
211  void OnUpdateInsertModuleInBoard( wxUpdateUIEvent& aEvent );
212 
214  void OnEditItemRequest( wxDC* aDC, BOARD_ITEM* aItem ) override;
215 
219  void LoadModuleFromBoard( wxCommandEvent& event );
220 
221  void LoadModuleFromLibrary( LIB_ID aFPID );
222 
227 
234  bool SaveFootprint( MODULE* aModule );
235  bool SaveFootprintAs( MODULE* aModule );
236  bool SaveFootprintToBoard( bool aAddNew );
237  bool RevertFootprint();
238 
245  virtual void OnModify() override;
246 
250  void ToPrinter( wxCommandEvent& event );
251 
252  // BOARD handling
253 
259  bool Clear_Pcb( bool aQuery );
260 
261  /* handlers for block commands */
262  virtual int BlockCommand( EDA_KEY key ) override;
263 
271  virtual void HandleBlockPlace( wxDC* DC ) override;
272 
282  virtual bool HandleBlockEnd( wxDC* DC ) override;
283 
284  BOARD_ITEM* ModeditLocateAndDisplay( int aHotKeyCode = 0 );
285 
287  LIB_ID getTargetFPID() const;
288 
290  LIB_ID GetLoadedFPID() const;
291 
292  void RemoveStruct( EDA_ITEM* Item );
293 
297  void Transform( MODULE* module, int transform );
298 
299  // importing / exporting Footprint
310  void Export_Module( MODULE* aModule );
311 
321  MODULE* Import_Module( const wxString& aName = wxT("") );
322 
329  bool Load_Module_From_BOARD( MODULE* Module );
330 
338 
339  // functions to edit footprint edges
340 
348  void Edit_Edge_Width( EDGE_MODULE* aEdge );
349 
356  void Edit_Edge_Layer( EDGE_MODULE* Edge );
357 
363  void Delete_Edge_Module( EDGE_MODULE* Edge );
364 
373  EDGE_MODULE* Begin_Edge_Module( EDGE_MODULE* Edge, wxDC* DC, STROKE_T type_edge );
374 
378  void End_Edge_Module( EDGE_MODULE* Edge );
379 
381  void Start_Move_EdgeMod( EDGE_MODULE* drawitem, wxDC* DC );
382 
384  void Place_EdgeMod( EDGE_MODULE* drawitem );
385 
392  void PushPadProperties( D_PAD* aPad );
393 
397  bool DeleteModuleFromLibrary( const LIB_ID& aFPID, bool aConfirm );
398 
408  bool IsElementVisible( GAL_LAYER_ID aElement ) const;
409 
417  void SetElementVisibility( GAL_LAYER_ID aElement, bool aNewState );
418 
422  virtual bool IsGridVisible() const override;
423 
429  virtual void SetGridVisibility( bool aVisible ) override;
430 
434  virtual COLOR4D GetGridColor() override;
435 
437  void SetActiveLayer( PCB_LAYER_ID aLayer ) override;
438 
440  void OnUpdateLayerAlpha( wxUpdateUIEvent& aEvent ) override;
441 
443  virtual void UseGalCanvas( bool aEnable ) override;
444 
458  bool OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl = 0 ) override;
459 
464  void AddModuleToBoard( MODULE* module ) override;
465 
469  void InstallPreferences( PAGED_DIALOG* aParent ) override;
470 
471  void ReFillLayerWidget();
472 
476  void ShowChangedLanguage() override;
477 
481  void CommonSettingsChanged() override;
482 
488  void SyncLibraryTree( bool aProgress );
489 
497  void UpdateMsgPanel() override;
498 
499  void KiwayMailIn( KIWAY_EXPRESS& mail ) override;
500 
501  DECLARE_EVENT_TABLE()
502 
503 protected:
504 
506  FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, EDA_DRAW_PANEL_GAL::GAL_TYPE aBackend );
507 
509 
512 
517  void initLibraryTree();
518 
522  void updateTitle();
523 
525  void updateView();
526 
527  void restoreLastFootprint();
528  void retainLastFootprint();
529 
536  TEXTE_MODULE* CreateTextModule( MODULE* aModule, wxDC* aDC );
537 
538 private:
539 
543  void editFootprintProperties( MODULE* aFootprint );
544 
545  bool saveFootprintInLibrary( MODULE* aModule, const wxString& aLibraryName );
546 
551  void moveExact();
552 
558  void duplicateItems( bool aIncrement ) override;
559 };
560 
561 #endif // FOOTPRINT_EDIT_FRAME_H
void OnUpdateVerticalToolbar(wxUpdateUIEvent &aEvent)
Handle most of tools og the vertical right toolbar ("Tools" toolbar)
void OnLeftDClick(wxDC *DC, const wxPoint &MousePos) override
Handle the double click in the footprint editor.
BOARD_ITEM * ModeditLocateAndDisplay(int aHotKeyCode=0)
PARAM_CFG_ARRAY m_configParams
List of footprint editor configuration parameters.
A list of parameters type.
Class KIWAY_EXPRESS carries a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition: kiway_express.h:39
void OnConfigurePaths(wxCommandEvent &aEvent)
LIB_TREE_MODEL_ADAPTER::PTR & GetLibTreeAdapter()
Returns the adapter object that provides the stored data.
void ReCreateHToolbar() override
Create the main horizontal toolbar for the footprint editor.
bool OnHotkeyRotateItem(int aIdCommand)
void OnUpdateLayerAlpha(wxUpdateUIEvent &aEvent) override
>
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
void SetActiveLayer(PCB_LAYER_ID aLayer) override
>
void RemoveStruct(EDA_ITEM *Item)
void OnVerticalToolbar(wxCommandEvent &aEvent)
EDA_HOTKEY * GetHotKeyDescription(int aCommand) const override
>
bool SaveFootprintToBoard(bool aAddNew)
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
virtual COLOR4D GetGridColor() override
Class PCB_LAYER_WIDGET is here to implement the abstract functions of LAYER_WIDGET so they may be tie...
virtual void OnSwitchCanvas(wxCommandEvent &aEvent) override
switches currently used canvas (default / Cairo / OpenGL).
void initLibraryTree()
Make sure the footprint info list is loaded (with a progress dialog) and then initialize the footprin...
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
Load a KiCad board (.kicad_pcb) from aFileName.
void InstallPreferences(PAGED_DIALOG *aParent) override
Allows Modedit to install its preferences panel into the preferences dialog.
bool OnHotkeyDuplicateItem(int aIdCommand)
PCB_LAYER_WIDGET * m_Layers
the layer manager
void LoadModuleFromLibrary(LIB_ID aFPID)
void OnCloseWindow(wxCloseEvent &Event) override
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
virtual void SetGridVisibility(bool aVisible) override
It may be overloaded by derived classes if you want to store/retrieve the grid visibility in configur...
The common library.
bool saveFootprintInLibrary(MODULE *aModule, const wxString &aLibraryName)
void UpdateUserInterface()
Update the layer manager and other widgets from the board setup (layer and items visibility, colors ...)
void duplicateItems(bool aIncrement) override
Duplicate the item under the cursor.
void OnToggleSearchTree(wxCommandEvent &event)
TEXTE_MODULE * CreateTextModule(MODULE *aModule, wxDC *aDC)
Creates a new text for the footprint.
Definition: edtxtmod.cpp:66
void CommonSettingsChanged() override
Called after the preferences dialog is run.
bool OnHotkeyMoveItem(int aIdCommand)
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
void OnUpdateLoadModuleFromBoard(wxUpdateUIEvent &aEvent)
void ReCreateOptToolbar() override
bool DeleteModuleFromLibrary(const LIB_ID &aFPID, bool aConfirm)
Delete the given module from its library.
virtual void UseGalCanvas(bool aEnable) override
>
Classes used in Pcbnew, CvPcb and GerbView.
MODULE * SelectFootprintFromBoard(BOARD *aPcb)
Display the list of modules currently existing on the BOARD.
void OnUpdateModuleTargeted(wxUpdateUIEvent &aEvent)
void Edit_Edge_Width(EDGE_MODULE *aEdge)
Change the width of module perimeter lines, EDGE_MODULEs.
Definition: edgemod.cpp:159
void ReCreateMenuBar() override
(Re)Create the menubar for the module editor frame
void SyncLibraryTree(bool aProgress)
Synchronize the footprint library tree to the current state of the footprint library table...
std::unique_ptr< MODULE > m_revertModule
void OnUpdateOptionsToolbar(wxUpdateUIEvent &aEvent)
PCB_LAYER_ID
A quick note on layer IDs:
bool Clear_Pcb(bool aQuery)
Delete all and reinitialize the current board.
Definition: initpcb.cpp:94
virtual bool IsGridVisible() const override
virtual void HandleBlockPlace(wxDC *DC) override
Handle the BLOCK PLACE command.
bool SaveLibraryAs(const wxString &aLibraryPath)
Save a library to a new name and/or library type.
void editFootprintProperties(MODULE *aFootprint)
Run the Footprint Properties dialog and handle changes made in it.
virtual void OnModify() override
Must be called after a footprint change in order to set the "modify" flag of the current screen and p...
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
void OnSelectOptionToolbar(wxCommandEvent &event)
void SetElementVisibility(GAL_LAYER_ID aElement, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
void Show3D_Frame(wxCommandEvent &event) override
Display 3D view of the footprint (module) being edited.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
bool Load_Module_From_BOARD(MODULE *Module)
Load in Modedit a footprint from the main board.
STROKE_T
Enum STROKE_T is the set of shapes for segments (graphic segments and tracks) which are often in the ...
uint32_t EDA_KEY
Definition: common.h:74
virtual int BlockCommand(EDA_KEY key) override
Return the block command code (BLOCK_MOVE, BLOCK_COPY...) corresponding to the keys pressed (ALT...
EDGE_MODULE * Begin_Edge_Module(EDGE_MODULE *Edge, wxDC *DC, STROKE_T type_edge)
Creates a new edge item (line, arc ..).
Definition: edgemod.cpp:294
void OnUpdateSelectTool(wxUpdateUIEvent &aEvent)
Handle ID_ZOOM_SELECTION and ID_NO_TOOL_SELECTED tools.
void ProcessPreferences(wxCommandEvent &event)
Footprint Editor pane with footprint library tree.
void moveExact()
Move the selected item exactly, popping up a dialog to allow the user the enter the move delta...
Class PCB_PLOT_PARAMS handles plot parameters and options when plotting/printing a board...
void RedrawActiveWindow(wxDC *DC, bool EraseBg) override
Draw the footprint editor BOARD, and others elements such as axis and grid.
void ToolOnRightClick(wxCommandEvent &event) override
const PCB_PLOT_PARAMS & GetPlotSettings() const override
Function GetPlotSettings returns the PCB_PLOT_PARAMS for the BOARD owned by this frame.
void Export_Module(MODULE *aModule)
Create a file containing only one footprint.
bool OnHotKey(wxDC *aDC, int aHotKey, const wxPoint &aPosition, EDA_ITEM *aItem=NULL) override
Handle hot key events.
Class to handle modifications to the symbol libraries.
Definition: lib_manager.h:49
bool SaveFootprintAs(MODULE *aModule)
double BestZoom() override
Function BestZoom.
void Process_Special_Functions(wxCommandEvent &event)
void SetDesignSettings(const BOARD_DESIGN_SETTINGS &aSettings) override
bool OnHotkeyEditItem(int aIdCommand)
void OnUpdateSaveAs(wxUpdateUIEvent &aEvent)
void updateTitle()
Updates window title according to getLibNickName().
void SaveSettings(wxConfigBase *aCfg) override
Function SaveSettings saves common frame parameters to a configuration data file. ...
void PushPadProperties(D_PAD *aPad)
Change pad characteristics for the given footprint or all footprints which look like the given footpr...
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
void SetPlotSettings(const PCB_PLOT_PARAMS &aSettings) override
void LoadModuleFromBoard(wxCommandEvent &event)
Called from the main toolbar to load a footprint from board mainly to edit it.
class EDA_HOTKEY is a class to handle hot key commands.
Definition: hotkeys_basic.h:59
Common, abstract interface for edit frames.
void UpdateMsgPanel() override
Redraw the message panel.
LIB_ID GetLoadedFPID() const
Return the LIB_ID of the part being edited.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:171
void Place_EdgeMod(EDGE_MODULE *drawitem)
Function to place a graphic item type EDGE_MODULE currently moved.
Definition: edgemod.cpp:77
PARAM_CFG_ARRAY & GetConfigurationSettings()
Return the footprint editor settings list.
void ToPrinter(wxCommandEvent &event)
Install the print dialog.
bool GeneralControl(wxDC *aDC, const wxPoint &aPosition, EDA_KEY aHotKey=0) override
Perform application specific control using aDC at aPosition in logical units.
void OnUpdateInsertModuleInBoard(wxUpdateUIEvent &aEvent)
BOARD_ITEM_CONTAINER * GetModel() const override
>
void updateView()
Reloads displayed items and sets view.
bool SaveFootprint(MODULE *aModule)
Save in an existing library a given footprint.
void Delete_Edge_Module(EDGE_MODULE *Edge)
Delete EDGE_MODULE ddge.
Definition: edgemod.cpp:244
FOOTPRINT_TREE_PANE * m_treePane
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
void End_Edge_Module(EDGE_MODULE *Edge)
Terminate a move or create edge function.
Definition: edgemod.cpp:391
void ShowChangedLanguage() override
Update visible items after a language change.
void OnUpdateSave(wxUpdateUIEvent &aEvent)
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > PTR
Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER_BASE.
void AddModuleToBoard(MODULE *module) override
Override from PCB_BASE_EDIT_FRAME which adds a module to the editor&#39;s dummy board, NOT to the user&#39;s PCB.
void CloseModuleEditor(wxCommandEvent &Event)
Abstract interface for BOARD_ITEMs capable of storing other items inside.
void OnEditItemRequest(wxDC *aDC, BOARD_ITEM *aItem) override
>
void OnUpdateModuleSelected(wxUpdateUIEvent &aEvent)
void Start_Move_EdgeMod(EDGE_MODULE *drawitem, wxDC *DC)
Function to initialize the move function params of a graphic item type DRAWSEGMENT.
Definition: edgemod.cpp:62
BOARD_ITEM * PrepareItemForHotkey(bool failIfCurrentlyEdited)
MODULE * Import_Module(const wxString &aName=wxT(""))
Read a file containing only one footprint.
LIB_ID getTargetFPID() const
Return the LIB_ID of the part selected in the footprint or the part being edited. ...
void Edit_Edge_Layer(EDGE_MODULE *Edge)
Change the EDGE_MODULE Edge layer, (The new layer will be asked) if Edge == NULL change the layer of ...
Definition: edgemod.cpp:186
void KiwayMailIn(KIWAY_EXPRESS &mail) override
Function KiwayMailIn receives KIWAY_EXPRESS messages from other players.
void OnLeftClick(wxDC *DC, const wxPoint &MousePos) override
static const wxChar * GetFootprintEditorFrameName()
Function GetFootprintEditorFrameName (static)
std::unique_ptr< MODULE > m_copiedModule
virtual bool HandleBlockEnd(wxDC *DC) override
Handle the "end" of a block command, i.e.
void Transform(MODULE *module, int transform)
Perform a geometric transform on the current footprint.
bool OnHotkeyDeleteItem(int aIdCommand)
void OnSaveFootprintAsPng(wxCommandEvent &event)
Class BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
bool OnRightClick(const wxPoint &MousePos, wxMenu *PopMenu) override
Handle the right mouse click in the footprint editor.
bool IsElementVisible(GAL_LAYER_ID aElement) const
Test whether a given element category is visible.