Salome HOME
PAL12607: Static objects in Geometry GUI libraries.
[modules/geom.git] / src / GEOMAlgo / BlockFix_SphereSpaceModifier.cxx
index c5f774d82de9dcd1ea4ad732878f54e03006da56..e61b4a53b39b942b41b59e5351790f533f081ea3 100644 (file)
@@ -1,3 +1,22 @@
+// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// 
+// 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.
+// 
+// This library is distributed in the hope that it will be useful 
+// but WITHOUT ANY WARRANTY; without even the implied warranty of 
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public  
+// License along with this library; if not, write to the Free Software 
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 // File:       BlockFix.cxx
 // Created:    Tue Dec  7 11:59:05 2004
 // Author:     Pavel DURANDIN
@@ -65,16 +84,35 @@ static Standard_Boolean ModifySurface(const TopoDS_Face& aFace,
     ShapeAnalysis::GetFaceUVBounds(aFace,Umin, Umax, Vmin, Vmax);
     Standard_Real PI2 = PI/2.;
     if(Vmax > PI2 - Precision::PConfusion() || Vmin < -PI2+::Precision::PConfusion()) {
+      Handle(Geom_SphericalSurface) aSphere = Handle(Geom_SphericalSurface)::DownCast(S);
+      gp_Sphere sp = aSphere->Sphere();
+      gp_Ax3 ax3 = sp.Position();
       if(Abs(Vmax-Vmin) < PI2) {
-        Handle(Geom_SphericalSurface) aSphere = Handle(Geom_SphericalSurface)::DownCast(S);
-        gp_Sphere sp = aSphere->Sphere();
-        gp_Ax3 ax3 = sp.Position();
         gp_Ax3 axnew3(ax3.Axis().Location(), ax3.Direction()^ax3.XDirection(),ax3.XDirection());
         sp.SetPosition(axnew3);
         Handle(Geom_SphericalSurface) aNewSphere = new Geom_SphericalSurface(sp);
         aNewSurface = aNewSphere;
         return Standard_True;
       }
+      else {
+        gp_Pnt PC = ax3.Location();
+        Standard_Real Vpar;
+        if(fabs(PI2-Vmax)>fabs(-PI2-Vmin))
+          Vpar = (PI2+Vmax)/2.;
+        else
+          Vpar = (-PI2+Vmin)/2.;
+        Standard_Real Upar = (Umin+Umax)/2.;;
+        gp_Pnt PN,PX;
+        S->D0(Upar,Vpar,PN);
+        S->D0(Upar+PI2,0.,PX);
+        gp_Dir newNorm(gp_Vec(PC,PN));
+        gp_Dir newDirX(gp_Vec(PC,PX));
+        gp_Ax3 axnew3(ax3.Axis().Location(), newNorm, newDirX);
+        sp.SetPosition(axnew3);
+        Handle(Geom_SphericalSurface) aNewSphere = new Geom_SphericalSurface(sp);
+        aNewSurface = aNewSphere;
+        return Standard_True;
+      }
     }
   }
   return Standard_False;
@@ -221,4 +259,3 @@ GeomAbs_Shape BlockFix_SphereSpaceModifier::Continuity(const TopoDS_Edge& E,cons
 {
   return BRep_Tool::Continuity(E,F1,F2);
 }
-