1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include <Standard_Stream.hxx>
24 #include <GEOMImpl_ITransformOperations.hxx>
26 #include "utilities.h"
28 #include <Utils_ExceptHandlers.hxx>
30 #include <GEOM_Function.hxx>
31 #include <GEOM_PythonDump.hxx>
33 #include <GEOMImpl_TranslateDriver.hxx>
34 #include <GEOMImpl_MirrorDriver.hxx>
35 #include <GEOMImpl_OffsetDriver.hxx>
36 #include <GEOMImpl_ScaleDriver.hxx>
37 #include <GEOMImpl_RotateDriver.hxx>
38 #include <GEOMImpl_PositionDriver.hxx>
40 #include <GEOMImpl_ITranslate.hxx>
41 #include <GEOMImpl_IMirror.hxx>
42 #include <GEOMImpl_IOffset.hxx>
43 #include <GEOMImpl_IScale.hxx>
44 #include <GEOMImpl_IRotate.hxx>
45 #include <GEOMImpl_IPosition.hxx>
47 #include <GEOMImpl_Types.hxx>
49 #include <TFunction_DriverTable.hxx>
50 #include <TFunction_Driver.hxx>
51 #include <TFunction_Logbook.hxx>
52 #include <TDF_Tool.hxx>
54 #include <BRep_Tool.hxx>
55 #include <BRep_Builder.hxx>
58 #include <TopoDS_Edge.hxx>
59 #include <TopoDS_Vertex.hxx>
60 #include <TopoDS_Compound.hxx>
63 #include <gp_Trsf.hxx>
65 #include <StdFail_NotDone.hxx>
66 #include <Standard_Failure.hxx>
67 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
69 //=============================================================================
73 //=============================================================================
75 GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations (GEOM_Engine* theEngine, int theDocID)
76 : GEOM_IOperations(theEngine, theDocID)
78 MESSAGE("GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations");
81 //=============================================================================
85 //=============================================================================
87 GEOMImpl_ITransformOperations::~GEOMImpl_ITransformOperations()
89 MESSAGE("GEOMImpl_ITransformOperations::~GEOMImpl_ITransformOperations");
93 //=============================================================================
97 //=============================================================================
98 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPoints
99 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
103 if (theObject.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
105 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
106 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
108 // Get last functions of the arguments
109 Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction();
110 Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction();
112 //Add a translate function
113 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_TWO_POINTS);
115 if (aFunction.IsNull()) return NULL;
117 //Check if the function is set correctly
118 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
120 GEOMImpl_ITranslate aTI (aFunction);
123 aTI.SetOriginal(aLastFunction);
125 //Compute the translation
127 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
130 if (!GetSolver()->ComputeFunction(aFunction)) {
131 SetErrorCode("Translation driver failed");
135 catch (Standard_Failure) {
136 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
137 SetErrorCode(aFail->GetMessageString());
141 //Make a Python command
142 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.TranslateTwoPoints("
143 << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
149 //=============================================================================
153 //=============================================================================
154 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZ
155 (Handle(GEOM_Object) theObject, double theX, double theY, double theZ)
159 if (theObject.IsNull()) return NULL;
161 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
162 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
164 //Add a translate function
165 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_XYZ);
167 if (aFunction.IsNull()) return NULL;
169 //Check if the function is set correctly
170 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
172 GEOMImpl_ITranslate aTI(aFunction);
176 aTI.SetOriginal(aLastFunction);
178 //Compute the translation
180 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
183 if (!GetSolver()->ComputeFunction(aFunction)) {
184 SetErrorCode("Translation driver failed");
188 catch (Standard_Failure) {
189 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
190 SetErrorCode(aFail->GetMessageString());
194 //Make a Python command
195 GEOM::TPythonDump(aFunction) << "geompy.TranslateDXDYDZ("
196 << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
203 //=============================================================================
205 * TranslateTwoPointsCopy
207 //=============================================================================
208 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPointsCopy
209 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
213 if (theObject.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
215 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
216 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
218 //Add a new Copy object
219 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
221 //Add a translate function
222 Handle(GEOM_Function) aFunction =
223 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_TWO_POINTS_COPY);
225 //Check if the function is set correctly
226 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
228 GEOMImpl_ITranslate aTI(aFunction);
229 aTI.SetPoint1(thePoint1->GetLastFunction());
230 aTI.SetPoint2(thePoint2->GetLastFunction());
231 //aTI.SetShape(theObject->GetValue());
232 aTI.SetOriginal(aLastFunction);
234 //Compute the translation
236 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
239 if (!GetSolver()->ComputeFunction(aFunction)) {
240 SetErrorCode("Translation driver failed");
244 catch (Standard_Failure) {
245 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
246 SetErrorCode(aFail->GetMessageString());
250 //Make a Python command
251 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationTwoPoints("
252 << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
258 //=============================================================================
260 * TranslateDXDYDZCopy
262 //=============================================================================
263 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZCopy
264 (Handle(GEOM_Object) theObject, double theX, double theY, double theZ)
268 if (theObject.IsNull()) return NULL;
270 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
271 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
273 //Add a new Copy object
274 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
276 //Add a translate function
277 Handle(GEOM_Function) aFunction =
278 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_XYZ_COPY);
280 //Check if the function is set correctly
281 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
283 GEOMImpl_ITranslate aTI(aFunction);
287 aTI.SetOriginal(aLastFunction);
289 //Compute the translation
291 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
294 if (!GetSolver()->ComputeFunction(aFunction)) {
295 SetErrorCode("Translation driver failed");
299 catch (Standard_Failure) {
300 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
301 SetErrorCode(aFail->GetMessageString());
305 //Make a Python command
306 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslation("
307 << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
314 //=============================================================================
318 //=============================================================================
319 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVector
320 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector)
324 if (theObject.IsNull() || theVector.IsNull()) return NULL;
326 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
327 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
329 // Get last functions of the arguments
330 Handle(GEOM_Function) aVF = theVector->GetLastFunction();
332 //Add a translate function
333 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR);
335 if (aFunction.IsNull()) return NULL;
337 //Check if the function is set correctly
338 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
340 GEOMImpl_ITranslate aTI (aFunction);
342 aTI.SetOriginal(aLastFunction);
344 //Compute the translation
346 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
349 if (!GetSolver()->ComputeFunction(aFunction)) {
350 SetErrorCode("Translation driver failed");
354 catch (Standard_Failure) {
355 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
356 SetErrorCode(aFail->GetMessageString());
360 //Make a Python command
361 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.TranslateVector("
362 << theObject << ", " << theVector << ")";
367 //=============================================================================
369 * TranslateVectorCopy
371 //=============================================================================
372 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorCopy
373 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector)
377 if (theObject.IsNull() || theVector.IsNull()) return NULL;
379 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
380 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
382 //Add a new Copy object
383 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
385 //Add a translate function
386 Handle(GEOM_Function) aFunction =
387 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_COPY);
389 //Check if the function is set correctly
390 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
392 GEOMImpl_ITranslate aTI(aFunction);
393 aTI.SetVector(theVector->GetLastFunction());
394 // aTI.SetShape(theObject->GetValue());
395 aTI.SetOriginal(aLastFunction);
397 //Compute the translation
399 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
402 if (!GetSolver()->ComputeFunction(aFunction)) {
403 SetErrorCode("Translation driver failed");
407 catch (Standard_Failure) {
408 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
409 SetErrorCode(aFail->GetMessageString());
413 //Make a Python command
414 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationVector("
415 << theObject << ", " << theVector << ")";
421 //=============================================================================
423 * TranslateVectorDistance
425 //=============================================================================
426 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorDistance
427 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector, double theDistance, bool theCopy)
431 if (theObject.IsNull() || theVector.IsNull()) return NULL;
433 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
434 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
436 Handle(GEOM_Object) aCopy; //Add a new Copy object
437 Handle(GEOM_Function) aFunction;
439 //Add a translate function
441 aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
442 aFunction = aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_DISTANCE);
445 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_DISTANCE);
447 if (aFunction.IsNull()) return NULL;
449 //Check if the function is set correctly
450 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
452 GEOMImpl_ITranslate aTI(aFunction);
453 aTI.SetVector(theVector->GetLastFunction());
454 aTI.SetDistance(theDistance);
455 // aTI.SetShape(theObject->GetValue());
456 aTI.SetOriginal(aLastFunction);
458 //Compute the translation
460 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
463 if (!GetSolver()->ComputeFunction(aFunction)) {
464 SetErrorCode("Translation driver failed");
468 catch (Standard_Failure) {
469 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
470 SetErrorCode(aFail->GetMessageString());
474 //Make a Python command
476 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationVectorDistance("
477 << theObject << ", " << theVector << ", " << theDistance << ")";
482 GEOM::TPythonDump(aFunction) << "geompy.TranslateVectorDistance("
483 << theObject << ", " << theVector << ", " << theDistance << ", " << theCopy << ")";
488 //=============================================================================
492 //=============================================================================
493 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate1D
494 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector,
495 double theStep, Standard_Integer theNbTimes)
499 if (theObject.IsNull() || theVector.IsNull()) return NULL;
501 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
502 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
504 //Add a new Copy object
505 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
507 //Add a translate function
508 Handle(GEOM_Function) aFunction =
509 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_1D);
511 //Check if the function is set correctly
512 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
514 GEOMImpl_ITranslate aTI(aFunction);
515 aTI.SetVector(theVector->GetLastFunction());
516 aTI.SetOriginal(aLastFunction);
517 aTI.SetStep1(theStep);
518 aTI.SetNbIter1(theNbTimes);
520 //Compute the translation
522 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
525 if (!GetSolver()->ComputeFunction(aFunction)) {
526 SetErrorCode("Translation driver failed");
530 catch (Standard_Failure) {
531 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
532 SetErrorCode(aFail->GetMessageString());
536 //Make a Python command
537 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMultiTranslation1D("
538 << theObject << ", " << theVector << ", " << theStep << ", " << theNbTimes << ")";
544 //=============================================================================
548 //=============================================================================
549 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate2D (Handle(GEOM_Object) theObject,
550 Handle(GEOM_Object) theVector,
552 Standard_Integer theNbTimes1,
553 Handle(GEOM_Object) theVector2,
555 Standard_Integer theNbTimes2)
559 if (theObject.IsNull() || theVector.IsNull() || theVector2.IsNull()) return NULL;
561 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
562 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
564 //Add a new Copy object
565 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
567 //Add a translate function
568 Handle(GEOM_Function) aFunction =
569 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_2D);
571 //Check if the function is set correctly
572 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
574 GEOMImpl_ITranslate aTI (aFunction);
575 aTI.SetVector(theVector->GetLastFunction());
576 aTI.SetVector2(theVector2->GetLastFunction());
577 aTI.SetOriginal(aLastFunction);
578 aTI.SetStep1(theStep1);
579 aTI.SetNbIter1(theNbTimes1);
580 aTI.SetStep2(theStep2);
581 aTI.SetNbIter2(theNbTimes2);
583 //Compute the translation
585 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
588 if (!GetSolver()->ComputeFunction(aFunction)) {
589 SetErrorCode("Translation driver failed");
593 catch (Standard_Failure) {
594 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
595 SetErrorCode(aFail->GetMessageString());
599 //Make a Python command
600 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMultiTranslation2D("
601 << theObject << ", " << theVector << ", " << theStep1 << ", " << theNbTimes1
602 << ", " << theVector2 << ", " << theStep2 << ", " << theNbTimes2 << ")";
608 //=============================================================================
612 //=============================================================================
614 TopoDS_Shape GEOMImpl_ITransformOperations::TranslateShape1D (const TopoDS_Shape& theShape,
615 GEOMImpl_ITranslate* theTI)
620 Handle(GEOM_Function) aVector = theTI->GetVector();
621 if (aVector.IsNull()) {
622 StdFail_NotDone::Raise("Invalid object is given for vector argument");
624 TopoDS_Shape aV = aVector->GetValue();
625 if (aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) {
626 StdFail_NotDone::Raise("Invalid object is given for vector argument");
628 TopoDS_Edge anEdge = TopoDS::Edge(aV);
630 gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
631 gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
632 if (aP1.Distance(aP2) < gp::Resolution()) {
633 StdFail_NotDone::Raise("Invalid object is given for vector argument");
637 Standard_Real step = theTI->GetStep1();
638 Standard_Integer nbtimes = theTI->GetNbIter1();
640 // Make multi-translation
643 TopoDS_Compound aCompound;
645 B.MakeCompound(aCompound);
647 gp_Vec Vec (aP1, aP2);
650 TopLoc_Location aLocOrig = theShape.Location();
651 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
653 for (int i = 0; i < nbtimes; i++) {
654 aVec = Vec * (i * step);
655 aTrsf.SetTranslation(aVec);
656 //NPAL18620: performance problem: multiple locations are accumulated
657 // in shape and need a great time to process
658 //BRepBuilderAPI_Transform aTransformation(theShape, aTrsf, Standard_False);
659 //B.Add(aCompound, aTransformation.Shape());
660 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
661 B.Add(aCompound, theShape.Located(aLocRes));
669 //=============================================================================
673 //=============================================================================
675 TopoDS_Shape GEOMImpl_ITransformOperations::TranslateShape2D (const TopoDS_Shape& theShape,
676 GEOMImpl_ITranslate* theTI)
681 Handle(GEOM_Function) aVector1 = theTI->GetVector();
682 Handle(GEOM_Function) aVector2 = theTI->GetVector2();
684 if (aVector1.IsNull() || aVector2.IsNull()) {
685 StdFail_NotDone::Raise("Invalid object is given for vector argument");
688 TopoDS_Shape aV1 = aVector1->GetValue();
689 TopoDS_Shape aV2 = aVector2->GetValue();
691 if (aV1.IsNull() || aV1.ShapeType() != TopAbs_EDGE ||
692 aV2.IsNull() || aV2.ShapeType() != TopAbs_EDGE) {
693 StdFail_NotDone::Raise("Invalid object is given for vector argument");
696 TopoDS_Edge anEdge1 = TopoDS::Edge(aV1);
697 TopoDS_Edge anEdge2 = TopoDS::Edge(aV2);
699 gp_Pnt aP11 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge1));
700 gp_Pnt aP12 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge1));
701 gp_Pnt aP21 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge2));
702 gp_Pnt aP22 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge2));
704 if (aP11.Distance(aP12) < gp::Resolution() ||
705 aP21.Distance(aP22) < gp::Resolution()) {
706 StdFail_NotDone::Raise("Invalid object is given for vector argument");
709 gp_Vec Vec1 (aP11, aP12);
710 gp_Vec Vec2 (aP21, aP22);
716 Standard_Real step1 = theTI->GetStep1(), step2 = theTI->GetStep2();
717 Standard_Integer nbtimes1 = theTI->GetNbIter1(), nbtimes2 = theTI->GetNbIter2();
719 // Make multi-translation
722 Standard_Real DX, DY, DZ;
723 TopoDS_Compound aCompound;
725 B.MakeCompound(aCompound);
727 TopLoc_Location aLocOrig = theShape.Location();
728 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
730 for (int i = 0; i < nbtimes1; i++) {
731 for (int j = 0; j < nbtimes2; j++) {
732 DX = i * step1 * Vec1.X() + j * step2 * Vec2.X();
733 DY = i * step1 * Vec1.Y() + j * step2 * Vec2.Y();
734 DZ = i * step1 * Vec1.Z() + j * step2 * Vec2.Z();
735 aVec.SetCoord(DX, DY, DZ);
736 aTrsf.SetTranslation(aVec);
737 //NPAL18620: performance problem: multiple locations are accumulated
738 // in shape and need a great time to process
739 //BRepBuilderAPI_Transform aBRepTransformation(theShape, aTrsf, Standard_False);
740 //B.Add(aCompound, aBRepTransformation.Shape());
741 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
742 B.Add(aCompound, theShape.Located(aLocRes));
751 //=============================================================================
755 //=============================================================================
756 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlane
757 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePlane)
761 if (theObject.IsNull() || thePlane.IsNull()) return NULL;
763 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
764 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
766 // Get last functions of the arguments
767 Handle(GEOM_Function) aPF = thePlane->GetLastFunction();
769 //Add a mirror function
770 Handle(GEOM_Function) aFunction =
771 theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_PLANE);
772 if (aFunction.IsNull()) return NULL;
774 //Check if the function is set correctly
775 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
777 GEOMImpl_IMirror aTI (aFunction);
779 aTI.SetOriginal(aLastFunction);
783 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
786 if (!GetSolver()->ComputeFunction(aFunction)) {
787 SetErrorCode("Mirror driver failed");
791 catch (Standard_Failure) {
792 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
793 SetErrorCode(aFail->GetMessageString());
797 //Make a Python command
798 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorPlane("
799 << theObject << ", " << thePlane << ")";
805 //=============================================================================
809 //=============================================================================
810 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlaneCopy
811 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePlane)
815 if (theObject.IsNull() || thePlane.IsNull()) return NULL;
817 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
818 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
820 //Add a new Copy object
821 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
823 //Add a mirror function
824 Handle(GEOM_Function) aFunction =
825 aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_PLANE_COPY);
827 //Check if the function is set correctly
828 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
830 GEOMImpl_IMirror aTI (aFunction);
831 aTI.SetPlane(thePlane->GetLastFunction());
832 aTI.SetOriginal(aLastFunction);
836 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
839 if (!GetSolver()->ComputeFunction(aFunction)) {
840 SetErrorCode("Mirror driver failed");
844 catch (Standard_Failure) {
845 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
846 SetErrorCode(aFail->GetMessageString());
850 //Make a Python command
851 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByPlane("
852 << theObject << ", " << thePlane << ")";
858 //=============================================================================
862 //=============================================================================
863 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPoint
864 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint)
868 if (theObject.IsNull() || thePoint.IsNull()) return NULL;
870 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
871 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
873 // Get last functions of the arguments
874 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
876 //Add a mirror function
877 Handle(GEOM_Function) aFunction =
878 theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_POINT);
879 if (aFunction.IsNull()) return NULL;
881 //Check if the function is set correctly
882 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
884 GEOMImpl_IMirror aTI (aFunction);
886 aTI.SetOriginal(aLastFunction);
890 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
893 if (!GetSolver()->ComputeFunction(aFunction)) {
894 SetErrorCode("Mirror driver failed");
898 catch (Standard_Failure) {
899 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
900 SetErrorCode(aFail->GetMessageString());
904 //Make a Python command
905 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorPoint("
906 << theObject << ", " << thePoint << ")";
912 //=============================================================================
916 //=============================================================================
917 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPointCopy
918 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint)
922 if (theObject.IsNull() || thePoint.IsNull()) return NULL;
924 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
925 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
927 //Add a new Copy object
928 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
930 //Add a mirror function
931 Handle(GEOM_Function) aFunction =
932 aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_POINT_COPY);
934 //Check if the function is set correctly
935 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
937 GEOMImpl_IMirror aTI (aFunction);
938 aTI.SetPoint(thePoint->GetLastFunction());
939 aTI.SetOriginal(aLastFunction);
943 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
946 if (!GetSolver()->ComputeFunction(aFunction)) {
947 SetErrorCode("Mirror driver failed");
951 catch (Standard_Failure) {
952 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
953 SetErrorCode(aFail->GetMessageString());
957 //Make a Python command
958 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByPoint("
959 << theObject << ", " << thePoint << ")";
965 //=============================================================================
969 //=============================================================================
970 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxis
971 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis)
975 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
977 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
978 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
980 // Get last functions of the arguments
981 Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
983 //Add a mirror function
984 Handle(GEOM_Function) aFunction =
985 theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_AXIS);
986 if (aFunction.IsNull()) return NULL;
988 //Check if the function is set correctly
989 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
991 GEOMImpl_IMirror aTI (aFunction);
993 aTI.SetOriginal(aLastFunction);
997 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1000 if (!GetSolver()->ComputeFunction(aFunction)) {
1001 SetErrorCode("Mirror driver failed");
1005 catch (Standard_Failure) {
1006 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1007 SetErrorCode(aFail->GetMessageString());
1011 //Make a Python command
1012 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorAxis("
1013 << theObject << ", " << theAxis << ")";
1019 //=============================================================================
1023 //=============================================================================
1024 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxisCopy
1025 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis)
1029 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1031 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
1032 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
1034 //Add a new Copy object
1035 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1037 //Add a mirror function
1038 Handle(GEOM_Function) aFunction =
1039 aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_AXIS_COPY);
1041 //Check if the function is set correctly
1042 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
1044 GEOMImpl_IMirror aTI (aFunction);
1045 aTI.SetAxis(theAxis->GetLastFunction());
1046 aTI.SetOriginal(aLastFunction);
1048 //Compute the mirror
1050 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1053 if (!GetSolver()->ComputeFunction(aFunction)) {
1054 SetErrorCode("Mirror driver failed");
1058 catch (Standard_Failure) {
1059 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1060 SetErrorCode(aFail->GetMessageString());
1064 //Make a Python command
1065 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByAxis("
1066 << theObject << ", " << theAxis << ")";
1073 //=============================================================================
1077 //=============================================================================
1078 Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShape
1079 (Handle(GEOM_Object) theObject, double theOffset)
1083 if (theObject.IsNull()) return NULL;
1085 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1086 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
1088 //Add a new Offset function
1089 Handle(GEOM_Function) aFunction =
1090 theObject->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE);
1091 if (aFunction.IsNull()) return NULL;
1093 //Check if the function is set correctly
1094 if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
1096 GEOMImpl_IOffset aTI (aFunction);
1097 aTI.SetShape(anOriginal);
1098 aTI.SetValue(theOffset);
1100 //Compute the offset
1102 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1105 if (!GetSolver()->ComputeFunction(aFunction)) {
1106 SetErrorCode("Offset driver failed");
1110 catch (Standard_Failure) {
1111 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1112 SetErrorCode(aFail->GetMessageString());
1116 //Make a Python command
1117 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.OffsetShape("
1118 << theObject << ", " << theOffset << ")";
1124 //=============================================================================
1128 //=============================================================================
1129 Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShapeCopy
1130 (Handle(GEOM_Object) theObject, double theOffset)
1134 if (theObject.IsNull()) return NULL;
1136 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1137 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
1139 //Add a new Copy object
1140 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1142 //Add a new Offset function
1143 Handle(GEOM_Function) aFunction =
1144 aCopy->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE_COPY);
1145 if (aFunction.IsNull()) return NULL;
1147 //Check if the function is set correctly
1148 if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
1150 GEOMImpl_IOffset aTI (aFunction);
1151 aTI.SetShape(anOriginal);
1152 aTI.SetValue(theOffset);
1154 //Compute the offset
1156 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1159 if (!GetSolver()->ComputeFunction(aFunction)) {
1160 SetErrorCode("Offset driver failed");
1164 catch (Standard_Failure) {
1165 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1166 SetErrorCode(aFail->GetMessageString());
1170 //Make a Python command
1171 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeOffset("
1172 << theObject << ", " << theOffset << ")";
1179 //=============================================================================
1183 //=============================================================================
1184 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShape
1185 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, double theFactor)
1189 if (theObject.IsNull()) return NULL;
1191 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1192 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1194 //Add a scale function
1195 Handle(GEOM_Function) aFunction =
1196 theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE);
1197 if (aFunction.IsNull()) return NULL;
1199 //Check if the function is set correctly
1200 if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1203 GEOMImpl_IScale aTI (aFunction);
1204 aTI.SetShape(anOriginal);
1205 aTI.SetFactor(theFactor);
1207 // Set point argument
1208 if (!thePoint.IsNull()) {
1209 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1215 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1218 if (!GetSolver()->ComputeFunction(aFunction)) {
1219 SetErrorCode("Scale driver failed");
1223 catch (Standard_Failure) {
1224 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1225 SetErrorCode(aFail->GetMessageString());
1229 //Make a Python command
1230 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.ScaleShape("
1231 << theObject << ", " << thePoint << ", " << theFactor << ")";
1237 //=============================================================================
1241 //=============================================================================
1242 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeCopy
1243 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, double theFactor)
1247 if (theObject.IsNull()) return NULL;
1249 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1250 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1252 //Add a new Copy object
1253 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1255 //Add a scale function
1256 Handle(GEOM_Function) aFunction =
1257 aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_COPY);
1258 if (aFunction.IsNull()) return NULL;
1260 //Check if the function is set correctly
1261 if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1264 GEOMImpl_IScale aTI (aFunction);
1265 aTI.SetShape(anOriginal);
1266 aTI.SetFactor(theFactor);
1268 // Set point argument
1269 if (!thePoint.IsNull()) {
1270 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1276 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1279 if (!GetSolver()->ComputeFunction(aFunction)) {
1280 SetErrorCode("Scale driver failed");
1284 catch (Standard_Failure) {
1285 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1286 SetErrorCode(aFail->GetMessageString());
1290 //Make a Python command
1291 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeScaleTransform("
1292 << theObject << ", " << thePoint << ", " << theFactor << ")";
1298 //=============================================================================
1300 * ScaleShapeAlongAxes
1302 //=============================================================================
1303 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeAlongAxes (Handle(GEOM_Object) theObject,
1304 Handle(GEOM_Object) thePoint,
1312 if (theObject.IsNull()) return NULL;
1314 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1315 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1317 //Add a scale function
1318 Handle(GEOM_Object) aCopy; //Add a new Copy object
1319 Handle(GEOM_Function) aFunction;
1321 aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1322 aFunction = aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES_COPY);
1325 aFunction = theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES);
1327 if (aFunction.IsNull()) return NULL;
1329 //Check if the function is set correctly
1330 if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1333 GEOMImpl_IScale aTI (aFunction);
1334 aTI.SetShape(anOriginal);
1335 aTI.SetFactorX(theFactorX);
1336 aTI.SetFactorY(theFactorY);
1337 aTI.SetFactorZ(theFactorZ);
1339 // Set point (optional argument)
1340 if (!thePoint.IsNull()) {
1341 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1347 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1350 if (!GetSolver()->ComputeFunction(aFunction)) {
1351 SetErrorCode("Scale driver failed");
1355 catch (Standard_Failure) {
1356 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1357 SetErrorCode(aFail->GetMessageString());
1363 //Make a Python command
1365 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeScaleAlongAxes("
1366 << theObject << ", " << thePoint << ", "
1367 << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")";
1371 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.ScaleShapeAlongAxes("
1372 << theObject << ", " << thePoint << ", "
1373 << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")";
1377 //=============================================================================
1381 //=============================================================================
1382 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShape
1383 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theStartLCS, Handle(GEOM_Object) theEndLCS)
1387 if (theObject.IsNull() || theEndLCS.IsNull()) return NULL;
1389 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1390 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1392 //Add a Position function
1393 Standard_Integer aType = POSITION_SHAPE;
1394 if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL;
1396 Handle(GEOM_Function) aFunction =
1397 theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
1398 if (aFunction.IsNull()) return NULL;
1400 //Check if the function is set correctly
1401 if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1403 //Set operation arguments
1404 GEOMImpl_IPosition aTI (aFunction);
1405 aTI.SetShape(anOriginal);
1406 aTI.SetEndLCS(theEndLCS->GetLastFunction());
1407 if (!theStartLCS.IsNull())
1408 aTI.SetStartLCS(theObject == theStartLCS ? anOriginal : theStartLCS->GetLastFunction());
1410 //Compute the Position
1412 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1415 if (!GetSolver()->ComputeFunction(aFunction)) {
1416 SetErrorCode("Position driver failed");
1420 catch (Standard_Failure) {
1421 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1422 SetErrorCode(aFail->GetMessageString());
1426 //Make a Python command
1427 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.PositionShape("
1428 << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
1434 //=============================================================================
1438 //=============================================================================
1439 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShapeCopy
1440 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theStartLCS, Handle(GEOM_Object) theEndLCS)
1444 if (theObject.IsNull() || theEndLCS.IsNull()) return NULL;
1446 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1447 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1449 //Add a new Copy object
1450 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1452 //Add a position function
1453 Standard_Integer aType = POSITION_SHAPE_COPY;
1454 if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL_COPY;
1456 Handle(GEOM_Function) aFunction =
1457 aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
1458 if (aFunction.IsNull()) return NULL;
1460 //Check if the function is set correctly
1461 if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1463 GEOMImpl_IPosition aTI (aFunction);
1464 aTI.SetShape(anOriginal);
1465 aTI.SetEndLCS(theEndLCS->GetLastFunction());
1466 if (!theStartLCS.IsNull())
1467 aTI.SetStartLCS(theStartLCS->GetLastFunction());
1469 //Compute the position
1471 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1474 if (!GetSolver()->ComputeFunction(aFunction)) {
1475 SetErrorCode("Position driver failed");
1479 catch (Standard_Failure) {
1480 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1481 SetErrorCode(aFail->GetMessageString());
1485 //Make a Python command
1486 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakePosition("
1487 << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
1493 //=============================================================================
1497 //=============================================================================
1498 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionAlongPath
1499 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePath,
1500 double theDistance, bool theCopy, bool theReverse)
1504 if (theObject.IsNull() || thePath.IsNull()) return NULL;
1506 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1507 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1509 //Add a position function
1510 Handle(GEOM_Function) aFunction;
1511 Handle(GEOM_Object) aCopy;
1514 aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1515 aFunction = aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
1518 aFunction = theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
1520 if (aFunction.IsNull()) return NULL;
1522 //Check if the function is set correctly
1523 if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1525 GEOMImpl_IPosition aTI (aFunction);
1526 aTI.SetShape(anOriginal);
1527 aTI.SetPath(thePath->GetLastFunction());
1528 aTI.SetDistance(theDistance);
1529 aTI.SetReverse(theReverse);
1531 //Compute the position
1533 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1536 if (!GetSolver()->ComputeFunction(aFunction)) {
1537 SetErrorCode("Position driver failed");
1541 catch (Standard_Failure) {
1542 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1543 SetErrorCode(aFail->GetMessageString());
1547 //Make a Python command
1549 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.PositionAlongPath("
1550 << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
1555 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.PositionAlongPath("
1556 << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
1562 //=============================================================================
1566 //=============================================================================
1567 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate (Handle(GEOM_Object) theObject,
1568 Handle(GEOM_Object) theAxis,
1573 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1575 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1576 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1578 // Get last functions of the arguments
1579 Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
1581 //Add a rotate function
1582 aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE);
1584 if (aFunction.IsNull()) return NULL;
1586 //Check if the function is set correctly
1587 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1589 GEOMImpl_IRotate aRI(aFunction);
1591 aRI.SetOriginal(aLastFunction);
1592 aRI.SetAngle(theAngle);
1594 //Compute the translation
1596 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1599 if (!GetSolver()->ComputeFunction(aFunction)) {
1600 SetErrorCode("Rotate driver failed");
1604 catch (Standard_Failure) {
1605 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1606 SetErrorCode(aFail->GetMessageString());
1610 //Make a Python command
1611 GEOM::TPythonDump(aFunction) << "geompy.Rotate(" << theObject
1612 << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
1618 //=============================================================================
1622 //=============================================================================
1623 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateCopy (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis, double theAngle)
1627 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1629 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1630 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1632 //Add a new Copy object
1633 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1635 //Add a rotate function
1636 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_COPY);
1637 if (aFunction.IsNull()) return NULL;
1639 //Check if the function is set correctly
1640 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1642 GEOMImpl_IRotate aRI(aFunction);
1643 aRI.SetAxis(theAxis->GetLastFunction());
1644 aRI.SetOriginal(aLastFunction);
1645 aRI.SetAngle(theAngle);
1647 //Compute the translation
1649 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1652 if (!GetSolver()->ComputeFunction(aFunction)) {
1653 SetErrorCode("Rotate driver failed");
1657 catch (Standard_Failure) {
1658 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1659 SetErrorCode(aFail->GetMessageString());
1663 //Make a Python command
1664 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotation(" << theObject
1665 << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
1671 //=============================================================================
1675 //=============================================================================
1676 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate1D (Handle(GEOM_Object) theObject,
1677 Handle(GEOM_Object) theAxis,
1678 Standard_Integer theNbTimes)
1682 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1684 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1685 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1687 //Add a new Copy object
1688 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1690 //Add a rotate function
1691 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_1D);
1692 if (aFunction.IsNull()) return NULL;
1694 //Check if the function is set correctly
1695 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1697 GEOMImpl_IRotate aRI(aFunction);
1698 aRI.SetOriginal(aLastFunction);
1699 aRI.SetAxis(theAxis->GetLastFunction());
1700 aRI.SetNbIter1(theNbTimes);
1702 //Compute the translation
1704 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1707 if (!GetSolver()->ComputeFunction(aFunction)) {
1708 SetErrorCode("Rotate driver failed");
1712 catch (Standard_Failure) {
1713 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1714 SetErrorCode(aFail->GetMessageString());
1718 //Make a Python command
1719 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate1D("
1720 << theObject << ", " << theAxis << ", " << theNbTimes << ")";
1726 //=============================================================================
1730 //=============================================================================
1731 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate2D (Handle(GEOM_Object) theObject,
1732 Handle(GEOM_Object) theAxis,
1734 Standard_Integer theNbTimes1,
1736 Standard_Integer theNbTimes2)
1740 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1742 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1743 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1745 //Add a new Copy object
1746 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1748 //Add a rotate function
1749 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_2D);
1750 if (aFunction.IsNull()) return NULL;
1752 //Check if the function is set correctly
1753 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1755 GEOMImpl_IRotate aRI(aFunction);
1756 aRI.SetAxis(theAxis->GetLastFunction());
1757 aRI.SetOriginal(aLastFunction);
1758 aRI.SetNbIter1(theNbTimes1);
1759 aRI.SetNbIter2(theNbTimes2);
1760 aRI.SetAngle(theAngle);
1761 aRI.SetStep(theStep);
1763 //Compute the translation
1765 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1768 if (!GetSolver()->ComputeFunction(aFunction)) {
1769 SetErrorCode("Rotate driver failed");
1773 catch (Standard_Failure) {
1774 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1775 SetErrorCode(aFail->GetMessageString());
1779 //Make a Python command
1780 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate2D("
1781 << theObject << ", " << theAxis << ", " << theAngle << ", "
1782 << theNbTimes1 << ", " << theStep << ", " << theNbTimes2 << ")";
1788 //=============================================================================
1792 //=============================================================================
1793 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePoints (Handle(GEOM_Object) theObject,
1794 Handle(GEOM_Object) theCentPoint,
1795 Handle(GEOM_Object) thePoint1,
1796 Handle(GEOM_Object) thePoint2)
1800 if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1802 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1803 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1805 // Get last functions of the arguments
1806 Handle(GEOM_Function) aCPF = theCentPoint->GetLastFunction();
1807 Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction();
1808 Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction();
1811 //Add a rotate function
1812 aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS);
1814 if (aFunction.IsNull()) return NULL;
1816 //Check if the function is set correctly
1817 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1819 GEOMImpl_IRotate aRI(aFunction);
1820 aRI.SetCentPoint(aCPF);
1821 aRI.SetPoint1(aP1F);
1822 aRI.SetPoint2(aP2F);
1823 aRI.SetOriginal(aLastFunction);
1825 //Compute the translation
1827 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1830 if (!GetSolver()->ComputeFunction(aFunction)) {
1831 SetErrorCode("Rotate driver failed");
1835 catch (Standard_Failure) {
1836 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1837 SetErrorCode(aFail->GetMessageString());
1841 //Make a Python command
1842 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.RotateThreePoints(" << theObject
1843 << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
1849 //=============================================================================
1851 * RotateThreePointsCopy
1853 //=============================================================================
1854 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePointsCopy (Handle(GEOM_Object) theObject,
1855 Handle(GEOM_Object) theCentPoint,
1856 Handle(GEOM_Object) thePoint1,
1857 Handle(GEOM_Object) thePoint2)
1861 if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1863 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1864 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1866 //Add a new Copy object
1867 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1869 //Add a rotate function
1870 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS_COPY);
1871 if (aFunction.IsNull()) return NULL;
1873 //Check if the function is set correctly
1874 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1876 GEOMImpl_IRotate aRI(aFunction);
1877 aRI.SetCentPoint(theCentPoint->GetLastFunction());
1878 aRI.SetPoint1(thePoint1->GetLastFunction());
1879 aRI.SetPoint2(thePoint2->GetLastFunction());
1880 aRI.SetOriginal(aLastFunction);
1882 //Compute the translation
1884 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1887 if (!GetSolver()->ComputeFunction(aFunction)) {
1888 SetErrorCode("Rotate driver failed");
1892 catch (Standard_Failure) {
1893 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1894 SetErrorCode(aFail->GetMessageString());
1898 //Make a Python command
1899 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotationThreePoints(" << theObject
1900 << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
1906 //=============================================================================
1908 * TransformLikeOtherCopy
1910 //=============================================================================
1911 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TransformLikeOtherCopy
1912 (Handle(GEOM_Object) theObject,
1913 Handle(GEOM_Object) theSample)
1917 if (theObject.IsNull() || theSample.IsNull()) return NULL;
1919 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
1920 if (aLastFunction.IsNull()) return NULL; // There is no function which creates an object to be transformed
1922 Handle(GEOM_Function) aSampleFunc = theSample->GetLastFunction();
1923 if (aSampleFunc.IsNull()) return NULL; // There is no function which creates a sample object
1925 // Add a new Copy object
1926 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1928 // Add a transform function (depends on theSample function)
1929 Handle(GEOM_Function) aFunction =
1930 aCopy->AddFunction(aSampleFunc->GetDriverGUID(), aSampleFunc->GetType());
1931 if (aFunction.IsNull()) return NULL;
1933 // Check if the function is set correctly
1934 if (aFunction->GetDriverGUID() != aSampleFunc->GetDriverGUID()) return NULL;
1936 if (aSampleFunc->GetDriverGUID() == GEOMImpl_TranslateDriver::GetID()) {
1937 switch (aSampleFunc->GetType()) {
1940 GEOMImpl_ITranslate aRI_sample (aSampleFunc);
1941 GEOMImpl_ITranslate aRI_target (aFunction);
1943 aRI_target.SetVector(aRI_sample.GetVector());
1944 aRI_target.SetStep1(aRI_sample.GetStep1());
1945 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
1947 aRI_target.SetOriginal(aLastFunction);
1952 GEOMImpl_ITranslate aRI_sample (aSampleFunc);
1953 GEOMImpl_ITranslate aRI_target (aFunction);
1955 aRI_target.SetVector(aRI_sample.GetVector());
1956 aRI_target.SetStep1(aRI_sample.GetStep1());
1957 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
1959 aRI_target.SetVector2(aRI_sample.GetVector2());
1960 aRI_target.SetStep2(aRI_sample.GetStep2());
1961 aRI_target.SetNbIter2(aRI_sample.GetNbIter2());
1963 aRI_target.SetOriginal(aLastFunction);
1968 SetErrorCode("Not implemented case of TransformLikeOtherCopy");
1973 else if (aSampleFunc->GetDriverGUID() == GEOMImpl_RotateDriver::GetID()) {
1974 switch (aSampleFunc->GetType()) {
1977 GEOMImpl_IRotate aRI_sample (aSampleFunc);
1978 GEOMImpl_IRotate aRI_target (aFunction);
1980 aRI_target.SetAxis(aRI_sample.GetAxis());
1981 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
1983 aRI_target.SetOriginal(aLastFunction);
1988 GEOMImpl_IRotate aRI_sample (aSampleFunc);
1989 GEOMImpl_IRotate aRI_target (aFunction);
1991 aRI_target.SetAxis(aRI_sample.GetAxis());
1993 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
1994 aRI_target.SetNbIter2(aRI_sample.GetNbIter2());
1996 aRI_target.SetAngle(aRI_sample.GetAngle());
1997 aRI_target.SetStep(aRI_sample.GetStep());
1999 aRI_target.SetDir2(aRI_sample.GetDir2());
2001 aRI_target.SetOriginal(aLastFunction);
2004 case ROTATE_THREE_POINTS_COPY:
2006 GEOMImpl_IRotate aRI_sample (aSampleFunc);
2007 GEOMImpl_IRotate aRI_target (aFunction);
2009 aRI_target.SetCentPoint(aRI_sample.GetCentPoint());
2010 aRI_target.SetPoint1(aRI_sample.GetPoint1());
2011 aRI_target.SetPoint2(aRI_sample.GetPoint2());
2013 aRI_target.SetOriginal(aLastFunction);
2018 SetErrorCode("Not implemented case of TransformLikeOtherCopy");
2024 SetErrorCode("Not implemented case of TransformLikeOtherCopy");
2028 // Compute the transformation
2030 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2033 if (!GetSolver()->ComputeFunction(aFunction)) {
2034 SetErrorCode("Driver failed");
2038 catch (Standard_Failure) {
2039 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2040 SetErrorCode(aFail->GetMessageString());
2044 //Make a Python command
2045 //GEOM::TPythonDump(aFunction) << aCopy << " = geompy.TransformLikeOtherCopy("
2046 // << theObject << ", " << theSample << ")";