OpenASIP  2.0
OSEdAddOperationCmd.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 OSEdAddOperationCmd.cc
26  *
27  * Definition of OSEdAddOperationCmd class.
28  *
29  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <string>
34 
35 #include "OSEdAddOperationCmd.hh"
36 #include "OSEdConstants.hh"
37 #include "OSEd.hh"
38 #include "ErrorDialog.hh"
39 #include "OperationContainer.hh"
40 #include "WxConversion.hh"
41 #include "OSEdTextGenerator.hh"
42 #include "OperationBehavior.hh"
44 #include "OSEdTreeView.hh"
45 #include "OperationSerializer.hh"
46 #include "OperationIndex.hh"
47 #include "OperationModule.hh"
48 #include "Operation.hh"
49 #include "TCEString.hh"
50 #include "ObjectState.hh"
51 
52 using std::string;
53 
54 /**
55  * Constructor.
56  */
58  GUICommand(OSEdConstants::CMD_NAME_ADD_OPERATION, NULL) {
59 }
60 
61 /**
62  * Destructor.
63  */
65 }
66 
67 /**
68  * Returns the id of the command.
69  *
70  * @return The id of the command.
71  */
72 int
75 }
76 
77 /**
78  * Creates a new command.
79  *
80  * @return New command.
81  */
84  return new OSEdAddOperationCmd();
85 }
86 
87 /**
88  * Executes the command.
89  */
90 bool
92 
93  OSEdMainFrame* mainFrame = wxGetApp().mainFrame();
94  OSEdTreeView* treeView = mainFrame->treeView();
95  string modName = treeView->selectedModule();
96 
97  wxTreeItemId modId = treeView->selectedModuleId();
98  string pathName = treeView->pathOfModule(modId);
100  OperationModule& module = OperationContainer::module(pathName, modName);
101 
102  assert(&module != &NullOperationModule::instance());
103 
104  OperationPropertyDialog dialog(parentWindow(), NULL, module, pathName);
105 
106  if (dialog.ShowModal() == wxID_OK) {
107  Operation* op = dialog.operation();
108 
109  OperationSerializer& serializer =
111  serializer.setDestinationFile(module.propertiesModule());
112  ObjectState* root = new ObjectState("");
113 
114  for (int k = 0; k < index.operationCount(module); k++) {
115 
116  string opName = index.operationName(k, module);
118  pathName, modName, opName);
119 
120  root->addChild(oper->saveState());
121  delete oper;
122  }
123 
124  root->addChild(op->saveState());
125 
126  try {
127  serializer.writeState(root);
128  delete root;
129  } catch (const SerializerException& s) {
130  wxString msg = WxConversion::toWxString(s.errorMessage());
131  ErrorDialog eDialog(parentWindow(), msg);
132  eDialog.ShowModal();
133  delete root;
134  delete op;
135  return false;
136  }
137 
138  index.refreshModule(pathName, modName);
139  treeView->addItem(modId, op->name());
140  treeView->update();
141  }
142 
143  return true;
144 }
145 
146 /**
147  * Returns true, if command is enabled.
148  *
149  * Operation can be added, if path is writable.
150  *
151  * @return True if command is enabled.
152  */
153 bool
155  OSEdTreeView* treeView = wxGetApp().mainFrame()->treeView();
156  string modName = treeView->selectedModule();
157  if (modName != "") {
158  wxTreeItemId modId = treeView->selectedModuleId();
159  string pathName = treeView->pathOfModule(modId);
160  string tempFile = pathName + FileSystem::DIRECTORY_SEPARATOR +
161  "temp12341";
162  if (FileSystem::createFile(tempFile)) {
164  return true;
165  } else {
166  return false;
167  }
168  }
169  return false;
170 }
171 
172 /**
173  * Returns the icon path.
174  *
175  * @return Empty string (no icons used).
176  */
177 string
179  return "";
180 }
OperationPropertyDialog
Definition: OperationPropertyDialog.hh:51
OSEdTreeView::selectedModule
std::string selectedModule()
Definition: OSEdTreeView.cc:513
OperationPropertyDialog::operation
Operation * operation() const
Definition: OperationPropertyDialog.cc:236
OperationIndex::refreshModule
void refreshModule(const std::string &path, const std::string &modName)
Definition: OperationIndex.cc:272
OSEdTreeView::selectedModuleId
wxTreeItemId selectedModuleId()
Definition: OSEdTreeView.cc:537
WxConversion::toWxString
static wxString toWxString(const std::string &source)
FileSystem::removeFileOrDirectory
static bool removeFileOrDirectory(const std::string &path)
Definition: FileSystem.cc:493
OSEdConstants::CMD_ADD_OPERATION
@ CMD_ADD_OPERATION
Add operation command id.
Definition: OSEdConstants.hh:93
OSEdTreeView::pathOfModule
std::string pathOfModule(wxTreeItemId id)
Definition: OSEdTreeView.cc:431
OperationSerializer::writeState
virtual void writeState(const ObjectState *state)
Definition: OperationSerializer.cc:96
OperationContainer::operationSerializer
static OperationSerializer & operationSerializer()
Definition: OperationContainer.cc:111
OperationSerializer::setDestinationFile
void setDestinationFile(const std::string &filename)
Definition: OperationSerializer.cc:546
OSEdTreeView::addItem
void addItem(wxTreeItemId parent, std::string item)
Definition: OSEdTreeView.cc:573
OperationContainer::module
static OperationModule & module(const std::string &path, const std::string &mod)
Definition: OperationContainer.cc:148
OSEdAddOperationCmd::icon
virtual std::string icon() const
Definition: OSEdAddOperationCmd.cc:178
OSEdAddOperationCmd::id
virtual int id() const
Definition: OSEdAddOperationCmd.cc:73
ObjectState
Definition: ObjectState.hh:59
OSEd.hh
Operation::name
virtual TCEString name() const
Definition: Operation.cc:93
OSEdMainFrame::treeView
OSEdTreeView * treeView() const
Definition: OSEdMainFrame.cc:241
OSEdConstants.hh
TCEString.hh
assert
#define assert(condition)
Definition: Application.hh:86
OperationModule::propertiesModule
virtual std::string propertiesModule() const
Definition: OperationModule.cc:121
GUICommand
Definition: GUICommand.hh:43
OSEdAddOperationCmd::~OSEdAddOperationCmd
virtual ~OSEdAddOperationCmd()
Definition: OSEdAddOperationCmd.cc:64
ErrorDialog
Definition: ErrorDialog.hh:42
OperationPropertyDialog.hh
OSEdTreeView
Definition: OSEdTreeView.hh:54
ErrorDialog.hh
OperationIndex.hh
OSEdConstants
Definition: OSEdConstants.hh:45
ObjectState.hh
OperationSerializer.hh
OSEdAddOperationCmd::isEnabled
virtual bool isEnabled()
Definition: OSEdAddOperationCmd.cc:154
OperationSerializer
Definition: OperationSerializer.hh:49
ObjectState::addChild
void addChild(ObjectState *child)
Definition: ObjectState.cc:376
Operation.hh
Operation::saveState
virtual ObjectState * saveState() const
Definition: Operation.cc:490
SerializerException
Definition: Exception.hh:675
FileSystem::createFile
static bool createFile(const std::string &file)
Definition: FileSystem.cc:468
Operation
Definition: Operation.hh:59
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
OSEdTreeView.hh
OSEdAddOperationCmd::create
virtual GUICommand * create() const
Definition: OSEdAddOperationCmd.cc:83
OSEdMainFrame
Definition: OSEdMainFrame.hh:49
OperationBehavior.hh
OperationModule
Definition: OperationModule.hh:46
OSEdTreeView::update
void update()
Definition: OSEdTreeView.cc:670
OperationIndex
Definition: OperationIndex.hh:58
WxConversion.hh
OperationContainer::operation
static Operation * operation(const std::string &path, const std::string &module, const std::string &oper)
Definition: OperationContainer.cc:173
OSEdAddOperationCmd::OSEdAddOperationCmd
OSEdAddOperationCmd()
Definition: OSEdAddOperationCmd.cc:57
OSEdAddOperationCmd::Do
virtual bool Do()
Definition: OSEdAddOperationCmd.cc:91
OSEdAddOperationCmd.hh
NullOperationModule::instance
static NullOperationModule & instance()
OperationIndex::operationCount
int operationCount(const OperationModule &om)
Definition: OperationIndex.cc:363
OSEdTextGenerator.hh
OperationContainer::operationIndex
static OperationIndex & operationIndex()
Definition: OperationContainer.cc:94
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
OperationIndex::operationName
std::string operationName(int i, const OperationModule &om)
Definition: OperationIndex.cc:337
OperationModule.hh
OperationContainer.hh