DataControlPlugin.hh 14.9 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
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
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40 41 42
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
43 44 45 46 47
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
48
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
49 50 51 52




Dirk Wilden's avatar
Dirk Wilden committed
53 54
#ifndef DATACONTROLPLUGIN_HH
#define DATACONTROLPLUGIN_HH
Jan Möbius's avatar
 
Jan Möbius committed
55 56 57 58 59 60 61 62 63


#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
64
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
Jan Möbius's avatar
 
Jan Möbius committed
65
#include <OpenFlipper/common/Types.hh>
66
#include <ObjectTypes/Light/Light.hh>
67
#include "Toolbox.hh"
Jan Möbius's avatar
 
Jan Möbius committed
68 69

#include "TreeModel.hh"
70
#include "DefaultObjectMarker.hh"
Jan Möbius's avatar
 
Jan Möbius committed
71 72


Jan Möbius's avatar
 
Jan Möbius committed
73
/** Plugin for controlling the Object data structures (Show,hide Object, Target, Source selection
Jan Möbius's avatar
 
Jan Möbius committed
74
*/
Dirk Wilden's avatar
Dirk Wilden committed
75
class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyInterface , LoggingInterface, INIInterface, ContextMenuInterface, ScriptInterface, LoadSaveInterface
Jan Möbius's avatar
 
Jan Möbius committed
76 77 78 79 80 81 82 83
{
  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
84
  Q_INTERFACES(ScriptInterface)
Dirk Wilden's avatar
Dirk Wilden committed
85
  Q_INTERFACES(LoadSaveInterface)
Jan Möbius's avatar
 
Jan Möbius committed
86

Matthias Möller's avatar
Matthias Möller committed
87 88 89 90
#if QT_VERSION >= 0x050000
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-DataControl")
#endif

Jan Möbius's avatar
 
Jan Möbius committed
91
  signals:
Dirk Wilden's avatar
Dirk Wilden committed
92
    // BaseInterface
Jan Möbius's avatar
 
Jan Möbius committed
93
    void updateView();
94
    void updatedObject(int _it, const UpdateType& _type);
Jan Möbius's avatar
 
Jan Möbius committed
95

Dirk Wilden's avatar
Dirk Wilden committed
96 97 98 99
    void setSlotDescription(QString     _slotName,   QString     _slotDescription,
                            QStringList _parameters, QStringList _descriptions);

    // LoggingInterface
Jan Möbius's avatar
 
Jan Möbius committed
100 101
    void log(Logtype _type, QString _message);
    void log(QString _message);
102
    
Dirk Wilden's avatar
Dirk Wilden committed
103
    // ContextMenuInterface
Jan Möbius's avatar
 
Jan Möbius committed
104 105
    void addContextMenuItem(QAction* _action , ContextMenuType _type);
    void addContextMenuItem(QAction* _action , DataType _objectType , ContextMenuType _type );
106
    
107 108
    // LoadSaveInterface
    void deleteObject( int _id );
109
    void emptyObjectAdded( int _id );
110
    void copyObject( int _oldId, int& _newId);
111 112
    
    // ToolboxInterface
Dirk Wilden's avatar
Dirk Wilden committed
113
    void addToolbox( QString _name  , QWidget* _widget, QIcon* _icon );
114

Dirk Wilden's avatar
Dirk Wilden committed
115 116
  private slots :
    // BaseInterface
117
    void initializePlugin();
Dirk Wilden's avatar
Dirk Wilden committed
118
    void pluginsInitialized();
Dirk Wilden's avatar
Dirk Wilden committed
119 120 121
    void slotVisibilityChanged      ( int _identifier );
    void slotObjectSelectionChanged ( int _identifier );
    void slotObjectPropertiesChanged( int _identifier );
122
    void slotObjectUpdated( int _identifier, const UpdateType& _type );
Jan Möbius's avatar
 
Jan Möbius committed
123

Dirk Wilden's avatar
Dirk Wilden committed
124 125
    // KeyInterface
    void slotKeyEvent( QKeyEvent* _event );
Jan Möbius's avatar
 
Jan Möbius committed
126

Dirk Wilden's avatar
Dirk Wilden committed
127 128 129
    // INIInterface
    void loadIniFileOptionsLast( INIFile& _ini );
    void saveIniFileOptions( INIFile& _ini );
130
    void saveOnExit(INIFile& _ini );
Jan Möbius's avatar
 
Jan Möbius committed
131

Dirk Wilden's avatar
Dirk Wilden committed
132 133 134
    // LoadSaveInterface
    void fileOpened(int _id);
    void addedEmptyObject(int _id);
Dirk Wilden's avatar
Dirk Wilden committed
135
    void objectDeleted(int _id);
Dirk Wilden's avatar
Dirk Wilden committed
136

137 138 139
    // Tell system that this plugin runs without ui
    void noguiSupported( ) {} ;

Dirk Wilden's avatar
Dirk Wilden committed
140
  public :
Jan Möbius's avatar
Jan Möbius committed
141 142 143 144

    /// Constructor
    DataControlPlugin();

Dirk Wilden's avatar
Dirk Wilden committed
145 146
    /// Destructor
    ~DataControlPlugin() {};
Jan Möbius's avatar
 
Jan Möbius committed
147

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

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

Dirk Wilden's avatar
Dirk Wilden committed
154 155 156
  private :
    /// Widget for Toolbox
    DatacontrolToolboxWidget* tool_;
Dirk Wilden's avatar
Dirk Wilden committed
157
    QIcon* toolIcon_;
Jan Möbius's avatar
 
Jan Möbius committed
158

Dirk Wilden's avatar
Dirk Wilden committed
159 160
    /// Layout for Toolbox
    QGridLayout* MeshDialogLayout_;
Jan Möbius's avatar
 
Jan Möbius committed
161

Dirk Wilden's avatar
Dirk Wilden committed
162 163
    /// Table containing Mesh information and status
    QTableWidget* objectList_;
Jan Möbius's avatar
 
Jan Möbius committed
164

Dirk Wilden's avatar
Dirk Wilden committed
165 166
    /// 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
167

Dirk Wilden's avatar
Dirk Wilden committed
168 169
    /// The Treemodel organizing the data
    TreeModel* model_;
Jan Möbius's avatar
 
Jan Möbius committed
170

Dirk Wilden's avatar
Dirk Wilden committed
171 172
    ///Tree view
    QTreeView* view_;
Jan Möbius's avatar
 
Jan Möbius committed
173

Dirk Wilden's avatar
Dirk Wilden committed
174 175
    /// Pointer to the header to the view widget
    QHeaderView * viewHeader_;
Jan Möbius's avatar
 
Jan Möbius committed
176

177 178 179
    /// Default marker to visualize "source" and "target" object flags
    DefaultObjectMarker objectMarker;

Dirk Wilden's avatar
Dirk Wilden committed
180

Dirk Wilden's avatar
Dirk Wilden committed
181 182 183 184
//===========================================================================
/** @name Slots which are called if data changed
* @{ */
//===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
185

Dirk Wilden's avatar
Dirk Wilden committed
186
  private slots:
Jan Möbius's avatar
 
Jan Möbius committed
187

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

Dirk Wilden's avatar
Dirk Wilden committed
191 192
    /// 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
193

Dirk Wilden's avatar
Dirk Wilden committed
194
  private:
Dirk Wilden's avatar
Dirk Wilden committed
195 196
    void propagateDownwards(BaseObject* _obj, int _column );
    void propagateUpwards(BaseObject* _obj, int _column );
Jan Möbius's avatar
 
Jan Möbius committed
197

198 199 200
    //variables to restrict propagation direction
    int onlyDown_;
    int onlyUp_;
201 202 203 204
    //defines, which selection column needs an update if not -1
    // 2: source 3: target
    int columnFromGUI_;

Dirk Wilden's avatar
Dirk Wilden committed
205
/** @} */
Jan Möbius's avatar
 
Jan Möbius committed
206

Dirk Wilden's avatar
Dirk Wilden committed
207 208 209 210
//===========================================================================
/** @name Popup Menu related
* @{ */
//===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
211 212 213
      private slots:
        /// Display a custom context window for the TreeView
        void slotCustomContextMenuRequested ( const QPoint & _pos );
Jan Möbius's avatar
 
Jan Möbius committed
214

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

Jan Möbius's avatar
 
Jan Möbius committed
218 219
        /// Called by the popup menu to ungroup items
        void slotUngroup ( );
Jan Möbius's avatar
 
Jan Möbius committed
220

Jan Möbius's avatar
 
Jan Möbius committed
221 222
        /// Called by the popup menu to group items
        void slotGroup ( );
Jan Möbius's avatar
 
Jan Möbius committed
223

224 225 226
        /// Called by the popup menu to copy items
        void slotCopy();

Jan Möbius's avatar
 
Jan Möbius committed
227 228
        ///Called by the popup menu to rename items
        void slotRename ( );
Dirk Wilden's avatar
Dirk Wilden committed
229 230 231

        ///Called by the popup menu to zoom to an object
        void slotZoomTo();
232 233 234
        
        /// Called by the popup menu in order to turn lights on/off
        void slotSwitchLight();
235 236 237
        
        /// Called by the popup menu in order to edit lights
        void slotEditLight();
Jan Möbius's avatar
 
Jan Möbius committed
238

Dirk Wilden's avatar
Dirk Wilden committed
239 240 241
        ///Called by the popup menu to set material properties
        void slotMaterialProperties();

242 243 244
        ///Called by the popup menu to copy material properties
        void slotCopyMaterialToTargeted();

245 246 247 248 249 250
        ///Called by the popup menu to copy material properties to clipboard
        void slotCopyMaterialToClipboard();

        ///Called by the popup menu to paste material properties from clipboard
        void slotPasteMaterialFromClipboard();

Jan Möbius's avatar
Jan Möbius committed
251 252 253 254
        /** \brief Called when the material properties were changed inside the material dialog
         *
         * @param _node unused
         */
Dirk Wilden's avatar
Dirk Wilden committed
255
        void slotNodeChanged( ACG::SceneGraph::BaseNode* _node );
256 257
        
        /// Hide/Show all light sources if checkbox has been checked
258
        void slotShowLightSources( bool _state );
259
        void slotShowLightSources();
Dirk Wilden's avatar
Dirk Wilden committed
260

Jan Möbius's avatar
 
Jan Möbius committed
261 262 263
      private :
        /// Index where a popup has been opened
        QModelIndex popupIndex_;
Jan Möbius's avatar
 
Jan Möbius committed
264

Jan Möbius's avatar
 
Jan Möbius committed
265
      private slots:
Jan Möbius's avatar
 
Jan Möbius committed
266

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

Jan Möbius's avatar
 
Jan Möbius committed
270 271 272
      private:
        /// Defines the section of the Popup
        int headerPopupType_;
Jan Möbius's avatar
 
Jan Möbius committed
273

Dirk Wilden's avatar
Dirk Wilden committed
274
/** @} */
Jan Möbius's avatar
 
Jan Möbius committed
275

Dirk Wilden's avatar
Dirk Wilden committed
276 277 278 279
//===========================================================================
/** @name GL Area Context Menu related slots
* @{ */
//===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
280

Jan Möbius's avatar
 
Jan Möbius committed
281
      private slots:
Jan Möbius's avatar
 
Jan Möbius committed
282

Jan Möbius's avatar
 
Jan Möbius committed
283 284
        /// Hide an object
        void slotContextMenuHide( );
Jan Möbius's avatar
 
Jan Möbius committed
285

Jan Möbius's avatar
 
Jan Möbius committed
286 287
        /// Target Selection
        void slotContextMenuTarget( );
Jan Möbius's avatar
 
Jan Möbius committed
288

Jan Möbius's avatar
 
Jan Möbius committed
289 290
        /// Source Selection
        void slotContextMenuSource( );
Dirk Wilden's avatar
 
Dirk Wilden committed
291 292 293
        
        /// Remove Selected Item
        void slotContextMenuRemove( );
Jan Möbius's avatar
 
Jan Möbius committed
294

Jan Möbius's avatar
 
Jan Möbius committed
295 296
        /// Update the context Menus for the given id
        void slotUpdateContextMenu( int _objectId);
Jan Möbius's avatar
 
Jan Möbius committed
297

Jan Möbius's avatar
 
Jan Möbius committed
298 299 300
      private :
        QAction* targetAction_;
        QAction* sourceAction_;
Dirk Wilden's avatar
 
Dirk Wilden committed
301
        QAction* removeAction_;
Jan Möbius's avatar
 
Jan Möbius committed
302

303 304
        QToolButton *advancedSettingsBtn_;

Dirk Wilden's avatar
Dirk Wilden committed
305
/** @} */
Jan Möbius's avatar
 
Jan Möbius committed
306

307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
//===========================================================================
/** @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
324 325 326 327
//===========================================================================
/** @name Scripting functions
* @{ */
//===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
328

Dirk Wilden's avatar
Dirk Wilden committed
329
      private slots:
Jan Möbius's avatar
Jan Möbius committed
330 331 332 333

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

Jan Möbius's avatar
 
Jan Möbius committed
336 337 338
      public slots:
        /// Get the Objects name from the id
        QString getObjectName( int objectId );
Jan Möbius's avatar
 
Jan Möbius committed
339

340
        /// Delete the given object
341
        void objectDelete(int objectId);
342

Jan Möbius's avatar
Jan Möbius committed
343 344 345
        /// Creates an object copy
        int copyObject( int objectId );

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

349 350 351
        /// Get the DataType of a given object
        DataType dataType( int objectId );

Jan Möbius's avatar
 
Jan Möbius committed
352 353
        /// Hide the given Object
        void hideObject( int objectId );
Jan Möbius's avatar
 
Jan Möbius committed
354

Jan Möbius's avatar
 
Jan Möbius committed
355
        /// Show the given Object
Jan Möbius's avatar
 
Jan Möbius committed
356 357
        void showObject( int objectId );

Dirk Wilden's avatar
Dirk Wilden committed
358 359 360 361 362 363 364 365 366
        /// 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
367 368
        /// Makes all available objects target
        void setAllTarget();
Jan Möbius's avatar
 
Jan Möbius committed
369

Jan Möbius's avatar
 
Jan Möbius committed
370 371
        /// Makes all available objects source
        void setAllSource();
Jan Möbius's avatar
 
Jan Möbius committed
372

Jan Möbius's avatar
 
Jan Möbius committed
373 374
        /// Unselect all objects
        void clearAllTarget();
Jan Möbius's avatar
 
Jan Möbius committed
375

Jan Möbius's avatar
 
Jan Möbius committed
376 377
        /// remove source selection from all objects
        void clearAllSource();
Jan Möbius's avatar
 
Jan Möbius committed
378

Jan Möbius's avatar
 
Jan Möbius committed
379 380
        /// Shows all objects
        void showAll();
Jan Möbius's avatar
 
Jan Möbius committed
381

Jan Möbius's avatar
 
Jan Möbius committed
382 383
        /// Hides all objects
        void hideAll();
Jan Möbius's avatar
 
Jan Möbius committed
384

385 386 387 388 389 390 391 392 393 394 395
		/** Create and add an empty group.
		 *
		 * @param _groupName Name of the new group. If it is an empty string,
		 *        a default name based on group id will be generated.
		 * @param _parentGroupId Parent object under which the new group is
		 *        created. If _parentGroupId is zero, the corresponding object
		 *        does not exist or it is not a group, the new group is created
		 *        as toplevel.
		 */
		int addEmptyGroup(QString _groupName = "", int _parentGroupId = 0);

396 397 398 399
        /** Group objects together
        *
        * @return object id of new group or -1 if failed
        */
Jan Möbius's avatar
Jan Möbius committed
400
        int groupObjects(IdList _objectIDs, QString _groupName = "");
401
        
402
        /// add an object to an existing group
Matthias Möller's avatar
Matthias Möller committed
403
        bool addObjectToGroup(int _objectId, int _groupId);
404

405 406 407 408 409
        /** remove an object from its group and place it at the toplevel group
        *
        * @return successfull
        */
        bool unGroupObject(int _id);
410 411 412 413 414 415
        
        /// 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
416

417 418 419
        /// Returns the number of groups
        unsigned int groupCount() const;

420 421 422
        /// Returns a list of all available DataTypes
        QStringList availableDataTypeNames() const;

423 424 425
        /// Print information about all open objects to the console
        void printObjectInfoToLog();

426 427 428
        /// Get all elements of the given group
        IdList getGroupElements(int _groupId);

Jan Möbius's avatar
Jan Möbius committed
429 430
        void showReducedUi(bool reduced);

Dirk Wilden's avatar
Dirk Wilden committed
431
/** @} */
Jan Möbius's avatar
 
Jan Möbius committed
432 433

  public slots:
Dirk Wilden's avatar
Dirk Wilden committed
434
    QString version() { return QString("1.03"); };
Jan Möbius's avatar
 
Jan Möbius committed
435 436
};

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