BaseObjectData.hh 10.5 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
#ifndef DLLEXPORT
Jan Möbius's avatar
 
Jan Möbius committed
53 54 55 56 57
#ifdef WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif
Jan Möbius's avatar
Jan Möbius committed
58
#endif 
Jan Möbius's avatar
 
Jan Möbius committed
59 60 61 62 63 64 65

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

#include "BaseObject.hh"
#include <vector>
#include <ACG/Scenegraph/MaterialNode.hh>
#include <ACG/Scenegraph/SeparatorNode.hh>
66
#include <ACG/Scenegraph/ShaderNode.hh>
Jan Möbius's avatar
 
Jan Möbius committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
#include <ACG/Scenegraph/BaseNode.hh>
#include <ACG/Scenegraph/ManipulatorNode.hh>

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

//== TYPEDEFS FOR SCENEGRAPH ===============================================
/// Materialnode
typedef ACG::SceneGraph::MaterialNode                     MaterialNode;
/// ManipulatorNode
typedef ACG::SceneGraph::ManipulatorNode                  ManipulatorNode;
/// 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:
    /// 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

Jan Möbius's avatar
 
Jan Möbius committed
160 161 162 163
    /** 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();
164

Jan Möbius's avatar
 
Jan Möbius committed
165 166 167 168
    /** 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)
     */
    ManipulatorNode* manipulatorNode();
169 170 171 172 173 174 175 176

    /** 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
177 178
    /// get a pointer to the materialnode
    MaterialNode* materialNode();
179

Jan Möbius's avatar
 
Jan Möbius committed
180 181
    /// Set the color of the object
    void setBaseColor(ACG::Vec4f _color);
182

Jan Möbius's avatar
 
Jan Möbius committed
183 184
    /// Check if the manipulator has been placed
    bool manipPlaced();
185

Jan Möbius's avatar
 
Jan Möbius committed
186 187
    /// set the manipulator place status
    void manipPlaced( bool _placed );
188 189 190

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

Jan Möbius's avatar
 
Jan Möbius committed
192 193
  private :

194

Jan Möbius's avatar
 
Jan Möbius committed
195
    bool manipPlaced_;
196

Jan Möbius's avatar
 
Jan Möbius committed
197 198
    /// rootNode of global Scenegraph structure
    SeparatorNode*    rootNode_;
199

Jan Möbius's avatar
 
Jan Möbius committed
200 201
    /// Separator at top of Scenegraph structure used for this Object
    SeparatorNode*    separatorNode_;
202 203

    /// Manipulator used for this Object
Jan Möbius's avatar
 
Jan Möbius committed
204
    ManipulatorNode*  manipulatorNode_;
205

Jan Möbius's avatar
 
Jan Möbius committed
206 207
    /// Scenegraph Material Node for the object
    MaterialNode*    materialNode_;
208 209 210 211

  /** @} */


Jan Möbius's avatar
 
Jan Möbius committed
212 213 214
  //===========================================================================
  /** @name Picking
   * @{ */
215 216
  //===========================================================================

Jan Möbius's avatar
 
Jan Möbius committed
217 218 219
  public :
    /// detect if the node has been picked
    virtual bool picked( uint _node_idx );
220 221 222 223 224 225 226 227 228 229 230 231

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

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
235 236 237 238
  //===========================================================================
  /** @name Content
   * @{ */
  //===========================================================================
239

Jan Möbius's avatar
 
Jan Möbius committed
240 241 242
  public:
    /// This function is called to update the object
    virtual void update();
243 244 245

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
246 247 248
  //===========================================================================
  /** @name Additional nodes
   * @{ */
249
  //===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
250 251
  public:
    /** \brief add an additional node to the object
252 253
    *
    * 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
254 255
    * 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
256
    * new node below the manipulatorNode if you want that it moves with the rest of the data. Otherwise
Jan Möbius's avatar
 
Jan Möbius committed
257
    * add it below the seperatorNode of the object.
258
    *
Jan Möbius's avatar
 
Jan Möbius committed
259 260
    *  @param _node Node to add
    *  @param _pluginName Name of the current plugin
261
    *  @param _nodeName Name of the New Node
Jan Möbius's avatar
 
Jan Möbius committed
262 263 264
    *  @param _id extra index, if there will be multiple nodes with this name( defaults to 0)
    *  @return true if successfull
    */
265
    template< typename NodeT >
Jan Möbius's avatar
 
Jan Möbius committed
266
    bool addAdditionalNode(NodeT* _node , QString _pluginName, QString _nodeName , int _id = 0);
267

Jan Möbius's avatar
 
Jan Möbius committed
268
    /** \brief check if an object has the additional node
269
    *
Jan Möbius's avatar
 
Jan Möbius committed
270 271
    * If you store additional Scenegraph nodes with the objects you can check if they
    * exist with this function.
272
    *
Jan Möbius's avatar
 
Jan Möbius committed
273
    *  @param _pluginName Name of the current plugin
274
    *  @param _nodeName Name of the Node
Jan Möbius's avatar
 
Jan Möbius committed
275 276 277
    *  @param _id extra index, if there are multiple nodes with this name( defaults to 0)
    *  @return true if found
    */
278 279
    bool hasAdditionalNode(QString _pluginName, QString _nodeName , int _id = 0);

Jan Möbius's avatar
 
Jan Möbius committed
280
    /** \brief get an addition node from the object
281
    *
Jan Möbius's avatar
 
Jan Möbius committed
282
    * If you store additional Scenegraph node with the objects you can get these nodes with this function.
283
    *
Jan Möbius's avatar
 
Jan Möbius committed
284 285
    *  @param _node Returns the node
    *  @param _pluginName Name of the current plugin
286
    *  @param _nodeName Name of the Node
Jan Möbius's avatar
 
Jan Möbius committed
287 288 289
    *  @param _id extra index, if there are multiple nodes with this name ( defaults to 0)
    *  @return true if found
    */
290
    template< typename NodeT >
Jan Möbius's avatar
 
Jan Möbius committed
291 292 293
    bool getAdditionalNode(NodeT*& _node , QString _pluginName, QString _nodeName , int _id = 0 );

    /** \brief remove an additional node from the object
294
    *
Jan Möbius's avatar
 
Jan Möbius committed
295
    * If additional nodes are stored for this object, such a node can be removed using this function
296
    *
Jan Möbius's avatar
 
Jan Möbius committed
297 298
    *  @param _node Needed for type specification
    *  @param _pluginName Name of the current plugin
299
    *  @param _nodeName Name of the Node
Jan Möbius's avatar
 
Jan Möbius committed
300 301 302
    *  @param _id extra index, if there are multiple nodes with this name ( defaults to 0)
    *  @return true if found and removed
    */
303
    template< typename NodeT >
Jan Möbius's avatar
 
Jan Möbius committed
304 305 306 307 308 309
    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_;
310 311 312

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
313 314 315 316 317 318 319 320 321 322 323 324 325
};


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

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

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