DataControlPlugin.hh 13.5 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-2014 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




Dirk Wilden's avatar
Dirk Wilden committed
46 47
#ifndef DATACONTROLPLUGIN_HH
#define DATACONTROLPLUGIN_HH
Jan Möbius's avatar
 
Jan Möbius committed
48 49 50 51 52 53 54 55 56


#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
#include <OpenFlipper/BasePlugin/KeyInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/INIInterface.hh>
Dirk Wilden's avatar
Dirk Wilden committed
57
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
Jan Möbius's avatar
 
Jan Möbius committed
58
#include <OpenFlipper/common/Types.hh>
59
#include <ObjectTypes/Light/Light.hh>
60
#include "Toolbox.hh"
Jan Möbius's avatar
 
Jan Möbius committed
61 62

#include "TreeModel.hh"
63
#include "DefaultObjectMarker.hh"
Jan Möbius's avatar
 
Jan Möbius committed
64 65


Jan Möbius's avatar
 
Jan Möbius committed
66
/** Plugin for controlling the Object data structures (Show,hide Object, Target, Source selection
Jan Möbius's avatar
 
Jan Möbius committed
67
*/
Dirk Wilden's avatar
Dirk Wilden committed
68
class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyInterface , LoggingInterface, INIInterface, ContextMenuInterface, ScriptInterface, LoadSaveInterface
Jan Möbius's avatar
 
Jan Möbius committed
69 70 71 72 73 74 75 76
{
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(ToolboxInterface)
  Q_INTERFACES(KeyInterface)
  Q_INTERFACES(LoggingInterface)
  Q_INTERFACES(INIInterface)
  Q_INTERFACES(ContextMenuInterface)
Jan Möbius's avatar
 
Jan Möbius committed
77
  Q_INTERFACES(ScriptInterface)
Dirk Wilden's avatar
Dirk Wilden committed
78
  Q_INTERFACES(LoadSaveInterface)
Jan Möbius's avatar
 
Jan Möbius committed
79

Matthias Möller's avatar
Matthias Möller committed
80 81 82 83
#if QT_VERSION >= 0x050000
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-DataControl")
#endif

Jan Möbius's avatar
 
Jan Möbius committed
84
  signals:
Dirk Wilden's avatar
Dirk Wilden committed
85
    // BaseInterface
Jan Möbius's avatar
 
Jan Möbius committed
86
    void updateView();
87
    void updatedObject(int _it, const UpdateType& _type);
Jan Möbius's avatar
 
Jan Möbius committed
88

Dirk Wilden's avatar
Dirk Wilden committed
89 90 91 92
    void setSlotDescription(QString     _slotName,   QString     _slotDescription,
                            QStringList _parameters, QStringList _descriptions);

    // LoggingInterface
Jan Möbius's avatar
 
Jan Möbius committed
93 94
    void log(Logtype _type, QString _message);
    void log(QString _message);
95
    
Dirk Wilden's avatar
Dirk Wilden committed
96
    // ContextMenuInterface
Jan Möbius's avatar
 
Jan Möbius committed
97 98
    void addContextMenuItem(QAction* _action , ContextMenuType _type);
    void addContextMenuItem(QAction* _action , DataType _objectType , ContextMenuType _type );
99
    
100 101
    // LoadSaveInterface
    void deleteObject( int _id );
102
    void emptyObjectAdded( int _id );
103
    void copyObject( int _oldId, int& _newId);
104 105
    
    // ToolboxInterface
Dirk Wilden's avatar
Dirk Wilden committed
106
    void addToolbox( QString _name  , QWidget* _widget, QIcon* _icon );
107

Dirk Wilden's avatar
Dirk Wilden committed
108 109
  private slots :
    // BaseInterface
110
    void initializePlugin();
Dirk Wilden's avatar
Dirk Wilden committed
111
    void pluginsInitialized();
Dirk Wilden's avatar
Dirk Wilden committed
112 113 114
    void slotVisibilityChanged      ( int _identifier );
    void slotObjectSelectionChanged ( int _identifier );
    void slotObjectPropertiesChanged( int _identifier );
Jan Möbius's avatar
 
Jan Möbius committed
115

Dirk Wilden's avatar
Dirk Wilden committed
116 117
    // KeyInterface
    void slotKeyEvent( QKeyEvent* _event );
Jan Möbius's avatar
 
Jan Möbius committed
118

Dirk Wilden's avatar
Dirk Wilden committed
119 120 121
    // INIInterface
    void loadIniFileOptionsLast( INIFile& _ini );
    void saveIniFileOptions( INIFile& _ini );
122
    void saveOnExit(INIFile& _ini );
Jan Möbius's avatar
 
Jan Möbius committed
123

Dirk Wilden's avatar
Dirk Wilden committed
124 125 126
    // LoadSaveInterface
    void fileOpened(int _id);
    void addedEmptyObject(int _id);
Dirk Wilden's avatar
Dirk Wilden committed
127
    void objectDeleted(int _id);
Dirk Wilden's avatar
Dirk Wilden committed
128

129 130 131
    // Tell system that this plugin runs without ui
    void noguiSupported( ) {} ;

Dirk Wilden's avatar
Dirk Wilden committed
132
  public :
Jan Möbius's avatar
Jan Möbius committed
133 134 135 136

    /// Constructor
    DataControlPlugin();

Dirk Wilden's avatar
Dirk Wilden committed
137 138
    /// Destructor
    ~DataControlPlugin() {};
Jan Möbius's avatar
 
Jan Möbius committed
139

Dirk Wilden's avatar
Dirk Wilden committed
140 141
    /// Name of the Plugin
    QString name(){ return (QString("DataControl")); };
Jan Möbius's avatar
 
Jan Möbius committed
142

Dirk Wilden's avatar
Dirk Wilden committed
143
    /// Description of the Plugin
Jan Möbius's avatar
Jan Möbius committed
144
    QString description() { return (QString(tr("Manages Data Objects"))); };
Jan Möbius's avatar
 
Jan Möbius committed
145

Dirk Wilden's avatar
Dirk Wilden committed
146 147 148
  private :
    /// Widget for Toolbox
    DatacontrolToolboxWidget* tool_;
Dirk Wilden's avatar
Dirk Wilden committed
149
    QIcon* toolIcon_;
Jan Möbius's avatar
 
Jan Möbius committed
150

Dirk Wilden's avatar
Dirk Wilden committed
151 152
    /// Layout for Toolbox
    QGridLayout* MeshDialogLayout_;
Jan Möbius's avatar
 
Jan Möbius committed
153

Dirk Wilden's avatar
Dirk Wilden committed
154 155
    /// Table containing Mesh information and status
    QTableWidget* objectList_;
Jan Möbius's avatar
 
Jan Möbius committed
156

Dirk Wilden's avatar
Dirk Wilden committed
157 158
    /// Flag set to true if meshlist is updated, preventing signal for list udate to be called
    bool locked;
Jan Möbius's avatar
 
Jan Möbius committed
159

Dirk Wilden's avatar
Dirk Wilden committed
160 161
    /// The Treemodel organizing the data
    TreeModel* model_;
Jan Möbius's avatar
 
Jan Möbius committed
162

Dirk Wilden's avatar
Dirk Wilden committed
163 164
    ///Tree view
    QTreeView* view_;
Jan Möbius's avatar
 
Jan Möbius committed
165

Dirk Wilden's avatar
Dirk Wilden committed
166 167
    /// Pointer to the header to the view widget
    QHeaderView * viewHeader_;
Jan Möbius's avatar
 
Jan Möbius committed
168

169 170 171
    /// Default marker to visualize "source" and "target" object flags
    DefaultObjectMarker objectMarker;

Dirk Wilden's avatar
Dirk Wilden committed
172

Dirk Wilden's avatar
Dirk Wilden committed
173 174 175 176
//===========================================================================
/** @name Slots which are called if data changed
* @{ */
//===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
177

Dirk Wilden's avatar
Dirk Wilden committed
178
  private slots:
Jan Möbius's avatar
 
Jan Möbius committed
179

Dirk Wilden's avatar
Dirk Wilden committed
180
    /// Gets called when the data in the table has changed
Dirk Wilden's avatar
Dirk Wilden committed
181
    void slotDataChanged (int _id, int _column, const QVariant& _value);
Jan Möbius's avatar
 
Jan Möbius committed
182

Dirk Wilden's avatar
Dirk Wilden committed
183 184
    /// Gets called when an object was moved via drag n drop
    void slotMoveBaseObject (int _id, int _newParentId);
Jan Möbius's avatar
 
Jan Möbius committed
185

Dirk Wilden's avatar
Dirk Wilden committed
186
  private:
Dirk Wilden's avatar
Dirk Wilden committed
187 188
    void propagateDownwards(BaseObject* _obj, int _column );
    void propagateUpwards(BaseObject* _obj, int _column );
Jan Möbius's avatar
 
Jan Möbius committed
189

190 191 192
    //variables to restrict propagation direction
    int onlyDown_;
    int onlyUp_;
193 194 195 196
    //defines, which selection column needs an update if not -1
    // 2: source 3: target
    int columnFromGUI_;

Dirk Wilden's avatar
Dirk Wilden committed
197
/** @} */
Jan Möbius's avatar
 
Jan Möbius committed
198

Dirk Wilden's avatar
Dirk Wilden committed
199 200 201 202
//===========================================================================
/** @name Popup Menu related
* @{ */
//===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
203 204 205
      private slots:
        /// Display a custom context window for the TreeView
        void slotCustomContextMenuRequested ( const QPoint & _pos );
Jan Möbius's avatar
 
Jan Möbius committed
206

Jan Möbius's avatar
 
Jan Möbius committed
207 208
        /// Called by the popup menu to remove an object/group
        void slotPopupRemove( );
Jan Möbius's avatar
 
Jan Möbius committed
209

Jan Möbius's avatar
 
Jan Möbius committed
210 211
        /// Called by the popup menu to ungroup items
        void slotUngroup ( );
Jan Möbius's avatar
 
Jan Möbius committed
212

Jan Möbius's avatar
 
Jan Möbius committed
213 214
        /// Called by the popup menu to group items
        void slotGroup ( );
Jan Möbius's avatar
 
Jan Möbius committed
215

216 217 218
        /// Called by the popup menu to copy items
        void slotCopy();

Jan Möbius's avatar
 
Jan Möbius committed
219 220
        ///Called by the popup menu to rename items
        void slotRename ( );
Dirk Wilden's avatar
Dirk Wilden committed
221 222 223

        ///Called by the popup menu to zoom to an object
        void slotZoomTo();
224 225 226
        
        /// Called by the popup menu in order to turn lights on/off
        void slotSwitchLight();
227 228 229
        
        /// Called by the popup menu in order to edit lights
        void slotEditLight();
Jan Möbius's avatar
 
Jan Möbius committed
230

Dirk Wilden's avatar
Dirk Wilden committed
231 232 233
        ///Called by the popup menu to set material properties
        void slotMaterialProperties();

234 235 236
        ///Called by the popup menu to copy material properties
        void slotCopyMaterialToTargeted();

Jan Möbius's avatar
Jan Möbius committed
237 238 239 240
        /** \brief Called when the material properties were changed inside the material dialog
         *
         * @param _node unused
         */
Dirk Wilden's avatar
Dirk Wilden committed
241
        void slotNodeChanged( ACG::SceneGraph::BaseNode* _node );
242 243 244
        
        /// Hide/Show all light sources if checkbox has been checked
        void slotShowLightSources( int _state );
245
        void slotShowLightSources();
Dirk Wilden's avatar
Dirk Wilden committed
246

Jan Möbius's avatar
 
Jan Möbius committed
247 248 249
      private :
        /// Index where a popup has been opened
        QModelIndex popupIndex_;
Jan Möbius's avatar
 
Jan Möbius committed
250

Jan Möbius's avatar
 
Jan Möbius committed
251
      private slots:
Jan Möbius's avatar
 
Jan Möbius committed
252

Jan Möbius's avatar
 
Jan Möbius committed
253 254
        /// Display a custom context window for the TreeViews header
        void slotHeaderCustomContextMenuRequested ( const QPoint & _pos );
Jan Möbius's avatar
 
Jan Möbius committed
255

Jan Möbius's avatar
 
Jan Möbius committed
256 257 258
      private:
        /// Defines the section of the Popup
        int headerPopupType_;
Jan Möbius's avatar
 
Jan Möbius committed
259

Dirk Wilden's avatar
Dirk Wilden committed
260
/** @} */
Jan Möbius's avatar
 
Jan Möbius committed
261

Dirk Wilden's avatar
Dirk Wilden committed
262 263 264 265
//===========================================================================
/** @name GL Area Context Menu related slots
* @{ */
//===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
266

Jan Möbius's avatar
 
Jan Möbius committed
267
      private slots:
Jan Möbius's avatar
 
Jan Möbius committed
268

Jan Möbius's avatar
 
Jan Möbius committed
269 270
        /// Hide an object
        void slotContextMenuHide( );
Jan Möbius's avatar
 
Jan Möbius committed
271

Jan Möbius's avatar
 
Jan Möbius committed
272 273
        /// Target Selection
        void slotContextMenuTarget( );
Jan Möbius's avatar
 
Jan Möbius committed
274

Jan Möbius's avatar
 
Jan Möbius committed
275 276
        /// Source Selection
        void slotContextMenuSource( );
Dirk Wilden's avatar
 
Dirk Wilden committed
277 278 279
        
        /// Remove Selected Item
        void slotContextMenuRemove( );
Jan Möbius's avatar
 
Jan Möbius committed
280

Jan Möbius's avatar
 
Jan Möbius committed
281 282
        /// Update the context Menus for the given id
        void slotUpdateContextMenu( int _objectId);
Jan Möbius's avatar
 
Jan Möbius committed
283

Jan Möbius's avatar
 
Jan Möbius committed
284 285 286
      private :
        QAction* targetAction_;
        QAction* sourceAction_;
Dirk Wilden's avatar
 
Dirk Wilden committed
287
        QAction* removeAction_;
Jan Möbius's avatar
 
Jan Möbius committed
288

Dirk Wilden's avatar
Dirk Wilden committed
289
/** @} */
Jan Möbius's avatar
 
Jan Möbius committed
290

291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
//===========================================================================
/** @name Bounding box related slots/functions
* @{ */
//===========================================================================

      private slots:

        /// Bounding box selection changed
        void slotBoundingBoxChange( );

     private:

        /// Updates bounding box
        void updateBoundingBox(BaseObjectData* _obj);

/** @} */

Dirk Wilden's avatar
Dirk Wilden committed
308 309 310 311
//===========================================================================
/** @name Scripting functions
* @{ */
//===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
312

Dirk Wilden's avatar
Dirk Wilden committed
313
      private slots:
Jan Möbius's avatar
Jan Möbius committed
314 315 316 317

        /** This function sets the slot descriptions for this plugin
         *  which will be visible in the script editor
         */
Dirk Wilden's avatar
Dirk Wilden committed
318 319
        void setDescriptions();

Jan Möbius's avatar
 
Jan Möbius committed
320 321 322
      public slots:
        /// Get the Objects name from the id
        QString getObjectName( int objectId );
Jan Möbius's avatar
 
Jan Möbius committed
323

324
        /// Delete the given object
325
        void objectDelete(int objectId);
326

Jan Möbius's avatar
Jan Möbius committed
327 328 329
        /// Creates an object copy
        int copyObject( int objectId );

Jan Möbius's avatar
 
Jan Möbius committed
330 331
        /// Get the id of an object by its name
        int getObject( QString _name );
Jan Möbius's avatar
 
Jan Möbius committed
332

333 334 335
        /// Get the DataType of a given object
        DataType dataType( int objectId );

Jan Möbius's avatar
 
Jan Möbius committed
336 337
        /// Hide the given Object
        void hideObject( int objectId );
Jan Möbius's avatar
 
Jan Möbius committed
338

Jan Möbius's avatar
 
Jan Möbius committed
339
        /// Show the given Object
Jan Möbius's avatar
 
Jan Möbius committed
340 341
        void showObject( int objectId );

Dirk Wilden's avatar
Dirk Wilden committed
342 343 344 345 346 347 348 349 350
        /// set the given Object as target
        void setTarget( int objectId, bool _target );

        /// set the given Object as source
        void setSource( int objectId, bool _source );

        /// set the name of the given object
        void setObjectName( int objectId, QString _name );

Jan Möbius's avatar
 
Jan Möbius committed
351 352
        /// Makes all available objects target
        void setAllTarget();
Jan Möbius's avatar
 
Jan Möbius committed
353

Jan Möbius's avatar
 
Jan Möbius committed
354 355
        /// Makes all available objects source
        void setAllSource();
Jan Möbius's avatar
 
Jan Möbius committed
356

Jan Möbius's avatar
 
Jan Möbius committed
357 358
        /// Unselect all objects
        void clearAllTarget();
Jan Möbius's avatar
 
Jan Möbius committed
359

Jan Möbius's avatar
 
Jan Möbius committed
360 361
        /// remove source selection from all objects
        void clearAllSource();
Jan Möbius's avatar
 
Jan Möbius committed
362

Jan Möbius's avatar
 
Jan Möbius committed
363 364
        /// Shows all objects
        void showAll();
Jan Möbius's avatar
 
Jan Möbius committed
365

Jan Möbius's avatar
 
Jan Möbius committed
366 367
        /// Hides all objects
        void hideAll();
Jan Möbius's avatar
 
Jan Möbius committed
368

369 370 371 372
        /** Group objects together
        *
        * @return object id of new group or -1 if failed
        */
Jan Möbius's avatar
Jan Möbius committed
373
        int groupObjects(IdList _objectIDs, QString _groupName = "");
374
        
375
        /// add an object to an existing group
Matthias Möller's avatar
Matthias Möller committed
376
        bool addObjectToGroup(int _objectId, int _groupId);
377

378 379 380 381 382
        /** remove an object from its group and place it at the toplevel group
        *
        * @return successfull
        */
        bool unGroupObject(int _id);
383 384 385 386 387 388
        
        /// Get all target objects of given type
        IdList getTargetObjects(DataType _type);
        
        /// Get all source objects of given type
        IdList getSourceObjects(DataType _type);
Dirk Wilden's avatar
Dirk Wilden committed
389

390 391 392
        /// Returns the number of groups
        unsigned int groupCount() const;

393 394 395
        /// Returns a list of all available DataTypes
        QStringList availableDataTypeNames() const;

396 397 398
        /// Print information about all open objects to the console
        void printObjectInfoToLog();

399 400 401
        /// Get all elements of the given group
        IdList getGroupElements(int _groupId);

Jan Möbius's avatar
Jan Möbius committed
402 403
        void showReducedUi(bool reduced);

Dirk Wilden's avatar
Dirk Wilden committed
404
/** @} */
Jan Möbius's avatar
 
Jan Möbius committed
405 406

  public slots:
Dirk Wilden's avatar
Dirk Wilden committed
407
    QString version() { return QString("1.03"); };
Jan Möbius's avatar
 
Jan Möbius committed
408 409
};

Dirk Wilden's avatar
Dirk Wilden committed
410
#endif //DATACONTROLPLUGIN_HH