Skip to content

Commit 8d35fe6

Browse files
committed
Save one file packages with correct indentation.
1 parent c56af4b commit 8d35fe6

File tree

8 files changed

+119
-82
lines changed

8 files changed

+119
-82
lines changed

OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ LineAnnotation::LineAnnotation(Component *pStartComponent, GraphicsView *pGraphi
151151
{
152152
setFlag(QGraphicsItem::ItemIsSelectable);
153153
mLineType = LineAnnotation::ConnectionType;
154-
setZValue(2000);
154+
setZValue(1000);
155155
// set the default values
156156
GraphicItem::setDefaults();
157157
ShapeAnnotation::setDefaults();
@@ -172,7 +172,7 @@ LineAnnotation::LineAnnotation(QString annotation, Component *pStartComponent, C
172172
{
173173
setFlag(QGraphicsItem::ItemIsSelectable);
174174
mLineType = LineAnnotation::ConnectionType;
175-
setZValue(2000);
175+
setZValue(1000);
176176
// set the default values
177177
GraphicItem::setDefaults();
178178
ShapeAnnotation::setDefaults();

OMEdit/OMEditGUI/Component/Component.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString tr
186186
GraphicsView *pGraphicsView)
187187
: QGraphicsItem(0), mpReferenceComponent(0), mpParentComponent(0)
188188
{
189-
setZValue(1000);
189+
setZValue(2000);
190190
mpLibraryTreeItem = pLibraryTreeItem;
191191
mpComponentInfo = pComponentInfo;
192192
mpComponentInfo->setName(name);
@@ -261,7 +261,6 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString tr
261261
Component::Component(Component *pComponent, GraphicsView *pGraphicsView, Component *pParent)
262262
: QGraphicsItem(pParent), mpReferenceComponent(pComponent), mpParentComponent(pParent)
263263
{
264-
setZValue(3000);
265264
mpLibraryTreeItem = mpReferenceComponent->getLibraryTreeItem();
266265
mpComponentInfo = mpReferenceComponent->getComponentInfo();
267266
mIsInheritedComponent = mpReferenceComponent->isInheritedComponent();
@@ -288,7 +287,7 @@ Component::Component(Component *pComponent, GraphicsView *pGraphicsView, Compone
288287
Component::Component(Component *pComponent, GraphicsView *pGraphicsView)
289288
: QGraphicsItem(0), mpReferenceComponent(pComponent), mpParentComponent(0)
290289
{
291-
setZValue(1000);
290+
setZValue(2000);
292291
mpLibraryTreeItem = mpReferenceComponent->getLibraryTreeItem();
293292
mpComponentInfo = mpReferenceComponent->getComponentInfo();
294293
mpGraphicsView = pGraphicsView;

OMEdit/OMEditGUI/Component/CornerItem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ void ResizerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
340340
*/
341341
OriginItem::OriginItem(Component *pComponent)
342342
{
343-
setZValue(4000);
343+
setZValue(3000);
344344
mpComponent = pComponent;
345345
mActivePen = QPen(Qt::red, 2);
346346
mActivePen.setCosmetic(true);
@@ -358,7 +358,7 @@ OriginItem::OriginItem(Component *pComponent)
358358
*/
359359
void OriginItem::setActive()
360360
{
361-
setZValue(4000);
361+
setZValue(3000);
362362
if (mpComponent->isInheritedComponent()) {
363363
mPen = mInheritedActivePen;
364364
} else {
@@ -373,7 +373,7 @@ void OriginItem::setActive()
373373
*/
374374
void OriginItem::setPassive()
375375
{
376-
setZValue(-4000);
376+
setZValue(-3000);
377377
mPen = mPassivePen;
378378
}
379379

OMEdit/OMEditGUI/Component/Transformation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Transformation::Transformation(StringHandler::ViewType viewType, QObject *pParen
4444
mViewType = viewType;
4545
mWidth = 200.0;
4646
mHeight = 200.0;
47-
mVisible = false;
47+
mVisible = true;
4848
mOriginDiagram = QPointF(0.0, 0.0);
4949
mHasOriginDiagramX = true;
5050
mHasOriginDiagramY = true;

OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp

Lines changed: 105 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,6 @@ void LibraryTreeModel::createNonExistingLibraryTreeItem(LibraryTreeItem *pLibrar
11781178
OMCProxy *pOMCProxy = mpLibraryWidget->getMainWindow()->getOMCProxy();
11791179
pLibraryTreeItem->setClassInformation(pOMCProxy->getClassInformation(pLibraryTreeItem->getNameStructure()));
11801180
pLibraryTreeItem->setIsSaved(isSaved);
1181-
pLibraryTreeItem->setSystemLibrary(pParentLibraryTreeItem == mpRootLibraryTreeItem ? true : pParentLibraryTreeItem->isSystemLibrary());
11821181
pLibraryTreeItem->setIsProtected(pOMCProxy->isProtectedClass(pParentLibraryTreeItem->getNameStructure(), pLibraryTreeItem->getName()));
11831182
if (pParentLibraryTreeItem->isDocumentationClass()) {
11841183
pLibraryTreeItem->setIsDocumentationClass(true);
@@ -2550,76 +2549,89 @@ void LibraryWidget::openLibraryTreeItem(QString nameStructure)
25502549
bool LibraryWidget::saveModelicaLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem)
25512550
{
25522551
bool result = false;
2553-
if (pLibraryTreeItem->isTopLevel() && pLibraryTreeItem->getChildren().size() == 0) {
2554-
/*
2555-
A root model with no sub models.
2556-
If it is a package then check whether save contents type. Otherwise simply save it to file.
2557-
*/
2558-
if (pLibraryTreeItem->getRestriction() == StringHandler::Package && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveInOneFile) {
2559-
result = saveLibraryTreeItemOneFileHelper(pLibraryTreeItem);
2560-
} else if (pLibraryTreeItem->getRestriction() == StringHandler::Package && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveFolderStructure) {
2561-
result = saveLibraryTreeItemFolderHelper(pLibraryTreeItem);
2562-
} else {
2563-
result = saveLibraryTreeItemHelper(pLibraryTreeItem);
2564-
}
2565-
if (result) {
2566-
getMainWindow()->addRecentFile(pLibraryTreeItem->getFileName(), Helper::utf8);
2567-
/* We need to load the file again so that the line number information for model_info.xml is correct.
2568-
* Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
2569-
* In order to get rid of it save API should update omc with new line information.
2570-
*/
2571-
mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
2572-
}
2573-
} else if (pLibraryTreeItem->isTopLevel() && pLibraryTreeItem->getChildren().size() > 0) {
2574-
/* A root model with sub models.
2575-
* If its a new model then its fileName is <interactive> then check its mSaveContentsType.
2576-
* If mSaveContentsType is LibraryTreeItem::SaveInOneFile then we save all sub models in one file
2552+
LibraryTreeItem *pParentLibraryTreeItem = mpLibraryTreeModel->getContainingParentLibraryTreeItem(pLibraryTreeItem);
2553+
result = saveLibraryTreeItemHelper(pParentLibraryTreeItem);
2554+
if (result && !pLibraryTreeItem->isTopLevel()) {
2555+
setChildLibraryTreeItemsSaved(pParentLibraryTreeItem);
2556+
}
2557+
if (result) {
2558+
getMainWindow()->addRecentFile(pLibraryTreeItem->getFileName(), Helper::utf8);
2559+
/* We need to load the file again so that the line number information for model_info.xml is correct.
2560+
* Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
2561+
* In order to get rid of it save API should update omc with new line information.
25772562
*/
2578-
if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveInOneFile) {
2579-
result = saveLibraryTreeItemOneFileHelper(pLibraryTreeItem);
2580-
} else if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveFolderStructure) {
2581-
/* A root model with sub models.
2582-
* If its a new model then its fileName is <interactive> then check its mSaveContentsType.
2583-
* If mSaveContentsType is LibraryTreeItem::SaveFolderStructure then we save sub models in folder structure
2584-
*/
2585-
result = saveLibraryTreeItemFolderHelper(pLibraryTreeItem);
2586-
} else {
2587-
result = saveLibraryTreeItemOneFileOrFolderHelper(pLibraryTreeItem);
2588-
}
2589-
if (result) {
2590-
getMainWindow()->addRecentFile(pLibraryTreeItem->getFileName(), Helper::utf8);
2591-
/* We need to load the file again so that the line number information for model_info.xml is correct.
2592-
* Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
2593-
* In order to get rid of it save API should update omc with new line information.
2594-
*/
2595-
mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
2596-
}
2597-
} else if (!pLibraryTreeItem->isTopLevel()) {
2598-
/* A sub model contained inside some other model.
2599-
* Find its root model.
2600-
* If the root model fileName is <interactive> then check its mSaveContentsType.
2601-
* If mSaveContentsType is LibraryTreeItem::SaveInOneFile then we save all sub models in one file.
2602-
*/
2603-
pLibraryTreeItem = mpLibraryTreeModel->findLibraryTreeItem(StringHandler::getFirstWordBeforeDot(pLibraryTreeItem->getNameStructure()));
2604-
if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveInOneFile) {
2605-
result = saveLibraryTreeItemOneFileHelper(pLibraryTreeItem);
2606-
}
2607-
/* If mSaveContentsType is LibraryTreeItem::SaveFolderStructure then we save sub models in folder structure
2608-
*/
2609-
else if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveFolderStructure) {
2610-
result = saveLibraryTreeItemFolderHelper(pLibraryTreeItem);
2611-
} else {
2612-
result = saveLibraryTreeItemOneFileOrFolderHelper(pLibraryTreeItem);
2613-
}
2614-
if (result) {
2615-
getMainWindow()->addRecentFile(pLibraryTreeItem->getFileName(), Helper::utf8);
2616-
/* We need to load the file again so that the line number information for model_info.xml is correct.
2617-
* Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
2618-
* In order to get rid of it save API should update omc with new line information.
2619-
*/
2620-
mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
2621-
}
2622-
}
2563+
// mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
2564+
}
2565+
// if (pLibraryTreeItem->isTopLevel() && pLibraryTreeItem->getChildren().size() == 0) {
2566+
// /*
2567+
// A root model with no sub models.
2568+
// If it is a package then check whether save contents type. Otherwise simply save it to file.
2569+
// */
2570+
// if (pLibraryTreeItem->getRestriction() == StringHandler::Package && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveInOneFile) {
2571+
// result = saveLibraryTreeItemOneFileHelper(pLibraryTreeItem);
2572+
// } else if (pLibraryTreeItem->getRestriction() == StringHandler::Package && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveFolderStructure) {
2573+
// result = saveLibraryTreeItemFolderHelper(pLibraryTreeItem);
2574+
// } else {
2575+
// result = saveLibraryTreeItemHelper(pLibraryTreeItem);
2576+
// }
2577+
// if (result) {
2578+
// getMainWindow()->addRecentFile(pLibraryTreeItem->getFileName(), Helper::utf8);
2579+
// /* We need to load the file again so that the line number information for model_info.xml is correct.
2580+
// * Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
2581+
// * In order to get rid of it save API should update omc with new line information.
2582+
// */
2583+
// mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
2584+
// }
2585+
// } else if (pLibraryTreeItem->isTopLevel() && pLibraryTreeItem->getChildren().size() > 0) {
2586+
// /* A root model with sub models.
2587+
// * If its a new model then its fileName is <interactive> then check its mSaveContentsType.
2588+
// * If mSaveContentsType is LibraryTreeItem::SaveInOneFile then we save all sub models in one file
2589+
// */
2590+
// if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveInOneFile) {
2591+
// result = saveLibraryTreeItemOneFileHelper(pLibraryTreeItem);
2592+
// } else if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveFolderStructure) {
2593+
// /* A root model with sub models.
2594+
// * If its a new model then its fileName is <interactive> then check its mSaveContentsType.
2595+
// * If mSaveContentsType is LibraryTreeItem::SaveFolderStructure then we save sub models in folder structure
2596+
// */
2597+
// result = saveLibraryTreeItemFolderHelper(pLibraryTreeItem);
2598+
// } else {
2599+
// result = saveLibraryTreeItemOneFileOrFolderHelper(pLibraryTreeItem);
2600+
// }
2601+
// if (result) {
2602+
// getMainWindow()->addRecentFile(pLibraryTreeItem->getFileName(), Helper::utf8);
2603+
// /* We need to load the file again so that the line number information for model_info.xml is correct.
2604+
// * Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
2605+
// * In order to get rid of it save API should update omc with new line information.
2606+
// */
2607+
// mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
2608+
// }
2609+
// } else if (!pLibraryTreeItem->isTopLevel()) {
2610+
// /* A sub model contained inside some other model.
2611+
// * Find its root model.
2612+
// * If the root model fileName is <interactive> then check its mSaveContentsType.
2613+
// * If mSaveContentsType is LibraryTreeItem::SaveInOneFile then we save all sub models in one file.
2614+
// */
2615+
// pLibraryTreeItem = mpLibraryTreeModel->findLibraryTreeItem(StringHandler::getFirstWordBeforeDot(pLibraryTreeItem->getNameStructure()));
2616+
// if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveInOneFile) {
2617+
// result = saveLibraryTreeItemOneFileHelper(pLibraryTreeItem);
2618+
// }
2619+
// /* If mSaveContentsType is LibraryTreeItem::SaveFolderStructure then we save sub models in folder structure
2620+
// */
2621+
// else if (pLibraryTreeItem->getFileName().isEmpty() && pLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveFolderStructure) {
2622+
// result = saveLibraryTreeItemFolderHelper(pLibraryTreeItem);
2623+
// } else {
2624+
// result = saveLibraryTreeItemOneFileOrFolderHelper(pLibraryTreeItem);
2625+
// }
2626+
// if (result) {
2627+
// getMainWindow()->addRecentFile(pLibraryTreeItem->getFileName(), Helper::utf8);
2628+
// /* We need to load the file again so that the line number information for model_info.xml is correct.
2629+
// * Update to AST (makes source info WRONG), saving it (source info STILL WRONG), reload it (and omc knows the new lines)
2630+
// * In order to get rid of it save API should update omc with new line information.
2631+
// */
2632+
// mpMainWindow->getOMCProxy()->loadFile(pLibraryTreeItem->getFileName());
2633+
// }
2634+
// }
26232635
return result;
26242636
}
26252637

@@ -2776,6 +2788,7 @@ bool LibraryWidget::saveLibraryTreeItemHelper(LibraryTreeItem *pLibraryTreeItem)
27762788
pLibraryTreeItem->getModelWidget()->setWindowTitle(pLibraryTreeItem->getNameStructure());
27772789
pLibraryTreeItem->getModelWidget()->setModelFilePathLabel(fileName);
27782790
}
2791+
mpLibraryTreeModel->updateLibraryTreeItem(pLibraryTreeItem);
27792792
} else {
27802793
QMessageBox::information(this, Helper::applicationName + " - " + Helper::error, GUIMessages::getMessage(GUIMessages::ERROR_OCCURRED)
27812794
.arg(GUIMessages::getMessage(GUIMessages::UNABLE_TO_SAVE_FILE).arg(file.errorString())), Helper::ok);
@@ -2784,6 +2797,28 @@ bool LibraryWidget::saveLibraryTreeItemHelper(LibraryTreeItem *pLibraryTreeItem)
27842797
return true;
27852798
}
27862799

2800+
/*!
2801+
* \brief LibraryWidget::setChildLibraryTreeItemsSaved
2802+
* Marks the child LibraryTreeItems saved.
2803+
* \param pLibraryTreeItem
2804+
*/
2805+
void LibraryWidget::setChildLibraryTreeItemsSaved(LibraryTreeItem *pLibraryTreeItem)
2806+
{
2807+
for (int i = 0; i < pLibraryTreeItem->getChildren().size(); i++) {
2808+
LibraryTreeItem *pChildLibraryTreeItem = pLibraryTreeItem->child(i);
2809+
pChildLibraryTreeItem->setIsSaved(true);
2810+
pChildLibraryTreeItem->setFileName(pLibraryTreeItem->getFileName());
2811+
if (pChildLibraryTreeItem->getModelWidget()) {
2812+
pChildLibraryTreeItem->getModelWidget()->setWindowTitle(pChildLibraryTreeItem->getNameStructure());
2813+
pChildLibraryTreeItem->getModelWidget()->setModelFilePathLabel(pLibraryTreeItem->getFileName());
2814+
}
2815+
mpLibraryTreeModel->updateLibraryTreeItem(pChildLibraryTreeItem);
2816+
if (pChildLibraryTreeItem->getSaveContentsType() == LibraryTreeItem::SaveInOneFile) {
2817+
setChildLibraryTreeItemsSaved(pChildLibraryTreeItem);
2818+
}
2819+
}
2820+
}
2821+
27872822
/*!
27882823
* \brief LibraryWidget::saveLibraryTreeItemOneFileHelper
27892824
* Helper function for saving a LibraryTreeItem.

OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ class LibraryWidget : public QWidget
335335
bool saveTextLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem);
336336
bool saveTLMLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem);
337337
bool saveLibraryTreeItemHelper(LibraryTreeItem *pLibraryTreeItem);
338+
void setChildLibraryTreeItemsSaved(LibraryTreeItem *pLibraryTreeItem);
339+
338340
bool saveLibraryTreeItemOneFileHelper(LibraryTreeItem *pLibraryTreeItem);
339341
bool setSubModelsFileNameOneFileHelper(LibraryTreeItem *pLibraryTreeItem, QString filePath);
340342
void setSubModelsSavedOneFileHelper(LibraryTreeItem *pLibraryTreeItem);

OMEdit/OMEditGUI/Modeling/ModelicaClassDialog.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ void ModelicaClassDialog::createModelicaClass()
321321
parentPackage = "Global Scope";
322322
} else {
323323
model = QString(mpParentClassTextBox->text().trimmed()).append(".").append(mpNameTextBox->text().trimmed());
324-
parentPackage = QString("in Package '").append(mpParentClassTextBox->text().trimmed()).append("'");
324+
parentPackage = QString("Package '").append(mpParentClassTextBox->text().trimmed()).append("'");
325325
}
326326
// Check whether model exists or not.
327327
if (mpMainWindow->getOMCProxy()->existClass(model) || mpMainWindow->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItem(model)) {
@@ -363,6 +363,7 @@ void ModelicaClassDialog::createModelicaClass()
363363
pLibraryTreeModel->loadLibraryTreeItemPixmap(pLibraryTreeItem);
364364
pLibraryTreeModel->loadNonExistingLibraryTreeItem(pLibraryTreeItem);
365365
}
366+
pLibraryTreeItem->setExpanded(true);
366367
// show the ModelWidget
367368
pLibraryTreeModel->showModelWidget(pLibraryTreeItem, "", true, true);
368369
accept();
@@ -672,7 +673,7 @@ void SaveAsClassDialog::saveAsModelicaClass()
672673
else
673674
{
674675
model = QString(mpParentClassComboBox->currentText()).append(".").append(mpNameTextBox->text());
675-
parentPackage = QString("in Package '").append(mpParentClassComboBox->currentText()).append("'");
676+
parentPackage = QString("Package '").append(mpParentClassComboBox->currentText()).append("'");
676677
}
677678
// Check whether model exists or not.
678679
if (mpMainWindow->getOMCProxy()->existClass(model))

OMEdit/OMEditGUI/OMC/OMCProxy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ bool OMCProxy::createSubClass(QString type, QString className, QString parentCla
13951395
} else {
13961396
expression = "within " + parentClassName + "; " + type + " " + className + " extends " + extendsClass + "; end " + className + ";";
13971397
}
1398-
return loadString(expression, parentClassName + "." + className, Helper::utf8, false);
1398+
return loadString(expression, StringHandler::getFirstWordBeforeDot(parentClassName), Helper::utf8, false);
13991399
}
14001400

14011401
/*!

0 commit comments

Comments
 (0)