Salome HOME
Mantis issue 0020998: EDF 1572 GEOM: Some limitations to the PipeTShape.
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ITransformOperations.cxx
index 9bf0da1bfd9e0194c80496d62ed93db602f76151..42ab3f44fd3d07f68be91a2b5279a34f585cab95 100644 (file)
@@ -1,22 +1,25 @@
-// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-// 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.
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-// 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.
+//  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.
 //
-// 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
+//  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.
 //
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  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 <Standard_Stream.hxx>
 
 #include <GEOMImpl_ITransformOperations.hxx>
@@ -178,7 +181,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZ
   }
 
   //Make a Python command
-  GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.TranslateDXDYDZ("
+  GEOM::TPythonDump(aFunction) << "geompy.TranslateDXDYDZ("
     << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
 
   SetErrorCode(OK);
@@ -350,7 +353,6 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVector
   SetErrorCode(OK);
   return theObject;
 }
-
 //=============================================================================
 /*!
  *  TranslateVectorCopy
@@ -405,6 +407,73 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorCopy
   return aCopy;
 }
 
+//=============================================================================
+/*!
+ *  TranslateVectorDistance
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorDistance
+       (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector, double theDistance, bool theCopy)
+{
+  SetErrorCode(KO);
+
+  if (theObject.IsNull() || theVector.IsNull()) return NULL;
+
+  Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
+  if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
+
+  Handle(GEOM_Object) aCopy;   //Add a new Copy object
+  Handle(GEOM_Function) aFunction;
+
+  //Add a translate function
+  if (theCopy) {
+    aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+    aFunction = aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_DISTANCE);
+  }
+  else {
+    aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_DISTANCE);
+  }
+  if (aFunction.IsNull()) return NULL;
+
+  //Check if the function is set correctly
+  if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
+
+  GEOMImpl_ITranslate aTI(aFunction);
+  aTI.SetVector(theVector->GetLastFunction());
+  aTI.SetDistance(theDistance);
+//  aTI.SetShape(theObject->GetValue());
+  aTI.SetOriginal(aLastFunction);
+
+  //Compute the translation
+  try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
+    if (!GetSolver()->ComputeFunction(aFunction)) {
+      SetErrorCode("Translation driver failed");
+      return NULL;
+    }
+  }
+  catch (Standard_Failure) {
+    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+    SetErrorCode(aFail->GetMessageString());
+    return NULL;
+  }
+
+  //Make a Python command
+  if (theCopy) {
+    GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationVectorDistance("
+                                 << theObject << ", " << theVector << ", " << theDistance << ")";
+    SetErrorCode(OK);
+    return aCopy;
+  }
+
+  GEOM::TPythonDump(aFunction) << "geompy.TranslateVectorDistance("
+                               << theObject << ", " << theVector << ", " << theDistance << ", " << theCopy << ")";
+  SetErrorCode(OK);
+  return theObject;
+}
+
 //=============================================================================
 /*!
  *  Translate1D
@@ -467,12 +536,12 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate1D
  */
 //=============================================================================
 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate2D (Handle(GEOM_Object) theObject,
-                                                               Handle(GEOM_Object) theVector,
-                                                               double theStep1,
-                                                               Standard_Integer theNbTimes1,
-                                                               Handle(GEOM_Object) theVector2,
-                                                               double theStep2,
-                                                               Standard_Integer theNbTimes2)
+                                                                Handle(GEOM_Object) theVector,
+                                                                double theStep1,
+                                                                Standard_Integer theNbTimes1,
+                                                                Handle(GEOM_Object) theVector2,
+                                                                double theStep2,
+                                                                Standard_Integer theNbTimes2)
 {
   SetErrorCode(KO);
 
@@ -964,14 +1033,11 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShape
 {
   SetErrorCode(KO);
 
-  if (theObject.IsNull() || thePoint.IsNull()) return NULL;
+  if (theObject.IsNull()) return NULL;
 
   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
 
-  // Get last functions of the arguments
-  Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
-
   //Add a scale function
   Handle(GEOM_Function) aFunction =
     theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE);
@@ -980,11 +1046,17 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShape
   //Check if the function is set correctly
   if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
 
+  // Set arguments
   GEOMImpl_IScale aTI (aFunction);
   aTI.SetShape(anOriginal);
-  aTI.SetPoint(aPF);
   aTI.SetFactor(theFactor);
 
+  // Set point argument
+  if (!thePoint.IsNull()) {
+    Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
+    aTI.SetPoint(aPF);
+  }
+
   //Compute the scale
   try {
 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
@@ -1019,7 +1091,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeCopy
 {
   SetErrorCode(KO);
 
-  if (theObject.IsNull() || thePoint.IsNull()) return NULL;
+  if (theObject.IsNull()) return NULL;
 
   Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
   if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
@@ -1035,11 +1107,17 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeCopy
   //Check if the function is set correctly
   if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
 
+  // Set arguments
   GEOMImpl_IScale aTI (aFunction);
   aTI.SetShape(anOriginal);
-  aTI.SetPoint(thePoint->GetLastFunction());
   aTI.SetFactor(theFactor);
 
+  // Set point argument
+  if (!thePoint.IsNull()) {
+    Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
+    aTI.SetPoint(aPF);
+  }
+
   //Compute the scale
   try {
 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
@@ -1064,6 +1142,85 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeCopy
   return aCopy;
 }
 
+//=============================================================================
+/*!
+ *  ScaleShapeAlongAxes
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeAlongAxes (Handle(GEOM_Object) theObject,
+                                                                        Handle(GEOM_Object) thePoint,
+                                                                        double theFactorX,
+                                                                        double theFactorY,
+                                                                        double theFactorZ,
+                                                                        bool   doCopy)
+{
+  SetErrorCode(KO);
+
+  if (theObject.IsNull()) return NULL;
+
+  Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
+  if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
+
+  //Add a scale function
+  Handle(GEOM_Object) aCopy;   //Add a new Copy object
+  Handle(GEOM_Function) aFunction;
+  if (doCopy) {
+    aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+    aFunction = aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES_COPY);
+  }
+  else {
+    aFunction = theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES);
+  }
+  if (aFunction.IsNull()) return NULL;
+
+  //Check if the function is set correctly
+  if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
+
+  // Set arguments
+  GEOMImpl_IScale aTI (aFunction);
+  aTI.SetShape(anOriginal);
+  aTI.SetFactorX(theFactorX);
+  aTI.SetFactorY(theFactorY);
+  aTI.SetFactorZ(theFactorZ);
+
+  // Set point (optional argument)
+  if (!thePoint.IsNull()) {
+    Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
+    aTI.SetPoint(aPF);
+  }
+
+  //Compute the scale
+  try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
+    if (!GetSolver()->ComputeFunction(aFunction)) {
+      SetErrorCode("Scale driver failed");
+      return NULL;
+    }
+  }
+  catch (Standard_Failure) {
+    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+    SetErrorCode(aFail->GetMessageString());
+    return NULL;
+  }
+
+  SetErrorCode(OK);
+
+  //Make a Python command
+  if (doCopy) {
+    GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeScaleAlongAxes("
+                                 << theObject << ", " << thePoint << ", "
+                                 << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")";
+    return aCopy;
+  }
+
+  GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.ScaleShapeAlongAxes("
+                               << theObject << ", " << thePoint << ", "
+                               << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")";
+  return theObject;
+}
+
 //=============================================================================
 /*!
  *  PositionShape
@@ -1095,7 +1252,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShape
   aTI.SetShape(anOriginal);
   aTI.SetEndLCS(theEndLCS->GetLastFunction());
   if (!theStartLCS.IsNull())
-    aTI.SetStartLCS(theStartLCS->GetLastFunction());
+    aTI.SetStartLCS(theObject == theStartLCS ? anOriginal : theStartLCS->GetLastFunction());
 
   //Compute the Position
   try {
@@ -1180,6 +1337,75 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShapeCopy
   return aCopy;
 }
 
+//=============================================================================
+/*!
+ *  PositionAlongPath
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionAlongPath
+       (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePath, 
+        double theDistance, bool theCopy, bool theReverse)
+{
+  SetErrorCode(KO);
+
+  if (theObject.IsNull() || thePath.IsNull()) return NULL;
+
+  Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
+  if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
+
+  //Add a position function
+  Handle(GEOM_Function) aFunction;
+  Handle(GEOM_Object) aCopy;
+
+  if (theCopy) {
+    aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+    aFunction = aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
+  }
+  else
+    aFunction = theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
+
+  if (aFunction.IsNull()) return NULL;
+
+  //Check if the function is set correctly
+  if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
+
+  GEOMImpl_IPosition aTI (aFunction);
+  aTI.SetShape(anOriginal);
+  aTI.SetPath(thePath->GetLastFunction());
+  aTI.SetDistance(theDistance);
+  aTI.SetReverse(theReverse);
+
+  //Compute the position
+  try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
+    if (!GetSolver()->ComputeFunction(aFunction)) {
+      SetErrorCode("Position driver failed");
+      return NULL;
+    }
+  }
+  catch (Standard_Failure) {
+    Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+    SetErrorCode(aFail->GetMessageString());
+    return NULL;
+  }
+
+  //Make a Python command
+  if (theCopy) {
+    GEOM::TPythonDump(aFunction) << aCopy << " = geompy.PositionAlongPath("
+                                 << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
+    SetErrorCode(OK);
+    return aCopy;
+  }
+
+  GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.PositionAlongPath("
+    << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
+
+  SetErrorCode(OK);
+  return theObject;
+}
+
 //=============================================================================
 /*!
  *  Rotate
@@ -1229,7 +1455,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate (Handle(GEOM_Object) t
   }
 
   //Make a Python command
-  GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.Rotate(" << theObject
+  GEOM::TPythonDump(aFunction) << "geompy.Rotate(" << theObject
     << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
 
   SetErrorCode(OK);
@@ -1350,11 +1576,11 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate1D (Handle(GEOM_Object)
  */
 //=============================================================================
 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate2D (Handle(GEOM_Object) theObject,
-                                                            Handle(GEOM_Object) theAxis,
-                                                            double theAngle,
-                                                            Standard_Integer theNbTimes1,
-                                                            double theStep,
-                                                            Standard_Integer theNbTimes2)
+                                                             Handle(GEOM_Object) theAxis,
+                                                             double theAngle,
+                                                             Standard_Integer theNbTimes1,
+                                                             double theStep,
+                                                             Standard_Integer theNbTimes2)
 {
   SetErrorCode(KO);
 
@@ -1412,9 +1638,9 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate2D (Handle(GEOM_Object)
  */
 //=============================================================================
 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePoints (Handle(GEOM_Object) theObject,
-                                                                     Handle(GEOM_Object) theCentPoint, 
-                                                                     Handle(GEOM_Object) thePoint1,
-                                                                     Handle(GEOM_Object) thePoint2)
+                                                                      Handle(GEOM_Object) theCentPoint, 
+                                                                      Handle(GEOM_Object) thePoint1,
+                                                                      Handle(GEOM_Object) thePoint2)
 {
   SetErrorCode(KO);
 
@@ -1461,7 +1687,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePoints (Handle(GEO
 
   //Make a Python command
   GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.RotateThreePoints(" << theObject
-                              << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
+                               << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
 
   SetErrorCode(OK);
   return theObject;
@@ -1473,9 +1699,9 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePoints (Handle(GEO
  */
 //=============================================================================
 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePointsCopy (Handle(GEOM_Object) theObject, 
-                                                        Handle(GEOM_Object) theCentPoint, 
-                                                        Handle(GEOM_Object) thePoint1,
-                                                        Handle(GEOM_Object) thePoint2)
+                                                         Handle(GEOM_Object) theCentPoint, 
+                                                         Handle(GEOM_Object) thePoint1,
+                                                         Handle(GEOM_Object) thePoint2)
 {
   SetErrorCode(KO);
 
@@ -1518,7 +1744,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePointsCopy (Handle
 
   //Make a Python command
   GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotationThreePoints(" << theObject
-                              << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
+                               << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
 
   SetErrorCode(OK);
   return aCopy;