OpenASIP  2.0
OSEdPropertiesCmd.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 OSEdPropertiesCmd.cc
26  *
27  * Definition of OSEdPropertiesCmd class.
28  *
29  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <boost/format.hpp>
34 #include <iostream>
35 
36 #include "OSEdPropertiesCmd.hh"
37 #include "OSEdConstants.hh"
39 #include "OSEd.hh"
40 #include "Application.hh"
41 #include "ErrorDialog.hh"
42 #include "OperationContainer.hh"
43 #include "FileSystem.hh"
44 #include "WxConversion.hh"
45 #include "OSEdTextGenerator.hh"
46 #include "OSEdTreeView.hh"
47 #include "OperationSerializer.hh"
48 #include "OperationIndex.hh"
49 #include "Operation.hh"
50 #include "OperationModule.hh"
51 #include "TCEString.hh"
52 #include "ObjectState.hh"
53 
54 using boost::format;
55 using std::string;
56 using std::cout;
57 using std::endl;
58 
59 /**
60  * Constructor.
61  */
63  GUICommand(OSEdConstants::CMD_NAME_PROPERTIES, NULL) {
64 }
65 
66 /**
67  * Destructor.
68  */
70 }
71 
72 /**
73  * Returns the id of the command.
74  *
75  * @return The id of the command.
76  */
77 int
80 }
81 
82 /**
83  * Creates a new command.
84  *
85  * @return The created command.
86  */
89  return new OSEdPropertiesCmd();
90 }
91 
92 /**
93  * Executes the command.
94  *
95  * @return True if execution is successful, false otherwise.
96  */
97 bool
99 
101  OSEdMainFrame* mainFrame = wxGetApp().mainFrame();
102  OSEdTreeView* treeView = mainFrame->treeView();
103  Operation* op = treeView->selectedOperation();
104  string opName = op->name();
105  wxTreeItemId opId = treeView->selectedOperationId();
106  string modName = treeView->moduleOfOperation(opId);
107  wxTreeItemId modId = treeView->moduleIdOfOperation(opId);
108  string pathName = treeView->pathOfModule(modId);
109  OperationModule& module = OperationContainer::module(pathName, modName);
110 
111  assert(&module != &NullOperationModule::instance());
112 
116  error.ShowModal();
117  delete op;
118  return false;
119  } else {
120  OperationPropertyDialog dialog(parentWindow(), op, module, pathName);
121  ObjectState* orig = op->saveState();
122  if (dialog.ShowModal() == wxID_OK) {
123 
124  ObjectState* mod = op->saveState();
125  if (*mod != *orig) {
126  // write operation properties to file
127  OperationSerializer& serializer =
129  serializer.setSourceFile(module.propertiesModule());
130  ObjectState* root = NULL;
131  try {
132  root = serializer.readState();
133  for (int i = 0; i < root->childCount(); i++) {
134  ObjectState* child = root->child(i);
135  if (child->stringAttribute("name") == opName) {
136  root->replaceChild(child, op->saveState());
137  break;
138  }
139  }
140  serializer.setDestinationFile(module.propertiesModule());
141  serializer.writeState(root);
142  } catch (const Exception& s) {
143  format fmt =
145  ErrorDialog eDialog(
146  parentWindow(), WxConversion::toWxString(fmt.str()));
147  eDialog.ShowModal();
148  }
149  delete root;
150 
151  // update the tree.
152  if (opName != op->name()) {
154  index.refreshModule(pathName, modName);
155  treeView->changeText(opId, op->name());
156  }
157 
158  treeView->update();
159  }
160  delete mod;
161  }
162  delete orig;
163  delete op;
164  return true;
165  }
166 
167  assert(false);
168  return false;
169 }
170 
171 /**
172  * Returns true, if command is enabled.
173  *
174  * @return True, if command is enabled.
175  */
176 bool
178  OSEdTreeView* treeView = wxGetApp().mainFrame()->treeView();
179  Operation* op = treeView->selectedOperation();
180  if (op != NULL) {
181  delete op;
182  return true;
183  } else {
184  return false;
185  }
186 }
187 
188 /**
189  * Returns the icon path.
190  *
191  * @return Empty string (icons not used).
192  */
193 string
195  return "";
196 }
OperationPropertyDialog
Definition: OperationPropertyDialog.hh:51
OperationIndex::refreshModule
void refreshModule(const std::string &path, const std::string &modName)
Definition: OperationIndex.cc:272
FileSystem.hh
WxConversion::toWxString
static wxString toWxString(const std::string &source)
OSEdTreeView::pathOfModule
std::string pathOfModule(wxTreeItemId id)
Definition: OSEdTreeView.cc:431
OSEdPropertiesCmd::OSEdPropertiesCmd
OSEdPropertiesCmd()
Definition: OSEdPropertiesCmd.cc:62
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition: ObjectState.cc:249
OSEdPropertiesCmd::icon
virtual std::string icon() const
Definition: OSEdPropertiesCmd.cc:194
OSEdPropertiesCmd::id
virtual int id() const
Definition: OSEdPropertiesCmd.cc:78
OperationSerializer::writeState
virtual void writeState(const ObjectState *state)
Definition: OperationSerializer.cc:96
OperationContainer::operationSerializer
static OperationSerializer & operationSerializer()
Definition: OperationContainer.cc:111
OSEdTreeView::moduleIdOfOperation
wxTreeItemId moduleIdOfOperation(wxTreeItemId id)
Definition: OSEdTreeView.cc:420
OSEdTextGenerator::TXT_ERROR_CAN_NOT_MODIFY
@ TXT_ERROR_CAN_NOT_MODIFY
Error when can not modify.
Definition: OSEdTextGenerator.hh:133
OperationSerializer::setDestinationFile
void setDestinationFile(const std::string &filename)
Definition: OperationSerializer.cc:546
OperationContainer::module
static OperationModule & module(const std::string &path, const std::string &mod)
Definition: OperationContainer.cc:148
OSEdPropertiesCmd.hh
ObjectState
Definition: ObjectState.hh:59
OSEd.hh
OSEdConstants::CMD_PROPERTIES
@ CMD_PROPERTIES
Operation properties command id.
Definition: OSEdConstants.hh:94
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
Operation::name
virtual TCEString name() const
Definition: Operation.cc:93
OSEdMainFrame::treeView
OSEdTreeView * treeView() const
Definition: OSEdMainFrame.cc:241
OSEdConstants.hh
ObjectState::replaceChild
void replaceChild(ObjectState *old, ObjectState *newChild)
Definition: ObjectState.cc:408
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
ErrorDialog
Definition: ErrorDialog.hh:42
FileSystem::fileIsWritable
static bool fileIsWritable(const std::string fileName)
OperationPropertyDialog.hh
OSEdTreeView
Definition: OSEdTreeView.hh:54
ErrorDialog.hh
OperationIndex.hh
OperationSerializer::readState
virtual ObjectState * readState()
Definition: OperationSerializer.cc:118
OSEdTreeView::moduleOfOperation
std::string moduleOfOperation(wxTreeItemId id)
Definition: OSEdTreeView.cc:407
Application.hh
OSEdConstants
Definition: OSEdConstants.hh:45
ObjectState.hh
OperationSerializer.hh
OSEdTreeView::changeText
void changeText(wxTreeItemId id, const std::string &text)
Definition: OSEdTreeView.cc:592
OperationSerializer
Definition: OperationSerializer.hh:49
ObjectState::child
ObjectState * child(int index) const
Definition: ObjectState.cc:471
Operation.hh
OSEdTreeView::selectedOperation
Operation * selectedOperation()
Definition: OSEdTreeView.cc:328
ObjectState::childCount
int childCount() const
Operation::saveState
virtual ObjectState * saveState() const
Definition: Operation.cc:490
OperationSerializer::setSourceFile
void setSourceFile(const std::string &filename)
Definition: OperationSerializer.cc:536
Exception
Definition: Exception.hh:54
OSEdPropertiesCmd::create
virtual GUICommand * create() const
Definition: OSEdPropertiesCmd.cc:88
Operation
Definition: Operation.hh:59
OSEdTreeView.hh
OSEdMainFrame
Definition: OSEdMainFrame.hh:49
OSEdPropertiesCmd::~OSEdPropertiesCmd
virtual ~OSEdPropertiesCmd()
Definition: OSEdPropertiesCmd.cc:69
OperationModule
Definition: OperationModule.hh:46
OSEdTreeView::update
void update()
Definition: OSEdTreeView.cc:670
OperationIndex
Definition: OperationIndex.hh:58
OSEdTextGenerator::instance
static OSEdTextGenerator & instance()
Definition: OSEdTextGenerator.cc:214
OSEdPropertiesCmd::isEnabled
virtual bool isEnabled()
Definition: OSEdPropertiesCmd.cc:177
OSEdTreeView::selectedOperationId
wxTreeItemId selectedOperationId()
Definition: OSEdTreeView.cc:379
OSEdTextGenerator
Definition: OSEdTextGenerator.hh:42
WxConversion.hh
NullOperationModule::instance
static NullOperationModule & instance()
OSEdTextGenerator.hh
OperationContainer::operationIndex
static OperationIndex & operationIndex()
Definition: OperationContainer.cc:94
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
OperationModule.hh
OSEdPropertiesCmd::Do
virtual bool Do()
Definition: OSEdPropertiesCmd.cc:98
OperationContainer.hh