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("");
999 // Last verification: result should be a block
1000 std::list<GEOMImpl_IBlocksOperations::BCError> errList;
1001 if (!myBlocksOperations->CheckCompoundOfBlocks(Te3,errList)) {
1002 SetErrorCode("TShape is not a block");
1005 TopoDS_Shape aShape = Te3->GetValue();
1006 theShape->GetLastFunction()->SetValue(aShape);
1012 // Mirror and glue faces
1013 bool GEOMImpl_IAdvancedOperations::MakePipeTShapeMirrorAndGlue(Handle(GEOM_Object) theShape,
1014 double theR1, double theW1, double theL1,
1015 double theR2, double theW2, double theL2)
1020 double aSize = 2*(theL1 + theL2);
1021 double aR1Ext = theR1 + theW1;
1024 Handle(GEOM_Object) aP0 = myBasicOperations->MakePointXYZ(0, 0, 0);
1025 aP0->GetLastFunction()->SetDescription("");
1026 Handle(GEOM_Object) aVX = myBasicOperations->MakeVectorDXDYDZ(1, 0, 0);
1027 Handle(GEOM_Object) aVY = myBasicOperations->MakeVectorDXDYDZ(0, 1, 0);
1028 aVX->GetLastFunction()->SetDescription("");
1029 aVY->GetLastFunction()->SetDescription("");
1030 Handle(GEOM_Object) aPlane_OX = myBasicOperations->MakePlanePntVec(aP0, aVX, 2*(aR1Ext + theL2));
1031 Handle(GEOM_Object) aPlane_OY = myBasicOperations->MakePlanePntVec(aP0, aVY, aSize);
1032 aPlane_OX->GetLastFunction()->SetDescription("");
1033 aPlane_OY->GetLastFunction()->SetDescription("");
1035 Handle(GEOM_Object) Te4 = myTransformOperations->MirrorPlaneCopy(theShape, aPlane_OX);
1037 SetErrorCode("Impossible to build mirror of quarter TShape");
1041 Handle(GEOM_Object) Te5 = myTransformOperations->MirrorPlaneCopy(theShape, aPlane_OY);
1043 SetErrorCode("Impossible to build mirror of half TShape");
1047 Handle(GEOM_Object) Te6 = myTransformOperations->MirrorPlaneCopy(Te4, aPlane_OY);
1049 SetErrorCode("Impossible to build mirror of half TShape");
1053 std::list<Handle(GEOM_Object)> aShapesList;
1054 aShapesList.push_back(theShape);
1055 aShapesList.push_back(Te4);
1056 aShapesList.push_back(Te5);
1057 aShapesList.push_back(Te6);
1058 Handle(GEOM_Object) Te7 = myShapesOperations->MakeCompound(aShapesList);
1060 SetErrorCode("Impossible to build compound");
1064 Handle(GEOM_Object) Te8 = myShapesOperations->MakeGlueFaces(Te7, 1e-7, true);
1066 SetErrorCode("Impossible to glue faces of TShape");
1070 TopoDS_Shape aShape = Te8->GetValue();
1072 theShape->GetLastFunction()->SetValue(aShape);
1074 Te4->GetLastFunction()->SetDescription("");
1075 Te5->GetLastFunction()->SetDescription("");
1076 Te6->GetLastFunction()->SetDescription("");
1077 Te7->GetLastFunction()->SetDescription("");
1078 Te8->GetLastFunction()->SetDescription("");
1084 //=============================================================================
1087 * Create a T-shape object with specified caracteristics for the main and
1088 * the incident pipes (radius, width, half-length).
1089 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1090 * \param theR1 Internal radius of main pipe
1091 * \param theW1 Width of main pipe
1092 * \param theL1 Half-length of main pipe
1093 * \param theR2 Internal radius of incident pipe (R2 < R1)
1094 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1095 * \param theL2 Half-length of incident pipe
1096 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1097 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1099 //=============================================================================
1100 Handle(TColStd_HSequenceOfTransient)
1101 GEOMImpl_IAdvancedOperations::MakePipeTShape(double theR1, double theW1, double theL1,
1102 double theR2, double theW2, double theL2,
1105 MESSAGE("GEOMImpl_IAdvancedOperations::MakePipeTShape");
1108 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1110 //Add a new shape function with parameters
1111 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_BASIC);
1112 if (aFunction.IsNull()) return NULL;
1114 //Check if the function is set correctly
1115 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1117 GEOMImpl_IPipeTShape aData(aFunction);
1125 aData.SetHexMesh(theHexMesh);
1127 //Compute the resulting value
1129 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1132 if (!GetSolver()->ComputeFunction(aFunction)) {
1133 SetErrorCode("TShape driver failed");
1136 } catch (Standard_Failure) {
1137 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1138 SetErrorCode(aFail->GetMessageString());
1143 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1145 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1149 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1150 aSeq->Append(aShape);
1154 * Get the groups: BEGIN
1157 if (!MakeGroups(aShape, TSHAPE_BASIC, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1160 catch (Standard_Failure) {
1161 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1162 SetErrorCode(aFail->GetMessageString());
1166 TCollection_AsciiString aListRes, anEntry;
1167 // Iterate over the sequence aSeq
1168 Standard_Integer aNbGroups = aSeq->Length();
1169 Standard_Integer i = 2;
1170 for (; i <= aNbGroups; i++) {
1171 Handle(Standard_Transient) anItem = aSeq->Value(i);
1172 if (anItem.IsNull()) continue;
1173 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1174 if (aGroup.IsNull()) continue;
1175 //Make a Python command
1176 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1177 aListRes += anEntry + ", ";
1180 aListRes.Trunc(aListRes.Length() - 2);
1182 //Make a Python command
1183 GEOM::TPythonDump(aFunction) << "[" << aShape << ", " << aListRes.ToCString() << "] = geompy.MakePipeTShape("
1184 << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", "
1185 << theHexMesh << ")";
1188 * Get the groups: END
1191 //Make a Python command
1192 GEOM::TPythonDump(aFunction) << "[" << aShape << "] = geompy.MakePipeTShape(" << theR1 << ", " << theW1 << ", "
1193 << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theHexMesh << ")";
1201 //=============================================================================
1203 * MakePipeTShapeWithPosition
1204 * Create a T-shape object with specified caracteristics for the main and
1205 * the incident pipes (radius, width, half-length).
1206 * The extremities of the main pipe are located on junctions points P1 and P2.
1207 * The extremity of the incident pipe is located on junction point P3.
1208 * \param theR1 Internal radius of main pipe
1209 * \param theW1 Width of main pipe
1210 * \param theL1 Half-length of main pipe
1211 * \param theR2 Internal radius of incident pipe (R2 < R1)
1212 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1213 * \param theL2 Half-length of incident pipe
1214 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1215 * \param theP1 1st junction point of main pipe
1216 * \param theP2 2nd junction point of main pipe
1217 * \param theP3 Junction point of incident pipe
1218 * \return List of GEOM_Objects, containing the created shape and propagation groups..
1220 //=============================================================================
1221 Handle(TColStd_HSequenceOfTransient)
1222 GEOMImpl_IAdvancedOperations::MakePipeTShapeWithPosition(double theR1, double theW1, double theL1,
1223 double theR2, double theW2, double theL2,
1225 Handle(GEOM_Object) theP1,
1226 Handle(GEOM_Object) theP2,
1227 Handle(GEOM_Object) theP3)
1231 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1235 //Add a new shape function with parameters
1236 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_BASIC);
1237 if (aFunction.IsNull()) return NULL;
1239 //Check if the function is set correctly
1240 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1242 // Check new position
1243 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1247 GEOMImpl_IPipeTShape aData(aFunction);
1255 aData.SetHexMesh(theHexMesh);
1257 //Compute the resulting value
1259 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1262 if (!GetSolver()->ComputeFunction(aFunction)) {
1263 SetErrorCode("TShape driver failed");
1266 } catch (Standard_Failure) {
1267 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1268 SetErrorCode(aFail->GetMessageString());
1273 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1275 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1279 TopoDS_Shape Te = aShape->GetValue();
1282 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
1283 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
1284 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
1285 aFunction->SetValue(aTrsf_Shape);
1286 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1287 aSeq->Append(aShape);
1291 // Get the groups: BEGIN
1294 if (!MakeGroups(aShape,TSHAPE_BASIC, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf)) {
1298 catch (Standard_Failure) {
1299 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1300 SetErrorCode(aFail->GetMessageString());
1304 TCollection_AsciiString aListRes, anEntry;
1305 // Iterate over the sequence aSeq
1306 Standard_Integer aNbGroups = aSeq->Length();
1307 Standard_Integer i = 2;
1308 for (; i <= aNbGroups; i++) {
1309 Handle(Standard_Transient) anItem = aSeq->Value(i);
1310 if (anItem.IsNull()) continue;
1311 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1312 if (aGroup.IsNull()) continue;
1313 //Make a Python command
1314 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1315 aListRes += anEntry + ", ";
1318 aListRes.Trunc(aListRes.Length() - 2);
1320 //Make a Python command
1321 GEOM::TPythonDump(aFunction) << "[" << aShape << ", " << aListRes.ToCString() << "] = geompy.MakePipeTShape("
1322 << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", "
1323 << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
1326 // Get the groups: END
1330 //Make a Python command
1331 GEOM::TPythonDump(aFunction) << "[" << aShape << "] = geompy.MakePipeTShape(" << theR1 << ", " << theW1 << ", "
1332 << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theHexMesh << ", " << theP1
1333 << ", " << theP2 << ", " << theP3 << ")";
1341 //=============================================================================
1343 * MakePipeTShapeChamfer
1344 * Create a T-shape object with specified caracteristics for the main and
1345 * the incident pipes (radius, width, half-length). A chamfer is created
1346 * on the junction of the pipes.
1347 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1348 * \param theR1 Internal radius of main pipe
1349 * \param theW1 Width of main pipe
1350 * \param theL1 Half-length of main pipe
1351 * \param theR2 Internal radius of incident pipe (R2 < R1)
1352 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1353 * \param theL2 Half-length of incident pipe
1354 * \param theH Height of chamfer.
1355 * \param theW Width of chamfer.
1356 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1357 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1359 //=============================================================================
1360 Handle(TColStd_HSequenceOfTransient)
1361 GEOMImpl_IAdvancedOperations::MakePipeTShapeChamfer(double theR1, double theW1, double theL1,
1362 double theR2, double theW2, double theL2,
1363 double theH, double theW,
1368 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1369 //Add a new shape function with parameters
1370 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_CHAMFER);
1371 if (aFunction.IsNull()) return NULL;
1373 //Check if the function is set correctly
1374 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1376 GEOMImpl_IPipeTShape aData(aFunction);
1386 aData.SetHexMesh(theHexMesh);
1388 //Compute the resulting value
1390 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1393 if (!GetSolver()->ComputeFunction(aFunction)) {
1394 SetErrorCode("TShape driver failed");
1397 } catch (Standard_Failure) {
1398 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1399 SetErrorCode(aFail->GetMessageString());
1404 TopoDS_Shape aShapeShape = aShape->GetValue();
1405 TopTools_IndexedMapOfShape anEdgesIndices;
1406 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1407 // Common edges on external cylinders
1408 Handle(GEOM_Object) box_e;
1410 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1413 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1415 box_e->GetLastFunction()->SetDescription("");
1416 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1417 box_e->GetLastFunction()->SetDescription("");
1419 Handle(TColStd_HSequenceOfInteger) edges_e = myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1420 box_e->GetLastFunction()->SetDescription("");
1422 if (edges_e.IsNull() || edges_e->Length() == 0) {
1423 SetErrorCode("External edges not found");
1426 int nbEdgesInChamfer = 0;
1427 std::list<int> theEdges;
1428 for (int i=1; i<=edges_e->Length();i++) {
1429 int edgeID = edges_e->Value(i);
1430 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1431 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1435 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1436 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1437 nbEdgesInChamfer ++;
1438 theEdges.push_back(edgeID);
1442 if (theHexMesh && nbEdgesInChamfer == 1)
1445 Handle(GEOM_Object) aChamfer;
1447 aChamfer = myLocalOperations->MakeChamferEdges(aShape, theW, theH, theEdges);
1449 catch (Standard_Failure) {
1450 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1451 SetErrorCode(aFail->GetMessageString());
1454 if (aChamfer.IsNull()) {
1455 SetErrorCode("Chamfer can not be computed on the given shape with the given parameters");
1458 aChamfer->GetLastFunction()->SetDescription("");
1460 TopoDS_Shape aChamferShape = aChamfer->GetValue();
1461 aFunction->SetValue(aChamferShape);
1464 // bool doMesh = false;
1467 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, 0, false)) {
1468 MESSAGE("PipeTShape partition failed");
1472 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2)) {
1473 MESSAGE("PipeTShape mirrors and glue failed");
1479 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1480 aSeq->Append(aShape);
1485 // Get the groups: BEGIN
1487 // if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf())) {
1488 // //Make a Python command
1489 // GEOM::TPythonDump(aFunction) << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1490 // << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1491 // << ", " << theHexMesh << ")";
1495 if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1498 catch (Standard_Failure) {
1499 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1500 SetErrorCode(aFail->GetMessageString());
1504 TCollection_AsciiString aListRes, anEntry;
1505 // Iterate over the sequence aSeq
1506 Standard_Integer aNbGroups = aSeq->Length();
1507 Standard_Integer i = 2;
1508 for (; i <= aNbGroups; i++) {
1509 Handle(Standard_Transient) anItem = aSeq->Value(i);
1510 if (anItem.IsNull()) continue;
1511 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1512 if (aGroup.IsNull()) continue;
1513 //Make a Python command
1514 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1515 aListRes += anEntry + ", ";
1518 aListRes.Trunc(aListRes.Length() - 2);
1520 //Make a Python command
1521 GEOM::TPythonDump(aFunction) << "[" << aShape << ", " << aListRes.ToCString()
1522 << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1523 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW << ", " << theHexMesh << ")";
1527 // Get the groups: END
1530 //Make a Python command
1531 GEOM::TPythonDump(aFunction) << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1532 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1533 << ", " << theHexMesh << ")";
1541 //=============================================================================
1543 * MakePipeTShapeChamferWithPosition
1544 * Create a T-shape object with specified caracteristics for the main and
1545 * the incident pipes (radius, width, half-length). A chamfer is created
1546 * on the junction of the pipes.
1547 * The extremities of the main pipe are located on junctions points P1 and P2.
1548 * The extremity of the incident pipe is located on junction point P3.
1549 * \param theR1 Internal radius of main pipe
1550 * \param theW1 Width of main pipe
1551 * \param theL1 Half-length of main pipe
1552 * \param theR2 Internal radius of incident pipe (R2 < R1)
1553 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1554 * \param theL2 Half-length of incident pipe
1555 * \param theH Height of chamfer.
1556 * \param theW Width of chamfer.
1557 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1558 * \param theP1 1st junction point of main pipe
1559 * \param theP2 2nd junction point of main pipe
1560 * \param theP3 Junction point of incident pipe
1561 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1563 //=============================================================================
1564 Handle(TColStd_HSequenceOfTransient)
1565 GEOMImpl_IAdvancedOperations::MakePipeTShapeChamferWithPosition(double theR1, double theW1, double theL1,
1566 double theR2, double theW2, double theL2,
1567 double theH, double theW,
1569 Handle(GEOM_Object) theP1,
1570 Handle(GEOM_Object) theP2,
1571 Handle(GEOM_Object) theP3)
1575 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1576 //Add a new shape function with parameters
1577 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_CHAMFER);
1578 if (aFunction.IsNull()) return NULL;
1580 //Check if the function is set correctly
1581 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1583 // Check new position
1584 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1588 GEOMImpl_IPipeTShape aData(aFunction);
1598 aData.SetHexMesh(theHexMesh);
1600 //Compute the resulting value
1602 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1605 if (!GetSolver()->ComputeFunction(aFunction)) {
1606 SetErrorCode("TShape driver failed");
1609 } catch (Standard_Failure) {
1610 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1611 SetErrorCode(aFail->GetMessageString());
1616 TopoDS_Shape aShapeShape = aShape->GetValue();
1617 TopTools_IndexedMapOfShape anEdgesIndices;
1618 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1619 // Common edges on external cylinders
1620 Handle(GEOM_Object) box_e;
1622 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1625 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1627 box_e->GetLastFunction()->SetDescription("");
1628 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1629 box_e->GetLastFunction()->SetDescription("");
1631 Handle(TColStd_HSequenceOfInteger) edges_e = myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1632 box_e->GetLastFunction()->SetDescription("");
1634 if (edges_e.IsNull() || edges_e->Length() == 0) {
1635 SetErrorCode("External edges not found");
1638 int nbEdgesInChamfer = 0;
1639 std::list<int> theEdges;
1640 for (int i=1; i<=edges_e->Length();i++) {
1641 int edgeID = edges_e->Value(i);
1642 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1643 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1645 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1646 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1647 nbEdgesInChamfer ++;
1648 theEdges.push_back(edgeID);
1652 if (theHexMesh && nbEdgesInChamfer == 1)
1655 Handle(GEOM_Object) aChamfer;
1657 aChamfer = myLocalOperations->MakeChamferEdges(aShape, theW, theH, theEdges);
1659 catch (Standard_Failure) {
1660 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1661 SetErrorCode(aFail->GetMessageString());
1664 if (aChamfer.IsNull()) {
1665 SetErrorCode("Chamfer can not be computed on the given shape with the given parameters");
1668 aChamfer->GetLastFunction()->SetDescription("");
1670 TopoDS_Shape aChamferShape = aChamfer->GetValue();
1671 aFunction->SetValue(aChamferShape);
1675 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, 0, false))
1677 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1681 TopoDS_Shape Te = aShape->GetValue();
1684 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
1685 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
1686 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
1687 aFunction->SetValue(aTrsf_Shape);
1688 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1689 aSeq->Append(aShape);
1692 * Get the groups: BEGIN
1695 if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf))
1698 catch (Standard_Failure) {
1699 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1700 SetErrorCode(aFail->GetMessageString());
1704 TCollection_AsciiString aListRes, anEntry;
1705 // Iterate over the sequence aSeq
1706 Standard_Integer aNbGroups = aSeq->Length();
1707 Standard_Integer i = 2;
1708 for (; i <= aNbGroups; i++) {
1709 Handle(Standard_Transient) anItem = aSeq->Value(i);
1710 if (anItem.IsNull()) continue;
1711 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1712 if (aGroup.IsNull()) continue;
1713 //Make a Python command
1714 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1715 aListRes += anEntry + ", ";
1718 aListRes.Trunc(aListRes.Length() - 2);
1720 //Make a Python command
1721 GEOM::TPythonDump(aFunction) << "[" << aShape << ", " << aListRes.ToCString()
1722 << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1723 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW << ", " << theHexMesh << ", "
1724 << theP1 << ", " << theP2 << ", " << theP3 << ")";
1727 * Get the groups: END
1730 //Make a Python command
1731 GEOM::TPythonDump(aFunction) << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1732 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1733 << ", " << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
1741 //=============================================================================
1743 * MakePipeTShapeFillet
1744 * Create a T-shape object with specified caracteristics for the main and
1745 * the incident pipes (radius, width, half-length). A fillet is created
1746 * on the junction of the pipes.
1747 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1748 * \param theR1 Internal radius of main pipe
1749 * \param theW1 Width of main pipe
1750 * \param theL1 Half-length of main pipe
1751 * \param theR2 Internal radius of incident pipe (R2 < R1)
1752 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1753 * \param theL2 Half-length of incident pipe
1754 * \param theRF Radius of curvature of fillet.
1755 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1756 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1758 //=============================================================================
1759 Handle(TColStd_HSequenceOfTransient)
1760 GEOMImpl_IAdvancedOperations::MakePipeTShapeFillet(double theR1, double theW1, double theL1,
1761 double theR2, double theW2, double theL2,
1762 double theRF, bool theHexMesh)
1766 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1767 //Add a new shape function with parameters
1768 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_FILLET);
1769 if (aFunction.IsNull()) return NULL;
1771 //Check if the function is set correctly
1772 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1774 GEOMImpl_IPipeTShape aData(aFunction);
1783 aData.SetHexMesh(theHexMesh);
1785 //Compute the resulting value
1787 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1790 if (!GetSolver()->ComputeFunction(aFunction)) {
1791 SetErrorCode("TShape driver failed");
1794 } catch (Standard_Failure) {
1795 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1796 SetErrorCode(aFail->GetMessageString());
1801 TopoDS_Shape aShapeShape = aShape->GetValue();
1802 TopTools_IndexedMapOfShape anEdgesIndices;
1803 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1804 // Common edges on external cylinders
1805 Handle(GEOM_Object) box_e;
1807 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1810 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1812 box_e->GetLastFunction()->SetDescription("");
1813 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1814 box_e->GetLastFunction()->SetDescription("");
1816 Handle(TColStd_HSequenceOfInteger) edges_e = myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1817 box_e->GetLastFunction()->SetDescription("");
1819 if (edges_e.IsNull() || edges_e->Length() == 0) {
1820 SetErrorCode("External edges not found");
1823 int nbEdgesInFillet = 0;
1824 std::list<int> theEdges;
1825 for (int i=1; i<=edges_e->Length();i++) {
1826 int edgeID = edges_e->Value(i);
1827 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1828 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1830 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1831 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1833 theEdges.push_back(edgeID);
1837 if (theHexMesh && nbEdgesInFillet == 1)
1841 Handle(GEOM_Object) aFillet;
1843 aFillet = myLocalOperations->MakeFilletEdges(aShape, theRF, theEdges);
1845 catch (Standard_Failure) {
1846 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1847 SetErrorCode(aFail->GetMessageString());
1850 if (aFillet.IsNull()) {
1851 // SetErrorCode("Fillet can not be computed on the given shape with the given parameters");
1852 SetErrorCode(myLocalOperations->GetErrorCode());
1855 aFillet->GetLastFunction()->SetDescription("");
1857 TopoDS_Shape aFilletShape = aFillet->GetValue();
1858 aFunction->SetValue(aFilletShape);
1862 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, 0, 0, theRF, false))
1864 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1868 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1869 aSeq->Append(aShape);
1872 * Get the groups: BEGIN
1875 if (!MakeGroups(aShape, TSHAPE_FILLET, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1878 catch (Standard_Failure) {
1879 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1880 SetErrorCode(aFail->GetMessageString());
1884 TCollection_AsciiString aListRes, anEntry;
1885 // Iterate over the sequence aSeq
1886 Standard_Integer aNbGroups = aSeq->Length();
1887 Standard_Integer i = 2;
1888 for (; i <= aNbGroups; i++) {
1889 Handle(Standard_Transient) anItem = aSeq->Value(i);
1890 if (anItem.IsNull()) continue;
1891 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1892 if (aGroup.IsNull()) continue;
1893 //Make a Python command
1894 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1895 aListRes += anEntry + ", ";
1898 aListRes.Trunc(aListRes.Length() - 2);
1900 //Make a Python command
1901 GEOM::TPythonDump(aFunction) << "[" << aShape << ", " << aListRes.ToCString()
1902 << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1903 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", " << theHexMesh << ")";
1906 * Get the groups: END
1909 //Make a Python command
1910 GEOM::TPythonDump(aFunction) << "[" << aShape << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1
1911 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", "
1912 << theHexMesh << ")";
1922 //=============================================================================
1924 * MakePipeTShapeFilletWithPosition
1925 * Create a T-shape object with specified caracteristics for the main and
1926 * the incident pipes (radius, width, half-length). A fillet is created
1927 * on the junction of the pipes.
1928 * The extremities of the main pipe are located on junctions points P1 and P2.
1929 * The extremity of the incident pipe is located on junction point P3.
1930 * \param theR1 Internal radius of main pipe
1931 * \param theW1 Width of main pipe
1932 * \param theL1 Half-length of main pipe
1933 * \param theR2 Internal radius of incident pipe (R2 < R1)
1934 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1935 * \param theL2 Half-length of incident pipe
1936 * \param theRF Radius of curvature of fillet
1937 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1938 * \param theP1 1st junction point of main pipe
1939 * \param theP2 2nd junction point of main pipe
1940 * \param theP3 Junction point of incident pipe
1941 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1943 //=============================================================================
1944 Handle(TColStd_HSequenceOfTransient)
1945 GEOMImpl_IAdvancedOperations::MakePipeTShapeFilletWithPosition(double theR1, double theW1, double theL1,
1946 double theR2, double theW2, double theL2,
1947 double theRF, bool theHexMesh,
1948 Handle(GEOM_Object) theP1,
1949 Handle(GEOM_Object) theP2,
1950 Handle(GEOM_Object) theP3)
1954 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1955 //Add a new shape function with parameters
1956 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_FILLET);
1957 if (aFunction.IsNull()) return NULL;
1959 //Check if the function is set correctly
1960 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1962 // Check new position
1963 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1967 GEOMImpl_IPipeTShape aData(aFunction);
1976 aData.SetHexMesh(theHexMesh);
1978 //Compute the resulting value
1980 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1983 if (!GetSolver()->ComputeFunction(aFunction)) {
1984 SetErrorCode("TShape driver failed");
1987 } catch (Standard_Failure) {
1988 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1989 SetErrorCode(aFail->GetMessageString());
1994 TopoDS_Shape aShapeShape = aShape->GetValue();
1995 TopTools_IndexedMapOfShape anEdgesIndices;
1996 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1997 // Common edges on external cylinders
1998 Handle(GEOM_Object) box_e;
2000 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
2003 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
2005 box_e->GetLastFunction()->SetDescription("");
2006 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
2007 box_e->GetLastFunction()->SetDescription("");
2009 Handle(TColStd_HSequenceOfInteger) edges_e = myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
2010 box_e->GetLastFunction()->SetDescription("");
2012 if (edges_e.IsNull() || edges_e->Length() == 0) {
2013 SetErrorCode("External edges not found");
2016 int nbEdgesInFillet = 0;
2017 std::list<int> theEdges;
2018 for (int i=1; i<=edges_e->Length();i++) {
2019 int edgeID = edges_e->Value(i);
2020 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
2021 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
2023 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
2024 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
2026 theEdges.push_back(edgeID);
2030 if (theHexMesh && nbEdgesInFillet == 1)
2034 Handle(GEOM_Object) aFillet;
2036 aFillet = myLocalOperations->MakeFilletEdges(aShape, theRF, theEdges);
2038 catch (Standard_Failure) {
2039 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2040 SetErrorCode(aFail->GetMessageString());
2043 if (aFillet.IsNull()) {
2044 SetErrorCode("Fillet can not be computed on the given shape with the given parameters");
2047 aFillet->GetLastFunction()->SetDescription("");
2049 TopoDS_Shape aFilletShape = aFillet->GetValue();
2050 aFunction->SetValue(aFilletShape);
2054 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, 0, 0, theRF, false))
2056 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
2060 TopoDS_Shape Te = aShape->GetValue();
2063 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
2064 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
2065 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
2066 aFunction->SetValue(aTrsf_Shape);
2067 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
2068 aSeq->Append(aShape);
2071 * Get the groups: BEGIN
2074 if (!MakeGroups(aShape, TSHAPE_FILLET, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf))
2077 catch (Standard_Failure) {
2078 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2079 SetErrorCode(aFail->GetMessageString());
2083 TCollection_AsciiString aListRes, anEntry;
2084 // Iterate over the sequence aSeq
2085 Standard_Integer aNbGroups = aSeq->Length();
2086 Standard_Integer i = 2;
2087 for (; i <= aNbGroups; i++) {
2088 Handle(Standard_Transient) anItem = aSeq->Value(i);
2089 if (anItem.IsNull()) continue;
2090 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
2091 if (aGroup.IsNull()) continue;
2092 //Make a Python command
2093 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
2094 aListRes += anEntry + ", ";
2097 aListRes.Trunc(aListRes.Length() - 2);
2099 //Make a Python command
2100 GEOM::TPythonDump(aFunction) << "[" << aShape << ", " << aListRes.ToCString()
2101 << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
2102 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", " << theHexMesh << ", " << theP1 << ", "
2103 << theP2 << ", " << theP3 << ")";
2106 * Get the groups: END
2109 //Make a Python command
2110 GEOM::TPythonDump(aFunction) << "[" << aShape << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1
2111 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", "
2112 << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
2120 /*@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@*/