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-2020 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 <kiway.h>
26 #include <view/view.h>
27 #include <tool/tool_manager.h>
28 #include <confirm.h>
29 #include <bitmaps.h>
33 
34 #include "pl_editor_frame.h"
35 #include "pl_editor_id.h"
36 #include "properties_frame.h"
37 #include "tools/pl_actions.h"
40 
41 
43 {
44  m_frame = getEditFrame<PL_EDITOR_FRAME>();
45  return true;
46 }
47 
48 
50 {
51  if( aReason == MODEL_RELOAD )
52  m_frame = getEditFrame<PL_EDITOR_FRAME>();
53 }
54 
55 
56 int PL_EDITOR_CONTROL::New( const TOOL_EVENT& aEvent )
57 {
58  wxCommandEvent evt( wxEVT_NULL, wxID_NEW );
59  m_frame->Files_io( evt );
60  return 0;
61 }
62 
63 
64 int PL_EDITOR_CONTROL::Open( const TOOL_EVENT& aEvent )
65 {
66  wxCommandEvent evt( wxEVT_NULL, wxID_OPEN );
67  m_frame->Files_io( evt );
68  return 0;
69 }
70 
71 
72 int PL_EDITOR_CONTROL::Save( const TOOL_EVENT& aEvent )
73 {
74  wxCommandEvent evt( wxEVT_NULL, wxID_SAVE );
75  m_frame->Files_io( evt );
76  return 0;
77 }
78 
79 
81 {
82  wxCommandEvent evt( wxEVT_NULL, wxID_SAVEAS );
83  m_frame->Files_io( evt );
84  return 0;
85 }
86 
87 
89 {
91 
94  dlg.EnableWksFileNamePicker( false );
95 
96  if( dlg.ShowModal() != wxID_OK )
97  {
98  // Nothing to roll back but we have to at least pop the stack
100  }
101  else
102  {
103  m_frame->HardRedraw();
104  }
105  return 0;
106 }
107 
108 
110 {
111  m_frame->ToPrinter( false );
112  return 0;
113 }
114 
115 
117 {
118  wxMessageBox( wxT( "Not yet available" ) );
119  return 0;
120 }
121 
122 
124 {
126  return 0;
127 }
128 
129 
131 {
132  if( aEvent.IsAction( &PL_ACTIONS::layoutEditMode ) )
134  else
136 
137  m_frame->HardRedraw();
138  return 0;
139 }
140 
141 
143 {
145  PL_SELECTION& selection = selTool->GetSelection();
146 
147  // The Properties frame will be updated. Avoid flicker during update:
148  m_frame->GetPropertiesFrame()->Freeze();
149 
150  if( selection.GetSize() == 1 )
151  {
152  EDA_ITEM* item = (EDA_ITEM*) selection.Front();
153 
154  MSG_PANEL_ITEMS msgItems;
155  item->GetMsgPanelInfo( m_frame, msgItems );
156  m_frame->SetMsgPanel( msgItems );
157 
158  DS_DATA_ITEM* dataItem = static_cast<DS_DRAW_ITEM_BASE*>( item )->GetPeer();
160  }
161  else
162  {
163  MSG_PANEL_ITEMS msgItems;
165  m_frame->SetMsgPanel( msgItems );
166 
168  }
169 
171 
172  // The Properties frame is updated. Reenable it:
173  m_frame->GetPropertiesFrame()->Thaw();
174 
175  return 0;
176 }
177 
178 
180 {
181  Go( &PL_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() );
182  Go( &PL_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() );
183  Go( &PL_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
185  Go( &PL_EDITOR_CONTROL::Print, ACTIONS::print.MakeEvent() );
186  Go( &PL_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );
187 
192 
197 }
void ToPrinter(bool doPreview)
Open a dialog frame to print layers.
PROPERTIES_FRAME * GetPropertiesFrame()
static const TOOL_EVENT SelectedEvent
Definition: actions.h:199
static TOOL_ACTION showInspector
Definition: pl_actions.h:72
void HardRedraw() override
Refresh the library tree and redraw the window.
static TOOL_ACTION layoutEditMode
Definition: pl_actions.h:68
Model changes (required full reload)
Definition: tool_base.h:80
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:200
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:214
void SetWksFileName(const wxString &aFilename)
static TOOL_ACTION print
Definition: actions.h:57
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
PL_SELECTION & GetSelection()
Return the set of currently selected items.
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:204
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:88
void setTransitions() override
< Set up handlers for various events.
int Save(const TOOL_EVENT &aEvent)
static DS_DATA_MODEL & GetTheInstance()
static function: returns the instance of DS_DATA_MODEL used in the application
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.
static TOOL_ACTION open
Definition: actions.h:50
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.
Definition: eda_item.h:214
static TOOL_ACTION save
Definition: actions.h:51
static TOOL_ACTION doNew
Definition: actions.h:44
Generic, UI-independent tool event.
Definition: tool_event.h:152
void ShowDesignInspector()
Show the dialog displaying the list of DS_DATA_ITEM items in the page layout.
static TOOL_ACTION previewSettings
Definition: pl_actions.h:73
static const TOOL_EVENT ClearedEvent
Selected item had a property changed (except movement)
Definition: actions.h:201
static TOOL_ACTION plot
Definition: actions.h:58
int PageSetup(const TOOL_EVENT &aEvent)
int Print(const TOOL_EVENT &aEvent)
int Plot(const TOOL_EVENT &aEvent)
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
int ShowInspector(const TOOL_EVENT &aEvent)
static TOOL_ACTION saveAs
Definition: actions.h:52
Drawing sheet structure type definitions.
Definition: ds_data_item.h:95
int TitleBlockDisplayMode(const TOOL_EVENT &aEvent)
int New(const TOOL_EVENT &aEvent)
#define IU_PER_MILS
Definition: plotter.cpp:137
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:97
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:77
void SaveCopyInUndoList()
Save a copy of the description (in a S expr string) for Undo/redo commands.
bool Init() override
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 CopyPrmsFromItemToPanel(DS_DATA_ITEM *aItem)
int Open(const TOOL_EVENT &aEvent)
static TOOL_ACTION layoutNormalMode
Definition: pl_actions.h:67
#define MAX_PAGE_SIZE_MILS
Definition: page_info.h:41
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
const PL_EDITOR_LAYOUT & GetPageLayout() const
void RollbackFromUndo()
Apply the last command in Undo List without stacking a Redo.
void Files_io(wxCommandEvent &event)