Warnings on vc14 were eliminated
[occt.git] / src / UnitsMethods / UnitsMethods.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 36978f4..f73b3ce
@@ -1,42 +1,40 @@
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
 //
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
 //
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// 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.
 //
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
-#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>
+#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.;
@@ -155,24 +153,12 @@ 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 {
@@ -200,28 +186,20 @@ 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
+#ifdef OCCT_DEBUG
       cout << "PCURVE of Parabola type in U or V Periodic Surface" << endl;
       cout << "Parameters Not transformed to Degree" << endl;
 #endif
     }
     else if (aCurve2d->IsKind(STANDARD_TYPE(Geom2d_Hyperbola))) {
-#ifdef DEBUG
+#ifdef OCCT_DEBUG
       cout << "PCURVE of Hyperbola type in U or V Periodic Surface" << endl;
       cout << "Parameters Not transformed to Degree" << endl;
 #endif
@@ -250,7 +228,7 @@ Handle(Geom2d_Curve) UnitsMethods::RadianToDegree
       return myNewBSpline2d;
     }
     else {
-#ifdef DEBUG
+#ifdef OCCT_DEBUG
       cout << "PCURVE of Other Types of Bounded Curve in U or V Periodic Surface" << endl;
       cout << "Parameters Not transformed to Degree" << endl;
 #endif
@@ -304,24 +282,12 @@ 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 {
@@ -338,14 +304,14 @@ Handle(Geom2d_Curve) UnitsMethods::DegreeToRadian
       aPcurve = aBSpline2d;
     }
     else if (aPcurve->IsKind(STANDARD_TYPE(Geom2d_Parabola))) {
-#ifdef DEBUG
+#ifdef OCCT_DEBUG
       cout << "PCURVE of Parabola type" << endl;
       cout << "Parameters Not Yet transformed according to LenghtUnit" << endl;
 #endif
       return aPcurve;
     }
     else if (aPcurve->IsKind(STANDARD_TYPE(Geom2d_Hyperbola))) {
-#ifdef DEBUG
+#ifdef OCCT_DEBUG
       cout << "PCURVE of Hyperbola type" << endl;
       cout << "Parameters Not Yet transformed according to LenghtUnit" << endl;
 #endif
@@ -392,7 +358,7 @@ Handle(Geom2d_Curve) UnitsMethods::DegreeToRadian
     aPcurve = aBSpline2d;
   }
   else {
-#ifdef DEBUG
+#ifdef OCCT_DEBUG
     cout << "DegreeToRadian : Type " << aPcurve->DynamicType();
     cout << " not yet implemented" << endl;
 #endif
@@ -448,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.;
   }
 }