OpenASIP  2.0
EditTemplatesCmd.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 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 EditTemplatesCmd.cc
26  *
27  * Definition of EditTemplatesCmd class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <vector>
34 #include <wx/docview.h>
35 
36 #include "EditTemplatesCmd.hh"
37 #include "ProDeConstants.hh"
38 #include "TemplateListDialog.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 /**
50  * The Constructor.
51  */
53  EditorCommand(ProDeConstants::CMD_NAME_EDIT_TEMPLATES) {
54 }
55 
56 
57 /**
58  * The Destructor.
59  */
61 
62 
63 /**
64  * Executes the command.
65  *
66  * @return True, if the command was succesfully executed, false otherwise.
67  */
68 bool
70 
71  assert(parentWindow() != NULL);
72  assert(view() != NULL);
73 
74  Model* model = dynamic_cast<MDFDocument*>(
75  view()->GetDocument())->getModel();
76 
77  model->pushToStack();
78 
79  TemplateListDialog dialog(parentWindow(), model->getMachine());
80 
81  if (dialog.ShowModal() == wxID_OK) {
82  model->notifyObservers();
83  return true;
84  } else {
85  // Cancel button was pressed, templates are not modified.
86  model->popFromStack();
87  return false;
88  }
89 }
90 
91 
92 /**
93  * Returns id of this command.
94  *
95  * @return Id of this command.
96  */
97 int
100 }
101 
102 
103 /**
104  * Creates and returns a new instance of this command.
105  *
106  * @return A new instance of this command.
107  */
110  return new EditTemplatesCmd();
111 }
112 
113 
114 
115 /**
116  * Returns path to the command's icon file.
117  *
118  * @return path to the command's icon file.
119  */
120 string
123 }
124 
125 
126 /**
127  * Returns short version of the command name.
128  *
129  * @return Short version of the command name.
130  */
131 string
134 }
135 
136 
137 /**
138  * Returns true when the command is executable, false when not.
139  *
140  * This command is executable when a document is open.
141  *
142  * @return True, if a document is open.
143  */
144 bool
146  wxDocManager* manager = wxGetApp().docManager();
147  if (manager->GetCurrentView() != NULL) {
148  return true;
149  }
150  return false;
151 }
TemplateListDialog.hh
EditTemplatesCmd.hh
ProDe.hh
EditTemplatesCmd
Definition: EditTemplatesCmd.hh:43
MDFDocument.hh
EditTemplatesCmd::~EditTemplatesCmd
virtual ~EditTemplatesCmd()
Definition: EditTemplatesCmd.cc:60
EditTemplatesCmd::EditTemplatesCmd
EditTemplatesCmd()
Definition: EditTemplatesCmd.cc:52
EditTemplatesCmd::icon
virtual std::string icon() const
Definition: EditTemplatesCmd.cc:121
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
ProDeConstants::CMD_SNAME_EDIT_TEMPLATES
static const std::string CMD_SNAME_EDIT_TEMPLATES
Command name for the "Edit Templates" command.
Definition: ProDeConstants.hh:231
EditTemplatesCmd::id
virtual int id() const
Definition: EditTemplatesCmd.cc:98
Model::notifyObservers
void notifyObservers(bool modified=true)
Definition: Model.cc:152
assert
#define assert(condition)
Definition: Application.hh:86
EditTemplatesCmd::create
virtual EditTemplatesCmd * create() const
Definition: EditTemplatesCmd.cc:109
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
Model.hh
EditTemplatesCmd::shortName
virtual std::string shortName() const
Definition: EditTemplatesCmd.cc:132
ModelConstants.hh
Machine.hh
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
EditTemplatesCmd::isEnabled
virtual bool isEnabled()
Definition: EditTemplatesCmd.cc:145
ProDeConstants::CMD_ICON_EDIT_TEMPLATES
static const std::string CMD_ICON_EDIT_TEMPLATES
Icon location for the "Edit Templates" command.
Definition: ProDeConstants.hh:340
MDFDocument
Definition: MDFDocument.hh:51
ProDeConstants.hh
ProDeConstants::COMMAND_EDIT_TEMPLATES
@ COMMAND_EDIT_TEMPLATES
Definition: ProDeConstants.hh:441
Model
Definition: Model.hh:50
TemplateListDialog
Definition: TemplateListDialog.hh:50
EditorCommand
Definition: EditorCommand.hh:46
ProDeConstants
Definition: ProDeConstants.hh:43
EditTemplatesCmd::Do
virtual bool Do()
Definition: EditTemplatesCmd.cc:69
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
Model::getMachine
TTAMachine::Machine * getMachine()
Definition: Model.cc:88