PolyLinePlugin.hh 10.4 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
//=============================================================================
//
// CLASS PolyLinePlugin
//
// Author:  David Bommes <bommes@cs.rwth-aachen.de>
//
// Version: $Revision: 1$
// Date:    $Author$
//   $Date: 03-10-2007$
//
//
//=============================================================================

#ifndef POLYLINEPLUGIN_HH
#define POLYLINEPLUGIN_HH

#define CGAL_NO_AUTOLINK_MPFR
#define CGAL_NO_AUTOLINK_GMP

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

#include <QObject>
#include <QMenuBar>
#include <QTimer>

#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/MouseInterface.hh>
#include <OpenFlipper/BasePlugin/PickingInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
#include <OpenFlipper/BasePlugin/BackupInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/ToolbarInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
34 35
#include <OpenFlipper/BasePlugin/KeyInterface.hh>
#include <OpenFlipper/BasePlugin/StatusbarInterface.hh>
Jan Möbius's avatar
 
Jan Möbius committed
36 37 38 39 40 41 42 43
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/PolyLine/PolyLine.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>

#include "PolyLineToolbarWidget.hh"

Jan Möbius's avatar
Jan Möbius committed
44
#include <ObjectTypes/Plane/QtPlaneSelect.hh>
Jan Möbius's avatar
 
Jan Möbius committed
45

46 47 48 49
#include <ACG/Scenegraph/GlutPrimitiveNode.hh>

#include <ObjectTypes/PolyLine/PolyLineCircleData.hh>

Jan Möbius's avatar
 
Jan Möbius committed
50 51 52 53 54 55 56
#define CREATE_CUT_POLYLINE "Create Polyline"

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


/** Plugin for PolyLine Support
 */
57 58 59 60 61 62 63 64 65 66 67 68 69
class PolyLinePlugin: public QObject,
                      BaseInterface,
                      MouseInterface,
                      PickingInterface,
                      ToolboxInterface,
                      LoggingInterface,
                      LoadSaveInterface,
                      ToolbarInterface,
                      StatusbarInterface,
                      KeyInterface,
                      ScriptInterface {
    Q_OBJECT
    Q_INTERFACES(BaseInterface)
Jan Möbius's avatar
 
Jan Möbius committed
70 71 72 73 74 75
    Q_INTERFACES(MouseInterface)
    Q_INTERFACES(PickingInterface)
    Q_INTERFACES(ToolboxInterface)
    Q_INTERFACES(LoggingInterface)
    Q_INTERFACES(LoadSaveInterface)
    Q_INTERFACES(ToolbarInterface)
76 77
    Q_INTERFACES(StatusbarInterface)
    Q_INTERFACES(KeyInterface)
Jan Möbius's avatar
 
Jan Möbius committed
78 79
    Q_INTERFACES(ScriptInterface)

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-PolyLine")
#endif

Jan Möbius's avatar
 
Jan Möbius committed
84 85 86 87
signals:
  
  // BaseInterface
  void updateView();
88
  void updatedObject(int _identifier, const UpdateType& _type);
Jan Möbius's avatar
 
Jan Möbius committed
89 90 91 92 93

  // PickingInterface
  void addPickMode( const std::string& _mode );
  void addHiddenPickMode( const std::string& _mode );
  void setPickModeToolbar (const std::string& _mode, QToolBar * _toolbar);
94
  void setPickModeMouseTracking(const std::string& _mode , bool _mouseTracking);
Jan Möbius's avatar
 
Jan Möbius committed
95 96 97 98 99 100 101 102 103 104 105 106 107

  // LoggingInterface
  void log(Logtype _type, QString _message);
  void log(QString _message);

  // ToolbarInterface
  void addToolbar(QToolBar* _toolbar);
  void getToolBar( QString _name, QToolBar*& _toolbar);
  
  // ScriptInterface
  void scriptInfo( QString _functionName );
  
  // ToolboxInterface
108
  void addToolbox( QString  _name  , QWidget* _widget, QIcon* _icon);
Jan Möbius's avatar
 
Jan Möbius committed
109 110 111 112
  
  void deleteObject( int _id );
  void addEmptyObject( DataType _type, int& _id);    

113 114 115
  void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);
  void showStatusMessage(QString _message, int _timeout = 0);
  void clearStatusMessage();
Jan Möbius's avatar
 
Jan Möbius committed
116 117 118 119 120 121 122 123

private slots :
  // BaseInterface
  void initializePlugin();

  void slotEditModeChanged();

  void slotMouseEvent( QMouseEvent* _event );
124
  void slotKeyEvent(QKeyEvent* _event);
Jan Möbius's avatar
 
Jan Möbius committed
125 126 127 128 129

  void slotPickModeChanged( const std::string& _mode);

  void pluginsInitialized();

130 131 132
  bool pick_triangle_mesh( QPoint mPos,
  						TriMeshObject*& _mesh_object_, TriMesh::FaceHandle& _fh, TriMesh::VertexHandle& _vh, ACG::Vec3d& _hitPoint);

Jan Möbius's avatar
 
Jan Möbius committed
133 134 135 136 137 138 139 140 141
public slots :

  void slotEnablePickMode(QString _name);

public :

  /// Edit Mode of PolyLinePlugin
  enum EditMode { PL_NONE  =0,
                  PL_INSERT=1,
142
                  PL_INSERTCIRCLE,
Jan Möbius's avatar
 
Jan Möbius committed
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
                  PL_DELETE,
                  PL_MOVE,
                  PL_SPLIT,
                  PL_MERGE,
                  PL_SMART_MOVE };

  /// default constructor
  PolyLinePlugin();

  /// default destructor
  ~PolyLinePlugin() {};

  /// Name of the Plugin
  QString name(){ return (QString("PolyLine")); };

  /// Description of the Plugin
  QString description() { return (QString("Handling of PolyLines (Insertion/Deletion/Modeling/...")); };

private slots:

  void slot_subdivide();
  void slot_subdivide_percent(bool _checked);
  void slot_decimate();
  void slot_decimate_percent(bool _checked);

#ifdef EXTENDED_POLY_LINE
  void slot_resample_on_edges();
#endif

  void slot_smooth();
  void slot_smooth( PolyLineObject*& _pol);
  void slot_project();
  void slot_project( PolyLineObject*& _pol);
  void slot_smooth_project();
  void slot_smooth_project( PolyLineObject*& _pol);

  void slot_smart_move_timer();

181 182
  void slot_setCirclePointNum(int i);

Jan Möbius's avatar
 
Jan Möbius committed
183 184 185 186 187
private :

  EditMode mode();

  // mouse events
188 189 190 191 192 193 194
  void me_insert      ( QMouseEvent* _event );
  void me_insertCircle( QMouseEvent* _event );
  void me_delete      ( QMouseEvent* _event );
  void me_move        ( QMouseEvent* _event );
  void me_split       ( QMouseEvent* _event );
  void me_merge       ( QMouseEvent* _event );
  void me_smart_move  ( QMouseEvent* _event );
Jan Möbius's avatar
 
Jan Möbius committed
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235

  //===========================================================================
  /** @name ToolBox
  * @{ */
  //===========================================================================
  
  private :
    
    /// Widget for Toolbox
    PolyLineToolbarWidget* tool_;
  
  /** @} */  
  
  //===========================================================================
  /** @name ToolBar
  * @{ */
  //===========================================================================
  
  private :
    QAction*      polyLineAction_;
    QActionGroup* toolBarActions_;
    
    QToolBar*     toolbar_;
    
  private slots:
    
    /// Called by Toolbar to enable pick mode
    void slotSetPolyLineMode(QAction* _action);
    
  /** @} */  
  
  //===========================================================================
  /** @name PickToolBar
  * @{ */
  //===========================================================================
  
  private :
    QToolBar*     pickToolbar_;
    QActionGroup* pickToolBarActions_;
    
    QAction*      insertAction_;
236
    QAction*	  insertCircleAction_;
Jan Möbius's avatar
 
Jan Möbius committed
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
    QAction*      deleteAction_;
    QAction*      moveAction_;
    QAction*      smartMoveAction_;
    QAction*      mergeAction_;
    QAction*      splitAction_;
    QAction*      cutAction_;
    
  private slots:
    
    /// Called by pick Toolbar
    void slotPickToolbarAction(QAction* _action);
    
  /** @} */
  
  //===========================================================================
  /** @name Template Functions
  * @{ */
  //===========================================================================
  
  private:
  
  /// get the points from the intersection between mesh and plane
  template< class MeshT > std::vector< ACG::Vec3d >
  getIntersectionPoints ( MeshT* _mesh, uint _fh, ACG::Vec3d _planeNormal ,
                          ACG::Vec3d _planePoint, bool& _closed );
                                                    
  /// get an edge of the mesh that is cut by the plane
  template< class MeshT >
  typename MeshT::EdgeHandle
  getCuttedEdge(MeshT& _mesh, ACG::Vec3d& _planeNormal, ACG::Vec3d& _planePoint);

  /** @} */
  
public slots:
  
  QString version() { return QString("1.02"); };
  
  //============================================
  
  /// Generates a polyLine of a plane intersection
  int generatePolyLineFromCut( int _objectId, Vector _planePoint, Vector _planeNormal, int _polyLineId = -1 );
  
private slots:
  
  /// Scissor Button was hit
  void slotScissorButton();
  
  /// Generate PolyLine after the cutPlane has been drawn
  void slotTriggerCutPlaneSelect();
  
private:
288 289
    int               cur_insert_id_;
    PolyLineObject   *cur_polyline_obj_;
Jan Möbius's avatar
 
Jan Möbius committed
290 291 292
    
    int               cur_move_id_;
    PolyLine::Point*  move_point_ref_;
293
    PolyLine::Point*  create_point_ref_;
Jan Möbius's avatar
 
Jan Möbius committed
294 295
    PolyLine::Point   move_point_orig_;
    
Jan Möbius's avatar
Jan Möbius committed
296 297 298 299 300
    /// The object which is being modified(created, dragged)
    int				    createCircle_CurrSelIndex_;
    /// Use this one to mark the last index to update the number of points
    int					createCircle_LastSelIndex_;
    /// Data for creating a circle, center and it's normal
301
    ACG::Vec3d		    createCircle_Point_;
302
    ACG::Vec3d		    createCircle_Normal_;
Jan Möbius's avatar
Jan Möbius committed
303
    /// The handle which is being dragged.
304 305
    ACG::SceneGraph::GlutPrimitiveNode* moveCircle_SelNode_;

Jan Möbius's avatar
Jan Möbius committed
306
    /// Finds the nearest point on the mesh given a point on the normal plane
307 308 309 310 311 312
    bool createCircle_getPointOnMesh(TriMeshObject* _triMeshObject,
                                     ACG::Vec3d     _center,
                                     ACG::Vec3d     _pOnPlane,
                                     ACG::Vec3d     _n,
                                     ACG::Vec3d*    _pOut);

Jan Möbius's avatar
Jan Möbius committed
313
    /// Calculates common info like point on the mesh, point on the normal plane and the distance from the circle center
314 315 316 317 318 319
    bool createCircle_getHitInfo(PolyLineCircleData* _circleData,
                                 ACG::Vec3d          _hit_Point,
                                 ACG::Vec3d*         _pOut = 0,
                                 double*             _r = 0,
                                 ACG::Vec3d*         _onPlane = 0);

Jan Möbius's avatar
Jan Möbius committed
320
    /// Helper function which returns the point on the mesh or if none could be found the point on the plane
321 322
    ACG::Vec3d createCircle_getHit(PolyLineCircleData* _circleData, ACG::Vec3d _hit_point);

Jan Möbius's avatar
Jan Möbius committed
323
    /// Generates points for the ellipse, given the PolyLineObject
324 325
    void updatePolyEllipse(PolyLineObject* _lineObject, unsigned int _pointCount);

Jan Möbius's avatar
Jan Möbius committed
326
    /// updates the center, forward and side handle of the Poly ellipse
327
    void updateHandles(PolyLineObject* _lineObject);
328

Jan Möbius's avatar
 
Jan Möbius committed
329 330 331 332 333 334 335 336 337 338 339 340
    int               cur_merge_id_;
    
    QTimer*           smart_move_timer_;
    
    PolyLineObject*   cur_smart_move_obj_;
    
    // Plane selection tool
    QtPlaneSelect*    planeSelect_;

};

#if defined(INCLUDE_TEMPLATES) && !defined(POLYLINEPLUGIN_CC)
341
#define POLYLINEPLUGIN_TEMPLATES
Jan Möbius's avatar
 
Jan Möbius committed
342 343 344 345
#include "PolyLinePluginT.cc"
#endif

#endif //MOVEPLUGIN_HH