Salome HOME
Bug IPAL19097 NPAL16768 is not implemented for "Normal to a face"
[modules/geom.git] / src / MeasureGUI / MeasureGUI_BndBoxDlg.cxx
index b478e6158741ca091512484883869f79ecd0143b..561d58c31b85d01cc07803f096e0555280d2c6e5 100644 (file)
 
 #include <GEOMBase.h>
 
+#include <GEOM_Function.hxx>
+#include <GEOM_Object.hxx>
+
 #include <BRepPrimAPI_MakeBox.hxx>
+#include <BRepAdaptor_Surface.hxx>
+#include <BRep_Tool.hxx>
+#include <BRep_TFace.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopExp_Explorer.hxx>
 
 #include <SUIT_Session.h>
 #include <SUIT_ResourceMgr.h>
@@ -154,8 +163,64 @@ bool MeasureGUI_BndBoxDlg::getParameters( double& theXmin, double& theXmax,
     return false;
   else {
     try {
+      Handle(Poly_Triangulation) Trtn = 0; 
+
+      Handle(GEOM_Object) anObject = GEOM_Engine::GetEngine()->GetObject(myObj->GetStudyID(), myObj->GetEntry());
+      if (!anObject.IsNull())
+      {
+       Handle(GEOM_Function) aRefShape = anObject->GetLastFunction();
+       if (!aRefShape.IsNull())
+       {
+         TopoDS_Shape aShape = aRefShape->GetValue();
+         if (!aShape.IsNull())
+         {
+           TopLoc_Location l;
+           Handle(Poly_Triangulation) T;
+           TopExp_Explorer ex;
+           for (ex.Init(aShape,TopAbs_FACE); ex.More(); ex.Next()) {
+             const TopoDS_Face& F = TopoDS::Face(ex.Current());
+             
+             BRepAdaptor_Surface surf(F);
+             if (surf.GetType() == GeomAbs_Sphere)
+             {
+               T = BRep_Tool::Triangulation(F, l);
+               if (!T.IsNull()) {
+                 Handle(Poly_Triangulation) NullTrtn = 0;
+                 (*((Handle(BRep_TFace)*)&F.TShape()))->Triangulation(NullTrtn);
+                 Trtn = T;
+                 break;
+               }
+             }
+             else
+               break;
+           }
+         }
+       }
+      }
+
       GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetBoundingBox(
         myObj, theXmin, theXmax, theYmin, theYmax, theZmin, theZmax );
+      
+      if (!Trtn.IsNull())
+      {
+       Handle(GEOM_Function) aRefShape = anObject->GetLastFunction();
+       if (!aRefShape.IsNull())
+       {
+         TopoDS_Shape aShape = aRefShape->GetValue();
+         if (!aShape.IsNull())
+         {
+           TopLoc_Location l;
+           Handle(Poly_Triangulation) T;
+           TopExp_Explorer ex;
+           for (ex.Init(aShape,TopAbs_FACE); ex.More(); ex.Next()) {
+             const TopoDS_Face& F = TopoDS::Face(ex.Current());
+             (*((Handle(BRep_TFace)*)&F.TShape()))->Triangulation(Trtn);
+             break;
+           }
+         }
+       }
+      }
+
     }
     catch( const SALOME::SALOME_Exception& e ) {
       SalomeApp_Tools::QtCatchCorbaException( e );