1 | /* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer |
---|
2 | * |
---|
3 | * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under |
---|
4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
---|
5 | * (at your option) any later version. The full license is in LICENSE file |
---|
6 | * included with this distribution, and on the openscenegraph.org website. |
---|
7 | * |
---|
8 | * osgVisual requires for some proprietary modules a license from the correspondig manufacturer. |
---|
9 | * You have to aquire licenses for all used proprietary modules. |
---|
10 | * |
---|
11 | * This library is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * OpenSceneGraph Public License for more details. |
---|
15 | */ |
---|
16 | |
---|
17 | #include <dataIO_extLinkVCL.h> |
---|
18 | |
---|
19 | #include <visual_dataIO.h> // include in.cpp to avoid circular inclusion (visual_dataIO <-> extLinkVCL) |
---|
20 | |
---|
21 | using namespace osgVisual; |
---|
22 | |
---|
23 | dataIO_extLinkVCL::dataIO_extLinkVCL(std::vector<dataIO_slot>& dataSlots_) : dataIO_extLink(dataSlots_) |
---|
24 | { |
---|
25 | OSG_NOTIFY( osg::ALWAYS ) << "extLinkVCL constructed" << std::endl; |
---|
26 | #include <leakDetection.h> |
---|
27 | } |
---|
28 | |
---|
29 | dataIO_extLinkVCL::~dataIO_extLinkVCL(void) |
---|
30 | { |
---|
31 | OSG_NOTIFY( osg::ALWAYS ) << "extLinkVCL destroyed" << std::endl; |
---|
32 | } |
---|
33 | |
---|
34 | void dataIO_extLinkVCL::init() |
---|
35 | { |
---|
36 | OSG_NOTIFY( osg::ALWAYS ) << "extLinkVCL init()" << std::endl; |
---|
37 | |
---|
38 | std::string VCLConfigFilename = "osgVisual.xml"; |
---|
39 | if ( osgDB::fileExists( VCLConfigFilename ) ) |
---|
40 | { |
---|
41 | CVCLIO::GetInstance().LoadProject(VCLConfigFilename.c_str()); |
---|
42 | bool error = false; |
---|
43 | |
---|
44 | if( !SAENGER1_POS_LAT.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER1_POS_LAT") ) |
---|
45 | error = true; |
---|
46 | if( !SAENGER1_POS_LON.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER1_POS_LON") ) |
---|
47 | error = true; |
---|
48 | if( !SAENGER1_POS_ALT.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER1_POS_ALT") ) |
---|
49 | error = true; |
---|
50 | if( !SAENGER1_ROT_X.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER1_ROT_X") ) |
---|
51 | error = true; |
---|
52 | if( !SAENGER1_ROT_Y.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER1_ROT_Y") ) |
---|
53 | error = true; |
---|
54 | if( !SAENGER1_ROT_Z.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER1_ROT_Z") ) |
---|
55 | error = true; |
---|
56 | |
---|
57 | if( !SAENGER2_POS_LAT.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER2_POS_LAT") ) |
---|
58 | error = true; |
---|
59 | if( !SAENGER2_POS_LON.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER2_POS_LON") ) |
---|
60 | error = true; |
---|
61 | if( !SAENGER2_POS_ALT.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER2_POS_ALT") ) |
---|
62 | error = true; |
---|
63 | if( !SAENGER2_ROT_X.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER2_ROT_X") ) |
---|
64 | error = true; |
---|
65 | if( !SAENGER2_ROT_Y.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER2_ROT_Y") ) |
---|
66 | error = true; |
---|
67 | if( !SAENGER2_ROT_Z.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER2_ROT_Z") ) |
---|
68 | error = true; |
---|
69 | |
---|
70 | if( !SAENGER_POS_LAT.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER_POS_LAT") ) |
---|
71 | error = true; |
---|
72 | if( !SAENGER_POS_LON.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER_POS_LON") ) |
---|
73 | error = true; |
---|
74 | if( !SAENGER_POS_ALT.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER_POS_ALT") ) |
---|
75 | error = true; |
---|
76 | if( !SAENGER_ROT_X.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER_ROT_X") ) |
---|
77 | error = true; |
---|
78 | if( !SAENGER_ROT_Y.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER_ROT_Y") ) |
---|
79 | error = true; |
---|
80 | if( !SAENGER_ROT_Z.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER_ROT_Z") ) |
---|
81 | error = true; |
---|
82 | |
---|
83 | if (error) |
---|
84 | OSG_NOTIFY( osg::FATAL ) << "ERROR: An error occured while attaching VCL." << std::endl; |
---|
85 | initialized = true; |
---|
86 | } |
---|
87 | else |
---|
88 | { |
---|
89 | OSG_NOTIFY( osg::FATAL ) << "ERROR: Could not find VCL Configuration file " << VCLConfigFilename << std::endl; |
---|
90 | exit(-1); |
---|
91 | } |
---|
92 | |
---|
93 | } |
---|
94 | |
---|
95 | void dataIO_extLinkVCL::shutdown() |
---|
96 | { |
---|
97 | OSG_NOTIFY( osg::ALWAYS ) << "extLinkVCL shutdown()" << std::endl; |
---|
98 | } |
---|
99 | |
---|
100 | |
---|
101 | bool dataIO_extLinkVCL::readTO_OBJvalues() |
---|
102 | { |
---|
103 | OSG_NOTIFY( osg::INFO ) << "extLinkVCL readTO_OBJvalues()" << std::endl; |
---|
104 | |
---|
105 | // perform external data exchange |
---|
106 | CVCLIO::GetInstance().DoDataExchange(); |
---|
107 | |
---|
108 | // Copy data from VCL variables to slot variables: |
---|
109 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER1_POS_LAT", osgVisual::dataIO_slot::TO_OBJ, SAENGER1_POS_LAT.GetValue() ); |
---|
110 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER1_POS_LON", osgVisual::dataIO_slot::TO_OBJ, SAENGER1_POS_LON.GetValue() ); |
---|
111 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER1_POS_ALT", osgVisual::dataIO_slot::TO_OBJ, -SAENGER1_POS_ALT.GetValue() ); // Negatives Vorzeichen da Z-Koordinaten anders herum. |
---|
112 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER1_ROT_X", osgVisual::dataIO_slot::TO_OBJ, SAENGER1_ROT_X.GetValue() ); |
---|
113 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER1_ROT_Y", osgVisual::dataIO_slot::TO_OBJ, SAENGER1_ROT_Y.GetValue() ); |
---|
114 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER1_ROT_Z", osgVisual::dataIO_slot::TO_OBJ, SAENGER1_ROT_Z.GetValue() ); |
---|
115 | |
---|
116 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER2_POS_LAT", osgVisual::dataIO_slot::TO_OBJ, SAENGER2_POS_LAT.GetValue() ); |
---|
117 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER2_POS_LON", osgVisual::dataIO_slot::TO_OBJ, SAENGER2_POS_LON.GetValue() ); |
---|
118 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER2_POS_ALT", osgVisual::dataIO_slot::TO_OBJ, -SAENGER2_POS_ALT.GetValue() ); // Negatives Vorzeichen da Z-Koordinaten anders herum. |
---|
119 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER2_ROT_X", osgVisual::dataIO_slot::TO_OBJ, SAENGER2_ROT_X.GetValue() ); |
---|
120 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER2_ROT_Y", osgVisual::dataIO_slot::TO_OBJ, SAENGER2_ROT_Y.GetValue() ); |
---|
121 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER2_ROT_Z", osgVisual::dataIO_slot::TO_OBJ, SAENGER2_ROT_Z.GetValue() ); |
---|
122 | |
---|
123 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER_POS_LAT", osgVisual::dataIO_slot::TO_OBJ, SAENGER_POS_LAT.GetValue() ); |
---|
124 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER_POS_LON", osgVisual::dataIO_slot::TO_OBJ, SAENGER_POS_LON.GetValue() ); |
---|
125 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER_POS_ALT", osgVisual::dataIO_slot::TO_OBJ, -SAENGER_POS_ALT.GetValue() ); // Negatives Vorzeichen da Z-Koordinaten anders herum. |
---|
126 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER_ROT_X", osgVisual::dataIO_slot::TO_OBJ, SAENGER_ROT_X.GetValue() ); |
---|
127 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER_ROT_Y", osgVisual::dataIO_slot::TO_OBJ, SAENGER_ROT_Y.GetValue() ); |
---|
128 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER_ROT_Z", osgVisual::dataIO_slot::TO_OBJ, SAENGER_ROT_Z.GetValue() ); |
---|
129 | |
---|
130 | //OSG_NOTIFY( osg::ALWAYS ) << "LAT: " << osgVisual::visual_dataIO::getInstance()->getSlotDataAsDouble("SAENGER1_POS_LAT", osgVisual::dataIO_slot::TO_OBJ ) << std::endl; |
---|
131 | return true; |
---|
132 | } |
---|
133 | |
---|
134 | bool dataIO_extLinkVCL::writebackFROM_OBJvalues() |
---|
135 | { |
---|
136 | OSG_NOTIFY( osg::INFO ) << "extLinkVCL writebackFROM_OBJvalues()" << std::endl; |
---|
137 | |
---|
138 | // Copy slot data to variables |
---|
139 | // Nothing to do |
---|
140 | // Example: MY_CHANNEL.setValue( myValue ); |
---|
141 | |
---|
142 | /* In VCL no writeback transaction is done, |
---|
143 | it is postponed until the next frame beginning, |
---|
144 | where TO_OBJ exchange calls CVCLIO::GetInstance().DoDataExchange();. |
---|
145 | */ |
---|
146 | return true; |
---|
147 | } |
---|