OpenASIP 2.2
Loading...
Searching...
No Matches
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
46using std::string;
47using 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 */
63bool
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 */
115int
119
120
121/**
122 * Creates and returns a new instance of this command.
123 *
124 * @return Newly created instance of this command.
125 */
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 */
137string
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 */
150bool
152 wxDocManager* manager = wxGetApp().docManager();
153 if (manager->GetCurrentView() != NULL) {
154 return true;
155 }
156 return false;
157}
#define assert(condition)
virtual AddASCmd * create() const
Definition AddASCmd.cc:127
virtual std::string shortName() const
Definition AddASCmd.cc:138
virtual int id() const
Definition AddASCmd.cc:116
virtual bool Do()
Definition AddASCmd.cc:64
virtual bool isEnabled()
Definition AddASCmd.cc:151
static std::string toString(const T &source)
wxView * view() const
wxWindow * parentWindow() const
Definition GUICommand.cc:75
static const int DEFAULT_AS_MIN_ADDRESS
Default address space min address.
static const int DEFAULT_WIDTH
Default bit width.
static const int DEFAULT_AS_MAX_ADDRESS
Default address space max address.
Definition Model.hh:50
void pushToStack()
Definition Model.cc:167
void notifyObservers(bool modified=true)
Definition Model.cc:152
void popFromStack(bool modified=false)
Definition Model.cc:195
TTAMachine::Machine * getMachine()
Definition Model.cc:88
static const std::string CMD_SNAME_ADD_AS
Command name for the "Add Address Space" command.
static const std::string COMP_NEW_NAME_PREFIX_AS
Prefix for new address space names.
bool hasItem(const std::string &name) const
virtual AddressSpaceNavigator addressSpaceNavigator() const
Definition Machine.cc:392