diff --git a/OMEdit/OMEditGUI/Component/Component.h b/OMEdit/OMEditGUI/Component/Component.h index 91dbae4ee..be167b860 100644 --- a/OMEdit/OMEditGUI/Component/Component.h +++ b/OMEdit/OMEditGUI/Component/Component.h @@ -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;} diff --git a/OMEdit/OMEditGUI/Modeling/Commands.cpp b/OMEdit/OMEditGUI/Modeling/Commands.cpp index 481ff7856..7fd6f0a35 100644 --- a/OMEdit/OMEditGUI/Modeling/Commands.cpp +++ b/OMEdit/OMEditGUI/Modeling/Commands.cpp @@ -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; @@ -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); } /*! @@ -1926,7 +1992,6 @@ void AddSubModelCommand::redoInternal() setFailed(true); return; } - //mpGraphicsView->addSubModel(mName, mPath); } if (!mpLibraryTreeItem) { // get the oms_element_t @@ -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(); } @@ -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 @@ -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); @@ -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, diff --git a/OMEdit/OMEditGUI/Modeling/Commands.h b/OMEdit/OMEditGUI/Modeling/Commands.h index 8cde5cd7c..5f72058a6 100644 --- a/OMEdit/OMEditGUI/Modeling/Commands.h +++ b/OMEdit/OMEditGUI/Modeling/Commands.h @@ -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: @@ -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; }; @@ -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: diff --git a/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp b/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp index ea65e9524..8a3914374 100644 --- a/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp +++ b/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp @@ -1422,7 +1422,9 @@ void LibraryTreeModel::updateLibraryTreeItemClassText(LibraryTreeItem *pLibraryT pParentLibraryTreeItem->getModelWidget()->setWindowTitle(QString(pParentLibraryTreeItem->getName()).append("*")); ModelicaEditor *pModelicaEditor = dynamic_cast(pParentLibraryTreeItem->getModelWidget()->getEditor()); if (pModelicaEditor) { + bool blockSignalsState = pModelicaEditor->getPlainTextEdit()->document()->blockSignals(true); pModelicaEditor->setPlainText(contents); + pModelicaEditor->getPlainTextEdit()->document()->blockSignals(blockSignalsState); } } // if we first updated the parent class then the child classes needs to be updated as well. @@ -1448,7 +1450,9 @@ void LibraryTreeModel::updateLibraryTreeItemClassText(LibraryTreeItem *pLibraryT if (pLibraryTreeItem->getModelWidget() && pLibraryTreeItem->getModelWidget()->getEditor()) { OMSimulatorEditor *pOMSimulatorEditor = dynamic_cast(pLibraryTreeItem->getModelWidget()->getEditor()); if (pOMSimulatorEditor) { + bool blockSignalsState = pOMSimulatorEditor->getPlainTextEdit()->document()->blockSignals(true); pOMSimulatorEditor->setPlainText(contents); + pOMSimulatorEditor->getPlainTextEdit()->document()->blockSignals(blockSignalsState); } } } @@ -1660,22 +1664,25 @@ void LibraryTreeModel::showModelWidget(LibraryTreeItem *pLibraryTreeItem, bool s MainWindow::instance()->getDocumentationDockWidget()->show(); MainWindow::instance()->getDocumentationDockWidget()->blockSignals(state); } else { - // only switch to modeling perspective if show is true and we are not in a debugging perspective. - if (show && MainWindow::instance()->getPerspectiveTabBar()->currentIndex() != 3) { - MainWindow::instance()->getPerspectiveTabBar()->setCurrentIndex(1); - } - if (!pLibraryTreeItem->getModelWidget()) { - ModelWidget *pModelWidget = new ModelWidget(pLibraryTreeItem, MainWindow::instance()->getModelWidgetContainer()); - pLibraryTreeItem->setModelWidget(pModelWidget); - } - /* Ticket #3797 - * Only show the class Name as window title instead of full path - */ - pLibraryTreeItem->getModelWidget()->setWindowTitle(pLibraryTreeItem->getName() + (pLibraryTreeItem->isSaved() ? "" : "*")); - if (show) { - MainWindow::instance()->getModelWidgetContainer()->addModelWidget(pLibraryTreeItem->getModelWidget(), true, viewType); - } else { - pLibraryTreeItem->getModelWidget()->hide(); + if (!(pLibraryTreeItem->getLibraryType() == LibraryTreeItem::OMS + && (pLibraryTreeItem->getOMSConnector() || pLibraryTreeItem->getOMSBusConnector() || pLibraryTreeItem->getOMSTLMBusConnector()))) { + // only switch to modeling perspective if show is true and we are not in a debugging perspective. + if (show && MainWindow::instance()->getPerspectiveTabBar()->currentIndex() != 3) { + MainWindow::instance()->getPerspectiveTabBar()->setCurrentIndex(1); + } + if (!pLibraryTreeItem->getModelWidget()) { + ModelWidget *pModelWidget = new ModelWidget(pLibraryTreeItem, MainWindow::instance()->getModelWidgetContainer()); + pLibraryTreeItem->setModelWidget(pModelWidget); + } + /* Ticket #3797 + * Only show the class Name as window title instead of full path + */ + pLibraryTreeItem->getModelWidget()->setWindowTitle(pLibraryTreeItem->getName() + (pLibraryTreeItem->isSaved() ? "" : "*")); + if (show) { + MainWindow::instance()->getModelWidgetContainer()->addModelWidget(pLibraryTreeItem->getModelWidget(), true, viewType); + } else { + pLibraryTreeItem->getModelWidget()->hide(); + } } } QApplication::restoreOverrideCursor(); diff --git a/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp b/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp index 17c1fe79b..41e493715 100644 --- a/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp +++ b/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp @@ -501,7 +501,13 @@ void GraphicsView::deleteComponent(Component *pComponent) } pComponent->setSelected(false); if (mpModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS) { - mpModelWidget->getUndoStack()->push(new DeleteSubModelCommand(pComponent, this)); + if (pComponent->getLibraryTreeItem()->isSystemElement()) { + mpModelWidget->getUndoStack()->push(new DeleteSystemCommand(pComponent, this)); + } else if (pComponent->getLibraryTreeItem()->isComponentElement()) { + mpModelWidget->getUndoStack()->push(new DeleteSubModelCommand(pComponent, this)); + } else if (pComponent->getLibraryTreeItem()->getOMSConnector()) { + mpModelWidget->getUndoStack()->push(new DeleteConnectorCommand(pComponent, this)); + } } else { mpModelWidget->getUndoStack()->push(new DeleteComponentCommand(pComponent, this)); } @@ -4325,10 +4331,7 @@ void ModelWidget::updateModelicaTextManually(QString contents) */ void ModelWidget::updateUndoRedoActions() { - if (mpIconGraphicsView && mpIconGraphicsView->isVisible()) { - MainWindow::instance()->getUndoAction()->setEnabled(mpUndoStack->canUndo()); - MainWindow::instance()->getRedoAction()->setEnabled(mpUndoStack->canRedo()); - } else if (mpDiagramGraphicsView && mpDiagramGraphicsView->isVisible()) { + if ((mpIconGraphicsView && mpIconGraphicsView->isVisible()) || (mpDiagramGraphicsView && mpDiagramGraphicsView->isVisible())) { MainWindow::instance()->getUndoAction()->setEnabled(mpUndoStack->canUndo()); MainWindow::instance()->getRedoAction()->setEnabled(mpUndoStack->canRedo()); } else if (mpEditor && mpEditor->isVisible()) { diff --git a/OMEdit/OMEditGUI/OMS/OMSProxy.cpp b/OMEdit/OMEditGUI/OMS/OMSProxy.cpp index 408f058c3..0e872f594 100644 --- a/OMEdit/OMEditGUI/OMS/OMSProxy.cpp +++ b/OMEdit/OMEditGUI/OMS/OMSProxy.cpp @@ -308,7 +308,12 @@ bool OMSProxy::newModel(QString cref) */ bool OMSProxy::omsDelete(QString cref) { + QString command = "oms3_delete"; + QStringList args; + args << cref; + LOG_COMMAND(command, args); oms_status_enu_t status = oms3_delete(cref.toStdString().c_str()); + logResponse(command, status, &commandTime); return statusToBool(status); }