OpenASIP 2.2
Loading...
Searching...
No Matches
AddBridgeCmd.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 AddBridgeCmd.cc
26 *
27 * Definition of AddBridgeCmd class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 * @note reviewed Jun 23 2004 by ml, jn, jm, vpj
32 */
33
34#include <wx/wx.h>
35#include <wx/docview.h>
36#include <boost/format.hpp>
37
38#include "AddBridgeCmd.hh"
39#include "BridgeDialog.hh"
40#include "Machine.hh"
41#include "Model.hh"
42#include "Conversion.hh"
43#include "MDFDocument.hh"
44#include "ProDeConstants.hh"
45#include "InformationDialog.hh"
46#include "Bus.hh"
47#include "Bridge.hh"
48#include "Segment.hh"
49#include "ProDe.hh"
50#include "MainFrame.hh"
51#include "MachineTester.hh"
52#include "ProDeTextGenerator.hh"
53#include "WxConversion.hh"
54
55using std::string;
56using namespace TTAMachine;
57
58/**
59 * The Constructor.
60 */
62 EditorCommand(ProDeConstants::CMD_NAME_ADD_BRIDGE) {
63}
64
65
66/**
67 * The Destructor.
68 */
71
72
73/**
74 * Executes the command.
75 *
76 * @return true, if the command was succesfully executed, false otherwise.
77 */
78bool
80
81 assert(parentWindow() != NULL);
82 assert(view() != NULL);
83
84 Model* model =
85 dynamic_cast<MDFDocument*>(view()->GetDocument())->getModel();
86 Machine* machine = model->getMachine();
87
89
90 Bus* source = NULL;
91 Bus* destination = NULL;
92 MachineTester tester(*machine);
93
94 // Check that two buses in the machine can be bridged.
95 int i = 0;
96 while (i < navigator.count() && source == NULL) {
97 for (int j = 0; j < navigator.count(); j++) {
98 if (tester.canBridge(*navigator.item(i), *navigator.item(j))) {
99 source = navigator.item(i);
100 destination = navigator.item(j);
101 break;
102 }
103 }
104 i++;
105 }
106
107 if (source == NULL) {
108 // It's not possible to create a legal bridge to the machine,
109 // display an error message.
111
112 boost::format message =
114
116 WxConversion::toWxString(message.str()));
117 info.ShowModal();
118 return false;
119 }
120
121
122 // Generate name for the new FU.
123 Machine::BridgeNavigator bridgeNavigator =
124 model->getMachine()->bridgeNavigator();
125 int suffix = 1;
127 Conversion::toString(suffix);
128 while (bridgeNavigator.hasItem(newName)) {
130 Conversion::toString(suffix);
131 suffix++;
132 }
133
134 // Create and show bridge dialog.
135 model->pushToStack();
136 Bridge* bridge = new Bridge(newName, *source, *destination);
137 BridgeDialog dialog(parentWindow(), bridge, NULL);
138
139 if (dialog.ShowModal() == wxID_OK) {
140 model->notifyObservers();
141 } else {
142 // bridge creation was cancelled
143 model->popFromStack();
144 }
145 return false;
146}
147
148
149/**
150 * Returns id of this command.
151 *
152 * @return ID for this command to be used in menus and toolbars.
153 */
154int
158
159
160/**
161 * Creates and returns a new instance of this command.
162 *
163 * @return Newly created instance of this command.
164 */
167 return new AddBridgeCmd();
168}
169
170
171
172/**
173 * Returns short version of the command name.
174 *
175 * @return Short name of the command to be used in the toolbar.
176 */
177string
181
182
183/**
184 * Returns true when the command is executable, false when not.
185 *
186 * This command is executable when a document is open.
187 *
188 * @return True, if a document is open.
189 */
190bool
192 wxDocManager* manager = wxGetApp().docManager();
193 if (manager->GetCurrentView() != NULL) {
194 return true;
195 }
196 return false;
197}
#define assert(condition)
TTAMachine::Machine * machine
the architecture definition of the estimated processor
virtual bool Do()
virtual int id() const
virtual ~AddBridgeCmd()
virtual bool isEnabled()
virtual AddBridgeCmd * create() const
virtual std::string shortName() const
static std::string toString(const T &source)
wxView * view() const
wxWindow * parentWindow() const
Definition GUICommand.cc:75
virtual bool canBridge(const TTAMachine::Bus &source, const TTAMachine::Bus &destination)
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_BRIDGE
Command name for the "Add Bridge" command.
static const std::string COMP_NEW_NAME_PREFIX_BRIDGE
Prefix for new bridge names.
static ProDeTextGenerator * instance()
@ MSG_ERROR_CANNOT_BRIDGE
Error: Bridge creation impossible.
ComponentType * item(int index) const
bool hasItem(const std::string &name) const
virtual BridgeNavigator bridgeNavigator() const
Definition Machine.cc:404
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
virtual boost::format text(int textId)
static wxString toWxString(const std::string &source)