BaseObjectData.hh 14.7 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
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
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40 41
\*===========================================================================*/

42 43 44 45 46 47 48 49

//=============================================================================
//
//  Types
//
//=============================================================================

/**
50
 * \file BaseObjectData.hh
51 52 53 54
 * This File contains the Basic object class for all Objects which show content vi
 * the Scenegraph.
 */

Jan Möbius's avatar
Jan Möbius committed
55
#pragma once
56

57

58 59
//== INCLUDES =================================================================

Jan Möbius's avatar
Jan Möbius committed
60
#include <OpenFlipper/common/GlobalDefines.hh>
61
#include <OpenFlipper/common/BaseObject.hh>
62
#include <vector>
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
#include <ACG/Scenegraph/PickTarget.hh>
#include <ACG/Scenegraph/DrawModes.hh>

//== FORWARD Declarations to avoid gl qt collisions =================================================================

namespace ACG {
namespace SceneGraph {

class MaterialNode;
class QtTranslationManipulatorNode;
class SeparatorNode;
class BaseNode;
class BoundingBoxNode;
class StencilRefNode;
class ShaderNode;

}
}

82 83 84 85 86

//== TYPEDEFS FOR SCENEGRAPH ===============================================
/// Materialnode
typedef ACG::SceneGraph::MaterialNode                     MaterialNode;
/// ManipulatorNode
87
typedef ACG::SceneGraph::QtTranslationManipulatorNode     QtTranslationManipulatorNode;
88 89 90 91
/// Seperator Node
typedef ACG::SceneGraph::SeparatorNode                    SeparatorNode;
/// Base Node
typedef ACG::SceneGraph::BaseNode                         BaseNode;
92 93
/// Bounding box Node
typedef ACG::SceneGraph::BoundingBoxNode                  BoundingBoxNode;
94 95
/// Stencil reference Node
typedef ACG::SceneGraph::StencilRefNode                   StencilRefNode;
96 97 98 99 100 101 102 103

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

/**
 * This is the basic Data class providing the functions common to all objects which show Objects in the SceneGraph
 */
class DLLEXPORT BaseObjectData : public BaseObject
{
104 105 106

  friend class Core;

107 108
  Q_OBJECT
  
109
  public:
110 111 112 113 114 115 116

    /** \brief copy constructor
     *
     *  Create new basic scenegraph nodes for this object
     */
    BaseObjectData(const BaseObjectData& _object);

117
    /// constructor
118
    BaseObjectData();
119 120 121

    ///destructor
    virtual ~BaseObjectData();
122

123 124 125
  private:
    /** This function creates the basic scenegraph nodes */
    void initializeScenegraphNodes();
126 127 128

  /** @} */

129 130 131
  //===========================================================================
  /** @name Data
   * @{ */
132 133 134
  //===========================================================================

  public:
135
    /** Clean all data structures of the object
136
      *
137
      * */
138
    virtual void cleanup() override;
139 140 141 142


  /** @} */

143
    virtual void setName(QString _name ) override;
144

145 146 147
  //===========================================================================
  /** @name Object visualization
   * @{ */
148 149
  //===========================================================================

150 151
  public :
    /// Sets the whole Scenegraph subtree of this node to visible
152
    virtual void show();
153

154
    /// Sets the whole Scenegraph subtree of this node to invisible
155
    virtual void hide();
156

157
    /// return visiblity
158
    virtual bool visible() override;
159 160

    /// Sets visiblity of the whole Scenegraph subtree of this node
161
    virtual void visible(bool _visible) override;
162

163 164 165 166
    /** get the base node of this object (Use this node to add custom Nodes to the Object
     * which should not be transformed with the manipulator of the Object)
     */
    SeparatorNode* baseNode();
167

168 169 170 171 172 173 174
    /** \brief Check if the given node is owned by this object
    *
    * You can overload this function and return true, if your object generated the given node. 
    * Don't forget to call this baseclass function on overload!
    */
    virtual bool hasNode(BaseNode* _node);
    
Dirk Wilden's avatar
Dirk Wilden committed
175 176 177 178
    /** get the primary node of this object (Use this node to change drawModes)
     */
    virtual BaseNode* primaryNode();
    
179 180 181
    /** get the ManipulatorNode node of this object (Use this node to add custom Nodes to the Object
     * which should be transformed with the manipulator of the Object)
     */
182
    QtTranslationManipulatorNode* manipulatorNode();
183 184 185 186 187 188 189 190

    /** Return pointer to the shader node
     * If you want to support shaders, you have to add a shader node into your scenegraph structure
     * above your object to be rendered. If you do not have a shader, just ignore this function
     * and it will return a 0 pointer.
     */
    virtual ACG::SceneGraph::ShaderNode* shaderNode();

191 192
    /// get a pointer to the materialnode
    MaterialNode* materialNode();
Heng Liu's avatar
Heng Liu committed
193
    
Jan Möbius's avatar
Jan Möbius committed
194
    /// get a const pointer to the materialnode
Heng Liu's avatar
Heng Liu committed
195
    const MaterialNode* materialNode() const;
Heng Liu's avatar
Heng Liu committed
196
    
197 198 199
    /// get a pointer to the bounding box node
    BoundingBoxNode* boundingBoxNode();

200 201 202
    /// get a pointer to the stencil reference node
    StencilRefNode* stencilRefNode();

203 204
    /// Check if the manipulator has been placed
    bool manipPlaced();
205

206 207
    /// set the manipulator place status
    void manipPlaced( bool _placed );
208 209 210

    /// get the bounding box of the object
    void getBoundingBox(ACG::Vec3d& bbmin, ACG::Vec3d& bbmax);
211
    
212 213
    /** \brief Set the draw mode for the object
     * @param _mode  The draw mode that should be active for this object
214
     * @param _force If true, the mode is set ignoring if its supported by the node and its subnodes
215
     */
Jan Möbius's avatar
Jan Möbius committed
216
    void setObjectDrawMode(const ACG::SceneGraph::DrawModes::DrawMode& _mode, const bool& _force = false);
217

218 219
  private :

220

221
    bool manipPlaced_;
222

223 224
    /// rootNode of global Scenegraph structure
    SeparatorNode*    rootNode_;
225

226 227
    /// Separator at top of Scenegraph structure used for this Object
    SeparatorNode*    separatorNode_;
228 229

    /// Manipulator used for this Object
230
    QtTranslationManipulatorNode*  manipulatorNode_;
231

232 233
    /// Scenegraph Material Node for the object
    MaterialNode*    materialNode_;
234

235 236 237
    /// Bounding box node for the object
    BoundingBoxNode * boundingBoxNode_;

238 239 240
    /// Stencil reference node for the object
    StencilRefNode* stencilRefNode_;

241 242 243
  /** @} */


244 245 246
  //===========================================================================
  /** @name Picking
   * @{ */
247 248
  //===========================================================================

249 250 251
  public :
    /// detect if the node has been picked
    virtual bool picked( uint _node_idx );
252 253 254 255 256 257 258 259 260 261 262 263

    /** Enable or disable picking for this Node
     * The basic function defined here does nothing.
     * It has to be reimplemented in the derived class
     */
    virtual void enablePicking( bool _enable );

    /** Check if picking is enabled for this Node
     * This function will return true unless the derived class overwrites
     * this function.
     */
    virtual bool pickingEnabled();
264

265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
    /** \brief Refine picking
     *
     * Reimplement this function, if the object type can refine picking. E.g.
     * the standard picking will rely on the z-buffer resolution, while a mesh
     * can intersect a ray with the triangle and refine the depth via
     * the exact intersection point.
     *
     * @param _pickTarget Current picking target (Faces, all,...)
     * @param _original hitpoint
     * @param _eyePos current picking ray start position
     * @param _dir Ray direction when picking
     * @param _targetIdx Entity id hit (e.g. face index for meshes
     *
     */
    virtual ACG::Vec3d refinePick(ACG::SceneGraph::PickTarget _pickTarget,
                                  const ACG::Vec3d _hitPoint,
                                  const ACG::Vec3d _start ,
                                  const ACG::Vec3d _dir,
                                  const unsigned int _targetIdx );

285 286
  /** @} */

287
  //===========================================================================
288
  /** @name Update handling
289 290
   * @{ */
  //===========================================================================
291

292
  protected:
Jan Möbius's avatar
Jan Möbius committed
293 294 295 296 297
    /** \brief  This function is called to update the object
    *
    * If the object changes, the core will call this function. Normally this will update
    * the corresponding scenegraph nodes or trigger other data handling which has to be done
    * when the object changes.
298
    *
299
    * \note Do not call this function yourself to avoid unnecessary overhead(the core will call it via the type plugins when it is required)
Jan Möbius's avatar
Jan Möbius committed
300
    */
301
    virtual void update(UpdateType _type = UPDATE_ALL ) override;
302 303 304

  /** @} */

305 306
  //===========================================================================
  /** @name Additional nodes
Jan Möbius's avatar
Jan Möbius committed
307 308 309 310 311
   *
   *  \anchor BaseObjectData_AdditionalNodes_header Functions to attach additional Nodes to objects
   *
   *  Manage additional scenegraph nodes that belong to an object.
   *
312
   * @{ */
313
  //===========================================================================
314 315
  public:
    /** \brief add an additional node to the object
316 317
    *
    * This function can be used to store an additional Scenegraph node. If you add nodes there, you do not
318 319
    * need to keep track of deleted, added objects, as this will be done in the main application.
    * You have to create the node yourself as this function does not know the type. You should add the
Jan Möbius's avatar
Jan Möbius committed
320 321
    * new node below the manipulatorNode ( BaseObjectData::manipulatorNode() ) if you want that it moves with the rest of the data. Otherwise
    * add it below the baseNode ( BaseObjectData::baseNode() of the object.
322
    *
323 324
    *  @param _node Node to add
    *  @param _pluginName Name of the current plugin
325
    *  @param _nodeName Name of the New Node
326 327 328
    *  @param _id extra index, if there will be multiple nodes with this name( defaults to 0)
    *  @return true if successfull
    */
329
    template< typename NodeT >
330
    bool addAdditionalNode(NodeT* _node , QString _pluginName, QString _nodeName , int _id = 0);
331

332
    /** \brief check if an object has the additional node
333
    *
334 335
    * If you store additional Scenegraph nodes with the objects you can check if they
    * exist with this function.
336
    *
337
    *  @param _pluginName Name of the current plugin
338
    *  @param _nodeName Name of the Node
339 340 341
    *  @param _id extra index, if there are multiple nodes with this name( defaults to 0)
    *  @return true if found
    */
342 343
    bool hasAdditionalNode(QString _pluginName, QString _nodeName , int _id = 0);

344
    /** \brief get an addition node from the object
345
    *
346
    * If you store additional Scenegraph node with the objects you can get these nodes with this function.
347
    *
348 349
    *  @param _node Returns the node
    *  @param _pluginName Name of the current plugin
350
    *  @param _nodeName Name of the Node
351 352 353
    *  @param _id extra index, if there are multiple nodes with this name ( defaults to 0)
    *  @return true if found
    */
354
    template< typename NodeT >
355 356 357
    bool getAdditionalNode(NodeT*& _node , QString _pluginName, QString _nodeName , int _id = 0 );

    /** \brief remove an additional node from the object
358
    *
Jan Möbius's avatar
Jan Möbius committed
359 360 361
    * If additional nodes are stored for this object, such a node can be removed using this function.
    * If this node has children, they will be removed from the scenegraph as well (and their
    * memory is freed).
362
    *
363 364
    *  @param _node Needed for type specification
    *  @param _pluginName Name of the current plugin
365
    *  @param _nodeName Name of the Node
366 367 368
    *  @param _id extra index, if there are multiple nodes with this name ( defaults to 0)
    *  @return true if found and removed
    */
369
    template< typename NodeT >
370 371 372 373 374 375
    bool removeAdditionalNode(NodeT*& _node, QString _pluginName, QString _nodeName , int _id = 0 );
  private:
    /** This pointer may be used to store additional Nodes belonging to this Object
     *   The String should be used by the plugin to identify its Nodes
     */
    std::vector< std::pair <BaseNode*,QString> > additionalNodes_;
376 377 378

  /** @} */

379 380 381 382 383 384 385
};


//=============================================================================

#if defined(INCLUDE_TEMPLATES) && !defined(BASEOBJECTDATA_C)
#define BASEOBJECT_TEMPLATES
386
#include "BaseObjectDataT_impl.hh"
387 388
#endif