Skip to content

Commit

Permalink
Store attributes of submodel inside ComponentInfo of Component.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Mar 8, 2016
1 parent 6fb638a commit afa6bc7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 53 deletions.
10 changes: 9 additions & 1 deletion OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -75,6 +75,11 @@ ComponentInfo::ComponentInfo(QObject *pParent)
mModifiersMap.clear();
mParameterValueLoaded = false;
mParameterValue = "";
mStartCommand = "";
mExactStep = false;
mModelFile = "";
mPosition = "";
mAngle321 = "";
}

/*!
Expand Down Expand Up @@ -301,7 +306,10 @@ bool ComponentInfo::operator==(const ComponentInfo &componentInfo) const
(componentInfo.getOuter() == this->getOuter()) && (componentInfo.getCausality() == this->getCausality()) &&
(componentInfo.getArrayIndex() == this->getArrayIndex()) &&
(componentInfo.getModifiersMapWithoutFetching() == this->getModifiersMapWithoutFetching()) &&
(componentInfo.getParameterValueWithoutFetching() == this->getParameterValueWithoutFetching());
(componentInfo.getParameterValueWithoutFetching() == this->getParameterValueWithoutFetching()) &&
(componentInfo.getStartCommand() == this->getStartCommand()) && (componentInfo.getExactStep() == this->getExactStep()) &&
(componentInfo.getModelFile() == this->getModelFile()) && (componentInfo.getPosition() == this->getPosition()) &&
(componentInfo.getAngle321() == this->getAngle321());
}

/*!
Expand Down
18 changes: 18 additions & 0 deletions OMEdit/OMEditGUI/Component/Component.h
Expand Up @@ -106,6 +106,18 @@ class ComponentInfo : public QObject
void setParameterValue(QString parameterValue) {mParameterValue = parameterValue;}
QString getParameterValueWithoutFetching() const {return mParameterValue;}
QString getParameterValue(OMCProxy *pOMCProxy, QString className);
// MetaModel attributes
void setStartCommand(QString startCommand) {mStartCommand = startCommand;}
QString getStartCommand() const {return mStartCommand;}
void setExactStep(bool exactStep) {mExactStep = exactStep;}
bool getExactStep() const {return mExactStep;}
void setModelFile(QString modelFile) {mModelFile = modelFile;}
QString getModelFile() const {return mModelFile;}
void setPosition(QString position) {mPosition = position;}
QString getPosition() const {return mPosition;}
void setAngle321(QString angle321) {mAngle321 = angle321;}
QString getAngle321() const {return mAngle321;}
// operator overloading
bool operator==(const ComponentInfo &componentInfo) const;
bool operator!=(const ComponentInfo &componentInfo) const;
private:
Expand All @@ -129,6 +141,12 @@ class ComponentInfo : public QObject
QMap<QString, QString> mModifiersMap;
bool mParameterValueLoaded;
QString mParameterValue;
// MetaModel attributes
QString mStartCommand;
bool mExactStep;
QString mModelFile;
QString mPosition;
QString mAngle321;
};

class Component : public QObject, public QGraphicsItem
Expand Down
17 changes: 6 additions & 11 deletions OMEdit/OMEditGUI/Component/ComponentProperties.cpp
Expand Up @@ -1283,19 +1283,15 @@ void SubModelAttributes::setUpDialog()
*/
void SubModelAttributes::initializeDialog()
{
// get component Name
// set Name
mpNameTextBox->setText(mpComponent->getName());
// get the simulation start command and exact step flag of the submodel
LibraryTreeItem *pLibraryTreeItem = mpComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem();
if (pLibraryTreeItem->getLibraryType()== LibraryTreeItem::TLM) {
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpComponent->getGraphicsView()->getModelWidget()->getEditor());
mpStartCommandTextBox->setText(pTLMEditor->getSimulationToolStartCommand(mpComponent->getName()));
mpExactStepFlagCheckBox->setChecked(pTLMEditor->isExactStepFlagSet(mpComponent->getName()));
}
// 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
mpSimulationToolComboBox->setCurrentIndex(StringHandler::getSimulationTool(mpStartCommandTextBox->text()));
QFileInfo fileInfo(mpComponent->getLibraryTreeItem()->getFileName());
mpModelFileTextBox->setText(fileInfo.fileName());
mpModelFileTextBox->setText(mpComponent->getComponentInfo()->getModelFile());
}

void SubModelAttributes::changeSimulationToolStartCommand(QString tool)
Expand All @@ -1308,7 +1304,6 @@ void SubModelAttributes::changeSimulationTool(QString simulationToolStartCommand
mpSimulationToolComboBox->setCurrentIndex(StringHandler::getSimulationTool(simulationToolStartCommand));
}


/*!
Updates subModel parameters.\n
Slot activated when mpOkButton clicked signal is raised.
Expand Down
37 changes: 0 additions & 37 deletions OMEdit/OMEditGUI/Editors/TLMEditor.cpp
Expand Up @@ -143,23 +143,6 @@ 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");
}
}
return "";
}

/*!
* \brief TLMEditor::addSubModel
* Adds a SubModel tag with Annotation tag as child of it.
Expand Down Expand Up @@ -272,26 +255,6 @@ void TLMEditor::updateSubModelParameters(QString name, QString startCommand, QSt
}
}

/*!
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
2 changes: 0 additions & 2 deletions OMEdit/OMEditGUI/Editors/TLMEditor.h
Expand Up @@ -68,13 +68,11 @@ 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
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -1344,8 +1344,8 @@ void LibraryTreeModel::updateLibraryTreeItemClassText(LibraryTreeItem *pLibraryT
{
// set the library node not saved.
pLibraryTreeItem->setIsSaved(false);
updateLibraryTreeItem(pLibraryTreeItem);
if (pLibraryTreeItem->getLibraryType() == LibraryTreeItem::Modelica) {
updateLibraryTreeItem(pLibraryTreeItem);
// update the containing parent LibraryTreeItem class text.
LibraryTreeItem *pParentLibraryTreeItem = getContainingFileParentLibraryTreeItem(pLibraryTreeItem);
// we also mark the containing parent class unsaved because it is very important for saving of single file packages.
Expand Down
18 changes: 17 additions & 1 deletion OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -399,6 +399,8 @@ void GraphicsView::addComponentToClass(Component *pComponent)
startCommand = "";
}
QString visible = pComponent->mTransformation.getVisible() ? "true" : "false";
pComponent->getComponentInfo()->setStartCommand(startCommand);
pComponent->getComponentInfo()->setModelFile(fileInfo.fileName());
// add SubModel Element
pTLMEditor->addSubModel(pComponent->getName(), "false", fileInfo.fileName(), startCommand, visible, pComponent->getTransformationOrigin(),
pComponent->getTransformationExtent(), QString::number(pComponent->mTransformation.getRotateAngle()));
Expand Down Expand Up @@ -3512,8 +3514,22 @@ void ModelWidget::getTLMComponents()
LibraryTreeModel *pLibraryTreeModel = mpModelWidgetContainer->getMainWindow()->getLibraryWidget()->getLibraryTreeModel();
LibraryTreeItem *pLibraryTreeItem = pLibraryTreeModel->findLibraryTreeItem(subModel.attribute("Name"));
QStringList dialogAnnotation;
// get the attibutes of the submodel
ComponentInfo *pComponentInfo = new ComponentInfo;
pComponentInfo->setStartCommand(subModel.attribute("StartCommand"));
bool exactStep;
if (subModel.attribute("ExactStep").toLower().compare("1") == 0) {
exactStep = true;
} else if (subModel.attribute("ExactStep").toLower().compare("true") == 0) {
exactStep = true;
} else {
exactStep = false;
}
pComponentInfo->setExactStep(exactStep);
pComponentInfo->setModelFile(subModel.attribute("ModelFile"));
// add submodel as component to view.
mpDiagramGraphicsView->addComponentToView(subModel.attribute("Name"), pLibraryTreeItem, transformation, QPointF(0.0, 0.0), dialogAnnotation,
new ComponentInfo(), false, true);
pComponentInfo, false, true);
}
}

Expand Down

0 comments on commit afa6bc7

Please sign in to comment.