/src/contrib/geom-5.1.2.7/src/GEOMImpl/GEOMImpl_ITransformOperations.cpp

http://pythonocc.googlecode.com/ · C++ · 1782 lines · 1119 code · 328 blank · 335 comment · 215 complexity · 260d8e4f051e2e58186a812bf24f3979 MD5 · raw file

Large files are truncated click here to view the full file

  1. // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
  2. // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
  3. //
  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.
  8. //
  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.
  13. //
  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
  17. //
  18. // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
  19. //
  20. #include "utilities.h"
  21. #include <Standard_Stream.hxx>
  22. #include <GEOMImpl_ITransformOperations.hxx>
  23. #define SETPARAM(aFUNC,aVAL) \
  24. if (aVAL.IsString()) \
  25. aFUNC( aVAL.GetString() ); \
  26. else \
  27. aFUNC( aVAL.GetDouble() );
  28. #include <TFunction_DriverTable.hxx>
  29. #include <TFunction_Driver.hxx>
  30. #include <TFunction_Logbook.hxx>
  31. #include <TDF_Tool.hxx>
  32. #include <GEOM_Function.hxx>
  33. #include <GEOM_PythonDump.hxx>
  34. #include <GEOMImpl_TranslateDriver.hxx>
  35. #include <GEOMImpl_MirrorDriver.hxx>
  36. #include <GEOMImpl_OffsetDriver.hxx>
  37. #include <GEOMImpl_ScaleDriver.hxx>
  38. #include <GEOMImpl_RotateDriver.hxx>
  39. #include <GEOMImpl_PositionDriver.hxx>
  40. #include <GEOMImpl_ITranslate.hxx>
  41. #include <GEOMImpl_IMirror.hxx>
  42. #include <GEOMImpl_IOffset.hxx>
  43. #include <GEOMImpl_IScale.hxx>
  44. #include <GEOMImpl_IRotate.hxx>
  45. #include <GEOMImpl_IPosition.hxx>
  46. #include <GEOMImpl_Types.hxx>
  47. #include <Standard_Failure.hxx>
  48. #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
  49. //=============================================================================
  50. /*!
  51. * constructor:
  52. */
  53. //=============================================================================
  54. GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations (GEOM_Engine* theEngine, int theDocID)
  55. : GEOM_IOperations(theEngine, theDocID)
  56. {
  57. //MESSAGE("GEOMImpl_ITransformOperations::GEOMImpl_ITransformOperations");
  58. }
  59. //=============================================================================
  60. /*!
  61. * destructor
  62. */
  63. //=============================================================================
  64. GEOMImpl_ITransformOperations::~GEOMImpl_ITransformOperations()
  65. {
  66. //MESSAGE("GEOMImpl_ITransformOperations::~GEOMImpl_ITransformOperations");
  67. }
  68. //=============================================================================
  69. /*!
  70. * TranslateTwoPoints
  71. */
  72. //=============================================================================
  73. Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPoints
  74. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
  75. {
  76. SetErrorCode(GEOM_KO);
  77. if (theObject.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
  78. Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
  79. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
  80. // Get last functions of the arguments
  81. Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction();
  82. Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction();
  83. //Add a translate function
  84. aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_TWO_POINTS);
  85. if (aFunction.IsNull()) return NULL;
  86. //Check if the function is set correctly
  87. if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
  88. GEOMImpl_ITranslate aTI (aFunction);
  89. aTI.SetPoint1(aP1F);
  90. aTI.SetPoint2(aP2F);
  91. aTI.SetOriginal(aLastFunction);
  92. //Compute the translation
  93. try {
  94. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  95. OCC_CATCH_SIGNALS;
  96. #endif
  97. if (!GetSolver()->ComputeFunction(aFunction)) {
  98. SetErrorCode("Translation driver failed");
  99. return NULL;
  100. }
  101. }
  102. catch (Standard_Failure) {
  103. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  104. SetErrorCode(aFail->GetMessageString());
  105. return NULL;
  106. }
  107. //Make a Python command
  108. GEOM::TPythonDump(aFunction) << "TranslateTwoPoints("
  109. << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
  110. SetErrorCode(GEOM_OK);
  111. return theObject;
  112. }
  113. //=============================================================================
  114. /*!
  115. * TranslateDXDYDZ
  116. */
  117. //=============================================================================
  118. Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZ
  119. (Handle(GEOM_Object) theObject, const GEOM_Parameter& theX, const GEOM_Parameter& theY, const GEOM_Parameter& theZ)
  120. {
  121. SetErrorCode(GEOM_KO);
  122. if (theObject.IsNull()) return NULL;
  123. Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
  124. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
  125. //Add a translate function
  126. aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_XYZ);
  127. if (aFunction.IsNull()) return NULL;
  128. //Check if the function is set correctly
  129. if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
  130. GEOMImpl_ITranslate aTI(aFunction);
  131. SETPARAM(aTI.SetDX,theX);
  132. SETPARAM(aTI.SetDY,theY);
  133. SETPARAM(aTI.SetDZ,theZ);
  134. aTI.SetOriginal(aLastFunction);
  135. //Compute the translation
  136. try {
  137. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  138. OCC_CATCH_SIGNALS;
  139. #endif
  140. if (!GetSolver()->ComputeFunction(aFunction)) {
  141. SetErrorCode("Translation driver failed");
  142. return NULL;
  143. }
  144. }
  145. catch (Standard_Failure) {
  146. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  147. SetErrorCode(aFail->GetMessageString());
  148. return NULL;
  149. }
  150. //Make a Python command
  151. GEOM::TPythonDump(aFunction) << "TranslateDXDYDZ("
  152. << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
  153. SetErrorCode(GEOM_OK);
  154. return theObject;
  155. }
  156. //=============================================================================
  157. /*!
  158. * TranslateTwoPointsCopy
  159. */
  160. //=============================================================================
  161. Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPointsCopy
  162. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2)
  163. {
  164. SetErrorCode(GEOM_KO);
  165. if (theObject.IsNull() || thePoint1.IsNull() || thePoint2.IsNull()) return NULL;
  166. Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
  167. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
  168. //Add a new Copy object
  169. Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
  170. //Add a translate function
  171. Handle(GEOM_Function) aFunction =
  172. aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_TWO_POINTS_COPY);
  173. //Check if the function is set correctly
  174. if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
  175. GEOMImpl_ITranslate aTI(aFunction);
  176. aTI.SetPoint1(thePoint1->GetLastFunction());
  177. aTI.SetPoint2(thePoint2->GetLastFunction());
  178. //aTI.SetShape(theObject->GetValue());
  179. aTI.SetOriginal(aLastFunction);
  180. //Compute the translation
  181. try {
  182. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  183. OCC_CATCH_SIGNALS;
  184. #endif
  185. if (!GetSolver()->ComputeFunction(aFunction)) {
  186. SetErrorCode("Translation driver failed");
  187. return NULL;
  188. }
  189. }
  190. catch (Standard_Failure) {
  191. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  192. SetErrorCode(aFail->GetMessageString());
  193. return NULL;
  194. }
  195. //Make a Python command
  196. GEOM::TPythonDump(aFunction) << aCopy << " = TranslateTwoPointsCopy("
  197. << theObject << ", " << thePoint1 << ", " << thePoint2 << ")";
  198. SetErrorCode(GEOM_OK);
  199. return aCopy;
  200. }
  201. //=============================================================================
  202. /*!
  203. * TranslateDXDYDZCopy
  204. */
  205. //=============================================================================
  206. Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZCopy
  207. (Handle(GEOM_Object) theObject, const GEOM_Parameter& theX, const GEOM_Parameter& theY, const GEOM_Parameter& theZ)
  208. {
  209. SetErrorCode(GEOM_KO);
  210. if (theObject.IsNull()) return NULL;
  211. Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
  212. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
  213. //Add a new Copy object
  214. Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
  215. //Add a translate function
  216. Handle(GEOM_Function) aFunction =
  217. aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_XYZ_COPY);
  218. //Check if the function is set correctly
  219. if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
  220. GEOMImpl_ITranslate aTI(aFunction);
  221. SETPARAM(aTI.SetDX,theX);
  222. SETPARAM(aTI.SetDY,theY);
  223. SETPARAM(aTI.SetDZ,theZ);
  224. aTI.SetOriginal(aLastFunction);
  225. //Compute the translation
  226. try {
  227. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  228. OCC_CATCH_SIGNALS;
  229. #endif
  230. if (!GetSolver()->ComputeFunction(aFunction)) {
  231. SetErrorCode("Translation driver failed");
  232. return NULL;
  233. }
  234. }
  235. catch (Standard_Failure) {
  236. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  237. SetErrorCode(aFail->GetMessageString());
  238. return NULL;
  239. }
  240. //Make a Python command
  241. GEOM::TPythonDump(aFunction) << aCopy << " = TranslateDXDYDZCopy("
  242. << theObject << ", " << theX << ", " << theY << ", " << theZ << ")";
  243. SetErrorCode(GEOM_OK);
  244. return aCopy;
  245. }
  246. //=============================================================================
  247. /*!
  248. * TranslateVector
  249. */
  250. //=============================================================================
  251. Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVector
  252. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector)
  253. {
  254. SetErrorCode(GEOM_KO);
  255. if (theObject.IsNull() || theVector.IsNull()) return NULL;
  256. Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
  257. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
  258. // Get last functions of the arguments
  259. Handle(GEOM_Function) aVF = theVector->GetLastFunction();
  260. //Add a translate function
  261. aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR);
  262. if (aFunction.IsNull()) return NULL;
  263. //Check if the function is set correctly
  264. if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
  265. GEOMImpl_ITranslate aTI (aFunction);
  266. aTI.SetVector(aVF);
  267. aTI.SetOriginal(aLastFunction);
  268. //Compute the translation
  269. try {
  270. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  271. OCC_CATCH_SIGNALS;
  272. #endif
  273. if (!GetSolver()->ComputeFunction(aFunction)) {
  274. SetErrorCode("Translation driver failed");
  275. return NULL;
  276. }
  277. }
  278. catch (Standard_Failure) {
  279. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  280. SetErrorCode(aFail->GetMessageString());
  281. return NULL;
  282. }
  283. //Make a Python command
  284. GEOM::TPythonDump(aFunction) << "TranslateVector("
  285. << theObject << ", " << theVector << ")";
  286. SetErrorCode(GEOM_OK);
  287. return theObject;
  288. }
  289. //=============================================================================
  290. /*!
  291. * TranslateVectorCopy
  292. */
  293. //=============================================================================
  294. Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorCopy
  295. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector)
  296. {
  297. SetErrorCode(GEOM_KO);
  298. if (theObject.IsNull() || theVector.IsNull()) return NULL;
  299. Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
  300. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
  301. //Add a new Copy object
  302. Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
  303. //Add a translate function
  304. Handle(GEOM_Function) aFunction =
  305. aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_COPY);
  306. //Check if the function is set correctly
  307. if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
  308. GEOMImpl_ITranslate aTI(aFunction);
  309. aTI.SetVector(theVector->GetLastFunction());
  310. // aTI.SetShape(theObject->GetValue());
  311. aTI.SetOriginal(aLastFunction);
  312. //Compute the translation
  313. try {
  314. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  315. OCC_CATCH_SIGNALS;
  316. #endif
  317. if (!GetSolver()->ComputeFunction(aFunction)) {
  318. SetErrorCode("Translation driver failed");
  319. return NULL;
  320. }
  321. }
  322. catch (Standard_Failure) {
  323. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  324. SetErrorCode(aFail->GetMessageString());
  325. return NULL;
  326. }
  327. //Make a Python command
  328. GEOM::TPythonDump(aFunction) << aCopy << " = TranslateVectorCopy("
  329. << theObject << ", " << theVector << ")";
  330. SetErrorCode(GEOM_OK);
  331. return aCopy;
  332. }
  333. //=============================================================================
  334. /*!
  335. * TranslateVectorDistance
  336. */
  337. //=============================================================================
  338. Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorDistance
  339. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector, const GEOM_Parameter& theDistance, bool theCopy)
  340. {
  341. SetErrorCode(GEOM_KO);
  342. if (theObject.IsNull() || theVector.IsNull()) return NULL;
  343. Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
  344. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
  345. Handle(GEOM_Object) aCopy; //Add a new Copy object
  346. Handle(GEOM_Function) aFunction;
  347. //Add a translate function
  348. if (theCopy) {
  349. aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
  350. aFunction = aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_DISTANCE);
  351. }
  352. else {
  353. aFunction = theObject->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_VECTOR_DISTANCE);
  354. }
  355. if (aFunction.IsNull()) return NULL;
  356. //Check if the function is set correctly
  357. if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
  358. GEOMImpl_ITranslate aTI(aFunction);
  359. aTI.SetVector(theVector->GetLastFunction());
  360. SETPARAM(aTI.SetDistance,theDistance);
  361. // aTI.SetShape(theObject->GetValue());
  362. aTI.SetOriginal(aLastFunction);
  363. //Compute the translation
  364. try {
  365. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  366. OCC_CATCH_SIGNALS;
  367. #endif
  368. if (!GetSolver()->ComputeFunction(aFunction)) {
  369. SetErrorCode("Translation driver failed");
  370. return NULL;
  371. }
  372. }
  373. catch (Standard_Failure) {
  374. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  375. SetErrorCode(aFail->GetMessageString());
  376. return NULL;
  377. }
  378. //Make a Python command
  379. if (theCopy) {
  380. GEOM::TPythonDump(aFunction) << aCopy << " = MakeTranslationVectorDistance("
  381. << theObject << ", " << theVector << ", " << theDistance << ")";
  382. SetErrorCode(GEOM_OK);
  383. return aCopy;
  384. }
  385. GEOM::TPythonDump(aFunction) << "TranslateVectorDistance("
  386. << theObject << ", " << theVector << ", " << theDistance << ", " << (int)theCopy << ")";
  387. SetErrorCode(GEOM_OK);
  388. return theObject;
  389. }
  390. //=============================================================================
  391. /*!
  392. * Translate1D
  393. */
  394. //=============================================================================
  395. Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate1D
  396. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector,
  397. const GEOM_Parameter& theStep, const GEOM_Parameter& theNbTimes)
  398. {
  399. SetErrorCode(GEOM_KO);
  400. if (theObject.IsNull() || theVector.IsNull()) return NULL;
  401. Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
  402. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
  403. //Add a new Copy object
  404. Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
  405. //Add a translate function
  406. Handle(GEOM_Function) aFunction =
  407. aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_1D);
  408. //Check if the function is set correctly
  409. if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
  410. GEOMImpl_ITranslate aTI(aFunction);
  411. aTI.SetVector(theVector->GetLastFunction());
  412. aTI.SetOriginal(aLastFunction);
  413. SETPARAM(aTI.SetStep1,theStep);
  414. SETPARAM(aTI.SetNbIter1,theNbTimes);
  415. //Compute the translation
  416. try {
  417. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  418. OCC_CATCH_SIGNALS;
  419. #endif
  420. if (!GetSolver()->ComputeFunction(aFunction)) {
  421. SetErrorCode("Translation driver failed");
  422. return NULL;
  423. }
  424. }
  425. catch (Standard_Failure) {
  426. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  427. SetErrorCode(aFail->GetMessageString());
  428. return NULL;
  429. }
  430. //Make a Python command
  431. GEOM::TPythonDump(aFunction) << aCopy << " = Translate1D("
  432. << theObject << ", " << theVector << ", " << theStep << ", " << theNbTimes << ")";
  433. SetErrorCode(GEOM_OK);
  434. return aCopy;
  435. }
  436. //=============================================================================
  437. /*!
  438. * Translate2D
  439. */
  440. //=============================================================================
  441. Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate2D (Handle(GEOM_Object) theObject,
  442. Handle(GEOM_Object) theVector,
  443. const GEOM_Parameter& theStep1,
  444. const GEOM_Parameter& theNbTimes1,
  445. Handle(GEOM_Object) theVector2,
  446. const GEOM_Parameter& theStep2,
  447. const GEOM_Parameter& theNbTimes2)
  448. {
  449. SetErrorCode(GEOM_KO);
  450. if (theObject.IsNull() || theVector.IsNull() || theVector2.IsNull()) return NULL;
  451. Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
  452. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
  453. //Add a new Copy object
  454. Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
  455. //Add a translate function
  456. Handle(GEOM_Function) aFunction =
  457. aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_2D);
  458. //Check if the function is set correctly
  459. if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
  460. GEOMImpl_ITranslate aTI(aFunction);
  461. aTI.SetVector(theVector->GetLastFunction());
  462. aTI.SetVector2(theVector2->GetLastFunction());
  463. aTI.SetOriginal(aLastFunction);
  464. SETPARAM(aTI.SetStep1,theStep1);
  465. SETPARAM(aTI.SetNbIter1,theNbTimes1);
  466. SETPARAM(aTI.SetStep2,theStep2);
  467. SETPARAM(aTI.SetNbIter2,theNbTimes2);
  468. //Compute the translation
  469. try {
  470. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  471. OCC_CATCH_SIGNALS;
  472. #endif
  473. if (!GetSolver()->ComputeFunction(aFunction)) {
  474. SetErrorCode("Translation driver failed");
  475. return NULL;
  476. }
  477. }
  478. catch (Standard_Failure) {
  479. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  480. SetErrorCode(aFail->GetMessageString());
  481. return NULL;
  482. }
  483. //Make a Python command
  484. GEOM::TPythonDump(aFunction) << aCopy << " = Translate2D("
  485. << theObject << ", " << theVector << ", " << theStep1 << ", " << theNbTimes1
  486. << ", " << theVector2 << ", " << theStep2 << ", " << theNbTimes2 << ")";
  487. SetErrorCode(GEOM_OK);
  488. return aCopy;
  489. }
  490. //=============================================================================
  491. /*!
  492. * TranslateAlongRail
  493. */
  494. //=============================================================================
  495. Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateAlongRail( Handle(GEOM_Object) theObject,
  496. Handle(GEOM_Object) theRail, const GEOM_Parameter& theStep,
  497. const GEOM_Parameter& theNbTimes, const GEOM_Parameter& theType)
  498. {
  499. SetErrorCode(GEOM_KO);
  500. if (theObject.IsNull() || theRail.IsNull()) return NULL;
  501. Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
  502. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be moved
  503. //Add a new Copy object
  504. Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
  505. //Add a translate function
  506. Handle(GEOM_Function) aFunction =
  507. aCopy->AddFunction(GEOMImpl_TranslateDriver::GetID(), TRANSLATE_ALONG_RAIL);
  508. //Check if the function is set correctly
  509. if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL;
  510. GEOMImpl_ITranslate aTI(aFunction);
  511. aTI.SetRailShape(theRail->GetLastFunction());
  512. aTI.SetOriginal(aLastFunction);
  513. SETPARAM(aTI.SetStep1,theStep);
  514. SETPARAM(aTI.SetNbIter1,theNbTimes);
  515. SETPARAM(aTI.SetNbIter2,theType); //0=No rotation, 1=Plane based rotation, 2=Freeform rotation
  516. //Compute the translation
  517. try {
  518. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  519. OCC_CATCH_SIGNALS;
  520. #endif
  521. if (!GetSolver()->ComputeFunction(aFunction)) {
  522. SetErrorCode("Translation driver failed");
  523. return NULL;
  524. }
  525. }
  526. catch (Standard_Failure) {
  527. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  528. SetErrorCode(aFail->GetMessageString());
  529. return NULL;
  530. }
  531. //Make a Python command
  532. GEOM::TPythonDump(aFunction) << aCopy << " = TranslateAlongRail("
  533. << theObject << ", " << theRail << ", " << theStep
  534. << ", " << theNbTimes << ", " << theType << ")";
  535. SetErrorCode(GEOM_OK);
  536. return aCopy;
  537. }
  538. //=============================================================================
  539. /*!
  540. * MirrorPlane
  541. */
  542. //=============================================================================
  543. Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlane
  544. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePlane)
  545. {
  546. SetErrorCode(GEOM_KO);
  547. if (theObject.IsNull() || thePlane.IsNull()) return NULL;
  548. Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
  549. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
  550. // Get last functions of the arguments
  551. Handle(GEOM_Function) aPF = thePlane->GetLastFunction();
  552. //Add a mirror function
  553. Handle(GEOM_Function) aFunction =
  554. theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_PLANE);
  555. if (aFunction.IsNull()) return NULL;
  556. //Check if the function is set correctly
  557. if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
  558. GEOMImpl_IMirror aTI (aFunction);
  559. aTI.SetPlane(aPF);
  560. aTI.SetOriginal(aLastFunction);
  561. //Compute the mirror
  562. try {
  563. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  564. OCC_CATCH_SIGNALS;
  565. #endif
  566. if (!GetSolver()->ComputeFunction(aFunction)) {
  567. SetErrorCode("Mirror driver failed");
  568. return NULL;
  569. }
  570. }
  571. catch (Standard_Failure) {
  572. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  573. SetErrorCode(aFail->GetMessageString());
  574. return NULL;
  575. }
  576. //Make a Python command
  577. GEOM::TPythonDump(aFunction) << "MirrorPlane("
  578. << theObject << ", " << thePlane << ")";
  579. SetErrorCode(GEOM_OK);
  580. return theObject;
  581. }
  582. //=============================================================================
  583. /*!
  584. * MirrorPlaneCopy
  585. */
  586. //=============================================================================
  587. Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlaneCopy
  588. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePlane)
  589. {
  590. SetErrorCode(GEOM_KO);
  591. if (theObject.IsNull() || thePlane.IsNull()) return NULL;
  592. Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
  593. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
  594. //Add a new Copy object
  595. Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
  596. //Add a mirror function
  597. Handle(GEOM_Function) aFunction =
  598. aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_PLANE_COPY);
  599. //Check if the function is set correctly
  600. if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
  601. GEOMImpl_IMirror aTI (aFunction);
  602. aTI.SetPlane(thePlane->GetLastFunction());
  603. aTI.SetOriginal(aLastFunction);
  604. //Compute the mirror
  605. try {
  606. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  607. OCC_CATCH_SIGNALS;
  608. #endif
  609. if (!GetSolver()->ComputeFunction(aFunction)) {
  610. SetErrorCode("Mirror driver failed");
  611. return NULL;
  612. }
  613. }
  614. catch (Standard_Failure) {
  615. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  616. SetErrorCode(aFail->GetMessageString());
  617. return NULL;
  618. }
  619. //Make a Python command
  620. GEOM::TPythonDump(aFunction) << aCopy << " = MirrorPlaneCopy("
  621. << theObject << ", " << thePlane << ")";
  622. SetErrorCode(GEOM_OK);
  623. return aCopy;
  624. }
  625. //=============================================================================
  626. /*!
  627. * MirrorPoint
  628. */
  629. //=============================================================================
  630. Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPoint
  631. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint)
  632. {
  633. SetErrorCode(GEOM_KO);
  634. if (theObject.IsNull() || thePoint.IsNull()) return NULL;
  635. Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
  636. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
  637. // Get last functions of the arguments
  638. Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
  639. //Add a mirror function
  640. Handle(GEOM_Function) aFunction =
  641. theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_POINT);
  642. if (aFunction.IsNull()) return NULL;
  643. //Check if the function is set correctly
  644. if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
  645. GEOMImpl_IMirror aTI (aFunction);
  646. aTI.SetPoint(aPF);
  647. aTI.SetOriginal(aLastFunction);
  648. //Compute the mirror
  649. try {
  650. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  651. OCC_CATCH_SIGNALS;
  652. #endif
  653. if (!GetSolver()->ComputeFunction(aFunction)) {
  654. SetErrorCode("Mirror driver failed");
  655. return NULL;
  656. }
  657. }
  658. catch (Standard_Failure) {
  659. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  660. SetErrorCode(aFail->GetMessageString());
  661. return NULL;
  662. }
  663. //Make a Python command
  664. GEOM::TPythonDump(aFunction) << "MirrorPoint("
  665. << theObject << ", " << thePoint << ")";
  666. SetErrorCode(GEOM_OK);
  667. return NULL;
  668. }
  669. //=============================================================================
  670. /*!
  671. * MirrorPointCopy
  672. */
  673. //=============================================================================
  674. Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPointCopy
  675. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint)
  676. {
  677. SetErrorCode(GEOM_KO);
  678. if (theObject.IsNull() || thePoint.IsNull()) return NULL;
  679. Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
  680. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
  681. //Add a new Copy object
  682. Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
  683. //Add a mirror function
  684. Handle(GEOM_Function) aFunction =
  685. aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_POINT_COPY);
  686. //Check if the function is set correctly
  687. if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
  688. GEOMImpl_IMirror aTI (aFunction);
  689. aTI.SetPoint(thePoint->GetLastFunction());
  690. aTI.SetOriginal(aLastFunction);
  691. //Compute the mirror
  692. try {
  693. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  694. OCC_CATCH_SIGNALS;
  695. #endif
  696. if (!GetSolver()->ComputeFunction(aFunction)) {
  697. SetErrorCode("Mirror driver failed");
  698. return NULL;
  699. }
  700. }
  701. catch (Standard_Failure) {
  702. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  703. SetErrorCode(aFail->GetMessageString());
  704. return NULL;
  705. }
  706. //Make a Python command
  707. GEOM::TPythonDump(aFunction) << aCopy << " = MirrorPointCopy("
  708. << theObject << ", " << thePoint << ")";
  709. SetErrorCode(GEOM_OK);
  710. return aCopy;
  711. }
  712. //=============================================================================
  713. /*!
  714. * MirrorAxis
  715. */
  716. //=============================================================================
  717. Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxis
  718. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis)
  719. {
  720. SetErrorCode(GEOM_KO);
  721. if (theObject.IsNull() || theAxis.IsNull()) return NULL;
  722. Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
  723. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
  724. // Get last functions of the arguments
  725. Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
  726. //Add a mirror function
  727. Handle(GEOM_Function) aFunction =
  728. theObject->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_AXIS);
  729. if (aFunction.IsNull()) return NULL;
  730. //Check if the function is set correctly
  731. if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
  732. GEOMImpl_IMirror aTI (aFunction);
  733. aTI.SetAxis(anAF);
  734. aTI.SetOriginal(aLastFunction);
  735. //Compute the mirror
  736. try {
  737. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  738. OCC_CATCH_SIGNALS;
  739. #endif
  740. if (!GetSolver()->ComputeFunction(aFunction)) {
  741. SetErrorCode("Mirror driver failed");
  742. return NULL;
  743. }
  744. }
  745. catch (Standard_Failure) {
  746. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  747. SetErrorCode(aFail->GetMessageString());
  748. return NULL;
  749. }
  750. //Make a Python command
  751. GEOM::TPythonDump(aFunction) << "MirrorAxis("
  752. << theObject << ", " << theAxis << ")";
  753. SetErrorCode(GEOM_OK);
  754. return NULL;
  755. }
  756. //=============================================================================
  757. /*!
  758. * MirrorAxisCopy
  759. */
  760. //=============================================================================
  761. Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxisCopy
  762. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis)
  763. {
  764. SetErrorCode(GEOM_KO);
  765. if (theObject.IsNull() || theAxis.IsNull()) return NULL;
  766. Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction();
  767. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be mirrored
  768. //Add a new Copy object
  769. Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
  770. //Add a mirror function
  771. Handle(GEOM_Function) aFunction =
  772. aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), MIRROR_AXIS_COPY);
  773. //Check if the function is set correctly
  774. if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL;
  775. GEOMImpl_IMirror aTI (aFunction);
  776. aTI.SetAxis(theAxis->GetLastFunction());
  777. aTI.SetOriginal(aLastFunction);
  778. //Compute the mirror
  779. try {
  780. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  781. OCC_CATCH_SIGNALS;
  782. #endif
  783. if (!GetSolver()->ComputeFunction(aFunction)) {
  784. SetErrorCode("Mirror driver failed");
  785. return NULL;
  786. }
  787. }
  788. catch (Standard_Failure) {
  789. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  790. SetErrorCode(aFail->GetMessageString());
  791. return NULL;
  792. }
  793. //Make a Python command
  794. GEOM::TPythonDump(aFunction) << aCopy << " = MirrorAxisCopy("
  795. << theObject << ", " << theAxis << ")";
  796. SetErrorCode(GEOM_OK);
  797. return aCopy;
  798. }
  799. //=============================================================================
  800. /*!
  801. * OffsetShape
  802. */
  803. //=============================================================================
  804. Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShape
  805. (Handle(GEOM_Object) theObject, const GEOM_Parameter& theOffset, const GEOM_Parameter& theHeightOffset, bool isPlanar)
  806. {
  807. SetErrorCode(GEOM_KO);
  808. if (theObject.IsNull()) return NULL;
  809. Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
  810. if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
  811. //Add a new Offset function
  812. Handle(GEOM_Function) aFunction;
  813. if (isPlanar)
  814. aFunction = theObject->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE_PLANAR);
  815. else
  816. aFunction = theObject->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE);
  817. if (aFunction.IsNull()) return NULL;
  818. //Check if the function is set correctly
  819. if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
  820. GEOMImpl_IOffset aTI (aFunction);
  821. aTI.SetShape(anOriginal);
  822. SETPARAM(aTI.SetValue,theOffset);
  823. SETPARAM(aTI.SetAltValue,theHeightOffset);
  824. //Compute the offset
  825. try {
  826. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  827. OCC_CATCH_SIGNALS;
  828. #endif
  829. if (!GetSolver()->ComputeFunction(aFunction)) {
  830. SetErrorCode("Offset driver failed");
  831. return NULL;
  832. }
  833. }
  834. catch (Standard_Failure) {
  835. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  836. SetErrorCode(aFail->GetMessageString());
  837. return NULL;
  838. }
  839. //Make a Python command
  840. GEOM::TPythonDump(aFunction) << "OffsetShape("
  841. << theObject << ", " << theOffset << ", " << theHeightOffset << ", Planar: " << (int)isPlanar << ")";
  842. SetErrorCode(GEOM_OK);
  843. return theObject;
  844. }
  845. //=============================================================================
  846. /*!
  847. * OffsetShapeCopy
  848. */
  849. //=============================================================================
  850. Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShapeCopy
  851. (Handle(GEOM_Object) theObject, const GEOM_Parameter& theOffset, const GEOM_Parameter& theHeightOffset, bool isPlanar)
  852. {
  853. SetErrorCode(GEOM_KO);
  854. if (theObject.IsNull()) return NULL;
  855. Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
  856. if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be offset
  857. //Add a new Copy object
  858. Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
  859. //Add a new Offset function
  860. Handle(GEOM_Function) aFunction;
  861. if (isPlanar)
  862. aFunction = aCopy->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE_PLANAR);
  863. else
  864. aFunction = aCopy->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE);
  865. //Add a new Offset function
  866. //Handle(GEOM_Function) aFunction =
  867. // aCopy->AddFunction(GEOMImpl_OffsetDriver::GetID(), OFFSET_SHAPE_COPY);
  868. if (aFunction.IsNull()) return NULL;
  869. //Check if the function is set correctly
  870. if (aFunction->GetDriverGUID() != GEOMImpl_OffsetDriver::GetID()) return NULL;
  871. GEOMImpl_IOffset aTI (aFunction);
  872. aTI.SetShape(anOriginal);
  873. SETPARAM(aTI.SetValue,theOffset);
  874. SETPARAM(aTI.SetAltValue,theHeightOffset);
  875. //Compute the offset
  876. try {
  877. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  878. OCC_CATCH_SIGNALS;
  879. #endif
  880. if (!GetSolver()->ComputeFunction(aFunction)) {
  881. SetErrorCode("Offset driver failed");
  882. return NULL;
  883. }
  884. }
  885. catch (Standard_Failure) {
  886. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  887. SetErrorCode(aFail->GetMessageString());
  888. return NULL;
  889. }
  890. //Make a Python command
  891. GEOM::TPythonDump(aFunction) << aCopy << " = OffsetShapeCopy("
  892. << theObject << ", " << theOffset << ", " << theHeightOffset << ", Planar: " << (int)isPlanar << ")";
  893. SetErrorCode(GEOM_OK);
  894. return aCopy;
  895. }
  896. //=============================================================================
  897. /*!
  898. * ScaleShape
  899. */
  900. //=============================================================================
  901. Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShape
  902. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, const GEOM_Parameter& theFactor)
  903. {
  904. SetErrorCode(GEOM_KO);
  905. if (theObject.IsNull()) return NULL;
  906. Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
  907. if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
  908. //Add a scale function
  909. Handle(GEOM_Function) aFunction =
  910. theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE);
  911. if (aFunction.IsNull()) return NULL;
  912. //Check if the function is set correctly
  913. if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
  914. // Set arguments
  915. GEOMImpl_IScale aTI (aFunction);
  916. aTI.SetShape(anOriginal);
  917. SETPARAM(aTI.SetFactor,theFactor);
  918. // Set point argument
  919. if (!thePoint.IsNull()) {
  920. Handle(GEOM_Function) aPF = thePoint->GetLastFunction();
  921. aTI.SetPoint(aPF);
  922. }
  923. //Compute the scale
  924. try {
  925. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  926. OCC_CATCH_SIGNALS;
  927. #endif
  928. if (!GetSolver()->ComputeFunction(aFunction)) {
  929. SetErrorCode("Scale driver failed");
  930. return NULL;
  931. }
  932. }
  933. catch (Standard_Failure) {
  934. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  935. SetErrorCode(aFail->GetMessageString());
  936. return NULL;
  937. }
  938. //Make a Python command
  939. GEOM::TPythonDump(aFunction) << "ScaleShape("
  940. << theObject << ", " << thePoint << ", " << theFactor << ")";
  941. SetErrorCode(GEOM_OK);
  942. return theObject;
  943. }
  944. //=============================================================================
  945. /*!
  946. * ScaleShapeCopy
  947. */
  948. //=============================================================================
  949. Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeCopy
  950. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, const GEOM_Parameter& theFactor)
  951. {
  952. SetErrorCode(GEOM_KO);
  953. if (theObject.IsNull() || thePoint.IsNull()) return NULL;
  954. Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
  955. if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
  956. //Add a new Copy object
  957. Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
  958. //Add a scale function
  959. Handle(GEOM_Function) aFunction =
  960. aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_COPY);
  961. if (aFunction.IsNull()) return NULL;
  962. //Check if the function is set correctly
  963. if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
  964. GEOMImpl_IScale aTI (aFunction);
  965. aTI.SetShape(anOriginal);
  966. aTI.SetPoint(thePoint->GetLastFunction());
  967. SETPARAM(aTI.SetFactor,theFactor);
  968. //Compute the scale
  969. try {
  970. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  971. OCC_CATCH_SIGNALS;
  972. #endif
  973. if (!GetSolver()->ComputeFunction(aFunction)) {
  974. SetErrorCode("Scale driver failed");
  975. return NULL;
  976. }
  977. }
  978. catch (Standard_Failure) {
  979. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  980. SetErrorCode(aFail->GetMessageString());
  981. return NULL;
  982. }
  983. //Make a Python command
  984. GEOM::TPythonDump(aFunction) << aCopy << " = ScaleShapeCopy("
  985. << theObject << ", " << thePoint << ", " << theFactor << ")";
  986. SetErrorCode(GEOM_OK);
  987. return aCopy;
  988. }
  989. //=============================================================================
  990. /*!
  991. * ScaleShapeAffine
  992. */
  993. //=============================================================================
  994. Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeAffine
  995. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector, const GEOM_Parameter& theFactor)
  996. {
  997. SetErrorCode(GEOM_KO);
  998. if (theObject.IsNull() || theVector.IsNull()) return NULL;
  999. Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
  1000. if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
  1001. // Get last functions of the arguments
  1002. Handle(GEOM_Function) aVF = theVector->GetLastFunction();
  1003. //Add a scale function
  1004. Handle(GEOM_Function) aFunction =
  1005. theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AFFINE);
  1006. if (aFunction.IsNull()) return NULL;
  1007. //Check if the function is set correctly
  1008. if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
  1009. GEOMImpl_IScale aTI (aFunction);
  1010. aTI.SetShape(anOriginal);
  1011. aTI.SetVector(aVF);
  1012. SETPARAM(aTI.SetFactor,theFactor);
  1013. //Compute the scale
  1014. try {
  1015. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  1016. OCC_CATCH_SIGNALS;
  1017. #endif
  1018. if (!GetSolver()->ComputeFunction(aFunction)) {
  1019. SetErrorCode("Scale driver failed");
  1020. return NULL;
  1021. }
  1022. }
  1023. catch (Standard_Failure) {
  1024. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  1025. SetErrorCode(aFail->GetMessageString());
  1026. return NULL;
  1027. }
  1028. //Make a Python command
  1029. GEOM::TPythonDump(aFunction) << "ScaleShapeAffine("
  1030. << theObject << ", " << theVector << ", " << theFactor << ")";
  1031. SetErrorCode(GEOM_OK);
  1032. return theObject;
  1033. }
  1034. //=============================================================================
  1035. /*!
  1036. * ScaleShapeAffineCopy
  1037. */
  1038. //=============================================================================
  1039. Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeAffineCopy
  1040. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector, const GEOM_Parameter& theFactor)
  1041. {
  1042. SetErrorCode(GEOM_KO);
  1043. if (theObject.IsNull() || theVector.IsNull()) return NULL;
  1044. Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
  1045. if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled
  1046. //Add a new Copy object
  1047. Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
  1048. //Add a scale function
  1049. Handle(GEOM_Function) aFunction =
  1050. aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AFFINE_COPY);
  1051. if (aFunction.IsNull()) return NULL;
  1052. //Check if the function is set correctly
  1053. if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL;
  1054. GEOMImpl_IScale aTI (aFunction);
  1055. aTI.SetShape(anOriginal);
  1056. aTI.SetVector(theVector->GetLastFunction());
  1057. SETPARAM(aTI.SetFactor,theFactor);
  1058. //Compute the scale
  1059. try {
  1060. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  1061. OCC_CATCH_SIGNALS;
  1062. #endif
  1063. if (!GetSolver()->ComputeFunction(aFunction)) {
  1064. SetErrorCode("Scale driver failed");
  1065. return NULL;
  1066. }
  1067. }
  1068. catch (Standard_Failure) {
  1069. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  1070. SetErrorCode(aFail->GetMessageString());
  1071. return NULL;
  1072. }
  1073. //Make a Python command
  1074. GEOM::TPythonDump(aFunction) << aCopy << " = ScaleShapeAffineCopy("
  1075. << theObject << ", " << theVector << ", " << theFactor << ")";
  1076. SetErrorCode(GEOM_OK);
  1077. return aCopy;
  1078. }
  1079. //=============================================================================
  1080. /*!
  1081. * PositionShape
  1082. */
  1083. //=============================================================================
  1084. Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShape
  1085. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theStartLCS, Handle(GEOM_Object) theEndLCS)
  1086. {
  1087. SetErrorCode(GEOM_KO);
  1088. if (theObject.IsNull() || theEndLCS.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 set in position
  1091. //Add a Position function
  1092. Standard_Integer aType = POSITION_SHAPE;
  1093. if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL;
  1094. Handle(GEOM_Function) aFunction =
  1095. theObject->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
  1096. if (aFunction.IsNull()) return NULL;
  1097. //Check if the function is set correctly
  1098. if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
  1099. //Set operation arguments
  1100. GEOMImpl_IPosition aTI (aFunction);
  1101. aTI.SetShape(anOriginal);
  1102. aTI.SetEndLCS(theEndLCS->GetLastFunction());
  1103. if (!theStartLCS.IsNull())
  1104. aTI.SetStartLCS(theStartLCS->GetLastFunction());
  1105. //Compute the Position
  1106. try {
  1107. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  1108. OCC_CATCH_SIGNALS;
  1109. #endif
  1110. if (!GetSolver()->ComputeFunction(aFunction)) {
  1111. SetErrorCode("Position driver failed");
  1112. return NULL;
  1113. }
  1114. }
  1115. catch (Standard_Failure) {
  1116. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  1117. SetErrorCode(aFail->GetMessageString());
  1118. return NULL;
  1119. }
  1120. //Make a Python command
  1121. GEOM::TPythonDump(aFunction) << "PositionShape("
  1122. << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
  1123. SetErrorCode(GEOM_OK);
  1124. return theObject;
  1125. }
  1126. //=============================================================================
  1127. /*!
  1128. * PositionShapeCopy
  1129. */
  1130. //=============================================================================
  1131. Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShapeCopy
  1132. (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theStartLCS, Handle(GEOM_Object) theEndLCS)
  1133. {
  1134. SetErrorCode(GEOM_KO);
  1135. if (theObject.IsNull() || theEndLCS.IsNull()) return NULL;
  1136. Handle(GEOM_Function) anOriginal = theObject->GetLastFunction();
  1137. if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be set in position
  1138. //Add a new Copy object
  1139. Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType());
  1140. //Add a position function
  1141. Standard_Integer aType = POSITION_SHAPE_COPY;
  1142. if (theStartLCS.IsNull()) aType = POSITION_SHAPE_FROM_GLOBAL_COPY;
  1143. Handle(GEOM_Function) aFunction =
  1144. aCopy->AddFunction(GEOMImpl_PositionDriver::GetID(), aType);
  1145. if (aFunction.IsNull()) return NULL;
  1146. //Check if the function is set correctly
  1147. if (aFunction->GetDriverGUID() != GEOMImpl_PositionDriver::GetID()) return NULL;
  1148. GEOMImpl_IPosition aTI (aFunction);
  1149. aTI.SetShape(anOriginal);
  1150. aTI.SetEndLCS(theEndLCS->GetLastFunction());
  1151. if (!theStartLCS.IsNull())
  1152. aTI.SetStartLCS(theStartLCS->GetLastFunction());
  1153. //Compute the position
  1154. try {
  1155. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  1156. OCC_CATCH_SIGNALS;
  1157. #endif
  1158. if (!GetSolver()->ComputeFunction(aFunction)) {
  1159. SetErrorCode("Position driver failed");
  1160. return NULL;
  1161. }
  1162. }
  1163. catch (Standard_Failure) {
  1164. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  1165. SetErrorCode(aFail->GetMessageString());
  1166. return NULL;
  1167. }
  1168. //Make a Python command
  1169. GEOM::TPythonDump(aFunction) << aCopy << " = PositionShapeCopy("
  1170. << theObject << ", " << theStartLCS << ", " << theEndLCS << ")";
  1171. SetErrorCode(GEOM_OK);
  1172. return aCopy;
  1173. }
  1174. //=============================================================================
  1175. /*!
  1176. * Rotate
  1177. */
  1178. //=============================================================================
  1179. Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate (Handle(GEOM_Object) theObject,
  1180. Handle(GEOM_Object) theAxis,
  1181. const GEOM_Parameter& theAngle)
  1182. {
  1183. SetErrorCode(GEOM_KO);
  1184. if (theObject.IsNull() || theAxis.IsNull()) return NULL;
  1185. Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
  1186. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
  1187. // Get last functions of the arguments
  1188. Handle(GEOM_Function) anAF = theAxis->GetLastFunction();
  1189. //Add a rotate function
  1190. aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE);
  1191. if (aFunction.IsNull()) return NULL;
  1192. //Check if the function is set correctly
  1193. if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL;
  1194. GEOMImpl_IRotate aRI(aFunction);
  1195. aRI.SetAxis(anAF);
  1196. aRI.SetOriginal(aLastFunction);
  1197. SETPARAM(aRI.SetAngle,theAngle);
  1198. //Compute the translation
  1199. try {
  1200. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  1201. OCC_CATCH_SIGNALS;
  1202. #endif
  1203. if (!GetSolver()->ComputeFunction(aFunction)) {
  1204. SetErrorCode("Rotate driver failed");
  1205. return NULL;
  1206. }
  1207. }
  1208. catch (Standard_Failure) {
  1209. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  1210. SetErrorCode(aFail->GetMessageString());
  1211. return NULL;
  1212. }
  1213. //Make a Python command
  1214. GEOM::TPythonDump(aFunction) << "Rotate(" << theObject
  1215. << ", " << theAxis << ", " << theAngle << ")";
  1216. SetErrorCode(GEOM_OK);
  1217. return theObject;
  1218. }
  1219. //=============================================================================
  1220. /*!
  1221. * Rotate
  1222. */
  1223. //=============================================================================
  1224. Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateCopy (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis, const GEOM_Parameter& theAngle)
  1225. {
  1226. SetErrorCode(GEOM_KO);
  1227. if (theObject.IsNull() || theAxis.IsNull()) return NULL;
  1228. Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
  1229. if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated
  1230. //Add a new Copy object
  1231. Handle(GEOM_Object) aCopy =