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::ProjectShapeCopy
1185 (Handle(GEOM_Object) theSource, Handle(GEOM_Object) theTarget)
1189 if (theSource.IsNull() || theTarget.IsNull()) return NULL;
1191 Handle(GEOM_Function) aLastFunction = theSource->GetLastFunction();
1192 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be projected
1194 //Add a new Projection object
1195 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), GEOM_PROJECTION);
1197 //Add a Projection function
1198 Handle(GEOM_Function) aFunction =
1199 aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), PROJECTION_COPY);
1201 //Check if the function is set correctly
1202 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
1204 GEOMImpl_IMirror aTI (aFunction);
1205 aTI.SetPlane(theTarget->GetLastFunction());
1206 aTI.SetOriginal(aLastFunction);
1208 //Compute the Projection
1210 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1213 if (!GetSolver()->ComputeFunction(aFunction)) {
1214 SetErrorCode("Projection driver failed");
1218 catch (Standard_Failure) {
1219 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1220 SetErrorCode(aFail->GetMessageString());
1224 //Make a Python command
1225 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeProjection("
1226 << theSource << ", " << theTarget << ")";
1233 //=============================================================================
1237 //=============================================================================
1238 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShape
1239 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, double theFactor)
1243 if (theObject.IsNull()) return NULL;
1245 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1246 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1248 //Add a scale function
1249 Handle(GEOM_Function) aFunction =
1250 theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE);
1251 if (aFunction.IsNull()) return NULL;
1253 //Check if the function is set correctly
1254 if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1257 GEOMImpl_IScale aTI (aFunction);
1258 aTI.SetShape(anOriginal);
1259 aTI.SetFactor(theFactor);
1261 // Set point argument
1262 if (!thePoint.IsNull()) {
1263 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1269 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1272 if (!GetSolver()->ComputeFunction(aFunction)) {
1273 SetErrorCode("Scale driver failed");
1277 catch (Standard_Failure) {
1278 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1279 SetErrorCode(aFail->GetMessageString());
1283 //Make a Python command
1284 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.ScaleShape("
1285 << theObject << ", " << thePoint << ", " << theFactor << ")";
1291 //=============================================================================
1295 //=============================================================================
1296 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeCopy
1297 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, double theFactor)
1301 if (theObject.IsNull()) return NULL;
1303 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1304 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1306 //Add a new Copy object
1307 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1309 //Add a scale function
1310 Handle(GEOM_Function) aFunction =
1311 aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_COPY);
1312 if (aFunction.IsNull()) return NULL;
1314 //Check if the function is set correctly
1315 if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1318 GEOMImpl_IScale aTI (aFunction);
1319 aTI.SetShape(anOriginal);
1320 aTI.SetFactor(theFactor);
1322 // Set point argument
1323 if (!thePoint.IsNull()) {
1324 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1330 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1333 if (!GetSolver()->ComputeFunction(aFunction)) {
1334 SetErrorCode("Scale driver failed");
1338 catch (Standard_Failure) {
1339 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1340 SetErrorCode(aFail->GetMessageString());
1344 //Make a Python command
1345 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeScaleTransform("
1346 << theObject << ", " << thePoint << ", " << theFactor << ")";
1352 //=============================================================================
1354 * ScaleShapeAlongAxes
1356 //=============================================================================
1357 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeAlongAxes (Handle(GEOM_Object) theObject,
1358 Handle(GEOM_Object) thePoint,
1366 if (theObject.IsNull()) return NULL;
1368 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1369 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1371 //Add a scale function
1372 Handle(GEOM_Object) aCopy; //Add a new Copy object
1373 Handle(GEOM_Function) aFunction;
1375 aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1376 aFunction = aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES_COPY);
1379 aFunction = theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES);
1381 if (aFunction.IsNull()) return NULL;
1383 //Check if the function is set correctly
1384 if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1387 GEOMImpl_IScale aTI (aFunction);
1388 aTI.SetShape(anOriginal);
1389 aTI.SetFactorX(theFactorX);
1390 aTI.SetFactorY(theFactorY);
1391 aTI.SetFactorZ(theFactorZ);
1393 // Set point (optional argument)
1394 if (!thePoint.IsNull()) {
1395 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1401 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1404 if (!GetSolver()->ComputeFunction(aFunction)) {
1405 SetErrorCode("Scale driver failed");
1409 catch (Standard_Failure) {
1410 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1411 SetErrorCode(aFail->GetMessageString());
1417 //Make a Python command
1419 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeScaleAlongAxes("
1420 << theObject << ", " << thePoint << ", "
1421 << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")";
1425 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.ScaleShapeAlongAxes("
1426 << theObject << ", " << thePoint << ", "
1427 << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")";
1431 //=============================================================================
1435 //=============================================================================
1436 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShape
1437 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theStartLCS, Handle(GEOM_Object) theEndLCS)
1441 if (theObject.IsNull() || theEndLCS.IsNull()) return NULL;
1443 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1444 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1446 //Add a Position function
1447 Standard_Integer aType = POSITION_SHAPE;
1448 if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL;
1450 Handle(GEOM_Function) aFunction =
1451 theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
1452 if (aFunction.IsNull()) return NULL;
1454 //Check if the function is set correctly
1455 if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1457 //Set operation arguments
1458 GEOMImpl_IPosition aTI (aFunction);
1459 aTI.SetShape(anOriginal);
1460 aTI.SetEndLCS(theEndLCS->GetLastFunction());
1461 if (!theStartLCS.IsNull())
1462 aTI.SetStartLCS(theObject == theStartLCS ? anOriginal : theStartLCS->GetLastFunction());
1464 //Compute the Position
1466 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1469 if (!GetSolver()->ComputeFunction(aFunction)) {
1470 SetErrorCode("Position driver failed");
1474 catch (Standard_Failure) {
1475 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1476 SetErrorCode(aFail->GetMessageString());
1480 //Make a Python command
1481 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.PositionShape("
1482 << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
1488 //=============================================================================
1492 //=============================================================================
1493 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShapeCopy
1494 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theStartLCS, Handle(GEOM_Object) theEndLCS)
1498 if (theObject.IsNull() || theEndLCS.IsNull()) return NULL;
1500 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1501 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1503 //Add a new Copy object
1504 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1506 //Add a position function
1507 Standard_Integer aType = POSITION_SHAPE_COPY;
1508 if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL_COPY;
1510 Handle(GEOM_Function) aFunction =
1511 aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
1512 if (aFunction.IsNull()) return NULL;
1514 //Check if the function is set correctly
1515 if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1517 GEOMImpl_IPosition aTI (aFunction);
1518 aTI.SetShape(anOriginal);
1519 aTI.SetEndLCS(theEndLCS->GetLastFunction());
1520 if (!theStartLCS.IsNull())
1521 aTI.SetStartLCS(theStartLCS->GetLastFunction());
1523 //Compute the position
1525 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1528 if (!GetSolver()->ComputeFunction(aFunction)) {
1529 SetErrorCode("Position driver failed");
1533 catch (Standard_Failure) {
1534 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1535 SetErrorCode(aFail->GetMessageString());
1539 //Make a Python command
1540 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakePosition("
1541 << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
1547 //=============================================================================
1551 //=============================================================================
1552 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionAlongPath
1553 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePath,
1554 double theDistance, bool theCopy, bool theReverse)
1558 if (theObject.IsNull() || thePath.IsNull()) return NULL;
1560 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1561 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1563 //Add a position function
1564 Handle(GEOM_Function) aFunction;
1565 Handle(GEOM_Object) aCopy;
1568 aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1569 aFunction = aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
1572 aFunction = theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
1574 if (aFunction.IsNull()) return NULL;
1576 //Check if the function is set correctly
1577 if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1579 GEOMImpl_IPosition aTI (aFunction);
1580 aTI.SetShape(anOriginal);
1581 aTI.SetPath(thePath->GetLastFunction());
1582 aTI.SetDistance(theDistance);
1583 aTI.SetReverse(theReverse);
1585 //Compute the position
1587 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1590 if (!GetSolver()->ComputeFunction(aFunction)) {
1591 SetErrorCode("Position driver failed");
1595 catch (Standard_Failure) {
1596 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1597 SetErrorCode(aFail->GetMessageString());
1601 //Make a Python command
1603 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.PositionAlongPath("
1604 << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
1609 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.PositionAlongPath("
1610 << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
1616 //=============================================================================
1620 //=============================================================================
1621 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate (Handle(GEOM_Object) theObject,
1622 Handle(GEOM_Object) theAxis,
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 // Get last functions of the arguments
1633 Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
1635 //Add a rotate function
1636 aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE);
1638 if (aFunction.IsNull()) return NULL;
1640 //Check if the function is set correctly
1641 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1643 GEOMImpl_IRotate aRI(aFunction);
1645 aRI.SetOriginal(aLastFunction);
1646 aRI.SetAngle(theAngle);
1648 //Compute the translation
1650 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1653 if (!GetSolver()->ComputeFunction(aFunction)) {
1654 SetErrorCode("Rotate driver failed");
1658 catch (Standard_Failure) {
1659 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1660 SetErrorCode(aFail->GetMessageString());
1664 //Make a Python command
1665 GEOM::TPythonDump(aFunction) << "geompy.Rotate(" << theObject
1666 << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
1672 //=============================================================================
1676 //=============================================================================
1677 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateCopy (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis, double theAngle)
1681 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1683 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1684 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1686 //Add a new Copy object
1687 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1689 //Add a rotate function
1690 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_COPY);
1691 if (aFunction.IsNull()) return NULL;
1693 //Check if the function is set correctly
1694 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1696 GEOMImpl_IRotate aRI(aFunction);
1697 aRI.SetAxis(theAxis->GetLastFunction());
1698 aRI.SetOriginal(aLastFunction);
1699 aRI.SetAngle(theAngle);
1701 //Compute the translation
1703 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1706 if (!GetSolver()->ComputeFunction(aFunction)) {
1707 SetErrorCode("Rotate driver failed");
1711 catch (Standard_Failure) {
1712 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1713 SetErrorCode(aFail->GetMessageString());
1717 //Make a Python command
1718 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotation(" << theObject
1719 << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
1725 //=============================================================================
1729 //=============================================================================
1730 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate1D (Handle(GEOM_Object) theObject,
1731 Handle(GEOM_Object) theAxis,
1732 Standard_Integer theNbTimes)
1736 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1738 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1739 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1741 //Add a new Copy object
1742 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1744 //Add a rotate function
1745 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_1D);
1746 if (aFunction.IsNull()) return NULL;
1748 //Check if the function is set correctly
1749 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1751 GEOMImpl_IRotate aRI(aFunction);
1752 aRI.SetOriginal(aLastFunction);
1753 aRI.SetAxis(theAxis->GetLastFunction());
1754 aRI.SetNbIter1(theNbTimes);
1756 //Compute the translation
1758 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1761 if (!GetSolver()->ComputeFunction(aFunction)) {
1762 SetErrorCode("Rotate driver failed");
1766 catch (Standard_Failure) {
1767 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1768 SetErrorCode(aFail->GetMessageString());
1772 //Make a Python command
1773 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate1D("
1774 << theObject << ", " << theAxis << ", " << theNbTimes << ")";
1780 //=============================================================================
1784 //=============================================================================
1785 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate2D (Handle(GEOM_Object) theObject,
1786 Handle(GEOM_Object) theAxis,
1788 Standard_Integer theNbTimes1,
1790 Standard_Integer theNbTimes2)
1794 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1796 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1797 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1799 //Add a new Copy object
1800 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1802 //Add a rotate function
1803 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_2D);
1804 if (aFunction.IsNull()) return NULL;
1806 //Check if the function is set correctly
1807 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1809 GEOMImpl_IRotate aRI(aFunction);
1810 aRI.SetAxis(theAxis->GetLastFunction());
1811 aRI.SetOriginal(aLastFunction);
1812 aRI.SetNbIter1(theNbTimes1);
1813 aRI.SetNbIter2(theNbTimes2);
1814 aRI.SetAngle(theAngle);
1815 aRI.SetStep(theStep);
1817 //Compute the translation
1819 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1822 if (!GetSolver()->ComputeFunction(aFunction)) {
1823 SetErrorCode("Rotate driver failed");
1827 catch (Standard_Failure) {
1828 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1829 SetErrorCode(aFail->GetMessageString());
1833 //Make a Python command
1834 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate2D("
1835 << theObject << ", " << theAxis << ", " << theAngle << ", "
1836 << theNbTimes1 << ", " << theStep << ", " << theNbTimes2 << ")";
1842 //=============================================================================
1846 //=============================================================================
1847 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePoints (Handle(GEOM_Object) theObject,
1848 Handle(GEOM_Object) theCentPoint,
1849 Handle(GEOM_Object) thePoint1,
1850 Handle(GEOM_Object) thePoint2)
1854 if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1856 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1857 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1859 // Get last functions of the arguments
1860 Handle(GEOM_Function) aCPF = theCentPoint->GetLastFunction();
1861 Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction();
1862 Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction();
1865 //Add a rotate function
1866 aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS);
1868 if (aFunction.IsNull()) return NULL;
1870 //Check if the function is set correctly
1871 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1873 GEOMImpl_IRotate aRI(aFunction);
1874 aRI.SetCentPoint(aCPF);
1875 aRI.SetPoint1(aP1F);
1876 aRI.SetPoint2(aP2F);
1877 aRI.SetOriginal(aLastFunction);
1879 //Compute the translation
1881 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1884 if (!GetSolver()->ComputeFunction(aFunction)) {
1885 SetErrorCode("Rotate driver failed");
1889 catch (Standard_Failure) {
1890 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1891 SetErrorCode(aFail->GetMessageString());
1895 //Make a Python command
1896 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.RotateThreePoints(" << theObject
1897 << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
1903 //=============================================================================
1905 * RotateThreePointsCopy
1907 //=============================================================================
1908 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePointsCopy (Handle(GEOM_Object) theObject,
1909 Handle(GEOM_Object) theCentPoint,
1910 Handle(GEOM_Object) thePoint1,
1911 Handle(GEOM_Object) thePoint2)
1915 if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1917 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1918 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1920 //Add a new Copy object
1921 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1923 //Add a rotate function
1924 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS_COPY);
1925 if (aFunction.IsNull()) return NULL;
1927 //Check if the function is set correctly
1928 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1930 GEOMImpl_IRotate aRI(aFunction);
1931 aRI.SetCentPoint(theCentPoint->GetLastFunction());
1932 aRI.SetPoint1(thePoint1->GetLastFunction());
1933 aRI.SetPoint2(thePoint2->GetLastFunction());
1934 aRI.SetOriginal(aLastFunction);
1936 //Compute the translation
1938 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1941 if (!GetSolver()->ComputeFunction(aFunction)) {
1942 SetErrorCode("Rotate driver failed");
1946 catch (Standard_Failure) {
1947 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1948 SetErrorCode(aFail->GetMessageString());
1952 //Make a Python command
1953 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotationThreePoints(" << theObject
1954 << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
1960 //=============================================================================
1962 * TransformLikeOtherCopy
1964 //=============================================================================
1965 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TransformLikeOtherCopy
1966 (Handle(GEOM_Object) theObject,
1967 Handle(GEOM_Object) theSample)
1971 if (theObject.IsNull() || theSample.IsNull()) return NULL;
1973 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
1974 if (aLastFunction.IsNull()) return NULL; // There is no function which creates an object to be transformed
1976 Handle(GEOM_Function) aSampleFunc = theSample->GetLastFunction();
1977 if (aSampleFunc.IsNull()) return NULL; // There is no function which creates a sample object
1979 // Add a new Copy object
1980 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1982 // Add a transform function (depends on theSample function)
1983 Handle(GEOM_Function) aFunction =
1984 aCopy->AddFunction(aSampleFunc->GetDriverGUID(), aSampleFunc->GetType());
1985 if (aFunction.IsNull()) return NULL;
1987 // Check if the function is set correctly
1988 if (aFunction->GetDriverGUID() != aSampleFunc->GetDriverGUID()) return NULL;
1990 if (aSampleFunc->GetDriverGUID() == GEOMImpl_TranslateDriver::GetID()) {
1991 switch (aSampleFunc->GetType()) {
1994 GEOMImpl_ITranslate aRI_sample (aSampleFunc);
1995 GEOMImpl_ITranslate aRI_target (aFunction);
1997 aRI_target.SetVector(aRI_sample.GetVector());
1998 aRI_target.SetStep1(aRI_sample.GetStep1());
1999 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2001 aRI_target.SetOriginal(aLastFunction);
2006 GEOMImpl_ITranslate aRI_sample (aSampleFunc);
2007 GEOMImpl_ITranslate aRI_target (aFunction);
2009 aRI_target.SetVector(aRI_sample.GetVector());
2010 aRI_target.SetStep1(aRI_sample.GetStep1());
2011 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2013 aRI_target.SetVector2(aRI_sample.GetVector2());
2014 aRI_target.SetStep2(aRI_sample.GetStep2());
2015 aRI_target.SetNbIter2(aRI_sample.GetNbIter2());
2017 aRI_target.SetOriginal(aLastFunction);
2022 SetErrorCode("Not implemented case of TransformLikeOtherCopy");
2027 else if (aSampleFunc->GetDriverGUID() == GEOMImpl_RotateDriver::GetID()) {
2028 switch (aSampleFunc->GetType()) {
2031 GEOMImpl_IRotate aRI_sample (aSampleFunc);
2032 GEOMImpl_IRotate aRI_target (aFunction);
2034 aRI_target.SetAxis(aRI_sample.GetAxis());
2035 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2037 aRI_target.SetOriginal(aLastFunction);
2042 GEOMImpl_IRotate aRI_sample (aSampleFunc);
2043 GEOMImpl_IRotate aRI_target (aFunction);
2045 aRI_target.SetAxis(aRI_sample.GetAxis());
2047 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2048 aRI_target.SetNbIter2(aRI_sample.GetNbIter2());
2050 aRI_target.SetAngle(aRI_sample.GetAngle());
2051 aRI_target.SetStep(aRI_sample.GetStep());
2053 aRI_target.SetDir2(aRI_sample.GetDir2());
2055 aRI_target.SetOriginal(aLastFunction);
2058 case ROTATE_THREE_POINTS_COPY:
2060 GEOMImpl_IRotate aRI_sample (aSampleFunc);
2061 GEOMImpl_IRotate aRI_target (aFunction);
2063 aRI_target.SetCentPoint(aRI_sample.GetCentPoint());
2064 aRI_target.SetPoint1(aRI_sample.GetPoint1());
2065 aRI_target.SetPoint2(aRI_sample.GetPoint2());
2067 aRI_target.SetOriginal(aLastFunction);
2072 SetErrorCode("Not implemented case of TransformLikeOtherCopy");
2078 SetErrorCode("Not implemented case of TransformLikeOtherCopy");
2082 // Compute the transformation
2084 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2087 if (!GetSolver()->ComputeFunction(aFunction)) {
2088 SetErrorCode("Driver failed");
2092 catch (Standard_Failure) {
2093 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2094 SetErrorCode(aFail->GetMessageString());
2098 //Make a Python command
2099 //GEOM::TPythonDump(aFunction) << aCopy << " = geompy.TransformLikeOtherCopy("
2100 // << theObject << ", " << theSample << ")";