59 #include <wx/snglinst.h> 62 #include <wx/dirdlg.h> 63 #include <wx/filedlg.h> 64 #include <wx/msgdlg.h> 65 #include <wx/socket.h> 67 #include <wx/snglinst.h> 68 #include <wx/fdrepdlg.h> 70 #define FR_HISTORY_LIST_CNT 10 81 const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
82 long aStyle, const wxString & aFrameName ) :
83 KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName )
85 m_socketServer =
nullptr;
86 m_mainToolBar =
nullptr;
87 m_drawToolBar =
nullptr;
88 m_optionsToolBar =
nullptr;
89 m_auxiliaryToolBar =
nullptr;
90 m_gridSelectBox =
nullptr;
91 m_zoomSelectBox =
nullptr;
92 m_firstRunDialogSetting = 0;
97 m_toolDispatcher =
nullptr;
98 m_messagePanel =
nullptr;
99 m_currentScreen =
nullptr;
100 m_showBorderAndTitleBlock =
false;
102 m_showPageLimits =
false;
105 m_colorSettings =
nullptr;
108 m_polarCoords =
false;
109 m_findReplaceData =
new wxFindReplaceData( wxFR_DOWN );
111 m_auimgr.SetFlags( wxAUI_MGR_DEFAULT );
113 CreateStatusBar( 8 );
117 wxWindow* stsbar = GetStatusBar();
135 KIUI::GetTextSize( wxT(
"dx 1234.1234 dy 1234.1234 dist 1234.1234" ), stsbar ).x + spacer,
150 SetStatusWidths(
arrayDim( dims ), dims );
154 GetClientSize( &m_frameSize.x, &m_frameSize.y );
155 m_framePos.x = m_framePos.y = 0;
156 m_frameSize.y -= m_msgFrameHeight;
158 m_messagePanel =
new EDA_MSG_PANEL(
this, -1, wxPoint( 0, m_frameSize.y ),
159 wxSize( m_frameSize.x, m_msgFrameHeight ) );
163 #if wxCHECK_VERSION( 3, 1, 3 ) 164 Bind( wxEVT_DPI_CHANGED,
165 [&]( wxDPIChangedEvent& )
220 wxRect rect = GetScreenRect();
221 wxPoint center = rect.GetPosition() + rect.GetSize() / 2;
231 if( !frame->IsVisible() )
235 if( frame->IsIconized() )
236 frame->Iconize(
false );
239 frame->SetPosition( center - frame->GetSize() / 2 );
244 frame->Show( !frame->IsVisible() );
245 frame->SetPosition( center - frame->GetSize() / 2 );
252 return frame && frame->IsVisible();
280 wxCommandEvent e( UNITS_CHANGED );
281 ProcessEventLocally( e );
322 wxArrayString gridsList;
326 for(
const wxString&
grid : gridsList )
344 idx = std::max( 0, std::min( idx, (
int)
m_gridSelectBox->GetCount() - 1 ) );
353 wxMessageBox( wxT(
"EDA_DRAW_FRAME::PrintPage() error") );
359 wxCHECK_RET(
m_gridSelectBox, wxT(
"m_gridSelectBox uninitialized" ) );
367 wxUpdateUIEvent
dummy;
374 wxUpdateUIEvent
dummy;
400 if( dlg.ShowModal() == wxID_OK )
451 if(
zoom == current )
459 wxCHECK_RET(
m_zoomSelectBox, wxT(
"m_zoomSelectBox uninitialized" ) );
483 wxSize clientSize = GetClientSize();
499 auto zoomMenu = std::make_shared<ZOOM_MENU>(
this );
500 zoomMenu->SetTool( commonTools );
503 auto gridMenu = std::make_shared<GRID_MENU>(
this );
504 gridMenu->SetTool( commonTools );
514 SetStatusText( msg, 6 );
520 SetStatusText( msg, 7 );
528 line.Printf( wxT(
"grid %s" ),
532 SetStatusText( line, 4 );
545 default: msg =
_(
"Units" );
break;
548 SetStatusText( msg, 5 );
693 wxCHECK_RET( aItem, wxT(
"Invalid EDA_ITEM pointer. Bad programmer." ) );
695 std::vector<MSG_PANEL_ITEM> items;
709 GetCanvas()->SetEvtHandlerEnabled(
true );
765 bool allow_save =
false;
767 for(
unsigned ii = 0; ii <
arrayDim( allowed_frames ); ii++ )
769 if(
m_ident == allowed_frames[ii] )
800 double xOffset = fmod( gridOrigin.x, gridSize.
x );
801 int x =
KiROUND( (aPosition.x - xOffset) / gridSize.
x );
802 double yOffset = fmod( gridOrigin.y, gridSize.
y );
803 int y =
KiROUND( (aPosition.y - yOffset) / gridSize.
y );
805 return wxPoint(
KiROUND( x * gridSize.
x + xOffset ),
KiROUND( y * gridSize.
y + yOffset ) );
814 double xOffset = fmod( gridOrigin.x, gridSize.
x );
815 int x =
KiROUND( (aPosition.x - xOffset) / gridSize.
x );
816 double yOffset = fmod( gridOrigin.y, gridSize.
y );
817 int y =
KiROUND( (aPosition.y - yOffset) / gridSize.
y );
819 return wxPoint(
KiROUND( x * gridSize.
x + xOffset ),
KiROUND( y * gridSize.
y + yOffset ) );
844 std::vector<wxWindow*> dialogs;
846 for( wxWindow* window : GetChildren() )
848 if( dynamic_cast<DIALOG_SHIM*>( window ) )
849 dialogs.push_back( window );
858 bool centerView =
false;
862 r.Inflate( - (
int)
r.GetWidth() / 10 );
864 if( !
r.Contains( aPos ) )
867 std::vector<BOX2D> dialogScreenRects;
871 dialogScreenRects.emplace_back(
GetCanvas()->ScreenToClient( dialog->GetScreenPosition() ),
876 for(
BOX2D rect : dialogScreenRects )
878 rect.Inflate( rect.GetWidth() / 10 );
880 if( rect.Contains(
GetCanvas()->GetView()->ToScreen( aPos ) ) )
890 catch(
const ClipperLib::clipperException& exc )
892 wxLogError( wxT(
"Clipper library error '%s' occurred centering object." ),
905 const wxString& aFullSheetName,
const wxString& aFileName,
907 const wxString& aPageNumber,
double aMils2Iu,
const PROJECT* aProject,
908 const wxString& aSheetLayer,
bool aIsFirstPage )
925 drawList.
Print( aSettings );
930 double aMils2Iu,
const wxString &aFilename,
931 const wxString &aSheetLayer )
937 wxPoint origin = DC->GetDeviceOrigin();
941 DC->SetDeviceOrigin( 0, 0 );
942 DC->SetAxisOrientation(
true,
false );
951 DC->SetDeviceOrigin( origin.x, origin.y );
952 DC->SetAxisOrientation(
true,
true );
960 return wxEmptyString;
965 const wxString& wildcard,
const wxString& ext,
966 bool isDirectory,
bool aIsGlobal,
967 const wxString& aGlobalPath )
969 wxString prompt = doOpen ?
_(
"Select Library" ) :
_(
"New Library" );
970 aFilename.SetExt( ext );
980 if( isDirectory && doOpen )
987 wxDirDialog dlg(
this, prompt, dir, wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
989 if( dlg.ShowModal() == wxID_CANCEL )
992 aFilename = dlg.GetPath();
993 aFilename.SetExt( ext );
998 if( aFilename.GetName().empty() )
999 aFilename.SetName( wxT(
"Library" ) );
1006 wxFileDialog dlg(
this, prompt, dir, aFilename.GetFullName(),
1007 wildcard, doOpen ? wxFD_OPEN | wxFD_FILE_MUST_EXIST
1008 : wxFD_SAVE | wxFD_CHANGE_DIR | wxFD_OVERWRITE_PROMPT );
1010 if( dlg.ShowModal() == wxID_CANCEL )
1013 aFilename = dlg.GetPath();
1014 aFilename.SetExt( ext );
1046 const_cast<EDA_DRAW_FRAME*>(
this )->m_colorSettings = colorSettings;
void DisplayConstraintsMsg(const wxString &msg)
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
virtual void ReCreateVToolbar()=0
void AddStandardSubMenus(TOOL_MENU &aMenu)
Construct a "basic" menu for a tool, containing only items that apply to all tools (e....
void SetIsFirstPage(bool aIsFirstPage)
Set if the page is the first page.
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
static TOOL_ACTION zoomPreset
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Return a pointer to the #VIEW_CONTROLS instance used in the panel.
Container for project specific data.
void SetMruPath(const wxString &aPath)
void SetMilsToIUfactor(double aMils2Iu)
Set the scalar to convert pages units (mils) to draw/plot units.
virtual const TITLE_BLOCK & GetTitleBlock() const =0
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
virtual void handleActivateEvent(wxActivateEvent &aEvent)
Handle a window activation event.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
std::vector< wxString > find_history
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Save common frame parameters to a configuration data file.
ACTION_TOOLBAR * m_auxiliaryToolBar
This file is part of the common library.
ACTION_TOOLBAR * m_optionsToolBar
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
virtual bool SwitchBackend(GAL_TYPE aGalType)
Switch method of rendering graphics.
void SetDefaultPenSize(int aPenSize)
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
static int GetRequiredHeight(wxWindow *aWindow)
Return the required height (in pixels) of a EDA_MSG_PANEL.
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory=false, bool aIsGlobal=false, const wxString &aGlobalPath=wxEmptyString)
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
int GetVirtualPageNumber() const
std::vector< wxSocketBase * > m_sockets
interprocess communication
static TOOL_ACTION zoomFitScreen
void OnMove(wxMoveEvent &aEvent) override
static TOOL_ACTION millimetersUnits
void RecreateToolbars()
Rebuild all toolbars, and update the checked state of check tools.
wxArrayString m_findStringHistoryList
void resolveCanvasType()
Determines the Canvas type to load (with prompt if required) and initializes m_canvasType.
void ReleaseFile()
Release the current file marked in use.
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
wxPoint GetNearestHalfGridPosition(const wxPoint &aPosition) const
Return the nearest aGridSize / 2 location to aPosition.
void UpdateZoomSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
ACTION_TOOLBAR * m_mainToolBar
void ScriptingConsoleEnableDisable()
Toggles the scripting console visibility.
wxPoint GetNearestGridPosition(const wxPoint &aPosition) const
Return the nearest aGridSize location to aPosition.
A panel to display various information messages.
Sentinel, do not use as a parameter.
The base class for create windows for drawing purpose.
#define DEFAULT_MAX_UNDO_ITEMS
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Hold the information shown in the lower right corner of a plot, printout, or editing view.
virtual const wxString GetProjectPath() const
Return the full path of the project.
wxChoice * m_gridSelectBox
virtual void LoadSettings()
std::unique_ptr< wxSingleInstanceChecker > m_file_checker
std::vector< double > zoom_factors
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
bool IsImperialUnit(EDA_UNITS aUnit)
Auxiliary rendering target (noncached)
This file contains miscellaneous commonly used macros and functions.
const wxString & GetPageNumber() const
void DisplayUnitsMsg()
Display current unit pane in the status bar.
EDA_DRAW_PANEL_GAL * m_canvas
This the frame's interface to setting GAL display options.
void Print(const RENDER_SETTINGS *aSettings)
Draws the item list created by BuildDrawItemsList.
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
void UpdateGridSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
wxString GetMruPath() const
virtual const PAGE_INFO & GetPageSettings() const =0
virtual void Zoom_Automatique(bool aWarpPointer)
Redraw the screen with best zoom level and the best centering that shows all the page or the board.
Stores the common settings that are saved and loaded for each window / frame.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
BASE_SCREEN * m_currentScreen
current used SCREEN
static TOOL_ACTION gridPreset
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
FIND_REPLACE m_FindReplace
wxArrayString m_replaceStringHistoryList
wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void OnSize(wxSizeEvent &aEvent)
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
bool IsGridVisible() const
void WriteConfig(WINDOW_SETTINGS &aCfg)
EDA_MSG_PANEL * m_messagePanel
GAL not used (the legacy wxDC engine is used)
virtual void OnSize(wxSizeEvent &event) override
Recalculate the size of toolbars and display panel when the frame size changes.
void OnUpdateSelectGrid(wxUpdateUIEvent &aEvent)
Update the checked item in the grid combobox.
void SetPageNumber(const wxString &aPageNumber)
Set the value of the sheet number.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
Describe the page size and margins of a paper page on which to eventually print or plot.
bool m_showBorderAndTitleBlock
static TOOL_ACTION inchesUnits
virtual void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Handles how to draw a screen (a board, a schematic ...)
wxChoice * m_zoomSelectBox
static TOOL_ACTION updatePreferences
void PrintDrawingSheet(const RENDER_SETTINGS *aSettings, const PAGE_INFO &aPageInfo, const wxString &aFullSheetName, const wxString &aFileName, const TITLE_BLOCK &aTitleBlock, int aSheetCount, const wxString &aPageNumber, double aMils2Iu, const PROJECT *aProject, const wxString &aSheetLayer, bool aIsFirstPage)
Print the border and title block.
virtual void PrintPage(const RENDER_SETTINGS *aSettings)
Print the page pointed by current screen, set by the calling print function.
std::vector< wxString > replace_history
virtual WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg)
Return a pointer to the window settings for this frame.
void ReadCommonConfig(COMMON_SETTINGS &aCommonSettings, wxWindow *aWindow)
Read GAL config options from the common config store.
Functions to provide common constants and other functions to assist in making a consistent UI.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
An interface for classes handling user events controlling the view behavior such as zooming,...
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
int GetMaxUndoItems() const
virtual KIGFX::VIEW * GetView() const
Return a pointer to the #VIEW instance used in the panel.
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
double GetZoomFactor() const
Get the zoom factor.
wxLogTrace helper definitions.
virtual void SetFocus() override
wxDC * GetPrintDC() const
virtual const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const
Returns bbox of document with option to not include some items.
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Move the graphic crosshair cursor to the requested position expressed in world coordinates.
virtual void ActivateGalCanvas()
Use to start up the GAL drawing canvas.
void PrintDrawingSheet(const RENDER_SETTINGS *aSettings, BASE_SCREEN *aScreen, double aMils2Iu, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString)
Prints the drawing-sheet (frame and title block).
#define FR_HISTORY_LIST_CNT
Maximum size of the find/replace history stacks.
virtual const wxPoint & GetGridOrigin() const =0
Return the absolute coordinates of the origin of the snap grid.
virtual void ClearMsgPanel()
Clear all messages from the message panel.
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
virtual void ResizeScreen(int aWidth, int aHeight)
Resize the canvas.
void StartDrawing()
Begin drawing if it was stopped previously.
virtual void ReCreateOptToolbar()=0
wxFont GetStatusFont(wxWindow *aWindow)
static TOOL_ACTION milsUnits
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
virtual void HardRedraw()
Rebuild the GAL and redraws the screen.
bool IsScriptingConsoleVisible()
Gets the current visibility of the scripting console window.
COLOR_SETTINGS * m_colorSettings
The current canvas type.
const wxString GetZoomLevelIndicator() const
Return a human readable value for display in dialogs.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
wxSocketServer * m_socketServer
void onActivate(wxActivateEvent &aEvent)
const VECTOR2D & GetGridSize() const
Return the grid size.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
EDA_DRAW_PANEL_GAL::GAL_TYPE loadCanvasTypeSetting()
Returns the canvas type stored in the application settings.
void BuildDrawItemsList(const PAGE_INFO &aPageInfo, const TITLE_BLOCK &aTitleBlock)
Drawing or plot the drawing sheet.
void SetAutoSaveInterval(int aInterval)
static TOOL_ACTION updateUnits
virtual void ReCreateHToolbar()=0
void OnSelectGrid(wxCommandEvent &event)
Command event handler for selecting grid sizes.
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
virtual void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Changes the current rendering backend.
KIGFX::GAL_DISPLAY_OPTIONS m_galDisplayOptions
Default display origin transforms object.
void setupUnits(APP_SETTINGS_BASE *aCfg)
std::vector< wxWindow * > findDialogs()
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
void SetProject(const PROJECT *aProject)
void ReadConfig(COMMON_SETTINGS &aCommonConfig, WINDOW_SETTINGS &aWindowConfig, wxWindow *aWindow)
Read application and common configs.
EDA_UNITS m_userUnits
Map containing the UI update handlers registered with wx for each action.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
A base class for most all the KiCad significant classes used in schematics and boards.
virtual void ReCreateAuxiliaryToolbar()
void SetGridVisibility(bool aVisibility)
Set the visibility setting of the grid.
wxFindReplaceData * m_findReplaceData
void SetSheetCount(int aSheetCount)
Set the value of the count of sheets, for basic inscriptions.
APP_SETTINGS_BASE * KifaceSettings() const
static TOOL_ACTION gridProperties
int GetDefaultPenWidth() const
Color settings are a bit different than most of the settings objects in that there can be more than o...
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
void SetUserUnits(EDA_UNITS aUnits)
void OnGridSettings(wxCommandEvent &event)
GAL_TYPE GetBackend() const
Return the type of backend currently used by GAL canvas.
void UpdateStatusBar() override
Update the status bar information.
virtual COLOR_SETTINGS * GetColorSettings() const
Returns a pointer to the active color theme settings.
EDA_MSG_PANEL items for displaying messages.
void AppendMessage(const wxString &aUpperText, const wxString &aLowerText, int aPadding=6)
Append a message to the message panel.
bool saveCanvasTypeSetting(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Stores the canvas type in the application settings.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
virtual void DisplayGridMsg()
Display current grid size in the status bar.
BASE_SCREEN class implementation.
Message panel definition file.
void FocusOnLocation(const wxPoint &aPos)
Useful to focus on a particular location, in find functions.
void ToggleUserUnits() override
virtual void SetGridVisibility(bool aVisible)
void GetUnitPair(EDA_UNITS &aPrimaryUnit, EDA_UNITS &aSecondaryUnits)
Get the pair or units in current use.
long m_firstRunDialogSetting
void MarkDirty()
Force redraw of view on the next rendering.
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
virtual void OnSelectZoom(wxCommandEvent &event)
Set the zoom factor when selected by the zoom list box in the main tool bar.
bool LockFile(const wxString &aFileName)
Mark a schematic file as being in use.
void DisplayToolMsg(const wxString &msg) override
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
virtual void UpdateMsgPanel()
Redraw the message panel.
virtual wxString GetScreenDesc() const
void AppendMsgPanel(const wxString &aTextUpper, const wxString &aTextLower, int aPadding=6)
Append a message to the message panel.
static const wxString productName
A color representation with 4 components: red, green, blue, alpha.
ACTION_TOOLBAR * m_drawToolBar