1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : GEOMImpl_IAdvancedOperations.cxx
21 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
24 #include <Standard_Stream.hxx>
25 #include "GEOMImpl_Types.hxx"
26 #include "GEOMImpl_IAdvancedOperations.hxx"
27 #include "GEOMImpl_IBasicOperations.hxx"
28 #include "GEOMImpl_IBooleanOperations.hxx"
29 #include "GEOMImpl_IShapesOperations.hxx"
30 #include "GEOMImpl_ITransformOperations.hxx"
31 #include "GEOMImpl_IBlocksOperations.hxx"
32 #include "GEOMImpl_I3DPrimOperations.hxx"
33 #include "GEOMImpl_ILocalOperations.hxx"
35 #include "GEOMImpl_Gen.hxx"
37 #include <utilities.h>
39 #include <Utils_ExceptHandlers.hxx>
41 #include "GEOM_Function.hxx"
42 #include "GEOM_PythonDump.hxx"
44 #include "GEOMImpl_PipeTShapeDriver.hxx"
45 #include "GEOMImpl_IPipeTShape.hxx"
46 /*@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@*/
49 #include <TopExp_Explorer.hxx>
51 #include <TopoDS_Vertex.hxx>
52 #include <TopTools_IndexedMapOfShape.hxx>
57 #include <BRepBuilderAPI_Transform.hxx>
58 #include <BRep_Tool.hxx>
61 #include <TFunction_DriverTable.hxx>
62 #include <TFunction_Driver.hxx>
63 #include <TFunction_Logbook.hxx>
64 #include <TDF_Tool.hxx>
65 #include <Standard_Failure.hxx>
66 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
68 #define HALF_LENGTH_MAIN_PIPE "Main pipe half length" //"Tuyau principal - demi longueur"
69 #define HALF_LENGTH_INCIDENT_PIPE "Incident pipe half length" //"Tuyau incident - demi longueur"
70 #define CIRCULAR_QUARTER_PIPE "Circular quarter of pipe" //"Circulaire - quart de tuyau"
71 #define THICKNESS "Thickness" //"Epaisseur"
72 #define FLANGE "Flange" // "Collerette"
73 #define CHAMFER_OR_FILLET "Chamfer or fillet" //"Chanfrein ou Raccord"
74 #define JUNCTION_FACE_1 "Junction 1" //"Face de jonction 1"
75 #define JUNCTION_FACE_2 "Junction 2" //"Face de jonction 2"
76 #define JUNCTION_FACE_3 "Junction 3" //"Face de jonction 3"
78 //=============================================================================
82 //=============================================================================
83 GEOMImpl_IAdvancedOperations::GEOMImpl_IAdvancedOperations(GEOM_Engine* theEngine, int theDocID) :
84 GEOM_IOperations(theEngine, theDocID)
86 MESSAGE("GEOMImpl_IAdvancedOperations::GEOMImpl_IAdvancedOperations");
87 myBasicOperations = new GEOMImpl_IBasicOperations(GetEngine(), GetDocID());
88 myBooleanOperations = new GEOMImpl_IBooleanOperations(GetEngine(), GetDocID());
89 myShapesOperations = new GEOMImpl_IShapesOperations(GetEngine(), GetDocID());
90 myTransformOperations = new GEOMImpl_ITransformOperations(GetEngine(), GetDocID());
91 myBlocksOperations = new GEOMImpl_IBlocksOperations(GetEngine(), GetDocID());
92 my3DPrimOperations = new GEOMImpl_I3DPrimOperations(GetEngine(), GetDocID());
93 myLocalOperations = new GEOMImpl_ILocalOperations(GetEngine(), GetDocID());
96 //=============================================================================
100 //=============================================================================
101 GEOMImpl_IAdvancedOperations::~GEOMImpl_IAdvancedOperations()
103 MESSAGE("GEOMImpl_IAdvancedOperations::~GEOMImpl_IAdvancedOperations");
104 delete myBasicOperations;
105 delete myBooleanOperations;
106 delete myShapesOperations;
107 delete myTransformOperations;
108 delete myBlocksOperations;
109 delete my3DPrimOperations;
110 delete myLocalOperations;
113 //=============================================================================
117 //=============================================================================
118 gp_Trsf GEOMImpl_IAdvancedOperations::GetPositionTrsf(double theL1, double theL2,
119 Handle(GEOM_Object) theP1,
120 Handle(GEOM_Object) theP2,
121 Handle(GEOM_Object) theP3)
123 // Old Local Coordinates System oldLCS
125 gp_Pnt P1(-theL1, 0, 0);
126 gp_Pnt P2(theL1, 0, 0);
127 gp_Pnt P3(0, 0, theL2);
129 gp_Dir oldX(gp_Vec(P1, P2));
130 gp_Dir oldZ(gp_Vec(P0, P3));
131 gp_Ax3 oldLCS(P0, oldZ, oldX);
133 // New Local Coordinates System newLCS
134 double LocX, LocY, LocZ;
135 gp_Pnt newP1 = BRep_Tool::Pnt(TopoDS::Vertex(theP1->GetValue()));
136 gp_Pnt newP2 = BRep_Tool::Pnt(TopoDS::Vertex(theP2->GetValue()));
137 gp_Pnt newP3 = BRep_Tool::Pnt(TopoDS::Vertex(theP3->GetValue()));
138 LocX = (newP1.X() + newP2.X()) / 2.;
139 LocY = (newP1.Y() + newP2.Y()) / 2.;
140 LocZ = (newP1.Z() + newP2.Z()) / 2.;
141 gp_Pnt newO(LocX, LocY, LocZ);
143 gp_Dir newX(gp_Vec(newP1, newP2)); // P1P2 Vector
144 gp_Dir newZ(gp_Vec(newO, newP3)); // OP3 Vector
145 gp_Ax3 newLCS = gp_Ax3(newO, newZ, newX);
148 aTrsf.SetDisplacement(oldLCS, newLCS);
153 //=============================================================================
155 * CheckCompatiblePosition
158 //=============================================================================
159 bool GEOMImpl_IAdvancedOperations::CheckCompatiblePosition(double& theL1, double& theL2,
160 Handle(GEOM_Object) theP1,
161 Handle(GEOM_Object) theP2,
162 Handle(GEOM_Object) theP3,
166 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(theP1->GetValue()));
167 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(theP2->GetValue()));
168 gp_Pnt P3 = BRep_Tool::Pnt(TopoDS::Vertex(theP3->GetValue()));
170 double d12 = P1.Distance(P2);
171 double d13 = P1.Distance(P3);
172 double d23 = P2.Distance(P3);
173 // double d2 = newO.Distance(P3);
175 if (Abs(d12) <= Precision::Confusion()) {
176 SetErrorCode("Junctions points P1 and P2 are identical");
179 if (Abs(d13) <= Precision::Confusion()) {
180 SetErrorCode("Junctions points P1 and P3 are identical");
183 if (Abs(d23) <= Precision::Confusion()) {
184 SetErrorCode("Junctions points P2 and P3 are identical");
189 double newL1 = 0.5 * d12;
190 double newL2 = sqrt(pow(d13,2)-pow(newL1,2));
192 // theL1*(1-theTolerance) <= newL1 <= theL1*(1+theTolerance)
194 if (fabs(newL1 - theL1) > Precision::Approximation()) {
195 if ( (newL1 * (1 - theTolerance) -theL1 <= Precision::Approximation()) &&
196 (newL1 * (1 + theTolerance) -theL1 >= Precision::Approximation()) ) {
197 // std::cerr << "theL1 = newL1" << std::endl;
201 SetErrorCode("Dimension for main pipe (L1) is incompatible with new position");
207 // theL2*(1-theTolerance) <= newL2 <= theL2*(1+theTolerance)
209 if (fabs(newL2 - theL2) > Precision::Approximation()) {
210 if ( (newL2 * (1 - theTolerance) -theL2 <= Precision::Approximation()) &&
211 (newL2 * (1 + theTolerance) -theL2 >= Precision::Approximation()) ) {
215 SetErrorCode("Dimension for incident pipe (L2) is incompatible with new position");
225 //=============================================================================
227 * Generate the propagation groups of a Pipe T-Shape used for hexa mesh
229 //=============================================================================
230 bool GEOMImpl_IAdvancedOperations::MakeGroups(Handle(GEOM_Object) theShape, int shapeType,
231 double theR1, double theW1, double theL1,
232 double theR2, double theW2, double theL2,
233 Handle(TColStd_HSequenceOfTransient) theSeq,
238 if (theShape.IsNull()) return false;
240 TopoDS_Shape aShape = theShape->GetValue();
241 if (aShape.IsNull()) {
242 SetErrorCode("Shape is not defined");
246 gp_Trsf aTrsfInv = aTrsf.Inverted();
248 int expectedGroups = 0;
249 if (shapeType == TSHAPE_BASIC)
250 if (Abs(theR2+theW2-theR1-theW1) <= Precision::Approximation())
254 else if (shapeType == TSHAPE_CHAMFER || shapeType == TSHAPE_FILLET)
257 double aR1Ext = theR1 + theW1;
258 double aR2Ext = theR2 + theW2;
260 /////////////////////////
261 //// Groups of Faces ////
262 /////////////////////////
265 // Comment the following lines when GetInPlace bug is solved
267 // Workaround of GetInPlace bug
268 // Create a bounding box that fits the shape
269 Handle(GEOM_Object) aBox = my3DPrimOperations->MakeBoxDXDYDZ(2*theL1, 2*aR1Ext, aR1Ext+theL2);
270 aBox->GetLastFunction()->SetDescription("");
271 myTransformOperations->TranslateDXDYDZ(aBox, -theL1, -aR1Ext, -aR1Ext);
272 aBox->GetLastFunction()->SetDescription("");
273 // Apply transformation to box
274 BRepBuilderAPI_Transform aTransformationBox(aBox->GetValue(), aTrsf, Standard_False);
275 TopoDS_Shape aBoxShapeTrsf = aTransformationBox.Shape();
276 aBox->GetLastFunction()->SetValue(aBoxShapeTrsf);
278 // Get the shell of the box
279 Handle(GEOM_Object) aShell = Handle(GEOM_Object)::DownCast(myShapesOperations->MakeExplode(aBox, TopAbs_SHELL, true)->Value(1));
280 aBox->GetLastFunction()->SetDescription("");
281 aShell->GetLastFunction()->SetDescription("");
282 // Get the common shapes between shell and shape
283 Handle(GEOM_Object) aCommonCompound = myBooleanOperations->MakeBoolean (theShape, aShell, 1); // MakeCommon
284 if (aCommonCompound.IsNull()) {
285 SetErrorCode(myBooleanOperations->GetErrorCode());
288 aCommonCompound->GetLastFunction()->SetDescription("");
289 // Explode the faces of common shapes => 3 faces
290 Handle(TColStd_HSequenceOfTransient) aCommonFaces = myShapesOperations->MakeExplode(aCommonCompound, TopAbs_FACE, true);
291 aCommonCompound->GetLastFunction()->SetDescription("");
292 std::list<Handle(GEOM_Object)> aCompoundOfFacesList;
294 for (int i=0 ; i<= aCommonFaces->Length()-4 ; i+=4) {
295 std::list<Handle(GEOM_Object)> aFacesList;
296 for (int j = 1 ; j <= 4 ; j++) {
297 Handle(GEOM_Object) aFace = Handle(GEOM_Object)::DownCast(aCommonFaces->Value(i+j)); // Junction faces
298 if (!aFace.IsNull()) {
299 aFace->GetLastFunction()->SetDescription("");
300 aFacesList.push_back(aFace);
303 Handle(GEOM_Object) aCompoundOfFaces = myShapesOperations->MakeCompound(aFacesList);
304 if (!aCompoundOfFaces.IsNull()) {
305 aCompoundOfFaces->GetLastFunction()->SetDescription("");
306 aCompoundOfFacesList.push_back(aCompoundOfFaces);
310 if (aCompoundOfFacesList.size() == 3) {
311 Handle(GEOM_Object) aPln1 = aCompoundOfFacesList.front();
312 aCompoundOfFacesList.pop_front();
313 Handle(GEOM_Object) aPln2 = aCompoundOfFacesList.front();
314 aCompoundOfFacesList.pop_front();
315 Handle(GEOM_Object) aPln3 = aCompoundOfFacesList.front();
316 aCompoundOfFacesList.pop_front();
321 // Uncomment the following lines when GetInPlace bug is solved
323 // Handle(GEOM_Object) aP1 = myBasicOperations->MakePointXYZ(-theL1, 0, 0);
324 // Handle(GEOM_Object) aP2 = myBasicOperations->MakePointXYZ(-0, 0, theL2);
325 // Handle(GEOM_Object) aP3 = myBasicOperations->MakePointXYZ(theL1, 0, 0);
326 // aP1->GetLastFunction()->SetDescription("");
327 // aP2->GetLastFunction()->SetDescription("");
328 // aP3->GetLastFunction()->SetDescription("");
329 // Handle(GEOM_Object) aV1 = myBasicOperations->MakeVectorDXDYDZ(-1, 0, 0);
330 // Handle(GEOM_Object) aV2 = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
331 // Handle(GEOM_Object) aV3 = myBasicOperations->MakeVectorDXDYDZ(1, 0, 0);
332 // aV1->GetLastFunction()->SetDescription("");
333 // aV2->GetLastFunction()->SetDescription("");
334 // aV3->GetLastFunction()->SetDescription("");
335 // Handle(GEOM_Object) aPln1 = myBasicOperations->MakePlanePntVec(aP1, aV1, 2*(aR1Ext+theL2));
336 // Handle(GEOM_Object) aPln2 = myBasicOperations->MakePlanePntVec(aP2, aV2, 2*(aR2Ext));
337 // Handle(GEOM_Object) aPln3 = myBasicOperations->MakePlanePntVec(aP3, aV3, 2*(aR1Ext+theL2));
338 // aPln1->GetLastFunction()->SetDescription("");
339 // aPln2->GetLastFunction()->SetDescription("");
340 // aPln3->GetLastFunction()->SetDescription("");
342 // BRepBuilderAPI_Transform aTransformation1(aPln1->GetValue(), aTrsf, Standard_False);
343 // TopoDS_Shape aTrsf_Shape1 = aTransformation1.Shape();
344 // aPln1->GetLastFunction()->SetValue(aTrsf_Shape1);
345 // BRepBuilderAPI_Transform aTransformation2(aPln2->GetValue(), aTrsf, Standard_False);
346 // TopoDS_Shape aTrsf_Shape2 = aTransformation2.Shape();
347 // aPln2->GetLastFunction()->SetValue(aTrsf_Shape2);
348 // BRepBuilderAPI_Transform aTransformation3(aPln3->GetValue(), aTrsf, Standard_False);
349 // TopoDS_Shape aTrsf_Shape3 = aTransformation3.Shape();
350 // aPln3->GetLastFunction()->SetValue(aTrsf_Shape3);
354 Handle(GEOM_Object) junctionFaces1 = myShapesOperations->GetInPlace(theShape, aPln1);
355 if (junctionFaces1.IsNull())
356 junctionFaces1 = myShapesOperations->GetShapesOnShapeAsCompound(aPln1, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
357 if (!junctionFaces1.IsNull()) {
358 junctionFaces1->GetLastFunction()->SetDescription("");
359 junctionFaces1->SetName("JUNCTION_FACE_1");
360 theSeq->Append(junctionFaces1);
363 SetErrorCode("Junction face 1 not found");
364 // theSeq->Append(aPln1);
367 Handle(GEOM_Object) junctionFaces2 = myShapesOperations->GetInPlace(theShape, aPln2);
368 if (junctionFaces2.IsNull())
369 junctionFaces2 = myShapesOperations->GetShapesOnShapeAsCompound(aPln2, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
370 if (!junctionFaces2.IsNull()) {
371 junctionFaces2->GetLastFunction()->SetDescription("");
372 junctionFaces2->SetName("JUNCTION_FACE_2");
373 theSeq->Append(junctionFaces2);
376 SetErrorCode("Junction face 2 not found");
377 // theSeq->Append(aPln2);
380 Handle(GEOM_Object) junctionFaces3 = myShapesOperations->GetInPlace(theShape, aPln3);
381 if (junctionFaces3.IsNull())
382 junctionFaces3 = myShapesOperations->GetShapesOnShapeAsCompound(aPln3, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
383 if (!junctionFaces3.IsNull()) {
384 junctionFaces3->GetLastFunction()->SetDescription("");
385 junctionFaces3->SetName("JUNCTION_FACE_3");
386 theSeq->Append(junctionFaces3);
389 SetErrorCode("Junction face 3 not found");
390 // theSeq->Append(aPln3);
393 // Comment the following lines when GetInPlace bug is solved
397 /////////////////////////
398 //// Groups of Edges ////
399 /////////////////////////
400 // Result of propagate
402 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
404 TCollection_AsciiString theDesc = aFunction->GetDescription();
405 Handle(TColStd_HSequenceOfTransient) aSeqPropagate = myBlocksOperations->Propagate(theShape);
406 if (aSeqPropagate.IsNull() || aSeqPropagate->Length() == 0) {
407 SetErrorCode("Propagation groups not found");
410 Standard_Integer nbEdges, aNbGroups = aSeqPropagate->Length();
411 // Recover previous description to get rid of Propagate dump
412 aFunction->SetDescription(theDesc);
415 bool circularFoundAndAdded = false;
416 bool incidentPipeFound = false;
417 bool mainPipeFound = false;
418 bool mainPipeFoundAndAdded = false;
419 bool radialFound =false;
420 bool flangeFound = false;
421 bool flangeFoundAndAdded = false;
422 bool chamferOrFilletFound = false;
424 for (int i=1 ; i<= aNbGroups; i++) {
427 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(aSeqPropagate->Value(i));
431 TopoDS_Shape aGroupShape = aGroup->GetValue();
432 BRepBuilderAPI_Transform aTransformationShapeInv(aGroupShape, aTrsfInv, Standard_False);
433 TopoDS_Shape aGroupShapeTrsfInv = aTransformationShapeInv.Shape();
435 TopTools_IndexedMapOfShape anEdgesMap;
436 TopExp::MapShapes(aGroupShapeTrsfInv,TopAbs_EDGE, anEdgesMap);
437 nbEdges = anEdgesMap.Extent();
439 if (shapeType == TSHAPE_BASIC) {
440 if ((nbEdges == 21) || /*R1Ext = R2Ext*/(nbEdges == 17)){
442 aGroup->SetName("THICKNESS");
444 else if (nbEdges == 6) {
445 if (!circularFoundAndAdded) {
446 circularFoundAndAdded = true;
448 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
451 else if (nbEdges == 8) {
452 incidentPipeFound = true;
453 mainPipeFound = false;
457 TopExp_Explorer Ex(aGroupShapeTrsfInv,TopAbs_VERTEX);
459 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
460 double x=aP.X(), y=aP.Y(), z=aP.Z();
463 if ((Abs(x) > aR2Ext + Precision::Confusion()) ||
464 (Abs(y) > aR2Ext + Precision::Confusion())) {
465 incidentPipeFound = false;
468 if ( z < -Precision::Confusion()) {
469 // length of main pipe
470 mainPipeFound = true;
471 if (!mainPipeFoundAndAdded) {
472 mainPipeFoundAndAdded = true;
474 aGroup->SetName("HALF_LENGTH_MAIN_PIPE");
478 else if (Abs(x) > (theL1-Precision::Confusion())) {
479 // discretisation circulaire
481 if (!circularFoundAndAdded) {
482 circularFoundAndAdded = true;
484 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
489 if (incidentPipeFound) {
491 aGroup->SetName("HALF_LENGTH_INCIDENT_PIPE");
493 if (!addGroup && (!incidentPipeFound &&
497 // Flange (collerette)
500 aGroup->SetName("FLANGE");
506 else if (shapeType == TSHAPE_CHAMFER || shapeType == TSHAPE_FILLET) {
509 aGroup->SetName("THICKNESS");
511 else if ((nbEdges == 10) || (nbEdges == 6)) {
512 if (!circularFoundAndAdded) {
514 circularFoundAndAdded = true;
515 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
518 else if (nbEdges == 8) {
519 incidentPipeFound = true;
520 mainPipeFound = true;
523 TopExp_Explorer Ex(aGroupShapeTrsfInv,TopAbs_VERTEX);
525 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
526 double x=aP.X(), y=aP.Y(), z=aP.Z();
528 // tuy_princ_long_avant & tuy_princ_long_apres
529 bool isMain = (((z < Precision::Confusion()) || (x < Precision::Confusion())) &&
530 ((y <= aR1Ext + Precision::Confusion()) ||
531 (y <= -(aR1Ext + Precision::Confusion())) ||
532 (y <= theR1 + Precision::Confusion()) ||
533 (y == -(theR1 + Precision::Confusion()))));
537 mainPipeFound = false;
541 if (z < Precision::Confusion()) {
543 if (!flangeFoundAndAdded) {
544 flangeFoundAndAdded = true;
546 aGroup->SetName("FLANGE");
551 if ((Abs(x) > aR2Ext + Precision::Confusion()) ||
552 (Abs(y) > aR2Ext + Precision::Confusion())) {
553 incidentPipeFound = false;
559 aGroup->SetName("HALF_LENGTH_MAIN_PIPE");
561 if (incidentPipeFound) {
563 aGroup->SetName("HALF_LENGTH_INCIDENT_PIPE");
565 if (!addGroup && (!incidentPipeFound &&
568 !chamferOrFilletFound)) {
570 chamferOrFilletFound = true;
571 if (shapeType == TSHAPE_CHAMFER)
572 aGroup->SetName("CHAMFER");
574 aGroup->SetName("FILLET");
580 // Add group to the list
582 theSeq->Append(aGroup);
589 bool GEOMImpl_IAdvancedOperations::MakePipeTShapePartition(Handle(GEOM_Object) theShape,
590 double theR1, double theW1, double theL1,
591 double theR2, double theW2, double theL2,
592 double theH, double theW,
593 double theRF, bool isNormal)
597 // Build tools for partition operation:
598 // 1 face and 2 planes
600 Handle(GEOM_Object) arete_intersect_int;
601 Handle(GEOM_Object) wire_t, wire_t2, face_t, face_t2;
602 Handle(GEOM_Object) chan_racc;
603 Handle(GEOM_Object) vi1, vi2;
605 Handle(GEOM_Object) Vector_Z = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
606 Vector_Z->GetLastFunction()->SetDescription("");
609 double aSize = 2*(theL1 + theL2);
610 double aR1Ext = theR1 + theW1;
611 double aR2Ext = theR2 + theW2;
612 double theVertCylinderRadius = aR2Ext + theW + theRF;
613 double theHoriCylinderRadius = aR1Ext + theH + theRF;
615 // Common edges on internal cylinder
616 Handle(GEOM_Object) box_i = my3DPrimOperations->MakeBoxDXDYDZ(theR2, theR2, theR1);
617 box_i->GetLastFunction()->SetDescription("");
618 box_i = myTransformOperations->TranslateDXDYDZ(box_i, -theR2, -theR2, 0);
619 box_i->GetLastFunction()->SetDescription("");
621 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
622 TCollection_AsciiString theDesc = aFunction->GetDescription();
623 Handle(TColStd_HSequenceOfTransient) edges_i = myShapesOperations->GetShapesOnBox(box_i, theShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
624 // Recover previous description to get rid of Propagate dump
625 aFunction->SetDescription(theDesc);
626 if (edges_i.IsNull() || edges_i->Length() == 0) {
627 SetErrorCode("Internal edges not found");
630 for (int i=1; i<=edges_i->Length();i++) {
631 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(edges_i->Value(i));
632 anObj->GetLastFunction()->SetDescription("");
634 arete_intersect_int = Handle(GEOM_Object)::DownCast(edges_i->Value(1));
636 // search for vertices located on both internal pipes
637 aFunction = theShape->GetLastFunction();
638 theDesc = aFunction->GetDescription();
639 Handle(TColStd_HSequenceOfTransient) vertices_i = myShapesOperations->GetShapesOnBox(box_i, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
640 // Recover previous description to get rid of Propagate dump
641 aFunction->SetDescription(theDesc);
642 if (vertices_i.IsNull() || vertices_i->Length() == 0) {
643 SetErrorCode("Internal vertices not found");
647 for (int i = 1; i <= vertices_i->Length(); i++) {
648 Handle(GEOM_Object) v = Handle(GEOM_Object)::DownCast(vertices_i->Value(i));
649 v->GetLastFunction()->SetDescription("");
650 TopoDS_Vertex aVertex = TopoDS::Vertex(v->GetValue());
651 gp_Pnt aP = BRep_Tool::Pnt(aVertex);
652 if (Abs(aP.X()) <= Precision::Confusion()) {
653 if (Abs(aP.Y()) - theR2 <= Precision::Confusion())
655 } else if (Abs(aP.Y()) <= Precision::Confusion()) {
656 if (Abs(aP.X()) - theR1 <= Precision::Confusion())
661 std::list<Handle(GEOM_Object)> theShapes;
664 Handle(GEOM_Object) ve1, ve2;
666 Handle(GEOM_Object) box_e = my3DPrimOperations->MakeBoxDXDYDZ(aR2Ext, aR2Ext, aR1Ext);
667 box_e->GetLastFunction()->SetDescription("");
668 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -aR2Ext, -aR2Ext, 0);
669 box_e->GetLastFunction()->SetDescription("");
670 // Common edges on external cylinder
671 aFunction = theShape->GetLastFunction();
672 theDesc = aFunction->GetDescription();
673 Handle(TColStd_HSequenceOfTransient) edges_e = myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
674 // Recover previous description to get rid of Propagate dump
675 aFunction->SetDescription(theDesc);
676 if (edges_e.IsNull() || edges_e->Length() == 0) {
677 SetErrorCode("External edges not found");
680 for (int i=1; i<=edges_e->Length();i++) {
681 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(edges_e->Value(i));
682 anObj->GetLastFunction()->SetDescription("");
685 // search for vertices located on both external pipes
686 aFunction = theShape->GetLastFunction();
687 theDesc = aFunction->GetDescription();
688 Handle(TColStd_HSequenceOfTransient) vertices_e = myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
689 // Recover previous description to get rid of Propagate dump
690 aFunction->SetDescription(theDesc);
691 if (vertices_e.IsNull() || vertices_e->Length() == 0) {
692 SetErrorCode("External vertices not found");
696 for (int i = 1; i <= vertices_e->Length(); i++) {
697 Handle(GEOM_Object) v = Handle(GEOM_Object)::DownCast(vertices_e->Value(i));
698 v->GetLastFunction()->SetDescription("");
699 TopoDS_Vertex aVertex = TopoDS::Vertex(v->GetValue());
700 gp_Pnt aP = BRep_Tool::Pnt(aVertex);
701 if (Abs(aP.X()) <= Precision::Confusion()) {
702 if (Abs(aP.Y()) - theR2 > Precision::Confusion())
704 } else if (Abs(aP.Y()) <= Precision::Confusion()) {
705 if (Abs(aP.X()) - theR2 > Precision::Confusion())
709 Handle(GEOM_Object) edge_e1, edge_e2;
711 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
714 edge_e1 = myBasicOperations->MakeLineTwoPnt(ve1, vi1);
715 if (edge_e1.IsNull()) {
716 SetErrorCode("Edge 1 could not be built");
719 } catch (Standard_Failure) {
720 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
721 SetErrorCode(aFail->GetMessageString());
726 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
729 edge_e2 = myBasicOperations->MakeLineTwoPnt(ve2, vi2);
730 if (edge_e2.IsNull()) {
731 SetErrorCode("Edge 2 could not be built");
734 } catch (Standard_Failure) {
735 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
736 SetErrorCode(aFail->GetMessageString());
740 edge_e1->GetLastFunction()->SetDescription("");
741 edge_e2->GetLastFunction()->SetDescription("");
743 std::list<Handle(GEOM_Object)> edge_e_elist;
744 edge_e_elist.push_back(arete_intersect_int);
745 edge_e_elist.push_back(edge_e1);
746 edge_e_elist.push_back(Handle(GEOM_Object)::DownCast(edges_e->Value(1)));
747 edge_e_elist.push_back(edge_e2);
748 wire_t = myShapesOperations->MakeWire(edge_e_elist, 1e-7);
749 if (wire_t.IsNull()) {
750 SetErrorCode("Impossible to build wire");
753 wire_t->GetLastFunction()->SetDescription("");
754 face_t = myShapesOperations->MakeFace(wire_t, false);
755 if (face_t.IsNull()) {
756 SetErrorCode("Impossible to build face");
759 face_t->GetLastFunction()->SetDescription("");
762 Handle(GEOM_Object) P1, P2, P3, P4, P5, P6;
763 int idP1, idP2, idP3, idP4;
768 Handle(GEOM_Object) box_e = my3DPrimOperations->MakeBoxDXDYDZ(theVertCylinderRadius, theVertCylinderRadius, theHoriCylinderRadius);
769 box_e->GetLastFunction()->SetDescription("");
770 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -theVertCylinderRadius, -theVertCylinderRadius, 0);
771 box_e->GetLastFunction()->SetDescription("");
773 aFunction = theShape->GetLastFunction();
774 theDesc = aFunction->GetDescription();
775 Handle(TColStd_HSequenceOfTransient) extremVertices = myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
776 // Recover previous description to get rid of Propagate dump
777 aFunction->SetDescription(theDesc);
779 if (extremVertices.IsNull() || extremVertices->Length() == 0) {
781 SetErrorCode("Vertices on chamfer not found");
783 SetErrorCode("Vertices on fillet not found");
787 theShapes.push_back(theShape);
788 theShapes.push_back(box_e);
789 if (extremVertices->Length() != 6) {
790 // for (int i=1; i<=extremVertices->Length(); i++){
791 // theShapes.push_back(Handle(GEOM_Object)::DownCast(extremVertices->Value(i)));
793 // Handle(GEOM_Object) aCompound = myShapesOperations->MakeCompound(theShapes);
794 // TopoDS_Shape aCompoundShape = aCompound->GetValue();
795 // theShape->GetLastFunction()->SetValue(aCompoundShape);
796 SetErrorCode("Bad number of vertices on chamfer found");
800 for (int i=1; i<=extremVertices->Length(); i++){
801 Handle(GEOM_Object) aV = Handle(GEOM_Object)::DownCast(extremVertices->Value(i));
802 aV->GetLastFunction()->SetDescription("");
803 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aV->GetValue()));
805 if (Abs(aP.X()) <= Precision::Confusion()) {
806 if (Abs(aP.Y()) - theR2 > Precision::Confusion()) {
808 if (aP.Z()-ZX > Precision::Confusion()) {
815 if (Abs(aP.X()) - theR2 > Precision::Confusion()) {
817 if (aP.Z() - ZY > Precision::Confusion()) {
834 P1 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP1));
835 P2 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP2));
836 P3 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP3));
837 P4 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP4));
839 Handle(GEOM_Object) Cote_1 = myBasicOperations->MakeLineTwoPnt(P1, vi1);
840 if (Cote_1.IsNull()) {
841 SetErrorCode("Impossible to build edge in thickness");
844 Cote_1->GetLastFunction()->SetDescription("");
846 Handle(GEOM_Object) Cote_2 = myBasicOperations->MakeLineTwoPnt(vi2, P3);
847 if (Cote_2.IsNull()) {
848 SetErrorCode("Impossible to build edge in thickness");
851 Cote_2->GetLastFunction()->SetDescription("");
853 // edge_chan_princ = arete du chanfrein (ou raccord) sur le tuyau principal
854 // edge_chan_inc = arete du chanfrein (ou raccord) sur le tuyau incident
855 // std::cerr << "Getting chamfer edge on main pipe" << std::endl;
856 Handle(GEOM_Object) edge_chan_princ = myBlocksOperations->GetEdge(theShape, P1, P3);
857 if (edge_chan_princ.IsNull()) {
858 SetErrorCode("Impossible to find edge on main pipe");
861 edge_chan_princ->GetLastFunction()->SetDescription("");
863 Handle(GEOM_Object) edge_chan_inc = myBlocksOperations->GetEdge(theShape, P2, P4);
864 if (edge_chan_inc.IsNull()) {
865 SetErrorCode("Impossible to find edge on incident pipe");
868 edge_chan_inc->GetLastFunction()->SetDescription("");
870 std::list<Handle(GEOM_Object)> edgeList1;
871 edgeList1.push_back(edge_chan_princ);
872 edgeList1.push_back(Cote_1);
873 edgeList1.push_back(arete_intersect_int);
874 edgeList1.push_back(Cote_2);
876 // std::cerr << "Creating wire 1" << std::endl;
877 wire_t = myShapesOperations->MakeWire(edgeList1, 1e-7);
878 if (wire_t.IsNull()) {
879 SetErrorCode("Impossible to build wire");
882 wire_t->GetLastFunction()->SetDescription("");
884 // std::cerr << "Creating face 1" << std::endl;
885 face_t = myShapesOperations->MakeFace(wire_t, false);
886 if (face_t.IsNull()) {
887 SetErrorCode("Impossible to build face");
890 face_t->GetLastFunction()->SetDescription("");
891 theShapes.push_back(face_t);
893 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(P2->GetValue()));
894 gp_Pnt aP5 = BRep_Tool::Pnt(TopoDS::Vertex(vi1->GetValue()));
895 double deltaZ = aP2.Z() - aP5.Z();
896 // std::cerr << "Creating new point from vi1 with deltaZ = " << deltaZ << std::endl;
897 Handle(GEOM_Object) P5bis = myTransformOperations->TranslateDXDYDZCopy(vi1, 0, 0, deltaZ);
898 if (P5bis.IsNull()) {
899 SetErrorCode("Impossible to translate vertex");
902 P5bis->GetLastFunction()->SetDescription("");
904 gp_Pnt aP4 = BRep_Tool::Pnt(TopoDS::Vertex(P4->GetValue()));
905 gp_Pnt aP6 = BRep_Tool::Pnt(TopoDS::Vertex(vi2->GetValue()));
906 deltaZ = aP4.Z() - aP6.Z();
907 // std::cerr << "Creating new point from vi2 with deltaZ = " << deltaZ << std::endl;
908 Handle(GEOM_Object) P6bis = myTransformOperations->TranslateDXDYDZCopy(vi2, 0, 0, deltaZ);
909 if (P6bis.IsNull()) {
910 SetErrorCode("Impossible to translate vertex");
913 P6bis->GetLastFunction()->SetDescription("");
915 // std::cerr << "Creating new line 1 from 2 previous points" << std::endl;
916 Handle(GEOM_Object) Cote_3 = myBasicOperations->MakeLineTwoPnt(P5bis, P2);
917 if (Cote_3.IsNull()) {
918 SetErrorCode("Impossible to build edge in thickness");
921 Cote_3->GetLastFunction()->SetDescription("");
923 // std::cerr << "Creating new line 2 from 2 previous points" << std::endl;
924 Handle(GEOM_Object) Cote_4 = myBasicOperations->MakeLineTwoPnt(P6bis, P4);
925 if (Cote_4.IsNull()) {
926 SetErrorCode("Impossible to build edge in thickness");
929 Cote_4->GetLastFunction()->SetDescription("");
931 // std::cerr << "Creating new line 3 from 2 previous points" << std::endl;
932 Handle(GEOM_Object) Cote_5 = myBasicOperations->MakeLineTwoPnt(P5bis, P6bis);
933 if (Cote_4.IsNull()) {
934 SetErrorCode("Impossible to build edge in thickness");
937 Cote_5->GetLastFunction()->SetDescription("");
939 std::list<Handle(GEOM_Object)> edgeList2;
940 edgeList2.push_back(edge_chan_inc);
941 edgeList2.push_back(Cote_3);
942 edgeList2.push_back(Cote_5);
943 edgeList2.push_back(Cote_4);
944 // std::cerr << "Creating wire 2" << std::endl;
945 wire_t2 = myShapesOperations->MakeWire(edgeList2, 1e-7);
946 if (wire_t2.IsNull()) {
947 SetErrorCode("Impossible to build wire");
950 wire_t2->GetLastFunction()->SetDescription("");
951 // std::cerr << "Creating face 2" << std::endl;
952 face_t2 = myShapesOperations->MakeFace(wire_t2, false);
953 if (face_t2.IsNull()) {
954 SetErrorCode("Impossible to build face");
957 face_t2->GetLastFunction()->SetDescription("");
958 theShapes.push_back(face_t2);
962 Handle(GEOM_Object) aP0 = myBasicOperations->MakePointXYZ(0, 0, 0);
963 Handle(GEOM_Object) aVZ = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
964 Handle(GEOM_Object) aVXZ = myBasicOperations->MakeVectorDXDYDZ(aR1Ext, 0, 0.5*(theL1+theVertCylinderRadius));
965 Handle(GEOM_Object) aPlnOZ = myBasicOperations->MakePlanePntVec(aP0, aVZ, aSize);
966 Handle(GEOM_Object) aPlnOXZ = myBasicOperations->MakePlanePntVec(aP0, aVXZ, aSize);
967 aP0->GetLastFunction()->SetDescription("");
968 aVZ->GetLastFunction()->SetDescription("");
969 aVXZ->GetLastFunction()->SetDescription("");
970 aPlnOZ->GetLastFunction()->SetDescription("");
971 aPlnOXZ->GetLastFunction()->SetDescription("");
972 theShapes.push_back(aPlnOZ);
973 theShapes.push_back(aPlnOXZ);
976 Handle(TColStd_HSequenceOfTransient) partitionShapes = new TColStd_HSequenceOfTransient;
977 Handle(TColStd_HSequenceOfTransient) theTools = new TColStd_HSequenceOfTransient;
978 Handle(TColStd_HSequenceOfTransient) theKeepInside = new TColStd_HSequenceOfTransient;
979 Handle(TColStd_HSequenceOfTransient) theRemoveInside = new TColStd_HSequenceOfTransient;
980 Handle(TColStd_HArray1OfInteger) theMaterials;
981 partitionShapes->Append(theShape);
982 theTools->Append(aPlnOZ);
983 if (Abs(aR1Ext - aR2Ext) > Precision::Confusion() )
984 theTools->Append(aPlnOXZ);
985 theTools->Append(face_t);
987 theTools->Append(face_t2);
989 Handle(GEOM_Object) Te3 = myBooleanOperations->MakePartition(partitionShapes, theTools, theKeepInside, theRemoveInside, TopAbs_SOLID, false, theMaterials, 0, false);
991 SetErrorCode("Impossible to build partition of TShape");
992 // Handle(GEOM_Object) aCompound = myShapesOperations->MakeCompound(theShapes);
993 // TopoDS_Shape aCompoundShape = aCompound->GetValue();
994 // theShape->GetLastFunction()->SetValue(aCompoundShape);
997 Te3->GetLastFunction()->SetDescription("");
1000 TopoDS_Shape aShape = Te3->GetValue();
1001 theShape->GetLastFunction()->SetValue(aShape);
1007 // Mirror and glue faces
1008 bool GEOMImpl_IAdvancedOperations::MakePipeTShapeMirrorAndGlue(Handle(GEOM_Object) theShape,
1009 double theR1, double theW1, double theL1,
1010 double theR2, double theW2, double theL2)
1015 double aSize = 2*(theL1 + theL2);
1016 double aR1Ext = theR1 + theW1;
1019 Handle(GEOM_Object) aP0 = myBasicOperations->MakePointXYZ(0, 0, 0);
1020 aP0->GetLastFunction()->SetDescription("");
1021 Handle(GEOM_Object) aVX = myBasicOperations->MakeVectorDXDYDZ(1, 0, 0);
1022 Handle(GEOM_Object) aVY = myBasicOperations->MakeVectorDXDYDZ(0, 1, 0);
1023 aVX->GetLastFunction()->SetDescription("");
1024 aVY->GetLastFunction()->SetDescription("");
1025 Handle(GEOM_Object) aPlane_OX = myBasicOperations->MakePlanePntVec(aP0, aVX, 2*(aR1Ext + theL2));
1026 Handle(GEOM_Object) aPlane_OY = myBasicOperations->MakePlanePntVec(aP0, aVY, aSize);
1027 aPlane_OX->GetLastFunction()->SetDescription("");
1028 aPlane_OY->GetLastFunction()->SetDescription("");
1030 Handle(GEOM_Object) Te4 = myTransformOperations->MirrorPlaneCopy(theShape, aPlane_OX);
1032 SetErrorCode("Impossible to build mirror of quarter TShape");
1036 Handle(GEOM_Object) Te5 = myTransformOperations->MirrorPlaneCopy(theShape, aPlane_OY);
1038 SetErrorCode("Impossible to build mirror of half TShape");
1042 Handle(GEOM_Object) Te6 = myTransformOperations->MirrorPlaneCopy(Te4, aPlane_OY);
1044 SetErrorCode("Impossible to build mirror of half TShape");
1048 std::list<Handle(GEOM_Object)> aShapesList;
1049 aShapesList.push_back(theShape);
1050 aShapesList.push_back(Te4);
1051 aShapesList.push_back(Te5);
1052 aShapesList.push_back(Te6);
1053 Handle(GEOM_Object) Te7 = myShapesOperations->MakeCompound(aShapesList);
1055 SetErrorCode("Impossible to build compound");
1059 Handle(GEOM_Object) Te8 = myShapesOperations->MakeGlueFaces(Te7, 1e-7, true);
1061 SetErrorCode("Impossible to glue faces of TShape");
1065 TopoDS_Shape aShape = Te8->GetValue();
1067 theShape->GetLastFunction()->SetValue(aShape);
1069 Te4->GetLastFunction()->SetDescription("");
1070 Te5->GetLastFunction()->SetDescription("");
1071 Te6->GetLastFunction()->SetDescription("");
1072 Te7->GetLastFunction()->SetDescription("");
1073 Te8->GetLastFunction()->SetDescription("");
1079 //=============================================================================
1082 * Create a T-shape object with specified caracteristics for the main and
1083 * the incident pipes (radius, width, half-length).
1084 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1085 * \param theR1 Internal radius of main pipe
1086 * \param theW1 Width of main pipe
1087 * \param theL1 Half-length of main pipe
1088 * \param theR2 Internal radius of incident pipe (R2 < R1)
1089 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1090 * \param theL2 Half-length of incident pipe
1091 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1092 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1094 //=============================================================================
1095 Handle(TColStd_HSequenceOfTransient)
1096 GEOMImpl_IAdvancedOperations::MakePipeTShape(double theR1, double theW1, double theL1,
1097 double theR2, double theW2, double theL2,
1100 MESSAGE("GEOMImpl_IAdvancedOperations::MakePipeTShape");
1103 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1105 //Add a new shape function with parameters
1106 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_BASIC);
1107 if (aFunction.IsNull()) return NULL;
1109 //Check if the function is set correctly
1110 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1112 GEOMImpl_IPipeTShape aData(aFunction);
1120 aData.SetHexMesh(theHexMesh);
1122 //Compute the resulting value
1124 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1127 if (!GetSolver()->ComputeFunction(aFunction)) {
1128 SetErrorCode("TShape driver failed");
1131 } catch (Standard_Failure) {
1132 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1133 SetErrorCode(aFail->GetMessageString());
1138 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1140 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1144 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1145 aSeq->Append(aShape);
1149 * Get the groups: BEGIN
1152 if (!MakeGroups(aShape, TSHAPE_BASIC, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1155 catch (Standard_Failure) {
1156 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1157 SetErrorCode(aFail->GetMessageString());
1161 TCollection_AsciiString aListRes, anEntry;
1162 // Iterate over the sequence aSeq
1163 Standard_Integer aNbGroups = aSeq->Length();
1164 Standard_Integer i = 2;
1165 for (; i <= aNbGroups; i++) {
1166 Handle(Standard_Transient) anItem = aSeq->Value(i);
1167 if (anItem.IsNull()) continue;
1168 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1169 if (aGroup.IsNull()) continue;
1170 //Make a Python command
1171 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1172 aListRes += anEntry + ", ";
1175 aListRes.Trunc(aListRes.Length() - 2);
1177 //Make a Python command
1178 GEOM::TPythonDump(aFunction) << "[" << aShape << ", " << aListRes.ToCString() << "] = geompy.MakePipeTShape("
1179 << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", "
1180 << theHexMesh << ")";
1183 * Get the groups: END
1186 //Make a Python command
1187 GEOM::TPythonDump(aFunction) << "[" << aShape << "] = geompy.MakePipeTShape(" << theR1 << ", " << theW1 << ", "
1188 << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theHexMesh << ")";
1196 //=============================================================================
1198 * MakePipeTShapeWithPosition
1199 * Create a T-shape object with specified caracteristics for the main and
1200 * the incident pipes (radius, width, half-length).
1201 * The extremities of the main pipe are located on junctions points P1 and P2.
1202 * The extremity of the incident pipe is located on junction point P3.
1203 * \param theR1 Internal radius of main pipe
1204 * \param theW1 Width of main pipe
1205 * \param theL1 Half-length of main pipe
1206 * \param theR2 Internal radius of incident pipe (R2 < R1)
1207 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1208 * \param theL2 Half-length of incident pipe
1209 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1210 * \param theP1 1st junction point of main pipe
1211 * \param theP2 2nd junction point of main pipe
1212 * \param theP3 Junction point of incident pipe
1213 * \return List of GEOM_Objects, containing the created shape and propagation groups..
1215 //=============================================================================
1216 Handle(TColStd_HSequenceOfTransient)
1217 GEOMImpl_IAdvancedOperations::MakePipeTShapeWithPosition(double theR1, double theW1, double theL1,
1218 double theR2, double theW2, double theL2,
1220 Handle(GEOM_Object) theP1,
1221 Handle(GEOM_Object) theP2,
1222 Handle(GEOM_Object) theP3)
1226 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1230 //Add a new shape function with parameters
1231 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_BASIC);
1232 if (aFunction.IsNull()) return NULL;
1234 //Check if the function is set correctly
1235 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1237 // Check new position
1238 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1242 GEOMImpl_IPipeTShape aData(aFunction);
1250 aData.SetHexMesh(theHexMesh);
1252 //Compute the resulting value
1254 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1257 if (!GetSolver()->ComputeFunction(aFunction)) {
1258 SetErrorCode("TShape driver failed");
1261 } catch (Standard_Failure) {
1262 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1263 SetErrorCode(aFail->GetMessageString());
1268 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1270 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1274 TopoDS_Shape Te = aShape->GetValue();
1277 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
1278 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
1279 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
1280 aFunction->SetValue(aTrsf_Shape);
1281 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1282 aSeq->Append(aShape);
1286 // Get the groups: BEGIN
1289 if (!MakeGroups(aShape,TSHAPE_BASIC, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf)) {
1293 catch (Standard_Failure) {
1294 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1295 SetErrorCode(aFail->GetMessageString());
1299 TCollection_AsciiString aListRes, anEntry;
1300 // Iterate over the sequence aSeq
1301 Standard_Integer aNbGroups = aSeq->Length();
1302 Standard_Integer i = 2;
1303 for (; i <= aNbGroups; i++) {
1304 Handle(Standard_Transient) anItem = aSeq->Value(i);
1305 if (anItem.IsNull()) continue;
1306 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1307 if (aGroup.IsNull()) continue;
1308 //Make a Python command
1309 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1310 aListRes += anEntry + ", ";
1313 aListRes.Trunc(aListRes.Length() - 2);
1315 //Make a Python command
1316 GEOM::TPythonDump(aFunction) << "[" << aShape << ", " << aListRes.ToCString() << "] = geompy.MakePipeTShape("
1317 << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", "
1318 << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
1321 // Get the groups: END
1325 //Make a Python command
1326 GEOM::TPythonDump(aFunction) << "[" << aShape << "] = geompy.MakePipeTShape(" << theR1 << ", " << theW1 << ", "
1327 << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theHexMesh << ", " << theP1
1328 << ", " << theP2 << ", " << theP3 << ")";
1336 //=============================================================================
1338 * MakePipeTShapeChamfer
1339 * Create a T-shape object with specified caracteristics for the main and
1340 * the incident pipes (radius, width, half-length). A chamfer is created
1341 * on the junction of the pipes.
1342 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1343 * \param theR1 Internal radius of main pipe
1344 * \param theW1 Width of main pipe
1345 * \param theL1 Half-length of main pipe
1346 * \param theR2 Internal radius of incident pipe (R2 < R1)
1347 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1348 * \param theL2 Half-length of incident pipe
1349 * \param theH Height of chamfer.
1350 * \param theW Width of chamfer.
1351 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1352 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1354 //=============================================================================
1355 Handle(TColStd_HSequenceOfTransient)
1356 GEOMImpl_IAdvancedOperations::MakePipeTShapeChamfer(double theR1, double theW1, double theL1,
1357 double theR2, double theW2, double theL2,
1358 double theH, double theW,
1363 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1364 //Add a new shape function with parameters
1365 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_CHAMFER);
1366 if (aFunction.IsNull()) return NULL;
1368 //Check if the function is set correctly
1369 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1371 GEOMImpl_IPipeTShape aData(aFunction);
1381 aData.SetHexMesh(theHexMesh);
1383 //Compute the resulting value
1385 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1388 if (!GetSolver()->ComputeFunction(aFunction)) {
1389 SetErrorCode("TShape driver failed");
1392 } catch (Standard_Failure) {
1393 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1394 SetErrorCode(aFail->GetMessageString());
1399 TopoDS_Shape aShapeShape = aShape->GetValue();
1400 TopTools_IndexedMapOfShape anEdgesIndices;
1401 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1402 // Common edges on external cylinders
1403 Handle(GEOM_Object) box_e;
1405 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1408 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1410 box_e->GetLastFunction()->SetDescription("");
1411 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1412 box_e->GetLastFunction()->SetDescription("");
1414 Handle(TColStd_HSequenceOfInteger) edges_e = myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1415 box_e->GetLastFunction()->SetDescription("");
1417 if (edges_e.IsNull() || edges_e->Length() == 0) {
1418 SetErrorCode("External edges not found");
1421 int nbEdgesInChamfer = 0;
1422 std::list<int> theEdges;
1423 for (int i=1; i<=edges_e->Length();i++) {
1424 int edgeID = edges_e->Value(i);
1425 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1426 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1430 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1431 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1432 nbEdgesInChamfer ++;
1433 theEdges.push_back(edgeID);
1437 if (theHexMesh && nbEdgesInChamfer == 1)
1440 Handle(GEOM_Object) aChamfer;
1442 aChamfer = myLocalOperations->MakeChamferEdges(aShape, theW, theH, theEdges);
1444 catch (Standard_Failure) {
1445 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1446 SetErrorCode(aFail->GetMessageString());
1449 if (aChamfer.IsNull()) {
1450 SetErrorCode("Chamfer can not be computed on the given shape with the given parameters");
1453 aChamfer->GetLastFunction()->SetDescription("");
1455 TopoDS_Shape aChamferShape = aChamfer->GetValue();
1456 aFunction->SetValue(aChamferShape);
1459 // bool doMesh = false;
1462 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, 0, false)) {
1463 MESSAGE("PipeTShape partition failed");
1467 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2)) {
1468 MESSAGE("PipeTShape mirrors and glue failed");
1474 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1475 aSeq->Append(aShape);
1480 // Get the groups: BEGIN
1482 // if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf())) {
1483 // //Make a Python command
1484 // GEOM::TPythonDump(aFunction) << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1485 // << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1486 // << ", " << theHexMesh << ")";
1490 if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1493 catch (Standard_Failure) {
1494 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1495 SetErrorCode(aFail->GetMessageString());
1499 TCollection_AsciiString aListRes, anEntry;
1500 // Iterate over the sequence aSeq
1501 Standard_Integer aNbGroups = aSeq->Length();
1502 Standard_Integer i = 2;
1503 for (; i <= aNbGroups; i++) {
1504 Handle(Standard_Transient) anItem = aSeq->Value(i);
1505 if (anItem.IsNull()) continue;
1506 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1507 if (aGroup.IsNull()) continue;
1508 //Make a Python command
1509 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1510 aListRes += anEntry + ", ";
1513 aListRes.Trunc(aListRes.Length() - 2);
1515 //Make a Python command
1516 GEOM::TPythonDump(aFunction) << "[" << aShape << ", " << aListRes.ToCString()
1517 << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1518 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW << ", " << theHexMesh << ")";
1522 // Get the groups: END
1525 //Make a Python command
1526 GEOM::TPythonDump(aFunction) << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1527 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1528 << ", " << theHexMesh << ")";
1536 //=============================================================================
1538 * MakePipeTShapeChamferWithPosition
1539 * Create a T-shape object with specified caracteristics for the main and
1540 * the incident pipes (radius, width, half-length). A chamfer is created
1541 * on the junction of the pipes.
1542 * The extremities of the main pipe are located on junctions points P1 and P2.
1543 * The extremity of the incident pipe is located on junction point P3.
1544 * \param theR1 Internal radius of main pipe
1545 * \param theW1 Width of main pipe
1546 * \param theL1 Half-length of main pipe
1547 * \param theR2 Internal radius of incident pipe (R2 < R1)
1548 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1549 * \param theL2 Half-length of incident pipe
1550 * \param theH Height of chamfer.
1551 * \param theW Width of chamfer.
1552 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1553 * \param theP1 1st junction point of main pipe
1554 * \param theP2 2nd junction point of main pipe
1555 * \param theP3 Junction point of incident pipe
1556 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1558 //=============================================================================
1559 Handle(TColStd_HSequenceOfTransient)
1560 GEOMImpl_IAdvancedOperations::MakePipeTShapeChamferWithPosition(double theR1, double theW1, double theL1,
1561 double theR2, double theW2, double theL2,
1562 double theH, double theW,
1564 Handle(GEOM_Object) theP1,
1565 Handle(GEOM_Object) theP2,
1566 Handle(GEOM_Object) theP3)
1570 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1571 //Add a new shape function with parameters
1572 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_CHAMFER);
1573 if (aFunction.IsNull()) return NULL;
1575 //Check if the function is set correctly
1576 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1578 // Check new position
1579 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1583 GEOMImpl_IPipeTShape aData(aFunction);
1593 aData.SetHexMesh(theHexMesh);
1595 //Compute the resulting value
1597 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1600 if (!GetSolver()->ComputeFunction(aFunction)) {
1601 SetErrorCode("TShape driver failed");
1604 } catch (Standard_Failure) {
1605 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1606 SetErrorCode(aFail->GetMessageString());
1611 TopoDS_Shape aShapeShape = aShape->GetValue();
1612 TopTools_IndexedMapOfShape anEdgesIndices;
1613 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1614 // Common edges on external cylinders
1615 Handle(GEOM_Object) box_e;
1617 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1620 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1622 box_e->GetLastFunction()->SetDescription("");
1623 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1624 box_e->GetLastFunction()->SetDescription("");
1626 Handle(TColStd_HSequenceOfInteger) edges_e = myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1627 box_e->GetLastFunction()->SetDescription("");
1629 if (edges_e.IsNull() || edges_e->Length() == 0) {
1630 SetErrorCode("External edges not found");
1633 int nbEdgesInChamfer = 0;
1634 std::list<int> theEdges;
1635 for (int i=1; i<=edges_e->Length();i++) {
1636 int edgeID = edges_e->Value(i);
1637 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1638 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1640 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1641 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1642 nbEdgesInChamfer ++;
1643 theEdges.push_back(edgeID);
1647 if (theHexMesh && nbEdgesInChamfer == 1)
1650 Handle(GEOM_Object) aChamfer;
1652 aChamfer = myLocalOperations->MakeChamferEdges(aShape, theW, theH, theEdges);
1654 catch (Standard_Failure) {
1655 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1656 SetErrorCode(aFail->GetMessageString());
1659 if (aChamfer.IsNull()) {
1660 SetErrorCode("Chamfer can not be computed on the given shape with the given parameters");
1663 aChamfer->GetLastFunction()->SetDescription("");
1665 TopoDS_Shape aChamferShape = aChamfer->GetValue();
1666 aFunction->SetValue(aChamferShape);
1670 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, 0, false))
1672 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1676 TopoDS_Shape Te = aShape->GetValue();
1679 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
1680 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
1681 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
1682 aFunction->SetValue(aTrsf_Shape);
1683 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1684 aSeq->Append(aShape);
1687 * Get the groups: BEGIN
1690 if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf))
1693 catch (Standard_Failure) {
1694 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1695 SetErrorCode(aFail->GetMessageString());
1699 TCollection_AsciiString aListRes, anEntry;
1700 // Iterate over the sequence aSeq
1701 Standard_Integer aNbGroups = aSeq->Length();
1702 Standard_Integer i = 2;
1703 for (; i <= aNbGroups; i++) {
1704 Handle(Standard_Transient) anItem = aSeq->Value(i);
1705 if (anItem.IsNull()) continue;
1706 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1707 if (aGroup.IsNull()) continue;
1708 //Make a Python command
1709 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1710 aListRes += anEntry + ", ";
1713 aListRes.Trunc(aListRes.Length() - 2);
1715 //Make a Python command
1716 GEOM::TPythonDump(aFunction) << "[" << aShape << ", " << aListRes.ToCString()
1717 << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1718 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW << ", " << theHexMesh << ", "
1719 << theP1 << ", " << theP2 << ", " << theP3 << ")";
1722 * Get the groups: END
1725 //Make a Python command
1726 GEOM::TPythonDump(aFunction) << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1727 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1728 << ", " << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
1736 //=============================================================================
1738 * MakePipeTShapeFillet
1739 * Create a T-shape object with specified caracteristics for the main and
1740 * the incident pipes (radius, width, half-length). A fillet is created
1741 * on the junction of the pipes.
1742 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1743 * \param theR1 Internal radius of main pipe
1744 * \param theW1 Width of main pipe
1745 * \param theL1 Half-length of main pipe
1746 * \param theR2 Internal radius of incident pipe (R2 < R1)
1747 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1748 * \param theL2 Half-length of incident pipe
1749 * \param theRF Radius of curvature of fillet.
1750 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1751 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1753 //=============================================================================
1754 Handle(TColStd_HSequenceOfTransient)
1755 GEOMImpl_IAdvancedOperations::MakePipeTShapeFillet(double theR1, double theW1, double theL1,
1756 double theR2, double theW2, double theL2,
1757 double theRF, bool theHexMesh)
1761 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1762 //Add a new shape function with parameters
1763 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_FILLET);
1764 if (aFunction.IsNull()) return NULL;
1766 //Check if the function is set correctly
1767 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1769 GEOMImpl_IPipeTShape aData(aFunction);
1778 aData.SetHexMesh(theHexMesh);
1780 //Compute the resulting value
1782 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1785 if (!GetSolver()->ComputeFunction(aFunction)) {
1786 SetErrorCode("TShape driver failed");
1789 } catch (Standard_Failure) {
1790 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1791 SetErrorCode(aFail->GetMessageString());
1796 TopoDS_Shape aShapeShape = aShape->GetValue();
1797 TopTools_IndexedMapOfShape anEdgesIndices;
1798 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1799 // Common edges on external cylinders
1800 Handle(GEOM_Object) box_e;
1802 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1805 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1807 box_e->GetLastFunction()->SetDescription("");
1808 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1809 box_e->GetLastFunction()->SetDescription("");
1811 Handle(TColStd_HSequenceOfInteger) edges_e = myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1812 box_e->GetLastFunction()->SetDescription("");
1814 if (edges_e.IsNull() || edges_e->Length() == 0) {
1815 SetErrorCode("External edges not found");
1818 int nbEdgesInFillet = 0;
1819 std::list<int> theEdges;
1820 for (int i=1; i<=edges_e->Length();i++) {
1821 int edgeID = edges_e->Value(i);
1822 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1823 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1825 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1826 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1828 theEdges.push_back(edgeID);
1832 if (theHexMesh && nbEdgesInFillet == 1)
1836 Handle(GEOM_Object) aFillet;
1838 aFillet = myLocalOperations->MakeFilletEdges(aShape, theRF, theEdges);
1840 catch (Standard_Failure) {
1841 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1842 SetErrorCode(aFail->GetMessageString());
1845 if (aFillet.IsNull()) {
1846 SetErrorCode("Fillet can not be computed on the given shape with the given parameters");
1849 aFillet->GetLastFunction()->SetDescription("");
1851 TopoDS_Shape aFilletShape = aFillet->GetValue();
1852 aFunction->SetValue(aFilletShape);
1856 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, 0, 0, theRF, false))
1858 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1862 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1863 aSeq->Append(aShape);
1866 * Get the groups: BEGIN
1869 if (!MakeGroups(aShape, TSHAPE_FILLET, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1872 catch (Standard_Failure) {
1873 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1874 SetErrorCode(aFail->GetMessageString());
1878 TCollection_AsciiString aListRes, anEntry;
1879 // Iterate over the sequence aSeq
1880 Standard_Integer aNbGroups = aSeq->Length();
1881 Standard_Integer i = 2;
1882 for (; i <= aNbGroups; i++) {
1883 Handle(Standard_Transient) anItem = aSeq->Value(i);
1884 if (anItem.IsNull()) continue;
1885 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1886 if (aGroup.IsNull()) continue;
1887 //Make a Python command
1888 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1889 aListRes += anEntry + ", ";
1892 aListRes.Trunc(aListRes.Length() - 2);
1894 //Make a Python command
1895 GEOM::TPythonDump(aFunction) << "[" << aShape << ", " << aListRes.ToCString()
1896 << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1897 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", " << theHexMesh << ")";
1900 * Get the groups: END
1903 //Make a Python command
1904 GEOM::TPythonDump(aFunction) << "[" << aShape << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1
1905 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", "
1906 << theHexMesh << ")";
1916 //=============================================================================
1918 * MakePipeTShapeFilletWithPosition
1919 * Create a T-shape object with specified caracteristics for the main and
1920 * the incident pipes (radius, width, half-length). A fillet is created
1921 * on the junction of the pipes.
1922 * The extremities of the main pipe are located on junctions points P1 and P2.
1923 * The extremity of the incident pipe is located on junction point P3.
1924 * \param theR1 Internal radius of main pipe
1925 * \param theW1 Width of main pipe
1926 * \param theL1 Half-length of main pipe
1927 * \param theR2 Internal radius of incident pipe (R2 < R1)
1928 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1929 * \param theL2 Half-length of incident pipe
1930 * \param theRF Radius of curvature of fillet
1931 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1932 * \param theP1 1st junction point of main pipe
1933 * \param theP2 2nd junction point of main pipe
1934 * \param theP3 Junction point of incident pipe
1935 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1937 //=============================================================================
1938 Handle(TColStd_HSequenceOfTransient)
1939 GEOMImpl_IAdvancedOperations::MakePipeTShapeFilletWithPosition(double theR1, double theW1, double theL1,
1940 double theR2, double theW2, double theL2,
1941 double theRF, bool theHexMesh,
1942 Handle(GEOM_Object) theP1,
1943 Handle(GEOM_Object) theP2,
1944 Handle(GEOM_Object) theP3)
1948 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1949 //Add a new shape function with parameters
1950 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_FILLET);
1951 if (aFunction.IsNull()) return NULL;
1953 //Check if the function is set correctly
1954 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1956 // Check new position
1957 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1961 GEOMImpl_IPipeTShape aData(aFunction);
1970 aData.SetHexMesh(theHexMesh);
1972 //Compute the resulting value
1974 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1977 if (!GetSolver()->ComputeFunction(aFunction)) {
1978 SetErrorCode("TShape driver failed");
1981 } catch (Standard_Failure) {
1982 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1983 SetErrorCode(aFail->GetMessageString());
1988 TopoDS_Shape aShapeShape = aShape->GetValue();
1989 TopTools_IndexedMapOfShape anEdgesIndices;
1990 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1991 // Common edges on external cylinders
1992 Handle(GEOM_Object) box_e;
1994 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1997 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1999 box_e->GetLastFunction()->SetDescription("");
2000 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
2001 box_e->GetLastFunction()->SetDescription("");
2003 Handle(TColStd_HSequenceOfInteger) edges_e = myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
2004 box_e->GetLastFunction()->SetDescription("");
2006 if (edges_e.IsNull() || edges_e->Length() == 0) {
2007 SetErrorCode("External edges not found");
2010 int nbEdgesInFillet = 0;
2011 std::list<int> theEdges;
2012 for (int i=1; i<=edges_e->Length();i++) {
2013 int edgeID = edges_e->Value(i);
2014 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
2015 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
2017 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
2018 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
2020 theEdges.push_back(edgeID);
2024 if (theHexMesh && nbEdgesInFillet == 1)
2028 Handle(GEOM_Object) aFillet;
2030 aFillet = myLocalOperations->MakeFilletEdges(aShape, theRF, theEdges);
2032 catch (Standard_Failure) {
2033 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2034 SetErrorCode(aFail->GetMessageString());
2037 if (aFillet.IsNull()) {
2038 SetErrorCode("Fillet can not be computed on the given shape with the given parameters");
2041 aFillet->GetLastFunction()->SetDescription("");
2043 TopoDS_Shape aFilletShape = aFillet->GetValue();
2044 aFunction->SetValue(aFilletShape);
2048 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, 0, 0, theRF, false))
2050 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
2054 TopoDS_Shape Te = aShape->GetValue();
2057 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
2058 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
2059 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
2060 aFunction->SetValue(aTrsf_Shape);
2061 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
2062 aSeq->Append(aShape);
2065 * Get the groups: BEGIN
2068 if (!MakeGroups(aShape, TSHAPE_FILLET, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf))
2071 catch (Standard_Failure) {
2072 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2073 SetErrorCode(aFail->GetMessageString());
2077 TCollection_AsciiString aListRes, anEntry;
2078 // Iterate over the sequence aSeq
2079 Standard_Integer aNbGroups = aSeq->Length();
2080 Standard_Integer i = 2;
2081 for (; i <= aNbGroups; i++) {
2082 Handle(Standard_Transient) anItem = aSeq->Value(i);
2083 if (anItem.IsNull()) continue;
2084 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
2085 if (aGroup.IsNull()) continue;
2086 //Make a Python command
2087 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
2088 aListRes += anEntry + ", ";
2091 aListRes.Trunc(aListRes.Length() - 2);
2093 //Make a Python command
2094 GEOM::TPythonDump(aFunction) << "[" << aShape << ", " << aListRes.ToCString()
2095 << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
2096 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", " << theHexMesh << ", " << theP1 << ", "
2097 << theP2 << ", " << theP3 << ")";
2100 * Get the groups: END
2103 //Make a Python command
2104 GEOM::TPythonDump(aFunction) << "[" << aShape << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1
2105 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", "
2106 << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
2114 /*@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@*/