GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_3dwidgetmanagerhandle.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  *****************************************************************************/
23 
25 
26 #include "../viewport/glc_viewport.h"
27 #include "../sceneGraph/glc_3dviewinstance.h"
28 #include "glc_3dwidget.h"
29 #include <QMouseEvent>
30 
32 : m_Collection()
33 , m_Count(1)
34 , m_3DWidgetHash()
35 , m_MapBetweenInstanceWidget()
36 , m_pViewport(pViewport)
37 , m_Active3DWidgetId(0)
38 , m_Preselected3DWidgetId(0)
39 {
40 
41 }
42 
44 {
45  QHash<GLC_uint, GLC_3DWidget*>::iterator iWidget= m_3DWidgetHash.begin();
46  while (m_3DWidgetHash.constEnd() != iWidget)
47  {
48  delete iWidget.value();
49  ++iWidget;
50  }
51 }
52 
54 {
55  Q_ASSERT(!m_MapBetweenInstanceWidget.contains(p3DWidget->id()));
56  m_3DWidgetHash.insert(p3DWidget->id(), p3DWidget);
57  p3DWidget->setWidgetManager(this);
58 }
59 
61 {
62  Q_ASSERT(m_3DWidgetHash.contains(id));
63  delete m_3DWidgetHash.take(id);
65 
66 }
67 
69 {
70  Q_ASSERT(m_3DWidgetHash.contains(id));
71  return m_3DWidgetHash.take(id);
72 }
73 
75 {
76  const GLC_uint instanceId= instance.id();
77  Q_ASSERT(!m_MapBetweenInstanceWidget.contains(instanceId));
78  Q_ASSERT(!m_Collection.contains(instanceId));
79 
80  m_MapBetweenInstanceWidget.insert(instanceId, widgetId);
81  m_Collection.add(instance, 0);
82 }
83 
85 {
86  Q_ASSERT(m_MapBetweenInstanceWidget.contains(id));
87  Q_ASSERT(m_Collection.contains(id));
88  m_Collection.remove(id);
89  m_MapBetweenInstanceWidget.remove(id);
90 }
91 
93 {
95  QHash<GLC_uint, GLC_3DWidget*>::iterator iWidget= m_3DWidgetHash.begin();
96  while (m_3DWidgetHash.constEnd() != iWidget)
97  {
98  delete iWidget.value();
99  ++iWidget;
100  }
101  m_3DWidgetHash.clear();
104 }
105 
107 {
109  Q_ASSERT(m_3DWidgetHash.contains(id));
110  m_3DWidgetHash.value(id)->setVisible(visible);
111 }
112 
114 {
115 
116  if (hasAnActiveWidget())
117  {
118 
119  }
120  return glc::IgnoreEvent;
121 }
122 
124 {
126  // Get the 3D cursor position and the id under
127  QPair<GLC_uint, GLC_Point3d> cursorInfo= select(pEvent);
128  const GLC_uint selectedId= cursorInfo.first;
129  const GLC_Point3d pos(cursorInfo.second);
130 
131  if (hasAnActiveWidget())
132  {
133  GLC_3DWidget* pActiveWidget= m_3DWidgetHash.value(m_Active3DWidgetId);
134  eventFlag= pActiveWidget->mouseMove(pos, pEvent->buttons(), selectedId);
135  }
136  else
137  {
138  if (m_MapBetweenInstanceWidget.contains(selectedId))
139  {
140  const GLC_uint select3DWidgetId= m_MapBetweenInstanceWidget.value(selectedId);
141 
142  if (m_Preselected3DWidgetId != select3DWidgetId)
143  {
145  GLC_3DWidget* pActiveWidget= m_3DWidgetHash.value(m_Preselected3DWidgetId);
146  eventFlag= pActiveWidget->mouseOver(pos, selectedId);
147  }
148  else if (0 != m_Preselected3DWidgetId && (m_Preselected3DWidgetId != select3DWidgetId))
149  {
150  eventFlag= m_3DWidgetHash.value(m_Preselected3DWidgetId)->unselect(pos, selectedId);
151  }
152 
153  }
154  else if (0 != m_Preselected3DWidgetId)
155  {
156  eventFlag= m_3DWidgetHash.value(m_Preselected3DWidgetId)->unselect(pos, selectedId);
158  }
159  }
160  return eventFlag;
161 }
162 
164 {
166 
167  if (pEvent->button() == Qt::LeftButton)
168  {
169  // Get the 3D cursor position and the id under
170  QPair<GLC_uint, GLC_Point3d> cursorInfo= select(pEvent);
171  const GLC_uint selectedId= cursorInfo.first;
172  const GLC_Point3d pos(cursorInfo.second);
173 
174  if (hasAnActiveWidget())
175  {
176  GLC_3DWidget* pActiveWidget= m_3DWidgetHash.value(m_Active3DWidgetId);
177  const bool activeWidgetUnderMouse= pActiveWidget->instanceBelongTo(selectedId);
178  if (activeWidgetUnderMouse)
179  {
180  eventFlag= pActiveWidget->mousePressed(pos, pEvent->button(), selectedId);
181  }
182  else
183  {
184  eventFlag= pActiveWidget->unselect(pos, selectedId);
185  if (m_MapBetweenInstanceWidget.contains(selectedId))
186  {
188  pActiveWidget= m_3DWidgetHash.value(m_Active3DWidgetId);
189  eventFlag= pActiveWidget->select(pos, selectedId);
190  }
191  else
192  {
194  }
195  }
196 
197  }
198  else
199  {
200  if (m_MapBetweenInstanceWidget.contains(selectedId))
201  {
203  GLC_3DWidget* pActiveWidget= m_3DWidgetHash.value(m_Active3DWidgetId);
204  eventFlag= pActiveWidget->select(pos, selectedId);
205  }
206  }
207  }
208 
209  return eventFlag;
210 }
211 
213 {
215  if (hasAnActiveWidget() && (pEvent->button() == Qt::LeftButton))
216  {
217 
218  GLC_3DWidget* pActiveWidget= m_3DWidgetHash.value(m_Active3DWidgetId);
219 
220  eventFlag= pActiveWidget->mouseReleased(pEvent->button());
221  }
222  return eventFlag;
223 }
224 
226 {
227  // Signal 3DWidget that the view as changed
228  QHash<GLC_uint, GLC_3DWidget*>::iterator iWidget= m_3DWidgetHash.begin();
229  while (m_3DWidgetHash.constEnd() != iWidget)
230  {
231  iWidget.value()->updateWidgetRep();
232  ++iWidget;
233  }
234 
235  // Render the 3D widget
239  if (GLC_State::glslUsed())
240  {
243  }
244 }
245 
246 QPair<GLC_uint, GLC_Point3d> GLC_3DWidgetManagerHandle::select(QMouseEvent* event)
247 {
248 
249  GLC_uint selectionId= m_pViewport->selectOnPreviousRender(event->x(), event->y());
250  const GLC_Point3d selectedPoint(m_pViewport->unProject(event->x(), event->y()));
251 
252  QPair<GLC_uint, GLC_Point3d> selection;
253  selection.first= selectionId;
254  selection.second= selectedPoint;
255 
256  return selection;
257 }

©2005-2013 Laurent Ribon