Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Component/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class Component : public QObject, public QGraphicsItem
QRectF boundingRect() const;
QRectF itemsBoundingRect();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void setLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem) {mpLibraryTreeItem = pLibraryTreeItem;}
LibraryTreeItem* getLibraryTreeItem() {return mpLibraryTreeItem;}
QString getName() {return mpComponentInfo->getName();}
GraphicsView* getGraphicsView() {return mpGraphicsView;}
Expand Down
225 changes: 195 additions & 30 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1847,9 +1847,6 @@ void AddSystemCommand::redoInternal()
LibraryTreeModel *pLibraryTreeModel = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel();
mpLibraryTreeItem = pLibraryTreeModel->createLibraryTreeItem(mName, nameStructure, pParentLibraryTreeItem->getFileName(),
pParentLibraryTreeItem->isSaved(), pParentLibraryTreeItem, pOMSElement);
if (!mOpeningClass) {
mpLibraryTreeItem->handleIconUpdated();
}
}
// add the FMU to view
ComponentInfo *pComponentInfo = new ComponentInfo;
Expand All @@ -1875,18 +1872,87 @@ void AddSystemCommand::redoInternal()
*/
void AddSystemCommand::undo()
{
// delete the connector
/*! @todo Add a function deleteSystem to delete the system from OMSimulator */
//mpGraphicsView->deleteSystem(mName);
// delete the system
LibraryTreeItem *pParentLibraryTreeItem = mpGraphicsView->getModelWidget()->getLibraryTreeItem();
QString nameStructure = QString("%1.%2").arg(pParentLibraryTreeItem->getNameStructure()).arg(mName);
OMSProxy::instance()->omsDelete(nameStructure);
// delete the LibraryTreeItem
// MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->unloadOMSModel(mpLibraryTreeItem, false);
// mpLibraryTreeItem = 0;
// // delete the Component
// mpGraphicsView->removeItem(mpComponent);
// mpGraphicsView->removeItem(mpComponent->getOriginItem());
// mpGraphicsView->deleteComponentFromList(mpComponent);
// mpComponent->deleteLater();
// mpComponent = 0;
MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->unloadOMSModel(mpLibraryTreeItem, false);
mpLibraryTreeItem = 0;
// delete the Component
mpGraphicsView->removeItem(mpComponent);
mpGraphicsView->removeItem(mpComponent->getOriginItem());
mpGraphicsView->deleteComponentFromList(mpComponent);
mpComponent->deleteLater();
mpComponent = 0;
}

/*!
* \brief DeleteSystemCommand::DeleteSystemCommand
* Used to delete the OMS system(s).
* \param pComponent
* \param pGraphicsView
* \param pParent
*/
DeleteSystemCommand::DeleteSystemCommand(Component *pComponent, GraphicsView *pGraphicsView, UndoCommand *pParent)
: UndoCommand(pParent)
{
mpComponent = pComponent;
mpGraphicsView = pGraphicsView;
mName = mpComponent->getName();
mType = mpComponent->getLibraryTreeItem()->getSystemType();
mAnnotation = mpComponent->getTransformationString();
}

/*!
* \brief DeleteSystemCommand::redoInternal
* redoInternal the DeleteSystemCommand.
*/
void DeleteSystemCommand::redoInternal()
{
// delete the system
LibraryTreeItem *pParentLibraryTreeItem = mpGraphicsView->getModelWidget()->getLibraryTreeItem();
QString nameStructure = QString("%1.%2").arg(pParentLibraryTreeItem->getNameStructure()).arg(mName);
if (!OMSProxy::instance()->omsDelete(nameStructure)) {
setFailed(true);
return;
}
// delete the LibraryTreeItem
MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->unloadOMSModel(mpComponent->getLibraryTreeItem(), false);
// delete the Component
mpGraphicsView->removeItem(mpComponent);
mpGraphicsView->removeItem(mpComponent->getOriginItem());
mpGraphicsView->deleteComponentFromList(mpComponent);
mpComponent->deleteLater();
mpComponent = 0;
mpGraphicsView->deleteComponentFromClass(mpComponent);
}

/*!
* \brief DeleteSystemCommand::undo
* Undo the DeleteSystemCommand.
*/
void DeleteSystemCommand::undo()
{
LibraryTreeItem *pParentLibraryTreeItem = mpGraphicsView->getModelWidget()->getLibraryTreeItem();
QString nameStructure = QString("%1.%2").arg(pParentLibraryTreeItem->getNameStructure()).arg(mName);
OMSProxy::instance()->addSystem(nameStructure, mType);
// get the oms_element_t
oms3_element_t *pOMSElement = 0;
OMSProxy::instance()->getElement(nameStructure, &pOMSElement);
// Create a LibraryTreeItem for system
LibraryTreeModel *pLibraryTreeModel = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel();
LibraryTreeItem *pLibraryTreeItem;
pLibraryTreeItem = pLibraryTreeModel->createLibraryTreeItem(mName, nameStructure, pParentLibraryTreeItem->getFileName(),
pParentLibraryTreeItem->isSaved(), pParentLibraryTreeItem, pOMSElement);
// add the FMU to view
ComponentInfo *pComponentInfo = new ComponentInfo;
pComponentInfo->setName(pLibraryTreeItem->getName());
pComponentInfo->setClassName(pLibraryTreeItem->getNameStructure());
mpComponent = new Component(mName, pLibraryTreeItem, mAnnotation, QPointF(0, 0), pComponentInfo, mpGraphicsView);
mpGraphicsView->addItem(mpComponent);
mpGraphicsView->addItem(mpComponent->getOriginItem());
mpGraphicsView->addComponentToList(mpComponent);
}

/*!
Expand Down Expand Up @@ -1926,7 +1992,6 @@ void AddSubModelCommand::redoInternal()
setFailed(true);
return;
}
//mpGraphicsView->addSubModel(mName, mPath);
}
if (!mpLibraryTreeItem) {
// get the oms_element_t
Expand Down Expand Up @@ -1991,6 +2056,8 @@ DeleteSubModelCommand::DeleteSubModelCommand(Component *pComponent, GraphicsView
mpGraphicsView = pGraphicsView;
mName = mpComponent->getName();
mPath = mpComponent->getLibraryTreeItem()->getFileName();
mElementType = mpComponent->getLibraryTreeItem()->getOMSElement()->type;
mSystemType = mpComponent->getLibraryTreeItem()->getSystemType();
mAnnotation = mpComponent->getTransformationString();
}

Expand All @@ -2000,8 +2067,13 @@ DeleteSubModelCommand::DeleteSubModelCommand(Component *pComponent, GraphicsView
*/
void DeleteSubModelCommand::redoInternal()
{
// delete the submodel
mpGraphicsView->deleteSubModel(mpComponent->getName());
// delete the system/submodel
LibraryTreeItem *pParentLibraryTreeItem = mpGraphicsView->getModelWidget()->getLibraryTreeItem();
QString nameStructure = QString("%1.%2").arg(pParentLibraryTreeItem->getNameStructure()).arg(mName);
if (!OMSProxy::instance()->omsDelete(nameStructure)) {
setFailed(true);
return;
}
// delete the LibraryTreeItem
MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->unloadOMSModel(mpComponent->getLibraryTreeItem(), false);
// delete the Component
Expand All @@ -2019,11 +2091,16 @@ void DeleteSubModelCommand::redoInternal()
*/
void DeleteSubModelCommand::undo()
{
// add submodel
mpGraphicsView->addSubModel(mName, mPath);
// add system/submodel
LibraryTreeItem *pParentLibraryTreeItem = mpGraphicsView->getModelWidget()->getLibraryTreeItem();
QString nameStructure = QString("%1.%2").arg(pParentLibraryTreeItem->getNameStructure()).arg(mName);
if (mElementType == oms_element_system) {
OMSProxy::instance()->addSystem(nameStructure, mSystemType);
} else {
//OMSProxy::instance()->addSubModel(nameStructure, );
}
// Create a LibraryTreeItem for FMU
LibraryTreeModel *pLibraryTreeModel = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel();
LibraryTreeItem *pParentLibraryTreeItem = mpGraphicsView->getModelWidget()->getLibraryTreeItem();
LibraryTreeItem *pLibraryTreeItem;
pLibraryTreeItem = pLibraryTreeModel->createLibraryTreeItem(mName, QString("%1.%2").arg(pParentLibraryTreeItem->getNameStructure())
.arg(mName), mPath, true, pParentLibraryTreeItem);
Expand Down Expand Up @@ -2130,17 +2207,105 @@ void AddConnectorCommand::redoInternal()
void AddConnectorCommand::undo()
{
// delete the connector
/*! @todo Add a function deleteConnector to delete the connector from OMSimulator */
//mpGraphicsView->deleteSubModel(mName);
LibraryTreeItem *pParentLibraryTreeItem = mpGraphicsView->getModelWidget()->getLibraryTreeItem();
QString nameStructure = QString("%1.%2").arg(pParentLibraryTreeItem->getNameStructure()).arg(mName);
OMSProxy::instance()->omsDelete(nameStructure);
// delete the LibraryTreeItem
// MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->unloadOMSModel(mpLibraryTreeItem, false);
// mpLibraryTreeItem = 0;
// // delete the Component
// mpGraphicsView->removeItem(mpComponent);
// mpGraphicsView->removeItem(mpComponent->getOriginItem());
// mpGraphicsView->deleteComponentFromList(mpComponent);
// mpComponent->deleteLater();
// mpComponent = 0;
MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->unloadOMSModel(mpLibraryTreeItem, false);
mpLibraryTreeItem = 0;
// delete the Icon Component
mpIconGraphicsView->removeItem(mpIconComponent);
mpIconGraphicsView->removeItem(mpIconComponent->getOriginItem());
mpIconGraphicsView->deleteComponentFromList(mpIconComponent);
mpIconComponent->emitDeleted();
// delete the Diagram Component
mpDiagramGraphicsView->removeItem(mpDiagramComponent);
mpDiagramGraphicsView->removeItem(mpDiagramComponent->getOriginItem());
mpDiagramGraphicsView->deleteComponentFromList(mpDiagramComponent);
}

/*!
* \brief DeleteConnectorCommand::DeleteConnectorCommand
* Used to delete the OMS connector(s).
* \param pComponent
* \param pGraphicsView
* \param pParent
*/
DeleteConnectorCommand::DeleteConnectorCommand(Component *pComponent, GraphicsView *pGraphicsView, UndoCommand *pParent)
: UndoCommand(pParent)
{
mpComponent = pComponent;
mpIconComponent = 0;
mpDiagramComponent = 0;
mpGraphicsView = pGraphicsView;
mpIconGraphicsView = pGraphicsView->getModelWidget()->getIconGraphicsView();
mpDiagramGraphicsView = pGraphicsView->getModelWidget()->getDiagramGraphicsView();
mName = mpComponent->getName();
mCausality = mpComponent->getLibraryTreeItem()->getOMSConnector()->causality;
mType = mpComponent->getLibraryTreeItem()->getOMSConnector()->type;
mAnnotation = mpComponent->getTransformationString();
}

/*!
* \brief DeleteConnectorCommand::redoInternal
* redoInternal the DeleteConnectorCommand.
*/
void DeleteConnectorCommand::redoInternal()
{
// delete the system
LibraryTreeItem *pParentLibraryTreeItem = mpGraphicsView->getModelWidget()->getLibraryTreeItem();
QString nameStructure = QString("%1.%2").arg(pParentLibraryTreeItem->getNameStructure()).arg(mName);
if (!OMSProxy::instance()->omsDelete(nameStructure)) {
setFailed(true);
return;
}
// delete the LibraryTreeItem
MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->unloadOMSModel(mpComponent->getLibraryTreeItem(), false);
// delete the Icon Component
mpIconComponent = mpIconGraphicsView->getComponentObject(mName);
if (mpIconComponent) {
mpIconGraphicsView->removeItem(mpIconComponent);
mpIconGraphicsView->removeItem(mpIconComponent->getOriginItem());
mpIconGraphicsView->deleteComponentFromList(mpIconComponent);
mpIconComponent->emitDeleted();
}
// delete the Diagram Component
mpDiagramComponent = mpDiagramGraphicsView->getComponentObject(mName);
if (mpDiagramComponent) {
mpDiagramGraphicsView->removeItem(mpDiagramComponent);
mpDiagramGraphicsView->removeItem(mpDiagramComponent->getOriginItem());
mpDiagramGraphicsView->deleteComponentFromList(mpDiagramComponent);
}
}

/*!
* \brief DeleteConnectorCommand::undo
* Undo the DeleteConnectorCommand.
*/
void DeleteConnectorCommand::undo()
{
LibraryTreeItem *pParentLibraryTreeItem = mpIconGraphicsView->getModelWidget()->getLibraryTreeItem();
QString nameStructure = QString("%1.%2").arg(pParentLibraryTreeItem->getNameStructure()).arg(mName);
OMSProxy::instance()->addConnector(nameStructure, mCausality, mType);
// get oms_connector_t
oms_connector_t *pOMSConnector = 0;
OMSProxy::instance()->getConnector(nameStructure, &pOMSConnector);
// Create a LibraryTreeItem for connector
LibraryTreeModel *pLibraryTreeModel = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel();
LibraryTreeItem *pLibraryTreeItem;
pLibraryTreeItem = pLibraryTreeModel->createLibraryTreeItem(mName, nameStructure, pParentLibraryTreeItem->getFileName(),
true, pParentLibraryTreeItem, 0, pOMSConnector);
// add the connector to icon view
mpIconComponent->setLibraryTreeItem(pLibraryTreeItem);
mpIconGraphicsView->addItem(mpIconComponent);
mpIconGraphicsView->addItem(mpIconComponent->getOriginItem());
mpIconGraphicsView->addComponentToList(mpIconComponent);
mpIconComponent->emitAdded();
// add the connector to diagram view
mpDiagramComponent->setLibraryTreeItem(pLibraryTreeItem);
mpDiagramGraphicsView->addItem(mpDiagramComponent);
mpDiagramGraphicsView->addItem(mpDiagramComponent->getOriginItem());
mpDiagramGraphicsView->addComponentToList(mpDiagramComponent);
}

FMUPropertiesCommand::FMUPropertiesCommand(Component *pComponent, QString name, FMUProperties oldFMUProperties,
Expand Down
35 changes: 35 additions & 0 deletions OMEdit/OMEditGUI/Modeling/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,20 @@ class AddSystemCommand : public UndoCommand
Component *mpComponent;
};

class DeleteSystemCommand : public UndoCommand
{
public:
DeleteSystemCommand(Component *pComponent, GraphicsView *pGraphicsView, UndoCommand *pParent = 0);
void redoInternal();
void undo();
private:
Component *mpComponent;
GraphicsView *mpGraphicsView;
QString mName;
oms_system_enu_t mType;
QString mAnnotation;
};

class AddSubModelCommand : public UndoCommand
{
public:
Expand Down Expand Up @@ -450,6 +464,8 @@ class DeleteSubModelCommand : public UndoCommand
GraphicsView *mpGraphicsView;
QString mName;
QString mPath;
oms3_element_enu_t mElementType;
oms_system_enu_t mSystemType;
QString mAnnotation;
};

Expand All @@ -474,6 +490,25 @@ class AddConnectorCommand : public UndoCommand
Component *mpDiagramComponent;
};

class DeleteConnectorCommand : public UndoCommand
{
public:
DeleteConnectorCommand(Component *pComponent, GraphicsView *pGraphicsView, UndoCommand *pParent = 0);
void redoInternal();
void undo();
private:
Component *mpComponent;
Component *mpIconComponent;
Component *mpDiagramComponent;
GraphicsView *mpGraphicsView;
GraphicsView *mpIconGraphicsView;
GraphicsView *mpDiagramGraphicsView;
QString mName;
oms_causality_enu_t mCausality;
oms_signal_type_enu_t mType;
QString mAnnotation;
};

class FMUPropertiesCommand : public UndoCommand
{
public:
Expand Down
Loading