OpenASIP 2.2
Loading...
Searching...
No Matches
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.
 

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}
Model * model_
Machine Object Model which the document represents.

◆ ~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}
Definition Model.hh:50
void addObserver(ModelObserver *observer)
Definition Model.cc:143

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
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}
#define assert(condition)
static std::string fileExtension(const std::string &fileName)
bool openADF(const std::string &filename)
bool openCFG(const std::string &filename)
static const std::string PROCESSOR_CONFIG_FILE_EXTENSION
Processor configuration file extension.
static std::string toString(const wxString &source)

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;
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}
void writeMachine(const TTAMachine::Machine &machine)
std::string errorMessage() const
Definition Exception.cc:123
TTAMachine::Machine * getMachine()
Definition Model.cc:88
static wxString toWxString(const std::string &source)
void setDestinationFile(const std::string &fileName)

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 const& 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}
static std::string fileOfPath(const std::string pathName)
static ProDeTextGenerator * instance()
@ MSG_ERROR_LOADING_FILE
Error: File loading failed.
virtual boost::format text(int textId)

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}
static std::string directoryOfPath(const std::string fileName)
Definition FileSystem.cc:79

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}
bool isModified() const
Definition Model.hh:66
void setNotModified()
Definition Model.hh:65

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: