Skip to content

Commit

Permalink
- compile a lot of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich committed Aug 24, 2016
1 parent 7f92104 commit 8627235
Show file tree
Hide file tree
Showing 11 changed files with 4,410 additions and 7 deletions.
127 changes: 127 additions & 0 deletions OMEdit/OMEditGUI/Animation/AnimationUtil.h
@@ -0,0 +1,127 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, 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 <volker.waurich@tu-dresden.de>
*/


#ifndef ANIMATIONUTIL_H
#define ANIMATIONUTIL_H

#include <sys/stat.h>
#include <string>

#include <osg/Vec3>
#include "Shapes.h"

enum class VisType
{
NONE = 0,
FMU = 1,
FMU_REMOTE = 2,
MAT = 3,
MAT_REMOTE = 4
};

/*!
* \brief isFMU
* checks of the file is of type FMU
*/
inline bool isFMU(const std::string& fileIn){
std::size_t fmu = fileIn.find(".fmu");
return (fmu != std::string::npos);
}

/*!
* \brief isMAT
* checks of the file is of type mat
*/
inline bool isMAT(const std::string& fileIn){
std::size_t mat = fileIn.find(".mat");
return (mat != std::string::npos);
}

/*!
* \brief assembleXMLFileName
* constructs the name of the corresponding xml file
*/
inline std::string assembleXMLFileName(const std::string& modelFile, const std::string& path){
int signsOff(0);
if (isFMU(modelFile))
signsOff = 4;
else if (isMAT(modelFile))
signsOff = 8;
else{
// todo: Handle this case.
}
// Cut off prefix [fmu|mat]
std::string fileName = modelFile.substr(0, modelFile.length() - signsOff);
// Construct XML file name
std::string xmlFileName = path + fileName + "_visual.xml";
return xmlFileName;
}

/*! \brief Checks if the file is accessible. */
inline bool fileExists(const std::string& file)
{
struct stat buffer;
return (stat(file.c_str(), &buffer) == 0);
}

/*!
* \brief checkForXMLFile
* checks if the xml file is available
*/
inline bool checkForXMLFile(const std::string& modelFile, const std::string& path){
// Cut off prefix [fmu|mat]
std::string xmlFileName = assembleXMLFileName(modelFile, path);
return fileExists(xmlFileName);
}

/*! \brief Checks if the type is a cad file
*/
inline bool isCADType(const std::string& typeName)
{
return (typeName.size() >= 12 && std::string(typeName.begin(), typeName.begin() + 11) == "modelica://");
}

/*! \brief Get file name of the cad file
*/
inline std::string extractCADFilename(const std::string& s)
{
std::string fileKey = "modelica://";
std::string s2 = s.substr(fileKey.length(), s.length());
int pos = s2.find("/");
return s2.substr(pos + 1, s.length());
}


#endif //ANIMATIONUTIL_H
61 changes: 56 additions & 5 deletions OMEdit/OMEditGUI/Animation/AnimationWindowContainer.cpp
Expand Up @@ -33,7 +33,7 @@
*/

#include "AnimationWindowContainer.h"

#include "AnimationUtil.h"
/*!
\class AnimationWindowContainer
\brief A MDI area for animation windows.
Expand All @@ -45,6 +45,8 @@
AnimationWindowContainer::AnimationWindowContainer(MainWindow *pParent)
: QWidget(pParent),
osgViewer::CompositeViewer(),
_pathName(""),
_fileName(""),
_sceneView(new osgViewer::View()),
viewerWidget(nullptr),
topWidget(nullptr),
Expand Down Expand Up @@ -115,7 +117,6 @@ QWidget* AnimationWindowContainer::setupViewWidget(osg::ref_ptr<osg::Node> rootN
/*!
* \brief AnimationWindowContainer::setupAnimationWidgets
* creates the widgets for the animation
* \return void
*/
QWidget* AnimationWindowContainer::setupAnimationWidgets()
{
Expand Down Expand Up @@ -161,29 +162,79 @@ QWidget* AnimationWindowContainer::setupAnimationWidgets()
return topWidget;
}


/*!
* \brief AnimationWindowContainer::showWidgets
* overwrite show method to explicitly show the viewer as well
*/
void AnimationWindowContainer::showWidgets(){
viewerWidget->show();
show();
}


/*!
* \brief AnimationWindowContainer::playSlotFunction
* slot function for the play button
*/
void AnimationWindowContainer::playSlotFunction(){
std::cout<<"playSlotFunction "<<std::endl;
}

/*!
* \brief AnimationWindowContainer::pauseSlotFunction
* slot function for the pause button
*/
void AnimationWindowContainer::pauseSlotFunction(){
std::cout<<"pauseSlotFunction "<<std::endl;
}

/*!
* \brief AnimationWindowContainer::initSlotFunction
* slot function for the init button
*/
void AnimationWindowContainer::initSlotFunction(){
std::cout<<"initSlotFunction "<<std::endl;
}

/*!
* \brief AnimationWindowContainer::loadVisualization
* loads the data and the xml scene description
*/
void AnimationWindowContainer::loadVisualization(){
VisType visType = VisType::NONE;
// Get visualization type.
if (isFMU(_fileName))
visType = VisType::FMU;
else if (isMAT(_fileName))
visType = VisType::MAT;
else
std::cout<<"doof "<<std::endl;


//init
if (visType == VisType::FMU){
//result = std::shared_ptr<VisualizerAbstract>(new VisualizerFMU(cP->modelFile, cP->path));
}
// MAT file based visualization
else if (visType == VisType::MAT)
{
VisualizerMAT* result = new VisualizerMAT(_fileName, _pathName);
}
else
{
std::cout<<"could not init "<<_pathName<<_fileName<<std::endl;
}

}

void AnimationWindowContainer::animationFileSlotFunction(){
std::cout<<"animationFileSlotFunction "<<std::endl;
QFileDialog dialog(this);
QString fileName = dialog.getOpenFileName(this,tr("Open Visualiation File"), "./", tr("Visualization Files (*.mat *.fmu)"));
std::string file = dialog.getOpenFileName(this,tr("Open Visualiation File"), "./", tr("Visualization FMU(*.fmu);; Visualization MAT(*.mat)")).toStdString();;
std::size_t pos = file.find_last_of("/\\");
_pathName = file.substr(0, pos + 1);
_fileName = file.substr(pos + 1, file.length());
std::cout<<"file "<<_fileName<<" path "<<_pathName<<std::endl;
loadVisualization();
}


Expand Down
8 changes: 7 additions & 1 deletion OMEdit/OMEditGUI/Animation/AnimationWindowContainer.h
Expand Up @@ -29,13 +29,15 @@
*
*/
/*
* @author Adeel Asghar <adeel.asghar@liu.se>
* @author Volker Waurich <volker.waurich@tu-dresden.de>
*/

#ifndef ANIMATIONWINDOWCONTAINER_H
#define ANIMATIONWINDOWCONTAINER_H

#include "MainWindow.h"
#include "AnimationUtil.h"
#include "Visualizer.h"

#include <iostream>

Expand Down Expand Up @@ -63,6 +65,7 @@ class AnimationWindowContainer : public QWidget, public osgViewer::CompositeView
QWidget* setupAnimationWidgets();
QWidget* setupViewWidget(osg::ref_ptr<osg::Node> rootNode);
void showWidgets();
void loadVisualization();

public slots:
void playSlotFunction();
Expand All @@ -72,6 +75,9 @@ class AnimationWindowContainer : public QWidget, public osgViewer::CompositeView
void animationFileSlotFunction();

private:
//to be animated
std::string _pathName;
std::string _fileName;
//osg viewer
osgViewer::View* _sceneView;
//widgets
Expand Down

0 comments on commit 8627235

Please sign in to comment.