KiCad PCB EDA Suite
pl_editor_control.cpp
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) 2019 CERN
5  * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <fctsys.h>
26 #include <kiway.h>
27 #include <view/view.h>
28 #include <tool/tool_manager.h>
29 #include <tools/pl_actions.h>
32 #include <pl_editor_frame.h>
33 #include <ws_painter.h>
34 #include <confirm.h>
35 #include <bitmaps.h>
36 #include <properties_frame.h>
37 #include <pl_editor_id.h>
38 #include <dialog_page_settings.h>
39 
41 {
42  m_frame = getEditFrame<PL_EDITOR_FRAME>();
43  return true;
44 }
45 
46 
48 {
49  if( aReason == MODEL_RELOAD )
50  m_frame = getEditFrame<PL_EDITOR_FRAME>();
51 }
52 
53 
54 int PL_EDITOR_CONTROL::New( const TOOL_EVENT& aEvent )
55 {
56  wxCommandEvent evt( wxEVT_NULL, wxID_NEW );
57  m_frame->Files_io( evt );
58  return 0;
59 }
60 
61 
62 int PL_EDITOR_CONTROL::Open( const TOOL_EVENT& aEvent )
63 {
64  wxCommandEvent evt( wxEVT_NULL, wxID_OPEN );
65  m_frame->Files_io( evt );
66  return 0;
67 }
68 
69 
70 int PL_EDITOR_CONTROL::Save( const TOOL_EVENT& aEvent )
71 {
72  wxCommandEvent evt( wxEVT_NULL, wxID_SAVE );
73  m_frame->Files_io( evt );
74  return 0;
75 }
76 
77 
79 {
80  wxCommandEvent evt( wxEVT_NULL, wxID_SAVEAS );
81  m_frame->Files_io( evt );
82  return 0;
83 }
84 
85 
87 {
88  m_frame->SaveCopyInUndoList( true );
89 
92  dlg.EnableWksFileNamePicker( false );
93 
94  if( dlg.ShowModal() != wxID_OK )
95  {
96  // Nothing to roll back but we have to at least pop the stack
98  }
99  else
100  {
101  m_frame->HardRedraw();
102  }
103  return 0;
104 }
105 
106 
108 {
109  m_frame->ToPrinter( false );
110  return 0;
111 }
112 
113 
115 {
116  wxMessageBox( wxT( "Not yet available" ) );
117  return 0;
118 }
119 
120 
122 {
125 
127  m_frame->GetCanvas()->Refresh();
128 
129  return 0;
130 }
131 
132 
134 {
136  return 0;
137 }
138 
139 
141 {
143  PL_SELECTION& selection = selTool->GetSelection();
144 
145  // The Properties frame will be updated. Avoid flicker during update:
146  m_frame->GetPropertiesFrame()->Freeze();
147 
148  if( selection.GetSize() == 1 )
149  {
150  EDA_ITEM* item = (EDA_ITEM*) selection.Front();
151 
152  MSG_PANEL_ITEMS msgItems;
153  item->GetMsgPanelInfo( m_frame->GetUserUnits(), msgItems );
154  m_frame->SetMsgPanel( msgItems );
155 
156  WS_DATA_ITEM* dataItem = static_cast<WS_DRAW_ITEM_BASE*>( item )->GetPeer();
158  }
159  else
160  {
163  }
164 
166 
167  // The Properties frame is updated. Reenable it:
168  m_frame->GetPropertiesFrame()->Thaw();
169 
170  return 0;
171 }
172 
173 
175 {
176  Go( &PL_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() );
177  Go( &PL_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() );
178  Go( &PL_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
180  Go( &PL_EDITOR_CONTROL::Print, ACTIONS::print.MakeEvent() );
181  Go( &PL_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );
182 
186 
191 }
void SaveCopyInUndoList(bool aSavePageSettingsAndTitleBlock=false)
Save a copy of the description (in a S expr string) for Undo/redo commands.
void ToPrinter(bool doPreview)
Function ToPrinter Open a dialog frame to print layers.
PROPERTIES_FRAME * GetPropertiesFrame()
static const TOOL_EVENT SelectedEvent
Definition: actions.h:197
static TOOL_ACTION showInspector
Definition: pl_actions.h:76
void HardRedraw() override
Refresh the library tree and redraw the window.
PL_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
Work sheet structure type definitions.
Definition: ws_data_item.h:93
Model changes (required full reload)
Definition: tool_base.h:82
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:198
PL_EDITOR_FRAME * m_frame
This file is part of the common library.
int SaveAs(const TOOL_EVENT &aEvent)
const wxString & GetCurrFileName() const
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
void SetWksFileName(const wxString &aFilename)
virtual void SetDrawBgColor(COLOR4D aColor)
static TOOL_ACTION print
Definition: actions.h:60
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
PL_SELECTION & GetSelection()
Function GetSelection()
static const TOOL_EVENT SelectedItemsModified
Definition: actions.h:201
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
void setTransitions() override
Sets up handlers for various events.
int Save(const TOOL_EVENT &aEvent)
void EnableWksFileNamePicker(bool aEnable)
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void CopyPrmsFromItemToPanel(WS_DATA_ITEM *aItem)
static TOOL_ACTION open
Definition: actions.h:53
static TOOL_ACTION save
Definition: actions.h:54
static TOOL_ACTION doNew
Definition: actions.h:47
Class TOOL_EVENT.
Definition: tool_event.h:171
void ShowDesignInspector()
Show the dialog displaying the list of WS_DATA_ITEM items in the page layout.
static TOOL_ACTION previewSettings
Definition: pl_actions.h:77
virtual KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
static const TOOL_EVENT ClearedEvent
Definition: actions.h:199
static TOOL_ACTION plot
Definition: actions.h:61
virtual void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList)
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Definition: base_struct.h:328
virtual void ClearMsgPanel()
Clear all messages from the message panel.
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
int PageSetup(const TOOL_EVENT &aEvent)
static TOOL_ACTION toggleBackground
Definition: pl_actions.h:75
int Print(const TOOL_EVENT &aEvent)
int Plot(const TOOL_EVENT &aEvent)
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
int ShowInspector(const TOOL_EVENT &aEvent)
virtual void SetBackgroundColor(const COLOR4D &aColor)=0
Sets the background color.
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
static TOOL_ACTION saveAs
Definition: actions.h:55
int ToggleBackgroundColor(const TOOL_EVENT &aEvent)
int New(const TOOL_EVENT &aEvent)
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
Definition: colors.h:49
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
int UpdateMessagePanel(const TOOL_EVENT &aEvent)
Update the message panel and the Properties frame, after change (selection, move, edit ....
virtual COLOR4D GetDrawBgColor() const
void CopyPrmsFromGeneralToPanel()
int Open(const TOOL_EVENT &aEvent)
#define MAX_PAGE_SIZE_MILS
Definition: page_info.h:41
Definition: colors.h:45
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
void UpdateAllLayersColor()
Function UpdateAllLayersColor() Applies the new coloring scheme to all layers.
Definition: view.cpp:798
void RollbackFromUndo()
Apply the last command in Undo List without stacking a Redo.
void Files_io(wxCommandEvent &event)