ViewProviderInspection.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 
00026 #ifndef _PreComp_
00027 # include <QMenu>
00028 # include <QMessageBox>
00029 #endif
00030 
00031 #include <Inventor/actions/SoRayPickAction.h>
00032 #include <Inventor/SoPickedPoint.h>
00033 #include <Inventor/lists/SoPickedPointList.h> 
00034 #include <Inventor/details/SoFaceDetail.h>
00035 #include <Inventor/events/SoMouseButtonEvent.h>
00036 #include <Inventor/nodes/SoCoordinate3.h>
00037 #include <Inventor/nodes/SoDrawStyle.h>
00038 #include <Inventor/nodes/SoIndexedFaceSet.h>
00039 #include <Inventor/nodes/SoPointSet.h>
00040 #include <Inventor/nodes/SoMaterial.h>
00041 #include <Inventor/nodes/SoShapeHints.h>
00042 #include <Inventor/nodes/SoOrthographicCamera.h>
00043 #include <Inventor/nodes/SoMaterialBinding.h>
00044 #include <Inventor/errors/SoDebugError.h>
00045 
00046 #include <Base/Exception.h>
00047 #include <App/PropertyLinks.h>
00048 #include <App/GeoFeature.h>
00049 #include <Gui/Application.h>
00050 #include <Gui/Document.h>
00051 #include <Gui/MainWindow.h>
00052 #include <Gui/SoFCColorBar.h>
00053 #include <Gui/SoFCSelection.h>
00054 #include <Gui/ViewProviderGeometryObject.h>
00055 #include <Gui/View3DInventorViewer.h>
00056 #include <Gui/Widgets.h>
00057 #include <Mod/Inspection/App/InspectionFeature.h>
00058 
00059 #include "ViewProviderInspection.h"
00060 
00061 
00062 using namespace InspectionGui;
00063 
00064 
00065 bool ViewProviderInspection::addflag = false;
00066 App::PropertyFloatConstraint::Constraints ViewProviderInspection::floatRange = {1.0f,64.0f,1.0f};
00067 
00068 PROPERTY_SOURCE(InspectionGui::ViewProviderInspection, Gui::ViewProviderDocumentObject)
00069 
00070 ViewProviderInspection::ViewProviderInspection() : search_radius(FLT_MAX)
00071 {
00072     ADD_PROPERTY_TYPE(OutsideGrayed,(false),"",(App::PropertyType) (App::Prop_Output|App::Prop_Hidden),"");
00073     ADD_PROPERTY_TYPE(PointSize,(1.0f),"Display",(App::PropertyType) (App::Prop_None/*App::Prop_Hidden*/),"");
00074     PointSize.setConstraints(&floatRange);
00075 
00076     pcColorRoot = new SoSeparator();
00077     pcColorRoot->ref();
00078     pcMatBinding = new SoMaterialBinding;
00079     pcMatBinding->ref();
00080     pcColorMat = new SoMaterial;
00081     pcColorMat->ref();
00082     pcColorStyle = new SoDrawStyle(); 
00083     pcColorRoot->addChild(pcColorStyle);
00084     pcCoords = new SoCoordinate3;
00085     pcCoords->ref();
00086     // simple color bar
00087     pcColorBar = new Gui::SoFCColorBar;
00088     pcColorBar->Attach(this);
00089     pcColorBar->ref();
00090     pcColorBar->setRange( -0.1f, 0.1f, 3 );
00091     pcLinkRoot = new SoGroup;
00092     pcLinkRoot->ref();
00093 
00094     pcPointStyle = new SoDrawStyle();
00095     pcPointStyle->ref();
00096     pcPointStyle->style = SoDrawStyle::POINTS;
00097     pcPointStyle->pointSize = PointSize.getValue();
00098 }
00099 
00100 ViewProviderInspection::~ViewProviderInspection()
00101 {
00102     pcColorRoot->unref();
00103     pcCoords->unref();
00104     pcMatBinding->unref();
00105     pcColorMat->unref();
00106     pcColorBar->Detach(this);
00107     pcColorBar->unref();
00108     pcLinkRoot->unref();
00109     pcPointStyle->unref();
00110 }
00111 
00112 void ViewProviderInspection::onChanged(const App::Property* prop)
00113 {
00114     if (prop == &OutsideGrayed) {
00115         if (pcColorBar) {
00116             pcColorBar->setOutsideGrayed(OutsideGrayed.getValue());
00117             pcColorBar->Notify(0);
00118         }
00119     }
00120     else if ( prop == &PointSize ) {
00121         pcPointStyle->pointSize = PointSize.getValue();
00122     }
00123     else {
00124         inherited::onChanged(prop);
00125     }
00126 }
00127 
00128 void ViewProviderInspection::hide(void)
00129 {
00130     inherited::hide();
00131     pcColorStyle->style = SoDrawStyle::INVISIBLE;
00132 }
00133 
00134 void ViewProviderInspection::show(void)
00135 {
00136     inherited::show();
00137     pcColorStyle->style = SoDrawStyle::FILLED;
00138 }
00139 
00140 void ViewProviderInspection::attach(App::DocumentObject *pcFeat)
00141 {
00142     // creats the standard viewing modes
00143     inherited::attach(pcFeat);
00144 
00145     SoShapeHints * flathints = new SoShapeHints;
00146     flathints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE ;
00147     flathints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
00148 
00149     SoGroup* pcColorShadedRoot = new SoGroup();
00150     pcColorShadedRoot->addChild(flathints);
00151 
00152     // color shaded  ------------------------------------------
00153     SoDrawStyle *pcFlatStyle = new SoDrawStyle();
00154     pcFlatStyle->style = SoDrawStyle::FILLED;
00155     pcColorShadedRoot->addChild(pcFlatStyle);
00156 
00157     pcColorShadedRoot->addChild(pcColorMat);
00158     pcColorShadedRoot->addChild(pcMatBinding);
00159     pcColorShadedRoot->addChild(pcLinkRoot);
00160 
00161     addDisplayMaskMode(pcColorShadedRoot, "ColorShaded");
00162 
00163     // Check for an already existing color bar
00164     Gui::SoFCColorBar* pcBar = ((Gui::SoFCColorBar*)findFrontRootOfType(Gui::SoFCColorBar::getClassTypeId()));
00165     if (pcBar) {
00166         float fMin = pcColorBar->getMinValue();
00167         float fMax = pcColorBar->getMaxValue();
00168     
00169         // Attach to the foreign color bar and delete our own bar
00170         pcBar->Attach(this);
00171         pcBar->ref();
00172         pcBar->setRange(fMin, fMax, 3);
00173         pcBar->Notify(0);
00174         pcColorBar->Detach(this);
00175         pcColorBar->unref();
00176         pcColorBar = pcBar;
00177     }
00178 
00179     pcColorRoot->addChild(pcColorBar);
00180 }
00181 
00182 void ViewProviderInspection::updateData(const App::Property* prop)
00183 {
00184     // set to the expected size
00185     if (prop->getTypeId() == App::PropertyLink::getClassTypeId()) {
00186         App::GeoFeature* object = static_cast<const App::PropertyLink*>(prop)->getValue<App::GeoFeature*>();
00187         if (object) {
00188             float accuracy=0;
00189             Base::Type meshId  = Base::Type::fromName("Mesh::Feature");
00190             Base::Type shapeId = Base::Type::fromName("Part::Feature");
00191             Base::Type pointId = Base::Type::fromName("Points::Feature");
00192             Base::Type propId  = App::PropertyComplexGeoData::getClassTypeId();
00193 
00194             // set the Distance property to the correct size to sync size of material node with number
00195             // of vertices/points of the referenced geometry
00196             const Data::ComplexGeoData* data = 0;
00197             if (object->getTypeId().isDerivedFrom(meshId)) {
00198                 App::Property* prop = object->getPropertyByName("Mesh");
00199                 if (prop && prop->getTypeId().isDerivedFrom(propId)) {
00200                     data = static_cast<App::PropertyComplexGeoData*>(prop)->getComplexData();
00201                 }
00202             }
00203             else if (object->getTypeId().isDerivedFrom(shapeId)) {
00204                 App::Property* prop = object->getPropertyByName("Shape");
00205                 if (prop && prop->getTypeId().isDerivedFrom(propId)) {
00206                     data = static_cast<App::PropertyComplexGeoData*>(prop)->getComplexData();
00207                     ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
00208                         ("User parameter:BaseApp/Preferences/Mod/Part");
00209                     float deviation = hGrp->GetFloat("MeshDeviation",0.2);
00210 
00211                     Base::BoundBox3d bbox = data->getBoundBox();
00212                     accuracy = (float)((bbox.LengthX() + bbox.LengthY() + bbox.LengthZ())/300.0 * deviation);
00213                 }
00214             }
00215             else if (object->getTypeId().isDerivedFrom(pointId)) {
00216                 App::Property* prop = object->getPropertyByName("Points");
00217                 if (prop && prop->getTypeId().isDerivedFrom(propId)) {
00218                     data = static_cast<App::PropertyComplexGeoData*>(prop)->getComplexData();
00219                 }
00220             }
00221 
00222             if (data) {
00223                 this->pcLinkRoot->removeAllChildren();
00224                 std::vector<Base::Vector3d> points;
00225                 std::vector<Data::ComplexGeoData::Facet> faces;
00226                 data->getFaces(points, faces, accuracy);
00227 
00228                 this->pcLinkRoot->addChild(this->pcCoords);
00229                 this->pcCoords->point.setNum(points.size());
00230                 SbVec3f* pts = this->pcCoords->point.startEditing();
00231                 for (size_t i=0; i < points.size(); i++) {
00232                     const Base::Vector3d& p = points[i];
00233                     pts[i].setValue((float)p.x,(float)p.y,(float)p.z);
00234                 }
00235                 this->pcCoords->point.finishEditing();
00236 
00237                 if (!faces.empty()) {
00238                     SoIndexedFaceSet* face = new SoIndexedFaceSet();
00239                     this->pcLinkRoot->addChild(face);
00240                     face->coordIndex.setNum(4*faces.size());
00241                     int32_t* indices = face->coordIndex.startEditing();
00242                     unsigned long j=0;
00243                     std::vector<Data::ComplexGeoData::Facet>::iterator it;
00244                     for (it = faces.begin(); it != faces.end(); ++it,j++) {
00245                         indices[4*j+0] = it->I1;
00246                         indices[4*j+1] = it->I2;
00247                         indices[4*j+2] = it->I3;
00248                         indices[4*j+3] = SO_END_FACE_INDEX;
00249                     }
00250                     face->coordIndex.finishEditing();
00251                 }
00252                 else {
00253                     this->pcLinkRoot->addChild(this->pcPointStyle);
00254                     this->pcLinkRoot->addChild(new SoPointSet());
00255                 }
00256             }
00257         }
00258     }
00259     else if (prop->getTypeId() == App::PropertyFloatList::getClassTypeId()) {
00260         // force an update of the Inventor data nodes
00261         if (this->pcObject) {
00262             App::Property* link = this->pcObject->getPropertyByName("Actual");
00263             if (link) updateData(link);
00264         }
00265         setDistances();
00266     }
00267     else if (prop->getTypeId() == App::PropertyFloat::getClassTypeId()) {
00268         if (strcmp(prop->getName(), "SearchRadius") == 0) {
00269             float fSearchRadius = ((App::PropertyFloat*)prop)->getValue();
00270             this->search_radius = fSearchRadius;
00271             pcColorBar->setRange( -fSearchRadius, fSearchRadius, 4 );
00272             pcColorBar->Notify(0);
00273         }
00274     }
00275 }
00276 
00277 SoSeparator* ViewProviderInspection::getFrontRoot(void) const
00278 {
00279     return pcColorRoot;
00280 }
00281 
00282 void ViewProviderInspection::setDistances()
00283 {
00284     App::Property* pDistances = pcObject->getPropertyByName("Distances");
00285     if (!pDistances) {
00286         SoDebugError::post("ViewProviderInspection::setDistances", "Unknown property 'Distances'");
00287         return;
00288     }
00289     if (pDistances->getTypeId() != App::PropertyFloatList::getClassTypeId()) {
00290         SoDebugError::post("ViewProviderInspection::setDistances", 
00291             "Property 'Distances' has type %s (App::PropertyFloatList was expected)", pDistances->getTypeId().getName());
00292         return;
00293     }
00294 
00295     // distance values
00296     const std::vector<float>& fValues = ((App::PropertyFloatList*)pDistances)->getValues();
00297     if ((int)fValues.size() != this->pcCoords->point.getNum()) {
00298         pcMatBinding->value = SoMaterialBinding::OVERALL;
00299         return;
00300     }
00301 
00302     if (pcColorMat->diffuseColor.getNum() != (int)fValues.size())
00303         pcColorMat->diffuseColor.setNum((int)fValues.size());
00304     if (pcColorMat->transparency.getNum() != (int)fValues.size())
00305         pcColorMat->transparency.setNum((int)fValues.size());
00306 
00307     SbColor * cols = pcColorMat->diffuseColor.startEditing();
00308     float   * tran = pcColorMat->transparency.startEditing();
00309 
00310     unsigned long j=0;
00311     for (std::vector<float>::const_iterator jt = fValues.begin(); jt != fValues.end(); ++jt, j++) {
00312         App::Color col = pcColorBar->getColor(*jt);
00313         cols[j] = SbColor(col.r, col.g, col.b);
00314         if (pcColorBar->isVisible(*jt))
00315             tran[j] = 0.0f;
00316         else
00317             tran[j] = 0.8f;
00318     }
00319 
00320     pcColorMat->diffuseColor.finishEditing();
00321     pcColorMat->transparency.finishEditing();
00322     pcMatBinding->value = SoMaterialBinding::PER_VERTEX_INDEXED;
00323 }
00324 
00325 QIcon ViewProviderInspection::getIcon() const
00326 {
00327     // Get the icon of the view provider to the associated feature
00328     QIcon px = inherited::getIcon();
00329     App::Property* pActual = pcObject->getPropertyByName("Actual");
00330     if (pActual && pActual->getTypeId().isDerivedFrom( App::PropertyLink::getClassTypeId())) {
00331         App::DocumentObject* docobj = ((App::PropertyLink*)pActual)->getValue();
00332         if (docobj) {
00333             Gui::Document* doc = Gui::Application::Instance->getDocument(docobj->getDocument());
00334             Gui::ViewProvider* view = doc->getViewProvider(docobj);
00335             px = view->getIcon();
00336         }
00337     }
00338 
00339     return px;
00340 }
00341 
00342 void ViewProviderInspection::setDisplayMode(const char* ModeName)
00343 {
00344     if (strcmp("Visual Inspection",ModeName)==0) {
00345         setDistances();
00346         setDisplayMaskMode("ColorShaded");
00347     }
00348 
00349     inherited::setDisplayMode(ModeName);
00350 }
00351 
00352 std::vector<std::string> ViewProviderInspection::getDisplayModes(void) const
00353 {
00354     // add modes
00355     std::vector<std::string> StrList;
00356     StrList.push_back("Visual Inspection");
00357     return StrList;
00358 }
00359 
00360 void ViewProviderInspection::OnChange(Base::Subject<int> &rCaller,int rcReason)
00361 {
00362     setActiveMode();
00363 }
00364 
00365 namespace InspectionGui {
00366 // Proxy class that receives an asynchronous custom event
00367 class ViewProviderProxyObject : public QObject
00368 {
00369 public:
00370     ViewProviderProxyObject(QWidget* w) : QObject(0), widget(w) {}
00371     ~ViewProviderProxyObject() {}
00372     void customEvent(QEvent *)
00373     {
00374         if (!widget.isNull()) {
00375             QList<Gui::Flag*> flags = widget->findChildren<Gui::Flag*>();
00376             if (!flags.isEmpty()) {
00377                 int ret = QMessageBox::question(Gui::getMainWindow(),
00378                     QObject::tr("Remove annotations"),
00379                     QObject::tr("Do you want to remove all annotations?"),
00380                     QMessageBox::Yes,QMessageBox::No);
00381                 if (ret == QMessageBox::Yes) {
00382                     for (QList<Gui::Flag*>::iterator it = flags.begin(); it != flags.end(); ++it)
00383                         (*it)->deleteLater();
00384                 }
00385             }
00386         }
00387 
00388         this->deleteLater();
00389     }
00390 
00391 private:
00392     QPointer<QWidget> widget;
00393 };
00394 
00395 void addFlag(Gui::View3DInventorViewer* view, const QString& text, const SoPickedPoint * point)
00396 {
00397     Gui::Flag* flag = new Gui::Flag;
00398     QPalette p;
00399     p.setColor(QPalette::Window, QColor(85,0,127));
00400     p.setColor(QPalette::Text, QColor(220,220,220));
00401     flag->setPalette(p);
00402     flag->setText(text);
00403     flag->setOrigin(point->getPoint());
00404     view->addFlag(flag, Gui::FlagLayout::BottomLeft);
00405 }
00406 }
00407 
00408 void ViewProviderInspection::inspectCallback(void * ud, SoEventCallback * n)
00409 {
00410     Gui::View3DInventorViewer* view  = reinterpret_cast<Gui::View3DInventorViewer*>(n->getUserData());
00411     const SoEvent* ev = n->getEvent();
00412     if (ev->getTypeId() == SoMouseButtonEvent::getClassTypeId()) {
00413         const SoMouseButtonEvent * mbe = static_cast<const SoMouseButtonEvent *>(ev);
00414 
00415         // Mark all incoming mouse button events as handled, especially, to deactivate the selection node
00416         n->getAction()->setHandled();
00417         n->setHandled();
00418         if (mbe->getButton() == SoMouseButtonEvent::BUTTON2 && mbe->getState() == SoButtonEvent::UP) {
00419             n->setHandled();
00420             // context-menu
00421             QMenu menu;
00422             QAction* fl = menu.addAction(QObject::tr("Annotation"));
00423             fl->setCheckable(true);
00424             fl->setChecked(addflag);
00425             QAction* cl = menu.addAction(QObject::tr("Leave info mode"));
00426             QAction* id = menu.exec(QCursor::pos());
00427             if (fl == id) {
00428                 addflag = fl->isChecked();
00429             }
00430             else if (cl == id) {
00431                 // post an event to a proxy object to make sure to avoid problems
00432                 // when opening a modal dialog
00433                 QApplication::postEvent(
00434                     new ViewProviderProxyObject(view->getGLWidget()),
00435                     new QEvent(QEvent::User));
00436                 view->setEditing(false);
00437                 view->getWidget()->setCursor(QCursor(Qt::ArrowCursor));
00438                 view->setRedirectToSceneGraph(false);
00439                 view->removeEventCallback(SoButtonEvent::getClassTypeId(), inspectCallback);
00440             }
00441         }
00442         else if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::UP) {
00443             const SoPickedPoint * point = n->getPickedPoint();
00444             if (point == NULL) {
00445                 Base::Console().Message("No point picked.\n");
00446                 return;
00447             }
00448 
00449             n->setHandled();
00450 
00451             // check if we have picked one a node of the view provider we are insterested in
00452             Gui::ViewProvider* vp = static_cast<Gui::ViewProvider*>(view->getViewProviderByPath(point->getPath()));
00453             if (vp && vp->getTypeId().isDerivedFrom(ViewProviderInspection::getClassTypeId())) {
00454                 ViewProviderInspection* that = static_cast<ViewProviderInspection*>(vp);
00455                 QString info = that->inspectDistance(point);
00456                 Gui::getMainWindow()->setPaneText(1,info);
00457                 if (addflag)
00458                     addFlag(view, info, point);
00459                 else
00460                     Gui::ToolTip::showText(QCursor::pos(), info);
00461             }
00462             else {
00463                 // the nearest picked point was not part of the view provider
00464                 SoRayPickAction action(view->getViewportRegion());
00465                 action.setPickAll(TRUE);
00466                 action.setPoint(mbe->getPosition());
00467                 action.apply(view->getSceneManager()->getSceneGraph());
00468 
00469                 const SoPickedPointList& pps = action.getPickedPointList();
00470                 for (int i=0; i<pps.getLength(); ++i) {
00471                     const SoPickedPoint * point = pps[i];
00472                     vp = static_cast<Gui::ViewProvider*>(view->getViewProviderByPath(point->getPath()));
00473                     if (vp && vp->getTypeId().isDerivedFrom(ViewProviderInspection::getClassTypeId())) {
00474                         ViewProviderInspection* that = static_cast<ViewProviderInspection*>(vp);
00475                         QString info = that->inspectDistance(point);
00476                         Gui::getMainWindow()->setPaneText(1,info);
00477                         if (addflag)
00478                             addFlag(view, info, point);
00479                         else
00480                             Gui::ToolTip::showText(QCursor::pos(), info);
00481                         break;
00482                     }
00483                 }
00484             }
00485         }
00486     }
00487     // toggle between inspection and navigation mode
00488     else if (ev->getTypeId().isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
00489         const SoKeyboardEvent * const ke = static_cast<const SoKeyboardEvent *>(ev);
00490         if (ke->getState() == SoButtonEvent::DOWN &&
00491             ke->getKey() == SoKeyboardEvent::ESCAPE) {
00492             SbBool toggle = view->isRedirectedToSceneGraph();
00493             view->setRedirectToSceneGraph(!toggle);
00494             n->setHandled();
00495         }
00496     }
00497 }
00498 
00499 namespace InspectionGui {
00500 float calcArea (const SbVec3f& v1, const SbVec3f& v2, const SbVec3f& v3)
00501 {
00502     SbVec3f a = v2-v1;
00503     SbVec3f b = v3-v1;
00504     return a.cross(b).length()/2.0f;
00505 }
00506 
00507 bool calcWeights(const SbVec3f& v1, const SbVec3f& v2, const SbVec3f& v3,
00508                  const SbVec3f& p, float& w0, float& w1, float& w2)
00509 {
00510     float fAreaABC = calcArea(v1,v2,v3);
00511     float fAreaPBC = calcArea(p,v2,v3);
00512     float fAreaPCA = calcArea(p,v3,v1);
00513     float fAreaPAB = calcArea(p,v1,v2);
00514 
00515     w0=fAreaPBC/fAreaABC;
00516     w1=fAreaPCA/fAreaABC;
00517     w2=fAreaPAB/fAreaABC;
00518 
00519     return fabs(w0+w1+w2-1.0f)<0.001f;
00520 }
00521 }
00522 
00523 QString ViewProviderInspection::inspectDistance(const SoPickedPoint* pp) const
00524 {
00525     QString info;
00526     const SoDetail* detail = pp->getDetail(pp->getPath()->getTail());
00527     if (detail && detail->getTypeId() == SoFaceDetail::getClassTypeId()) {
00528         // get the distances of the three points of the picked facet
00529         const SoFaceDetail * facedetail = static_cast<const SoFaceDetail*>(detail);
00530         App::Property* pDistance = this->pcObject->getPropertyByName("Distances");
00531         if (pDistance && pDistance->getTypeId() == App::PropertyFloatList::getClassTypeId()) {
00532             App::PropertyFloatList* dist = (App::PropertyFloatList*)pDistance;
00533             int index1 = facedetail->getPoint(0)->getCoordinateIndex();
00534             int index2 = facedetail->getPoint(1)->getCoordinateIndex();
00535             int index3 = facedetail->getPoint(2)->getCoordinateIndex();
00536             float fVal1 = (*dist)[index1];
00537             float fVal2 = (*dist)[index2];
00538             float fVal3 = (*dist)[index3];
00539           
00540             App::Property* pActual = this->pcObject->getPropertyByName("Actual");
00541             if (pActual && pActual->getTypeId().isDerivedFrom( App::PropertyLink::getClassTypeId())) {
00542                 float fSearchRadius = this->search_radius;
00543                 if (fVal1 > fSearchRadius || fVal2 > fSearchRadius || fVal3 > fSearchRadius) {
00544                     info = QObject::tr("Distance: > %1").arg(fSearchRadius);
00545                 }
00546                 else if (fVal1 < -fSearchRadius || fVal2 < -fSearchRadius || fVal3 < -fSearchRadius) {
00547                     info = QObject::tr("Distance: < %1").arg(-fSearchRadius);
00548                 }
00549                 else {
00550                     const SbVec3f& v1 = this->pcCoords->point[index1];
00551                     const SbVec3f& v2 = this->pcCoords->point[index2];
00552                     const SbVec3f& v3 = this->pcCoords->point[index3];
00553                     const SbVec3f& p = pp->getObjectPoint();
00554                     // get the weights
00555                     float w1, w2, w3;
00556                     calcWeights(v1,v2,v3,p,w1,w2,w3);
00557                     float fVal = w1*fVal1+w2*fVal2+w3*fVal3;
00558                     info = QObject::tr("Distance: %1").arg(fVal);
00559                 }
00560             }
00561         }
00562     }
00563     else if (detail && detail->getTypeId() == SoPointDetail::getClassTypeId()) {
00564         // safe downward cast, know the type
00565         const SoPointDetail * pointdetail = static_cast<const SoPointDetail*>(detail);
00566 
00567         // get the distance of the picked point
00568         int index = pointdetail->getCoordinateIndex();
00569         App::Property* prop = this->pcObject->getPropertyByName("Distances");
00570         if ( prop && prop->getTypeId() == App::PropertyFloatList::getClassTypeId() ) {
00571             App::PropertyFloatList* dist = (App::PropertyFloatList*)prop;
00572             float fVal = (*dist)[index];
00573             info = QObject::tr("Distance: %1").arg(fVal);
00574         }
00575     }
00576 
00577     return info;
00578 }
00579 
00580 // -----------------------------------------------
00581 
00582 PROPERTY_SOURCE(InspectionGui::ViewProviderInspectionGroup, Gui::ViewProviderDocumentObjectGroup)
00583 
00584 
00585 
00588 ViewProviderInspectionGroup::ViewProviderInspectionGroup()
00589 {
00590 }
00591 
00592 ViewProviderInspectionGroup::~ViewProviderInspectionGroup()
00593 {
00594 }
00595 
00599 QIcon ViewProviderInspectionGroup::getIcon() const
00600 {
00601     static const char * const ScanViewOpen[]={
00602         "16 16 10 1",
00603         "c c #000000",
00604         ". c None",
00605         "h c #808000",
00606         "# c #808080",
00607         "a c #ffff00",
00608         "r c #ff0000",
00609         "o c #ffff00",
00610         "g c #00ff00",
00611         "t c #00ffff",
00612         "b c #0000ff",
00613         "................",
00614         "...#####........",
00615         "..#hhhhh#.......",
00616         ".#hhhhhhh######.",
00617         ".#hhhhhhhhhhhh#c",
00618         ".#hhhhhhhhhhhh#c",
00619         ".#hhhhhhhhhhhh#c",
00620         "#############h#c",
00621         "#aaaaaaaaaa##h#c",
00622         "#aarroggtbbac##c",
00623         ".#arroggtbbaac#c",
00624         ".#aarroggtbbac#c",
00625         "..#aaaaaaaaaa#cc",
00626         "..#############c",
00627         "...ccccccccccccc",
00628         "................"};
00629 
00630     static const char * const ScanViewClosed[] = {
00631         "16 16 9 1",
00632         "c c #000000",
00633         ". c None",
00634         "# c #808080",
00635         "a c #ffff00",
00636         "r c #ff0000",
00637         "o c #ffff00",
00638         "g c #00ff00",
00639         "t c #00ffff",
00640         "b c #0000ff",
00641         "................",
00642         "...#####........",
00643         "..#aaaaa#.......",
00644         ".#aaaaaaa######.",
00645         ".#aaaaaaaaaaaa#c",
00646         ".#aarroggtbbaa#c",
00647         ".#aarroggtbbaa#c",
00648         ".#aarroggtbbaa#c",
00649         ".#aarroggtbbaa#c",
00650         ".#aarroggtbbaa#c",
00651         ".#aarroggtbbaa#c",
00652         ".#aarroggtbbaa#c",
00653         ".#aaaaaaaaaaaa#c",
00654         ".##############c",
00655         "..cccccccccccccc",
00656         "................"};
00657 
00658     QIcon groupIcon;
00659     groupIcon.addPixmap(QPixmap(ScanViewClosed), QIcon::Normal, QIcon::Off);
00660     groupIcon.addPixmap(QPixmap(ScanViewOpen), QIcon::Normal, QIcon::On);
00661     return groupIcon;
00662 }

Generated on Wed Nov 23 19:00:59 2011 for FreeCAD by  doxygen 1.6.1