1 // Copyright (C) 2007-2011 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 <GEOMImpl_TranslateDriver.hxx>
27 #include <GEOMImpl_MirrorDriver.hxx>
28 #include <GEOMImpl_ProjectionDriver.hxx>
29 #include <GEOMImpl_OffsetDriver.hxx>
30 #include <GEOMImpl_ScaleDriver.hxx>
31 #include <GEOMImpl_RotateDriver.hxx>
32 #include <GEOMImpl_PositionDriver.hxx>
34 #include <GEOMImpl_ITranslate.hxx>
35 #include <GEOMImpl_IMirror.hxx>
36 #include <GEOMImpl_IOffset.hxx>
37 #include <GEOMImpl_IScale.hxx>
38 #include <GEOMImpl_IRotate.hxx>
39 #include <GEOMImpl_IPosition.hxx>
41 #include <GEOMImpl_Types.hxx>
43 #include <GEOM_Function.hxx>
44 #include <GEOM_PythonDump.hxx>
46 #include <Basics_OCCTVersion.hxx>
48 #include "utilities.h"
50 #include <Utils_ExceptHandlers.hxx>
52 #include <TFunction_DriverTable.hxx>
53 #include <TFunction_Driver.hxx>
54 #include <TFunction_Logbook.hxx>
55 #include <TDF_Tool.hxx>
57 #include <BRep_Tool.hxx>
58 #include <BRep_Builder.hxx>
61 #include <TopoDS_Edge.hxx>
62 #include <TopoDS_Vertex.hxx>
63 #include <TopoDS_Compound.hxx>
66 #include <gp_Trsf.hxx>
68 #include <StdFail_NotDone.hxx>
69 #include <Standard_Failure.hxx>
70 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
72 //=============================================================================
76 //=============================================================================
78 GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations (GEOM_Engine* theEngine, int theDocID)
79 : GEOM_IOperations(theEngine, theDocID)
81 MESSAGE("GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations");
84 //=============================================================================
88 //=============================================================================
90 GEOMImpl_ITransformOperations::~GEOMImpl_ITransformOperations()
92 MESSAGE("GEOMImpl_ITransformOperations::~GEOMImpl_ITransformOperations");
96 //=============================================================================
100 //=============================================================================
101 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPoints
102 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
106 if (theObject.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
108 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
109 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
111 // Get last functions of the arguments
112 Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction();
113 Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction();
115 //Add a translate function
116 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_TWO_POINTS);
118 if (aFunction.IsNull()) return NULL;
120 //Check if the function is set correctly
121 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
123 GEOMImpl_ITranslate aTI (aFunction);
126 aTI.SetOriginal(aLastFunction);
128 //Compute the translation
130 #if OCC_VERSION_LARGE > 0x06010000
133 if (!GetSolver()->ComputeFunction(aFunction)) {
134 SetErrorCode("Translation driver failed");
138 catch (Standard_Failure) {
139 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
140 SetErrorCode(aFail->GetMessageString());
144 //Make a Python command
145 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.TranslateTwoPoints("
146 << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
152 //=============================================================================
156 //=============================================================================
157 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZ
158 (Handle(GEOM_Object) theObject, double theX, double theY, double theZ)
162 if (theObject.IsNull()) return NULL;
164 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
165 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
167 //Add a translate function
168 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_XYZ);
170 if (aFunction.IsNull()) return NULL;
172 //Check if the function is set correctly
173 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
175 GEOMImpl_ITranslate aTI(aFunction);
179 aTI.SetOriginal(aLastFunction);
181 //Compute the translation
183 #if OCC_VERSION_LARGE > 0x06010000
186 if (!GetSolver()->ComputeFunction(aFunction)) {
187 SetErrorCode("Translation driver failed");
191 catch (Standard_Failure) {
192 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
193 SetErrorCode(aFail->GetMessageString());
197 //Make a Python command
198 GEOM::TPythonDump(aFunction) << "geompy.TranslateDXDYDZ("
199 << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
206 //=============================================================================
208 * TranslateTwoPointsCopy
210 //=============================================================================
211 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPointsCopy
212 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
216 if (theObject.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
218 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
219 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
221 //Add a new Copy object
222 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
224 //Add a translate function
225 Handle(GEOM_Function) aFunction =
226 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_TWO_POINTS_COPY);
228 //Check if the function is set correctly
229 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
231 GEOMImpl_ITranslate aTI(aFunction);
232 aTI.SetPoint1(thePoint1->GetLastFunction());
233 aTI.SetPoint2(thePoint2->GetLastFunction());
234 //aTI.SetShape(theObject->GetValue());
235 aTI.SetOriginal(aLastFunction);
237 //Compute the translation
239 #if OCC_VERSION_LARGE > 0x06010000
242 if (!GetSolver()->ComputeFunction(aFunction)) {
243 SetErrorCode("Translation driver failed");
247 catch (Standard_Failure) {
248 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
249 SetErrorCode(aFail->GetMessageString());
253 //Make a Python command
254 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationTwoPoints("
255 << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
261 //=============================================================================
263 * TranslateDXDYDZCopy
265 //=============================================================================
266 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZCopy
267 (Handle(GEOM_Object) theObject, double theX, double theY, double theZ)
271 if (theObject.IsNull()) return NULL;
273 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
274 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
276 //Add a new Copy object
277 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
279 //Add a translate function
280 Handle(GEOM_Function) aFunction =
281 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_XYZ_COPY);
283 //Check if the function is set correctly
284 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
286 GEOMImpl_ITranslate aTI(aFunction);
290 aTI.SetOriginal(aLastFunction);
292 //Compute the translation
294 #if OCC_VERSION_LARGE > 0x06010000
297 if (!GetSolver()->ComputeFunction(aFunction)) {
298 SetErrorCode("Translation driver failed");
302 catch (Standard_Failure) {
303 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
304 SetErrorCode(aFail->GetMessageString());
308 //Make a Python command
309 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslation("
310 << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
317 //=============================================================================
321 //=============================================================================
322 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVector
323 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector)
327 if (theObject.IsNull() || theVector.IsNull()) return NULL;
329 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
330 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
332 // Get last functions of the arguments
333 Handle(GEOM_Function) aVF = theVector->GetLastFunction();
335 //Add a translate function
336 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR);
338 if (aFunction.IsNull()) return NULL;
340 //Check if the function is set correctly
341 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
343 GEOMImpl_ITranslate aTI (aFunction);
345 aTI.SetOriginal(aLastFunction);
347 //Compute the translation
349 #if OCC_VERSION_LARGE > 0x06010000
352 if (!GetSolver()->ComputeFunction(aFunction)) {
353 SetErrorCode("Translation driver failed");
357 catch (Standard_Failure) {
358 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
359 SetErrorCode(aFail->GetMessageString());
363 //Make a Python command
364 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.TranslateVector("
365 << theObject << ", " << theVector << ")";
370 //=============================================================================
372 * TranslateVectorCopy
374 //=============================================================================
375 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorCopy
376 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector)
380 if (theObject.IsNull() || theVector.IsNull()) return NULL;
382 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
383 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
385 //Add a new Copy object
386 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
388 //Add a translate function
389 Handle(GEOM_Function) aFunction =
390 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_COPY);
392 //Check if the function is set correctly
393 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
395 GEOMImpl_ITranslate aTI(aFunction);
396 aTI.SetVector(theVector->GetLastFunction());
397 // aTI.SetShape(theObject->GetValue());
398 aTI.SetOriginal(aLastFunction);
400 //Compute the translation
402 #if OCC_VERSION_LARGE > 0x06010000
405 if (!GetSolver()->ComputeFunction(aFunction)) {
406 SetErrorCode("Translation driver failed");
410 catch (Standard_Failure) {
411 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
412 SetErrorCode(aFail->GetMessageString());
416 //Make a Python command
417 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationVector("
418 << theObject << ", " << theVector << ")";
424 //=============================================================================
426 * TranslateVectorDistance
428 //=============================================================================
429 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorDistance
430 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector, double theDistance, bool theCopy)
434 if (theObject.IsNull() || theVector.IsNull()) return NULL;
436 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
437 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
439 Handle(GEOM_Object) aCopy; //Add a new Copy object
440 Handle(GEOM_Function) aFunction;
442 //Add a translate function
444 aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
445 aFunction = aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_DISTANCE);
448 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_DISTANCE);
450 if (aFunction.IsNull()) return NULL;
452 //Check if the function is set correctly
453 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
455 GEOMImpl_ITranslate aTI(aFunction);
456 aTI.SetVector(theVector->GetLastFunction());
457 aTI.SetDistance(theDistance);
458 // aTI.SetShape(theObject->GetValue());
459 aTI.SetOriginal(aLastFunction);
461 //Compute the translation
463 #if OCC_VERSION_LARGE > 0x06010000
466 if (!GetSolver()->ComputeFunction(aFunction)) {
467 SetErrorCode("Translation driver failed");
471 catch (Standard_Failure) {
472 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
473 SetErrorCode(aFail->GetMessageString());
477 //Make a Python command
479 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationVectorDistance("
480 << theObject << ", " << theVector << ", " << theDistance << ")";
485 GEOM::TPythonDump(aFunction) << "geompy.TranslateVectorDistance("
486 << theObject << ", " << theVector << ", " << theDistance << ", " << theCopy << ")";
491 //=============================================================================
495 //=============================================================================
496 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate1D
497 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector,
498 double theStep, Standard_Integer theNbTimes)
502 if (theObject.IsNull() || theVector.IsNull()) return NULL;
504 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
505 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
507 //Add a new Copy object
508 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
510 //Add a translate function
511 Handle(GEOM_Function) aFunction =
512 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_1D);
514 //Check if the function is set correctly
515 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
517 GEOMImpl_ITranslate aTI(aFunction);
518 aTI.SetVector(theVector->GetLastFunction());
519 aTI.SetOriginal(aLastFunction);
520 aTI.SetStep1(theStep);
521 aTI.SetNbIter1(theNbTimes);
523 //Compute the translation
525 #if OCC_VERSION_LARGE > 0x06010000
528 if (!GetSolver()->ComputeFunction(aFunction)) {
529 SetErrorCode("Translation driver failed");
533 catch (Standard_Failure) {
534 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
535 SetErrorCode(aFail->GetMessageString());
539 //Make a Python command
540 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMultiTranslation1D("
541 << theObject << ", " << theVector << ", " << theStep << ", " << theNbTimes << ")";
547 //=============================================================================
551 //=============================================================================
552 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate2D (Handle(GEOM_Object) theObject,
553 Handle(GEOM_Object) theVector,
555 Standard_Integer theNbTimes1,
556 Handle(GEOM_Object) theVector2,
558 Standard_Integer theNbTimes2)
562 if (theObject.IsNull() || theVector.IsNull() || theVector2.IsNull()) return NULL;
564 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
565 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
567 //Add a new Copy object
568 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
570 //Add a translate function
571 Handle(GEOM_Function) aFunction =
572 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_2D);
574 //Check if the function is set correctly
575 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
577 GEOMImpl_ITranslate aTI (aFunction);
578 aTI.SetVector(theVector->GetLastFunction());
579 aTI.SetVector2(theVector2->GetLastFunction());
580 aTI.SetOriginal(aLastFunction);
581 aTI.SetStep1(theStep1);
582 aTI.SetNbIter1(theNbTimes1);
583 aTI.SetStep2(theStep2);
584 aTI.SetNbIter2(theNbTimes2);
586 //Compute the translation
588 #if OCC_VERSION_LARGE > 0x06010000
591 if (!GetSolver()->ComputeFunction(aFunction)) {
592 SetErrorCode("Translation driver failed");
596 catch (Standard_Failure) {
597 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
598 SetErrorCode(aFail->GetMessageString());
602 //Make a Python command
603 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMultiTranslation2D("
604 << theObject << ", " << theVector << ", " << theStep1 << ", " << theNbTimes1
605 << ", " << theVector2 << ", " << theStep2 << ", " << theNbTimes2 << ")";
611 //=============================================================================
615 //=============================================================================
617 TopoDS_Shape GEOMImpl_ITransformOperations::TranslateShape1D (const TopoDS_Shape& theShape,
618 GEOMImpl_ITranslate* theTI)
623 Handle(GEOM_Function) aVector = theTI->GetVector();
624 if (aVector.IsNull()) {
625 StdFail_NotDone::Raise("Invalid object is given for vector argument");
627 TopoDS_Shape aV = aVector->GetValue();
628 if (aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) {
629 StdFail_NotDone::Raise("Invalid object is given for vector argument");
631 TopoDS_Edge anEdge = TopoDS::Edge(aV);
633 gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
634 gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
635 if (aP1.Distance(aP2) < gp::Resolution()) {
636 StdFail_NotDone::Raise("Invalid object is given for vector argument");
640 Standard_Real step = theTI->GetStep1();
641 Standard_Integer nbtimes = theTI->GetNbIter1();
643 // Make multi-translation
646 TopoDS_Compound aCompound;
648 B.MakeCompound(aCompound);
650 gp_Vec Vec (aP1, aP2);
653 TopLoc_Location aLocOrig = theShape.Location();
654 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
656 for (int i = 0; i < nbtimes; i++) {
657 aVec = Vec * (i * step);
658 aTrsf.SetTranslation(aVec);
659 //NPAL18620: performance problem: multiple locations are accumulated
660 // in shape and need a great time to process
661 //BRepBuilderAPI_Transform aTransformation(theShape, aTrsf, Standard_False);
662 //B.Add(aCompound, aTransformation.Shape());
663 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
664 B.Add(aCompound, theShape.Located(aLocRes));
672 //=============================================================================
676 //=============================================================================
678 TopoDS_Shape GEOMImpl_ITransformOperations::TranslateShape2D (const TopoDS_Shape& theShape,
679 GEOMImpl_ITranslate* theTI)
684 Handle(GEOM_Function) aVector1 = theTI->GetVector();
685 Handle(GEOM_Function) aVector2 = theTI->GetVector2();
687 if (aVector1.IsNull() || aVector2.IsNull()) {
688 StdFail_NotDone::Raise("Invalid object is given for vector argument");
691 TopoDS_Shape aV1 = aVector1->GetValue();
692 TopoDS_Shape aV2 = aVector2->GetValue();
694 if (aV1.IsNull() || aV1.ShapeType() != TopAbs_EDGE ||
695 aV2.IsNull() || aV2.ShapeType() != TopAbs_EDGE) {
696 StdFail_NotDone::Raise("Invalid object is given for vector argument");
699 TopoDS_Edge anEdge1 = TopoDS::Edge(aV1);
700 TopoDS_Edge anEdge2 = TopoDS::Edge(aV2);
702 gp_Pnt aP11 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge1));
703 gp_Pnt aP12 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge1));
704 gp_Pnt aP21 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge2));
705 gp_Pnt aP22 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge2));
707 if (aP11.Distance(aP12) < gp::Resolution() ||
708 aP21.Distance(aP22) < gp::Resolution()) {
709 StdFail_NotDone::Raise("Invalid object is given for vector argument");
712 gp_Vec Vec1 (aP11, aP12);
713 gp_Vec Vec2 (aP21, aP22);
719 Standard_Real step1 = theTI->GetStep1(), step2 = theTI->GetStep2();
720 Standard_Integer nbtimes1 = theTI->GetNbIter1(), nbtimes2 = theTI->GetNbIter2();
722 // Make multi-translation
725 Standard_Real DX, DY, DZ;
726 TopoDS_Compound aCompound;
728 B.MakeCompound(aCompound);
730 TopLoc_Location aLocOrig = theShape.Location();
731 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
733 for (int i = 0; i < nbtimes1; i++) {
734 for (int j = 0; j < nbtimes2; j++) {
735 DX = i * step1 * Vec1.X() + j * step2 * Vec2.X();
736 DY = i * step1 * Vec1.Y() + j * step2 * Vec2.Y();
737 DZ = i * step1 * Vec1.Z() + j * step2 * Vec2.Z();
738 aVec.SetCoord(DX, DY, DZ);
739 aTrsf.SetTranslation(aVec);
740 //NPAL18620: performance problem: multiple locations are accumulated
741 // in shape and need a great time to process
742 //BRepBuilderAPI_Transform aBRepTransformation(theShape, aTrsf, Standard_False);
743 //B.Add(aCompound, aBRepTransformation.Shape());
744 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
745 B.Add(aCompound, theShape.Located(aLocRes));
754 //=============================================================================
758 //=============================================================================
759 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlane
760 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePlane)
764 if (theObject.IsNull() || thePlane.IsNull()) return NULL;
766 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
767 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
769 // Get last functions of the arguments
770 Handle(GEOM_Function) aPF = thePlane->GetLastFunction();
772 //Add a mirror function
773 Handle(GEOM_Function) aFunction =
774 theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_PLANE);
775 if (aFunction.IsNull()) return NULL;
777 //Check if the function is set correctly
778 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
780 GEOMImpl_IMirror aTI (aFunction);
782 aTI.SetOriginal(aLastFunction);
786 #if OCC_VERSION_LARGE > 0x06010000
789 if (!GetSolver()->ComputeFunction(aFunction)) {
790 SetErrorCode("Mirror driver failed");
794 catch (Standard_Failure) {
795 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
796 SetErrorCode(aFail->GetMessageString());
800 //Make a Python command
801 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorPlane("
802 << theObject << ", " << thePlane << ")";
808 //=============================================================================
812 //=============================================================================
813 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlaneCopy
814 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePlane)
818 if (theObject.IsNull() || thePlane.IsNull()) return NULL;
820 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
821 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
823 //Add a new Copy object
824 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
826 //Add a mirror function
827 Handle(GEOM_Function) aFunction =
828 aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_PLANE_COPY);
830 //Check if the function is set correctly
831 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
833 GEOMImpl_IMirror aTI (aFunction);
834 aTI.SetPlane(thePlane->GetLastFunction());
835 aTI.SetOriginal(aLastFunction);
839 #if OCC_VERSION_LARGE > 0x06010000
842 if (!GetSolver()->ComputeFunction(aFunction)) {
843 SetErrorCode("Mirror driver failed");
847 catch (Standard_Failure) {
848 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
849 SetErrorCode(aFail->GetMessageString());
853 //Make a Python command
854 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByPlane("
855 << theObject << ", " << thePlane << ")";
861 //=============================================================================
865 //=============================================================================
866 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPoint
867 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint)
871 if (theObject.IsNull() || thePoint.IsNull()) return NULL;
873 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
874 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
876 // Get last functions of the arguments
877 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
879 //Add a mirror function
880 Handle(GEOM_Function) aFunction =
881 theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_POINT);
882 if (aFunction.IsNull()) return NULL;
884 //Check if the function is set correctly
885 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
887 GEOMImpl_IMirror aTI (aFunction);
889 aTI.SetOriginal(aLastFunction);
893 #if OCC_VERSION_LARGE > 0x06010000
896 if (!GetSolver()->ComputeFunction(aFunction)) {
897 SetErrorCode("Mirror driver failed");
901 catch (Standard_Failure) {
902 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
903 SetErrorCode(aFail->GetMessageString());
907 //Make a Python command
908 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorPoint("
909 << theObject << ", " << thePoint << ")";
915 //=============================================================================
919 //=============================================================================
920 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPointCopy
921 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint)
925 if (theObject.IsNull() || thePoint.IsNull()) return NULL;
927 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
928 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
930 //Add a new Copy object
931 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
933 //Add a mirror function
934 Handle(GEOM_Function) aFunction =
935 aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_POINT_COPY);
937 //Check if the function is set correctly
938 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
940 GEOMImpl_IMirror aTI (aFunction);
941 aTI.SetPoint(thePoint->GetLastFunction());
942 aTI.SetOriginal(aLastFunction);
946 #if OCC_VERSION_LARGE > 0x06010000
949 if (!GetSolver()->ComputeFunction(aFunction)) {
950 SetErrorCode("Mirror driver failed");
954 catch (Standard_Failure) {
955 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
956 SetErrorCode(aFail->GetMessageString());
960 //Make a Python command
961 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByPoint("
962 << theObject << ", " << thePoint << ")";
968 //=============================================================================
972 //=============================================================================
973 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxis
974 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis)
978 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
980 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
981 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
983 // Get last functions of the arguments
984 Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
986 //Add a mirror function
987 Handle(GEOM_Function) aFunction =
988 theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_AXIS);
989 if (aFunction.IsNull()) return NULL;
991 //Check if the function is set correctly
992 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
994 GEOMImpl_IMirror aTI (aFunction);
996 aTI.SetOriginal(aLastFunction);
1000 #if OCC_VERSION_LARGE > 0x06010000
1003 if (!GetSolver()->ComputeFunction(aFunction)) {
1004 SetErrorCode("Mirror driver failed");
1008 catch (Standard_Failure) {
1009 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1010 SetErrorCode(aFail->GetMessageString());
1014 //Make a Python command
1015 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorAxis("
1016 << theObject << ", " << theAxis << ")";
1022 //=============================================================================
1026 //=============================================================================
1027 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxisCopy
1028 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis)
1032 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1034 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
1035 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
1037 //Add a new Copy object
1038 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1040 //Add a mirror function
1041 Handle(GEOM_Function) aFunction =
1042 aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_AXIS_COPY);
1044 //Check if the function is set correctly
1045 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
1047 GEOMImpl_IMirror aTI (aFunction);
1048 aTI.SetAxis(theAxis->GetLastFunction());
1049 aTI.SetOriginal(aLastFunction);
1051 //Compute the mirror
1053 #if OCC_VERSION_LARGE > 0x06010000
1056 if (!GetSolver()->ComputeFunction(aFunction)) {
1057 SetErrorCode("Mirror driver failed");
1061 catch (Standard_Failure) {
1062 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1063 SetErrorCode(aFail->GetMessageString());
1067 //Make a Python command
1068 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByAxis("
1069 << theObject << ", " << theAxis << ")";
1076 //=============================================================================
1080 //=============================================================================
1081 Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShape
1082 (Handle(GEOM_Object) theObject, double theOffset)
1086 if (theObject.IsNull()) return NULL;
1088 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1089 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
1091 //Add a new Offset function
1092 Handle(GEOM_Function) aFunction =
1093 theObject->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE);
1094 if (aFunction.IsNull()) return NULL;
1096 //Check if the function is set correctly
1097 if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
1099 GEOMImpl_IOffset aTI (aFunction);
1100 aTI.SetShape(anOriginal);
1101 aTI.SetValue(theOffset);
1103 //Compute the offset
1105 #if OCC_VERSION_LARGE > 0x06010000
1108 if (!GetSolver()->ComputeFunction(aFunction)) {
1109 SetErrorCode("Offset driver failed");
1113 catch (Standard_Failure) {
1114 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1115 SetErrorCode(aFail->GetMessageString());
1119 //Make a Python command
1120 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.OffsetShape("
1121 << theObject << ", " << theOffset << ")";
1127 //=============================================================================
1131 //=============================================================================
1132 Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShapeCopy
1133 (Handle(GEOM_Object) theObject, double theOffset)
1137 if (theObject.IsNull()) return NULL;
1139 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1140 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
1142 //Add a new Copy object
1143 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1145 //Add a new Offset function
1146 Handle(GEOM_Function) aFunction =
1147 aCopy->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE_COPY);
1148 if (aFunction.IsNull()) return NULL;
1150 //Check if the function is set correctly
1151 if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
1153 GEOMImpl_IOffset aTI (aFunction);
1154 aTI.SetShape(anOriginal);
1155 aTI.SetValue(theOffset);
1157 //Compute the offset
1159 #if OCC_VERSION_LARGE > 0x06010000
1162 if (!GetSolver()->ComputeFunction(aFunction)) {
1163 SetErrorCode("Offset driver failed");
1167 catch (Standard_Failure) {
1168 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1169 SetErrorCode(aFail->GetMessageString());
1173 //Make a Python command
1174 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeOffset("
1175 << theObject << ", " << theOffset << ")";
1182 //=============================================================================
1186 //=============================================================================
1187 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ProjectShapeCopy
1188 (Handle(GEOM_Object) theSource, Handle(GEOM_Object) theTarget)
1192 if (theSource.IsNull() || theTarget.IsNull()) return NULL;
1194 Handle(GEOM_Function) aLastFunction = theSource->GetLastFunction();
1195 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be projected
1197 //Add a new Projection object
1198 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), GEOM_PROJECTION);
1200 //Add a Projection function
1201 Handle(GEOM_Function) aFunction =
1202 aCopy->AddFunction(GEOMImpl_ProjectionDriver::GetID(), PROJECTION_COPY);
1204 //Check if the function is set correctly
1205 if (aFunction->GetDriverGUID() != GEOMImpl_ProjectionDriver::GetID()) return NULL;
1207 GEOMImpl_IMirror aTI (aFunction);
1208 aTI.SetPlane(theTarget->GetLastFunction());
1209 aTI.SetOriginal(aLastFunction);
1211 //Compute the Projection
1213 #if OCC_VERSION_LARGE > 0x06010000
1216 if (!GetSolver()->ComputeFunction(aFunction)) {
1217 SetErrorCode("Projection driver failed");
1221 catch (Standard_Failure) {
1222 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1223 SetErrorCode(aFail->GetMessageString());
1227 //Make a Python command
1228 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeProjection("
1229 << theSource << ", " << theTarget << ")";
1236 //=============================================================================
1240 //=============================================================================
1241 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShape
1242 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, double theFactor)
1246 if (theObject.IsNull()) return NULL;
1248 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1249 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1251 //Add a scale function
1252 Handle(GEOM_Function) aFunction =
1253 theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE);
1254 if (aFunction.IsNull()) return NULL;
1256 //Check if the function is set correctly
1257 if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1260 GEOMImpl_IScale aTI (aFunction);
1261 aTI.SetShape(anOriginal);
1262 aTI.SetFactor(theFactor);
1264 // Set point argument
1265 if (!thePoint.IsNull()) {
1266 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1272 #if OCC_VERSION_LARGE > 0x06010000
1275 if (!GetSolver()->ComputeFunction(aFunction)) {
1276 SetErrorCode("Scale driver failed");
1280 catch (Standard_Failure) {
1281 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1282 SetErrorCode(aFail->GetMessageString());
1286 //Make a Python command
1287 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.ScaleShape("
1288 << theObject << ", " << thePoint << ", " << theFactor << ")";
1294 //=============================================================================
1298 //=============================================================================
1299 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeCopy
1300 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, double theFactor)
1304 if (theObject.IsNull()) return NULL;
1306 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1307 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1309 //Add a new Copy object
1310 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1312 //Add a scale function
1313 Handle(GEOM_Function) aFunction =
1314 aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_COPY);
1315 if (aFunction.IsNull()) return NULL;
1317 //Check if the function is set correctly
1318 if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1321 GEOMImpl_IScale aTI (aFunction);
1322 aTI.SetShape(anOriginal);
1323 aTI.SetFactor(theFactor);
1325 // Set point argument
1326 if (!thePoint.IsNull()) {
1327 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1333 #if OCC_VERSION_LARGE > 0x06010000
1336 if (!GetSolver()->ComputeFunction(aFunction)) {
1337 SetErrorCode("Scale driver failed");
1341 catch (Standard_Failure) {
1342 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1343 SetErrorCode(aFail->GetMessageString());
1347 //Make a Python command
1348 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeScaleTransform("
1349 << theObject << ", " << thePoint << ", " << theFactor << ")";
1355 //=============================================================================
1357 * ScaleShapeAlongAxes
1359 //=============================================================================
1360 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeAlongAxes (Handle(GEOM_Object) theObject,
1361 Handle(GEOM_Object) thePoint,
1369 if (theObject.IsNull()) return NULL;
1371 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1372 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1374 //Add a scale function
1375 Handle(GEOM_Object) aCopy; //Add a new Copy object
1376 Handle(GEOM_Function) aFunction;
1378 aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1379 aFunction = aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES_COPY);
1382 aFunction = theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES);
1384 if (aFunction.IsNull()) return NULL;
1386 //Check if the function is set correctly
1387 if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1390 GEOMImpl_IScale aTI (aFunction);
1391 aTI.SetShape(anOriginal);
1392 aTI.SetFactorX(theFactorX);
1393 aTI.SetFactorY(theFactorY);
1394 aTI.SetFactorZ(theFactorZ);
1396 // Set point (optional argument)
1397 if (!thePoint.IsNull()) {
1398 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1404 #if OCC_VERSION_LARGE > 0x06010000
1407 if (!GetSolver()->ComputeFunction(aFunction)) {
1408 SetErrorCode("Scale driver failed");
1412 catch (Standard_Failure) {
1413 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1414 SetErrorCode(aFail->GetMessageString());
1420 //Make a Python command
1422 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeScaleAlongAxes("
1423 << theObject << ", " << thePoint << ", "
1424 << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")";
1428 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.ScaleShapeAlongAxes("
1429 << theObject << ", " << thePoint << ", "
1430 << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")";
1434 //=============================================================================
1438 //=============================================================================
1439 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShape
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 Position function
1450 Standard_Integer aType = POSITION_SHAPE;
1451 if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL;
1453 Handle(GEOM_Function) aFunction =
1454 theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
1455 if (aFunction.IsNull()) return NULL;
1457 //Check if the function is set correctly
1458 if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1460 //Set operation arguments
1461 GEOMImpl_IPosition aTI (aFunction);
1462 aTI.SetShape(anOriginal);
1463 aTI.SetEndLCS(theEndLCS->GetLastFunction());
1464 if (!theStartLCS.IsNull())
1465 aTI.SetStartLCS(theObject == theStartLCS ? anOriginal : theStartLCS->GetLastFunction());
1467 //Compute the Position
1469 #if OCC_VERSION_LARGE > 0x06010000
1472 if (!GetSolver()->ComputeFunction(aFunction)) {
1473 SetErrorCode("Position driver failed");
1477 catch (Standard_Failure) {
1478 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1479 SetErrorCode(aFail->GetMessageString());
1483 //Make a Python command
1484 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.PositionShape("
1485 << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
1491 //=============================================================================
1495 //=============================================================================
1496 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShapeCopy
1497 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theStartLCS, Handle(GEOM_Object) theEndLCS)
1501 if (theObject.IsNull() || theEndLCS.IsNull()) return NULL;
1503 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1504 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1506 //Add a new Copy object
1507 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1509 //Add a position function
1510 Standard_Integer aType = POSITION_SHAPE_COPY;
1511 if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL_COPY;
1513 Handle(GEOM_Function) aFunction =
1514 aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
1515 if (aFunction.IsNull()) return NULL;
1517 //Check if the function is set correctly
1518 if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1520 GEOMImpl_IPosition aTI (aFunction);
1521 aTI.SetShape(anOriginal);
1522 aTI.SetEndLCS(theEndLCS->GetLastFunction());
1523 if (!theStartLCS.IsNull())
1524 aTI.SetStartLCS(theStartLCS->GetLastFunction());
1526 //Compute the position
1528 #if OCC_VERSION_LARGE > 0x06010000
1531 if (!GetSolver()->ComputeFunction(aFunction)) {
1532 SetErrorCode("Position driver failed");
1536 catch (Standard_Failure) {
1537 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1538 SetErrorCode(aFail->GetMessageString());
1542 //Make a Python command
1543 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakePosition("
1544 << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
1550 //=============================================================================
1554 //=============================================================================
1555 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionAlongPath
1556 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePath,
1557 double theDistance, bool theCopy, bool theReverse)
1561 if (theObject.IsNull() || thePath.IsNull()) return NULL;
1563 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1564 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1566 //Add a position function
1567 Handle(GEOM_Function) aFunction;
1568 Handle(GEOM_Object) aCopy;
1571 aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1572 aFunction = aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
1575 aFunction = theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
1577 if (aFunction.IsNull()) return NULL;
1579 //Check if the function is set correctly
1580 if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1582 GEOMImpl_IPosition aTI (aFunction);
1583 aTI.SetShape(anOriginal);
1584 aTI.SetPath(thePath->GetLastFunction());
1585 aTI.SetDistance(theDistance);
1586 aTI.SetReverse(theReverse);
1588 //Compute the position
1590 #if OCC_VERSION_LARGE > 0x06010000
1593 if (!GetSolver()->ComputeFunction(aFunction)) {
1594 SetErrorCode("Position driver failed");
1598 catch (Standard_Failure) {
1599 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1600 SetErrorCode(aFail->GetMessageString());
1604 //Make a Python command
1606 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.PositionAlongPath("
1607 << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
1612 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.PositionAlongPath("
1613 << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
1619 //=============================================================================
1623 //=============================================================================
1624 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate (Handle(GEOM_Object) theObject,
1625 Handle(GEOM_Object) theAxis,
1630 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1632 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1633 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1635 // Get last functions of the arguments
1636 Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
1638 //Add a rotate function
1639 aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE);
1641 if (aFunction.IsNull()) return NULL;
1643 //Check if the function is set correctly
1644 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1646 GEOMImpl_IRotate aRI(aFunction);
1648 aRI.SetOriginal(aLastFunction);
1649 aRI.SetAngle(theAngle);
1651 //Compute the translation
1653 #if OCC_VERSION_LARGE > 0x06010000
1656 if (!GetSolver()->ComputeFunction(aFunction)) {
1657 SetErrorCode("Rotate driver failed");
1661 catch (Standard_Failure) {
1662 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1663 SetErrorCode(aFail->GetMessageString());
1667 //Make a Python command
1668 GEOM::TPythonDump(aFunction) << "geompy.Rotate(" << theObject
1669 << ", " << theAxis << ", " << theAngle * 180.0 / M_PI << "*math.pi/180.0)";
1675 //=============================================================================
1679 //=============================================================================
1680 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateCopy (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis, double theAngle)
1684 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1686 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1687 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1689 //Add a new Copy object
1690 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1692 //Add a rotate function
1693 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_COPY);
1694 if (aFunction.IsNull()) return NULL;
1696 //Check if the function is set correctly
1697 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1699 GEOMImpl_IRotate aRI(aFunction);
1700 aRI.SetAxis(theAxis->GetLastFunction());
1701 aRI.SetOriginal(aLastFunction);
1702 aRI.SetAngle(theAngle);
1704 //Compute the translation
1706 #if OCC_VERSION_LARGE > 0x06010000
1709 if (!GetSolver()->ComputeFunction(aFunction)) {
1710 SetErrorCode("Rotate driver failed");
1714 catch (Standard_Failure) {
1715 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1716 SetErrorCode(aFail->GetMessageString());
1720 //Make a Python command
1721 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotation(" << theObject
1722 << ", " << theAxis << ", " << theAngle * 180.0 / M_PI << "*math.pi/180.0)";
1728 //=============================================================================
1732 //=============================================================================
1733 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate1D (Handle(GEOM_Object) theObject,
1734 Handle(GEOM_Object) theAxis,
1735 Standard_Integer theNbTimes)
1739 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1741 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1742 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1744 //Add a new Copy object
1745 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1747 //Add a rotate function
1748 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_1D);
1749 if (aFunction.IsNull()) return NULL;
1751 //Check if the function is set correctly
1752 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1754 GEOMImpl_IRotate aRI(aFunction);
1755 aRI.SetOriginal(aLastFunction);
1756 aRI.SetAxis(theAxis->GetLastFunction());
1757 aRI.SetNbIter1(theNbTimes);
1759 //Compute the translation
1761 #if OCC_VERSION_LARGE > 0x06010000
1764 if (!GetSolver()->ComputeFunction(aFunction)) {
1765 SetErrorCode("Rotate driver failed");
1769 catch (Standard_Failure) {
1770 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1771 SetErrorCode(aFail->GetMessageString());
1775 //Make a Python command
1776 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate1D("
1777 << theObject << ", " << theAxis << ", " << theNbTimes << ")";
1783 //=============================================================================
1787 //=============================================================================
1788 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate2D (Handle(GEOM_Object) theObject,
1789 Handle(GEOM_Object) theAxis,
1791 Standard_Integer theNbTimes1,
1793 Standard_Integer theNbTimes2)
1797 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1799 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1800 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1802 //Add a new Copy object
1803 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1805 //Add a rotate function
1806 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_2D);
1807 if (aFunction.IsNull()) return NULL;
1809 //Check if the function is set correctly
1810 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1812 GEOMImpl_IRotate aRI(aFunction);
1813 aRI.SetAxis(theAxis->GetLastFunction());
1814 aRI.SetOriginal(aLastFunction);
1815 aRI.SetNbIter1(theNbTimes1);
1816 aRI.SetNbIter2(theNbTimes2);
1817 aRI.SetAngle(theAngle);
1818 aRI.SetStep(theStep);
1820 //Compute the translation
1822 #if OCC_VERSION_LARGE > 0x06010000
1825 if (!GetSolver()->ComputeFunction(aFunction)) {
1826 SetErrorCode("Rotate driver failed");
1830 catch (Standard_Failure) {
1831 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1832 SetErrorCode(aFail->GetMessageString());
1836 //Make a Python command
1837 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate2D("
1838 << theObject << ", " << theAxis << ", " << theAngle << ", "
1839 << theNbTimes1 << ", " << theStep << ", " << theNbTimes2 << ")";
1845 //=============================================================================
1849 //=============================================================================
1850 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePoints (Handle(GEOM_Object) theObject,
1851 Handle(GEOM_Object) theCentPoint,
1852 Handle(GEOM_Object) thePoint1,
1853 Handle(GEOM_Object) thePoint2)
1857 if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1859 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1860 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1862 // Get last functions of the arguments
1863 Handle(GEOM_Function) aCPF = theCentPoint->GetLastFunction();
1864 Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction();
1865 Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction();
1868 //Add a rotate function
1869 aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS);
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(aCPF);
1878 aRI.SetPoint1(aP1F);
1879 aRI.SetPoint2(aP2F);
1880 aRI.SetOriginal(aLastFunction);
1882 //Compute the translation
1884 #if OCC_VERSION_LARGE > 0x06010000
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) << "geompy.TrsfOp.RotateThreePoints(" << theObject
1900 << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
1906 //=============================================================================
1908 * RotateThreePointsCopy
1910 //=============================================================================
1911 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePointsCopy (Handle(GEOM_Object) theObject,
1912 Handle(GEOM_Object) theCentPoint,
1913 Handle(GEOM_Object) thePoint1,
1914 Handle(GEOM_Object) thePoint2)
1918 if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1920 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1921 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1923 //Add a new Copy object
1924 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1926 //Add a rotate function
1927 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS_COPY);
1928 if (aFunction.IsNull()) return NULL;
1930 //Check if the function is set correctly
1931 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1933 GEOMImpl_IRotate aRI(aFunction);
1934 aRI.SetCentPoint(theCentPoint->GetLastFunction());
1935 aRI.SetPoint1(thePoint1->GetLastFunction());
1936 aRI.SetPoint2(thePoint2->GetLastFunction());
1937 aRI.SetOriginal(aLastFunction);
1939 //Compute the translation
1941 #if OCC_VERSION_LARGE > 0x06010000
1944 if (!GetSolver()->ComputeFunction(aFunction)) {
1945 SetErrorCode("Rotate driver failed");
1949 catch (Standard_Failure) {
1950 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1951 SetErrorCode(aFail->GetMessageString());
1955 //Make a Python command
1956 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotationThreePoints(" << theObject
1957 << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
1963 //=============================================================================
1965 * TransformLikeOtherCopy
1967 //=============================================================================
1968 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TransformLikeOtherCopy
1969 (Handle(GEOM_Object) theObject,
1970 Handle(GEOM_Object) theSample)
1974 if (theObject.IsNull() || theSample.IsNull()) return NULL;
1976 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
1977 if (aLastFunction.IsNull()) return NULL; // There is no function which creates an object to be transformed
1979 Handle(GEOM_Function) aSampleFunc = theSample->GetLastFunction();
1980 if (aSampleFunc.IsNull()) return NULL; // There is no function which creates a sample object
1982 // Add a new Copy object
1983 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1985 // Add a transform function (depends on theSample function)
1986 Handle(GEOM_Function) aFunction =
1987 aCopy->AddFunction(aSampleFunc->GetDriverGUID(), aSampleFunc->GetType());
1988 if (aFunction.IsNull()) return NULL;
1990 // Check if the function is set correctly
1991 if (aFunction->GetDriverGUID() != aSampleFunc->GetDriverGUID()) return NULL;
1993 if (aSampleFunc->GetDriverGUID() == GEOMImpl_TranslateDriver::GetID()) {
1994 switch (aSampleFunc->GetType()) {
1997 GEOMImpl_ITranslate aRI_sample (aSampleFunc);
1998 GEOMImpl_ITranslate aRI_target (aFunction);
2000 aRI_target.SetVector(aRI_sample.GetVector());
2001 aRI_target.SetStep1(aRI_sample.GetStep1());
2002 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2004 aRI_target.SetOriginal(aLastFunction);
2009 GEOMImpl_ITranslate aRI_sample (aSampleFunc);
2010 GEOMImpl_ITranslate aRI_target (aFunction);
2012 aRI_target.SetVector(aRI_sample.GetVector());
2013 aRI_target.SetStep1(aRI_sample.GetStep1());
2014 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2016 aRI_target.SetVector2(aRI_sample.GetVector2());
2017 aRI_target.SetStep2(aRI_sample.GetStep2());
2018 aRI_target.SetNbIter2(aRI_sample.GetNbIter2());
2020 aRI_target.SetOriginal(aLastFunction);
2025 SetErrorCode("Not implemented case of TransformLikeOtherCopy");
2030 else if (aSampleFunc->GetDriverGUID() == GEOMImpl_RotateDriver::GetID()) {
2031 switch (aSampleFunc->GetType()) {
2034 GEOMImpl_IRotate aRI_sample (aSampleFunc);
2035 GEOMImpl_IRotate aRI_target (aFunction);
2037 aRI_target.SetAxis(aRI_sample.GetAxis());
2038 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2040 aRI_target.SetOriginal(aLastFunction);
2045 GEOMImpl_IRotate aRI_sample (aSampleFunc);
2046 GEOMImpl_IRotate aRI_target (aFunction);
2048 aRI_target.SetAxis(aRI_sample.GetAxis());
2050 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2051 aRI_target.SetNbIter2(aRI_sample.GetNbIter2());
2053 aRI_target.SetAngle(aRI_sample.GetAngle());
2054 aRI_target.SetStep(aRI_sample.GetStep());
2056 aRI_target.SetDir2(aRI_sample.GetDir2());
2058 aRI_target.SetOriginal(aLastFunction);
2061 case ROTATE_THREE_POINTS_COPY:
2063 GEOMImpl_IRotate aRI_sample (aSampleFunc);
2064 GEOMImpl_IRotate aRI_target (aFunction);
2066 aRI_target.SetCentPoint(aRI_sample.GetCentPoint());
2067 aRI_target.SetPoint1(aRI_sample.GetPoint1());
2068 aRI_target.SetPoint2(aRI_sample.GetPoint2());
2070 aRI_target.SetOriginal(aLastFunction);
2075 SetErrorCode("Not implemented case of TransformLikeOtherCopy");
2081 SetErrorCode("Not implemented case of TransformLikeOtherCopy");
2085 // Compute the transformation
2087 #if OCC_VERSION_LARGE > 0x06010000
2090 if (!GetSolver()->ComputeFunction(aFunction)) {
2091 SetErrorCode("Driver failed");
2095 catch (Standard_Failure) {
2096 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2097 SetErrorCode(aFail->GetMessageString());
2101 //Make a Python command
2102 //GEOM::TPythonDump(aFunction) << aCopy << " = geompy.TransformLikeOtherCopy("
2103 // << theObject << ", " << theSample << ")";