15 #include "boost/bind.hpp"
17 #include <vtkProperty.h>
18 #include <vtkPolyDataMapper.h>
19 #include <vtkPolyDataNormals.h>
20 #include <vtkSTLReader.h>
21 #include <vtkMatrix4x4.h>
22 #include <vtkRenderer.h>
39 mSpaceProvider(spaceProvider),
40 mSphereRadiusInNormalizedViewport(false),
41 mStipplePattern(0xFFFF)
43 mTooltipPointColor =
settings()->
value(
"View/toolTipPointColor").value<QColor>();
44 mOffsetPointColor =
settings()->
value(
"View/toolOffsetPointColor").value<QColor>();
45 mOffsetLineColor =
settings()->
value(
"View/toolOffsetLineColor").value<QColor>();
47 mSphereRadius =
settings()->
value(
"View3D/sphereRadius").value<
double>();
48 mStayHiddenAfterVisible =
false;
49 mStayVisibleAfterHide =
false;
50 mOffsetPointVisibleAtZeroOffset =
false;
51 mToolActor = vtkActorPtr::New();
52 mPolyDataMapper = vtkPolyDataMapperPtr::New();
60 mProbeSectorPolyDataMapper = vtkPolyDataMapperPtr::New();
61 mProbeSectorActor = vtkActorPtr::New();
89 void ToolRep3D::updateToolActor()
93 mToolActor->SetMapper(NULL);
102 normals->SetInputData(model);
103 mPolyDataMapper->SetInputConnection(normals->GetOutputPort());
104 mPolyDataMapper->Update();
105 mToolActor->SetMapper(mPolyDataMapper);
109 mToolActor->GetProperty()->SetColor(1.0, 1.0, 1.0);
116 mToolActor->SetVisibility(mTool->getVisible());
124 mTracer->setTool(tool);
128 disconnect(mTool.get(), SIGNAL(toolTransformAndTimestamp(
Transform3D,
double)),
this, SLOT(
setModified()));
129 disconnect(mTool.get(), SIGNAL(toolVisible(
bool)),
this, SLOT(receiveVisible(
bool)));
130 disconnect(mTool.get(), SIGNAL(tooltipOffset(
double)),
this, SLOT(tooltipOffsetSlot(
double)));
131 disconnect(mTool.get(), SIGNAL(toolProbeSector()),
this, SLOT(probeSectorChanged()));
132 disconnect(mTool.get(), SIGNAL(toolProbeSector()),
this, SLOT(updateToolActor()));
140 connect(mTool.get(), SIGNAL(toolVisible(
bool)),
this, SLOT(receiveVisible(
bool)));
141 connect(mTool.get(), SIGNAL(tooltipOffset(
double)),
this, SLOT(tooltipOffsetSlot(
double)));
142 connect(mTool.get(), SIGNAL(toolProbeSector()),
this, SLOT(probeSectorChanged()));
143 connect(mTool.get(), SIGNAL(toolProbeSector()),
this, SLOT(updateToolActor()));
146 this->updateToolActor();
148 this->probeSectorChanged();
153 return (mTool == tool);
158 mSphereRadius = radius;
160 mOffsetPoint->setRadius(mSphereRadius);
162 mTooltipPoint->setRadius(mSphereRadius);
167 if (mSphereRadiusInNormalizedViewport == on)
170 mSphereRadiusInNormalizedViewport = on;
175 mViewportListener->setCallback(boost::bind(&ToolRep3D::scaleSpheres,
this));
179 mViewportListener.reset();
193 mTooltipPoint->setColor(color);
199 mOffsetPoint->setColor(color);
205 mOffsetLine->setColor(color);
210 view->getRenderer()->AddActor(mTracer->getActor());
212 view->getRenderer()->AddActor(mToolActor);
213 view->getRenderer()->AddActor(mProbeSectorActor);
216 mOffsetPoint->setRadius(mSphereRadius);
217 mOffsetPoint->setColor(mOffsetPointColor);
220 mTooltipPoint->setRadius(mSphereRadius);
221 mTooltipPoint->setColor(mTooltipPointColor);
224 mOffsetLine->setColor(mOffsetLineColor);
225 mOffsetLine->setStipple(mStipplePattern);
227 mTooltipPoint->getActor()->SetVisibility(
false);
228 mOffsetPoint->getActor()->SetVisibility(
false);
229 mOffsetLine->getActor()->SetVisibility(
false);
231 if (mViewportListener)
232 mViewportListener->startListen(view->getRenderer());
237 view->getRenderer()->RemoveActor(mTracer->getActor());
238 view->getRenderer()->RemoveActor(mToolActor);
239 view->getRenderer()->RemoveActor(mProbeSectorActor);
245 if (mViewportListener)
246 mViewportListener->stopListen();
255 void ToolRep3D::scaleSpheres()
257 if (!mViewportListener)
259 if (!mViewportListener->isListening())
263 double size = mViewportListener->getVpnZoom();
264 double sphereSize = mSphereRadius/100/size;
267 mOffsetPoint->setRadius(sphereSize);
269 mTooltipPoint->setRadius(sphereSize);
278 void ToolRep3D::update()
282 prMt = mTool->get_prMt();
286 mToolActor->SetUserMatrix(rMt.getVtkMatrix());
291 mProbeSectorActor->SetUserMatrix((rMpr * prMt * tMu).
getVtkMatrix());
292 mProbeSectorActor->SetVisibility(mTool->getVisible());
295 mProbeSectorActor->SetVisibility(
false);
297 this->updateOffsetGraphics();
300 void ToolRep3D::probeSectorChanged()
310 mProbeSector->setData(mTool->getProbe()->getProbeDefinition());
313 mProbeSectorPolyDataMapper->SetInputData(mProbeSector->getSectorLinesOnly());
314 if (mProbeSectorPolyDataMapper->GetInput())
316 mProbeSectorActor->SetMapper(mProbeSectorPolyDataMapper);
318 mProbeSectorActor->SetUserMatrix((rMpr * prMt * tMu).
getVtkMatrix());
319 mProbeSectorActor->SetVisibility(mTool->getVisible());
322 mProbeSectorActor->SetVisibility(
false);
325 void ToolRep3D::updateOffsetGraphics()
327 bool visible = mTool && mTool->getVisible();
329 if (!mStayVisibleAfterHide || (mOffsetPoint->getActor()->GetVisibility() ==
false))
331 mOffsetPoint->getActor()->SetVisibility(visible);
332 mTooltipPoint->getActor()->SetVisibility(visible);
334 if (mStayHiddenAfterVisible)
335 mTooltipPoint->getActor()->SetVisibility(
false);
336 mOffsetLine->getActor()->SetVisibility(visible);
339 if (
similar(0.0, mTool->getTooltipOffset()))
342 mTooltipPoint->getActor()->SetVisibility(
false);
344 mTooltipPoint->getActor()->SetVisibility(visible && mOffsetPointVisibleAtZeroOffset);
345 mOffsetPoint->getActor()->SetVisibility(
false);
346 mOffsetLine->getActor()->SetVisibility(
false);
356 mOffsetPoint->setValue(p1);
357 mOffsetLine->setValue(p0, p1);
358 mTooltipPoint->setValue(
Vector3D(p0));
360 this->scaleSpheres();
363 void ToolRep3D::receiveVisible(
bool visible)
365 if (!visible && mStayVisibleAfterHide)
367 mToolActor->SetVisibility(visible);
369 if (mStayHiddenAfterVisible)
370 mToolActor->SetVisibility(
false);
372 mToolActor->SetVisibility(mTool->getVisible());
379 mStayHiddenAfterVisible = val;
381 receiveVisible(mTool->getVisible());
390 mStayVisibleAfterHide = val;
395 mOffsetPointVisibleAtZeroOffset = val;
398 void ToolRep3D::tooltipOffsetSlot(
double val)
400 updateOffsetGraphics();