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

http://pythonocc.googlecode.com/ · C++ · 1628 lines · 1085 code · 280 blank · 263 comment · 193 complexity · 7610f87fbaa6bfe843883d82b7126859 MD5 · raw 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_ILocalOperations.hxx>
  23. #include <GEOM_Function.hxx>
  24. #include <GEOM_PythonDump.hxx>
  25. #include <GEOMImpl_Types.hxx>
  26. #include <GEOMImpl_FilletDriver.hxx>
  27. #include <GEOMImpl_ChamferDriver.hxx>
  28. #include <GEOMImpl_ThickSolidDriver.hxx>
  29. #include <GEOMImpl_VariableFilletDriver.hxx>
  30. #include <GEOMImpl_DraftDriver.hxx>
  31. #include <GEOMImpl_IFillet.hxx>
  32. #include <GEOMImpl_IVariableFillet.hxx>
  33. #include <GEOMImpl_IChamfer.hxx>
  34. #include <GEOMImpl_IThickSolid.hxx>
  35. #include <GEOMImpl_IDraft.hxx>
  36. #include <GEOMImpl_IArchimede.hxx>
  37. #include <GEOMImpl_ArchimedeDriver.hxx>
  38. #include <GEOMImpl_Gen.hxx>
  39. #include <GEOMImpl_IShapesOperations.hxx>
  40. #define SETPARAM(aFUNC,aVAL) \
  41. if (aVAL.IsString()) \
  42. aFUNC( aVAL.GetString() ); \
  43. else \
  44. aFUNC( aVAL.GetDouble() );
  45. #include <TFunction_DriverTable.hxx>
  46. #include <TFunction_Driver.hxx>
  47. #include <TFunction_Logbook.hxx>
  48. #include <TDF_Tool.hxx>
  49. #include <TopExp.hxx>
  50. #include <TopoDS_TShape.hxx>
  51. #include <TopTools_IndexedMapOfShape.hxx>
  52. #include <TColStd_HArray1OfReal.hxx>
  53. #include <Standard_Failure.hxx>
  54. #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
  55. #define LOCAL_OPS_CREATE_NEW_OBJECT
  56. //=============================================================================
  57. /*!
  58. * constructor:
  59. */
  60. //=============================================================================
  61. GEOMImpl_ILocalOperations::GEOMImpl_ILocalOperations (GEOM_Engine* theEngine, int theDocID)
  62. : GEOM_IOperations(theEngine, theDocID)
  63. {
  64. //MESSAGE("GEOMImpl_ILocalOperations::GEOMImpl_ILocalOperations");
  65. }
  66. //=============================================================================
  67. /*!
  68. * destructor
  69. */
  70. //=============================================================================
  71. GEOMImpl_ILocalOperations::~GEOMImpl_ILocalOperations()
  72. {
  73. //MESSAGE("GEOMImpl_ILocalOperations::~GEOMImpl_ILocalOperations");
  74. }
  75. //=============================================================================
  76. /*!
  77. * MakeFilletAll
  78. */
  79. //=============================================================================
  80. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletAll
  81. (Handle(GEOM_Object) theShape, const GEOM_Parameter& theR)
  82. {
  83. SetErrorCode(GEOM_KO);
  84. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  85. //Add a new Fillet object
  86. Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
  87. #else
  88. Handle(GEOM_Object) aFillet = theShape;
  89. #endif
  90. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  91. if (aRefShape.IsNull()) return NULL;
  92. //Add a new Fillet function
  93. Handle(GEOM_Function) aFunction =
  94. aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_ALL);
  95. if (aFunction.IsNull()) return NULL;
  96. //Check if the function is set correctly
  97. if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
  98. GEOMImpl_IFillet aCI (aFunction);
  99. aCI.SetShape(aRefShape);
  100. SETPARAM(aCI.SetR,theR);
  101. //Compute the Fillet value
  102. try {
  103. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  104. OCC_CATCH_SIGNALS;
  105. #endif
  106. if (!GetSolver()->ComputeFunction(aFunction)) {
  107. SetErrorCode("Fillet driver failed");
  108. return NULL;
  109. }
  110. }
  111. catch (Standard_Failure) {
  112. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  113. SetErrorCode(aFail->GetMessageString());
  114. return NULL;
  115. }
  116. //Make a Python command
  117. GEOM::TPythonDump(aFunction) << aFillet << " = MakeFilletAll("
  118. << theShape << ", " << theR << ")";
  119. SetErrorCode(GEOM_OK);
  120. return aFillet;
  121. }
  122. //=============================================================================
  123. /*!
  124. * MakeFilletEdges
  125. */
  126. //=============================================================================
  127. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletEdges
  128. (Handle(GEOM_Object) theShape, const GEOM_Parameter& theR, std::list<int> theEdges)
  129. {
  130. SetErrorCode(GEOM_KO);
  131. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  132. //Add a new Fillet object
  133. Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
  134. #else
  135. Handle(GEOM_Object) aFillet = theShape;
  136. #endif
  137. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  138. if (aRefShape.IsNull()) return NULL;
  139. //Add a new Fillet function
  140. Handle(GEOM_Function) aFunction =
  141. aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_EDGES);
  142. if (aFunction.IsNull()) return NULL;
  143. //Check if the function is set correctly
  144. if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
  145. GEOMImpl_IFillet aCI (aFunction);
  146. aCI.SetShape(aRefShape);
  147. SETPARAM(aCI.SetR,theR);
  148. int aLen = theEdges.size();
  149. aCI.SetLength(aLen);
  150. int ind = 1;
  151. std::list<int>::iterator it = theEdges.begin();
  152. for (; it != theEdges.end(); it++, ind++) {
  153. aCI.SetEdge(ind, (*it));
  154. }
  155. //Compute the Fillet value
  156. try {
  157. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  158. OCC_CATCH_SIGNALS;
  159. #endif
  160. if (!GetSolver()->ComputeFunction(aFunction)) {
  161. SetErrorCode("Fillet driver failed");
  162. return NULL;
  163. }
  164. }
  165. catch (Standard_Failure) {
  166. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  167. SetErrorCode(aFail->GetMessageString());
  168. return NULL;
  169. }
  170. //Make a Python command
  171. GEOM::TPythonDump pd (aFunction);
  172. pd << aFillet << " = MakeFilletEdges(" << theShape
  173. << ", " << theR << ", [";
  174. it = theEdges.begin();
  175. pd << (*it++);
  176. while (it != theEdges.end()) {
  177. pd << ", " << (*it++);
  178. }
  179. pd << "])";
  180. SetErrorCode(GEOM_OK);
  181. return aFillet;
  182. }
  183. //=============================================================================
  184. /*!
  185. * MakeFilletEdges R1 R2
  186. */
  187. //=============================================================================
  188. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletEdgesR1R2
  189. (Handle(GEOM_Object) theShape, const GEOM_Parameter& theR1, const GEOM_Parameter& theR2, std::list<int> theEdges)
  190. {
  191. SetErrorCode(GEOM_KO);
  192. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  193. //Add a new Fillet object
  194. Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
  195. #else
  196. Handle(GEOM_Object) aFillet = theShape;
  197. #endif
  198. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  199. if (aRefShape.IsNull()) return NULL;
  200. //Add a new Fillet function
  201. Handle(GEOM_Function) aFunction =
  202. aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_EDGES_2R);
  203. if (aFunction.IsNull()) return NULL;
  204. //Check if the function is set correctly
  205. if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
  206. GEOMImpl_IFillet aCI (aFunction);
  207. aCI.SetShape(aRefShape);
  208. SETPARAM(aCI.SetR1,theR1);
  209. SETPARAM(aCI.SetR2,theR2);
  210. int aLen = theEdges.size();
  211. aCI.SetLength(aLen);
  212. int ind = 1;
  213. std::list<int>::iterator it = theEdges.begin();
  214. for (; it != theEdges.end(); it++, ind++) {
  215. aCI.SetEdge(ind, (*it));
  216. }
  217. //Compute the Fillet value
  218. try {
  219. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  220. OCC_CATCH_SIGNALS;
  221. #endif
  222. if (!GetSolver()->ComputeFunction(aFunction)) {
  223. SetErrorCode("Fillet driver failed");
  224. return NULL;
  225. }
  226. }
  227. catch (Standard_Failure) {
  228. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  229. SetErrorCode(aFail->GetMessageString());
  230. return NULL;
  231. }
  232. //Make a Python command
  233. GEOM::TPythonDump pd (aFunction);
  234. pd << aFillet << " = MakeFilletR1R2(" << theShape
  235. << ", " << theR1 << ", " <<theR2 << ", ShapeType[\"EDGE\"], [";
  236. it = theEdges.begin();
  237. pd << (*it++);
  238. while (it != theEdges.end()) {
  239. pd << ", " << (*it++);
  240. }
  241. pd << "])";
  242. SetErrorCode(GEOM_OK);
  243. return aFillet;
  244. }
  245. //=============================================================================
  246. /*!
  247. * MakeFilletFaces
  248. */
  249. //=============================================================================
  250. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletFaces
  251. (Handle(GEOM_Object) theShape, const GEOM_Parameter& theR, std::list<int> theFaces)
  252. {
  253. SetErrorCode(GEOM_KO);
  254. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  255. //Add a new Fillet object
  256. Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
  257. #else
  258. Handle(GEOM_Object) aFillet = theShape;
  259. #endif
  260. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  261. if (aRefShape.IsNull()) return NULL;
  262. //Add a new Fillet function
  263. Handle(GEOM_Function) aFunction =
  264. aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_FACES);
  265. if (aFunction.IsNull()) return NULL;
  266. //Check if the function is set correctly
  267. if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
  268. GEOMImpl_IFillet aCI (aFunction);
  269. aCI.SetShape(aRefShape);
  270. SETPARAM(aCI.SetR,theR);
  271. int aLen = theFaces.size();
  272. aCI.SetLength(aLen);
  273. int ind = 1;
  274. std::list<int>::iterator it = theFaces.begin();
  275. for (; it != theFaces.end(); it++, ind++) {
  276. aCI.SetFace(ind, (*it));
  277. }
  278. //Compute the Fillet value
  279. try {
  280. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  281. OCC_CATCH_SIGNALS;
  282. #endif
  283. if (!GetSolver()->ComputeFunction(aFunction)) {
  284. SetErrorCode("Fillet driver failed");
  285. return NULL;
  286. }
  287. }
  288. catch (Standard_Failure) {
  289. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  290. SetErrorCode(aFail->GetMessageString());
  291. return NULL;
  292. }
  293. //Make a Python command
  294. GEOM::TPythonDump pd (aFunction);
  295. pd << aFillet << " = MakeFilletFaces(" << theShape
  296. << ", " << theR << ", [";
  297. it = theFaces.begin();
  298. pd << (*it++);
  299. while (it != theFaces.end()) {
  300. pd << ", " << (*it++);
  301. }
  302. pd << "])";
  303. SetErrorCode(GEOM_OK);
  304. return aFillet;
  305. }
  306. //=============================================================================
  307. /*!
  308. * MakeVariableFillet
  309. */
  310. //=============================================================================
  311. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeVariableFillet
  312. (Handle(GEOM_Object) theShape, std::list<GEOM_Parameter> theEdgesParams, std::list<GEOM_Parameter> theRadiusAtParam, std::list<int> theEdges)
  313. {
  314. SetErrorCode(GEOM_KO);
  315. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  316. //Add a new Fillet object
  317. Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_VARFILLET);
  318. #else
  319. Handle(GEOM_Object) aFillet = theShape;
  320. #endif
  321. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  322. if (aRefShape.IsNull()) return NULL;
  323. //Add a new Fillet function
  324. Handle(GEOM_Function) aFunction =
  325. aFillet->AddFunction(GEOMImpl_VariableFilletDriver::GetID(), VARFILLET);
  326. if (aFunction.IsNull()) return NULL;
  327. //Check if the function is set correctly
  328. if (aFunction->GetDriverGUID() != GEOMImpl_VariableFilletDriver::GetID()) return NULL;
  329. GEOMImpl_IVariableFillet aCI (aFunction);
  330. //check if the input data is ok
  331. if (theEdges.size() == 0)
  332. return NULL;
  333. else if (theRadiusAtParam.size() == 0)
  334. return NULL;
  335. else if ((theEdgesParams.size() != 0) && (theEdgesParams.size() != theRadiusAtParam.size()))
  336. return NULL;
  337. //set the base shape
  338. aCI.SetShape(aRefShape);
  339. //------------------------
  340. //BEGIN EDGES LIST SECTION
  341. //create an edge array to be filled
  342. Handle(TColStd_HArray1OfInteger) anEdgeArray = new TColStd_HArray1OfInteger(1, theEdges.size() );
  343. //fill the edge array
  344. int ind = 1;
  345. std::list<int>::iterator it = theEdges.begin();
  346. for (; it != theEdges.end(); it++, ind++) {
  347. anEdgeArray->SetValue(ind, *it);
  348. }
  349. //add the data to the function
  350. aCI.SetEdgesArray( anEdgeArray );
  351. //END EDGES LIST SECTION
  352. //------------------------
  353. //set the GEOM_Parameter iterator
  354. std::list<GEOM_Parameter>::iterator it2;
  355. //------------------------
  356. //BEGIN PARAMETER VALUES SECTION
  357. //set flags for later use
  358. bool ParamsAreExpressionsFlag = false;
  359. bool hasEdgeParameters = true;
  360. if (theEdgesParams.size() == 0)
  361. hasEdgeParameters = false;
  362. if (hasEdgeParameters)
  363. {
  364. //now check if the u param of edge is a double or an expression
  365. it2 = theEdgesParams.begin();
  366. for (; it2 != theEdgesParams.end(); it2++, ind++)
  367. {
  368. GEOM_Parameter aParam = *it2;
  369. if (aParam.IsString())
  370. {
  371. ParamsAreExpressionsFlag = true;
  372. break;
  373. }
  374. }
  375. }
  376. Handle(TColStd_HArray1OfReal) aParamArrayAsReal;
  377. Handle(TColStd_HArray1OfAsciiString) aParamArrayAsString;
  378. //if params are expressions fill an asciistring array and pass it to the driver
  379. //otherwise fill a double array ans pass it.
  380. if (ParamsAreExpressionsFlag && hasEdgeParameters)
  381. {
  382. //here we have expressions
  383. aParamArrayAsString = new TColStd_HArray1OfAsciiString(1, theEdgesParams.size() );
  384. ind = 1;
  385. it2 = theEdgesParams.begin();
  386. for (; it2 != theEdgesParams.end(); it2++, ind++) {
  387. GEOM_Parameter aParam = *it2;
  388. aParamArrayAsString->SetValue(ind, aParam.GetString() );
  389. }
  390. aCI.SetParamsArray(aParamArrayAsString);
  391. }
  392. else if (!ParamsAreExpressionsFlag && hasEdgeParameters)
  393. {
  394. //here we have doubles
  395. aParamArrayAsReal = new TColStd_HArray1OfReal(1, theEdgesParams.size() );
  396. ind = 1;
  397. it2 = theEdgesParams.begin();
  398. for (; it2 != theEdgesParams.end(); it2++, ind++) {
  399. GEOM_Parameter aParam = *it2;
  400. aParamArrayAsReal->SetValue(ind, aParam.GetDouble() );
  401. }
  402. if (theEdgesParams.size() != 0)
  403. aCI.SetParamsArray(aParamArrayAsReal);
  404. }
  405. //END PARAMETER VALUES SECTION
  406. //------------------------
  407. //------------------------
  408. //BEGIN RADIUS VALUES SECTION
  409. bool RadiusAreExpressionsFlag = false;
  410. //also check if the radiuses used are expressions or doubles
  411. it2 = theRadiusAtParam.begin();
  412. for (; it2 != theRadiusAtParam.end(); it2++, ind++)
  413. {
  414. GEOM_Parameter aParam = *it2;
  415. if (aParam.IsString())
  416. {
  417. RadiusAreExpressionsFlag = true;
  418. break;
  419. }
  420. }
  421. //Do the same as above for the radius values
  422. if (RadiusAreExpressionsFlag)
  423. {
  424. //here we have expressions
  425. Handle(TColStd_HArray1OfAsciiString) aRadiusArray = new TColStd_HArray1OfAsciiString(1, theRadiusAtParam.size() );
  426. ind = 1;
  427. it2 = theRadiusAtParam.begin();
  428. for (; it2 != theRadiusAtParam.end(); it2++, ind++) {
  429. GEOM_Parameter aParam = *it2;
  430. aRadiusArray->SetValue(ind, aParam.GetString() );
  431. }
  432. aCI.SetRadiusArray(aRadiusArray);
  433. }
  434. else
  435. {
  436. //here we have doubles
  437. Handle(TColStd_HArray1OfReal) aRadiusArray = new TColStd_HArray1OfReal(1, theRadiusAtParam.size() );
  438. ind = 1;
  439. it2 = theRadiusAtParam.begin();
  440. for (; it2 != theRadiusAtParam.end(); it2++, ind++) {
  441. GEOM_Parameter aParam = *it2;
  442. aRadiusArray->SetValue(ind, aParam.GetDouble() );
  443. }
  444. aCI.SetRadiusArray(aRadiusArray);
  445. }
  446. //------------------------
  447. //END RADIUS VALUES SECTION
  448. //Compute the var Fillet value
  449. try {
  450. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  451. OCC_CATCH_SIGNALS;
  452. #endif
  453. if (!GetSolver()->ComputeFunction(aFunction)) {
  454. SetErrorCode("Variable Fillet driver failed");
  455. return NULL;
  456. }
  457. }
  458. catch (Standard_Failure) {
  459. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  460. SetErrorCode(aFail->GetMessageString());
  461. return NULL;
  462. }
  463. //Make a Python command
  464. GEOM::TPythonDump pd (aFunction);
  465. pd << aFillet << " = MakeVariableFillet(" << theShape
  466. //EDGE DUMP
  467. <<", [";
  468. it = theEdges.begin();
  469. pd << (*it++);
  470. while (it != theEdges.end()) {
  471. pd << ", " << (*it++);
  472. }
  473. pd << "]";
  474. //PARAM DUMP
  475. pd << ", [";
  476. it2 = theEdgesParams.begin();
  477. pd << (*it2++);
  478. while (it2 != theEdgesParams.end()) {
  479. pd << ", " << (*it2++);
  480. }
  481. pd << "]";
  482. //RADIUS AT PARAM DUMP
  483. pd << ", [";
  484. it2 = theRadiusAtParam.begin();
  485. pd << (*it2++);
  486. while (it2 != theRadiusAtParam.end()) {
  487. pd << ", " << (*it2++);
  488. }
  489. pd << "]";
  490. SetErrorCode(GEOM_OK);
  491. return aFillet;
  492. }
  493. //=============================================================================
  494. /*!
  495. * MakeFillet2DVertices
  496. */
  497. //=============================================================================
  498. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFillet2DVertices
  499. (Handle(GEOM_Object) theShape, const GEOM_Parameter& theR, std::list<int> theVertices)
  500. {
  501. SetErrorCode(GEOM_KO);
  502. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  503. //Add a new Fillet object
  504. Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
  505. #else
  506. Handle(GEOM_Object) aFillet = theShape;
  507. #endif
  508. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  509. if (aRefShape.IsNull()) return NULL;
  510. //Add a new Fillet function
  511. Handle(GEOM_Function) aFunction =
  512. aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_VERTEX_2D);
  513. if (aFunction.IsNull()) return NULL;
  514. //Check if the function is set correctly
  515. if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
  516. GEOMImpl_IFillet aCI (aFunction);
  517. aCI.SetShape(aRefShape);
  518. SETPARAM(aCI.SetR,theR);
  519. int aLen = theVertices.size();
  520. aCI.SetLength(aLen);
  521. int ind = 1;
  522. std::list<int>::iterator it = theVertices.begin();
  523. for (; it != theVertices.end(); it++, ind++) {
  524. aCI.SetVertex(ind, (*it));
  525. }
  526. //Compute the Fillet value
  527. try {
  528. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  529. OCC_CATCH_SIGNALS;
  530. #endif
  531. if (!GetSolver()->ComputeFunction(aFunction)) {
  532. SetErrorCode("Fillet driver failed");
  533. return NULL;
  534. }
  535. }
  536. catch (Standard_Failure) {
  537. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  538. SetErrorCode(aFail->GetMessageString());
  539. return NULL;
  540. }
  541. //Make a Python command
  542. GEOM::TPythonDump pd (aFunction);
  543. pd << aFillet << " = MakeFillet2DVertices(" << theShape
  544. << ", " << theR << ", [";
  545. it = theVertices.begin();
  546. pd << (*it++);
  547. while (it != theVertices.end()) {
  548. pd << ", " << (*it++);
  549. }
  550. pd << "])";
  551. SetErrorCode(GEOM_OK);
  552. return aFillet;
  553. }
  554. //=============================================================================
  555. /*!
  556. * MakeFilletFaces R1 R2
  557. */
  558. //=============================================================================
  559. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletFacesR1R2
  560. (Handle(GEOM_Object) theShape, const GEOM_Parameter& theR1, const GEOM_Parameter& theR2, std::list<int> theFaces)
  561. {
  562. SetErrorCode(GEOM_KO);
  563. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  564. //Add a new Fillet object
  565. Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
  566. #else
  567. Handle(GEOM_Object) aFillet = theShape;
  568. #endif
  569. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  570. if (aRefShape.IsNull()) return NULL;
  571. //Add a new Fillet function
  572. Handle(GEOM_Function) aFunction =
  573. aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_FACES_2R);
  574. if (aFunction.IsNull()) return NULL;
  575. //Check if the function is set correctly
  576. if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
  577. GEOMImpl_IFillet aCI (aFunction);
  578. aCI.SetShape(aRefShape);
  579. SETPARAM(aCI.SetR1,theR1);
  580. SETPARAM(aCI.SetR2,theR2);
  581. int aLen = theFaces.size();
  582. aCI.SetLength(aLen);
  583. int ind = 1;
  584. std::list<int>::iterator it = theFaces.begin();
  585. for (; it != theFaces.end(); it++, ind++) {
  586. aCI.SetFace(ind, (*it));
  587. }
  588. //Compute the Fillet value
  589. try {
  590. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  591. OCC_CATCH_SIGNALS;
  592. #endif
  593. if (!GetSolver()->ComputeFunction(aFunction)) {
  594. SetErrorCode("Fillet driver failed");
  595. return NULL;
  596. }
  597. }
  598. catch (Standard_Failure) {
  599. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  600. SetErrorCode(aFail->GetMessageString());
  601. return NULL;
  602. }
  603. //Make a Python command
  604. GEOM::TPythonDump pd (aFunction);
  605. pd << aFillet << " = MakeFilletR1R2(" << theShape
  606. << ", " << theR1 << ", " << theR2 << ", ShapeType[\"FACE\"], [";
  607. it = theFaces.begin();
  608. pd << (*it++);
  609. while (it != theFaces.end()) {
  610. pd << ", " << (*it++);
  611. }
  612. pd << "])";
  613. SetErrorCode(GEOM_OK);
  614. return aFillet;
  615. }
  616. //=============================================================================
  617. /*!
  618. * MakeChamferAll
  619. */
  620. //=============================================================================
  621. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferAll (Handle(GEOM_Object) theShape, const GEOM_Parameter& theD)
  622. {
  623. SetErrorCode(GEOM_KO);
  624. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  625. //Add a new Chamfer object
  626. Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
  627. #else
  628. Handle(GEOM_Object) aChamfer = theShape;
  629. #endif
  630. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  631. if (aRefShape.IsNull()) return NULL;
  632. //Add a new Chamfer function
  633. Handle(GEOM_Function) aFunction =
  634. aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_ALL);
  635. if (aFunction.IsNull()) return NULL;
  636. //Check if the function is set correctly
  637. if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
  638. GEOMImpl_IChamfer aCI (aFunction);
  639. aCI.SetShape(aRefShape);
  640. SETPARAM(aCI.SetD, theD);
  641. //Compute the Chamfer value
  642. try {
  643. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  644. OCC_CATCH_SIGNALS;
  645. #endif
  646. if (!GetSolver()->ComputeFunction(aFunction)) {
  647. SetErrorCode("Chamfer driver failed");
  648. return NULL;
  649. }
  650. }
  651. catch (Standard_Failure) {
  652. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  653. SetErrorCode(aFail->GetMessageString());
  654. return NULL;
  655. }
  656. //Make a Python command
  657. GEOM::TPythonDump(aFunction) << aChamfer << " = MakeChamferAll("
  658. << theShape << ", " << theD << ")";
  659. SetErrorCode(GEOM_OK);
  660. return aChamfer;
  661. }
  662. //=============================================================================
  663. /*!
  664. * MakeChamferEdge
  665. */
  666. //=============================================================================
  667. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdge
  668. (Handle(GEOM_Object) theShape, const GEOM_Parameter& theD1, const GEOM_Parameter& theD2,
  669. int theFace1, int theFace2)
  670. {
  671. SetErrorCode(GEOM_KO);
  672. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  673. //Add a new Chamfer object
  674. Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
  675. #else
  676. Handle(GEOM_Object) aChamfer = theShape;
  677. #endif
  678. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  679. if (aRefShape.IsNull()) return NULL;
  680. //Add a new Chamfer function
  681. Handle(GEOM_Function) aFunction =
  682. aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGE);
  683. if (aFunction.IsNull()) return NULL;
  684. //Check if the function is set correctly
  685. if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
  686. GEOMImpl_IChamfer aCI (aFunction);
  687. aCI.SetShape(aRefShape);
  688. SETPARAM(aCI.SetD1,theD1);
  689. SETPARAM(aCI.SetD2,theD2);
  690. aCI.SetFace1(theFace1);
  691. aCI.SetFace2(theFace2);
  692. //Compute the Chamfer value
  693. try {
  694. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  695. OCC_CATCH_SIGNALS;
  696. #endif
  697. if (!GetSolver()->ComputeFunction(aFunction)) {
  698. SetErrorCode("Chamfer driver failed");
  699. return NULL;
  700. }
  701. }
  702. catch (Standard_Failure) {
  703. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  704. SetErrorCode(aFail->GetMessageString());
  705. return NULL;
  706. }
  707. //Make a Python command
  708. GEOM::TPythonDump(aFunction) << aChamfer
  709. << " = MakeChamferEdge(" << theShape << ", " << theD1
  710. << ", " << theD2 << ", " << theFace1 << ", " << theFace2 << ")";
  711. SetErrorCode(GEOM_OK);
  712. return aChamfer;
  713. }
  714. //=============================================================================
  715. /*!
  716. * MakeChamferEdgeAD
  717. */
  718. //=============================================================================
  719. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdgeAD
  720. (Handle(GEOM_Object) theShape, const GEOM_Parameter& theD, const GEOM_Parameter& theAngle,
  721. int theFace1, int theFace2)
  722. {
  723. SetErrorCode(GEOM_KO);
  724. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  725. //Add a new Chamfer object
  726. Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
  727. #else
  728. Handle(GEOM_Object) aChamfer = theShape;
  729. #endif
  730. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  731. if (aRefShape.IsNull()) return NULL;
  732. //Add a new Chamfer function
  733. Handle(GEOM_Function) aFunction =
  734. aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGE_AD);
  735. if (aFunction.IsNull()) return NULL;
  736. //Check if the function is set correctly
  737. if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
  738. GEOMImpl_IChamfer aCI (aFunction);
  739. aCI.SetShape(aRefShape);
  740. SETPARAM(aCI.SetD, theD);
  741. SETPARAM(aCI.SetAngle, theAngle);
  742. aCI.SetFace1(theFace1);
  743. aCI.SetFace2(theFace2);
  744. //Compute the Chamfer value
  745. try {
  746. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  747. OCC_CATCH_SIGNALS;
  748. #endif
  749. if (!GetSolver()->ComputeFunction(aFunction)) {
  750. SetErrorCode("Chamfer driver failed");
  751. return NULL;
  752. }
  753. }
  754. catch (Standard_Failure) {
  755. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  756. SetErrorCode(aFail->GetMessageString());
  757. return NULL;
  758. }
  759. //Make a Python command
  760. GEOM::TPythonDump(aFunction) << aChamfer
  761. << " = MakeChamferEdgeAD(" << theShape << ", " << theD
  762. << ", " << theAngle << ", " << theFace1 << ", " << theFace2 << ")";
  763. SetErrorCode(GEOM_OK);
  764. return aChamfer;
  765. }
  766. //=============================================================================
  767. /*!
  768. * MakeChamferFaces
  769. */
  770. //=============================================================================
  771. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferFaces
  772. (Handle(GEOM_Object) theShape, const GEOM_Parameter& theD1, const GEOM_Parameter& theD2,
  773. std::list<int> theFaces)
  774. {
  775. SetErrorCode(GEOM_KO);
  776. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  777. //Add a new Chamfer object
  778. Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
  779. #else
  780. Handle(GEOM_Object) aChamfer = theShape;
  781. #endif
  782. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  783. if (aRefShape.IsNull()) return NULL;
  784. //Add a new Chamfer function
  785. Handle(GEOM_Function) aFunction =
  786. aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_FACES);
  787. if (aFunction.IsNull()) return NULL;
  788. //Check if the function is set correctly
  789. if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
  790. GEOMImpl_IChamfer aCI (aFunction);
  791. aCI.SetShape(aRefShape);
  792. SETPARAM(aCI.SetD1,theD1);
  793. SETPARAM(aCI.SetD2,theD2);
  794. int aLen = theFaces.size();
  795. aCI.SetLength(aLen);
  796. int ind = 1;
  797. std::list<int>::iterator it = theFaces.begin();
  798. for (; it != theFaces.end(); it++, ind++) {
  799. aCI.SetFace(ind, (*it));
  800. }
  801. //Compute the Chamfer value
  802. try {
  803. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  804. OCC_CATCH_SIGNALS;
  805. #endif
  806. if (!GetSolver()->ComputeFunction(aFunction)) {
  807. SetErrorCode("Chamfer driver failed");
  808. return NULL;
  809. }
  810. }
  811. catch (Standard_Failure) {
  812. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  813. SetErrorCode(aFail->GetMessageString());
  814. return NULL;
  815. }
  816. //Make a Python command
  817. GEOM::TPythonDump pd (aFunction);
  818. pd << aChamfer << " = MakeChamferFaces(" << theShape
  819. << ", " << theD1 << ", " << theD2 << ", [";
  820. it = theFaces.begin();
  821. pd << (*it++);
  822. while (it != theFaces.end()) {
  823. pd << ", " << (*it++);
  824. }
  825. pd << "])";
  826. SetErrorCode(GEOM_OK);
  827. return aChamfer;
  828. }
  829. //=============================================================================
  830. /*!
  831. * MakeChamfer2DEdges
  832. */
  833. //=============================================================================
  834. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamfer2DEdges
  835. (Handle(GEOM_Object) theShape, const GEOM_Parameter& theD1, const GEOM_Parameter& theD2,
  836. int theEdge1, int theEdge2)
  837. {
  838. SetErrorCode(GEOM_KO);
  839. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  840. //Add a new Chamfer object
  841. Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
  842. #else
  843. Handle(GEOM_Object) aChamfer = theShape;
  844. #endif
  845. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  846. if (aRefShape.IsNull()) return NULL;
  847. //Add a new Chamfer function
  848. Handle(GEOM_Function) aFunction =
  849. aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGES_2D);
  850. if (aFunction.IsNull()) return NULL;
  851. //Check if the function is set correctly
  852. if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
  853. GEOMImpl_IChamfer aCI (aFunction);
  854. aCI.SetShape(aRefShape);
  855. SETPARAM(aCI.SetD1,theD1);
  856. SETPARAM(aCI.SetD2,theD2);
  857. aCI.Set2DEdge1(theEdge1);
  858. aCI.Set2DEdge2(theEdge2);
  859. //Compute the Chamfer value
  860. try {
  861. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  862. OCC_CATCH_SIGNALS;
  863. #endif
  864. if (!GetSolver()->ComputeFunction(aFunction)) {
  865. SetErrorCode("Chamfer driver failed");
  866. return NULL;
  867. }
  868. }
  869. catch (Standard_Failure) {
  870. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  871. SetErrorCode(aFail->GetMessageString());
  872. return NULL;
  873. }
  874. //Make a Python command
  875. GEOM::TPythonDump(aFunction) << aChamfer
  876. << " = MakeChamfer2DEdge(" << theShape << ", " << theD1
  877. << ", " << theD2 << ", " << theEdge1 << ", " << theEdge2 << ")";
  878. SetErrorCode(GEOM_OK);
  879. return aChamfer;
  880. }
  881. //=============================================================================
  882. /*!
  883. * MakeThickSolid
  884. */
  885. //=============================================================================
  886. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeThickSolid
  887. (Handle(GEOM_Object) theShape, const GEOM_Parameter& theOffset, std::list<int> theFaces)
  888. {
  889. SetErrorCode(GEOM_KO);
  890. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  891. //Add a new ThickSolid object
  892. Handle(GEOM_Object) aThickSolid = GetEngine()->AddObject(GetDocID(), GEOM_THICKSOLID);
  893. #else
  894. Handle(GEOM_Object) aThickSolid = theShape;
  895. #endif
  896. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  897. if (aRefShape.IsNull()) return NULL;
  898. //Add a new ThickSolid function
  899. Handle(GEOM_Function) aFunction =
  900. aThickSolid->AddFunction(GEOMImpl_ThickSolidDriver::GetID(), THICKSOLID);
  901. if (aFunction.IsNull()) return NULL;
  902. //Check if the function is set correctly
  903. if (aFunction->GetDriverGUID() != GEOMImpl_ThickSolidDriver::GetID()) return NULL;
  904. GEOMImpl_IThickSolid aCI (aFunction);
  905. aCI.SetShape(aRefShape);
  906. SETPARAM(aCI.SetOffset,theOffset);
  907. int aLen = theFaces.size();
  908. aCI.SetLength(aLen);
  909. int ind = 1;
  910. std::list<int>::iterator it = theFaces.begin();
  911. for (; it != theFaces.end(); it++, ind++) {
  912. aCI.SetFace(ind, (*it));
  913. }
  914. //Compute the ThickSolid value
  915. try {
  916. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  917. OCC_CATCH_SIGNALS;
  918. #endif
  919. if (!GetSolver()->ComputeFunction(aFunction)) {
  920. SetErrorCode("ThickSolid driver failed");
  921. return NULL;
  922. }
  923. }
  924. catch (Standard_Failure) {
  925. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  926. SetErrorCode(aFail->GetMessageString());
  927. return NULL;
  928. }
  929. //Make a Python command
  930. GEOM::TPythonDump pd (aFunction);
  931. pd << aThickSolid << " = MakeThickSolid(" << theShape
  932. << ", " << theOffset << ", ";
  933. it = theFaces.begin();
  934. pd << (*it++);
  935. while (it != theFaces.end()) {
  936. pd << ", " << (*it++);
  937. }
  938. pd << ")";
  939. SetErrorCode(GEOM_OK);
  940. return aThickSolid;
  941. }
  942. //=============================================================================
  943. /*!
  944. * MakeDraftFacesAngle
  945. */
  946. //=============================================================================
  947. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeDraftFacesAngle
  948. (Handle(GEOM_Object) theShape, Handle(GEOM_Object) theNeutralPlane,
  949. const GEOM_Parameter& theAngle, std::list<int> theFaces)
  950. {
  951. SetErrorCode(GEOM_KO);
  952. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  953. //Add a new Draft Solid object
  954. Handle(GEOM_Object) aDraftSolid = GetEngine()->AddObject(GetDocID(), GEOM_DRAFT);
  955. #else
  956. Handle(GEOM_Object) aDraftSolid = theShape;
  957. #endif
  958. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  959. if (aRefShape.IsNull())
  960. return NULL;
  961. Handle(GEOM_Function) aRefPlane = theNeutralPlane->GetLastFunction();
  962. if (aRefPlane.IsNull())
  963. return NULL;
  964. //Add a new Draft Solid function
  965. Handle(GEOM_Function) aFunction = aDraftSolid->AddFunction(GEOMImpl_DraftDriver::GetID(), DRAFT_BY_FACE_PLN_ANG);
  966. if (aFunction.IsNull())
  967. return NULL;
  968. //Check if the function is set correctly
  969. if (aFunction->GetDriverGUID() != GEOMImpl_DraftDriver::GetID())
  970. return NULL;
  971. GEOMImpl_IDraft aCI (aFunction);
  972. aCI.SetShape(aRefShape);
  973. aCI.SetPlane(aRefPlane);
  974. SETPARAM(aCI.SetAngle,theAngle);
  975. int aLen = theFaces.size();
  976. aCI.SetLength(aLen);
  977. int ind = 1;
  978. std::list<int>::iterator it = theFaces.begin();
  979. for (; it != theFaces.end(); it++, ind++) {
  980. aCI.SetFace(ind, (*it));
  981. }
  982. //Compute the Draft value
  983. try {
  984. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  985. OCC_CATCH_SIGNALS;
  986. #endif
  987. if (!GetSolver()->ComputeFunction(aFunction)) {
  988. SetErrorCode("Draft driver failed");
  989. return NULL;
  990. }
  991. }
  992. catch (Standard_Failure) {
  993. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  994. SetErrorCode(aFail->GetMessageString());
  995. return NULL;
  996. }
  997. //Make a Python command
  998. GEOM::TPythonDump pd (aFunction);
  999. pd << aDraftSolid << " = MakeDraftFacesAngle(" << theShape
  1000. << ", " << theNeutralPlane << ", " << theAngle << ", [";
  1001. it = theFaces.begin();
  1002. pd << (*it++);
  1003. while (it != theFaces.end()) {
  1004. pd << ", " << (*it++);
  1005. }
  1006. pd << "])";
  1007. SetErrorCode(GEOM_OK);
  1008. return aDraftSolid;
  1009. }
  1010. //=============================================================================
  1011. /*!
  1012. * MakeDraftFacesAngleWithStationaryFace
  1013. */
  1014. //=============================================================================
  1015. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeDraftFacesAngleWithStationaryFace
  1016. (Handle(GEOM_Object) theShape, int theNeutralPlane, const GEOM_Parameter& theAngle, std::list<int> theFaces)
  1017. {
  1018. SetErrorCode(GEOM_KO);
  1019. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  1020. //Add a new Draft Solid object
  1021. Handle(GEOM_Object) aDraftSolid = GetEngine()->AddObject(GetDocID(), GEOM_DRAFT);
  1022. #else
  1023. Handle(GEOM_Object) aDraftSolid = theShape;
  1024. #endif
  1025. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  1026. if (aRefShape.IsNull())
  1027. return NULL;
  1028. //Add a new Draft Solid function
  1029. Handle(GEOM_Function) aFunction = aDraftSolid->AddFunction(GEOMImpl_DraftDriver::GetID(), DRAFT_BY_FACE_STA_ANG);
  1030. if (aFunction.IsNull())
  1031. return NULL;
  1032. //Check if the function is set correctly
  1033. if (aFunction->GetDriverGUID() != GEOMImpl_DraftDriver::GetID())
  1034. return NULL;
  1035. GEOMImpl_IDraft aCI (aFunction);
  1036. aCI.SetStationary(theNeutralPlane);
  1037. aCI.SetShape(aRefShape);
  1038. SETPARAM(aCI.SetAngle,theAngle);
  1039. int aLen = theFaces.size();
  1040. aCI.SetLength(aLen);
  1041. int ind = 1;
  1042. std::list<int>::iterator it = theFaces.begin();
  1043. for (; it != theFaces.end(); it++, ind++) {
  1044. aCI.SetFace(ind, (*it));
  1045. }
  1046. //Compute the Draft value
  1047. try {
  1048. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  1049. OCC_CATCH_SIGNALS;
  1050. #endif
  1051. if (!GetSolver()->ComputeFunction(aFunction)) {
  1052. SetErrorCode("Draft driver failed");
  1053. return NULL;
  1054. }
  1055. }
  1056. catch (Standard_Failure) {
  1057. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  1058. SetErrorCode(aFail->GetMessageString());
  1059. return NULL;
  1060. }
  1061. //Make a Python command
  1062. GEOM::TPythonDump pd (aFunction);
  1063. pd << aDraftSolid << " = MakeDraftFacesAngleWithStationaryFace(" << theShape
  1064. << ", " << theNeutralPlane << ", " << theAngle << ", [";
  1065. it = theFaces.begin();
  1066. pd << (*it++);
  1067. while (it != theFaces.end()) {
  1068. pd << ", " << (*it++);
  1069. }
  1070. pd << "])";
  1071. SetErrorCode(GEOM_OK);
  1072. return aDraftSolid;
  1073. }
  1074. //=============================================================================
  1075. /*!
  1076. * MakeChamferFacesAD
  1077. */
  1078. //=============================================================================
  1079. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferFacesAD
  1080. (Handle(GEOM_Object) theShape, const GEOM_Parameter& theD, const GEOM_Parameter& theAngle,
  1081. std::list<int> theFaces)
  1082. {
  1083. SetErrorCode(GEOM_KO);
  1084. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  1085. //Add a new Chamfer object
  1086. Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
  1087. #else
  1088. Handle(GEOM_Object) aChamfer = theShape;
  1089. #endif
  1090. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  1091. if (aRefShape.IsNull()) return NULL;
  1092. //Add a new Chamfer function
  1093. Handle(GEOM_Function) aFunction =
  1094. aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_FACES_AD);
  1095. if (aFunction.IsNull()) return NULL;
  1096. //Check if the function is set correctly
  1097. if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
  1098. GEOMImpl_IChamfer aCI (aFunction);
  1099. aCI.SetShape(aRefShape);
  1100. SETPARAM(aCI.SetD, theD);
  1101. SETPARAM(aCI.SetAngle, theAngle);
  1102. int aLen = theFaces.size();
  1103. aCI.SetLength(aLen);
  1104. int ind = 1;
  1105. std::list<int>::iterator it = theFaces.begin();
  1106. for (; it != theFaces.end(); it++, ind++) {
  1107. aCI.SetFace(ind, (*it));
  1108. }
  1109. //Compute the Chamfer value
  1110. try {
  1111. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  1112. OCC_CATCH_SIGNALS;
  1113. #endif
  1114. if (!GetSolver()->ComputeFunction(aFunction)) {
  1115. SetErrorCode("Chamfer driver failed");
  1116. return NULL;
  1117. }
  1118. }
  1119. catch (Standard_Failure) {
  1120. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  1121. SetErrorCode(aFail->GetMessageString());
  1122. return NULL;
  1123. }
  1124. //Make a Python command
  1125. GEOM::TPythonDump pd (aFunction);
  1126. pd << aChamfer << " = MakeChamferFacesAD(" << theShape
  1127. << ", " << theD << ", " << theAngle << ", [";
  1128. it = theFaces.begin();
  1129. pd << (*it++);
  1130. while (it != theFaces.end()) {
  1131. pd << ", " << (*it++);
  1132. }
  1133. pd << "])";
  1134. SetErrorCode(GEOM_OK);
  1135. return aChamfer;
  1136. }
  1137. //=============================================================================
  1138. /*!
  1139. * MakeChamferEdges
  1140. */
  1141. //=============================================================================
  1142. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdges
  1143. (Handle(GEOM_Object) theShape, const GEOM_Parameter& theD1, const GEOM_Parameter& theD2,
  1144. std::list<int> theEdges)
  1145. {
  1146. SetErrorCode(GEOM_KO);
  1147. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  1148. //Add a new Chamfer object
  1149. Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
  1150. #else
  1151. Handle(GEOM_Object) aChamfer = theShape;
  1152. #endif
  1153. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  1154. if (aRefShape.IsNull()) { MESSAGE ("Shape is NULL!!!"); return NULL;}
  1155. //Add a new Chamfer function
  1156. Handle(GEOM_Function) aFunction =
  1157. aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGES);
  1158. if (aFunction.IsNull()) { MESSAGE ( "Edges Function is NULL!!!" ); return NULL;}
  1159. //Check if the function is set correctly
  1160. if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID())
  1161. { MESSAGE ( "Chamfer Driver is NULL!!!" ); return NULL; }
  1162. GEOMImpl_IChamfer aCI (aFunction);
  1163. aCI.SetShape(aRefShape);
  1164. SETPARAM(aCI.SetD1, theD1);
  1165. SETPARAM(aCI.SetD2, theD2);
  1166. int aLen = theEdges.size();
  1167. aCI.SetLength(aLen);
  1168. int ind = 1;
  1169. std::list<int>::iterator it = theEdges.begin();
  1170. for (; it != theEdges.end(); it++, ind++) {
  1171. aCI.SetEdge(ind, (*it));
  1172. }
  1173. //Compute the Chamfer value
  1174. try {
  1175. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  1176. OCC_CATCH_SIGNALS;
  1177. #endif
  1178. if (!GetSolver()->ComputeFunction(aFunction)) {
  1179. SetErrorCode("Chamfer driver failed");
  1180. return NULL;
  1181. }
  1182. }
  1183. catch (Standard_Failure) {
  1184. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  1185. SetErrorCode(aFail->GetMessageString());
  1186. return NULL;
  1187. }
  1188. //Make a Python command
  1189. GEOM::TPythonDump pd (aFunction);
  1190. pd << aChamfer << " = MakeChamferEdges(" << theShape
  1191. << ", " << theD1 << ", " << theD2 << ", [";
  1192. it = theEdges.begin();
  1193. pd << (*it++);
  1194. while (it != theEdges.end()) {
  1195. pd << ", " << (*it++);
  1196. }
  1197. pd << "])";
  1198. SetErrorCode(GEOM_OK);
  1199. return aChamfer;
  1200. }
  1201. //=============================================================================
  1202. /*!
  1203. * MakeChamferEdgesAD
  1204. */
  1205. //=============================================================================
  1206. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdgesAD
  1207. (Handle(GEOM_Object) theShape, const GEOM_Parameter& theD, const GEOM_Parameter& theAngle,
  1208. std::list<int> theEdges)
  1209. {
  1210. SetErrorCode(GEOM_KO);
  1211. #ifdef LOCAL_OPS_CREATE_NEW_OBJECT
  1212. //Add a new Chamfer object
  1213. Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
  1214. #else
  1215. Handle(GEOM_Object) aChamfer = theShape;
  1216. #endif
  1217. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  1218. if (aRefShape.IsNull()) { MESSAGE ("Shape is NULL!!!"); return NULL;}
  1219. //Add a new Chamfer function
  1220. Handle(GEOM_Function) aFunction =
  1221. aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGES_AD);
  1222. if (aFunction.IsNull()) { MESSAGE ( "Edges Function is NULL!!!" ); return NULL; }
  1223. //Check if the function is set correctly
  1224. if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID())
  1225. { MESSAGE("Chamfer Driver is NULL!!!"); return NULL;}
  1226. GEOMImpl_IChamfer aCI (aFunction);
  1227. aCI.SetShape(aRefShape);
  1228. SETPARAM(aCI.SetD, theD);
  1229. SETPARAM(aCI.SetAngle, theAngle);
  1230. int aLen = theEdges.size();
  1231. aCI.SetLength(aLen);
  1232. int ind = 1;
  1233. std::list<int>::iterator it = theEdges.begin();
  1234. for (; it != theEdges.end(); it++, ind++) {
  1235. aCI.SetEdge(ind, (*it));
  1236. }
  1237. //Compute the Chamfer value
  1238. try {
  1239. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  1240. OCC_CATCH_SIGNALS;
  1241. #endif
  1242. if (!GetSolver()->ComputeFunction(aFunction)) {
  1243. SetErrorCode("Chamfer driver failed");
  1244. return NULL;
  1245. }
  1246. }
  1247. catch (Standard_Failure) {
  1248. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  1249. SetErrorCode(aFail->GetMessageString());
  1250. return NULL;
  1251. }
  1252. //Make a Python command
  1253. GEOM::TPythonDump pd (aFunction);
  1254. pd << aChamfer << " = MakeChamferEdgesAD(" << theShape
  1255. << ", " << theD << ", " << theAngle << ", [";
  1256. it = theEdges.begin();
  1257. pd << (*it++);
  1258. while (it != theEdges.end()) {
  1259. pd << ", " << (*it++);
  1260. }
  1261. pd << "])";
  1262. SetErrorCode(GEOM_OK);
  1263. return aChamfer;
  1264. }
  1265. //=============================================================================
  1266. /*!
  1267. * Archimede
  1268. */
  1269. //=============================================================================
  1270. Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeArchimede (Handle(GEOM_Object) theShape,
  1271. const GEOM_Parameter& theWeight,
  1272. const GEOM_Parameter& theWaterDensity,
  1273. const GEOM_Parameter& theMeshingDeflection)
  1274. {
  1275. SetErrorCode(GEOM_KO);
  1276. //Add a new Archimede object
  1277. Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_ARCHIMEDE);
  1278. //Add a new Archimede function
  1279. Handle(GEOM_Function) aFunction = aChamfer->AddFunction(GEOMImpl_ArchimedeDriver::GetID(), ARCHIMEDE_TYPE);
  1280. if (aFunction.IsNull()) return NULL;
  1281. //Check if the function is set correctly
  1282. if (aFunction->GetDriverGUID() != GEOMImpl_ArchimedeDriver::GetID()) return NULL;
  1283. GEOMImpl_IArchimede aAI (aFunction);
  1284. Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
  1285. if (aRefShape.IsNull()) return NULL;
  1286. aAI.SetBasicShape(aRefShape);
  1287. SETPARAM(aAI.SetWeight,theWeight);
  1288. SETPARAM(aAI.SetDensity,theWaterDensity);
  1289. SETPARAM(aAI.SetDeflection,theMeshingDeflection);
  1290. //Compute the Archimede value
  1291. try {
  1292. #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
  1293. OCC_CATCH_SIGNALS;
  1294. #endif
  1295. if (!GetSolver()->ComputeFunction(aFunction)) {
  1296. SetErrorCode("Archimede driver failed");
  1297. return NULL;
  1298. }
  1299. }
  1300. catch (Standard_Failure) {
  1301. Handle(Standard_Failure) aFail = Standard_Failure::Caught();
  1302. SetErrorCode(aFail->GetMessageString());
  1303. return NULL;
  1304. }
  1305. //Make a Python command
  1306. GEOM::TPythonDump(aFunction) << aChamfer
  1307. << " = Archimede(" << theShape << ", " << theWeight << ", "
  1308. << theWaterDensity << ", " << theMeshingDeflection << ")";
  1309. SetErrorCode(GEOM_OK);
  1310. return aChamfer;
  1311. }
  1312. //=============================================================================
  1313. /*!
  1314. * GetSubShape
  1315. */
  1316. //=============================================================================
  1317. bool GEOMImpl_ILocalOperations::GetSubShape (const TopoDS_Shape& theShape, const int theIndex,
  1318. TopoDS_Shape& theSubShape)
  1319. {
  1320. if (theShape.IsNull() || theIndex < 1)
  1321. return false;
  1322. TopTools_IndexedMapOfShape anIndices;
  1323. TopExp::MapShapes(theShape, anIndices);
  1324. if (theIndex > anIndices.Extent()) return false;
  1325. theSubShape = anIndices.FindKey(theIndex);
  1326. return true;
  1327. }
  1328. //=============================================================================
  1329. /*!
  1330. * GetSubShapeIndex
  1331. */
  1332. //=============================================================================
  1333. Standard_Integer GEOMImpl_ILocalOperations::GetSubShapeIndex (Handle(GEOM_Object) theShape,
  1334. Handle(GEOM_Object) theSubShape)
  1335. {
  1336. SetErrorCode(GEOM_KO);
  1337. Standard_Integer anInd = -1;
  1338. GEOM_Engine* anEngine = GetEngine();
  1339. //GEOMImpl_Gen* aGen = dynamic_cast<GEOMImpl_Gen*>(anEngine);
  1340. GEOMImpl_Gen* aGen = (GEOMImpl_Gen*)anEngine;
  1341. if (aGen) {
  1342. GEOMImpl_IShapesOperations* anIShapesOperations =
  1343. aGen->GetIShapesOperations(GetDocID());
  1344. anInd = anIShapesOperations->GetSubShapeIndex(theShape, theSubShape);
  1345. SetErrorCode(anIShapesOperations->GetErrorCode());
  1346. }
  1347. return anInd;
  1348. }