Skip to content

Commit

Permalink
Add external TLM models to OMSimulator models
Browse files Browse the repository at this point in the history
  • Loading branch information
robbr48 authored and adeas31 committed Aug 16, 2019
1 parent c4d95ff commit 55e2dbd
Show file tree
Hide file tree
Showing 16 changed files with 230 additions and 15 deletions.
17 changes: 13 additions & 4 deletions OMEdit/OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -1841,12 +1841,13 @@ void AddSystemCommand::undo()
* \param pGraphicsView
* \param pParent
*/
AddSubModelCommand::AddSubModelCommand(QString name, QString path, LibraryTreeItem *pLibraryTreeItem, QString annotation,
AddSubModelCommand::AddSubModelCommand(QString name, QString path, QString startScript, LibraryTreeItem *pLibraryTreeItem, QString annotation,
bool openingClass, GraphicsView *pGraphicsView, UndoCommand *pParent)
: UndoCommand(pParent)
{
mName = name;
mPath = path;
mStartScript = startScript;
mpLibraryTreeItem = pLibraryTreeItem;
mAnnotation = annotation;
mOpeningClass = openingClass;
Expand All @@ -1864,9 +1865,17 @@ void AddSubModelCommand::redoInternal()
QString nameStructure = QString("%1.%2").arg(pParentLibraryTreeItem->getNameStructure()).arg(mName);
if (!mOpeningClass) {
QFileInfo fileInfo(mPath);
if (!OMSProxy::instance()->addSubModel(nameStructure, fileInfo.absoluteFilePath())) {
setFailed(true);
return;
if(mStartScript.isEmpty()) {
if (!OMSProxy::instance()->addSubModel(nameStructure, fileInfo.absoluteFilePath())) {
setFailed(true);
return;
}
}
else {
if (!OMSProxy::instance()->addExternalTLMModel(nameStructure, mStartScript, fileInfo.absoluteFilePath())) {
setFailed(true);
return;
}
}
//mpGraphicsView->addSubModel(mName, mPath);
}
Expand Down
3 changes: 2 additions & 1 deletion OMEdit/OMEdit/OMEditGUI/Modeling/Commands.h
Expand Up @@ -430,13 +430,14 @@ class AddSystemCommand : public UndoCommand
class AddSubModelCommand : public UndoCommand
{
public:
AddSubModelCommand(QString name, QString path, LibraryTreeItem *pLibraryTreeItem, QString annotation, bool openingClass,
AddSubModelCommand(QString name, QString path, QString startScript, LibraryTreeItem *pLibraryTreeItem, QString annotation, bool openingClass,
GraphicsView *pGraphicsView, UndoCommand *pParent = 0);
void redoInternal();
void undo();
private:
QString mName;
QString mPath;
QString mStartScript;
LibraryTreeItem *mpLibraryTreeItem;
QString mAnnotation;
bool mOpeningClass;
Expand Down
7 changes: 7 additions & 0 deletions OMEdit/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -86,6 +86,7 @@ LibraryTreeItem::LibraryTreeItem()
setOMSBusConnector(0);
setOMSTLMBusConnector(0);
setFMUInfo(0);
setExternalTLMModelInfo(0);
setSubModelPath("");
setModelState(oms_modelState_virgin);
}
Expand Down Expand Up @@ -132,6 +133,7 @@ LibraryTreeItem::LibraryTreeItem(LibraryType type, QString text, QString nameStr
setOMSBusConnector(0);
setOMSTLMBusConnector(0);
setFMUInfo(0);
setExternalTLMModelInfo(0);
setSubModelPath("");
setModelState(oms_modelState_virgin);
}
Expand Down Expand Up @@ -2769,6 +2771,11 @@ LibraryTreeItem* LibraryTreeModel::createOMSLibraryTreeItemImpl(QString name, QS
pLibraryTreeItem->setFMUInfo(pFMUInfo);
pLibraryTreeItem->setSubModelPath(QString(pFMUInfo->path));
}
} else if (pLibraryTreeItem->isExternalTLMModelComponent()) {
const oms_external_tlm_model_info_t *pExternalTLMModelInfo;
if(OMSProxy::instance()->getExternalTLMModelInfo(pLibraryTreeItem->getNameStructure(), &pExternalTLMModelInfo)) {
pLibraryTreeItem->setExternalTLMModelInfo(pExternalTLMModelInfo);
}
} else if (pLibraryTreeItem->isTableComponent()) {
QString path;
if (OMSProxy::instance()->getSubModelPath(pLibraryTreeItem->getNameStructure(), &path)) {
Expand Down
4 changes: 4 additions & 0 deletions OMEdit/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h
Expand Up @@ -133,6 +133,7 @@ class LibraryTreeItem : public QObject
bool isSystemElement() const {return (mpOMSElement && (mpOMSElement->type == oms_element_system));}
bool isComponentElement() const {return (mpOMSElement && (mpOMSElement->type == oms_element_component));}
bool isFMUComponent() const {return (mpOMSElement && (mpOMSElement->type == oms_element_component) && (mComponentType == oms_component_fmu));}
bool isExternalTLMModelComponent() const {return (mpOMSElement && (mpOMSElement->type == oms_element_component) && (mComponentType == oms_component_external));}
bool isTableComponent() const {return (mpOMSElement && (mpOMSElement->type == oms_element_component) && (mComponentType == oms_component_table));}
void setSystemType(oms_system_enu_t type) {mSystemType = type;}
oms_system_enu_t getSystemType() {return mSystemType;}
Expand All @@ -150,6 +151,8 @@ class LibraryTreeItem : public QObject
oms_tlmbusconnector_t* getOMSTLMBusConnector() const {return mpOMSTLMBusConnector;}
void setFMUInfo(const oms_fmu_info_t *pFMUInfo) {mpFMUInfo = pFMUInfo;}
const oms_fmu_info_t* getFMUInfo() const {return mpFMUInfo;}
void setExternalTLMModelInfo(const oms_external_tlm_model_info_t *pExternalTLMModelInfo) { mpExternalTLMModelInfo = pExternalTLMModelInfo;}
const oms_external_tlm_model_info_t* getExternalTLMModelInfo() const {return mpExternalTLMModelInfo;}
void setSubModelPath(QString subModelPath) {mSubModelPath = subModelPath;}
QString getSubModelPath() const {return mSubModelPath;}
oms_modelState_enu_t getModelState() const {return mModelState;}
Expand Down Expand Up @@ -224,6 +227,7 @@ class LibraryTreeItem : public QObject
oms_busconnector_t *mpOMSBusConnector;
oms_tlmbusconnector_t *mpOMSTLMBusConnector;
const oms_fmu_info_t *mpFMUInfo;
const oms_external_tlm_model_info_t *mpExternalTLMModelInfo;
QString mSubModelPath;
oms_modelState_enu_t mModelState;
signals:
Expand Down
4 changes: 1 addition & 3 deletions OMEdit/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -3177,8 +3177,6 @@ void GraphicsView::contextMenuEvent(QContextMenuEvent *event)
menu.addAction(MainWindow::instance()->getAddBusAction());
menu.addAction(MainWindow::instance()->getAddTLMBusAction());
if (mpModelWidget->getLibraryTreeItem()->isSystemElement()) {
menu.addSeparator();
menu.addAction(MainWindow::instance()->getAddSubModelAction());
menu.addSeparator();
menu.addAction(MainWindow::instance()->getAddSubModelAction());
menu.addSeparator();
Expand Down Expand Up @@ -6328,7 +6326,7 @@ void ModelWidget::drawOMSModelDiagramElements()
pChildLibraryTreeItem->getSystemType());
mpUndoStack->push(pAddSystemCommand);
} else if (pChildLibraryTreeItem->isComponentElement()) {
AddSubModelCommand *pAddSubModelCommand = new AddSubModelCommand(pChildLibraryTreeItem->getName(), "", pChildLibraryTreeItem,
AddSubModelCommand *pAddSubModelCommand = new AddSubModelCommand(pChildLibraryTreeItem->getName(), "", "", pChildLibraryTreeItem,
annotation, true, mpDiagramGraphicsView);
mpUndoStack->push(pAddSubModelCommand);
}
Expand Down
15 changes: 13 additions & 2 deletions OMEdit/OMEdit/OMEditGUI/OMS/ElementPropertiesDialog.cpp
Expand Up @@ -70,6 +70,13 @@ ElementPropertiesDialog::ElementPropertiesDialog(Component *pComponent, QWidget
* And then fix the OMSRenameCommand accordingly.
*/
mpNameTextBox->setDisabled(true);

if(mpComponent->getLibraryTreeItem()->getExternalTLMModelInfo()) {
const oms_external_tlm_model_info_t *pExternalTLMModelInfo = mpComponent->getLibraryTreeItem()->getExternalTLMModelInfo();
mpStartScriptLabel = new Label(Helper::startScript);
mpStartScriptTextBox = new QLineEdit(QString(pExternalTLMModelInfo->startScript));
mpStartScriptTextBox->setDisabled(true); //! @todo Enable this to make start script changeable
}
// tab widget
mpTabWidget = new QTabWidget;
// info tab
Expand Down Expand Up @@ -318,10 +325,14 @@ ElementPropertiesDialog::ElementPropertiesDialog(Component *pComponent, QWidget
pMainLayout->addWidget(mpHorizontalLine, 1, 0, 1, 2);
pMainLayout->addWidget(mpNameLabel, 2, 0);
pMainLayout->addWidget(mpNameTextBox, 2, 1);
if(mpComponent->getLibraryTreeItem()->isExternalTLMModelComponent()) {
pMainLayout->addWidget(mpStartScriptLabel, 3, 0);
pMainLayout->addWidget(mpStartScriptTextBox, 3, 1);
}
if (mpComponent->getLibraryTreeItem()->getFMUInfo() || hasParameter || hasInput) {
pMainLayout->addWidget(mpTabWidget, 3, 0, 1, 2);
pMainLayout->addWidget(mpTabWidget, 4, 0, 1, 2);
}
pMainLayout->addWidget(mpButtonBox, 4, 0, 1, 2, Qt::AlignRight);
pMainLayout->addWidget(mpButtonBox, 5, 0, 1, 2, Qt::AlignRight);
setLayout(pMainLayout);
}

Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEdit/OMEditGUI/OMS/ElementPropertiesDialog.h
Expand Up @@ -56,6 +56,8 @@ class ElementPropertiesDialog : public QDialog
QFrame *mpHorizontalLine;
Label *mpNameLabel;
QLineEdit *mpNameTextBox;
Label *mpStartScriptLabel;
QLineEdit *mpStartScriptTextBox;
QTabWidget *mpTabWidget;
QGroupBox *mpGeneralGroupBox;
Label *mpDescriptionLabel;
Expand Down
24 changes: 21 additions & 3 deletions OMEdit/OMEdit/OMEditGUI/OMS/ModelDialog.cpp
Expand Up @@ -282,6 +282,9 @@ AddSubModelDialog::AddSubModelDialog(GraphicsView *pGraphicsView)
mpBrowsePathButton = new QPushButton(Helper::browse);
mpBrowsePathButton->setAutoDefault(false);
connect(mpBrowsePathButton, SIGNAL(clicked()), SLOT(browseSubModelPath()));
// start script
mpStartScriptLabel = new Label(Helper::startScript);
mpStartScriptTextBox = new QLineEdit;
// buttons
mpOkButton = new QPushButton(Helper::ok);
mpOkButton->setAutoDefault(true);
Expand All @@ -303,7 +306,11 @@ AddSubModelDialog::AddSubModelDialog(GraphicsView *pGraphicsView)
pMainLayout->addWidget(mpPathLabel, 3, 0);
pMainLayout->addWidget(mpPathTextBox, 3, 1);
pMainLayout->addWidget(mpBrowsePathButton, 3, 2);
pMainLayout->addWidget(mpButtonBox, 4, 0, 1, 3, Qt::AlignRight);
if(mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isTLMSystem()) {
pMainLayout->addWidget(mpStartScriptLabel, 4, 0);
pMainLayout->addWidget(mpStartScriptTextBox, 4, 1, 1, 2);
}
pMainLayout->addWidget(mpButtonBox, 5, 0, 1, 3, Qt::AlignRight);
setLayout(pMainLayout);
}

Expand All @@ -314,8 +321,12 @@ AddSubModelDialog::AddSubModelDialog(GraphicsView *pGraphicsView)
*/
void AddSubModelDialog::browseSubModelPath()
{
QString fileTypes;
if(!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isTLMSystem()) {
fileTypes = Helper::subModelFileTypes;
}
mpPathTextBox->setText(StringHandler::getOpenFileName(this, QString("%1 - %2").arg(Helper::applicationName, Helper::chooseFile),
NULL, Helper::subModelFileTypes, NULL));
NULL, fileTypes, NULL));
}

/*!
Expand All @@ -329,6 +340,13 @@ void AddSubModelDialog::addSubModel()
GUIMessages::getMessage(GUIMessages::ENTER_NAME).arg(tr("SubModel")), Helper::ok);
return;
}

if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isTLMSystem() && mpStartScriptTextBox->text().isEmpty()) {
QMessageBox::critical(this, QString("%1 - %2").arg(Helper::applicationName, Helper::error),
GUIMessages::getMessage(GUIMessages::ENTER_SCRIPT), Helper::ok);
return;
}

QFileInfo fileInfo(mpPathTextBox->text());
if (!fileInfo.exists()) {
QMessageBox::critical(this, QString("%1 - %2").arg(Helper::applicationName, Helper::error),
Expand All @@ -347,7 +365,7 @@ void AddSubModelDialog::addSubModel()
}
}
QString annotation = QString("Placement(true,-,-,-10.0,-10.0,10.0,10.0,0,-,-,-,-,-,-,)");
AddSubModelCommand *pAddSubModelCommand = new AddSubModelCommand(mpNameTextBox->text(), mpPathTextBox->text(), 0,
AddSubModelCommand *pAddSubModelCommand = new AddSubModelCommand(mpNameTextBox->text(), mpPathTextBox->text(), mpStartScriptTextBox->text(), 0,
annotation, false, mpGraphicsView);
mpGraphicsView->getModelWidget()->getUndoStack()->push(pAddSubModelCommand);
mpGraphicsView->getModelWidget()->updateModelText();
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEdit/OMEditGUI/OMS/ModelDialog.h
Expand Up @@ -109,6 +109,8 @@ class AddSubModelDialog : public QDialog
Label *mpPathLabel;
QLineEdit *mpPathTextBox;
QPushButton *mpBrowsePathButton;
Label *mpStartScriptLabel;
QLineEdit *mpStartScriptTextBox;
QPushButton *mpOkButton;
QPushButton *mpCancelButton;
QDialogButtonBox *mpButtonBox;
Expand Down
29 changes: 29 additions & 0 deletions OMEdit/OMEdit/OMEditGUI/OMS/OMSProxy.cpp
Expand Up @@ -453,6 +453,17 @@ bool OMSProxy::addSubModel(QString cref, QString fmuPath)
return statusToBool(status);
}

bool OMSProxy::addExternalTLMModel(QString cref, QString startScript, QString modelPath)
{
QString command = "oms_addExternalModel";
QStringList args;
args << "\"" + cref + "\"" << modelPath << "\"" << startScript;
LOG_COMMAND(command, args);
oms_status_enu_t status = oms_addExternalModel(cref.toUtf8().constData(), modelPath.toUtf8().constData(), startScript.toUtf8().constData());
logResponse(command, status, &commandTime);
return statusToBool(status);
}

/*!
* \brief OMSProxy::addSystem
* Adds a system to a model.
Expand Down Expand Up @@ -748,6 +759,24 @@ bool OMSProxy::getFMUInfo(QString cref, const oms_fmu_info_t** pFmuInfo)
return statusToBool(status);
}

/*!
* \brief OMSProxy::getFMUInfo
* Gets the FMU info.
* \param cref
* \param pFmuInfo
* \return
*/
bool OMSProxy::getExternalTLMModelInfo(QString cref, const oms_external_tlm_model_info_t** pExternalTLMModelInfo)
{
QString command = "getExternalTLMModelInfo";
QStringList args;
args << "\"" + cref + "\"";
LOG_COMMAND(command, args);
oms_status_enu_t status = oms_getExternalModelInfo(cref.toUtf8().constData(), pExternalTLMModelInfo);
logResponse(command, status, &commandTime);
return statusToBool(status);
}

/*!
* \brief OMSProxy::getInteger
* Gets the integer variable value.
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEdit/OMEditGUI/OMS/OMSProxy.h
Expand Up @@ -78,6 +78,7 @@ class OMSProxy : public QObject
bool addConnectorToBus(QString busCref, QString connectorCref);
bool addConnectorToTLMBus(QString busCref, QString connectorCref, QString type);
bool addSubModel(QString cref, QString fmuPath);
bool addExternalTLMModel(QString cref, QString startScript, QString modelPath);
bool addSystem(QString cref, oms_system_enu_t type);
bool addTLMBus(QString cref, oms_tlm_domain_t domain, int dimensions, const oms_tlm_interpolation_t interpolation);
bool addTLMConnection(QString crefA, QString crefB, double delay, double alpha, double linearimpedance, double angularimpedance);
Expand All @@ -92,6 +93,7 @@ class OMSProxy : public QObject
bool getConnector(QString cref, oms_connector_t **pConnector);
bool getElement(QString cref, oms_element_t **pElement);
bool getElements(QString cref, oms_element_t ***pElements);
bool getExternalTLMModelInfo(QString cref, const oms_external_tlm_model_info_t** pExternalTLMModelInfo);
bool getFixedStepSize(QString cref, double* stepSize);
bool getFMUInfo(QString cref, const oms_fmu_info_t** pFmuInfo);
bool getInteger(QString signal, int* value);
Expand Down

0 comments on commit 55e2dbd

Please sign in to comment.