BaseObject.hh 16.3 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2
3
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
Jan Möbius committed
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
*                           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/>.                                       *
*                                                                            *
33
34
35
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36
37
38
39
40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
41
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62




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

/**
 * \file BaseObject.hh
 * This File contains the Basic object class for all Objects (Includes also non visual objects such as Groups).
 */


#ifndef BASEOBJECT_HH
#define BASEOBJECT_HH

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

Jan Möbius's avatar
Jan Möbius committed
63
#include <OpenFlipper/common/GlobalDefines.hh>
64
#include <OpenFlipper/common/DataTypes.hh>
Dirk Wilden's avatar
Dirk Wilden committed
65
#include <OpenFlipper/common/UpdateType.hh>
66
#include <QObject>
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
#include <QString>
#include <QList>
#include <QStringList>
#include <vector>
#include <QMap>
#include "perObjectData.hh"

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


//== CLASS DEFINITION =========================================================

/**
 * This is the basic Data class providing the functions common to all objects.
 * If the Datacontrol Plugin is available, a Tree structure will be generated allowing groups of objects.
 */
83
84
85
86
class DLLEXPORTONLY BaseObject : public QObject {
  
  Q_OBJECT 
  
Jan Möbius's avatar
 
Jan Möbius committed
87
88
89
  friend class BaseObjectData;

  public :
90
91

    /** Creates a copy of this Object. Currently it will not have any per Object data attached.
92
     *  Its automatically attached to the objectRoot.
93
94
95
     */
    BaseObject(const BaseObject& _object);

96
97
98
99
    /** Creates a new object. If the parent is 0 and the objectroot does not exist, it will have no parent.
    * If the objectroot exists and parent is 0, it will be appended to the objectroot.
    * If a parent is given, it is appended to this object.
    */
Jan Möbius's avatar
 
Jan Möbius committed
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
    BaseObject( BaseObject *_parent = 0);

    virtual ~BaseObject();

  //===========================================================================
  /** @name Object Identification
   * @{ */
  //===========================================================================
  public:
    /** return the unique id of the object. These ids will be generated every time an object is created.
     * It will stay valid during the runtime of the application.
     */
    int id();

    /** return the persistent id of an object ( This id can be managed by a database ). It should
     * be persistent across program starts. It will be -1 if the object has not been registered by
     * a database. This id will only be set if a database plugin manages it.
     */
    int persistentId();

    /** set the persistent id of the object
     */
    void persistentId( int _id );

  private:
    /** \brief Unique ID for this Object
    *
    *  If you need to identify an Object in your plugin then use this id to find it. It does not change during the
    * Objects lifetime. In PluginFunctions.hh are some Functions which help with finding objects using this id.
    */
    int id_;

    /** \brief Persistent ID for this Object
    *
    *  If you need to identify an Object acroos program starts in your plugin then use this id to find it.
    * It will not change across program restarts. This id will only be set if a database plugin manages it.
    */
    int persistentId_;

  //===========================================================================
  /** @name Data Type Handling
    * @{ */
  //===========================================================================

  public:
    /** Check the if the object is of the given type
     * @param _type checks, if the object is of the given type
     */
    bool dataType(DataType _type);

    /** return the dataType of the object
     */
    DataType dataType();

    /** set the object type
     * @param _type the type of the object (if it has a type defined, it will output a warning)
     */
    void setDataType(DataType _type);

  private:
    /** This Field describes the Data Types available in the object. \n
     *  You should check this Field, if your plugin can handle the data in the object.
     */
    DataType objectType_;

  /** @} */

  //===========================================================================
  /** @name Data
   * @{ */
  //===========================================================================

  public:
    /** Clean all data structures of the object
      *
      * */
    virtual void cleanup();

  /** @} */

  //===========================================================================
  /** @name Object Information
   * @{ */
  //===========================================================================
  public:
    /// Get all Info for the Object as a string
    virtual QString getObjectinfo();

    /// Print all information about the object
    virtual void printObjectInfo();

  /** @} */

  //===========================================================================
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
194
  /** @name Flag handling (source, target, ...)
Jan Möbius's avatar
 
Jan Möbius committed
195
196
197
   * @{ */
  //===========================================================================

198
199
200
  signals:
    void objectSelectionChanged(int _objectId);
    
Jan Möbius's avatar
 
Jan Möbius committed
201
202
  public:
    /** Is this item selected as a target item?
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
203
204
205
206
      * Most algorithms operate on target meshes. These meshes are also considered as active.
      * Blending for inactive meshes is handled by DataControlPlugin so emit objectSelectionChanged
      * if you changed this value.\n
      */
Jan Möbius's avatar
 
Jan Möbius committed
207
208
209
210
211
212
213
    bool target();

    /** Set this item as a target
     */
    void target(bool _target);

    /** Is this item selected as a source item?
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
214
215
      * Some algorithms use source meshes to define their input.
      */
Jan Möbius's avatar
 
Jan Möbius committed
216
217
218
219
220
221
    bool source();

    /** Set this item as a source
     */
    void source(bool _source);

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
222
223
224
    /** Get a custom flag of this item
     */
    bool flag(QString _flag);
Jan Möbius's avatar
 
Jan Möbius committed
225

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
226
227
228
    /** Set a custom flag on this item
     */
    void setFlag(QString _flag, bool _set);
Jan Möbius's avatar
 
Jan Möbius committed
229

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
230
    /** Get all flags of this item
Jan Möbius's avatar
 
Jan Möbius committed
231
     */
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
232
233
234
235
236
237
238
239
240
    QStringList flags();

  private:

    /** Stores all item flags as strings. Source and target flags are represented
      * as "source" and "target" strings.
      */
    QStringList flags_;

Jan Möbius's avatar
 
Jan Möbius committed
241
242
243
244
245
246
247

  /** @} */

  //===========================================================================
  /** @name Object visualization
   * @{ */
  //===========================================================================
248
249
250
251
252
253
254
255
256
  
  signals:
    /** This slot is emitted when the visibility of the object gets changed.
    *
    * The signal is normally handled by the core to tell the plugins that an object changed its visibility
    *
    */
    void visibilityChanged(int _objectId);

Jan Möbius's avatar
 
Jan Möbius committed
257
258

  public :
259
260
261
262
263
    /// return if object is visible
    virtual bool visible();

    /// Sets visiblity
    virtual void visible(bool _visible);
Jan Möbius's avatar
 
Jan Möbius committed
264

265
  protected :
Jan Möbius's avatar
 
Jan Möbius committed
266
267
268
269
270
271
272
273
274
275
276
277
278
279
    /** Show/hide/ Object\n
    * Visibility is handled by DataControlPlugin so emit updated_objects if you changed this value
    * defaults to visible
    */
    bool visible_;

  /** @} */

  //===========================================================================
  /** @name Content
   * @{ */
  //===========================================================================

  public:
Jan Möbius's avatar
Jan Möbius committed
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
286
     *
     * \note Do not call this function yourself to avoid unnecessary overhead(the core will call it when it is required)
Jan Möbius's avatar
Jan Möbius committed
287
     */
Dirk Wilden's avatar
Dirk Wilden committed
288
    virtual void update(UpdateType _type = UPDATE_ALL);
Jan Möbius's avatar
 
Jan Möbius committed
289
290
291
292

    /// Debugging function, writing the subtree to output
    void dumpTree();

293
294
295
    /// Returns a full copy of the object
    virtual BaseObject* copy();

Jan Möbius's avatar
 
Jan Möbius committed
296
297
298
299
300
301
302
303
304
305
  /** @} */


  //===========================================================================
    /** @name Tree Structure
    * @{ */
  //===========================================================================

  public:

306
307
308
309
    /** Get the last item of the tree (Preorder traversal of the tree)
     */
    BaseObject* last();

Jan Möbius's avatar
 
Jan Möbius committed
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
    /** Get the next item of the tree (Preorder traversal of the tree)
     */
    BaseObject* next();

    /** level of the current object ( root node has level 0)
     */
    int level();

  private:
    /// Parent item or 0 if rootnode
    BaseObject *parentItem_;

    /// Children of this node
    QList<BaseObject*> childItems_;

  public:
    //===========================================================================
    /** @name Tree : Parent nodes
    * @{ */
    //===========================================================================

331
332
  public:
    
Jan Möbius's avatar
 
Jan Möbius committed
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
    /// get the row of this item from the parent
    int row() const;

    /// Get the parent item ( 0 if rootitem )
    BaseObject *parent();

    /// Set the parent pointer
    void setParent(BaseObject* _parent);

    /** @} */

    //===========================================================================
    /** @name Tree : Children
    * @{ */
    //===========================================================================
348
349
350
    
  public:
    
Jan Möbius's avatar
 
Jan Möbius committed
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
    /// Check if the element exists in the subtree of this element
    BaseObject* childExists(int _objectId);

    /// Check if the element exists in the subtree of this element
    BaseObject* childExists(QString _name);

    /// add a child to this node
    void appendChild(BaseObject *child);

    /// return a child
    BaseObject *child(int row);

    /// get the number of children
    int childCount() const;

    /// Remove a child from this object
    void removeChild( BaseObject* _item );

    /// get all leafes of the tree below this object ( These will be all visible objects )
    QList< BaseObject* > getLeafs();

    /// delete the whole subtree below this item ( The item itself is not touched )
    void deleteSubtree();

    /** @} */

    //===========================================================================
    /** @name Grouping
    * @{ */
    //===========================================================================

382
383
  public:
    
Jan Möbius's avatar
 
Jan Möbius committed
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
    /** Return the primary group of this object or -1 if ungrouped.
     * As this is a tree structure this returns the first group of this object.
     * Groups of groups are only suppurted via the other functions.
     * @return Primary group of this object or -1
     */
    int group();

    /// Check if object is a group
    bool isGroup();

    /** Check if this item belongs to a group with this id
     *
     *  @param _id id of the group
     */
    bool isInGroup( int _id );

    /** Check if this item belongs to a group with this name
      *
      * @param _name Name of the group
      */
    bool isInGroup( QString _name );

    /** Get a vector of all Group ids this object belongs to ( this function omits the root object )
    */
    std::vector< int > getGroupIds();

    /** Get a vector of all group names  this object belongs to ( this function omits the root object )
     */
    QStringList getGroupNames();


    /** @} */

    //===========================================================================
    /** @name Name and Path handling
    * @{ */
    //===========================================================================

422
423
424
425
426
427
428
  signals:
    /** This signal is emitted when properties of the object have been changed like its name
    * or the parent changed
    */
    void objectPropertiesChanged(int _objectId);

  public:
Jan Möbius's avatar
 
Jan Möbius committed
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
    /// return the name of the object. The name defaults to NONAME if unset.
    QString name( );

    /// set the name of the object. ( If you overwrite it, call BaseObject::setName(_name ) it in your funtion first)
    virtual void setName( QString _name );


  private:

    /// Object/FileName ( defaults to NONAME )
    QString name_;


    /** @} */

  //===========================================================================
  /** @name Object Payload
446
   * \anchor baseObjectPerObjectDataFunctions
Jan Möbius's avatar
 
Jan Möbius committed
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
   * @{ */
  //===========================================================================

  public:

    /** Set a pointer to your object data
     * Your data class has to be derived from PerObjectData and should implement a destructor.
     * use dynamic_casts to cast between your object and the Baseclass.
     *
     * @param _dataName Define a name for your data
     * @param _data a pointer to your object data
     */
    void setObjectData( QString _dataName , PerObjectData* _data );

    /// Clear the object data pointer ( this will not delete the object!! )
    void clearObjectData( QString _dataName );

    /// Checks if object data with given name is available
    bool hasObjectData( QString _dataName );

    /// Returns the object data pointer
    PerObjectData* objectData( QString _dataName );

    /// Delete all data attached to this object ( calls delete on each object )
    void deleteData();
472
473
474
475
476
477
478
479
    
    /** @} */
    
    //===========================================================================
    /** @name Object Payload functions for internal use only!
    * @{ */
    //===========================================================================
    
Jan Möbius's avatar
Jan Möbius committed
480
    /** \brief get reference to map of all perObject Datas
481
482
483
484
    *
    * Don't use this function! It's only for the backup Plugin to store and restore
    * perObjectDatas!
    */
Jan Möbius's avatar
Jan Möbius committed
485
    QMap<QString, PerObjectData*>& getPerObjectDataMap();
486
487
    
    
Jan Möbius's avatar
 
Jan Möbius committed
488
489
490
491
492
493
494
495
496
497
498
499
  private:

    QMap<QString, PerObjectData* > dataMap_;

  /** @} */

};


//=============================================================================
#endif // BASEOBJECT_HH defined
//=============================================================================