OpenASIP  2.0
AddIUCmd.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 AddIUCmd.cc
26  *
27  * Definition of AddIUCmd 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 "AddIUCmd.hh"
36 #include "IUDialog.hh"
37 #include "Model.hh"
38 #include "MDFDocument.hh"
39 #include "ModelConstants.hh"
40 #include "ProDeConstants.hh"
41 #include "ErrorDialog.hh"
42 #include "ProDe.hh"
43 #include "ImmediateUnit.hh"
44 #include "Conversion.hh"
45 
46 using std::string;
47 using namespace TTAMachine;
48 
49 /**
50  * The Constructor.
51  */
53  EditorCommand(ProDeConstants::CMD_NAME_ADD_IU) {
54 }
55 
56 
57 
58 /**
59  * Executes the command.
60  *
61  * @return true, if the command was succesfully executed, false otherwise.
62  */
63 bool
65 
66  assert(parentWindow() != NULL);
67  assert(view() != NULL);
68 
69 
70  Model* model =
71  dynamic_cast<MDFDocument*>(view()->GetDocument())->getModel();
72 
73  model->pushToStack();
74 
75  // Generate name for the new IU.
79  int i = 1;
80  while (navigator.hasItem(newName)) {
83  i++;
84  }
85 
86  ImmediateUnit* iu =
91  Machine::ZERO);
92 
93  iu->setMachine(*(model->getMachine()));
94 
95  IUDialog dialog(parentWindow(), iu);
96 
97  if (dialog.ShowModal() == wxID_OK) {
98  model->notifyObservers();
99  return true;
100  } else {
101  // immediate unit creation was cancelled
102  model->popFromStack();
103  return false;
104  }
105  return false;
106 }
107 
108 
109 /**
110  * Returns id of this command.
111  *
112  * @return ID for this command to be used in menus and toolbars.
113  */
114 int
115 AddIUCmd::id() const {
117 }
118 
119 
120 /**
121  * Creates and returns a new instance of this command.
122  *
123  * @return Newly created instance of this command.
124  */
125 AddIUCmd*
127  return new AddIUCmd();
128 }
129 
130 
131 /**
132  * Returns short version of the command name.
133  *
134  * @return Short name of the command to be used in the toolbar.
135  */
136 string
139 }
140 
141 
142 /**
143  * Returns true when the command is executable, false when not.
144  *
145  * This command is executable when a document is open.
146  *
147  * @return True, if a document is open.
148  */
149 bool
151  wxDocManager* manager = wxGetApp().docManager();
152  if (manager->GetCurrentView() != NULL) {
153  return true;
154  }
155  return false;
156 }
AddIUCmd::shortName
virtual std::string shortName() const
Definition: AddIUCmd.cc:137
ProDe.hh
ProDeConstants::COMMAND_ADD_IU
@ COMMAND_ADD_IU
Definition: ProDeConstants.hh:422
MDFDocument.hh
AddIUCmd::id
virtual int id() const
Definition: AddIUCmd.cc:115
ImmediateUnit.hh
ProDeConstants::CMD_SNAME_ADD_IU
static const std::string CMD_SNAME_ADD_IU
Command name for the "Add Immediate Unit" command.
Definition: ProDeConstants.hh:215
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
AddIUCmd::create
virtual AddIUCmd * create() const
Definition: AddIUCmd.cc:126
ModelConstants::DEFAULT_WIDTH
static const int DEFAULT_WIDTH
Default bit width.
Definition: ModelConstants.hh:46
AddIUCmd.hh
TTAMachine::Machine::immediateUnitNavigator
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition: Machine.cc:416
AddIUCmd::isEnabled
virtual bool isEnabled()
Definition: AddIUCmd.cc:150
ErrorDialog.hh
Conversion.hh
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
TTAMachine::Machine::Navigator::hasItem
bool hasItem(const std::string &name) const
ModelConstants::DEFAULT_IU_SIZE
static const int DEFAULT_IU_SIZE
Default immediate unit size.
Definition: ModelConstants.hh:56
Model.hh
ModelConstants.hh
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
MDFDocument
Definition: MDFDocument.hh:51
ProDeConstants.hh
IUDialog
Definition: IUDialog.hh:48
AddIUCmd
Definition: AddIUCmd.hh:43
ProDeConstants::COMP_NEW_NAME_PREFIX_IU
static const std::string COMP_NEW_NAME_PREFIX_IU
Prefix for new immediate unit names.
Definition: ProDeConstants.hh:367
Model
Definition: Model.hh:50
IUDialog.hh
ModelConstants::DEFAULT_IU_GUARD_LATENCY
static const int DEFAULT_IU_GUARD_LATENCY
Default local IU guard latency.
Definition: ModelConstants.hh:64
TTAMachine::Unit::setMachine
virtual void setMachine(Machine &mach)
Definition: Unit.cc:253
AddIUCmd::AddIUCmd
AddIUCmd()
Definition: AddIUCmd.cc:52
EditorCommand
Definition: EditorCommand.hh:46
ModelConstants::DEFAULT_IU_MAX_READS
static const int DEFAULT_IU_MAX_READS
Default maximum read ports of a immediate unit.
Definition: ModelConstants.hh:60
ProDeConstants
Definition: ProDeConstants.hh:43
TTAMachine
Definition: Assembler.hh:48
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
AddIUCmd::Do
virtual bool Do()
Definition: AddIUCmd.cc:64
TTAMachine::ImmediateUnit
Definition: ImmediateUnit.hh:50