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 | } |
---|
27 | |
---|
28 | dataIO_extLinkVCL::~dataIO_extLinkVCL(void) |
---|
29 | { |
---|
30 | OSG_NOTIFY( osg::ALWAYS ) << "extLinkVCL destroyed" << std::endl; |
---|
31 | } |
---|
32 | |
---|
33 | void dataIO_extLinkVCL::init() |
---|
34 | { |
---|
35 | OSG_NOTIFY( osg::ALWAYS ) << "extLinkVCL init()" << std::endl; |
---|
36 | |
---|
37 | std::string VCLConfigFilename = "osgVisual.xml"; |
---|
38 | if ( osgDB::fileExists( VCLConfigFilename ) ) |
---|
39 | { |
---|
40 | CVCLIO::GetInstance().LoadProject(VCLConfigFilename.c_str()); |
---|
41 | bool error = false; |
---|
42 | |
---|
43 | if( !SAENGER1_POS_LAT.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER1_POS_LAT") ) |
---|
44 | error = true; |
---|
45 | if( !SAENGER1_POS_LON.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER1_POS_LON") ) |
---|
46 | error = true; |
---|
47 | if( !SAENGER1_POS_ALT.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER1_POS_ALT") ) |
---|
48 | error = true; |
---|
49 | if( !SAENGER1_ROT_X.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER1_ROT_X") ) |
---|
50 | error = true; |
---|
51 | if( !SAENGER1_ROT_Y.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER1_ROT_Y") ) |
---|
52 | error = true; |
---|
53 | if( !SAENGER1_ROT_Z.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER1_ROT_Z") ) |
---|
54 | error = true; |
---|
55 | |
---|
56 | if( !SAENGER2_POS_LAT.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER2_POS_LAT") ) |
---|
57 | error = true; |
---|
58 | if( !SAENGER2_POS_LON.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER2_POS_LON") ) |
---|
59 | error = true; |
---|
60 | if( !SAENGER2_POS_ALT.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER2_POS_ALT") ) |
---|
61 | error = true; |
---|
62 | if( !SAENGER2_ROT_X.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER2_ROT_X") ) |
---|
63 | error = true; |
---|
64 | if( !SAENGER2_ROT_Y.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER2_ROT_Y") ) |
---|
65 | error = true; |
---|
66 | if( !SAENGER2_ROT_Z.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER2_ROT_Z") ) |
---|
67 | error = true; |
---|
68 | |
---|
69 | if( !SAENGER_POS_LAT.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER_POS_LAT") ) |
---|
70 | error = true; |
---|
71 | if( !SAENGER_POS_LON.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER_POS_LON") ) |
---|
72 | error = true; |
---|
73 | if( !SAENGER_POS_ALT.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER_POS_ALT") ) |
---|
74 | error = true; |
---|
75 | if( !SAENGER_ROT_X.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER_ROT_X") ) |
---|
76 | error = true; |
---|
77 | if( !SAENGER_ROT_Y.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER_ROT_Y") ) |
---|
78 | error = true; |
---|
79 | if( !SAENGER_ROT_Z.Attach("VISENGINE_CAMERA_CHANNEL", "SAENGER_ROT_Z") ) |
---|
80 | error = true; |
---|
81 | |
---|
82 | if (error) |
---|
83 | OSG_NOTIFY( osg::FATAL ) << "ERROR: An error occured while attaching VCL." << std::endl; |
---|
84 | initialized = true; |
---|
85 | } |
---|
86 | else |
---|
87 | { |
---|
88 | OSG_NOTIFY( osg::FATAL ) << "ERROR: Could not find VCL Configuration file " << VCLConfigFilename << std::endl; |
---|
89 | exit(-1); |
---|
90 | } |
---|
91 | |
---|
92 | } |
---|
93 | |
---|
94 | void dataIO_extLinkVCL::shutdown() |
---|
95 | { |
---|
96 | OSG_NOTIFY( osg::ALWAYS ) << "extLinkVCL shutdown()" << std::endl; |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | bool dataIO_extLinkVCL::readTO_OBJvalues() |
---|
101 | { |
---|
102 | OSG_NOTIFY( osg::INFO ) << "extLinkVCL readTO_OBJvalues()" << std::endl; |
---|
103 | |
---|
104 | // perform external data exchange |
---|
105 | CVCLIO::GetInstance().DoDataExchange(); |
---|
106 | |
---|
107 | // Copy data from VCL variables to slot variables: |
---|
108 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER1_POS_LAT", osgVisual::dataIO_slot::TO_OBJ, SAENGER1_POS_LAT.GetValue() ); |
---|
109 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER1_POS_LON", osgVisual::dataIO_slot::TO_OBJ, SAENGER1_POS_LON.GetValue() ); |
---|
110 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER1_POS_ALT", osgVisual::dataIO_slot::TO_OBJ, -SAENGER1_POS_ALT.GetValue() ); // Negatives Vorzeichen da Z-Koordinaten anders herum. |
---|
111 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER1_ROT_X", osgVisual::dataIO_slot::TO_OBJ, SAENGER1_ROT_X.GetValue() ); |
---|
112 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER1_ROT_Y", osgVisual::dataIO_slot::TO_OBJ, SAENGER1_ROT_Y.GetValue() ); |
---|
113 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER1_ROT_Z", osgVisual::dataIO_slot::TO_OBJ, SAENGER1_ROT_Z.GetValue() ); |
---|
114 | |
---|
115 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER2_POS_LAT", osgVisual::dataIO_slot::TO_OBJ, SAENGER2_POS_LAT.GetValue() ); |
---|
116 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER2_POS_LON", osgVisual::dataIO_slot::TO_OBJ, SAENGER2_POS_LON.GetValue() ); |
---|
117 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER2_POS_ALT", osgVisual::dataIO_slot::TO_OBJ, -SAENGER2_POS_ALT.GetValue() ); // Negatives Vorzeichen da Z-Koordinaten anders herum. |
---|
118 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER2_ROT_X", osgVisual::dataIO_slot::TO_OBJ, SAENGER2_ROT_X.GetValue() ); |
---|
119 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER2_ROT_Y", osgVisual::dataIO_slot::TO_OBJ, SAENGER2_ROT_Y.GetValue() ); |
---|
120 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER2_ROT_Z", osgVisual::dataIO_slot::TO_OBJ, SAENGER2_ROT_Z.GetValue() ); |
---|
121 | |
---|
122 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER_POS_LAT", osgVisual::dataIO_slot::TO_OBJ, SAENGER_POS_LAT.GetValue() ); |
---|
123 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER_POS_LON", osgVisual::dataIO_slot::TO_OBJ, SAENGER_POS_LON.GetValue() ); |
---|
124 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER_POS_ALT", osgVisual::dataIO_slot::TO_OBJ, -SAENGER_POS_ALT.GetValue() ); // Negatives Vorzeichen da Z-Koordinaten anders herum. |
---|
125 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER_ROT_X", osgVisual::dataIO_slot::TO_OBJ, SAENGER_ROT_X.GetValue() ); |
---|
126 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER_ROT_Y", osgVisual::dataIO_slot::TO_OBJ, SAENGER_ROT_Y.GetValue() ); |
---|
127 | osgVisual::visual_dataIO::getInstance()->setSlotData( "SAENGER_ROT_Z", osgVisual::dataIO_slot::TO_OBJ, SAENGER_ROT_Z.GetValue() ); |
---|
128 | |
---|
129 | //OSG_NOTIFY( osg::ALWAYS ) << "LAT: " << osgVisual::visual_dataIO::getInstance()->getSlotDataAsDouble("SAENGER1_POS_LAT", osgVisual::dataIO_slot::TO_OBJ ) << std::endl; |
---|
130 | return true; |
---|
131 | } |
---|
132 | |
---|
133 | bool dataIO_extLinkVCL::writebackFROM_OBJvalues() |
---|
134 | { |
---|
135 | OSG_NOTIFY( osg::INFO ) << "extLinkVCL writebackFROM_OBJvalues()" << std::endl; |
---|
136 | |
---|
137 | // Copy slot data to variables |
---|
138 | // Nothing to do |
---|
139 | // Example: MY_CHANNEL.setValue( myValue ); |
---|
140 | |
---|
141 | /* In VCL no writeback transaction is done, |
---|
142 | it is postponed until the next frame beginning, |
---|
143 | where TO_OBJ exchange calls CVCLIO::GetInstance().DoDataExchange();. |
---|
144 | */ |
---|
145 | return true; |
---|
146 | } |
---|