OpenASIP  2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MDFDocument Class Reference

#include <MDFDocument.hh>

Inheritance diagram for MDFDocument:
Inheritance graph
Collaboration diagram for MDFDocument:
Collaboration graph

Public Member Functions

 MDFDocument ()
 
virtual ~MDFDocument ()
 
virtual bool OnOpenDocument (const wxString &filename)
 
virtual bool OnSaveDocument (const wxString &filename)
 
virtual bool OnNewDocument ()
 
ModelgetModel ()
 
virtual void update ()
 

Private Member Functions

bool openCFG (const std::string &filename)
 
bool openADF (const std::string &filename)
 
- Private Member Functions inherited from ModelObserver
virtual ~ModelObserver ()
 

Private Attributes

Modelmodel_
 Machine Object Model which the document represents. More...
 

Detailed Description

An instance of MDFDocument represents one machine object model for the editor.

Part of the wxWindows document/view framework. Opening and saving of documents is passed through this class to the xml reader/writer components. When a new document is created or opened, this class initializes a new model. Document's model can be accessed with the getModel() method.

Definition at line 51 of file MDFDocument.hh.

Constructor & Destructor Documentation

◆ MDFDocument()

MDFDocument::MDFDocument ( )

The constructor.

Definition at line 54 of file MDFDocument.cc.

54  : model_(NULL) {
55 }

◆ ~MDFDocument()

MDFDocument::~MDFDocument ( )
virtual

The destructor.

Definition at line 61 of file MDFDocument.cc.

61  {
62  if (model_ != NULL) {
63  delete model_;
64  model_ = NULL;
65  }
66 }

References model_.

Member Function Documentation

◆ getModel()

Model * MDFDocument::getModel ( )

Returns document's model.

Returns
Document's model.

Definition at line 229 of file MDFDocument.cc.

229  {
230  return model_;
231 }

References model_.

Referenced by PasteComponentCmd::Do(), and MDFView::OnUpdate().

◆ OnNewDocument()

bool MDFDocument::OnNewDocument ( )
virtual

Creates a new document.

Returns
True, if a new document was succesfully created, false otherwise.

Definition at line 75 of file MDFDocument.cc.

75  {
76  model_ = new Model();
77  model_->addObserver(this);
78  return wxDocument::OnNewDocument();
79 }

References Model::addObserver(), and model_.

Here is the call graph for this function:

◆ OnOpenDocument()

bool MDFDocument::OnOpenDocument ( const wxString &  fileName)
virtual

Opens an .adf or .cfg file. If the opened file extension is .cfg, the architecture file name is read from the configuration.

Parameters
fileNameName of the file to read.
Returns
True if the file was succesfully loaded, false otherwise.

Definition at line 90 of file MDFDocument.cc.

90  {
91 
92  string configExtension = ProDeConstants::PROCESSOR_CONFIG_FILE_EXTENSION;
93  string fileExtension =
95 
96  if (fileExtension == configExtension) {
97  // read .adf filename from the configuration
98  return openCFG(WxConversion::toString(fileName));
99  } else {
100  return openADF(WxConversion::toString(fileName));
101  }
102 
103  assert(false);
104  return false;
105 }

References assert, FileSystem::fileExtension(), openADF(), openCFG(), ProDeConstants::PROCESSOR_CONFIG_FILE_EXTENSION, and WxConversion::toString().

Here is the call graph for this function:

◆ OnSaveDocument()

bool MDFDocument::OnSaveDocument ( const wxString &  filename)
virtual

Writes the machine object model to an mdf file using the mdf writer component and sets the model unmodified.

Parameters
filenameName of the file into which the Model will be saved.

Definition at line 205 of file MDFDocument.cc.

205  {
206 
207  ADFSerializer writer;
208  writer.setDestinationFile(WxConversion::toString(filename));
209  try {
210  writer.writeMachine(*model_->getMachine());
211  } catch (Exception& e) {
212  ErrorDialog errorDialog(GetDocumentWindow(),
214  errorDialog.ShowModal();
215  return false;
216  }
217 
218  Modify(false);
219  return true;
220 }

References Exception::errorMessage(), Model::getMachine(), model_, XMLSerializer::setDestinationFile(), WxConversion::toString(), WxConversion::toWxString(), and ADFSerializer::writeMachine().

Here is the call graph for this function:

◆ openADF()

bool MDFDocument::openADF ( const std::string &  filename)
private

Opens an architecture definition file, and creates model of the architecture.

Parameters
filenameArchitecture file to open.
Returns
True, if the file was succesfully opened, false otherwise.

Definition at line 169 of file MDFDocument.cc.

169  {
170  try {
171  model_ = new Model(filename);
172  model_->addObserver(this);
173  } catch (Exception e) {
174  // Display an error dialog and return false.
176  boost::format fmt =
178  fmt % filename;
179  wxString message = WxConversion::toWxString(fmt.str());
180  message.Append(_T("\n"));
181  message.Append(WxConversion::toWxString(e.errorMessage()));
182  ErrorDialog errorDialog(GetDocumentWindow(), message);
183  errorDialog.ShowModal();
184  return false;
185  }
186 
187  // Update document title.
188  string title = FileSystem::fileOfPath(filename);
189  SetTitle(WxConversion::toWxString(title));
190 
191  // File opened succesfully.
192  Modify(false);
193  UpdateAllViews();
194  return true;
195 }

References Model::addObserver(), Exception::errorMessage(), FileSystem::fileOfPath(), ProDeTextGenerator::instance(), model_, ProDeTextGenerator::MSG_ERROR_LOADING_FILE, Texts::TextGenerator::text(), and WxConversion::toWxString().

Referenced by OnOpenDocument(), and openCFG().

Here is the call graph for this function:

◆ openCFG()

bool MDFDocument::openCFG ( const std::string &  filename)
private

Reads architectrue definition file name from a processor configuration file, and opens the .adf file.

Parameters
filenameConfiguration file to read.
Returns
True, if the adf defined in the .cfg was succesfully opened, false otherwise.

Definition at line 117 of file MDFDocument.cc.

117  {
118 
119  std::fstream cfgFile(filename.c_str());
120 
121  if (cfgFile.fail()) {
122  return false;
123  }
124 
125  ProcessorConfigurationFile cfg(cfgFile);
126  cfg.setPCFDirectory(FileSystem::directoryOfPath(filename));
127 
128  if (cfg.errors()) {
129  // Errors in the .cfg file.
130  // Display error strings in an error dialog.
131  wxString message;
132  for (int i = 0;i < cfg.errorCount();i++) {
133  message.Append(WxConversion::toWxString(cfg.errorString(i)));
134  message.Append(_T("\n\n"));
135  }
136  ErrorDialog dialog(GetDocumentWindow(), message);
137  dialog.ShowModal();
138  return false;
139  }
140 
141  string adfName;
142 
143  try {
144  adfName = cfg.architectureName();
145  } catch (KeyNotFound& e) {
146  wxString message = WxConversion::toWxString(e.errorMessage());
147  ErrorDialog dialog(GetDocumentWindow(), message);
148  dialog.ShowModal();
149  return false;
150  }
151 
152  if(openADF(adfName)) {
153  SetFilename(WxConversion::toWxString(adfName), true);
154  return true;
155  } else {
156  return false;
157  }
158 }

References ProcessorConfigurationFile::architectureName(), FileSystem::directoryOfPath(), ProcessorConfigurationFile::errorCount(), Exception::errorMessage(), ProcessorConfigurationFile::errors(), ProcessorConfigurationFile::errorString(), openADF(), ProcessorConfigurationFile::setPCFDirectory(), and WxConversion::toWxString().

Referenced by OnOpenDocument().

Here is the call graph for this function:

◆ update()

void MDFDocument::update ( )
virtual

Updates the document when the Model changes.

Implements ModelObserver.

Definition at line 238 of file MDFDocument.cc.

238  {
239  if (model_->isModified()) {
240  Modify(true);
242  }
243  UpdateAllViews();
244 }

References Model::isModified(), model_, and Model::setNotModified().

Here is the call graph for this function:

Member Data Documentation

◆ model_

Model* MDFDocument::model_
private

Machine Object Model which the document represents.

Definition at line 67 of file MDFDocument.hh.

Referenced by getModel(), OnNewDocument(), OnSaveDocument(), openADF(), update(), and ~MDFDocument().


The documentation for this class was generated from the following files:
WxConversion::toWxString
static wxString toWxString(const std::string &source)
MDFDocument::model_
Model * model_
Machine Object Model which the document represents.
Definition: MDFDocument.hh:67
ProcessorConfigurationFile
Definition: ProcessorConfigurationFile.hh:46
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
FileSystem::fileOfPath
static std::string fileOfPath(const std::string pathName)
Definition: FileSystem.cc:101
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
assert
#define assert(condition)
Definition: Application.hh:86
Model::setNotModified
void setNotModified()
Definition: Model.hh:65
Model::addObserver
void addObserver(ModelObserver *observer)
Definition: Model.cc:143
ErrorDialog
Definition: ErrorDialog.hh:42
FileSystem::fileExtension
static std::string fileExtension(const std::string &fileName)
Definition: FileSystem.cc:279
ADFSerializer
Definition: ADFSerializer.hh:49
XMLSerializer::setDestinationFile
void setDestinationFile(const std::string &fileName)
Definition: XMLSerializer.cc:142
FileSystem::directoryOfPath
static std::string directoryOfPath(const std::string fileName)
Definition: FileSystem.cc:79
MDFDocument::openADF
bool openADF(const std::string &filename)
Definition: MDFDocument.cc:169
Exception
Definition: Exception.hh:54
MDFDocument::openCFG
bool openCFG(const std::string &filename)
Definition: MDFDocument.cc:117
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
Model
Definition: Model.hh:50
ADFSerializer::writeMachine
void writeMachine(const TTAMachine::Machine &machine)
Definition: ADFSerializer.cc:259
KeyNotFound
Definition: Exception.hh:285
ProDeConstants::PROCESSOR_CONFIG_FILE_EXTENSION
static const std::string PROCESSOR_CONFIG_FILE_EXTENSION
Processor configuration file extension.
Definition: ProDeConstants.hh:394
ProDeTextGenerator::MSG_ERROR_LOADING_FILE
@ MSG_ERROR_LOADING_FILE
Error: File loading failed.
Definition: ProDeTextGenerator.hh:244
Model::isModified
bool isModified() const
Definition: Model.hh:66
WxConversion::toString
static std::string toString(const wxString &source)
Model::getMachine
TTAMachine::Machine * getMachine()
Definition: Model.cc:88