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 #include <ws_data_model.h>
40 
42 {
43  m_frame = getEditFrame<PL_EDITOR_FRAME>();
44  return true;
45 }
46 
47 
49 {
50  if( aReason == MODEL_RELOAD )
51  m_frame = getEditFrame<PL_EDITOR_FRAME>();
52 }
53 
54 
55 int PL_EDITOR_CONTROL::New( const TOOL_EVENT& aEvent )
56 {
57  wxCommandEvent evt( wxEVT_NULL, wxID_NEW );
58  m_frame->Files_io( evt );
59  return 0;
60 }
61 
62 
63 int PL_EDITOR_CONTROL::Open( const TOOL_EVENT& aEvent )
64 {
65  wxCommandEvent evt( wxEVT_NULL, wxID_OPEN );
66  m_frame->Files_io( evt );
67  return 0;
68 }
69 
70 
71 int PL_EDITOR_CONTROL::Save( const TOOL_EVENT& aEvent )
72 {
73  wxCommandEvent evt( wxEVT_NULL, wxID_SAVE );
74  m_frame->Files_io( evt );
75  return 0;
76 }
77 
78 
80 {
81  wxCommandEvent evt( wxEVT_NULL, wxID_SAVEAS );
82  m_frame->Files_io( evt );
83  return 0;
84 }
85 
86 
88 {
90 
93  dlg.EnableWksFileNamePicker( false );
94 
95  if( dlg.ShowModal() != wxID_OK )
96  {
97  // Nothing to roll back but we have to at least pop the stack
99  }
100  else
101  {
102  m_frame->HardRedraw();
103  }
104  return 0;
105 }
106 
107 
109 {
110  m_frame->ToPrinter( false );
111  return 0;
112 }
113 
114 
116 {
117  wxMessageBox( wxT( "Not yet available" ) );
118  return 0;
119 }
120 
121 
123 {
125  return 0;
126 }
127 
128 
130 {
131  if( aEvent.IsAction( &PL_ACTIONS::layoutEditMode ) )
133  else
135 
136  m_frame->HardRedraw();
137  return 0;
138 }
139 
140 
142 {
144  PL_SELECTION& selection = selTool->GetSelection();
145 
146  // The Properties frame will be updated. Avoid flicker during update:
147  m_frame->GetPropertiesFrame()->Freeze();
148 
149  if( selection.GetSize() == 1 )
150  {
151  EDA_ITEM* item = (EDA_ITEM*) selection.Front();
152 
153  MSG_PANEL_ITEMS msgItems;
154  item->GetMsgPanelInfo( m_frame, msgItems );
155  m_frame->SetMsgPanel( msgItems );
156 
157  WS_DATA_ITEM* dataItem = static_cast<WS_DRAW_ITEM_BASE*>( item )->GetPeer();
159  }
160  else
161  {
164  }
165 
167 
168  // The Properties frame is updated. Reenable it:
169  m_frame->GetPropertiesFrame()->Thaw();
170 
171  return 0;
172 }
173 
174 
176 {
177  Go( &PL_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() );
178  Go( &PL_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() );
179  Go( &PL_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
181  Go( &PL_EDITOR_CONTROL::Print, ACTIONS::print.MakeEvent() );
182  Go( &PL_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );
183 
188 
193 }
void ToPrinter(bool doPreview)
Function ToPrinter Open a dialog frame to print layers.
PROPERTIES_FRAME * GetPropertiesFrame()
static const TOOL_EVENT SelectedEvent
Definition: actions.h:206
static TOOL_ACTION showInspector
Definition: pl_actions.h:78
void HardRedraw() override
Refresh the library tree and redraw the window.
Work sheet structure type definitions.
Definition: ws_data_item.h:93
static TOOL_ACTION layoutEditMode
Definition: pl_actions.h:74
Model changes (required full reload)
Definition: tool_base.h:82
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:207
PL_EDITOR_FRAME * m_frame
This file is part of the common library.
int SaveAs(const TOOL_EVENT &aEvent)
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
void SetWksFileName(const wxString &aFilename)
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:211
bool IsAction(const TOOL_ACTION *aAction) const
Function IsAction() Tests if the event contains an action issued upon activation of the given TOOL_AC...
Definition: tool_event.cpp:67
static WS_DATA_MODEL & GetTheInstance()
static function: returns the instance of WS_DATA_MODEL used in the application
void setTransitions() override
Sets up handlers for various events.
int Save(const TOOL_EVENT &aEvent)
wxString GetCurrentFileName() const override
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
virtual void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, 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:295
static TOOL_ACTION save
Definition: actions.h:54
static TOOL_ACTION doNew
Definition: actions.h:47
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:79
static const TOOL_EVENT ClearedEvent
Definition: actions.h:208
static TOOL_ACTION plot
Definition: actions.h:61
virtual void ClearMsgPanel()
Clear all messages from the message panel.
int PageSetup(const TOOL_EVENT &aEvent)
int Print(const TOOL_EVENT &aEvent)
int Plot(const TOOL_EVENT &aEvent)
int ShowInspector(const TOOL_EVENT &aEvent)
static TOOL_ACTION saveAs
Definition: actions.h:55
int TitleBlockDisplayMode(const TOOL_EVENT &aEvent)
int New(const TOOL_EVENT &aEvent)
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
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
void SaveCopyInUndoList()
Save a copy of the description (in a S expr string) for Undo/redo commands.
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 ....
void CopyPrmsFromGeneralToPanel()
int Open(const TOOL_EVENT &aEvent)
static TOOL_ACTION layoutNormalMode
Definition: pl_actions.h:73
#define MAX_PAGE_SIZE_MILS
Definition: page_info.h:41
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
void RollbackFromUndo()
Apply the last command in Undo List without stacking a Redo.
void Files_io(wxCommandEvent &event)