Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/OpenModelica/OMEdit
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Jun 24, 2015
2 parents 0c261a0 + c618de1 commit fadb66a
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 159 deletions.
73 changes: 25 additions & 48 deletions OMEdit/OMEditGUI/Component/ComponentProperties.cpp
Expand Up @@ -1299,17 +1299,17 @@ TLMConnectionAttributes::TLMConnectionAttributes(LineAnnotation *pConnectionLine
void TLMConnectionAttributes::setUpDialog()
{
// Create the start component class name label and text box
mpStartComponentClassNameLabel = new Label(tr("From:"));
mpStartComponentClassNameTextBox = new QLineEdit;
mpStartComponentClassNameTextBox->setReadOnly(true);
mpStartSubModelNameLabel = new Label(tr("From:"));
mpStartSubModelNameTextBox = new QLineEdit;
mpStartSubModelNameTextBox->setReadOnly(true);
// Create the start component interface points combo box
mpStartComponentInterfacePointComboBox = new QComboBox;
mpStartSubModelInterfacePointComboBox = new QComboBox;
// Create the end component class name label and text box
mpEndComponentClassNameLabel = new Label(tr("To:"));
mpEndComponentClassNameTextBox = new QLineEdit;
mpEndComponentClassNameTextBox->setReadOnly(true);
mpEndSubModelNameLabel = new Label(tr("To:"));
mpEndSubModelNameTextBox = new QLineEdit;
mpEndSubModelNameTextBox->setReadOnly(true);
// Create the end component interface points combo box
mpEndComponentInterfacePointComboBox = new QComboBox;
mpEndSubModelInterfacePointComboBox = new QComboBox;
// Create the delay label and text box
mpDelayLabel = new Label(tr("Delay:"));
mpDelayTextBox = new QLineEdit;
Expand All @@ -1325,18 +1325,18 @@ void TLMConnectionAttributes::setUpDialog()
// Create the buttons
mpOkButton = new QPushButton(Helper::ok);
mpOkButton->setAutoDefault(true);
connect(mpOkButton, SIGNAL(clicked()), this, SLOT(updateTLMConnectionAttributes()));
connect(mpOkButton, SIGNAL(clicked()), this, SLOT(createTLMConnection()));
mpButtonBox = new QDialogButtonBox(Qt::Horizontal);
mpButtonBox->addButton(mpOkButton, QDialogButtonBox::ActionRole);
// Create a layout
QGridLayout *pMainLayout = new QGridLayout;
pMainLayout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
pMainLayout->addWidget(mpStartComponentClassNameLabel, 0, 0);
pMainLayout->addWidget(mpStartComponentClassNameTextBox, 0, 1);
pMainLayout->addWidget(mpStartComponentInterfacePointComboBox, 0, 2);
pMainLayout->addWidget(mpEndComponentClassNameLabel, 1, 0);
pMainLayout->addWidget(mpEndComponentClassNameTextBox, 1, 1);
pMainLayout->addWidget(mpEndComponentInterfacePointComboBox, 1, 2);
pMainLayout->addWidget(mpStartSubModelNameLabel, 0, 0);
pMainLayout->addWidget(mpStartSubModelNameTextBox, 0, 1);
pMainLayout->addWidget(mpStartSubModelInterfacePointComboBox, 0, 2);
pMainLayout->addWidget(mpEndSubModelNameLabel, 1, 0);
pMainLayout->addWidget(mpEndSubModelNameTextBox, 1, 1);
pMainLayout->addWidget(mpEndSubModelInterfacePointComboBox, 1, 2);
pMainLayout->addWidget(mpDelayLabel, 2, 0);
pMainLayout->addWidget(mpDelayTextBox, 2, 1, 1, 3);
pMainLayout->addWidget(mpZfLabel,3, 0);
Expand All @@ -1354,54 +1354,31 @@ void TLMConnectionAttributes::setUpDialog()
*/
void TLMConnectionAttributes::initializeDialog()
{
mpStartComponentClassNameTextBox->setText(mpConnectionLineAnnotation->getStartComponent()->getName());
mpEndComponentClassNameTextBox->setText(mpConnectionLineAnnotation->getEndComponent()->getName());
mpStartSubModelNameTextBox->setText(mpConnectionLineAnnotation->getStartComponent()->getName());
mpEndSubModelNameTextBox->setText(mpConnectionLineAnnotation->getEndComponent()->getName());
mInterfacepointsList = mpConnectionLineAnnotation->getStartComponent()->getInterfacepointsList();
for( int i=0; i<mInterfacepointsList.count(); ++i )
{
mpStartComponentInterfacePointComboBox->addItem(mInterfacepointsList.at(i)->getInterfaceName());
mpStartSubModelInterfacePointComboBox->addItem(mInterfacepointsList.at(i)->getInterfaceName());
}

mInterfacepointsList = mpConnectionLineAnnotation->getEndComponent()->getInterfacepointsList();
for( int i=0; i<mInterfacepointsList.count(); ++i )
{
mpEndComponentInterfacePointComboBox->addItem(mInterfacepointsList.at(i)->getInterfaceName());
mpEndSubModelInterfacePointComboBox->addItem(mInterfacepointsList.at(i)->getInterfaceName());
}
}

/*!
Slot activated when mpOkButton clicked signal is raised.\n
Updates the TLM component attributes.
*/
void TLMConnectionAttributes::updateTLMConnectionAttributes()
void TLMConnectionAttributes::createTLMConnection()
{
QDomDocument doc;
doc.setContent(mpMainWindow->getModelWidgetContainer()->getCurrentModelWidget()->getEditor()->getPlainTextEdit()->toPlainText());
// Get the Root MetaModel node
QDomElement docElem = doc.documentElement();

QDomElement connections = docElem.firstChildElement();
while (!connections.isNull())
{
if(connections.tagName() == "Connections")
break;
connections = connections.nextSiblingElement();
}

QDomElement connection = doc.createElement("Connection");
connection.setAttribute("From", mpStartComponentClassNameTextBox->text().append(".").append(mpStartComponentInterfacePointComboBox->currentText()));
connection.setAttribute("To", mpEndComponentClassNameTextBox->text().append(".").append(mpEndComponentInterfacePointComboBox->currentText()));
connection.setAttribute("Delay", mpDelayTextBox->text());
connection.setAttribute("Zf", mpZfTextBox->text());
connection.setAttribute("Zfr",mpZfrTextBox->text());
connection.setAttribute("alpha", mpAlphaTextBox->text());

QDomElement annotation = doc.createElement("Annotation");
annotation.setAttribute("Points", mpConnectionLineAnnotation->getTLMShapeAnnotation());
connection.appendChild(annotation);
connections.appendChild(connection);
QString metaModelText = doc.toString();

mpMainWindow->getModelWidgetContainer()->getCurrentModelWidget()->getEditor()->getPlainTextEdit()->setPlainText(metaModelText);
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(mpMainWindow->getModelWidgetContainer()->getCurrentModelWidget()->getEditor());
QString startFrom = mpStartSubModelNameTextBox->text().append(".").append(mpStartSubModelInterfacePointComboBox->currentText());
QString endTo = mpEndSubModelNameTextBox->text().append(".").append(mpEndSubModelInterfacePointComboBox->currentText());
pTLMEditor->createConnection(startFrom, endTo, mpDelayTextBox->text(), mpAlphaTextBox->text(),mpZfTextBox->text(), mpZfrTextBox->text(),
mpConnectionLineAnnotation->getTLMShapeAnnotation());
accept();
}
14 changes: 7 additions & 7 deletions OMEdit/OMEditGUI/Component/ComponentProperties.h
Expand Up @@ -243,12 +243,12 @@ class TLMConnectionAttributes : public QDialog
LineAnnotation *mpConnectionLineAnnotation;
MainWindow *mpMainWindow;
QList<TLMInterfacePointInfo*> mInterfacepointsList;
Label *mpStartComponentClassNameLabel;
QLineEdit *mpStartComponentClassNameTextBox;
QComboBox *mpStartComponentInterfacePointComboBox;
QComboBox *mpEndComponentInterfacePointComboBox;
Label *mpEndComponentClassNameLabel;
QLineEdit *mpEndComponentClassNameTextBox;
Label *mpStartSubModelNameLabel;
QLineEdit *mpStartSubModelNameTextBox;
QComboBox *mpStartSubModelInterfacePointComboBox;
QComboBox *mpEndSubModelInterfacePointComboBox;
Label *mpEndSubModelNameLabel;
QLineEdit *mpEndSubModelNameTextBox;
Label *mpDelayLabel;
QLineEdit *mpDelayTextBox;
Label *mpZfLabel;
Expand All @@ -260,7 +260,7 @@ class TLMConnectionAttributes : public QDialog
QPushButton *mpOkButton;
QDialogButtonBox *mpButtonBox;
public slots:
void updateTLMConnectionAttributes();
void createTLMConnection();
};

#endif // COMPONENTPROPERTIES_H
85 changes: 85 additions & 0 deletions OMEdit/OMEditGUI/Editors/TLMEditor.cpp
Expand Up @@ -69,6 +69,7 @@ void TLMEditor::contentsHasChanged(int position, int charsRemoved, int charsAdde
bool TLMEditor::validateMetaModelText()
{
if (mTextChanged) {
mXmlDocument.setContent(mpPlainTextEdit->toPlainText());
if (!emit focusOut()) {
return false;
} else {
Expand Down Expand Up @@ -108,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 All @@ -118,6 +133,16 @@ QDomNodeList TLMEditor::getSubModels()
return mXmlDocument.elementsByTagName("SubModel");
}

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

/*!
* \brief TLMEditor::addSubModel
* Adds a SubModel tag with Annotation tag as child of it.
Expand Down Expand Up @@ -209,6 +234,40 @@ void TLMEditor::updateSubModelPlacementAnnotation(QString name, QString visible,
}
}

/*!
* \brief TLMEditor::createConnection
* Adds a a connection tag with Annotation tag as child of it.
* \param from
* \param to
* \param delay
* \param alpha
* \param zf
* \param zfr
* \param points
* \return
*/
bool TLMEditor::createConnection(QString from, QString to, QString delay, QString alpha, QString zf, QString zfr, QString points)
{
QDomElement connections = getConnectionsElement();
if (!connections.isNull()) {
QDomElement connection = mXmlDocument.createElement("Connection");
connection.setAttribute("From", from);
connection.setAttribute("To", to);
connection.setAttribute("Delay", delay);
connection.setAttribute("alpha", alpha);
connection.setAttribute("Zf", zf);
connection.setAttribute("Zfr", zfr);
// create Annotation Element
QDomElement annotation = mXmlDocument.createElement("Annotation");
annotation.setAttribute("Points", points);
connection.appendChild(annotation);
connections.appendChild(connection);
mpPlainTextEdit->setPlainText(mXmlDocument.toString());
return true;
}
return false;
}

/*!
* \brief TLMEditor::addInterfacesData
* Adds the InterfacePoint tag to SubModel.
Expand Down Expand Up @@ -258,6 +317,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
4 changes: 4 additions & 0 deletions OMEdit/OMEditGUI/Editors/TLMEditor.h
Expand Up @@ -51,12 +51,16 @@ 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);
bool createConnection(QString From, QString To, QString delay, QString alpha, QString zf, QString zfr, QString points);
void addInterfacesData(QDomElement interfaces);
bool deleteSubModel(QString name);
bool deleteConnection(QString startComponentName, QString endComponentName );
private:
bool mForceSetPlainText;
bool mTextChanged;
Expand Down
50 changes: 32 additions & 18 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -916,6 +916,13 @@ void MainWindow::exportModelFigaro(LibraryTreeNode *pLibraryTreeNode)
*/
void MainWindow::fetchInterfaceData(LibraryTreeNode *pLibraryTreeNode)
{
/* if MetaModel text is changed manually by user then validate it before fetaching the interface data. */
if (pLibraryTreeNode->getModelWidget()) {
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(pLibraryTreeNode->getModelWidget()->getEditor());
if (pTLMEditor && !pTLMEditor->validateMetaModelText()) {
return;
}
}
if (mpOptionsDialog->getTLMPage()->getTLMManagerProcessTextBox()->text().isEmpty()) {
QString message;
#ifdef Q_OS_MAC
Expand Down Expand Up @@ -956,27 +963,34 @@ void MainWindow::fetchInterfaceData(LibraryTreeNode *pLibraryTreeNode)
*/
void MainWindow::TLMSimulate(LibraryTreeNode *pLibraryTreeNode)
{
/* if MetaModel text is changed manually by user then validate it before starting the TLM co-simulation. */
if (pLibraryTreeNode->getModelWidget()) {
TLMEditor *pTLMEditor = dynamic_cast<TLMEditor*>(pLibraryTreeNode->getModelWidget()->getEditor());
if (pTLMEditor && !pTLMEditor->validateMetaModelText()) {
return;
}
}
if (pLibraryTreeNode->isSaved()) {
mpTLMCoSimulationDialog->show(pLibraryTreeNode);
} else {
QMessageBox *pMessageBox = new QMessageBox(this);
pMessageBox->setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::question));
pMessageBox->setIcon(QMessageBox::Question);
pMessageBox->setText(GUIMessages::getMessage(GUIMessages::METAMODEL_UNSAVED).arg(pLibraryTreeNode->getNameStructure()));
pMessageBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
pMessageBox->setDefaultButton(QMessageBox::Yes);
int answer = pMessageBox->exec();
switch (answer) {
case QMessageBox::Yes:
if (mpLibraryTreeWidget->saveLibraryTreeNode(pLibraryTreeNode)) {
mpTLMCoSimulationDialog->show(pLibraryTreeNode);
mpTLMCoSimulationDialog->show(pLibraryTreeNode);
} else {
QMessageBox *pMessageBox = new QMessageBox(this);
pMessageBox->setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::question));
pMessageBox->setIcon(QMessageBox::Question);
pMessageBox->setText(GUIMessages::getMessage(GUIMessages::METAMODEL_UNSAVED).arg(pLibraryTreeNode->getNameStructure()));
pMessageBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
pMessageBox->setDefaultButton(QMessageBox::Yes);
int answer = pMessageBox->exec();
switch (answer) {
case QMessageBox::Yes:
if (mpLibraryTreeWidget->saveLibraryTreeNode(pLibraryTreeNode)) {
mpTLMCoSimulationDialog->show(pLibraryTreeNode);
}
break;
case QMessageBox::No:
default:
break;
}
break;
case QMessageBox::No:
default:
break;
}
}
}

void MainWindow::exportModelToOMNotebook(LibraryTreeNode *pLibraryTreeNode)
Expand Down

0 comments on commit fadb66a

Please sign in to comment.