OpenASIP  2.0
EditOTAFormatsCmd.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2022 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file EditOTAFormatsCmd.cc
26  *
27  * Definition of EditOTAFormatsCmd class.
28  *
29  * @author Kari Hepola 2022
30  * @note rating: red
31  */
32 
33 #include <vector>
34 #include <wx/docview.h>
35 
36 #include "EditOTAFormatsCmd.hh"
37 #include "ProDeConstants.hh"
38 #include "OTAFormatListDialog.hh"
39 #include "ProDe.hh"
40 #include "Model.hh"
41 #include "MDFDocument.hh"
42 #include "Machine.hh"
43 #include "ModelConstants.hh"
44 
45 using std::string;
46 using std::vector;
47 
48 /**
49  * The Constructor.
50  */
52  : EditorCommand(ProDeConstants::CMD_NAME_EDIT_OTA_FORMATS) {}
53 
54 /**
55  * The Destructor.
56  */
58 
59 /**
60  * Executes the command.
61  *
62  * @return True, if the command was succesfully executed, false otherwise.
63  */
64 bool
66  assert(parentWindow() != NULL);
67  assert(view() != NULL);
68 
69  Model* model =
70  dynamic_cast<MDFDocument*>(view()->GetDocument())->getModel();
71 
72  model->pushToStack();
73 
74  OTAFormatListDialog dialog(parentWindow(), model->getMachine());
75 
76  if (dialog.ShowModal() == wxID_OK) {
77  model->notifyObservers();
78  return true;
79  } else {
80  // Cancel button was pressed, templates are not modified.
81  model->popFromStack();
82  return false;
83  }
84 }
85 
86 /**
87  * Returns id of this command.
88  *
89  * @return Id of this command.
90  */
91 int
94 }
95 
96 /**
97  * Creates and returns a new instance of this command.
98  *
99  * @return A new instance of this command.
100  */
103  return new EditOTAFormatsCmd();
104 }
105 
106 /**
107  * Returns path to the command's icon file.
108  *
109  * @return path to the command's icon file.
110  */
111 string
114 }
115 
116 /**
117  * Returns short version of the command name.
118  *
119  * @return Short version of the command name.
120  */
121 string
124 }
125 
126 /**
127  * Returns true when the command is executable, false when not.
128  *
129  * This command is executable when a document is open.
130  *
131  * @return True, if a document is open.
132  */
133 bool
135  wxDocManager* manager = wxGetApp().docManager();
136  if (manager->GetCurrentView() != NULL) {
137  return true;
138  }
139  return false;
140 }
ProDe.hh
ProDeConstants::COMMAND_EDIT_OTA_FORMATS
@ COMMAND_EDIT_OTA_FORMATS
Definition: ProDeConstants.hh:442
MDFDocument.hh
EditOTAFormatsCmd::EditOTAFormatsCmd
EditOTAFormatsCmd()
Definition: EditOTAFormatsCmd.cc:51
EditOTAFormatsCmd::Do
virtual bool Do()
Definition: EditOTAFormatsCmd.cc:65
EditOTAFormatsCmd::shortName
virtual std::string shortName() const
Definition: EditOTAFormatsCmd.cc:122
EditOTAFormatsCmd::id
virtual int id() const
Definition: EditOTAFormatsCmd.cc:92
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
Model::notifyObservers
void notifyObservers(bool modified=true)
Definition: Model.cc:152
assert
#define assert(condition)
Definition: Application.hh:86
OTAFormatListDialog
Definition: OTAFormatListDialog.hh:44
OTAFormatListDialog.hh
EditOTAFormatsCmd::icon
virtual std::string icon() const
Definition: EditOTAFormatsCmd.cc:112
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
EditOTAFormatsCmd
Definition: EditOTAFormatsCmd.hh:43
Model.hh
ModelConstants.hh
ProDeConstants::CMD_ICON_EDIT_OTA_FORMATS
static const std::string CMD_ICON_EDIT_OTA_FORMATS
Icon location for the "Edit OTA Formats" command.
Definition: ProDeConstants.hh:342
Machine.hh
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
MDFDocument
Definition: MDFDocument.hh:51
ProDeConstants.hh
EditOTAFormatsCmd.hh
Model
Definition: Model.hh:50
EditOTAFormatsCmd::create
virtual EditOTAFormatsCmd * create() const
Definition: EditOTAFormatsCmd.cc:102
EditorCommand
Definition: EditorCommand.hh:46
EditOTAFormatsCmd::~EditOTAFormatsCmd
virtual ~EditOTAFormatsCmd()
Definition: EditOTAFormatsCmd.cc:57
ProDeConstants
Definition: ProDeConstants.hh:43
EditOTAFormatsCmd::isEnabled
virtual bool isEnabled()
Definition: EditOTAFormatsCmd.cc:134
ProDeConstants::CMD_SNAME_EDIT_OTA_FORMATS
static const std::string CMD_SNAME_EDIT_OTA_FORMATS
Command name for the "Edit Templates" command.
Definition: ProDeConstants.hh:233
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
Model::getMachine
TTAMachine::Machine * getMachine()
Definition: Model.cc:88