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 // #include <GEOMImpl_DividedCylinderDriver.hxx>
51 // #include <GEOMImpl_IDividedCylinder.hxx>
52 /*@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@*/
55 #include <TopExp_Explorer.hxx>
57 #include <TopoDS_Vertex.hxx>
58 #include <TopTools_IndexedMapOfShape.hxx>
64 #include <BRepBuilderAPI_Transform.hxx>
65 #include <BRep_Tool.hxx>
69 #include <TFunction_DriverTable.hxx>
70 #include <TFunction_Driver.hxx>
71 #include <TFunction_Logbook.hxx>
72 #include <TDF_Tool.hxx>
73 #include <Standard_Failure.hxx>
74 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
76 #define HALF_LENGTH_MAIN_PIPE "Main pipe half length" //"Tuyau principal - demi longueur"
77 #define HALF_LENGTH_INCIDENT_PIPE "Incident pipe half length" //"Tuyau incident - demi longueur"
78 #define CIRCULAR_QUARTER_PIPE "Circular quarter of pipe" //"Circulaire - quart de tuyau"
79 #define THICKNESS "Thickness" //"Epaisseur"
80 #define FLANGE "Flange" // "Collerette"
81 #define CHAMFER_OR_FILLET "Chamfer or fillet" //"Chanfrein ou Raccord"
82 #define JUNCTION_FACE_1 "Junction 1" //"Face de jonction 1"
83 #define JUNCTION_FACE_2 "Junction 2" //"Face de jonction 2"
84 #define JUNCTION_FACE_3 "Junction 3" //"Face de jonction 3"
86 //=============================================================================
90 //=============================================================================
91 GEOMImpl_IAdvancedOperations::GEOMImpl_IAdvancedOperations(GEOM_Engine* theEngine, int theDocID) :
92 GEOM_IOperations(theEngine, theDocID)
94 MESSAGE("GEOMImpl_IAdvancedOperations::GEOMImpl_IAdvancedOperations");
95 myBasicOperations = new GEOMImpl_IBasicOperations(GetEngine(), GetDocID());
96 myBooleanOperations = new GEOMImpl_IBooleanOperations(GetEngine(), GetDocID());
97 myShapesOperations = new GEOMImpl_IShapesOperations(GetEngine(), GetDocID());
98 myTransformOperations = new GEOMImpl_ITransformOperations(GetEngine(), GetDocID());
99 myBlocksOperations = new GEOMImpl_IBlocksOperations(GetEngine(), GetDocID());
100 my3DPrimOperations = new GEOMImpl_I3DPrimOperations(GetEngine(), GetDocID());
101 myLocalOperations = new GEOMImpl_ILocalOperations(GetEngine(), GetDocID());
102 myHealingOperations = new GEOMImpl_IHealingOperations(GetEngine(), GetDocID());
105 //=============================================================================
109 //=============================================================================
110 GEOMImpl_IAdvancedOperations::~GEOMImpl_IAdvancedOperations()
112 MESSAGE("GEOMImpl_IAdvancedOperations::~GEOMImpl_IAdvancedOperations");
113 delete myBasicOperations;
114 delete myBooleanOperations;
115 delete myShapesOperations;
116 delete myTransformOperations;
117 delete myBlocksOperations;
118 delete my3DPrimOperations;
119 delete myLocalOperations;
120 delete myHealingOperations;
123 //=============================================================================
127 //=============================================================================
128 gp_Trsf GEOMImpl_IAdvancedOperations::GetPositionTrsf(double theL1, double theL2,
129 Handle(GEOM_Object) theP1,
130 Handle(GEOM_Object) theP2,
131 Handle(GEOM_Object) theP3)
133 // Old Local Coordinates System oldLCS
135 gp_Pnt P1(-theL1, 0, 0);
136 gp_Pnt P2(theL1, 0, 0);
137 gp_Pnt P3(0, 0, theL2);
139 gp_Dir oldX(gp_Vec(P1, P2));
140 gp_Dir oldZ(gp_Vec(P0, P3));
141 gp_Ax3 oldLCS(P0, oldZ, oldX);
143 // New Local Coordinates System newLCS
144 double LocX, LocY, LocZ;
145 gp_Pnt newP1 = BRep_Tool::Pnt(TopoDS::Vertex(theP1->GetValue()));
146 gp_Pnt newP2 = BRep_Tool::Pnt(TopoDS::Vertex(theP2->GetValue()));
147 gp_Pnt newP3 = BRep_Tool::Pnt(TopoDS::Vertex(theP3->GetValue()));
148 LocX = (newP1.X() + newP2.X()) / 2.;
149 LocY = (newP1.Y() + newP2.Y()) / 2.;
150 LocZ = (newP1.Z() + newP2.Z()) / 2.;
151 gp_Pnt newO(LocX, LocY, LocZ);
153 gp_Dir newX(gp_Vec(newP1, newP2)); // P1P2 Vector
154 gp_Dir newZ(gp_Vec(newO, newP3)); // OP3 Vector
155 gp_Ax3 newLCS = gp_Ax3(newO, newZ, newX);
158 aTrsf.SetDisplacement(oldLCS, newLCS);
163 //=============================================================================
165 * CheckCompatiblePosition
168 //=============================================================================
169 bool GEOMImpl_IAdvancedOperations::CheckCompatiblePosition(double& theL1, double& theL2,
170 Handle(GEOM_Object) theP1,
171 Handle(GEOM_Object) theP2,
172 Handle(GEOM_Object) theP3,
176 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(theP1->GetValue()));
177 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(theP2->GetValue()));
178 gp_Pnt P3 = BRep_Tool::Pnt(TopoDS::Vertex(theP3->GetValue()));
180 double d12 = P1.Distance(P2);
181 double d13 = P1.Distance(P3);
182 double d23 = P2.Distance(P3);
183 // double d2 = newO.Distance(P3);
185 if (Abs(d12) <= Precision::Confusion()) {
186 SetErrorCode("Junctions points P1 and P2 are identical");
189 if (Abs(d13) <= Precision::Confusion()) {
190 SetErrorCode("Junctions points P1 and P3 are identical");
193 if (Abs(d23) <= Precision::Confusion()) {
194 SetErrorCode("Junctions points P2 and P3 are identical");
199 double newL1 = 0.5 * d12;
200 double newL2 = sqrt(pow(d13,2)-pow(newL1,2));
202 // theL1*(1-theTolerance) <= newL1 <= theL1*(1+theTolerance)
204 if (fabs(newL1 - theL1) > Precision::Approximation()) {
205 if ( (newL1 * (1 - theTolerance) -theL1 <= Precision::Approximation()) &&
206 (newL1 * (1 + theTolerance) -theL1 >= Precision::Approximation()) ) {
207 // std::cerr << "theL1 = newL1" << std::endl;
211 SetErrorCode("Dimension for main pipe (L1) is incompatible with new position");
217 // theL2*(1-theTolerance) <= newL2 <= theL2*(1+theTolerance)
219 if (fabs(newL2 - theL2) > Precision::Approximation()) {
220 if ( (newL2 * (1 - theTolerance) -theL2 <= Precision::Approximation()) &&
221 (newL2 * (1 + theTolerance) -theL2 >= Precision::Approximation()) ) {
225 SetErrorCode("Dimension for incident pipe (L2) is incompatible with new position");
235 //=============================================================================
237 * Generate the propagation groups of a Pipe T-Shape used for hexa mesh
239 //=============================================================================
240 bool GEOMImpl_IAdvancedOperations::MakeGroups(Handle(GEOM_Object) theShape, int shapeType,
241 double theR1, double theW1, double theL1,
242 double theR2, double theW2, double theL2,
243 Handle(TColStd_HSequenceOfTransient) theSeq,
248 if (theShape.IsNull()) return false;
250 TopoDS_Shape aShape = theShape->GetValue();
251 if (aShape.IsNull()) {
252 SetErrorCode("Shape is not defined");
256 gp_Trsf aTrsfInv = aTrsf.Inverted();
258 // int expectedGroups = 0;
259 // if (shapeType == TSHAPE_BASIC)
260 // if (Abs(theR2+theW2-theR1-theW1) <= Precision::Approximation())
261 // expectedGroups = 10;
263 // expectedGroups = 11;
264 // else if (shapeType == TSHAPE_CHAMFER || shapeType == TSHAPE_FILLET)
265 // expectedGroups = 12;
267 double aR1Ext = theR1 + theW1;
268 double aR2Ext = theR2 + theW2;
270 /////////////////////////
271 //// Groups of Faces ////
272 /////////////////////////
275 // Comment the following lines when GetInPlace bug is solved
277 // Workaround of GetInPlace bug
278 // Create a bounding box that fits the shape
279 Handle(GEOM_Object) aBox = my3DPrimOperations->MakeBoxDXDYDZ(2*theL1, 2*aR1Ext, aR1Ext+theL2);
280 aBox->GetLastFunction()->SetDescription("");
281 myTransformOperations->TranslateDXDYDZ(aBox, -theL1, -aR1Ext, -aR1Ext);
282 aBox->GetLastFunction()->SetDescription("");
283 // Apply transformation to box
284 BRepBuilderAPI_Transform aTransformationBox(aBox->GetValue(), aTrsf, Standard_False);
285 TopoDS_Shape aBoxShapeTrsf = aTransformationBox.Shape();
286 aBox->GetLastFunction()->SetValue(aBoxShapeTrsf);
288 // Get the shell of the box
289 Handle(GEOM_Object) aShell = Handle(GEOM_Object)::DownCast
290 (myShapesOperations->MakeExplode(aBox, TopAbs_SHELL, true)->Value(1));
291 aBox->GetLastFunction()->SetDescription("");
292 aShell->GetLastFunction()->SetDescription("");
293 // Get the common shapes between shell and shape
294 Handle(GEOM_Object) aCommonCompound = myBooleanOperations->MakeBoolean (theShape, aShell, 1); // MakeCommon
295 if (aCommonCompound.IsNull()) {
296 SetErrorCode(myBooleanOperations->GetErrorCode());
299 aCommonCompound->GetLastFunction()->SetDescription("");
300 // Explode the faces of common shapes => 3 faces
301 Handle(TColStd_HSequenceOfTransient) aCommonFaces =
302 myShapesOperations->MakeExplode(aCommonCompound, TopAbs_FACE, true);
303 aCommonCompound->GetLastFunction()->SetDescription("");
304 std::list<Handle(GEOM_Object)> aCompoundOfFacesList;
306 for (int i=0 ; i<= aCommonFaces->Length()-4 ; i+=4) {
307 std::list<Handle(GEOM_Object)> aFacesList;
308 for (int j = 1 ; j <= 4 ; j++) {
309 Handle(GEOM_Object) aFace = Handle(GEOM_Object)::DownCast(aCommonFaces->Value(i+j)); // Junction faces
310 if (!aFace.IsNull()) {
311 aFace->GetLastFunction()->SetDescription("");
312 aFacesList.push_back(aFace);
315 Handle(GEOM_Object) aCompoundOfFaces = myShapesOperations->MakeCompound(aFacesList);
316 if (!aCompoundOfFaces.IsNull()) {
317 aCompoundOfFaces->GetLastFunction()->SetDescription("");
318 aCompoundOfFacesList.push_back(aCompoundOfFaces);
322 if (aCompoundOfFacesList.size() == 3) {
323 Handle(GEOM_Object) aPln1 = aCompoundOfFacesList.front();
324 aCompoundOfFacesList.pop_front();
325 Handle(GEOM_Object) aPln2 = aCompoundOfFacesList.front();
326 aCompoundOfFacesList.pop_front();
327 Handle(GEOM_Object) aPln3 = aCompoundOfFacesList.front();
328 aCompoundOfFacesList.pop_front();
333 // Uncomment the following lines when GetInPlace bug is solved
335 // Handle(GEOM_Object) aP1 = myBasicOperations->MakePointXYZ(-theL1, 0, 0);
336 // Handle(GEOM_Object) aP2 = myBasicOperations->MakePointXYZ(-0, 0, theL2);
337 // Handle(GEOM_Object) aP3 = myBasicOperations->MakePointXYZ(theL1, 0, 0);
338 // aP1->GetLastFunction()->SetDescription("");
339 // aP2->GetLastFunction()->SetDescription("");
340 // aP3->GetLastFunction()->SetDescription("");
341 // Handle(GEOM_Object) aV1 = myBasicOperations->MakeVectorDXDYDZ(-1, 0, 0);
342 // Handle(GEOM_Object) aV2 = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
343 // Handle(GEOM_Object) aV3 = myBasicOperations->MakeVectorDXDYDZ(1, 0, 0);
344 // aV1->GetLastFunction()->SetDescription("");
345 // aV2->GetLastFunction()->SetDescription("");
346 // aV3->GetLastFunction()->SetDescription("");
347 // Handle(GEOM_Object) aPln1 = myBasicOperations->MakePlanePntVec(aP1, aV1, 2*(aR1Ext+theL2));
348 // Handle(GEOM_Object) aPln2 = myBasicOperations->MakePlanePntVec(aP2, aV2, 2*(aR2Ext));
349 // Handle(GEOM_Object) aPln3 = myBasicOperations->MakePlanePntVec(aP3, aV3, 2*(aR1Ext+theL2));
350 // aPln1->GetLastFunction()->SetDescription("");
351 // aPln2->GetLastFunction()->SetDescription("");
352 // aPln3->GetLastFunction()->SetDescription("");
354 // BRepBuilderAPI_Transform aTransformation1(aPln1->GetValue(), aTrsf, Standard_False);
355 // TopoDS_Shape aTrsf_Shape1 = aTransformation1.Shape();
356 // aPln1->GetLastFunction()->SetValue(aTrsf_Shape1);
357 // BRepBuilderAPI_Transform aTransformation2(aPln2->GetValue(), aTrsf, Standard_False);
358 // TopoDS_Shape aTrsf_Shape2 = aTransformation2.Shape();
359 // aPln2->GetLastFunction()->SetValue(aTrsf_Shape2);
360 // BRepBuilderAPI_Transform aTransformation3(aPln3->GetValue(), aTrsf, Standard_False);
361 // TopoDS_Shape aTrsf_Shape3 = aTransformation3.Shape();
362 // aPln3->GetLastFunction()->SetValue(aTrsf_Shape3);
366 Handle(GEOM_Object) junctionFaces1 = myShapesOperations->GetInPlace(theShape, aPln1);
367 if (junctionFaces1.IsNull())
368 junctionFaces1 = myShapesOperations->GetShapesOnShapeAsCompound
369 (aPln1, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
370 if (!junctionFaces1.IsNull()) {
371 junctionFaces1->GetLastFunction()->SetDescription("");
372 junctionFaces1->SetName("JUNCTION_FACE_1");
373 theSeq->Append(junctionFaces1);
376 SetErrorCode("Junction face 1 not found");
377 // theSeq->Append(aPln1);
380 Handle(GEOM_Object) junctionFaces2 = myShapesOperations->GetInPlace(theShape, aPln2);
381 if (junctionFaces2.IsNull())
382 junctionFaces2 = myShapesOperations->GetShapesOnShapeAsCompound
383 (aPln2, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
384 if (!junctionFaces2.IsNull()) {
385 junctionFaces2->GetLastFunction()->SetDescription("");
386 junctionFaces2->SetName("JUNCTION_FACE_2");
387 theSeq->Append(junctionFaces2);
390 SetErrorCode("Junction face 2 not found");
391 // theSeq->Append(aPln2);
394 Handle(GEOM_Object) junctionFaces3 = myShapesOperations->GetInPlace(theShape, aPln3);
395 if (junctionFaces3.IsNull())
396 junctionFaces3 = myShapesOperations->GetShapesOnShapeAsCompound
397 (aPln3, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
398 if (!junctionFaces3.IsNull()) {
399 junctionFaces3->GetLastFunction()->SetDescription("");
400 junctionFaces3->SetName("JUNCTION_FACE_3");
401 theSeq->Append(junctionFaces3);
404 SetErrorCode("Junction face 3 not found");
405 // theSeq->Append(aPln3);
408 // Comment the following lines when GetInPlace bug is solved
412 /////////////////////////
413 //// Groups of Edges ////
414 /////////////////////////
415 // Result of propagate
417 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
419 TCollection_AsciiString theDesc = aFunction->GetDescription();
420 Handle(TColStd_HSequenceOfTransient) aSeqPropagate = myBlocksOperations->Propagate(theShape);
421 if (aSeqPropagate.IsNull() || aSeqPropagate->Length() == 0) {
422 SetErrorCode("Propagation groups not found");
425 Standard_Integer nbEdges, aNbGroups = aSeqPropagate->Length();
426 // Recover previous description to get rid of Propagate dump
427 aFunction->SetDescription(theDesc);
430 bool circularFoundAndAdded = false;
431 bool circularFound10 = false;
432 bool incidentPipeFound = false;
433 bool mainPipeFound = false;
434 bool mainPipeFoundAndAdded = false;
435 bool radialFound =false;
436 bool flangeFound = false;
437 bool flangeFoundAndAdded = false;
438 bool chamferOrFilletFound = false;
440 for (int i=1 ; i<= aNbGroups; i++) {
443 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(aSeqPropagate->Value(i));
447 TopoDS_Shape aGroupShape = aGroup->GetValue();
448 BRepBuilderAPI_Transform aTransformationShapeInv(aGroupShape, aTrsfInv, Standard_False);
449 TopoDS_Shape aGroupShapeTrsfInv = aTransformationShapeInv.Shape();
451 TopTools_IndexedMapOfShape anEdgesMap;
452 TopExp::MapShapes(aGroupShapeTrsfInv,TopAbs_EDGE, anEdgesMap);
453 nbEdges = anEdgesMap.Extent();
455 if (shapeType == TSHAPE_BASIC) {
456 if ((nbEdges == 21) || /*R1Ext = R2Ext*/(nbEdges == 17)){
458 aGroup->SetName("THICKNESS");
460 else if (nbEdges == 6) {
461 if (!circularFoundAndAdded) {
462 circularFoundAndAdded = true;
464 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
467 else if (nbEdges == 8) {
468 incidentPipeFound = true;
469 mainPipeFound = false;
473 TopExp_Explorer Ex(aGroupShapeTrsfInv,TopAbs_VERTEX);
475 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
476 double x=aP.X(), y=aP.Y(), z=aP.Z();
479 if ((Abs(x) > aR2Ext + Precision::Confusion()) ||
480 (Abs(y) > aR2Ext + Precision::Confusion())) {
481 incidentPipeFound = false;
484 if ( z < -Precision::Confusion()) {
485 // length of main pipe
486 mainPipeFound = true;
487 if (!mainPipeFoundAndAdded) {
488 mainPipeFoundAndAdded = true;
490 aGroup->SetName("HALF_LENGTH_MAIN_PIPE");
494 else if (Abs(x) > (theL1-Precision::Confusion())) {
495 // discretisation circulaire
497 if (!circularFoundAndAdded) {
498 circularFoundAndAdded = true;
500 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
505 if (incidentPipeFound) {
507 aGroup->SetName("HALF_LENGTH_INCIDENT_PIPE");
509 if (!addGroup && (!incidentPipeFound &&
513 // Flange (collerette)
516 aGroup->SetName("FLANGE");
522 else if (shapeType == TSHAPE_CHAMFER || shapeType == TSHAPE_FILLET) {
525 aGroup->SetName("THICKNESS");
527 else if ((nbEdges == 10) || (nbEdges == 6)) {
528 if (!circularFoundAndAdded) {
530 circularFoundAndAdded = true;
531 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
533 circularFound10 = true;
536 else if (!circularFound10 && nbEdges == 10) {
537 circularFound10 = true;
539 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
542 else if (nbEdges == 8) {
543 incidentPipeFound = true;
544 mainPipeFound = true;
547 bool isNearZ0 = false;
548 bool isBelowZ0 = false;
550 TopExp_Explorer Ex (aGroupShapeTrsfInv,TopAbs_VERTEX);
552 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
553 double x=aP.X(), y=aP.Y(), z=aP.Z();
555 // tuy_princ_long_avant & tuy_princ_long_apres
556 //bool isMain = (((z < Precision::Confusion()) || (x < Precision::Confusion())) &&
557 // ((y <= aR1Ext + Precision::Confusion()) ||
558 // (y <= -(aR1Ext + Precision::Confusion())) ||
559 // (y <= theR1 + Precision::Confusion()) ||
560 // (y == -(theR1 + Precision::Confusion()))));
561 bool isMain = ((z < Precision::Confusion() || x < Precision::Confusion()) &&
562 (fabs(y) > theR1 - Precision::Confusion() ||
563 fabs(y) < Precision::Confusion()));
566 mainPipeFound = false;
570 //if (z < Precision::Confusion() && !isMain) {
571 // flangeFound = true;
572 // if (!flangeFoundAndAdded) {
573 // flangeFoundAndAdded = true;
575 // aGroup->SetName("FLANGE");
578 if (fabs(z) < Precision::Confusion()) isNearZ0 = true;
579 if (z < - Precision::Confusion()) isBelowZ0 = true;
582 if ((Abs(x) > aR2Ext + Precision::Confusion()) ||
583 (Abs(y) > aR2Ext + Precision::Confusion())) {
584 incidentPipeFound = false;
590 aGroup->SetName("HALF_LENGTH_MAIN_PIPE");
592 if (incidentPipeFound) {
594 aGroup->SetName("HALF_LENGTH_INCIDENT_PIPE");
596 if (isNearZ0 && !isBelowZ0) {
598 if (!flangeFoundAndAdded) {
599 flangeFoundAndAdded = true;
601 aGroup->SetName("FLANGE");
604 if (!addGroup && (!incidentPipeFound &&
607 !chamferOrFilletFound)) {
609 chamferOrFilletFound = true;
610 if (shapeType == TSHAPE_CHAMFER)
611 aGroup->SetName("CHAMFER");
613 aGroup->SetName("FILLET");
619 // Add group to the list
621 theSeq->Append(aGroup);
628 bool GEOMImpl_IAdvancedOperations::MakePipeTShapePartition(Handle(GEOM_Object) theShape,
629 double theR1, double theW1, double theL1,
630 double theR2, double theW2, double theL2,
631 double theH, double theW,
632 double theRF, bool isNormal)
636 // Build tools for partition operation:
637 // 1 face and 2 planes
639 Handle(GEOM_Object) arete_intersect_int;
640 Handle(GEOM_Object) wire_t, wire_t2, face_t, face_t2;
641 Handle(GEOM_Object) chan_racc;
642 Handle(GEOM_Object) vi1, vi2;
643 Handle(GEOM_Object) Te3;
646 #if OCC_VERSION_LARGE > 0x06010000
649 Handle(GEOM_Object) Vector_Z = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
650 Vector_Z->GetLastFunction()->SetDescription("");
653 double aSize = 2*(theL1 + theL2);
654 double aR1Ext = theR1 + theW1;
655 double aR2Ext = theR2 + theW2;
656 double theVertCylinderRadius = aR2Ext + theW + theRF;
657 double theHoriCylinderRadius = aR1Ext + theH + theRF;
659 // Common edges on internal cylinder
660 Handle(GEOM_Object) box_i = my3DPrimOperations->MakeBoxDXDYDZ(theR2, theR2, theR1);
661 box_i->GetLastFunction()->SetDescription("");
662 box_i = myTransformOperations->TranslateDXDYDZ(box_i, -theR2, -theR2, 0);
663 box_i->GetLastFunction()->SetDescription("");
665 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
666 TCollection_AsciiString theDesc = aFunction->GetDescription();
667 Handle(TColStd_HSequenceOfTransient) edges_i =
668 myShapesOperations->GetShapesOnBox(box_i, theShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
669 // Recover previous description to get rid of Propagate dump
670 aFunction->SetDescription(theDesc);
671 if (edges_i.IsNull() || edges_i->Length() == 0) {
672 SetErrorCode("Internal edges not found");
675 for (int i=1; i<=edges_i->Length();i++) {
676 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(edges_i->Value(i));
677 anObj->GetLastFunction()->SetDescription("");
679 arete_intersect_int = Handle(GEOM_Object)::DownCast(edges_i->Value(1));
681 // search for vertices located on both internal pipes
682 aFunction = theShape->GetLastFunction();
683 theDesc = aFunction->GetDescription();
684 Handle(TColStd_HSequenceOfTransient) vertices_i =
685 myShapesOperations->GetShapesOnBox(box_i, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
686 // Recover previous description to get rid of Propagate dump
687 aFunction->SetDescription(theDesc);
688 if (vertices_i.IsNull() || vertices_i->Length() == 0) {
689 SetErrorCode("Internal vertices not found");
693 for (int i = 1; i <= vertices_i->Length(); i++) {
694 Handle(GEOM_Object) v = Handle(GEOM_Object)::DownCast(vertices_i->Value(i));
695 v->GetLastFunction()->SetDescription("");
696 TopoDS_Vertex aVertex = TopoDS::Vertex(v->GetValue());
697 gp_Pnt aP = BRep_Tool::Pnt(aVertex);
698 // std::cout << "Coords: " << aP.X() << ", " << aP.Y() << ", " << aP.Z() << std::endl;
699 if (Abs(aP.X()) <= Precision::Confusion()) {
700 if (Abs(aP.Y()) - theR1 <= Precision::Confusion()) {
703 } else if (Abs(aP.Y()) <= Precision::Confusion()) {
704 if (Abs(aP.X()) - theR1 <= Precision::Confusion()) {
710 std::list<Handle(GEOM_Object)> theShapes;
713 Handle(GEOM_Object) ve1, ve2;
715 Handle(GEOM_Object) box_e = my3DPrimOperations->MakeBoxDXDYDZ(aR2Ext, aR2Ext, aR1Ext);
716 box_e->GetLastFunction()->SetDescription("");
717 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -aR2Ext, -aR2Ext, 0);
718 box_e->GetLastFunction()->SetDescription("");
719 // Common edges on external cylinder
720 aFunction = theShape->GetLastFunction();
721 theDesc = aFunction->GetDescription();
722 Handle(TColStd_HSequenceOfTransient) edges_e =
723 myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
724 // Recover previous description to get rid of Propagate dump
725 aFunction->SetDescription(theDesc);
726 if (edges_e.IsNull() || edges_e->Length() == 0) {
727 SetErrorCode("External edges not found");
730 for (int i=1; i<=edges_e->Length();i++) {
731 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(edges_e->Value(i));
732 anObj->GetLastFunction()->SetDescription("");
735 // search for vertices located on both external pipes
736 aFunction = theShape->GetLastFunction();
737 theDesc = aFunction->GetDescription();
738 Handle(TColStd_HSequenceOfTransient) vertices_e =
739 myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
740 // Recover previous description to get rid of Propagate dump
741 aFunction->SetDescription(theDesc);
742 if (vertices_e.IsNull() || vertices_e->Length() == 0) {
743 SetErrorCode("External vertices not found");
747 for (int i = 1; i <= vertices_e->Length(); i++) {
748 Handle(GEOM_Object) v = Handle(GEOM_Object)::DownCast(vertices_e->Value(i));
749 v->GetLastFunction()->SetDescription("");
750 TopoDS_Vertex aVertex = TopoDS::Vertex(v->GetValue());
751 gp_Pnt aP = BRep_Tool::Pnt(aVertex);
752 // std::cout << "Coords: " << aP.X() << ", " << aP.Y() << ", " << aP.Z() << std::endl;
753 if (Abs(aP.X()) <= Precision::Confusion()) {
754 if (Abs(aP.Y()) - theR2 > Precision::Confusion()) {
757 } else if (Abs(aP.Y()) <= Precision::Confusion()) {
758 if (Abs(aP.X()) - theR2 > Precision::Confusion()) {
762 if ( !ve1.IsNull() && !ve2.IsNull())
765 Handle(GEOM_Object) edge_e1, edge_e2;
767 edge_e1 = myBasicOperations->MakeLineTwoPnt(ve1, vi1);
768 if (edge_e1.IsNull()) {
769 SetErrorCode("Edge 1 could not be built");
773 edge_e2 = myBasicOperations->MakeLineTwoPnt(ve2, vi2);
774 if (edge_e2.IsNull()) {
775 SetErrorCode("Edge 2 could not be built");
779 edge_e1->GetLastFunction()->SetDescription("");
780 edge_e2->GetLastFunction()->SetDescription("");
782 std::list<Handle(GEOM_Object)> edge_e_elist;
783 edge_e_elist.push_back(arete_intersect_int);
784 edge_e_elist.push_back(edge_e1);
785 edge_e_elist.push_back(Handle(GEOM_Object)::DownCast(edges_e->Value(1)));
786 edge_e_elist.push_back(edge_e2);
787 wire_t = myShapesOperations->MakeWire(edge_e_elist, 1e-7);
788 if (wire_t.IsNull()) {
789 SetErrorCode("Impossible to build wire");
792 wire_t->GetLastFunction()->SetDescription("");
793 face_t = myShapesOperations->MakeFace(wire_t, false);
794 if (face_t.IsNull()) {
795 SetErrorCode("Impossible to build face");
798 face_t->GetLastFunction()->SetDescription("");
800 theShapes.push_back(theShape);
801 theShapes.push_back(vi1);
802 theShapes.push_back(vi2);
803 theShapes.push_back(ve1);
804 theShapes.push_back(ve2);
805 theShapes.push_back(edge_e1);
806 theShapes.push_back(edge_e2);
807 theShapes.push_back(wire_t);
808 theShapes.push_back(face_t);
811 Handle(GEOM_Object) P1, P2, P3, P4, P5, P6;
812 int idP1, idP2, idP3, idP4;
817 Handle(GEOM_Object) box_e = my3DPrimOperations->MakeBoxDXDYDZ
818 (theVertCylinderRadius, theVertCylinderRadius, theHoriCylinderRadius);
819 box_e->GetLastFunction()->SetDescription("");
820 box_e = myTransformOperations->TranslateDXDYDZ
821 (box_e, -theVertCylinderRadius, -theVertCylinderRadius, 0);
822 box_e->GetLastFunction()->SetDescription("");
824 aFunction = theShape->GetLastFunction();
825 theDesc = aFunction->GetDescription();
826 Handle(TColStd_HSequenceOfTransient) extremVertices =
827 myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
828 // Recover previous description to get rid of Propagate dump
829 aFunction->SetDescription(theDesc);
831 if (extremVertices.IsNull() || extremVertices->Length() == 0) {
833 SetErrorCode("Vertices on chamfer not found");
835 SetErrorCode("Vertices on fillet not found");
839 theShapes.push_back(theShape);
840 theShapes.push_back(box_e);
841 if (extremVertices->Length() != 6) {
842 // for (int i=1; i<=extremVertices->Length(); i++){
843 // theShapes.push_back(Handle(GEOM_Object)::DownCast(extremVertices->Value(i)));
845 // Handle(GEOM_Object) aCompound = myShapesOperations->MakeCompound(theShapes);
846 // TopoDS_Shape aCompoundShape = aCompound->GetValue();
847 // theShape->GetLastFunction()->SetValue(aCompoundShape);
848 SetErrorCode("Bad number of vertices on chamfer found");
852 for (int i=1; i<=extremVertices->Length(); i++){
853 Handle(GEOM_Object) aV = Handle(GEOM_Object)::DownCast(extremVertices->Value(i));
854 aV->GetLastFunction()->SetDescription("");
855 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aV->GetValue()));
857 if (Abs(aP.X()) <= Precision::Confusion()) {
858 if (Abs(aP.Y()) - theR2 > Precision::Confusion()) {
860 if (aP.Z()-ZX > Precision::Confusion()) {
867 if (Abs(aP.X()) - theR2 > Precision::Confusion()) {
869 if (aP.Z() - ZY > Precision::Confusion()) {
886 P1 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP1));
887 P2 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP2));
888 P3 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP3));
889 P4 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP4));
891 Handle(GEOM_Object) Cote_1 = myBasicOperations->MakeLineTwoPnt(P1, vi1);
892 if (Cote_1.IsNull()) {
893 SetErrorCode("Impossible to build edge in thickness");
896 Cote_1->GetLastFunction()->SetDescription("");
898 Handle(GEOM_Object) Cote_2 = myBasicOperations->MakeLineTwoPnt(vi2, P3);
899 if (Cote_2.IsNull()) {
900 SetErrorCode("Impossible to build edge in thickness");
903 Cote_2->GetLastFunction()->SetDescription("");
905 // edge_chan_princ = arete du chanfrein (ou raccord) sur le tuyau principal
906 // edge_chan_inc = arete du chanfrein (ou raccord) sur le tuyau incident
907 // std::cerr << "Getting chamfer edge on main pipe" << std::endl;
908 Handle(GEOM_Object) edge_chan_princ = myBlocksOperations->GetEdge(theShape, P1, P3);
909 if (edge_chan_princ.IsNull()) {
910 SetErrorCode("Impossible to find edge on main pipe");
913 edge_chan_princ->GetLastFunction()->SetDescription("");
915 Handle(GEOM_Object) edge_chan_inc = myBlocksOperations->GetEdge(theShape, P2, P4);
916 if (edge_chan_inc.IsNull()) {
917 SetErrorCode("Impossible to find edge on incident pipe");
920 edge_chan_inc->GetLastFunction()->SetDescription("");
922 std::list<Handle(GEOM_Object)> edgeList1;
923 edgeList1.push_back(edge_chan_princ);
924 edgeList1.push_back(Cote_1);
925 edgeList1.push_back(arete_intersect_int);
926 edgeList1.push_back(Cote_2);
928 // std::cerr << "Creating wire 1" << std::endl;
929 wire_t = myShapesOperations->MakeWire(edgeList1, 1e-7);
930 if (wire_t.IsNull()) {
931 SetErrorCode("Impossible to build wire");
934 wire_t->GetLastFunction()->SetDescription("");
936 // std::cerr << "Creating face 1" << std::endl;
937 face_t = myShapesOperations->MakeFace(wire_t, false);
938 if (face_t.IsNull()) {
939 SetErrorCode("Impossible to build face");
942 face_t->GetLastFunction()->SetDescription("");
943 theShapes.push_back(face_t);
945 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(P2->GetValue()));
946 gp_Pnt aP5 = BRep_Tool::Pnt(TopoDS::Vertex(vi1->GetValue()));
947 double deltaZ = aP2.Z() - aP5.Z();
948 // std::cerr << "Creating new point from vi1 with deltaZ = " << deltaZ << std::endl;
949 Handle(GEOM_Object) P5bis = myTransformOperations->TranslateDXDYDZCopy(vi1, 0, 0, deltaZ);
950 if (P5bis.IsNull()) {
951 SetErrorCode("Impossible to translate vertex");
954 P5bis->GetLastFunction()->SetDescription("");
956 gp_Pnt aP4 = BRep_Tool::Pnt(TopoDS::Vertex(P4->GetValue()));
957 gp_Pnt aP6 = BRep_Tool::Pnt(TopoDS::Vertex(vi2->GetValue()));
958 deltaZ = aP4.Z() - aP6.Z();
959 // std::cerr << "Creating new point from vi2 with deltaZ = " << deltaZ << std::endl;
960 Handle(GEOM_Object) P6bis = myTransformOperations->TranslateDXDYDZCopy(vi2, 0, 0, deltaZ);
961 if (P6bis.IsNull()) {
962 SetErrorCode("Impossible to translate vertex");
965 P6bis->GetLastFunction()->SetDescription("");
967 // std::cerr << "Creating new line 1 from 2 previous points" << std::endl;
968 Handle(GEOM_Object) Cote_3 = myBasicOperations->MakeLineTwoPnt(P5bis, P2);
969 if (Cote_3.IsNull()) {
970 SetErrorCode("Impossible to build edge in thickness");
973 Cote_3->GetLastFunction()->SetDescription("");
975 // std::cerr << "Creating new line 2 from 2 previous points" << std::endl;
976 Handle(GEOM_Object) Cote_4 = myBasicOperations->MakeLineTwoPnt(P6bis, P4);
977 if (Cote_4.IsNull()) {
978 SetErrorCode("Impossible to build edge in thickness");
981 Cote_4->GetLastFunction()->SetDescription("");
983 // std::cerr << "Creating new line 3 from 2 previous points" << std::endl;
984 Handle(GEOM_Object) Cote_5 = myBasicOperations->MakeLineTwoPnt(P5bis, P6bis);
985 if (Cote_4.IsNull()) {
986 SetErrorCode("Impossible to build edge in thickness");
989 Cote_5->GetLastFunction()->SetDescription("");
991 //std::list<Handle(GEOM_Object)> edgeList2;
992 //edgeList2.push_back(edge_chan_inc);
993 //edgeList2.push_back(Cote_3);
994 //edgeList2.push_back(Cote_5);
995 //edgeList2.push_back(Cote_4);
996 // std::cerr << "Creating wire 2" << std::endl;
997 //wire_t2 = myShapesOperations->MakeWire(edgeList2, 1e-7);
998 //if (wire_t2.IsNull()) {
999 // SetErrorCode("Impossible to build wire");
1002 //wire_t2->GetLastFunction()->SetDescription("");
1003 // std::cerr << "Creating face 2" << std::endl;
1004 //face_t2 = myShapesOperations->MakeFace(wire_t2, false);
1006 // Mantis issue 0021682
1007 face_t2 = my3DPrimOperations->MakePrismVecH(edge_chan_inc, Cote_4, - (theR2 + theW2));
1008 //face_t2 = my3DPrimOperations->MakePrismVecH(edge_chan_inc, Cote_4, - 2.0*theR2);
1009 if (face_t2.IsNull()) {
1010 SetErrorCode("Impossible to build face");
1013 face_t2->GetLastFunction()->SetDescription("");
1014 theShapes.push_back(face_t2);
1018 Handle(GEOM_Object) aP0 = myBasicOperations->MakePointXYZ(0, 0, 0);
1019 Handle(GEOM_Object) aVZ = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
1020 Handle(GEOM_Object) aVXZ = myBasicOperations->MakeVectorDXDYDZ(aR1Ext, 0, 0.5*(theL1+theVertCylinderRadius));
1021 Handle(GEOM_Object) aPlnOZ = myBasicOperations->MakePlanePntVec(aP0, aVZ, aSize);
1022 Handle(GEOM_Object) aPlnOXZ = myBasicOperations->MakePlanePntVec(aP0, aVXZ, aSize);
1023 aP0->GetLastFunction()->SetDescription("");
1024 aVZ->GetLastFunction()->SetDescription("");
1025 aVXZ->GetLastFunction()->SetDescription("");
1026 aPlnOZ->GetLastFunction()->SetDescription("");
1027 aPlnOXZ->GetLastFunction()->SetDescription("");
1028 theShapes.push_back(aPlnOZ);
1029 theShapes.push_back(aPlnOXZ);
1032 Handle(TColStd_HSequenceOfTransient) partitionShapes = new TColStd_HSequenceOfTransient;
1033 Handle(TColStd_HSequenceOfTransient) theTools = new TColStd_HSequenceOfTransient;
1034 Handle(TColStd_HSequenceOfTransient) theKeepInside = new TColStd_HSequenceOfTransient;
1035 Handle(TColStd_HSequenceOfTransient) theRemoveInside = new TColStd_HSequenceOfTransient;
1036 Handle(TColStd_HArray1OfInteger) theMaterials;
1038 partitionShapes->Append(theShape);
1039 theTools->Append(aPlnOZ);
1040 if (Abs(aR1Ext - aR2Ext) > Precision::Confusion())
1041 theTools->Append(aPlnOXZ);
1042 theTools->Append(face_t);
1044 theTools->Append(face_t2);
1046 Te3 = myBooleanOperations->MakePartition
1047 (partitionShapes, theTools, theKeepInside, theRemoveInside,
1048 TopAbs_SOLID, false, theMaterials, 0, false);
1050 SetErrorCode("Impossible to build partition of TShape");
1053 Te3->GetLastFunction()->SetDescription("");
1055 // Last verification: result should be a block
1056 std::list<GEOMImpl_IBlocksOperations::BCError> errList;
1057 if (!myBlocksOperations->CheckCompoundOfBlocks(Te3,errList)) {
1058 SetErrorCode("TShape is not a compound of block");
1062 // // BEGIN Compound of created shapes - Only for debug purpose
1063 // theShapes.clear();
1064 // theShapes.push_back(theShape);
1065 // theShapes.push_back(aPlnOZ);
1066 // if (Abs(aR1Ext - aR2Ext) > Precision::Confusion() )
1067 // theShapes.push_back(aPlnOXZ);
1068 // theShapes.push_back(face_t);
1070 // theShapes.push_back(face_t2);
1072 // Handle(GEOM_Object) aCompound = myShapesOperations->MakeCompound(theShapes);
1073 // TopoDS_Shape aCompoundShape = aCompound->GetValue();
1074 // theShape->GetLastFunction()->SetValue(aCompoundShape);
1075 // // END Compound of created shapes - Only for debug purpose
1077 TopoDS_Shape aShape = Te3->GetValue();
1078 theShape->GetLastFunction()->SetValue(aShape);
1079 } catch (Standard_Failure) {
1080 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1081 SetErrorCode(aFail->GetMessageString());
1089 // Mirror and glue faces
1090 bool GEOMImpl_IAdvancedOperations::MakePipeTShapeMirrorAndGlue(Handle(GEOM_Object) theShape,
1091 double theR1, double theW1, double theL1,
1092 double theR2, double theW2, double theL2)
1097 double aSize = 2*(theL1 + theL2);
1098 double aR1Ext = theR1 + theW1;
1101 Handle(GEOM_Object) aP0 = myBasicOperations->MakePointXYZ(0, 0, 0);
1102 aP0->GetLastFunction()->SetDescription("");
1103 Handle(GEOM_Object) aVX = myBasicOperations->MakeVectorDXDYDZ(1, 0, 0);
1104 Handle(GEOM_Object) aVY = myBasicOperations->MakeVectorDXDYDZ(0, 1, 0);
1105 aVX->GetLastFunction()->SetDescription("");
1106 aVY->GetLastFunction()->SetDescription("");
1107 Handle(GEOM_Object) aPlane_OX = myBasicOperations->MakePlanePntVec(aP0, aVX, 2*(aR1Ext + theL2));
1108 Handle(GEOM_Object) aPlane_OY = myBasicOperations->MakePlanePntVec(aP0, aVY, aSize);
1109 aPlane_OX->GetLastFunction()->SetDescription("");
1110 aPlane_OY->GetLastFunction()->SetDescription("");
1112 Handle(GEOM_Object) Te4 = myTransformOperations->MirrorPlaneCopy(theShape, aPlane_OX);
1114 SetErrorCode("Impossible to build mirror of quarter TShape");
1118 Handle(GEOM_Object) Te5 = myTransformOperations->MirrorPlaneCopy(theShape, aPlane_OY);
1120 SetErrorCode("Impossible to build mirror of half TShape");
1124 Handle(GEOM_Object) Te6 = myTransformOperations->MirrorPlaneCopy(Te4, aPlane_OY);
1126 SetErrorCode("Impossible to build mirror of half TShape");
1130 std::list<Handle(GEOM_Object)> aShapesList;
1131 aShapesList.push_back(theShape);
1132 aShapesList.push_back(Te4);
1133 aShapesList.push_back(Te5);
1134 aShapesList.push_back(Te6);
1135 Handle(GEOM_Object) Te7 = myShapesOperations->MakeCompound(aShapesList);
1137 SetErrorCode("Impossible to build compound");
1141 Handle(GEOM_Object) Te8 = myShapesOperations->MakeGlueFaces(Te7, 1e-7, true);
1143 SetErrorCode("Impossible to glue faces of TShape");
1147 TopoDS_Shape aShape = Te8->GetValue();
1149 theShape->GetLastFunction()->SetValue(aShape);
1151 Te4->GetLastFunction()->SetDescription("");
1152 Te5->GetLastFunction()->SetDescription("");
1153 Te6->GetLastFunction()->SetDescription("");
1154 Te7->GetLastFunction()->SetDescription("");
1155 Te8->GetLastFunction()->SetDescription("");
1161 //=============================================================================
1164 * \brief Create a T-shape object with specified caracteristics for the main and
1165 * the incident pipes (radius, width, half-length).
1166 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1167 * \param theR1 Internal radius of main pipe
1168 * \param theW1 Width of main pipe
1169 * \param theL1 Half-length of main pipe
1170 * \param theR2 Internal radius of incident pipe (R2 < R1)
1171 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1172 * \param theL2 Half-length of incident pipe
1173 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1174 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1176 //=============================================================================
1177 Handle(TColStd_HSequenceOfTransient)
1178 GEOMImpl_IAdvancedOperations::MakePipeTShape(double theR1, double theW1, double theL1,
1179 double theR2, double theW2, double theL2,
1182 MESSAGE("GEOMImpl_IAdvancedOperations::MakePipeTShape");
1185 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1187 //Add a new shape function with parameters
1188 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_BASIC);
1189 if (aFunction.IsNull()) return NULL;
1191 //Check if the function is set correctly
1192 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1194 GEOMImpl_IPipeTShape aData(aFunction);
1202 aData.SetHexMesh(theHexMesh);
1204 //Compute the resulting value
1206 #if OCC_VERSION_LARGE > 0x06010000
1209 if (!GetSolver()->ComputeFunction(aFunction)) {
1210 SetErrorCode("TShape driver failed");
1214 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1216 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1219 } catch (Standard_Failure) {
1220 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1221 SetErrorCode(aFail->GetMessageString());
1226 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1227 aSeq->Append(aShape);
1231 * Get the groups: BEGIN
1234 if (!MakeGroups(aShape, TSHAPE_BASIC, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1237 catch (Standard_Failure) {
1238 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1239 SetErrorCode(aFail->GetMessageString());
1243 TCollection_AsciiString aListRes, anEntry;
1244 // Iterate over the sequence aSeq
1245 Standard_Integer aNbGroups = aSeq->Length();
1246 Standard_Integer i = 2;
1247 for (; i <= aNbGroups; i++) {
1248 Handle(Standard_Transient) anItem = aSeq->Value(i);
1249 if (anItem.IsNull()) continue;
1250 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1251 if (aGroup.IsNull()) continue;
1252 //Make a Python command
1253 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1254 aListRes += anEntry + ", ";
1257 aListRes.Trunc(aListRes.Length() - 2);
1259 //Make a Python command
1260 GEOM::TPythonDump(aFunction)
1261 << "[" << aShape << ", " << aListRes.ToCString() << "] = geompy.MakePipeTShape("
1262 << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", "
1263 << theHexMesh << ")";
1266 * Get the groups: END
1269 //Make a Python command
1270 GEOM::TPythonDump(aFunction)
1271 << "[" << aShape << "] = geompy.MakePipeTShape(" << theR1 << ", " << theW1 << ", "
1272 << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theHexMesh << ")";
1280 //=============================================================================
1282 * MakePipeTShapeWithPosition
1283 * Create a T-shape object with specified caracteristics for the main and
1284 * the incident pipes (radius, width, half-length).
1285 * The extremities of the main pipe are located on junctions points P1 and P2.
1286 * The extremity of the incident pipe is located on junction point P3.
1287 * \param theR1 Internal radius of main pipe
1288 * \param theW1 Width of main pipe
1289 * \param theL1 Half-length of main pipe
1290 * \param theR2 Internal radius of incident pipe (R2 < R1)
1291 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1292 * \param theL2 Half-length of incident pipe
1293 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1294 * \param theP1 1st junction point of main pipe
1295 * \param theP2 2nd junction point of main pipe
1296 * \param theP3 Junction point of incident pipe
1297 * \return List of GEOM_Objects, containing the created shape and propagation groups..
1299 //=============================================================================
1300 Handle(TColStd_HSequenceOfTransient)
1301 GEOMImpl_IAdvancedOperations::MakePipeTShapeWithPosition(double theR1, double theW1, double theL1,
1302 double theR2, double theW2, double theL2,
1304 Handle(GEOM_Object) theP1,
1305 Handle(GEOM_Object) theP2,
1306 Handle(GEOM_Object) theP3)
1310 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1314 //Add a new shape function with parameters
1315 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_BASIC);
1316 if (aFunction.IsNull()) return NULL;
1318 //Check if the function is set correctly
1319 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1321 // Check new position
1322 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1326 GEOMImpl_IPipeTShape aData(aFunction);
1334 aData.SetHexMesh(theHexMesh);
1336 //Compute the resulting value
1338 #if OCC_VERSION_LARGE > 0x06010000
1341 if (!GetSolver()->ComputeFunction(aFunction)) {
1342 SetErrorCode("TShape driver failed");
1345 } catch (Standard_Failure) {
1346 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1347 SetErrorCode(aFail->GetMessageString());
1352 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1354 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1358 TopoDS_Shape Te = aShape->GetValue();
1361 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
1362 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
1363 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
1364 aFunction->SetValue(aTrsf_Shape);
1365 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1366 aSeq->Append(aShape);
1370 // Get the groups: BEGIN
1373 if (!MakeGroups(aShape,TSHAPE_BASIC, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf)) {
1377 catch (Standard_Failure) {
1378 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1379 SetErrorCode(aFail->GetMessageString());
1383 TCollection_AsciiString aListRes, anEntry;
1384 // Iterate over the sequence aSeq
1385 Standard_Integer aNbGroups = aSeq->Length();
1386 Standard_Integer i = 2;
1387 for (; i <= aNbGroups; i++) {
1388 Handle(Standard_Transient) anItem = aSeq->Value(i);
1389 if (anItem.IsNull()) continue;
1390 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1391 if (aGroup.IsNull()) continue;
1392 //Make a Python command
1393 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1394 aListRes += anEntry + ", ";
1397 aListRes.Trunc(aListRes.Length() - 2);
1399 //Make a Python command
1400 GEOM::TPythonDump(aFunction)
1401 << "[" << aShape << ", " << aListRes.ToCString() << "] = geompy.MakePipeTShape("
1402 << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", "
1403 << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
1406 // Get the groups: END
1410 //Make a Python command
1411 GEOM::TPythonDump(aFunction)
1412 << "[" << aShape << "] = geompy.MakePipeTShape(" << theR1 << ", " << theW1 << ", "
1413 << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theHexMesh << ", " << theP1
1414 << ", " << theP2 << ", " << theP3 << ")";
1422 //=============================================================================
1424 * MakePipeTShapeChamfer
1425 * Create a T-shape object with specified caracteristics for the main and
1426 * the incident pipes (radius, width, half-length). A chamfer is created
1427 * on the junction of the pipes.
1428 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1429 * \param theR1 Internal radius of main pipe
1430 * \param theW1 Width of main pipe
1431 * \param theL1 Half-length of main pipe
1432 * \param theR2 Internal radius of incident pipe (R2 < R1)
1433 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1434 * \param theL2 Half-length of incident pipe
1435 * \param theH Height of chamfer.
1436 * \param theW Width of chamfer.
1437 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1438 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1440 //=============================================================================
1441 Handle(TColStd_HSequenceOfTransient)
1442 GEOMImpl_IAdvancedOperations::MakePipeTShapeChamfer(double theR1, double theW1, double theL1,
1443 double theR2, double theW2, double theL2,
1444 double theH, double theW,
1449 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1450 //Add a new shape function with parameters
1451 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_CHAMFER);
1452 if (aFunction.IsNull()) return NULL;
1454 //Check if the function is set correctly
1455 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1457 GEOMImpl_IPipeTShape aData(aFunction);
1467 aData.SetHexMesh(theHexMesh);
1469 //Compute the resulting value
1471 #if OCC_VERSION_LARGE > 0x06010000
1474 if (!GetSolver()->ComputeFunction(aFunction)) {
1475 SetErrorCode("TShape driver failed");
1478 } catch (Standard_Failure) {
1479 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1480 SetErrorCode(aFail->GetMessageString());
1485 TopoDS_Shape aShapeShape = aShape->GetValue();
1486 TopTools_IndexedMapOfShape anEdgesIndices;
1487 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1488 // Common edges on external cylinders
1489 Handle(GEOM_Object) box_e;
1491 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1494 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1496 box_e->GetLastFunction()->SetDescription("");
1497 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1498 box_e->GetLastFunction()->SetDescription("");
1500 Handle(TColStd_HSequenceOfInteger) edges_e =
1501 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1502 box_e->GetLastFunction()->SetDescription("");
1504 if (edges_e.IsNull() || edges_e->Length() == 0) {
1505 SetErrorCode("External edges not found");
1508 int nbEdgesInChamfer = 0;
1509 std::list<int> theEdges;
1510 for (int i=1; i<=edges_e->Length();i++) {
1511 int edgeID = edges_e->Value(i);
1512 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1513 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1517 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1518 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1519 nbEdgesInChamfer ++;
1520 theEdges.push_back(edgeID);
1524 if (theHexMesh && nbEdgesInChamfer == 1)
1527 Handle(GEOM_Object) aChamfer;
1529 aChamfer = myLocalOperations->MakeChamferEdges(aShape, theW, theH, theEdges);
1531 catch (Standard_Failure) {
1532 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1533 SetErrorCode(aFail->GetMessageString());
1536 if (aChamfer.IsNull()) {
1537 SetErrorCode("Chamfer can not be computed on the given shape with the given parameters");
1540 aChamfer->GetLastFunction()->SetDescription("");
1542 TopoDS_Shape aChamferShape = aChamfer->GetValue();
1543 aFunction->SetValue(aChamferShape);
1546 // bool doMesh = false;
1549 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, 0, false)) {
1550 MESSAGE("PipeTShape partition failed");
1554 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2)) {
1555 MESSAGE("PipeTShape mirrors and glue failed");
1561 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1562 aSeq->Append(aShape);
1567 // Get the groups: BEGIN
1569 //if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf())) {
1570 // //Make a Python command
1571 // GEOM::TPythonDump(aFunction)
1572 // << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1573 // << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1574 // << ", " << theHexMesh << ")";
1578 if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1581 catch (Standard_Failure) {
1582 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1583 SetErrorCode(aFail->GetMessageString());
1587 TCollection_AsciiString aListRes, anEntry;
1588 // Iterate over the sequence aSeq
1589 Standard_Integer aNbGroups = aSeq->Length();
1590 Standard_Integer i = 2;
1591 for (; i <= aNbGroups; i++) {
1592 Handle(Standard_Transient) anItem = aSeq->Value(i);
1593 if (anItem.IsNull()) continue;
1594 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1595 if (aGroup.IsNull()) continue;
1596 //Make a Python command
1597 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1598 aListRes += anEntry + ", ";
1601 aListRes.Trunc(aListRes.Length() - 2);
1603 //Make a Python command
1604 GEOM::TPythonDump(aFunction)
1605 << "[" << aShape << ", " << aListRes.ToCString()
1606 << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1607 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW << ", " << theHexMesh << ")";
1611 // Get the groups: END
1614 //Make a Python command
1615 GEOM::TPythonDump(aFunction)
1616 << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1617 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1618 << ", " << theHexMesh << ")";
1626 //=============================================================================
1628 * MakePipeTShapeChamferWithPosition
1629 * Create a T-shape object with specified caracteristics for the main and
1630 * the incident pipes (radius, width, half-length). A chamfer is created
1631 * on the junction of the pipes.
1632 * The extremities of the main pipe are located on junctions points P1 and P2.
1633 * The extremity of the incident pipe is located on junction point P3.
1634 * \param theR1 Internal radius of main pipe
1635 * \param theW1 Width of main pipe
1636 * \param theL1 Half-length of main pipe
1637 * \param theR2 Internal radius of incident pipe (R2 < R1)
1638 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1639 * \param theL2 Half-length of incident pipe
1640 * \param theH Height of chamfer.
1641 * \param theW Width of chamfer.
1642 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1643 * \param theP1 1st junction point of main pipe
1644 * \param theP2 2nd junction point of main pipe
1645 * \param theP3 Junction point of incident pipe
1646 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1648 //=============================================================================
1649 Handle(TColStd_HSequenceOfTransient)
1650 GEOMImpl_IAdvancedOperations::MakePipeTShapeChamferWithPosition(double theR1, double theW1, double theL1,
1651 double theR2, double theW2, double theL2,
1652 double theH, double theW,
1654 Handle(GEOM_Object) theP1,
1655 Handle(GEOM_Object) theP2,
1656 Handle(GEOM_Object) theP3)
1660 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1661 //Add a new shape function with parameters
1662 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_CHAMFER);
1663 if (aFunction.IsNull()) return NULL;
1665 //Check if the function is set correctly
1666 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1668 // Check new position
1669 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1673 GEOMImpl_IPipeTShape aData(aFunction);
1683 aData.SetHexMesh(theHexMesh);
1685 //Compute the resulting value
1687 #if OCC_VERSION_LARGE > 0x06010000
1690 if (!GetSolver()->ComputeFunction(aFunction)) {
1691 SetErrorCode("TShape driver failed");
1694 } catch (Standard_Failure) {
1695 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1696 SetErrorCode(aFail->GetMessageString());
1701 TopoDS_Shape aShapeShape = aShape->GetValue();
1702 TopTools_IndexedMapOfShape anEdgesIndices;
1703 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1704 // Common edges on external cylinders
1705 Handle(GEOM_Object) box_e;
1707 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1710 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1712 box_e->GetLastFunction()->SetDescription("");
1713 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1714 box_e->GetLastFunction()->SetDescription("");
1716 Handle(TColStd_HSequenceOfInteger) edges_e =
1717 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1718 box_e->GetLastFunction()->SetDescription("");
1720 if (edges_e.IsNull() || edges_e->Length() == 0) {
1721 SetErrorCode("External edges not found");
1724 int nbEdgesInChamfer = 0;
1725 std::list<int> theEdges;
1726 for (int i=1; i<=edges_e->Length();i++) {
1727 int edgeID = edges_e->Value(i);
1728 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1729 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1731 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1732 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1733 nbEdgesInChamfer ++;
1734 theEdges.push_back(edgeID);
1738 if (theHexMesh && nbEdgesInChamfer == 1)
1741 Handle(GEOM_Object) aChamfer;
1743 aChamfer = myLocalOperations->MakeChamferEdges(aShape, theW, theH, theEdges);
1745 catch (Standard_Failure) {
1746 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1747 SetErrorCode(aFail->GetMessageString());
1750 if (aChamfer.IsNull()) {
1751 SetErrorCode("Chamfer can not be computed on the given shape with the given parameters");
1754 aChamfer->GetLastFunction()->SetDescription("");
1756 TopoDS_Shape aChamferShape = aChamfer->GetValue();
1757 aFunction->SetValue(aChamferShape);
1761 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, 0, false))
1763 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1767 TopoDS_Shape Te = aShape->GetValue();
1770 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
1771 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
1772 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
1773 aFunction->SetValue(aTrsf_Shape);
1774 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1775 aSeq->Append(aShape);
1778 * Get the groups: BEGIN
1781 if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf))
1784 catch (Standard_Failure) {
1785 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1786 SetErrorCode(aFail->GetMessageString());
1790 TCollection_AsciiString aListRes, anEntry;
1791 // Iterate over the sequence aSeq
1792 Standard_Integer aNbGroups = aSeq->Length();
1793 Standard_Integer i = 2;
1794 for (; i <= aNbGroups; i++) {
1795 Handle(Standard_Transient) anItem = aSeq->Value(i);
1796 if (anItem.IsNull()) continue;
1797 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1798 if (aGroup.IsNull()) continue;
1799 //Make a Python command
1800 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1801 aListRes += anEntry + ", ";
1804 aListRes.Trunc(aListRes.Length() - 2);
1806 //Make a Python command
1807 GEOM::TPythonDump(aFunction)
1808 << "[" << aShape << ", " << aListRes.ToCString()
1809 << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1810 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW << ", " << theHexMesh << ", "
1811 << theP1 << ", " << theP2 << ", " << theP3 << ")";
1814 * Get the groups: END
1817 //Make a Python command
1818 GEOM::TPythonDump(aFunction)
1819 << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1820 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1821 << ", " << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
1829 //=============================================================================
1831 * MakePipeTShapeFillet
1832 * Create a T-shape object with specified caracteristics for the main and
1833 * the incident pipes (radius, width, half-length). A fillet is created
1834 * on the junction of the pipes.
1835 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1836 * \param theR1 Internal radius of main pipe
1837 * \param theW1 Width of main pipe
1838 * \param theL1 Half-length of main pipe
1839 * \param theR2 Internal radius of incident pipe (R2 < R1)
1840 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1841 * \param theL2 Half-length of incident pipe
1842 * \param theRF Radius of curvature of fillet.
1843 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1844 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1846 //=============================================================================
1847 Handle(TColStd_HSequenceOfTransient)
1848 GEOMImpl_IAdvancedOperations::MakePipeTShapeFillet(double theR1, double theW1, double theL1,
1849 double theR2, double theW2, double theL2,
1850 double theRF, bool theHexMesh)
1854 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1855 //Add a new shape function with parameters
1856 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_FILLET);
1857 if (aFunction.IsNull()) return NULL;
1859 //Check if the function is set correctly
1860 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1862 GEOMImpl_IPipeTShape aData(aFunction);
1871 aData.SetHexMesh(theHexMesh);
1873 //Compute the resulting value
1875 #if OCC_VERSION_LARGE > 0x06010000
1878 if (!GetSolver()->ComputeFunction(aFunction)) {
1879 SetErrorCode("TShape driver failed");
1882 } catch (Standard_Failure) {
1883 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1884 SetErrorCode(aFail->GetMessageString());
1889 TopoDS_Shape aShapeShape = aShape->GetValue();
1890 TopTools_IndexedMapOfShape anEdgesIndices;
1891 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1892 // Common edges on external cylinders
1893 Handle(GEOM_Object) box_e;
1895 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1898 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1900 box_e->GetLastFunction()->SetDescription("");
1901 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1902 box_e->GetLastFunction()->SetDescription("");
1904 Handle(TColStd_HSequenceOfInteger) edges_e =
1905 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1906 box_e->GetLastFunction()->SetDescription("");
1908 if (edges_e.IsNull() || edges_e->Length() == 0) {
1909 SetErrorCode("External edges not found");
1912 int nbEdgesInFillet = 0;
1913 std::list<int> theEdges;
1914 for (int i=1; i<=edges_e->Length();i++) {
1915 int edgeID = edges_e->Value(i);
1916 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1917 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1919 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1920 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1922 theEdges.push_back(edgeID);
1926 if (theHexMesh && nbEdgesInFillet == 1)
1930 Handle(GEOM_Object) aFillet;
1932 aFillet = myLocalOperations->MakeFilletEdges(aShape, theRF, theEdges);
1934 catch (Standard_Failure) {
1935 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1936 SetErrorCode(aFail->GetMessageString());
1939 if (aFillet.IsNull()) {
1940 //SetErrorCode("Fillet can not be computed on the given shape with the given parameters");
1941 SetErrorCode(myLocalOperations->GetErrorCode());
1944 aFillet->GetLastFunction()->SetDescription("");
1946 TopoDS_Shape aFilletShape = aFillet->GetValue();
1947 aFunction->SetValue(aFilletShape);
1950 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - BEGIN (1)
1951 // the following block, when enabled, leads to partitioning problems
1953 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - END (1)
1954 // BEGIN: Limit tolerances (debug)
1955 Handle(GEOM_Object) aCorr1 = myHealingOperations->LimitTolerance(aShape, 1e-07);
1956 TopoDS_Shape aCorr1Shape = aCorr1->GetValue();
1957 aShape->GetLastFunction()->SetValue(aCorr1Shape);
1958 aCorr1->GetLastFunction()->SetDescription("");
1959 // END: Limit tolerances (debug)
1960 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - BEGIN (2)
1962 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - END (2)
1965 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, 0, 0, theRF, false))
1967 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1971 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1972 aSeq->Append(aShape);
1975 * Get the groups: BEGIN
1978 if (!MakeGroups(aShape, TSHAPE_FILLET, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1981 catch (Standard_Failure) {
1982 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1983 SetErrorCode(aFail->GetMessageString());
1987 TCollection_AsciiString aListRes, anEntry;
1988 // Iterate over the sequence aSeq
1989 Standard_Integer aNbGroups = aSeq->Length();
1990 Standard_Integer i = 2;
1991 for (; i <= aNbGroups; i++) {
1992 Handle(Standard_Transient) anItem = aSeq->Value(i);
1993 if (anItem.IsNull()) continue;
1994 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1995 if (aGroup.IsNull()) continue;
1996 //Make a Python command
1997 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1998 aListRes += anEntry + ", ";
2001 aListRes.Trunc(aListRes.Length() - 2);
2003 //Make a Python command
2004 GEOM::TPythonDump(aFunction)
2005 << "[" << aShape << ", " << aListRes.ToCString()
2006 << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
2007 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", " << theHexMesh << ")";
2010 * Get the groups: END
2013 //Make a Python command
2014 GEOM::TPythonDump(aFunction)
2015 << "[" << aShape << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1
2016 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", "
2017 << theHexMesh << ")";
2025 //=============================================================================
2027 * MakePipeTShapeFilletWithPosition
2028 * \brief Create a T-shape object with specified caracteristics for the main and
2029 * the incident pipes (radius, width, half-length). A fillet is created
2030 * on the junction of the pipes.
2031 * The extremities of the main pipe are located on junctions points P1 and P2.
2032 * The extremity of the incident pipe is located on junction point P3.
2033 * \param theR1 Internal radius of main pipe
2034 * \param theW1 Width of main pipe
2035 * \param theL1 Half-length of main pipe
2036 * \param theR2 Internal radius of incident pipe (R2 < R1)
2037 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
2038 * \param theL2 Half-length of incident pipe
2039 * \param theRF Radius of curvature of fillet
2040 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
2041 * \param theP1 1st junction point of main pipe
2042 * \param theP2 2nd junction point of main pipe
2043 * \param theP3 Junction point of incident pipe
2044 * \return List of GEOM_Objects, containing the created shape and propagation groups.
2046 //=============================================================================
2047 Handle(TColStd_HSequenceOfTransient)
2048 GEOMImpl_IAdvancedOperations::MakePipeTShapeFilletWithPosition(double theR1, double theW1, double theL1,
2049 double theR2, double theW2, double theL2,
2050 double theRF, bool theHexMesh,
2051 Handle(GEOM_Object) theP1,
2052 Handle(GEOM_Object) theP2,
2053 Handle(GEOM_Object) theP3)
2057 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
2058 //Add a new shape function with parameters
2059 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_FILLET);
2060 if (aFunction.IsNull()) return NULL;
2062 //Check if the function is set correctly
2063 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
2065 // Check new position
2066 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
2070 GEOMImpl_IPipeTShape aData(aFunction);
2079 aData.SetHexMesh(theHexMesh);
2081 //Compute the resulting value
2083 #if OCC_VERSION_LARGE > 0x06010000
2086 if (!GetSolver()->ComputeFunction(aFunction)) {
2087 SetErrorCode("TShape driver failed");
2090 } catch (Standard_Failure) {
2091 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2092 SetErrorCode(aFail->GetMessageString());
2097 TopoDS_Shape aShapeShape = aShape->GetValue();
2098 TopTools_IndexedMapOfShape anEdgesIndices;
2099 TopExp::MapShapes(aShapeShape, anEdgesIndices);
2100 // Common edges on external cylinders
2101 Handle(GEOM_Object) box_e;
2103 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
2106 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
2108 box_e->GetLastFunction()->SetDescription("");
2109 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
2110 box_e->GetLastFunction()->SetDescription("");
2112 Handle(TColStd_HSequenceOfInteger) edges_e =
2113 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
2114 box_e->GetLastFunction()->SetDescription("");
2116 if (edges_e.IsNull() || edges_e->Length() == 0) {
2117 SetErrorCode("External edges not found");
2120 int nbEdgesInFillet = 0;
2121 std::list<int> theEdges;
2122 for (int i=1; i<=edges_e->Length();i++) {
2123 int edgeID = edges_e->Value(i);
2124 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
2125 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
2127 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
2128 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
2130 theEdges.push_back(edgeID);
2134 if (theHexMesh && nbEdgesInFillet == 1)
2138 Handle(GEOM_Object) aFillet;
2140 aFillet = myLocalOperations->MakeFilletEdges(aShape, theRF, theEdges);
2142 catch (Standard_Failure) {
2143 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2144 SetErrorCode(aFail->GetMessageString());
2147 if (aFillet.IsNull()) {
2148 SetErrorCode("Fillet can not be computed on the given shape with the given parameters");
2151 aFillet->GetLastFunction()->SetDescription("");
2153 TopoDS_Shape aFilletShape = aFillet->GetValue();
2154 aFunction->SetValue(aFilletShape);
2157 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - BEGIN (3)
2158 // the following block, when enabled, leads to partitioning problems
2160 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - END (3)
2161 // BEGIN: Limit tolerances (debug)
2162 Handle(GEOM_Object) aCorr1 = myHealingOperations->LimitTolerance(aShape, 1e-07);
2163 TopoDS_Shape aCorr1Shape = aCorr1->GetValue();
2164 aShape->GetLastFunction()->SetValue(aCorr1Shape);
2165 aCorr1->GetLastFunction()->SetDescription("");
2166 // END: Limit tolerances (debug)
2167 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - BEGIN (4)
2169 // VSR: debug issues 0021568 and 0021550 (15/05/2012) - END (4)
2172 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, 0, 0, theRF, false))
2174 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
2178 TopoDS_Shape Te = aShape->GetValue();
2181 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
2182 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
2183 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
2184 aFunction->SetValue(aTrsf_Shape);
2185 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
2186 aSeq->Append(aShape);
2189 * Get the groups: BEGIN
2192 if (!MakeGroups(aShape, TSHAPE_FILLET, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf))
2195 catch (Standard_Failure) {
2196 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2197 SetErrorCode(aFail->GetMessageString());
2201 TCollection_AsciiString aListRes, anEntry;
2202 // Iterate over the sequence aSeq
2203 Standard_Integer aNbGroups = aSeq->Length();
2204 Standard_Integer i = 2;
2205 for (; i <= aNbGroups; i++) {
2206 Handle(Standard_Transient) anItem = aSeq->Value(i);
2207 if (anItem.IsNull()) continue;
2208 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
2209 if (aGroup.IsNull()) continue;
2210 //Make a Python command
2211 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
2212 aListRes += anEntry + ", ";
2215 aListRes.Trunc(aListRes.Length() - 2);
2217 //Make a Python command
2218 GEOM::TPythonDump(aFunction)
2219 << "[" << aShape << ", " << aListRes.ToCString()
2220 << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
2221 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", " << theHexMesh << ", " << theP1 << ", "
2222 << theP2 << ", " << theP3 << ")";
2225 * Get the groups: END
2228 //Make a Python command
2229 GEOM::TPythonDump(aFunction)
2230 << "[" << aShape << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1
2231 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", "
2232 << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
2240 //=============================================================================
2242 * This function allows to create a disk already divided into blocks. It can be
2243 * used to create divided pipes for later meshing in hexaedra.
2244 * \param theR Radius of the disk
2245 * \param theRatio Relative size of the central square diagonal against the disk diameter
2246 * \param theOrientation Plane on which the disk will be built
2247 * \param thePattern The division pattern of the disk (hexagon or square in the center)
2248 * \return New GEOM_Object, containing the created shape.
2250 //=============================================================================
2251 Handle(GEOM_Object) GEOMImpl_IAdvancedOperations::MakeDividedDisk (double theR, double theRatio,
2252 int theOrientation, int thePattern)
2257 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_DIVIDEDDISK);
2259 //Add a new shape function with parameters
2260 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_DividedDiskDriver::GetID(), DIVIDEDDISK_R_RATIO);
2261 if (aFunction.IsNull()) return NULL;
2263 //Check if the function is set correctly
2264 if (aFunction->GetDriverGUID() != GEOMImpl_DividedDiskDriver::GetID()) return NULL;
2266 GEOMImpl_IDividedDisk aData (aFunction);
2269 aData.SetRatio(theRatio);
2270 aData.SetOrientation(theOrientation);
2271 aData.SetType(thePattern);
2273 //Compute the resulting value
2275 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2278 if (!GetSolver()->ComputeFunction(aFunction)) {
2279 SetErrorCode("DividedDisk driver failed");
2283 catch (Standard_Failure) {
2284 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2285 SetErrorCode(aFail->GetMessageString());
2289 std::string aPatternStr;
2294 aPatternStr = "GEOM.SQUARE";
2297 aPatternStr = "GEOM.HEXAGON";
2301 //Make a Python command
2302 GEOM::TPythonDump(aFunction) << aShape << " = geompy.MakeDividedDisk(" << theR << ", " << theOrientation << ", " << aPatternStr.c_str() << ")";
2309 //=============================================================================
2311 * This function allows to create a disk already divided into blocks. It can be
2312 * used to create divided pipes for later meshing in hexaedra.
2313 * \param theR Radius of the disk
2314 * \param theRatio Relative size of the central square diagonal against the disk diameter
2315 * \return New GEOM_Object, containing the created shape.
2317 //=============================================================================
2318 Handle(GEOM_Object) GEOMImpl_IAdvancedOperations::MakeDividedDiskPntVecR (Handle(GEOM_Object) thePnt,
2319 Handle(GEOM_Object) theVec,
2327 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_DIVIDEDDISK);
2329 //Add a new shape function with parameters
2330 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_DividedDiskDriver::GetID(), DIVIDEDDISK_R_VECTOR_PNT);
2331 if (aFunction.IsNull()) return NULL;
2333 //Check if the function is set correctly
2334 if (aFunction->GetDriverGUID() != GEOMImpl_DividedDiskDriver::GetID()) return NULL;
2336 GEOMImpl_IDividedDisk aData (aFunction);
2338 Handle(GEOM_Function) aRefPnt = thePnt->GetLastFunction();
2339 Handle(GEOM_Function) aRefVec = theVec->GetLastFunction();
2341 if (aRefPnt.IsNull() || aRefVec.IsNull()) return NULL;
2343 aData.SetCenter(aRefPnt);
2344 aData.SetVector(aRefVec);
2347 aData.SetRatio(theRatio);
2348 aData.SetType(thePattern);
2350 //Compute the resulting value
2352 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2355 if (!GetSolver()->ComputeFunction(aFunction)) {
2356 SetErrorCode("DividedDisk driver failed");
2360 catch (Standard_Failure) {
2361 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2362 SetErrorCode(aFail->GetMessageString());
2366 std::string aPatternStr;
2371 aPatternStr = "GEOM.SQUARE";
2374 aPatternStr = "GEOM.HEXAGON";
2379 //Make a Python command
2380 GEOM::TPythonDump(aFunction) << aShape << " = geompy.MakeDividedDiskPntVecR(" << thePnt << ", " << theVec << ", " << theR << ", " << aPatternStr.c_str() << ")";
2387 //=============================================================================
2389 * Builds a cylinder prepared for hexa meshes
2390 * \param theR Radius of the cylinder
2391 * \param theH Height of the cylinder
2392 * \return New GEOM_Object, containing the created shape.
2394 //=============================================================================
2395 Handle(GEOM_Object) GEOMImpl_IAdvancedOperations::MakeDividedCylinder (double theR,
2402 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_DIVIDEDCYLINDER);
2404 Handle(GEOM_Object) aBaseShape = MakeDividedDisk(theR, 67.0, 1, thePattern);
2405 aBaseShape->GetLastFunction()->SetDescription(""); // Erase dump of MakeDividedDisk
2407 aShape = my3DPrimOperations->MakePrismDXDYDZ(aBaseShape,0.0,0.0,theH, -1.0);
2409 Handle(GEOM_Function) aFunction = aShape->GetLastFunction();
2410 aFunction->SetDescription(""); // Erase dump of MakePrismDXDYDZ
2411 aShape->SetType(GEOM_DIVIDEDCYLINDER);
2413 std::string aPatternStr;
2418 aPatternStr = "GEOM.SQUARE";
2421 aPatternStr = "GEOM.HEXAGON";
2425 //Make a Python command
2426 GEOM::TPythonDump(aFunction) << aShape << " = geompy.MakeDividedCylinder(" << theR << ", " << theH << ", " << aPatternStr.c_str() << ")";
2432 /*@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@*/