OpenWalnut  1.5.0dev
WUtilityFunctions.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <string>
26 #include <osgGA/TrackballManipulator>
27 
28 #include "../../common/WLogger.h"
29 
30 #include "../../graphicsEngine/WGraphicsEngine.h"
31 
32 #include "../../kernel/WKernel.h"
33 
34 #include "WUtilityFunctions.h"
35 
36 void screenshot()
37 {
38  if( WKernel::getRunningKernel()->getGraphicsEngine() )
39  {
40  WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getScreenCapture()->screenshot();
41  }
42  else
43  {
44  wlog::error( "Script" ) << "No graphics engine! Cannot make screenshot!";
45  }
46 }
47 
48 void initCamera( std::string const& view )
49 {
50  if( WKernel::getRunningKernel()->getGraphicsEngine() )
51  {
52  osg::ref_ptr< osgGA::TrackballManipulator > cm = osg::dynamic_pointer_cast< osgGA::TrackballManipulator >(
53  WKernel::getRunningKernel()->getGraphicsEngine()->getViewer()->getCameraManipulator() );
54  if( cm )
55  {
56  osg::Quat q;
57 
58  if( view == "anterior" )
59  {
60  q = osg::Quat( 0., -0.707107, -0.707107, 0. );
61  }
62  else if( view == "posterior" )
63  {
64  q = osg::Quat( 0.707107, 0., 0., 0.707107 );
65  }
66  else if( view == "left" )
67  {
68  q = osg::Quat( 0.5, -0.5, -0.5, 0.5 );
69  }
70  else if( view == "right" )
71  {
72  q = osg::Quat( -0.5, -0.5, -0.5, -0.5 );
73  }
74  else if( view == "superior" )
75  {
76  q = osg::Quat( 0., 0., 0., 1 );
77  }
78  else if( view == "inferior" )
79  {
80  q = osg::Quat( 0., -1., 0., 0. );
81  }
82  else
83  {
84  q = osg::Quat( 0., 0., 0., 1 );
85 
86  wlog::warn( "Script" ) << "Unknown preset: " << view << "!";
87  }
88 
89  cm->setRotation( q );
90  }
91  else
92  {
93  wlog::warn( "Script" ) << "GL Widget does not use a TrackballManipulator. Preset cannot be used.";
94  }
95  }
96  else
97  {
98  wlog::error( "Script" ) << "No graphics engine! Cannot set camera preset!";
99  }
100 }
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
Definition: WKernel.cpp:117
std::shared_ptr< WGraphicsEngine > getGraphicsEngine() const
Returns pointer to currently running instance of graphics engine.
Definition: WKernel.cpp:122
WStreamedLogger warn(const std::string &source)
Logging a warning message.
Definition: WLogger.h:309
WStreamedLogger error(const std::string &source)
Logging an error message.
Definition: WLogger.h:298