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
23 #include <Standard_Stream.hxx>
25 #include <GEOMImpl_ITransformOperations.hxx>
27 #include "utilities.h"
29 #include <Utils_ExceptHandlers.hxx>
31 #include <GEOM_Function.hxx>
32 #include <GEOM_PythonDump.hxx>
34 #include <GEOMImpl_TranslateDriver.hxx>
35 #include <GEOMImpl_MirrorDriver.hxx>
36 #include <GEOMImpl_ProjectionDriver.hxx>
37 #include <GEOMImpl_OffsetDriver.hxx>
38 #include <GEOMImpl_ScaleDriver.hxx>
39 #include <GEOMImpl_RotateDriver.hxx>
40 #include <GEOMImpl_PositionDriver.hxx>
42 #include <GEOMImpl_ITranslate.hxx>
43 #include <GEOMImpl_IMirror.hxx>
44 #include <GEOMImpl_IOffset.hxx>
45 #include <GEOMImpl_IScale.hxx>
46 #include <GEOMImpl_IRotate.hxx>
47 #include <GEOMImpl_IPosition.hxx>
49 #include <GEOMImpl_Types.hxx>
51 #include <TFunction_DriverTable.hxx>
52 #include <TFunction_Driver.hxx>
53 #include <TFunction_Logbook.hxx>
54 #include <TDF_Tool.hxx>
56 #include <BRep_Tool.hxx>
57 #include <BRep_Builder.hxx>
60 #include <TopoDS_Edge.hxx>
61 #include <TopoDS_Vertex.hxx>
62 #include <TopoDS_Compound.hxx>
65 #include <gp_Trsf.hxx>
67 #include <StdFail_NotDone.hxx>
68 #include <Standard_Failure.hxx>
69 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
71 //=============================================================================
75 //=============================================================================
77 GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations (GEOM_Engine* theEngine, int theDocID)
78 : GEOM_IOperations(theEngine, theDocID)
80 MESSAGE("GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations");
83 //=============================================================================
87 //=============================================================================
89 GEOMImpl_ITransformOperations::~GEOMImpl_ITransformOperations()
91 MESSAGE("GEOMImpl_ITransformOperations::~GEOMImpl_ITransformOperations");
95 //=============================================================================
99 //=============================================================================
100 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPoints
101 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
105 if (theObject.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
107 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
108 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
110 // Get last functions of the arguments
111 Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction();
112 Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction();
114 //Add a translate function
115 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_TWO_POINTS);
117 if (aFunction.IsNull()) return NULL;
119 //Check if the function is set correctly
120 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
122 GEOMImpl_ITranslate aTI (aFunction);
125 aTI.SetOriginal(aLastFunction);
127 //Compute the translation
129 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
132 if (!GetSolver()->ComputeFunction(aFunction)) {
133 SetErrorCode("Translation driver failed");
137 catch (Standard_Failure) {
138 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
139 SetErrorCode(aFail->GetMessageString());
143 //Make a Python command
144 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.TranslateTwoPoints("
145 << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
151 //=============================================================================
155 //=============================================================================
156 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZ
157 (Handle(GEOM_Object) theObject, double theX, double theY, double theZ)
161 if (theObject.IsNull()) return NULL;
163 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
164 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
166 //Add a translate function
167 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_XYZ);
169 if (aFunction.IsNull()) return NULL;
171 //Check if the function is set correctly
172 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
174 GEOMImpl_ITranslate aTI(aFunction);
178 aTI.SetOriginal(aLastFunction);
180 //Compute the translation
182 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
185 if (!GetSolver()->ComputeFunction(aFunction)) {
186 SetErrorCode("Translation driver failed");
190 catch (Standard_Failure) {
191 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
192 SetErrorCode(aFail->GetMessageString());
196 //Make a Python command
197 GEOM::TPythonDump(aFunction) << "geompy.TranslateDXDYDZ("
198 << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
205 //=============================================================================
207 * TranslateTwoPointsCopy
209 //=============================================================================
210 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPointsCopy
211 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
215 if (theObject.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
217 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
218 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
220 //Add a new Copy object
221 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
223 //Add a translate function
224 Handle(GEOM_Function) aFunction =
225 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_TWO_POINTS_COPY);
227 //Check if the function is set correctly
228 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
230 GEOMImpl_ITranslate aTI(aFunction);
231 aTI.SetPoint1(thePoint1->GetLastFunction());
232 aTI.SetPoint2(thePoint2->GetLastFunction());
233 //aTI.SetShape(theObject->GetValue());
234 aTI.SetOriginal(aLastFunction);
236 //Compute the translation
238 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
241 if (!GetSolver()->ComputeFunction(aFunction)) {
242 SetErrorCode("Translation driver failed");
246 catch (Standard_Failure) {
247 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
248 SetErrorCode(aFail->GetMessageString());
252 //Make a Python command
253 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationTwoPoints("
254 << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
260 //=============================================================================
262 * TranslateDXDYDZCopy
264 //=============================================================================
265 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZCopy
266 (Handle(GEOM_Object) theObject, double theX, double theY, double theZ)
270 if (theObject.IsNull()) return NULL;
272 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
273 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
275 //Add a new Copy object
276 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
278 //Add a translate function
279 Handle(GEOM_Function) aFunction =
280 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_XYZ_COPY);
282 //Check if the function is set correctly
283 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
285 GEOMImpl_ITranslate aTI(aFunction);
289 aTI.SetOriginal(aLastFunction);
291 //Compute the translation
293 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
296 if (!GetSolver()->ComputeFunction(aFunction)) {
297 SetErrorCode("Translation driver failed");
301 catch (Standard_Failure) {
302 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
303 SetErrorCode(aFail->GetMessageString());
307 //Make a Python command
308 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslation("
309 << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
316 //=============================================================================
320 //=============================================================================
321 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVector
322 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector)
326 if (theObject.IsNull() || theVector.IsNull()) return NULL;
328 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
329 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
331 // Get last functions of the arguments
332 Handle(GEOM_Function) aVF = theVector->GetLastFunction();
334 //Add a translate function
335 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR);
337 if (aFunction.IsNull()) return NULL;
339 //Check if the function is set correctly
340 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
342 GEOMImpl_ITranslate aTI (aFunction);
344 aTI.SetOriginal(aLastFunction);
346 //Compute the translation
348 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
351 if (!GetSolver()->ComputeFunction(aFunction)) {
352 SetErrorCode("Translation driver failed");
356 catch (Standard_Failure) {
357 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
358 SetErrorCode(aFail->GetMessageString());
362 //Make a Python command
363 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.TranslateVector("
364 << theObject << ", " << theVector << ")";
369 //=============================================================================
371 * TranslateVectorCopy
373 //=============================================================================
374 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorCopy
375 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector)
379 if (theObject.IsNull() || theVector.IsNull()) return NULL;
381 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
382 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
384 //Add a new Copy object
385 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
387 //Add a translate function
388 Handle(GEOM_Function) aFunction =
389 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_COPY);
391 //Check if the function is set correctly
392 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
394 GEOMImpl_ITranslate aTI(aFunction);
395 aTI.SetVector(theVector->GetLastFunction());
396 // aTI.SetShape(theObject->GetValue());
397 aTI.SetOriginal(aLastFunction);
399 //Compute the translation
401 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
404 if (!GetSolver()->ComputeFunction(aFunction)) {
405 SetErrorCode("Translation driver failed");
409 catch (Standard_Failure) {
410 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
411 SetErrorCode(aFail->GetMessageString());
415 //Make a Python command
416 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationVector("
417 << theObject << ", " << theVector << ")";
423 //=============================================================================
425 * TranslateVectorDistance
427 //=============================================================================
428 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorDistance
429 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector, double theDistance, bool theCopy)
433 if (theObject.IsNull() || theVector.IsNull()) return NULL;
435 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
436 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
438 Handle(GEOM_Object) aCopy; //Add a new Copy object
439 Handle(GEOM_Function) aFunction;
441 //Add a translate function
443 aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
444 aFunction = aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_DISTANCE);
447 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_DISTANCE);
449 if (aFunction.IsNull()) return NULL;
451 //Check if the function is set correctly
452 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
454 GEOMImpl_ITranslate aTI(aFunction);
455 aTI.SetVector(theVector->GetLastFunction());
456 aTI.SetDistance(theDistance);
457 // aTI.SetShape(theObject->GetValue());
458 aTI.SetOriginal(aLastFunction);
460 //Compute the translation
462 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
465 if (!GetSolver()->ComputeFunction(aFunction)) {
466 SetErrorCode("Translation driver failed");
470 catch (Standard_Failure) {
471 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
472 SetErrorCode(aFail->GetMessageString());
476 //Make a Python command
478 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationVectorDistance("
479 << theObject << ", " << theVector << ", " << theDistance << ")";
484 GEOM::TPythonDump(aFunction) << "geompy.TranslateVectorDistance("
485 << theObject << ", " << theVector << ", " << theDistance << ", " << theCopy << ")";
490 //=============================================================================
494 //=============================================================================
495 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate1D
496 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector,
497 double theStep, Standard_Integer theNbTimes)
501 if (theObject.IsNull() || theVector.IsNull()) return NULL;
503 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
504 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
506 //Add a new Copy object
507 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
509 //Add a translate function
510 Handle(GEOM_Function) aFunction =
511 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_1D);
513 //Check if the function is set correctly
514 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
516 GEOMImpl_ITranslate aTI(aFunction);
517 aTI.SetVector(theVector->GetLastFunction());
518 aTI.SetOriginal(aLastFunction);
519 aTI.SetStep1(theStep);
520 aTI.SetNbIter1(theNbTimes);
522 //Compute the translation
524 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
527 if (!GetSolver()->ComputeFunction(aFunction)) {
528 SetErrorCode("Translation driver failed");
532 catch (Standard_Failure) {
533 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
534 SetErrorCode(aFail->GetMessageString());
538 //Make a Python command
539 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMultiTranslation1D("
540 << theObject << ", " << theVector << ", " << theStep << ", " << theNbTimes << ")";
546 //=============================================================================
550 //=============================================================================
551 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate2D (Handle(GEOM_Object) theObject,
552 Handle(GEOM_Object) theVector,
554 Standard_Integer theNbTimes1,
555 Handle(GEOM_Object) theVector2,
557 Standard_Integer theNbTimes2)
561 if (theObject.IsNull() || theVector.IsNull() || theVector2.IsNull()) return NULL;
563 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
564 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
566 //Add a new Copy object
567 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
569 //Add a translate function
570 Handle(GEOM_Function) aFunction =
571 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_2D);
573 //Check if the function is set correctly
574 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
576 GEOMImpl_ITranslate aTI (aFunction);
577 aTI.SetVector(theVector->GetLastFunction());
578 aTI.SetVector2(theVector2->GetLastFunction());
579 aTI.SetOriginal(aLastFunction);
580 aTI.SetStep1(theStep1);
581 aTI.SetNbIter1(theNbTimes1);
582 aTI.SetStep2(theStep2);
583 aTI.SetNbIter2(theNbTimes2);
585 //Compute the translation
587 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
590 if (!GetSolver()->ComputeFunction(aFunction)) {
591 SetErrorCode("Translation driver failed");
595 catch (Standard_Failure) {
596 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
597 SetErrorCode(aFail->GetMessageString());
601 //Make a Python command
602 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMultiTranslation2D("
603 << theObject << ", " << theVector << ", " << theStep1 << ", " << theNbTimes1
604 << ", " << theVector2 << ", " << theStep2 << ", " << theNbTimes2 << ")";
610 //=============================================================================
614 //=============================================================================
616 TopoDS_Shape GEOMImpl_ITransformOperations::TranslateShape1D (const TopoDS_Shape& theShape,
617 GEOMImpl_ITranslate* theTI)
622 Handle(GEOM_Function) aVector = theTI->GetVector();
623 if (aVector.IsNull()) {
624 StdFail_NotDone::Raise("Invalid object is given for vector argument");
626 TopoDS_Shape aV = aVector->GetValue();
627 if (aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) {
628 StdFail_NotDone::Raise("Invalid object is given for vector argument");
630 TopoDS_Edge anEdge = TopoDS::Edge(aV);
632 gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
633 gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
634 if (aP1.Distance(aP2) < gp::Resolution()) {
635 StdFail_NotDone::Raise("Invalid object is given for vector argument");
639 Standard_Real step = theTI->GetStep1();
640 Standard_Integer nbtimes = theTI->GetNbIter1();
642 // Make multi-translation
645 TopoDS_Compound aCompound;
647 B.MakeCompound(aCompound);
649 gp_Vec Vec (aP1, aP2);
652 TopLoc_Location aLocOrig = theShape.Location();
653 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
655 for (int i = 0; i < nbtimes; i++) {
656 aVec = Vec * (i * step);
657 aTrsf.SetTranslation(aVec);
658 //NPAL18620: performance problem: multiple locations are accumulated
659 // in shape and need a great time to process
660 //BRepBuilderAPI_Transform aTransformation(theShape, aTrsf, Standard_False);
661 //B.Add(aCompound, aTransformation.Shape());
662 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
663 B.Add(aCompound, theShape.Located(aLocRes));
671 //=============================================================================
675 //=============================================================================
677 TopoDS_Shape GEOMImpl_ITransformOperations::TranslateShape2D (const TopoDS_Shape& theShape,
678 GEOMImpl_ITranslate* theTI)
683 Handle(GEOM_Function) aVector1 = theTI->GetVector();
684 Handle(GEOM_Function) aVector2 = theTI->GetVector2();
686 if (aVector1.IsNull() || aVector2.IsNull()) {
687 StdFail_NotDone::Raise("Invalid object is given for vector argument");
690 TopoDS_Shape aV1 = aVector1->GetValue();
691 TopoDS_Shape aV2 = aVector2->GetValue();
693 if (aV1.IsNull() || aV1.ShapeType() != TopAbs_EDGE ||
694 aV2.IsNull() || aV2.ShapeType() != TopAbs_EDGE) {
695 StdFail_NotDone::Raise("Invalid object is given for vector argument");
698 TopoDS_Edge anEdge1 = TopoDS::Edge(aV1);
699 TopoDS_Edge anEdge2 = TopoDS::Edge(aV2);
701 gp_Pnt aP11 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge1));
702 gp_Pnt aP12 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge1));
703 gp_Pnt aP21 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge2));
704 gp_Pnt aP22 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge2));
706 if (aP11.Distance(aP12) < gp::Resolution() ||
707 aP21.Distance(aP22) < gp::Resolution()) {
708 StdFail_NotDone::Raise("Invalid object is given for vector argument");
711 gp_Vec Vec1 (aP11, aP12);
712 gp_Vec Vec2 (aP21, aP22);
718 Standard_Real step1 = theTI->GetStep1(), step2 = theTI->GetStep2();
719 Standard_Integer nbtimes1 = theTI->GetNbIter1(), nbtimes2 = theTI->GetNbIter2();
721 // Make multi-translation
724 Standard_Real DX, DY, DZ;
725 TopoDS_Compound aCompound;
727 B.MakeCompound(aCompound);
729 TopLoc_Location aLocOrig = theShape.Location();
730 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
732 for (int i = 0; i < nbtimes1; i++) {
733 for (int j = 0; j < nbtimes2; j++) {
734 DX = i * step1 * Vec1.X() + j * step2 * Vec2.X();
735 DY = i * step1 * Vec1.Y() + j * step2 * Vec2.Y();
736 DZ = i * step1 * Vec1.Z() + j * step2 * Vec2.Z();
737 aVec.SetCoord(DX, DY, DZ);
738 aTrsf.SetTranslation(aVec);
739 //NPAL18620: performance problem: multiple locations are accumulated
740 // in shape and need a great time to process
741 //BRepBuilderAPI_Transform aBRepTransformation(theShape, aTrsf, Standard_False);
742 //B.Add(aCompound, aBRepTransformation.Shape());
743 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
744 B.Add(aCompound, theShape.Located(aLocRes));
753 //=============================================================================
757 //=============================================================================
758 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlane
759 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePlane)
763 if (theObject.IsNull() || thePlane.IsNull()) return NULL;
765 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
766 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
768 // Get last functions of the arguments
769 Handle(GEOM_Function) aPF = thePlane->GetLastFunction();
771 //Add a mirror function
772 Handle(GEOM_Function) aFunction =
773 theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_PLANE);
774 if (aFunction.IsNull()) return NULL;
776 //Check if the function is set correctly
777 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
779 GEOMImpl_IMirror aTI (aFunction);
781 aTI.SetOriginal(aLastFunction);
785 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
788 if (!GetSolver()->ComputeFunction(aFunction)) {
789 SetErrorCode("Mirror driver failed");
793 catch (Standard_Failure) {
794 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
795 SetErrorCode(aFail->GetMessageString());
799 //Make a Python command
800 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorPlane("
801 << theObject << ", " << thePlane << ")";
807 //=============================================================================
811 //=============================================================================
812 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlaneCopy
813 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePlane)
817 if (theObject.IsNull() || thePlane.IsNull()) return NULL;
819 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
820 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
822 //Add a new Copy object
823 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
825 //Add a mirror function
826 Handle(GEOM_Function) aFunction =
827 aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_PLANE_COPY);
829 //Check if the function is set correctly
830 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
832 GEOMImpl_IMirror aTI (aFunction);
833 aTI.SetPlane(thePlane->GetLastFunction());
834 aTI.SetOriginal(aLastFunction);
838 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
841 if (!GetSolver()->ComputeFunction(aFunction)) {
842 SetErrorCode("Mirror driver failed");
846 catch (Standard_Failure) {
847 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
848 SetErrorCode(aFail->GetMessageString());
852 //Make a Python command
853 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByPlane("
854 << theObject << ", " << thePlane << ")";
860 //=============================================================================
864 //=============================================================================
865 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPoint
866 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint)
870 if (theObject.IsNull() || thePoint.IsNull()) return NULL;
872 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
873 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
875 // Get last functions of the arguments
876 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
878 //Add a mirror function
879 Handle(GEOM_Function) aFunction =
880 theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_POINT);
881 if (aFunction.IsNull()) return NULL;
883 //Check if the function is set correctly
884 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
886 GEOMImpl_IMirror aTI (aFunction);
888 aTI.SetOriginal(aLastFunction);
892 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
895 if (!GetSolver()->ComputeFunction(aFunction)) {
896 SetErrorCode("Mirror driver failed");
900 catch (Standard_Failure) {
901 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
902 SetErrorCode(aFail->GetMessageString());
906 //Make a Python command
907 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorPoint("
908 << theObject << ", " << thePoint << ")";
914 //=============================================================================
918 //=============================================================================
919 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPointCopy
920 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint)
924 if (theObject.IsNull() || thePoint.IsNull()) return NULL;
926 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
927 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
929 //Add a new Copy object
930 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
932 //Add a mirror function
933 Handle(GEOM_Function) aFunction =
934 aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_POINT_COPY);
936 //Check if the function is set correctly
937 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
939 GEOMImpl_IMirror aTI (aFunction);
940 aTI.SetPoint(thePoint->GetLastFunction());
941 aTI.SetOriginal(aLastFunction);
945 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
948 if (!GetSolver()->ComputeFunction(aFunction)) {
949 SetErrorCode("Mirror driver failed");
953 catch (Standard_Failure) {
954 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
955 SetErrorCode(aFail->GetMessageString());
959 //Make a Python command
960 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByPoint("
961 << theObject << ", " << thePoint << ")";
967 //=============================================================================
971 //=============================================================================
972 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxis
973 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis)
977 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
979 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
980 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
982 // Get last functions of the arguments
983 Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
985 //Add a mirror function
986 Handle(GEOM_Function) aFunction =
987 theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_AXIS);
988 if (aFunction.IsNull()) return NULL;
990 //Check if the function is set correctly
991 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
993 GEOMImpl_IMirror aTI (aFunction);
995 aTI.SetOriginal(aLastFunction);
999 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1002 if (!GetSolver()->ComputeFunction(aFunction)) {
1003 SetErrorCode("Mirror driver failed");
1007 catch (Standard_Failure) {
1008 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1009 SetErrorCode(aFail->GetMessageString());
1013 //Make a Python command
1014 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorAxis("
1015 << theObject << ", " << theAxis << ")";
1021 //=============================================================================
1025 //=============================================================================
1026 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxisCopy
1027 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis)
1031 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1033 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
1034 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
1036 //Add a new Copy object
1037 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1039 //Add a mirror function
1040 Handle(GEOM_Function) aFunction =
1041 aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_AXIS_COPY);
1043 //Check if the function is set correctly
1044 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
1046 GEOMImpl_IMirror aTI (aFunction);
1047 aTI.SetAxis(theAxis->GetLastFunction());
1048 aTI.SetOriginal(aLastFunction);
1050 //Compute the mirror
1052 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1055 if (!GetSolver()->ComputeFunction(aFunction)) {
1056 SetErrorCode("Mirror driver failed");
1060 catch (Standard_Failure) {
1061 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1062 SetErrorCode(aFail->GetMessageString());
1066 //Make a Python command
1067 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByAxis("
1068 << theObject << ", " << theAxis << ")";
1075 //=============================================================================
1079 //=============================================================================
1080 Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShape
1081 (Handle(GEOM_Object) theObject, double theOffset)
1085 if (theObject.IsNull()) return NULL;
1087 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1088 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
1090 //Add a new Offset function
1091 Handle(GEOM_Function) aFunction =
1092 theObject->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE);
1093 if (aFunction.IsNull()) return NULL;
1095 //Check if the function is set correctly
1096 if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
1098 GEOMImpl_IOffset aTI (aFunction);
1099 aTI.SetShape(anOriginal);
1100 aTI.SetValue(theOffset);
1102 //Compute the offset
1104 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1107 if (!GetSolver()->ComputeFunction(aFunction)) {
1108 SetErrorCode("Offset driver failed");
1112 catch (Standard_Failure) {
1113 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1114 SetErrorCode(aFail->GetMessageString());
1118 //Make a Python command
1119 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.OffsetShape("
1120 << theObject << ", " << theOffset << ")";
1126 //=============================================================================
1130 //=============================================================================
1131 Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShapeCopy
1132 (Handle(GEOM_Object) theObject, double theOffset)
1136 if (theObject.IsNull()) return NULL;
1138 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1139 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
1141 //Add a new Copy object
1142 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1144 //Add a new Offset function
1145 Handle(GEOM_Function) aFunction =
1146 aCopy->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE_COPY);
1147 if (aFunction.IsNull()) return NULL;
1149 //Check if the function is set correctly
1150 if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
1152 GEOMImpl_IOffset aTI (aFunction);
1153 aTI.SetShape(anOriginal);
1154 aTI.SetValue(theOffset);
1156 //Compute the offset
1158 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1161 if (!GetSolver()->ComputeFunction(aFunction)) {
1162 SetErrorCode("Offset driver failed");
1166 catch (Standard_Failure) {
1167 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1168 SetErrorCode(aFail->GetMessageString());
1172 //Make a Python command
1173 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeOffset("
1174 << theObject << ", " << theOffset << ")";
1181 //=============================================================================
1185 //=============================================================================
1186 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ProjectShapeCopy
1187 (Handle(GEOM_Object) theSource, Handle(GEOM_Object) theTarget)
1191 if (theSource.IsNull() || theTarget.IsNull()) return NULL;
1193 Handle(GEOM_Function) aLastFunction = theSource->GetLastFunction();
1194 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be projected
1196 //Add a new Projection object
1197 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), GEOM_PROJECTION);
1199 //Add a Projection function
1200 Handle(GEOM_Function) aFunction =
1201 aCopy->AddFunction(GEOMImpl_ProjectionDriver::GetID(), PROJECTION_COPY);
1203 //Check if the function is set correctly
1204 if (aFunction->GetDriverGUID() != GEOMImpl_ProjectionDriver::GetID()) return NULL;
1206 GEOMImpl_IMirror aTI (aFunction);
1207 aTI.SetPlane(theTarget->GetLastFunction());
1208 aTI.SetOriginal(aLastFunction);
1210 //Compute the Projection
1212 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1215 if (!GetSolver()->ComputeFunction(aFunction)) {
1216 SetErrorCode("Projection driver failed");
1220 catch (Standard_Failure) {
1221 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1222 SetErrorCode(aFail->GetMessageString());
1226 //Make a Python command
1227 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeProjection("
1228 << theSource << ", " << theTarget << ")";
1235 //=============================================================================
1239 //=============================================================================
1240 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShape
1241 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, double theFactor)
1245 if (theObject.IsNull()) return NULL;
1247 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1248 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1250 //Add a scale function
1251 Handle(GEOM_Function) aFunction =
1252 theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE);
1253 if (aFunction.IsNull()) return NULL;
1255 //Check if the function is set correctly
1256 if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1259 GEOMImpl_IScale aTI (aFunction);
1260 aTI.SetShape(anOriginal);
1261 aTI.SetFactor(theFactor);
1263 // Set point argument
1264 if (!thePoint.IsNull()) {
1265 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1271 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1274 if (!GetSolver()->ComputeFunction(aFunction)) {
1275 SetErrorCode("Scale driver failed");
1279 catch (Standard_Failure) {
1280 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1281 SetErrorCode(aFail->GetMessageString());
1285 //Make a Python command
1286 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.ScaleShape("
1287 << theObject << ", " << thePoint << ", " << theFactor << ")";
1293 //=============================================================================
1297 //=============================================================================
1298 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeCopy
1299 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, double theFactor)
1303 if (theObject.IsNull()) return NULL;
1305 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1306 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1308 //Add a new Copy object
1309 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1311 //Add a scale function
1312 Handle(GEOM_Function) aFunction =
1313 aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_COPY);
1314 if (aFunction.IsNull()) return NULL;
1316 //Check if the function is set correctly
1317 if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1320 GEOMImpl_IScale aTI (aFunction);
1321 aTI.SetShape(anOriginal);
1322 aTI.SetFactor(theFactor);
1324 // Set point argument
1325 if (!thePoint.IsNull()) {
1326 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1332 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1335 if (!GetSolver()->ComputeFunction(aFunction)) {
1336 SetErrorCode("Scale driver failed");
1340 catch (Standard_Failure) {
1341 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1342 SetErrorCode(aFail->GetMessageString());
1346 //Make a Python command
1347 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeScaleTransform("
1348 << theObject << ", " << thePoint << ", " << theFactor << ")";
1354 //=============================================================================
1356 * ScaleShapeAlongAxes
1358 //=============================================================================
1359 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeAlongAxes (Handle(GEOM_Object) theObject,
1360 Handle(GEOM_Object) thePoint,
1368 if (theObject.IsNull()) return NULL;
1370 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1371 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1373 //Add a scale function
1374 Handle(GEOM_Object) aCopy; //Add a new Copy object
1375 Handle(GEOM_Function) aFunction;
1377 aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1378 aFunction = aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES_COPY);
1381 aFunction = theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES);
1383 if (aFunction.IsNull()) return NULL;
1385 //Check if the function is set correctly
1386 if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1389 GEOMImpl_IScale aTI (aFunction);
1390 aTI.SetShape(anOriginal);
1391 aTI.SetFactorX(theFactorX);
1392 aTI.SetFactorY(theFactorY);
1393 aTI.SetFactorZ(theFactorZ);
1395 // Set point (optional argument)
1396 if (!thePoint.IsNull()) {
1397 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1403 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1406 if (!GetSolver()->ComputeFunction(aFunction)) {
1407 SetErrorCode("Scale driver failed");
1411 catch (Standard_Failure) {
1412 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1413 SetErrorCode(aFail->GetMessageString());
1419 //Make a Python command
1421 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeScaleAlongAxes("
1422 << theObject << ", " << thePoint << ", "
1423 << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")";
1427 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.ScaleShapeAlongAxes("
1428 << theObject << ", " << thePoint << ", "
1429 << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")";
1433 //=============================================================================
1437 //=============================================================================
1438 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShape
1439 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theStartLCS, Handle(GEOM_Object) theEndLCS)
1443 if (theObject.IsNull() || theEndLCS.IsNull()) return NULL;
1445 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1446 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1448 //Add a Position function
1449 Standard_Integer aType = POSITION_SHAPE;
1450 if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL;
1452 Handle(GEOM_Function) aFunction =
1453 theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
1454 if (aFunction.IsNull()) return NULL;
1456 //Check if the function is set correctly
1457 if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1459 //Set operation arguments
1460 GEOMImpl_IPosition aTI (aFunction);
1461 aTI.SetShape(anOriginal);
1462 aTI.SetEndLCS(theEndLCS->GetLastFunction());
1463 if (!theStartLCS.IsNull())
1464 aTI.SetStartLCS(theObject == theStartLCS ? anOriginal : theStartLCS->GetLastFunction());
1466 //Compute the Position
1468 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1471 if (!GetSolver()->ComputeFunction(aFunction)) {
1472 SetErrorCode("Position driver failed");
1476 catch (Standard_Failure) {
1477 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1478 SetErrorCode(aFail->GetMessageString());
1482 //Make a Python command
1483 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.PositionShape("
1484 << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
1490 //=============================================================================
1494 //=============================================================================
1495 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShapeCopy
1496 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theStartLCS, Handle(GEOM_Object) theEndLCS)
1500 if (theObject.IsNull() || theEndLCS.IsNull()) return NULL;
1502 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1503 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1505 //Add a new Copy object
1506 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1508 //Add a position function
1509 Standard_Integer aType = POSITION_SHAPE_COPY;
1510 if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL_COPY;
1512 Handle(GEOM_Function) aFunction =
1513 aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
1514 if (aFunction.IsNull()) return NULL;
1516 //Check if the function is set correctly
1517 if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1519 GEOMImpl_IPosition aTI (aFunction);
1520 aTI.SetShape(anOriginal);
1521 aTI.SetEndLCS(theEndLCS->GetLastFunction());
1522 if (!theStartLCS.IsNull())
1523 aTI.SetStartLCS(theStartLCS->GetLastFunction());
1525 //Compute the position
1527 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1530 if (!GetSolver()->ComputeFunction(aFunction)) {
1531 SetErrorCode("Position driver failed");
1535 catch (Standard_Failure) {
1536 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1537 SetErrorCode(aFail->GetMessageString());
1541 //Make a Python command
1542 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakePosition("
1543 << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
1549 //=============================================================================
1553 //=============================================================================
1554 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionAlongPath
1555 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePath,
1556 double theDistance, bool theCopy, bool theReverse)
1560 if (theObject.IsNull() || thePath.IsNull()) return NULL;
1562 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1563 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1565 //Add a position function
1566 Handle(GEOM_Function) aFunction;
1567 Handle(GEOM_Object) aCopy;
1570 aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1571 aFunction = aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
1574 aFunction = theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
1576 if (aFunction.IsNull()) return NULL;
1578 //Check if the function is set correctly
1579 if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1581 GEOMImpl_IPosition aTI (aFunction);
1582 aTI.SetShape(anOriginal);
1583 aTI.SetPath(thePath->GetLastFunction());
1584 aTI.SetDistance(theDistance);
1585 aTI.SetReverse(theReverse);
1587 //Compute the position
1589 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1592 if (!GetSolver()->ComputeFunction(aFunction)) {
1593 SetErrorCode("Position driver failed");
1597 catch (Standard_Failure) {
1598 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1599 SetErrorCode(aFail->GetMessageString());
1603 //Make a Python command
1605 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.PositionAlongPath("
1606 << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
1611 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.PositionAlongPath("
1612 << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
1618 //=============================================================================
1622 //=============================================================================
1623 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate (Handle(GEOM_Object) theObject,
1624 Handle(GEOM_Object) theAxis,
1629 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1631 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1632 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1634 // Get last functions of the arguments
1635 Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
1637 //Add a rotate function
1638 aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE);
1640 if (aFunction.IsNull()) return NULL;
1642 //Check if the function is set correctly
1643 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1645 GEOMImpl_IRotate aRI(aFunction);
1647 aRI.SetOriginal(aLastFunction);
1648 aRI.SetAngle(theAngle);
1650 //Compute the translation
1652 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1655 if (!GetSolver()->ComputeFunction(aFunction)) {
1656 SetErrorCode("Rotate driver failed");
1660 catch (Standard_Failure) {
1661 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1662 SetErrorCode(aFail->GetMessageString());
1666 //Make a Python command
1667 GEOM::TPythonDump(aFunction) << "geompy.Rotate(" << theObject
1668 << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
1674 //=============================================================================
1678 //=============================================================================
1679 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateCopy (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis, double theAngle)
1683 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1685 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1686 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1688 //Add a new Copy object
1689 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1691 //Add a rotate function
1692 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_COPY);
1693 if (aFunction.IsNull()) return NULL;
1695 //Check if the function is set correctly
1696 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1698 GEOMImpl_IRotate aRI(aFunction);
1699 aRI.SetAxis(theAxis->GetLastFunction());
1700 aRI.SetOriginal(aLastFunction);
1701 aRI.SetAngle(theAngle);
1703 //Compute the translation
1705 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1708 if (!GetSolver()->ComputeFunction(aFunction)) {
1709 SetErrorCode("Rotate driver failed");
1713 catch (Standard_Failure) {
1714 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1715 SetErrorCode(aFail->GetMessageString());
1719 //Make a Python command
1720 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotation(" << theObject
1721 << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
1727 //=============================================================================
1731 //=============================================================================
1732 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate1D (Handle(GEOM_Object) theObject,
1733 Handle(GEOM_Object) theAxis,
1734 Standard_Integer theNbTimes)
1738 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1740 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1741 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1743 //Add a new Copy object
1744 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1746 //Add a rotate function
1747 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_1D);
1748 if (aFunction.IsNull()) return NULL;
1750 //Check if the function is set correctly
1751 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1753 GEOMImpl_IRotate aRI(aFunction);
1754 aRI.SetOriginal(aLastFunction);
1755 aRI.SetAxis(theAxis->GetLastFunction());
1756 aRI.SetNbIter1(theNbTimes);
1758 //Compute the translation
1760 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1763 if (!GetSolver()->ComputeFunction(aFunction)) {
1764 SetErrorCode("Rotate driver failed");
1768 catch (Standard_Failure) {
1769 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1770 SetErrorCode(aFail->GetMessageString());
1774 //Make a Python command
1775 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate1D("
1776 << theObject << ", " << theAxis << ", " << theNbTimes << ")";
1782 //=============================================================================
1786 //=============================================================================
1787 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate2D (Handle(GEOM_Object) theObject,
1788 Handle(GEOM_Object) theAxis,
1790 Standard_Integer theNbTimes1,
1792 Standard_Integer theNbTimes2)
1796 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1798 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1799 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1801 //Add a new Copy object
1802 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1804 //Add a rotate function
1805 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_2D);
1806 if (aFunction.IsNull()) return NULL;
1808 //Check if the function is set correctly
1809 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1811 GEOMImpl_IRotate aRI(aFunction);
1812 aRI.SetAxis(theAxis->GetLastFunction());
1813 aRI.SetOriginal(aLastFunction);
1814 aRI.SetNbIter1(theNbTimes1);
1815 aRI.SetNbIter2(theNbTimes2);
1816 aRI.SetAngle(theAngle);
1817 aRI.SetStep(theStep);
1819 //Compute the translation
1821 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1824 if (!GetSolver()->ComputeFunction(aFunction)) {
1825 SetErrorCode("Rotate driver failed");
1829 catch (Standard_Failure) {
1830 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1831 SetErrorCode(aFail->GetMessageString());
1835 //Make a Python command
1836 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate2D("
1837 << theObject << ", " << theAxis << ", " << theAngle << ", "
1838 << theNbTimes1 << ", " << theStep << ", " << theNbTimes2 << ")";
1844 //=============================================================================
1848 //=============================================================================
1849 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePoints (Handle(GEOM_Object) theObject,
1850 Handle(GEOM_Object) theCentPoint,
1851 Handle(GEOM_Object) thePoint1,
1852 Handle(GEOM_Object) thePoint2)
1856 if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1858 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1859 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1861 // Get last functions of the arguments
1862 Handle(GEOM_Function) aCPF = theCentPoint->GetLastFunction();
1863 Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction();
1864 Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction();
1867 //Add a rotate function
1868 aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS);
1870 if (aFunction.IsNull()) return NULL;
1872 //Check if the function is set correctly
1873 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1875 GEOMImpl_IRotate aRI(aFunction);
1876 aRI.SetCentPoint(aCPF);
1877 aRI.SetPoint1(aP1F);
1878 aRI.SetPoint2(aP2F);
1879 aRI.SetOriginal(aLastFunction);
1881 //Compute the translation
1883 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1886 if (!GetSolver()->ComputeFunction(aFunction)) {
1887 SetErrorCode("Rotate driver failed");
1891 catch (Standard_Failure) {
1892 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1893 SetErrorCode(aFail->GetMessageString());
1897 //Make a Python command
1898 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.RotateThreePoints(" << theObject
1899 << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
1905 //=============================================================================
1907 * RotateThreePointsCopy
1909 //=============================================================================
1910 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePointsCopy (Handle(GEOM_Object) theObject,
1911 Handle(GEOM_Object) theCentPoint,
1912 Handle(GEOM_Object) thePoint1,
1913 Handle(GEOM_Object) thePoint2)
1917 if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1919 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1920 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1922 //Add a new Copy object
1923 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1925 //Add a rotate function
1926 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS_COPY);
1927 if (aFunction.IsNull()) return NULL;
1929 //Check if the function is set correctly
1930 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1932 GEOMImpl_IRotate aRI(aFunction);
1933 aRI.SetCentPoint(theCentPoint->GetLastFunction());
1934 aRI.SetPoint1(thePoint1->GetLastFunction());
1935 aRI.SetPoint2(thePoint2->GetLastFunction());
1936 aRI.SetOriginal(aLastFunction);
1938 //Compute the translation
1940 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1943 if (!GetSolver()->ComputeFunction(aFunction)) {
1944 SetErrorCode("Rotate driver failed");
1948 catch (Standard_Failure) {
1949 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1950 SetErrorCode(aFail->GetMessageString());
1954 //Make a Python command
1955 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotationThreePoints(" << theObject
1956 << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
1962 //=============================================================================
1964 * TransformLikeOtherCopy
1966 //=============================================================================
1967 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TransformLikeOtherCopy
1968 (Handle(GEOM_Object) theObject,
1969 Handle(GEOM_Object) theSample)
1973 if (theObject.IsNull() || theSample.IsNull()) return NULL;
1975 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
1976 if (aLastFunction.IsNull()) return NULL; // There is no function which creates an object to be transformed
1978 Handle(GEOM_Function) aSampleFunc = theSample->GetLastFunction();
1979 if (aSampleFunc.IsNull()) return NULL; // There is no function which creates a sample object
1981 // Add a new Copy object
1982 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1984 // Add a transform function (depends on theSample function)
1985 Handle(GEOM_Function) aFunction =
1986 aCopy->AddFunction(aSampleFunc->GetDriverGUID(), aSampleFunc->GetType());
1987 if (aFunction.IsNull()) return NULL;
1989 // Check if the function is set correctly
1990 if (aFunction->GetDriverGUID() != aSampleFunc->GetDriverGUID()) return NULL;
1992 if (aSampleFunc->GetDriverGUID() == GEOMImpl_TranslateDriver::GetID()) {
1993 switch (aSampleFunc->GetType()) {
1996 GEOMImpl_ITranslate aRI_sample (aSampleFunc);
1997 GEOMImpl_ITranslate aRI_target (aFunction);
1999 aRI_target.SetVector(aRI_sample.GetVector());
2000 aRI_target.SetStep1(aRI_sample.GetStep1());
2001 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2003 aRI_target.SetOriginal(aLastFunction);
2008 GEOMImpl_ITranslate aRI_sample (aSampleFunc);
2009 GEOMImpl_ITranslate aRI_target (aFunction);
2011 aRI_target.SetVector(aRI_sample.GetVector());
2012 aRI_target.SetStep1(aRI_sample.GetStep1());
2013 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2015 aRI_target.SetVector2(aRI_sample.GetVector2());
2016 aRI_target.SetStep2(aRI_sample.GetStep2());
2017 aRI_target.SetNbIter2(aRI_sample.GetNbIter2());
2019 aRI_target.SetOriginal(aLastFunction);
2024 SetErrorCode("Not implemented case of TransformLikeOtherCopy");
2029 else if (aSampleFunc->GetDriverGUID() == GEOMImpl_RotateDriver::GetID()) {
2030 switch (aSampleFunc->GetType()) {
2033 GEOMImpl_IRotate aRI_sample (aSampleFunc);
2034 GEOMImpl_IRotate aRI_target (aFunction);
2036 aRI_target.SetAxis(aRI_sample.GetAxis());
2037 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2039 aRI_target.SetOriginal(aLastFunction);
2044 GEOMImpl_IRotate aRI_sample (aSampleFunc);
2045 GEOMImpl_IRotate aRI_target (aFunction);
2047 aRI_target.SetAxis(aRI_sample.GetAxis());
2049 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2050 aRI_target.SetNbIter2(aRI_sample.GetNbIter2());
2052 aRI_target.SetAngle(aRI_sample.GetAngle());
2053 aRI_target.SetStep(aRI_sample.GetStep());
2055 aRI_target.SetDir2(aRI_sample.GetDir2());
2057 aRI_target.SetOriginal(aLastFunction);
2060 case ROTATE_THREE_POINTS_COPY:
2062 GEOMImpl_IRotate aRI_sample (aSampleFunc);
2063 GEOMImpl_IRotate aRI_target (aFunction);
2065 aRI_target.SetCentPoint(aRI_sample.GetCentPoint());
2066 aRI_target.SetPoint1(aRI_sample.GetPoint1());
2067 aRI_target.SetPoint2(aRI_sample.GetPoint2());
2069 aRI_target.SetOriginal(aLastFunction);
2074 SetErrorCode("Not implemented case of TransformLikeOtherCopy");
2080 SetErrorCode("Not implemented case of TransformLikeOtherCopy");
2084 // Compute the transformation
2086 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2089 if (!GetSolver()->ComputeFunction(aFunction)) {
2090 SetErrorCode("Driver failed");
2094 catch (Standard_Failure) {
2095 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2096 SetErrorCode(aFail->GetMessageString());
2100 //Make a Python command
2101 //GEOM::TPythonDump(aFunction) << aCopy << " = geompy.TransformLikeOtherCopy("
2102 // << theObject << ", " << theSample << ")";