Skip to content

Commit 09275d8

Browse files
committed
- Use API for getTLMConnections
1 parent df58213 commit 09275d8

File tree

3 files changed

+43
-54
lines changed

3 files changed

+43
-54
lines changed

OMEdit/OMEditGUI/Editors/TLMEditor.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ QDomNodeList TLMEditor::getSubModels()
119119
return mXmlDocument.elementsByTagName("SubModel");
120120
}
121121

122+
/*!
123+
* \brief TLMEditor::getConnections
124+
* Returns the list of Connection tags.
125+
* \return
126+
*/
127+
QDomNodeList TLMEditor::getConnections()
128+
{
129+
return mXmlDocument.elementsByTagName("Connection");
130+
}
131+
122132
/*!
123133
* \brief TLMEditor::addSubModel
124134
* Adds a SubModel tag with Annotation tag as child of it.

OMEdit/OMEditGUI/Editors/TLMEditor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class TLMEditor : public BaseEditor
5151
void setPlainText(const QString &text);
5252
QDomElement getSubModelsElement();
5353
QDomNodeList getSubModels();
54+
QDomNodeList getConnections();
5455
bool addSubModel(QString name, QString exactStep, QString modelFile, QString startCommand, QString visible, QString origin, QString extent,
5556
QString rotation);
5657
void createAnnotationElement(QDomElement subModel, QString visible, QString origin, QString extent, QString rotation);

OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp

Lines changed: 32 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,29 +2502,14 @@ void ModelWidget::getTLMComponents()
25022502

25032503
void ModelWidget::getTLMConnections()
25042504
{
2505-
// get the components and thier annotations
2506-
QDomDocument doc;
2507-
doc.setContent(getEditor()->getPlainTextEdit()->toPlainText());
2508-
2509-
// Get the "Root" element
2510-
QDomElement docElem = doc.documentElement();
2511-
2512-
QDomElement connections = docElem.firstChildElement();
2513-
while (!connections.isNull())
2514-
{
2515-
if(connections.tagName() == "Connections")
2516-
break;
2517-
connections = connections.nextSiblingElement();
2518-
}
2519-
2520-
QDomElement connection = connections.firstChildElement("Connection");
2521-
while (!connection.isNull())
2522-
{
2523-
if(connection.tagName() == "Connection" )
2524-
{
2525-
QDomElement annotation = connection.firstChildElement("Annotation");
2526-
if(annotation.tagName() == "Annotation" )
2527-
{
2505+
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpEditor);
2506+
QDomNodeList connections = pTLMEditor->getConnections();
2507+
for (int i = 0; i < connections.size(); i++) {
2508+
QDomElement connection = connections.at(i).toElement();
2509+
QDomNodeList connectionChildren = connection.childNodes();
2510+
for (int j = 0 ; j < connectionChildren.size() ; j++) {
2511+
QDomElement annotationElement = connectionChildren.at(j).toElement();
2512+
if (annotationElement.tagName().compare("Annotation") == 0) {
25282513
// get start component
25292514
Component *pStartComponent = 0;
25302515
pStartComponent = mpDiagramGraphicsView->getComponentObject(StringHandler::getSubStringBeforeDots(connection.attribute("From")));
@@ -2535,42 +2520,35 @@ void ModelWidget::getTLMConnections()
25352520
Component *pStartConnectorComponent = 0;
25362521
Component *pEndConnectorComponent = 0;
25372522
if (pStartComponent)
2538-
{
25392523
pStartConnectorComponent = pStartComponent;
2540-
}
2541-
if (pEndComponent)
2542-
{
2543-
pEndConnectorComponent = pEndComponent;
2544-
}
2545-
// get the connector annotations
2546-
QString connectionAnnotationString;
2547-
connectionAnnotationString.append("{Line(true, {0.0, 0.0}, 0, ").append(annotation.attribute("Points"));
2548-
connectionAnnotationString.append(", {0, 0, 0}, LinePattern.Solid, 0.25, {Arrow.None, Arrow.None}, 3, Smooth.None)}");
2549-
QStringList shapesList = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(connectionAnnotationString), '(', ')');
2550-
// Now parse the shapes available in list
2551-
foreach (QString shape, shapesList)
2552-
{
2553-
if (shape.startsWith("Line"))
2554-
{
2555-
shape = shape.mid(QString("Line").length());
2556-
shape = StringHandler::removeFirstLastBrackets(shape);
2557-
LineAnnotation *pConnectionLineAnnotation = new LineAnnotation(shape, false, pStartConnectorComponent,
2558-
pEndConnectorComponent, mpDiagramGraphicsView);
2559-
if (pStartConnectorComponent)
2560-
pStartConnectorComponent->getRootParentComponent()->addConnectionDetails(pConnectionLineAnnotation);
2561-
pConnectionLineAnnotation->setStartComponentName(StringHandler::getSubStringBeforeDots(connection.attribute("From")));
2562-
if (pEndConnectorComponent)
2563-
pEndConnectorComponent->getRootParentComponent()->addConnectionDetails(pConnectionLineAnnotation);
2564-
pConnectionLineAnnotation->setEndComponentName(StringHandler::getSubStringBeforeDots(connection.attribute("To")));
2565-
pConnectionLineAnnotation->addPoint(QPointF(0, 0));
2566-
pConnectionLineAnnotation->drawCornerItems();
2567-
pConnectionLineAnnotation->setCornerItemsPassive();
2568-
mpDiagramGraphicsView->addConnectionObject(pConnectionLineAnnotation);
2524+
if (pEndComponent)
2525+
pEndConnectorComponent = pEndComponent;
2526+
// get the connector annotations
2527+
QString connectionAnnotationString;
2528+
connectionAnnotationString.append("{Line(true, {0.0, 0.0}, 0, ").append(annotationElement.attribute("Points"));
2529+
connectionAnnotationString.append(", {0, 0, 0}, LinePattern.Solid, 0.25, {Arrow.None, Arrow.None}, 3, Smooth.None)}");
2530+
QStringList shapesList = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(connectionAnnotationString), '(', ')');
2531+
// Now parse the shapes available in list
2532+
foreach (QString shape, shapesList) {
2533+
if (shape.startsWith("Line")) {
2534+
shape = shape.mid(QString("Line").length());
2535+
shape = StringHandler::removeFirstLastBrackets(shape);
2536+
LineAnnotation *pConnectionLineAnnotation = new LineAnnotation(shape, false, pStartConnectorComponent,
2537+
pEndConnectorComponent, mpDiagramGraphicsView);
2538+
if (pStartConnectorComponent)
2539+
pStartConnectorComponent->getRootParentComponent()->addConnectionDetails(pConnectionLineAnnotation);
2540+
pConnectionLineAnnotation->setStartComponentName(StringHandler::getSubStringBeforeDots(connection.attribute("From")));
2541+
if (pEndConnectorComponent)
2542+
pEndConnectorComponent->getRootParentComponent()->addConnectionDetails(pConnectionLineAnnotation);
2543+
pConnectionLineAnnotation->setEndComponentName(StringHandler::getSubStringBeforeDots(connection.attribute("To")));
2544+
pConnectionLineAnnotation->addPoint(QPointF(0, 0));
2545+
pConnectionLineAnnotation->drawCornerItems();
2546+
pConnectionLineAnnotation->setCornerItemsPassive();
2547+
mpDiagramGraphicsView->addConnectionObject(pConnectionLineAnnotation);
25692548
}
25702549
}
25712550
}
25722551
}
2573-
connection = connection.nextSiblingElement();
25742552
}
25752553
}
25762554

0 commit comments

Comments
 (0)