Salome HOME
Copyright update 2020
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Symmetry.cpp
index f5baf287d1ecfa6022197313eba7c13d6db7d924..b7144ddee302bb837c94ef9d6526bf6ac5996ab5 100644 (file)
-// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
-
-// File:        GeomAlgoAPI_Symmetry.cpp
-// Created:     30 Nov 2016
-// Author:      Clarisse Genrault (CEA)
-
-#include "GeomAlgoAPI_Symmetry.h"
-
-#include <BRepBuilderAPI_Transform.hxx>
+// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+//
+// 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, 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
+// 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
+//
+
+#include <GeomAlgoAPI_Symmetry.h>
+
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Ax1.h>
+#include <GeomAPI_Ax2.h>
 
 //=================================================================================================
 GeomAlgoAPI_Symmetry::GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
                                            std::shared_ptr<GeomAPI_Pnt>   thePoint)
 {
-  myMethodType = BY_POINT;
-  mySourceShape = theSourceShape;
-  myPoint = thePoint;
+  if (!thePoint) {
+    myError = "Symmetry builder :: point is not valid.";
+    return;
+  }
+
+  GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+  aTrsf->setSymmetry(thePoint);
+
+  build(theSourceShape, aTrsf);
 }
 
 //=================================================================================================
 GeomAlgoAPI_Symmetry::GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
                                            std::shared_ptr<GeomAPI_Ax1>   theAxis)
 {
-  myMethodType = BY_AXIS;
-  mySourceShape = theSourceShape;
-  myAxis = theAxis;
-}
+  if (!theAxis) {
+    myError = "Symmetry builder :: axis is not valid.";
+    return;
+  }
 
-//=================================================================================================
-GeomAlgoAPI_Symmetry::GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
-                                           std::shared_ptr<GeomAPI_Ax2>   thePlane)
-{
-  myMethodType = BY_PLANE;
-  mySourceShape = theSourceShape;
-  myPlane = thePlane;
-}
+  GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+  aTrsf->setSymmetry(theAxis);
 
-//=================================================================================================
-bool GeomAlgoAPI_Symmetry::check()
-{
-  switch (myMethodType) {
-    case BY_POINT: {
-      if (!myPoint) {
-        myError = "Symmetry builder :: point is invalid.";
-        return false;
-      }
-      if (!mySourceShape) {
-        myError = "Symmetry builder :: source shape is invalid.";
-        return false;
-      }
-      return true;
-    }
-    case BY_AXIS: {
-      if (!myAxis) {
-        myError = "Symmetry builder :: axis is invalid.";
-        return false;
-      }
-      if (!mySourceShape) {
-        myError = "Symmetry builder :: source shape is invalid.";
-        return false;
-      }
-      return true;
-    }
-    case BY_PLANE: {
-      if (!myPlane) {
-        myError = "Symmetry builder :: plane is invalid.";
-        return false;
-      }
-      if (!mySourceShape) {
-        myError = "Symmetry builder :: source shape is invalid.";
-        return false;
-      }
-      return true;
-    }
-    default: {
-      myError = "Symmetry builder :: method not implemented.";
-      return false;
-    }
-  }
+  build(theSourceShape, aTrsf);
 }
 
 //=================================================================================================
-void GeomAlgoAPI_Symmetry::build()
+GeomAlgoAPI_Symmetry::GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
+                                           std::shared_ptr<GeomAPI_Ax2>   thePlane)
 {
-  gp_Trsf* aTrsf = new gp_Trsf();
-
-  switch (myMethodType) {
-    case BY_POINT: {
-      const gp_Pnt& aPoint = myPoint->impl<gp_Pnt>();
-      aTrsf->SetMirror(aPoint);
-      break;
-    }
-    case BY_AXIS: {
-      const gp_Ax1& anAxis = myAxis->impl<gp_Ax1>();
-      aTrsf->SetMirror(anAxis);
-      break;
-    }
-    case BY_PLANE: {
-      const gp_Ax2& aPlane = myPlane->impl<gp_Ax2>();
-      aTrsf->SetMirror(aPlane);
-      break;
-    }
-    default: {
-      myError = "Symmetry builder :: method not supported";
-      return;
-    }
-  }
-
-  const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
-
-  if(aSourceShape.IsNull()) {
-    myError = "Symmetry builder :: source shape does not contain any actual shape.";
+  if (!thePlane) {
+    myError = "Symmetry builder :: plane is not valid.";
     return;
   }
 
-  // Transform the shape while copying it.
-  BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
-  if(!aBuilder) {
-    myError = "Symmetry builder :: transform initialization failed.";
-    return;
-  }
-
-  setImpl(aBuilder);
-  setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
-
-  if(!aBuilder->IsDone()) {
-    myError = "Symmetry builder :: algorithm failed.";
-    return;
-  }
+  GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+  aTrsf->setSymmetry(thePlane);
 
-  TopoDS_Shape aResult = aBuilder->Shape();
-
-  std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
-  aShape->setImpl(new TopoDS_Shape(aResult));
-  setShape(aShape);
-  setDone(true);
-}
\ No newline at end of file
+  build(theSourceShape, aTrsf);
+}