source: osgVisual/include/dataIO/visual_dataIO.h @ 85

Last change on this file since 85 was 85, checked in by Torben Dannhauer, 14 years ago
File size: 5.1 KB
Line 
1#pragma once
2/* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer
3 *
4 * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under
5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6 * (at your option) any later version.  The full license is in LICENSE file
7 * included with this distribution, and on the openscenegraph.org website.
8 *
9 * osgVisual requires for some proprietary modules a license from the correspondig manufacturer.
10 * You have to aquire licenses for all used proprietary modules.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * OpenSceneGraph Public License for more details.
16*/
17
18#include <osg/notify>
19#include <osg/referenced>
20#include <osg/ArgumentParser>
21
22#include <osgViewer/Viewer>
23
24// Cluster einbinden
25#ifdef USE_CLUSTER_ASIO_TCP_IOSTREAM
26        #include <dataIO_clusterAsioTcpIostream.h>
27#endif
28#ifdef USE_CLUSTER_ENET
29        #include <dataIO_clusterENet.h>
30#endif
31#ifdef USE_CLUSTER_DUMMY
32        #include <dataIO_clusterDummy.h>
33#endif
34
35
36//ExtLink einbinden
37#ifdef USE_EXTLINK_DUMMY
38        #include <dataIO_extLinkDummy.h>
39#endif
40#ifdef USE_EXTLINK_VCL
41        #include <dataIO_extLinkVCL.h>
42#endif
43
44
45// slot and transportContainer definitions
46#include <dataIO_slot.h>
47#include <dataIO_transportContainer.h>
48
49#include <vector>
50
51
52
53
54namespace osgVisual {
55
56/**
57 * \brief Zentrale Klasse für Datenanbindung des Sichtsystemnodes an das Gesamtsichtsystem bzw. dem Simulator.
58 *
59 * Damit nur eine Klasse instantiiert werden kann, ist diese Klasse als Singleton realisiert.
60 *
61 *
62 * @author Torben Dannhauer
63 * @date  Nov 2009
64 */ 
65class visual_dataIO : public osg::Referenced
66{
67private:
68        class dataIO_eventCallback : public osg::NodeCallback
69        {
70        public: 
71                /**
72                 * \brief Constructor, for setting the member variables.
73                 *
74                 * @param viewer_ : Pointer to the viewer.
75                 * @param sceneCamera_ : Pointer to the scene camera.
76                 */ 
77                dataIO_eventCallback(visual_dataIO* dataIO_):dataIO(dataIO_){};
78
79                /**
80                 * \brief This function is execute d as callback during update traversal.
81                 *
82                 */ 
83                virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
84        private:
85                visual_dataIO* dataIO;
86        };
87        osg::ref_ptr<dataIO_eventCallback> eventCallback;
88
89        class dataIO_finalDrawCallback : public osg::Camera::DrawCallback
90        {
91        public:
92                /**
93                 * \brief Constructor
94                 *
95                 */ 
96                dataIO_finalDrawCallback::dataIO_finalDrawCallback(visual_dataIO* dataIO_):dataIO(dataIO_){};
97               
98                /**
99                 * \brief Operator executed at callback
100                 *
101                 */ 
102                virtual void operator () (const osg::Camera& camera) const;
103        private:
104                visual_dataIO* dataIO;
105        };
106
107        osg::ref_ptr<dataIO_finalDrawCallback> finalDrawCallback;
108
109        // Make Constructor private to prevent creating instances via ptr* = new ..().
110        visual_dataIO();
111        // Make Copy-Constructor private to prevent getting instances via copying dataIO instance.
112        visual_dataIO(const visual_dataIO& cc);
113
114        osg::Matrixd calcViewMatrix();
115        osg::ref_ptr<dataIO_extLink> extLink;
116        osg::ref_ptr<dataIO_cluster> cluster;
117
118        /**
119         * Referenced Pointer to the applications viewer.
120         */ 
121        osg::ref_ptr<osgViewer::Viewer> viewer;
122
123        osg::ref_ptr<osgVisual::dataIO_transportContainer> slotContainer;
124
125        /**
126         * List of SLOT variables dataIO provides.
127         */ 
128        std::vector<dataIO_slot> dataSlots;
129
130        friend dataIO_eventCallback;
131        friend dataIO_finalDrawCallback;
132
133public:
134        // Public destructor to allow singleton cleanup from extern
135        ~visual_dataIO();
136
137        /**
138         * \brief This function returns an pointer to the singleton instalce of dataIO. If now instance exist, it will be instantiated silently.
139         *
140         * After instantiation, dataIO still needs to bei initiialized to configure working mode etc!
141         *
142         * @return : Pointer to the instance.
143         */ 
144        static visual_dataIO* getInstance();
145
146        void init(osgViewer::Viewer* viewer_,osg::ArgumentParser& arguments_);
147        void shutdown();
148        bool isMaster(){if (clusterMode==osgVisual::dataIO_cluster::MASTER) return true; else return false;};
149        bool isSlave(){if (clusterMode==osgVisual::dataIO_cluster::SLAVE) return true; else return false;};
150        bool isStandalone(){if (clusterMode==osgVisual::dataIO_cluster::STANDALONE) return true; else return false;};
151
152// SLOT Access functions
153        void* getSlotPointer(std::string slotName_, osgVisual::dataIO_slot::dataDirection direction_, osgVisual::dataIO_slot::varType variableTyp_ );
154        double getSlotDataAsDouble(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_ );
155        std::string getSlotDataAsString(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_ );
156        void setSlotData(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_, std::string sValue_ );
157        void setSlotData(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_, double value_ );
158
159        int getSlotNum() {return dataSlots.size();}
160
161        osgVisual::dataIO_cluster::clustermode clusterMode;
162
163        bool initialized;
164};
165
166
167} // END namespace osgVisual
Note: See TracBrowser for help on using the repository browser.