ViewControlPlugin.hh 13.3 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
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
#pragma once
43 44 45 46

#include <QObject>
#include <QMenuBar>
#include <QGroupBox>
Jan Möbius's avatar
Jan Möbius committed
47
#include <QCheckBox>
48 49 50 51

#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/PickingInterface.hh>
Jan Möbius's avatar
Jan Möbius committed
52
#include <OpenFlipper/BasePlugin/PythonInterface.hh>
53
#include <OpenFlipper/BasePlugin/ToolbarInterface.hh>
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
#include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include "shaderWidget.hh"

struct ShaderInfo {
      QString name;
      QString description;
      QString details;
      QString version;
      QString example;

      QString directory;

      QString vertexShader;
      QString fragmentShader;

Jan Möbius's avatar
Jan Möbius committed
72 73 74
      QString pickVertexShader;
      QString pickFragmentShader;

75 76 77 78 79 80 81 82
      bool        hasUniforms;
      QStringList uniforms;
      QStringList uniformTypes;
      QStringList uniformsDefault;
      QStringList uniformsMax;
      QStringList uniformsMin;
};

Jan Möbius's avatar
Jan Möbius committed
83
class ViewControlPlugin : public QObject, BaseInterface , PickingInterface, LoggingInterface, ToolbarInterface, ContextMenuInterface, PythonInterface
84 85 86 87 88
{
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(PickingInterface)
  Q_INTERFACES(LoggingInterface)
89
  Q_INTERFACES(ToolbarInterface)
90
  Q_INTERFACES(ContextMenuInterface)
Jan Möbius's avatar
Jan Möbius committed
91
  Q_INTERFACES(PythonInterface)
92

93 94
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-ViewControl")

95
  signals:
96
    //BaseInterface
97 98
    void updateView();

99
    //PickingInterface
100
    void addHiddenPickMode( const std::string& _mode );
101 102
    
    //LoggingInterface
103 104
    void log(Logtype _type, QString _message);
    void log(QString _message);
105 106 107 108
    
    //ToolbarInterface
    void addToolbar(QToolBar* _toolbar);
    void getToolBar(QString _name, QToolBar*& _toolbar);
109

110 111 112
    // ContextMenuInterface
    void addContextMenuItem(QAction* _action , ContextMenuType _type);
    void addContextMenuItem(QAction* _action , DataType _objectType , ContextMenuType _type );
113
    void hideContextMenu();
114

Jan Möbius's avatar
Jan Möbius committed
115 116 117
    void setSlotDescription(QString     _slotName,   QString     _slotDescription,
                            QStringList _parameters, QStringList _descriptions);

118 119 120 121 122 123 124 125 126 127
  private slots:

    void pluginsInitialized();

    void contextMenuTriggered(QAction* _action);

    void slotUpdateContextMenu( int _objectId );

  public :

128
    ViewControlPlugin();
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
    ~ViewControlPlugin() {};


    QString name() { return (QString("ViewControl")); };
    QString description( ) { return (QString("Control the current or global visualization settings")); };


  private:
    QMenu* viewControlMenu_;

    /** Last object id for context menu. Is -1 if no object was selected
     */
    int lastObjectId_;

    /** Active draw Modes for the last clicked object and its children
     */
145
    ACG::SceneGraph::DrawModes::DrawMode activeDrawModes_;
146 147 148

    /** Available draw Modes for the last clicked object and its children
     */
149
    ACG::SceneGraph::DrawModes::DrawMode availDrawModes_;
150 151 152 153 154 155

    ShaderWidget* shaderWidget_;

    /** List of available shaders
    */
    std::vector <ShaderInfo> shaderList_;
156
    
157
    QToolBar*     toolbar_;
158
    QActionGroup* toolbarViewingDirections_;
159 160 161 162 163 164
    QAction*      viewTop_;
    QAction*      viewBottom_;
    QAction*      viewLeft_;
    QAction*      viewRight_;
    QAction*      viewFront_;
    QAction*      viewBack_;
165

166 167
    std::map<QCheckBox*, ACG::SceneGraph::DrawModes::DrawMode> activeCheckboxes;

168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
  private slots:
    QString version() { return QString("1.0"); };

    // This slot is called when a custom draw mode is selected from the context menu
    void slotDrawModeSelected( QAction * _action );

    // This slot is called when the user clicks on an item in the shaderWidget
    void slotShaderClicked( QListWidgetItem * _item );

    // This slot is called when the user doubleclicks on an item in the shaderWidget
    void slotShaderDoubleClicked( QListWidgetItem * _item );

    // slot for setting a shader from the widget
    void slotSetShader();

    // slot is called when the data of the uniforms-table changes
    void itemChanged(QTableWidgetItem* item);
185 186 187 188 189 190
    
    // Set the view to one of the six possible look-at directions
    void setView(int _mode, int _viewer = PluginFunctions::ACTIVE_VIEWER );
    
    // Set the view mode using the defined actions
    void setView(QAction* _action);
191 192 193 194 195 196 197 198

  private:
    // Update the list of available shaders
    void updateShaderList();

    // initialize the shader Widget
    void initShaderWidget();

Jan Möbius's avatar
Jan Möbius committed
199 200 201
    // Announce local slots
    void setDescriptions();

202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
    /** \brief Return of all of the given modeling areas are visible
     *
     * @param _bits  Which areas to test
     * @param _id    Id of the object
     * @return       All areas visible?
     */
    bool areasVisible( StatusBits _bits, int _id );

    /** \brief Show or hide modeling areas
     *
     * @param _bits   Which areas to test
     * @param _id     Id of the object
     * @param _state  Show or hide?
     */
    void showAreas(  StatusBits _bits, int _id , bool _state  );

218 219 220 221 222 223 224 225 226 227 228 229 230 231

  public slots:
    /// For meshes returns if the selection for this object is visible
    bool selectionVisible( int _id );

    /// Allows to enable/disable visualization of the objects selection for meshes
    void showSelection( int _id , bool _state );

    /// For meshes returns if the modeling areas for this object is visible
    bool modelingAreasVisible( int _id );

    /// Allows to enable/disable visualization of the objects modeling area for meshes
    void showModelingAreas( int _id , bool _state  );

232 233 234 235 236 237 238 239 240
    /** Disable the given shader for a given object and draw mode.
     * @param _objectId ID of the object for which to disable the shader
     * @param _drawMode _drawMode for which the shader is disabled
     * @param _shader Shader which is disabled. If this shader is not currently active for
     *                the given _drawMode, nothing will be disabled. In order to disable
     *                all shaders for the given _drawMode, use _shader=0 (default).
     */
    void disableShader(int _objectId, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo* _shader=0);
    
241
    /** Sets a shader for the object and the given drawMode( can be a combination of draw modes )
242 243 244
     *  @param _id                 Object Id
     *  @param _drawMode           ; separated list of drawmodes used by the shader
     *  @param _shader             Shader information
245
     */
246
    void setShader(int _id, ACG::SceneGraph::DrawModes::DrawMode _drawMode, ShaderInfo _shader);
247

248
    /**
249 250
     *
     */
251 252 253 254 255 256 257

    /** Sets a Shader for a specific draw mode
     *
     * @param _id        Object id that should use the shader
     * @param _drawMode  Draw mode where this shader will be active
     * @param _name      Name of the shader that should be used
     */
258 259
    void setShader(int _id, QString _drawMode, QString _name );

260
    /// get information about available uniforms for a given shader
261 262 263 264 265 266
    QStringList getUniforms(QString _shader);

    QString getUniformType(QString _shader, QString _uniform );
    QString getUniformDefault(QString _shader, QString _uniform );
    QString getUniformMin(QString _shader, QString _uniform );
    QString getUniformMax(QString _shader, QString _uniform );
267 268

    /// set the value of a uniform in a shader for a specific drawMode
269
    void setUniform(int _objID, ACG::SceneGraph::DrawModes::DrawMode _drawMode, QString _shader, QString _uniform, QString _value );
270

Dirk Wilden's avatar
Dirk Wilden committed
271

Jan Möbius's avatar
Jan Möbius committed
272 273 274
    /// Set the viewing direction
    void setViewingDirection( Vector _direction, Vector _upvector , int _viewer = PluginFunctions::ALL_VIEWERS );

275 276 277
    /// Set scene radius
    void setSceneRadius( double _radius , int _viewer = PluginFunctions::ALL_VIEWERS );

Jan Möbius's avatar
Jan Möbius committed
278 279 280 281 282
    /// Rotate Scene
    void rotate( Vector _axis, double _angle, Vector _center , int _viewer = PluginFunctions::ALL_VIEWERS );

    /// translate Scene
    void translate( Vector _vec , int _viewer = PluginFunctions::ALL_VIEWERS );
283
    
Jan Möbius's avatar
Jan Möbius committed
284 285
    /// Set the draw mode for a viewer
    void setDrawMode(QString _mode, int _viewer = PluginFunctions::ALL_VIEWERS );
286 287 288 289 290 291
    
    /** \brief Set the draw mode for an object
    *
    * This function can be used to set the drawmode for an object.
    * 
    * @param _mode DrawMode as String ( can be a list of drawmodes which will be combined to a new mode )
292
    * @param _objectID Id of the object to set the draw mode
293 294 295
    * @param _force Set the draw mode even if its not directly supported by the objects nodes
    */
    void setObjectDrawMode(QString _mode, int _objectID , bool _force = true );
Dirk Wilden's avatar
Dirk Wilden committed
296

297 298 299 300 301 302 303 304 305 306 307
    /// Get a viewers viewing direction
    Vector viewingDirection( int _viewer = PluginFunctions::ACTIVE_VIEWER );

    /// get a viewers up vector
    Vector upVector( int _viewer = PluginFunctions::ACTIVE_VIEWER );

    /// get a viewers eye Position
    Vector eyePosition( int _viewer = PluginFunctions::ACTIVE_VIEWER );

    /// Get the scene center
    Vector sceneCenter( int _viewer = PluginFunctions::ACTIVE_VIEWER );
Dirk Wilden's avatar
Dirk Wilden committed
308

309 310 311
    /// Set the scene center
    void setSceneCenter( Vector _center, int _viewer = PluginFunctions::ALL_VIEWERS );

312 313 314
    /// Enable or disable Backface culling
    void enableBackfaceCulling( bool _state , int _viewer = PluginFunctions::ALL_VIEWERS );

315 316

    void setEyePosition(Vector _eye);
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344

    /// Change View on all viewers to view whole scene
    void viewAll();

    /// Change View on given Viewer to view whole scene
    void viewAll(int _viewer);

    /// Change View on given Viewer to view home position
    void viewHome();

    /// Change View on all Viewers to view home position
    void viewHome(int _viewer);



    /// Change Viewer to orthographicProjection
    void orthographicProjection();

    /// Change all Viewers to orthographicProjection
    void orthographicProjection(int _viewer);



    /// Change Viewer to perspectiveProjection
    void perspectiveProjection();

    /// Change all Viewers to perspectiveProjection
    void perspectiveProjection(int _viewer);
345 346
    
    /// Set fovy angle of projection
347
    void setFOVY( double _fovy );
348 349 350 351
    
    /// Set the mode for the coordinate system
    /// Perspective or orthogonal
    void setCoordsysProjection(bool _orthogonal);
352

353 354
    void setTwoSidedLighting(bool _enabled);

355 356 357
    /// Use the projection matrix of the given viewer to project the point
    ACG::Vec3d project(ACG::Vec3d _point, int _viewerId = 0);

358 359
};

360