Skip to content

Commit

Permalink
Save one file packages with correct indentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Oct 9, 2015
1 parent a9cfc40 commit 61693d9
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 82 deletions.
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -151,7 +151,7 @@ LineAnnotation::LineAnnotation(Component *pStartComponent, GraphicsView *pGraphi
{
setFlag(QGraphicsItem::ItemIsSelectable);
mLineType = LineAnnotation::ConnectionType;
setZValue(2000);
setZValue(1000);
// set the default values
GraphicItem::setDefaults();
ShapeAnnotation::setDefaults();
Expand All @@ -172,7 +172,7 @@ LineAnnotation::LineAnnotation(QString annotation, Component *pStartComponent, C
{
setFlag(QGraphicsItem::ItemIsSelectable);
mLineType = LineAnnotation::ConnectionType;
setZValue(2000);
setZValue(1000);
// set the default values
GraphicItem::setDefaults();
ShapeAnnotation::setDefaults();
Expand Down
5 changes: 2 additions & 3 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -186,7 +186,7 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString tr
GraphicsView *pGraphicsView)
: QGraphicsItem(0), mpReferenceComponent(0), mpParentComponent(0)
{
setZValue(1000);
setZValue(2000);
mpLibraryTreeItem = pLibraryTreeItem;
mpComponentInfo = pComponentInfo;
mpComponentInfo->setName(name);
Expand Down Expand Up @@ -261,7 +261,6 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString tr
Component::Component(Component *pComponent, GraphicsView *pGraphicsView, Component *pParent)
: QGraphicsItem(pParent), mpReferenceComponent(pComponent), mpParentComponent(pParent)
{
setZValue(3000);
mpLibraryTreeItem = mpReferenceComponent->getLibraryTreeItem();
mpComponentInfo = mpReferenceComponent->getComponentInfo();
mIsInheritedComponent = mpReferenceComponent->isInheritedComponent();
Expand All @@ -288,7 +287,7 @@ Component::Component(Component *pComponent, GraphicsView *pGraphicsView, Compone
Component::Component(Component *pComponent, GraphicsView *pGraphicsView)
: QGraphicsItem(0), mpReferenceComponent(pComponent), mpParentComponent(0)
{
setZValue(1000);
setZValue(2000);
mpLibraryTreeItem = mpReferenceComponent->getLibraryTreeItem();
mpComponentInfo = mpReferenceComponent->getComponentInfo();
mpGraphicsView = pGraphicsView;
Expand Down
6 changes: 3 additions & 3 deletions OMEdit/OMEditGUI/Component/CornerItem.cpp
Expand Up @@ -340,7 +340,7 @@ void ResizerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
*/
OriginItem::OriginItem(Component *pComponent)
{
setZValue(4000);
setZValue(3000);
mpComponent = pComponent;
mActivePen = QPen(Qt::red, 2);
mActivePen.setCosmetic(true);
Expand All @@ -358,7 +358,7 @@ OriginItem::OriginItem(Component *pComponent)
*/
void OriginItem::setActive()
{
setZValue(4000);
setZValue(3000);
if (mpComponent->isInheritedComponent()) {
mPen = mInheritedActivePen;
} else {
Expand All @@ -373,7 +373,7 @@ void OriginItem::setActive()
*/
void OriginItem::setPassive()
{
setZValue(-4000);
setZValue(-3000);
mPen = mPassivePen;
}

Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Component/Transformation.cpp
Expand Up @@ -44,7 +44,7 @@ Transformation::Transformation(StringHandler::ViewType viewType, QObject *pParen
mViewType = viewType;
mWidth = 200.0;
mHeight = 200.0;
mVisible = false;
mVisible = true;
mOriginDiagram = QPointF(0.0, 0.0);
mHasOriginDiagramX = true;
mHasOriginDiagramY = true;
Expand Down
175 changes: 105 additions & 70 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -1178,7 +1178,6 @@ void LibraryTreeModel::createNonExistingLibraryTreeItem(LibraryTreeItem *pLibrar
OMCProxy *pOMCProxy = mpLibraryWidget->getMainWindow()->getOMCProxy();
pLibraryTreeItem->setClassInformation(pOMCProxy->getClassInformation(pLibraryTreeItem->getNameStructure()));
pLibraryTreeItem->setIsSaved(isSaved);
pLibraryTreeItem->setSystemLibrary(pParentLibraryTreeItem == mpRootLibraryTreeItem ? true : pParentLibraryTreeItem->isSystemLibrary());
pLibraryTreeItem->setIsProtected(pOMCProxy->isProtectedClass(pParentLibraryTreeItem->getNameStructure(), pLibraryTreeItem->getName()));
if (pParentLibraryTreeItem->isDocumentationClass()) {
pLibraryTreeItem->setIsDocumentationClass(true);
Expand Down Expand Up @@ -2550,76 +2549,89 @@ void LibraryWidget::openLibraryTreeItem(QString nameStructure)
bool LibraryWidget::saveModelicaLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem)
{
bool result = false;
if (pLibraryTreeItem->isTopLevel() && pLibraryTreeItem->getChildren().size() == 0) {
/*
A root model with no sub models.
If it is a package then check whether save contents type. Otherwise simply save it to file.
*/
if (pLibraryTreeItem->getRestriction() == StringHandler::Package && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveInOneFile) {
result = saveLibraryTreeItemOneFileHelper(pLibraryTreeItem);
} else if (pLibraryTreeItem->getRestriction() == StringHandler::Package && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveFolderStructure) {
result = saveLibraryTreeItemFolderHelper(pLibraryTreeItem);
} else {
result = saveLibraryTreeItemHelper(pLibraryTreeItem);
}
if (result) {
getMainWindow()->addRecentFile(pLibraryTreeItem->getFileName(), Helper::utf8);
/* We need to load the file again so that the line number information for model_info.xml is correct.
* Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
* In order to get rid of it save API should update omc with new line information.
*/
mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
}
} else if (pLibraryTreeItem->isTopLevel() && pLibraryTreeItem->getChildren().size() > 0) {
/* A root model with sub models.
* If its a new model then its fileName is <interactive> then check its mSaveContentsType.
* If mSaveContentsType is LibraryTreeItem::SaveInOneFile then we save all sub models in one file
LibraryTreeItem *pParentLibraryTreeItem = mpLibraryTreeModel->getContainingParentLibraryTreeItem(pLibraryTreeItem);
result = saveLibraryTreeItemHelper(pParentLibraryTreeItem);
if (result && !pLibraryTreeItem->isTopLevel()) {
setChildLibraryTreeItemsSaved(pParentLibraryTreeItem);
}
if (result) {
getMainWindow()->addRecentFile(pLibraryTreeItem->getFileName(), Helper::utf8);
/* We need to load the file again so that the line number information for model_info.xml is correct.
* Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
* In order to get rid of it save API should update omc with new line information.
*/
if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveInOneFile) {
result = saveLibraryTreeItemOneFileHelper(pLibraryTreeItem);
} else if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveFolderStructure) {
/* A root model with sub models.
* If its a new model then its fileName is <interactive> then check its mSaveContentsType.
* If mSaveContentsType is LibraryTreeItem::SaveFolderStructure then we save sub models in folder structure
*/
result = saveLibraryTreeItemFolderHelper(pLibraryTreeItem);
} else {
result = saveLibraryTreeItemOneFileOrFolderHelper(pLibraryTreeItem);
}
if (result) {
getMainWindow()->addRecentFile(pLibraryTreeItem->getFileName(), Helper::utf8);
/* We need to load the file again so that the line number information for model_info.xml is correct.
* Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
* In order to get rid of it save API should update omc with new line information.
*/
mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
}
} else if (!pLibraryTreeItem->isTopLevel()) {
/* A sub model contained inside some other model.
* Find its root model.
* If the root model fileName is <interactive> then check its mSaveContentsType.
* If mSaveContentsType is LibraryTreeItem::SaveInOneFile then we save all sub models in one file.
*/
pLibraryTreeItem = mpLibraryTreeModel->findLibraryTreeItem(StringHandler::getFirstWordBeforeDot(pLibraryTreeItem->getNameStructure()));
if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveInOneFile) {
result = saveLibraryTreeItemOneFileHelper(pLibraryTreeItem);
}
/* If mSaveContentsType is LibraryTreeItem::SaveFolderStructure then we save sub models in folder structure
*/
else if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveFolderStructure) {
result = saveLibraryTreeItemFolderHelper(pLibraryTreeItem);
} else {
result = saveLibraryTreeItemOneFileOrFolderHelper(pLibraryTreeItem);
}
if (result) {
getMainWindow()->addRecentFile(pLibraryTreeItem->getFileName(), Helper::utf8);
/* We need to load the file again so that the line number information for model_info.xml is correct.
* Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
* In order to get rid of it save API should update omc with new line information.
*/
mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
}
}
// mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
}
// if (pLibraryTreeItem->isTopLevel() && pLibraryTreeItem->getChildren().size() == 0) {
// /*
// A root model with no sub models.
// If it is a package then check whether save contents type. Otherwise simply save it to file.
// */
// if (pLibraryTreeItem->getRestriction() == StringHandler::Package && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveInOneFile) {
// result = saveLibraryTreeItemOneFileHelper(pLibraryTreeItem);
// } else if (pLibraryTreeItem->getRestriction() == StringHandler::Package && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveFolderStructure) {
// result = saveLibraryTreeItemFolderHelper(pLibraryTreeItem);
// } else {
// result = saveLibraryTreeItemHelper(pLibraryTreeItem);
// }
// if (result) {
// getMainWindow()->addRecentFile(pLibraryTreeItem->getFileName(), Helper::utf8);
// /* We need to load the file again so that the line number information for model_info.xml is correct.
// * Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
// * In order to get rid of it save API should update omc with new line information.
// */
// mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
// }
// } else if (pLibraryTreeItem->isTopLevel() && pLibraryTreeItem->getChildren().size() > 0) {
// /* A root model with sub models.
// * If its a new model then its fileName is <interactive> then check its mSaveContentsType.
// * If mSaveContentsType is LibraryTreeItem::SaveInOneFile then we save all sub models in one file
// */
// if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveInOneFile) {
// result = saveLibraryTreeItemOneFileHelper(pLibraryTreeItem);
// } else if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveFolderStructure) {
// /* A root model with sub models.
// * If its a new model then its fileName is <interactive> then check its mSaveContentsType.
// * If mSaveContentsType is LibraryTreeItem::SaveFolderStructure then we save sub models in folder structure
// */
// result = saveLibraryTreeItemFolderHelper(pLibraryTreeItem);
// } else {
// result = saveLibraryTreeItemOneFileOrFolderHelper(pLibraryTreeItem);
// }
// if (result) {
// getMainWindow()->addRecentFile(pLibraryTreeItem->getFileName(), Helper::utf8);
// /* We need to load the file again so that the line number information for model_info.xml is correct.
// * Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
// * In order to get rid of it save API should update omc with new line information.
// */
// mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
// }
// } else if (!pLibraryTreeItem->isTopLevel()) {
// /* A sub model contained inside some other model.
// * Find its root model.
// * If the root model fileName is <interactive> then check its mSaveContentsType.
// * If mSaveContentsType is LibraryTreeItem::SaveInOneFile then we save all sub models in one file.
// */
// pLibraryTreeItem = mpLibraryTreeModel->findLibraryTreeItem(StringHandler::getFirstWordBeforeDot(pLibraryTreeItem->getNameStructure()));
// if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveInOneFile) {
// result = saveLibraryTreeItemOneFileHelper(pLibraryTreeItem);
// }
// /* If mSaveContentsType is LibraryTreeItem::SaveFolderStructure then we save sub models in folder structure
// */
// else if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveFolderStructure) {
// result = saveLibraryTreeItemFolderHelper(pLibraryTreeItem);
// } else {
// result = saveLibraryTreeItemOneFileOrFolderHelper(pLibraryTreeItem);
// }
// if (result) {
// getMainWindow()->addRecentFile(pLibraryTreeItem->getFileName(), Helper::utf8);
// /* We need to load the file again so that the line number information for model_info.xml is correct.
// * Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
// * In order to get rid of it save API should update omc with new line information.
// */
// mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
// }
// }
return result;
}

Expand Down Expand Up @@ -2776,6 +2788,7 @@ bool LibraryWidget::saveLibraryTreeItemHelper(LibraryTreeItem *pLibraryTreeItem)
pLibraryTreeItem->getModelWidget()->setWindowTitle(pLibraryTreeItem->getNameStructure());
pLibraryTreeItem->getModelWidget()->setModelFilePathLabel(fileName);
}
mpLibraryTreeModel->updateLibraryTreeItem(pLibraryTreeItem);
} else {
QMessageBox::information(this, Helper::applicationName + " - " + Helper::error, GUIMessages::getMessage(GUIMessages::ERROR_OCCURRED)
.arg(GUIMessages::getMessage(GUIMessages::UNABLE_TO_SAVE_FILE).arg(file.errorString())), Helper::ok);
Expand All @@ -2784,6 +2797,28 @@ bool LibraryWidget::saveLibraryTreeItemHelper(LibraryTreeItem *pLibraryTreeItem)
return true;
}

/*!
* \brief LibraryWidget::setChildLibraryTreeItemsSaved
* Marks the child LibraryTreeItems saved.
* \param pLibraryTreeItem
*/
void LibraryWidget::setChildLibraryTreeItemsSaved(LibraryTreeItem *pLibraryTreeItem)
{
for (int i = 0; i < pLibraryTreeItem->getChildren().size(); i++) {
LibraryTreeItem *pChildLibraryTreeItem = pLibraryTreeItem->child(i);
pChildLibraryTreeItem->setIsSaved(true);
pChildLibraryTreeItem->setFileName(pLibraryTreeItem->getFileName());
if (pChildLibraryTreeItem->getModelWidget()) {
pChildLibraryTreeItem->getModelWidget()->setWindowTitle(pChildLibraryTreeItem->getNameStructure());
pChildLibraryTreeItem->getModelWidget()->setModelFilePathLabel(pLibraryTreeItem->getFileName());
}
mpLibraryTreeModel->updateLibraryTreeItem(pChildLibraryTreeItem);
if (pChildLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveInOneFile) {
setChildLibraryTreeItemsSaved(pChildLibraryTreeItem);
}
}
}

/*!
* \brief LibraryWidget::saveLibraryTreeItemOneFileHelper
* Helper function for saving a LibraryTreeItem.
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h
Expand Up @@ -335,6 +335,8 @@ class LibraryWidget : public QWidget
bool saveTextLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem);
bool saveTLMLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem);
bool saveLibraryTreeItemHelper(LibraryTreeItem *pLibraryTreeItem);
void setChildLibraryTreeItemsSaved(LibraryTreeItem *pLibraryTreeItem);

bool saveLibraryTreeItemOneFileHelper(LibraryTreeItem *pLibraryTreeItem);
bool setSubModelsFileNameOneFileHelper(LibraryTreeItem *pLibraryTreeItem, QString filePath);
void setSubModelsSavedOneFileHelper(LibraryTreeItem *pLibraryTreeItem);
Expand Down
5 changes: 3 additions & 2 deletions OMEdit/OMEditGUI/Modeling/ModelicaClassDialog.cpp
Expand Up @@ -321,7 +321,7 @@ void ModelicaClassDialog::createModelicaClass()
parentPackage = "Global Scope";
} else {
model = QString(mpParentClassTextBox->text().trimmed()).append(".").append(mpNameTextBox->text().trimmed());
parentPackage = QString("in Package '").append(mpParentClassTextBox->text().trimmed()).append("'");
parentPackage = QString("Package '").append(mpParentClassTextBox->text().trimmed()).append("'");
}
// Check whether model exists or not.
if (mpMainWindow->getOMCProxy()->existClass(model) || mpMainWindow->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItem(model)) {
Expand Down Expand Up @@ -363,6 +363,7 @@ void ModelicaClassDialog::createModelicaClass()
pLibraryTreeModel->loadLibraryTreeItemPixmap(pLibraryTreeItem);
pLibraryTreeModel->loadNonExistingLibraryTreeItem(pLibraryTreeItem);
}
pLibraryTreeItem->setExpanded(true);
// show the ModelWidget
pLibraryTreeModel->showModelWidget(pLibraryTreeItem, "", true, true);
accept();
Expand Down Expand Up @@ -672,7 +673,7 @@ void SaveAsClassDialog::saveAsModelicaClass()
else
{
model = QString(mpParentClassComboBox->currentText()).append(".").append(mpNameTextBox->text());
parentPackage = QString("in Package '").append(mpParentClassComboBox->currentText()).append("'");
parentPackage = QString("Package '").append(mpParentClassComboBox->currentText()).append("'");
}
// Check whether model exists or not.
if (mpMainWindow->getOMCProxy()->existClass(model))
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -1395,7 +1395,7 @@ bool OMCProxy::createSubClass(QString type, QString className, QString parentCla
} else {
expression = "within " + parentClassName + "; " + type + " " + className + " extends " + extendsClass + "; end " + className + ";";
}
return loadString(expression, parentClassName + "." + className, Helper::utf8, false);
return loadString(expression, StringHandler::getFirstWordBeforeDot(parentClassName), Helper::utf8, false);
}

/*!
Expand Down

0 comments on commit 61693d9

Please sign in to comment.