1 // Copyright (C) 2007-2012 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 <GEOMImpl_TranslateDriver.hxx>
28 #include <GEOMImpl_MirrorDriver.hxx>
29 #include <GEOMImpl_ProjectionDriver.hxx>
30 #include <GEOMImpl_OffsetDriver.hxx>
31 #include <GEOMImpl_ScaleDriver.hxx>
32 #include <GEOMImpl_RotateDriver.hxx>
33 #include <GEOMImpl_PositionDriver.hxx>
35 #include <GEOMImpl_ITranslate.hxx>
36 #include <GEOMImpl_IMirror.hxx>
37 #include <GEOMImpl_IOffset.hxx>
38 #include <GEOMImpl_IScale.hxx>
39 #include <GEOMImpl_IRotate.hxx>
40 #include <GEOMImpl_IPosition.hxx>
42 #include <GEOMImpl_Types.hxx>
44 #include <GEOM_Function.hxx>
45 #include <GEOM_PythonDump.hxx>
47 #include <Basics_OCCTVersion.hxx>
49 #include "utilities.h"
51 #include <Utils_ExceptHandlers.hxx>
53 #include <TFunction_DriverTable.hxx>
54 #include <TFunction_Driver.hxx>
55 #include <TFunction_Logbook.hxx>
56 #include <TDF_Tool.hxx>
58 #include <BRep_Tool.hxx>
59 #include <BRep_Builder.hxx>
62 #include <TopoDS_Edge.hxx>
63 #include <TopoDS_Vertex.hxx>
64 #include <TopoDS_Compound.hxx>
67 #include <gp_Trsf.hxx>
69 #include <StdFail_NotDone.hxx>
70 #include <Standard_Failure.hxx>
71 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
73 //=============================================================================
77 //=============================================================================
79 GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations (GEOM_Engine* theEngine, int theDocID)
80 : GEOM_IOperations(theEngine, theDocID)
82 MESSAGE("GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations");
85 //=============================================================================
89 //=============================================================================
91 GEOMImpl_ITransformOperations::~GEOMImpl_ITransformOperations()
93 MESSAGE("GEOMImpl_ITransformOperations::~GEOMImpl_ITransformOperations");
97 //=============================================================================
101 //=============================================================================
102 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPoints
103 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
107 if (theObject.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
109 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
110 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
112 // Get last functions of the arguments
113 Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction();
114 Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction();
116 //Add a translate function
117 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_TWO_POINTS);
119 if (aFunction.IsNull()) return NULL;
121 //Check if the function is set correctly
122 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
124 GEOMImpl_ITranslate aTI (aFunction);
127 aTI.SetOriginal(aLastFunction);
129 //Compute the translation
131 #if OCC_VERSION_LARGE > 0x06010000
134 if (!GetSolver()->ComputeFunction(aFunction)) {
135 SetErrorCode("Translation driver failed");
139 catch (Standard_Failure) {
140 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
141 SetErrorCode(aFail->GetMessageString());
145 //Make a Python command
146 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.TranslateTwoPoints("
147 << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
153 //=============================================================================
157 //=============================================================================
158 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZ
159 (Handle(GEOM_Object) theObject, double theX, double theY, double theZ)
163 if (theObject.IsNull()) return NULL;
165 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
166 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
168 //Add a translate function
169 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_XYZ);
171 if (aFunction.IsNull()) return NULL;
173 //Check if the function is set correctly
174 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
176 GEOMImpl_ITranslate aTI(aFunction);
180 aTI.SetOriginal(aLastFunction);
182 //Compute the translation
184 #if OCC_VERSION_LARGE > 0x06010000
187 if (!GetSolver()->ComputeFunction(aFunction)) {
188 SetErrorCode("Translation driver failed");
192 catch (Standard_Failure) {
193 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
194 SetErrorCode(aFail->GetMessageString());
198 //Make a Python command
199 GEOM::TPythonDump(aFunction) << "geompy.TranslateDXDYDZ("
200 << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
207 //=============================================================================
209 * TranslateTwoPointsCopy
211 //=============================================================================
212 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPointsCopy
213 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
217 if (theObject.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
219 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
220 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
222 //Add a new Copy object
223 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
225 //Add a translate function
226 Handle(GEOM_Function) aFunction =
227 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_TWO_POINTS_COPY);
229 //Check if the function is set correctly
230 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
232 GEOMImpl_ITranslate aTI(aFunction);
233 aTI.SetPoint1(thePoint1->GetLastFunction());
234 aTI.SetPoint2(thePoint2->GetLastFunction());
235 //aTI.SetShape(theObject->GetValue());
236 aTI.SetOriginal(aLastFunction);
238 //Compute the translation
240 #if OCC_VERSION_LARGE > 0x06010000
243 if (!GetSolver()->ComputeFunction(aFunction)) {
244 SetErrorCode("Translation driver failed");
248 catch (Standard_Failure) {
249 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
250 SetErrorCode(aFail->GetMessageString());
254 //Make a Python command
255 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationTwoPoints("
256 << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
262 //=============================================================================
264 * TranslateDXDYDZCopy
266 //=============================================================================
267 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZCopy
268 (Handle(GEOM_Object) theObject, double theX, double theY, double theZ)
272 if (theObject.IsNull()) return NULL;
274 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
275 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
277 //Add a new Copy object
278 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
280 //Add a translate function
281 Handle(GEOM_Function) aFunction =
282 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_XYZ_COPY);
284 //Check if the function is set correctly
285 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
287 GEOMImpl_ITranslate aTI(aFunction);
291 aTI.SetOriginal(aLastFunction);
293 //Compute the translation
295 #if OCC_VERSION_LARGE > 0x06010000
298 if (!GetSolver()->ComputeFunction(aFunction)) {
299 SetErrorCode("Translation driver failed");
303 catch (Standard_Failure) {
304 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
305 SetErrorCode(aFail->GetMessageString());
309 //Make a Python command
310 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslation("
311 << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
318 //=============================================================================
322 //=============================================================================
323 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVector
324 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector)
328 if (theObject.IsNull() || theVector.IsNull()) return NULL;
330 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
331 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
333 // Get last functions of the arguments
334 Handle(GEOM_Function) aVF = theVector->GetLastFunction();
336 //Add a translate function
337 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR);
339 if (aFunction.IsNull()) return NULL;
341 //Check if the function is set correctly
342 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
344 GEOMImpl_ITranslate aTI (aFunction);
346 aTI.SetOriginal(aLastFunction);
348 //Compute the translation
350 #if OCC_VERSION_LARGE > 0x06010000
353 if (!GetSolver()->ComputeFunction(aFunction)) {
354 SetErrorCode("Translation driver failed");
358 catch (Standard_Failure) {
359 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
360 SetErrorCode(aFail->GetMessageString());
364 //Make a Python command
365 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.TranslateVector("
366 << theObject << ", " << theVector << ")";
371 //=============================================================================
373 * TranslateVectorCopy
375 //=============================================================================
376 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorCopy
377 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector)
381 if (theObject.IsNull() || theVector.IsNull()) return NULL;
383 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
384 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
386 //Add a new Copy object
387 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
389 //Add a translate function
390 Handle(GEOM_Function) aFunction =
391 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_COPY);
393 //Check if the function is set correctly
394 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
396 GEOMImpl_ITranslate aTI(aFunction);
397 aTI.SetVector(theVector->GetLastFunction());
398 // aTI.SetShape(theObject->GetValue());
399 aTI.SetOriginal(aLastFunction);
401 //Compute the translation
403 #if OCC_VERSION_LARGE > 0x06010000
406 if (!GetSolver()->ComputeFunction(aFunction)) {
407 SetErrorCode("Translation driver failed");
411 catch (Standard_Failure) {
412 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
413 SetErrorCode(aFail->GetMessageString());
417 //Make a Python command
418 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationVector("
419 << theObject << ", " << theVector << ")";
425 //=============================================================================
427 * TranslateVectorDistance
429 //=============================================================================
430 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorDistance
431 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector, double theDistance, bool theCopy)
435 if (theObject.IsNull() || theVector.IsNull()) return NULL;
437 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
438 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
440 Handle(GEOM_Object) aCopy; //Add a new Copy object
441 Handle(GEOM_Function) aFunction;
443 //Add a translate function
445 aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
446 aFunction = aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_DISTANCE);
449 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_DISTANCE);
451 if (aFunction.IsNull()) return NULL;
453 //Check if the function is set correctly
454 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
456 GEOMImpl_ITranslate aTI(aFunction);
457 aTI.SetVector(theVector->GetLastFunction());
458 aTI.SetDistance(theDistance);
459 // aTI.SetShape(theObject->GetValue());
460 aTI.SetOriginal(aLastFunction);
462 //Compute the translation
464 #if OCC_VERSION_LARGE > 0x06010000
467 if (!GetSolver()->ComputeFunction(aFunction)) {
468 SetErrorCode("Translation driver failed");
472 catch (Standard_Failure) {
473 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
474 SetErrorCode(aFail->GetMessageString());
478 //Make a Python command
480 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationVectorDistance("
481 << theObject << ", " << theVector << ", " << theDistance << ")";
486 GEOM::TPythonDump(aFunction) << "geompy.TranslateVectorDistance("
487 << theObject << ", " << theVector << ", " << theDistance << ", " << theCopy << ")";
492 //=============================================================================
496 //=============================================================================
497 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate1D
498 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector,
499 double theStep, Standard_Integer theNbTimes)
503 if (theObject.IsNull() || theVector.IsNull()) return NULL;
505 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
506 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
508 //Add a new Copy object
509 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
511 //Add a translate function
512 Handle(GEOM_Function) aFunction =
513 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_1D);
515 //Check if the function is set correctly
516 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
518 GEOMImpl_ITranslate aTI(aFunction);
519 aTI.SetVector(theVector->GetLastFunction());
520 aTI.SetOriginal(aLastFunction);
521 aTI.SetStep1(theStep);
522 aTI.SetNbIter1(theNbTimes);
524 //Compute the translation
526 #if OCC_VERSION_LARGE > 0x06010000
529 if (!GetSolver()->ComputeFunction(aFunction)) {
530 SetErrorCode("Translation driver failed");
534 catch (Standard_Failure) {
535 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
536 SetErrorCode(aFail->GetMessageString());
540 //Make a Python command
541 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMultiTranslation1D("
542 << theObject << ", " << theVector << ", " << theStep << ", " << theNbTimes << ")";
548 //=============================================================================
552 //=============================================================================
553 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate2D (Handle(GEOM_Object) theObject,
554 Handle(GEOM_Object) theVector,
556 Standard_Integer theNbTimes1,
557 Handle(GEOM_Object) theVector2,
559 Standard_Integer theNbTimes2)
563 if (theObject.IsNull() || theVector.IsNull() || theVector2.IsNull()) return NULL;
565 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
566 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
568 //Add a new Copy object
569 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
571 //Add a translate function
572 Handle(GEOM_Function) aFunction =
573 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_2D);
575 //Check if the function is set correctly
576 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
578 GEOMImpl_ITranslate aTI (aFunction);
579 aTI.SetVector(theVector->GetLastFunction());
580 aTI.SetVector2(theVector2->GetLastFunction());
581 aTI.SetOriginal(aLastFunction);
582 aTI.SetStep1(theStep1);
583 aTI.SetNbIter1(theNbTimes1);
584 aTI.SetStep2(theStep2);
585 aTI.SetNbIter2(theNbTimes2);
587 //Compute the translation
589 #if OCC_VERSION_LARGE > 0x06010000
592 if (!GetSolver()->ComputeFunction(aFunction)) {
593 SetErrorCode("Translation driver failed");
597 catch (Standard_Failure) {
598 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
599 SetErrorCode(aFail->GetMessageString());
603 //Make a Python command
604 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMultiTranslation2D("
605 << theObject << ", " << theVector << ", " << theStep1 << ", " << theNbTimes1
606 << ", " << theVector2 << ", " << theStep2 << ", " << theNbTimes2 << ")";
612 //=============================================================================
616 //=============================================================================
618 TopoDS_Shape GEOMImpl_ITransformOperations::TranslateShape1D (const TopoDS_Shape& theShape,
619 GEOMImpl_ITranslate* theTI)
624 Handle(GEOM_Function) aVector = theTI->GetVector();
625 if (aVector.IsNull()) {
626 StdFail_NotDone::Raise("Invalid object is given for vector argument");
628 TopoDS_Shape aV = aVector->GetValue();
629 if (aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) {
630 StdFail_NotDone::Raise("Invalid object is given for vector argument");
632 TopoDS_Edge anEdge = TopoDS::Edge(aV);
634 gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
635 gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
636 if (aP1.Distance(aP2) < gp::Resolution()) {
637 StdFail_NotDone::Raise("Invalid object is given for vector argument");
641 Standard_Real step = theTI->GetStep1();
642 Standard_Integer nbtimes = theTI->GetNbIter1();
644 // Make multi-translation
647 TopoDS_Compound aCompound;
649 B.MakeCompound(aCompound);
651 gp_Vec Vec (aP1, aP2);
654 TopLoc_Location aLocOrig = theShape.Location();
655 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
657 for (int i = 0; i < nbtimes; i++) {
658 aVec = Vec * (i * step);
659 aTrsf.SetTranslation(aVec);
660 //NPAL18620: performance problem: multiple locations are accumulated
661 // in shape and need a great time to process
662 //BRepBuilderAPI_Transform aTransformation(theShape, aTrsf, Standard_False);
663 //B.Add(aCompound, aTransformation.Shape());
664 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
665 B.Add(aCompound, theShape.Located(aLocRes));
673 //=============================================================================
677 //=============================================================================
679 TopoDS_Shape GEOMImpl_ITransformOperations::TranslateShape2D (const TopoDS_Shape& theShape,
680 GEOMImpl_ITranslate* theTI)
685 Handle(GEOM_Function) aVector1 = theTI->GetVector();
686 Handle(GEOM_Function) aVector2 = theTI->GetVector2();
688 if (aVector1.IsNull() || aVector2.IsNull()) {
689 StdFail_NotDone::Raise("Invalid object is given for vector argument");
692 TopoDS_Shape aV1 = aVector1->GetValue();
693 TopoDS_Shape aV2 = aVector2->GetValue();
695 if (aV1.IsNull() || aV1.ShapeType() != TopAbs_EDGE ||
696 aV2.IsNull() || aV2.ShapeType() != TopAbs_EDGE) {
697 StdFail_NotDone::Raise("Invalid object is given for vector argument");
700 TopoDS_Edge anEdge1 = TopoDS::Edge(aV1);
701 TopoDS_Edge anEdge2 = TopoDS::Edge(aV2);
703 gp_Pnt aP11 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge1));
704 gp_Pnt aP12 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge1));
705 gp_Pnt aP21 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge2));
706 gp_Pnt aP22 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge2));
708 if (aP11.Distance(aP12) < gp::Resolution() ||
709 aP21.Distance(aP22) < gp::Resolution()) {
710 StdFail_NotDone::Raise("Invalid object is given for vector argument");
713 gp_Vec Vec1 (aP11, aP12);
714 gp_Vec Vec2 (aP21, aP22);
720 Standard_Real step1 = theTI->GetStep1(), step2 = theTI->GetStep2();
721 Standard_Integer nbtimes1 = theTI->GetNbIter1(), nbtimes2 = theTI->GetNbIter2();
723 // Make multi-translation
726 Standard_Real DX, DY, DZ;
727 TopoDS_Compound aCompound;
729 B.MakeCompound(aCompound);
731 TopLoc_Location aLocOrig = theShape.Location();
732 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
734 for (int i = 0; i < nbtimes1; i++) {
735 for (int j = 0; j < nbtimes2; j++) {
736 DX = i * step1 * Vec1.X() + j * step2 * Vec2.X();
737 DY = i * step1 * Vec1.Y() + j * step2 * Vec2.Y();
738 DZ = i * step1 * Vec1.Z() + j * step2 * Vec2.Z();
739 aVec.SetCoord(DX, DY, DZ);
740 aTrsf.SetTranslation(aVec);
741 //NPAL18620: performance problem: multiple locations are accumulated
742 // in shape and need a great time to process
743 //BRepBuilderAPI_Transform aBRepTransformation(theShape, aTrsf, Standard_False);
744 //B.Add(aCompound, aBRepTransformation.Shape());
745 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
746 B.Add(aCompound, theShape.Located(aLocRes));
755 //=============================================================================
759 //=============================================================================
760 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlane
761 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePlane)
765 if (theObject.IsNull() || thePlane.IsNull()) return NULL;
767 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
768 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
770 // Get last functions of the arguments
771 Handle(GEOM_Function) aPF = thePlane->GetLastFunction();
773 //Add a mirror function
774 Handle(GEOM_Function) aFunction =
775 theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_PLANE);
776 if (aFunction.IsNull()) return NULL;
778 //Check if the function is set correctly
779 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
781 GEOMImpl_IMirror aTI (aFunction);
783 aTI.SetOriginal(aLastFunction);
787 #if OCC_VERSION_LARGE > 0x06010000
790 if (!GetSolver()->ComputeFunction(aFunction)) {
791 SetErrorCode("Mirror driver failed");
795 catch (Standard_Failure) {
796 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
797 SetErrorCode(aFail->GetMessageString());
801 //Make a Python command
802 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorPlane("
803 << theObject << ", " << thePlane << ")";
809 //=============================================================================
813 //=============================================================================
814 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlaneCopy
815 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePlane)
819 if (theObject.IsNull() || thePlane.IsNull()) return NULL;
821 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
822 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
824 //Add a new Copy object
825 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
827 //Add a mirror function
828 Handle(GEOM_Function) aFunction =
829 aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_PLANE_COPY);
831 //Check if the function is set correctly
832 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
834 GEOMImpl_IMirror aTI (aFunction);
835 aTI.SetPlane(thePlane->GetLastFunction());
836 aTI.SetOriginal(aLastFunction);
840 #if OCC_VERSION_LARGE > 0x06010000
843 if (!GetSolver()->ComputeFunction(aFunction)) {
844 SetErrorCode("Mirror driver failed");
848 catch (Standard_Failure) {
849 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
850 SetErrorCode(aFail->GetMessageString());
854 //Make a Python command
855 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByPlane("
856 << theObject << ", " << thePlane << ")";
862 //=============================================================================
866 //=============================================================================
867 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPoint
868 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint)
872 if (theObject.IsNull() || thePoint.IsNull()) return NULL;
874 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
875 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
877 // Get last functions of the arguments
878 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
880 //Add a mirror function
881 Handle(GEOM_Function) aFunction =
882 theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_POINT);
883 if (aFunction.IsNull()) return NULL;
885 //Check if the function is set correctly
886 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
888 GEOMImpl_IMirror aTI (aFunction);
890 aTI.SetOriginal(aLastFunction);
894 #if OCC_VERSION_LARGE > 0x06010000
897 if (!GetSolver()->ComputeFunction(aFunction)) {
898 SetErrorCode("Mirror driver failed");
902 catch (Standard_Failure) {
903 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
904 SetErrorCode(aFail->GetMessageString());
908 //Make a Python command
909 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorPoint("
910 << theObject << ", " << thePoint << ")";
916 //=============================================================================
920 //=============================================================================
921 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPointCopy
922 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint)
926 if (theObject.IsNull() || thePoint.IsNull()) return NULL;
928 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
929 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
931 //Add a new Copy object
932 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
934 //Add a mirror function
935 Handle(GEOM_Function) aFunction =
936 aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_POINT_COPY);
938 //Check if the function is set correctly
939 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
941 GEOMImpl_IMirror aTI (aFunction);
942 aTI.SetPoint(thePoint->GetLastFunction());
943 aTI.SetOriginal(aLastFunction);
947 #if OCC_VERSION_LARGE > 0x06010000
950 if (!GetSolver()->ComputeFunction(aFunction)) {
951 SetErrorCode("Mirror driver failed");
955 catch (Standard_Failure) {
956 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
957 SetErrorCode(aFail->GetMessageString());
961 //Make a Python command
962 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByPoint("
963 << theObject << ", " << thePoint << ")";
969 //=============================================================================
973 //=============================================================================
974 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxis
975 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis)
979 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
981 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
982 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
984 // Get last functions of the arguments
985 Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
987 //Add a mirror function
988 Handle(GEOM_Function) aFunction =
989 theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_AXIS);
990 if (aFunction.IsNull()) return NULL;
992 //Check if the function is set correctly
993 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
995 GEOMImpl_IMirror aTI (aFunction);
997 aTI.SetOriginal(aLastFunction);
1001 #if OCC_VERSION_LARGE > 0x06010000
1004 if (!GetSolver()->ComputeFunction(aFunction)) {
1005 SetErrorCode("Mirror driver failed");
1009 catch (Standard_Failure) {
1010 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1011 SetErrorCode(aFail->GetMessageString());
1015 //Make a Python command
1016 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorAxis("
1017 << theObject << ", " << theAxis << ")";
1023 //=============================================================================
1027 //=============================================================================
1028 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxisCopy
1029 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis)
1033 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1035 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
1036 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
1038 //Add a new Copy object
1039 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1041 //Add a mirror function
1042 Handle(GEOM_Function) aFunction =
1043 aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_AXIS_COPY);
1045 //Check if the function is set correctly
1046 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
1048 GEOMImpl_IMirror aTI (aFunction);
1049 aTI.SetAxis(theAxis->GetLastFunction());
1050 aTI.SetOriginal(aLastFunction);
1052 //Compute the mirror
1054 #if OCC_VERSION_LARGE > 0x06010000
1057 if (!GetSolver()->ComputeFunction(aFunction)) {
1058 SetErrorCode("Mirror driver failed");
1062 catch (Standard_Failure) {
1063 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1064 SetErrorCode(aFail->GetMessageString());
1068 //Make a Python command
1069 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByAxis("
1070 << theObject << ", " << theAxis << ")";
1077 //=============================================================================
1081 //=============================================================================
1082 Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShape
1083 (Handle(GEOM_Object) theObject, double theOffset)
1087 if (theObject.IsNull()) return NULL;
1089 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1090 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
1092 //Add a new Offset function
1093 Handle(GEOM_Function) aFunction =
1094 theObject->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE);
1095 if (aFunction.IsNull()) return NULL;
1097 //Check if the function is set correctly
1098 if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
1100 GEOMImpl_IOffset aTI (aFunction);
1101 aTI.SetShape(anOriginal);
1102 aTI.SetValue(theOffset);
1104 //Compute the offset
1106 #if OCC_VERSION_LARGE > 0x06010000
1109 if (!GetSolver()->ComputeFunction(aFunction)) {
1110 SetErrorCode("Offset driver failed");
1114 catch (Standard_Failure) {
1115 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1116 SetErrorCode(aFail->GetMessageString());
1120 //Make a Python command
1121 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.OffsetShape("
1122 << theObject << ", " << theOffset << ")";
1128 //=============================================================================
1132 //=============================================================================
1133 Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShapeCopy
1134 (Handle(GEOM_Object) theObject, double theOffset)
1138 if (theObject.IsNull()) return NULL;
1140 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1141 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
1143 //Add a new Copy object
1144 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1146 //Add a new Offset function
1147 Handle(GEOM_Function) aFunction =
1148 aCopy->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE_COPY);
1149 if (aFunction.IsNull()) return NULL;
1151 //Check if the function is set correctly
1152 if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
1154 GEOMImpl_IOffset aTI (aFunction);
1155 aTI.SetShape(anOriginal);
1156 aTI.SetValue(theOffset);
1158 //Compute the offset
1160 #if OCC_VERSION_LARGE > 0x06010000
1163 if (!GetSolver()->ComputeFunction(aFunction)) {
1164 SetErrorCode("Offset driver failed");
1168 catch (Standard_Failure) {
1169 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1170 SetErrorCode(aFail->GetMessageString());
1174 //Make a Python command
1175 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeOffset("
1176 << theObject << ", " << theOffset << ")";
1183 //=============================================================================
1187 //=============================================================================
1188 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ProjectShapeCopy
1189 (Handle(GEOM_Object) theSource, Handle(GEOM_Object) theTarget)
1193 if (theSource.IsNull() || theTarget.IsNull()) return NULL;
1195 Handle(GEOM_Function) aLastFunction = theSource->GetLastFunction();
1196 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be projected
1198 //Add a new Projection object
1199 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), GEOM_PROJECTION);
1201 //Add a Projection function
1202 Handle(GEOM_Function) aFunction =
1203 aCopy->AddFunction(GEOMImpl_ProjectionDriver::GetID(), PROJECTION_COPY);
1205 //Check if the function is set correctly
1206 if (aFunction->GetDriverGUID() != GEOMImpl_ProjectionDriver::GetID()) return NULL;
1208 GEOMImpl_IMirror aTI (aFunction);
1209 aTI.SetPlane(theTarget->GetLastFunction());
1210 aTI.SetOriginal(aLastFunction);
1212 //Compute the Projection
1214 #if OCC_VERSION_LARGE > 0x06010000
1217 if (!GetSolver()->ComputeFunction(aFunction)) {
1218 SetErrorCode("Projection driver failed");
1222 catch (Standard_Failure) {
1223 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1224 SetErrorCode(aFail->GetMessageString());
1228 //Make a Python command
1229 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeProjection("
1230 << theSource << ", " << theTarget << ")";
1237 //=============================================================================
1241 //=============================================================================
1242 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShape
1243 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, double theFactor)
1247 if (theObject.IsNull()) return NULL;
1249 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1250 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1252 //Add a scale function
1253 Handle(GEOM_Function) aFunction =
1254 theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE);
1255 if (aFunction.IsNull()) return NULL;
1257 //Check if the function is set correctly
1258 if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1261 GEOMImpl_IScale aTI (aFunction);
1262 aTI.SetShape(anOriginal);
1263 aTI.SetFactor(theFactor);
1265 // Set point argument
1266 if (!thePoint.IsNull()) {
1267 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1273 #if OCC_VERSION_LARGE > 0x06010000
1276 if (!GetSolver()->ComputeFunction(aFunction)) {
1277 SetErrorCode("Scale driver failed");
1281 catch (Standard_Failure) {
1282 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1283 SetErrorCode(aFail->GetMessageString());
1287 //Make a Python command
1288 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.ScaleShape("
1289 << theObject << ", " << thePoint << ", " << theFactor << ")";
1295 //=============================================================================
1299 //=============================================================================
1300 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeCopy
1301 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, double theFactor)
1305 if (theObject.IsNull()) return NULL;
1307 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1308 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1310 //Add a new Copy object
1311 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1313 //Add a scale function
1314 Handle(GEOM_Function) aFunction =
1315 aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_COPY);
1316 if (aFunction.IsNull()) return NULL;
1318 //Check if the function is set correctly
1319 if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1322 GEOMImpl_IScale aTI (aFunction);
1323 aTI.SetShape(anOriginal);
1324 aTI.SetFactor(theFactor);
1326 // Set point argument
1327 if (!thePoint.IsNull()) {
1328 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1334 #if OCC_VERSION_LARGE > 0x06010000
1337 if (!GetSolver()->ComputeFunction(aFunction)) {
1338 SetErrorCode("Scale driver failed");
1342 catch (Standard_Failure) {
1343 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1344 SetErrorCode(aFail->GetMessageString());
1348 //Make a Python command
1349 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeScaleTransform("
1350 << theObject << ", " << thePoint << ", " << theFactor << ")";
1356 //=============================================================================
1358 * ScaleShapeAlongAxes
1360 //=============================================================================
1361 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeAlongAxes (Handle(GEOM_Object) theObject,
1362 Handle(GEOM_Object) thePoint,
1370 if (theObject.IsNull()) return NULL;
1372 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1373 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
1375 //Add a scale function
1376 Handle(GEOM_Object) aCopy; //Add a new Copy object
1377 Handle(GEOM_Function) aFunction;
1379 aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1380 aFunction = aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES_COPY);
1383 aFunction = theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES);
1385 if (aFunction.IsNull()) return NULL;
1387 //Check if the function is set correctly
1388 if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
1391 GEOMImpl_IScale aTI (aFunction);
1392 aTI.SetShape(anOriginal);
1393 aTI.SetFactorX(theFactorX);
1394 aTI.SetFactorY(theFactorY);
1395 aTI.SetFactorZ(theFactorZ);
1397 // Set point (optional argument)
1398 if (!thePoint.IsNull()) {
1399 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
1405 #if OCC_VERSION_LARGE > 0x06010000
1408 if (!GetSolver()->ComputeFunction(aFunction)) {
1409 SetErrorCode("Scale driver failed");
1413 catch (Standard_Failure) {
1414 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1415 SetErrorCode(aFail->GetMessageString());
1421 //Make a Python command
1423 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeScaleAlongAxes("
1424 << theObject << ", " << thePoint << ", "
1425 << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")";
1429 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.ScaleShapeAlongAxes("
1430 << theObject << ", " << thePoint << ", "
1431 << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")";
1435 //=============================================================================
1439 //=============================================================================
1440 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShape
1441 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theStartLCS, Handle(GEOM_Object) theEndLCS)
1445 if (theObject.IsNull() || theEndLCS.IsNull()) return NULL;
1447 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1448 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1450 //Add a Position function
1451 Standard_Integer aType = POSITION_SHAPE;
1452 if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL;
1454 Handle(GEOM_Function) aFunction =
1455 theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
1456 if (aFunction.IsNull()) return NULL;
1458 //Check if the function is set correctly
1459 if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1461 //Set operation arguments
1462 GEOMImpl_IPosition aTI (aFunction);
1463 aTI.SetShape(anOriginal);
1464 aTI.SetEndLCS(theEndLCS->GetLastFunction());
1465 if (!theStartLCS.IsNull())
1466 aTI.SetStartLCS(theObject == theStartLCS ? anOriginal : theStartLCS->GetLastFunction());
1468 //Compute the Position
1470 #if OCC_VERSION_LARGE > 0x06010000
1473 if (!GetSolver()->ComputeFunction(aFunction)) {
1474 SetErrorCode("Position driver failed");
1478 catch (Standard_Failure) {
1479 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1480 SetErrorCode(aFail->GetMessageString());
1484 //Make a Python command
1485 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.PositionShape("
1486 << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
1492 //=============================================================================
1496 //=============================================================================
1497 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShapeCopy
1498 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theStartLCS, Handle(GEOM_Object) theEndLCS)
1502 if (theObject.IsNull() || theEndLCS.IsNull()) return NULL;
1504 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1505 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1507 //Add a new Copy object
1508 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1510 //Add a position function
1511 Standard_Integer aType = POSITION_SHAPE_COPY;
1512 if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL_COPY;
1514 Handle(GEOM_Function) aFunction =
1515 aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
1516 if (aFunction.IsNull()) return NULL;
1518 //Check if the function is set correctly
1519 if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1521 GEOMImpl_IPosition aTI (aFunction);
1522 aTI.SetShape(anOriginal);
1523 aTI.SetEndLCS(theEndLCS->GetLastFunction());
1524 if (!theStartLCS.IsNull())
1525 aTI.SetStartLCS(theStartLCS->GetLastFunction());
1527 //Compute the position
1529 #if OCC_VERSION_LARGE > 0x06010000
1532 if (!GetSolver()->ComputeFunction(aFunction)) {
1533 SetErrorCode("Position driver failed");
1537 catch (Standard_Failure) {
1538 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1539 SetErrorCode(aFail->GetMessageString());
1543 //Make a Python command
1544 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakePosition("
1545 << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
1551 //=============================================================================
1555 //=============================================================================
1556 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionAlongPath
1557 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePath,
1558 double theDistance, bool theCopy, bool theReverse)
1562 if (theObject.IsNull() || thePath.IsNull()) return NULL;
1564 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1565 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1567 //Add a position function
1568 Handle(GEOM_Function) aFunction;
1569 Handle(GEOM_Object) aCopy;
1572 aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1573 aFunction = aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
1576 aFunction = theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_ALONG_PATH);
1578 if (aFunction.IsNull()) return NULL;
1580 //Check if the function is set correctly
1581 if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1583 GEOMImpl_IPosition aTI (aFunction);
1584 aTI.SetShape(anOriginal);
1585 aTI.SetPath(thePath->GetLastFunction());
1586 aTI.SetDistance(theDistance);
1587 aTI.SetReverse(theReverse);
1589 //Compute the position
1591 #if OCC_VERSION_LARGE > 0x06010000
1594 if (!GetSolver()->ComputeFunction(aFunction)) {
1595 SetErrorCode("Position driver failed");
1599 catch (Standard_Failure) {
1600 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1601 SetErrorCode(aFail->GetMessageString());
1605 //Make a Python command
1607 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.PositionAlongPath("
1608 << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
1613 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.PositionAlongPath("
1614 << theObject << ", " << thePath << ", " << theDistance << ", " << theCopy << ", " << theReverse << ")";
1620 //=============================================================================
1624 //=============================================================================
1625 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate (Handle(GEOM_Object) theObject,
1626 Handle(GEOM_Object) theAxis,
1631 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1633 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1634 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1636 // Get last functions of the arguments
1637 Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
1639 //Add a rotate function
1640 aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE);
1642 if (aFunction.IsNull()) return NULL;
1644 //Check if the function is set correctly
1645 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1647 GEOMImpl_IRotate aRI(aFunction);
1649 aRI.SetOriginal(aLastFunction);
1650 aRI.SetAngle(theAngle);
1652 //Compute the translation
1654 #if OCC_VERSION_LARGE > 0x06010000
1657 if (!GetSolver()->ComputeFunction(aFunction)) {
1658 SetErrorCode("Rotate driver failed");
1662 catch (Standard_Failure) {
1663 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1664 SetErrorCode(aFail->GetMessageString());
1668 //Make a Python command
1669 GEOM::TPythonDump(aFunction) << "geompy.Rotate(" << theObject
1670 << ", " << theAxis << ", " << theAngle * 180.0 / M_PI << "*math.pi/180.0)";
1676 //=============================================================================
1680 //=============================================================================
1681 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateCopy (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis, double theAngle)
1685 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1687 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1688 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1690 //Add a new Copy object
1691 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1693 //Add a rotate function
1694 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_COPY);
1695 if (aFunction.IsNull()) return NULL;
1697 //Check if the function is set correctly
1698 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1700 GEOMImpl_IRotate aRI(aFunction);
1701 aRI.SetAxis(theAxis->GetLastFunction());
1702 aRI.SetOriginal(aLastFunction);
1703 aRI.SetAngle(theAngle);
1705 //Compute the translation
1707 #if OCC_VERSION_LARGE > 0x06010000
1710 if (!GetSolver()->ComputeFunction(aFunction)) {
1711 SetErrorCode("Rotate driver failed");
1715 catch (Standard_Failure) {
1716 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1717 SetErrorCode(aFail->GetMessageString());
1721 //Make a Python command
1722 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotation(" << theObject
1723 << ", " << theAxis << ", " << theAngle * 180.0 / M_PI << "*math.pi/180.0)";
1729 //=============================================================================
1733 //=============================================================================
1734 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate1D (Handle(GEOM_Object) theObject,
1735 Handle(GEOM_Object) theAxis,
1736 Standard_Integer theNbTimes)
1740 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1742 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1743 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1745 //Add a new Copy object
1746 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1748 //Add a rotate function
1749 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_1D);
1750 if (aFunction.IsNull()) return NULL;
1752 //Check if the function is set correctly
1753 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1755 GEOMImpl_IRotate aRI(aFunction);
1756 aRI.SetOriginal(aLastFunction);
1757 aRI.SetAxis(theAxis->GetLastFunction());
1758 aRI.SetNbIter1(theNbTimes);
1760 //Compute the translation
1762 #if OCC_VERSION_LARGE > 0x06010000
1765 if (!GetSolver()->ComputeFunction(aFunction)) {
1766 SetErrorCode("Rotate driver failed");
1770 catch (Standard_Failure) {
1771 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1772 SetErrorCode(aFail->GetMessageString());
1776 //Make a Python command
1777 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate1D("
1778 << theObject << ", " << theAxis << ", " << theNbTimes << ")";
1784 //=============================================================================
1788 //=============================================================================
1789 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate2D (Handle(GEOM_Object) theObject,
1790 Handle(GEOM_Object) theAxis,
1792 Standard_Integer theNbTimes1,
1794 Standard_Integer theNbTimes2)
1798 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1800 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1801 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1803 //Add a new Copy object
1804 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1806 //Add a rotate function
1807 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_2D);
1808 if (aFunction.IsNull()) return NULL;
1810 //Check if the function is set correctly
1811 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1813 GEOMImpl_IRotate aRI(aFunction);
1814 aRI.SetAxis(theAxis->GetLastFunction());
1815 aRI.SetOriginal(aLastFunction);
1816 aRI.SetNbIter1(theNbTimes1);
1817 aRI.SetNbIter2(theNbTimes2);
1818 aRI.SetAngle(theAngle);
1819 aRI.SetStep(theStep);
1821 //Compute the translation
1823 #if OCC_VERSION_LARGE > 0x06010000
1826 if (!GetSolver()->ComputeFunction(aFunction)) {
1827 SetErrorCode("Rotate driver failed");
1831 catch (Standard_Failure) {
1832 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1833 SetErrorCode(aFail->GetMessageString());
1837 //Make a Python command
1838 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate2D("
1839 << theObject << ", " << theAxis << ", " << theAngle << ", "
1840 << theNbTimes1 << ", " << theStep << ", " << theNbTimes2 << ")";
1846 //=============================================================================
1850 //=============================================================================
1851 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePoints (Handle(GEOM_Object) theObject,
1852 Handle(GEOM_Object) theCentPoint,
1853 Handle(GEOM_Object) thePoint1,
1854 Handle(GEOM_Object) thePoint2)
1858 if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1860 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1861 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1863 // Get last functions of the arguments
1864 Handle(GEOM_Function) aCPF = theCentPoint->GetLastFunction();
1865 Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction();
1866 Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction();
1869 //Add a rotate function
1870 aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS);
1872 if (aFunction.IsNull()) return NULL;
1874 //Check if the function is set correctly
1875 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1877 GEOMImpl_IRotate aRI(aFunction);
1878 aRI.SetCentPoint(aCPF);
1879 aRI.SetPoint1(aP1F);
1880 aRI.SetPoint2(aP2F);
1881 aRI.SetOriginal(aLastFunction);
1883 //Compute the translation
1885 #if OCC_VERSION_LARGE > 0x06010000
1888 if (!GetSolver()->ComputeFunction(aFunction)) {
1889 SetErrorCode("Rotate driver failed");
1893 catch (Standard_Failure) {
1894 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1895 SetErrorCode(aFail->GetMessageString());
1899 //Make a Python command
1900 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.RotateThreePoints(" << theObject
1901 << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
1907 //=============================================================================
1909 * RotateThreePointsCopy
1911 //=============================================================================
1912 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePointsCopy (Handle(GEOM_Object) theObject,
1913 Handle(GEOM_Object) theCentPoint,
1914 Handle(GEOM_Object) thePoint1,
1915 Handle(GEOM_Object) thePoint2)
1919 if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
1921 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1922 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1924 //Add a new Copy object
1925 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1927 //Add a rotate function
1928 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS_COPY);
1929 if (aFunction.IsNull()) return NULL;
1931 //Check if the function is set correctly
1932 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1934 GEOMImpl_IRotate aRI(aFunction);
1935 aRI.SetCentPoint(theCentPoint->GetLastFunction());
1936 aRI.SetPoint1(thePoint1->GetLastFunction());
1937 aRI.SetPoint2(thePoint2->GetLastFunction());
1938 aRI.SetOriginal(aLastFunction);
1940 //Compute the translation
1942 #if OCC_VERSION_LARGE > 0x06010000
1945 if (!GetSolver()->ComputeFunction(aFunction)) {
1946 SetErrorCode("Rotate driver failed");
1950 catch (Standard_Failure) {
1951 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1952 SetErrorCode(aFail->GetMessageString());
1956 //Make a Python command
1957 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotationThreePoints(" << theObject
1958 << ", " << theCentPoint << ", "<<thePoint1 << ", " << thePoint2 << ")";
1964 //=============================================================================
1966 * TransformLikeOtherCopy
1968 //=============================================================================
1969 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TransformLikeOtherCopy
1970 (Handle(GEOM_Object) theObject,
1971 Handle(GEOM_Object) theSample)
1975 if (theObject.IsNull() || theSample.IsNull()) return NULL;
1977 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
1978 if (aLastFunction.IsNull()) return NULL; // There is no function which creates an object to be transformed
1980 Handle(GEOM_Function) aSampleFunc = theSample->GetLastFunction();
1981 if (aSampleFunc.IsNull()) return NULL; // There is no function which creates a sample object
1983 // Add a new Copy object
1984 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1986 // Add a transform function (depends on theSample function)
1987 Handle(GEOM_Function) aFunction =
1988 aCopy->AddFunction(aSampleFunc->GetDriverGUID(), aSampleFunc->GetType());
1989 if (aFunction.IsNull()) return NULL;
1991 // Check if the function is set correctly
1992 if (aFunction->GetDriverGUID() != aSampleFunc->GetDriverGUID()) return NULL;
1994 if (aSampleFunc->GetDriverGUID() == GEOMImpl_TranslateDriver::GetID()) {
1995 switch (aSampleFunc->GetType()) {
1998 GEOMImpl_ITranslate aRI_sample (aSampleFunc);
1999 GEOMImpl_ITranslate aRI_target (aFunction);
2001 aRI_target.SetVector(aRI_sample.GetVector());
2002 aRI_target.SetStep1(aRI_sample.GetStep1());
2003 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2005 aRI_target.SetOriginal(aLastFunction);
2010 GEOMImpl_ITranslate aRI_sample (aSampleFunc);
2011 GEOMImpl_ITranslate aRI_target (aFunction);
2013 aRI_target.SetVector(aRI_sample.GetVector());
2014 aRI_target.SetStep1(aRI_sample.GetStep1());
2015 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2017 aRI_target.SetVector2(aRI_sample.GetVector2());
2018 aRI_target.SetStep2(aRI_sample.GetStep2());
2019 aRI_target.SetNbIter2(aRI_sample.GetNbIter2());
2021 aRI_target.SetOriginal(aLastFunction);
2026 SetErrorCode("Not implemented case of TransformLikeOtherCopy");
2031 else if (aSampleFunc->GetDriverGUID() == GEOMImpl_RotateDriver::GetID()) {
2032 switch (aSampleFunc->GetType()) {
2035 GEOMImpl_IRotate aRI_sample (aSampleFunc);
2036 GEOMImpl_IRotate aRI_target (aFunction);
2038 aRI_target.SetAxis(aRI_sample.GetAxis());
2039 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2041 aRI_target.SetOriginal(aLastFunction);
2046 GEOMImpl_IRotate aRI_sample (aSampleFunc);
2047 GEOMImpl_IRotate aRI_target (aFunction);
2049 aRI_target.SetAxis(aRI_sample.GetAxis());
2051 aRI_target.SetNbIter1(aRI_sample.GetNbIter1());
2052 aRI_target.SetNbIter2(aRI_sample.GetNbIter2());
2054 aRI_target.SetAngle(aRI_sample.GetAngle());
2055 aRI_target.SetStep(aRI_sample.GetStep());
2057 aRI_target.SetDir2(aRI_sample.GetDir2());
2059 aRI_target.SetOriginal(aLastFunction);
2062 case ROTATE_THREE_POINTS_COPY:
2064 GEOMImpl_IRotate aRI_sample (aSampleFunc);
2065 GEOMImpl_IRotate aRI_target (aFunction);
2067 aRI_target.SetCentPoint(aRI_sample.GetCentPoint());
2068 aRI_target.SetPoint1(aRI_sample.GetPoint1());
2069 aRI_target.SetPoint2(aRI_sample.GetPoint2());
2071 aRI_target.SetOriginal(aLastFunction);
2076 SetErrorCode("Not implemented case of TransformLikeOtherCopy");
2082 SetErrorCode("Not implemented case of TransformLikeOtherCopy");
2086 // Compute the transformation
2088 #if OCC_VERSION_LARGE > 0x06010000
2091 if (!GetSolver()->ComputeFunction(aFunction)) {
2092 SetErrorCode("Driver failed");
2096 catch (Standard_Failure) {
2097 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2098 SetErrorCode(aFail->GetMessageString());
2102 //Make a Python command
2103 //GEOM::TPythonDump(aFunction) << aCopy << " = geompy.TransformLikeOtherCopy("
2104 // << theObject << ", " << theSample << ")";