-using namespace std;
-
-#include "GEOMImpl_ITransformOperations.hxx"
+// Copyright (C) 2007-2022 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, 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 <Standard_Stream.hxx>
+
+#include <GEOMImpl_ITransformOperations.hxx>
+
+#include <GEOMImpl_TranslateDriver.hxx>
+#include <GEOMImpl_MirrorDriver.hxx>
+#include <GEOMImpl_ProjectionDriver.hxx>
+#include <GEOMImpl_OffsetDriver.hxx>
+#include <GEOMImpl_ScaleDriver.hxx>
+#include <GEOMImpl_RotateDriver.hxx>
+#include <GEOMImpl_PositionDriver.hxx>
+
+#include <GEOMImpl_ITranslate.hxx>
+#include <GEOMImpl_IMirror.hxx>
+#include <GEOMImpl_IProjection.hxx>
+#include <GEOMImpl_IProjOnCyl.hxx>
+#include <GEOMImpl_IOffset.hxx>
+#include <GEOMImpl_IScale.hxx>
+#include <GEOMImpl_IRotate.hxx>
+#include <GEOMImpl_IPosition.hxx>
+
+#include <GEOMImpl_Types.hxx>
+
+#include <GEOM_Function.hxx>
+#include <GEOM_PythonDump.hxx>
#include "utilities.h"
-#include "OpUtil.hxx"
-#include "Utils_ExceptHandlers.hxx"
+#include <Utils_ExceptHandlers.hxx>
#include <TFunction_DriverTable.hxx>
#include <TFunction_Driver.hxx>
-#include <TFunction_Logbook.hxx>
#include <TDF_Tool.hxx>
-#include "GEOM_Function.hxx"
-
-#include "GEOMImpl_TranslateDriver.hxx"
-#include "GEOMImpl_MirrorDriver.hxx"
-#include "GEOMImpl_OffsetDriver.hxx"
-#include "GEOMImpl_ScaleDriver.hxx"
-#include "GEOMImpl_RotateDriver.hxx"
-#include "GEOMImpl_PositionDriver.hxx"
-
-#include "GEOMImpl_ITranslate.hxx"
-#include "GEOMImpl_IMirror.hxx"
-#include "GEOMImpl_IOffset.hxx"
-#include "GEOMImpl_IScale.hxx"
-#include "GEOMImpl_IRotate.hxx"
-#include "GEOMImpl_IPosition.hxx"
-
-#include "GEOMImpl_Types.hxx"
-
+#include <BRep_Tool.hxx>
+#include <BRep_Builder.hxx>
+#include <TopExp.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS_Compound.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Vec.hxx>
+#include <gp_Trsf.hxx>
+
+#include <StdFail_NotDone.hxx>
+#include <Standard_Failure.hxx>
#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
//=============================================================================
*/
//=============================================================================
-GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations (GEOM_Engine* theEngine, int theDocID)
-: GEOM_IOperations(theEngine, theDocID)
+GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations (GEOM_Engine* theEngine)
+: GEOM_IOperations(theEngine)
{
MESSAGE("GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations");
}
//Compute the translation
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Translation driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.TranslateTwoPoints(");
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(thePoint1->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(thePoint2->GetEntry(), anEntry);
- aDescr += (anEntry+")");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << "geompy.TranslateTwoPoints("
+ << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
SetErrorCode(OK);
return theObject;
//Compute the translation
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Translation driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.TranslateDXDXYDZ(");
- aDescr += (anEntry+", ");
- aDescr += (TCollection_AsciiString(theX)+", ");
- aDescr += (TCollection_AsciiString(theY)+", ");
- aDescr += (TCollection_AsciiString(theZ)+")");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << "geompy.TranslateDXDYDZ("
+ << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
SetErrorCode(OK);
return theObject;
if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
//Add a new Copy object
- Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GEOM_COPY);
//Add a translate function
Handle(GEOM_Function) aFunction =
//Compute the translation
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Translation driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(aCopy->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.TranslateTwoPointsCopy(");
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(thePoint1->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(thePoint2->GetEntry(), anEntry);
- aDescr += (anEntry+")");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationTwoPoints("
+ << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
SetErrorCode(OK);
return aCopy;
if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
//Add a new Copy object
- Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GEOM_COPY);
//Add a translate function
Handle(GEOM_Function) aFunction =
//Compute the translation
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Translation driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(aCopy->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.TranslateDXDXYDZCopy(");
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- aDescr += (TCollection_AsciiString(theX)+", ");
- aDescr += (TCollection_AsciiString(theY)+", ");
- aDescr += (TCollection_AsciiString(theZ)+")");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslation("
+ << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
SetErrorCode(OK);
return aCopy;
//Compute the translation
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Translation driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.TranslateVector(");
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(theVector->GetEntry(), anEntry);
- aDescr += (anEntry+") ");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << "geompy.TranslateVector("
+ << theObject << ", " << theVector << ")";
SetErrorCode(OK);
return theObject;
}
-
//=============================================================================
/*!
* TranslateVectorCopy
if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
//Add a new Copy object
- Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GEOM_COPY);
//Add a translate function
Handle(GEOM_Function) aFunction =
//Compute the translation
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Translation driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(aCopy->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.TranslateVectorCopy(");
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(theVector->GetEntry(), anEntry);
- aDescr += (anEntry+")");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationVector("
+ << theObject << ", " << theVector << ")";
SetErrorCode(OK);
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(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 {
+ OCC_CATCH_SIGNALS;
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("Translation driver failed");
+ return NULL;
+ }
+ }
+ catch (Standard_Failure& aFail) {
+ 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
{
SetErrorCode(KO);
- if (theObject.IsNull() || theVector.IsNull()) return NULL;
+ if (theObject.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
//Add a new Copy object
- Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(theObject->GetType());
//Add a translate function
Handle(GEOM_Function) aFunction =
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
- GEOMImpl_ITranslate aTI(aFunction);
- aTI.SetVector(theVector->GetLastFunction());
+ GEOMImpl_ITranslate aTI (aFunction);
aTI.SetOriginal(aLastFunction);
+ if (!theVector.IsNull())
+ aTI.SetVector(theVector->GetLastFunction());
aTI.SetStep1(theStep);
aTI.SetNbIter1(theNbTimes);
//Compute the translation
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Translation driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(aCopy->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.Translate1D(");
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(theVector->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- aDescr += (TCollection_AsciiString(theStep)+", ");
- aDescr += (TCollection_AsciiString(theNbTimes)+") ");
-
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMultiTranslation1D("
+ << theObject << ", " << theVector << ", " << theStep << ", " << theNbTimes << ")";
SetErrorCode(OK);
return aCopy;
*/
//=============================================================================
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);
- if (theObject.IsNull() || theVector.IsNull() || theVector2.IsNull()) return NULL;
+ if (theObject.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
//Add a new Copy object
- Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(theObject->GetType());
//Add a translate function
Handle(GEOM_Function) aFunction =
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
- GEOMImpl_ITranslate aTI(aFunction);
- aTI.SetVector(theVector->GetLastFunction());
- aTI.SetVector2(theVector2->GetLastFunction());
+ GEOMImpl_ITranslate aTI (aFunction);
aTI.SetOriginal(aLastFunction);
+ if (!theVector.IsNull())
+ aTI.SetVector(theVector->GetLastFunction());
aTI.SetStep1(theStep1);
aTI.SetNbIter1(theNbTimes1);
+ if (!theVector2.IsNull())
+ aTI.SetVector2(theVector2->GetLastFunction());
aTI.SetStep2(theStep2);
aTI.SetNbIter2(theNbTimes2);
//Compute the translation
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Translation driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(aCopy->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.Translate2D(");
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(theVector->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- aDescr += (TCollection_AsciiString(theStep1)+", ");
- aDescr += (TCollection_AsciiString(theNbTimes2)+", ");
- TDF_Tool::Entry(theVector2->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- aDescr += (TCollection_AsciiString(theStep2)+", ");
- aDescr += (TCollection_AsciiString(theNbTimes2)+") ");
-
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMultiTranslation2D("
+ << theObject << ", " << theVector << ", " << theStep1 << ", " << theNbTimes1
+ << ", " << theVector2 << ", " << theStep2 << ", " << theNbTimes2 << ")";
SetErrorCode(OK);
return aCopy;
}
+//=============================================================================
+/*!
+ * TranslateShape1D
+ */
+//=============================================================================
+/*
+TopoDS_Shape GEOMImpl_ITransformOperations::TranslateShape1D (const TopoDS_Shape& theShape,
+ GEOMImpl_ITranslate* theTI)
+{
+ TopoDS_Shape aRes;
+
+ // Vector
+ Handle(GEOM_Function) aVector = theTI->GetVector();
+ if (aVector.IsNull()) {
+ StdFail_NotDone::Raise("Invalid object is given for vector argument");
+ }
+ TopoDS_Shape aV = aVector->GetValue();
+ if (aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) {
+ StdFail_NotDone::Raise("Invalid object is given for vector argument");
+ }
+ TopoDS_Edge anEdge = TopoDS::Edge(aV);
+
+ gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
+ gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
+ if (aP1.Distance(aP2) < gp::Resolution()) {
+ StdFail_NotDone::Raise("Invalid object is given for vector argument");
+ }
+
+ // Step and Nb.times
+ Standard_Real step = theTI->GetStep1();
+ Standard_Integer nbtimes = theTI->GetNbIter1();
+
+ // Make multi-translation
+ gp_Trsf aTrsf;
+ gp_Vec aVec;
+ TopoDS_Compound aCompound;
+ BRep_Builder B;
+ B.MakeCompound(aCompound);
+
+ gp_Vec Vec (aP1, aP2);
+ Vec.Normalize();
+
+ TopLoc_Location aLocOrig = theShape.Location();
+ gp_Trsf aTrsfOrig = aLocOrig.Transformation();
+
+ for (int i = 0; i < nbtimes; i++) {
+ aVec = Vec * (i * step);
+ aTrsf.SetTranslation(aVec);
+ //NPAL18620: performance problem: multiple locations are accumulated
+ // in shape and need a great time to process
+ //BRepBuilderAPI_Transform aTransformation(theShape, aTrsf, Standard_False);
+ //B.Add(aCompound, aTransformation.Shape());
+ TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
+ B.Add(aCompound, theShape.Located(aLocRes));
+ }
+ aRes = aCompound;
+
+ return aRes;
+}
+*/
+
+//=============================================================================
+/*!
+ * TranslateShape2D
+ */
+//=============================================================================
+/*
+TopoDS_Shape GEOMImpl_ITransformOperations::TranslateShape2D (const TopoDS_Shape& theShape,
+ GEOMImpl_ITranslate* theTI)
+{
+ TopoDS_Shape aRes;
+
+ // Vectors
+ Handle(GEOM_Function) aVector1 = theTI->GetVector();
+ Handle(GEOM_Function) aVector2 = theTI->GetVector2();
+
+ if (aVector1.IsNull() || aVector2.IsNull()) {
+ StdFail_NotDone::Raise("Invalid object is given for vector argument");
+ }
+
+ TopoDS_Shape aV1 = aVector1->GetValue();
+ TopoDS_Shape aV2 = aVector2->GetValue();
+
+ if (aV1.IsNull() || aV1.ShapeType() != TopAbs_EDGE ||
+ aV2.IsNull() || aV2.ShapeType() != TopAbs_EDGE) {
+ StdFail_NotDone::Raise("Invalid object is given for vector argument");
+ }
+
+ TopoDS_Edge anEdge1 = TopoDS::Edge(aV1);
+ TopoDS_Edge anEdge2 = TopoDS::Edge(aV2);
+
+ gp_Pnt aP11 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge1));
+ gp_Pnt aP12 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge1));
+ gp_Pnt aP21 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge2));
+ gp_Pnt aP22 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge2));
+
+ if (aP11.Distance(aP12) < gp::Resolution() ||
+ aP21.Distance(aP22) < gp::Resolution()) {
+ StdFail_NotDone::Raise("Invalid object is given for vector argument");
+ }
+
+ gp_Vec Vec1 (aP11, aP12);
+ gp_Vec Vec2 (aP21, aP22);
+
+ Vec1.Normalize();
+ Vec2.Normalize();
+
+ // Step and Nb.times
+ Standard_Real step1 = theTI->GetStep1(), step2 = theTI->GetStep2();
+ Standard_Integer nbtimes1 = theTI->GetNbIter1(), nbtimes2 = theTI->GetNbIter2();
+
+ // Make multi-translation
+ gp_Trsf aTrsf;
+ gp_Vec aVec;
+ Standard_Real DX, DY, DZ;
+ TopoDS_Compound aCompound;
+ BRep_Builder B;
+ B.MakeCompound(aCompound);
+
+ TopLoc_Location aLocOrig = theShape.Location();
+ gp_Trsf aTrsfOrig = aLocOrig.Transformation();
+
+ for (int i = 0; i < nbtimes1; i++) {
+ for (int j = 0; j < nbtimes2; j++) {
+ DX = i * step1 * Vec1.X() + j * step2 * Vec2.X();
+ DY = i * step1 * Vec1.Y() + j * step2 * Vec2.Y();
+ DZ = i * step1 * Vec1.Z() + j * step2 * Vec2.Z();
+ aVec.SetCoord(DX, DY, DZ);
+ aTrsf.SetTranslation(aVec);
+ //NPAL18620: performance problem: multiple locations are accumulated
+ // in shape and need a great time to process
+ //BRepBuilderAPI_Transform aBRepTransformation(theShape, aTrsf, Standard_False);
+ //B.Add(aCompound, aBRepTransformation.Shape());
+ TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
+ B.Add(aCompound, theShape.Located(aLocRes));
+ }
+ }
+ aRes = aCompound;
+
+ return aRes;
+}
+*/
//=============================================================================
/*!
//Compute the mirror
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Mirror driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry + " = ITransformOperations.MirrorPlane(");
- aDescr += (anEntry + ", ");
- TDF_Tool::Entry(thePlane->GetEntry(), anEntry);
- aDescr += (anEntry + ") ");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << "geompy.MirrorByPlane("
+ << theObject << ", " << thePlane << ")";
SetErrorCode(OK);
return theObject;
if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
//Add a new Copy object
- Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GEOM_COPY);
//Add a mirror function
Handle(GEOM_Function) aFunction =
//Compute the mirror
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Mirror driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(aCopy->GetEntry(), anEntry);
- aDescr += (anEntry + " = ITransformOperations.MirrorPlaneCopy(");
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry + ", ");
- TDF_Tool::Entry(thePlane->GetEntry(), anEntry);
- aDescr += (anEntry + ")");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByPlane("
+ << theObject << ", " << thePlane << ")";
SetErrorCode(OK);
return aCopy;
//Compute the mirror
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Mirror driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry + " = ITransformOperations.MirrorPoint(");
- aDescr += (anEntry + ", ");
- TDF_Tool::Entry(thePoint->GetEntry(), anEntry);
- aDescr += (anEntry + ") ");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << "geompy.MirrorByPoint("
+ << theObject << ", " << thePoint << ")";
SetErrorCode(OK);
return NULL;
if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
//Add a new Copy object
- Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GEOM_COPY);
//Add a mirror function
Handle(GEOM_Function) aFunction =
//Compute the mirror
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Mirror driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(aCopy->GetEntry(), anEntry);
- aDescr += (anEntry + " = ITransformOperations.MirrorPointCopy(");
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry + ", ");
- TDF_Tool::Entry(thePoint->GetEntry(), anEntry);
- aDescr += (anEntry + ")");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByPoint("
+ << theObject << ", " << thePoint << ")";
SetErrorCode(OK);
return aCopy;
//Compute the mirror
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Mirror driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry + " = ITransformOperations.MirrorAxis(");
- aDescr += (anEntry + ", ");
- TDF_Tool::Entry(theAxis->GetEntry(), anEntry);
- aDescr += (anEntry + ") ");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << "geompy.MirrorByAxis("
+ << theObject << ", " << theAxis << ")";
SetErrorCode(OK);
return NULL;
if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
//Add a new Copy object
- Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GEOM_COPY);
//Add a mirror function
Handle(GEOM_Function) aFunction =
//Compute the mirror
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Mirror driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(aCopy->GetEntry(), anEntry);
- aDescr += (anEntry + " = ITransformOperations.MirrorAxisCopy(");
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry + ", ");
- TDF_Tool::Entry(theAxis->GetEntry(), anEntry);
- aDescr += (anEntry + ")");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByAxis("
+ << theObject << ", " << theAxis << ")";
SetErrorCode(OK);
return aCopy;
* OffsetShape
*/
//=============================================================================
-Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShape
- (Handle(GEOM_Object) theObject, double theOffset)
+Handle(GEOM_Object)
+GEOMImpl_ITransformOperations::OffsetShape (Handle(GEOM_Object) theObject,
+ double theOffset,
+ bool theJoinByPipes)
{
SetErrorCode(KO);
if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
GEOMImpl_IOffset aTI (aFunction);
- aTI.SetShape(anOriginal);
- aTI.SetValue(theOffset);
+ aTI.SetShape( anOriginal );
+ aTI.SetValue( theOffset );
+ aTI.SetJoinByPipes( theJoinByPipes );
//Compute the offset
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Offset driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.OffsetShape(");
- aDescr += (anEntry+", ");
- aDescr += TCollection_AsciiString(theOffset)+")";
- aFunction->SetDescription(aDescr);
+ if (theJoinByPipes)
+ GEOM::TPythonDump(aFunction) << "geompy.Offset("
+ << theObject << ", " << theOffset << ")";
+ else
+ GEOM::TPythonDump(aFunction) << theObject << " = geompy.MakeOffsetIntersectionJoin("
+ << theObject << ", " << theOffset << ")";
SetErrorCode(OK);
return theObject;
* OffsetShapeCopy
*/
//=============================================================================
-Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShapeCopy
- (Handle(GEOM_Object) theObject, double theOffset)
+Handle(GEOM_Object)
+GEOMImpl_ITransformOperations::OffsetShapeCopy( Handle(GEOM_Object) theObject,
+ double theOffset,
+ bool theJoinByPipes)
{
SetErrorCode(KO);
if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
//Add a new Copy object
- Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GEOM_COPY);
//Add a new Offset function
Handle(GEOM_Function) aFunction =
if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
GEOMImpl_IOffset aTI (aFunction);
- aTI.SetShape(anOriginal);
- aTI.SetValue(theOffset);
+ aTI.SetShape( anOriginal );
+ aTI.SetValue( theOffset );
+ aTI.SetJoinByPipes( theJoinByPipes );
//Compute the offset
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Offset driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(aCopy->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.OffsetShapeCopy(");
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- aDescr += TCollection_AsciiString(theOffset)+")";
- aFunction->SetDescription(aDescr);
+ if (theJoinByPipes)
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeOffset("
+ << theObject << ", " << theOffset << ")";
+ else
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeOffsetIntersectionJoin("
+ << theObject << ", " << theOffset << ")";
SetErrorCode(OK);
return aCopy;
}
+//=============================================================================
+/*!
+ * ProjectShapeCopy
+ */
+//=============================================================================
+Handle(GEOM_Object)
+GEOMImpl_ITransformOperations::ProjectShapeCopy (Handle(GEOM_Object) theSource,
+ Handle(GEOM_Object) theTarget)
+{
+ SetErrorCode(KO);
+
+ if (theSource.IsNull() || theTarget.IsNull()) return NULL;
+
+ Handle(GEOM_Function) aLastFunction = theSource->GetLastFunction();
+ if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be projected
+
+ Handle(GEOM_Object) aCopy;
+
+ TopoDS_Shape aTarget = theTarget->GetValue();
+ if ( aTarget.IsNull() ) return NULL;
+ if ( aTarget.ShapeType() == TopAbs_EDGE ||
+ aTarget.ShapeType() == TopAbs_WIRE )
+ {
+ // a TPythonDump prevents dumping ProjectPointOnWire(),
+ // dump of MakeProjection() is done at the end of this function
+ GEOM::TPythonDump preventDump(aLastFunction, /*append=*/true);
+ Standard_Integer dummy;
+ ProjectPointOnWire( theSource, theTarget, aCopy, dummy );
+ if ( aCopy.IsNull() || !IsDone() )
+ return NULL;
+ }
+ else
+ {
+ //Add a new Projection object
+ aCopy = GetEngine()->AddObject(GEOM_PROJECTION);
+
+ //Add a Projection function
+ Handle(GEOM_Function) aFunction =
+ aCopy->AddFunction(GEOMImpl_ProjectionDriver::GetID(), PROJECTION_COPY);
+
+ //Check if the function is set correctly
+ if (aFunction->GetDriverGUID() != GEOMImpl_ProjectionDriver::GetID()) return NULL;
+
+ GEOMImpl_IMirror aTI (aFunction);
+ aTI.SetPlane(theTarget->GetLastFunction());
+ aTI.SetOriginal(aLastFunction);
+
+ //Compute the Projection
+ try {
+ OCC_CATCH_SIGNALS;
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("Projection driver failed");
+ return NULL;
+ }
+ }
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
+ return NULL;
+ }
+ }
+
+ //Make a Python command
+ Handle(GEOM_Function) aFunction = aCopy->GetLastFunction();
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeProjection("
+ << theSource << ", " << theTarget << ")";
+
+ SetErrorCode(OK);
+ return aCopy;
+}
+
+//=============================================================================
+/*!
+ * ProjectPointOnWire
+ */
+//=============================================================================
+Standard_Real GEOMImpl_ITransformOperations::ProjectPointOnWire
+ (Handle(GEOM_Object) thePoint,
+ Handle(GEOM_Object) theWire,
+ Handle(GEOM_Object) &thePointOnEdge,
+ Standard_Integer &theEdgeInWireIndex)
+{
+ Standard_Real aResult = -1.;
+
+ SetErrorCode(KO);
+
+ if (thePoint.IsNull() || theWire.IsNull()) {
+ return aResult;
+ }
+
+ Handle(GEOM_Function) aLastFunction = thePoint->GetLastFunction();
+
+ if (aLastFunction.IsNull()) {
+ //There is no function which creates an object to be projected
+ return aResult;
+ }
+
+ //Add a new Projection object
+ thePointOnEdge = GetEngine()->AddObject(GEOM_PROJECTION);
+
+ //Add a Projection function
+ Handle(GEOM_Function) aFunction = thePointOnEdge->AddFunction
+ (GEOMImpl_ProjectionDriver::GetID(), PROJECTION_ON_WIRE);
+
+ //Check if the function is set correctly
+ if (aFunction->GetDriverGUID() != GEOMImpl_ProjectionDriver::GetID()) {
+ return aResult;
+ }
+
+ GEOMImpl_IProjection aProj (aFunction);
+ aProj.SetPoint(aLastFunction);
+ aProj.SetShape(theWire->GetLastFunction());
+
+ //Compute the Projection
+ try {
+ OCC_CATCH_SIGNALS;
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("Projection driver failed");
+ return aResult;
+ }
+ }
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
+ return aResult;
+ }
+
+ aResult = aProj.GetU();
+ theEdgeInWireIndex = aProj.GetIndex();
+
+
+ //Make a Python command
+ GEOM::TPythonDump(aFunction) << "(u, " << thePointOnEdge
+ << ", EdgeInWireIndex) = geompy.MakeProjectionOnWire(" << thePoint
+ << ", " << theWire << ")";
+
+ SetErrorCode(OK);
+
+ return aResult;
+}
+
//=============================================================================
/*!
* 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);
//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 {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Scale driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.ScaleShape(");
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(thePoint->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- aDescr += TCollection_AsciiString(theFactor)+")";
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << "geompy.Scale("
+ << theObject << ", " << thePoint << ", " << theFactor << ")";
SetErrorCode(OK);
return theObject;
{
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
//Add a new Copy object
- Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GEOM_COPY);
//Add a scale function
Handle(GEOM_Function) aFunction =
//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 {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Scale driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(aCopy->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.ScaleShapeCopy(");
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(thePoint->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- aDescr += TCollection_AsciiString(theFactor)+")";
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeScaleTransform("
+ << theObject << ", " << thePoint << ", " << theFactor << ")";
SetErrorCode(OK);
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(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 {
+ OCC_CATCH_SIGNALS;
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("Scale driver failed");
+ return NULL;
+ }
+ }
+ catch (Standard_Failure& aFail) {
+ 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.ScaleAlongAxes("
+ << theObject << ", " << thePoint << ", "
+ << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")";
+ return theObject;
+}
+
//=============================================================================
/*!
* PositionShape
{
SetErrorCode(KO);
- if (theObject.IsNull() || theStartLCS.IsNull() || theEndLCS.IsNull()) return NULL;
+ if (theObject.IsNull() || theEndLCS.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
- // Get last functions of the arguments
- Handle(GEOM_Function) aStartLCS = theStartLCS->GetLastFunction();
- Handle(GEOM_Function) aEndLCS = theEndLCS->GetLastFunction();
-
//Add a Position function
+ Standard_Integer aType = POSITION_SHAPE;
+ if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL;
+
Handle(GEOM_Function) aFunction =
- theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_SHAPE);
+ theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
if (aFunction.IsNull()) return NULL;
//Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
+ //Set operation arguments
GEOMImpl_IPosition aTI (aFunction);
aTI.SetShape(anOriginal);
- aTI.SetStartLCS(aStartLCS);
- aTI.SetEndLCS(aEndLCS);
+ aTI.SetEndLCS(theEndLCS->GetLastFunction());
+ if (!theStartLCS.IsNull())
+ aTI.SetStartLCS(theObject == theStartLCS ? anOriginal : theStartLCS->GetLastFunction());
//Compute the Position
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Position driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.PositionShape(");
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(theStartLCS->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(theEndLCS->GetEntry(), anEntry);
- aDescr += (anEntry+") ");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << "geompy.Position("
+ << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
SetErrorCode(OK);
return theObject;
{
SetErrorCode(KO);
- if (theObject.IsNull() || theStartLCS.IsNull() || theEndLCS.IsNull()) return NULL;
+ if (theObject.IsNull() || theEndLCS.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 new Copy object
- Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GEOM_COPY);
//Add a position function
+ Standard_Integer aType = POSITION_SHAPE_COPY;
+ if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL_COPY;
+
Handle(GEOM_Function) aFunction =
- aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_SHAPE_COPY);
+ aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
if (aFunction.IsNull()) return NULL;
//Check if the function is set correctly
GEOMImpl_IPosition aTI (aFunction);
aTI.SetShape(anOriginal);
- aTI.SetStartLCS(theStartLCS->GetLastFunction());
aTI.SetEndLCS(theEndLCS->GetLastFunction());
+ if (!theStartLCS.IsNull())
+ aTI.SetStartLCS(theStartLCS->GetLastFunction());
//Compute the position
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Position driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(aCopy->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.PositionShapeCopy(");
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(theStartLCS->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(theEndLCS->GetEntry(), anEntry);
- aDescr += (anEntry+")");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakePosition("
+ << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
SetErrorCode(OK);
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(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 {
+ OCC_CATCH_SIGNALS;
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("Position driver failed");
+ return NULL;
+ }
+ }
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
+ return NULL;
+ }
+
+ //Make a Python command
+ if (theCopy) {
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakePositionAlongPath("
+ << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
+ SetErrorCode(OK);
+ return aCopy;
+ }
+
+ GEOM::TPythonDump(aFunction) << "geompy.PositionAlongPath("
+ << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
+
+ SetErrorCode(OK);
+ return theObject;
+}
+
//=============================================================================
/*!
* Rotate
//Compute the translation
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Rotate driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.Rotate(");
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(theAxis->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- aDescr += (TCollection_AsciiString(theAngle)+") ");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << "geompy.Rotate(" << theObject
+ << ", " << theAxis << ", " << theAngle * 180.0 / M_PI << "*math.pi/180.0)";
SetErrorCode(OK);
return theObject;
//=============================================================================
/*!
- * Rotate
+ * RotateCopy
*/
//=============================================================================
-Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateCopy (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis, double theAngle)
+Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateCopy (Handle(GEOM_Object) theObject,
+ Handle(GEOM_Object) theAxis,
+ double theAngle)
{
SetErrorCode(KO);
if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
//Add a new Copy object
- Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GEOM_COPY);
//Add a rotate function
aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_COPY);
//Compute the translation
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Rotate driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.RotateCopy(");
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(theAxis->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- aDescr += (TCollection_AsciiString(theAngle)+") ");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotation(" << theObject
+ << ", " << theAxis << ", " << theAngle * 180.0 / M_PI << "*math.pi/180.0)";
SetErrorCode(OK);
return aCopy;
//=============================================================================
/*!
- * Rotate1D
+ * Rotate1D (for MultiRotate1DNbTimes)
*/
//=============================================================================
Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate1D (Handle(GEOM_Object) theObject,
{
SetErrorCode(KO);
- if (theObject.IsNull() || theAxis.IsNull()) return NULL;
+ if (theObject.IsNull()) return NULL;
Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
//Add a new Copy object
- Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(theObject->GetType());
//Add a rotate function
aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_1D);
if (aFunction.IsNull()) return NULL;
- //Check if the function is set correctly
+ //Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
GEOMImpl_IRotate aRI(aFunction);
aRI.SetOriginal(aLastFunction);
- aRI.SetAxis(theAxis->GetLastFunction());
+ if (!theAxis.IsNull())
+ aRI.SetAxis(theAxis->GetLastFunction());
aRI.SetNbIter1(theNbTimes);
//Compute the translation
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Rotate driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.Rotate1D(");
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(theAxis->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- aDescr += (TCollection_AsciiString(theNbTimes)+") ");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate1DNbTimes("
+ << theObject << ", " << theAxis << ", " << theNbTimes << ")";
SetErrorCode(OK);
return aCopy;
//=============================================================================
/*!
- * Rotate2D
+ * Rotate1D (for MultiRotate1DByStep)
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate1D (Handle(GEOM_Object) theObject,
+ Handle(GEOM_Object) theAxis,
+ double theAngleStep,
+ Standard_Integer theNbSteps)
+{
+ SetErrorCode(KO);
+
+ if (theObject.IsNull()) return NULL;
+
+ Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
+ if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
+
+ //Add a new Copy object
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(theObject->GetType());
+
+ //Add a rotate function
+ aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_1D_STEP);
+ if (aFunction.IsNull()) return NULL;
+
+ //Check if the function is set correctly
+ if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
+
+ //Convert angle into degrees
+ double anAngleStep = theAngleStep * 180. / M_PI;
+
+ GEOMImpl_IRotate aRI (aFunction);
+ aRI.SetOriginal(aLastFunction);
+ if (!theAxis.IsNull())
+ aRI.SetAxis(theAxis->GetLastFunction());
+ aRI.SetAngle(anAngleStep);
+ aRI.SetNbIter1(theNbSteps);
+
+ //Compute the translation
+ try {
+ OCC_CATCH_SIGNALS;
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("Rotate driver failed");
+ return NULL;
+ }
+ }
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
+ return NULL;
+ }
+
+ //Make a Python command
+ GEOM::TPythonDump(aFunction)
+ << aCopy << " = geompy.MultiRotate1DByStep(" << theObject << ", "
+ << theAxis << ", " << anAngleStep << "*math.pi/180.0, " << theNbSteps << ")";
+
+ SetErrorCode(OK);
+ return aCopy;
+}
+
+//=============================================================================
+/*!
+ * Rotate2D (for MultiRotate2DNbTimes)
*/
//=============================================================================
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,
+ Standard_Integer theNbObjects,
+ double theRadialStep,
+ Standard_Integer theNbSteps)
{
SetErrorCode(KO);
- if (theObject.IsNull() || theAxis.IsNull()) return NULL;
+ if (theObject.IsNull()) return NULL;
Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
//Add a new Copy object
- Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(theObject->GetType());
//Add a rotate function
aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_2D);
if (aFunction.IsNull()) return NULL;
- //Check if the function is set correctly
+ //Check if the function is set correctly
if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
- GEOMImpl_IRotate aRI(aFunction);
- aRI.SetAxis(theAxis->GetLastFunction());
+ double anAngle = 360. / (double)theNbObjects;
+
+ GEOMImpl_IRotate aRI (aFunction);
+ aRI.SetOriginal(aLastFunction);
+ if (!theAxis.IsNull())
+ aRI.SetAxis(theAxis->GetLastFunction());
+ aRI.SetAngle(anAngle);
+ aRI.SetNbIter1(theNbObjects);
+ aRI.SetStep(theRadialStep);
+ aRI.SetNbIter2(theNbSteps);
+
+ //Compute the translation
+ try {
+ OCC_CATCH_SIGNALS;
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("Rotate driver failed");
+ return NULL;
+ }
+ }
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
+ return NULL;
+ }
+
+ //Make a Python command
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate2DNbTimes("
+ << theObject << ", " << theAxis << ", " << theNbObjects
+ << ", " << theRadialStep << ", " << theNbSteps << ")";
+
+ SetErrorCode(OK);
+ return aCopy;
+}
+
+//=============================================================================
+/*!
+ * Rotate2D (for MultiRotate2DByStep)
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate2D (Handle(GEOM_Object) theObject,
+ Handle(GEOM_Object) theAxis,
+ double theAngleStep,
+ Standard_Integer theNbTimes1,
+ double theStep,
+ Standard_Integer theNbTimes2)
+{
+ SetErrorCode(KO);
+
+ if (theObject.IsNull()) return NULL;
+
+ Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
+ if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
+
+ //Add a new Copy object
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(theObject->GetType());
+
+ //Add a rotate function
+ aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_2D);
+ if (aFunction.IsNull()) return NULL;
+
+ //Check if the function is set correctly
+ if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
+
+ //Convert angle into degrees
+ double anAngleStep = theAngleStep * 180. / M_PI;
+
+ GEOMImpl_IRotate aRI (aFunction);
aRI.SetOriginal(aLastFunction);
+ if (!theAxis.IsNull())
+ aRI.SetAxis(theAxis->GetLastFunction());
+ aRI.SetAngle(anAngleStep);
aRI.SetNbIter1(theNbTimes1);
- aRI.SetNbIter2(theNbTimes2);
- aRI.SetAngle(theAngle);
aRI.SetStep(theStep);
+ aRI.SetNbIter2(theNbTimes2);
//Compute the translation
try {
+ OCC_CATCH_SIGNALS;
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Rotate driver failed");
return NULL;
}
}
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
return NULL;
}
//Make a Python command
- TCollection_AsciiString anEntry, aDescr;
- TDF_Tool::Entry(theObject->GetEntry(), anEntry);
- aDescr += (anEntry+" = ITransformOperations.Rotate2D(");
- aDescr += (anEntry+", ");
- TDF_Tool::Entry(theAxis->GetEntry(), anEntry);
- aDescr += (anEntry+", ");
- aDescr += (TCollection_AsciiString(theAngle)+", ");
- aDescr += (TCollection_AsciiString(theNbTimes1)+", ");
- aDescr += (TCollection_AsciiString(theStep)+", ");
- aDescr += (TCollection_AsciiString(theNbTimes2)+") ");
- aFunction->SetDescription(aDescr);
+ GEOM::TPythonDump(aFunction)
+ << aCopy << " = geompy.MultiRotate2DByStep(" << theObject << ", "
+ << theAxis << ", " << anAngleStep << "*math.pi/180.0, "
+ << theNbTimes1 << ", " << theStep << ", " << theNbTimes2 << ")";
SetErrorCode(OK);
return aCopy;
}
+
+//=============================================================================
+/*!
+ * RotateThreePoints
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePoints (Handle(GEOM_Object) theObject,
+ Handle(GEOM_Object) theCentPoint,
+ Handle(GEOM_Object) thePoint1,
+ Handle(GEOM_Object) thePoint2)
+{
+ SetErrorCode(KO);
+
+ if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
+
+ Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
+ if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
+
+ // Get last functions of the arguments
+ Handle(GEOM_Function) aCPF = theCentPoint->GetLastFunction();
+ Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction();
+ Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction();
+
+
+ //Add a rotate function
+ aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS);
+
+ if (aFunction.IsNull()) return NULL;
+
+ //Check if the function is set correctly
+ if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
+
+ GEOMImpl_IRotate aRI(aFunction);
+ aRI.SetCentPoint(aCPF);
+ aRI.SetPoint1(aP1F);
+ aRI.SetPoint2(aP2F);
+ aRI.SetOriginal(aLastFunction);
+
+ //Compute the translation
+ try {
+ OCC_CATCH_SIGNALS;
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("Rotate driver failed");
+ return NULL;
+ }
+ }
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
+ return NULL;
+ }
+
+ //Make a Python command
+ GEOM::TPythonDump(aFunction) << "geompy.RotateThreePoints(" << theObject
+ << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
+
+ SetErrorCode(OK);
+ return theObject;
+}
+
+//=============================================================================
+/*!
+ * RotateThreePointsCopy
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePointsCopy (Handle(GEOM_Object) theObject,
+ Handle(GEOM_Object) theCentPoint,
+ Handle(GEOM_Object) thePoint1,
+ Handle(GEOM_Object) thePoint2)
+{
+ SetErrorCode(KO);
+
+ if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
+
+ Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
+ if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
+
+ //Add a new Copy object
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GEOM_COPY);
+
+ //Add a rotate function
+ aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS_COPY);
+ if (aFunction.IsNull()) return NULL;
+
+ //Check if the function is set correctly
+ if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
+
+ GEOMImpl_IRotate aRI(aFunction);
+ aRI.SetCentPoint(theCentPoint->GetLastFunction());
+ aRI.SetPoint1(thePoint1->GetLastFunction());
+ aRI.SetPoint2(thePoint2->GetLastFunction());
+ aRI.SetOriginal(aLastFunction);
+
+ //Compute the translation
+ try {
+ OCC_CATCH_SIGNALS;
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("Rotate driver failed");
+ return NULL;
+ }
+ }
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
+ return NULL;
+ }
+
+ //Make a Python command
+ GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotationThreePoints(" << theObject
+ << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
+
+ SetErrorCode(OK);
+ return aCopy;
+}
+
+//=============================================================================
+/*!
+ * TransformLikeOtherCopy
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_ITransformOperations::TransformLikeOtherCopy
+ (Handle(GEOM_Object) theObject,
+ Handle(GEOM_Object) theSample)
+{
+ SetErrorCode(KO);
+
+ if (theObject.IsNull() || theSample.IsNull()) return NULL;
+
+ Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
+ if (aLastFunction.IsNull()) return NULL; // There is no function which creates an object to be transformed
+
+ Handle(GEOM_Function) aSampleFunc = theSample->GetLastFunction();
+ if (aSampleFunc.IsNull()) return NULL; // There is no function which creates a sample object
+
+ // Add a new Copy object
+ Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GEOM_COPY);
+
+ // Add a transform function (depends on theSample function)
+ Handle(GEOM_Function) aFunction =
+ aCopy->AddFunction(aSampleFunc->GetDriverGUID(), aSampleFunc->GetType());
+ if (aFunction.IsNull()) return NULL;
+
+ // Check if the function is set correctly
+ if (aFunction->GetDriverGUID() != aSampleFunc->GetDriverGUID()) return NULL;
+
+ if (aSampleFunc->GetDriverGUID() == GEOMImpl_TranslateDriver::GetID()) {
+ switch (aSampleFunc->GetType()) {
+ case TRANSLATE_1D:
+ {
+ GEOMImpl_ITranslate aRI_sample (aSampleFunc);
+ GEOMImpl_ITranslate aRI_target (aFunction);
+
+ aRI_target.SetVector(aRI_sample.GetVector());
+ aRI_target.SetStep1(aRI_sample.GetStep1());
+ aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
+
+ aRI_target.SetOriginal(aLastFunction);
+ }
+ break;
+ case TRANSLATE_2D:
+ {
+ GEOMImpl_ITranslate aRI_sample (aSampleFunc);
+ GEOMImpl_ITranslate aRI_target (aFunction);
+
+ aRI_target.SetVector(aRI_sample.GetVector());
+ aRI_target.SetStep1(aRI_sample.GetStep1());
+ aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
+
+ aRI_target.SetVector2(aRI_sample.GetVector2());
+ aRI_target.SetStep2(aRI_sample.GetStep2());
+ aRI_target.SetNbIter2(aRI_sample.GetNbIter2());
+
+ aRI_target.SetOriginal(aLastFunction);
+ }
+ break;
+ default:
+ {
+ SetErrorCode("Not implemented case of TransformLikeOtherCopy");
+ return NULL;
+ }
+ }
+ }
+ else if (aSampleFunc->GetDriverGUID() == GEOMImpl_RotateDriver::GetID()) {
+ switch (aSampleFunc->GetType()) {
+ case ROTATE_1D:
+ {
+ GEOMImpl_IRotate aRI_sample (aSampleFunc);
+ GEOMImpl_IRotate aRI_target (aFunction);
+
+ aRI_target.SetAxis(aRI_sample.GetAxis());
+ aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
+
+ aRI_target.SetOriginal(aLastFunction);
+ }
+ break;
+ case ROTATE_2D:
+ {
+ GEOMImpl_IRotate aRI_sample (aSampleFunc);
+ GEOMImpl_IRotate aRI_target (aFunction);
+
+ aRI_target.SetAxis(aRI_sample.GetAxis());
+
+ aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
+ aRI_target.SetNbIter2(aRI_sample.GetNbIter2());
+
+ aRI_target.SetAngle(aRI_sample.GetAngle());
+ aRI_target.SetStep(aRI_sample.GetStep());
+
+ aRI_target.SetDir2(aRI_sample.GetDir2());
+
+ aRI_target.SetOriginal(aLastFunction);
+ }
+ break;
+ case ROTATE_THREE_POINTS_COPY:
+ {
+ GEOMImpl_IRotate aRI_sample (aSampleFunc);
+ GEOMImpl_IRotate aRI_target (aFunction);
+
+ aRI_target.SetCentPoint(aRI_sample.GetCentPoint());
+ aRI_target.SetPoint1(aRI_sample.GetPoint1());
+ aRI_target.SetPoint2(aRI_sample.GetPoint2());
+
+ aRI_target.SetOriginal(aLastFunction);
+ }
+ break;
+ default:
+ {
+ SetErrorCode("Not implemented case of TransformLikeOtherCopy");
+ return NULL;
+ }
+ }
+ }
+ else {
+ SetErrorCode("Not implemented case of TransformLikeOtherCopy");
+ return NULL;
+ }
+
+ // Compute the transformation
+ try {
+ OCC_CATCH_SIGNALS;
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("Driver failed");
+ return NULL;
+ }
+ }
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
+ return NULL;
+ }
+
+ //Make a Python command
+ //GEOM::TPythonDump(aFunction) << aCopy << " = geompy.TransformLikeOtherCopy("
+ // << theObject << ", " << theSample << ")";
+
+ SetErrorCode(OK);
+ return aCopy;
+}
+
+//=============================================================================
+/*!
+ * MakeProjectionOnCylinder
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_ITransformOperations::MakeProjectionOnCylinder
+ (const Handle(GEOM_Object) &theObject,
+ const Standard_Real theRadius,
+ const Standard_Real theStartAngle,
+ const Standard_Real theAngleLength,
+ const Standard_Real theAngleRotation)
+{
+ SetErrorCode(KO);
+
+ if (theObject.IsNull()) {
+ return NULL;
+ }
+
+ Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
+
+ if (aLastFunction.IsNull()) {
+ //There is no function which creates an object to be projected
+ return NULL;
+ }
+
+ //Add a new Projection object
+ Handle(GEOM_Object) aResult =
+ GetEngine()->AddObject(GEOM_PROJECTION);
+
+ //Add a Projection function
+ Handle(GEOM_Function) aFunction = aResult->AddFunction
+ (GEOMImpl_ProjectionDriver::GetID(), PROJECTION_ON_CYLINDER);
+
+ //Check if the function is set correctly
+ if (aFunction->GetDriverGUID() != GEOMImpl_ProjectionDriver::GetID()) {
+ return aResult;
+ }
+
+ GEOMImpl_IProjOnCyl aProj (aFunction);
+
+ aProj.SetShape(aLastFunction);
+ aProj.SetRadius(theRadius);
+ aProj.SetStartAngle(theStartAngle);
+ aProj.SetAngleLength(theAngleLength);
+ aProj.SetAngleRotation(theAngleRotation);
+
+ //Compute the Projection
+ try {
+ OCC_CATCH_SIGNALS;
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("Projection driver failed");
+ return aResult;
+ }
+ }
+ catch (Standard_Failure& aFail) {
+ SetErrorCode(aFail.GetMessageString());
+ return aResult;
+ }
+
+ //Make a Python command
+ GEOM::TPythonDump(aFunction)
+ << aResult << " = geompy.MakeProjectionOnCylinder("
+ << theObject << ", " << theRadius << ", " << theStartAngle
+ << ", " << theAngleLength << ", " << theAngleRotation << ")";
+
+ SetErrorCode(OK);
+
+ return aResult;
+}