Skip to content

Commit 1094e7b

Browse files
committed
- TLM editor DeleteConenction API
1 parent 09275d8 commit 1094e7b

File tree

3 files changed

+44
-31
lines changed

3 files changed

+44
-31
lines changed

OMEdit/OMEditGUI/Editors/TLMEditor.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,20 @@ QDomElement TLMEditor::getSubModelsElement()
109109
return QDomElement();
110110
}
111111

112+
/*!
113+
* \brief TLMEditor::getConnectionsElement
114+
* Returns the Connections element tag.
115+
* \return
116+
*/
117+
QDomElement TLMEditor::getConnectionsElement()
118+
{
119+
QDomNodeList connections = mXmlDocument.elementsByTagName("Connections");
120+
if (connections.size() > 0) {
121+
return connections.at(0).toElement();
122+
}
123+
return QDomElement();
124+
}
125+
112126
/*!
113127
* \brief TLMEditor::getSubModels
114128
* Returns the list of SubModel tags.
@@ -269,6 +283,32 @@ bool TLMEditor::deleteSubModel(QString name)
269283
return false;
270284
}
271285

286+
/*!
287+
* \brief TLMEditor::deleteConnection
288+
* Delets a connection.
289+
* \param name
290+
* \return
291+
*/
292+
bool TLMEditor::deleteConnection(QString startSubModelName, QString endSubModelName)
293+
{
294+
QDomNodeList connectionList = mXmlDocument.elementsByTagName("Connection");
295+
for (int i = 0 ; i < connectionList.size() ; i++) {
296+
QDomElement connection = connectionList.at(i).toElement();
297+
QString startName = StringHandler::getSubStringBeforeDots(connection.attribute("From"));
298+
QString endName = StringHandler::getSubStringBeforeDots(connection.attribute("To"));
299+
if (startName.compare(startSubModelName) == 0 && endName.compare(endSubModelName) == 0 ) {
300+
QDomElement connections = getConnectionsElement();
301+
if (!connections.isNull()) {
302+
connections.removeChild(connection);
303+
mpPlainTextEdit->setPlainText(mXmlDocument.toString());
304+
return true;
305+
}
306+
break;
307+
}
308+
}
309+
return false;
310+
}
311+
272312
//! @class TLMHighlighter
273313
//! @brief A syntax highlighter for TLMEditor.
274314

OMEdit/OMEditGUI/Editors/TLMEditor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ class TLMEditor : public BaseEditor
5151
void setPlainText(const QString &text);
5252
QDomElement getSubModelsElement();
5353
QDomNodeList getSubModels();
54+
QDomElement getConnectionsElement();
5455
QDomNodeList getConnections();
5556
bool addSubModel(QString name, QString exactStep, QString modelFile, QString startCommand, QString visible, QString origin, QString extent,
5657
QString rotation);
5758
void createAnnotationElement(QDomElement subModel, QString visible, QString origin, QString extent, QString rotation);
5859
void updateSubModelPlacementAnnotation(QString name, QString visible, QString origin, QString extent, QString rotation);
5960
void addInterfacesData(QDomElement interfaces);
6061
bool deleteSubModel(QString name);
62+
bool deleteConnection(QString startComponentName, QString endComponentName );
6163
private:
6264
bool mForceSetPlainText;
6365
bool mTextChanged;

OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -696,39 +696,10 @@ void GraphicsView::createConnection(QString startComponentName, QString endCompo
696696
void GraphicsView::deleteConnection(QString startComponentName, QString endComponentName)
697697
{
698698
MainWindow *pMainWindow = mpModelWidget->getModelWidgetContainer()->getMainWindow();
699-
700699
if(mpModelWidget->getLibraryTreeNode()->getLibraryType()== LibraryTreeNode::TLM)
701700
{
702-
QDomDocument doc;
703-
doc.setContent(pMainWindow->getModelWidgetContainer()->getCurrentModelWidget()->getEditor()->getPlainTextEdit()->toPlainText());
704-
// Get the "Root" element
705-
QDomElement docElem = doc.documentElement();
706-
// remove the connection annotations from TLM editor
707-
QDomElement connections = docElem.firstChildElement();
708-
// remove the connection from TLM editor
709-
while (!connections.isNull())
710-
{
711-
if(connections.tagName() == "Connections")
712-
{
713-
QDomElement connection = connections.firstChildElement();
714-
while (!connection.isNull()&& connection.tagName() == "Connection" )
715-
{
716-
QString startName = StringHandler::getSubStringBeforeDots(connection.attribute("From"));
717-
QString endName = StringHandler::getSubStringBeforeDots(connection.attribute("To"));
718-
if(startName == startComponentName && endName == endComponentName)
719-
{
720-
connections.removeChild(connection);
721-
break;
722-
}
723-
connection = connection.nextSiblingElement();
724-
}
725-
break;
726-
}
727-
connections = connections.nextSiblingElement();
728-
}
729-
730-
QString metaModelText = doc.toString();
731-
pMainWindow->getModelWidgetContainer()->getCurrentModelWidget()->getEditor()->getPlainTextEdit()->setPlainText(metaModelText);
701+
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpModelWidget->getEditor());
702+
pTLMEditor->deleteConnection(startComponentName, endComponentName);
732703
}
733704
else
734705
pMainWindow->getOMCProxy()->deleteConnection(startComponentName, endComponentName, mpModelWidget->getLibraryTreeNode()->getNameStructure());

0 commit comments

Comments
 (0)