Skip to content

Commit

Permalink
-Editing of external model parameters
Browse files Browse the repository at this point in the history
-Editable start command so user can specify any command they wanted
  • Loading branch information
alash325 committed Dec 2, 2015
1 parent 55f4584 commit 7ff4d7e
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 9 deletions.
72 changes: 63 additions & 9 deletions OMEdit/OMEditGUI/Component/ComponentProperties.cpp
Expand Up @@ -1207,45 +1207,99 @@ void SubModelAttributes::setUpDialog()
mpNameLabel = new Label(Helper::name);
mpNameTextBox = new QLineEdit;
mpNameTextBox->setReadOnly(true);
// Create the simulation tool label and combo box
mpSimulationToolLabel = new Label(tr("Simulation Tool"));
mpSimulationToolComboBox = new QComboBox;
mpSimulationToolComboBox->addItem(StringHandler::getSimulationTool(StringHandler::Adams));
mpSimulationToolComboBox->addItem(StringHandler::getSimulationTool(StringHandler::Beast));
mpSimulationToolComboBox->addItem(StringHandler::getSimulationTool(StringHandler::Dymola));
mpSimulationToolComboBox->addItem(StringHandler::getSimulationTool(StringHandler::OpenModelica));
mpSimulationToolComboBox->addItem(StringHandler::getSimulationTool(StringHandler::Simulink));
mpSimulationToolComboBox->addItem(StringHandler::getSimulationTool(StringHandler::WolframSystemModeler));
mpSimulationToolComboBox->addItem(StringHandler::getSimulationTool(StringHandler::Other));
connect(mpSimulationToolComboBox, SIGNAL(currentIndexChanged(QString)), SLOT(changeSimulationToolStartCommand(QString)));
// Create the start command label and text box
mpStartCommandLabel = new Label(tr("Start Command:"));
mpStartCommandTextBox = new QLineEdit;
mpStartCommandTextBox->setReadOnly(true);
connect(mpStartCommandTextBox, SIGNAL(textChanged(QString)), SLOT(changeSimulationTool(QString)));
// Create the model file label and text box
mpModelFileLabel = new Label(tr("Model File:"));
mpModelFileTextBox = new QLineEdit;
mpModelFileTextBox->setReadOnly(true);
// Create the exact step flag check box
mpExactStepFlagCheckBox = new QCheckBox(tr("Exact Step Flag"));
// Create the buttons
mpOkButton = new QPushButton(Helper::ok);
mpOkButton->setAutoDefault(true);
connect(mpOkButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(mpOkButton, SIGNAL(clicked()), this, SLOT(updateSubModelParameters()));
mpCancelButton = new QPushButton(Helper::cancel);
mpCancelButton->setAutoDefault(false);
connect(mpCancelButton, SIGNAL(clicked()), this, SLOT(reject()));
// Create buttons box
mpButtonBox = new QDialogButtonBox(Qt::Horizontal);
mpButtonBox->addButton(mpOkButton, QDialogButtonBox::ActionRole);
mpButtonBox->addButton(mpCancelButton, QDialogButtonBox::ActionRole);
// Create a layout
QGridLayout *pMainLayout = new QGridLayout;
pMainLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
pMainLayout->addWidget(mpNameLabel, 0, 0);
pMainLayout->addWidget(mpNameTextBox, 0, 1);
pMainLayout->addWidget(mpStartCommandLabel, 1, 0);
pMainLayout->addWidget(mpStartCommandTextBox, 1, 1);
pMainLayout->addWidget(mpModelFileLabel, 2, 0);
pMainLayout->addWidget(mpModelFileTextBox, 2, 1);
pMainLayout->addWidget(mpButtonBox, 3, 0, 1, 2, Qt::AlignRight);
pMainLayout->addWidget(mpModelFileLabel, 1, 0);
pMainLayout->addWidget(mpModelFileTextBox, 1, 1);
pMainLayout->addWidget(mpSimulationToolLabel, 2, 0);
pMainLayout->addWidget(mpSimulationToolComboBox, 2, 1);
pMainLayout->addWidget(mpStartCommandLabel, 3, 0);
pMainLayout->addWidget(mpStartCommandTextBox, 3, 1);
pMainLayout->addWidget(mpExactStepFlagCheckBox, 4, 0 );
pMainLayout->addWidget(mpButtonBox, 5, 0, 1, 2, Qt::AlignRight);
setLayout(pMainLayout);
}

/*!
Initialize the fields with default values.
Initialize the fields with values.
*/
void SubModelAttributes::initializeDialog()
{
// get component Name
mpNameTextBox->setText(mpComponent->getName());
mpStartCommandTextBox->setText("StartTLMOpenModelica");
// get the simulation start command and exact step flag of the submodel
LibraryTreeNode *pLibraryTreeNode = mpComponent->getGraphicsView()->getModelWidget()->getLibraryTreeNode();
if (pLibraryTreeNode->getLibraryType()== LibraryTreeNode::TLM) {
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpComponent->getGraphicsView()->getModelWidget()->getEditor());
mpStartCommandTextBox->setText(pTLMEditor->getSimulationToolStartCommand(mpComponent->getName()));
mpExactStepFlagCheckBox->setChecked(pTLMEditor->isExactStepFlagSet(mpComponent->getName()));
}
// get the simulation tool of the submodel
mpSimulationToolComboBox->setCurrentIndex(StringHandler::getSimulationTool(mpStartCommandTextBox->text()));
QFileInfo fileInfo(mpComponent->getFileName());
mpModelFileTextBox->setText(fileInfo.fileName());
}

void SubModelAttributes::changeSimulationToolStartCommand(QString tool)
{
mpStartCommandTextBox->setText(StringHandler::getSimulationToolStartCommand(tool, mpStartCommandTextBox->text()));
}

void SubModelAttributes::changeSimulationTool(QString simulationToolStartCommand)
{
mpSimulationToolComboBox->setCurrentIndex(StringHandler::getSimulationTool(simulationToolStartCommand));
}


/*!
Updates subModel parameters.\n
Slot activated when mpOkButton clicked signal is raised.
*/
void SubModelAttributes::updateSubModelParameters()
{
QString exactStepFlag = mpExactStepFlagCheckBox->isChecked() ? "1" : "0";
LibraryTreeNode *pLibraryTreeNode = mpComponent->getGraphicsView()->getModelWidget()->getLibraryTreeNode();
if (pLibraryTreeNode->getLibraryType()== LibraryTreeNode::TLM) {
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpComponent->getGraphicsView()->getModelWidget()->getEditor());
pTLMEditor->updateSubModelParameters(mpComponent->getName(), mpStartCommandTextBox->text(), exactStepFlag);
accept();
}
}
TLMInterfacePointInfo::TLMInterfacePointInfo(QString name, QString className, QString interfaceName)
{
mName = name;
Expand Down
9 changes: 9 additions & 0 deletions OMEdit/OMEditGUI/Component/ComponentProperties.h
Expand Up @@ -208,12 +208,21 @@ class SubModelAttributes : public QDialog
MainWindow *mpMainWindow;
Label *mpNameLabel;
QLineEdit *mpNameTextBox;
Label *mpSimulationToolLabel;
QComboBox *mpSimulationToolComboBox;
Label *mpStartCommandLabel;
QLineEdit *mpStartCommandTextBox;
Label *mpModelFileLabel;
QLineEdit *mpModelFileTextBox;
Label *mpExactStepFlagLabel;
QCheckBox *mpExactStepFlagCheckBox;
QPushButton *mpOkButton;
QPushButton *mpCancelButton;
QDialogButtonBox *mpButtonBox;
private slots:
void changeSimulationToolStartCommand(QString tool);
void changeSimulationTool(QString simulationToolStartCommand);
void updateSubModelParameters();
};

class Component;
Expand Down
57 changes: 57 additions & 0 deletions OMEdit/OMEditGUI/Editors/TLMEditor.cpp
Expand Up @@ -144,6 +144,22 @@ QDomNodeList TLMEditor::getConnections()
return mXmlDocument.elementsByTagName("Connection");
}

/*!
* \brief TLMEditor::getSimulationToolStartCommand
* Returns the simulation tool start command.
* \return
*/
QString TLMEditor::getSimulationToolStartCommand(QString name)
{
QDomNodeList subModelList = mXmlDocument.elementsByTagName("SubModel");
for (int i = 0 ; i < subModelList.size() ; i++) {
QDomElement subModel = subModelList.at(i).toElement();
if (subModel.attribute("Name").compare(name) == 0) {
return subModel.attribute("StartCommand");
}
}
}

/*!
* \brief TLMEditor::addSubModel
* Adds a SubModel tag with Annotation tag as child of it.
Expand Down Expand Up @@ -235,6 +251,47 @@ void TLMEditor::updateSubModelPlacementAnnotation(QString name, QString visible,
}
}

/*!
* \brief TLMEditor::updateSubModelParameters
* Updates the SubModel parameters.
* \param name
* \param startCommand
* \param ExactStepflag
*/
void TLMEditor::updateSubModelParameters(QString name, QString startCommand, QString exactStepFlag)
{
QDomNodeList subModelList = mXmlDocument.elementsByTagName("SubModel");
for (int i = 0 ; i < subModelList.size() ; i++) {
QDomElement subModel = subModelList.at(i).toElement();
if (subModel.attribute("Name").compare(name) == 0) {
subModel.setAttribute("StartCommand", startCommand);
subModel.setAttribute("ExactStep", exactStepFlag);
mpPlainTextEdit->setPlainText(mXmlDocument.toString());
return;
}
}
}

/*!
Checks whether the exact step flag is set to 1 or not.
\param subModelName - the name for the submodel to check.
\return true on success.
*/
bool TLMEditor::isExactStepFlagSet(QString subModelName)
{
QDomNodeList subModelList = mXmlDocument.elementsByTagName("SubModel");
for (int i = 0 ; i < subModelList.size() ; i++) {
QDomElement subModel = subModelList.at(i).toElement();
if (subModel.attribute("Name").compare(subModelName) == 0) {
if (subModel.attribute("ExactStep").compare("1") == 0 ) {
return true;
}
}
break;
}
return false;
}

/*!
* \brief TLMEditor::createConnection
* Adds a a connection tag with Annotation tag as child of it.
Expand Down
3 changes: 3 additions & 0 deletions OMEdit/OMEditGUI/Editors/TLMEditor.h
Expand Up @@ -53,10 +53,13 @@ class TLMEditor : public BaseEditor
QDomNodeList getSubModels();
QDomElement getConnectionsElement();
QDomNodeList getConnections();
QString getSimulationToolStartCommand(QString name);
bool addSubModel(QString name, QString exactStep, QString modelFile, QString startCommand, QString visible, QString origin, QString extent,
QString rotation);
void createAnnotationElement(QDomElement subModel, QString visible, QString origin, QString extent, QString rotation);
void updateSubModelPlacementAnnotation(QString name, QString visible, QString origin, QString extent, QString rotation);
void updateSubModelParameters(QString name, QString startCommand, QString exactStepFlag);
bool isExactStepFlagSet(QString subModelName);
bool createConnection(QString From, QString To, QString delay, QString alpha, QString zf, QString zfr, QString points);
void updateTLMConnectiontAnnotation(QString fromSubModel, QString toSubModel, QString points);
void addInterfacesData(QDomElement interfaces);
Expand Down
63 changes: 63 additions & 0 deletions OMEdit/OMEditGUI/Util/StringHandler.cpp
Expand Up @@ -64,6 +64,69 @@ StringHandler::~StringHandler()

}

QString StringHandler::getSimulationTool(int tool)
{
switch (tool)
{
case StringHandler::Adams:
return "ADAMS";
case StringHandler::Beast:
return "BEAST";
case StringHandler::Dymola:
return "Dymola";
case StringHandler::OpenModelica:
return "OpenModelica";
case StringHandler::Simulink:
return "Simulink";
case StringHandler::WolframSystemModeler:
return "Wolfram SystemModeler";
case StringHandler::Other:
return "Other";
default:
// should never be reached
return "";
}
}

QString StringHandler::getSimulationToolStartCommand(QString tool, QString simulationToolStartCommand)
{
if (tool.toLower().contains("adams"))
return "startTLMAdams";
else if (tool.toLower().contains("beast"))
return "startTLMBeast";
else if (tool.toLower().contains("dymola"))
return "startTLMDymola";
else if (tool.toLower().contains("openmodelica"))
return "startTLMOpenModelica";
else if (tool.toLower().contains("simulink"))
return "startTLMSimulink";
else if (tool.toLower().contains("wolfram systemmodeler"))
return "startTLMWSM";
else if (tool.toLower().contains("other"))
return simulationToolStartCommand;
else
// should never be reached
return "";
}

StringHandler::SimulationTools StringHandler::getSimulationTool(QString simulationToolStartCommand)
{
if (simulationToolStartCommand.toLower().compare("starttlmadams")== 0)
return StringHandler::Adams;
else if (simulationToolStartCommand.toLower().compare("starttlmbeast")== 0)
return StringHandler::Beast;
else if (simulationToolStartCommand.toLower().compare("starttlmdymola")== 0)
return StringHandler::Dymola;
else if (simulationToolStartCommand.toLower().compare("starttlmopenmodelica")== 0)
return StringHandler::OpenModelica;
else if (simulationToolStartCommand.toLower().compare("starttlmsimulink")== 0)
return StringHandler::Simulink;
else if (simulationToolStartCommand.toLower().compare("starttlmwsm")== 0)
return StringHandler::WolframSystemModeler;
else
return StringHandler::Other;
}

QString StringHandler::getModelicaClassType(int type)
{
switch (type)
Expand Down
4 changes: 4 additions & 0 deletions OMEdit/OMEditGUI/Util/StringHandler.h
Expand Up @@ -76,6 +76,10 @@ class StringHandler : public QObject
Debug,
OMEditInfo /* used internally by OMEdit to mark message blue. */
};
enum SimulationTools {Adams, Beast, Dymola, OpenModelica, Simulink, WolframSystemModeler, Other};
static QString getSimulationTool(int tool);
static QString getSimulationToolStartCommand(QString tool, QString simulationToolStartCommand);
static StringHandler::SimulationTools getSimulationTool(QString simulationToolStartCommand);
static QString getModelicaClassType(int type);
static StringHandler::ModelicaClasses getModelicaClassType(QString type);
static QString getViewType(int type);
Expand Down

0 comments on commit 7ff4d7e

Please sign in to comment.