]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/MeasureGUI/MeasureGUI_DimensionCreateTool.cxx
Salome HOME
Avoid installing redundant files
[modules/geom.git] / src / MeasureGUI / MeasureGUI_DimensionCreateTool.cxx
index dbd26cf0df6ce70b84b262b447c501c7225d063c..d860ce1382849c6c247eb1549dd5f377d996968a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -76,7 +76,6 @@
 #include <TColgp_SequenceOfDir.hxx>
 #include <V3d_View.hxx>
 
-
 // plane associated with custom data
 struct PlaneAndSegment
 {
@@ -407,6 +406,9 @@ Handle(AIS_LengthDimension) MeasureGUI_DimensionCreateTool::LengthByParallelEdge
     return NULL;
   }
 
+  if( aFirstSh == aSecondSh )
+    return NULL;
+
   TopoDS_Edge aFirstEdge  = TopoDS::Edge( aFirstSh );
   TopoDS_Edge aSecondEdge = TopoDS::Edge( aSecondSh );
 
@@ -477,31 +479,46 @@ Handle(AIS_DiameterDimension) MeasureGUI_DimensionCreateTool::Diameter( const GE
 
       BRepAdaptor_Surface aSurf( aMeasuredFace );
 
+      Standard_Real aUmin = aSurf.FirstUParameter();
+      Standard_Real aUmax = aSurf.LastUParameter();
       Standard_Real aVmin = aSurf.FirstVParameter();
       Standard_Real aVmax = aSurf.LastVParameter();
 
-      // get arguments of closed sphere
+      // get arguments of sphere (the sphere should not be cutted at v-center)
       if ( aSurf.GetType() == GeomAbs_Sphere )
       {
-        if ( !aSurf.IsUClosed() || !aSurf.IsVClosed() )
+        if ( aVmax <= Precision::PConfusion() || aVmin >= Precision::PConfusion() )
         {
           return NULL;
         }
 
-        // take circle in XOY plane from sphere
-        gp_Sphere aSphere = aSurf.Sphere();
-        gp_Ax2 anAx2 = gp_Ax2( aSphere.Location(), gp::DZ() );
-        aCircle = new Geom_Circle( anAx2, aSphere.Radius() );
+        Handle(Geom_Surface) aBasisSurface = Handle(Geom_Surface)::DownCast(
+          aSurf.Surface().Surface()->Transformed( aSurf.Trsf() ) );
+
+        Handle(Geom_Curve) aCurve = aBasisSurface->VIso( 0.0 );
+
+        if ( aCurve->IsKind( STANDARD_TYPE( Geom_Circle ) ) )
+        {
+          aPmin = aUmin;
+          aPmax = aUmax;
+          aCircle = Handle(Geom_Circle)::DownCast( aCurve );
+        }
+        else if (  aCurve->IsKind( STANDARD_TYPE( Geom_TrimmedCurve ) ) )
+        {
+          Handle(Geom_TrimmedCurve) aTrimmedCurve = Handle(Geom_TrimmedCurve)::DownCast( aCurve );
+          aPmin = aTrimmedCurve->FirstParameter();
+          aPmax = aTrimmedCurve->LastParameter();
+
+          aCircle = Handle(Geom_Circle)::DownCast( aTrimmedCurve ); // todo: useless downcast: aCircle always NULL
+        }
         break;
       }
 
-      // get arguments of closed cone
+      // get arguments of cone
       if ( aSurf.GetType() == GeomAbs_Cone )
       {
-        if ( !aSurf.IsUClosed() || !aSurf.IsVClosed() )
-        {
-          return NULL;
-        }
+        aPmin = aUmin;
+        aPmax = aUmax;
 
         gp_Cone aCone = aSurf.Cone();
         gp_Ax2 anAx2 = aCone.Position().Ax2();
@@ -516,11 +533,6 @@ Handle(AIS_DiameterDimension) MeasureGUI_DimensionCreateTool::Diameter( const GE
       // get arguments of closed torus or cylinder
       if ( aSurf.GetType() == GeomAbs_Torus || aSurf.GetType() == GeomAbs_Cylinder )
       {
-        if ( !aSurf.IsUClosed() || !aSurf.IsVClosed() )
-        {
-          return NULL;
-        }
-
         Handle(Geom_Surface) aBasisSurface = Handle(Geom_Surface)::DownCast(
           aSurf.Surface().Surface()->Transformed( aSurf.Trsf() ) );
 
@@ -528,8 +540,8 @@ Handle(AIS_DiameterDimension) MeasureGUI_DimensionCreateTool::Diameter( const GE
 
         if ( aCurve->IsKind( STANDARD_TYPE( Geom_Circle ) ) )
         {
-          aPmin = aSurf.FirstUParameter();
-          aPmax = aSurf.LastUParameter();
+          aPmin = aUmin;
+          aPmax = aUmax;
           aCircle = Handle(Geom_Circle)::DownCast( aCurve );
         }
         else if (  aCurve->IsKind( STANDARD_TYPE( Geom_TrimmedCurve ) ) )
@@ -538,7 +550,7 @@ Handle(AIS_DiameterDimension) MeasureGUI_DimensionCreateTool::Diameter( const GE
           aPmin = aTrimmedCurve->FirstParameter();
           aPmax = aTrimmedCurve->LastParameter();
 
-          aCircle = Handle(Geom_Circle)::DownCast( aTrimmedCurve );
+          aCircle = Handle(Geom_Circle)::DownCast( aTrimmedCurve ); // todo: useless downcast: aCircle always NULL
         }
 
         break;
@@ -567,6 +579,7 @@ Handle(AIS_DiameterDimension) MeasureGUI_DimensionCreateTool::Diameter( const GE
       // do not break, go to edge checking
       aMeasuredShape = anExpEdge;
     }
+    // fall through!
 
     case TopAbs_EDGE:
     {
@@ -615,6 +628,8 @@ Handle(AIS_DiameterDimension) MeasureGUI_DimensionCreateTool::Diameter( const GE
       }
     }
     break;
+  default:
+    break;
   }
 
   if ( aCircle.IsNull() )
@@ -675,7 +690,7 @@ Handle(AIS_DiameterDimension) MeasureGUI_DimensionCreateTool::Diameter( const GE
   Handle(AIS_DiameterDimension) aDimension = new AIS_DiameterDimension( aRuledCirc, aPln );
 
   // if flyout is extended in tangent direction to circle, the default flyout value is used
-  // if flyout is extended in plane of circle, the zero flyout value is choosen initially
+  // if flyout is extended in plane of circle, the zero flyout value is chosen initially
   Standard_Real aFlyout = aCircN.IsParallel( aPln.Axis().Direction(), Precision::Angular() ) ? 0.0 : Settings.DefaultFlyout;
 
   aDimension->SetFlyout(aFlyout);
@@ -917,7 +932,7 @@ void MeasureGUI_DimensionCreateTool::PositionLength( const Bnd_Box& theBnd,
 //            flyout plane to best match the current view projection (if any)
 //            The points are aligned to XOY, YOZ, ZOX planes.
 //            The flyout takes into account bounding box of main shape of face normal
-//            vector. The flyouts tangetial to the circle plane are directed in 
+//            vector. The flyouts tangential to the circle plane are directed in 
 //            accordance with the face normal (if not-null), otherwise the flyouts
 //            are turned to direct to the closest border of bounding box.
 //=================================================================================
@@ -1064,7 +1079,7 @@ void MeasureGUI_DimensionCreateTool::ChooseLengthFlyoutsFromBnd( SeqOfDirs& theD
   {
     const gp_Pln& aPlane = aPlaneIt.Value();
 
-    // transform bounding box to orthogonal coordiantes relative to
+    // transform bounding box to orthogonal coordinates relative to
     // dimension points P1, P2 (x-axis) and plane direction (z-axis),
     // where y coordinates will correspond to flyout direction against
     // the dimension point line
@@ -1134,8 +1149,8 @@ template <typename TPlane>
 TPlane MeasureGUI_DimensionCreateTool::SelectPlaneForProjection( const NCollection_Sequence<TPlane>& thePlanes,
                                                                  const Handle(V3d_View)& theView ) const
 {
-  Quantity_Parameter U[3];
-  Quantity_Parameter N[3];
+  Standard_Real U[3];
+  Standard_Real N[3];
   theView->Up( U[0], U[1], U[2] );
   theView->Proj( N[0], N[1], N[2] );