Skip to content

Commit

Permalink
Merge pull request #17 from robbr48/master
Browse files Browse the repository at this point in the history
Improved align interfaces dialog for meta models.
  • Loading branch information
adeas31 committed Mar 29, 2016
2 parents f806cd8 + 2ecd6ba commit 858eed0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 54 deletions.
36 changes: 16 additions & 20 deletions OMEdit/OMEditGUI/Editors/MetaModelEditor.cpp
Expand Up @@ -568,14 +568,21 @@ void MetaModelEditor::alignInterfaces(QString fromSubModel, QString toSubModel)
}

//Assert that all rotations and positions were found (do something smarter?)
Q_ASSERT(!cg_x1_phi_cg_str.isEmpty());
Q_ASSERT(!cg_x2_phi_cg_str.isEmpty());
Q_ASSERT(!cg_x1_r_cg_str.isEmpty());
Q_ASSERT(!cg_x2_r_cg_str.isEmpty());
Q_ASSERT(!x1_c1_r_x1_str.isEmpty());
Q_ASSERT(!x1_c1_phi_x1_str.isEmpty());
Q_ASSERT(!x2_c2_r_x2_str.isEmpty());
Q_ASSERT(!x2_c2_phi_x2_str.isEmpty());
if(cg_x1_phi_cg_str.isEmpty() ||
cg_x2_phi_cg_str.isEmpty() ||
cg_x1_r_cg_str.isEmpty() ||
cg_x2_r_cg_str.isEmpty() ||
x1_c1_r_x1_str.isEmpty() ||
x1_c1_phi_x1_str.isEmpty() ||
x2_c2_r_x2_str.isEmpty() ||
x2_c2_phi_x2_str.isEmpty())
{
QString msg = "Interface coordinates does not exist in xml";
mpMainWindow->getMessagesWidget()->addGUIMessage(MessageItem(MessageItem::MetaModel, "",false,0,0,0,0,msg,Helper::scriptingKind,Helper::errorLevel));
return;
}

Q_ASSERT(1==2);

//Convert from strings to arrays
double cg_x1_phi_cg[3],cg_x2_phi_cg[3],x1_c1_phi_x1[3],x2_c2_phi_x2[3];
Expand Down Expand Up @@ -613,7 +620,6 @@ void MetaModelEditor::alignInterfaces(QString fromSubModel, QString toSubModel)
x2_c2_r_x2[1] = x2_c2_r_x2_str.split(",")[1].toDouble();
x2_c2_r_x2[2] = x2_c2_r_x2_str.split(",")[2].toDouble();


//Convert from arrays to Qt matrices
QGenericMatrix<3,1,double> CG_X1_PHI_CG(cg_x1_phi_cg); //Rotation of X1 relative to CG expressed in CG
QGenericMatrix<3,1,double> CG_X2_PHI_CG(cg_x2_phi_cg); //Rotation of X2 relative to CG expressed in CG
Expand All @@ -624,8 +630,7 @@ void MetaModelEditor::alignInterfaces(QString fromSubModel, QString toSubModel)
QGenericMatrix<3,1,double> X1_C1_R_X1(x1_c1_r_x1); //Position of C1 relative to X1 expressed in X1
QGenericMatrix<3,1,double> X2_C2_R_X2(x2_c2_r_x2); //Position of C2 relative to X2 expressed in X2

QGenericMatrix<3,3,double> R_X2_C2, R_CG_X1, R_CG_X2, R_CG_C2, R_X1_C1, R_CG_C1;
QGenericMatrix<3,1,double> X1_C1_PHI_CG, CG_C1_PHI_CG, X1_C1_R_CG, CG_C1_R_CG, X2_C2_PHI_CG, CG_C2_PHI_CG, X2_C2_R_CG, CG_C2_R_CG, ones;
QGenericMatrix<3,3,double> R_X2_C2, R_CG_X1, R_CG_X2, R_CG_C2, R_X1_C1;

//Equations from BEAST
R_X2_C2 = getRotationMatrix(X2_C2_PHI_X2); //Rotation matrix between X2 and C2
Expand All @@ -643,15 +648,6 @@ void MetaModelEditor::alignInterfaces(QString fromSubModel, QString toSubModel)
//New position of X1 relative to CG
CG_X1_R_CG = CG_X2_R_CG + X2_C2_R_X2*R_CG_X2 - X1_C1_R_X1*R_CG_X1;

// //Verify positions
// qDebug() << CG_X1_R_CG +X1_C1_R_X1*R_CG_X1;
// qDebug() << CG_X2_R_CG +X2_C2_R_X2*R_CG_X2;

// //Verify rotations
// R_CG_C1 = R_X1_C1*R_CG_X1;
// qDebug() << R_CG_C1;
// qDebug() << R_CG_C2;

//Write back new rotation and position to XML
cg_x1_r_cg_str = QString("%1,%2,%3").arg(CG_X1_R_CG(0,0)).arg(CG_X1_R_CG(0,1)).arg(CG_X1_R_CG(0,2));
subModelElement1.setAttribute("Position", cg_x1_r_cg_str);
Expand Down
58 changes: 25 additions & 33 deletions OMEdit/OMEditGUI/TLM/FetchInterfaceDataDialog.cpp
Expand Up @@ -210,32 +210,25 @@ AlignInterfacesDialog::AlignInterfacesDialog(ModelWidget *pModelWidget)
QStringList interfaces;
MetaModelEditor *pMetaModelEditor = dynamic_cast<MetaModelEditor*>(pModelWidget->getEditor());
if (pMetaModelEditor) {
QDomNodeList subModels = pMetaModelEditor->getSubModels();
for (int i = 0; i < subModels.size(); i++) {
QDomElement subModel = subModels.at(i).toElement();
QDomNodeList interfacePoints = subModel.elementsByTagName("InterfacePoint");
for (int j = 0; j < interfacePoints.size(); j++) {
QDomElement interfacePoint = interfacePoints.at(j).toElement();
interfaces << subModel.attribute("Name") + "." + interfacePoint.attribute("Name");
}
QDomNodeList connections = pMetaModelEditor->getConnections();
for (int i = 0; i < connections.size(); i++) {
QDomElement connection = connections.at(i).toElement();
interfaces << connection.attribute("From")+" to "+connection.attribute("To");
interfaces << connection.attribute("To")+" to "+connection.attribute("From");
}
}
// from interfaces list
mpFromInterfaceListWidget = new QListWidget;
mpFromInterfaceListWidget->setItemDelegate(new ItemDelegate(mpFromInterfaceListWidget));
mpFromInterfaceListWidget->setTextElideMode(Qt::ElideMiddle);
mpFromInterfaceListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
mpFromInterfaceListWidget->addItems(interfaces);
// to interfaces list
mpToInterfaceListWidget = new QListWidget;
mpToInterfaceListWidget->setItemDelegate(new ItemDelegate(mpFromInterfaceListWidget));
mpToInterfaceListWidget->setTextElideMode(Qt::ElideMiddle);
mpToInterfaceListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
mpToInterfaceListWidget->addItems(interfaces);

// interfaces list
mpInterfaceListWidget = new QListWidget;
mpInterfaceListWidget->setItemDelegate(new ItemDelegate(mpInterfaceListWidget));
mpInterfaceListWidget->setTextElideMode(Qt::ElideMiddle);
mpInterfaceListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
mpInterfaceListWidget->addItems(interfaces);

if (interfaces.size() > 0) {
mpFromInterfaceListWidget->item(0)->setSelected(true);
mpToInterfaceListWidget->item(0)->setSelected(true);
mpInterfaceListWidget->item(0)->setSelected(true);
}

// Create the buttons
mpOkButton = new QPushButton(Helper::ok);
mpOkButton->setAutoDefault(true);
Expand All @@ -250,13 +243,11 @@ AlignInterfacesDialog::AlignInterfacesDialog(ModelWidget *pModelWidget)
// Create a layout
QGridLayout *pMainLayout = new QGridLayout;
pMainLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
pMainLayout->addWidget(mpAlignInterfacesHeading, 0, 0, 1, 2);
pMainLayout->addWidget(mpHorizontalLine, 1, 0, 1, 2);
pMainLayout->addWidget(new Label(tr("From Interface")), 2, 0);
pMainLayout->addWidget(new Label(tr("To Interface")), 2, 1);
pMainLayout->addWidget(mpFromInterfaceListWidget, 3, 0);
pMainLayout->addWidget(mpToInterfaceListWidget, 3, 1);
pMainLayout->addWidget(mpButtonBox, 4, 0, 1, 2, Qt::AlignRight);
pMainLayout->addWidget(mpAlignInterfacesHeading, 0, 0);
pMainLayout->addWidget(mpHorizontalLine, 1, 0);
pMainLayout->addWidget(new Label(tr("Interfaces")), 2, 0);
pMainLayout->addWidget(mpInterfaceListWidget, 3, 0);
pMainLayout->addWidget(mpButtonBox, 4, 0, Qt::AlignRight);
setLayout(pMainLayout);
}

Expand All @@ -269,10 +260,11 @@ void AlignInterfacesDialog::alignInterfaces()
{
MetaModelEditor *pMetaModelEditor = dynamic_cast<MetaModelEditor*>(mpModelWidget->getEditor());
if (pMetaModelEditor) {
QList<QListWidgetItem*> fromSelectedItems = mpFromInterfaceListWidget->selectedItems();
QList<QListWidgetItem*> toSelectedItems = mpToInterfaceListWidget->selectedItems();
if (fromSelectedItems.size() > 0 && toSelectedItems.size() > 0) {
pMetaModelEditor->alignInterfaces(fromSelectedItems.at(0)->text(), toSelectedItems.at(0)->text());
QList<QListWidgetItem*> selectedItems = mpInterfaceListWidget->selectedItems();
if (!selectedItems.isEmpty()) {
QString fromInterface = selectedItems.first()->text().section(" to ",0,0);
QString toInterface = selectedItems.first()->text().section(" to ",1,1);
pMetaModelEditor->alignInterfaces(fromInterface, toInterface);
}
}
accept();
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/TLM/FetchInterfaceDataDialog.h
Expand Up @@ -73,7 +73,7 @@ class AlignInterfacesDialog : public QDialog
ModelWidget *mpModelWidget;
Label *mpAlignInterfacesHeading;
QFrame *mpHorizontalLine;
QListWidget *mpFromInterfaceListWidget;
QListWidget *mpInterfaceListWidget;
QListWidget *mpToInterfaceListWidget;
QPushButton *mpOkButton;
QPushButton *mpCancelButton;
Expand Down

0 comments on commit 858eed0

Please sign in to comment.