Developer Documentation
PolyLinePlugin.hh
1/*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40\*===========================================================================*/
41
42//=============================================================================
43//
44// CLASS PolyLinePlugin
45//
46// Author: David Bommes <bommes@cs.rwth-aachen.de>
47//
48// Version: $Revision: 1$
49// Date: $Author$
50// $Date: 03-10-2007$
51//
52//
53//=============================================================================
54
55#ifndef POLYLINEPLUGIN_HH
56#define POLYLINEPLUGIN_HH
57
58//== INCLUDES =================================================================
59
60#include <QObject>
61#include <QMenuBar>
62#include <QTimer>
63
80
81#include "PolyLineToolbarWidget.hh"
82
83#include <ObjectTypes/Plane/QtPlaneSelect.hh>
84
85#include <ACG/Scenegraph/GlutPrimitiveNode.hh>
86
87#include <ObjectTypes/PolyLine/PolyLineCircleData.hh>
88#include <ObjectTypes/PolyLine/PolyLineBezierSplineData.hh>
89
90#define CREATE_CUT_POLYLINE "Create Polyline"
91#define CREATE_CUT_POLYLINES "Create Polylines"
92
93//== CLASS DEFINITION =========================================================
94
95
98class PolyLinePlugin: public QObject,
110 Q_OBJECT
111 Q_INTERFACES(BaseInterface)
112 Q_INTERFACES(MouseInterface)
113 Q_INTERFACES(PickingInterface)
114 Q_INTERFACES(ToolboxInterface)
115 Q_INTERFACES(LoggingInterface)
116 Q_INTERFACES(LoadSaveInterface)
117 Q_INTERFACES(ToolbarInterface)
118 Q_INTERFACES(StatusbarInterface)
119 Q_INTERFACES(KeyInterface)
120 Q_INTERFACES(ScriptInterface)
121 Q_INTERFACES(ContextMenuInterface)
122
123 Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-PolyLine")
124
125signals:
126
127 // BaseInterface
128 void updateView();
129 void updatedObject(int _identifier, const UpdateType& _type);
130 void nodeVisibilityChanged(int _id);
131
132 // PickingInterface
133 void addPickMode( const std::string& _mode );
134 void addHiddenPickMode( const std::string& _mode );
135 void setPickModeToolbar (const std::string& _mode, QToolBar * _toolbar);
136 void setPickModeMouseTracking(const std::string& _mode , bool _mouseTracking);
137
138 // LoggingInterface
139 void log(Logtype _type, QString _message);
140 void log(QString _message);
141
142 // ToolbarInterface
143 void addToolbar(QToolBar* _toolbar);
144 void getToolBar( QString _name, QToolBar*& _toolbar);
145
146 // ScriptInterface
147 void scriptInfo( QString _functionName );
148
149 // ToolboxInterface
150 void addToolbox( QString _name , QWidget* _widget, QIcon* _icon);
151
152 void deleteObject( int _id );
153 void addEmptyObject( DataType _type, int& _id);
154
155 void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description, bool _multiUse = false);
156 void showStatusMessage(QString _message, int _timeout = 0);
157 void clearStatusMessage();
158
159 //ContextMenuInterface
160 void addContextMenuItem(QAction* _action ,DataType _objectType , ContextMenuType _type );
161
162private slots :
163 // BaseInterface
164 void initializePlugin();
165
166 void slotEditModeChanged();
167
168 void slotMouseEvent( QMouseEvent* _event );
169 void slotKeyEvent(QKeyEvent* _event);
170
171 void slotPickModeChanged( const std::string& _mode);
172
173 void pluginsInitialized();
174
175 bool pick_triangle_mesh( QPoint mPos,
176 TriMeshObject*& _mesh_object_, TriMesh::FaceHandle& _fh, TriMesh::VertexHandle& _vh, ACG::Vec3d& _hitPoint);
177
178 void slotUpdateContextMenu(int objectId);
179public slots :
180
181 void slotEnablePickMode(const QString& _name);
182
183public :
184
186 enum EditMode { PL_NONE =0,
187 PL_INSERT=1,
188 PL_INSERTCIRCLE,
189 PL_INSERTSPLINE,
190 PL_DELETE,
191 PL_MOVE,
192 PL_SPLIT,
193 PL_MERGE,
194 PL_SMART_MOVE,
195 PL_COPY_PASTE };
196
199
202
204 QString name(){ return (QString("PolyLine")); };
205
207 QString description() { return (QString("Handling of PolyLines (Insertion/Deletion/Modeling/...")); };
208
209public slots:
210
211#ifdef EXTENDED_POLY_LINE
212 void slot_resample_on_edges();
213#endif
214
215private slots:
216
217 void slot_subdivide();
218 void slot_subdivide_percent(bool _checked);
219 void slot_decimate();
220 void slot_decimate_percent(bool _checked);
221
222 void slot_smooth();
223 void slot_smooth( PolyLineObject*& _pol);
224 void slot_project();
225 void slot_project( PolyLineObject*& _pol);
226 void slot_smooth_project();
227 void slot_smooth_project( PolyLineObject*& _pol);
228
229 void slot_smart_move_timer();
230
231 void slot_setCirclePointNum(int i);
232 void slot_setSplinePointNum(int i);
233
234 virtual void slotObjectUpdated( int _identifier, const UpdateType &_type );
235
236 void slot_duplicate();
237 void slot_instanciate();
238 void finishSpline();
239private :
240
241 EditMode mode();
242
243 // mouse events
244 void me_insert ( QMouseEvent* _event );
245 void me_insertCircle( QMouseEvent* _event );
246 void me_insertSpline( QMouseEvent* _event );
247 void me_delete ( QMouseEvent* _event );
248 void me_move ( QMouseEvent* _event );
249 void me_split ( QMouseEvent* _event );
250 void me_merge ( QMouseEvent* _event );
251 void me_smart_move ( QMouseEvent* _event );
252
253 //===========================================================================
256 //===========================================================================
257
258 private :
259
262
264 QIcon* toolIcon_;
265
268 //===========================================================================
271 //===========================================================================
272
273 private :
275 QActionGroup* toolBarActions_;
276
277 QToolBar* toolbar_;
278
279 private slots:
280
282 void slotSetPolyLineMode(QAction* _action);
283
286 //===========================================================================
289 //===========================================================================
290
291 private :
292 QToolBar* pickToolbar_;
293 QActionGroup* pickToolBarActions_;
294
299 QAction* moveAction_;
301 QAction* mergeAction_;
302 QAction* splitAction_;
303 QAction* cutAction_;
305
306 private slots:
307
309 void slotPickToolbarAction(QAction* _action);
310
313 //===========================================================================
316 //===========================================================================
317
318 private:
319
321 template< class MeshT > std::vector< ACG::Vec3d >
322 getIntersectionPoints ( MeshT* _mesh, uint _fh, ACG::Vec3d _planeNormal ,
323 ACG::Vec3d _planePoint, bool& _closed );
324
326 template< class MeshT > std::vector< std::vector< ACG::Vec3d > >
327 getMultipleIntersectionPoints( MeshT* _mesh, ACG::Vec3d _planeNormal , ACG::Vec3d _planePoint );
328
330 template< class MeshT >
331 typename MeshT::EdgeHandle
332 getCuttedEdge(MeshT& _mesh, ACG::Vec3d& _planeNormal, ACG::Vec3d& _planePoint);
333
336public slots:
337
338 QString version() { return QString("1.02"); };
339
340 //============================================
341
343 int generatePolyLineFromCut( int _objectId, Vector _planePoint, Vector _planeNormal, int _polyLineId = -1 );
344
346 IdList generatePolyLinesFromCut( int _objectId, Vector _planePoint, Vector _planeNormal );
347
348private slots:
349
351 void slotScissorButton();
352
355
358
359private:
360 int cur_insert_id_;
361 PolyLineObject *cur_polyline_obj_;
362
363 int cur_move_id_;
364 PolyLine::Point* move_point_ref_;
365 PolyLine::Point* create_point_ref_;
366 PolyLine::Point move_point_orig_;
367
376 ACG::Vec3d moveCircle_LastHitNor_;
377 bool moveCircle_IsLocked;
378 bool moveCircle_IsFloating;
379
380 QAction* copyPaste_Action_;
381 int copyPaste_ObjectId_;
382 int copyPaste_ActionType_;
383 int copyPaste_NewObjectId_;
384 std::vector<ACG::Vec3d> copyPaste_RelativePoints_;
385 QPoint copyPaste_LastMouse;
386
387 /*
388 * \brief Handles the mouse event during a copy paste event
389 *
390 * Determines wether duplicate or instanciate is happening and performs the
391 * action, ending the mode.
392 */
393 void me_copyPasteMouse(QMouseEvent* _event);
394
407 bool createCircle_getPointOnMesh(TriMeshObject* _triMeshObject,
408 ACG::Vec3d _center,
409 ACG::Vec3d _pOnPlane,
410 ACG::Vec3d _n,
411 ACG::Vec3d* _pOut);
412
424 ACG::Vec3d _hit_Point,
425 ACG::Vec3d* _pOut = 0,
426 double* _r = 0,
427 ACG::Vec3d* _onPlane = 0);
428
439
440public slots:
441 /* \brief Creates the UI elements for the poly line(asserting it has circle data)
442 *
443 */
444 void createCircle_createUI(int _polyLineObjectID);
445
446 /* \brief Creates the UI elements for the poly line(asserting it has spline data)
447 *
448 */
449 void createSpline_createUI(int _polyLineObjectID);
450
451private:
458 void updatePolyEllipse(PolyLineObject* _lineObject, unsigned int _pointCount);
459
464 void updateHandles(PolyLineObject* _lineObject);
465
472 void updatePolyBezierSpline(PolyLineObject* _lineObject, unsigned int _pointsPerSegment);
473
479
488
493
500
501 int cur_merge_id_;
502
503 QTimer* smart_move_timer_;
504
505 PolyLineObject* cur_smart_move_obj_;
506
509
510};
511
512#if defined(INCLUDE_TEMPLATES) && !defined(POLYLINEPLUGIN_CC)
513#define POLYLINEPLUGIN_TEMPLATES
514#include "PolyLinePluginT_impl.hh"
515#endif
516
517#endif //MOVEPLUGIN_HH
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:181
Logtype
Log types for Message Window.
Interface class from which all plugins have to be created.
Interface class for creating custom context menus.
Predefined datatypes.
Definition: DataTypes.hh:83
Keyboard Event Interface.
Definition: KeyInterface.hh:59
Interface for all plugins which want to Load or Save files and create Objects.
Interface for all Plugins which do logging to the logging window of the framework.
Interface class for receiving mouse events.
Allow access to picking functions.
QString name()
Name of the Plugin.
QAction * mergeAction_
Called by pick Toolbar.
QActionGroup * toolBarActions_
Called by Toolbar to enable pick mode.
MeshT::EdgeHandle getCuttedEdge(MeshT &_mesh, ACG::Vec3d &_planeNormal, ACG::Vec3d &_planePoint)
get an edge of the mesh that is cut by the plane
bool createCircle_getPointOnMesh(TriMeshObject *_triMeshObject, ACG::Vec3d _center, ACG::Vec3d _pOnPlane, ACG::Vec3d _n, ACG::Vec3d *_pOut)
Calculates a point on the mesh.
void updatePolyBezierHandles(PolyLineObject *_lineObject, ACG::SceneGraph::LineNode *_line)
Updates all the handles on the PolyBezier.
void slotTriggerCutPlaneSelect()
Generate PolyLine after the cutPlane has been drawn.
int createCircle_LastSelIndex_
Use this one to mark the last index to update the number of points.
int createCircle_CurrSelIndex_
The object which is being modified(created, dragged)
void slotScissorLinesButton()
Scissor Button for multiple polylines was hit.
QAction * insertAction_
Called by pick Toolbar.
IdList generatePolyLinesFromCut(int _objectId, Vector _planePoint, Vector _planeNormal)
Generates a polyLine of a plane intersection.
int moveBezSpline_SelIndex_
The object which is being moved.
QIcon * toolIcon_
Icon for the toolbox.
QAction * deleteAction_
Called by pick Toolbar.
int generatePolyLineFromCut(int _objectId, Vector _planePoint, Vector _planeNormal, int _polyLineId=-1)
Generates a polyLine of a plane intersection.
ACG::Vec3d moveCircle_LastHitPos_
The last valid hit on the mesh.
ACG::Vec3d createCircle_getHit(PolyLineCircleData *_circleData, ACG::Vec3d _hit_point)
Returns point on mesh or point on the normal plane.
QAction * splitAction_
Called by pick Toolbar.
int createSpline_CurrSelIndex_
The index of the currently created spline.
QAction * polyLineAction_
Called by Toolbar to enable pick mode.
int moveBezSpline_SelSubIndex_
The index of the control or handle being moved.
PolyLineToolbarWidget * tool_
Widget for Toolbox.
void slotPickToolbarAction(QAction *_action)
Called by pick Toolbar.
QAction * cutMultipleAction_
Called by pick Toolbar.
int createSpline_LastSelIndex_
Use this one to mark the last index to update the number of points.
QtPlaneSelect * planeSelect_
Plane selection tool.
void slotSetPolyLineMode(QAction *_action)
Called by Toolbar to enable pick mode.
QToolBar * toolbar_
Called by Toolbar to enable pick mode.
ACG::SceneGraph::GlutPrimitiveNode * moveCircle_SelNode_
The handle which is being dragged.
QAction * smartMoveAction_
Called by pick Toolbar.
std::vector< ACG::Vec3d > getIntersectionPoints(MeshT *_mesh, uint _fh, ACG::Vec3d _planeNormal, ACG::Vec3d _planePoint, bool &_closed)
get the points from the closest connected intersection between mesh and plane
bool createCircle_getHitInfo(PolyLineCircleData *_circleData, ACG::Vec3d _hit_Point, ACG::Vec3d *_pOut=0, double *_r=0, ACG::Vec3d *_onPlane=0)
Calculates common info.
QActionGroup * pickToolBarActions_
Called by pick Toolbar.
QAction * cutAction_
Called by pick Toolbar.
void updatePolyBezierSpline(PolyLineObject *_lineObject, unsigned int _pointsPerSegment)
Generates points for the spline, updates handles.
PolyLinePlugin()
default constructor
QAction * insertSplineAction_
Called by pick Toolbar.
QAction * moveAction_
Called by pick Toolbar.
std::vector< std::vector< ACG::Vec3d > > getMultipleIntersectionPoints(MeshT *_mesh, ACG::Vec3d _planeNormal, ACG::Vec3d _planePoint)
get all points from the intersection between mesh and plane
ACG::SceneGraph::GlutPrimitiveNode * moveBezSpline_SelNode_
The handle which is being dragged.
QString description()
Description of the Plugin.
void updateHandles(PolyLineObject *_lineObject)
Updates the center, forward and side handle of the Poly ellipse.
void updatePolyEllipse(PolyLineObject *_lineObject, unsigned int _pointCount)
Generates points for the ellipse.
QToolBar * pickToolbar_
Called by pick Toolbar.
EditMode
Edit Mode of PolyLinePlugin.
ACG::Vec3d getPointOnMesh(PolyLineBezierSplineData *_SplineData, ACG::Vec3d _point, ACG::Vec3d *_nor=0)
Returns the nearest point on the mesh or if none could be found the input.
void slotScissorButton()
Scissor Button was hit.
QAction * insertCircleAction_
Called by pick Toolbar.
~PolyLinePlugin()
default destructor
Interface for all Plugins which provide scriptable Functions.
Control OpenFlippers status bar.
Add a toolbox to OpenFlipper.
Plugins can add its own toolbox to the main widget's toolbox area by using this interface.
Type for a MeshObject containing a triangle mesh.
Definition: TriangleMesh.hh:67
Update type class.
Definition: UpdateType.hh:59