OpenASIP  2.0
AddASCmd.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 AddASCmd.cc
26  *
27  * Definition of AddASCmd class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30  */
31 
32 #include <vector>
33 #include <wx/wx.h>
34 #include <wx/docview.h>
35 
36 #include "AddASCmd.hh"
37 #include "AddressSpaceDialog.hh"
38 #include "Model.hh"
39 #include "MDFDocument.hh"
40 #include "ProDeConstants.hh"
41 #include "ProDe.hh"
42 #include "Machine.hh"
43 #include "ModelConstants.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_AS) {
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  Model* model = dynamic_cast<MDFDocument*>(
70  view()->GetDocument())->getModel();
71 
72  model->pushToStack();
73 
74  // Generate name for the new AS.
77  int i = 1;
80  while (navigator.hasItem(newName)) {
83  i++;
84  }
85 
86  AddressSpace* addressSpace =
87  new AddressSpace(newName,
91  *model->getMachine());
92 
93 
94  AddressSpaceDialog dialog(parentWindow(), model->getMachine(),
95  addressSpace);
96 
97  if (dialog.ShowModal() == wxID_OK) {
98  model->notifyObservers();
99  return true;
100  } else {
101  // as creation was cancelled
102  model->popFromStack();
103  return false;
104  }
105 
106  return false;
107 }
108 
109 
110 /**
111  * Returns id of this command.
112  *
113  * @return ID for this command to be used in menus and toolbars.
114  */
115 int
116 AddASCmd::id() const {
118 }
119 
120 
121 /**
122  * Creates and returns a new instance of this command.
123  *
124  * @return Newly created instance of this command.
125  */
126 AddASCmd*
128  return new AddASCmd();
129 }
130 
131 
132 /**
133  * Returns short version of the command name.
134  *
135  * @return Short name of the command to be used in the toolbar.
136  */
137 string
140 }
141 
142 
143 /**
144  * Returns true when the command is executable, false when not.
145  *
146  * This command is executable when a document is open.
147  *
148  * @return True, if a document is open.
149  */
150 bool
152  wxDocManager* manager = wxGetApp().docManager();
153  if (manager->GetCurrentView() != NULL) {
154  return true;
155  }
156  return false;
157 }
AddASCmd::AddASCmd
AddASCmd()
Definition: AddASCmd.cc:52
AddASCmd::id
virtual int id() const
Definition: AddASCmd.cc:116
ProDe.hh
AddASCmd.hh
MDFDocument.hh
TTAMachine::AddressSpace
Definition: AddressSpace.hh:51
AddASCmd::create
virtual AddASCmd * create() const
Definition: AddASCmd.cc:127
AddASCmd::isEnabled
virtual bool isEnabled()
Definition: AddASCmd.cc:151
ProDeConstants::COMP_NEW_NAME_PREFIX_AS
static const std::string COMP_NEW_NAME_PREFIX_AS
Prefix for new address space names.
Definition: ProDeConstants.hh:379
ModelConstants::DEFAULT_AS_MIN_ADDRESS
static const int DEFAULT_AS_MIN_ADDRESS
Default address space min address.
Definition: ModelConstants.hh:68
AddressSpaceDialog
Definition: AddressSpaceDialog.hh:50
ProDeConstants::COMMAND_ADD_AS
@ COMMAND_ADD_AS
Definition: ProDeConstants.hh:424
Conversion::toString
static std::string toString(const T &source)
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
AddASCmd
Definition: AddASCmd.hh:43
ModelConstants::DEFAULT_AS_MAX_ADDRESS
static const int DEFAULT_AS_MAX_ADDRESS
Default address space max address.
Definition: ModelConstants.hh:70
Model::notifyObservers
void notifyObservers(bool modified=true)
Definition: Model.cc:152
assert
#define assert(condition)
Definition: Application.hh:86
ModelConstants::DEFAULT_WIDTH
static const int DEFAULT_WIDTH
Default bit width.
Definition: ModelConstants.hh:46
Conversion.hh
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
TTAMachine::Machine::Navigator::hasItem
bool hasItem(const std::string &name) const
Model.hh
AddressSpaceDialog.hh
ModelConstants.hh
Machine.hh
TTAMachine::Machine::addressSpaceNavigator
virtual AddressSpaceNavigator addressSpaceNavigator() const
Definition: Machine.cc:392
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
AddASCmd::Do
virtual bool Do()
Definition: AddASCmd.cc:64
MDFDocument
Definition: MDFDocument.hh:51
ProDeConstants.hh
Model
Definition: Model.hh:50
AddASCmd::shortName
virtual std::string shortName() const
Definition: AddASCmd.cc:138
EditorCommand
Definition: EditorCommand.hh:46
ProDeConstants
Definition: ProDeConstants.hh:43
TTAMachine
Definition: Assembler.hh:48
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
ProDeConstants::CMD_SNAME_ADD_AS
static const std::string CMD_SNAME_ADD_AS
Command name for the "Add Address Space" command.
Definition: ProDeConstants.hh:219
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
Model::getMachine
TTAMachine::Machine * getMachine()
Definition: Model.cc:88