Skip to content

Commit

Permalink
Allow users to specify the geometry files from the GUI.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Nov 15, 2016
1 parent ccaec3f commit 3ca15dd
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 27 deletions.
6 changes: 4 additions & 2 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -76,6 +76,7 @@ ComponentInfo::ComponentInfo(QObject *pParent)
mStartCommand = "";
mExactStep = false;
mModelFile = "";
mGeometryFile = "";
mPosition = "";
mAngle321 = "";
}
Expand Down Expand Up @@ -122,6 +123,7 @@ void ComponentInfo::updateComponentInfo(const ComponentInfo *pComponentInfo)
mStartCommand = pComponentInfo->getStartCommand();
mExactStep = pComponentInfo->getExactStep();
mModelFile = pComponentInfo->getModelFile();
mGeometryFile = pComponentInfo->getGeometryFile();
mPosition = pComponentInfo->getPosition();
mAngle321 = pComponentInfo->getAngle321();
}
Expand Down Expand Up @@ -360,8 +362,8 @@ bool ComponentInfo::operator==(const ComponentInfo &componentInfo) const
(componentInfo.getModifiersMapWithoutFetching() == this->getModifiersMapWithoutFetching()) &&
(componentInfo.getParameterValueWithoutFetching() == this->getParameterValueWithoutFetching()) &&
(componentInfo.getStartCommand() == this->getStartCommand()) && (componentInfo.getExactStep() == this->getExactStep()) &&
(componentInfo.getModelFile() == this->getModelFile()) && (componentInfo.getPosition() == this->getPosition()) &&
(componentInfo.getAngle321() == this->getAngle321());
(componentInfo.getModelFile() == this->getModelFile()) && (componentInfo.getGeometryFile() == this->getGeometryFile()) &&
(componentInfo.getPosition() == this->getPosition()) && (componentInfo.getAngle321() == this->getAngle321());
}

/*!
Expand Down
3 changes: 3 additions & 0 deletions OMEdit/OMEditGUI/Component/Component.h
Expand Up @@ -111,6 +111,8 @@ class ComponentInfo : public QObject
bool getExactStep() const {return mExactStep;}
void setModelFile(QString modelFile) {mModelFile = modelFile;}
QString getModelFile() const {return mModelFile;}
void setGeometryFile(QString geometryFile) {mGeometryFile = geometryFile;}
QString getGeometryFile() const {return mGeometryFile;}
void setPosition(QString position) {mPosition = position;}
QString getPosition() const {return mPosition;}
void setAngle321(QString angle321) {mAngle321 = angle321;}
Expand Down Expand Up @@ -143,6 +145,7 @@ class ComponentInfo : public QObject
QString mStartCommand;
bool mExactStep;
QString mModelFile;
QString mGeometryFile;
QString mPosition;
QString mAngle321;

Expand Down
63 changes: 51 additions & 12 deletions OMEdit/OMEditGUI/Component/ComponentProperties.cpp
Expand Up @@ -1392,7 +1392,6 @@ MetaModelSubModelAttributes::MetaModelSubModelAttributes(Component *pComponent,
{
setWindowTitle(QString(Helper::applicationName).append(" - ").append(tr("SubModel Attributes")));
setAttribute(Qt::WA_DeleteOnClose);
setMinimumWidth(250);
mpComponent = pComponent;
mpMainWindow = pMainWindow;
setUpDialog();
Expand Down Expand Up @@ -1428,8 +1427,13 @@ void MetaModelSubModelAttributes::setUpDialog()
mpModelFileLabel = new Label(tr("Model File:"));
mpModelFileTextBox = new QLineEdit;
mpModelFileTextBox->setDisabled(true);
// Create the exact step flag check box
mpExactStepFlagCheckBox = new QCheckBox(tr("Exact Step Flag"));
// Create the exact step check box
mpExactStepCheckBox = new QCheckBox(tr("Exact Step"));
// geometry file label, text box and browse button
mpGeometryFileLabel = new Label(tr("Geometry File:"));
mpGeometryFileTextBox = new QLineEdit;
mpGeometryFileBrowseButton = new QPushButton(Helper::browse);
connect(mpGeometryFileBrowseButton, SIGNAL(clicked()), this, SLOT(browseGeometryFile()));
// Create the buttons
mpOkButton = new QPushButton(Helper::ok);
mpOkButton->setAutoDefault(true);
Expand All @@ -1445,15 +1449,18 @@ void MetaModelSubModelAttributes::setUpDialog()
QGridLayout *pMainLayout = new QGridLayout;
pMainLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
pMainLayout->addWidget(mpNameLabel, 0, 0);
pMainLayout->addWidget(mpNameTextBox, 0, 1);
pMainLayout->addWidget(mpNameTextBox, 0, 1, 1, 2);
pMainLayout->addWidget(mpModelFileLabel, 1, 0);
pMainLayout->addWidget(mpModelFileTextBox, 1, 1);
pMainLayout->addWidget(mpModelFileTextBox, 1, 1, 1, 2);
pMainLayout->addWidget(mpSimulationToolLabel, 2, 0);
pMainLayout->addWidget(mpSimulationToolComboBox, 2, 1);
pMainLayout->addWidget(mpSimulationToolComboBox, 2, 1, 1, 2);
pMainLayout->addWidget(mpStartCommandLabel, 3, 0);
pMainLayout->addWidget(mpStartCommandTextBox, 3, 1);
pMainLayout->addWidget(mpExactStepFlagCheckBox, 4, 0 );
pMainLayout->addWidget(mpButtonBox, 5, 0, 1, 2, Qt::AlignRight);
pMainLayout->addWidget(mpStartCommandTextBox, 3, 1, 1, 2);
pMainLayout->addWidget(mpExactStepCheckBox, 4, 0 );
pMainLayout->addWidget(mpGeometryFileLabel, 5, 0);
pMainLayout->addWidget(mpGeometryFileTextBox, 5, 1);
pMainLayout->addWidget(mpGeometryFileBrowseButton, 5, 2);
pMainLayout->addWidget(mpButtonBox, 6, 0, 1, 3, Qt::AlignRight);
setLayout(pMainLayout);
}

Expand All @@ -1467,22 +1474,53 @@ void MetaModelSubModelAttributes::initializeDialog()
// set the start command
mpStartCommandTextBox->setText(mpComponent->getComponentInfo()->getStartCommand());
// set the exact step
mpExactStepFlagCheckBox->setChecked(mpComponent->getComponentInfo()->getExactStep());
// get the simulation tool of the submodel
mpExactStepCheckBox->setChecked(mpComponent->getComponentInfo()->getExactStep());
// set the simulation tool of the submodel
mpSimulationToolComboBox->setCurrentIndex(StringHandler::getSimulationTool(mpStartCommandTextBox->text()));
// set the model file name
mpModelFileTextBox->setText(mpComponent->getComponentInfo()->getModelFile());
// set the geometry file name
mpGeometryFileTextBox->setText(mpComponent->getComponentInfo()->getGeometryFile());

}

/*!
* \brief MetaModelSubModelAttributes::changeSimulationToolStartCommand
* Updates the simulation tool start command.\n
* Slot activated when mpSimulationToolComboBox currentIndexChanged signal is raised.
* \param tool
*/
void MetaModelSubModelAttributes::changeSimulationToolStartCommand(QString tool)
{
mpStartCommandTextBox->setText(StringHandler::getSimulationToolStartCommand(tool, mpStartCommandTextBox->text()));
}

/*!
* \brief MetaModelSubModelAttributes::changeSimulationTool
* Updates the simulation tool.\n
* Slot activated when mpStartCommandTextBox textChanged signal is raised.
* \param simulationToolStartCommand
*/
void MetaModelSubModelAttributes::changeSimulationTool(QString simulationToolStartCommand)
{
mpSimulationToolComboBox->setCurrentIndex(StringHandler::getSimulationTool(simulationToolStartCommand));
}

/*!
* \brief MetaModelSubModelAttributes::browseGeometryFile
* Updates subModel parameters.\n
* Slot activated when mpGeometryFileBrowseButton clicked signal is raised.
*/
void MetaModelSubModelAttributes::browseGeometryFile()
{
QString geometryFile = StringHandler::getOpenFileName(this, QString("%1 - %2").arg(Helper::applicationName).arg(Helper::chooseFile),
NULL, "", NULL);
if (geometryFile.isEmpty()) {
return;
}
mpGeometryFileTextBox->setText(geometryFile);
}

/*!
* \brief MetaModelSubModelAttributes::updateSubModelParameters
* Updates subModel parameters.\n
Expand All @@ -1495,7 +1533,8 @@ void MetaModelSubModelAttributes::updateSubModelParameters()
// Create a new ComponentInfo
ComponentInfo newComponentInfo(mpComponent->getComponentInfo());
newComponentInfo.setStartCommand(mpStartCommandTextBox->text());
newComponentInfo.setExactStep(mpExactStepFlagCheckBox->isChecked());
newComponentInfo.setExactStep(mpExactStepCheckBox->isChecked());
newComponentInfo.setGeometryFile(mpGeometryFileTextBox->text());
// If user has really changed the Component's attributes then push that change on the stack.
if (oldComponentInfo != newComponentInfo) {
UpdateSubModelAttributesCommand *pUpdateSubModelAttributesCommand = new UpdateSubModelAttributesCommand(mpComponent, oldComponentInfo,
Expand Down
6 changes: 5 additions & 1 deletion OMEdit/OMEditGUI/Component/ComponentProperties.h
Expand Up @@ -237,13 +237,17 @@ class MetaModelSubModelAttributes : public QDialog
Label *mpModelFileLabel;
QLineEdit *mpModelFileTextBox;
Label *mpExactStepFlagLabel;
QCheckBox *mpExactStepFlagCheckBox;
QCheckBox *mpExactStepCheckBox;
Label *mpGeometryFileLabel;
QLineEdit *mpGeometryFileTextBox;
QPushButton *mpGeometryFileBrowseButton;
QPushButton *mpOkButton;
QPushButton *mpCancelButton;
QDialogButtonBox *mpButtonBox;
private slots:
void changeSimulationToolStartCommand(QString tool);
void changeSimulationTool(QString simulationToolStartCommand);
void browseGeometryFile();
void updateSubModelParameters();
};

Expand Down
17 changes: 12 additions & 5 deletions OMEdit/OMEditGUI/Editors/MetaModelEditor.cpp
Expand Up @@ -317,23 +317,30 @@ void MetaModelEditor::updateSubModelPlacementAnnotation(QString name, QString vi
* Updates the SubModel parameters.
* \param name
* \param startCommand
* \param ExactStepflag
* \param exactStep
* \param geometryFile
*/
void MetaModelEditor::updateSubModelParameters(QString name, QString startCommand, QString exactStepFlag)
void MetaModelEditor::updateSubModelParameters(QString name, QString startCommand, QString exactStep, QString geometryFile)
{
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);
if (exactStepFlag.compare("true") == 0) {
subModel.setAttribute("ExactStep", exactStepFlag);
if (exactStep.compare("true") == 0) {
subModel.setAttribute("ExactStep", exactStep);
} else if (subModel.hasAttribute("ExactStep")) {
subModel.removeAttribute("ExactStep");
}
if (geometryFile.isEmpty()) {
subModel.removeAttribute("GeometryFile");
} else {
QFileInfo geometryFileInfo(geometryFile);
subModel.setAttribute("GeometryFile", geometryFileInfo.fileName());
}
setPlainText(mXmlDocument.toString());
return;
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Editors/MetaModelEditor.h
Expand Up @@ -79,7 +79,7 @@ class MetaModelEditor : public BaseEditor
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);
void updateSubModelParameters(QString name, QString startCommand, QString exactStep, QString geometryFile);
void updateSubModelOrientation(QString name, QGenericMatrix<3,1,double> rot, QGenericMatrix<3,1,double> pos);
bool createConnection(LineAnnotation *pConnectionLineAnnotation);
void updateConnection(LineAnnotation *pConnectionLineAnnotation);
Expand Down
6 changes: 4 additions & 2 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -1149,9 +1149,10 @@ void UpdateSubModelAttributesCommand::redo()
{
MetaModelEditor *pMetaModelEditor = dynamic_cast<MetaModelEditor*>(mpComponent->getGraphicsView()->getModelWidget()->getEditor());
pMetaModelEditor->updateSubModelParameters(mpComponent->getName(), mNewComponentInfo.getStartCommand(),
mNewComponentInfo.getExactStep() ? "true" : "false");
mNewComponentInfo.getExactStep() ? "true" : "false", mNewComponentInfo.getGeometryFile());
mpComponent->getComponentInfo()->setStartCommand(mNewComponentInfo.getStartCommand());
mpComponent->getComponentInfo()->setExactStep(mNewComponentInfo.getExactStep());
mpComponent->getComponentInfo()->setGeometryFile(mNewComponentInfo.getGeometryFile());
}

/*!
Expand All @@ -1162,9 +1163,10 @@ void UpdateSubModelAttributesCommand::undo()
{
MetaModelEditor *pMetaModelEditor = dynamic_cast<MetaModelEditor*>(mpComponent->getGraphicsView()->getModelWidget()->getEditor());
pMetaModelEditor->updateSubModelParameters(mpComponent->getName(), mOldComponentInfo.getStartCommand(),
mOldComponentInfo.getExactStep() ? "true" : "false");
mOldComponentInfo.getExactStep() ? "true" : "false", mOldComponentInfo.getGeometryFile());
mpComponent->getComponentInfo()->setStartCommand(mOldComponentInfo.getStartCommand());
mpComponent->getComponentInfo()->setExactStep(mOldComponentInfo.getExactStep());
mpComponent->getComponentInfo()->setGeometryFile(mOldComponentInfo.getGeometryFile());
}

UpdateSimulationParamsCommand::UpdateSimulationParamsCommand(LibraryTreeItem *pLibraryTreeItem, QString oldStartTime, QString newStartTime, QString oldStopTime,
Expand Down
17 changes: 13 additions & 4 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -4148,12 +4148,21 @@ bool LibraryWidget::saveMetaModelLibraryTreeItem(LibraryTreeItem *pLibraryTreeIt
}
// copy the submodel file to the created directory
QFileInfo modelFileInfo(modelFile);
QString newFileName = directoryPath + "/" + modelFileInfo.fileName();
if (modelFileInfo.absoluteFilePath().compare(newFileName) != 0) {
QString newModelFilePath = directoryPath + "/" + modelFileInfo.fileName();
if (modelFileInfo.absoluteFilePath().compare(newModelFilePath) != 0) {
// first try to remove the file because QFile::copy will not override the file.
QFile::remove(newFileName);
QFile::remove(newModelFilePath);
}
QFile::copy(modelFileInfo.absoluteFilePath(), newFileName);
QFile::copy(modelFileInfo.absoluteFilePath(), newModelFilePath);
// copy the geomtry file to the created directory
QFileInfo geometryFileInfo(pComponent->getComponentInfo()->getGeometryFile());
QString newGeometryFilePath = directoryPath + "/" + geometryFileInfo.fileName();
if (geometryFileInfo.absoluteFilePath().compare(newGeometryFilePath) != 0) {
// first try to remove the file because QFile::copy will not override the file.
QFile::remove(newGeometryFilePath);
}
QFile::copy(geometryFileInfo.absoluteFilePath(), newGeometryFilePath);
pComponent->getComponentInfo()->setGeometryFile(newGeometryFilePath);
}
} else {
return false;
Expand Down
13 changes: 13 additions & 0 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -3837,6 +3837,19 @@ void ModelWidget::getMetaModelSubModels()
MessagesWidget *pMessagesWidget = mpModelWidgetContainer->getMainWindow()->getMessagesWidget();
pMessagesWidget->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, msg, Helper::scriptingKind, Helper::errorLevel));
}
// Geometry File
if (!subModel.attribute("GeometryFile").isEmpty()) {
QString absoluteGeometryFilePath = QString("%1/%2/%3").arg(fileInfo.absolutePath()).arg(subModel.attribute("Name"))
.arg(subModel.attribute("GeometryFile"));
pComponentInfo->setGeometryFile(absoluteGeometryFilePath);
// if GeometryFile doesn't exist
if (!QFile::exists(absoluteGeometryFilePath)) {
QString msg = tr("Unable to find GeometryFile <b>%1</b> for SubModel <b>%2</b>. The file location should be <b>%3</b>.")
.arg(subModel.attribute("GeometryFile")).arg(subModel.attribute("Name")).arg(absoluteGeometryFilePath);
MessagesWidget *pMessagesWidget = mpModelWidgetContainer->getMainWindow()->getMessagesWidget();
pMessagesWidget->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, msg, Helper::scriptingKind, Helper::errorLevel));
}
}
// add submodel as component to view.
mpDiagramGraphicsView->addComponentToView(subModel.attribute("Name"), pLibraryTreeItem, transformation, QPointF(0.0, 0.0), dialogAnnotation,
pComponentInfo, false, true);
Expand Down

0 comments on commit 3ca15dd

Please sign in to comment.