OpenASIP  2.0
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 
50 using std::string;
51 using 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  */
67 bool
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 =
91  ModelConstants::DEFAULT_WIDTH, Machine::ZERO);
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  */
118 int
119 AddBusCmd::id() const {
121 }
122 
123 
124 /**
125  * Creates and returns a new instance of this command.
126  *
127  * @return Newly created instance of this command.
128  */
129 AddBusCmd*
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  */
140 string
143 }
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  */
153 bool
155  wxDocManager* manager = wxGetApp().docManager();
156  if (manager->GetCurrentView() != NULL) {
157  return true;
158  }
159  return false;
160 }
AddBusCmd
Definition: AddBusCmd.hh:43
ProDe.hh
MDFDocument.hh
TTAMachine::Segment
Definition: Segment.hh:54
ProDeConstants::CMD_SNAME_ADD_BUS
static const std::string CMD_SNAME_ADD_BUS
Command name for the "Add Bus" command.
Definition: ProDeConstants.hh:209
TTAMachine::Bus
Definition: Bus.hh:53
AddBusCmd::AddBusCmd
AddBusCmd()
Definition: AddBusCmd.cc:56
Conversion::toString
static std::string toString(const T &source)
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
AddBusCmd::shortName
virtual std::string shortName() const
Definition: AddBusCmd.cc:141
Model::notifyObservers
void notifyObservers(bool modified=true)
Definition: Model.cc:152
assert
#define assert(condition)
Definition: Application.hh:86
TTAMachine::UnconditionalGuard
Definition: Guard.hh:180
Segment.hh
ModelConstants::DEFAULT_WIDTH
static const int DEFAULT_WIDTH
Default bit width.
Definition: ModelConstants.hh:46
ProDeConstants::COMP_DEFAULT_NAME_SEGMENT
static const std::string COMP_DEFAULT_NAME_SEGMENT
Name for the default segments of busses.
Definition: ProDeConstants.hh:359
AddBusCmd::isEnabled
virtual bool isEnabled()
Definition: AddBusCmd.cc:154
ErrorDialog.hh
Conversion.hh
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
AddBusCmd::id
virtual int id() const
Definition: AddBusCmd.cc:119
TTAMachine::Machine::Navigator::hasItem
bool hasItem(const std::string &name) const
Model.hh
ProDeConstants::COMMAND_ADD_BUS
@ COMMAND_ADD_BUS
Definition: ProDeConstants.hh:419
Guard.hh
TTAMachine::Bus::setMachine
virtual void setMachine(Machine &mach)
Definition: Bus.cc:671
ModelConstants.hh
Machine.hh
BusDialog.hh
Bus.hh
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
MDFDocument
Definition: MDFDocument.hh:51
ProDeConstants.hh
Model
Definition: Model.hh:50
AddBusCmd::create
virtual AddBusCmd * create() const
Definition: AddBusCmd.cc:130
TTAMachine::Machine::busNavigator
virtual BusNavigator busNavigator() const
Definition: Machine.cc:356
BusDialog
Definition: BusDialog.hh:54
AddBusCmd::Do
virtual bool Do()
Definition: AddBusCmd.cc:68
EditorCommand
Definition: EditorCommand.hh:46
ProDeConstants::COMP_NEW_NAME_PREFIX_BUS
static const std::string COMP_NEW_NAME_PREFIX_BUS
Prefix for new bus names.
Definition: ProDeConstants.hh:371
ProDeConstants
Definition: ProDeConstants.hh:43
TTAMachine
Definition: Assembler.hh:48
AddBusCmd.hh
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
Model::getMachine
TTAMachine::Machine * getMachine()
Definition: Model.cc:88