Skip to content

Commit

Permalink
Fixed loading metamodels.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Mar 8, 2016
1 parent d763c77 commit 6fb638a
Show file tree
Hide file tree
Showing 21 changed files with 365 additions and 229 deletions.
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -1505,6 +1505,6 @@ void CreateConnectionDialog::createArrayConnection()
mpConnectionLineAnnotation->setEndComponentName(endComponentName);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddConnectionCommand(mpConnectionLineAnnotation, true));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitConnectionAdded(mpConnectionLineAnnotation);
mpGraphicsView->getModelWidget()->updateModelicaText();
mpGraphicsView->getModelWidget()->updateModelText();
accept();
}
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/Annotations/ShapePropertiesDialog.cpp
Expand Up @@ -839,14 +839,14 @@ bool ShapePropertiesDialog::applyShapeProperties()
UpdateConnectionCommand *pUpdateConnectionCommand;
pUpdateConnectionCommand = new UpdateConnectionCommand(mpLineAnnotation, mOldAnnotation, mpShapeAnnotation->getOMCShapeAnnotation());
mpShapeAnnotation->getGraphicsView()->getModelWidget()->getUndoStack()->push(pUpdateConnectionCommand);
mpShapeAnnotation->getGraphicsView()->getModelWidget()->updateModelicaText();
mpShapeAnnotation->getGraphicsView()->getModelWidget()->updateModelText();
} else {
// create a UpdateShapeCommand object and push it to the undo stack.
UpdateShapeCommand *pUpdateShapeCommand;
pUpdateShapeCommand = new UpdateShapeCommand(mpShapeAnnotation, mOldAnnotation, mpShapeAnnotation->getOMCShapeAnnotation());
mpShapeAnnotation->getGraphicsView()->getModelWidget()->getUndoStack()->push(pUpdateShapeCommand);
mpShapeAnnotation->getGraphicsView()->getModelWidget()->updateClassAnnotationIfNeeded();
mpShapeAnnotation->getGraphicsView()->getModelWidget()->updateModelicaText();
mpShapeAnnotation->getGraphicsView()->getModelWidget()->updateModelText();
}
return true;
}
Expand Down
5 changes: 3 additions & 2 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -344,7 +344,8 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString tr
createNonExistingComponent();
createDefaultComponent();
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::TLM) {
// parseAnnotationString(Helper::defaultComponentAnnotationString);
mpDefaultComponentRectangle->setVisible(true);
mpDefaultComponentText->setVisible(true);
} else {
drawComponent();
}
Expand Down Expand Up @@ -1711,7 +1712,7 @@ void Component::resizedComponent()
UpdateComponentTransformationsCommand *pUpdateComponentCommand = new UpdateComponentTransformationsCommand(this, mOldTransformation,
mTransformation);
mpGraphicsView->getModelWidget()->getUndoStack()->push(pUpdateComponentCommand);
mpGraphicsView->getModelWidget()->updateModelicaText();
mpGraphicsView->getModelWidget()->updateModelText();
}

/*!
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/Component/ComponentProperties.cpp
Expand Up @@ -953,7 +953,7 @@ void ComponentParameters::updateComponentParameters()
oldComponentExtendsModifiersMap, newComponentModifiersMap,
newComponentExtendsModifiersMap);
mpComponent->getGraphicsView()->getModelWidget()->getUndoStack()->push(pUpdateComponentParametersCommand);
mpComponent->getGraphicsView()->getModelWidget()->updateModelicaText();
mpComponent->getGraphicsView()->getModelWidget()->updateModelText();
}
accept();
}
Expand Down Expand Up @@ -1194,7 +1194,7 @@ void ComponentAttributes::updateComponentAttributes()
UpdateComponentAttributesCommand *pUpdateComponentAttributesCommand = new UpdateComponentAttributesCommand(mpComponent, oldComponentInfo,
newComponentInfo);
pModelWidget->getUndoStack()->push(pUpdateComponentAttributesCommand);
pModelWidget->updateModelicaText();
pModelWidget->updateModelText();
}
accept();
}
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/Component/CornerItem.cpp
Expand Up @@ -152,12 +152,12 @@ void CornerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
mpShapeAnnotation->removeRedundantPointsGeometriesAndCornerItems();
QString newAnnotation = mpShapeAnnotation->getOMCShapeAnnotation();
pModelWidget->getUndoStack()->push(new UpdateConnectionCommand(pLineAnnotation, mOldAnnotation, newAnnotation));
pModelWidget->updateModelicaText();
pModelWidget->updateModelText();
} else {
QString newAnnotation = mpShapeAnnotation->getOMCShapeAnnotation();
pModelWidget->getUndoStack()->push(new UpdateShapeCommand(mpShapeAnnotation, mOldAnnotation, newAnnotation));
pModelWidget->updateClassAnnotationIfNeeded();
pModelWidget->updateModelicaText();
pModelWidget->updateModelText();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Editors/ModelicaTextEditor.cpp
Expand Up @@ -197,7 +197,7 @@ bool ModelicaTextEditor::validateText(LibraryTreeItem **pLibraryTreeItem)
pMessageBox->setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::error));
pMessageBox->setIcon(QMessageBox::Critical);
pMessageBox->setAttribute(Qt::WA_DeleteOnClose);
pMessageBox->setText(GUIMessages::getMessage(GUIMessages::ERROR_IN_MODELICA_TEXT)
pMessageBox->setText(GUIMessages::getMessage(GUIMessages::ERROR_IN_TEXT).arg("Modelica")
.append(GUIMessages::getMessage(GUIMessages::CHECK_MESSAGES_BROWSER))
.append(GUIMessages::getMessage(GUIMessages::REVERT_PREVIOUS_OR_FIX_ERRORS_MANUALLY)));
pMessageBox->addButton(tr("Fix error(s) manually"), QMessageBox::AcceptRole);
Expand Down
172 changes: 116 additions & 56 deletions OMEdit/OMEditGUI/Editors/TLMEditor.cpp
@@ -1,4 +1,3 @@

/*
* This file is part of OpenModelica.
*
Expand Down Expand Up @@ -32,68 +31,68 @@
#include "TLMEditor.h"
#include "ComponentProperties.h"

TLMEditor::TLMEditor(ModelWidget *pModelWidget)
: BaseEditor(pModelWidget), mTextChanged(false)
XMLDocument::XMLDocument()
: QDomDocument()
{
connect(this, SIGNAL(focusOut()), mpModelWidget, SLOT(TLMEditorTextChanged()));

}

/*!
* \brief TLMEditor::showContextMenu
* Create a context menu.
* \param point
*/
void TLMEditor::showContextMenu(QPoint point)
XMLDocument::XMLDocument(TLMEditor *pTLMEditor)
: QDomDocument()
{
QMenu *pMenu = createStandardContextMenu();
pMenu->exec(mapToGlobal(point));
delete pMenu;
mpTLMEditor = pTLMEditor;
}

//! Slot activated when TLMEdit's QTextDocument contentsChanged SIGNAL is raised.
//! Sets the model as modified so that user knows that his current TLM is not saved.
void TLMEditor::contentsHasChanged(int position, int charsRemoved, int charsAdded)
QString XMLDocument::toString() const
{
Q_UNUSED(position);
if (mpModelWidget->isVisible()) {
if (charsRemoved == 0 && charsAdded == 0) {
return;
}
/* if user is changing the text. */
if (!mForceSetPlainText) {
//mpModelWidget->setModelModified();
mTextChanged = true;
}
}
TabSettings tabSettings = mpTLMEditor->getMainWindow()->getOptionsDialog()->getTLMTabSettings();
return QDomDocument::toString(tabSettings.getIndentSize());
}

bool TLMEditor::validateMetaModelText()

TLMEditor::TLMEditor(ModelWidget *pModelWidget)
: BaseEditor(pModelWidget), mLastValidText(""), mTextChanged(false), mForceSetPlainText(false)
{
if (mTextChanged) {
mXmlDocument.setContent(mpPlainTextEdit->toPlainText());
if (!emit focusOut()) {
return false;
} else {
mTextChanged = false;
}
}
return true;
mXmlDocument = XMLDocument(this);
}

/*!
* \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.
* \brief TLMEditor::validateText
* When user make some changes in the TLMEditor text then this method validates the text.
* \return
*/
void TLMEditor::setPlainText(const QString &text)
bool TLMEditor::validateText()
{
if (text != mpPlainTextEdit->toPlainText()) {
mForceSetPlainText = true;
mpPlainTextEdit->setPlainText(text);
mXmlDocument.setContent(text);
mForceSetPlainText = false;
if (mTextChanged) {
// if the user makes few mistakes in the text then dont let him change the perspective
if (!mpModelWidget->TLMEditorTextChanged()) {
QMessageBox *pMessageBox = new QMessageBox(mpMainWindow);
pMessageBox->setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::error));
pMessageBox->setIcon(QMessageBox::Critical);
pMessageBox->setAttribute(Qt::WA_DeleteOnClose);
pMessageBox->setText(GUIMessages::getMessage(GUIMessages::ERROR_IN_TEXT).arg("MetaModel")
.append(GUIMessages::getMessage(GUIMessages::CHECK_MESSAGES_BROWSER))
.append(GUIMessages::getMessage(GUIMessages::REVERT_PREVIOUS_OR_FIX_ERRORS_MANUALLY)));
pMessageBox->addButton(tr("Fix error(s) manually"), QMessageBox::AcceptRole);
pMessageBox->addButton(tr("Revert to last correct version"), QMessageBox::RejectRole);
int answer = pMessageBox->exec();
switch (answer) {
case QMessageBox::RejectRole:
mTextChanged = false;
// revert back to last correct version
setPlainText(mLastValidText);
return true;
case QMessageBox::AcceptRole:
default:
mTextChanged = true;
return false;
}
} else {
mTextChanged = false;
mLastValidText = mpPlainTextEdit->toPlainText();
}
}
return true;
}

/*!
Expand Down Expand Up @@ -192,7 +191,7 @@ bool TLMEditor::addSubModel(QString name, QString exactStep, QString modelFile,
annotation.setAttribute("Rotation", rotation);
subModel.appendChild(annotation);
subModels.appendChild(subModel);
mpPlainTextEdit->setPlainText(mXmlDocument.toString());
setPlainText(mXmlDocument.toString());
return true;
}
return false;
Expand All @@ -215,7 +214,7 @@ void TLMEditor::createAnnotationElement(QDomElement subModel, QString visible, Q
annotation.setAttribute("Extent", extent);
annotation.setAttribute("Rotation", rotation);
subModel.insertBefore(annotation, QDomNode());
mpPlainTextEdit->setPlainText(mXmlDocument.toString());
setPlainText(mXmlDocument.toString());
}

/*!
Expand All @@ -241,7 +240,7 @@ void TLMEditor::updateSubModelPlacementAnnotation(QString name, QString visible,
annotationElement.setAttribute("Origin", origin);
annotationElement.setAttribute("Extent", extent);
annotationElement.setAttribute("Rotation", rotation);
mpPlainTextEdit->setPlainText(mXmlDocument.toString());
setPlainText(mXmlDocument.toString());
return;
}
}
Expand All @@ -267,7 +266,7 @@ void TLMEditor::updateSubModelParameters(QString name, QString startCommand, QSt
if (subModel.attribute("Name").compare(name) == 0) {
subModel.setAttribute("StartCommand", startCommand);
subModel.setAttribute("ExactStep", exactStepFlag);
mpPlainTextEdit->setPlainText(mXmlDocument.toString());
setPlainText(mXmlDocument.toString());
return;
}
}
Expand Down Expand Up @@ -321,7 +320,7 @@ bool TLMEditor::createConnection(QString from, QString to, QString delay, QStrin
annotation.setAttribute("Points", points);
connection.appendChild(annotation);
connections.appendChild(connection);
mpPlainTextEdit->setPlainText(mXmlDocument.toString());
setPlainText(mXmlDocument.toString());
return true;
}
return false;
Expand All @@ -346,7 +345,7 @@ void TLMEditor::updateTLMConnectiontAnnotation(QString fromSubModel, QString toS
QDomElement annotationElement = connectionChildren.at(j).toElement();
if (annotationElement.tagName().compare("Annotation") == 0) {
annotationElement.setAttribute("Points", points);
mpPlainTextEdit->setPlainText(mXmlDocument.toString());
setPlainText(mXmlDocument.toString());
return;
}
}
Expand Down Expand Up @@ -374,7 +373,7 @@ void TLMEditor::addInterfacesData(QDomElement interfaces)
interfacePoint.setAttribute("Position",interfaceDataElement.attribute("Position"));
interfacePoint.setAttribute("Angle321",interfaceDataElement.attribute("Angle321"));
subModel.appendChild(interfacePoint);
mpPlainTextEdit->setPlainText(mXmlDocument.toString());
setPlainText(mXmlDocument.toString());

TLMInterfacePointInfo *pTLMInterfacePointInfo;
pTLMInterfacePointInfo = new TLMInterfacePointInfo(subModel.attribute("Name"),"shaft3" , interfaceDataElement.attribute("name"));
Expand Down Expand Up @@ -424,7 +423,7 @@ bool TLMEditor::deleteSubModel(QString name)
QDomElement subModels = getSubModelsElement();
if (!subModels.isNull()) {
subModels.removeChild(subModel);
mpPlainTextEdit->setPlainText(mXmlDocument.toString());
setPlainText(mXmlDocument.toString());
return true;
}
break;
Expand All @@ -450,7 +449,7 @@ bool TLMEditor::deleteConnection(QString startSubModelName, QString endSubModelN
QDomElement connections = getConnectionsElement();
if (!connections.isNull()) {
connections.removeChild(connection);
mpPlainTextEdit->setPlainText(mXmlDocument.toString());
setPlainText(mXmlDocument.toString());
return true;
}
break;
Expand All @@ -459,6 +458,67 @@ bool TLMEditor::deleteConnection(QString startSubModelName, QString endSubModelN
return false;
}

/*!
* \brief TLMEditor::showContextMenu
* Create a context menu.
* \param point
*/
void TLMEditor::showContextMenu(QPoint point)
{
QMenu *pMenu = createStandardContextMenu();
pMenu->exec(mapToGlobal(point));
delete pMenu;
}

/*!
* \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;
mXmlDocument.setContent(text);
// use the text from mXmlDocument so that we can map error to line numbers. We don't care about users formatting in the file.
mpPlainTextEdit->setPlainText(mXmlDocument.toString());
mForceSetPlainText = false;
mLastValidText = text;
}
}

/*!
* \brief TLMEditor::contentsHasChanged
* Slot activated when TLMEdit's QTextDocument contentsChanged SIGNAL is raised.\n
* Sets the model as modified so that user knows that his current TLM is not saved.
* \param position
* \param charsRemoved
* \param charsAdded
*/
void TLMEditor::contentsHasChanged(int position, int charsRemoved, int charsAdded)
{
Q_UNUSED(position);
if (mpModelWidget->isVisible()) {
if (charsRemoved == 0 && charsAdded == 0) {
return;
}
/* if user is changing the read only file. */
if (mpModelWidget->getLibraryTreeItem()->isReadOnly() && !mForceSetPlainText) {
/* if user is changing the read-only class. */
mpMainWindow->getInfoBar()->showMessage(tr("<b>Warning: </b>You are changing a read-only class."));
} else {
/* if user is changing, the normal file. */
if (!mForceSetPlainText) {
mpModelWidget->setWindowTitle(QString(mpModelWidget->getLibraryTreeItem()->getNameStructure()).append("*"));
mpModelWidget->getLibraryTreeItem()->setIsSaved(false);
mpMainWindow->getLibraryWidget()->getLibraryTreeModel()->updateLibraryTreeItem(mpModelWidget->getLibraryTreeItem());
mTextChanged = true;
}
}
}
}

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

Expand Down

0 comments on commit 6fb638a

Please sign in to comment.