BaseObjectData.hh 10.3 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
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//=============================================================================
//
//                               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.
// 
//  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 Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================




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

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


#ifndef BASEOBJECTDATA_HH
#define BASEOBJECTDATA_HH

 
#ifdef WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif

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

#include "BaseObject.hh"
#include <vector>
#include <ACG/Scenegraph/MaterialNode.hh>
#include <ACG/Scenegraph/SeparatorNode.hh>
#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();
    
  protected:
    /** This function creates the scenegraph nodes */
    virtual void init();
    
  /** @} */ 
    
  //===========================================================================
  /** @name Data
   * @{ */
  //===========================================================================        
    
  public:  
    /** Clean all data structures of the object
      * 
      * */
    virtual void cleanup();
      
  /** @} */     
    
  //===========================================================================
  /** @name Name and Path handling
   * @{ */
  //===========================================================================   
     
  public:    
    
    /** 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
     * 
     * @param _filename path to the file.
     */
    void setFromFileName(QString _filename );
    
    /// set the name of the object. ( If you overwrite it, call BaseObjectData::setName(_name ) it in your funtion first)
    virtual void setName( QString _name );
    
    /// return the path to the object ( defaults to "." if unset )
    QString path();
    
    /// set the path to the object.
    void path(QString _path);
    
  private:
    
    /// path to the file from which the object is loaded ( defaults to "." )
    QString path_;
    
  /** @} */ 
    
  
    
  //===========================================================================
  /** @name Object visualization
   * @{ */
  //=========================================================================== 
    
  public :
    /// Sets the whole Scenegraph subtree of this node to visible
    void show();
    
    /// Sets the whole Scenegraph subtree of this node to invisible
    void hide();
    
    /** 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();
    
    /** 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();
    
    /// get a pointer to the materialnode
    MaterialNode* materialNode();
    
    /// Set the color of the object
    void setBaseColor(ACG::Vec4f _color);
    
    /// Check if the manipulator has been placed
    bool manipPlaced();
    
    /// set the manipulator place status
    void manipPlaced( bool _placed );
178
179
180

    /// get the bounding box of the object
    void getBoundingBox(ACG::Vec3d& bbmin, ACG::Vec3d& bbmax);
Jan Möbius's avatar
 
Jan Möbius committed
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
    
  private :

    
    bool manipPlaced_;
    
    /// rootNode of global Scenegraph structure
    SeparatorNode*    rootNode_;
    
    /// Separator at top of Scenegraph structure used for this Object
    SeparatorNode*    separatorNode_;
    
    /// Manipulator used for this Object 
    ManipulatorNode*  manipulatorNode_;
    
    /// Scenegraph Material Node for the object
    MaterialNode*    materialNode_;
    
  /** @} */ 
    
    
  //===========================================================================
  /** @name Picking
   * @{ */
  //=========================================================================== 
    
  public :
    /// detect if the node has been picked
    virtual bool picked( uint _node_idx );
210
211
212
213
214
215
216
217
218
219
220
221

    /** 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();
Jan Möbius's avatar
 
Jan Möbius committed
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
    
  /** @} */ 
    
  //===========================================================================
  /** @name Content
   * @{ */
  //===========================================================================
    
  public:
    /// This function is called to update the object
    virtual void update();
    
  /** @} */ 
    
  //===========================================================================
  /** @name Additional nodes
   * @{ */
  //===========================================================================    
  public:
    /** \brief add an additional node to the object
    * 
    * This function can be used to store an additional Scenegraph node. If you add nodes there, you do not 
    * 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
    * new node below the manipulatorNode if you want that it moves with the rest of the data. Otherwise 
    * add it below the seperatorNode of the object.
    * 
    *  @param _node Node to add
    *  @param _pluginName Name of the current plugin
    *  @param _nodeName Name of the New Node 
    *  @param _id extra index, if there will be multiple nodes with this name( defaults to 0)
    *  @return true if successfull
    */
    template< typename NodeT > 
    bool addAdditionalNode(NodeT* _node , QString _pluginName, QString _nodeName , int _id = 0);
  
    /** \brief check if an object has the additional node
    * 
    * If you store additional Scenegraph nodes with the objects you can check if they
    * exist with this function.
    * 
    *  @param _pluginName Name of the current plugin
    *  @param _nodeName Name of the Node 
    *  @param _id extra index, if there are multiple nodes with this name( defaults to 0)
    *  @return true if found
    */
    bool hasAdditionalNode(QString _pluginName, QString _nodeName , int _id = 0);  
    
    /** \brief get an addition node from the object
    * 
    * If you store additional Scenegraph node with the objects you can get these nodes with this function.
    * 
    *  @param _node Returns the node
    *  @param _pluginName Name of the current plugin
    *  @param _nodeName Name of the Node 
    *  @param _id extra index, if there are multiple nodes with this name ( defaults to 0)
    *  @return true if found
    */
    template< typename NodeT > 
    bool getAdditionalNode(NodeT*& _node , QString _pluginName, QString _nodeName , int _id = 0 );

    /** \brief remove an additional node from the object
    * 
    * If additional nodes are stored for this object, such a node can be removed using this function
    * 
    *  @param _node Needed for type specification
    *  @param _pluginName Name of the current plugin
    *  @param _nodeName Name of the Node 
    *  @param _id extra index, if there are multiple nodes with this name ( defaults to 0)
    *  @return true if found and removed
    */
    template< typename NodeT > 
    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_;
    
  /** @} */ 
    
};


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

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

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