OpenASIP 2.2
Loading...
Searching...
No Matches
AddBusCmd.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 AddBusCmd.cc
26 *
27 * Definition of AddBusCmd class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <wx/wx.h>
34#include <wx/docview.h>
35
36#include "AddBusCmd.hh"
37#include "Bus.hh"
38#include "Segment.hh"
39#include "BusDialog.hh"
40#include "Model.hh"
41#include "ModelConstants.hh"
42#include "MDFDocument.hh"
43#include "ProDeConstants.hh"
44#include "ErrorDialog.hh"
45#include "ProDe.hh"
46#include "Machine.hh"
47#include "Guard.hh"
48#include "Conversion.hh"
49
50using std::string;
51using namespace TTAMachine;
52
53/**
54 * The Constructor.
55 */
57 EditorCommand(ProDeConstants::CMD_NAME_ADD_BUS) {
58}
59
60
61
62/**
63 * Executes the command.
64 *
65 * @return true, if the command was succesfully executed, false otherwise.
66 */
67bool
69
70 assert(parentWindow() != NULL);
71 assert(view() != NULL);
72
73 Model* model = dynamic_cast<MDFDocument*>(
74 view()->GetDocument())->getModel();
75
76 model->pushToStack();
77
78 // Generate name for the new bus.
79 Machine::BusNavigator navigator =
80 model->getMachine()->busNavigator();
81 int i = 1;
84 while (navigator.hasItem(newName)) {
87 i++;
88 }
89 Bus* bus =
92 bus->setMachine(*(model->getMachine()));
93
94 // Create an always-true guard for the bus by default.
95 new UnconditionalGuard(false, *bus);
96
97 // Add a default segment to the bus.
99
100 BusDialog dialog(parentWindow(), bus);
101
102 if (dialog.ShowModal() == wxID_OK) {
103 model->notifyObservers();
104 return true;
105 } else {
106 // bus creation was cancelled
107 model->popFromStack();
108 return false;
109 }
110}
111
112
113/**
114 * Returns id of this command.
115 *
116 * @return ID for this command to be used in menus and toolbars.
117 */
118int
122
123
124/**
125 * Creates and returns a new instance of this command.
126 *
127 * @return Newly created instance of this command.
128 */
131 return new AddBusCmd();
132}
133
134
135/**
136 * Returns short version of the command name.
137 *
138 * @return Short name of the command to be used in the toolbar.
139 */
140string
144
145
146/**
147 * Returns true when the command is executable, false when not.
148 *
149 * This command is executable when a document is open.
150 *
151 * @return True, if a document is open.
152 */
153bool
155 wxDocManager* manager = wxGetApp().docManager();
156 if (manager->GetCurrentView() != NULL) {
157 return true;
158 }
159 return false;
160}
#define assert(condition)
virtual int id() const
Definition AddBusCmd.cc:119
virtual std::string shortName() const
Definition AddBusCmd.cc:141
virtual bool Do()
Definition AddBusCmd.cc:68
virtual AddBusCmd * create() const
Definition AddBusCmd.cc:130
virtual bool isEnabled()
Definition AddBusCmd.cc:154
static std::string toString(const T &source)
wxView * view() const
wxWindow * parentWindow() const
Definition GUICommand.cc:75
static const int DEFAULT_WIDTH
Default bit width.
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_BUS
Command name for the "Add Bus" command.
static const std::string COMP_NEW_NAME_PREFIX_BUS
Prefix for new bus names.
static const std::string COMP_DEFAULT_NAME_SEGMENT
Name for the default segments of busses.
virtual void setMachine(Machine &mach)
Definition Bus.cc:671
bool hasItem(const std::string &name) const
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
@ ZERO
Zero extension.
Definition Machine.hh:81