OpenASIP  2.0
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 
55 using std::string;
56 using namespace TTAMachine;
57 
58 /**
59  * The Constructor.
60  */
62  EditorCommand(ProDeConstants::CMD_NAME_ADD_BRIDGE) {
63 }
64 
65 
66 /**
67  * The Destructor.
68  */
70 }
71 
72 
73 /**
74  * Executes the command.
75  *
76  * @return true, if the command was succesfully executed, false otherwise.
77  */
78 bool
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  */
154 int
157 }
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  */
177 string
180 }
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  */
190 bool
192  wxDocManager* manager = wxGetApp().docManager();
193  if (manager->GetCurrentView() != NULL) {
194  return true;
195  }
196  return false;
197 }
ProDe.hh
WxConversion::toWxString
static wxString toWxString(const std::string &source)
MDFDocument.hh
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
TTAMachine::Bridge
Definition: Bridge.hh:51
AddBridgeCmd
Definition: AddBridgeCmd.hh:43
TTAMachine::Bus
Definition: Bus.hh:53
MachineTester::canBridge
virtual bool canBridge(const TTAMachine::Bus &source, const TTAMachine::Bus &destination)
Definition: MachineTester.cc:203
AddBridgeCmd::AddBridgeCmd
AddBridgeCmd()
Definition: AddBridgeCmd.cc:61
TTAMachine::Machine::Navigator::count
int count() const
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
ProDeTextGenerator.hh
Conversion::toString
static std::string toString(const T &source)
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
Model::notifyObservers
void notifyObservers(bool modified=true)
Definition: Model.cc:152
AddBridgeCmd::shortName
virtual std::string shortName() const
Definition: AddBridgeCmd.cc:178
assert
#define assert(condition)
Definition: Application.hh:86
Segment.hh
ProDeConstants::COMP_NEW_NAME_PREFIX_BRIDGE
static const std::string COMP_NEW_NAME_PREFIX_BRIDGE
Prefix for new bridge names.
Definition: ProDeConstants.hh:375
TTAMachine::Machine::bridgeNavigator
virtual BridgeNavigator bridgeNavigator() const
Definition: Machine.cc:404
BridgeDialog
Definition: BridgeDialog.hh:46
Conversion.hh
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
TTAMachine::Machine::Navigator::hasItem
bool hasItem(const std::string &name) const
InformationDialog.hh
AddBridgeCmd.hh
AddBridgeCmd::Do
virtual bool Do()
Definition: AddBridgeCmd.cc:79
Model.hh
AddBridgeCmd::isEnabled
virtual bool isEnabled()
Definition: AddBridgeCmd.cc:191
AddBridgeCmd::id
virtual int id() const
Definition: AddBridgeCmd.cc:155
Machine.hh
Bus.hh
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
MDFDocument
Definition: MDFDocument.hh:51
ProDeConstants.hh
MachineTester.hh
MainFrame.hh
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
AddBridgeCmd::create
virtual AddBridgeCmd * create() const
Definition: AddBridgeCmd.cc:166
Model
Definition: Model.hh:50
AddBridgeCmd::~AddBridgeCmd
virtual ~AddBridgeCmd()
Definition: AddBridgeCmd.cc:69
TTAMachine::Machine::busNavigator
virtual BusNavigator busNavigator() const
Definition: Machine.cc:356
EditorCommand
Definition: EditorCommand.hh:46
WxConversion.hh
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
BridgeDialog.hh
InformationDialog
Definition: InformationDialog.hh:42
ProDeTextGenerator::MSG_ERROR_CANNOT_BRIDGE
@ MSG_ERROR_CANNOT_BRIDGE
Error: Bridge creation impossible.
Definition: ProDeTextGenerator.hh:225
ProDeConstants
Definition: ProDeConstants.hh:43
TTAMachine
Definition: Assembler.hh:48
MachineTester
Definition: MachineTester.hh:46
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
ProDeConstants::COMMAND_ADD_BRIDGE
@ COMMAND_ADD_BRIDGE
Definition: ProDeConstants.hh:421
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
Bridge.hh
Model::getMachine
TTAMachine::Machine * getMachine()
Definition: Model.cc:88
TTAMachine::Machine
Definition: Machine.hh:73
ProDeConstants::CMD_SNAME_ADD_BRIDGE
static const std::string CMD_SNAME_ADD_BRIDGE
Command name for the "Add Bridge" command.
Definition: ProDeConstants.hh:213