]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/GEOMImpl/GEOMImpl_TranslateDriver.cxx
Salome HOME
Merge branch 'master' of https://git.salome-platform.org/git/modules/geom
[modules/geom.git] / src / GEOMImpl / GEOMImpl_TranslateDriver.cxx
index ad967865bd9c016b4aaba7fd45c6adc7a3bf8f1b..cb67a9ec09b3943309f4f968cd7da4059d66ff04 100644 (file)
@@ -1,14 +1,16 @@
-// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// Copyright (C) 2007-2014  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
 //
 // 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
+// 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
+// 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
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#include <Standard_Stream.hxx>
-
 #include <GEOMImpl_TranslateDriver.hxx>
 #include <GEOMImpl_ITranslate.hxx>
 #include <GEOMImpl_Types.hxx>
 #include <GEOM_Function.hxx>
-#include <gp_Trsf.hxx>
-#include <gp_Pnt.hxx>
-#include <gp_Vec.hxx>
-#include <BRepBuilderAPI_Transform.hxx>
+#include <GEOMUtils.hxx>
+
+#include <BRep_Tool.hxx>
 #include <BRep_Builder.hxx>
+
 #include <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS_Compound.hxx>
 #include <TopAbs.hxx>
 #include <TopExp.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS_Edge.hxx>
-#include <BRep_Tool.hxx>
+
+#include <gp_Trsf.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Vec.hxx>
 
 //=======================================================================
 //function : GetID
@@ -70,7 +71,7 @@ Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const
 
   if (aFunction.IsNull()) return 0;
 
-  GEOMImpl_ITranslate TI(aFunction);
+  GEOMImpl_ITranslate TI (aFunction);
   gp_Trsf aTrsf;
   gp_Pnt aP1, aP2;
   Standard_Integer aType = aFunction->GetType();
@@ -122,6 +123,26 @@ Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const
     TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
     aShape = anOriginal.Located(aLocRes);
   }
+  else if (aType == TRANSLATE_VECTOR_DISTANCE) {
+    Handle(GEOM_Function) aVector = TI.GetVector();
+    double aDistance = TI.GetDistance();
+    if(aVector.IsNull()) return 0;
+    TopoDS_Shape aV = aVector->GetValue();
+    if(aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) return 0;
+    TopoDS_Edge anEdge = TopoDS::Edge(aV);
+
+    aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
+    aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
+
+    gp_Vec aVec (aP1, aP2);
+    aVec.Normalize();
+    aTrsf.SetTranslation(aVec * aDistance);
+
+    TopLoc_Location aLocOrig = anOriginal.Location();
+    gp_Trsf aTrsfOrig = aLocOrig.Transformation();
+    TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
+    aShape = anOriginal.Located(aLocRes);
+  }
   else if (aType == TRANSLATE_XYZ || aType == TRANSLATE_XYZ_COPY) {
     gp_Vec aVec (TI.GetDX(), TI.GetDY(), TI.GetDZ());
     aTrsf.SetTranslation(aVec);
@@ -143,13 +164,11 @@ Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const
     B.MakeCompound( aCompound );
 
     Handle(GEOM_Function) aVector = TI.GetVector();
-    if(aVector.IsNull()) return 0;
-    TopoDS_Shape aV = aVector->GetValue();
-    if(aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) return 0;
-    TopoDS_Edge anEdge = TopoDS::Edge(aV);
-
-    gp_Vec Vec(BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)), BRep_Tool::Pnt(TopExp::LastVertex(anEdge)));
-    Vec.Normalize();
+    gp_Vec Vec = gp::DX();
+    if (!aVector.IsNull()) {
+      Vec = GEOMUtils::GetVector( aVector->GetValue(), Standard_False );
+      Vec.Normalize();
+    }
 
     TopLoc_Location aLocOrig = anOriginal.Location();
     gp_Trsf aTrsfOrig = aLocOrig.Transformation();
@@ -171,32 +190,30 @@ Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const
   }
   else if (aType == TRANSLATE_2D) {
     Standard_Integer nbtimes1 = TI.GetNbIter1(), nbtimes2 = TI.GetNbIter2();
-    Standard_Real DX, DY, DZ,  step1 = TI.GetStep1(),  step2 = TI.GetStep2();
-    gp_Vec aVec;
+    Standard_Real DX, DY, DZ, step1 = TI.GetStep1(), step2 = TI.GetStep2();
     Handle(GEOM_Function) aVector = TI.GetVector();
-    if(aVector.IsNull()) return 0;
-    TopoDS_Shape aV = aVector->GetValue();
-    if(aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) return 0;
-    TopoDS_Edge anEdge = TopoDS::Edge(aV);
+    Handle(GEOM_Function) aVector2 = TI.GetVector2();
 
-    gp_Vec Vec1(BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)), BRep_Tool::Pnt(TopExp::LastVertex(anEdge)));
-    Vec1.Normalize();
+    gp_Vec Vec1 = gp::DX();
+    gp_Vec Vec2 = gp::DY();
 
-    Handle(GEOM_Function) aVector2 = TI.GetVector2();
-    if(aVector2.IsNull()) return 0;
-    aV = aVector2->GetValue();
-    if(aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) return 0;
-    anEdge = TopoDS::Edge(aV);
+    if (!aVector.IsNull()) {
+      Vec1 = GEOMUtils::GetVector( aVector->GetValue(), Standard_False );
+      Vec1.Normalize();
+    }
 
-    gp_Vec Vec2(BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)), BRep_Tool::Pnt(TopExp::LastVertex(anEdge)));
-    Vec2.Normalize();
+    if (!aVector2.IsNull()) {
+      Vec2 = GEOMUtils::GetVector( aVector2->GetValue(), Standard_False );
+      Vec2.Normalize();
+    }
 
     TopoDS_Compound aCompound;
     BRep_Builder B;
-    B.MakeCompound( aCompound );
+    B.MakeCompound(aCompound);
 
     TopLoc_Location aLocOrig = anOriginal.Location();
     gp_Trsf aTrsfOrig = aLocOrig.Transformation();
+    gp_Vec aVec;
 
     for (int i = 0; i < nbtimes1; i++) {
       for (int j = 0; j < nbtimes2; j++) {
@@ -213,13 +230,15 @@ Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const
         B.Add(aCompound, anOriginal.Located(aLocRes));
       }
     }
-   aShape = aCompound;
+    aShape = aCompound;
   }
   else return 0;
 
-
   if (aShape.IsNull()) return 0;
 
+  if ( !GEOMUtils::CheckShape(aShape, true) && !GEOMUtils::FixShapeTolerance(aShape) )
+    Standard_ConstructionError::Raise("Scaling aborted : algorithm has produced an invalid shape result");
+
   aFunction->SetValue(aShape);
 
   log.SetTouched(Label());
@@ -227,44 +246,73 @@ Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const
   return 1;
 }
 
+//================================================================================
+/*!
+ * \brief Returns a name of creation operation and names and values of creation parameters
+ */
+//================================================================================
 
-//=======================================================================
-//function :  GEOMImpl_TranslateDriver_Type_
-//purpose  :
-//=======================================================================
-Standard_EXPORT Handle_Standard_Type& GEOMImpl_TranslateDriver_Type_()
+bool GEOMImpl_TranslateDriver::
+GetCreationInformation(std::string&             theOperationName,
+                       std::vector<GEOM_Param>& theParams)
 {
-
-  static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
-  if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
-  static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
-  if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
-  static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
-  if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
-
-  static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
-  static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_TranslateDriver",
-                                                        sizeof(GEOMImpl_TranslateDriver),
-                                                        1,
-                                                        (Standard_Address)_Ancestors,
-                                                        (Standard_Address)NULL);
-
-  return _aType;
-}
-
-//=======================================================================
-//function : DownCast
-//purpose  :
-//=======================================================================
-const Handle(GEOMImpl_TranslateDriver) Handle(GEOMImpl_TranslateDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
-{
-  Handle(GEOMImpl_TranslateDriver) _anOtherObject;
-
-  if (!AnObject.IsNull()) {
-     if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_TranslateDriver))) {
-       _anOtherObject = Handle(GEOMImpl_TranslateDriver)((Handle(GEOMImpl_TranslateDriver)&)AnObject);
-     }
+  if (Label().IsNull()) return 0;
+  Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
+
+  GEOMImpl_ITranslate aCI( function );
+  Standard_Integer aType = function->GetType();
+
+  switch ( aType ) {
+  case TRANSLATE_TWO_POINTS:
+  case TRANSLATE_TWO_POINTS_COPY:
+    theOperationName = "TRANSLATION";
+    AddParam( theParams, "Object", aCI.GetOriginal() );
+    AddParam( theParams, "Point 1", aCI.GetPoint1() );
+    AddParam( theParams, "Point 2", aCI.GetPoint2() );
+    break;
+  case TRANSLATE_VECTOR:
+  case TRANSLATE_VECTOR_COPY:
+    theOperationName = "TRANSLATION";
+    AddParam( theParams, "Object", aCI.GetOriginal() );
+    AddParam( theParams, "Vector", aCI.GetVector() );
+    break;
+  case TRANSLATE_VECTOR_DISTANCE:
+    theOperationName = "TRANSLATION";
+    AddParam( theParams, "Object", aCI.GetOriginal() );
+    AddParam( theParams, "Vector", aCI.GetVector() );
+    AddParam( theParams, "Distance", aCI.GetDistance() );
+    break;
+  case TRANSLATE_XYZ:
+  case TRANSLATE_XYZ_COPY:
+    theOperationName = "TRANSLATION";
+    AddParam( theParams, "Object", aCI.GetOriginal() );
+    AddParam( theParams, "Dx", aCI.GetDX() );
+    AddParam( theParams, "Dy", aCI.GetDY() );
+    AddParam( theParams, "Dz", aCI.GetDZ() );
+    break;
+  case TRANSLATE_1D:
+    theOperationName = "MUL_TRANSLATION";
+    AddParam( theParams, "Main Object", aCI.GetOriginal() );
+    AddParam( theParams, "Vector", aCI.GetVector(), "DX" );
+    AddParam( theParams, "Step", aCI.GetStep1() );
+    AddParam( theParams, "Nb. Times", aCI.GetNbIter1() );
+    break;
+  case TRANSLATE_2D:
+    theOperationName = "MUL_TRANSLATION";
+    AddParam( theParams, "Main Object", aCI.GetOriginal() );
+    AddParam( theParams, "Vector U", aCI.GetVector(), "DX" );
+    AddParam( theParams, "Vector V", aCI.GetVector2(), "DY" );
+    AddParam( theParams, "Step U", aCI.GetStep1() );
+    AddParam( theParams, "Nb. Times U", aCI.GetNbIter1() );
+    AddParam( theParams, "Step V", aCI.GetStep2() );
+    AddParam( theParams, "Nb. Times V", aCI.GetNbIter2() );
+    break;
+  default:
+    return false;
   }
 
-  return _anOtherObject;
+  return true;
 }
+
+IMPLEMENT_STANDARD_HANDLE (GEOMImpl_TranslateDriver,GEOM_BaseDriver);
+IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_TranslateDriver,GEOM_BaseDriver);