Skip to content

Commit

Permalink
- TLM editor DeleteConenction API
Browse files Browse the repository at this point in the history
  • Loading branch information
alash325 committed Jun 24, 2015
1 parent add672d commit 7880d7c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
40 changes: 40 additions & 0 deletions OMEdit/OMEditGUI/Editors/TLMEditor.cpp
Expand Up @@ -109,6 +109,20 @@ QDomElement TLMEditor::getSubModelsElement()
return QDomElement();
}

/*!
* \brief TLMEditor::getConnectionsElement
* Returns the Connections element tag.
* \return
*/
QDomElement TLMEditor::getConnectionsElement()
{
QDomNodeList connections = mXmlDocument.elementsByTagName("Connections");
if (connections.size() > 0) {
return connections.at(0).toElement();
}
return QDomElement();
}

/*!
* \brief TLMEditor::getSubModels
* Returns the list of SubModel tags.
Expand Down Expand Up @@ -269,6 +283,32 @@ bool TLMEditor::deleteSubModel(QString name)
return false;
}

/*!
* \brief TLMEditor::deleteConnection
* Delets a connection.
* \param name
* \return
*/
bool TLMEditor::deleteConnection(QString startSubModelName, QString endSubModelName)
{
QDomNodeList connectionList = mXmlDocument.elementsByTagName("Connection");
for (int i = 0 ; i < connectionList.size() ; i++) {
QDomElement connection = connectionList.at(i).toElement();
QString startName = StringHandler::getSubStringBeforeDots(connection.attribute("From"));
QString endName = StringHandler::getSubStringBeforeDots(connection.attribute("To"));
if (startName.compare(startSubModelName) == 0 && endName.compare(endSubModelName) == 0 ) {
QDomElement connections = getConnectionsElement();
if (!connections.isNull()) {
connections.removeChild(connection);
mpPlainTextEdit->setPlainText(mXmlDocument.toString());
return true;
}
break;
}
}
return false;
}

//! @class TLMHighlighter
//! @brief A syntax highlighter for TLMEditor.

Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Editors/TLMEditor.h
Expand Up @@ -51,13 +51,15 @@ class TLMEditor : public BaseEditor
void setPlainText(const QString &text);
QDomElement getSubModelsElement();
QDomNodeList getSubModels();
QDomElement getConnectionsElement();
QDomNodeList getConnections();
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 addInterfacesData(QDomElement interfaces);
bool deleteSubModel(QString name);
bool deleteConnection(QString startComponentName, QString endComponentName );
private:
bool mForceSetPlainText;
bool mTextChanged;
Expand Down
33 changes: 2 additions & 31 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -696,39 +696,10 @@ void GraphicsView::createConnection(QString startComponentName, QString endCompo
void GraphicsView::deleteConnection(QString startComponentName, QString endComponentName)
{
MainWindow *pMainWindow = mpModelWidget->getModelWidgetContainer()->getMainWindow();

if(mpModelWidget->getLibraryTreeNode()->getLibraryType()== LibraryTreeNode::TLM)
{
QDomDocument doc;
doc.setContent(pMainWindow->getModelWidgetContainer()->getCurrentModelWidget()->getEditor()->getPlainTextEdit()->toPlainText());
// Get the "Root" element
QDomElement docElem = doc.documentElement();
// remove the connection annotations from TLM editor
QDomElement connections = docElem.firstChildElement();
// remove the connection from TLM editor
while (!connections.isNull())
{
if(connections.tagName() == "Connections")
{
QDomElement connection = connections.firstChildElement();
while (!connection.isNull()&& connection.tagName() == "Connection" )
{
QString startName = StringHandler::getSubStringBeforeDots(connection.attribute("From"));
QString endName = StringHandler::getSubStringBeforeDots(connection.attribute("To"));
if(startName == startComponentName && endName == endComponentName)
{
connections.removeChild(connection);
break;
}
connection = connection.nextSiblingElement();
}
break;
}
connections = connections.nextSiblingElement();
}

QString metaModelText = doc.toString();
pMainWindow->getModelWidgetContainer()->getCurrentModelWidget()->getEditor()->getPlainTextEdit()->setPlainText(metaModelText);
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpModelWidget->getEditor());
pTLMEditor->deleteConnection(startComponentName, endComponentName);
}
else
pMainWindow->getOMCProxy()->deleteConnection(startComponentName, endComponentName, mpModelWidget->getLibraryTreeNode()->getNameStructure());
Expand Down

0 comments on commit 7880d7c

Please sign in to comment.