BaseObjectData.hh 11.4 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  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.
15
//
Jan Möbius's avatar
 
Jan Möbius committed
16 17 18 19
//  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.
20
//
Jan Möbius's avatar
 
Jan Möbius committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================




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

/**
42
 * \file BaseObjectData.hh
Jan Möbius's avatar
 
Jan Möbius committed
43 44 45 46 47 48 49 50
 * This File contains the Basic object class for all Objects which show content vi
 * the Scenegraph.
 */


#ifndef BASEOBJECTDATA_HH
#define BASEOBJECTDATA_HH

51

Jan Möbius's avatar
 
Jan Möbius committed
52 53
//== INCLUDES =================================================================

Jan Möbius's avatar
Jan Möbius committed
54
#include <OpenFlipper/common/GlobalDefines.hh>
Jan Möbius's avatar
 
Jan Möbius committed
55 56 57 58
#include "BaseObject.hh"
#include <vector>
#include <ACG/Scenegraph/MaterialNode.hh>
#include <ACG/Scenegraph/SeparatorNode.hh>
59
#include <ACG/Scenegraph/ShaderNode.hh>
Jan Möbius's avatar
 
Jan Möbius committed
60
#include <ACG/Scenegraph/BaseNode.hh>
61
#include <ACG/Scenegraph/BoundingBoxNode.hh>
62
#include <ACG/QtScenegraph/QtTranslationManipulatorNode.hh>
Jan Möbius's avatar
 
Jan Möbius committed
63 64 65 66 67 68 69

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

//== TYPEDEFS FOR SCENEGRAPH ===============================================
/// Materialnode
typedef ACG::SceneGraph::MaterialNode                     MaterialNode;
/// ManipulatorNode
70
typedef ACG::SceneGraph::QtTranslationManipulatorNode     QtTranslationManipulatorNode;
Jan Möbius's avatar
 
Jan Möbius committed
71 72 73 74
/// Seperator Node
typedef ACG::SceneGraph::SeparatorNode                    SeparatorNode;
/// Base Node
typedef ACG::SceneGraph::BaseNode                         BaseNode;
75 76
/// Bounding box Node
typedef ACG::SceneGraph::BoundingBoxNode                  BoundingBoxNode;
Jan Möbius's avatar
 
Jan Möbius committed
77 78 79 80 81 82 83 84 85

//== 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
{
  public:
86 87 88 89 90 91 92

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

Jan Möbius's avatar
 
Jan Möbius committed
93 94 95 96 97
    /// constructor
    BaseObjectData(SeparatorNode* _rootNode);

    ///destructor
    virtual ~BaseObjectData();
98

Jan Möbius's avatar
 
Jan Möbius committed
99 100 101
  protected:
    /** This function creates the scenegraph nodes */
    virtual void init();
102 103 104

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
105 106 107
  //===========================================================================
  /** @name Data
   * @{ */
108 109 110
  //===========================================================================

  public:
Jan Möbius's avatar
 
Jan Möbius committed
111
    /** Clean all data structures of the object
112
      *
Jan Möbius's avatar
 
Jan Möbius committed
113 114
      * */
    virtual void cleanup();
115 116 117

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
118 119 120
  //===========================================================================
  /** @name Name and Path handling
   * @{ */
121 122 123 124
  //===========================================================================

  public:

Jan Möbius's avatar
 
Jan Möbius committed
125 126 127
    /** 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
128
     *
Jan Möbius's avatar
 
Jan Möbius committed
129 130 131
     * @param _filename path to the file.
     */
    void setFromFileName(QString _filename );
132

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

Jan Möbius's avatar
 
Jan Möbius committed
136 137
    /// return the path to the object ( defaults to "." if unset )
    QString path();
138

Jan Möbius's avatar
 
Jan Möbius committed
139 140
    /// set the path to the object.
    void path(QString _path);
141

Jan Möbius's avatar
 
Jan Möbius committed
142
  private:
143

Jan Möbius's avatar
 
Jan Möbius committed
144 145
    /// path to the file from which the object is loaded ( defaults to "." )
    QString path_;
146 147 148 149 150

  /** @} */



Jan Möbius's avatar
 
Jan Möbius committed
151 152 153
  //===========================================================================
  /** @name Object visualization
   * @{ */
154 155
  //===========================================================================

Jan Möbius's avatar
 
Jan Möbius committed
156 157 158
  public :
    /// Sets the whole Scenegraph subtree of this node to visible
    void show();
159

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

163 164 165 166 167 168
    /// return visiblity
    bool visible();

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

Jan Möbius's avatar
 
Jan Möbius committed
169 170 171 172
    /** 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();
173

Jan Möbius's avatar
 
Jan Möbius committed
174 175 176
    /** 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)
     */
177
    QtTranslationManipulatorNode* manipulatorNode();
178 179 180 181 182 183 184 185

    /** 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
186 187
    /// get a pointer to the materialnode
    MaterialNode* materialNode();
188

189 190 191
    /// get a pointer to the bounding box node
    BoundingBoxNode* boundingBoxNode();

Jan Möbius's avatar
 
Jan Möbius committed
192 193
    /// Set the color of the object
    void setBaseColor(ACG::Vec4f _color);
194

Jan Möbius's avatar
 
Jan Möbius committed
195 196
    /// Check if the manipulator has been placed
    bool manipPlaced();
197

Jan Möbius's avatar
 
Jan Möbius committed
198 199
    /// set the manipulator place status
    void manipPlaced( bool _placed );
200 201 202

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

Jan Möbius's avatar
 
Jan Möbius committed
204 205
  private :

206

Jan Möbius's avatar
 
Jan Möbius committed
207
    bool manipPlaced_;
208

Jan Möbius's avatar
 
Jan Möbius committed
209 210
    /// rootNode of global Scenegraph structure
    SeparatorNode*    rootNode_;
211

Jan Möbius's avatar
 
Jan Möbius committed
212 213
    /// Separator at top of Scenegraph structure used for this Object
    SeparatorNode*    separatorNode_;
214 215

    /// Manipulator used for this Object
216
    QtTranslationManipulatorNode*  manipulatorNode_;
217

Jan Möbius's avatar
 
Jan Möbius committed
218 219
    /// Scenegraph Material Node for the object
    MaterialNode*    materialNode_;
220

221 222 223
    /// Bounding box node for the object
    BoundingBoxNode * boundingBoxNode_;

224 225 226
  /** @} */


Jan Möbius's avatar
 
Jan Möbius committed
227 228 229
  //===========================================================================
  /** @name Picking
   * @{ */
230 231
  //===========================================================================

Jan Möbius's avatar
 
Jan Möbius committed
232 233 234
  public :
    /// detect if the node has been picked
    virtual bool picked( uint _node_idx );
235 236 237 238 239 240 241 242 243 244 245 246

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

  /** @} */

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

Jan Möbius's avatar
 
Jan Möbius committed
255
  public:
Jan Möbius's avatar
Jan Möbius committed
256 257 258 259 260 261
    /** \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
262
    virtual void update();
263 264 265

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
266 267 268
  //===========================================================================
  /** @name Additional nodes
   * @{ */
269
  //===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
270 271
  public:
    /** \brief add an additional node to the object
272 273
    *
    * 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
274 275
    * 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
276 277
    * 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.
278
    *
Jan Möbius's avatar
 
Jan Möbius committed
279 280
    *  @param _node Node to add
    *  @param _pluginName Name of the current plugin
281
    *  @param _nodeName Name of the New Node
Jan Möbius's avatar
 
Jan Möbius committed
282 283 284
    *  @param _id extra index, if there will be multiple nodes with this name( defaults to 0)
    *  @return true if successfull
    */
285
    template< typename NodeT >
Jan Möbius's avatar
 
Jan Möbius committed
286
    bool addAdditionalNode(NodeT* _node , QString _pluginName, QString _nodeName , int _id = 0);
287

Jan Möbius's avatar
 
Jan Möbius committed
288
    /** \brief check if an object has the additional node
289
    *
Jan Möbius's avatar
 
Jan Möbius committed
290 291
    * If you store additional Scenegraph nodes with the objects you can check if they
    * exist with this function.
292
    *
Jan Möbius's avatar
 
Jan Möbius committed
293
    *  @param _pluginName Name of the current plugin
294
    *  @param _nodeName Name of the Node
Jan Möbius's avatar
 
Jan Möbius committed
295 296 297
    *  @param _id extra index, if there are multiple nodes with this name( defaults to 0)
    *  @return true if found
    */
298 299
    bool hasAdditionalNode(QString _pluginName, QString _nodeName , int _id = 0);

Jan Möbius's avatar
 
Jan Möbius committed
300
    /** \brief get an addition node from the object
301
    *
Jan Möbius's avatar
 
Jan Möbius committed
302
    * If you store additional Scenegraph node with the objects you can get these nodes with this function.
303
    *
Jan Möbius's avatar
 
Jan Möbius committed
304 305
    *  @param _node Returns the node
    *  @param _pluginName Name of the current plugin
306
    *  @param _nodeName Name of the Node
Jan Möbius's avatar
 
Jan Möbius committed
307 308 309
    *  @param _id extra index, if there are multiple nodes with this name ( defaults to 0)
    *  @return true if found
    */
310
    template< typename NodeT >
Jan Möbius's avatar
 
Jan Möbius committed
311 312 313
    bool getAdditionalNode(NodeT*& _node , QString _pluginName, QString _nodeName , int _id = 0 );

    /** \brief remove an additional node from the object
314
    *
Jan Möbius's avatar
 
Jan Möbius committed
315
    * If additional nodes are stored for this object, such a node can be removed using this function
316
    *
Jan Möbius's avatar
 
Jan Möbius committed
317 318
    *  @param _node Needed for type specification
    *  @param _pluginName Name of the current plugin
319
    *  @param _nodeName Name of the Node
Jan Möbius's avatar
 
Jan Möbius committed
320 321 322
    *  @param _id extra index, if there are multiple nodes with this name ( defaults to 0)
    *  @return true if found and removed
    */
323
    template< typename NodeT >
Jan Möbius's avatar
 
Jan Möbius committed
324 325 326 327 328 329
    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_;
330 331 332

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
333 334 335 336 337 338 339 340 341 342 343 344 345
};


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

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

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