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

Last change on this file since 75 was 73, checked in by Torben Dannhauer, 14 years ago
File size: 5.2 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_DUMMY
29        #include <dataIO_clusterDummy.h>
30#endif
31#ifdef USE_CLUSTER_UDP
32        #include <dataIO_clusterUDP.h>
33#endif
34#ifdef USE_CLUSTER_ENET
35        #include <dataIO_clusterENet.h>
36#endif
37
38
39//ExtLink einbinden
40#ifdef USE_EXTLINK_DUMMY
41        #include <dataIO_extLinkDummy.h>
42#endif
43#ifdef USE_EXTLINK_VCL
44        #include <dataIO_extLinkVCL.h>
45#endif
46
47
48// slot and transportContainer definitions
49#include <dataIO_slot.h>
50#include <dataIO_transportContainer.h>
51
52#include <vector>
53
54
55
56
57namespace osgVisual {
58
59/**
60 * \brief Zentrale Klasse für Datenanbindung des Sichtsystemnodes an das Gesamtsichtsystem bzw. dem Simulator.
61 *
62 * Damit nur eine Klasse instantiiert werden kann, ist diese Klasse als Singleton realisiert.
63 *
64 *
65 * @author Torben Dannhauer
66 * @date  Nov 2009
67 */ 
68class visual_dataIO : public osg::Referenced
69{
70private:
71        class dataIO_eventCallback : public osg::NodeCallback
72        {
73        public: 
74                /**
75                 * \brief Constructor, for setting the member variables.
76                 *
77                 * @param viewer_ : Pointer to the viewer.
78                 * @param sceneCamera_ : Pointer to the scene camera.
79                 */ 
80                dataIO_eventCallback(visual_dataIO* dataIO_):dataIO(dataIO_){};
81
82                /**
83                 * \brief This function is execute d as callback during update traversal.
84                 *
85                 */ 
86                virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
87        private:
88                visual_dataIO* dataIO;
89        };
90        osg::ref_ptr<dataIO_eventCallback> eventCallback;
91
92        class dataIO_finalDrawCallback : public osg::Camera::DrawCallback
93        {
94        public:
95                /**
96                 * \brief Constructor
97                 *
98                 */ 
99                dataIO_finalDrawCallback::dataIO_finalDrawCallback(visual_dataIO* dataIO_):dataIO(dataIO_){};
100               
101                /**
102                 * \brief Operator executed at callback
103                 *
104                 */ 
105                virtual void operator () (const osg::Camera& camera) const;
106        private:
107                visual_dataIO* dataIO;
108        };
109
110        osg::ref_ptr<dataIO_finalDrawCallback> finalDrawCallback;
111
112        // Make Constructor private to prevent creating instances via ptr* = new ..().
113        visual_dataIO();
114        // Make Copy-Constructor private to prevent getting instances via copying dataIO instance.
115        visual_dataIO(const visual_dataIO& cc);
116
117        osg::ref_ptr<dataIO_extLink> extLink;
118        osg::ref_ptr<dataIO_cluster> cluster;
119
120        /**
121         * Referenced Pointer to the applications viewer.
122         */ 
123        osg::ref_ptr<osgViewer::Viewer> viewer;
124
125        osg::ref_ptr<osgVisual::dataIO_transportContainer> slotContainer;
126
127        /**
128         * List of SLOT variables dataIO provides.
129         */ 
130        std::vector<dataIO_slot> dataSlots;
131
132        friend dataIO_eventCallback;
133        friend dataIO_finalDrawCallback;
134
135public:
136        // Public destructor to allow singleton cleanup from extern
137        ~visual_dataIO();
138
139        /**
140         * \brief This function returns an pointer to the singleton instalce of dataIO. If now instance exist, it will be instantiated silently.
141         *
142         * After instantiation, dataIO still needs to bei initiialized to configure working mode etc!
143         *
144         * @return : Pointer to the instance.
145         */ 
146        static visual_dataIO* getInstance();
147
148        void init(osgViewer::Viewer* viewer_,osg::ArgumentParser& arguments_);
149        void shutdown();
150        bool isMaster(){if (clusterMode==osgVisual::dataIO_cluster::MASTER) return true; else return false;};
151        bool isSlave(){if (clusterMode==osgVisual::dataIO_cluster::SLAVE) return true; else return false;};
152        bool isStandalone(){if (clusterMode==osgVisual::dataIO_cluster::STANDALONE) return true; else return false;};
153
154// SLOT Access functions
155        void* getSlotPointer(std::string slotName_, osgVisual::dataIO_slot::dataDirection direction_, osgVisual::dataIO_slot::varType variableTyp_ );
156        double getSlotDataAsDouble(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_ );
157        std::string getSlotDataAsString(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_ );
158        void setSlotData(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_, std::string sValue_ );
159        void setSlotData(std::string variableName_, osgVisual::dataIO_slot::dataDirection direction_, double value_ );
160
161        int getSlotNum() {return dataSlots.size();}
162
163        osgVisual::dataIO_cluster::clustermode clusterMode;
164
165        bool initialized;
166};
167
168
169} // END namespace osgVisual
Note: See TracBrowser for help on using the repository browser.