kicad/include/pcb_base_frame.h

439 lines
15 KiB
C
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file pcb_base_frame.h
* @brief Classes used in Pcbnew, CvPcb and GerbView.
*/
2009-07-30 11:04:07 +00:00
#ifndef PCB_BASE_FRAME_H
#define PCB_BASE_FRAME_H
2009-07-30 11:04:07 +00:00
#include <eda_item.h>
#include <class_board.h>
#include <eda_draw_frame.h>
2020-10-15 23:33:18 +00:00
#include <outline_mode.h>
#include <lib_id.h>
#include <pcb_display_options.h>
#include <pcb_draw_panel_gal.h>
#include <pcb_origin_transforms.h>
#include <pcb_screen.h>
#include <richio.h>
#include <vector>
/* Forward declarations of classes. */
class APP_SETTINGS_BASE;
2009-07-30 11:04:07 +00:00
class BOARD;
class BOARD_CONNECTED_ITEM;
class COLOR_SETTINGS;
2009-07-30 11:04:07 +00:00
class MODULE;
class TRACK;
class D_PAD;
class EDA_3D_VIEWER;
2009-07-30 11:04:07 +00:00
class GENERAL_COLLECTOR;
class GENERAL_COLLECTORS_GUIDE;
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
class BOARD_DESIGN_SETTINGS;
2012-02-06 05:44:19 +00:00
class ZONE_SETTINGS;
class PCB_PLOT_PARAMS;
class FP_LIB_TABLE;
class PCBNEW_SETTINGS;
class FOOTPRINT_EDITOR_SETTINGS;
struct MAGNETIC_SETTINGS;
2009-07-30 11:04:07 +00:00
wxDECLARE_EVENT( BOARD_CHANGED, wxCommandEvent );
/**
* PCB_BASE_FRAME
* basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
*/
class PCB_BASE_FRAME : public EDA_DRAW_FRAME
2009-07-30 11:04:07 +00:00
{
protected:
2020-09-30 22:02:05 +00:00
BOARD* m_pcb;
PCB_DISPLAY_OPTIONS m_displayOptions;
PCB_ORIGIN_TRANSFORMS m_originTransforms;
PCBNEW_SETTINGS* m_settings; // No ownership, just a shortcut
2009-07-30 11:04:07 +00:00
2016-09-24 18:53:15 +00:00
virtual void unitsChangeRefresh() override;
/**
* Function loadFootprint
* attempts to load \a aFootprintId from the footprint library table.
*
* @param aFootprintId is the #LIB_ID of component footprint to load.
* @return the #MODULE if found or NULL if \a aFootprintId not found in any of the
* libraries in the table returned from #Prj().PcbFootprintLibs().
* @throw IO_ERROR if an I/O error occurs or a #PARSE_ERROR if a file parsing error
* occurs while reading footprint library files.
*/
MODULE* loadFootprint( const LIB_ID& aFootprintId );
2009-07-30 11:04:07 +00:00
public:
PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
* 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.
2014-03-20 00:42:08 +00:00
const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
long aStyle, const wxString& aFrameName );
2009-07-30 11:04:07 +00:00
~PCB_BASE_FRAME();
2009-07-30 11:04:07 +00:00
/**
* @return a reference to the child 3D viewer frame, when exists, or NULL
*/
EDA_3D_VIEWER* Get3DViewerFrame();
/**
* Update the 3D view, if the viewer is opened by this frame
* @param aTitle = the new title of the 3D frame, or nullptr
* to do not change the frame title
* @return false if the 3D view cannot be updated (because the
* owner of the viewer is not this frame)
*/
2019-06-02 14:34:19 +00:00
virtual void Update3DView( bool aForceReload, const wxString* aTitle = nullptr );
/**
* Request a redraw of 3D-Viewer canvas
*/
void Redraw3Dview();
/**
* Function LoadFootprint
* attempts to load \a aFootprintId from the footprint library table.
*
* @param aFootprintId is the #LIB_ID of component footprint to load.
* @return the #MODULE if found or NULL if \a aFootprintId not found in any of the
* libraries in table returned from #Prj().PcbFootprintLibs().
*/
MODULE* LoadFootprint( const LIB_ID& aFootprintId );
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
/**
* Function GetBoardBoundingBox
* calculates the bounding box containing all board items (or board edge segments).
* @param aBoardEdgesOnly is true if we are interested in board edge segments only.
* @return EDA_RECT - the board's bounding box
*/
EDA_RECT GetBoardBoundingBox( bool aBoardEdgesOnly = false ) const;
const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const override
{
/* "Zoom to Fit" calls this with "aIncludeAllVisible" as true. Since that
* feature always ignored the page and border, this function returns a bbox
* without them as well when passed true. This technically is not all things
* visible, but it keeps behavior consistent.
*
* When passed false, this function returns a bbox of just the board edge.
* This allows things like fabrication text or anything else outside the board
* edge to be ignored, and just zooms up to the board itself.
*
* Calling "GetBoardBoundingBox(true)" when edge cuts are turned off will return bbox of
* entire page and border, so we make sure to do "GetBoardBoundingBox(false)" instead.
*/
2020-09-30 22:02:05 +00:00
if( aIncludeAllVisible || ( !aIncludeAllVisible && !m_pcb->IsLayerVisible( Edge_Cuts ) ) )
return GetBoardBoundingBox( false );
else
return GetBoardBoundingBox( true );
}
2016-09-24 18:53:15 +00:00
virtual void SetPageSettings( const PAGE_INFO& aPageSettings ) override;
const PAGE_INFO& GetPageSettings() const override;
const wxSize GetPageSizeIU() const override;
2016-09-24 18:53:15 +00:00
const wxPoint& GetGridOrigin() const override;
void SetGridOrigin( const wxPoint& aPoint ) override;
const wxPoint& GetAuxOrigin() const;
const wxPoint GetUserOrigin() const;
/**
* Return a reference to the default ORIGIN_TRANSFORMS object
*/
ORIGIN_TRANSFORMS& GetOriginTransforms() override;
2016-09-24 18:53:15 +00:00
const TITLE_BLOCK& GetTitleBlock() const override;
void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) override;
/**
* Returns the BOARD_DESIGN_SETTINGS for the open project
* Overloaded in FOOTPRINT_EDIT_FRAME.
*/
virtual BOARD_DESIGN_SETTINGS& GetDesignSettings() const;
2012-02-06 05:44:19 +00:00
/**
* Helper to retrieve the current color settings
* @return a pointer to the active COLOR_SETTINGS
*/
virtual COLOR_SETTINGS* GetColorSettings() override
{
wxFAIL_MSG( "Color settings requested for a PCB_BASE_FRAME that does not override!" );
return nullptr;
}
2020-09-30 22:02:05 +00:00
PCBNEW_SETTINGS& Settings() { return *m_settings; }
void SetDrawBgColor( COLOR4D aColor ) override;
/**
* Function GetDisplayOptions
* Display options control the way tracks, vias, outlines and other things are shown
* (for instance solid or sketch mode)
*/
2020-09-30 22:02:05 +00:00
const PCB_DISPLAY_OPTIONS& GetDisplayOptions() const { return m_displayOptions; }
void SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions );
2012-02-06 05:44:19 +00:00
const ZONE_SETTINGS& GetZoneSettings() const;
void SetZoneSettings( const ZONE_SETTINGS& aSettings );
/**
* Function GetPlotSettings
* returns the PCB_PLOT_PARAMS for the BOARD owned by this frame.
* Overloaded in FOOTPRINT_EDIT_FRAME.
*/
virtual const PCB_PLOT_PARAMS& GetPlotSettings() const;
virtual void SetPlotSettings( const PCB_PLOT_PARAMS& aSettings );
2009-07-30 11:04:07 +00:00
/**
* Function SetBoard
* sets the m_Pcb member in such as way as to ensure deleting any previous
* BOARD.
* @param aBoard The BOARD to put into the frame.
*/
2013-11-25 15:50:03 +00:00
virtual void SetBoard( BOARD* aBoard );
2009-07-30 11:04:07 +00:00
BOARD* GetBoard() const
2009-07-30 11:04:07 +00:00
{
2020-09-30 22:02:05 +00:00
wxASSERT( m_pcb );
return m_pcb;
2009-07-30 11:04:07 +00:00
}
/**
* Function GetModel()
* @return the primary data model.
*/
virtual BOARD_ITEM_CONTAINER* GetModel() const = 0;
EDA_ITEM* GetItem( const KIID& aId ) override;
void FocusOnItem( BOARD_ITEM* aItem );
2009-07-30 11:04:07 +00:00
// General
virtual void ReCreateOptToolbar() override { }
virtual void ShowChangedLanguage() override;
2016-09-24 18:53:15 +00:00
virtual void ReCreateMenuBar() override;
virtual void UpdateStatusBar() override;
2009-11-23 20:18:47 +00:00
2016-09-25 17:06:49 +00:00
PCB_SCREEN* GetScreen() const override { return (PCB_SCREEN*) EDA_DRAW_FRAME::GetScreen(); }
2009-07-30 11:04:07 +00:00
/**
* Shows the 3D view frame.
* If it does not exist, it is created.
* If it exists, it is bring to the foreground
*/
2019-06-02 14:34:19 +00:00
EDA_3D_VIEWER* CreateAndShow3D_Frame();
2009-07-30 11:04:07 +00:00
/**
* Function GetCollectorsGuide
* @return GENERAL_COLLECTORS_GUIDE - that considers the global configuration options.
2009-07-30 11:04:07 +00:00
*/
GENERAL_COLLECTORS_GUIDE GetCollectorsGuide();
/**
* Function SelectLibrary
* puts up a dialog and allows the user to pick a library, for unspecified use.
*
* @param aNicknameExisting is the current choice to highlight
* @return wxString - the library or wxEmptyString on abort.
*/
wxString SelectLibrary( const wxString& aNicknameExisting );
/**
* Function GetFootprintFromBoardByReference
* @return a reference to the footprint found by its refence on the curent board. The
* reference is entered by the user from a dialog (by awxTextCtlr, or a list of
* available references)
*/
MODULE* GetFootprintFromBoardByReference();
2009-07-30 11:04:07 +00:00
2010-11-12 15:17:10 +00:00
/**
* Function OnModify
* Must be called after a change in order to set the "modify" flag of the current screen
* and update the date in frame reference.
* Do not forget to call this basic OnModify function to update info in derived OnModify
* functions.
*/
virtual void OnModify();
// footprints (footprints)
2010-11-12 15:17:10 +00:00
/**
* Function CreateNewModule
* Creates a new module or footprint, at position 0,0
* The new module contains only 2 texts: a reference and a value:
* Reference = REF**
* Value = "VAL**" or Footprint name in lib
* Note: they are dummy texts, which will be replaced by the actual texts
* when the fooprint is placed on a board and a netlist is read
* @param aModuleName = name of the new footprint in library
* @return a reference to the new module
2010-07-20 18:11:34 +00:00
*/
MODULE* CreateNewModule( const wxString& aModuleName );
/**
* Function PlaceModule
* places \a aModule at the current cursor position and updates module coordinates
* with the new position.
*
* @param aModule A MODULE object point of the module to be placed.
* @param aRecreateRatsnest A bool true redraws the module rats nest.
*/
void PlaceModule( MODULE* aModule, bool aRecreateRatsnest = true );
2009-07-30 11:04:07 +00:00
2020-10-14 23:37:26 +00:00
void ShowPadPropertiesDialog( D_PAD* aPad );
2009-11-23 20:18:47 +00:00
/**
* Function SelectFootprintFromLibTree
* opens a dialog to select a footprint.
*
* @param aPreslect = if valid, the LIB_ID to select (otherwise the global history is used)
*/
MODULE* SelectFootprintFromLibTree( LIB_ID aPreselect = LIB_ID() );
/**
* Adds the given module to the board.
* @param module
* @param aDC (can be NULL ) = the current Device Context, to draw the new footprint
*/
virtual void AddModuleToBoard( MODULE* module );
/**
* Function SelectFootprintFromLibBrowser
* launches the footprint viewer to select the name of a footprint to load.
*
* @return the selected footprint name or an empty string if no selection was made.
*/
wxString SelectFootprintFromLibBrowser();
2010-12-29 17:47:32 +00:00
/**
* Function Compile_Ratsnest
* Create the entire board ratsnest.
* Must be called after a board change (changes for
* pads, footprints or a read netlist ).
* @param aDC = the current device context (can be NULL)
* @param aDisplayStatus : if true, display the computation results
*/
2019-05-30 15:11:17 +00:00
void Compile_Ratsnest( bool aDisplayStatus );
2010-12-29 17:47:32 +00:00
2019-05-30 15:11:17 +00:00
/* Functions relative to Undo/redo commands: */
2010-11-12 15:17:10 +00:00
/**
* Function SaveCopyInUndoList (virtual pure)
2009-07-30 11:04:07 +00:00
* Creates a new entry in undo list of commands.
* add a picker to handle aItemToCopy
* @param aItemToCopy = the board item modified by the command to undo
2020-08-26 18:04:32 +00:00
* @param aTypeCommand = command type (see enum UNDO_REDO)
* @param aTransformPoint = the reference point of the transformation, for
* commands like move
2009-07-30 11:04:07 +00:00
*/
virtual void SaveCopyInUndoList( EDA_ITEM* aItemToCopy, UNDO_REDO aTypeCommand,
const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) = 0;
2009-07-30 11:04:07 +00:00
2010-11-12 15:17:10 +00:00
/**
* Function SaveCopyInUndoList (virtual pure, overloaded).
* Creates a new entry in undo list of commands.
* add a list of pickers to handle a list of items
* @param aItemsList = the list of items modified by the command to undo
2020-08-26 18:04:32 +00:00
* @param aTypeCommand = command type (see enum UNDO_REDO)
* @param aTransformPoint = the reference point of the transformation,
* for commands like move
*/
2020-08-26 18:04:32 +00:00
virtual void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, UNDO_REDO aTypeCommand,
const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) = 0;
2009-07-30 11:04:07 +00:00
/** Install the dialog box for layer selection
* @param aDefaultLayer = Preselection (NB_PCB_LAYERS for "(Deselect)" layer)
* @param aNotAllowedLayersMask = a layer mask for not allowed layers
* (= 0 to show all layers in use)
* @param aDlgPosition = position of dialog ( defualt = centered)
* @return the selected layer id
*/
PCB_LAYER_ID SelectLayer( PCB_LAYER_ID aDefaultLayer, LSET aNotAllowedLayersMask = LSET(),
wxPoint aDlgPosition = wxDefaultPosition );
virtual void SwitchLayer( wxDC* DC, PCB_LAYER_ID layer );
2009-07-30 11:04:07 +00:00
virtual void SetActiveLayer( PCB_LAYER_ID aLayer )
{
GetScreen()->m_Active_Layer = aLayer;
}
virtual PCB_LAYER_ID GetActiveLayer() const
{
return GetScreen()->m_Active_Layer;
}
int GetSeverity( int aErrorCode ) const override;
virtual void OnDisplayOptionsChanged() {}
void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
PCBNEW_SETTINGS* GetPcbNewSettings();
FOOTPRINT_EDITOR_SETTINGS* GetFootprintEditorSettings();
virtual MAGNETIC_SETTINGS* GetMagneticItemsSettings();
void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
virtual void OnUpdateLayerAlpha( wxUpdateUIEvent& aEvent ) {}
2019-05-24 13:55:33 +00:00
/**
* Function DisplayGridMsg()
*
* Display the current grid pane on the status bar.
*/
void DisplayGridMsg() override;
2019-05-24 13:55:33 +00:00
PCB_DRAW_PANEL_GAL* GetCanvas() const override;
///> @copydoc EDA_DRAW_FRAME::UseGalCanvas
virtual void ActivateGalCanvas() override;
/**
* Does nothing. Should be overriden in derived classes which support autozoom.
*/
virtual void SetAutoZoom( bool aAutoZoom ) {}
/**
* Always returns false. Should be overriden in derived classes which support autozoom.
*/
virtual bool GetAutoZoom() { return false; }
2009-07-30 11:04:07 +00:00
};
#endif // PCB_BASE_FRAME_H