BaseObjectData.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #include "Types.hh"
00055 #include <ACG/Scenegraph/SceneGraph.hh>
00056 #include <OpenFlipper/common/BaseObjectCore.hh>
00057 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
00058 #include <QDir>
00059
00060
00061
00062
00063
00064
00065
00066 BaseObjectData::BaseObjectData(const BaseObjectData& _object)
00067 : BaseObject(_object),
00068 path_("."),
00069 manipPlaced_(false),
00070 rootNode_(_object.rootNode_),
00071 separatorNode_(0),
00072 manipulatorNode_(0),
00073 materialNode_(0),
00074 boundingBoxNode_(0),
00075 stencilRefNode_(0)
00076 {
00077
00078 init();
00079 }
00080
00081 BaseObjectData::BaseObjectData() :
00082 BaseObject(),
00083 path_("."),
00084 manipPlaced_(false),
00085 rootNode_( dynamic_cast< ACG::SceneGraph::SeparatorNode* > (PluginFunctions::getRootNode()) ),
00086 separatorNode_(0),
00087 manipulatorNode_(0),
00088 materialNode_(0),
00089 boundingBoxNode_(0),
00090 stencilRefNode_(0)
00091 {
00092 init();
00093 }
00094
00095 BaseObjectData::~BaseObjectData() {
00096 if ( separatorNode_ != 0 ) {
00097 separatorNode_->delete_subtree();
00098 }
00099
00100 }
00101
00102 void BaseObjectData::cleanup() {
00103 path_ = ".";
00104
00105
00106 if ( separatorNode_ == 0 )
00107 std::cerr << "cleanup : separatorNode_ is already 0" << std::endl;
00108 else {
00109 separatorNode_->delete_subtree();
00110 separatorNode_ = 0;
00111 manipulatorNode_ = 0;
00112 materialNode_ = 0;
00113 boundingBoxNode_ = 0;
00114 additionalNodes_.clear();
00115 }
00116
00117 BaseObject::cleanup();
00118
00119 BaseObjectData::init();
00120 }
00121
00122 void BaseObjectData::init() {
00123
00124 if ( separatorNode_ == 0 )
00125 separatorNode_ = new SeparatorNode((BaseNode*)rootNode_,"NEW Object");
00126 else
00127 std::cerr << "Separator Node already exists. this should not happen!" << std::endl;
00128
00129 if ( manipulatorNode_ == 0 ) {
00130 manipulatorNode_ = new QtTranslationManipulatorNode(baseNode(),"NEW ManipulatorNode");
00131
00132
00133 manipulatorNode_->setIdentifier(id());
00134 manipulatorNode_->set_status( ACG::SceneGraph::TranslationManipulatorNode::HideNode );
00135 }
00136 else
00137 std::cerr << "Manipulator Node already exists. this should not happen!" << std::endl;
00138 if ( boundingBoxNode_ == 0)
00139 {
00140 boundingBoxNode_ = new BoundingBoxNode(manipulatorNode(), "New Bounding Box");
00141 boundingBoxNode_->set_status( ACG::SceneGraph::BaseNode::HideNode );
00142 }
00143 if ( stencilRefNode_ == 0 )
00144 {
00145 stencilRefNode_ = new StencilRefNode(boundingBoxNode(), "New Stencil Reference");
00146 stencilRefNode_->set_status( ACG::SceneGraph::BaseNode::HideNode );
00147 }
00148 if ( materialNode_ == 0 )
00149 materialNode_ = new MaterialNode(stencilRefNode(), "New Material");
00150 }
00151
00152
00153
00154
00155
00156
00157 void BaseObjectData::setFromFileName(QString _filename ) {
00158 QString str = _filename;
00159 path_ = str.section(QDir::separator() ,0,-2);
00160 setName(str.section(QDir::separator(),-1));
00161 }
00162
00163 void BaseObjectData::setName( QString _name ) {
00164 BaseObject::setName( _name );
00165
00166 std::string nodename = std::string("SeparatorNode for object " + _name.toUtf8());
00167 separatorNode_->name( nodename );
00168
00169 nodename = std::string("ManipulatorNode for object " + _name.toUtf8());
00170 manipulatorNode_->name( nodename );
00171
00172 nodename = std::string("BoundingBoxNode for object " + _name.toUtf8());
00173 boundingBoxNode_->name( nodename );
00174
00175 nodename = std::string(_name.toUtf8() + "'s Material" );
00176 materialNode_->name( nodename );
00177
00178 nodename = std::string("StencilRefNode for object " + _name.toUtf8());
00179 stencilRefNode_->name( nodename );
00180 }
00181
00182
00183 QString BaseObjectData::path(){
00184 return path_;
00185 }
00186
00187 void BaseObjectData::setPath(QString _path ) {
00188 path_ = _path;
00189 }
00190
00191
00192
00193
00194
00195 void BaseObjectData::show() {
00196 if ( !visible_ ) {
00197 separatorNode_->set_status( ACG::SceneGraph::BaseNode::Active );
00198 visible_ = true;
00199
00200 emit visibilityChanged( id() );
00201 }
00202 }
00203
00204 void BaseObjectData::hide() {
00205 if ( visible_ ) {
00206 separatorNode_->set_status( ACG::SceneGraph::BaseNode::HideSubtree );
00207 visible_ = false;
00208
00209 emit visibilityChanged( id() );
00210 }
00211 }
00212
00213 bool BaseObjectData::visible(){
00214 return visible_;
00215 }
00216
00217 void BaseObjectData::visible(bool _visible) {
00218
00219 if ( visible_ != _visible ) {
00220
00221 if (_visible)
00222 separatorNode_->set_status( ACG::SceneGraph::BaseNode::Active );
00223 else
00224 separatorNode_->set_status( ACG::SceneGraph::BaseNode::HideSubtree );
00225
00226 visible_ = _visible;
00227
00228 emit visibilityChanged( id() );
00229 }
00230 }
00231
00232 SeparatorNode* BaseObjectData::baseNode() {
00233 return separatorNode_;
00234 }
00235
00236 BaseNode* BaseObjectData::primaryNode() {
00237 return separatorNode_;
00238 }
00239
00240 QtTranslationManipulatorNode* BaseObjectData::manipulatorNode() {
00241 return manipulatorNode_;
00242 }
00243
00244 ACG::SceneGraph::ShaderNode* BaseObjectData::shaderNode() {
00245 return 0;
00246 }
00247
00248 MaterialNode* BaseObjectData::materialNode() {
00249 return materialNode_;
00250 }
00251
00252 BoundingBoxNode* BaseObjectData::boundingBoxNode() {
00253 return boundingBoxNode_;
00254 }
00255
00256 StencilRefNode* BaseObjectData::stencilRefNode() {
00257 return stencilRefNode_;
00258 }
00259
00260
00261 void BaseObjectData::setBaseColor(ACG::Vec4f _color) {
00262 materialNode_->set_base_color(_color);
00263 }
00264
00265 bool BaseObjectData::manipPlaced() {
00266 return manipPlaced_;
00267 }
00268
00269 void BaseObjectData::manipPlaced( bool _placed ) {
00270 manipPlaced_ = _placed;
00271 }
00272
00273 void BaseObjectData::getBoundingBox(ACG::Vec3d& bbmin, ACG::Vec3d& bbmax){
00274
00275
00276 ACG::SceneGraph::BoundingBoxAction act;
00277 ACG::SceneGraph::traverse(separatorNode_, act);
00278
00279
00280 bbmin = (ACG::Vec3d) act.bbMin();
00281 bbmax = (ACG::Vec3d) act.bbMax();
00282 }
00283
00284
00285
00286
00287
00288 bool BaseObjectData::picked( uint ) {
00289 return false;
00290 }
00291
00292 void BaseObjectData::enablePicking( bool ) {
00293 }
00294
00295 bool BaseObjectData::pickingEnabled() {
00296 return true;
00297 }
00298
00299
00300
00301
00302 void BaseObjectData::update()
00303 {
00304
00305 }
00306
00307
00308
00309
00310
00311 bool BaseObjectData::hasAdditionalNode(QString _pluginName, QString _nodeName , int _id )
00312 {
00313 QString index;
00314 index.setNum(_id);
00315 QString searchname = _pluginName+"#"+_nodeName+"#"+index;
00316
00317 for ( uint i =0 ; i < additionalNodes_.size() ; ++i ) {
00318 if (additionalNodes_[i].second == searchname )
00319 return true;
00320 }
00321
00322 return false;
00323 }
00324
00325
00326