Developer Documentation
QtPlaneSelect.cc
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 #include "QtPlaneSelect.hh"
45 
47 #include <ACG/Scenegraph/GlutPrimitiveNode.hh>
48 #define PLUGINFUNCTIONS_C
50 
51 #include <ACG/QtWidgets/QtColorTranslator.hh>
52 
53 
54 /*******************************************************************************
55  Initialization and de initialization
56 *******************************************************************************/
57 QtPlaneSelect::QtPlaneSelect( ACG::GLState& glState )
58  : glState( glState ),
59  nodeIdx_(0),
60  targetIdx_(0),
61  isDragging( false ),
62  planeNode_(0)
63 {
64 
65 }
66 
67 QtPlaneSelect::~QtPlaneSelect( )
68 {
69 }
70 
71 
72 /*******************************************************************************
73  Implementation of public slots
74 *******************************************************************************/
75 
76 void QtPlaneSelect::slotKeyReleaseEvent(QKeyEvent* event)
77 {
78  if (event->key() == Qt::Key_Escape){
79  if( planeNode_ )
80  {
81  planeNode_->delete_subtree( );
82  planeNode_ = 0;
83  }
84 
85  emit updateViewProxy( );
86 
87  // Trigger the event
88  isDragging = false;
89  }
90 }
91 
92 void QtPlaneSelect::slotMouseEvent(QMouseEvent* event)
93 {
94 // unsigned int width = glState.viewport_width();
95  unsigned int height = glState.viewport_height();
96 
97  //cancel on rightclick
98  if (event->button() == Qt::RightButton){
99  if( planeNode_ )
100  {
101  planeNode_->delete_subtree( );
102  planeNode_ = 0;
103  }
104 
105  emit updateViewProxy( );
106 
107  // Trigger the event
108  isDragging = false;
109 
110  return;
111  }
112 
113 
114  switch( event->type() )
115  {
116  case QEvent::MouseButtonPress:
117  {
118 
119  // Only react on the left button and ignore the others
120  if ( event->button() != Qt::LeftButton )
121  return;
122 
123 
124  size_t node_idx, target_idx;
125 
127  event->pos(),
128  node_idx,
129  target_idx,
130  &sourcePoint3D))
131  {
132 
133  // Shift toward viewer
134  //sourcePoint3D = sourcePoint3D + PluginFunctions::viewingDirection();
135 
136  isDragging = true;
137 
138  if ( planeNode_ == 0 ) {
139  planeNode_ = new PlaneNode(plane_,PluginFunctions::getRootNode(),"PolyLine generation Plane" );
140  }
141 
142  setPlaneAndSize(sourcePoint3D,ACG::Vec3d(event->pos().x(), height-event->pos().y()-1.0, 0.0));
143 
144  planeNode_->show();
145  emit nodeVisChangedProxy(planeNode_->id());
146 
147  nodeIdx_ = node_idx;
148  targetIdx_ = target_idx;
149 
150 
151  emit updateViewProxy( );
152  }
153  }break;
154  case QEvent::MouseMove:
155  {
156  if( isDragging )
157  {
158  setPlaneAndSize(sourcePoint3D,ACG::Vec3d(event->pos().x(), height-event->pos().y()-1.0, 0.0));
159 
160  emit updateViewProxy( );
161  }
162  } break;
163 
164  case QEvent::MouseButtonRelease:
165  {
166  if( isDragging )
167  {
168  if( planeNode_ )
169  {
170  planeNode_->delete_subtree( );
171  planeNode_ = NULL;
172  }
173 
174  emit updateViewProxy( );
175 
176  emit( signalTriggerCut( ) );
177  // Trigger the event
178  isDragging = false;
179  }
180  } break;
181 
182  default:
183  break;
184  }
185 
186 
187 }
188 
189 
190 void QtPlaneSelect::setPlaneAndSize(const ACG::Vec3d& _sourcePoint3D,const ACG::Vec3d& _target2D)
191 {
192 
193  ACG::Vec3d source2D = glState.project( _sourcePoint3D );
194 
195  source2D[2] = 0;
196 
197 
198  ACG::Vec3d diff = source2D - _target2D;
199  //diff.normalize( ); <- this is bad
200  ACG::Vec3d ortho(-diff[1], diff[0], 0 );
201 
202  ACG::Vec3d left = glState.unproject( source2D+ortho*10 + ACG::Vec3d(0,0,0) );
203  ACG::Vec3d right= glState.unproject( source2D-ortho*10 + ACG::Vec3d(0,0,0) );
204 
205  ACG::Vec3d leftvec = left-sourcePoint3D;
206  leftvec.normalize( );
207  ACG::Vec3d rightvec = right-sourcePoint3D;
208  rightvec.normalize( );
209 
210  normal = cross( rightvec, leftvec );
211  normal.normalize( );
212 
213  ACG::Vec3d sourcePoint3Df(sourcePoint3D);
214  ACG::Vec3d normald(normal);
215  plane_.setPlane(sourcePoint3Df,normald);
217  planeNode_->update();
218 }
219 
220 
221 
222 
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
Definition: Vector11T.hh:429
ACG::SceneGraph::BaseNode * getRootNode()
Get the root node for data objects.
picks faces (should be implemented for all nodes)
Definition: PickTarget.hh:78
double sceneRadius()
Returns the current scene radius from the active examiner widget.