0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / UnitsMethods / UnitsMethods.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 52ec679..953d0b0
@@ -1,25 +1,40 @@
-#include <UnitsMethods.ixx>
-
-#include <Geom_Plane.hxx>
-#include <Geom_Surface.hxx>
-#include <Geom_ConicalSurface.hxx>
-#include <Geom_CylindricalSurface.hxx>
-#include <Geom_SphericalSurface.hxx>
-#include <Geom_ToroidalSurface.hxx>
-#include <Geom_SurfaceOfRevolution.hxx>
-#include <Geom2dConvert.hxx>
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+
+#include <Geom2d_BoundedCurve.hxx>
 #include <Geom2d_BSplineCurve.hxx>
 #include <Geom2d_Circle.hxx>
+#include <Geom2d_Conic.hxx>
 #include <Geom2d_Curve.hxx>
 #include <Geom2d_Ellipse.hxx>
 #include <Geom2d_Hyperbola.hxx>
 #include <Geom2d_Line.hxx>
 #include <Geom2d_Parabola.hxx>
+#include <Geom2dConvert.hxx>
+#include <Geom_ConicalSurface.hxx>
+#include <Geom_CylindricalSurface.hxx>
+#include <Geom_Plane.hxx>
+#include <Geom_SphericalSurface.hxx>
+#include <Geom_Surface.hxx>
+#include <Geom_SurfaceOfRevolution.hxx>
+#include <Geom_ToroidalSurface.hxx>
 #include <gp.hxx>
+#include <gp_Dir2d.hxx>
 #include <gp_GTrsf2d.hxx>
-#include <gp_Trsf2d.hxx>
 #include <gp_Pnt2d.hxx>
-#include <gp_Dir2d.hxx>
+#include <gp_Trsf2d.hxx>
+#include <UnitsMethods.hxx>
 
 static Standard_Real theLengthFactor     = 1.;
 static Standard_Real thePlaneAngleFactor = 1.;
@@ -138,29 +153,17 @@ Handle(Geom2d_Curve) UnitsMethods::RadianToDegree
   }
   else if (theSurf->IsKind(STANDARD_TYPE(Geom_Plane))) {
     uFact = vFact = LengthFact;
-    if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Circle))) {
-      Handle(Geom2d_Circle) newCircle = 
-       Handle(Geom2d_Circle)::DownCast(aCurve2d);
-      gp_Pnt2d Loc = newCircle->Location();
-      Loc.SetX(Loc.X()*LengthFact);
-      Loc.SetY(Loc.Y()*LengthFact);
-      newCircle->SetRadius(newCircle->Radius()*LengthFact);
-      return newCircle;
-    }
-    else if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Ellipse))) {
-      Handle(Geom2d_Ellipse) newEllipse = 
-       Handle(Geom2d_Ellipse)::DownCast(aCurve2d);
-      gp_Pnt2d Loc = newEllipse->Location();
-      Loc.SetX(Loc.X()*LengthFact);
-      Loc.SetY(Loc.Y()*LengthFact);
-      newEllipse->SetMajorRadius(newEllipse->MajorRadius()*LengthFact);
-      newEllipse->SetMinorRadius(newEllipse->MinorRadius()*LengthFact);
-      return newEllipse;
+    if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Circle)) ||
+        aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Ellipse))) {
+      gp_Trsf2d aT;
+      aT.SetScale (gp::Origin2d(), LengthFact);
+      aCurve2d->Transform (aT);
+      return aCurve2d;
     }
   }
   else {
 //  debug
-//    cout <<"UnitsMethods: SurfType = "<< aSurface->DynamicType();
+//    std::cout <<"UnitsMethods: SurfType = "<< aSurface->DynamicType();
     return aCurve2d;
   }
 
@@ -183,30 +186,22 @@ Handle(Geom2d_Curve) UnitsMethods::RadianToDegree
     return myNewLine2d;
   }
   else if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Conic))) {
-    if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Circle))) {
-      Handle(Geom2d_Circle) aCirc2d = 
-       Handle(Geom2d_Circle)::DownCast(aCurve2d);
+    if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Circle)) ||
+        aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Ellipse))) {
       Handle(Geom2d_BSplineCurve) aBSpline2d = 
-       Geom2dConvert::CurveToBSplineCurve(aCirc2d);
+       Geom2dConvert::CurveToBSplineCurve(aCurve2d);
       aCurve2d = aBSpline2d;
     } 
-    else if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Ellipse))) {
-      Handle(Geom2d_Ellipse) aHel2d = 
-       Handle(Geom2d_Ellipse)::DownCast(aCurve2d);
-      Handle(Geom2d_BSplineCurve) aBSpline2d = 
-       Geom2dConvert::CurveToBSplineCurve(aHel2d);
-      aCurve2d = aBSpline2d;
-    }
     else if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Parabola))) {
-#ifdef DEBUG
-      cout << "PCURVE of Parabola type in U or V Periodic Surface" << endl;
-      cout << "Parameters Not transformed to Degree" << endl;
+#ifdef OCCT_DEBUG
+      std::cout << "PCURVE of Parabola type in U or V Periodic Surface" << std::endl;
+      std::cout << "Parameters Not transformed to Degree" << std::endl;
 #endif
     }
     else if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Hyperbola))) {
-#ifdef DEBUG
-      cout << "PCURVE of Hyperbola type in U or V Periodic Surface" << endl;
-      cout << "Parameters Not transformed to Degree" << endl;
+#ifdef OCCT_DEBUG
+      std::cout << "PCURVE of Hyperbola type in U or V Periodic Surface" << std::endl;
+      std::cout << "Parameters Not transformed to Degree" << std::endl;
 #endif
     }
     
@@ -233,9 +228,9 @@ Handle(Geom2d_Curve) UnitsMethods::RadianToDegree
       return myNewBSpline2d;
     }
     else {
-#ifdef DEBUG
-      cout << "PCURVE of Other Types of Bounded Curve in U or V Periodic Surface" << endl;
-      cout << "Parameters Not transformed to Degree" << endl;
+#ifdef OCCT_DEBUG
+      std::cout << "PCURVE of Other Types of Bounded Curve in U or V Periodic Surface" << std::endl;
+      std::cout << "Parameters Not transformed to Degree" << std::endl;
 #endif
     }
   }
@@ -287,29 +282,17 @@ Handle(Geom2d_Curve) UnitsMethods::DegreeToRadian
   }
   else if (aSurface->IsKind(STANDARD_TYPE(Geom_Plane))) {
     uFact = vFact = LengthFact;
-    if (aPcurve->IsKind(STANDARD_TYPE(Geom2d_Circle))) {
-      Handle(Geom2d_Circle) newCircle = 
-       Handle(Geom2d_Circle)::DownCast(aPcurve);
-      gp_Pnt2d Loc = newCircle->Location();
-      Loc.SetX(Loc.X()*LengthFact);
-      Loc.SetY(Loc.Y()*LengthFact);
-      newCircle->SetRadius(newCircle->Radius()*LengthFact);
-      return newCircle;
-    }
-    else if (aPcurve->IsKind(STANDARD_TYPE(Geom2d_Ellipse))) {
-      Handle(Geom2d_Ellipse) newEllipse = 
-       Handle(Geom2d_Ellipse)::DownCast(aPcurve);
-      gp_Pnt2d Loc = newEllipse->Location();
-      Loc.SetX(Loc.X()*LengthFact);
-      Loc.SetY(Loc.Y()*LengthFact);
-      newEllipse->SetMajorRadius(newEllipse->MajorRadius()*LengthFact);
-      newEllipse->SetMinorRadius(newEllipse->MinorRadius()*LengthFact);
-      return newEllipse;
+    if (aPcurve->IsKind(STANDARD_TYPE(Geom2d_Circle)) ||
+        aPcurve->IsKind(STANDARD_TYPE(Geom2d_Ellipse))) {
+      gp_Trsf2d aT;
+      aT.SetScale (gp::Origin2d(), LengthFact);
+      aPcurve->Transform (aT);
+      return aPcurve;
     }
   }
   else {
 //  debug
-//    cout <<"UnitsMethods: SurfType = "<< aSurface->DynamicType();
+//    std::cout <<"UnitsMethods: SurfType = "<< aSurface->DynamicType();
     return aPcurve;
   }
 
@@ -321,16 +304,16 @@ Handle(Geom2d_Curve) UnitsMethods::DegreeToRadian
       aPcurve = aBSpline2d;
     }
     else if (aPcurve->IsKind(STANDARD_TYPE(Geom2d_Parabola))) {
-#ifdef DEBUG
-      cout << "PCURVE of Parabola type" << endl;
-      cout << "Parameters Not Yet transformed according to LenghtUnit" << endl;
+#ifdef OCCT_DEBUG
+      std::cout << "PCURVE of Parabola type" << std::endl;
+      std::cout << "Parameters Not Yet transformed according to LenghtUnit" << std::endl;
 #endif
       return aPcurve;
     }
     else if (aPcurve->IsKind(STANDARD_TYPE(Geom2d_Hyperbola))) {
-#ifdef DEBUG
-      cout << "PCURVE of Hyperbola type" << endl;
-      cout << "Parameters Not Yet transformed according to LenghtUnit" << endl;
+#ifdef OCCT_DEBUG
+      std::cout << "PCURVE of Hyperbola type" << std::endl;
+      std::cout << "Parameters Not Yet transformed according to LenghtUnit" << std::endl;
 #endif
       return aPcurve;
     }
@@ -375,9 +358,9 @@ Handle(Geom2d_Curve) UnitsMethods::DegreeToRadian
     aPcurve = aBSpline2d;
   }
   else {
-#ifdef DEBUG
-    cout << "DegreeToRadian : Type " << aPcurve->DynamicType();
-    cout << " not yet implemented" << endl;
+#ifdef OCCT_DEBUG
+    std::cout << "DegreeToRadian : Type " << aPcurve->DynamicType();
+    std::cout << " not yet implemented" << std::endl;
 #endif
   }
   return aPcurve;
@@ -431,17 +414,17 @@ void UnitsMethods::SetCasCadeLengthUnit (const Standard_Integer unit)
 Standard_Real UnitsMethods::GetLengthFactorValue (const Standard_Integer par) 
 {
   switch ( par ) {
-  case  1 : return 25.4;
-  case  2 : return 1.;
+  case  1 : return 25.4; // inch
+  case  2 : return 1.; // millimeter
   
-  case  4 : return 304.8;
-  case  5 : return 1609270.;
-  case  6 : return 1000.;
-  case  7 : return 1000000.;
-  case  8 : return 0.0254;
-  case  9 : return 0.001;
-  case 10 : return 10.;
-  case 11 : return 0.0000254;
+  case  4 : return 304.8; // foot
+  case  5 : return 1609344.; // mile
+  case  6 : return 1000.; // meter
+  case  7 : return 1000000.; // kilometer
+  case  8 : return 0.0254; // mil (0.001 inch)
+  case  9 : return 0.001; // micron
+  case 10 : return 10.; // centimeter
+  case 11 : return 0.0000254; // microinch
   default : return 1.;
   }
 }