diff --git a/OMEdit/OMEditLIB/Animation/AbstractAnimationWindow.cpp b/OMEdit/OMEditLIB/Animation/AbstractAnimationWindow.cpp index 371748e2a01..2f51e6ecdf0 100644 --- a/OMEdit/OMEditLIB/Animation/AbstractAnimationWindow.cpp +++ b/OMEdit/OMEditLIB/Animation/AbstractAnimationWindow.cpp @@ -41,9 +41,9 @@ #include "Modeling/MessagesWidget.h" #include "Plotting/PlotWindowContainer.h" #include "ViewerWidget.h" -#include "Visualization.h" -#include "VisualizationMAT.h" -#include "VisualizationCSV.h" +#include "Visualizer.h" +#include "VisualizerMAT.h" +#include "VisualizerCSV.h" /*! * \class AbstractAnimationWindow @@ -58,7 +58,7 @@ AbstractAnimationWindow::AbstractAnimationWindow(QWidget *pParent) // osgViewer::CompositeViewer(), mPathName(""), mFileName(""), - mpVisualization(nullptr), + mpVisualizer(nullptr), mpViewerWidget(nullptr), mpAnimationToolBar(new QToolBar(QString("Animation Toolbar"),this)), mpAnimationParameterDockerWidget(new QDockWidget(QString("Parameter Settings"),this)), @@ -125,7 +125,7 @@ void AbstractAnimationWindow::openAnimationFile(QString fileName, bool stashCame mpAnimationSlider->blockSignals(state); mpSpeedComboBox->setEnabled(true); mpTimeTextBox->setEnabled(true); - mpTimeTextBox->setText(QString::number(mpVisualization->getTimeManager()->getStartTime())); + mpTimeTextBox->setText(QString::number(mpVisualizer->getTimeManager()->getStartTime())); /* Only use isometric view as default for csv file type. * Otherwise use side view as default which suits better for Modelica models. */ @@ -236,8 +236,8 @@ void AbstractAnimationWindow::createActions() */ void AbstractAnimationWindow::updateControlPanelValues() { - if (getVisualization()) { - VisualizationFMU* FMUvis = dynamic_cast(mpVisualization); + if (getVisualizer()) { + VisualizerFMU* FMUvis = dynamic_cast(mpVisualizer); for (int stateIdx = 0; stateIdx < mSpinBoxVector.size(); stateIdx++) { mStateLabels.at(stateIdx)->setText(QString::number(FMUvis->getFMU()->getFMUData()->_states[stateIdx])); } @@ -249,8 +249,8 @@ void AbstractAnimationWindow::updateControlPanelValues() */ void AbstractAnimationWindow::initInteractiveControlPanel() { - if (getVisualization()) { - VisualizationFMU* FMUvis = dynamic_cast(mpVisualization); + if (getVisualizer()) { + VisualizerFMU* FMUvis = dynamic_cast(mpVisualizer); QWidget *widget = new QWidget(this); mSpinBoxVector.clear(); mStateLabels.clear(); @@ -333,7 +333,7 @@ void AbstractAnimationWindow::initInteractiveControlPanel() void AbstractAnimationWindow::setStateSolveSystem(double val, int idx) { if (idx>=0) { - VisualizationFMU* FMUvis = dynamic_cast(mpVisualization); + VisualizerFMU* FMUvis = dynamic_cast(mpVisualizer); if (FMUvis) { FMUvis->getFMU()->getFMUData()->_states[idx] = val; } @@ -388,7 +388,7 @@ bool AbstractAnimationWindow::loadVisualization() Helper::scriptingKind, Helper::errorLevel)); return false; } - //load the XML File, build osgTree, get initial values for the visualizers + //load the XML File, build osgTree, get initial values for the shapes bool xmlExists = checkForXMLFile(mFileName, mPathName); if (!xmlExists) { QString msg = tr("Could not find the visual XML file %1.").arg(QString(assembleXMLFileName(mFileName, mPathName).c_str())); @@ -396,31 +396,31 @@ bool AbstractAnimationWindow::loadVisualization() Helper::errorLevel)); return false; } else { - //init visualization + //init visualizer if (visType == VisType::MAT) { - mpVisualization = new VisualizationMAT(mFileName, mPathName); + mpVisualizer = new VisualizerMAT(mFileName, mPathName); } else if (visType == VisType::CSV) { - mpVisualization = new VisualizationCSV(mFileName, mPathName); + mpVisualizer = new VisualizerCSV(mFileName, mPathName); } else if (visType == VisType::FMU) { - mpVisualization = new VisualizationFMU(mFileName, mPathName); + mpVisualizer = new VisualizerFMU(mFileName, mPathName); } else { QString msg = tr("Could not init %1 %2.").arg(QString(mPathName.c_str())).arg(QString(mFileName.c_str())); MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, Helper::scriptingKind, Helper::errorLevel)); return false; } - connect(mpVisualization->getTimeManager()->getUpdateSceneTimer(), SIGNAL(timeout()), SLOT(updateScene())); - mpVisualization->initData(); - mpVisualization->setUpScene(); - mpVisualization->initVisualization(); + connect(mpVisualizer->getTimeManager()->getUpdateSceneTimer(), SIGNAL(timeout()), SLOT(updateScene())); + mpVisualizer->initData(); + mpVisualizer->setUpScene(); + mpVisualizer->initVisualization(); //add scene for the chosen visualization - mpViewerWidget->getSceneView()->setSceneData(mpVisualization->getOMVisScene()->getScene().getRootNode()); + mpViewerWidget->getSceneView()->setSceneData(mpVisualizer->getOMVisScene()->getScene().getRootNode()); } //add window title setWindowTitle(QString::fromStdString(mFileName)); //open settings dialog for FMU simulation if (visType == VisType::FMU) { - openFMUSettingsDialog(dynamic_cast(mpVisualization)); + openFMUSettingsDialog(dynamic_cast(mpVisualizer)); mpInteractiveControlAction->setEnabled(true); initInteractiveControlPanel(); } @@ -528,11 +528,11 @@ double AbstractAnimationWindow::computeDistanceToOrigin() /*! * \brief AbstractAnimationWindow::openFMUSettingsDialog * Opens a dialog to set the settings for the FMU visualization - * \param pVisualizationFMU + * \param pVisualizerFMU */ -void AbstractAnimationWindow::openFMUSettingsDialog(VisualizationFMU* pVisualizationFMU) +void AbstractAnimationWindow::openFMUSettingsDialog(VisualizerFMU* pVisualizerFMU) { - FMUSettingsDialog *pFMUSettingsDialog = new FMUSettingsDialog(this, pVisualizationFMU); + FMUSettingsDialog *pFMUSettingsDialog = new FMUSettingsDialog(this, pVisualizerFMU); pFMUSettingsDialog->exec(); } @@ -542,13 +542,13 @@ void AbstractAnimationWindow::openFMUSettingsDialog(VisualizationFMU* pVisualiza */ void AbstractAnimationWindow::updateScene() { - if (mpVisualization) { + if (!(mpVisualizer == NULL)) { //set time label - if (!mpVisualization->getTimeManager()->isPaused()) { - mpTimeTextBox->setText(QString::number(mpVisualization->getTimeManager()->getVisTime())); + if (!mpVisualizer->getTimeManager()->isPaused()) { + mpTimeTextBox->setText(QString::number(mpVisualizer->getTimeManager()->getVisTime())); // set time slider - if (mpVisualization->getVisType() != VisType::FMU) { - int time = mpVisualization->getTimeManager()->getTimeFraction(); + if (mpVisualizer->getVisType() != VisType::FMU) { + int time = mpVisualizer->getTimeManager()->getTimeFraction(); bool state = mpAnimationSlider->blockSignals(true); mpAnimationSlider->setValue(time); mpAnimationSlider->blockSignals(state); @@ -556,7 +556,7 @@ void AbstractAnimationWindow::updateScene() } //update the scene - mpVisualization->sceneUpdate(); + mpVisualizer->sceneUpdate(); mpViewerWidget->update(); updateControlPanelValues(); @@ -569,8 +569,8 @@ void AbstractAnimationWindow::updateScene() */ void AbstractAnimationWindow::chooseAnimationFileSlotFunction() { - QString fileName = StringHandler::getOpenFileName(this, QString("%1 – %2").arg(Helper::applicationName).arg(Helper::chooseFile), - nullptr, Helper::visualizationFileTypes, nullptr); + QString fileName = StringHandler::getOpenFileName(this, QString("%1 - %2").arg(Helper::applicationName).arg(Helper::chooseFile), + NULL, Helper::visualizationFileTypes, NULL); if (fileName.isEmpty()) { return; } @@ -583,11 +583,11 @@ void AbstractAnimationWindow::chooseAnimationFileSlotFunction() */ void AbstractAnimationWindow::initSlotFunction() { - mpVisualization->initVisualization(); + mpVisualizer->initVisualization(); bool state = mpAnimationSlider->blockSignals(true); mpAnimationSlider->setValue(0); mpAnimationSlider->blockSignals(state); - mpTimeTextBox->setText(QString::number(mpVisualization->getTimeManager()->getVisTime())); + mpTimeTextBox->setText(QString::number(mpVisualizer->getTimeManager()->getVisTime())); mpViewerWidget->update(); updateControlPanelValues(); } @@ -598,7 +598,7 @@ void AbstractAnimationWindow::initSlotFunction() */ void AbstractAnimationWindow::playSlotFunction() { - mpVisualization->getTimeManager()->setPause(false); + mpVisualizer->getTimeManager()->setPause(false); } /*! @@ -607,7 +607,7 @@ void AbstractAnimationWindow::playSlotFunction() */ void AbstractAnimationWindow::pauseSlotFunction() { - mpVisualization->getTimeManager()->setPause(true); + mpVisualizer->getTimeManager()->setPause(true); } /*! @@ -617,7 +617,7 @@ void AbstractAnimationWindow::pauseSlotFunction() */ void AbstractAnimationWindow::repeatSlotFunciton(bool checked) { - mpVisualization->getTimeManager()->setRepeat(checked); + mpVisualizer->getTimeManager()->setRepeat(checked); } /*! @@ -626,12 +626,12 @@ void AbstractAnimationWindow::repeatSlotFunciton(bool checked) */ void AbstractAnimationWindow::sliderSetTimeSlotFunction(int value) { - float time = (mpVisualization->getTimeManager()->getEndTime() - - mpVisualization->getTimeManager()->getStartTime()) + float time = (mpVisualizer->getTimeManager()->getEndTime() + - mpVisualizer->getTimeManager()->getStartTime()) * (float) (value / (float)mSliderRange); - mpVisualization->getTimeManager()->setVisTime(time); - mpTimeTextBox->setText(QString::number(mpVisualization->getTimeManager()->getVisTime())); - mpVisualization->updateScene(time); + mpVisualizer->getTimeManager()->setVisTime(time); + mpTimeTextBox->setText(QString::number(mpVisualizer->getTimeManager()->getVisTime())); + mpVisualizer->updateScene(time); mpViewerWidget->update(); } @@ -643,8 +643,8 @@ void AbstractAnimationWindow::jumpToTimeSlotFunction() { QString str = mpTimeTextBox->text(); bool isFloat = true; - double start = mpVisualization->getTimeManager()->getStartTime(); - double end = mpVisualization->getTimeManager()->getEndTime(); + double start = mpVisualizer->getTimeManager()->getStartTime(); + double end = mpVisualizer->getTimeManager()->getEndTime(); double value = str.toFloat(&isFloat); if (isFloat && value >= 0.0) { if (value < start) { @@ -652,11 +652,11 @@ void AbstractAnimationWindow::jumpToTimeSlotFunction() } else if (value > end) { value = end; } - mpVisualization->getTimeManager()->setVisTime(value); + mpVisualizer->getTimeManager()->setVisTime(value); bool state = mpAnimationSlider->blockSignals(true); - mpAnimationSlider->setValue(mpVisualization->getTimeManager()->getTimeFraction()); + mpAnimationSlider->setValue(mpVisualizer->getTimeManager()->getTimeFraction()); mpAnimationSlider->blockSignals(state); - mpVisualization->updateScene(value); + mpVisualizer->updateScene(value); mpViewerWidget->update(); } } @@ -671,7 +671,7 @@ void AbstractAnimationWindow::setSpeedSlotFunction() bool isFloat = true; double value = str.toFloat(&isFloat); if (isFloat && value > 0.0) { - mpVisualization->getTimeManager()->setSpeedUp(value); + mpVisualizer->getTimeManager()->setSpeedUp(value); mpViewerWidget->update(); } } diff --git a/OMEdit/OMEditLIB/Animation/AbstractAnimationWindow.h b/OMEdit/OMEditLIB/Animation/AbstractAnimationWindow.h index 16d070b1322..e11e3e399b8 100644 --- a/OMEdit/OMEditLIB/Animation/AbstractAnimationWindow.h +++ b/OMEdit/OMEditLIB/Animation/AbstractAnimationWindow.h @@ -45,7 +45,7 @@ #include "FMUSettingsDialog.h" -class VisualizationAbstract; +class VisualizerAbstract; class ViewerWidget; class Label; @@ -70,7 +70,7 @@ class AbstractAnimationWindow : public QMainWindow public: AbstractAnimationWindow(QWidget *pParent); ViewerWidget* getViewerWidget() {return mpViewerWidget;} - VisualizationAbstract* getVisualization() {return mpVisualization;} + VisualizerAbstract* getVisualizer() {return mpVisualizer;} void openAnimationFile(QString fileName, bool stashCamera=false); virtual void createActions(); void clearView(); @@ -82,8 +82,8 @@ class AbstractAnimationWindow : public QMainWindow //to be animated std::string mPathName; std::string mFileName; - //stores the data for the visualizers, time management, functionality for updating the values(mat/fmu) etc. - VisualizationAbstract* mpVisualization; + //stores the data for the shapes, time management, functionality for updating the values(mat/fmu) etc. + VisualizerAbstract* mpVisualizer; //widgets ViewerWidget *mpViewerWidget; QToolBar* mpAnimationToolBar; @@ -114,7 +114,7 @@ class AbstractAnimationWindow : public QMainWindow void cameraPositionFront(); void cameraPositionTop(); double computeDistanceToOrigin(); - void openFMUSettingsDialog(VisualizationFMU *pVisualizationFMU); + void openFMUSettingsDialog(VisualizerFMU *pVisualizerFMU); void updateControlPanelValues(); public slots: diff --git a/OMEdit/OMEditLIB/Animation/AbstractVisualizer.cpp b/OMEdit/OMEditLIB/Animation/AbstractVisualizer.cpp deleted file mode 100644 index 283421b26c0..00000000000 --- a/OMEdit/OMEditLIB/Animation/AbstractVisualizer.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - * This file is part of OpenModelica. - * - * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), - * c/o Linköpings universitet, Department of Computer and Information Science, - * SE-58183 Linköping, Sweden. - * - * All rights reserved. - * - * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR - * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. - * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES - * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, - * ACCORDING TO RECIPIENTS CHOICE. - * - * The OpenModelica software and the Open Source Modelica - * Consortium (OSMC) Public License (OSMC-PL) are obtained - * from OSMC, either from the above address, - * from the URLs: http://www.ida.liu.se/projects/OpenModelica or - * http://www.openmodelica.org, and in the OpenModelica distribution. - * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. - * - * This program is distributed WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH - * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. - * - * See the full OSMC Public License conditions for more details. - * - */ -/* - * @author Volker Waurich - */ - -#include "AbstractVisualizer.h" - -std::string operator+(const std::string& st, const VisualizerType type) -{ - switch (type) - { - case VisualizerType::shape: - return st + "Shape"; - case VisualizerType::vector: - return st + "Vector"; - case VisualizerType::surface: - return st + "Surface"; - default: - return st; - } -} - -std::ostream& operator<<(std::ostream& os, const VisualizerType type) -{ - switch (type) - { - case VisualizerType::shape: - return os << "shape"; - case VisualizerType::vector: - return os << "vector"; - case VisualizerType::surface: - return os << "surface"; - default: - return os; - } -} - -std::ostream& operator<<(std::ostream& os, const StateSetAction action) -{ - switch (action) - { - case StateSetAction::update: - return os << "update"; - case StateSetAction::modify: - return os << "modify"; - default: - return os; - } -} - -VisualizerAttribute::VisualizerAttribute() - : isConst(true), - exp(0.0), - cref(""), - fmuValueRef(0) -{ -} - -VisualizerAttribute::VisualizerAttribute(const float value) - : isConst(true), - exp(value), - cref(""), - fmuValueRef(0) -{ -} - -std::string VisualizerAttribute::getValueString() const -{ - return std::to_string(exp) + " (" + std::to_string(fmuValueRef) + ") " + std::to_string(isConst); -} - -AbstractVisualizerObject::AbstractVisualizerObject(const VisualizerType type) - : mVisualizerType(type), - mStateSetAction(StateSetAction::update), - mTextureImagePath(""), - mTransparency(0.0), - _id(""), - _mat(osg::Matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)), - _specCoeff(VisualizerAttribute(0.7)) -{ - _T[0] = VisualizerAttribute(0.0); - _T[1] = VisualizerAttribute(0.0); - _T[2] = VisualizerAttribute(1.0); - _T[3] = VisualizerAttribute(1.0); - _T[4] = VisualizerAttribute(0.0); - _T[5] = VisualizerAttribute(0.0); - _T[6] = VisualizerAttribute(0.0); - _T[7] = VisualizerAttribute(1.0); - _T[8] = VisualizerAttribute(0.0); - _r[0] = VisualizerAttribute(0.1); - _r[1] = VisualizerAttribute(0.1); - _r[2] = VisualizerAttribute(0.1); - _color[0] = VisualizerAttribute(255.0); - _color[1] = VisualizerAttribute(255.0); - _color[2] = VisualizerAttribute(255.0); -} - -AbstractVisualizerObject::~AbstractVisualizerObject() -{ - /* A function body is required for a pure virtual destructor. */ -} - -void AbstractVisualizerObject::dumpVisualizerAttributes() const -{ - std::cout << "id " << _id << std::endl; - std::cout << "visualizerType " << mVisualizerType << std::endl; - std::cout << "stateSetAction " << mStateSetAction << std::endl; - std::cout << "textureImagePath " << mTextureImagePath << std::endl; - std::cout << "transparency " << mTransparency << std::endl; - std::cout << "color " << _color[0].getValueString() << " , " << _color[1].getValueString() << " , " << _color[2].getValueString() << std::endl; - std::cout << "specCoeff " << _specCoeff.getValueString() << std::endl; - std::cout << "mat " << _mat(0, 0) << " , " << _mat(0, 1) << " , " << _mat(0, 2) << " , " << _mat(0, 3) << std::endl; - std::cout << " " << _mat(1, 0) << " , " << _mat(1, 1) << " , " << _mat(1, 2) << " , " << _mat(1, 3) << std::endl; - std::cout << " " << _mat(2, 0) << " , " << _mat(2, 1) << " , " << _mat(2, 2) << " , " << _mat(2, 3) << std::endl; - std::cout << " " << _mat(3, 0) << " , " << _mat(3, 1) << " , " << _mat(3, 2) << " , " << _mat(3, 3) << std::endl; - std::cout << "T " << _T[0].getValueString() << " , " << _T[1].getValueString() << " , " << _T[2].getValueString() << std::endl; - std::cout << " " << _T[3].getValueString() << " , " << _T[4].getValueString() << " , " << _T[5].getValueString() << std::endl; - std::cout << " " << _T[6].getValueString() << " , " << _T[7].getValueString() << " , " << _T[8].getValueString() << std::endl; - std::cout << "r " << _r[0].getValueString() << " , " << _r[1].getValueString() << " , " << _r[2].getValueString() << std::endl; -} - -VisualizerAttribute getVisualizerAttributeForNode(const rapidxml::xml_node<>* node) -{ - VisualizerAttribute oa; - if (strcmp("cref", node->name()) == 0) { - oa.cref = std::string(node->value()); - oa.isConst = false; - } else if (strcmp("exp", node->name()) == 0) { - oa.exp = std::strtof(node->value(), nullptr); - oa.isConst = true; - } else if (strcmp("bexp", node->name()) == 0) { - oa.exp = (strcmp("true", node->value()) == 0); - oa.isConst = true; - } - return oa; -} diff --git a/OMEdit/OMEditLIB/Animation/AbstractVisualizer.h b/OMEdit/OMEditLIB/Animation/AbstractVisualizer.h deleted file mode 100644 index 3eab5985954..00000000000 --- a/OMEdit/OMEditLIB/Animation/AbstractVisualizer.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * This file is part of OpenModelica. - * - * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), - * c/o Linköpings universitet, Department of Computer and Information Science, - * SE-58183 Linköping, Sweden. - * - * All rights reserved. - * - * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR - * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. - * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES - * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, - * ACCORDING TO RECIPIENTS CHOICE. - * - * The OpenModelica software and the Open Source Modelica - * Consortium (OSMC) Public License (OSMC-PL) are obtained - * from OSMC, either from the above address, - * from the URLs: http://www.ida.liu.se/projects/OpenModelica or - * http://www.openmodelica.org, and in the OpenModelica distribution. - * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. - * - * This program is distributed WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH - * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. - * - * See the full OSMC Public License conditions for more details. - * - */ -/* - * @author Volker Waurich - */ - -#ifndef ABSTRACTVISUALIZER_H -#define ABSTRACTVISUALIZER_H - -#include - -#include "rapidxml.hpp" - -#include -#include -#include - -#include - -enum class VisualizerType {shape, vector, surface}; - -enum class StateSetAction {update, modify}; - -std::string operator+(const std::string& st, const VisualizerType type); - -std::ostream& operator<<(std::ostream& os, const VisualizerType type); - -std::ostream& operator<<(std::ostream& os, const StateSetAction action); - -struct rAndT -{ - rAndT() - : _r(osg::Vec3f()), - _T(osg::Matrix3()) - { - } - osg::Vec3f _r; - osg::Matrix3 _T; -}; - -struct Directions -{ - Directions() - : _lDir(osg::Vec3f()), - _wDir(osg::Vec3f()) - { - } - osg::Vec3f _lDir; - osg::Vec3f _wDir; -}; - -class VisualizerAttribute -{ -public: - VisualizerAttribute(); - VisualizerAttribute(const float value); - virtual ~VisualizerAttribute() = default; - virtual std::string getValueString() const; - virtual void setConstValue(const float value) {isConst = true, exp = value;} -public: - bool isConst; - float exp; - std::string cref; - unsigned int fmuValueRef; -}; - -class AbstractVisualizerObject -{ -public: - AbstractVisualizerObject(const VisualizerType type); - virtual ~AbstractVisualizerObject() = 0; - virtual void dumpVisualizerAttributes() const; - virtual bool isShape() const final {return mVisualizerType == VisualizerType::shape;} - virtual bool isVector() const final {return mVisualizerType == VisualizerType::vector;} - virtual bool isSurface() const final {return mVisualizerType == VisualizerType::surface;} - virtual VisualizerType getVisualizerType() const final {return mVisualizerType;} - virtual StateSetAction getStateSetAction() const final {return mStateSetAction;} - virtual void setStateSetAction(const StateSetAction action) final {mStateSetAction = action;} - virtual std::string getTextureImagePath() const final {return mTextureImagePath;} - virtual void setTextureImagePath(const std::string texture) final {mTextureImagePath = texture;} - virtual float getTransparency() const final {return mTransparency;} - virtual void setTransparency(const float transparency) final {mTransparency = transparency;} - virtual QColor getColor() const {return QColor(_color[0].exp, _color[1].exp, _color[2].exp);} - virtual void setColor(const QColor color) {_color[0].setConstValue(color.red()), - _color[1].setConstValue(color.green()), - _color[2].setConstValue(color.blue());} -private: - VisualizerType mVisualizerType; - StateSetAction mStateSetAction; - std::string mTextureImagePath; - float mTransparency; -public: - std::string _id; - osg::Matrix _mat; - VisualizerAttribute _T[9]; - VisualizerAttribute _r[3]; - VisualizerAttribute _color[3]; - VisualizerAttribute _specCoeff; -}; - -VisualizerAttribute getVisualizerAttributeForNode(const rapidxml::xml_node<>* node); - -#endif diff --git a/OMEdit/OMEditLIB/Animation/AnimationUtil.h b/OMEdit/OMEditLIB/Animation/AnimationUtil.h index 4d9aef5cd29..bb60e9ef0e6 100644 --- a/OMEdit/OMEditLIB/Animation/AnimationUtil.h +++ b/OMEdit/OMEditLIB/Animation/AnimationUtil.h @@ -32,6 +32,7 @@ * @author Volker Waurich */ + #ifndef ANIMATIONUTIL_H #define ANIMATIONUTIL_H @@ -43,6 +44,7 @@ #include #include +#include "Shapes.h" #include "Util/Helper.h" #include "Modeling/MessagesWidget.h" diff --git a/OMEdit/OMEditLIB/Animation/AnimationWindow.cpp b/OMEdit/OMEditLIB/Animation/AnimationWindow.cpp index 98fdb2bc079..f10c3cfe296 100644 --- a/OMEdit/OMEditLIB/Animation/AnimationWindow.cpp +++ b/OMEdit/OMEditLIB/Animation/AnimationWindow.cpp @@ -34,7 +34,7 @@ #include "AnimationWindow.h" #include "Options/OptionsDialog.h" -#include "Visualization.h" +#include "Visualizer.h" #include /*! @@ -56,8 +56,8 @@ AnimationWindow::AnimationWindow(QWidget *pParent) */ AnimationWindow::~AnimationWindow() { - if (mpVisualization) { - delete mpVisualization; + if (mpVisualizer) { + delete mpVisualizer; } } diff --git a/OMEdit/OMEditLIB/Animation/ExtraShapes.h b/OMEdit/OMEditLIB/Animation/ExtraShapes.h index 5c86da80e0a..9775c79742f 100644 --- a/OMEdit/OMEditLIB/Animation/ExtraShapes.h +++ b/OMEdit/OMEditLIB/Animation/ExtraShapes.h @@ -35,7 +35,7 @@ #ifndef EXTRASHAPES_H #define EXTRASHAPES_H -#include "Visualization.h" +#include "Visualizer.h" #include #include @@ -46,15 +46,6 @@ #include #include -// TODO: Support is missing for the following shape types: -// - beam, -// - gearwheel. -// They are currently replaced by a capsule. -// In addition, the extra parameter is not always considered, in particular for cone and cylinder shapes. -// See documentation of Modelica.Mechanics.MultiBody.Visualizers.Advanced.Shape model. -// Also, the spring shape is implemented but has an undesired torsion near the end of each winding, -// and it should be drawn with more facets for a nicer animation. - class Pipecylinder : public osg::Geometry { public: @@ -62,6 +53,7 @@ class Pipecylinder : public osg::Geometry ~Pipecylinder() {}; }; + class Spring : public osg::Geometry { public: diff --git a/OMEdit/OMEditLIB/Animation/FMUSettingsDialog.cpp b/OMEdit/OMEditLIB/Animation/FMUSettingsDialog.cpp index 5cb2aa01069..acc45d73e20 100644 --- a/OMEdit/OMEditLIB/Animation/FMUSettingsDialog.cpp +++ b/OMEdit/OMEditLIB/Animation/FMUSettingsDialog.cpp @@ -43,11 +43,11 @@ /*! * \brief FMUSettingsDialog::FMUSettingsDialog * \param pParent - * \param pVisualizationFMU + * \param pVisualizerFMU */ -FMUSettingsDialog::FMUSettingsDialog(QWidget *pParent, VisualizationFMU* pVisualizationFMU) +FMUSettingsDialog::FMUSettingsDialog(QWidget *pParent, VisualizerFMU* pVisualizerFMU) : QDialog(pParent), - mpVisualizationFMU(pVisualizationFMU), + mpVisualizerFMU(pVisualizerFMU), mStepSize(0.001), mRenderFreq(0.1) { @@ -107,7 +107,7 @@ void FMUSettingsDialog::saveSimSettings() handleEvents = false; }; //store in FMU simulator - mpVisualizationFMU->setSimulationSettings(stepSize, static_cast(mpSolverComboBox->itemData(mpSolverComboBox->currentIndex()).toInt()), + mpVisualizerFMU->setSimulationSettings(stepSize, static_cast(mpSolverComboBox->itemData(mpSolverComboBox->currentIndex()).toInt()), handleEvents); accept(); } diff --git a/OMEdit/OMEditLIB/Animation/FMUSettingsDialog.h b/OMEdit/OMEditLIB/Animation/FMUSettingsDialog.h index ff450542b79..66fd77763bf 100644 --- a/OMEdit/OMEditLIB/Animation/FMUSettingsDialog.h +++ b/OMEdit/OMEditLIB/Animation/FMUSettingsDialog.h @@ -32,10 +32,11 @@ * @author Volker Waurich */ + #ifndef FMU_SETTINGS_WINDOW_H #define FMU_SETTINGS_WINDOW_H -#include "VisualizationFMU.h" +#include "VisualizerFMU.h" #include #include @@ -49,9 +50,9 @@ class FMUSettingsDialog : public QDialog { Q_OBJECT public: - FMUSettingsDialog(QWidget *pParent, VisualizationFMU *pVisualizationFMU); + FMUSettingsDialog(QWidget *pParent, VisualizerFMU *pVisualizerFMU); private: - VisualizationFMU *mpVisualizationFMU; + VisualizerFMU *mpVisualizerFMU; double mStepSize; double mRenderFreq; bool mHandleEvents; diff --git a/OMEdit/OMEditLIB/Animation/FMUWrapper.cpp b/OMEdit/OMEditLIB/Animation/FMUWrapper.cpp index 818d2b2554b..c61e3f3cb35 100644 --- a/OMEdit/OMEditLIB/Animation/FMUWrapper.cpp +++ b/OMEdit/OMEditLIB/Animation/FMUWrapper.cpp @@ -32,6 +32,7 @@ * @author Volker Waurich */ + #include "FMUWrapper.h" #include "Modeling/MessagesWidget.h" #include "Util/Helper.h" diff --git a/OMEdit/OMEditLIB/Animation/FMUWrapper.h b/OMEdit/OMEditLIB/Animation/FMUWrapper.h index 1035504f54b..6d9a5860f7c 100644 --- a/OMEdit/OMEditLIB/Animation/FMUWrapper.h +++ b/OMEdit/OMEditLIB/Animation/FMUWrapper.h @@ -32,6 +32,7 @@ * @author Volker Waurich */ + #ifndef FMUWRAPPER_H #define FMUWRAPPER_H diff --git a/OMEdit/OMEditLIB/Animation/Shape.cpp b/OMEdit/OMEditLIB/Animation/Shape.cpp deleted file mode 100644 index f3722e894a9..00000000000 --- a/OMEdit/OMEditLIB/Animation/Shape.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * This file is part of OpenModelica. - * - * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), - * c/o Linköpings universitet, Department of Computer and Information Science, - * SE-58183 Linköping, Sweden. - * - * All rights reserved. - * - * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR - * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. - * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES - * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, - * ACCORDING TO RECIPIENTS CHOICE. - * - * The OpenModelica software and the Open Source Modelica - * Consortium (OSMC) Public License (OSMC-PL) are obtained - * from OSMC, either from the above address, - * from the URLs: http://www.ida.liu.se/projects/OpenModelica or - * http://www.openmodelica.org, and in the OpenModelica distribution. - * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. - * - * This program is distributed WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH - * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. - * - * See the full OSMC Public License conditions for more details. - * - */ -/* - * @author Volker Waurich - */ - -#include "Shape.h" - -ShapeObject::ShapeObject() - : AbstractVisualizerObject(VisualizerType::shape), - _type(""), - _fileName(""), - _length(VisualizerAttribute(0.1)), - _width(VisualizerAttribute(0.1)), - _height(VisualizerAttribute(0.1)), - _extra(VisualizerAttribute(0.0)) -{ - _rShape[0] = VisualizerAttribute(0.0); - _rShape[1] = VisualizerAttribute(0.0); - _rShape[2] = VisualizerAttribute(0.0); - _lDir[0] = VisualizerAttribute(1.0); - _lDir[1] = VisualizerAttribute(0.0); - _lDir[2] = VisualizerAttribute(0.0); - _wDir[0] = VisualizerAttribute(0.0); - _wDir[1] = VisualizerAttribute(1.0); - _wDir[2] = VisualizerAttribute(0.0); -} - -void ShapeObject::dumpVisualizerAttributes() const -{ - AbstractVisualizerObject::dumpVisualizerAttributes(); - std::cout << "type " << _type << std::endl; - std::cout << "fileName " << _fileName << std::endl; - std::cout << "rShape " << _rShape[0].getValueString() << " , " << _rShape[1].getValueString() << " , " << _rShape[2].getValueString() << std::endl; - std::cout << "lDir " << _lDir[0].getValueString() << " , " << _lDir[1].getValueString() << " , " << _lDir[2].getValueString() << std::endl; - std::cout << "wDir " << _wDir[0].getValueString() << " , " << _wDir[1].getValueString() << " , " << _wDir[2].getValueString() << std::endl; - std::cout << "length " << _length.getValueString() << std::endl; - std::cout << "width " << _width.getValueString() << std::endl; - std::cout << "height " << _height.getValueString() << std::endl; - std::cout << "extra " << _extra.getValueString() << std::endl; -} diff --git a/OMEdit/OMEditLIB/Animation/Shape.h b/OMEdit/OMEditLIB/Animation/Shape.h deleted file mode 100644 index 25f121b9496..00000000000 --- a/OMEdit/OMEditLIB/Animation/Shape.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is part of OpenModelica. - * - * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), - * c/o Linköpings universitet, Department of Computer and Information Science, - * SE-58183 Linköping, Sweden. - * - * All rights reserved. - * - * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR - * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. - * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES - * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, - * ACCORDING TO RECIPIENTS CHOICE. - * - * The OpenModelica software and the Open Source Modelica - * Consortium (OSMC) Public License (OSMC-PL) are obtained - * from OSMC, either from the above address, - * from the URLs: http://www.ida.liu.se/projects/OpenModelica or - * http://www.openmodelica.org, and in the OpenModelica distribution. - * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. - * - * This program is distributed WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH - * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. - * - * See the full OSMC Public License conditions for more details. - * - */ -/* - * @author Volker Waurich - */ - -#ifndef SHAPE_H -#define SHAPE_H - -#include "AbstractVisualizer.h" - -class ShapeObject : public AbstractVisualizerObject -{ -public: - ShapeObject(); - ~ShapeObject() = default; - ShapeObject(const ShapeObject&) = default; - ShapeObject& operator=(const ShapeObject&) = default; - void dumpVisualizerAttributes() const override; -public: - std::string _type; - std::string _fileName; - VisualizerAttribute _rShape[3]; - VisualizerAttribute _lDir[3]; - VisualizerAttribute _wDir[3]; - VisualizerAttribute _length; - VisualizerAttribute _width; - VisualizerAttribute _height; - VisualizerAttribute _extra; -}; - -#endif diff --git a/OMEdit/OMEditLIB/Animation/Shapes.cpp b/OMEdit/OMEditLIB/Animation/Shapes.cpp new file mode 100644 index 00000000000..c05c46d73d8 --- /dev/null +++ b/OMEdit/OMEditLIB/Animation/Shapes.cpp @@ -0,0 +1,164 @@ +/* + * This file is part of OpenModelica. + * + * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), + * c/o Linköpings universitet, Department of Computer and Information Science, + * SE-58183 Linköping, Sweden. + * + * All rights reserved. + * + * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR + * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. + * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES + * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, + * ACCORDING TO RECIPIENTS CHOICE. + * + * The OpenModelica software and the Open Source Modelica + * Consortium (OSMC) Public License (OSMC-PL) are obtained + * from OSMC, either from the above address, + * from the URLs: http://www.ida.liu.se/projects/OpenModelica or + * http://www.openmodelica.org, and in the OpenModelica distribution. + * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. + * + * This program is distributed WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH + * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. + * + * See the full OSMC Public License conditions for more details. + * + */ +/* + * @author Volker Waurich + */ + +#include "Shapes.h" + +ShapeObjectAttribute::ShapeObjectAttribute() + : isConst(true), + exp(0.0), + cref("NONE"), + fmuValueRef(0) +{ +} + +ShapeObjectAttribute::ShapeObjectAttribute(float value) + : isConst(true), + exp(value), + cref("NONE"), + fmuValueRef(0) +{ +} + +std::string ShapeObjectAttribute::getValueString() const +{ + return std::to_string(exp) + " (" + std::to_string(fmuValueRef) + ") " + std::to_string(isConst) + " "; +} + + +ShapeObject::ShapeObject() + : _id("noID"), + _type("box"), + _fileName("noFile"), + _length(ShapeObjectAttribute(0.1)), + _width(ShapeObjectAttribute(0.1)), + _height(ShapeObjectAttribute(0.1)), + _specCoeff(ShapeObjectAttribute(0.7)), + _mat(osg::Matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)), + _extra(ShapeObjectAttribute(0.0)), + mTransparent(0.0), + mTextureImagePath(""), + mStateSetAction(stateSetAction::update) + +{ + _r[0] = ShapeObjectAttribute(0.1); + _r[1] = ShapeObjectAttribute(0.1); + _r[2] = ShapeObjectAttribute(0.1); + _rShape[0] = ShapeObjectAttribute(0.0); + _rShape[1] = ShapeObjectAttribute(0.0); + _rShape[2] = ShapeObjectAttribute(0.0); + _lDir[0] = ShapeObjectAttribute(1.0); + _lDir[1] = ShapeObjectAttribute(0.0); + _lDir[2] = ShapeObjectAttribute(0.0); + _wDir[0] = ShapeObjectAttribute(0.0); + _wDir[1] = ShapeObjectAttribute(1.0); + _wDir[2] = ShapeObjectAttribute(0.0); + _color[0] = ShapeObjectAttribute(255.0); + _color[1] = ShapeObjectAttribute(255.0); + _color[2] = ShapeObjectAttribute(255.0); + _T[0] = ShapeObjectAttribute(0.0); + _T[1] = ShapeObjectAttribute(0.0); + _T[2] = ShapeObjectAttribute(1.0); + _T[3] = ShapeObjectAttribute(1.0); + _T[4] = ShapeObjectAttribute(0.0); + _T[5] = ShapeObjectAttribute(0.0); + _T[6] = ShapeObjectAttribute(0.0); + _T[7] = ShapeObjectAttribute(1.0); + _T[8] = ShapeObjectAttribute(0.0); +} + +void ShapeObject::dumpVisAttributes() const +{ + std::cout << "id " << _id << std::endl; + std::cout << "type " << _type << std::endl; + std::cout << "fileName " << _fileName << std::endl; + std::cout << "length " << _length.getValueString() << std::endl; + std::cout << "width " << _width.getValueString() << std::endl; + std::cout << "height " << _height.getValueString() << std::endl; + std::cout << "lDir " << _lDir[0].getValueString() << ", " << _lDir[1].getValueString() << ", " << _lDir[2].getValueString() << ", " << std::endl; + std::cout << "wDir " << _wDir[0].getValueString() << ", " << _wDir[1].getValueString() << ", " << _wDir[2].getValueString() << ", " << std::endl; + std::cout << "r " << _r[0].getValueString() << ", " << _r[1].getValueString() << ", " << _r[2].getValueString() << ", " << std::endl; + std::cout << "r_shape " << _rShape[0].getValueString() << ", " << _rShape[1].getValueString() << ", " << _rShape[2].getValueString() << ", " << std::endl; + std::cout << "T0 " << _T[0].getValueString() << ", " << _T[1].getValueString() << ", " << _T[2].getValueString() << ", " << std::endl; + std::cout << " " << _T[3].getValueString() << ", " << _T[4].getValueString() << ", " << _T[5].getValueString() << ", " << std::endl; + std::cout << " " << _T[6].getValueString() << ", " << _T[7].getValueString() << ", " << _T[8].getValueString() << ", " << std::endl; + std::cout << "color " << _color[0].getValueString() << ", " << _color[1].getValueString() << ", " << _color[2].getValueString() << ", " << std::endl; + std::cout << "mat " << _mat(0, 0) << ", " << _mat(0, 1) << ", " << _mat(0, 2) << ", " << _mat(0, 3) << std::endl; + std::cout << " " << _mat(1, 0) << ", " << _mat(1, 1) << ", " << _mat(1, 2) << ", " << _mat(1, 3) << std::endl; + std::cout << " " << _mat(2, 0) << ", " << _mat(2, 1) << ", " << _mat(2, 2) << ", " << _mat(2, 3) << std::endl; + std::cout << " " << _mat(3, 0) << ", " << _mat(3, 1) << ", " << _mat(3, 2) << ", " << _mat(3, 3) << std::endl; + std::cout << "extra " << _extra.getValueString() << std::endl; + std::cout << "transparency " << mTransparent << std::endl; + +} + +/* +double getShapeAttrFMU(const char* attr, rapidxml::xml_node<>* node, double time, fmi1_import_t* fmu) +{ + rapidxml::xml_node<>* expNode = node->first_node(attr)->first_node(); + return evaluateExpressionFMU(expNode, time, fmu); +} +*/ +ShapeObjectAttribute getObjectAttributeForNode(const rapidxml::xml_node<>* node) +{ + ShapeObjectAttribute oa; + if (strcmp("exp", node->name()) == 0) + { + oa.exp = std::strtod(node->value(), nullptr); + oa.cref = "NONE"; + oa.isConst = true; + } + else if (strcmp("cref", node->name()) == 0) + { + char* cref = node->value(); + oa.cref = std::string(cref); + oa.exp = -1.0; + oa.isConst = false; + } + return oa; +} + + +unsigned int numShapes(rapidxml::xml_node<>* rootNode) +{ + unsigned int num = 0; + + if (NULL == rootNode->first_node("shape")) + return num; + else + for (rapidxml::xml_node<>* shapeNode = rootNode->first_node("shape"); shapeNode; shapeNode = shapeNode->next_sibling()) + ++num; + + return num; +} + diff --git a/OMEdit/OMEditLIB/Animation/Shapes.h b/OMEdit/OMEditLIB/Animation/Shapes.h new file mode 100644 index 00000000000..b2ad29fcaf2 --- /dev/null +++ b/OMEdit/OMEditLIB/Animation/Shapes.h @@ -0,0 +1,133 @@ +/* + * This file is part of OpenModelica. + * + * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), + * c/o Linköpings universitet, Department of Computer and Information Science, + * SE-58183 Linköping, Sweden. + * + * All rights reserved. + * + * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR + * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. + * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES + * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, + * ACCORDING TO RECIPIENTS CHOICE. + * + * The OpenModelica software and the Open Source Modelica + * Consortium (OSMC) Public License (OSMC-PL) are obtained + * from OSMC, either from the above address, + * from the URLs: http://www.ida.liu.se/projects/OpenModelica or + * http://www.openmodelica.org, and in the OpenModelica distribution. + * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. + * + * This program is distributed WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH + * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. + * + * See the full OSMC Public License conditions for more details. + * + */ +/* + * @author Volker Waurich + */ +#ifndef SHAPES_H +#define SHAPES_H + +#include + +#include "util/read_matlab4.h" +#include "util/read_csv.h" +#include "rapidxml.hpp" +#include +#include +#include + +#include + +class ShapeObjectAttribute +{ + public: + ShapeObjectAttribute(); + ShapeObjectAttribute(float value); + ~ShapeObjectAttribute() = default; + std::string getValueString() const; + void setConstValue(float e){exp=e, isConst=true;} + public: + bool isConst; + float exp; + std::string cref; + unsigned int fmuValueRef; +}; + +enum class stateSetAction {update, modify}; + +class ShapeObject +{ + public: + ShapeObject(); + ~ShapeObject() = default; + ShapeObject(const ShapeObject&) = default; + ShapeObject& operator=(const ShapeObject&) = default; + void dumpVisAttributes() const; + void setTransparency(float transp) {mTransparent = transp;} + float getTransparency() {return mTransparent;} + void setTextureImagePath(std::string imagePath) {mTextureImagePath = imagePath;} + std::string getTextureImagePath() {return mTextureImagePath;} + void setColor(QColor col) {_color[0].setConstValue(col.red()); + _color[1].setConstValue(col.green()); + _color[2].setConstValue(col.blue());} + QColor getColor() {return QColor(_color[0].exp, _color[1].exp, _color[2].exp);} + void setStateSetAction(stateSetAction action) {mStateSetAction = action;} + stateSetAction getStateSetAction() {return mStateSetAction;} + public: + std::string _id; + std::string _type; + std::string _fileName; + ShapeObjectAttribute _length; + ShapeObjectAttribute _width; + ShapeObjectAttribute _height; + ShapeObjectAttribute _r[3]; + ShapeObjectAttribute _rShape[3]; + ShapeObjectAttribute _lDir[3]; + ShapeObjectAttribute _wDir[3]; + ShapeObjectAttribute _color[3]; + ShapeObjectAttribute _T[9]; + ShapeObjectAttribute _specCoeff; + osg::Matrix _mat; + ShapeObjectAttribute _extra; +private: + float mTransparent; + std::string mTextureImagePath; + stateSetAction mStateSetAction; +}; + +struct rAndT +{ + rAndT() + : _r(osg::Vec3f()), + _T(osg::Matrix3()) + { + } + osg::Vec3f _r; + osg::Matrix3 _T; +}; + +struct Directions +{ + Directions() + : _lDir(osg::Vec3f()), + _wDir(osg::Vec3f()) + { + } + osg::Vec3f _lDir; + osg::Vec3f _wDir; +}; + +ShapeObjectAttribute getObjectAttributeForNode(const rapidxml::xml_node<>* node); +//double getShapeAttrFMU(const char* attr, rapidxml::xml_node<>* node, double time/*, fmi1_import_t* fmu*/); +unsigned int numShapes(rapidxml::xml_node<>* rootNode); + + + +#endif diff --git a/OMEdit/OMEditLIB/Animation/ThreeDViewer.cpp b/OMEdit/OMEditLIB/Animation/ThreeDViewer.cpp index 035160c8e51..57a73ff96ba 100644 --- a/OMEdit/OMEditLIB/Animation/ThreeDViewer.cpp +++ b/OMEdit/OMEditLIB/Animation/ThreeDViewer.cpp @@ -32,7 +32,7 @@ */ #include "ThreeDViewer.h" -#include "Visualization.h" +#include "Visualizer.h" /*! * \class ThreeDViewer @@ -53,8 +53,8 @@ ThreeDViewer::ThreeDViewer(QWidget *pParent) */ ThreeDViewer::~ThreeDViewer() { - if (mpVisualization) { - delete mpVisualization; + if (mpVisualizer) { + delete mpVisualizer; } } diff --git a/OMEdit/OMEditLIB/Animation/Vector.cpp b/OMEdit/OMEditLIB/Animation/Vector.cpp deleted file mode 100644 index accaadd154c..00000000000 --- a/OMEdit/OMEditLIB/Animation/Vector.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * This file is part of OpenModelica. - * - * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), - * c/o Linköpings universitet, Department of Computer and Information Science, - * SE-58183 Linköping, Sweden. - * - * All rights reserved. - * - * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR - * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. - * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES - * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, - * ACCORDING TO RECIPIENTS CHOICE. - * - * The OpenModelica software and the Open Source Modelica - * Consortium (OSMC) Public License (OSMC-PL) are obtained - * from OSMC, either from the above address, - * from the URLs: http://www.ida.liu.se/projects/OpenModelica or - * http://www.openmodelica.org, and in the OpenModelica distribution. - * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. - * - * This program is distributed WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH - * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. - * - * See the full OSMC Public License conditions for more details. - * - */ - -#include "Vector.h" - -#include - -std::ostream& operator<<(std::ostream& os, const VectorQuantity quantity) -{ - switch (quantity) - { - case VectorQuantity::force: - return os << "force"; - case VectorQuantity::torque: - return os << "torque"; - case VectorQuantity::velocity: - return os << "velocity"; - case VectorQuantity::acceleration: - return os << "acceleration"; - case VectorQuantity::angularVelocity: - return os << "angular velocity"; - case VectorQuantity::angularAcceleration: - return os << "angular acceleration"; - case VectorQuantity::relativePosition: - return os << "relative position"; - default: - return os; - } -} - -VectorObject::VectorObject() - : AbstractVisualizerObject(VisualizerType::vector), - _quantity(VisualizerAttribute(0.0)), - _headAtOrigin(VisualizerAttribute(0.0)), - _twoHeadedArrow(VisualizerAttribute(0.0)) -{ - _coords[0] = VisualizerAttribute(1.0); - _coords[1] = VisualizerAttribute(0.0); - _coords[2] = VisualizerAttribute(0.0); -} - -void VectorObject::dumpVisualizerAttributes() const -{ - AbstractVisualizerObject::dumpVisualizerAttributes(); - std::cout << "coords " << _coords[0].getValueString() << " , " << _coords[1].getValueString() << " , " << _coords[2].getValueString() << std::endl; - std::cout << "quantity " << _quantity.getValueString() << " = " << getQuantity() << std::endl; - std::cout << "headAtOrigin " << _headAtOrigin.getValueString() << " = " << (hasHeadAtOrigin() ? "true" : "false") << std::endl; - std::cout << "twoHeadedArrow " << _twoHeadedArrow.getValueString() << " = " << (isTwoHeadedArrow() ? "true" : "false") << std::endl; -} - -float VectorObject::getScale() const -{ - switch (getQuantity()) - { - case VectorQuantity::force: - return kScaleForce; - case VectorQuantity::torque: - return kScaleTorque; - default: - return 1; - } -} - -float VectorObject::getLength() const -{ - return std::sqrt(std::pow(_coords[0].exp, 2) + std::pow(_coords[1].exp, 2) + std::pow(_coords[2].exp, 2)) / getScale(); -} diff --git a/OMEdit/OMEditLIB/Animation/Vector.h b/OMEdit/OMEditLIB/Animation/Vector.h deleted file mode 100644 index c939c0ad686..00000000000 --- a/OMEdit/OMEditLIB/Animation/Vector.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of OpenModelica. - * - * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), - * c/o Linköpings universitet, Department of Computer and Information Science, - * SE-58183 Linköping, Sweden. - * - * All rights reserved. - * - * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR - * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. - * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES - * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, - * ACCORDING TO RECIPIENTS CHOICE. - * - * The OpenModelica software and the Open Source Modelica - * Consortium (OSMC) Public License (OSMC-PL) are obtained - * from OSMC, either from the above address, - * from the URLs: http://www.ida.liu.se/projects/OpenModelica or - * http://www.openmodelica.org, and in the OpenModelica distribution. - * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. - * - * This program is distributed WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH - * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. - * - * See the full OSMC Public License conditions for more details. - * - */ - -#ifndef VECTOR_H -#define VECTOR_H - -#include "AbstractVisualizer.h" - -/*! Equivalent to Modelica.Mechanics.MultiBody.Types.VectorQuantity */ -enum class VectorQuantity {force = 1, torque, velocity, acceleration, angularVelocity, angularAcceleration, relativePosition}; - -std::ostream& operator<<(std::ostream& os, const VectorQuantity quantity); - -class VectorObject : public AbstractVisualizerObject -{ -public: - VectorObject(); - ~VectorObject() = default; - VectorObject(const VectorObject&) = default; - VectorObject& operator=(const VectorObject&) = default; - void dumpVisualizerAttributes() const override; - float getScale() const; - float getLength() const; - float getRadius() const {return kRadius;} - float getHeadLength() const {return kHeadLength;} - float getHeadRadius() const {return kHeadRadius;} - VectorQuantity getQuantity() const {return static_cast(_quantity.exp);} - bool hasHeadAtOrigin() const {return _headAtOrigin.exp;} - bool isTwoHeadedArrow() const {return _twoHeadedArrow.exp;} -private: - const float kRadius = 0.0125; //!< Modelica.Mechanics.MultiBody.World.defaultArrowDiameter / 2 = 1 / 40 / 2 = 0.0125 - const float kHeadLength = 0.1000; //!< Modelica.Mechanics.MultiBody.Types.Defaults.ArrowHeadLengthFraction * (2 * kRadius) = 4 * 0.025 = 0.1000 - const float kHeadRadius = 0.0375; //!< Modelica.Mechanics.MultiBody.Types.Defaults.ArrowHeadWidthFraction * (2 * kRadius) / 2 = 3 * 0.025 / 2 = 0.0375 - const float kScaleForce = 1200; //!< Modelica.Mechanics.MultiBody.Examples.Elementary.ForceAndTorque.world.defaultN_to_m = 1200 - const float kScaleTorque = 120; //!< Modelica.Mechanics.MultiBody.Examples.Elementary.ForceAndTorque.world.defaultNm_to_m = 120 -public: - VisualizerAttribute _coords[3]; - VisualizerAttribute _quantity; - VisualizerAttribute _headAtOrigin; - VisualizerAttribute _twoHeadedArrow; -}; - -#endif diff --git a/OMEdit/OMEditLIB/Animation/ViewerWidget.cpp b/OMEdit/OMEditLIB/Animation/ViewerWidget.cpp index 8781ba3e24a..ca71fa122fc 100644 --- a/OMEdit/OMEditLIB/Animation/ViewerWidget.cpp +++ b/OMEdit/OMEditLIB/Animation/ViewerWidget.cpp @@ -36,7 +36,6 @@ #include #include -#include #include #include #include @@ -72,6 +71,7 @@ void Viewer::setUpThreading() */ ViewerWidget::ViewerWidget(QWidget* parent, Qt::WindowFlags flags) : GLWidget(parent, flags) + { // Set the number of samples used for multisampling #if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)) @@ -211,8 +211,8 @@ void ViewerWidget::mousePressEvent(QMouseEvent *event) button = 3; if (event->modifiers() == Qt::ShiftModifier) { //qt counts pixels from upper left corner and osg from bottom left corner - pickVisualizer(event->x(), this->height() - event->y()); - showVisualizerPickContextMenu(event->pos()); + pickShape(event->x(), this->height() - event->y()); + showShapePickContextMenu(event->pos()); return; } break; @@ -224,259 +224,247 @@ void ViewerWidget::mousePressEvent(QMouseEvent *event) } /*! - * \brief ViewerWidget::pickVisualizer - * Picks the name of the selected visualizer in the osg view + * \brief ViewerWidget::pickShape + * Picks the name of the selected shape in the osg view * \param x - mouse position pixel in x direction in osg system * \param y - mouse position pixel in y direction in osg system */ -void ViewerWidget::pickVisualizer(int x, int y) +void ViewerWidget::pickShape(int x, int y) { - //std::cout<<"pickVisualizer "<computeIntersections(mpSceneView->getCamera(), osgUtil::Intersector::WINDOW, x, y, intersections)) { + if (mpSceneView->computeIntersections(mpSceneView->getCamera(),osgUtil::Intersector::WINDOW , x, y, intersections)) { //take the first intersection with a facette only - osgUtil::LineSegmentIntersector::Intersections::const_iterator hitr = intersections.cbegin(); + osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin(); - if (!hitr->nodePath.empty() && !hitr->nodePath.back()->getName().empty()) { - mSelectedVisualizer = hitr->nodePath.back()->getName(); - //std::cout<<"Object identified by name "<nodePath.empty() && !(hitr->nodePath.back()->getName().empty())) { + mSelectedShape = hitr->nodePath.back()->getName(); + //std::cout<<"Object identified by name "<drawable.valid()) { - mSelectedVisualizer = hitr->drawable->className(); - //std::cout<<"Object identified by its drawable "<drawable->className(); + //std::cout<<"Object identified by its drawable "<getVisualization()->getBaseData()->getVisualizerObjectByID(mSelectedVisualizer))) { - action2.setText(tr((std::string("Make ") + visualizer->getVisualizerType() + " Invisible").c_str())); - contextMenu.addMenu(&visualizerMenu); + //if a shape is picked, we can set it transparent + if (0 != QString::compare(name,QString(""))) { + contextMenu.addMenu(&shapeMenu); + shapeMenu.addAction( &action1); + shapeMenu.addAction( &action2); + shapeMenu.addSeparator(); + shapeMenu.addAction( &action3); + shapeMenu.addSeparator(); + shapeMenu.addAction( &action4); + shapeMenu.addAction( &action5); + shapeMenu.addAction( &action6); + shapeMenu.addSeparator(); + connect(&action1, SIGNAL(triggered()), this, SLOT(changeShapeTransparency())); + connect(&action2, SIGNAL(triggered()), this, SLOT(makeShapeInvisible())); + connect(&action3, SIGNAL(triggered()), this, SLOT(changeShapeColor())); + connect(&action4, SIGNAL(triggered()), this, SLOT(applyCheckTexture())); + connect(&action5, SIGNAL(triggered()), this, SLOT(applyCustomTexture())); + connect(&action6, SIGNAL(triggered()), this, SLOT(removeTexture())); } - contextMenu.addAction(&action0); - visualizerMenu.addAction(&action1); - visualizerMenu.addAction(&action2); - visualizerMenu.addSeparator(); - visualizerMenu.addAction(&action3); - visualizerMenu.addSeparator(); - visualizerMenu.addAction(&action4); - visualizerMenu.addAction(&action5); - visualizerMenu.addAction(&action6); - + connect(&action0, SIGNAL(triggered()), this, SLOT(removeTransparencyForAllShapes())); contextMenu.exec(this->mapToGlobal(pos)); } /*! - * \brief ViewerWidget::changeVisualizerTransparency - * changes the transparency selection of a visualizer + * \brief ViewerWidget::applyCheckTexture + * adds a checkered texture to the shape */ -void ViewerWidget::changeVisualizerTransparency() +void ViewerWidget::applyCheckTexture() { - AbstractVisualizerObject* visualizer = nullptr; - if ((visualizer = mpAnimationWidget->getVisualization()->getBaseData()->getVisualizerObjectByID(mSelectedVisualizer))) { - if (visualizer->isShape()) { - ShapeObject* shape = static_cast(visualizer); - if (shape->_type.compare("dxf") == 0) { - QString msg = tr("Transparency is not applicable for DXF-Files."); - MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, - Helper::scriptingKind, Helper::notificationLevel)); - mSelectedVisualizer = ""; - return; + ShapeObject* shape = nullptr; + if ((shape = mpAnimationWidget->getVisualizer()->getBaseData()->getShapeObjectByID(mSelectedShape))) + { + if (shape->_type.compare("dxf") == 0 or shape->_type.compare("stl") == 0) + { + QString msg = tr("Texture feature for CAD-Files is not applicable."); + MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, Helper::scriptingKind, + Helper::notificationLevel)); + } + else + { + shape->setTextureImagePath(":/Resources/bitmaps/check.png"); + mpAnimationWidget->getVisualizer()->modifyShape(mSelectedShape); + mSelectedShape = ""; } } - bool ok; - const int min = 0, max = 100, step = 1; // Unit: [%] - const int currentTransparency = visualizer->getTransparency() * (max - min) + min; - const int transparency = QInputDialog::getInt(this, Helper::chooseTransparency, Helper::percentageLabel, - currentTransparency, min, max, step, &ok); - if (ok) { // Picked transparency is not OK if the user cancels the dialog - visualizer->setTransparency((float) (transparency - min) / (max - min)); - mpAnimationWidget->getVisualization()->modifyVisualizer(mSelectedVisualizer); - } - mSelectedVisualizer = ""; - } } /*! - * \brief ViewerWidget::makeVisualizerInvisible - * suppresses the visualization of this visualizer + * \brief ViewerWidget::removeTexture + * removes the texture of the shape */ -void ViewerWidget::makeVisualizerInvisible() +void ViewerWidget::removeTexture() { - AbstractVisualizerObject* visualizer = nullptr; - if ((visualizer = mpAnimationWidget->getVisualization()->getBaseData()->getVisualizerObjectByID(mSelectedVisualizer))) { - if (visualizer->isShape()) { - ShapeObject* shape = static_cast(visualizer); - if (shape->_type.compare("dxf") == 0) { - QString msg = tr("Invisibility is not applicable for DXF-Files."); - MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, - Helper::scriptingKind, Helper::notificationLevel)); - mSelectedVisualizer = ""; - return; + ShapeObject* shape = nullptr; + if ((shape = mpAnimationWidget->getVisualizer()->getBaseData()->getShapeObjectByID(mSelectedShape))) + { + if (shape->_type.compare("dxf") == 0 or shape->_type.compare("stl") == 0) + { + QString msg = tr("Texture feature for CAD-Files is not applicable."); + MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, Helper::scriptingKind, + Helper::notificationLevel)); + } + else + { + shape->setTextureImagePath(""); + mpAnimationWidget->getVisualizer()->modifyShape(mSelectedShape); + mSelectedShape = ""; } } - visualizer->setTransparency(1.0); - mpAnimationWidget->getVisualization()->modifyVisualizer(mSelectedVisualizer); - mSelectedVisualizer = ""; - } } + /*! - * \brief ViewerWidget::changeVisualizerColor - * opens a color dialog and selects a new color for the visualizer + * \brief ViewerWidget::applyCustomTexture + * adds a user-defiend texture to the shape */ -void ViewerWidget::changeVisualizerColor() +void ViewerWidget::applyCustomTexture() { - AbstractVisualizerObject* visualizer = nullptr; - if ((visualizer = mpAnimationWidget->getVisualization()->getBaseData()->getVisualizerObjectByID(mSelectedVisualizer))) { - if (visualizer->isShape()) { - ShapeObject* shape = static_cast(visualizer); - if (shape->_type.compare("dxf") == 0) { - QString msg = tr("Changing the color is not applicable for DXF-Files."); - MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, - Helper::scriptingKind, Helper::notificationLevel)); - mSelectedVisualizer = ""; - return; + ShapeObject* shape = nullptr; + if ((shape = mpAnimationWidget->getVisualizer()->getBaseData()->getShapeObjectByID(mSelectedShape))) + { + if (shape->_type.compare("dxf") == 0 or shape->_type.compare("stl") == 0) + { + QString msg = tr("Texture feature for CAD-Files is not applicable."); + MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, Helper::scriptingKind, + Helper::notificationLevel)); + } + else + { + QString fileName = StringHandler::getOpenFileName(this, QString("%1 - %2").arg(Helper::applicationName).arg(Helper::chooseFile), + NULL, Helper::bitmapFileTypes, NULL); + if(fileName.compare("")) + { + shape->setTextureImagePath(fileName.toStdString()); + mpAnimationWidget->getVisualizer()->modifyShape(mSelectedShape); + mSelectedShape = ""; + } } } - const QColor currentColor = visualizer->getColor(); - const QColor color = QColorDialog::getColor(currentColor, this, Helper::chooseColor); - if (color.isValid()) { // Picked color is invalid if the user cancels the dialog - visualizer->setColor(color); - mpAnimationWidget->getVisualization()->modifyVisualizer(mSelectedVisualizer); - } - mSelectedVisualizer = ""; - } } /*! - * \brief ViewerWidget::applyCheckerTexture - * adds a checkered texture to the visualizer + * \brief ViewerWidget::changeShapeTransparency + * changes the transparency selection of a shape */ -void ViewerWidget::applyCheckerTexture() +void ViewerWidget::changeShapeTransparency() { - AbstractVisualizerObject* visualizer = nullptr; - if ((visualizer = mpAnimationWidget->getVisualization()->getBaseData()->getVisualizerObjectByID(mSelectedVisualizer))) { - if (visualizer->isShape()) { - ShapeObject* shape = static_cast(visualizer); - if (shape->_type.compare("dxf") == 0 or shape->_type.compare("stl") == 0) { - QString msg = tr("Texture feature is not applicable for CAD-Files."); - MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, - Helper::scriptingKind, Helper::notificationLevel)); - mSelectedVisualizer = ""; - return; + ShapeObject* shape = nullptr; + if ((shape = mpAnimationWidget->getVisualizer()->getBaseData()->getShapeObjectByID(mSelectedShape))) { + if (shape->_type.compare("dxf") == 0) { + QString msg = tr("Transparency is not applicable for DXF-Files."); + MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, Helper::scriptingKind, + Helper::notificationLevel)); + mSelectedShape = ""; + } else { + if (shape->getTransparency() == 0) { + shape->setTransparency(0.5); + } else { + shape->setTransparency(0.0); } + mpAnimationWidget->getVisualizer()->modifyShape(mSelectedShape); + mSelectedShape = ""; } - visualizer->setTextureImagePath(":/Resources/bitmaps/check.png"); - mpAnimationWidget->getVisualization()->modifyVisualizer(mSelectedVisualizer); - mSelectedVisualizer = ""; } } /*! - * \brief ViewerWidget::applyCustomTexture - * adds a user-defined texture to the visualizer + * \brief ViewerWidget::makeShapeInvisible + * suppresses the visualization of this shape */ -void ViewerWidget::applyCustomTexture() +void ViewerWidget::makeShapeInvisible() { - AbstractVisualizerObject* visualizer = nullptr; - if ((visualizer = mpAnimationWidget->getVisualization()->getBaseData()->getVisualizerObjectByID(mSelectedVisualizer))) { - if (visualizer->isShape()) { - ShapeObject* shape = static_cast(visualizer); - if (shape->_type.compare("dxf") == 0 or shape->_type.compare("stl") == 0) { - QString msg = tr("Texture feature is not applicable for CAD-Files."); - MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, - Helper::scriptingKind, Helper::notificationLevel)); - mSelectedVisualizer = ""; - return; - } - } - const QString* currentFileName = nullptr; // File picker starts at the last open directory if any, otherwise the user's home directory - const QString fileName = StringHandler::getOpenFileName(this, QString("%1 – %2").arg(Helper::applicationName).arg(Helper::chooseFile), - (QString*) currentFileName, Helper::bitmapFileTypes, nullptr); - if (!fileName.isEmpty()) { // Picked file name is empty if the user cancels the dialog - visualizer->setTextureImagePath(fileName.toStdString()); - mpAnimationWidget->getVisualization()->modifyVisualizer(mSelectedVisualizer); + ShapeObject* shape = nullptr; + if ((shape = mpAnimationWidget->getVisualizer()->getBaseData()->getShapeObjectByID(mSelectedShape))) { + if (shape->_type.compare("dxf") == 0) { + QString msg = tr("Invisibility is not applicable for DXF-Files."); + MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, Helper::scriptingKind, + Helper::notificationLevel)); + mSelectedShape = ""; + } else { + shape->setTransparency(1.0); + mpAnimationWidget->getVisualizer()->modifyShape(mSelectedShape); + mSelectedShape = ""; } - mSelectedVisualizer = ""; } } /*! - * \brief ViewerWidget::removeTexture - * removes the texture of the visualizer + * \brief ViewerWidget::changeShapeColor + * opens a color dialog and selects a new color for the shape */ -void ViewerWidget::removeTexture() +void ViewerWidget::changeShapeColor() { - AbstractVisualizerObject* visualizer = nullptr; - if ((visualizer = mpAnimationWidget->getVisualization()->getBaseData()->getVisualizerObjectByID(mSelectedVisualizer))) { - if (visualizer->isShape()) { - ShapeObject* shape = static_cast(visualizer); - if (shape->_type.compare("dxf") == 0 or shape->_type.compare("stl") == 0) { - QString msg = tr("Texture feature is not applicable for CAD-Files."); - MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, - Helper::scriptingKind, Helper::notificationLevel)); - mSelectedVisualizer = ""; - return; + ShapeObject* shape = nullptr; + if ((shape = mpAnimationWidget->getVisualizer()->getBaseData()->getShapeObjectByID(mSelectedShape))) { + if (shape->_type.compare("dxf") == 0) + { + QString msg = tr("Changing the color is not applicable for DXF-Files."); + MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, Helper::scriptingKind, + Helper::notificationLevel)); + mSelectedShape = ""; + } + else + { + QColor currentColor = shape->getColor(); + QColor color = QColorDialog::getColor(currentColor, this,"Shape Color"); + if(color.isValid()) + { + shape->setColor(color); + } + else + { + QString msg = tr("The selected color is not valid."); + MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, msg, Helper::scriptingKind, + Helper::notificationLevel)); } + mpAnimationWidget->getVisualizer()->modifyShape(mSelectedShape); + mSelectedShape = ""; } - visualizer->setTextureImagePath(""); - mpAnimationWidget->getVisualization()->modifyVisualizer(mSelectedVisualizer); - mSelectedVisualizer = ""; } } /*! - * \brief ViewerWidget::resetTransparencyAndTextureForAllVisualizers - * sets all transparency and texture settings back to default + * \brief ViewerWidget::removeTransparancyForAllShapes + * sets all transparency settings back to default (nothing is transparent) + * */ -void ViewerWidget::resetTransparencyAndTextureForAllVisualizers() +void ViewerWidget::removeTransparencyForAllShapes() { - std::vector& shapes = mpAnimationWidget->getVisualization()->getBaseData()->_shapes; - std::vector& vectors = mpAnimationWidget->getVisualization()->getBaseData()->_vectors; - std::vector> visualizers; - visualizers.reserve(shapes.size() + vectors.size()); - for (ShapeObject& shape : shapes) { - visualizers.push_back(shape); - } - for (VectorObject& vector : vectors) { - visualizers.push_back(vector); - } - for (AbstractVisualizerObject& visualizer : visualizers) { - visualizer.setTransparency(0.0); - visualizer.setTextureImagePath(""); - mpAnimationWidget->getVisualization()->modifyVisualizer(visualizer._id); + if (mpAnimationWidget->getVisualizer() != NULL) { + std::vector* shapes = nullptr; + shapes = &mpAnimationWidget->getVisualizer()->getBaseData()->_shapes; + for (std::vector::iterator shape = shapes->begin() ; shape < shapes->end(); ++shape) { + shape->setTransparency(0.0); + shape->setTextureImagePath(""); + mpAnimationWidget->getVisualizer()->modifyShape(shape->_id); + } } } @@ -500,7 +488,7 @@ void ViewerWidget::mouseReleaseEvent(QMouseEvent *event) break; case Qt::RightButton: button = 3; - mSelectedVisualizer = ""; + mSelectedShape = ""; break; default: break; @@ -549,7 +537,7 @@ bool ViewerWidget::event(QEvent *event) // This ensures that the OSG widget is always going to be repainted after the // user performed some interaction. Doing this in the event handler ensures // that we don't forget about some event and prevents duplicate code. - switch (event->type()) { + switch(event->type()) { case QEvent::KeyPress: case QEvent::KeyRelease: case QEvent::MouseButtonDblClick: diff --git a/OMEdit/OMEditLIB/Animation/ViewerWidget.h b/OMEdit/OMEditLIB/Animation/ViewerWidget.h index be1918df1b7..25d36a620a8 100644 --- a/OMEdit/OMEditLIB/Animation/ViewerWidget.h +++ b/OMEdit/OMEditLIB/Animation/ViewerWidget.h @@ -38,9 +38,9 @@ #include #include -#include +#include -#include +#include #include "AbstractAnimationWindow.h" #include "Util/Helper.h" @@ -73,9 +73,9 @@ class ViewerWidget : public GLWidget public: ViewerWidget(QWidget *pParent = 0, Qt::WindowFlags flags = Qt::WindowFlags()); osgViewer::View* getSceneView() {return mpSceneView;} - std::string getSelectedVisualizer() {return mSelectedVisualizer;} - void setSelectedVisualizer(std::string visualizer) {mSelectedVisualizer = visualizer;} - void pickVisualizer(int x, int y); + std::string getSelectedShape() {return mSelectedShape;} + void setSelectedShape(std::string shape) {mSelectedShape = shape;} + void pickShape(int x, int y); protected: virtual void paintEvent(QPaintEvent *paintEvent) override; virtual void paintGL() override; @@ -87,22 +87,23 @@ class ViewerWidget : public GLWidget virtual void mouseReleaseEvent(QMouseEvent *event) override; virtual void wheelEvent(QWheelEvent *event) override; virtual bool event(QEvent* event) override; - void showVisualizerPickContextMenu(const QPoint& pos); + void showShapePickContextMenu(const QPoint& pos); private: osgGA::EventQueue* getEventQueue() const; osg::ref_ptr mpGraphicsWindow; osg::ref_ptr mpViewer; osgViewer::View* mpSceneView; - std::string mSelectedVisualizer; + std::string mSelectedShape; AbstractAnimationWindow *mpAnimationWidget; public slots: - void changeVisualizerTransparency(); - void makeVisualizerInvisible(); - void changeVisualizerColor(); - void applyCheckerTexture(); + void changeShapeTransparency(); + void removeTransparencyForAllShapes(); + void makeShapeInvisible(); + void applyCheckTexture(); void applyCustomTexture(); void removeTexture(); - void resetTransparencyAndTextureForAllVisualizers(); + void changeShapeColor(); + }; -#endif +#endif // VIEWERWIDGET_H diff --git a/OMEdit/OMEditLIB/Animation/Visualization.cpp b/OMEdit/OMEditLIB/Animation/Visualization.cpp deleted file mode 100644 index 01d0a9bf882..00000000000 --- a/OMEdit/OMEditLIB/Animation/Visualization.cpp +++ /dev/null @@ -1,1065 +0,0 @@ -/* - * This file is part of OpenModelica. - * - * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), - * c/o Linköpings universitet, Department of Computer and Information Science, - * SE-58183 Linköping, Sweden. - * - * All rights reserved. - * - * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR - * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. - * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES - * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, - * ACCORDING TO RECIPIENTS CHOICE. - * - * The OpenModelica software and the Open Source Modelica - * Consortium (OSMC) Public License (OSMC-PL) are obtained - * from OSMC, either from the above address, - * from the URLs: http://www.ida.liu.se/projects/OpenModelica or - * http://www.openmodelica.org, and in the OpenModelica distribution. - * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. - * - * This program is distributed WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH - * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. - * - * See the full OSMC Public License conditions for more details. - * - */ -/* - * @author Volker Waurich - */ - -#include "Visualization.h" - -#if (QT_VERSION < QT_VERSION_CHECK(5, 2, 0)) -#include -#endif -#include -#include -#include -#include -#include -#include - -OMVisualBase::OMVisualBase(const std::string& modelFile, const std::string& path) - : _shapes(), - _vectors(), - _modelFile(modelFile), - _path(path), - _xmlFileName(assembleXMLFileName(modelFile, path)) -{ -} - -/*! - * \brief OMVisualBase::getVisualizerObjectByID - * get the AbstractVisualizerObject with the same visualizerID - *\param the name of the visualizer - *\return the selected visualizer - */ -AbstractVisualizerObject* OMVisualBase::getVisualizerObjectByID(const std::string& visualizerID) -{ - std::vector> visualizers; - visualizers.reserve(_shapes.size() + _vectors.size()); - for (ShapeObject& shape : _shapes) { - visualizers.push_back(shape); - } - for (VectorObject& vector : _vectors) { - visualizers.push_back(vector); - } - for (AbstractVisualizerObject& visualizer : visualizers) { - if (visualizer._id == visualizerID) { - return &visualizer; - } - } - return nullptr; -} - -/*! - * \brief OMVisualBase::getVisualizerObjectIndexByID - * get the index of the AbstractVisualizerObject with the same visualizerID - *\param the name of the visualizer - *\return the selected visualizer index - */ -int OMVisualBase::getVisualizerObjectIndexByID(const std::string& visualizerID) -{ - int i = 0; - std::vector> visualizers; - visualizers.reserve(_shapes.size() + _vectors.size()); - for (ShapeObject& shape : _shapes) { - visualizers.push_back(shape); - } - for (VectorObject& vector : _vectors) { - visualizers.push_back(vector); - } - for (AbstractVisualizerObject& visualizer : visualizers) { - if (visualizer._id == visualizerID) { - return i; - } - i++; - } - return -1; -} - -void OMVisualBase::initVisObjects() -{ - if (!fileExists(_xmlFileName)) { - MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, - QString(QObject::tr("Could not find the visual XML file %1.")) - .arg(_xmlFileName.c_str()), - Helper::scriptingKind, Helper::errorLevel)); - return; - } - - QFile file(QString::fromStdString(_xmlFileName)); - if (!file.open(QIODevice::ReadOnly)) { - MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, - QString(QObject::tr("Could not open the visual XML file %1.")) - .arg(_xmlFileName.c_str()), - Helper::scriptingKind, Helper::errorLevel)); - return; - } - - QByteArray buffer = file.readAll(); - file.close(); - - rapidxml::xml_document<> xmlDoc; - xmlDoc.parse<0>(buffer.data()); - - rapidxml::xml_node<>* rootNode = xmlDoc.first_node(); - rapidxml::xml_node<>* expNode; - - for (rapidxml::xml_node<>* shapeNode = rootNode->first_node("shape"); shapeNode; shapeNode = shapeNode->next_sibling("shape")) - { - ShapeObject shape; // Create a new object for each node to ensure that all attributes are reset to default values - - expNode = shapeNode->first_node("ident")->first_node(); - shape._id = std::string(expNode->value()); - - //std::cout<<"id "<first_node("T")->first_node(); - shape._T[0] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._T[1] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._T[2] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._T[3] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._T[4] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._T[5] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._T[6] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._T[7] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._T[8] = getVisualizerAttributeForNode(expNode); - - expNode = shapeNode->first_node("r")->first_node(); - shape._r[0] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._r[1] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._r[2] = getVisualizerAttributeForNode(expNode); - - expNode = shapeNode->first_node("color")->first_node(); - shape._color[0] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._color[1] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._color[2] = getVisualizerAttributeForNode(expNode); - - expNode = shapeNode->first_node("specCoeff")->first_node(); - shape._specCoeff = getVisualizerAttributeForNode(expNode); - - expNode = shapeNode->first_node("type")->first_node(); - if (!expNode) { - MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, - QString(QObject::tr("The type of %1 is not supported right in the visxml file.")) - .arg(shape._id.c_str()), - Helper::scriptingKind, Helper::errorLevel)); - continue; - } - shape._type = std::string(expNode->value()); - - if (isCADType(shape._type)) - { - shape._fileName = extractCADFilename(shape._type); - if (!fileExists(shape._fileName)) { - MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, - QString(QObject::tr("Could not find the file %1.")) - .arg(shape._fileName.c_str()), - Helper::scriptingKind, Helper::errorLevel)); - continue; - } - - if (dxfFileType(shape._fileName)) { - shape._type = "dxf"; - } else if (stlFileType(shape._fileName)) { - shape._type = "stl"; - } - } - - //std::cout<<"type "<first_node("r_shape")->first_node(); - shape._rShape[0] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._rShape[1] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._rShape[2] = getVisualizerAttributeForNode(expNode); - - expNode = shapeNode->first_node("lengthDir")->first_node(); - shape._lDir[0] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._lDir[1] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._lDir[2] = getVisualizerAttributeForNode(expNode); - - expNode = shapeNode->first_node("widthDir")->first_node(); - shape._wDir[0] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._wDir[1] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - shape._wDir[2] = getVisualizerAttributeForNode(expNode); - - expNode = shapeNode->first_node("length")->first_node(); - shape._length = getVisualizerAttributeForNode(expNode); - expNode = shapeNode->first_node("width")->first_node(); - shape._width = getVisualizerAttributeForNode(expNode); - expNode = shapeNode->first_node("height")->first_node(); - shape._height = getVisualizerAttributeForNode(expNode); - - expNode = shapeNode->first_node("extra")->first_node(); - shape._extra = getVisualizerAttributeForNode(expNode); - - _shapes.push_back(shape); - } - - for (rapidxml::xml_node<>* vectorNode = rootNode->first_node("vector"); vectorNode; vectorNode = vectorNode->next_sibling("vector")) - { - VectorObject vector; // Create a new object for each node to ensure that all attributes are reset to default values - - expNode = vectorNode->first_node("ident")->first_node(); - vector._id = std::string(expNode->value()); - - //std::cout<<"id "<first_node("T")->first_node(); - vector._T[0] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - vector._T[1] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - vector._T[2] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - vector._T[3] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - vector._T[4] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - vector._T[5] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - vector._T[6] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - vector._T[7] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - vector._T[8] = getVisualizerAttributeForNode(expNode); - - expNode = vectorNode->first_node("r")->first_node(); - vector._r[0] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - vector._r[1] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - vector._r[2] = getVisualizerAttributeForNode(expNode); - - expNode = vectorNode->first_node("color")->first_node(); - vector._color[0] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - vector._color[1] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - vector._color[2] = getVisualizerAttributeForNode(expNode); - - expNode = vectorNode->first_node("specCoeff")->first_node(); - vector._specCoeff = getVisualizerAttributeForNode(expNode); - - expNode = vectorNode->first_node("coordinates")->first_node(); - vector._coords[0] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - vector._coords[1] = getVisualizerAttributeForNode(expNode); - expNode = expNode->next_sibling(); - vector._coords[2] = getVisualizerAttributeForNode(expNode); - - expNode = vectorNode->first_node("quantity")->first_node(); - vector._quantity = getVisualizerAttributeForNode(expNode); - - expNode = vectorNode->first_node("headAtOrigin")->first_node(); - vector._headAtOrigin = getVisualizerAttributeForNode(expNode); - - expNode = vectorNode->first_node("twoHeadedArrow")->first_node(); - vector._twoHeadedArrow = getVisualizerAttributeForNode(expNode); - - _vectors.push_back(vector); - } -} - -const std::string OMVisualBase::getModelFile() const -{ - return _modelFile; -} - -const std::string OMVisualBase::getPath() const -{ - return _path; -} - -const std::string OMVisualBase::getXMLFileName() const -{ - return _xmlFileName; -} - -void OMVisualBase::appendVisVariable(const rapidxml::xml_node<>* node, std::vector& visVariables) const -{ - if (strcmp("cref", node->name()) == 0) - { - visVariables.push_back(std::string(node->value())); - } -} - - -///--------------------------------------------------/// -///ABSTRACT VISUALIZATION CLASS----------------------/// -///--------------------------------------------------/// - -VisualizationAbstract::VisualizationAbstract() - : _visType(VisType::NONE), - mpOMVisualBase(nullptr), - mpOMVisScene(nullptr), - mpUpdateVisitor(nullptr) -{ - mpTimeManager = new TimeManager(0.0, 0.0, 1.0, 0.0, 0.1, 0.0, 1.0); -} - -VisualizationAbstract::VisualizationAbstract(const std::string& modelFile, const std::string& path, const VisType visType) - : _visType(visType), - mpOMVisualBase(nullptr), - mpOMVisScene(new OMVisScene()), - mpUpdateVisitor(new UpdateVisitor()), - mpTimeManager(new TimeManager(0.0, 0.0, 0.0, 0.0, 0.1, 0.0, 100.0)) -{ - mpOMVisualBase = new OMVisualBase(modelFile, path); - mpOMVisScene->getScene().setPath(path); -} - -void VisualizationAbstract::initData() -{ - mpOMVisualBase->initVisObjects(); -} - -void VisualizationAbstract::initVisualization() -{ - initializeVisAttributes(mpTimeManager->getStartTime()); - mpTimeManager->setVisTime(mpTimeManager->getStartTime()); - mpTimeManager->setRealTimeFactor(0.0); - mpTimeManager->setPause(true); -} - -TimeManager* VisualizationAbstract::getTimeManager() const -{ - return mpTimeManager; -} - -void VisualizationAbstract::modifyVisualizer(const std::string& visualizerName) -{ - int visualizerIdx = getBaseData()->getVisualizerObjectIndexByID(visualizerName); - AbstractVisualizerObject* visualizer = getBaseData()->getVisualizerObjectByID(visualizerName); - visualizer->setStateSetAction(StateSetAction::modify); - mpUpdateVisitor->_visualizer = visualizer; - osg::ref_ptr child = mpOMVisScene->getScene().getRootNode()->getChild(visualizerIdx); - child->accept(*mpUpdateVisitor); - visualizer->setStateSetAction(StateSetAction::update); -} - - -void VisualizationAbstract::sceneUpdate() -{ - //measure realtime - mpTimeManager->updateTick(); - //update scene and set next time step - if (!mpTimeManager->isPaused()) { - updateScene(mpTimeManager->getVisTime()); - //finish animation with pause when endtime is reached - if (mpTimeManager->getVisTime() >= mpTimeManager->getEndTime()) { - if (mpTimeManager->canRepeat()) { - initVisualization(); - mpTimeManager->setPause(false); - } else { - mpTimeManager->setPause(true); - } - } else { // get the new visualization time - double newTime = mpTimeManager->getVisTime() + (mpTimeManager->getHVisual()*mpTimeManager->getSpeedUp()); - if (newTime <= mpTimeManager->getEndTime()) { - mpTimeManager->setVisTime(newTime); - } else { - mpTimeManager->setVisTime(mpTimeManager->getEndTime()); - } - } - } -} - -void VisualizationAbstract::setUpScene() -{ - // Build scene graph. - mpOMVisScene->getScene().setUpScene(mpOMVisualBase->_shapes); - mpOMVisScene->getScene().setUpScene(mpOMVisualBase->_vectors); -} - -VisType VisualizationAbstract::getVisType() const -{ - return _visType; -} - -OMVisualBase* VisualizationAbstract::getBaseData() const -{ - return mpOMVisualBase; -} - - - -OMVisScene* VisualizationAbstract::getOMVisScene() const -{ - return mpOMVisScene; -} - -std::string VisualizationAbstract::getModelFile() const -{ - return mpOMVisualBase->getModelFile(); -} - -void VisualizationAbstract::startVisualization() -{ - if (mpTimeManager->getVisTime() < mpTimeManager->getEndTime() - 1.e-6) { - mpTimeManager->setPause(false); - } else { - MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, - QObject::tr("There is nothing left to visualize. Initialize the model first."), - Helper::scriptingKind, Helper::errorLevel)); - } -} - -void VisualizationAbstract::pauseVisualization() -{ - mpTimeManager->setPause(true); -} - - -OMVisScene::OMVisScene() - : _scene() -{ -} - -void OMVisScene::dumpOSGTreeDebug() -{ - // The node traverser which dumps the tree - InfoVisitor infoVisitor; - _scene.getRootNode()->accept(infoVisitor); -} - -OSGScene& OMVisScene::getScene() -{ - return _scene; -} - - -OSGScene::OSGScene() - : _rootNode(new osg::Group()), - _path("") -{ -} - -void OSGScene::setUpScene(const std::vector& shapes) -{ - for (const ShapeObject& shape : shapes) - { - osg::ref_ptr transf = new osg::MatrixTransform(); - - if (shape._type.compare("stl") == 0) - { //cad node - //std::cout<<"It's a stl and the filename is "< node = osgDB::readNodeFile(shape._fileName); - - if (node) - { - osg::ref_ptr material = new osg::Material(); - material->setDiffuse(osg::Material::FRONT, osg::Vec4f(0.0, 0.0, 0.0, 0.0)); - - osg::ref_ptr ss = node->getOrCreateStateSet(); - ss->setAttribute(material.get()); - - node->setStateSet(ss.get()); - - transf->addChild(node.get()); - } - } - else if (shape._type.compare("dxf") == 0) - { //geode with dxf drawable - //std::cout<<"It's a dxf and the filename is "< dxfDraw = new DXFile(shape._fileName); - - osg::ref_ptr geode = new osg::Geode(); - geode->addDrawable(dxfDraw.get()); - - transf->addChild(geode.get()); - } - else - { //geode with shape drawable - osg::ref_ptr shapeDraw = new osg::ShapeDrawable(); - shapeDraw->setColor(osg::Vec4(1.0, 1.0, 1.0, 1.0)); - - osg::ref_ptr geode = new osg::Geode(); - geode->addDrawable(shapeDraw.get()); - - osg::ref_ptr material = new osg::Material(); - material->setDiffuse(osg::Material::FRONT, osg::Vec4f(0.0, 0.0, 0.0, 0.0)); - - osg::ref_ptr ss = geode->getOrCreateStateSet(); - ss->setAttribute(material.get()); - - geode->setStateSet(ss.get()); - - transf->addChild(geode.get()); - } - - _rootNode->addChild(transf.get()); - } -} - -void OSGScene::setUpScene(const std::vector& vectors) -{ - for (const VectorObject& vector : vectors) - { - Q_UNUSED(vector); - - osg::ref_ptr transf = new osg::MatrixTransform(); - - osg::ref_ptr shapeDraw0 = new osg::ShapeDrawable(); // shaft cylinder - shapeDraw0->setColor(osg::Vec4(1.0, 1.0, 1.0, 1.0)); - - osg::ref_ptr shapeDraw1 = new osg::ShapeDrawable(); // first head cone - shapeDraw1->setColor(osg::Vec4(1.0, 1.0, 1.0, 1.0)); - - osg::ref_ptr shapeDraw2 = new osg::ShapeDrawable(); // second head cone - shapeDraw2->setColor(osg::Vec4(1.0, 1.0, 1.0, 1.0)); - - osg::ref_ptr geode = new osg::Geode(); - geode->addDrawable(shapeDraw0.get()); - geode->addDrawable(shapeDraw1.get()); - geode->addDrawable(shapeDraw2.get()); - - osg::ref_ptr material = new osg::Material(); - material->setDiffuse(osg::Material::FRONT, osg::Vec4f(0.0, 0.0, 0.0, 0.0)); - - osg::ref_ptr ss = geode->getOrCreateStateSet(); - ss->setAttribute(material.get()); - - geode->setStateSet(ss.get()); - - transf->addChild(geode.get()); - - _rootNode->addChild(transf.get()); - } -} - -osg::ref_ptr OSGScene::getRootNode() -{ - return _rootNode; -} - -std::string OSGScene::getPath() const -{ - return _path; -} - -void OSGScene::setPath(const std::string path) -{ - _path = path; -} - - -UpdateVisitor::UpdateVisitor() - : _visualizer(nullptr) -{ - setTraversalMode(NodeVisitor::TRAVERSE_ALL_CHILDREN); -} - -/** - MatrixTransform - */ -void UpdateVisitor::apply(osg::MatrixTransform& node) -{ - //std::cout<<"MT "<_mat); - traverse(node); -} - -/** - Geode - */ -void UpdateVisitor::apply(osg::Geode& node) -{ - //std::cout<<"GEODE "<< _visualizer->_id<<" "<<_visualizer->getTransparency()< ss = node.getOrCreateStateSet(); - node.setName(_visualizer->_id); - switch (_visualizer->getStateSetAction()) - { - case StateSetAction::update: - { - switch (_visualizer->getVisualizerType()) - { - case VisualizerType::shape: - { - ShapeObject* shape = static_cast(_visualizer); - if (shape->_type.compare("dxf") != 0 and shape->_type.compare("stl") != 0) - { - //it's a drawable and not a cad file so we have to create a new drawable - osg::ref_ptr draw = node.getDrawable(0); - draw->dirtyDisplayList(); - if (shape->_type == "pipe") - { - node.removeDrawable(draw.get()); - draw = new Pipecylinder(shape->_width.exp * shape->_extra.exp / 2, shape->_width.exp / 2, shape->_length.exp); - } - else if (shape->_type == "pipecylinder") - { - node.removeDrawable(draw.get()); - draw = new Pipecylinder(shape->_width.exp * shape->_extra.exp / 2, shape->_width.exp / 2, shape->_length.exp); - } - else if (shape->_type == "spring") - { - node.removeDrawable(draw.get()); - draw = new Spring(shape->_width.exp, shape->_height.exp, shape->_extra.exp, shape->_length.exp); - } - else if (shape->_type == "box") - { - draw->setShape(new osg::Box(osg::Vec3f(), shape->_width.exp, shape->_height.exp, shape->_length.exp)); - } - else if (shape->_type == "cone") - { - draw->setShape(new osg::Cone(osg::Vec3f(), shape->_width.exp / 2, shape->_length.exp)); - } - else if (shape->_type == "cylinder") - { - draw->setShape(new osg::Cylinder(osg::Vec3f(), shape->_width.exp / 2, shape->_length.exp)); - } - else if (shape->_type == "sphere") - { - draw->setShape(new osg::Sphere(osg::Vec3f(), shape->_length.exp / 2)); - } - else - { - MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, - QString(QObject::tr("Unknown type %1, we make a capsule.")).arg(shape->_type.c_str()), - Helper::scriptingKind, Helper::errorLevel)); - draw->setShape(new osg::Capsule(osg::Vec3f(), 0.1, 0.5)); - } - //std::cout<<"SHAPE "<getShape()->className()<(_visualizer); - - const float vectorRadius = vector->getRadius(); - const float vectorLength = vector->getLength(); - const float headRadius = vector->getHeadRadius(); - const float headLength = vector->getHeadLength(); - const float shaftRadius = vectorRadius; - const float shaftLength = vectorLength > headLength ? vectorLength - headLength : 0; - const osg::Vec3f vectorDirection = osg::Vec3f(0, 0, 1); // axis of symmetry directed from tail to head of arrow - const osg::Vec3f shaftPosition = vectorDirection * (- headLength / 2); // center of cylinder shifted for top of shaft to meet bottom of first head - const osg::Vec3f head1Position = vectorDirection * (vectorLength / 2 - headLength); // base of first cone (offset added by osg::Cone is canceled below) - const osg::Vec3f head2Position = head1Position - vectorDirection * headLength / 2; // base of second cone (offset added by osg::Cone is canceled below) - - osg::ref_ptr shaftShape = new osg::Cylinder(shaftPosition, shaftRadius, shaftLength); - osg::ref_ptr head1Shape = new osg::Cone(head1Position, headRadius, headLength); - osg::ref_ptr head2Shape = new osg::Cone(head2Position, headRadius, headLength); - - head1Shape->setCenter(head1Shape->getCenter() - vectorDirection * head1Shape->getBaseOffset()); - head2Shape->setCenter(head2Shape->getCenter() - vectorDirection * head2Shape->getBaseOffset()); - - osg::ref_ptr draw0 = node.getDrawable(0); // shaft cylinder - draw0->dirtyDisplayList(); - draw0->setShape(shaftShape.get()); - //std::cout<<"VECTOR shaft "<getShape()->className()< draw1 = node.getDrawable(1); // first head cone - draw1->dirtyDisplayList(); - draw1->setShape(head1Shape.get()); - //std::cout<<"VECTOR first head "<getShape()->className()< draw2 = node.getDrawable(2); // second head cone - draw2->dirtyDisplayList(); - if (vector->isTwoHeadedArrow()) - { - draw2->setShape(head2Shape.get()); - //std::cout<<"VECTOR second head "<getShape()->className()<setShape(nullptr); - } - break; - }//end case type vector - - default: - {break;} - - }//end switch type - break; - }//end case action update - - case StateSetAction::modify: - { - //apply texture - applyTexture(ss.get(), _visualizer->getTextureImagePath()); - break; - }//end case action modify - - default: - {break;} - - }//end switch action - - //set color - if (!_visualizer->isShape() or static_cast(_visualizer)->_type.compare("dxf") != 0) - changeColor(ss.get(), _visualizer->_color[0].exp, _visualizer->_color[1].exp, _visualizer->_color[2].exp); - - //set transparency - changeTransparency(ss.get(), _visualizer->getTransparency()); - - node.setStateSet(ss.get()); - traverse(node); -} - -osg::Image* UpdateVisitor::convertImage(const QImage& iImage) -{ - osg::Image* osgImage = new osg::Image(); - if (!iImage.isNull()) { -#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)) - QImage glImage = iImage.convertToFormat(QImage::Format_RGBA8888_Premultiplied); -#else - QImage glImage = QGLWidget::convertToGLFormat(iImage); -#endif - if (!glImage.isNull()) { -#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) - int bytesSize = glImage.sizeInBytes(); -#else // QT_VERSION_CHECK - int bytesSize = glImage.byteCount(); -#endif // QT_VERSION_CHECK - unsigned char* data = new unsigned char[bytesSize]; - for (int i = 0; i < bytesSize; ++i) { - data[i] = glImage.bits()[i]; - } - osgImage->setImage(glImage.width(), glImage.height(), 1, 4, GL_RGBA, GL_UNSIGNED_BYTE, data, osg::Image::USE_NEW_DELETE, 1); - } - } - return osgImage; -} - -/*! - * \brief UpdateVisitor::applyTexture - * sets a texture for a geode - */ -void UpdateVisitor::applyTexture(osg::StateSet* ss, const std::string& imagePath) -{ - if (ss) - { - if (imagePath.compare("")) - { - osg::ref_ptr image = nullptr; - std::string resIdent = ":/Resources"; - if (!imagePath.compare(0, resIdent.length(), resIdent)) - { - QImage* qim = new QImage(QString::fromStdString(imagePath)); - image = convertImage(*qim); - delete qim; - if (image.get()) - { - image->setInternalTextureFormat(GL_RGBA); - } - } - else - { - image = osgDB::readImageFile(imagePath); - } - if (image.get()) - { - osg::ref_ptr texture = new osg::Texture2D(); - texture->setDataVariance(osg::Object::DYNAMIC); - texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR); - texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); - texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); - texture->setImage(image.get()); - texture->setResizeNonPowerOfTwoHint(false);// don't output console message about scaling - ss->setTextureAttributeAndModes(0, texture.get(), osg::StateAttribute::ON); - } - } - else - { - ss->getTextureAttributeList().clear(); - ss->getTextureModeList().clear(); - } - } -} - -/*! - * \brief UpdateVisitor::changeColor - * changes color for a geode - */ -void UpdateVisitor::changeColor(osg::StateSet* ss, float r, float g, float b) -{ - if (ss) - { - osg::ref_ptr material = dynamic_cast(ss->getAttribute(osg::StateAttribute::MATERIAL)); - if (!material.get()) material = new osg::Material(); - material->setDiffuse(osg::Material::FRONT, osg::Vec4f(r / 255, g / 255, b / 255, 1.0)); - ss->setAttribute(material.get()); - } -} - -/*! - * \brief UpdateVisitor::changeTransparency - * changes transparency for a geode - */ -void UpdateVisitor::changeTransparency(osg::StateSet* ss, float transpCoeff) -{ - if (ss and _visualizer->getTransparency()) - { - ss->setMode(GL_BLEND, osg::StateAttribute::ON); - ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - osg::ref_ptr material = dynamic_cast(ss->getAttribute(osg::StateAttribute::MATERIAL)); - if (!material.get()) material = new osg::Material(); - material->setTransparency(osg::Material::FRONT_AND_BACK, transpCoeff); - ss->setAttributeAndModes(material.get(), osg::StateAttribute::OVERRIDE); - } -} - -InfoVisitor::InfoVisitor() - : _level(0) -{ - setTraversalMode(NodeVisitor::TRAVERSE_ALL_CHILDREN); -} - -std::string InfoVisitor::spaces() -{ - return std::string(_level * 2, ' '); -} - -void InfoVisitor::apply(osg::Node& node) -{ - std::cout << spaces() << node.libraryName() << "::" << node.className() << std::endl; - ++_level; - traverse(node); - --_level; -} - -void InfoVisitor::apply(osg::Geode& geode) -{ - std::cout << spaces() << geode.libraryName() << "::" << geode.className() << std::endl; - ++_level; - for (size_t i = 0; i < geode.getNumDrawables(); ++i) - { - osg::ref_ptr drawable = geode.getDrawable(i); - std::cout << spaces() << drawable->libraryName() << "::" << drawable->className() << std::endl; - } - traverse(geode); - --_level; -} - - -osg::Vec3f Mat3mulV3(osg::Matrix3 M, osg::Vec3f V) -{ - return osg::Vec3f(M[0] * V[0] + M[1] * V[1] + M[2] * V[2], - M[3] * V[0] + M[4] * V[1] + M[5] * V[2], - M[6] * V[0] + M[7] * V[1] + M[8] * V[2]); -} - -osg::Vec3f V3mulMat3(osg::Vec3f V, osg::Matrix3 M) -{ - return osg::Vec3f(M[0] * V[0] + M[3] * V[1] + M[6] * V[2], - M[1] * V[0] + M[4] * V[1] + M[7] * V[2], - M[2] * V[0] + M[5] * V[1] + M[8] * V[2]); -} - -osg::Matrix3 Mat3mulMat3(osg::Matrix3 M1, osg::Matrix3 M2) -{ - osg::Matrix3 M3; - for (int i = 0; i < 3; ++i) - { - for (int j = 0; j < 3; ++j) - { - //cout<<" i and j "< - */ - -#include "VisualizationCSV.h" - -VisualizationCSV::VisualizationCSV(const std::string& modelFile, const std::string& path) - : VisualizationAbstract(modelFile, path, VisType::CSV), mpCSVData(0) -{ - -} - -VisualizationCSV::~VisualizationCSV() -{ - if (mpCSVData) { - omc_free_csv_reader(mpCSVData); - } -} - -void VisualizationCSV::initData() -{ - VisualizationAbstract::initData(); - readCSV(mpOMVisualBase->getModelFile(), mpOMVisualBase->getPath()); - double *time = read_csv_dataset(mpCSVData, "time"); - if (time) { - mpTimeManager->setStartTime(time[0]); - mpTimeManager->setEndTime(time[mpCSVData->numsteps - 1]); - } -} - -void VisualizationCSV::initializeVisAttributes(const double time) -{ - if (0.0 > time) { - MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, - QObject::tr("Cannot load visualization attributes for time point < 0.0."), - Helper::scriptingKind, Helper::errorLevel)); - } - updateVisAttributes(time); -} - -void VisualizationCSV::readCSV(const std::string& modelFile, const std::string& path) -{ - std::string resFileName = path + modelFile; // + "_res.csv"; - - // Check if the file exists. - if (!fileExists(resFileName)) { - MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, QString(QObject::tr("Could not find CSV file %1.")) - .arg(resFileName.c_str()), Helper::scriptingKind, Helper::errorLevel)); - } else { - // Read mat file. - mpCSVData = read_csv(resFileName.c_str()); - // Check return value. - if (!mpCSVData) { - MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, QString(QObject::tr("Could not read CSV file %1.")) - .arg(resFileName.c_str()), Helper::scriptingKind, Helper::errorLevel)); - } - } -} - -void VisualizationCSV::updateVisAttributes(const double time) -{ - // Update all visualizers - //std::cout<<"updateVisAttributes at "<