BaseObjectData.cc 9.94 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                         *
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
42 43 44 45 46 47 48 49 50 51 52 53 54 55




//=============================================================================
//
//  MyTypes
//
//=============================================================================

//== INCLUDES =================================================================

#include "Types.hh"
#include <OpenFlipper/common/GlobalOptions.hh>
56
#include <ACG/Scenegraph/SceneGraph.hh>
57 58 59 60

//== TYPEDEFS =================================================================

//== CLASS DEFINITION =========================================================
61

62 63 64
BaseObjectData::BaseObjectData(const BaseObjectData& _object)
  : BaseObject(_object),
    path_("."),
65
    manipPlaced_(false),
66 67 68
    rootNode_(_object.rootNode_),
    separatorNode_(0),
    manipulatorNode_(0),
69
    materialNode_(0),
70 71
    boundingBoxNode_(0),
    stencilRefNode_(0)
72 73 74 75 76
{
  // We have to create our own visualization nodes as we are a new object
  init();
}

77 78 79
BaseObjectData::BaseObjectData( SeparatorNode* _rootNode ) :
  BaseObject(),
  path_("."),
80
  manipPlaced_(false),
81
  rootNode_(_rootNode),
82 83
  separatorNode_(0),
  manipulatorNode_(0),
84
  materialNode_(0),
85 86
  boundingBoxNode_(0),
  stencilRefNode_(0)
87 88 89 90 91 92 93 94
{
  init();
}

BaseObjectData::~BaseObjectData() {
  if ( separatorNode_ != 0 ) {
    separatorNode_->delete_subtree();
  }
95

96 97 98 99
}

void BaseObjectData::cleanup() {
  path_       = ".";
100

101 102 103 104 105 106 107 108
  // Delete everything below the seperator node on top of the object. This will remove the complete subtree.
  if ( separatorNode_ == 0 )
    std::cerr << "cleanup : separatorNode_ is already 0" << std::endl;
  else {
    separatorNode_->delete_subtree();
    separatorNode_   = 0;
    manipulatorNode_ = 0;
    materialNode_    = 0;
109
    boundingBoxNode_ = 0;
110 111
    additionalNodes_.clear();
  }
112

113
  BaseObject::cleanup();
114

115 116 117 118 119 120 121
  BaseObjectData::init();
}

void BaseObjectData::init() {
  // Create seperatorNode for Object only if it does not exist.
  if ( separatorNode_ == 0 )
    separatorNode_       = new SeparatorNode((BaseNode*)rootNode_,"NEW Object");
122
  else
123
    std::cerr << "Separator Node already exists. this should not happen!" << std::endl;
124

125
  if ( manipulatorNode_ == 0 ) {
126
    manipulatorNode_      = new QtTranslationManipulatorNode(baseNode(),"NEW ManipulatorNode");
127 128 129

    // Bind this manipulator to the current object
    manipulatorNode_->setIdentifier(id());
130
    manipulatorNode_->set_status( ACG::SceneGraph::TranslationManipulatorNode::HideNode );
131
  }
132
  else
133
    std::cerr << "Manipulator Node already exists. this should not happen!" << std::endl;
134 135 136 137 138
  if ( boundingBoxNode_ == 0)
  {
    boundingBoxNode_      = new BoundingBoxNode(manipulatorNode(),  "New Bounding Box");
    boundingBoxNode_->set_status( ACG::SceneGraph::BaseNode::HideNode );
  }
139 140
  if ( stencilRefNode_ == 0 )
  {
141
    stencilRefNode_       = new StencilRefNode(boundingBoxNode(),  "New Stencil Reference");
142 143
    stencilRefNode_->set_status( ACG::SceneGraph::BaseNode::HideNode );
  }
144 145
  if ( materialNode_ == 0 )
    materialNode_         = new MaterialNode(stencilRefNode(),  "New Material");
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
}


// ===============================================================================
// Name and path Handling
// ===============================================================================

void BaseObjectData::setFromFileName(QString _filename ) {
  QString str = _filename;
  path_ = str.section(OpenFlipper::Options::dirSeparator(),0,-2);
  setName(str.section(OpenFlipper::Options::dirSeparator(),-1));
}

void BaseObjectData::setName( QString _name ) {
  BaseObject::setName( _name );
161

162 163
  std::string nodename = std::string("SeparatorNode for object " + _name.toUtf8());
  separatorNode_->name( nodename );
164

165 166
  nodename = std::string("ManipulatorNode for object " + _name.toUtf8());
  manipulatorNode_->name( nodename );
167

168 169 170
  nodename = std::string("BoundingBoxNode for object " + _name.toUtf8());
  boundingBoxNode_->name( nodename );

171 172
  nodename = std::string(_name.toUtf8() + "'s Material" );
  materialNode_->name( nodename );
173 174 175

  nodename = std::string("StencilRefNode for object " + _name.toUtf8());
  stencilRefNode_->name( nodename );
176 177 178 179 180 181 182 183
}


QString BaseObjectData::path(){
  return path_;
}

void BaseObjectData::path(QString _path ) {
184
  path_ = _path;
185 186 187 188 189 190 191
}

// ===============================================================================
// Object visualization
// ===============================================================================

void BaseObjectData::show() {
192
  separatorNode_->set_status( ACG::SceneGraph::BaseNode::Active  );
193 194 195 196
  visible_ = true;
}

void BaseObjectData::hide() {
197
  separatorNode_->set_status( ACG::SceneGraph::BaseNode::HideSubtree );
198 199 200
  visible_ = false;
}

201 202 203 204 205 206 207 208 209 210 211 212 213 214
bool BaseObjectData::visible(){
  return visible_;
}

void BaseObjectData::visible(bool _visible) {

  if (_visible)
    separatorNode_->set_status( ACG::SceneGraph::BaseNode::Active  );
  else
    separatorNode_->set_status( ACG::SceneGraph::BaseNode::HideSubtree );

  visible_ = _visible;
}

215
SeparatorNode* BaseObjectData::baseNode() {
216
  return separatorNode_;
217 218
}

219
QtTranslationManipulatorNode* BaseObjectData::manipulatorNode() {
220 221 222 223 224
  return manipulatorNode_;
}

ACG::SceneGraph::ShaderNode* BaseObjectData::shaderNode() {
  return 0;
225 226 227
}

MaterialNode* BaseObjectData::materialNode() {
228
  return materialNode_;
229 230
}

231 232 233 234
BoundingBoxNode* BaseObjectData::boundingBoxNode() {
  return boundingBoxNode_;
}

235 236 237 238
StencilRefNode* BaseObjectData::stencilRefNode() {
  return stencilRefNode_;
}

239

240
void BaseObjectData::setBaseColor(ACG::Vec4f _color) {
241
  materialNode_->set_base_color(_color);
242 243 244 245 246 247 248 249 250 251
}

bool BaseObjectData::manipPlaced() {
  return manipPlaced_;
}

void BaseObjectData::manipPlaced( bool _placed ) {
  manipPlaced_ = _placed;
}

252 253 254 255 256 257 258 259 260 261
void BaseObjectData::getBoundingBox(ACG::Vec3d& bbmin, ACG::Vec3d& bbmax){

  ACG::SceneGraph::BoundingBoxAction act;
  ACG::SceneGraph::traverse(separatorNode_, act);


  bbmin = (ACG::Vec3d) act.bbMin();
  bbmax = (ACG::Vec3d) act.bbMax();
}

262
// ===============================================================================
263
// Picking
264 265 266
// ===============================================================================

bool BaseObjectData::picked( uint /* _node_idx */ ) {
267
 return false;
268 269
}

270 271 272 273 274 275 276
void BaseObjectData::enablePicking( bool /*_enable*/ ) {
}

bool BaseObjectData::pickingEnabled() {
  return true;
}

277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
// ===============================================================================
// Content Nodes
// ===============================================================================
void BaseObjectData::update()
{

}

// ===============================================================================
// Additional Nodes
// ===============================================================================

bool BaseObjectData::hasAdditionalNode(QString _pluginName, QString _nodeName , int _id )
{
  QString index;
  index.setNum(_id);
  QString searchname = _pluginName+"#"+_nodeName+"#"+index;
294

295 296 297 298
  for ( uint i =0 ; i < additionalNodes_.size() ; ++i ) {
    if (additionalNodes_[i].second == searchname )
      return true;
  }
299

300 301 302
  return false;
}

303

304
//=============================================================================