PolyLinePlugin.hh 13.2 KB
Newer Older
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>
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>
45

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

#include <ObjectTypes/PolyLine/PolyLineCircleData.hh>
49
#include <ObjectTypes/PolyLine/PolyLineBezierSplineData.hh>
50

51 52 53 54 55 56 57
#define CREATE_CUT_POLYLINE "Create Polyline"

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


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

81 82 83 84
#if QT_VERSION >= 0x050000
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-PolyLine")
#endif

85 86 87 88
signals:
  
  // BaseInterface
  void updateView();
89
  void updatedObject(int _identifier, const UpdateType& _type);
90 91 92 93 94

  // PickingInterface
  void addPickMode( const std::string& _mode );
  void addHiddenPickMode( const std::string& _mode );
  void setPickModeToolbar (const std::string& _mode, QToolBar * _toolbar);
95
  void setPickModeMouseTracking(const std::string& _mode , bool _mouseTracking);
96 97 98 99 100 101 102 103 104 105 106 107 108

  // 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
109
  void addToolbox( QString  _name  , QWidget* _widget, QIcon* _icon);
110 111 112 113
  
  void deleteObject( int _id );
  void addEmptyObject( DataType _type, int& _id);    

114 115 116
  void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);
  void showStatusMessage(QString _message, int _timeout = 0);
  void clearStatusMessage();
117 118 119 120 121 122 123 124

private slots :
  // BaseInterface
  void initializePlugin();

  void slotEditModeChanged();

  void slotMouseEvent( QMouseEvent* _event );
125
  void slotKeyEvent(QKeyEvent* _event);
126 127 128 129 130

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

  void pluginsInitialized();

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

134 135 136 137 138 139 140 141 142
public slots :

  void slotEnablePickMode(QString _name);

public :

  /// Edit Mode of PolyLinePlugin
  enum EditMode { PL_NONE  =0,
                  PL_INSERT=1,
143
                  PL_INSERTCIRCLE,
144
                  PL_INSERTSPLINE,
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
                  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();

183
  void slot_setCirclePointNum(int i);
184
  void slot_setSplinePointNum(int i);
185

186 187
  virtual void slotObjectUpdated( int _identifier );

188 189 190 191 192
private :

  EditMode mode();

  // mouse events
193 194
  void me_insert      ( QMouseEvent* _event );
  void me_insertCircle( QMouseEvent* _event );
195
  void me_insertSpline( QMouseEvent* _event );
196 197 198 199 200
  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 );
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 236 237 238 239 240 241

  //===========================================================================
  /** @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_;
242
    QAction*	  insertCircleAction_;
243
    QAction*	  insertSplineAction_;
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 288 289 290 291 292 293 294
    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:
295 296
    int               cur_insert_id_;
    PolyLineObject   *cur_polyline_obj_;
297 298 299
    
    int               cur_move_id_;
    PolyLine::Point*  move_point_ref_;
300
    PolyLine::Point*  create_point_ref_;
301 302
    PolyLine::Point   move_point_orig_;
    
Jan Möbius's avatar
Jan Möbius committed
303 304 305 306 307
    /// 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_;
    /// The handle which is being dragged.
308
    ACG::SceneGraph::GlutPrimitiveNode* moveCircle_SelNode_;
309 310 311 312 313
    ///The last valid hit on the mesh
    ACG::Vec3d          moveCircle_LastHitPos_;
    ACG::Vec3d          moveCircle_LastHitNor_;
    bool                moveCircle_IsLocked;
    bool                moveCircle_IsFloating;
314

315
    /**
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
	 * \brief Calculates a point on the mesh.
	 *
	 * Finds the nearest point on the mesh given a point on the normal plane
	 *
	 * @param _triMeshObject The mesh to use
	 * @param _center The center of the ellipse
	 * @param _pOnPlane The projection of the hit point on the plane
	 * @param _n The normal of the ellipse
	 * @param _pOut The point on the mesh if one could be found.
	 * @return True if a point could be found.
	 */
	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
333
	/** \brief Calculates common info.
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
	 *
	 * Calculates common info like point on the mesh, point on the normal plane and the distance from the circle center
	 *
	 * @param _circleData The circle to use.
	 * @param _hit_Point The point which to "project".
	 * @param _pOut (optional)Point on the mesh.
	 * @param _r The distance between circle center and point on the plane.
	 * @param _onPlane Point on the normal plane regarding the hit_point.
	 */
	bool createCircle_getHitInfo(PolyLineCircleData* _circleData,
								 ACG::Vec3d          _hit_Point,
								 ACG::Vec3d*         _pOut = 0,
								 double*             _r = 0,
								 ACG::Vec3d*         _onPlane = 0);

	/** \brief Returns point on mesh or point on the normal plane.
	 *
	 * Helper function which returns the point on the mesh or if none could be found the point on the plane
	 *
	 * @param _circleData The circle to use.
	 * @param _hit_point The point to "project".
	 *
	 * @return Point on the mesh if one was found or on the normal plane.
	 */
	ACG::Vec3d createCircle_getHit(PolyLineCircleData* _circleData, ACG::Vec3d _hit_point);

360 361 362 363 364 365 366 367 368 369 370 371
public slots:
	/* \brief Creates the UI elements for the poly line(asserting it has circle data)
	 *
	 */
	void createCircle_createUI(int _polyLineObjectID);

	/* \brief Creates the UI elements for the poly line(asserting it has spline data)
	 *
	 */
	void createSpline_createUI(int _polyLineObjectID);

private:
Jan Möbius's avatar
Jan Möbius committed
372
	/** \brief Generates points for the ellipse.
373 374 375 376 377 378 379
	 *
	 * @param _lineObject The object to generate points for.
	 * @param _pointCount The number of points to generate.
	 *
	 */
	void updatePolyEllipse(PolyLineObject* _lineObject, unsigned int _pointCount);

Jan Möbius's avatar
Jan Möbius committed
380
	/** \brief Updates the center, forward and side handle of the Poly ellipse
381 382 383 384 385
	 *
	 * @param _lineObject The object containing the handles.
	 */
	void updateHandles(PolyLineObject* _lineObject);

Jan Möbius's avatar
Jan Möbius committed
386
	/** \brief Generates points for the spline, updates handles.
387
	 *
Jan Möbius's avatar
Jan Möbius committed
388 389
	 * @param _lineObject       The object to generate points for.
	 * @param _pointsPerSegment The number of points per segment.
390 391 392 393
	 *
	 */
	void updatePolyBezierSpline(PolyLineObject* _lineObject, unsigned int _pointsPerSegment);

Jan Möbius's avatar
Jan Möbius committed
394
	/** \brief Updates all the handles on the PolyBezier
395 396 397 398 399
	 * @param _lineObject The object to update.
	 * @param _line the line node containing all the handles
	 */
	void updatePolyBezierHandles(PolyLineObject* _lineObject, ACG::SceneGraph::LineNode* _line);

Jan Möbius's avatar
Jan Möbius committed
400
	/** \brief Returns the nearest point on the mesh or if none could be found the input.
401 402 403 404 405 406 407 408 409 410 411 412
	 *
	 * @param _SplineData The spline which is being used.
	 * @param _point The input point.
	 * @param _nor (Optional)Normal at nearest point.
	 * @return The nearest point on the mesh from _point
	 */
	ACG::Vec3d getPointOnMesh(PolyLineBezierSplineData* _SplineData, ACG::Vec3d _point, ACG::Vec3d* _nor = 0);

	/// The index of the currently created spline.
	int createSpline_CurrSelIndex_;
	/// Use this one to mark the last index to update the number of points
	int createSpline_LastSelIndex_;
413

Jan Möbius's avatar
Jan Möbius committed
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
	/// The handle which is being dragged.
	ACG::SceneGraph::GlutPrimitiveNode* moveBezSpline_SelNode_;
	/// The object which is being moved
	int moveBezSpline_SelIndex_;
	/// The index of the control or handle being moved
	int moveBezSpline_SelSubIndex_;

	int               cur_merge_id_;

	QTimer*           smart_move_timer_;

	PolyLineObject*   cur_smart_move_obj_;

	/// Plane selection tool
	QtPlaneSelect*    planeSelect_;
429 430 431 432

};

#if defined(INCLUDE_TEMPLATES) && !defined(POLYLINEPLUGIN_CC)
433
#define POLYLINEPLUGIN_TEMPLATES
434 435 436 437
#include "PolyLinePluginT.cc"
#endif

#endif //MOVEPLUGIN_HH