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 #include <GEOMImpl_DividedDiskDriver.hxx>
49 #include <GEOMImpl_IDividedDisk.hxx>
50 /*@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@*/
53 #include <TopExp_Explorer.hxx>
55 #include <TopoDS_Vertex.hxx>
56 #include <TopTools_IndexedMapOfShape.hxx>
62 #include <BRepBuilderAPI_Transform.hxx>
63 #include <BRep_Tool.hxx>
67 #include <TFunction_DriverTable.hxx>
68 #include <TFunction_Driver.hxx>
69 #include <TFunction_Logbook.hxx>
70 #include <TDF_Tool.hxx>
71 #include <Standard_Failure.hxx>
72 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
74 #define HALF_LENGTH_MAIN_PIPE "Main pipe half length" //"Tuyau principal - demi longueur"
75 #define HALF_LENGTH_INCIDENT_PIPE "Incident pipe half length" //"Tuyau incident - demi longueur"
76 #define CIRCULAR_QUARTER_PIPE "Circular quarter of pipe" //"Circulaire - quart de tuyau"
77 #define THICKNESS "Thickness" //"Epaisseur"
78 #define FLANGE "Flange" // "Collerette"
79 #define CHAMFER_OR_FILLET "Chamfer or fillet" //"Chanfrein ou Raccord"
80 #define JUNCTION_FACE_1 "Junction 1" //"Face de jonction 1"
81 #define JUNCTION_FACE_2 "Junction 2" //"Face de jonction 2"
82 #define JUNCTION_FACE_3 "Junction 3" //"Face de jonction 3"
84 //=============================================================================
88 //=============================================================================
89 GEOMImpl_IAdvancedOperations::GEOMImpl_IAdvancedOperations(GEOM_Engine* theEngine, int theDocID) :
90 GEOM_IOperations(theEngine, theDocID)
92 MESSAGE("GEOMImpl_IAdvancedOperations::GEOMImpl_IAdvancedOperations");
93 myBasicOperations = new GEOMImpl_IBasicOperations(GetEngine(), GetDocID());
94 myBooleanOperations = new GEOMImpl_IBooleanOperations(GetEngine(), GetDocID());
95 myShapesOperations = new GEOMImpl_IShapesOperations(GetEngine(), GetDocID());
96 myTransformOperations = new GEOMImpl_ITransformOperations(GetEngine(), GetDocID());
97 myBlocksOperations = new GEOMImpl_IBlocksOperations(GetEngine(), GetDocID());
98 my3DPrimOperations = new GEOMImpl_I3DPrimOperations(GetEngine(), GetDocID());
99 myLocalOperations = new GEOMImpl_ILocalOperations(GetEngine(), GetDocID());
100 myHealingOperations = new GEOMImpl_IHealingOperations(GetEngine(), GetDocID());
103 //=============================================================================
107 //=============================================================================
108 GEOMImpl_IAdvancedOperations::~GEOMImpl_IAdvancedOperations()
110 MESSAGE("GEOMImpl_IAdvancedOperations::~GEOMImpl_IAdvancedOperations");
111 delete myBasicOperations;
112 delete myBooleanOperations;
113 delete myShapesOperations;
114 delete myTransformOperations;
115 delete myBlocksOperations;
116 delete my3DPrimOperations;
117 delete myLocalOperations;
118 delete myHealingOperations;
121 //=============================================================================
125 //=============================================================================
126 gp_Trsf GEOMImpl_IAdvancedOperations::GetPositionTrsf(double theL1, double theL2,
127 Handle(GEOM_Object) theP1,
128 Handle(GEOM_Object) theP2,
129 Handle(GEOM_Object) theP3)
131 // Old Local Coordinates System oldLCS
133 gp_Pnt P1(-theL1, 0, 0);
134 gp_Pnt P2(theL1, 0, 0);
135 gp_Pnt P3(0, 0, theL2);
137 gp_Dir oldX(gp_Vec(P1, P2));
138 gp_Dir oldZ(gp_Vec(P0, P3));
139 gp_Ax3 oldLCS(P0, oldZ, oldX);
141 // New Local Coordinates System newLCS
142 double LocX, LocY, LocZ;
143 gp_Pnt newP1 = BRep_Tool::Pnt(TopoDS::Vertex(theP1->GetValue()));
144 gp_Pnt newP2 = BRep_Tool::Pnt(TopoDS::Vertex(theP2->GetValue()));
145 gp_Pnt newP3 = BRep_Tool::Pnt(TopoDS::Vertex(theP3->GetValue()));
146 LocX = (newP1.X() + newP2.X()) / 2.;
147 LocY = (newP1.Y() + newP2.Y()) / 2.;
148 LocZ = (newP1.Z() + newP2.Z()) / 2.;
149 gp_Pnt newO(LocX, LocY, LocZ);
151 gp_Dir newX(gp_Vec(newP1, newP2)); // P1P2 Vector
152 gp_Dir newZ(gp_Vec(newO, newP3)); // OP3 Vector
153 gp_Ax3 newLCS = gp_Ax3(newO, newZ, newX);
156 aTrsf.SetDisplacement(oldLCS, newLCS);
161 //=============================================================================
163 * CheckCompatiblePosition
166 //=============================================================================
167 bool GEOMImpl_IAdvancedOperations::CheckCompatiblePosition(double& theL1, double& theL2,
168 Handle(GEOM_Object) theP1,
169 Handle(GEOM_Object) theP2,
170 Handle(GEOM_Object) theP3,
174 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(theP1->GetValue()));
175 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(theP2->GetValue()));
176 gp_Pnt P3 = BRep_Tool::Pnt(TopoDS::Vertex(theP3->GetValue()));
178 double d12 = P1.Distance(P2);
179 double d13 = P1.Distance(P3);
180 double d23 = P2.Distance(P3);
181 // double d2 = newO.Distance(P3);
183 if (Abs(d12) <= Precision::Confusion()) {
184 SetErrorCode("Junctions points P1 and P2 are identical");
187 if (Abs(d13) <= Precision::Confusion()) {
188 SetErrorCode("Junctions points P1 and P3 are identical");
191 if (Abs(d23) <= Precision::Confusion()) {
192 SetErrorCode("Junctions points P2 and P3 are identical");
197 double newL1 = 0.5 * d12;
198 double newL2 = sqrt(pow(d13,2)-pow(newL1,2));
200 // theL1*(1-theTolerance) <= newL1 <= theL1*(1+theTolerance)
202 if (fabs(newL1 - theL1) > Precision::Approximation()) {
203 if ( (newL1 * (1 - theTolerance) -theL1 <= Precision::Approximation()) &&
204 (newL1 * (1 + theTolerance) -theL1 >= Precision::Approximation()) ) {
205 // std::cerr << "theL1 = newL1" << std::endl;
209 SetErrorCode("Dimension for main pipe (L1) is incompatible with new position");
215 // theL2*(1-theTolerance) <= newL2 <= theL2*(1+theTolerance)
217 if (fabs(newL2 - theL2) > Precision::Approximation()) {
218 if ( (newL2 * (1 - theTolerance) -theL2 <= Precision::Approximation()) &&
219 (newL2 * (1 + theTolerance) -theL2 >= Precision::Approximation()) ) {
223 SetErrorCode("Dimension for incident pipe (L2) is incompatible with new position");
233 //=============================================================================
235 * Generate the propagation groups of a Pipe T-Shape used for hexa mesh
237 //=============================================================================
238 bool GEOMImpl_IAdvancedOperations::MakeGroups(Handle(GEOM_Object) theShape, int shapeType,
239 double theR1, double theW1, double theL1,
240 double theR2, double theW2, double theL2,
241 Handle(TColStd_HSequenceOfTransient) theSeq,
246 if (theShape.IsNull()) return false;
248 TopoDS_Shape aShape = theShape->GetValue();
249 if (aShape.IsNull()) {
250 SetErrorCode("Shape is not defined");
254 gp_Trsf aTrsfInv = aTrsf.Inverted();
256 // int expectedGroups = 0;
257 // if (shapeType == TSHAPE_BASIC)
258 // if (Abs(theR2+theW2-theR1-theW1) <= Precision::Approximation())
259 // expectedGroups = 10;
261 // expectedGroups = 11;
262 // else if (shapeType == TSHAPE_CHAMFER || shapeType == TSHAPE_FILLET)
263 // expectedGroups = 12;
265 double aR1Ext = theR1 + theW1;
266 double aR2Ext = theR2 + theW2;
268 /////////////////////////
269 //// Groups of Faces ////
270 /////////////////////////
273 // Comment the following lines when GetInPlace bug is solved
275 // Workaround of GetInPlace bug
276 // Create a bounding box that fits the shape
277 Handle(GEOM_Object) aBox = my3DPrimOperations->MakeBoxDXDYDZ(2*theL1, 2*aR1Ext, aR1Ext+theL2);
278 aBox->GetLastFunction()->SetDescription("");
279 myTransformOperations->TranslateDXDYDZ(aBox, -theL1, -aR1Ext, -aR1Ext);
280 aBox->GetLastFunction()->SetDescription("");
281 // Apply transformation to box
282 BRepBuilderAPI_Transform aTransformationBox(aBox->GetValue(), aTrsf, Standard_False);
283 TopoDS_Shape aBoxShapeTrsf = aTransformationBox.Shape();
284 aBox->GetLastFunction()->SetValue(aBoxShapeTrsf);
286 // Get the shell of the box
287 Handle(GEOM_Object) aShell = Handle(GEOM_Object)::DownCast
288 (myShapesOperations->MakeExplode(aBox, TopAbs_SHELL, true)->Value(1));
289 aBox->GetLastFunction()->SetDescription("");
290 aShell->GetLastFunction()->SetDescription("");
291 // Get the common shapes between shell and shape
292 Handle(GEOM_Object) aCommonCompound = myBooleanOperations->MakeBoolean (theShape, aShell, 1); // MakeCommon
293 if (aCommonCompound.IsNull()) {
294 SetErrorCode(myBooleanOperations->GetErrorCode());
297 aCommonCompound->GetLastFunction()->SetDescription("");
298 // Explode the faces of common shapes => 3 faces
299 Handle(TColStd_HSequenceOfTransient) aCommonFaces =
300 myShapesOperations->MakeExplode(aCommonCompound, TopAbs_FACE, true);
301 aCommonCompound->GetLastFunction()->SetDescription("");
302 std::list<Handle(GEOM_Object)> aCompoundOfFacesList;
304 for (int i=0 ; i<= aCommonFaces->Length()-4 ; i+=4) {
305 std::list<Handle(GEOM_Object)> aFacesList;
306 for (int j = 1 ; j <= 4 ; j++) {
307 Handle(GEOM_Object) aFace = Handle(GEOM_Object)::DownCast(aCommonFaces->Value(i+j)); // Junction faces
308 if (!aFace.IsNull()) {
309 aFace->GetLastFunction()->SetDescription("");
310 aFacesList.push_back(aFace);
313 Handle(GEOM_Object) aCompoundOfFaces = myShapesOperations->MakeCompound(aFacesList);
314 if (!aCompoundOfFaces.IsNull()) {
315 aCompoundOfFaces->GetLastFunction()->SetDescription("");
316 aCompoundOfFacesList.push_back(aCompoundOfFaces);
320 if (aCompoundOfFacesList.size() == 3) {
321 Handle(GEOM_Object) aPln1 = aCompoundOfFacesList.front();
322 aCompoundOfFacesList.pop_front();
323 Handle(GEOM_Object) aPln2 = aCompoundOfFacesList.front();
324 aCompoundOfFacesList.pop_front();
325 Handle(GEOM_Object) aPln3 = aCompoundOfFacesList.front();
326 aCompoundOfFacesList.pop_front();
331 // Uncomment the following lines when GetInPlace bug is solved
333 // Handle(GEOM_Object) aP1 = myBasicOperations->MakePointXYZ(-theL1, 0, 0);
334 // Handle(GEOM_Object) aP2 = myBasicOperations->MakePointXYZ(-0, 0, theL2);
335 // Handle(GEOM_Object) aP3 = myBasicOperations->MakePointXYZ(theL1, 0, 0);
336 // aP1->GetLastFunction()->SetDescription("");
337 // aP2->GetLastFunction()->SetDescription("");
338 // aP3->GetLastFunction()->SetDescription("");
339 // Handle(GEOM_Object) aV1 = myBasicOperations->MakeVectorDXDYDZ(-1, 0, 0);
340 // Handle(GEOM_Object) aV2 = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
341 // Handle(GEOM_Object) aV3 = myBasicOperations->MakeVectorDXDYDZ(1, 0, 0);
342 // aV1->GetLastFunction()->SetDescription("");
343 // aV2->GetLastFunction()->SetDescription("");
344 // aV3->GetLastFunction()->SetDescription("");
345 // Handle(GEOM_Object) aPln1 = myBasicOperations->MakePlanePntVec(aP1, aV1, 2*(aR1Ext+theL2));
346 // Handle(GEOM_Object) aPln2 = myBasicOperations->MakePlanePntVec(aP2, aV2, 2*(aR2Ext));
347 // Handle(GEOM_Object) aPln3 = myBasicOperations->MakePlanePntVec(aP3, aV3, 2*(aR1Ext+theL2));
348 // aPln1->GetLastFunction()->SetDescription("");
349 // aPln2->GetLastFunction()->SetDescription("");
350 // aPln3->GetLastFunction()->SetDescription("");
352 // BRepBuilderAPI_Transform aTransformation1(aPln1->GetValue(), aTrsf, Standard_False);
353 // TopoDS_Shape aTrsf_Shape1 = aTransformation1.Shape();
354 // aPln1->GetLastFunction()->SetValue(aTrsf_Shape1);
355 // BRepBuilderAPI_Transform aTransformation2(aPln2->GetValue(), aTrsf, Standard_False);
356 // TopoDS_Shape aTrsf_Shape2 = aTransformation2.Shape();
357 // aPln2->GetLastFunction()->SetValue(aTrsf_Shape2);
358 // BRepBuilderAPI_Transform aTransformation3(aPln3->GetValue(), aTrsf, Standard_False);
359 // TopoDS_Shape aTrsf_Shape3 = aTransformation3.Shape();
360 // aPln3->GetLastFunction()->SetValue(aTrsf_Shape3);
364 Handle(GEOM_Object) junctionFaces1 = myShapesOperations->GetInPlace(theShape, aPln1);
365 if (junctionFaces1.IsNull())
366 junctionFaces1 = myShapesOperations->GetShapesOnShapeAsCompound
367 (aPln1, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
368 if (!junctionFaces1.IsNull()) {
369 junctionFaces1->GetLastFunction()->SetDescription("");
370 junctionFaces1->SetName("JUNCTION_FACE_1");
371 theSeq->Append(junctionFaces1);
374 SetErrorCode("Junction face 1 not found");
375 // theSeq->Append(aPln1);
378 Handle(GEOM_Object) junctionFaces2 = myShapesOperations->GetInPlace(theShape, aPln2);
379 if (junctionFaces2.IsNull())
380 junctionFaces2 = myShapesOperations->GetShapesOnShapeAsCompound
381 (aPln2, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
382 if (!junctionFaces2.IsNull()) {
383 junctionFaces2->GetLastFunction()->SetDescription("");
384 junctionFaces2->SetName("JUNCTION_FACE_2");
385 theSeq->Append(junctionFaces2);
388 SetErrorCode("Junction face 2 not found");
389 // theSeq->Append(aPln2);
392 Handle(GEOM_Object) junctionFaces3 = myShapesOperations->GetInPlace(theShape, aPln3);
393 if (junctionFaces3.IsNull())
394 junctionFaces3 = myShapesOperations->GetShapesOnShapeAsCompound
395 (aPln3, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
396 if (!junctionFaces3.IsNull()) {
397 junctionFaces3->GetLastFunction()->SetDescription("");
398 junctionFaces3->SetName("JUNCTION_FACE_3");
399 theSeq->Append(junctionFaces3);
402 SetErrorCode("Junction face 3 not found");
403 // theSeq->Append(aPln3);
406 // Comment the following lines when GetInPlace bug is solved
410 /////////////////////////
411 //// Groups of Edges ////
412 /////////////////////////
413 // Result of propagate
415 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
417 TCollection_AsciiString theDesc = aFunction->GetDescription();
418 Handle(TColStd_HSequenceOfTransient) aSeqPropagate = myBlocksOperations->Propagate(theShape);
419 if (aSeqPropagate.IsNull() || aSeqPropagate->Length() == 0) {
420 SetErrorCode("Propagation groups not found");
423 Standard_Integer nbEdges, aNbGroups = aSeqPropagate->Length();
424 // Recover previous description to get rid of Propagate dump
425 aFunction->SetDescription(theDesc);
428 bool circularFoundAndAdded = false;
429 bool circularFound10 = false;
430 bool incidentPipeFound = false;
431 bool mainPipeFound = false;
432 bool mainPipeFoundAndAdded = false;
433 bool radialFound =false;
434 bool flangeFound = false;
435 bool flangeFoundAndAdded = false;
436 bool chamferOrFilletFound = false;
438 for (int i=1 ; i<= aNbGroups; i++) {
441 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(aSeqPropagate->Value(i));
445 TopoDS_Shape aGroupShape = aGroup->GetValue();
446 BRepBuilderAPI_Transform aTransformationShapeInv(aGroupShape, aTrsfInv, Standard_False);
447 TopoDS_Shape aGroupShapeTrsfInv = aTransformationShapeInv.Shape();
449 TopTools_IndexedMapOfShape anEdgesMap;
450 TopExp::MapShapes(aGroupShapeTrsfInv,TopAbs_EDGE, anEdgesMap);
451 nbEdges = anEdgesMap.Extent();
453 if (shapeType == TSHAPE_BASIC) {
454 if ((nbEdges == 21) || /*R1Ext = R2Ext*/(nbEdges == 17)){
456 aGroup->SetName("THICKNESS");
458 else if (nbEdges == 6) {
459 if (!circularFoundAndAdded) {
460 circularFoundAndAdded = true;
462 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
465 else if (nbEdges == 8) {
466 incidentPipeFound = true;
467 mainPipeFound = false;
471 TopExp_Explorer Ex(aGroupShapeTrsfInv,TopAbs_VERTEX);
473 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
474 double x=aP.X(), y=aP.Y(), z=aP.Z();
477 if ((Abs(x) > aR2Ext + Precision::Confusion()) ||
478 (Abs(y) > aR2Ext + Precision::Confusion())) {
479 incidentPipeFound = false;
482 if ( z < -Precision::Confusion()) {
483 // length of main pipe
484 mainPipeFound = true;
485 if (!mainPipeFoundAndAdded) {
486 mainPipeFoundAndAdded = true;
488 aGroup->SetName("HALF_LENGTH_MAIN_PIPE");
492 else if (Abs(x) > (theL1-Precision::Confusion())) {
493 // discretisation circulaire
495 if (!circularFoundAndAdded) {
496 circularFoundAndAdded = true;
498 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
503 if (incidentPipeFound) {
505 aGroup->SetName("HALF_LENGTH_INCIDENT_PIPE");
507 if (!addGroup && (!incidentPipeFound &&
511 // Flange (collerette)
514 aGroup->SetName("FLANGE");
520 else if (shapeType == TSHAPE_CHAMFER || shapeType == TSHAPE_FILLET) {
523 aGroup->SetName("THICKNESS");
525 else if ((nbEdges == 10) || (nbEdges == 6)) {
526 if (!circularFoundAndAdded) {
528 circularFoundAndAdded = true;
529 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
531 circularFound10 = true;
534 else if (!circularFound10 && nbEdges == 10) {
535 circularFound10 = true;
537 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
540 else if (nbEdges == 8) {
541 incidentPipeFound = true;
542 mainPipeFound = true;
545 bool isNearZ0 = false;
546 bool isBelowZ0 = false;
548 TopExp_Explorer Ex (aGroupShapeTrsfInv,TopAbs_VERTEX);
550 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
551 double x=aP.X(), y=aP.Y(), z=aP.Z();
553 // tuy_princ_long_avant & tuy_princ_long_apres
554 //bool isMain = (((z < Precision::Confusion()) || (x < Precision::Confusion())) &&
555 // ((y <= aR1Ext + Precision::Confusion()) ||
556 // (y <= -(aR1Ext + Precision::Confusion())) ||
557 // (y <= theR1 + Precision::Confusion()) ||
558 // (y == -(theR1 + Precision::Confusion()))));
559 bool isMain = ((z < Precision::Confusion() || x < Precision::Confusion()) &&
560 (fabs(y) > theR1 - Precision::Confusion() ||
561 fabs(y) < Precision::Confusion()));
564 mainPipeFound = false;
568 //if (z < Precision::Confusion() && !isMain) {
569 // flangeFound = true;
570 // if (!flangeFoundAndAdded) {
571 // flangeFoundAndAdded = true;
573 // aGroup->SetName("FLANGE");
576 if (fabs(z) < Precision::Confusion()) isNearZ0 = true;
577 if (z < - Precision::Confusion()) isBelowZ0 = true;
580 if ((Abs(x) > aR2Ext + Precision::Confusion()) ||
581 (Abs(y) > aR2Ext + Precision::Confusion())) {
582 incidentPipeFound = false;
588 aGroup->SetName("HALF_LENGTH_MAIN_PIPE");
590 if (incidentPipeFound) {
592 aGroup->SetName("HALF_LENGTH_INCIDENT_PIPE");
594 if (isNearZ0 && !isBelowZ0) {
596 if (!flangeFoundAndAdded) {
597 flangeFoundAndAdded = true;
599 aGroup->SetName("FLANGE");
602 if (!addGroup && (!incidentPipeFound &&
605 !chamferOrFilletFound)) {
607 chamferOrFilletFound = true;
608 if (shapeType == TSHAPE_CHAMFER)
609 aGroup->SetName("CHAMFER");
611 aGroup->SetName("FILLET");
617 // Add group to the list
619 theSeq->Append(aGroup);
626 bool GEOMImpl_IAdvancedOperations::MakePipeTShapePartition(Handle(GEOM_Object) theShape,
627 double theR1, double theW1, double theL1,
628 double theR2, double theW2, double theL2,
629 double theH, double theW,
630 double theRF, bool isNormal)
634 // Build tools for partition operation:
635 // 1 face and 2 planes
637 Handle(GEOM_Object) arete_intersect_int;
638 Handle(GEOM_Object) wire_t, wire_t2, face_t, face_t2;
639 Handle(GEOM_Object) chan_racc;
640 Handle(GEOM_Object) vi1, vi2;
641 Handle(GEOM_Object) Te3;
644 #if OCC_VERSION_LARGE > 0x06010000
647 Handle(GEOM_Object) Vector_Z = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
648 Vector_Z->GetLastFunction()->SetDescription("");
651 double aSize = 2*(theL1 + theL2);
652 double aR1Ext = theR1 + theW1;
653 double aR2Ext = theR2 + theW2;
654 double theVertCylinderRadius = aR2Ext + theW + theRF;
655 double theHoriCylinderRadius = aR1Ext + theH + theRF;
657 // Common edges on internal cylinder
658 Handle(GEOM_Object) box_i = my3DPrimOperations->MakeBoxDXDYDZ(theR2, theR2, theR1);
659 box_i->GetLastFunction()->SetDescription("");
660 box_i = myTransformOperations->TranslateDXDYDZ(box_i, -theR2, -theR2, 0);
661 box_i->GetLastFunction()->SetDescription("");
663 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
664 TCollection_AsciiString theDesc = aFunction->GetDescription();
665 Handle(TColStd_HSequenceOfTransient) edges_i =
666 myShapesOperations->GetShapesOnBox(box_i, theShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
667 // Recover previous description to get rid of Propagate dump
668 aFunction->SetDescription(theDesc);
669 if (edges_i.IsNull() || edges_i->Length() == 0) {
670 SetErrorCode("Internal edges not found");
673 for (int i=1; i<=edges_i->Length();i++) {
674 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(edges_i->Value(i));
675 anObj->GetLastFunction()->SetDescription("");
677 arete_intersect_int = Handle(GEOM_Object)::DownCast(edges_i->Value(1));
679 // search for vertices located on both internal pipes
680 aFunction = theShape->GetLastFunction();
681 theDesc = aFunction->GetDescription();
682 Handle(TColStd_HSequenceOfTransient) vertices_i =
683 myShapesOperations->GetShapesOnBox(box_i, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
684 // Recover previous description to get rid of Propagate dump
685 aFunction->SetDescription(theDesc);
686 if (vertices_i.IsNull() || vertices_i->Length() == 0) {
687 SetErrorCode("Internal vertices not found");
691 for (int i = 1; i <= vertices_i->Length(); i++) {
692 Handle(GEOM_Object) v = Handle(GEOM_Object)::DownCast(vertices_i->Value(i));
693 v->GetLastFunction()->SetDescription("");
694 TopoDS_Vertex aVertex = TopoDS::Vertex(v->GetValue());
695 gp_Pnt aP = BRep_Tool::Pnt(aVertex);
696 // std::cout << "Coords: " << aP.X() << ", " << aP.Y() << ", " << aP.Z() << std::endl;
697 if (Abs(aP.X()) <= Precision::Confusion()) {
698 if (Abs(aP.Y()) - theR1 <= Precision::Confusion()) {
701 } else if (Abs(aP.Y()) <= Precision::Confusion()) {
702 if (Abs(aP.X()) - theR1 <= Precision::Confusion()) {
708 std::list<Handle(GEOM_Object)> theShapes;
711 Handle(GEOM_Object) ve1, ve2;
713 Handle(GEOM_Object) box_e = my3DPrimOperations->MakeBoxDXDYDZ(aR2Ext, aR2Ext, aR1Ext);
714 box_e->GetLastFunction()->SetDescription("");
715 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -aR2Ext, -aR2Ext, 0);
716 box_e->GetLastFunction()->SetDescription("");
717 // Common edges on external cylinder
718 aFunction = theShape->GetLastFunction();
719 theDesc = aFunction->GetDescription();
720 Handle(TColStd_HSequenceOfTransient) edges_e =
721 myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
722 // Recover previous description to get rid of Propagate dump
723 aFunction->SetDescription(theDesc);
724 if (edges_e.IsNull() || edges_e->Length() == 0) {
725 SetErrorCode("External edges not found");
728 for (int i=1; i<=edges_e->Length();i++) {
729 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(edges_e->Value(i));
730 anObj->GetLastFunction()->SetDescription("");
733 // search for vertices located on both external pipes
734 aFunction = theShape->GetLastFunction();
735 theDesc = aFunction->GetDescription();
736 Handle(TColStd_HSequenceOfTransient) vertices_e =
737 myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
738 // Recover previous description to get rid of Propagate dump
739 aFunction->SetDescription(theDesc);
740 if (vertices_e.IsNull() || vertices_e->Length() == 0) {
741 SetErrorCode("External vertices not found");
745 for (int i = 1; i <= vertices_e->Length(); i++) {
746 Handle(GEOM_Object) v = Handle(GEOM_Object)::DownCast(vertices_e->Value(i));
747 v->GetLastFunction()->SetDescription("");
748 TopoDS_Vertex aVertex = TopoDS::Vertex(v->GetValue());
749 gp_Pnt aP = BRep_Tool::Pnt(aVertex);
750 // std::cout << "Coords: " << aP.X() << ", " << aP.Y() << ", " << aP.Z() << std::endl;
751 if (Abs(aP.X()) <= Precision::Confusion()) {
752 if (Abs(aP.Y()) - theR2 > Precision::Confusion()) {
755 } else if (Abs(aP.Y()) <= Precision::Confusion()) {
756 if (Abs(aP.X()) - theR2 > Precision::Confusion()) {
760 if ( !ve1.IsNull() && !ve2.IsNull())
763 Handle(GEOM_Object) edge_e1, edge_e2;
765 edge_e1 = myBasicOperations->MakeLineTwoPnt(ve1, vi1);
766 if (edge_e1.IsNull()) {
767 SetErrorCode("Edge 1 could not be built");
771 edge_e2 = myBasicOperations->MakeLineTwoPnt(ve2, vi2);
772 if (edge_e2.IsNull()) {
773 SetErrorCode("Edge 2 could not be built");
777 edge_e1->GetLastFunction()->SetDescription("");
778 edge_e2->GetLastFunction()->SetDescription("");
780 std::list<Handle(GEOM_Object)> edge_e_elist;
781 edge_e_elist.push_back(arete_intersect_int);
782 edge_e_elist.push_back(edge_e1);
783 edge_e_elist.push_back(Handle(GEOM_Object)::DownCast(edges_e->Value(1)));
784 edge_e_elist.push_back(edge_e2);
785 wire_t = myShapesOperations->MakeWire(edge_e_elist, 1e-7);
786 if (wire_t.IsNull()) {
787 SetErrorCode("Impossible to build wire");
790 wire_t->GetLastFunction()->SetDescription("");
791 face_t = myShapesOperations->MakeFace(wire_t, false);
792 if (face_t.IsNull()) {
793 SetErrorCode("Impossible to build face");
796 face_t->GetLastFunction()->SetDescription("");
798 theShapes.push_back(theShape);
799 theShapes.push_back(vi1);
800 theShapes.push_back(vi2);
801 theShapes.push_back(ve1);
802 theShapes.push_back(ve2);
803 theShapes.push_back(edge_e1);
804 theShapes.push_back(edge_e2);
805 theShapes.push_back(wire_t);
806 theShapes.push_back(face_t);
809 Handle(GEOM_Object) P1, P2, P3, P4, P5, P6;
810 int idP1, idP2, idP3, idP4;
815 Handle(GEOM_Object) box_e = my3DPrimOperations->MakeBoxDXDYDZ
816 (theVertCylinderRadius, theVertCylinderRadius, theHoriCylinderRadius);
817 box_e->GetLastFunction()->SetDescription("");
818 box_e = myTransformOperations->TranslateDXDYDZ
819 (box_e, -theVertCylinderRadius, -theVertCylinderRadius, 0);
820 box_e->GetLastFunction()->SetDescription("");
822 aFunction = theShape->GetLastFunction();
823 theDesc = aFunction->GetDescription();
824 Handle(TColStd_HSequenceOfTransient) extremVertices =
825 myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
826 // Recover previous description to get rid of Propagate dump
827 aFunction->SetDescription(theDesc);
829 if (extremVertices.IsNull() || extremVertices->Length() == 0) {
831 SetErrorCode("Vertices on chamfer not found");
833 SetErrorCode("Vertices on fillet not found");
837 theShapes.push_back(theShape);
838 theShapes.push_back(box_e);
839 if (extremVertices->Length() != 6) {
840 // for (int i=1; i<=extremVertices->Length(); i++){
841 // theShapes.push_back(Handle(GEOM_Object)::DownCast(extremVertices->Value(i)));
843 // Handle(GEOM_Object) aCompound = myShapesOperations->MakeCompound(theShapes);
844 // TopoDS_Shape aCompoundShape = aCompound->GetValue();
845 // theShape->GetLastFunction()->SetValue(aCompoundShape);
846 SetErrorCode("Bad number of vertices on chamfer found");
850 for (int i=1; i<=extremVertices->Length(); i++){
851 Handle(GEOM_Object) aV = Handle(GEOM_Object)::DownCast(extremVertices->Value(i));
852 aV->GetLastFunction()->SetDescription("");
853 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aV->GetValue()));
855 if (Abs(aP.X()) <= Precision::Confusion()) {
856 if (Abs(aP.Y()) - theR2 > Precision::Confusion()) {
858 if (aP.Z()-ZX > Precision::Confusion()) {
865 if (Abs(aP.X()) - theR2 > Precision::Confusion()) {
867 if (aP.Z() - ZY > Precision::Confusion()) {
884 P1 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP1));
885 P2 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP2));
886 P3 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP3));
887 P4 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP4));
889 Handle(GEOM_Object) Cote_1 = myBasicOperations->MakeLineTwoPnt(P1, vi1);
890 if (Cote_1.IsNull()) {
891 SetErrorCode("Impossible to build edge in thickness");
894 Cote_1->GetLastFunction()->SetDescription("");
896 Handle(GEOM_Object) Cote_2 = myBasicOperations->MakeLineTwoPnt(vi2, P3);
897 if (Cote_2.IsNull()) {
898 SetErrorCode("Impossible to build edge in thickness");
901 Cote_2->GetLastFunction()->SetDescription("");
903 // edge_chan_princ = arete du chanfrein (ou raccord) sur le tuyau principal
904 // edge_chan_inc = arete du chanfrein (ou raccord) sur le tuyau incident
905 // std::cerr << "Getting chamfer edge on main pipe" << std::endl;
906 Handle(GEOM_Object) edge_chan_princ = myBlocksOperations->GetEdge(theShape, P1, P3);
907 if (edge_chan_princ.IsNull()) {
908 SetErrorCode("Impossible to find edge on main pipe");
911 edge_chan_princ->GetLastFunction()->SetDescription("");
913 Handle(GEOM_Object) edge_chan_inc = myBlocksOperations->GetEdge(theShape, P2, P4);
914 if (edge_chan_inc.IsNull()) {
915 SetErrorCode("Impossible to find edge on incident pipe");
918 edge_chan_inc->GetLastFunction()->SetDescription("");
920 std::list<Handle(GEOM_Object)> edgeList1;
921 edgeList1.push_back(edge_chan_princ);
922 edgeList1.push_back(Cote_1);
923 edgeList1.push_back(arete_intersect_int);
924 edgeList1.push_back(Cote_2);
926 // std::cerr << "Creating wire 1" << std::endl;
927 wire_t = myShapesOperations->MakeWire(edgeList1, 1e-7);
928 if (wire_t.IsNull()) {
929 SetErrorCode("Impossible to build wire");
932 wire_t->GetLastFunction()->SetDescription("");
934 // std::cerr << "Creating face 1" << std::endl;
935 face_t = myShapesOperations->MakeFace(wire_t, false);
936 if (face_t.IsNull()) {
937 SetErrorCode("Impossible to build face");
940 face_t->GetLastFunction()->SetDescription("");
941 theShapes.push_back(face_t);
943 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(P2->GetValue()));
944 gp_Pnt aP5 = BRep_Tool::Pnt(TopoDS::Vertex(vi1->GetValue()));
945 double deltaZ = aP2.Z() - aP5.Z();
946 // std::cerr << "Creating new point from vi1 with deltaZ = " << deltaZ << std::endl;
947 Handle(GEOM_Object) P5bis = myTransformOperations->TranslateDXDYDZCopy(vi1, 0, 0, deltaZ);
948 if (P5bis.IsNull()) {
949 SetErrorCode("Impossible to translate vertex");
952 P5bis->GetLastFunction()->SetDescription("");
954 gp_Pnt aP4 = BRep_Tool::Pnt(TopoDS::Vertex(P4->GetValue()));
955 gp_Pnt aP6 = BRep_Tool::Pnt(TopoDS::Vertex(vi2->GetValue()));
956 deltaZ = aP4.Z() - aP6.Z();
957 // std::cerr << "Creating new point from vi2 with deltaZ = " << deltaZ << std::endl;
958 Handle(GEOM_Object) P6bis = myTransformOperations->TranslateDXDYDZCopy(vi2, 0, 0, deltaZ);
959 if (P6bis.IsNull()) {
960 SetErrorCode("Impossible to translate vertex");
963 P6bis->GetLastFunction()->SetDescription("");
965 // std::cerr << "Creating new line 1 from 2 previous points" << std::endl;
966 Handle(GEOM_Object) Cote_3 = myBasicOperations->MakeLineTwoPnt(P5bis, P2);
967 if (Cote_3.IsNull()) {
968 SetErrorCode("Impossible to build edge in thickness");
971 Cote_3->GetLastFunction()->SetDescription("");
973 // std::cerr << "Creating new line 2 from 2 previous points" << std::endl;
974 Handle(GEOM_Object) Cote_4 = myBasicOperations->MakeLineTwoPnt(P6bis, P4);
975 if (Cote_4.IsNull()) {
976 SetErrorCode("Impossible to build edge in thickness");
979 Cote_4->GetLastFunction()->SetDescription("");
981 // std::cerr << "Creating new line 3 from 2 previous points" << std::endl;
982 Handle(GEOM_Object) Cote_5 = myBasicOperations->MakeLineTwoPnt(P5bis, P6bis);
983 if (Cote_4.IsNull()) {
984 SetErrorCode("Impossible to build edge in thickness");
987 Cote_5->GetLastFunction()->SetDescription("");
989 //std::list<Handle(GEOM_Object)> edgeList2;
990 //edgeList2.push_back(edge_chan_inc);
991 //edgeList2.push_back(Cote_3);
992 //edgeList2.push_back(Cote_5);
993 //edgeList2.push_back(Cote_4);
994 // std::cerr << "Creating wire 2" << std::endl;
995 //wire_t2 = myShapesOperations->MakeWire(edgeList2, 1e-7);
996 //if (wire_t2.IsNull()) {
997 // SetErrorCode("Impossible to build wire");
1000 //wire_t2->GetLastFunction()->SetDescription("");
1001 // std::cerr << "Creating face 2" << std::endl;
1002 //face_t2 = myShapesOperations->MakeFace(wire_t2, false);
1004 // Mantis issue 0021682
1005 face_t2 = my3DPrimOperations->MakePrismVecH(edge_chan_inc, Cote_4, - (theR2 + theW2));
1006 //face_t2 = my3DPrimOperations->MakePrismVecH(edge_chan_inc, Cote_4, - 2.0*theR2);
1007 if (face_t2.IsNull()) {
1008 SetErrorCode("Impossible to build face");
1011 face_t2->GetLastFunction()->SetDescription("");
1012 theShapes.push_back(face_t2);
1016 Handle(GEOM_Object) aP0 = myBasicOperations->MakePointXYZ(0, 0, 0);
1017 Handle(GEOM_Object) aVZ = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
1018 Handle(GEOM_Object) aVXZ = myBasicOperations->MakeVectorDXDYDZ(aR1Ext, 0, 0.5*(theL1+theVertCylinderRadius));
1019 Handle(GEOM_Object) aPlnOZ = myBasicOperations->MakePlanePntVec(aP0, aVZ, aSize);
1020 Handle(GEOM_Object) aPlnOXZ = myBasicOperations->MakePlanePntVec(aP0, aVXZ, aSize);
1021 aP0->GetLastFunction()->SetDescription("");
1022 aVZ->GetLastFunction()->SetDescription("");
1023 aVXZ->GetLastFunction()->SetDescription("");
1024 aPlnOZ->GetLastFunction()->SetDescription("");
1025 aPlnOXZ->GetLastFunction()->SetDescription("");
1026 theShapes.push_back(aPlnOZ);
1027 theShapes.push_back(aPlnOXZ);
1030 Handle(TColStd_HSequenceOfTransient) partitionShapes = new TColStd_HSequenceOfTransient;
1031 Handle(TColStd_HSequenceOfTransient) theTools = new TColStd_HSequenceOfTransient;
1032 Handle(TColStd_HSequenceOfTransient) theKeepInside = new TColStd_HSequenceOfTransient;
1033 Handle(TColStd_HSequenceOfTransient) theRemoveInside = new TColStd_HSequenceOfTransient;
1034 Handle(TColStd_HArray1OfInteger) theMaterials;
1036 partitionShapes->Append(theShape);
1037 theTools->Append(aPlnOZ);
1038 if (Abs(aR1Ext - aR2Ext) > Precision::Confusion())
1039 theTools->Append(aPlnOXZ);
1040 theTools->Append(face_t);
1042 theTools->Append(face_t2);
1044 Te3 = myBooleanOperations->MakePartition
1045 (partitionShapes, theTools, theKeepInside, theRemoveInside,
1046 TopAbs_SOLID, false, theMaterials, 0, false);
1048 SetErrorCode("Impossible to build partition of TShape");
1051 Te3->GetLastFunction()->SetDescription("");
1053 // Last verification: result should be a block
1054 std::list<GEOMImpl_IBlocksOperations::BCError> errList;
1055 if (!myBlocksOperations->CheckCompoundOfBlocks(Te3,errList)) {
1056 SetErrorCode("TShape is not a compound of block");
1060 // // BEGIN Compound of created shapes - Only for debug purpose
1061 // theShapes.clear();
1062 // theShapes.push_back(theShape);
1063 // theShapes.push_back(aPlnOZ);
1064 // if (Abs(aR1Ext - aR2Ext) > Precision::Confusion() )
1065 // theShapes.push_back(aPlnOXZ);
1066 // theShapes.push_back(face_t);
1068 // theShapes.push_back(face_t2);
1070 // Handle(GEOM_Object) aCompound = myShapesOperations->MakeCompound(theShapes);
1071 // TopoDS_Shape aCompoundShape = aCompound->GetValue();
1072 // theShape->GetLastFunction()->SetValue(aCompoundShape);
1073 // // END Compound of created shapes - Only for debug purpose
1075 TopoDS_Shape aShape = Te3->GetValue();
1076 theShape->GetLastFunction()->SetValue(aShape);
1077 } catch (Standard_Failure) {
1078 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1079 SetErrorCode(aFail->GetMessageString());
1087 // Mirror and glue faces
1088 bool GEOMImpl_IAdvancedOperations::MakePipeTShapeMirrorAndGlue(Handle(GEOM_Object) theShape,
1089 double theR1, double theW1, double theL1,
1090 double theR2, double theW2, double theL2)
1095 double aSize = 2*(theL1 + theL2);
1096 double aR1Ext = theR1 + theW1;
1099 Handle(GEOM_Object) aP0 = myBasicOperations->MakePointXYZ(0, 0, 0);
1100 aP0->GetLastFunction()->SetDescription("");
1101 Handle(GEOM_Object) aVX = myBasicOperations->MakeVectorDXDYDZ(1, 0, 0);
1102 Handle(GEOM_Object) aVY = myBasicOperations->MakeVectorDXDYDZ(0, 1, 0);
1103 aVX->GetLastFunction()->SetDescription("");
1104 aVY->GetLastFunction()->SetDescription("");
1105 Handle(GEOM_Object) aPlane_OX = myBasicOperations->MakePlanePntVec(aP0, aVX, 2*(aR1Ext + theL2));
1106 Handle(GEOM_Object) aPlane_OY = myBasicOperations->MakePlanePntVec(aP0, aVY, aSize);
1107 aPlane_OX->GetLastFunction()->SetDescription("");
1108 aPlane_OY->GetLastFunction()->SetDescription("");
1110 Handle(GEOM_Object) Te4 = myTransformOperations->MirrorPlaneCopy(theShape, aPlane_OX);
1112 SetErrorCode("Impossible to build mirror of quarter TShape");
1116 Handle(GEOM_Object) Te5 = myTransformOperations->MirrorPlaneCopy(theShape, aPlane_OY);
1118 SetErrorCode("Impossible to build mirror of half TShape");
1122 Handle(GEOM_Object) Te6 = myTransformOperations->MirrorPlaneCopy(Te4, aPlane_OY);
1124 SetErrorCode("Impossible to build mirror of half TShape");
1128 std::list<Handle(GEOM_Object)> aShapesList;
1129 aShapesList.push_back(theShape);
1130 aShapesList.push_back(Te4);
1131 aShapesList.push_back(Te5);
1132 aShapesList.push_back(Te6);
1133 Handle(GEOM_Object) Te7 = myShapesOperations->MakeCompound(aShapesList);
1135 SetErrorCode("Impossible to build compound");
1139 Handle(GEOM_Object) Te8 = myShapesOperations->MakeGlueFaces(Te7, 1e-7, true);
1141 SetErrorCode("Impossible to glue faces of TShape");
1145 TopoDS_Shape aShape = Te8->GetValue();
1147 theShape->GetLastFunction()->SetValue(aShape);
1149 Te4->GetLastFunction()->SetDescription("");
1150 Te5->GetLastFunction()->SetDescription("");
1151 Te6->GetLastFunction()->SetDescription("");
1152 Te7->GetLastFunction()->SetDescription("");
1153 Te8->GetLastFunction()->SetDescription("");
1159 //=============================================================================
1162 * \brief Create a T-shape object with specified caracteristics for the main and
1163 * the incident pipes (radius, width, half-length).
1164 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1165 * \param theR1 Internal radius of main pipe
1166 * \param theW1 Width of main pipe
1167 * \param theL1 Half-length of main pipe
1168 * \param theR2 Internal radius of incident pipe (R2 < R1)
1169 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1170 * \param theL2 Half-length of incident pipe
1171 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1172 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1174 //=============================================================================
1175 Handle(TColStd_HSequenceOfTransient)
1176 GEOMImpl_IAdvancedOperations::MakePipeTShape(double theR1, double theW1, double theL1,
1177 double theR2, double theW2, double theL2,
1180 MESSAGE("GEOMImpl_IAdvancedOperations::MakePipeTShape");
1183 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1185 //Add a new shape function with parameters
1186 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_BASIC);
1187 if (aFunction.IsNull()) return NULL;
1189 //Check if the function is set correctly
1190 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1192 GEOMImpl_IPipeTShape aData(aFunction);
1200 aData.SetHexMesh(theHexMesh);
1202 //Compute the resulting value
1204 #if OCC_VERSION_LARGE > 0x06010000
1207 if (!GetSolver()->ComputeFunction(aFunction)) {
1208 SetErrorCode("TShape driver failed");
1212 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1214 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1217 } catch (Standard_Failure) {
1218 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1219 SetErrorCode(aFail->GetMessageString());
1224 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1225 aSeq->Append(aShape);
1229 * Get the groups: BEGIN
1232 if (!MakeGroups(aShape, TSHAPE_BASIC, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1235 catch (Standard_Failure) {
1236 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1237 SetErrorCode(aFail->GetMessageString());
1241 TCollection_AsciiString aListRes, anEntry;
1242 // Iterate over the sequence aSeq
1243 Standard_Integer aNbGroups = aSeq->Length();
1244 Standard_Integer i = 2;
1245 for (; i <= aNbGroups; i++) {
1246 Handle(Standard_Transient) anItem = aSeq->Value(i);
1247 if (anItem.IsNull()) continue;
1248 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1249 if (aGroup.IsNull()) continue;
1250 //Make a Python command
1251 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1252 aListRes += anEntry + ", ";
1255 aListRes.Trunc(aListRes.Length() - 2);
1257 //Make a Python command
1258 GEOM::TPythonDump(aFunction)
1259 << "[" << aShape << ", " << aListRes.ToCString() << "] = geompy.MakePipeTShape("
1260 << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", "
1261 << theHexMesh << ")";
1264 * Get the groups: END
1267 //Make a Python command
1268 GEOM::TPythonDump(aFunction)
1269 << "[" << aShape << "] = geompy.MakePipeTShape(" << theR1 << ", " << theW1 << ", "
1270 << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theHexMesh << ")";
1278 //=============================================================================
1280 * MakePipeTShapeWithPosition
1281 * Create a T-shape object with specified caracteristics for the main and
1282 * the incident pipes (radius, width, half-length).
1283 * The extremities of the main pipe are located on junctions points P1 and P2.
1284 * The extremity of the incident pipe is located on junction point P3.
1285 * \param theR1 Internal radius of main pipe
1286 * \param theW1 Width of main pipe
1287 * \param theL1 Half-length of main pipe
1288 * \param theR2 Internal radius of incident pipe (R2 < R1)
1289 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1290 * \param theL2 Half-length of incident pipe
1291 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1292 * \param theP1 1st junction point of main pipe
1293 * \param theP2 2nd junction point of main pipe
1294 * \param theP3 Junction point of incident pipe
1295 * \return List of GEOM_Objects, containing the created shape and propagation groups..
1297 //=============================================================================
1298 Handle(TColStd_HSequenceOfTransient)
1299 GEOMImpl_IAdvancedOperations::MakePipeTShapeWithPosition(double theR1, double theW1, double theL1,
1300 double theR2, double theW2, double theL2,
1302 Handle(GEOM_Object) theP1,
1303 Handle(GEOM_Object) theP2,
1304 Handle(GEOM_Object) theP3)
1308 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1312 //Add a new shape function with parameters
1313 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_BASIC);
1314 if (aFunction.IsNull()) return NULL;
1316 //Check if the function is set correctly
1317 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1319 // Check new position
1320 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1324 GEOMImpl_IPipeTShape aData(aFunction);
1332 aData.SetHexMesh(theHexMesh);
1334 //Compute the resulting value
1336 #if OCC_VERSION_LARGE > 0x06010000
1339 if (!GetSolver()->ComputeFunction(aFunction)) {
1340 SetErrorCode("TShape driver failed");
1343 } catch (Standard_Failure) {
1344 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1345 SetErrorCode(aFail->GetMessageString());
1350 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1352 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1356 TopoDS_Shape Te = aShape->GetValue();
1359 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
1360 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
1361 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
1362 aFunction->SetValue(aTrsf_Shape);
1363 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1364 aSeq->Append(aShape);
1368 // Get the groups: BEGIN
1371 if (!MakeGroups(aShape,TSHAPE_BASIC, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf)) {
1375 catch (Standard_Failure) {
1376 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1377 SetErrorCode(aFail->GetMessageString());
1381 TCollection_AsciiString aListRes, anEntry;
1382 // Iterate over the sequence aSeq
1383 Standard_Integer aNbGroups = aSeq->Length();
1384 Standard_Integer i = 2;
1385 for (; i <= aNbGroups; i++) {
1386 Handle(Standard_Transient) anItem = aSeq->Value(i);
1387 if (anItem.IsNull()) continue;
1388 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1389 if (aGroup.IsNull()) continue;
1390 //Make a Python command
1391 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1392 aListRes += anEntry + ", ";
1395 aListRes.Trunc(aListRes.Length() - 2);
1397 //Make a Python command
1398 GEOM::TPythonDump(aFunction)
1399 << "[" << aShape << ", " << aListRes.ToCString() << "] = geompy.MakePipeTShape("
1400 << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", "
1401 << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
1404 // Get the groups: END
1408 //Make a Python command
1409 GEOM::TPythonDump(aFunction)
1410 << "[" << aShape << "] = geompy.MakePipeTShape(" << theR1 << ", " << theW1 << ", "
1411 << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theHexMesh << ", " << theP1
1412 << ", " << theP2 << ", " << theP3 << ")";
1420 //=============================================================================
1422 * MakePipeTShapeChamfer
1423 * Create a T-shape object with specified caracteristics for the main and
1424 * the incident pipes (radius, width, half-length). A chamfer is created
1425 * on the junction of the pipes.
1426 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1427 * \param theR1 Internal radius of main pipe
1428 * \param theW1 Width of main pipe
1429 * \param theL1 Half-length of main pipe
1430 * \param theR2 Internal radius of incident pipe (R2 < R1)
1431 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1432 * \param theL2 Half-length of incident pipe
1433 * \param theH Height of chamfer.
1434 * \param theW Width of chamfer.
1435 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1436 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1438 //=============================================================================
1439 Handle(TColStd_HSequenceOfTransient)
1440 GEOMImpl_IAdvancedOperations::MakePipeTShapeChamfer(double theR1, double theW1, double theL1,
1441 double theR2, double theW2, double theL2,
1442 double theH, double theW,
1447 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1448 //Add a new shape function with parameters
1449 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_CHAMFER);
1450 if (aFunction.IsNull()) return NULL;
1452 //Check if the function is set correctly
1453 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1455 GEOMImpl_IPipeTShape aData(aFunction);
1465 aData.SetHexMesh(theHexMesh);
1467 //Compute the resulting value
1469 #if OCC_VERSION_LARGE > 0x06010000
1472 if (!GetSolver()->ComputeFunction(aFunction)) {
1473 SetErrorCode("TShape driver failed");
1476 } catch (Standard_Failure) {
1477 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1478 SetErrorCode(aFail->GetMessageString());
1483 TopoDS_Shape aShapeShape = aShape->GetValue();
1484 TopTools_IndexedMapOfShape anEdgesIndices;
1485 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1486 // Common edges on external cylinders
1487 Handle(GEOM_Object) box_e;
1489 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1492 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1494 box_e->GetLastFunction()->SetDescription("");
1495 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1496 box_e->GetLastFunction()->SetDescription("");
1498 Handle(TColStd_HSequenceOfInteger) edges_e =
1499 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1500 box_e->GetLastFunction()->SetDescription("");
1502 if (edges_e.IsNull() || edges_e->Length() == 0) {
1503 SetErrorCode("External edges not found");
1506 int nbEdgesInChamfer = 0;
1507 std::list<int> theEdges;
1508 for (int i=1; i<=edges_e->Length();i++) {
1509 int edgeID = edges_e->Value(i);
1510 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1511 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1515 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1516 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1517 nbEdgesInChamfer ++;
1518 theEdges.push_back(edgeID);
1522 if (theHexMesh && nbEdgesInChamfer == 1)
1525 Handle(GEOM_Object) aChamfer;
1527 aChamfer = myLocalOperations->MakeChamferEdges(aShape, theW, theH, theEdges);
1529 catch (Standard_Failure) {
1530 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1531 SetErrorCode(aFail->GetMessageString());
1534 if (aChamfer.IsNull()) {
1535 SetErrorCode("Chamfer can not be computed on the given shape with the given parameters");
1538 aChamfer->GetLastFunction()->SetDescription("");
1540 TopoDS_Shape aChamferShape = aChamfer->GetValue();
1541 aFunction->SetValue(aChamferShape);
1544 // bool doMesh = false;
1547 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, 0, false)) {
1548 MESSAGE("PipeTShape partition failed");
1552 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2)) {
1553 MESSAGE("PipeTShape mirrors and glue failed");
1559 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1560 aSeq->Append(aShape);
1565 // Get the groups: BEGIN
1567 //if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf())) {
1568 // //Make a Python command
1569 // GEOM::TPythonDump(aFunction)
1570 // << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1571 // << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1572 // << ", " << theHexMesh << ")";
1576 if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1579 catch (Standard_Failure) {
1580 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1581 SetErrorCode(aFail->GetMessageString());
1585 TCollection_AsciiString aListRes, anEntry;
1586 // Iterate over the sequence aSeq
1587 Standard_Integer aNbGroups = aSeq->Length();
1588 Standard_Integer i = 2;
1589 for (; i <= aNbGroups; i++) {
1590 Handle(Standard_Transient) anItem = aSeq->Value(i);
1591 if (anItem.IsNull()) continue;
1592 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1593 if (aGroup.IsNull()) continue;
1594 //Make a Python command
1595 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1596 aListRes += anEntry + ", ";
1599 aListRes.Trunc(aListRes.Length() - 2);
1601 //Make a Python command
1602 GEOM::TPythonDump(aFunction)
1603 << "[" << aShape << ", " << aListRes.ToCString()
1604 << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1605 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW << ", " << theHexMesh << ")";
1609 // Get the groups: END
1612 //Make a Python command
1613 GEOM::TPythonDump(aFunction)
1614 << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1615 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1616 << ", " << theHexMesh << ")";
1624 //=============================================================================
1626 * MakePipeTShapeChamferWithPosition
1627 * Create a T-shape object with specified caracteristics for the main and
1628 * the incident pipes (radius, width, half-length). A chamfer is created
1629 * on the junction of the pipes.
1630 * The extremities of the main pipe are located on junctions points P1 and P2.
1631 * The extremity of the incident pipe is located on junction point P3.
1632 * \param theR1 Internal radius of main pipe
1633 * \param theW1 Width of main pipe
1634 * \param theL1 Half-length of main pipe
1635 * \param theR2 Internal radius of incident pipe (R2 < R1)
1636 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1637 * \param theL2 Half-length of incident pipe
1638 * \param theH Height of chamfer.
1639 * \param theW Width of chamfer.
1640 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1641 * \param theP1 1st junction point of main pipe
1642 * \param theP2 2nd junction point of main pipe
1643 * \param theP3 Junction point of incident pipe
1644 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1646 //=============================================================================
1647 Handle(TColStd_HSequenceOfTransient)
1648 GEOMImpl_IAdvancedOperations::MakePipeTShapeChamferWithPosition(double theR1, double theW1, double theL1,
1649 double theR2, double theW2, double theL2,
1650 double theH, double theW,
1652 Handle(GEOM_Object) theP1,
1653 Handle(GEOM_Object) theP2,
1654 Handle(GEOM_Object) theP3)
1658 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1659 //Add a new shape function with parameters
1660 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_CHAMFER);
1661 if (aFunction.IsNull()) return NULL;
1663 //Check if the function is set correctly
1664 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1666 // Check new position
1667 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1671 GEOMImpl_IPipeTShape aData(aFunction);
1681 aData.SetHexMesh(theHexMesh);
1683 //Compute the resulting value
1685 #if OCC_VERSION_LARGE > 0x06010000
1688 if (!GetSolver()->ComputeFunction(aFunction)) {
1689 SetErrorCode("TShape driver failed");
1692 } catch (Standard_Failure) {
1693 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1694 SetErrorCode(aFail->GetMessageString());
1699 TopoDS_Shape aShapeShape = aShape->GetValue();
1700 TopTools_IndexedMapOfShape anEdgesIndices;
1701 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1702 // Common edges on external cylinders
1703 Handle(GEOM_Object) box_e;
1705 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1708 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1710 box_e->GetLastFunction()->SetDescription("");
1711 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1712 box_e->GetLastFunction()->SetDescription("");
1714 Handle(TColStd_HSequenceOfInteger) edges_e =
1715 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1716 box_e->GetLastFunction()->SetDescription("");
1718 if (edges_e.IsNull() || edges_e->Length() == 0) {
1719 SetErrorCode("External edges not found");
1722 int nbEdgesInChamfer = 0;
1723 std::list<int> theEdges;
1724 for (int i=1; i<=edges_e->Length();i++) {
1725 int edgeID = edges_e->Value(i);
1726 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1727 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1729 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1730 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1731 nbEdgesInChamfer ++;
1732 theEdges.push_back(edgeID);
1736 if (theHexMesh && nbEdgesInChamfer == 1)
1739 Handle(GEOM_Object) aChamfer;
1741 aChamfer = myLocalOperations->MakeChamferEdges(aShape, theW, theH, theEdges);
1743 catch (Standard_Failure) {
1744 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1745 SetErrorCode(aFail->GetMessageString());
1748 if (aChamfer.IsNull()) {
1749 SetErrorCode("Chamfer can not be computed on the given shape with the given parameters");
1752 aChamfer->GetLastFunction()->SetDescription("");
1754 TopoDS_Shape aChamferShape = aChamfer->GetValue();
1755 aFunction->SetValue(aChamferShape);
1759 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, 0, false))
1761 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1765 TopoDS_Shape Te = aShape->GetValue();
1768 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
1769 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
1770 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
1771 aFunction->SetValue(aTrsf_Shape);
1772 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1773 aSeq->Append(aShape);
1776 * Get the groups: BEGIN
1779 if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf))
1782 catch (Standard_Failure) {
1783 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1784 SetErrorCode(aFail->GetMessageString());
1788 TCollection_AsciiString aListRes, anEntry;
1789 // Iterate over the sequence aSeq
1790 Standard_Integer aNbGroups = aSeq->Length();
1791 Standard_Integer i = 2;
1792 for (; i <= aNbGroups; i++) {
1793 Handle(Standard_Transient) anItem = aSeq->Value(i);
1794 if (anItem.IsNull()) continue;
1795 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1796 if (aGroup.IsNull()) continue;
1797 //Make a Python command
1798 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1799 aListRes += anEntry + ", ";
1802 aListRes.Trunc(aListRes.Length() - 2);
1804 //Make a Python command
1805 GEOM::TPythonDump(aFunction)
1806 << "[" << aShape << ", " << aListRes.ToCString()
1807 << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1808 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW << ", " << theHexMesh << ", "
1809 << theP1 << ", " << theP2 << ", " << theP3 << ")";
1812 * Get the groups: END
1815 //Make a Python command
1816 GEOM::TPythonDump(aFunction)
1817 << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1818 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1819 << ", " << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
1827 //=============================================================================
1829 * MakePipeTShapeFillet
1830 * Create a T-shape object with specified caracteristics for the main and
1831 * the incident pipes (radius, width, half-length). A fillet is created
1832 * on the junction of the pipes.
1833 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1834 * \param theR1 Internal radius of main pipe
1835 * \param theW1 Width of main pipe
1836 * \param theL1 Half-length of main pipe
1837 * \param theR2 Internal radius of incident pipe (R2 < R1)
1838 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1839 * \param theL2 Half-length of incident pipe
1840 * \param theRF Radius of curvature of fillet.
1841 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1842 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1844 //=============================================================================
1845 Handle(TColStd_HSequenceOfTransient)
1846 GEOMImpl_IAdvancedOperations::MakePipeTShapeFillet(double theR1, double theW1, double theL1,
1847 double theR2, double theW2, double theL2,
1848 double theRF, bool theHexMesh)
1852 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1853 //Add a new shape function with parameters
1854 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_FILLET);
1855 if (aFunction.IsNull()) return NULL;
1857 //Check if the function is set correctly
1858 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1860 GEOMImpl_IPipeTShape aData(aFunction);
1869 aData.SetHexMesh(theHexMesh);
1871 //Compute the resulting value
1873 #if OCC_VERSION_LARGE > 0x06010000
1876 if (!GetSolver()->ComputeFunction(aFunction)) {
1877 SetErrorCode("TShape driver failed");
1880 } catch (Standard_Failure) {
1881 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1882 SetErrorCode(aFail->GetMessageString());
1887 TopoDS_Shape aShapeShape = aShape->GetValue();
1888 TopTools_IndexedMapOfShape anEdgesIndices;
1889 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1890 // Common edges on external cylinders
1891 Handle(GEOM_Object) box_e;
1893 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1896 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1898 box_e->GetLastFunction()->SetDescription("");
1899 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1900 box_e->GetLastFunction()->SetDescription("");
1902 Handle(TColStd_HSequenceOfInteger) edges_e =
1903 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1904 box_e->GetLastFunction()->SetDescription("");
1906 if (edges_e.IsNull() || edges_e->Length() == 0) {
1907 SetErrorCode("External edges not found");
1910 int nbEdgesInFillet = 0;
1911 std::list<int> theEdges;
1912 for (int i=1; i<=edges_e->Length();i++) {
1913 int edgeID = edges_e->Value(i);
1914 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1915 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1917 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1918 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1920 theEdges.push_back(edgeID);
1924 if (theHexMesh && nbEdgesInFillet == 1)
1928 Handle(GEOM_Object) aFillet;
1930 aFillet = myLocalOperations->MakeFilletEdges(aShape, theRF, theEdges);
1932 catch (Standard_Failure) {
1933 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1934 SetErrorCode(aFail->GetMessageString());
1937 if (aFillet.IsNull()) {
1938 //SetErrorCode("Fillet can not be computed on the given shape with the given parameters");
1939 SetErrorCode(myLocalOperations->GetErrorCode());
1942 aFillet->GetLastFunction()->SetDescription("");
1944 TopoDS_Shape aFilletShape = aFillet->GetValue();
1945 aFunction->SetValue(aFilletShape);
1948 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - BEGIN (1)
1949 // the following block, when enabled, leads to partitioning problems
1951 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - END (1)
1952 // BEGIN: Limit tolerances (debug)
1953 Handle(GEOM_Object) aCorr1 = myHealingOperations->LimitTolerance(aShape, 1e-07);
1954 TopoDS_Shape aCorr1Shape = aCorr1->GetValue();
1955 aShape->GetLastFunction()->SetValue(aCorr1Shape);
1956 aCorr1->GetLastFunction()->SetDescription("");
1957 // END: Limit tolerances (debug)
1958 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - BEGIN (2)
1960 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - END (2)
1963 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, 0, 0, theRF, false))
1965 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1969 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1970 aSeq->Append(aShape);
1973 * Get the groups: BEGIN
1976 if (!MakeGroups(aShape, TSHAPE_FILLET, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1979 catch (Standard_Failure) {
1980 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1981 SetErrorCode(aFail->GetMessageString());
1985 TCollection_AsciiString aListRes, anEntry;
1986 // Iterate over the sequence aSeq
1987 Standard_Integer aNbGroups = aSeq->Length();
1988 Standard_Integer i = 2;
1989 for (; i <= aNbGroups; i++) {
1990 Handle(Standard_Transient) anItem = aSeq->Value(i);
1991 if (anItem.IsNull()) continue;
1992 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1993 if (aGroup.IsNull()) continue;
1994 //Make a Python command
1995 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1996 aListRes += anEntry + ", ";
1999 aListRes.Trunc(aListRes.Length() - 2);
2001 //Make a Python command
2002 GEOM::TPythonDump(aFunction)
2003 << "[" << aShape << ", " << aListRes.ToCString()
2004 << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
2005 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", " << theHexMesh << ")";
2008 * Get the groups: END
2011 //Make a Python command
2012 GEOM::TPythonDump(aFunction)
2013 << "[" << aShape << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1
2014 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", "
2015 << theHexMesh << ")";
2023 //=============================================================================
2025 * MakePipeTShapeFilletWithPosition
2026 * \brief Create a T-shape object with specified caracteristics for the main and
2027 * the incident pipes (radius, width, half-length). A fillet is created
2028 * on the junction of the pipes.
2029 * The extremities of the main pipe are located on junctions points P1 and P2.
2030 * The extremity of the incident pipe is located on junction point P3.
2031 * \param theR1 Internal radius of main pipe
2032 * \param theW1 Width of main pipe
2033 * \param theL1 Half-length of main pipe
2034 * \param theR2 Internal radius of incident pipe (R2 < R1)
2035 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
2036 * \param theL2 Half-length of incident pipe
2037 * \param theRF Radius of curvature of fillet
2038 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
2039 * \param theP1 1st junction point of main pipe
2040 * \param theP2 2nd junction point of main pipe
2041 * \param theP3 Junction point of incident pipe
2042 * \return List of GEOM_Objects, containing the created shape and propagation groups.
2044 //=============================================================================
2045 Handle(TColStd_HSequenceOfTransient)
2046 GEOMImpl_IAdvancedOperations::MakePipeTShapeFilletWithPosition(double theR1, double theW1, double theL1,
2047 double theR2, double theW2, double theL2,
2048 double theRF, bool theHexMesh,
2049 Handle(GEOM_Object) theP1,
2050 Handle(GEOM_Object) theP2,
2051 Handle(GEOM_Object) theP3)
2055 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
2056 //Add a new shape function with parameters
2057 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_FILLET);
2058 if (aFunction.IsNull()) return NULL;
2060 //Check if the function is set correctly
2061 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
2063 // Check new position
2064 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
2068 GEOMImpl_IPipeTShape aData(aFunction);
2077 aData.SetHexMesh(theHexMesh);
2079 //Compute the resulting value
2081 #if OCC_VERSION_LARGE > 0x06010000
2084 if (!GetSolver()->ComputeFunction(aFunction)) {
2085 SetErrorCode("TShape driver failed");
2088 } catch (Standard_Failure) {
2089 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2090 SetErrorCode(aFail->GetMessageString());
2095 TopoDS_Shape aShapeShape = aShape->GetValue();
2096 TopTools_IndexedMapOfShape anEdgesIndices;
2097 TopExp::MapShapes(aShapeShape, anEdgesIndices);
2098 // Common edges on external cylinders
2099 Handle(GEOM_Object) box_e;
2101 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
2104 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
2106 box_e->GetLastFunction()->SetDescription("");
2107 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
2108 box_e->GetLastFunction()->SetDescription("");
2110 Handle(TColStd_HSequenceOfInteger) edges_e =
2111 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
2112 box_e->GetLastFunction()->SetDescription("");
2114 if (edges_e.IsNull() || edges_e->Length() == 0) {
2115 SetErrorCode("External edges not found");
2118 int nbEdgesInFillet = 0;
2119 std::list<int> theEdges;
2120 for (int i=1; i<=edges_e->Length();i++) {
2121 int edgeID = edges_e->Value(i);
2122 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
2123 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
2125 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
2126 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
2128 theEdges.push_back(edgeID);
2132 if (theHexMesh && nbEdgesInFillet == 1)
2136 Handle(GEOM_Object) aFillet;
2138 aFillet = myLocalOperations->MakeFilletEdges(aShape, theRF, theEdges);
2140 catch (Standard_Failure) {
2141 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2142 SetErrorCode(aFail->GetMessageString());
2145 if (aFillet.IsNull()) {
2146 SetErrorCode("Fillet can not be computed on the given shape with the given parameters");
2149 aFillet->GetLastFunction()->SetDescription("");
2151 TopoDS_Shape aFilletShape = aFillet->GetValue();
2152 aFunction->SetValue(aFilletShape);
2155 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - BEGIN (3)
2156 // the following block, when enabled, leads to partitioning problems
2158 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - END (3)
2159 // BEGIN: Limit tolerances (debug)
2160 Handle(GEOM_Object) aCorr1 = myHealingOperations->LimitTolerance(aShape, 1e-07);
2161 TopoDS_Shape aCorr1Shape = aCorr1->GetValue();
2162 aShape->GetLastFunction()->SetValue(aCorr1Shape);
2163 aCorr1->GetLastFunction()->SetDescription("");
2164 // END: Limit tolerances (debug)
2165 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - BEGIN (4)
2167 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - END (4)
2170 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, 0, 0, theRF, false))
2172 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
2176 TopoDS_Shape Te = aShape->GetValue();
2179 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
2180 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
2181 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
2182 aFunction->SetValue(aTrsf_Shape);
2183 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
2184 aSeq->Append(aShape);
2187 * Get the groups: BEGIN
2190 if (!MakeGroups(aShape, TSHAPE_FILLET, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf))
2193 catch (Standard_Failure) {
2194 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2195 SetErrorCode(aFail->GetMessageString());
2199 TCollection_AsciiString aListRes, anEntry;
2200 // Iterate over the sequence aSeq
2201 Standard_Integer aNbGroups = aSeq->Length();
2202 Standard_Integer i = 2;
2203 for (; i <= aNbGroups; i++) {
2204 Handle(Standard_Transient) anItem = aSeq->Value(i);
2205 if (anItem.IsNull()) continue;
2206 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
2207 if (aGroup.IsNull()) continue;
2208 //Make a Python command
2209 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
2210 aListRes += anEntry + ", ";
2213 aListRes.Trunc(aListRes.Length() - 2);
2215 //Make a Python command
2216 GEOM::TPythonDump(aFunction)
2217 << "[" << aShape << ", " << aListRes.ToCString()
2218 << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
2219 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", " << theHexMesh << ", " << theP1 << ", "
2220 << theP2 << ", " << theP3 << ")";
2223 * Get the groups: END
2226 //Make a Python command
2227 GEOM::TPythonDump(aFunction)
2228 << "[" << aShape << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1
2229 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", "
2230 << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
2238 //=============================================================================
2240 * This function allows to create a disk already divided into blocks. It can be
2241 * use to create divided pipes for later meshing in hexaedra.
2242 * \param theR Radius of the disk
2243 * \param theRatio Relative size of the central square diagonal against the disk diameter
2244 * \return New GEOM_Object, containing the created shape.
2246 //=============================================================================
2247 Handle(GEOM_Object) GEOMImpl_IAdvancedOperations::MakeDividedDisk (double theR, double theRatio, int theOrientation)
2252 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_DIVIDEDDISK);
2254 //Add a new shape function with parameters
2255 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_DividedDiskDriver::GetID(), DIVIDEDDISK_R_RATIO);
2256 if (aFunction.IsNull()) return NULL;
2258 //Check if the function is set correctly
2259 if (aFunction->GetDriverGUID() != GEOMImpl_DividedDiskDriver::GetID()) return NULL;
2261 GEOMImpl_IDividedDisk aData (aFunction);
2264 aData.SetRatio(theRatio);
2265 aData.SetOrientation(theOrientation);
2267 //Compute the resulting value
2269 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2272 if (!GetSolver()->ComputeFunction(aFunction)) {
2273 SetErrorCode("DividedDisk driver failed");
2277 catch (Standard_Failure) {
2278 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2279 SetErrorCode(aFail->GetMessageString());
2283 //Make a Python command
2284 GEOM::TPythonDump(aFunction) << aShape << " = geompy.MakeDividedDisk(" << theR << ", " << theOrientation << ")";
2290 /*@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@*/