Skip to content

Commit

Permalink
- Read interface data from the xml file
Browse files Browse the repository at this point in the history
- show the metamodel file unsaved if and only if the file is modified
  • Loading branch information
alash325 committed Jun 8, 2015
1 parent c2b4b82 commit 4fe0377
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 13 deletions.
35 changes: 28 additions & 7 deletions OMEdit/OMEditGUI/Editors/TLMEditor.cpp
Expand Up @@ -32,7 +32,7 @@
#include "TLMEditor.h"

TLMEditor::TLMEditor(ModelWidget *pModelWidget)
: BaseEditor(pModelWidget)
: BaseEditor(pModelWidget), mTextChanged(false)
{
connect(this, SIGNAL(focusOut()), mpModelWidget, SLOT(TLMEditorTextChanged()));
}
Expand All @@ -54,20 +54,41 @@ void TLMEditor::showContextMenu(QPoint point)
void TLMEditor::contentsHasChanged(int position, int charsRemoved, int charsAdded)
{
Q_UNUSED(position);
if (mpModelWidget->isVisible())
{
if (charsRemoved == 0 && charsAdded == 0)
if (mpModelWidget->isVisible()) {
if (charsRemoved == 0 && charsAdded == 0) {
return;
mpModelWidget->setModelModified();
}
/* if user is changing the text. */
if (!mForceSetPlainText) {
mpModelWidget->setModelModified();
mTextChanged = true;
}
}
}

bool TLMEditor::TLMEditorFocusChanged()
bool TLMEditor::validateMetaModelText()
{
emit focusOut();
if (mTextChanged) {
emit focusOut();
}
return true;
}

/*!
* \brief TLMEditor::setPlainText
* Reimplementation of QPlainTextEdit::setPlainText method.
* Makes sure we dont update if the passed text is same.
* \param text the string to set.
*/
void TLMEditor::setPlainText(const QString &text)
{
if (text != mpPlainTextEdit->toPlainText()) {
mForceSetPlainText = true;
mpPlainTextEdit->setPlainText(text);
mForceSetPlainText = false;
}
}

//! @class TLMHighlighter
//! @brief A syntax highlighter for TLMEditor.

Expand Down
6 changes: 5 additions & 1 deletion OMEdit/OMEditGUI/Editors/TLMEditor.h
Expand Up @@ -47,7 +47,11 @@ class TLMEditor : public BaseEditor
Q_OBJECT
public:
TLMEditor(ModelWidget *pModelWidget);
bool TLMEditorFocusChanged();
bool validateMetaModelText();
void setPlainText(const QString &text);
private:
bool mForceSetPlainText;
bool mTextChanged;
signals:
bool focusOut();
private slots:
Expand Down
53 changes: 52 additions & 1 deletion OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -2915,7 +2915,58 @@ void MainWindow::fetchInterfaceDataHelper(LibraryTreeNode *pLibraryTreeNode)
pManagerProcess->start(mpOptionsDialog->getTLMPage()->getTLMManagerProcessTextBox()->text(), args);
pManagerProcess->waitForFinished();

/*! @todo Read the interfaceData.xml file here */
/*! Read the interfaceData.xml file here */
QFile file(fileInfo.absoluteDir().absolutePath()+ "/interfaceData.xml");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox::critical(this, QString(Helper::applicationName).append(" - ").append(Helper::error),
GUIMessages::getMessage(GUIMessages::ERROR_OPENING_FILE).arg("interfacedata.xml")
.arg(file.errorString()), Helper::ok);
}
else {
QDomDocument interfaceData;
if (!interfaceData.setContent(&file)) {
file.close();
}
file.close();
// Get the "Root" element
QDomElement interfaces = interfaceData.documentElement();
QDomElement interfaceDataElement = interfaces.firstChildElement();
while (!interfaceDataElement.isNull()) {
if(interfaceDataElement.tagName() == "Interface")
break;
interfaceDataElement = interfaceDataElement.nextSiblingElement();
}

QDomDocument doc;
doc.setContent(pLibraryTreeNode->getModelWidget()->getEditor()->getPlainTextEdit()->toPlainText());

// Get the "Root" element
QDomElement docElem = doc.documentElement();
QDomElement subModels = docElem.firstChildElement();
while (!subModels.isNull()) {
if(subModels.tagName() == "SubModels")
break;
subModels = subModels.nextSiblingElement();
}
QDomElement subModel = subModels.firstChildElement();
while (!subModel.isNull()) {
QDomElement interfaceDataElement = interfaces.firstChildElement();
while(!interfaceDataElement.isNull()){
if(subModel.tagName() == "SubModel" && subModel.attribute("Name") == interfaceDataElement.attribute("model") ) {
QDomElement interfacePoint = doc.createElement("InterfacePoint");
interfacePoint.setAttribute("Name",interfaceDataElement.attribute("name") );
interfacePoint.setAttribute("Position",interfaceDataElement.attribute("Position") );
interfacePoint.setAttribute("Angle321",interfaceDataElement.attribute("Angle321") );
subModel.appendChild(interfacePoint);
break;
}
interfaceDataElement = interfaceDataElement.nextSiblingElement();
}
subModel = subModel.nextSiblingElement();
}
QString metaModelText = doc.toString();
pLibraryTreeNode->getModelWidget()->getEditor()->getPlainTextEdit()->setPlainText(metaModelText);
}
}

//! Creates the toolbars
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -1951,7 +1951,7 @@ void LibraryTreeWidget::openTLMFile(QFileInfo fileInfo, bool showProgress)
}
}
// create a LibraryTreeNode for new loaded TLM file.
LibraryTreeNode *pLibraryTreeNode = addLibraryTreeNode(LibraryTreeNode::TLM, fileInfo.completeBaseName(), false);
LibraryTreeNode *pLibraryTreeNode = addLibraryTreeNode(LibraryTreeNode::TLM, fileInfo.completeBaseName(), true);
if (pLibraryTreeNode) {
pLibraryTreeNode->setSaveContentsType(LibraryTreeNode::SaveInOneFile);
pLibraryTreeNode->setIsSaved(true);
Expand Down
8 changes: 5 additions & 3 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -2237,15 +2237,17 @@ ModelWidget::ModelWidget(LibraryTreeNode* pLibraryTreeNode, ModelWidgetContainer
" <!-- Parameters for the simulation -->\n"
" <SimulationParams StartTime=\"0\" StopTime=\"1\" />\n"
"</Model>").arg(mpLibraryTreeNode->getName());
mpEditor->getPlainTextEdit()->setPlainText(defaultMetaModelText);
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpEditor);
pTLMEditor->setPlainText(defaultMetaModelText);
} else {
QFile file(mpLibraryTreeNode->getFileName());
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, QString(Helper::applicationName).append(" - ").append(Helper::error),
GUIMessages::getMessage(GUIMessages::ERROR_OPENING_FILE).arg(mpLibraryTreeNode->getFileName())
.arg(file.errorString()), Helper::ok);
} else {
mpEditor->getPlainTextEdit()->setPlainText(QString(file.readAll()));
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpEditor);
pTLMEditor->setPlainText(QString(file.readAll()));
file.close();
}
}
Expand Down Expand Up @@ -2846,7 +2848,7 @@ void ModelWidget::showDiagramView(bool checked)
return;
}
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpEditor);
if (pTLMEditor && !pTLMEditor->TLMEditorFocusChanged()) {
if (pTLMEditor && !pTLMEditor->validateMetaModelText()) {
mpTextViewToolButton->setChecked(true);
return;
}
Expand Down

0 comments on commit 4fe0377

Please sign in to comment.