OpenASIP  2.0
AddFUCmd.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 AddFUCmd.cc
26  *
27  * Definition of AddFUCmd class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30  */
31 
32 #include <wx/wx.h>
33 #include <wx/docview.h>
34 
35 #include "AddFUCmd.hh"
36 #include "FUDialog.hh"
37 #include "FunctionUnit.hh"
38 #include "Model.hh"
39 #include "ModelConstants.hh"
40 #include "MDFDocument.hh"
41 #include "ProDeConstants.hh"
42 #include "ProDe.hh"
43 #include "Machine.hh"
44 #include "Conversion.hh"
45 
46 using std::string;
47 using namespace TTAMachine;
48 
49 /**
50  * The Constructor.
51  */
53 }
54 
55 
56 
57 /**
58  * Executes the command.
59  *
60  * @return true, if the command was succesfully executed, false otherwise.
61  */
62 bool
64 
65  assert(parentWindow() != NULL);
66  assert(view() != NULL);
67 
68  Model* model = dynamic_cast<MDFDocument*>(
69  view()->GetDocument())->getModel();
70 
71  model->pushToStack();
72 
73  // Generate name for the new FU.
77  int i = 1;
78  while (navigator.hasItem(newName)) {
81  i++;
82  }
83 
84  FunctionUnit* functionUnit = new FunctionUnit(newName);
85  functionUnit->setMachine(*(model->getMachine()));
86 
87  FUDialog dialog(parentWindow(), functionUnit);
88 
89  if (dialog.ShowModal() == wxID_OK) {
90  model->notifyObservers();
91  return true;
92  } else {
93  // FU creation was cancelled
94  model->popFromStack();
95  return false;
96  }
97 }
98 
99 
100 /**
101  * Returns id of this command.
102  *
103  * @return ID for this command to be used in menus and toolbars.
104  */
105 int
106 AddFUCmd::id() const {
108 }
109 
110 
111 /**
112  * Creates and returns a new instance of this command.
113  *
114  * @return Newly created instance of this command.
115  */
116 AddFUCmd*
118  return new AddFUCmd();
119 }
120 
121 
122 /**
123  * Returns short version of the command name.
124  *
125  * @return Short name of the command to be used in the toolbar.
126  */
127 string
130 }
131 
132 
133 /**
134  * Returns true when the command is executable, false when not.
135  *
136  * This command is executable when a document is open.
137  *
138  * @return True, if a document is open.
139  */
140 bool
142  wxDocManager* manager = wxGetApp().docManager();
143  if (manager->GetCurrentView() != NULL) {
144  return true;
145  }
146  return false;
147 }
AddFUCmd::AddFUCmd
AddFUCmd()
Definition: AddFUCmd.cc:52
AddFUCmd::create
virtual AddFUCmd * create() const
Definition: AddFUCmd.cc:117
FUDialog
Definition: FUDialog.hh:48
ProDe.hh
ProDeConstants::CMD_SNAME_ADD_FU
static const std::string CMD_SNAME_ADD_FU
Command name for the "Add Function Unit" command.
Definition: ProDeConstants.hh:205
FUDialog.hh
MDFDocument.hh
AddFUCmd::id
virtual int id() const
Definition: AddFUCmd.cc:106
ProDeConstants::COMP_NEW_NAME_PREFIX_FU
static const std::string COMP_NEW_NAME_PREFIX_FU
Prefix for new function unit names.
Definition: ProDeConstants.hh:363
AddFUCmd::isEnabled
virtual bool isEnabled()
Definition: AddFUCmd.cc:141
ProDeConstants::COMMAND_ADD_FU
@ COMMAND_ADD_FU
Definition: ProDeConstants.hh:417
Conversion::toString
static std::string toString(const T &source)
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
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
AddFUCmd.hh
Conversion.hh
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
TTAMachine::Machine::Navigator::hasItem
bool hasItem(const std::string &name) const
Model.hh
TTAMachine::Machine::functionUnitNavigator
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition: Machine.cc:380
AddFUCmd::shortName
virtual std::string shortName() const
Definition: AddFUCmd.cc:128
ModelConstants.hh
Machine.hh
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
MDFDocument
Definition: MDFDocument.hh:51
ProDeConstants.hh
Model
Definition: Model.hh:50
TTAMachine::Unit::setMachine
virtual void setMachine(Machine &mach)
Definition: Unit.cc:253
EditorCommand
Definition: EditorCommand.hh:46
AddFUCmd::Do
virtual bool Do()
Definition: AddFUCmd.cc:63
ProDeConstants
Definition: ProDeConstants.hh:43
TTAMachine
Definition: Assembler.hh:48
AddFUCmd
Definition: AddFUCmd.hh:43
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
Model::getMachine
TTAMachine::Machine * getMachine()
Definition: Model.cc:88
FunctionUnit.hh