Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Commit 066657b

Browse files
committed
Delete system
1 parent d132392 commit 066657b

3 files changed

Lines changed: 106 additions & 10 deletions

File tree

OMEdit/OMEditGUI/Modeling/Commands.cpp

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,9 +1847,6 @@ void AddSystemCommand::redoInternal()
18471847
LibraryTreeModel *pLibraryTreeModel = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel();
18481848
mpLibraryTreeItem = pLibraryTreeModel->createLibraryTreeItem(mName, nameStructure, pParentLibraryTreeItem->getFileName(),
18491849
pParentLibraryTreeItem->isSaved(), pParentLibraryTreeItem, pOMSElement);
1850-
if (!mOpeningClass) {
1851-
mpLibraryTreeItem->handleIconUpdated();
1852-
}
18531850
}
18541851
// add the FMU to view
18551852
ComponentInfo *pComponentInfo = new ComponentInfo;
@@ -1890,6 +1887,74 @@ void AddSystemCommand::undo()
18901887
mpComponent = 0;
18911888
}
18921889

1890+
/*!
1891+
* \brief DeleteSystemCommand::DeleteSystemCommand
1892+
* Used to delete the OMS system(s).
1893+
* \param pComponent
1894+
* \param pGraphicsView
1895+
* \param pParent
1896+
*/
1897+
DeleteSystemCommand::DeleteSystemCommand(Component *pComponent, GraphicsView *pGraphicsView, UndoCommand *pParent)
1898+
: UndoCommand(pParent)
1899+
{
1900+
mpComponent = pComponent;
1901+
mpGraphicsView = pGraphicsView;
1902+
mName = mpComponent->getName();
1903+
mType = mpComponent->getLibraryTreeItem()->getSystemType();
1904+
mAnnotation = mpComponent->getTransformationString();
1905+
}
1906+
1907+
/*!
1908+
* \brief DeleteSystemCommand::redoInternal
1909+
* redoInternal the DeleteSystemCommand.
1910+
*/
1911+
void DeleteSystemCommand::redoInternal()
1912+
{
1913+
// delete the system
1914+
LibraryTreeItem *pParentLibraryTreeItem = mpGraphicsView->getModelWidget()->getLibraryTreeItem();
1915+
QString nameStructure = QString("%1.%2").arg(pParentLibraryTreeItem->getNameStructure()).arg(mName);
1916+
if (!OMSProxy::instance()->omsDelete(nameStructure)) {
1917+
setFailed(true);
1918+
return;
1919+
}
1920+
// delete the LibraryTreeItem
1921+
MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->unloadOMSModel(mpComponent->getLibraryTreeItem(), false);
1922+
// delete the Component
1923+
mpGraphicsView->removeItem(mpComponent);
1924+
mpGraphicsView->removeItem(mpComponent->getOriginItem());
1925+
mpGraphicsView->deleteComponentFromList(mpComponent);
1926+
mpComponent->deleteLater();
1927+
mpComponent = 0;
1928+
mpGraphicsView->deleteComponentFromClass(mpComponent);
1929+
}
1930+
1931+
/*!
1932+
* \brief DeleteSystemCommand::undo
1933+
* Undo the DeleteSystemCommand.
1934+
*/
1935+
void DeleteSystemCommand::undo()
1936+
{
1937+
LibraryTreeItem *pParentLibraryTreeItem = mpGraphicsView->getModelWidget()->getLibraryTreeItem();
1938+
QString nameStructure = QString("%1.%2").arg(pParentLibraryTreeItem->getNameStructure()).arg(mName);
1939+
OMSProxy::instance()->addSystem(nameStructure, mType);
1940+
// get the oms_element_t
1941+
oms3_element_t *pOMSElement = 0;
1942+
OMSProxy::instance()->getElement(nameStructure, &pOMSElement);
1943+
// Create a LibraryTreeItem for system
1944+
LibraryTreeModel *pLibraryTreeModel = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel();
1945+
LibraryTreeItem *pLibraryTreeItem;
1946+
pLibraryTreeItem = pLibraryTreeModel->createLibraryTreeItem(mName, nameStructure, pParentLibraryTreeItem->getFileName(),
1947+
pParentLibraryTreeItem->isSaved(), pParentLibraryTreeItem, pOMSElement);
1948+
// add the FMU to view
1949+
ComponentInfo *pComponentInfo = new ComponentInfo;
1950+
pComponentInfo->setName(pLibraryTreeItem->getName());
1951+
pComponentInfo->setClassName(pLibraryTreeItem->getNameStructure());
1952+
mpComponent = new Component(mName, pLibraryTreeItem, mAnnotation, QPointF(0, 0), pComponentInfo, mpGraphicsView);
1953+
mpGraphicsView->addItem(mpComponent);
1954+
mpGraphicsView->addItem(mpComponent->getOriginItem());
1955+
mpGraphicsView->addComponentToList(mpComponent);
1956+
}
1957+
18931958
/*!
18941959
* \brief AddSubModelCommand::AddSubModelCommand
18951960
* Adds a submodel to fmi model.
@@ -1927,7 +1992,6 @@ void AddSubModelCommand::redoInternal()
19271992
setFailed(true);
19281993
return;
19291994
}
1930-
//mpGraphicsView->addSubModel(mName, mPath);
19311995
}
19321996
if (!mpLibraryTreeItem) {
19331997
// get the oms_element_t
@@ -1992,6 +2056,8 @@ DeleteSubModelCommand::DeleteSubModelCommand(Component *pComponent, GraphicsView
19922056
mpGraphicsView = pGraphicsView;
19932057
mName = mpComponent->getName();
19942058
mPath = mpComponent->getLibraryTreeItem()->getFileName();
2059+
mElementType = mpComponent->getLibraryTreeItem()->getOMSElement()->type;
2060+
mSystemType = mpComponent->getLibraryTreeItem()->getSystemType();
19952061
mAnnotation = mpComponent->getTransformationString();
19962062
}
19972063

@@ -2001,8 +2067,13 @@ DeleteSubModelCommand::DeleteSubModelCommand(Component *pComponent, GraphicsView
20012067
*/
20022068
void DeleteSubModelCommand::redoInternal()
20032069
{
2004-
// delete the submodel
2005-
mpGraphicsView->deleteSubModel(mpComponent->getName());
2070+
// delete the system/submodel
2071+
LibraryTreeItem *pParentLibraryTreeItem = mpGraphicsView->getModelWidget()->getLibraryTreeItem();
2072+
QString nameStructure = QString("%1.%2").arg(pParentLibraryTreeItem->getNameStructure()).arg(mName);
2073+
if (!OMSProxy::instance()->omsDelete(nameStructure)) {
2074+
setFailed(true);
2075+
return;
2076+
}
20062077
// delete the LibraryTreeItem
20072078
MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->unloadOMSModel(mpComponent->getLibraryTreeItem(), false);
20082079
// delete the Component
@@ -2020,11 +2091,16 @@ void DeleteSubModelCommand::redoInternal()
20202091
*/
20212092
void DeleteSubModelCommand::undo()
20222093
{
2023-
// add submodel
2024-
mpGraphicsView->addSubModel(mName, mPath);
2094+
// add system/submodel
2095+
LibraryTreeItem *pParentLibraryTreeItem = mpGraphicsView->getModelWidget()->getLibraryTreeItem();
2096+
QString nameStructure = QString("%1.%2").arg(pParentLibraryTreeItem->getNameStructure()).arg(mName);
2097+
if (mElementType == oms_element_system) {
2098+
OMSProxy::instance()->addSystem(nameStructure, mSystemType);
2099+
} else {
2100+
//OMSProxy::instance()->addSubModel(nameStructure, );
2101+
}
20252102
// Create a LibraryTreeItem for FMU
20262103
LibraryTreeModel *pLibraryTreeModel = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel();
2027-
LibraryTreeItem *pParentLibraryTreeItem = mpGraphicsView->getModelWidget()->getLibraryTreeItem();
20282104
LibraryTreeItem *pLibraryTreeItem;
20292105
pLibraryTreeItem = pLibraryTreeModel->createLibraryTreeItem(mName, QString("%1.%2").arg(pParentLibraryTreeItem->getNameStructure())
20302106
.arg(mName), mPath, true, pParentLibraryTreeItem);

OMEdit/OMEditGUI/Modeling/Commands.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,20 @@ class AddSystemCommand : public UndoCommand
422422
Component *mpComponent;
423423
};
424424

425+
class DeleteSystemCommand : public UndoCommand
426+
{
427+
public:
428+
DeleteSystemCommand(Component *pComponent, GraphicsView *pGraphicsView, UndoCommand *pParent = 0);
429+
void redoInternal();
430+
void undo();
431+
private:
432+
Component *mpComponent;
433+
GraphicsView *mpGraphicsView;
434+
QString mName;
435+
oms_system_enu_t mType;
436+
QString mAnnotation;
437+
};
438+
425439
class AddSubModelCommand : public UndoCommand
426440
{
427441
public:
@@ -450,6 +464,8 @@ class DeleteSubModelCommand : public UndoCommand
450464
GraphicsView *mpGraphicsView;
451465
QString mName;
452466
QString mPath;
467+
oms3_element_enu_t mElementType;
468+
oms_system_enu_t mSystemType;
453469
QString mAnnotation;
454470
};
455471

OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,11 @@ void GraphicsView::deleteComponent(Component *pComponent)
501501
}
502502
pComponent->setSelected(false);
503503
if (mpModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS) {
504-
mpModelWidget->getUndoStack()->push(new DeleteSubModelCommand(pComponent, this));
504+
if (pComponent->getLibraryTreeItem()->isSystemElement()) {
505+
mpModelWidget->getUndoStack()->push(new DeleteSystemCommand(pComponent, this));
506+
} else if (pComponent->getLibraryTreeItem()->isComponentElement()) {
507+
mpModelWidget->getUndoStack()->push(new DeleteSubModelCommand(pComponent, this));
508+
}
505509
} else {
506510
mpModelWidget->getUndoStack()->push(new DeleteComponentCommand(pComponent, this));
507511
}

0 commit comments

Comments
 (0)