OpenASIP  2.0
AddSocketCmd.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 AddSocketCmd.cc
26  *
27  * Definition of AddSocketCmd class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30  */
31 
32 #include <wx/wx.h>
33 #include <wx/docview.h>
34 
35 #include "AddSocketCmd.hh"
36 #include "Socket.hh"
37 #include "SocketDialog.hh"
38 #include "Model.hh"
39 #include "ModelConstants.hh"
40 #include "MDFDocument.hh"
41 #include "ProDeConstants.hh"
42 #include "ErrorDialog.hh"
43 #include "ProDe.hh"
44 #include "Machine.hh"
45 #include "ObjectState.hh"
46 
47 using std::string;
48 using namespace TTAMachine;
49 
50 /**
51  * The Constructor.
52  */
54  EditorCommand(ProDeConstants::CMD_NAME_ADD_SOCKET) {
55 }
56 
57 
58 
59 /**
60  * Executes the command.
61  *
62  * @return true, if the command was succesfully executed, false otherwise.
63  */
64 bool
66 
67  assert(parentWindow() != NULL);
68  assert(view() != NULL);
69 
70  Model* model = dynamic_cast<MDFDocument*>(
71  view()->GetDocument())->getModel();
72 
73  model->pushToStack();
74 
75  // Generate name for the new socket.
76  Machine::SocketNavigator navigator =
77  model->getMachine()->socketNavigator();
78  int i = 1;
81  while (navigator.hasItem(newName)) {
84  i++;
85  }
86 
87  Socket* socket = new Socket(newName);
88  socket->setMachine(*(model->getMachine()));
89 
90  SocketDialog dialog(parentWindow(), socket);
91 
92  if (dialog.ShowModal() == wxID_OK) {
93  model->notifyObservers();
94  return true;
95  } else {
96  model->popFromStack();
97  return false;
98  }
99  return false;
100 }
101 
102 
103 /**
104  * Returns id of this command.
105  *
106  * @return ID for this command to be used in menus and toolbars.
107  */
108 int
111 }
112 
113 
114 /**
115  * Creates and returns a new instance of this command.
116  *
117  * @return Newly created instance of this command.
118  */
121  return new AddSocketCmd();
122 }
123 
124 
125 /**
126  * Returns short version of the command name.
127  *
128  * @return Short name of the command to be used in the toolbar.
129  */
130 string
133 }
134 
135 
136 /**
137  * Returns true when the command is executable, false when not.
138  *
139  * This command is executable when a document is open.
140  *
141  * @return True, if a document is open.
142  */
143 bool
145  wxDocManager* manager = wxGetApp().docManager();
146  if (manager->GetCurrentView() != NULL) {
147  return true;
148  }
149  return false;
150 }
ProDe.hh
AddSocketCmd
Definition: AddSocketCmd.hh:43
AddSocketCmd::AddSocketCmd
AddSocketCmd()
Definition: AddSocketCmd.cc:53
MDFDocument.hh
AddSocketCmd::Do
virtual bool Do()
Definition: AddSocketCmd.cc:65
AddSocketCmd::create
virtual AddSocketCmd * create() const
Definition: AddSocketCmd.cc:120
AddSocketCmd::id
virtual int id() const
Definition: AddSocketCmd.cc:109
AddSocketCmd.hh
Socket.hh
Conversion::toString
static std::string toString(const T &source)
Model::pushToStack
void pushToStack()
Definition: Model.cc:167
Model::notifyObservers
void notifyObservers(bool modified=true)
Definition: Model.cc:152
assert
#define assert(condition)
Definition: Application.hh:86
ErrorDialog.hh
EditorCommand::view
wxView * view() const
Definition: EditorCommand.cc:76
TTAMachine::Machine::Navigator::hasItem
bool hasItem(const std::string &name) const
SocketDialog.hh
Model.hh
ObjectState.hh
TTAMachine::Socket::setMachine
virtual void setMachine(Machine &mach)
Definition: Socket.cc:432
TTAMachine::Socket
Definition: Socket.hh:53
ModelConstants.hh
Machine.hh
Model::popFromStack
void popFromStack(bool modified=false)
Definition: Model.cc:195
TTAMachine::Machine::socketNavigator
virtual SocketNavigator socketNavigator() const
Definition: Machine.cc:368
ProDeConstants::COMP_NEW_NAME_PREFIX_SOCKET
static const std::string COMP_NEW_NAME_PREFIX_SOCKET
Prefix for new socket names..
Definition: ProDeConstants.hh:369
SocketDialog
Definition: SocketDialog.hh:50
MDFDocument
Definition: MDFDocument.hh:51
ProDeConstants.hh
Model
Definition: Model.hh:50
AddSocketCmd::shortName
virtual std::string shortName() const
Definition: AddSocketCmd.cc:131
ProDeConstants::COMMAND_ADD_SOCKET
@ COMMAND_ADD_SOCKET
Definition: ProDeConstants.hh:420
EditorCommand
Definition: EditorCommand.hh:46
ProDeConstants::CMD_SNAME_ADD_SOCKET
static const std::string CMD_SNAME_ADD_SOCKET
Command name for the "Add Socket" command.
Definition: ProDeConstants.hh:211
AddSocketCmd::isEnabled
virtual bool isEnabled()
Definition: AddSocketCmd.cc:144
ProDeConstants
Definition: ProDeConstants.hh:43
TTAMachine
Definition: Assembler.hh:48
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