server/segment.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "segment.h"
00019
00020 #include "canvas.h"
00021 #include "channel.h"
00022 #include "config.h"
00023 #include "paths.h"
00024 #include "view.h"
00025
00026 #include <eq/net/dataOStream.h>
00027
00028 using namespace eq::base;
00029
00030 namespace eq
00031 {
00032 namespace server
00033 {
00034
00035 Segment::Segment()
00036 : _canvas( 0 )
00037 , _channel( 0 )
00038 {
00039 EQINFO << "New segment @" << (void*)this << std::endl;
00040 }
00041
00042 Segment::Segment( const Segment& from, Config* config )
00043 : eq::Segment( from )
00044 , _canvas( 0 )
00045 , _channel( 0 )
00046 {
00047 if( from._channel )
00048 {
00049 const Channel* oldChannel = from._channel;
00050 const ChannelPath path( oldChannel->getPath( ));
00051
00052 _channel = config->getChannel( path );
00053 EQASSERT( _channel );
00054 }
00055
00056 for( ChannelVector::const_iterator i = from._destinationChannels.begin();
00057 i != from._destinationChannels.end(); ++i )
00058 {
00059 const Channel* oldChannel = *i;
00060 const ChannelPath channelPath( oldChannel->getPath( ));
00061
00062 Channel* newChannel = config->getChannel( channelPath );
00063 EQASSERT( newChannel );
00064
00065 const View* oldView = oldChannel->getView();
00066 EQASSERT( oldView );
00067 const ViewPath viewPath( oldView->getPath( ));
00068
00069 View* newView = config->getView( viewPath );
00070 EQASSERT( newView );
00071
00072 newChannel->setOutput( newView, this );
00073 }
00074
00075 EQINFO << "Copy segment @" << (void*)this << std::endl;
00076 }
00077
00078 Segment::~Segment()
00079 {
00080 EQINFO << "Delete segment @" << (void*)this << std::endl;
00081
00082
00083 ChannelVector destinationChannels = _destinationChannels;
00084 for( ChannelVector::const_iterator i = destinationChannels.begin();
00085 i != destinationChannels.end(); ++i )
00086 {
00087 Channel* channel = *i;
00088 channel->unsetOutput();
00089 }
00090
00091 EQASSERT( _destinationChannels.empty( ));
00092 _destinationChannels.clear();
00093 _channel = 0;
00094 _canvas = 0;
00095 }
00096
00097 void Segment::getInstanceData( net::DataOStream& os )
00098 {
00099
00100
00101
00102
00103 const uint64_t dirty = DIRTY_CUSTOM - 1;
00104 os << dirty;
00105 serialize( os, dirty );
00106 }
00107
00108 Config* Segment::getConfig()
00109 {
00110 EQASSERT( _canvas );
00111 return _canvas ? _canvas->getConfig() : 0;
00112 }
00113
00114
00115 const Config* Segment::getConfig() const
00116 {
00117 EQASSERT( _canvas );
00118 return _canvas ? _canvas->getConfig() : 0;
00119 }
00120
00121 void Segment::setViewport( const eq::Viewport& vp )
00122 {
00123 _vp = vp;
00124 setDirty( DIRTY_VIEWPORT );
00125 }
00126
00127 void Segment::addDestinationChannel( Channel* channel )
00128 {
00129 EQASSERT( std::find( _destinationChannels.begin(),
00130 _destinationChannels.end(), channel ) ==
00131 _destinationChannels.end( ));
00132
00133 _destinationChannels.push_back( channel );
00134 }
00135
00136 bool Segment::removeDestinationChannel( Channel* channel )
00137 {
00138 ChannelVector::iterator i = find( _destinationChannels.begin(),
00139 _destinationChannels.end(), channel );
00140
00141 EQASSERT( i != _destinationChannels.end( ));
00142 if( i == _destinationChannels.end( ))
00143 return false;
00144
00145 _destinationChannels.erase( i );
00146
00147 EQASSERT( std::find( _destinationChannels.begin(),
00148 _destinationChannels.end(), channel ) ==
00149 _destinationChannels.end( ));
00150 return true;
00151 }
00152
00153 SegmentPath Segment::getPath() const
00154 {
00155 EQASSERT( _canvas );
00156 SegmentPath path( _canvas->getPath( ));
00157
00158 const SegmentVector& segments = _canvas->getSegments();
00159 SegmentVector::const_iterator i = std::find( segments.begin(),
00160 segments.end(), this );
00161 EQASSERT( i != segments.end( ));
00162 path.segmentIndex = std::distance( segments.begin(), i );
00163 return path;
00164 }
00165
00166 std::ostream& operator << ( std::ostream& os, const Segment* segment)
00167 {
00168 if( !segment )
00169 return os;
00170
00171 os << disableFlush << disableHeader << "segment" << std::endl;
00172 os << "{" << std::endl << indent;
00173
00174 const std::string& name = segment->getName();
00175 if( !name.empty( ))
00176 os << "name \"" << name << "\"" << std::endl;
00177
00178 const Channel* channel = segment->getChannel();
00179 if( channel && !channel->getName().empty( ))
00180 os << "channel \"" << channel->getName() << "\"" << std::endl;
00181
00182 const eq::Viewport& vp = segment->getViewport();
00183 if( vp.isValid( ) && vp != eq::Viewport::FULL )
00184 os << "viewport " << vp << std::endl;
00185
00186 os << static_cast< const eq::Frustum& >( *segment );
00187
00188 os << exdent << "}" << std::endl << enableHeader << enableFlush;
00189 return os;
00190 }
00191
00192 }
00193 }