Skip to content

Commit

Permalink
Merge branch 'adeas31-3dviewer'
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Jan 27, 2017
2 parents 4bf74df + 1ebe198 commit d4d7d13
Show file tree
Hide file tree
Showing 16 changed files with 498 additions and 207 deletions.
64 changes: 63 additions & 1 deletion OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.cpp
Expand Up @@ -135,8 +135,59 @@ void AbstractAnimationWindow::openAnimationFile(QString fileName)

void AbstractAnimationWindow::createActions()
{
// actions and widgets for the toolbar
int toolbarIconSize = OptionsDialog::instance()->getGeneralSettingsPage()->getToolbarIconSizeSpinBox()->value();
// choose file action
mpAnimationChooseFileAction = new QAction(QIcon(":/Resources/icons/open.svg"), Helper::animationChooseFile, this);
mpAnimationChooseFileAction->setStatusTip(Helper::animationChooseFileTip);
connect(mpAnimationChooseFileAction, SIGNAL(triggered()),this, SLOT(chooseAnimationFileSlotFunction()));
// initialize action
mpAnimationInitializeAction = new QAction(QIcon(":/Resources/icons/initialize.svg"), Helper::animationInitialize, this);
mpAnimationInitializeAction->setStatusTip(Helper::animationInitializeTip);
mpAnimationInitializeAction->setEnabled(false);
connect(mpAnimationInitializeAction, SIGNAL(triggered()),this, SLOT(initSlotFunction()));
// animation play action
mpAnimationPlayAction = new QAction(QIcon(":/Resources/icons/play_animation.svg"), Helper::animationPlay, this);
mpAnimationPlayAction->setStatusTip(Helper::animationPlayTip);
mpAnimationPlayAction->setEnabled(false);
connect(mpAnimationPlayAction, SIGNAL(triggered()),this, SLOT(playSlotFunction()));
// animation pause action
mpAnimationPauseAction = new QAction(QIcon(":/Resources/icons/pause.svg"), Helper::animationPause, this);
mpAnimationPauseAction->setStatusTip(Helper::animationPauseTip);
mpAnimationPauseAction->setEnabled(false);
connect(mpAnimationPauseAction, SIGNAL(triggered()),this, SLOT(pauseSlotFunction()));
// animation slide
mpAnimationSlider = new QSlider(Qt::Horizontal);
mpAnimationSlider->setMinimum(0);
mpAnimationSlider->setMaximum(100);
mpAnimationSlider->setSliderPosition(0);
mpAnimationSlider->setEnabled(false);
connect(mpAnimationSlider, SIGNAL(valueChanged(int)),this, SLOT(sliderSetTimeSlotFunction(int)));
// animation time
QDoubleValidator *pDoubleValidator = new QDoubleValidator(this);
pDoubleValidator->setBottom(0);
mpAnimationTimeLabel = new Label;
mpAnimationTimeLabel->setText(tr("Time [s]:"));
mpTimeTextBox = new QLineEdit("0.0");
mpTimeTextBox->setMaximumSize(QSize(toolbarIconSize*2, toolbarIconSize));
mpTimeTextBox->setEnabled(false);
mpTimeTextBox->setValidator(pDoubleValidator);
connect(mpTimeTextBox, SIGNAL(returnPressed()),this, SLOT(jumpToTimeSlotFunction()));
// animation speed
mpAnimationSpeedLabel = new Label;
mpAnimationSpeedLabel->setText(tr("Speed:"));
mpSpeedComboBox = new QComboBox;
mpSpeedComboBox->setEditable(true);
mpSpeedComboBox->addItems(QStringList() << "10" << "5" << "2" << "1" << "0.5" << "0.2" << "0.1");
mpSpeedComboBox->setCurrentIndex(3);
mpSpeedComboBox->setMaximumSize(QSize(toolbarIconSize*2, toolbarIconSize));
mpSpeedComboBox->setEnabled(false);
mpSpeedComboBox->setValidator(pDoubleValidator);
mpSpeedComboBox->setCompleter(0);
connect(mpSpeedComboBox, SIGNAL(currentIndexChanged(int)),this, SLOT(setSpeedSlotFunction()));
connect(mpSpeedComboBox->lineEdit(), SIGNAL(textChanged(QString)),this, SLOT(setSpeedSlotFunction()));
// perspective drop down
mpPerspectiveDropDownBox = new QComboBox(this);
mpPerspectiveDropDownBox = new QComboBox;
mpPerspectiveDropDownBox->addItem(QIcon(":/Resources/icons/perspective0.svg"), QString("Isometric"));
mpPerspectiveDropDownBox->addItem(QIcon(":/Resources/icons/perspective1.svg"),QString("Side"));
mpPerspectiveDropDownBox->addItem(QIcon(":/Resources/icons/perspective2.svg"),QString("Front"));
Expand All @@ -152,6 +203,17 @@ void AbstractAnimationWindow::createActions()
connect(mpRotateCameraRightAction, SIGNAL(triggered()), this, SLOT(rotateCameraRight()));
}

/*!
* \brief AbstractAnimationWindow::clearView
*/
void AbstractAnimationWindow::clearView()
{
if (mpViewerWidget) {
mpViewerWidget->getSceneView()->setSceneData(0);
mpViewerWidget->update();
}
}

/*!
* \brief AbstractAnimationWindow::loadVisualization
* loads the data and the xml scene description
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.h
Expand Up @@ -54,6 +54,7 @@ class AbstractAnimationWindow : public QMainWindow
AbstractAnimationWindow(QWidget *pParent);
void openAnimationFile(QString fileName);
virtual void createActions();
void clearView();
private:
bool loadVisualization();
protected:
Expand Down
51 changes: 0 additions & 51 deletions OMEdit/OMEditGUI/Animation/AnimationWindow.cpp
Expand Up @@ -67,57 +67,6 @@ AnimationWindow::~AnimationWindow()
void AnimationWindow::createActions()
{
AbstractAnimationWindow::createActions();
// actions and widgets for the toolbar
int toolbarIconSize = OptionsDialog::instance()->getGeneralSettingsPage()->getToolbarIconSizeSpinBox()->value();
// choose file action
mpAnimationChooseFileAction = new QAction(QIcon(":/Resources/icons/open.svg"), Helper::animationChooseFile, this);
mpAnimationChooseFileAction->setStatusTip(Helper::animationChooseFileTip);
connect(mpAnimationChooseFileAction, SIGNAL(triggered()),this, SLOT(chooseAnimationFileSlotFunction()));
// initialize action
mpAnimationInitializeAction = new QAction(QIcon(":/Resources/icons/initialize.svg"), Helper::animationInitialize, this);
mpAnimationInitializeAction->setStatusTip(Helper::animationInitializeTip);
mpAnimationInitializeAction->setEnabled(false);
connect(mpAnimationInitializeAction, SIGNAL(triggered()),this, SLOT(initSlotFunction()));
// animation play action
mpAnimationPlayAction = new QAction(QIcon(":/Resources/icons/play_animation.svg"), Helper::animationPlay, this);
mpAnimationPlayAction->setStatusTip(Helper::animationPlayTip);
mpAnimationPlayAction->setEnabled(false);
connect(mpAnimationPlayAction, SIGNAL(triggered()),this, SLOT(playSlotFunction()));
// animation pause action
mpAnimationPauseAction = new QAction(QIcon(":/Resources/icons/pause.svg"), Helper::animationPause, this);
mpAnimationPauseAction->setStatusTip(Helper::animationPauseTip);
mpAnimationPauseAction->setEnabled(false);
connect(mpAnimationPauseAction, SIGNAL(triggered()),this, SLOT(pauseSlotFunction()));
// animation slide
mpAnimationSlider = new QSlider(Qt::Horizontal);
mpAnimationSlider->setMinimum(0);
mpAnimationSlider->setMaximum(100);
mpAnimationSlider->setSliderPosition(0);
mpAnimationSlider->setEnabled(false);
connect(mpAnimationSlider, SIGNAL(valueChanged(int)),this, SLOT(sliderSetTimeSlotFunction(int)));
// animation time
QDoubleValidator *pDoubleValidator = new QDoubleValidator(this);
pDoubleValidator->setBottom(0);
mpAnimationTimeLabel = new Label;
mpAnimationTimeLabel->setText(tr("Time [s]:"));
mpTimeTextBox = new QLineEdit("0.0", this);
mpTimeTextBox->setMaximumSize(QSize(toolbarIconSize*2, toolbarIconSize));
mpTimeTextBox->setEnabled(false);
mpTimeTextBox->setValidator(pDoubleValidator);
connect(mpTimeTextBox, SIGNAL(returnPressed()),this, SLOT(jumpToTimeSlotFunction()));
// animation speed
mpAnimationSpeedLabel = new Label;
mpAnimationSpeedLabel->setText(tr("Speed:"));
mpSpeedComboBox = new QComboBox(this);
mpSpeedComboBox->setEditable(true);
mpSpeedComboBox->addItems(QStringList() << "10" << "5" << "2" << "1" << "0.5" << "0.2" << "0.1");
mpSpeedComboBox->setCurrentIndex(3);
mpSpeedComboBox->setMaximumSize(QSize(toolbarIconSize*2, toolbarIconSize));
mpSpeedComboBox->setEnabled(false);
mpSpeedComboBox->setValidator(pDoubleValidator);
mpSpeedComboBox->setCompleter(0);
connect(mpSpeedComboBox, SIGNAL(currentIndexChanged(int)),this, SLOT(setSpeedSlotFunction()));
connect(mpSpeedComboBox->lineEdit(), SIGNAL(textChanged(QString)),this, SLOT(setSpeedSlotFunction()));
//assemble the animation toolbar
mpAnimationToolBar->addAction(mpAnimationChooseFileAction);
mpAnimationToolBar->addSeparator();
Expand Down
21 changes: 17 additions & 4 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -82,8 +82,11 @@ ComponentInfo::ComponentInfo(QObject *pParent)
mExactStep = false;
mModelFile = "";
mGeometryFile = "";
mPosition = "";
mAngle321 = "";
mPosition = "0,0,0";
mAngle321 = "0,0,0";
mDimensions = 3;
mTLMCausality = StringHandler::getTLMCausality(StringHandler::TLMBidirectional);
mDomain = StringHandler::getTLMDomain(StringHandler::Mechanical);
}

/*!
Expand Down Expand Up @@ -131,6 +134,9 @@ void ComponentInfo::updateComponentInfo(const ComponentInfo *pComponentInfo)
mGeometryFile = pComponentInfo->getGeometryFile();
mPosition = pComponentInfo->getPosition();
mAngle321 = pComponentInfo->getAngle321();
mDimensions = pComponentInfo->getDimensions();
mTLMCausality = pComponentInfo->getTLMCausality();
mDomain = pComponentInfo->getDomain();
}

/*!
Expand Down Expand Up @@ -1319,7 +1325,7 @@ void Component::drawInterfacePoints()
pComponentInfo->setAngle321(interfacePoint.attribute("Angle321", "0,0,0"));
pComponentInfo->setDimensions(interfacePoint.attribute("Dimensions", "3").toInt());
pComponentInfo->setTLMCausality(interfacePoint.attribute("Causality",
StringHandler::getTLMCausality(StringHandler::TLMBidirectional)));
StringHandler::getTLMCausality(StringHandler::TLMBidirectional)));
pComponentInfo->setDomain(interfacePoint.attribute("Domain",
StringHandler::getTLMDomain(StringHandler::Mechanical)));
mComponentsList.append(new Component(pComponentInfo, this));
Expand Down Expand Up @@ -1459,7 +1465,7 @@ void Component::createActions()
mpParametersAction->setStatusTip(tr("Shows the component parameters"));
connect(mpParametersAction, SIGNAL(triggered()), SLOT(showParameters()));
// Fetch interfaces action
mpFetchInterfaceDataAction = new QAction(Helper::fetchInterfaceData, mpGraphicsView);
mpFetchInterfaceDataAction = new QAction(QIcon(":/Resources/icons/interface-data.svg"), Helper::fetchInterfaceData, mpGraphicsView);
mpFetchInterfaceDataAction->setStatusTip(tr("Fetch interface data for this external model"));
connect(mpFetchInterfaceDataAction, SIGNAL(triggered()), SLOT(fetchInterfaceData()));
// Todo: Connect /robbr
Expand Down Expand Up @@ -2482,6 +2488,7 @@ void Component::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
break;
case LibraryTreeItem::MetaModel:
menu.addAction(pComponent->getFetchInterfaceDataAction());
menu.addSeparator();
menu.addAction(pComponent->getSubModelAttributesAction());
break;
}
Expand Down Expand Up @@ -2561,6 +2568,12 @@ QVariant Component::itemChange(GraphicsItemChange change, const QVariant &value)
disconnect(mpGraphicsView, SIGNAL(keyPressCtrlRight()), this, SLOT(moveCtrlRight()));
}
}
#if !defined(WITHOUT_OSG)
// if subModel selection is changed in MetaModel
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::MetaModel) {
MainWindow::instance()->getModelWidgetContainer()->updateThreeDViewer(mpGraphicsView->getModelWidget());
}
#endif
} else if (change == QGraphicsItem::ItemPositionHasChanged) {
emit transformChange();
}
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Component/ComponentProperties.cpp
Expand Up @@ -1438,6 +1438,7 @@ void MetaModelSubModelAttributes::setUpDialog()
mpGeometryFileLabel = new Label(tr("Geometry File:"));
mpGeometryFileTextBox = new QLineEdit;
mpGeometryFileBrowseButton = new QPushButton(Helper::browse);
mpGeometryFileBrowseButton->setAutoDefault(false);
connect(mpGeometryFileBrowseButton, SIGNAL(clicked()), this, SLOT(browseGeometryFile()));
// Create the buttons
mpOkButton = new QPushButton(Helper::ok);
Expand Down
70 changes: 45 additions & 25 deletions OMEdit/OMEditGUI/Editors/MetaModelEditor.cpp
Expand Up @@ -32,7 +32,6 @@
#include "MainWindow.h"
#include "Options/OptionsDialog.h"
#include "Modeling/MessagesWidget.h"
#include "Component/ComponentProperties.h"
#include "Modeling/Commands.h"

#include <QMessageBox>
Expand Down Expand Up @@ -232,33 +231,32 @@ void MetaModelEditor::setMetaModelName(QString name)
/*!
* \brief MetaModelEditor::addSubModel
* Adds a SubModel tag with Annotation tag as child of it.
* \param name
* \param modelFile
* \param startCommand
* \param visible
* \param origin
* \param extent
* \param rotation
* \param pComponent
* \return
*/
bool MetaModelEditor::addSubModel(QString name, QString modelFile, QString startCommand, QString visible, QString origin,
QString extent, QString rotation)
bool MetaModelEditor::addSubModel(Component *pComponent)
{
Component* pComp = mpModelWidget->getDiagramGraphicsView()->getComponentObject(name);
name = name.remove(".");
pComp->getComponentInfo()->setName(name);
pComponent->getComponentInfo()->setName(pComponent->getName().remove("."));
QDomElement subModels = getSubModelsElement();
if (!subModels.isNull()) {
QDomElement subModel = mXmlDocument.createElement("SubModel");
subModel.setAttribute("Name", name);
subModel.setAttribute("ModelFile", modelFile);
subModel.setAttribute("StartCommand", startCommand);
subModel.setAttribute("Name", pComponent->getName());
subModel.setAttribute("ModelFile", pComponent->getComponentInfo()->getModelFile());
subModel.setAttribute("StartCommand", pComponent->getComponentInfo()->getStartCommand());
subModel.setAttribute("Position", pComponent->getComponentInfo()->getPosition());
subModel.setAttribute("Angle321", pComponent->getComponentInfo()->getAngle321());
if (pComponent->getComponentInfo()->getGeometryFile().isEmpty()) {
subModel.removeAttribute("GeometryFile");
} else {
QFileInfo geometryFileInfo(pComponent->getComponentInfo()->getGeometryFile());
subModel.setAttribute("GeometryFile", geometryFileInfo.fileName());
}
// create Annotation Element
QDomElement annotation = mXmlDocument.createElement("Annotation");
annotation.setAttribute("Visible", visible);
annotation.setAttribute("Origin", origin);
annotation.setAttribute("Extent", extent);
annotation.setAttribute("Rotation", rotation);
annotation.setAttribute("Visible", pComponent->mTransformation.getVisible() ? "true" : "false");
annotation.setAttribute("Origin", pComponent->getTransformationOrigin());
annotation.setAttribute("Extent", pComponent->getTransformationExtent());
annotation.setAttribute("Rotation", QString::number(pComponent->mTransformation.getRotateAngle()));
subModel.appendChild(annotation);
subModels.appendChild(subModel);
setPlainText(mXmlDocument.toString());
Expand Down Expand Up @@ -552,7 +550,7 @@ void MetaModelEditor::addInterfacesData(QDomElement interfaces, QString singleMo
(subModel.attribute("Name") == singleModel || singleModel.isEmpty())) {
QDomElement interfacePoint;
// update interface point
if (existInterfaceData(subModel.attribute("Name"), interfaceDataElement)) {
if (existInterfacePoint(subModel.attribute("Name"), interfaceDataElement.attribute("Name"))) {
interfacePoint = getInterfacePoint(subModel.attribute("Name"), interfaceDataElement.attribute("Name"));
interfacePoint.setAttribute("Name", interfaceDataElement.attribute("Name"));
interfacePoint.setAttribute("Position", interfaceDataElement.attribute("Position"));
Expand Down Expand Up @@ -580,6 +578,7 @@ void MetaModelEditor::addInterfacesData(QDomElement interfaces, QString singleMo
interfacePoint.setAttribute("Causality", interfaceDataElement.attribute("Causality"));
interfacePoint.setAttribute("Domain", interfaceDataElement.attribute("Domain"));
subModel.appendChild(interfacePoint);
setPlainText(mXmlDocument.toString());
Component *pComponent = mpModelWidget->getDiagramGraphicsView()->getComponentObject(subModel.attribute("Name"));
if (pComponent) {
pComponent->insertInterfacePoint(interfaceDataElement.attribute("Name"),
Expand Down Expand Up @@ -664,6 +663,26 @@ void MetaModelEditor::addInterfacesData(QDomElement interfaces, QString singleMo
setPlainText(mXmlDocument.toString());
}

/*!
* \brief MetaModelEditor::addInterface
* Adds the interface to submodel.
* \param pInterfaceComponent
* \param subModel
*/
void MetaModelEditor::addInterface(Component *pInterfaceComponent, QString subModel)
{
QDomElement subModelElement = getSubModelElement(subModel);
QDomElement interfacePoint = mXmlDocument.createElement("InterfacePoint");
interfacePoint.setAttribute("Name", pInterfaceComponent->getName());
interfacePoint.setAttribute("Position", pInterfaceComponent->getComponentInfo()->getPosition());
interfacePoint.setAttribute("Angle321", pInterfaceComponent->getComponentInfo()->getAngle321());
interfacePoint.setAttribute("Dimensions", pInterfaceComponent->getComponentInfo()->getDimensions());
interfacePoint.setAttribute("Causality", pInterfaceComponent->getComponentInfo()->getTLMCausality());
interfacePoint.setAttribute("Domain", pInterfaceComponent->getComponentInfo()->getDomain());
subModelElement.appendChild(interfacePoint);
setPlainText(mXmlDocument.toString());
}

/*!
* \brief MetaModelEditor::interfacesAligned
* Checkes whether specified TLM interfaces are aligned
Expand Down Expand Up @@ -787,13 +806,13 @@ bool MetaModelEditor::deleteConnection(QString startSubModelName, QString endSub
}

/*!
* \brief MetaModelEditor::existInterfaceData
* \brief MetaModelEditor::existInterfacePoint
* Checks whether the interface already exists in MetaModel or not.
* \param subModelName
* \param interfaceElement
* \param interfaceName
* \return
*/
bool MetaModelEditor::existInterfaceData(QString subModelName, QDomElement interfaceDataElement)
bool MetaModelEditor::existInterfacePoint(QString subModelName, QString interfaceName)
{
QDomNodeList subModelList = mXmlDocument.elementsByTagName("SubModel");
for (int i = 0 ; i < subModelList.size() ; i++) {
Expand All @@ -803,7 +822,7 @@ bool MetaModelEditor::existInterfaceData(QString subModelName, QDomElement inter
for (int j = 0 ; j < subModelChildren.size() ; j++) {
QDomElement interfaceElement = subModelChildren.at(j).toElement();
if (interfaceElement.tagName().compare("InterfacePoint") == 0 &&
interfaceElement.attribute("Name").compare(interfaceDataElement.attribute("Name")) == 0) {
interfaceElement.attribute("Name").compare(interfaceName) == 0) {
return true;
}
}
Expand Down Expand Up @@ -866,6 +885,7 @@ bool MetaModelEditor::getPositionAndRotationVectors(QString interfacePoint, QGen
if (interfaceElement.attribute("Name").compare(interfaceName) == 0) {
x_c_r_x_str = interfaceElement.attribute("Position");
x_c_phi_x_str = interfaceElement.attribute("Angle321");
break;
}
interfaceElement = interfaceElement.nextSiblingElement("InterfacePoint");
}
Expand Down

0 comments on commit d4d7d13

Please sign in to comment.