1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
20 #include <Standard_Stream.hxx>
22 #include <GEOMImpl_ITransformOperations.hxx>
24 #include "utilities.h"
26 #include <Utils_ExceptHandlers.hxx>
28 #include <TFunction_DriverTable.hxx>
29 #include <TFunction_Driver.hxx>
30 #include <TFunction_Logbook.hxx>
31 #include <TDF_Tool.hxx>
33 #include <GEOM_Function.hxx>
34 #include <GEOM_PythonDump.hxx>
36 #include <GEOMImpl_TranslateDriver.hxx>
37 #include <GEOMImpl_MirrorDriver.hxx>
38 #include <GEOMImpl_OffsetDriver.hxx>
39 #include <GEOMImpl_ScaleDriver.hxx>
40 #include <GEOMImpl_RotateDriver.hxx>
41 #include <GEOMImpl_PositionDriver.hxx>
43 #include <GEOMImpl_ITranslate.hxx>
44 #include <GEOMImpl_IMirror.hxx>
45 #include <GEOMImpl_IOffset.hxx>
46 #include <GEOMImpl_IScale.hxx>
47 #include <GEOMImpl_IRotate.hxx>
48 #include <GEOMImpl_IPosition.hxx>
50 #include <GEOMImpl_Types.hxx>
52 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
54 //=============================================================================
58 //=============================================================================
60 GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations (GEOM_Engine* theEngine, int theDocID)
61 : GEOM_IOperations(theEngine, theDocID)
63 MESSAGE("GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations");
66 //=============================================================================
70 //=============================================================================
72 GEOMImpl_ITransformOperations::~GEOMImpl_ITransformOperations()
74 MESSAGE("GEOMImpl_ITransformOperations::~GEOMImpl_ITransformOperations");
78 //=============================================================================
82 //=============================================================================
83 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPoints
84 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
88 if (theObject.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
90 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
91 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
93 // Get last functions of the arguments
94 Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction();
95 Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction();
97 //Add a translate function
98 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_TWO_POINTS);
100 if (aFunction.IsNull()) return NULL;
102 //Check if the function is set correctly
103 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
105 GEOMImpl_ITranslate aTI (aFunction);
108 aTI.SetOriginal(aLastFunction);
110 //Compute the translation
112 if (!GetSolver()->ComputeFunction(aFunction)) {
113 SetErrorCode("Translation driver failed");
117 catch (Standard_Failure) {
118 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
119 SetErrorCode(aFail->GetMessageString());
123 //Make a Python command
124 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.TranslateTwoPoints("
125 << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
131 //=============================================================================
135 //=============================================================================
136 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZ
137 (Handle(GEOM_Object) theObject, double theX, double theY, double theZ)
141 if (theObject.IsNull()) return NULL;
143 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
144 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
146 //Add a translate function
147 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_XYZ);
149 if (aFunction.IsNull()) return NULL;
151 //Check if the function is set correctly
152 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
154 GEOMImpl_ITranslate aTI(aFunction);
158 aTI.SetOriginal(aLastFunction);
160 //Compute the translation
162 if (!GetSolver()->ComputeFunction(aFunction)) {
163 SetErrorCode("Translation driver failed");
167 catch (Standard_Failure) {
168 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
169 SetErrorCode(aFail->GetMessageString());
173 //Make a Python command
174 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.TranslateDXDYDZ("
175 << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
182 //=============================================================================
184 * TranslateTwoPointsCopy
186 //=============================================================================
187 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPointsCopy
188 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
192 if (theObject.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
194 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
195 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
197 //Add a new Copy object
198 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
200 //Add a translate function
201 Handle(GEOM_Function) aFunction =
202 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_TWO_POINTS_COPY);
204 //Check if the function is set correctly
205 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
207 GEOMImpl_ITranslate aTI(aFunction);
208 aTI.SetPoint1(thePoint1->GetLastFunction());
209 aTI.SetPoint2(thePoint2->GetLastFunction());
210 //aTI.SetShape(theObject->GetValue());
211 aTI.SetOriginal(aLastFunction);
213 //Compute the translation
215 if (!GetSolver()->ComputeFunction(aFunction)) {
216 SetErrorCode("Translation driver failed");
220 catch (Standard_Failure) {
221 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
222 SetErrorCode(aFail->GetMessageString());
226 //Make a Python command
227 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationTwoPoints("
228 << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
234 //=============================================================================
236 * TranslateDXDYDZCopy
238 //=============================================================================
239 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZCopy
240 (Handle(GEOM_Object) theObject, double theX, double theY, double theZ)
244 if (theObject.IsNull()) return NULL;
246 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
247 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
249 //Add a new Copy object
250 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
252 //Add a translate function
253 Handle(GEOM_Function) aFunction =
254 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_XYZ_COPY);
256 //Check if the function is set correctly
257 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
259 GEOMImpl_ITranslate aTI(aFunction);
263 aTI.SetOriginal(aLastFunction);
265 //Compute the translation
267 if (!GetSolver()->ComputeFunction(aFunction)) {
268 SetErrorCode("Translation driver failed");
272 catch (Standard_Failure) {
273 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
274 SetErrorCode(aFail->GetMessageString());
278 //Make a Python command
279 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslation("
280 << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
287 //=============================================================================
291 //=============================================================================
292 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVector
293 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector)
297 if (theObject.IsNull() || theVector.IsNull()) return NULL;
299 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
300 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
302 // Get last functions of the arguments
303 Handle(GEOM_Function) aVF = theVector->GetLastFunction();
305 //Add a translate function
306 aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR);
308 if (aFunction.IsNull()) return NULL;
310 //Check if the function is set correctly
311 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
313 GEOMImpl_ITranslate aTI (aFunction);
315 aTI.SetOriginal(aLastFunction);
317 //Compute the translation
319 if (!GetSolver()->ComputeFunction(aFunction)) {
320 SetErrorCode("Translation driver failed");
324 catch (Standard_Failure) {
325 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
326 SetErrorCode(aFail->GetMessageString());
330 //Make a Python command
331 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.TranslateVector("
332 << theObject << ", " << theVector << ")";
338 //=============================================================================
340 * TranslateVectorCopy
342 //=============================================================================
343 Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorCopy
344 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector)
348 if (theObject.IsNull() || theVector.IsNull()) return NULL;
350 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
351 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
353 //Add a new Copy object
354 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
356 //Add a translate function
357 Handle(GEOM_Function) aFunction =
358 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_COPY);
360 //Check if the function is set correctly
361 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
363 GEOMImpl_ITranslate aTI(aFunction);
364 aTI.SetVector(theVector->GetLastFunction());
365 // aTI.SetShape(theObject->GetValue());
366 aTI.SetOriginal(aLastFunction);
368 //Compute the translation
370 if (!GetSolver()->ComputeFunction(aFunction)) {
371 SetErrorCode("Translation driver failed");
375 catch (Standard_Failure) {
376 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
377 SetErrorCode(aFail->GetMessageString());
381 //Make a Python command
382 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeTranslationVector("
383 << theObject << ", " << theVector << ")";
389 //=============================================================================
393 //=============================================================================
394 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate1D
395 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector,
396 double theStep, Standard_Integer theNbTimes)
400 if (theObject.IsNull() || theVector.IsNull()) return NULL;
402 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
403 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
405 //Add a new Copy object
406 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
408 //Add a translate function
409 Handle(GEOM_Function) aFunction =
410 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_1D);
412 //Check if the function is set correctly
413 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
415 GEOMImpl_ITranslate aTI(aFunction);
416 aTI.SetVector(theVector->GetLastFunction());
417 aTI.SetOriginal(aLastFunction);
418 aTI.SetStep1(theStep);
419 aTI.SetNbIter1(theNbTimes);
421 //Compute the translation
423 if (!GetSolver()->ComputeFunction(aFunction)) {
424 SetErrorCode("Translation driver failed");
428 catch (Standard_Failure) {
429 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
430 SetErrorCode(aFail->GetMessageString());
434 //Make a Python command
435 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMultiTranslation1D("
436 << theObject << ", " << theVector << ", " << theStep << ", " << theNbTimes << ")";
442 //=============================================================================
446 //=============================================================================
447 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate2D (Handle(GEOM_Object) theObject,
448 Handle(GEOM_Object) theVector,
450 Standard_Integer theNbTimes1,
451 Handle(GEOM_Object) theVector2,
453 Standard_Integer theNbTimes2)
457 if (theObject.IsNull() || theVector.IsNull() || theVector2.IsNull()) return NULL;
459 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
460 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
462 //Add a new Copy object
463 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
465 //Add a translate function
466 Handle(GEOM_Function) aFunction =
467 aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_2D);
469 //Check if the function is set correctly
470 if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
472 GEOMImpl_ITranslate aTI(aFunction);
473 aTI.SetVector(theVector->GetLastFunction());
474 aTI.SetVector2(theVector2->GetLastFunction());
475 aTI.SetOriginal(aLastFunction);
476 aTI.SetStep1(theStep1);
477 aTI.SetNbIter1(theNbTimes1);
478 aTI.SetStep2(theStep2);
479 aTI.SetNbIter2(theNbTimes2);
481 //Compute the translation
483 if (!GetSolver()->ComputeFunction(aFunction)) {
484 SetErrorCode("Translation driver failed");
488 catch (Standard_Failure) {
489 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
490 SetErrorCode(aFail->GetMessageString());
494 //Make a Python command
495 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMultiTranslation2D("
496 << theObject << ", " << theVector << ", " << theStep1 << ", " << theNbTimes1
497 << ", " << theVector2 << ", " << theStep2 << ", " << theNbTimes2 << ")";
504 //=============================================================================
508 //=============================================================================
509 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlane
510 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePlane)
514 if (theObject.IsNull() || thePlane.IsNull()) return NULL;
516 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
517 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
519 // Get last functions of the arguments
520 Handle(GEOM_Function) aPF = thePlane->GetLastFunction();
522 //Add a mirror function
523 Handle(GEOM_Function) aFunction =
524 theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_PLANE);
525 if (aFunction.IsNull()) return NULL;
527 //Check if the function is set correctly
528 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
530 GEOMImpl_IMirror aTI (aFunction);
532 aTI.SetOriginal(aLastFunction);
536 if (!GetSolver()->ComputeFunction(aFunction)) {
537 SetErrorCode("Mirror driver failed");
541 catch (Standard_Failure) {
542 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
543 SetErrorCode(aFail->GetMessageString());
547 //Make a Python command
548 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorPlane("
549 << theObject << ", " << thePlane << ")";
555 //=============================================================================
559 //=============================================================================
560 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlaneCopy
561 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePlane)
565 if (theObject.IsNull() || thePlane.IsNull()) return NULL;
567 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
568 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
570 //Add a new Copy object
571 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
573 //Add a mirror function
574 Handle(GEOM_Function) aFunction =
575 aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_PLANE_COPY);
577 //Check if the function is set correctly
578 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
580 GEOMImpl_IMirror aTI (aFunction);
581 aTI.SetPlane(thePlane->GetLastFunction());
582 aTI.SetOriginal(aLastFunction);
586 if (!GetSolver()->ComputeFunction(aFunction)) {
587 SetErrorCode("Mirror driver failed");
591 catch (Standard_Failure) {
592 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
593 SetErrorCode(aFail->GetMessageString());
597 //Make a Python command
598 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByPlane("
599 << theObject << ", " << thePlane << ")";
605 //=============================================================================
609 //=============================================================================
610 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPoint
611 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint)
615 if (theObject.IsNull() || thePoint.IsNull()) return NULL;
617 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
618 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
620 // Get last functions of the arguments
621 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
623 //Add a mirror function
624 Handle(GEOM_Function) aFunction =
625 theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_POINT);
626 if (aFunction.IsNull()) return NULL;
628 //Check if the function is set correctly
629 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
631 GEOMImpl_IMirror aTI (aFunction);
633 aTI.SetOriginal(aLastFunction);
637 if (!GetSolver()->ComputeFunction(aFunction)) {
638 SetErrorCode("Mirror driver failed");
642 catch (Standard_Failure) {
643 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
644 SetErrorCode(aFail->GetMessageString());
648 //Make a Python command
649 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorPoint("
650 << theObject << ", " << thePoint << ")";
656 //=============================================================================
660 //=============================================================================
661 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPointCopy
662 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint)
666 if (theObject.IsNull() || thePoint.IsNull()) return NULL;
668 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
669 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
671 //Add a new Copy object
672 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
674 //Add a mirror function
675 Handle(GEOM_Function) aFunction =
676 aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_POINT_COPY);
678 //Check if the function is set correctly
679 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
681 GEOMImpl_IMirror aTI (aFunction);
682 aTI.SetPoint(thePoint->GetLastFunction());
683 aTI.SetOriginal(aLastFunction);
687 if (!GetSolver()->ComputeFunction(aFunction)) {
688 SetErrorCode("Mirror driver failed");
692 catch (Standard_Failure) {
693 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
694 SetErrorCode(aFail->GetMessageString());
698 //Make a Python command
699 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeMirrorByPoint("
700 << theObject << ", " << thePoint << ")";
706 //=============================================================================
710 //=============================================================================
711 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxis
712 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis)
716 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
718 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
719 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
721 // Get last functions of the arguments
722 Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
724 //Add a mirror function
725 Handle(GEOM_Function) aFunction =
726 theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_AXIS);
727 if (aFunction.IsNull()) return NULL;
729 //Check if the function is set correctly
730 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
732 GEOMImpl_IMirror aTI (aFunction);
734 aTI.SetOriginal(aLastFunction);
738 if (!GetSolver()->ComputeFunction(aFunction)) {
739 SetErrorCode("Mirror driver failed");
743 catch (Standard_Failure) {
744 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
745 SetErrorCode(aFail->GetMessageString());
749 //Make a Python command
750 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.MirrorAxis("
751 << theObject << ", " << theAxis << ")";
757 //=============================================================================
761 //=============================================================================
762 Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxisCopy
763 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis)
767 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
769 Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
770 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
772 //Add a new Copy object
773 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
775 //Add a mirror function
776 Handle(GEOM_Function) aFunction =
777 aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_AXIS_COPY);
779 //Check if the function is set correctly
780 if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
782 GEOMImpl_IMirror aTI (aFunction);
783 aTI.SetAxis(theAxis->GetLastFunction());
784 aTI.SetOriginal(aLastFunction);
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) << aCopy << " = geompy.MakeMirrorByAxis("
801 << theObject << ", " << theAxis << ")";
808 //=============================================================================
812 //=============================================================================
813 Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShape
814 (Handle(GEOM_Object) theObject, double theOffset)
818 if (theObject.IsNull()) return NULL;
820 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
821 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
823 //Add a new Offset function
824 Handle(GEOM_Function) aFunction =
825 theObject->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE);
826 if (aFunction.IsNull()) return NULL;
828 //Check if the function is set correctly
829 if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
831 GEOMImpl_IOffset aTI (aFunction);
832 aTI.SetShape(anOriginal);
833 aTI.SetValue(theOffset);
837 if (!GetSolver()->ComputeFunction(aFunction)) {
838 SetErrorCode("Offset driver failed");
842 catch (Standard_Failure) {
843 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
844 SetErrorCode(aFail->GetMessageString());
848 //Make a Python command
849 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.OffsetShape("
850 << theObject << ", " << theOffset << ")";
856 //=============================================================================
860 //=============================================================================
861 Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShapeCopy
862 (Handle(GEOM_Object) theObject, double theOffset)
866 if (theObject.IsNull()) return NULL;
868 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
869 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
871 //Add a new Copy object
872 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
874 //Add a new Offset function
875 Handle(GEOM_Function) aFunction =
876 aCopy->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE_COPY);
877 if (aFunction.IsNull()) return NULL;
879 //Check if the function is set correctly
880 if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
882 GEOMImpl_IOffset aTI (aFunction);
883 aTI.SetShape(anOriginal);
884 aTI.SetValue(theOffset);
888 if (!GetSolver()->ComputeFunction(aFunction)) {
889 SetErrorCode("Offset driver failed");
893 catch (Standard_Failure) {
894 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
895 SetErrorCode(aFail->GetMessageString());
899 //Make a Python command
900 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeOffset("
901 << theObject << ", " << theOffset << ")";
908 //=============================================================================
912 //=============================================================================
913 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShape
914 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, double theFactor)
918 if (theObject.IsNull() || thePoint.IsNull()) return NULL;
920 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
921 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
923 // Get last functions of the arguments
924 Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
926 //Add a scale function
927 Handle(GEOM_Function) aFunction =
928 theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE);
929 if (aFunction.IsNull()) return NULL;
931 //Check if the function is set correctly
932 if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
934 GEOMImpl_IScale aTI (aFunction);
935 aTI.SetShape(anOriginal);
937 aTI.SetFactor(theFactor);
941 if (!GetSolver()->ComputeFunction(aFunction)) {
942 SetErrorCode("Scale driver failed");
946 catch (Standard_Failure) {
947 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
948 SetErrorCode(aFail->GetMessageString());
952 //Make a Python command
953 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.ScaleShape("
954 << theObject << ", " << thePoint << ", " << theFactor << ")";
960 //=============================================================================
964 //=============================================================================
965 Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeCopy
966 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, double theFactor)
970 if (theObject.IsNull() || thePoint.IsNull()) return NULL;
972 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
973 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
975 //Add a new Copy object
976 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
978 //Add a scale function
979 Handle(GEOM_Function) aFunction =
980 aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_COPY);
981 if (aFunction.IsNull()) return NULL;
983 //Check if the function is set correctly
984 if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
986 GEOMImpl_IScale aTI (aFunction);
987 aTI.SetShape(anOriginal);
988 aTI.SetPoint(thePoint->GetLastFunction());
989 aTI.SetFactor(theFactor);
993 if (!GetSolver()->ComputeFunction(aFunction)) {
994 SetErrorCode("Scale driver failed");
998 catch (Standard_Failure) {
999 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1000 SetErrorCode(aFail->GetMessageString());
1004 //Make a Python command
1005 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeScaleTransform("
1006 << theObject << ", " << thePoint << ", " << theFactor << ")";
1012 //=============================================================================
1016 //=============================================================================
1017 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShape
1018 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theStartLCS, Handle(GEOM_Object) theEndLCS)
1022 if (theObject.IsNull() || theStartLCS.IsNull() || theEndLCS.IsNull()) return NULL;
1024 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1025 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1027 // Get last functions of the arguments
1028 Handle(GEOM_Function) aStartLCS = theStartLCS->GetLastFunction();
1029 Handle(GEOM_Function) aEndLCS = theEndLCS->GetLastFunction();
1031 //Add a Position function
1032 Handle(GEOM_Function) aFunction =
1033 theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_SHAPE);
1034 if (aFunction.IsNull()) return NULL;
1036 //Check if the function is set correctly
1037 if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1039 GEOMImpl_IPosition aTI (aFunction);
1040 aTI.SetShape(anOriginal);
1041 aTI.SetStartLCS(aStartLCS);
1042 aTI.SetEndLCS(aEndLCS);
1044 //Compute the Position
1046 if (!GetSolver()->ComputeFunction(aFunction)) {
1047 SetErrorCode("Position driver failed");
1051 catch (Standard_Failure) {
1052 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1053 SetErrorCode(aFail->GetMessageString());
1057 //Make a Python command
1058 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.PositionShape("
1059 << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
1065 //=============================================================================
1069 //=============================================================================
1070 Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShapeCopy
1071 (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theStartLCS, Handle(GEOM_Object) theEndLCS)
1075 if (theObject.IsNull() || theStartLCS.IsNull() || theEndLCS.IsNull()) return NULL;
1077 Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
1078 if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
1080 //Add a new Copy object
1081 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1083 //Add a position function
1084 Handle(GEOM_Function) aFunction =
1085 aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), POSITION_SHAPE_COPY);
1086 if (aFunction.IsNull()) return NULL;
1088 //Check if the function is set correctly
1089 if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
1091 GEOMImpl_IPosition aTI (aFunction);
1092 aTI.SetShape(anOriginal);
1093 aTI.SetStartLCS(theStartLCS->GetLastFunction());
1094 aTI.SetEndLCS(theEndLCS->GetLastFunction());
1096 //Compute the position
1098 if (!GetSolver()->ComputeFunction(aFunction)) {
1099 SetErrorCode("Position driver failed");
1103 catch (Standard_Failure) {
1104 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1105 SetErrorCode(aFail->GetMessageString());
1109 //Make a Python command
1110 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakePosition("
1111 << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
1117 //=============================================================================
1121 //=============================================================================
1122 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate (Handle(GEOM_Object) theObject,
1123 Handle(GEOM_Object) theAxis,
1128 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1130 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1131 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1133 // Get last functions of the arguments
1134 Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
1136 //Add a rotate function
1137 aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE);
1139 if (aFunction.IsNull()) return NULL;
1141 //Check if the function is set correctly
1142 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1144 GEOMImpl_IRotate aRI(aFunction);
1146 aRI.SetOriginal(aLastFunction);
1147 aRI.SetAngle(theAngle);
1149 //Compute the translation
1151 if (!GetSolver()->ComputeFunction(aFunction)) {
1152 SetErrorCode("Rotate driver failed");
1156 catch (Standard_Failure) {
1157 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1158 SetErrorCode(aFail->GetMessageString());
1162 //Make a Python command
1163 GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.Rotate(" << theObject
1164 << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
1170 //=============================================================================
1174 //=============================================================================
1175 Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateCopy (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis, double theAngle)
1179 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1181 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1182 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1184 //Add a new Copy object
1185 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1187 //Add a rotate function
1188 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_COPY);
1189 if (aFunction.IsNull()) return NULL;
1191 //Check if the function is set correctly
1192 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1194 GEOMImpl_IRotate aRI(aFunction);
1195 aRI.SetAxis(theAxis->GetLastFunction());
1196 aRI.SetOriginal(aLastFunction);
1197 aRI.SetAngle(theAngle);
1199 //Compute the translation
1201 if (!GetSolver()->ComputeFunction(aFunction)) {
1202 SetErrorCode("Rotate driver failed");
1206 catch (Standard_Failure) {
1207 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1208 SetErrorCode(aFail->GetMessageString());
1212 //Make a Python command
1213 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotation(" << theObject
1214 << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)";
1220 //=============================================================================
1224 //=============================================================================
1225 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate1D (Handle(GEOM_Object) theObject,
1226 Handle(GEOM_Object) theAxis,
1227 Standard_Integer theNbTimes)
1231 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1233 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1234 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1236 //Add a new Copy object
1237 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1239 //Add a rotate function
1240 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_1D);
1241 if (aFunction.IsNull()) return NULL;
1243 //Check if the function is set correctly
1244 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1246 GEOMImpl_IRotate aRI(aFunction);
1247 aRI.SetOriginal(aLastFunction);
1248 aRI.SetAxis(theAxis->GetLastFunction());
1249 aRI.SetNbIter1(theNbTimes);
1251 //Compute the translation
1253 if (!GetSolver()->ComputeFunction(aFunction)) {
1254 SetErrorCode("Rotate driver failed");
1258 catch (Standard_Failure) {
1259 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1260 SetErrorCode(aFail->GetMessageString());
1264 //Make a Python command
1265 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate1D("
1266 << theObject << ", " << theAxis << ", " << theNbTimes << ")";
1272 //=============================================================================
1276 //=============================================================================
1277 Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate2D (Handle(GEOM_Object) theObject,
1278 Handle(GEOM_Object) theAxis,
1280 Standard_Integer theNbTimes1,
1282 Standard_Integer theNbTimes2)
1286 if (theObject.IsNull() || theAxis.IsNull()) return NULL;
1288 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1289 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
1291 //Add a new Copy object
1292 Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1294 //Add a rotate function
1295 aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_2D);
1296 if (aFunction.IsNull()) return NULL;
1298 //Check if the function is set correctly
1299 if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
1301 GEOMImpl_IRotate aRI(aFunction);
1302 aRI.SetAxis(theAxis->GetLastFunction());
1303 aRI.SetOriginal(aLastFunction);
1304 aRI.SetNbIter1(theNbTimes1);
1305 aRI.SetNbIter2(theNbTimes2);
1306 aRI.SetAngle(theAngle);
1307 aRI.SetStep(theStep);
1309 //Compute the translation
1311 if (!GetSolver()->ComputeFunction(aFunction)) {
1312 SetErrorCode("Rotate driver failed");
1316 catch (Standard_Failure) {
1317 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1318 SetErrorCode(aFail->GetMessageString());
1322 //Make a Python command
1323 GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MultiRotate2D("
1324 << theObject << ", " << theAxis << ", " << theAngle << ", "
1325 << theNbTimes1 << ", " << theStep << ", " << theNbTimes2 << ")";