1 // Copyright (C) 2007-2012 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
19 // File : GEOMImpl_IAdvancedOperations.cxx
20 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
22 #include <Standard_Stream.hxx>
24 #include "GEOMImpl_Types.hxx"
25 #include "GEOMImpl_IAdvancedOperations.hxx"
26 #include "GEOMImpl_IBasicOperations.hxx"
27 #include "GEOMImpl_IBooleanOperations.hxx"
28 #include "GEOMImpl_IShapesOperations.hxx"
29 #include "GEOMImpl_ITransformOperations.hxx"
30 #include "GEOMImpl_IBlocksOperations.hxx"
31 #include "GEOMImpl_I3DPrimOperations.hxx"
32 #include "GEOMImpl_ILocalOperations.hxx"
33 #include "GEOMImpl_IHealingOperations.hxx"
35 #include "GEOMImpl_Gen.hxx"
37 #include <Basics_OCCTVersion.hxx>
39 #include <utilities.h>
41 #include <Utils_ExceptHandlers.hxx>
43 #include "GEOM_Function.hxx"
44 #include "GEOM_PythonDump.hxx"
46 #include "GEOMImpl_PipeTShapeDriver.hxx"
47 #include "GEOMImpl_IPipeTShape.hxx"
48 /*@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@*/
51 #include <TopExp_Explorer.hxx>
53 #include <TopoDS_Vertex.hxx>
54 #include <TopTools_IndexedMapOfShape.hxx>
59 #include <BRepBuilderAPI_Transform.hxx>
60 #include <BRep_Tool.hxx>
63 #include <TFunction_DriverTable.hxx>
64 #include <TFunction_Driver.hxx>
65 #include <TFunction_Logbook.hxx>
66 #include <TDF_Tool.hxx>
67 #include <Standard_Failure.hxx>
68 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
70 #define HALF_LENGTH_MAIN_PIPE "Main pipe half length" //"Tuyau principal - demi longueur"
71 #define HALF_LENGTH_INCIDENT_PIPE "Incident pipe half length" //"Tuyau incident - demi longueur"
72 #define CIRCULAR_QUARTER_PIPE "Circular quarter of pipe" //"Circulaire - quart de tuyau"
73 #define THICKNESS "Thickness" //"Epaisseur"
74 #define FLANGE "Flange" // "Collerette"
75 #define CHAMFER_OR_FILLET "Chamfer or fillet" //"Chanfrein ou Raccord"
76 #define JUNCTION_FACE_1 "Junction 1" //"Face de jonction 1"
77 #define JUNCTION_FACE_2 "Junction 2" //"Face de jonction 2"
78 #define JUNCTION_FACE_3 "Junction 3" //"Face de jonction 3"
80 //=============================================================================
84 //=============================================================================
85 GEOMImpl_IAdvancedOperations::GEOMImpl_IAdvancedOperations(GEOM_Engine* theEngine, int theDocID) :
86 GEOM_IOperations(theEngine, theDocID)
88 MESSAGE("GEOMImpl_IAdvancedOperations::GEOMImpl_IAdvancedOperations");
89 myBasicOperations = new GEOMImpl_IBasicOperations(GetEngine(), GetDocID());
90 myBooleanOperations = new GEOMImpl_IBooleanOperations(GetEngine(), GetDocID());
91 myShapesOperations = new GEOMImpl_IShapesOperations(GetEngine(), GetDocID());
92 myTransformOperations = new GEOMImpl_ITransformOperations(GetEngine(), GetDocID());
93 myBlocksOperations = new GEOMImpl_IBlocksOperations(GetEngine(), GetDocID());
94 my3DPrimOperations = new GEOMImpl_I3DPrimOperations(GetEngine(), GetDocID());
95 myLocalOperations = new GEOMImpl_ILocalOperations(GetEngine(), GetDocID());
96 myHealingOperations = new GEOMImpl_IHealingOperations(GetEngine(), GetDocID());
99 //=============================================================================
103 //=============================================================================
104 GEOMImpl_IAdvancedOperations::~GEOMImpl_IAdvancedOperations()
106 MESSAGE("GEOMImpl_IAdvancedOperations::~GEOMImpl_IAdvancedOperations");
107 delete myBasicOperations;
108 delete myBooleanOperations;
109 delete myShapesOperations;
110 delete myTransformOperations;
111 delete myBlocksOperations;
112 delete my3DPrimOperations;
113 delete myLocalOperations;
114 delete myHealingOperations;
117 //=============================================================================
121 //=============================================================================
122 gp_Trsf GEOMImpl_IAdvancedOperations::GetPositionTrsf(double theL1, double theL2,
123 Handle(GEOM_Object) theP1,
124 Handle(GEOM_Object) theP2,
125 Handle(GEOM_Object) theP3)
127 // Old Local Coordinates System oldLCS
129 gp_Pnt P1(-theL1, 0, 0);
130 gp_Pnt P2(theL1, 0, 0);
131 gp_Pnt P3(0, 0, theL2);
133 gp_Dir oldX(gp_Vec(P1, P2));
134 gp_Dir oldZ(gp_Vec(P0, P3));
135 gp_Ax3 oldLCS(P0, oldZ, oldX);
137 // New Local Coordinates System newLCS
138 double LocX, LocY, LocZ;
139 gp_Pnt newP1 = BRep_Tool::Pnt(TopoDS::Vertex(theP1->GetValue()));
140 gp_Pnt newP2 = BRep_Tool::Pnt(TopoDS::Vertex(theP2->GetValue()));
141 gp_Pnt newP3 = BRep_Tool::Pnt(TopoDS::Vertex(theP3->GetValue()));
142 LocX = (newP1.X() + newP2.X()) / 2.;
143 LocY = (newP1.Y() + newP2.Y()) / 2.;
144 LocZ = (newP1.Z() + newP2.Z()) / 2.;
145 gp_Pnt newO(LocX, LocY, LocZ);
147 gp_Dir newX(gp_Vec(newP1, newP2)); // P1P2 Vector
148 gp_Dir newZ(gp_Vec(newO, newP3)); // OP3 Vector
149 gp_Ax3 newLCS = gp_Ax3(newO, newZ, newX);
152 aTrsf.SetDisplacement(oldLCS, newLCS);
157 //=============================================================================
159 * CheckCompatiblePosition
162 //=============================================================================
163 bool GEOMImpl_IAdvancedOperations::CheckCompatiblePosition(double& theL1, double& theL2,
164 Handle(GEOM_Object) theP1,
165 Handle(GEOM_Object) theP2,
166 Handle(GEOM_Object) theP3,
170 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(theP1->GetValue()));
171 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(theP2->GetValue()));
172 gp_Pnt P3 = BRep_Tool::Pnt(TopoDS::Vertex(theP3->GetValue()));
174 double d12 = P1.Distance(P2);
175 double d13 = P1.Distance(P3);
176 double d23 = P2.Distance(P3);
177 // double d2 = newO.Distance(P3);
179 if (Abs(d12) <= Precision::Confusion()) {
180 SetErrorCode("Junctions points P1 and P2 are identical");
183 if (Abs(d13) <= Precision::Confusion()) {
184 SetErrorCode("Junctions points P1 and P3 are identical");
187 if (Abs(d23) <= Precision::Confusion()) {
188 SetErrorCode("Junctions points P2 and P3 are identical");
193 double newL1 = 0.5 * d12;
194 double newL2 = sqrt(pow(d13,2)-pow(newL1,2));
196 // theL1*(1-theTolerance) <= newL1 <= theL1*(1+theTolerance)
198 if (fabs(newL1 - theL1) > Precision::Approximation()) {
199 if ( (newL1 * (1 - theTolerance) -theL1 <= Precision::Approximation()) &&
200 (newL1 * (1 + theTolerance) -theL1 >= Precision::Approximation()) ) {
201 // std::cerr << "theL1 = newL1" << std::endl;
205 SetErrorCode("Dimension for main pipe (L1) is incompatible with new position");
211 // theL2*(1-theTolerance) <= newL2 <= theL2*(1+theTolerance)
213 if (fabs(newL2 - theL2) > Precision::Approximation()) {
214 if ( (newL2 * (1 - theTolerance) -theL2 <= Precision::Approximation()) &&
215 (newL2 * (1 + theTolerance) -theL2 >= Precision::Approximation()) ) {
219 SetErrorCode("Dimension for incident pipe (L2) is incompatible with new position");
229 //=============================================================================
231 * Generate the propagation groups of a Pipe T-Shape used for hexa mesh
233 //=============================================================================
234 bool GEOMImpl_IAdvancedOperations::MakeGroups(Handle(GEOM_Object) theShape, int shapeType,
235 double theR1, double theW1, double theL1,
236 double theR2, double theW2, double theL2,
237 Handle(TColStd_HSequenceOfTransient) theSeq,
242 if (theShape.IsNull()) return false;
244 TopoDS_Shape aShape = theShape->GetValue();
245 if (aShape.IsNull()) {
246 SetErrorCode("Shape is not defined");
250 gp_Trsf aTrsfInv = aTrsf.Inverted();
252 // int expectedGroups = 0;
253 // if (shapeType == TSHAPE_BASIC)
254 // if (Abs(theR2+theW2-theR1-theW1) <= Precision::Approximation())
255 // expectedGroups = 10;
257 // expectedGroups = 11;
258 // else if (shapeType == TSHAPE_CHAMFER || shapeType == TSHAPE_FILLET)
259 // expectedGroups = 12;
261 double aR1Ext = theR1 + theW1;
262 double aR2Ext = theR2 + theW2;
264 /////////////////////////
265 //// Groups of Faces ////
266 /////////////////////////
269 // Comment the following lines when GetInPlace bug is solved
271 // Workaround of GetInPlace bug
272 // Create a bounding box that fits the shape
273 Handle(GEOM_Object) aBox = my3DPrimOperations->MakeBoxDXDYDZ(2*theL1, 2*aR1Ext, aR1Ext+theL2);
274 aBox->GetLastFunction()->SetDescription("");
275 myTransformOperations->TranslateDXDYDZ(aBox, -theL1, -aR1Ext, -aR1Ext);
276 aBox->GetLastFunction()->SetDescription("");
277 // Apply transformation to box
278 BRepBuilderAPI_Transform aTransformationBox(aBox->GetValue(), aTrsf, Standard_False);
279 TopoDS_Shape aBoxShapeTrsf = aTransformationBox.Shape();
280 aBox->GetLastFunction()->SetValue(aBoxShapeTrsf);
282 // Get the shell of the box
283 Handle(GEOM_Object) aShell = Handle(GEOM_Object)::DownCast
284 (myShapesOperations->MakeExplode(aBox, TopAbs_SHELL, true)->Value(1));
285 aBox->GetLastFunction()->SetDescription("");
286 aShell->GetLastFunction()->SetDescription("");
287 // Get the common shapes between shell and shape
288 Handle(GEOM_Object) aCommonCompound = myBooleanOperations->MakeBoolean (theShape, aShell, 1); // MakeCommon
289 if (aCommonCompound.IsNull()) {
290 SetErrorCode(myBooleanOperations->GetErrorCode());
293 aCommonCompound->GetLastFunction()->SetDescription("");
294 // Explode the faces of common shapes => 3 faces
295 Handle(TColStd_HSequenceOfTransient) aCommonFaces =
296 myShapesOperations->MakeExplode(aCommonCompound, TopAbs_FACE, true);
297 aCommonCompound->GetLastFunction()->SetDescription("");
298 std::list<Handle(GEOM_Object)> aCompoundOfFacesList;
300 for (int i=0 ; i<= aCommonFaces->Length()-4 ; i+=4) {
301 std::list<Handle(GEOM_Object)> aFacesList;
302 for (int j = 1 ; j <= 4 ; j++) {
303 Handle(GEOM_Object) aFace = Handle(GEOM_Object)::DownCast(aCommonFaces->Value(i+j)); // Junction faces
304 if (!aFace.IsNull()) {
305 aFace->GetLastFunction()->SetDescription("");
306 aFacesList.push_back(aFace);
309 Handle(GEOM_Object) aCompoundOfFaces = myShapesOperations->MakeCompound(aFacesList);
310 if (!aCompoundOfFaces.IsNull()) {
311 aCompoundOfFaces->GetLastFunction()->SetDescription("");
312 aCompoundOfFacesList.push_back(aCompoundOfFaces);
316 if (aCompoundOfFacesList.size() == 3) {
317 Handle(GEOM_Object) aPln1 = aCompoundOfFacesList.front();
318 aCompoundOfFacesList.pop_front();
319 Handle(GEOM_Object) aPln2 = aCompoundOfFacesList.front();
320 aCompoundOfFacesList.pop_front();
321 Handle(GEOM_Object) aPln3 = aCompoundOfFacesList.front();
322 aCompoundOfFacesList.pop_front();
327 // Uncomment the following lines when GetInPlace bug is solved
329 // Handle(GEOM_Object) aP1 = myBasicOperations->MakePointXYZ(-theL1, 0, 0);
330 // Handle(GEOM_Object) aP2 = myBasicOperations->MakePointXYZ(-0, 0, theL2);
331 // Handle(GEOM_Object) aP3 = myBasicOperations->MakePointXYZ(theL1, 0, 0);
332 // aP1->GetLastFunction()->SetDescription("");
333 // aP2->GetLastFunction()->SetDescription("");
334 // aP3->GetLastFunction()->SetDescription("");
335 // Handle(GEOM_Object) aV1 = myBasicOperations->MakeVectorDXDYDZ(-1, 0, 0);
336 // Handle(GEOM_Object) aV2 = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
337 // Handle(GEOM_Object) aV3 = myBasicOperations->MakeVectorDXDYDZ(1, 0, 0);
338 // aV1->GetLastFunction()->SetDescription("");
339 // aV2->GetLastFunction()->SetDescription("");
340 // aV3->GetLastFunction()->SetDescription("");
341 // Handle(GEOM_Object) aPln1 = myBasicOperations->MakePlanePntVec(aP1, aV1, 2*(aR1Ext+theL2));
342 // Handle(GEOM_Object) aPln2 = myBasicOperations->MakePlanePntVec(aP2, aV2, 2*(aR2Ext));
343 // Handle(GEOM_Object) aPln3 = myBasicOperations->MakePlanePntVec(aP3, aV3, 2*(aR1Ext+theL2));
344 // aPln1->GetLastFunction()->SetDescription("");
345 // aPln2->GetLastFunction()->SetDescription("");
346 // aPln3->GetLastFunction()->SetDescription("");
348 // BRepBuilderAPI_Transform aTransformation1(aPln1->GetValue(), aTrsf, Standard_False);
349 // TopoDS_Shape aTrsf_Shape1 = aTransformation1.Shape();
350 // aPln1->GetLastFunction()->SetValue(aTrsf_Shape1);
351 // BRepBuilderAPI_Transform aTransformation2(aPln2->GetValue(), aTrsf, Standard_False);
352 // TopoDS_Shape aTrsf_Shape2 = aTransformation2.Shape();
353 // aPln2->GetLastFunction()->SetValue(aTrsf_Shape2);
354 // BRepBuilderAPI_Transform aTransformation3(aPln3->GetValue(), aTrsf, Standard_False);
355 // TopoDS_Shape aTrsf_Shape3 = aTransformation3.Shape();
356 // aPln3->GetLastFunction()->SetValue(aTrsf_Shape3);
360 Handle(GEOM_Object) junctionFaces1 = myShapesOperations->GetInPlace(theShape, aPln1);
361 if (junctionFaces1.IsNull())
362 junctionFaces1 = myShapesOperations->GetShapesOnShapeAsCompound
363 (aPln1, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
364 if (!junctionFaces1.IsNull()) {
365 junctionFaces1->GetLastFunction()->SetDescription("");
366 junctionFaces1->SetName("JUNCTION_FACE_1");
367 theSeq->Append(junctionFaces1);
370 SetErrorCode("Junction face 1 not found");
371 // theSeq->Append(aPln1);
374 Handle(GEOM_Object) junctionFaces2 = myShapesOperations->GetInPlace(theShape, aPln2);
375 if (junctionFaces2.IsNull())
376 junctionFaces2 = myShapesOperations->GetShapesOnShapeAsCompound
377 (aPln2, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
378 if (!junctionFaces2.IsNull()) {
379 junctionFaces2->GetLastFunction()->SetDescription("");
380 junctionFaces2->SetName("JUNCTION_FACE_2");
381 theSeq->Append(junctionFaces2);
384 SetErrorCode("Junction face 2 not found");
385 // theSeq->Append(aPln2);
388 Handle(GEOM_Object) junctionFaces3 = myShapesOperations->GetInPlace(theShape, aPln3);
389 if (junctionFaces3.IsNull())
390 junctionFaces3 = myShapesOperations->GetShapesOnShapeAsCompound
391 (aPln3, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
392 if (!junctionFaces3.IsNull()) {
393 junctionFaces3->GetLastFunction()->SetDescription("");
394 junctionFaces3->SetName("JUNCTION_FACE_3");
395 theSeq->Append(junctionFaces3);
398 SetErrorCode("Junction face 3 not found");
399 // theSeq->Append(aPln3);
402 // Comment the following lines when GetInPlace bug is solved
406 /////////////////////////
407 //// Groups of Edges ////
408 /////////////////////////
409 // Result of propagate
411 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
413 TCollection_AsciiString theDesc = aFunction->GetDescription();
414 Handle(TColStd_HSequenceOfTransient) aSeqPropagate = myBlocksOperations->Propagate(theShape);
415 if (aSeqPropagate.IsNull() || aSeqPropagate->Length() == 0) {
416 SetErrorCode("Propagation groups not found");
419 Standard_Integer nbEdges, aNbGroups = aSeqPropagate->Length();
420 // Recover previous description to get rid of Propagate dump
421 aFunction->SetDescription(theDesc);
424 bool circularFoundAndAdded = false;
425 bool circularFound10 = false;
426 bool incidentPipeFound = false;
427 bool mainPipeFound = false;
428 bool mainPipeFoundAndAdded = false;
429 bool radialFound =false;
430 bool flangeFound = false;
431 bool flangeFoundAndAdded = false;
432 bool chamferOrFilletFound = false;
434 for (int i=1 ; i<= aNbGroups; i++) {
437 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(aSeqPropagate->Value(i));
441 TopoDS_Shape aGroupShape = aGroup->GetValue();
442 BRepBuilderAPI_Transform aTransformationShapeInv(aGroupShape, aTrsfInv, Standard_False);
443 TopoDS_Shape aGroupShapeTrsfInv = aTransformationShapeInv.Shape();
445 TopTools_IndexedMapOfShape anEdgesMap;
446 TopExp::MapShapes(aGroupShapeTrsfInv,TopAbs_EDGE, anEdgesMap);
447 nbEdges = anEdgesMap.Extent();
449 if (shapeType == TSHAPE_BASIC) {
450 if ((nbEdges == 21) || /*R1Ext = R2Ext*/(nbEdges == 17)){
452 aGroup->SetName("THICKNESS");
454 else if (nbEdges == 6) {
455 if (!circularFoundAndAdded) {
456 circularFoundAndAdded = true;
458 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
461 else if (nbEdges == 8) {
462 incidentPipeFound = true;
463 mainPipeFound = false;
467 TopExp_Explorer Ex(aGroupShapeTrsfInv,TopAbs_VERTEX);
469 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
470 double x=aP.X(), y=aP.Y(), z=aP.Z();
473 if ((Abs(x) > aR2Ext + Precision::Confusion()) ||
474 (Abs(y) > aR2Ext + Precision::Confusion())) {
475 incidentPipeFound = false;
478 if ( z < -Precision::Confusion()) {
479 // length of main pipe
480 mainPipeFound = true;
481 if (!mainPipeFoundAndAdded) {
482 mainPipeFoundAndAdded = true;
484 aGroup->SetName("HALF_LENGTH_MAIN_PIPE");
488 else if (Abs(x) > (theL1-Precision::Confusion())) {
489 // discretisation circulaire
491 if (!circularFoundAndAdded) {
492 circularFoundAndAdded = true;
494 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
499 if (incidentPipeFound) {
501 aGroup->SetName("HALF_LENGTH_INCIDENT_PIPE");
503 if (!addGroup && (!incidentPipeFound &&
507 // Flange (collerette)
510 aGroup->SetName("FLANGE");
516 else if (shapeType == TSHAPE_CHAMFER || shapeType == TSHAPE_FILLET) {
519 aGroup->SetName("THICKNESS");
521 else if ((nbEdges == 10) || (nbEdges == 6)) {
522 if (!circularFoundAndAdded) {
524 circularFoundAndAdded = true;
525 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
527 circularFound10 = true;
530 else if (!circularFound10 && nbEdges == 10) {
531 circularFound10 = true;
533 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
536 else if (nbEdges == 8) {
537 incidentPipeFound = true;
538 mainPipeFound = true;
541 bool isNearZ0 = false;
542 bool isBelowZ0 = false;
544 TopExp_Explorer Ex (aGroupShapeTrsfInv,TopAbs_VERTEX);
546 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
547 double x=aP.X(), y=aP.Y(), z=aP.Z();
549 // tuy_princ_long_avant & tuy_princ_long_apres
550 //bool isMain = (((z < Precision::Confusion()) || (x < Precision::Confusion())) &&
551 // ((y <= aR1Ext + Precision::Confusion()) ||
552 // (y <= -(aR1Ext + Precision::Confusion())) ||
553 // (y <= theR1 + Precision::Confusion()) ||
554 // (y == -(theR1 + Precision::Confusion()))));
555 bool isMain = ((z < Precision::Confusion() || x < Precision::Confusion()) &&
556 (fabs(y) > theR1 - Precision::Confusion() ||
557 fabs(y) < Precision::Confusion()));
560 mainPipeFound = false;
564 //if (z < Precision::Confusion() && !isMain) {
565 // flangeFound = true;
566 // if (!flangeFoundAndAdded) {
567 // flangeFoundAndAdded = true;
569 // aGroup->SetName("FLANGE");
572 if (fabs(z) < Precision::Confusion()) isNearZ0 = true;
573 if (z < - Precision::Confusion()) isBelowZ0 = true;
576 if ((Abs(x) > aR2Ext + Precision::Confusion()) ||
577 (Abs(y) > aR2Ext + Precision::Confusion())) {
578 incidentPipeFound = false;
584 aGroup->SetName("HALF_LENGTH_MAIN_PIPE");
586 if (incidentPipeFound) {
588 aGroup->SetName("HALF_LENGTH_INCIDENT_PIPE");
590 if (isNearZ0 && !isBelowZ0) {
592 if (!flangeFoundAndAdded) {
593 flangeFoundAndAdded = true;
595 aGroup->SetName("FLANGE");
598 if (!addGroup && (!incidentPipeFound &&
601 !chamferOrFilletFound)) {
603 chamferOrFilletFound = true;
604 if (shapeType == TSHAPE_CHAMFER)
605 aGroup->SetName("CHAMFER");
607 aGroup->SetName("FILLET");
613 // Add group to the list
615 theSeq->Append(aGroup);
622 bool GEOMImpl_IAdvancedOperations::MakePipeTShapePartition(Handle(GEOM_Object) theShape,
623 double theR1, double theW1, double theL1,
624 double theR2, double theW2, double theL2,
625 double theH, double theW,
626 double theRF, bool isNormal)
630 // Build tools for partition operation:
631 // 1 face and 2 planes
633 Handle(GEOM_Object) arete_intersect_int;
634 Handle(GEOM_Object) wire_t, wire_t2, face_t, face_t2;
635 Handle(GEOM_Object) chan_racc;
636 Handle(GEOM_Object) vi1, vi2;
637 Handle(GEOM_Object) Te3;
640 #if OCC_VERSION_LARGE > 0x06010000
643 Handle(GEOM_Object) Vector_Z = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
644 Vector_Z->GetLastFunction()->SetDescription("");
647 double aSize = 2*(theL1 + theL2);
648 double aR1Ext = theR1 + theW1;
649 double aR2Ext = theR2 + theW2;
650 double theVertCylinderRadius = aR2Ext + theW + theRF;
651 double theHoriCylinderRadius = aR1Ext + theH + theRF;
653 // Common edges on internal cylinder
654 Handle(GEOM_Object) box_i = my3DPrimOperations->MakeBoxDXDYDZ(theR2, theR2, theR1);
655 box_i->GetLastFunction()->SetDescription("");
656 box_i = myTransformOperations->TranslateDXDYDZ(box_i, -theR2, -theR2, 0);
657 box_i->GetLastFunction()->SetDescription("");
659 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
660 TCollection_AsciiString theDesc = aFunction->GetDescription();
661 Handle(TColStd_HSequenceOfTransient) edges_i =
662 myShapesOperations->GetShapesOnBox(box_i, theShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
663 // Recover previous description to get rid of Propagate dump
664 aFunction->SetDescription(theDesc);
665 if (edges_i.IsNull() || edges_i->Length() == 0) {
666 SetErrorCode("Internal edges not found");
669 for (int i=1; i<=edges_i->Length();i++) {
670 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(edges_i->Value(i));
671 anObj->GetLastFunction()->SetDescription("");
673 arete_intersect_int = Handle(GEOM_Object)::DownCast(edges_i->Value(1));
675 // search for vertices located on both internal pipes
676 aFunction = theShape->GetLastFunction();
677 theDesc = aFunction->GetDescription();
678 Handle(TColStd_HSequenceOfTransient) vertices_i =
679 myShapesOperations->GetShapesOnBox(box_i, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
680 // Recover previous description to get rid of Propagate dump
681 aFunction->SetDescription(theDesc);
682 if (vertices_i.IsNull() || vertices_i->Length() == 0) {
683 SetErrorCode("Internal vertices not found");
687 for (int i = 1; i <= vertices_i->Length(); i++) {
688 Handle(GEOM_Object) v = Handle(GEOM_Object)::DownCast(vertices_i->Value(i));
689 v->GetLastFunction()->SetDescription("");
690 TopoDS_Vertex aVertex = TopoDS::Vertex(v->GetValue());
691 gp_Pnt aP = BRep_Tool::Pnt(aVertex);
692 // std::cout << "Coords: " << aP.X() << ", " << aP.Y() << ", " << aP.Z() << std::endl;
693 if (Abs(aP.X()) <= Precision::Confusion()) {
694 if (Abs(aP.Y()) - theR1 <= Precision::Confusion()) {
697 } else if (Abs(aP.Y()) <= Precision::Confusion()) {
698 if (Abs(aP.X()) - theR1 <= Precision::Confusion()) {
704 std::list<Handle(GEOM_Object)> theShapes;
707 Handle(GEOM_Object) ve1, ve2;
709 Handle(GEOM_Object) box_e = my3DPrimOperations->MakeBoxDXDYDZ(aR2Ext, aR2Ext, aR1Ext);
710 box_e->GetLastFunction()->SetDescription("");
711 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -aR2Ext, -aR2Ext, 0);
712 box_e->GetLastFunction()->SetDescription("");
713 // Common edges on external cylinder
714 aFunction = theShape->GetLastFunction();
715 theDesc = aFunction->GetDescription();
716 Handle(TColStd_HSequenceOfTransient) edges_e =
717 myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
718 // Recover previous description to get rid of Propagate dump
719 aFunction->SetDescription(theDesc);
720 if (edges_e.IsNull() || edges_e->Length() == 0) {
721 SetErrorCode("External edges not found");
724 for (int i=1; i<=edges_e->Length();i++) {
725 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(edges_e->Value(i));
726 anObj->GetLastFunction()->SetDescription("");
729 // search for vertices located on both external pipes
730 aFunction = theShape->GetLastFunction();
731 theDesc = aFunction->GetDescription();
732 Handle(TColStd_HSequenceOfTransient) vertices_e =
733 myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
734 // Recover previous description to get rid of Propagate dump
735 aFunction->SetDescription(theDesc);
736 if (vertices_e.IsNull() || vertices_e->Length() == 0) {
737 SetErrorCode("External vertices not found");
741 for (int i = 1; i <= vertices_e->Length(); i++) {
742 Handle(GEOM_Object) v = Handle(GEOM_Object)::DownCast(vertices_e->Value(i));
743 v->GetLastFunction()->SetDescription("");
744 TopoDS_Vertex aVertex = TopoDS::Vertex(v->GetValue());
745 gp_Pnt aP = BRep_Tool::Pnt(aVertex);
746 // std::cout << "Coords: " << aP.X() << ", " << aP.Y() << ", " << aP.Z() << std::endl;
747 if (Abs(aP.X()) <= Precision::Confusion()) {
748 if (Abs(aP.Y()) - theR2 > Precision::Confusion()) {
751 } else if (Abs(aP.Y()) <= Precision::Confusion()) {
752 if (Abs(aP.X()) - theR2 > Precision::Confusion()) {
756 if ( !ve1.IsNull() && !ve2.IsNull())
759 Handle(GEOM_Object) edge_e1, edge_e2;
761 edge_e1 = myBasicOperations->MakeLineTwoPnt(ve1, vi1);
762 if (edge_e1.IsNull()) {
763 SetErrorCode("Edge 1 could not be built");
767 edge_e2 = myBasicOperations->MakeLineTwoPnt(ve2, vi2);
768 if (edge_e2.IsNull()) {
769 SetErrorCode("Edge 2 could not be built");
773 edge_e1->GetLastFunction()->SetDescription("");
774 edge_e2->GetLastFunction()->SetDescription("");
776 std::list<Handle(GEOM_Object)> edge_e_elist;
777 edge_e_elist.push_back(arete_intersect_int);
778 edge_e_elist.push_back(edge_e1);
779 edge_e_elist.push_back(Handle(GEOM_Object)::DownCast(edges_e->Value(1)));
780 edge_e_elist.push_back(edge_e2);
781 wire_t = myShapesOperations->MakeWire(edge_e_elist, 1e-7);
782 if (wire_t.IsNull()) {
783 SetErrorCode("Impossible to build wire");
786 wire_t->GetLastFunction()->SetDescription("");
787 face_t = myShapesOperations->MakeFace(wire_t, false);
788 if (face_t.IsNull()) {
789 SetErrorCode("Impossible to build face");
792 face_t->GetLastFunction()->SetDescription("");
794 theShapes.push_back(theShape);
795 theShapes.push_back(vi1);
796 theShapes.push_back(vi2);
797 theShapes.push_back(ve1);
798 theShapes.push_back(ve2);
799 theShapes.push_back(edge_e1);
800 theShapes.push_back(edge_e2);
801 theShapes.push_back(wire_t);
802 theShapes.push_back(face_t);
805 Handle(GEOM_Object) P1, P2, P3, P4, P5, P6;
806 int idP1, idP2, idP3, idP4;
811 Handle(GEOM_Object) box_e = my3DPrimOperations->MakeBoxDXDYDZ
812 (theVertCylinderRadius, theVertCylinderRadius, theHoriCylinderRadius);
813 box_e->GetLastFunction()->SetDescription("");
814 box_e = myTransformOperations->TranslateDXDYDZ
815 (box_e, -theVertCylinderRadius, -theVertCylinderRadius, 0);
816 box_e->GetLastFunction()->SetDescription("");
818 aFunction = theShape->GetLastFunction();
819 theDesc = aFunction->GetDescription();
820 Handle(TColStd_HSequenceOfTransient) extremVertices =
821 myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
822 // Recover previous description to get rid of Propagate dump
823 aFunction->SetDescription(theDesc);
825 if (extremVertices.IsNull() || extremVertices->Length() == 0) {
827 SetErrorCode("Vertices on chamfer not found");
829 SetErrorCode("Vertices on fillet not found");
833 theShapes.push_back(theShape);
834 theShapes.push_back(box_e);
835 if (extremVertices->Length() != 6) {
836 // for (int i=1; i<=extremVertices->Length(); i++){
837 // theShapes.push_back(Handle(GEOM_Object)::DownCast(extremVertices->Value(i)));
839 // Handle(GEOM_Object) aCompound = myShapesOperations->MakeCompound(theShapes);
840 // TopoDS_Shape aCompoundShape = aCompound->GetValue();
841 // theShape->GetLastFunction()->SetValue(aCompoundShape);
842 SetErrorCode("Bad number of vertices on chamfer found");
846 for (int i=1; i<=extremVertices->Length(); i++){
847 Handle(GEOM_Object) aV = Handle(GEOM_Object)::DownCast(extremVertices->Value(i));
848 aV->GetLastFunction()->SetDescription("");
849 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aV->GetValue()));
851 if (Abs(aP.X()) <= Precision::Confusion()) {
852 if (Abs(aP.Y()) - theR2 > Precision::Confusion()) {
854 if (aP.Z()-ZX > Precision::Confusion()) {
861 if (Abs(aP.X()) - theR2 > Precision::Confusion()) {
863 if (aP.Z() - ZY > Precision::Confusion()) {
880 P1 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP1));
881 P2 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP2));
882 P3 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP3));
883 P4 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP4));
885 Handle(GEOM_Object) Cote_1 = myBasicOperations->MakeLineTwoPnt(P1, vi1);
886 if (Cote_1.IsNull()) {
887 SetErrorCode("Impossible to build edge in thickness");
890 Cote_1->GetLastFunction()->SetDescription("");
892 Handle(GEOM_Object) Cote_2 = myBasicOperations->MakeLineTwoPnt(vi2, P3);
893 if (Cote_2.IsNull()) {
894 SetErrorCode("Impossible to build edge in thickness");
897 Cote_2->GetLastFunction()->SetDescription("");
899 // edge_chan_princ = arete du chanfrein (ou raccord) sur le tuyau principal
900 // edge_chan_inc = arete du chanfrein (ou raccord) sur le tuyau incident
901 // std::cerr << "Getting chamfer edge on main pipe" << std::endl;
902 Handle(GEOM_Object) edge_chan_princ = myBlocksOperations->GetEdge(theShape, P1, P3);
903 if (edge_chan_princ.IsNull()) {
904 SetErrorCode("Impossible to find edge on main pipe");
907 edge_chan_princ->GetLastFunction()->SetDescription("");
909 Handle(GEOM_Object) edge_chan_inc = myBlocksOperations->GetEdge(theShape, P2, P4);
910 if (edge_chan_inc.IsNull()) {
911 SetErrorCode("Impossible to find edge on incident pipe");
914 edge_chan_inc->GetLastFunction()->SetDescription("");
916 std::list<Handle(GEOM_Object)> edgeList1;
917 edgeList1.push_back(edge_chan_princ);
918 edgeList1.push_back(Cote_1);
919 edgeList1.push_back(arete_intersect_int);
920 edgeList1.push_back(Cote_2);
922 // std::cerr << "Creating wire 1" << std::endl;
923 wire_t = myShapesOperations->MakeWire(edgeList1, 1e-7);
924 if (wire_t.IsNull()) {
925 SetErrorCode("Impossible to build wire");
928 wire_t->GetLastFunction()->SetDescription("");
930 // std::cerr << "Creating face 1" << std::endl;
931 face_t = myShapesOperations->MakeFace(wire_t, false);
932 if (face_t.IsNull()) {
933 SetErrorCode("Impossible to build face");
936 face_t->GetLastFunction()->SetDescription("");
937 theShapes.push_back(face_t);
939 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(P2->GetValue()));
940 gp_Pnt aP5 = BRep_Tool::Pnt(TopoDS::Vertex(vi1->GetValue()));
941 double deltaZ = aP2.Z() - aP5.Z();
942 // std::cerr << "Creating new point from vi1 with deltaZ = " << deltaZ << std::endl;
943 Handle(GEOM_Object) P5bis = myTransformOperations->TranslateDXDYDZCopy(vi1, 0, 0, deltaZ);
944 if (P5bis.IsNull()) {
945 SetErrorCode("Impossible to translate vertex");
948 P5bis->GetLastFunction()->SetDescription("");
950 gp_Pnt aP4 = BRep_Tool::Pnt(TopoDS::Vertex(P4->GetValue()));
951 gp_Pnt aP6 = BRep_Tool::Pnt(TopoDS::Vertex(vi2->GetValue()));
952 deltaZ = aP4.Z() - aP6.Z();
953 // std::cerr << "Creating new point from vi2 with deltaZ = " << deltaZ << std::endl;
954 Handle(GEOM_Object) P6bis = myTransformOperations->TranslateDXDYDZCopy(vi2, 0, 0, deltaZ);
955 if (P6bis.IsNull()) {
956 SetErrorCode("Impossible to translate vertex");
959 P6bis->GetLastFunction()->SetDescription("");
961 // std::cerr << "Creating new line 1 from 2 previous points" << std::endl;
962 Handle(GEOM_Object) Cote_3 = myBasicOperations->MakeLineTwoPnt(P5bis, P2);
963 if (Cote_3.IsNull()) {
964 SetErrorCode("Impossible to build edge in thickness");
967 Cote_3->GetLastFunction()->SetDescription("");
969 // std::cerr << "Creating new line 2 from 2 previous points" << std::endl;
970 Handle(GEOM_Object) Cote_4 = myBasicOperations->MakeLineTwoPnt(P6bis, P4);
971 if (Cote_4.IsNull()) {
972 SetErrorCode("Impossible to build edge in thickness");
975 Cote_4->GetLastFunction()->SetDescription("");
977 // std::cerr << "Creating new line 3 from 2 previous points" << std::endl;
978 Handle(GEOM_Object) Cote_5 = myBasicOperations->MakeLineTwoPnt(P5bis, P6bis);
979 if (Cote_4.IsNull()) {
980 SetErrorCode("Impossible to build edge in thickness");
983 Cote_5->GetLastFunction()->SetDescription("");
985 //std::list<Handle(GEOM_Object)> edgeList2;
986 //edgeList2.push_back(edge_chan_inc);
987 //edgeList2.push_back(Cote_3);
988 //edgeList2.push_back(Cote_5);
989 //edgeList2.push_back(Cote_4);
990 // std::cerr << "Creating wire 2" << std::endl;
991 //wire_t2 = myShapesOperations->MakeWire(edgeList2, 1e-7);
992 //if (wire_t2.IsNull()) {
993 // SetErrorCode("Impossible to build wire");
996 //wire_t2->GetLastFunction()->SetDescription("");
997 // std::cerr << "Creating face 2" << std::endl;
998 //face_t2 = myShapesOperations->MakeFace(wire_t2, false);
999 face_t2 = my3DPrimOperations->MakePrismVecH(edge_chan_inc, Cote_4, - 2.0*theR2);
1000 if (face_t2.IsNull()) {
1001 SetErrorCode("Impossible to build face");
1004 face_t2->GetLastFunction()->SetDescription("");
1005 theShapes.push_back(face_t2);
1009 Handle(GEOM_Object) aP0 = myBasicOperations->MakePointXYZ(0, 0, 0);
1010 Handle(GEOM_Object) aVZ = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
1011 Handle(GEOM_Object) aVXZ = myBasicOperations->MakeVectorDXDYDZ(aR1Ext, 0, 0.5*(theL1+theVertCylinderRadius));
1012 Handle(GEOM_Object) aPlnOZ = myBasicOperations->MakePlanePntVec(aP0, aVZ, aSize);
1013 Handle(GEOM_Object) aPlnOXZ = myBasicOperations->MakePlanePntVec(aP0, aVXZ, aSize);
1014 aP0->GetLastFunction()->SetDescription("");
1015 aVZ->GetLastFunction()->SetDescription("");
1016 aVXZ->GetLastFunction()->SetDescription("");
1017 aPlnOZ->GetLastFunction()->SetDescription("");
1018 aPlnOXZ->GetLastFunction()->SetDescription("");
1019 theShapes.push_back(aPlnOZ);
1020 theShapes.push_back(aPlnOXZ);
1023 Handle(TColStd_HSequenceOfTransient) partitionShapes = new TColStd_HSequenceOfTransient;
1024 Handle(TColStd_HSequenceOfTransient) theTools = new TColStd_HSequenceOfTransient;
1025 Handle(TColStd_HSequenceOfTransient) theKeepInside = new TColStd_HSequenceOfTransient;
1026 Handle(TColStd_HSequenceOfTransient) theRemoveInside = new TColStd_HSequenceOfTransient;
1027 Handle(TColStd_HArray1OfInteger) theMaterials;
1028 partitionShapes->Append(theShape);
1029 theTools->Append(aPlnOZ);
1030 if (Abs(aR1Ext - aR2Ext) > Precision::Confusion() )
1031 theTools->Append(aPlnOXZ);
1032 theTools->Append(face_t);
1034 theTools->Append(face_t2);
1036 Te3 = myBooleanOperations->MakePartition
1037 (partitionShapes, theTools, theKeepInside, theRemoveInside,
1038 TopAbs_SOLID, false, theMaterials, 0, false);
1040 SetErrorCode("Impossible to build partition of TShape");
1043 Te3->GetLastFunction()->SetDescription("");
1045 // Last verification: result should be a block
1046 std::list<GEOMImpl_IBlocksOperations::BCError> errList;
1047 if (!myBlocksOperations->CheckCompoundOfBlocks(Te3,errList)) {
1048 SetErrorCode("TShape is not a compound of block");
1052 // // BEGIN Compound of created shapes - Only for debug purpose
1053 // theShapes.clear();
1054 // theShapes.push_back(theShape);
1055 // theShapes.push_back(aPlnOZ);
1056 // if (Abs(aR1Ext - aR2Ext) > Precision::Confusion() )
1057 // theShapes.push_back(aPlnOXZ);
1058 // theShapes.push_back(face_t);
1060 // theShapes.push_back(face_t2);
1062 // Handle(GEOM_Object) aCompound = myShapesOperations->MakeCompound(theShapes);
1063 // TopoDS_Shape aCompoundShape = aCompound->GetValue();
1064 // theShape->GetLastFunction()->SetValue(aCompoundShape);
1065 // // END Compound of created shapes - Only for debug purpose
1067 TopoDS_Shape aShape = Te3->GetValue();
1068 theShape->GetLastFunction()->SetValue(aShape);
1069 } catch (Standard_Failure) {
1070 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1071 SetErrorCode(aFail->GetMessageString());
1079 // Mirror and glue faces
1080 bool GEOMImpl_IAdvancedOperations::MakePipeTShapeMirrorAndGlue(Handle(GEOM_Object) theShape,
1081 double theR1, double theW1, double theL1,
1082 double theR2, double theW2, double theL2)
1087 double aSize = 2*(theL1 + theL2);
1088 double aR1Ext = theR1 + theW1;
1091 Handle(GEOM_Object) aP0 = myBasicOperations->MakePointXYZ(0, 0, 0);
1092 aP0->GetLastFunction()->SetDescription("");
1093 Handle(GEOM_Object) aVX = myBasicOperations->MakeVectorDXDYDZ(1, 0, 0);
1094 Handle(GEOM_Object) aVY = myBasicOperations->MakeVectorDXDYDZ(0, 1, 0);
1095 aVX->GetLastFunction()->SetDescription("");
1096 aVY->GetLastFunction()->SetDescription("");
1097 Handle(GEOM_Object) aPlane_OX = myBasicOperations->MakePlanePntVec(aP0, aVX, 2*(aR1Ext + theL2));
1098 Handle(GEOM_Object) aPlane_OY = myBasicOperations->MakePlanePntVec(aP0, aVY, aSize);
1099 aPlane_OX->GetLastFunction()->SetDescription("");
1100 aPlane_OY->GetLastFunction()->SetDescription("");
1102 Handle(GEOM_Object) Te4 = myTransformOperations->MirrorPlaneCopy(theShape, aPlane_OX);
1104 SetErrorCode("Impossible to build mirror of quarter TShape");
1108 Handle(GEOM_Object) Te5 = myTransformOperations->MirrorPlaneCopy(theShape, aPlane_OY);
1110 SetErrorCode("Impossible to build mirror of half TShape");
1114 Handle(GEOM_Object) Te6 = myTransformOperations->MirrorPlaneCopy(Te4, aPlane_OY);
1116 SetErrorCode("Impossible to build mirror of half TShape");
1120 std::list<Handle(GEOM_Object)> aShapesList;
1121 aShapesList.push_back(theShape);
1122 aShapesList.push_back(Te4);
1123 aShapesList.push_back(Te5);
1124 aShapesList.push_back(Te6);
1125 Handle(GEOM_Object) Te7 = myShapesOperations->MakeCompound(aShapesList);
1127 SetErrorCode("Impossible to build compound");
1131 Handle(GEOM_Object) Te8 = myShapesOperations->MakeGlueFaces(Te7, 1e-7, true);
1133 SetErrorCode("Impossible to glue faces of TShape");
1137 TopoDS_Shape aShape = Te8->GetValue();
1139 theShape->GetLastFunction()->SetValue(aShape);
1141 Te4->GetLastFunction()->SetDescription("");
1142 Te5->GetLastFunction()->SetDescription("");
1143 Te6->GetLastFunction()->SetDescription("");
1144 Te7->GetLastFunction()->SetDescription("");
1145 Te8->GetLastFunction()->SetDescription("");
1151 //=============================================================================
1154 * \brief Create a T-shape object with specified caracteristics for the main and
1155 * the incident pipes (radius, width, half-length).
1156 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1157 * \param theR1 Internal radius of main pipe
1158 * \param theW1 Width of main pipe
1159 * \param theL1 Half-length of main pipe
1160 * \param theR2 Internal radius of incident pipe (R2 < R1)
1161 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1162 * \param theL2 Half-length of incident pipe
1163 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1164 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1166 //=============================================================================
1167 Handle(TColStd_HSequenceOfTransient)
1168 GEOMImpl_IAdvancedOperations::MakePipeTShape(double theR1, double theW1, double theL1,
1169 double theR2, double theW2, double theL2,
1172 MESSAGE("GEOMImpl_IAdvancedOperations::MakePipeTShape");
1175 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1177 //Add a new shape function with parameters
1178 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_BASIC);
1179 if (aFunction.IsNull()) return NULL;
1181 //Check if the function is set correctly
1182 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1184 GEOMImpl_IPipeTShape aData(aFunction);
1192 aData.SetHexMesh(theHexMesh);
1194 //Compute the resulting value
1196 #if OCC_VERSION_LARGE > 0x06010000
1199 if (!GetSolver()->ComputeFunction(aFunction)) {
1200 SetErrorCode("TShape driver failed");
1204 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1206 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1209 } catch (Standard_Failure) {
1210 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1211 SetErrorCode(aFail->GetMessageString());
1216 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1217 aSeq->Append(aShape);
1221 * Get the groups: BEGIN
1224 if (!MakeGroups(aShape, TSHAPE_BASIC, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1227 catch (Standard_Failure) {
1228 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1229 SetErrorCode(aFail->GetMessageString());
1233 TCollection_AsciiString aListRes, anEntry;
1234 // Iterate over the sequence aSeq
1235 Standard_Integer aNbGroups = aSeq->Length();
1236 Standard_Integer i = 2;
1237 for (; i <= aNbGroups; i++) {
1238 Handle(Standard_Transient) anItem = aSeq->Value(i);
1239 if (anItem.IsNull()) continue;
1240 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1241 if (aGroup.IsNull()) continue;
1242 //Make a Python command
1243 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1244 aListRes += anEntry + ", ";
1247 aListRes.Trunc(aListRes.Length() - 2);
1249 //Make a Python command
1250 GEOM::TPythonDump(aFunction)
1251 << "[" << aShape << ", " << aListRes.ToCString() << "] = geompy.MakePipeTShape("
1252 << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", "
1253 << theHexMesh << ")";
1256 * Get the groups: END
1259 //Make a Python command
1260 GEOM::TPythonDump(aFunction)
1261 << "[" << aShape << "] = geompy.MakePipeTShape(" << theR1 << ", " << theW1 << ", "
1262 << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theHexMesh << ")";
1270 //=============================================================================
1272 * MakePipeTShapeWithPosition
1273 * Create a T-shape object with specified caracteristics for the main and
1274 * the incident pipes (radius, width, half-length).
1275 * The extremities of the main pipe are located on junctions points P1 and P2.
1276 * The extremity of the incident pipe is located on junction point P3.
1277 * \param theR1 Internal radius of main pipe
1278 * \param theW1 Width of main pipe
1279 * \param theL1 Half-length of main pipe
1280 * \param theR2 Internal radius of incident pipe (R2 < R1)
1281 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1282 * \param theL2 Half-length of incident pipe
1283 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1284 * \param theP1 1st junction point of main pipe
1285 * \param theP2 2nd junction point of main pipe
1286 * \param theP3 Junction point of incident pipe
1287 * \return List of GEOM_Objects, containing the created shape and propagation groups..
1289 //=============================================================================
1290 Handle(TColStd_HSequenceOfTransient)
1291 GEOMImpl_IAdvancedOperations::MakePipeTShapeWithPosition(double theR1, double theW1, double theL1,
1292 double theR2, double theW2, double theL2,
1294 Handle(GEOM_Object) theP1,
1295 Handle(GEOM_Object) theP2,
1296 Handle(GEOM_Object) theP3)
1300 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1304 //Add a new shape function with parameters
1305 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_BASIC);
1306 if (aFunction.IsNull()) return NULL;
1308 //Check if the function is set correctly
1309 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1311 // Check new position
1312 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1316 GEOMImpl_IPipeTShape aData(aFunction);
1324 aData.SetHexMesh(theHexMesh);
1326 //Compute the resulting value
1328 #if OCC_VERSION_LARGE > 0x06010000
1331 if (!GetSolver()->ComputeFunction(aFunction)) {
1332 SetErrorCode("TShape driver failed");
1335 } catch (Standard_Failure) {
1336 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1337 SetErrorCode(aFail->GetMessageString());
1342 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1344 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1348 TopoDS_Shape Te = aShape->GetValue();
1351 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
1352 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
1353 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
1354 aFunction->SetValue(aTrsf_Shape);
1355 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1356 aSeq->Append(aShape);
1360 // Get the groups: BEGIN
1363 if (!MakeGroups(aShape,TSHAPE_BASIC, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf)) {
1367 catch (Standard_Failure) {
1368 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1369 SetErrorCode(aFail->GetMessageString());
1373 TCollection_AsciiString aListRes, anEntry;
1374 // Iterate over the sequence aSeq
1375 Standard_Integer aNbGroups = aSeq->Length();
1376 Standard_Integer i = 2;
1377 for (; i <= aNbGroups; i++) {
1378 Handle(Standard_Transient) anItem = aSeq->Value(i);
1379 if (anItem.IsNull()) continue;
1380 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1381 if (aGroup.IsNull()) continue;
1382 //Make a Python command
1383 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1384 aListRes += anEntry + ", ";
1387 aListRes.Trunc(aListRes.Length() - 2);
1389 //Make a Python command
1390 GEOM::TPythonDump(aFunction)
1391 << "[" << aShape << ", " << aListRes.ToCString() << "] = geompy.MakePipeTShape("
1392 << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", "
1393 << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
1396 // Get the groups: END
1400 //Make a Python command
1401 GEOM::TPythonDump(aFunction)
1402 << "[" << aShape << "] = geompy.MakePipeTShape(" << theR1 << ", " << theW1 << ", "
1403 << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theHexMesh << ", " << theP1
1404 << ", " << theP2 << ", " << theP3 << ")";
1412 //=============================================================================
1414 * MakePipeTShapeChamfer
1415 * Create a T-shape object with specified caracteristics for the main and
1416 * the incident pipes (radius, width, half-length). A chamfer is created
1417 * on the junction of the pipes.
1418 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1419 * \param theR1 Internal radius of main pipe
1420 * \param theW1 Width of main pipe
1421 * \param theL1 Half-length of main pipe
1422 * \param theR2 Internal radius of incident pipe (R2 < R1)
1423 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1424 * \param theL2 Half-length of incident pipe
1425 * \param theH Height of chamfer.
1426 * \param theW Width of chamfer.
1427 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1428 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1430 //=============================================================================
1431 Handle(TColStd_HSequenceOfTransient)
1432 GEOMImpl_IAdvancedOperations::MakePipeTShapeChamfer(double theR1, double theW1, double theL1,
1433 double theR2, double theW2, double theL2,
1434 double theH, double theW,
1439 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1440 //Add a new shape function with parameters
1441 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_CHAMFER);
1442 if (aFunction.IsNull()) return NULL;
1444 //Check if the function is set correctly
1445 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1447 GEOMImpl_IPipeTShape aData(aFunction);
1457 aData.SetHexMesh(theHexMesh);
1459 //Compute the resulting value
1461 #if OCC_VERSION_LARGE > 0x06010000
1464 if (!GetSolver()->ComputeFunction(aFunction)) {
1465 SetErrorCode("TShape driver failed");
1468 } catch (Standard_Failure) {
1469 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1470 SetErrorCode(aFail->GetMessageString());
1475 TopoDS_Shape aShapeShape = aShape->GetValue();
1476 TopTools_IndexedMapOfShape anEdgesIndices;
1477 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1478 // Common edges on external cylinders
1479 Handle(GEOM_Object) box_e;
1481 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1484 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1486 box_e->GetLastFunction()->SetDescription("");
1487 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1488 box_e->GetLastFunction()->SetDescription("");
1490 Handle(TColStd_HSequenceOfInteger) edges_e =
1491 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1492 box_e->GetLastFunction()->SetDescription("");
1494 if (edges_e.IsNull() || edges_e->Length() == 0) {
1495 SetErrorCode("External edges not found");
1498 int nbEdgesInChamfer = 0;
1499 std::list<int> theEdges;
1500 for (int i=1; i<=edges_e->Length();i++) {
1501 int edgeID = edges_e->Value(i);
1502 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1503 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1507 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1508 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1509 nbEdgesInChamfer ++;
1510 theEdges.push_back(edgeID);
1514 if (theHexMesh && nbEdgesInChamfer == 1)
1517 Handle(GEOM_Object) aChamfer;
1519 aChamfer = myLocalOperations->MakeChamferEdges(aShape, theW, theH, theEdges);
1521 catch (Standard_Failure) {
1522 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1523 SetErrorCode(aFail->GetMessageString());
1526 if (aChamfer.IsNull()) {
1527 SetErrorCode("Chamfer can not be computed on the given shape with the given parameters");
1530 aChamfer->GetLastFunction()->SetDescription("");
1532 TopoDS_Shape aChamferShape = aChamfer->GetValue();
1533 aFunction->SetValue(aChamferShape);
1536 // bool doMesh = false;
1539 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, 0, false)) {
1540 MESSAGE("PipeTShape partition failed");
1544 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2)) {
1545 MESSAGE("PipeTShape mirrors and glue failed");
1551 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1552 aSeq->Append(aShape);
1557 // Get the groups: BEGIN
1559 //if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf())) {
1560 // //Make a Python command
1561 // GEOM::TPythonDump(aFunction)
1562 // << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1563 // << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1564 // << ", " << theHexMesh << ")";
1568 if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1571 catch (Standard_Failure) {
1572 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1573 SetErrorCode(aFail->GetMessageString());
1577 TCollection_AsciiString aListRes, anEntry;
1578 // Iterate over the sequence aSeq
1579 Standard_Integer aNbGroups = aSeq->Length();
1580 Standard_Integer i = 2;
1581 for (; i <= aNbGroups; i++) {
1582 Handle(Standard_Transient) anItem = aSeq->Value(i);
1583 if (anItem.IsNull()) continue;
1584 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1585 if (aGroup.IsNull()) continue;
1586 //Make a Python command
1587 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1588 aListRes += anEntry + ", ";
1591 aListRes.Trunc(aListRes.Length() - 2);
1593 //Make a Python command
1594 GEOM::TPythonDump(aFunction)
1595 << "[" << aShape << ", " << aListRes.ToCString()
1596 << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1597 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW << ", " << theHexMesh << ")";
1601 // Get the groups: END
1604 //Make a Python command
1605 GEOM::TPythonDump(aFunction)
1606 << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1607 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1608 << ", " << theHexMesh << ")";
1616 //=============================================================================
1618 * MakePipeTShapeChamferWithPosition
1619 * Create a T-shape object with specified caracteristics for the main and
1620 * the incident pipes (radius, width, half-length). A chamfer is created
1621 * on the junction of the pipes.
1622 * The extremities of the main pipe are located on junctions points P1 and P2.
1623 * The extremity of the incident pipe is located on junction point P3.
1624 * \param theR1 Internal radius of main pipe
1625 * \param theW1 Width of main pipe
1626 * \param theL1 Half-length of main pipe
1627 * \param theR2 Internal radius of incident pipe (R2 < R1)
1628 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1629 * \param theL2 Half-length of incident pipe
1630 * \param theH Height of chamfer.
1631 * \param theW Width of chamfer.
1632 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1633 * \param theP1 1st junction point of main pipe
1634 * \param theP2 2nd junction point of main pipe
1635 * \param theP3 Junction point of incident pipe
1636 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1638 //=============================================================================
1639 Handle(TColStd_HSequenceOfTransient)
1640 GEOMImpl_IAdvancedOperations::MakePipeTShapeChamferWithPosition(double theR1, double theW1, double theL1,
1641 double theR2, double theW2, double theL2,
1642 double theH, double theW,
1644 Handle(GEOM_Object) theP1,
1645 Handle(GEOM_Object) theP2,
1646 Handle(GEOM_Object) theP3)
1650 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1651 //Add a new shape function with parameters
1652 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_CHAMFER);
1653 if (aFunction.IsNull()) return NULL;
1655 //Check if the function is set correctly
1656 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1658 // Check new position
1659 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1663 GEOMImpl_IPipeTShape aData(aFunction);
1673 aData.SetHexMesh(theHexMesh);
1675 //Compute the resulting value
1677 #if OCC_VERSION_LARGE > 0x06010000
1680 if (!GetSolver()->ComputeFunction(aFunction)) {
1681 SetErrorCode("TShape driver failed");
1684 } catch (Standard_Failure) {
1685 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1686 SetErrorCode(aFail->GetMessageString());
1691 TopoDS_Shape aShapeShape = aShape->GetValue();
1692 TopTools_IndexedMapOfShape anEdgesIndices;
1693 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1694 // Common edges on external cylinders
1695 Handle(GEOM_Object) box_e;
1697 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1700 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1702 box_e->GetLastFunction()->SetDescription("");
1703 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1704 box_e->GetLastFunction()->SetDescription("");
1706 Handle(TColStd_HSequenceOfInteger) edges_e =
1707 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1708 box_e->GetLastFunction()->SetDescription("");
1710 if (edges_e.IsNull() || edges_e->Length() == 0) {
1711 SetErrorCode("External edges not found");
1714 int nbEdgesInChamfer = 0;
1715 std::list<int> theEdges;
1716 for (int i=1; i<=edges_e->Length();i++) {
1717 int edgeID = edges_e->Value(i);
1718 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1719 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1721 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1722 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1723 nbEdgesInChamfer ++;
1724 theEdges.push_back(edgeID);
1728 if (theHexMesh && nbEdgesInChamfer == 1)
1731 Handle(GEOM_Object) aChamfer;
1733 aChamfer = myLocalOperations->MakeChamferEdges(aShape, theW, theH, theEdges);
1735 catch (Standard_Failure) {
1736 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1737 SetErrorCode(aFail->GetMessageString());
1740 if (aChamfer.IsNull()) {
1741 SetErrorCode("Chamfer can not be computed on the given shape with the given parameters");
1744 aChamfer->GetLastFunction()->SetDescription("");
1746 TopoDS_Shape aChamferShape = aChamfer->GetValue();
1747 aFunction->SetValue(aChamferShape);
1751 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, 0, false))
1753 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1757 TopoDS_Shape Te = aShape->GetValue();
1760 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
1761 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
1762 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
1763 aFunction->SetValue(aTrsf_Shape);
1764 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1765 aSeq->Append(aShape);
1768 * Get the groups: BEGIN
1771 if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf))
1774 catch (Standard_Failure) {
1775 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1776 SetErrorCode(aFail->GetMessageString());
1780 TCollection_AsciiString aListRes, anEntry;
1781 // Iterate over the sequence aSeq
1782 Standard_Integer aNbGroups = aSeq->Length();
1783 Standard_Integer i = 2;
1784 for (; i <= aNbGroups; i++) {
1785 Handle(Standard_Transient) anItem = aSeq->Value(i);
1786 if (anItem.IsNull()) continue;
1787 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1788 if (aGroup.IsNull()) continue;
1789 //Make a Python command
1790 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1791 aListRes += anEntry + ", ";
1794 aListRes.Trunc(aListRes.Length() - 2);
1796 //Make a Python command
1797 GEOM::TPythonDump(aFunction)
1798 << "[" << aShape << ", " << aListRes.ToCString()
1799 << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1800 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW << ", " << theHexMesh << ", "
1801 << theP1 << ", " << theP2 << ", " << theP3 << ")";
1804 * Get the groups: END
1807 //Make a Python command
1808 GEOM::TPythonDump(aFunction)
1809 << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1810 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1811 << ", " << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
1819 //=============================================================================
1821 * MakePipeTShapeFillet
1822 * Create a T-shape object with specified caracteristics for the main and
1823 * the incident pipes (radius, width, half-length). A fillet is created
1824 * on the junction of the pipes.
1825 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1826 * \param theR1 Internal radius of main pipe
1827 * \param theW1 Width of main pipe
1828 * \param theL1 Half-length of main pipe
1829 * \param theR2 Internal radius of incident pipe (R2 < R1)
1830 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1831 * \param theL2 Half-length of incident pipe
1832 * \param theRF Radius of curvature of fillet.
1833 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1834 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1836 //=============================================================================
1837 Handle(TColStd_HSequenceOfTransient)
1838 GEOMImpl_IAdvancedOperations::MakePipeTShapeFillet(double theR1, double theW1, double theL1,
1839 double theR2, double theW2, double theL2,
1840 double theRF, bool theHexMesh)
1844 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1845 //Add a new shape function with parameters
1846 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_FILLET);
1847 if (aFunction.IsNull()) return NULL;
1849 //Check if the function is set correctly
1850 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1852 GEOMImpl_IPipeTShape aData(aFunction);
1861 aData.SetHexMesh(theHexMesh);
1863 //Compute the resulting value
1865 #if OCC_VERSION_LARGE > 0x06010000
1868 if (!GetSolver()->ComputeFunction(aFunction)) {
1869 SetErrorCode("TShape driver failed");
1872 } catch (Standard_Failure) {
1873 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1874 SetErrorCode(aFail->GetMessageString());
1879 TopoDS_Shape aShapeShape = aShape->GetValue();
1880 TopTools_IndexedMapOfShape anEdgesIndices;
1881 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1882 // Common edges on external cylinders
1883 Handle(GEOM_Object) box_e;
1885 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1888 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1890 box_e->GetLastFunction()->SetDescription("");
1891 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1892 box_e->GetLastFunction()->SetDescription("");
1894 Handle(TColStd_HSequenceOfInteger) edges_e =
1895 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1896 box_e->GetLastFunction()->SetDescription("");
1898 if (edges_e.IsNull() || edges_e->Length() == 0) {
1899 SetErrorCode("External edges not found");
1902 int nbEdgesInFillet = 0;
1903 std::list<int> theEdges;
1904 for (int i=1; i<=edges_e->Length();i++) {
1905 int edgeID = edges_e->Value(i);
1906 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1907 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1909 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1910 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1912 theEdges.push_back(edgeID);
1916 if (theHexMesh && nbEdgesInFillet == 1)
1920 Handle(GEOM_Object) aFillet;
1922 aFillet = myLocalOperations->MakeFilletEdges(aShape, theRF, theEdges);
1924 catch (Standard_Failure) {
1925 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1926 SetErrorCode(aFail->GetMessageString());
1929 if (aFillet.IsNull()) {
1930 //SetErrorCode("Fillet can not be computed on the given shape with the given parameters");
1931 SetErrorCode(myLocalOperations->GetErrorCode());
1934 aFillet->GetLastFunction()->SetDescription("");
1936 TopoDS_Shape aFilletShape = aFillet->GetValue();
1937 aFunction->SetValue(aFilletShape);
1940 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - BEGIN (1)
1941 // the following block, when enabled, leads to partitioning problems
1943 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - END (1)
1944 // BEGIN: Limit tolerances (debug)
1945 Handle(GEOM_Object) aCorr1 = myHealingOperations->LimitTolerance(aShape, 1e-07);
1946 TopoDS_Shape aCorr1Shape = aCorr1->GetValue();
1947 aShape->GetLastFunction()->SetValue(aCorr1Shape);
1948 aCorr1->GetLastFunction()->SetDescription("");
1949 // END: Limit tolerances (debug)
1950 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - BEGIN (2)
1952 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - END (2)
1955 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, 0, 0, theRF, false))
1957 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1961 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1962 aSeq->Append(aShape);
1965 * Get the groups: BEGIN
1968 if (!MakeGroups(aShape, TSHAPE_FILLET, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1971 catch (Standard_Failure) {
1972 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1973 SetErrorCode(aFail->GetMessageString());
1977 TCollection_AsciiString aListRes, anEntry;
1978 // Iterate over the sequence aSeq
1979 Standard_Integer aNbGroups = aSeq->Length();
1980 Standard_Integer i = 2;
1981 for (; i <= aNbGroups; i++) {
1982 Handle(Standard_Transient) anItem = aSeq->Value(i);
1983 if (anItem.IsNull()) continue;
1984 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1985 if (aGroup.IsNull()) continue;
1986 //Make a Python command
1987 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1988 aListRes += anEntry + ", ";
1991 aListRes.Trunc(aListRes.Length() - 2);
1993 //Make a Python command
1994 GEOM::TPythonDump(aFunction)
1995 << "[" << aShape << ", " << aListRes.ToCString()
1996 << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1997 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", " << theHexMesh << ")";
2000 * Get the groups: END
2003 //Make a Python command
2004 GEOM::TPythonDump(aFunction)
2005 << "[" << aShape << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1
2006 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", "
2007 << theHexMesh << ")";
2015 //=============================================================================
2017 * MakePipeTShapeFilletWithPosition
2018 * \brief Create a T-shape object with specified caracteristics for the main and
2019 * the incident pipes (radius, width, half-length). A fillet is created
2020 * on the junction of the pipes.
2021 * The extremities of the main pipe are located on junctions points P1 and P2.
2022 * The extremity of the incident pipe is located on junction point P3.
2023 * \param theR1 Internal radius of main pipe
2024 * \param theW1 Width of main pipe
2025 * \param theL1 Half-length of main pipe
2026 * \param theR2 Internal radius of incident pipe (R2 < R1)
2027 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
2028 * \param theL2 Half-length of incident pipe
2029 * \param theRF Radius of curvature of fillet
2030 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
2031 * \param theP1 1st junction point of main pipe
2032 * \param theP2 2nd junction point of main pipe
2033 * \param theP3 Junction point of incident pipe
2034 * \return List of GEOM_Objects, containing the created shape and propagation groups.
2036 //=============================================================================
2037 Handle(TColStd_HSequenceOfTransient)
2038 GEOMImpl_IAdvancedOperations::MakePipeTShapeFilletWithPosition(double theR1, double theW1, double theL1,
2039 double theR2, double theW2, double theL2,
2040 double theRF, bool theHexMesh,
2041 Handle(GEOM_Object) theP1,
2042 Handle(GEOM_Object) theP2,
2043 Handle(GEOM_Object) theP3)
2047 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
2048 //Add a new shape function with parameters
2049 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_FILLET);
2050 if (aFunction.IsNull()) return NULL;
2052 //Check if the function is set correctly
2053 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
2055 // Check new position
2056 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
2060 GEOMImpl_IPipeTShape aData(aFunction);
2069 aData.SetHexMesh(theHexMesh);
2071 //Compute the resulting value
2073 #if OCC_VERSION_LARGE > 0x06010000
2076 if (!GetSolver()->ComputeFunction(aFunction)) {
2077 SetErrorCode("TShape driver failed");
2080 } catch (Standard_Failure) {
2081 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2082 SetErrorCode(aFail->GetMessageString());
2087 TopoDS_Shape aShapeShape = aShape->GetValue();
2088 TopTools_IndexedMapOfShape anEdgesIndices;
2089 TopExp::MapShapes(aShapeShape, anEdgesIndices);
2090 // Common edges on external cylinders
2091 Handle(GEOM_Object) box_e;
2093 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
2096 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
2098 box_e->GetLastFunction()->SetDescription("");
2099 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
2100 box_e->GetLastFunction()->SetDescription("");
2102 Handle(TColStd_HSequenceOfInteger) edges_e =
2103 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
2104 box_e->GetLastFunction()->SetDescription("");
2106 if (edges_e.IsNull() || edges_e->Length() == 0) {
2107 SetErrorCode("External edges not found");
2110 int nbEdgesInFillet = 0;
2111 std::list<int> theEdges;
2112 for (int i=1; i<=edges_e->Length();i++) {
2113 int edgeID = edges_e->Value(i);
2114 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
2115 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
2117 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
2118 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
2120 theEdges.push_back(edgeID);
2124 if (theHexMesh && nbEdgesInFillet == 1)
2128 Handle(GEOM_Object) aFillet;
2130 aFillet = myLocalOperations->MakeFilletEdges(aShape, theRF, theEdges);
2132 catch (Standard_Failure) {
2133 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2134 SetErrorCode(aFail->GetMessageString());
2137 if (aFillet.IsNull()) {
2138 SetErrorCode("Fillet can not be computed on the given shape with the given parameters");
2141 aFillet->GetLastFunction()->SetDescription("");
2143 TopoDS_Shape aFilletShape = aFillet->GetValue();
2144 aFunction->SetValue(aFilletShape);
2147 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - BEGIN (3)
2148 // the following block, when enabled, leads to partitioning problems
2150 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - END (3)
2151 // BEGIN: Limit tolerances (debug)
2152 Handle(GEOM_Object) aCorr1 = myHealingOperations->LimitTolerance(aShape, 1e-07);
2153 TopoDS_Shape aCorr1Shape = aCorr1->GetValue();
2154 aShape->GetLastFunction()->SetValue(aCorr1Shape);
2155 aCorr1->GetLastFunction()->SetDescription("");
2156 // END: Limit tolerances (debug)
2157 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - BEGIN (4)
2159 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - END (4)
2162 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, 0, 0, theRF, false))
2164 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
2168 TopoDS_Shape Te = aShape->GetValue();
2171 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
2172 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
2173 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
2174 aFunction->SetValue(aTrsf_Shape);
2175 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
2176 aSeq->Append(aShape);
2179 * Get the groups: BEGIN
2182 if (!MakeGroups(aShape, TSHAPE_FILLET, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf))
2185 catch (Standard_Failure) {
2186 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2187 SetErrorCode(aFail->GetMessageString());
2191 TCollection_AsciiString aListRes, anEntry;
2192 // Iterate over the sequence aSeq
2193 Standard_Integer aNbGroups = aSeq->Length();
2194 Standard_Integer i = 2;
2195 for (; i <= aNbGroups; i++) {
2196 Handle(Standard_Transient) anItem = aSeq->Value(i);
2197 if (anItem.IsNull()) continue;
2198 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
2199 if (aGroup.IsNull()) continue;
2200 //Make a Python command
2201 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
2202 aListRes += anEntry + ", ";
2205 aListRes.Trunc(aListRes.Length() - 2);
2207 //Make a Python command
2208 GEOM::TPythonDump(aFunction)
2209 << "[" << aShape << ", " << aListRes.ToCString()
2210 << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
2211 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", " << theHexMesh << ", " << theP1 << ", "
2212 << theP2 << ", " << theP3 << ")";
2215 * Get the groups: END
2218 //Make a Python command
2219 GEOM::TPythonDump(aFunction)
2220 << "[" << aShape << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1
2221 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", "
2222 << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
2230 /*@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@*/