Skip to content

Commit

Permalink
Create/delete model
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Nov 5, 2018
1 parent ac8e7b9 commit f47adba
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
26 changes: 25 additions & 1 deletion OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -1529,6 +1529,25 @@ void MainWindow::createNewFMIModel()
}
}

/*!
* \brief MainWindow::createNewOMSModel
* Create a new OMSimulator model.
*/
void MainWindow::createNewOMSModel()
{
QString newModelName = mpLibraryWidget->getLibraryTreeModel()->getUniqueTopLevelItemName("OMSimulatorModel");
// create new model
if (OMSProxy::instance()->newModel(newModelName)) {
LibraryTreeModel *pLibraryTreeModel = mpLibraryWidget->getLibraryTreeModel();
LibraryTreeItem *pLibraryTreeItem = pLibraryTreeModel->createLibraryTreeItem(LibraryTreeItem::OMS, newModelName,
newModelName, "", false,
pLibraryTreeModel->getRootLibraryTreeItem());
if (pLibraryTreeItem) {
mpLibraryWidget->getLibraryTreeModel()->showModelWidget(pLibraryTreeItem);
}
}
}

/*!
* \brief MainWindow::openOMSModelFile
* Opens the OMSimulator model file(s).\n
Expand Down Expand Up @@ -3026,6 +3045,10 @@ void MainWindow::createActions()
mpNewFMIModelAction = new QAction(QIcon(":/Resources/icons/new.svg"), tr("New FMI Model"), this);
mpNewFMIModelAction->setStatusTip(tr("Create a new FMI Model"));
connect(mpNewFMIModelAction, SIGNAL(triggered()), SLOT(createNewFMIModel()));
// create new OMSimulator Model action
mpNewOMSimulatorModelAction = new QAction(QIcon(":/Resources/icons/new.svg"), tr("New OMSimulator Model"), this);
mpNewOMSimulatorModelAction->setStatusTip(tr("Create a new OMSimulator Model"));
connect(mpNewOMSimulatorModelAction, SIGNAL(triggered()), SLOT(createNewOMSModel()));
// open OMSimulator Model file action
mpOpenOMSModelFileAction = new QAction(QIcon(":/Resources/icons/open.svg"), tr("Open OMSimulator Model(s)"), this);
mpOpenOMSModelFileAction->setStatusTip(tr("Opens the OMSimulator model file(s)"));
Expand Down Expand Up @@ -3507,6 +3530,7 @@ void MainWindow::createMenus()
pFileMenu->addAction(mpLoadExternModelAction);
pFileMenu->addSeparator();
pFileMenu->addAction(mpNewFMIModelAction);
pFileMenu->addAction(mpNewOMSimulatorModelAction);
pFileMenu->addAction(mpOpenOMSModelFileAction);
pFileMenu->addSeparator();
pFileMenu->addAction(mpOpenDirectoryAction);
Expand Down Expand Up @@ -4220,7 +4244,7 @@ AboutOMEditDialog::AboutOMEditDialog(MainWindow *pMainWindow)
Helper::applicationIntroText,
GIT_SHA,
Helper::OpenModelicaVersion,
oms2_getVersion());
oms3_getVersion());
// about text label
Label *pAboutTextLabel = new Label(aboutText);
pAboutTextLabel->setWordWrap(true);
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -295,6 +295,7 @@ class MainWindow : public QMainWindow
QAction *mpLoadExternModelAction;
// OMSimulator File Actions
QAction *mpNewFMIModelAction;
QAction *mpNewOMSimulatorModelAction;
QAction *mpOpenOMSModelFileAction;
QAction *mpOpenDirectoryAction;
QAction *mpSaveAction;
Expand Down Expand Up @@ -448,6 +449,7 @@ public slots:
void openCompositeModelFile();
void loadExternalModels();
void createNewFMIModel();
void createNewOMSModel();
void openOMSModelFile();
void openDirectory();
void loadSystemLibrary();
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -1727,7 +1727,7 @@ bool LibraryTreeModel::unloadOMSModel(LibraryTreeItem *pLibraryTreeItem, bool as
}
// unload OMSimulator model
bool deleted = false;
if (pLibraryTreeItem->isTopLevel() && OMSProxy::instance()->unloadModel(pLibraryTreeItem->getNameStructure())) {
if (pLibraryTreeItem->isTopLevel() && OMSProxy::instance()->omsDelete(pLibraryTreeItem->getNameStructure())) {
deleted = true;
} else if (!pLibraryTreeItem->isTopLevel()) {
deleted = true;
Expand Down
28 changes: 25 additions & 3 deletions OMEdit/OMEditGUI/OMS/OMSProxy.cpp
Expand Up @@ -232,6 +232,28 @@ bool OMSProxy::statusToBool(oms_status_enu_t status)
}
}

/*!
* \brief OMSProxy::newModel
* \param cref
* \return
*/
bool OMSProxy::newModel(QString cref)
{
oms_status_enu_t status = oms3_newModel(cref.toStdString().c_str());
return statusToBool(status);
}

/*!
* \brief OMSProxy::omsDelete
* \param cref
* \return
*/
bool OMSProxy::omsDelete(QString cref)
{
oms_status_enu_t status = oms3_delete(cref.toStdString().c_str());
return statusToBool(status);
}

/*!
* \brief OMSProxy::newFMIModel
* Creates a new FMI model.
Expand Down Expand Up @@ -593,7 +615,7 @@ void OMSProxy::setLoggingLevel(int logLevel)
*/
void OMSProxy::setLogFile(QString filename)
{
oms2_setLogFile(filename.toStdString().c_str());
oms3_setLogFile(filename.toStdString().c_str());
}

/*!
Expand All @@ -603,7 +625,7 @@ void OMSProxy::setLogFile(QString filename)
*/
void OMSProxy::setTempDirectory(QString path)
{
oms2_setTempDirectory(path.toStdString().c_str());
oms3_setTempDirectory(path.toStdString().c_str());
}

/*!
Expand All @@ -613,7 +635,7 @@ void OMSProxy::setTempDirectory(QString path)
*/
void OMSProxy::setWorkingDirectory(QString path)
{
oms2_setWorkingDirectory(path.toStdString().c_str());
oms3_setWorkingDirectory(path.toStdString().c_str());
}

/*!
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/OMS/OMSProxy.h
Expand Up @@ -60,6 +60,8 @@ class OMSProxy : public QObject

bool statusToBool(oms_status_enu_t status);

bool newModel(QString cref);
bool omsDelete(QString cref);
bool newFMIModel(QString ident);
bool newTLMModel(QString ident);
bool unloadModel(QString ident);
Expand Down

0 comments on commit f47adba

Please sign in to comment.