BaseObjectData.hh 13.7 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$                   *
 *                                                                           *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42 43 44 45 46 47 48 49 50 51 52




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

/**
53
 * \file BaseObjectData.hh
Jan Möbius's avatar
 
Jan Möbius committed
54 55 56 57 58 59 60 61
 * This File contains the Basic object class for all Objects which show content vi
 * the Scenegraph.
 */


#ifndef BASEOBJECTDATA_HH
#define BASEOBJECTDATA_HH

62

Jan Möbius's avatar
 
Jan Möbius committed
63 64
//== INCLUDES =================================================================

Jan Möbius's avatar
Jan Möbius committed
65
#include <OpenFlipper/common/GlobalDefines.hh>
66 67
#include <OpenFlipper/common/BaseObject.hh>
#include <QObject>
Jan Möbius's avatar
 
Jan Möbius committed
68 69 70
#include <vector>
#include <ACG/Scenegraph/MaterialNode.hh>
#include <ACG/Scenegraph/SeparatorNode.hh>
71
#include <ACG/Scenegraph/ShaderNode.hh>
Jan Möbius's avatar
 
Jan Möbius committed
72
#include <ACG/Scenegraph/BaseNode.hh>
73
#include <ACG/Scenegraph/BoundingBoxNode.hh>
74
#include <ACG/Scenegraph/StencilRefNode.hh>
75
#include <ACG/QtScenegraph/QtTranslationManipulatorNode.hh>
Jan Möbius's avatar
 
Jan Möbius committed
76 77 78 79 80 81 82

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

//== TYPEDEFS FOR SCENEGRAPH ===============================================
/// Materialnode
typedef ACG::SceneGraph::MaterialNode                     MaterialNode;
/// ManipulatorNode
83
typedef ACG::SceneGraph::QtTranslationManipulatorNode     QtTranslationManipulatorNode;
Jan Möbius's avatar
 
Jan Möbius committed
84 85 86 87
/// Seperator Node
typedef ACG::SceneGraph::SeparatorNode                    SeparatorNode;
/// Base Node
typedef ACG::SceneGraph::BaseNode                         BaseNode;
88 89
/// Bounding box Node
typedef ACG::SceneGraph::BoundingBoxNode                  BoundingBoxNode;
90 91
/// Stencil reference Node
typedef ACG::SceneGraph::StencilRefNode                   StencilRefNode;
Jan Möbius's avatar
 
Jan Möbius committed
92 93 94 95 96 97 98 99

//== 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
{
100 101
  Q_OBJECT
  
Jan Möbius's avatar
 
Jan Möbius committed
102
  public:
103 104 105 106 107 108 109

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

Jan Möbius's avatar
 
Jan Möbius committed
110 111 112 113 114
    /// constructor
    BaseObjectData(SeparatorNode* _rootNode);

    ///destructor
    virtual ~BaseObjectData();
115

Jan Möbius's avatar
 
Jan Möbius committed
116 117 118
  protected:
    /** This function creates the scenegraph nodes */
    virtual void init();
119 120 121

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
122 123 124
  //===========================================================================
  /** @name Data
   * @{ */
125 126 127
  //===========================================================================

  public:
Jan Möbius's avatar
 
Jan Möbius committed
128
    /** Clean all data structures of the object
129
      *
Jan Möbius's avatar
 
Jan Möbius committed
130 131
      * */
    virtual void cleanup();
132 133 134

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
135 136 137
  //===========================================================================
  /** @name Name and Path handling
   * @{ */
138 139 140 141
  //===========================================================================

  public:

Jan Möbius's avatar
 
Jan Möbius committed
142 143 144
    /** Set the object name from a filename. The function will set the name of the
     * object to the filename. At the same time the path is set to the one given in
     * the parameter
145
     *
Jan Möbius's avatar
 
Jan Möbius committed
146 147 148
     * @param _filename path to the file.
     */
    void setFromFileName(QString _filename );
149

Jan Möbius's avatar
 
Jan Möbius committed
150 151
    /// set the name of the object. ( If you overwrite it, call BaseObjectData::setName(_name ) it in your funtion first)
    virtual void setName( QString _name );
152

Jan Möbius's avatar
 
Jan Möbius committed
153 154
    /// return the path to the object ( defaults to "." if unset )
    QString path();
155

Jan Möbius's avatar
 
Jan Möbius committed
156 157
    /// set the path to the object.
    void path(QString _path);
158

Jan Möbius's avatar
 
Jan Möbius committed
159
  private:
160

Jan Möbius's avatar
 
Jan Möbius committed
161 162
    /// path to the file from which the object is loaded ( defaults to "." )
    QString path_;
163 164 165 166 167

  /** @} */



Jan Möbius's avatar
 
Jan Möbius committed
168 169 170
  //===========================================================================
  /** @name Object visualization
   * @{ */
171 172
  //===========================================================================

Jan Möbius's avatar
 
Jan Möbius committed
173 174 175
  public :
    /// Sets the whole Scenegraph subtree of this node to visible
    void show();
176

Jan Möbius's avatar
 
Jan Möbius committed
177 178
    /// Sets the whole Scenegraph subtree of this node to invisible
    void hide();
179

180
    /// return visiblity
181
    virtual bool visible();
182 183

    /// Sets visiblity of the whole Scenegraph subtree of this node
184
    virtual void visible(bool _visible);
185

Jan Möbius's avatar
 
Jan Möbius committed
186 187 188 189
    /** 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();
190

Jan Möbius's avatar
 
Jan Möbius committed
191 192 193
    /** 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)
     */
194
    QtTranslationManipulatorNode* manipulatorNode();
195 196 197 198 199 200 201 202

    /** 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();

Jan Möbius's avatar
 
Jan Möbius committed
203 204
    /// get a pointer to the materialnode
    MaterialNode* materialNode();
205

206 207 208
    /// get a pointer to the bounding box node
    BoundingBoxNode* boundingBoxNode();

209 210 211
    /// get a pointer to the stencil reference node
    StencilRefNode* stencilRefNode();

Jan Möbius's avatar
 
Jan Möbius committed
212 213
    /// Set the color of the object
    void setBaseColor(ACG::Vec4f _color);
214

Jan Möbius's avatar
 
Jan Möbius committed
215 216
    /// Check if the manipulator has been placed
    bool manipPlaced();
217

Jan Möbius's avatar
 
Jan Möbius committed
218 219
    /// set the manipulator place status
    void manipPlaced( bool _placed );
220 221 222

    /// get the bounding box of the object
    void getBoundingBox(ACG::Vec3d& bbmin, ACG::Vec3d& bbmax);
223

Jan Möbius's avatar
 
Jan Möbius committed
224 225
  private :

226

Jan Möbius's avatar
 
Jan Möbius committed
227
    bool manipPlaced_;
228

Jan Möbius's avatar
 
Jan Möbius committed
229 230
    /// rootNode of global Scenegraph structure
    SeparatorNode*    rootNode_;
231

Jan Möbius's avatar
 
Jan Möbius committed
232 233
    /// Separator at top of Scenegraph structure used for this Object
    SeparatorNode*    separatorNode_;
234 235

    /// Manipulator used for this Object
236
    QtTranslationManipulatorNode*  manipulatorNode_;
237

Jan Möbius's avatar
 
Jan Möbius committed
238 239
    /// Scenegraph Material Node for the object
    MaterialNode*    materialNode_;
240

241 242 243
    /// Bounding box node for the object
    BoundingBoxNode * boundingBoxNode_;

244 245 246
    /// Stencil reference node for the object
    StencilRefNode* stencilRefNode_;

247 248 249
  /** @} */


Jan Möbius's avatar
 
Jan Möbius committed
250 251 252
  //===========================================================================
  /** @name Picking
   * @{ */
253 254
  //===========================================================================

Jan Möbius's avatar
 
Jan Möbius committed
255 256 257
  public :
    /// detect if the node has been picked
    virtual bool picked( uint _node_idx );
258 259 260 261 262 263 264 265 266 267 268 269

    /** 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();
270 271 272

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
273 274 275 276
  //===========================================================================
  /** @name Content
   * @{ */
  //===========================================================================
277

Jan Möbius's avatar
 
Jan Möbius committed
278
  public:
Jan Möbius's avatar
Jan Möbius committed
279 280 281 282 283 284
    /** \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.
    */
Jan Möbius's avatar
 
Jan Möbius committed
285
    virtual void update();
286 287 288

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
289 290 291
  //===========================================================================
  /** @name Additional nodes
   * @{ */
292
  //===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
293 294
  public:
    /** \brief add an additional node to the object
295 296
    *
    * This function can be used to store an additional Scenegraph node. If you add nodes there, you do not
Jan Möbius's avatar
 
Jan Möbius committed
297 298
    * 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
299 300
    * 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.
301
    *
Jan Möbius's avatar
 
Jan Möbius committed
302 303
    *  @param _node Node to add
    *  @param _pluginName Name of the current plugin
304
    *  @param _nodeName Name of the New Node
Jan Möbius's avatar
 
Jan Möbius committed
305 306 307
    *  @param _id extra index, if there will be multiple nodes with this name( defaults to 0)
    *  @return true if successfull
    */
308
    template< typename NodeT >
Jan Möbius's avatar
 
Jan Möbius committed
309
    bool addAdditionalNode(NodeT* _node , QString _pluginName, QString _nodeName , int _id = 0);
310

Jan Möbius's avatar
 
Jan Möbius committed
311
    /** \brief check if an object has the additional node
312
    *
Jan Möbius's avatar
 
Jan Möbius committed
313 314
    * If you store additional Scenegraph nodes with the objects you can check if they
    * exist with this function.
315
    *
Jan Möbius's avatar
 
Jan Möbius committed
316
    *  @param _pluginName Name of the current plugin
317
    *  @param _nodeName Name of the Node
Jan Möbius's avatar
 
Jan Möbius committed
318 319 320
    *  @param _id extra index, if there are multiple nodes with this name( defaults to 0)
    *  @return true if found
    */
321 322
    bool hasAdditionalNode(QString _pluginName, QString _nodeName , int _id = 0);

Jan Möbius's avatar
 
Jan Möbius committed
323
    /** \brief get an addition node from the object
324
    *
Jan Möbius's avatar
 
Jan Möbius committed
325
    * If you store additional Scenegraph node with the objects you can get these nodes with this function.
326
    *
Jan Möbius's avatar
 
Jan Möbius committed
327 328
    *  @param _node Returns the node
    *  @param _pluginName Name of the current plugin
329
    *  @param _nodeName Name of the Node
Jan Möbius's avatar
 
Jan Möbius committed
330 331 332
    *  @param _id extra index, if there are multiple nodes with this name ( defaults to 0)
    *  @return true if found
    */
333
    template< typename NodeT >
Jan Möbius's avatar
 
Jan Möbius committed
334 335 336
    bool getAdditionalNode(NodeT*& _node , QString _pluginName, QString _nodeName , int _id = 0 );

    /** \brief remove an additional node from the object
337
    *
Jan Möbius's avatar
Jan Möbius committed
338 339 340
    * 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).
341
    *
Jan Möbius's avatar
 
Jan Möbius committed
342 343
    *  @param _node Needed for type specification
    *  @param _pluginName Name of the current plugin
344
    *  @param _nodeName Name of the Node
Jan Möbius's avatar
 
Jan Möbius committed
345 346 347
    *  @param _id extra index, if there are multiple nodes with this name ( defaults to 0)
    *  @return true if found and removed
    */
348
    template< typename NodeT >
Jan Möbius's avatar
 
Jan Möbius committed
349 350 351 352 353 354
    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_;
355 356 357

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
358 359 360 361 362 363 364 365 366 367 368 369 370
};


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

#if defined(INCLUDE_TEMPLATES) && !defined(BASEOBJECTDATA_C)
#define BASEOBJECT_TEMPLATES
#include "BaseObjectDataT.cc"
#endif

//=============================================================================
#endif // BASEOBJECTDATA_HH defined
//=============================================================================