Salome HOME
Typo-fix by Kunda
[modules/geom.git] / src / MeasureGUI / MeasureGUI_DimensionCreateTool.cxx
index 9b3379f9177c05a43ad5cce6af708a8cb1c5a3b4..a03a0f4e865bc75a7ef3ebb294041e8346327bb0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  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,46 +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() );
-        break;
-      }
+        Handle(Geom_Surface) aBasisSurface = Handle(Geom_Surface)::DownCast(
+          aSurf.Surface().Surface()->Transformed( aSurf.Trsf() ) );
 
+        Handle(Geom_Curve) aCurve = aBasisSurface->VIso( 0.0 );
 
-      // get arguments of closed torus
-      if ( aSurf.GetType() == GeomAbs_Torus )
-      {
-        if ( !aSurf.IsUClosed() || !aSurf.IsVClosed() )
+        if ( aCurve->IsKind( STANDARD_TYPE( Geom_Circle ) ) )
         {
-          return NULL;
+          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();
 
-        gp_Torus aTorus = aSurf.Torus();
-        gp_Ax2 anAx2 = aTorus.Position().Ax2();
-        aCircle = new Geom_Circle( anAx2, aTorus.MinorRadius() );
+          aCircle = Handle(Geom_Circle)::DownCast( aTrimmedCurve );
+        }
         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();
@@ -528,15 +530,18 @@ Handle(AIS_DiameterDimension) MeasureGUI_DimensionCreateTool::Diameter( const GE
         break;
       }
 
-      // get arguments of closed/opened cylinder
-      if ( aSurf.GetType() == GeomAbs_Cylinder )
+      // get arguments of closed torus or cylinder
+      if ( aSurf.GetType() == GeomAbs_Torus || aSurf.GetType() == GeomAbs_Cylinder )
       {
-        Handle(Geom_Curve) aCurve = aSurf.Surface().Surface()->VIso( (aVmax + aVmin) * 0.5 );
+        Handle(Geom_Surface) aBasisSurface = Handle(Geom_Surface)::DownCast(
+          aSurf.Surface().Surface()->Transformed( aSurf.Trsf() ) );
+
+        Handle(Geom_Curve) aCurve = aBasisSurface->VIso( (aVmax + aVmin) * 0.5 );
 
         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 ) ) )
@@ -599,7 +604,9 @@ Handle(AIS_DiameterDimension) MeasureGUI_DimensionCreateTool::Diameter( const GE
       TopTools_ListIteratorOfListOfShape aFaceIt( aFaces );
       for ( ; aFaceIt.More(); aFaceIt.Next() )
       {
-        Handle(Geom_Surface) aSurface = BRep_Tool::Surface( TopoDS::Face( aFaceIt.Value() ) );
+        TopoDS_Face aFace = TopoDS::Face( aFaceIt.Value() );
+
+        Handle(Geom_Surface) aSurface = BRep_Tool::Surface( TopoDS::Face( aFace ) );
 
         gp_Pnt aCircCenter = aCircle->Circ().Location();
         Standard_Real aCircU = 0.0, aCircV = 0.0;
@@ -616,7 +623,7 @@ Handle(AIS_DiameterDimension) MeasureGUI_DimensionCreateTool::Diameter( const GE
           continue;
         }
 
-        aFaceN = gp_Vec( aNorm );
+        aFaceN = gp_Vec( aFace.Orientation() == TopAbs_REVERSED ? -aNorm : aNorm );
       }
     }
     break;
@@ -673,12 +680,14 @@ Handle(AIS_DiameterDimension) MeasureGUI_DimensionCreateTool::Diameter( const GE
   Standard_Real aCircR = aCircle->Circ().Radius();
 
   // construct closed circle as base for the diameter dimension
-  gp_Circ aRuledCirc = gce_MakeCirc( gp_Ax2( aCircP, aCircN, aCircX ), aCircR );
+  Standard_Boolean isReversed = ( ( aPln.Axis().Direction() ^ aCircX ) * aCircN ) < 0.0;
+
+  gp_Circ aRuledCirc = gce_MakeCirc( gp_Ax2( aCircP, isReversed ? -aCircN : aCircN, aCircX ), aCircR );
 
   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);
@@ -800,6 +809,8 @@ Handle(AIS_AngleDimension) MeasureGUI_DimensionCreateTool::AngleByThreePoints( c
     return NULL;
   }
 
+  aDimension->SetFlyout( Settings.DefaultFlyout );
+
   return aDimension;
 }
 
@@ -918,7 +929,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.
 //=================================================================================
@@ -1065,7 +1076,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
@@ -1135,8 +1146,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] );