Skip to content

Commit

Permalink
Fixed getTLMComponents. Generate default annotation for sub-models th…
Browse files Browse the repository at this point in the history
…at doesn't have any.

Some source code documentation.
  • Loading branch information
adeas31 committed Jun 22, 2015
1 parent 825f74c commit b8c416e
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 36 deletions.
70 changes: 67 additions & 3 deletions OMEdit/OMEditGUI/Editors/TLMEditor.cpp
Expand Up @@ -94,6 +94,11 @@ void TLMEditor::setPlainText(const QString &text)
}
}

/*!
* \brief TLMEditor::getSubModelsElement
* Returns the SubModels element tag.
* \return
*/
QDomElement TLMEditor::getSubModelsElement()
{
QDomNodeList subModels = mXmlDocument.elementsByTagName("SubModels");
Expand All @@ -103,11 +108,29 @@ QDomElement TLMEditor::getSubModelsElement()
return QDomElement();
}

/*!
* \brief TLMEditor::getSubModels
* Returns the list of SubModel tags.
* \return
*/
QDomNodeList TLMEditor::getSubModels()
{
return mXmlDocument.elementsByTagName("SubModel");
}

/*!
* \brief TLMEditor::addSubModel
* Adds a SubModel tag with Annotation tag as child of it.
* \param name
* \param exactStep
* \param modelFile
* \param startCommand
* \param visible
* \param origin
* \param extent
* \param rotation
* \return
*/
bool TLMEditor::addSubModel(QString name, QString exactStep, QString modelFile, QString startCommand, QString visible, QString origin,
QString extent, QString rotation)
{
Expand All @@ -132,7 +155,36 @@ bool TLMEditor::addSubModel(QString name, QString exactStep, QString modelFile,
return false;
}

bool TLMEditor::updateSubModelPlacementAnnotation(QString name, QString visible, QString origin, QString extent, QString rotation)
/*!
* \brief TLMEditor::createAnnotationElement
* Creates an Annotation tag for SubModel.
* \param subModel
* \param visible
* \param origin
* \param extent
* \param rotation
*/
void TLMEditor::createAnnotationElement(QDomElement subModel, QString visible, QString origin, QString extent, QString rotation)
{
QDomElement annotation = mXmlDocument.createElement("Annotation");
annotation.setAttribute("Visible", visible);
annotation.setAttribute("Origin", origin);
annotation.setAttribute("Extent", extent);
annotation.setAttribute("Rotation", rotation);
subModel.insertBefore(annotation, QDomNode());
mpPlainTextEdit->setPlainText(mXmlDocument.toString());
}

/*!
* \brief TLMEditor::updateSubModelPlacementAnnotation
* Updates the SubModel annotation.
* \param name
* \param visible
* \param origin
* \param extent
* \param rotation
*/
void TLMEditor::updateSubModelPlacementAnnotation(QString name, QString visible, QString origin, QString extent, QString rotation)
{
QDomNodeList subModelList = mXmlDocument.elementsByTagName("SubModel");
for (int i = 0 ; i < subModelList.size() ; i++) {
Expand All @@ -147,15 +199,21 @@ bool TLMEditor::updateSubModelPlacementAnnotation(QString name, QString visible,
annotationElement.setAttribute("Extent", extent);
annotationElement.setAttribute("Rotation", rotation);
mpPlainTextEdit->setPlainText(mXmlDocument.toString());
return true;
return;
}
}
// create annotation element
createAnnotationElement(subModel, visible, origin, extent, rotation);
break;
}
}
return false;
}

/*!
* \brief TLMEditor::addInterfacesData
* Adds the InterfacePoint tag to SubModel.
* \param interfaces
*/
void TLMEditor::addInterfacesData(QDomElement interfaces)
{
QDomNodeList subModelList = mXmlDocument.elementsByTagName("SubModel");
Expand All @@ -176,6 +234,12 @@ void TLMEditor::addInterfacesData(QDomElement interfaces)
}
}

/*!
* \brief TLMEditor::deleteSubModel
* Delets a SubModel.
* \param name
* \return
*/
bool TLMEditor::deleteSubModel(QString name)
{
QDomNodeList subModelList = mXmlDocument.elementsByTagName("SubModel");
Expand Down
3 changes: 2 additions & 1 deletion OMEdit/OMEditGUI/Editors/TLMEditor.h
Expand Up @@ -53,7 +53,8 @@ class TLMEditor : public BaseEditor
QDomNodeList getSubModels();
bool addSubModel(QString name, QString exactStep, QString modelFile, QString startCommand, QString visible, QString origin, QString extent,
QString rotation);
bool updateSubModelPlacementAnnotation(QString name, 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 addInterfacesData(QDomElement interfaces);
bool deleteSubModel(QString name);
private:
Expand Down
7 changes: 6 additions & 1 deletion OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -1292,7 +1292,12 @@ bool LibraryTreeWidget::saveTLMLibraryTreeNode(LibraryTreeNode *pLibraryTreeNode
// copy the submodel file to the created directory
QString modelFile = pComponent->getFileName();
QFileInfo modelFileInfo(modelFile);
QFile::copy(modelFileInfo.absoluteFilePath(), directoryPath + "/" + modelFileInfo.fileName());
QString newFileName = directoryPath + "/" + modelFileInfo.fileName();
if (modelFileInfo.absoluteFilePath().compare(newFileName) != 0) {
// first try to remove the file because QFile::copy will not override the file.
QFile::remove(newFileName);
}
QFile::copy(modelFileInfo.absoluteFilePath(), newFileName);
}
}
} else {
Expand Down
58 changes: 27 additions & 31 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -2467,39 +2467,35 @@ void ModelWidget::getModelComponents(QString className, bool inheritedCycle)
*/
void ModelWidget::getTLMComponents()
{
// get the components and thier annotation
QDomDocument TLMMetaModel;
TLMMetaModel.setContent(getEditor()->getPlainTextEdit()->toPlainText());

// Get the "Root" element
QDomElement rootElement = TLMMetaModel.documentElement();

QDomElement subModels = rootElement.firstChildElement();
while (!subModels.isNull())
{
if(subModels.tagName() == "SubModels")
break;
subModels = subModels.nextSiblingElement();
}

QDomElement subModel = subModels.firstChildElement();
while (!subModel.isNull())
{
if(subModel.tagName() == "SubModel")
{
QDomElement annotation = subModel.firstChildElement("Annotation");
if(annotation.tagName() == "Annotation" )
{
QString transformation = "Placement(";
transformation.append(annotation.attribute("Visible")).append(",").append(StringHandler::removeFirstLastCurlBrackets(annotation.attribute("Origin")));
transformation.append(",").append(StringHandler::removeFirstLastCurlBrackets(annotation.attribute("Extent")));
transformation.append(",0,0,0,-,-,-,-,").append(annotation.attribute("Rotation")).append(")");
// add the component to the the diagram view.
mpDiagramGraphicsView->addComponentToView(subModel.attribute("Name"), subModel.attribute("ModelFile"), transformation,
QPointF(0.0, 0.0), 0, StringHandler::Connector, false);
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpEditor);
QDomNodeList subModels = pTLMEditor->getSubModels();
for (int i = 0; i < subModels.size(); i++) {
QString transformation;
bool annotationFound = false;
QDomElement subModel = subModels.at(i).toElement();
QDomNodeList subModelChildren = subModel.childNodes();
for (int j = 0 ; j < subModelChildren.size() ; j++) {
QDomElement annotationElement = subModelChildren.at(j).toElement();
if (annotationElement.tagName().compare("Annotation") == 0) {
annotationFound = true;
transformation = "Placement(";
transformation.append(annotationElement.attribute("Visible")).append(",");
transformation.append(StringHandler::removeFirstLastCurlBrackets(annotationElement.attribute("Origin"))).append(",");
transformation.append(StringHandler::removeFirstLastCurlBrackets(annotationElement.attribute("Extent"))).append(",");
transformation.append(StringHandler::removeFirstLastCurlBrackets(annotationElement.attribute("Rotation"))).append(",");
transformation.append("-,-,-,-,-,-,");
}
}
subModel = subModel.nextSiblingElement();
if (!annotationFound) {
transformation = "Placement(true, 0.0, 0.0, -10.0, -10.0, 10.0, 10.0, 0.0, -, -, -, -, -, -,";
pTLMEditor->createAnnotationElement(subModel, "true", "{0,0}", "{-10,-10,10,10}", "0");
setModelModified();
}
QFileInfo fileInfo(mpLibraryTreeNode->getFileName());
QString fileName = fileInfo.absolutePath() + "/" + subModel.attribute("Name") + "/" + subModel.attribute("ModelFile");
// add the component to the the diagram view.
mpDiagramGraphicsView->addComponentToView(subModel.attribute("Name"), subModel.attribute("Name"), transformation, QPointF(0.0, 0.0),
new ComponentInfo(""), StringHandler::Connector, false, false, false, "", fileName);
}
}

Expand Down

0 comments on commit b8c416e

Please sign in to comment.