OpenASIP 2.2
Loading...
Searching...
No Matches
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
47using std::string;
48using 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 */
64bool
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 */
108int
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 */
130string
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 */
143bool
145 wxDocManager* manager = wxGetApp().docManager();
146 if (manager->GetCurrentView() != NULL) {
147 return true;
148 }
149 return false;
150}
#define assert(condition)
virtual std::string shortName() const
virtual int id() const
virtual bool Do()
virtual AddSocketCmd * create() const
virtual bool isEnabled()
static std::string toString(const T &source)
wxView * view() const
wxWindow * parentWindow() const
Definition GUICommand.cc:75
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_SOCKET
Command name for the "Add Socket" command.
static const std::string COMP_NEW_NAME_PREFIX_SOCKET
Prefix for new socket names..
bool hasItem(const std::string &name) const
virtual SocketNavigator socketNavigator() const
Definition Machine.cc:368
virtual void setMachine(Machine &mach)
Definition Socket.cc:432