Skip to content

Commit

Permalink
Add system dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Nov 5, 2018
1 parent f47adba commit 6cee4f3
Show file tree
Hide file tree
Showing 15 changed files with 440 additions and 19 deletions.
4 changes: 4 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -3489,6 +3489,9 @@ void MainWindow::createActions()
mpTLMCoSimulationAction->setStatusTip(Helper::tlmCoSimulationSetupTip);
mpTLMCoSimulationAction->setEnabled(false);
connect(mpTLMCoSimulationAction, SIGNAL(triggered()), SLOT(TLMSimulate()));
// Add System Action
mpAddSystemAction = new QAction(QIcon(":/Resources/icons/add-system.svg"), Helper::addSystem, this);
mpAddSystemAction->setStatusTip(Helper::addSystemTip);
// Add SubModel Action
mpAddSubModelAction = new QAction(QIcon(":/Resources/icons/import-fmu.svg"), Helper::addSubModel, this);
mpAddSubModelAction->setStatusTip(Helper::addSubModelTip);
Expand Down Expand Up @@ -4150,6 +4153,7 @@ void MainWindow::createToolbars()
mpOMSimulatorToobar->setObjectName("OMSimulator Toolbar");
mpOMSimulatorToobar->setAllowedAreas(Qt::TopToolBarArea);
// add actions to OMSimulator Toolbar
mpOMSimulatorToobar->addAction(mpAddSystemAction);
mpOMSimulatorToobar->addAction(mpAddSubModelAction);
mpOMSimulatorToobar->addAction(mpAddOrEditSubModelIconAction);
mpOMSimulatorToobar->addAction(mpAddConnectorAction);
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -186,6 +186,7 @@ class MainWindow : public QMainWindow
QAction* getFetchInterfaceDataAction() {return mpFetchInterfaceDataAction;}
QAction* getAlignInterfacesAction() {return mpAlignInterfacesAction;}
QAction* getTLMSimulationAction() {return mpTLMCoSimulationAction;}
QAction* getAddSystemAction() {return mpAddSystemAction;}
QAction* getAddSubModelAction() {return mpAddSubModelAction;}
QAction* getAddOrEditSubModelIconAction() {return mpAddOrEditSubModelIconAction;}
QAction* getAddConnectorAction() {return mpAddConnectorAction;}
Expand Down Expand Up @@ -410,6 +411,7 @@ class MainWindow : public QMainWindow
QAction *mpAlignInterfacesAction;
QAction *mpTLMCoSimulationAction;
// OMSimulator Actions
QAction *mpAddSystemAction;
QAction *mpAddSubModelAction;
QAction *mpAddOrEditSubModelIconAction;
QAction *mpAddConnectorAction;
Expand Down
86 changes: 83 additions & 3 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -1777,9 +1777,89 @@ void RenameCompositeModelCommand::undo()
mpCompositeModelEditor->getModelWidget()->setWindowTitle(mOldCompositeModelName);
}

/*!
* \brief AddSystemCommand::AddSystemCommand
* Adds a system to a model.
* \param name
* \param pLibraryTreeItem
* \param annotation
* \param pGraphicsView
* \param openingClass
* \param type
* \param pParent
*/
AddSystemCommand::AddSystemCommand(QString name, LibraryTreeItem *pLibraryTreeItem, QString annotation, GraphicsView *pGraphicsView,
bool openingClass, oms_system_enu_t type, QUndoCommand *pParent)
: QUndoCommand(pParent)
{
mName = name;
mpLibraryTreeItem = pLibraryTreeItem;
mAnnotation = annotation;
mpGraphicsView = pGraphicsView;
mOpeningClass = openingClass;
mType = type;
setText(QString("Add system %1").arg(name));
}

/*!
* \brief AddSystemCommand::redo
* Redo the AddSystemCommand.
*/
void AddSystemCommand::redo()
{
if (!mOpeningClass) {
mpGraphicsView->addSystem(mName, mType);
}
if (!mpLibraryTreeItem) {
// Create a LibraryTreeItem for connector
LibraryTreeModel *pLibraryTreeModel = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel();
LibraryTreeItem *pParentLibraryTreeItem = mpGraphicsView->getModelWidget()->getLibraryTreeItem();
mpLibraryTreeItem = pLibraryTreeModel->createLibraryTreeItem(LibraryTreeItem::OMS, mName,
QString("%1.%2").arg(pParentLibraryTreeItem->getNameStructure())
.arg(mName), "",
true, pParentLibraryTreeItem);
}
// add the FMU to view
ComponentInfo *pComponentInfo = new ComponentInfo;
pComponentInfo->setName(mpLibraryTreeItem->getName());
pComponentInfo->setClassName(mpLibraryTreeItem->getNameStructure());
mpComponent = new Component(mName, mpLibraryTreeItem, mAnnotation, QPointF(0, 0), pComponentInfo, mpGraphicsView);
mpGraphicsView->addItem(mpComponent);
mpGraphicsView->addItem(mpComponent->getOriginItem());
mpGraphicsView->addComponentToList(mpComponent);
// select the component when not opening class.
if (!mOpeningClass) {
// unselect all items
foreach (QGraphicsItem *pItem, mpGraphicsView->items()) {
pItem->setSelected(false);
}
mpComponent->setSelected(true);
}
}

/*!
* \brief AddSystemCommand::undo
* Undo the AddSystemCommand.
*/
void AddSystemCommand::undo()
{
// delete the connector
/*! @todo Add a function deleteSystem to delete the system from OMSimulator */
//mpGraphicsView->deleteSystem(mName);
// 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;
}

/*!
* \brief AddSubModelCommand::AddSubModelCommand
* Adds the submodel to fmi model.
* Adds a submodel to fmi model.
* \param name
* \param path
* \param pLibraryTreeItem
Expand Down Expand Up @@ -1925,7 +2005,7 @@ void DeleteSubModelCommand::undo()

/*!
* \brief AddConnectorCommand::AddConnectorCommand
* Adds the connector.
* Adds a connector.
* \param name
* \param pLibraryTreeItem
* \param annotation
Expand All @@ -1936,7 +2016,7 @@ void DeleteSubModelCommand::undo()
* \param pParent
*/
AddConnectorCommand::AddConnectorCommand(QString name, LibraryTreeItem *pLibraryTreeItem, QString annotation, GraphicsView *pGraphicsView,
bool openingClass, int causality, int type, QUndoCommand *pParent)
bool openingClass, oms_causality_enu_t causality, oms_signal_type_enu_t type, QUndoCommand *pParent)
: QUndoCommand(pParent)
{
mName = name;
Expand Down
23 changes: 20 additions & 3 deletions OMEdit/OMEditGUI/Modeling/Commands.h
Expand Up @@ -390,6 +390,23 @@ class RenameCompositeModelCommand : public QUndoCommand
QString mNewCompositeModelName;
};

class AddSystemCommand : public QUndoCommand
{
public:
AddSystemCommand(QString name, LibraryTreeItem *pLibraryTreeItem, QString annotation, GraphicsView *pGraphicsView,
bool openingClass, oms_system_enu_t type, QUndoCommand *pParent = 0);
void redo();
void undo();
private:
QString mName;
LibraryTreeItem *mpLibraryTreeItem;
QString mAnnotation;
GraphicsView *mpGraphicsView;
bool mOpeningClass;
oms_system_enu_t mType;
Component *mpComponent;
};

class AddSubModelCommand : public QUndoCommand
{
public:
Expand Down Expand Up @@ -425,7 +442,7 @@ class AddConnectorCommand : public QUndoCommand
{
public:
AddConnectorCommand(QString name, LibraryTreeItem *pLibraryTreeItem, QString annotation, GraphicsView *pGraphicsView,
bool openingClass = false, int causality = 0, int type = 0, QUndoCommand *pParent = 0);
bool openingClass, oms_causality_enu_t causality, oms_signal_type_enu_t type, QUndoCommand *pParent = 0);
void redo();
void undo();
private:
Expand All @@ -434,8 +451,8 @@ class AddConnectorCommand : public QUndoCommand
QString mAnnotation;
GraphicsView *mpGraphicsView;
bool mOpeningClass;
int mCausality;
int mType;
oms_causality_enu_t mCausality;
oms_signal_type_enu_t mType;
Component *mpComponent;
};

Expand Down
35 changes: 34 additions & 1 deletion OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -1172,6 +1172,17 @@ void GraphicsView::fitInViewInternal()
}
}

/*!
* \brief GraphicsView::addSystem
* Adds a system to a model.
* \param name
* \param type
*/
void GraphicsView::addSystem(QString name, oms_system_enu_t type)
{
OMSProxy::instance()->addSystem(name, type);
}

/*!
* \brief GraphicsView::addSubModel
* Adds the submodel to the OMS model.
Expand Down Expand Up @@ -2677,6 +2688,7 @@ void GraphicsView::contextMenuEvent(QContextMenuEvent *event)
menu.addAction(mpSimulationParamsAction);
} else if (mpModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS) {
menu.addSeparator();
menu.addAction(MainWindow::instance()->getAddSystemAction());
if (mpModelWidget->getLibraryTreeItem()->getOMSElement()) {
if (mpModelWidget->getLibraryTreeItem()->getOMSElement()->type == oms_component_fmi) {
menu.addAction(MainWindow::instance()->getAddSubModelAction());
Expand Down Expand Up @@ -5720,7 +5732,9 @@ void ModelWidget::drawOMSModelElements()
.arg(Utilities::mapToCoOrdinateSystem(pChildLibraryTreeItem->getOMSConnector()->geometry->x, 0, 1, -100, 100))
.arg(Utilities::mapToCoOrdinateSystem(pChildLibraryTreeItem->getOMSConnector()->geometry->y, 0, 1, -100, 100));
AddConnectorCommand *pAddConnectorCommand = new AddConnectorCommand(pChildLibraryTreeItem->getName(), pChildLibraryTreeItem,
annotation, mpDiagramGraphicsView, true);
annotation, mpDiagramGraphicsView, true,
pChildLibraryTreeItem->getOMSConnector()->causality,
pChildLibraryTreeItem->getOMSConnector()->type);
mpUndoStack->push(pAddConnectorCommand);
}
}
Expand Down Expand Up @@ -6150,6 +6164,7 @@ ModelWidgetContainer::ModelWidgetContainer(QWidget *pParent)
connect(MainWindow::instance()->getPrintModelAction(), SIGNAL(triggered()), SLOT(printModel()));
connect(MainWindow::instance()->getSimulationParamsAction(), SIGNAL(triggered()), SLOT(showSimulationParams()));
connect(MainWindow::instance()->getAlignInterfacesAction(), SIGNAL(triggered()), SLOT(alignInterfaces()));
connect(MainWindow::instance()->getAddSystemAction(), SIGNAL(triggered()), SLOT(addSystem()));
connect(MainWindow::instance()->getAddSubModelAction(), SIGNAL(triggered()), SLOT(addSubModel()));
connect(MainWindow::instance()->getAddOrEditSubModelIconAction(), SIGNAL(triggered()), SLOT(addOrEditSubModelIcon()));
connect(MainWindow::instance()->getAddConnectorAction(), SIGNAL(triggered()), SLOT(addConnector()));
Expand Down Expand Up @@ -6665,6 +6680,7 @@ void ModelWidgetContainer::currentModelWidgetChanged(QMdiSubWindow *pSubWindow)
MainWindow::instance()->getFetchInterfaceDataAction()->setEnabled(enabled && compositeModel);
MainWindow::instance()->getAlignInterfacesAction()->setEnabled(enabled && compositeModel);
MainWindow::instance()->getTLMSimulationAction()->setEnabled(enabled && compositeModel);
MainWindow::instance()->getAddSystemAction()->setEnabled(enabled && oms);
MainWindow::instance()->getAddSubModelAction()->setEnabled(enabled && (oms && !(oms_submodel || oms_connector)));
MainWindow::instance()->getAddOrEditSubModelIconAction()->setEnabled(enabled && oms_submodel);
MainWindow::instance()->getAddConnectorAction()->setEnabled(enabled && (oms || oms_submodel));
Expand Down Expand Up @@ -6848,6 +6864,19 @@ void ModelWidgetContainer::alignInterfaces()
}
}

/*!
* \brief ModelWidgetContainer::addSystem
* Opens the AddSystemDialog
*/
void ModelWidgetContainer::addSystem()
{
ModelWidget *pModelWidget = getCurrentModelWidget();
if (pModelWidget && pModelWidget->getDiagramGraphicsView()) {
AddSystemDialog *pAddSystemDialog = new AddSystemDialog(pModelWidget->getDiagramGraphicsView());
pAddSystemDialog->exec();
}
}

/*!
* \brief ModelWidgetContainer::addSubModel
* Opens the AddFMUDialog.
Expand Down Expand Up @@ -6883,6 +6912,10 @@ void ModelWidgetContainer::addOrEditSubModelIcon()
}
}

/*!
* \brief ModelWidgetContainer::addConnector
* Opens the AddConnectorDialog.
*/
void ModelWidgetContainer::addConnector()
{
ModelWidget *pModelWidget = getCurrentModelWidget();
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h
Expand Up @@ -246,6 +246,7 @@ class GraphicsView : public QGraphicsView
void addItem(QGraphicsItem *pGraphicsItem);
void removeItem(QGraphicsItem *pGraphicsItem);
void fitInViewInternal();
void addSystem(QString name, oms_system_enu_t type);
void addSubModel(QString name, QString path);
void deleteSubModel(QString name);
private:
Expand Down Expand Up @@ -541,6 +542,7 @@ public slots:
void printModel();
void showSimulationParams();
void alignInterfaces();
void addSystem();
void addSubModel();
void addOrEditSubModelIcon();
void addConnector();
Expand Down

0 comments on commit 6cee4f3

Please sign in to comment.