BaseObjectData.hh 11.1 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/QtScenegraph/QtTranslationManipulatorNode.hh>
Jan Möbius's avatar
 
Jan Möbius committed
62 63 64 65 66 67 68

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

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

//== 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:
83 84 85 86 87 88 89

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

Jan Möbius's avatar
 
Jan Möbius committed
90 91 92 93 94
    /// constructor
    BaseObjectData(SeparatorNode* _rootNode);

    ///destructor
    virtual ~BaseObjectData();
95

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

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
102 103 104
  //===========================================================================
  /** @name Data
   * @{ */
105 106 107
  //===========================================================================

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

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
115 116 117
  //===========================================================================
  /** @name Name and Path handling
   * @{ */
118 119 120 121
  //===========================================================================

  public:

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

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

Jan Möbius's avatar
 
Jan Möbius committed
133 134
    /// return the path to the object ( defaults to "." if unset )
    QString path();
135

Jan Möbius's avatar
 
Jan Möbius committed
136 137
    /// set the path to the object.
    void path(QString _path);
138

Jan Möbius's avatar
 
Jan Möbius committed
139
  private:
140

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

  /** @} */



Jan Möbius's avatar
 
Jan Möbius committed
148 149 150
  //===========================================================================
  /** @name Object visualization
   * @{ */
151 152
  //===========================================================================

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

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

160 161 162 163 164 165
    /// 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
166 167 168 169
    /** 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();
170

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

    /** 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
183 184
    /// get a pointer to the materialnode
    MaterialNode* materialNode();
185

Jan Möbius's avatar
 
Jan Möbius committed
186 187
    /// Set the color of the object
    void setBaseColor(ACG::Vec4f _color);
188

Jan Möbius's avatar
 
Jan Möbius committed
189 190
    /// Check if the manipulator has been placed
    bool manipPlaced();
191

Jan Möbius's avatar
 
Jan Möbius committed
192 193
    /// set the manipulator place status
    void manipPlaced( bool _placed );
194 195 196

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

Jan Möbius's avatar
 
Jan Möbius committed
198 199
  private :

200

Jan Möbius's avatar
 
Jan Möbius committed
201
    bool manipPlaced_;
202

Jan Möbius's avatar
 
Jan Möbius committed
203 204
    /// rootNode of global Scenegraph structure
    SeparatorNode*    rootNode_;
205

Jan Möbius's avatar
 
Jan Möbius committed
206 207
    /// Separator at top of Scenegraph structure used for this Object
    SeparatorNode*    separatorNode_;
208 209

    /// Manipulator used for this Object
210
    QtTranslationManipulatorNode*  manipulatorNode_;
211

Jan Möbius's avatar
 
Jan Möbius committed
212 213
    /// Scenegraph Material Node for the object
    MaterialNode*    materialNode_;
214 215 216 217

  /** @} */


Jan Möbius's avatar
 
Jan Möbius committed
218 219 220
  //===========================================================================
  /** @name Picking
   * @{ */
221 222
  //===========================================================================

Jan Möbius's avatar
 
Jan Möbius committed
223 224 225
  public :
    /// detect if the node has been picked
    virtual bool picked( uint _node_idx );
226 227 228 229 230 231 232 233 234 235 236 237

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

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
241 242 243 244
  //===========================================================================
  /** @name Content
   * @{ */
  //===========================================================================
245

Jan Möbius's avatar
 
Jan Möbius committed
246
  public:
Jan Möbius's avatar
Jan Möbius committed
247 248 249 250 251 252
    /** \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
253
    virtual void update();
254 255 256

  /** @} */

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

Jan Möbius's avatar
 
Jan Möbius committed
279
    /** \brief check if an object has the additional node
280
    *
Jan Möbius's avatar
 
Jan Möbius committed
281 282
    * If you store additional Scenegraph nodes with the objects you can check if they
    * exist with this function.
283
    *
Jan Möbius's avatar
 
Jan Möbius committed
284
    *  @param _pluginName Name of the current plugin
285
    *  @param _nodeName Name of the Node
Jan Möbius's avatar
 
Jan Möbius committed
286 287 288
    *  @param _id extra index, if there are multiple nodes with this name( defaults to 0)
    *  @return true if found
    */
289 290
    bool hasAdditionalNode(QString _pluginName, QString _nodeName , int _id = 0);

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

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

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
324 325 326 327 328 329 330 331 332 333 334 335 336
};


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

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

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