1 // Copyright (C) 2007-2011 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 <CASCatch_OCCTVersion.hxx>
39 #include <utilities.h>
41 #include <Utils_ExceptHandlers.hxx>
43 #include "GEOM_Function.hxx"
44 #include "GEOM_PythonDump.hxx"
46 #include "GEOMImpl_PipeTShapeDriver.hxx"
47 #include "GEOMImpl_IPipeTShape.hxx"
48 /*@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@*/
51 #include <TopExp_Explorer.hxx>
53 #include <TopoDS_Vertex.hxx>
54 #include <TopTools_IndexedMapOfShape.hxx>
59 #include <BRepBuilderAPI_Transform.hxx>
60 #include <BRep_Tool.hxx>
63 #include <TFunction_DriverTable.hxx>
64 #include <TFunction_Driver.hxx>
65 #include <TFunction_Logbook.hxx>
66 #include <TDF_Tool.hxx>
67 #include <Standard_Failure.hxx>
68 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
70 #define HALF_LENGTH_MAIN_PIPE "Main pipe half length" //"Tuyau principal - demi longueur"
71 #define HALF_LENGTH_INCIDENT_PIPE "Incident pipe half length" //"Tuyau incident - demi longueur"
72 #define CIRCULAR_QUARTER_PIPE "Circular quarter of pipe" //"Circulaire - quart de tuyau"
73 #define THICKNESS "Thickness" //"Epaisseur"
74 #define FLANGE "Flange" // "Collerette"
75 #define CHAMFER_OR_FILLET "Chamfer or fillet" //"Chanfrein ou Raccord"
76 #define JUNCTION_FACE_1 "Junction 1" //"Face de jonction 1"
77 #define JUNCTION_FACE_2 "Junction 2" //"Face de jonction 2"
78 #define JUNCTION_FACE_3 "Junction 3" //"Face de jonction 3"
80 //=============================================================================
84 //=============================================================================
85 GEOMImpl_IAdvancedOperations::GEOMImpl_IAdvancedOperations(GEOM_Engine* theEngine, int theDocID) :
86 GEOM_IOperations(theEngine, theDocID)
88 MESSAGE("GEOMImpl_IAdvancedOperations::GEOMImpl_IAdvancedOperations");
89 myBasicOperations = new GEOMImpl_IBasicOperations(GetEngine(), GetDocID());
90 myBooleanOperations = new GEOMImpl_IBooleanOperations(GetEngine(), GetDocID());
91 myShapesOperations = new GEOMImpl_IShapesOperations(GetEngine(), GetDocID());
92 myTransformOperations = new GEOMImpl_ITransformOperations(GetEngine(), GetDocID());
93 myBlocksOperations = new GEOMImpl_IBlocksOperations(GetEngine(), GetDocID());
94 my3DPrimOperations = new GEOMImpl_I3DPrimOperations(GetEngine(), GetDocID());
95 myLocalOperations = new GEOMImpl_ILocalOperations(GetEngine(), GetDocID());
96 myHealingOperations = new GEOMImpl_IHealingOperations(GetEngine(), GetDocID());
99 //=============================================================================
103 //=============================================================================
104 GEOMImpl_IAdvancedOperations::~GEOMImpl_IAdvancedOperations()
106 MESSAGE("GEOMImpl_IAdvancedOperations::~GEOMImpl_IAdvancedOperations");
107 delete myBasicOperations;
108 delete myBooleanOperations;
109 delete myShapesOperations;
110 delete myTransformOperations;
111 delete myBlocksOperations;
112 delete my3DPrimOperations;
113 delete myLocalOperations;
114 delete myHealingOperations;
117 //=============================================================================
121 //=============================================================================
122 gp_Trsf GEOMImpl_IAdvancedOperations::GetPositionTrsf(double theL1, double theL2,
123 Handle(GEOM_Object) theP1,
124 Handle(GEOM_Object) theP2,
125 Handle(GEOM_Object) theP3)
127 // Old Local Coordinates System oldLCS
129 gp_Pnt P1(-theL1, 0, 0);
130 gp_Pnt P2(theL1, 0, 0);
131 gp_Pnt P3(0, 0, theL2);
133 gp_Dir oldX(gp_Vec(P1, P2));
134 gp_Dir oldZ(gp_Vec(P0, P3));
135 gp_Ax3 oldLCS(P0, oldZ, oldX);
137 // New Local Coordinates System newLCS
138 double LocX, LocY, LocZ;
139 gp_Pnt newP1 = BRep_Tool::Pnt(TopoDS::Vertex(theP1->GetValue()));
140 gp_Pnt newP2 = BRep_Tool::Pnt(TopoDS::Vertex(theP2->GetValue()));
141 gp_Pnt newP3 = BRep_Tool::Pnt(TopoDS::Vertex(theP3->GetValue()));
142 LocX = (newP1.X() + newP2.X()) / 2.;
143 LocY = (newP1.Y() + newP2.Y()) / 2.;
144 LocZ = (newP1.Z() + newP2.Z()) / 2.;
145 gp_Pnt newO(LocX, LocY, LocZ);
147 gp_Dir newX(gp_Vec(newP1, newP2)); // P1P2 Vector
148 gp_Dir newZ(gp_Vec(newO, newP3)); // OP3 Vector
149 gp_Ax3 newLCS = gp_Ax3(newO, newZ, newX);
152 aTrsf.SetDisplacement(oldLCS, newLCS);
157 //=============================================================================
159 * CheckCompatiblePosition
162 //=============================================================================
163 bool GEOMImpl_IAdvancedOperations::CheckCompatiblePosition(double& theL1, double& theL2,
164 Handle(GEOM_Object) theP1,
165 Handle(GEOM_Object) theP2,
166 Handle(GEOM_Object) theP3,
170 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(theP1->GetValue()));
171 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(theP2->GetValue()));
172 gp_Pnt P3 = BRep_Tool::Pnt(TopoDS::Vertex(theP3->GetValue()));
174 double d12 = P1.Distance(P2);
175 double d13 = P1.Distance(P3);
176 double d23 = P2.Distance(P3);
177 // double d2 = newO.Distance(P3);
179 if (Abs(d12) <= Precision::Confusion()) {
180 SetErrorCode("Junctions points P1 and P2 are identical");
183 if (Abs(d13) <= Precision::Confusion()) {
184 SetErrorCode("Junctions points P1 and P3 are identical");
187 if (Abs(d23) <= Precision::Confusion()) {
188 SetErrorCode("Junctions points P2 and P3 are identical");
193 double newL1 = 0.5 * d12;
194 double newL2 = sqrt(pow(d13,2)-pow(newL1,2));
196 // theL1*(1-theTolerance) <= newL1 <= theL1*(1+theTolerance)
198 if (fabs(newL1 - theL1) > Precision::Approximation()) {
199 if ( (newL1 * (1 - theTolerance) -theL1 <= Precision::Approximation()) &&
200 (newL1 * (1 + theTolerance) -theL1 >= Precision::Approximation()) ) {
201 // std::cerr << "theL1 = newL1" << std::endl;
205 SetErrorCode("Dimension for main pipe (L1) is incompatible with new position");
211 // theL2*(1-theTolerance) <= newL2 <= theL2*(1+theTolerance)
213 if (fabs(newL2 - theL2) > Precision::Approximation()) {
214 if ( (newL2 * (1 - theTolerance) -theL2 <= Precision::Approximation()) &&
215 (newL2 * (1 + theTolerance) -theL2 >= Precision::Approximation()) ) {
219 SetErrorCode("Dimension for incident pipe (L2) is incompatible with new position");
229 //=============================================================================
231 * Generate the propagation groups of a Pipe T-Shape used for hexa mesh
233 //=============================================================================
234 bool GEOMImpl_IAdvancedOperations::MakeGroups(Handle(GEOM_Object) theShape, int shapeType,
235 double theR1, double theW1, double theL1,
236 double theR2, double theW2, double theL2,
237 Handle(TColStd_HSequenceOfTransient) theSeq,
242 if (theShape.IsNull()) return false;
244 TopoDS_Shape aShape = theShape->GetValue();
245 if (aShape.IsNull()) {
246 SetErrorCode("Shape is not defined");
250 gp_Trsf aTrsfInv = aTrsf.Inverted();
252 int expectedGroups = 0;
253 if (shapeType == TSHAPE_BASIC)
254 if (Abs(theR2+theW2-theR1-theW1) <= Precision::Approximation())
258 else if (shapeType == TSHAPE_CHAMFER || shapeType == TSHAPE_FILLET)
261 double aR1Ext = theR1 + theW1;
262 double aR2Ext = theR2 + theW2;
264 /////////////////////////
265 //// Groups of Faces ////
266 /////////////////////////
269 // Comment the following lines when GetInPlace bug is solved
271 // Workaround of GetInPlace bug
272 // Create a bounding box that fits the shape
273 Handle(GEOM_Object) aBox = my3DPrimOperations->MakeBoxDXDYDZ(2*theL1, 2*aR1Ext, aR1Ext+theL2);
274 aBox->GetLastFunction()->SetDescription("");
275 myTransformOperations->TranslateDXDYDZ(aBox, -theL1, -aR1Ext, -aR1Ext);
276 aBox->GetLastFunction()->SetDescription("");
277 // Apply transformation to box
278 BRepBuilderAPI_Transform aTransformationBox(aBox->GetValue(), aTrsf, Standard_False);
279 TopoDS_Shape aBoxShapeTrsf = aTransformationBox.Shape();
280 aBox->GetLastFunction()->SetValue(aBoxShapeTrsf);
282 // Get the shell of the box
283 Handle(GEOM_Object) aShell = Handle(GEOM_Object)::DownCast
284 (myShapesOperations->MakeExplode(aBox, TopAbs_SHELL, true)->Value(1));
285 aBox->GetLastFunction()->SetDescription("");
286 aShell->GetLastFunction()->SetDescription("");
287 // Get the common shapes between shell and shape
288 Handle(GEOM_Object) aCommonCompound = myBooleanOperations->MakeBoolean (theShape, aShell, 1); // MakeCommon
289 if (aCommonCompound.IsNull()) {
290 SetErrorCode(myBooleanOperations->GetErrorCode());
293 aCommonCompound->GetLastFunction()->SetDescription("");
294 // Explode the faces of common shapes => 3 faces
295 Handle(TColStd_HSequenceOfTransient) aCommonFaces =
296 myShapesOperations->MakeExplode(aCommonCompound, TopAbs_FACE, true);
297 aCommonCompound->GetLastFunction()->SetDescription("");
298 std::list<Handle(GEOM_Object)> aCompoundOfFacesList;
300 for (int i=0 ; i<= aCommonFaces->Length()-4 ; i+=4) {
301 std::list<Handle(GEOM_Object)> aFacesList;
302 for (int j = 1 ; j <= 4 ; j++) {
303 Handle(GEOM_Object) aFace = Handle(GEOM_Object)::DownCast(aCommonFaces->Value(i+j)); // Junction faces
304 if (!aFace.IsNull()) {
305 aFace->GetLastFunction()->SetDescription("");
306 aFacesList.push_back(aFace);
309 Handle(GEOM_Object) aCompoundOfFaces = myShapesOperations->MakeCompound(aFacesList);
310 if (!aCompoundOfFaces.IsNull()) {
311 aCompoundOfFaces->GetLastFunction()->SetDescription("");
312 aCompoundOfFacesList.push_back(aCompoundOfFaces);
316 if (aCompoundOfFacesList.size() == 3) {
317 Handle(GEOM_Object) aPln1 = aCompoundOfFacesList.front();
318 aCompoundOfFacesList.pop_front();
319 Handle(GEOM_Object) aPln2 = aCompoundOfFacesList.front();
320 aCompoundOfFacesList.pop_front();
321 Handle(GEOM_Object) aPln3 = aCompoundOfFacesList.front();
322 aCompoundOfFacesList.pop_front();
327 // Uncomment the following lines when GetInPlace bug is solved
329 // Handle(GEOM_Object) aP1 = myBasicOperations->MakePointXYZ(-theL1, 0, 0);
330 // Handle(GEOM_Object) aP2 = myBasicOperations->MakePointXYZ(-0, 0, theL2);
331 // Handle(GEOM_Object) aP3 = myBasicOperations->MakePointXYZ(theL1, 0, 0);
332 // aP1->GetLastFunction()->SetDescription("");
333 // aP2->GetLastFunction()->SetDescription("");
334 // aP3->GetLastFunction()->SetDescription("");
335 // Handle(GEOM_Object) aV1 = myBasicOperations->MakeVectorDXDYDZ(-1, 0, 0);
336 // Handle(GEOM_Object) aV2 = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
337 // Handle(GEOM_Object) aV3 = myBasicOperations->MakeVectorDXDYDZ(1, 0, 0);
338 // aV1->GetLastFunction()->SetDescription("");
339 // aV2->GetLastFunction()->SetDescription("");
340 // aV3->GetLastFunction()->SetDescription("");
341 // Handle(GEOM_Object) aPln1 = myBasicOperations->MakePlanePntVec(aP1, aV1, 2*(aR1Ext+theL2));
342 // Handle(GEOM_Object) aPln2 = myBasicOperations->MakePlanePntVec(aP2, aV2, 2*(aR2Ext));
343 // Handle(GEOM_Object) aPln3 = myBasicOperations->MakePlanePntVec(aP3, aV3, 2*(aR1Ext+theL2));
344 // aPln1->GetLastFunction()->SetDescription("");
345 // aPln2->GetLastFunction()->SetDescription("");
346 // aPln3->GetLastFunction()->SetDescription("");
348 // BRepBuilderAPI_Transform aTransformation1(aPln1->GetValue(), aTrsf, Standard_False);
349 // TopoDS_Shape aTrsf_Shape1 = aTransformation1.Shape();
350 // aPln1->GetLastFunction()->SetValue(aTrsf_Shape1);
351 // BRepBuilderAPI_Transform aTransformation2(aPln2->GetValue(), aTrsf, Standard_False);
352 // TopoDS_Shape aTrsf_Shape2 = aTransformation2.Shape();
353 // aPln2->GetLastFunction()->SetValue(aTrsf_Shape2);
354 // BRepBuilderAPI_Transform aTransformation3(aPln3->GetValue(), aTrsf, Standard_False);
355 // TopoDS_Shape aTrsf_Shape3 = aTransformation3.Shape();
356 // aPln3->GetLastFunction()->SetValue(aTrsf_Shape3);
360 Handle(GEOM_Object) junctionFaces1 = myShapesOperations->GetInPlace(theShape, aPln1);
361 if (junctionFaces1.IsNull())
362 junctionFaces1 = myShapesOperations->GetShapesOnShapeAsCompound
363 (aPln1, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
364 if (!junctionFaces1.IsNull()) {
365 junctionFaces1->GetLastFunction()->SetDescription("");
366 junctionFaces1->SetName("JUNCTION_FACE_1");
367 theSeq->Append(junctionFaces1);
370 SetErrorCode("Junction face 1 not found");
371 // theSeq->Append(aPln1);
374 Handle(GEOM_Object) junctionFaces2 = myShapesOperations->GetInPlace(theShape, aPln2);
375 if (junctionFaces2.IsNull())
376 junctionFaces2 = myShapesOperations->GetShapesOnShapeAsCompound
377 (aPln2, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
378 if (!junctionFaces2.IsNull()) {
379 junctionFaces2->GetLastFunction()->SetDescription("");
380 junctionFaces2->SetName("JUNCTION_FACE_2");
381 theSeq->Append(junctionFaces2);
384 SetErrorCode("Junction face 2 not found");
385 // theSeq->Append(aPln2);
388 Handle(GEOM_Object) junctionFaces3 = myShapesOperations->GetInPlace(theShape, aPln3);
389 if (junctionFaces3.IsNull())
390 junctionFaces3 = myShapesOperations->GetShapesOnShapeAsCompound
391 (aPln3, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
392 if (!junctionFaces3.IsNull()) {
393 junctionFaces3->GetLastFunction()->SetDescription("");
394 junctionFaces3->SetName("JUNCTION_FACE_3");
395 theSeq->Append(junctionFaces3);
398 SetErrorCode("Junction face 3 not found");
399 // theSeq->Append(aPln3);
402 // Comment the following lines when GetInPlace bug is solved
406 /////////////////////////
407 //// Groups of Edges ////
408 /////////////////////////
409 // Result of propagate
411 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
413 TCollection_AsciiString theDesc = aFunction->GetDescription();
414 Handle(TColStd_HSequenceOfTransient) aSeqPropagate = myBlocksOperations->Propagate(theShape);
415 if (aSeqPropagate.IsNull() || aSeqPropagate->Length() == 0) {
416 SetErrorCode("Propagation groups not found");
419 Standard_Integer nbEdges, aNbGroups = aSeqPropagate->Length();
420 // Recover previous description to get rid of Propagate dump
421 aFunction->SetDescription(theDesc);
424 bool circularFoundAndAdded = false;
425 bool circularFound10 = false;
426 bool incidentPipeFound = false;
427 bool mainPipeFound = false;
428 bool mainPipeFoundAndAdded = false;
429 bool radialFound =false;
430 bool flangeFound = false;
431 bool flangeFoundAndAdded = false;
432 bool chamferOrFilletFound = false;
434 for (int i=1 ; i<= aNbGroups; i++) {
437 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(aSeqPropagate->Value(i));
441 TopoDS_Shape aGroupShape = aGroup->GetValue();
442 BRepBuilderAPI_Transform aTransformationShapeInv(aGroupShape, aTrsfInv, Standard_False);
443 TopoDS_Shape aGroupShapeTrsfInv = aTransformationShapeInv.Shape();
445 TopTools_IndexedMapOfShape anEdgesMap;
446 TopExp::MapShapes(aGroupShapeTrsfInv,TopAbs_EDGE, anEdgesMap);
447 nbEdges = anEdgesMap.Extent();
449 if (shapeType == TSHAPE_BASIC) {
450 if ((nbEdges == 21) || /*R1Ext = R2Ext*/(nbEdges == 17)){
452 aGroup->SetName("THICKNESS");
454 else if (nbEdges == 6) {
455 if (!circularFoundAndAdded) {
456 circularFoundAndAdded = true;
458 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
461 else if (nbEdges == 8) {
462 incidentPipeFound = true;
463 mainPipeFound = false;
467 TopExp_Explorer Ex(aGroupShapeTrsfInv,TopAbs_VERTEX);
469 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
470 double x=aP.X(), y=aP.Y(), z=aP.Z();
473 if ((Abs(x) > aR2Ext + Precision::Confusion()) ||
474 (Abs(y) > aR2Ext + Precision::Confusion())) {
475 incidentPipeFound = false;
478 if ( z < -Precision::Confusion()) {
479 // length of main pipe
480 mainPipeFound = true;
481 if (!mainPipeFoundAndAdded) {
482 mainPipeFoundAndAdded = true;
484 aGroup->SetName("HALF_LENGTH_MAIN_PIPE");
488 else if (Abs(x) > (theL1-Precision::Confusion())) {
489 // discretisation circulaire
491 if (!circularFoundAndAdded) {
492 circularFoundAndAdded = true;
494 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
499 if (incidentPipeFound) {
501 aGroup->SetName("HALF_LENGTH_INCIDENT_PIPE");
503 if (!addGroup && (!incidentPipeFound &&
507 // Flange (collerette)
510 aGroup->SetName("FLANGE");
516 else if (shapeType == TSHAPE_CHAMFER || shapeType == TSHAPE_FILLET) {
519 aGroup->SetName("THICKNESS");
521 else if ((nbEdges == 10) || (nbEdges == 6)) {
522 if (!circularFoundAndAdded) {
524 circularFoundAndAdded = true;
525 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
527 circularFound10 = true;
530 else if (!circularFound10 && nbEdges == 10) {
531 circularFound10 = true;
533 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
536 else if (nbEdges == 8) {
537 incidentPipeFound = true;
538 mainPipeFound = true;
541 bool isNearZ0 = false;
542 bool isBelowZ0 = false;
544 TopExp_Explorer Ex (aGroupShapeTrsfInv,TopAbs_VERTEX);
546 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
547 double x=aP.X(), y=aP.Y(), z=aP.Z();
549 // tuy_princ_long_avant & tuy_princ_long_apres
550 //bool isMain = (((z < Precision::Confusion()) || (x < Precision::Confusion())) &&
551 // ((y <= aR1Ext + Precision::Confusion()) ||
552 // (y <= -(aR1Ext + Precision::Confusion())) ||
553 // (y <= theR1 + Precision::Confusion()) ||
554 // (y == -(theR1 + Precision::Confusion()))));
555 bool isMain = ((z < Precision::Confusion() || x < Precision::Confusion()) &&
556 (fabs(y) > theR1 - Precision::Confusion() ||
557 fabs(y) < Precision::Confusion()));
560 mainPipeFound = false;
564 //if (z < Precision::Confusion() && !isMain) {
565 // flangeFound = true;
566 // if (!flangeFoundAndAdded) {
567 // flangeFoundAndAdded = true;
569 // aGroup->SetName("FLANGE");
572 if (fabs(z) < Precision::Confusion()) isNearZ0 = true;
573 if (z < - Precision::Confusion()) isBelowZ0 = true;
576 if ((Abs(x) > aR2Ext + Precision::Confusion()) ||
577 (Abs(y) > aR2Ext + Precision::Confusion())) {
578 incidentPipeFound = false;
584 aGroup->SetName("HALF_LENGTH_MAIN_PIPE");
586 if (incidentPipeFound) {
588 aGroup->SetName("HALF_LENGTH_INCIDENT_PIPE");
590 if (isNearZ0 && !isBelowZ0) {
592 if (!flangeFoundAndAdded) {
593 flangeFoundAndAdded = true;
595 aGroup->SetName("FLANGE");
598 if (!addGroup && (!incidentPipeFound &&
601 !chamferOrFilletFound)) {
603 chamferOrFilletFound = true;
604 if (shapeType == TSHAPE_CHAMFER)
605 aGroup->SetName("CHAMFER");
607 aGroup->SetName("FILLET");
613 // Add group to the list
615 theSeq->Append(aGroup);
622 bool GEOMImpl_IAdvancedOperations::MakePipeTShapePartition(Handle(GEOM_Object) theShape,
623 double theR1, double theW1, double theL1,
624 double theR2, double theW2, double theL2,
625 double theH, double theW,
626 double theRF, bool isNormal)
630 // Build tools for partition operation:
631 // 1 face and 2 planes
633 Handle(GEOM_Object) arete_intersect_int;
634 Handle(GEOM_Object) wire_t, wire_t2, face_t, face_t2;
635 Handle(GEOM_Object) chan_racc;
636 Handle(GEOM_Object) vi1, vi2;
638 Handle(GEOM_Object) Vector_Z = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
639 Vector_Z->GetLastFunction()->SetDescription("");
642 double aSize = 2*(theL1 + theL2);
643 double aR1Ext = theR1 + theW1;
644 double aR2Ext = theR2 + theW2;
645 double theVertCylinderRadius = aR2Ext + theW + theRF;
646 double theHoriCylinderRadius = aR1Ext + theH + theRF;
648 // Common edges on internal cylinder
649 Handle(GEOM_Object) box_i = my3DPrimOperations->MakeBoxDXDYDZ(theR2, theR2, theR1);
650 box_i->GetLastFunction()->SetDescription("");
651 box_i = myTransformOperations->TranslateDXDYDZ(box_i, -theR2, -theR2, 0);
652 box_i->GetLastFunction()->SetDescription("");
654 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
655 TCollection_AsciiString theDesc = aFunction->GetDescription();
656 Handle(TColStd_HSequenceOfTransient) edges_i =
657 myShapesOperations->GetShapesOnBox(box_i, theShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
658 // Recover previous description to get rid of Propagate dump
659 aFunction->SetDescription(theDesc);
660 if (edges_i.IsNull() || edges_i->Length() == 0) {
661 SetErrorCode("Internal edges not found");
664 for (int i=1; i<=edges_i->Length();i++) {
665 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(edges_i->Value(i));
666 anObj->GetLastFunction()->SetDescription("");
668 arete_intersect_int = Handle(GEOM_Object)::DownCast(edges_i->Value(1));
670 // search for vertices located on both internal pipes
671 aFunction = theShape->GetLastFunction();
672 theDesc = aFunction->GetDescription();
673 Handle(TColStd_HSequenceOfTransient) vertices_i =
674 myShapesOperations->GetShapesOnBox(box_i, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
675 // Recover previous description to get rid of Propagate dump
676 aFunction->SetDescription(theDesc);
677 if (vertices_i.IsNull() || vertices_i->Length() == 0) {
678 SetErrorCode("Internal vertices not found");
682 for (int i = 1; i <= vertices_i->Length(); i++) {
683 Handle(GEOM_Object) v = Handle(GEOM_Object)::DownCast(vertices_i->Value(i));
684 v->GetLastFunction()->SetDescription("");
685 TopoDS_Vertex aVertex = TopoDS::Vertex(v->GetValue());
686 gp_Pnt aP = BRep_Tool::Pnt(aVertex);
687 if (Abs(aP.X()) <= Precision::Confusion()) {
688 if (Abs(aP.Y()) - theR2 <= Precision::Confusion())
690 } else if (Abs(aP.Y()) <= Precision::Confusion()) {
691 if (Abs(aP.X()) - theR1 <= Precision::Confusion())
696 std::list<Handle(GEOM_Object)> theShapes;
699 Handle(GEOM_Object) ve1, ve2;
701 Handle(GEOM_Object) box_e = my3DPrimOperations->MakeBoxDXDYDZ(aR2Ext, aR2Ext, aR1Ext);
702 box_e->GetLastFunction()->SetDescription("");
703 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -aR2Ext, -aR2Ext, 0);
704 box_e->GetLastFunction()->SetDescription("");
705 // Common edges on external cylinder
706 aFunction = theShape->GetLastFunction();
707 theDesc = aFunction->GetDescription();
708 Handle(TColStd_HSequenceOfTransient) edges_e =
709 myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
710 // Recover previous description to get rid of Propagate dump
711 aFunction->SetDescription(theDesc);
712 if (edges_e.IsNull() || edges_e->Length() == 0) {
713 SetErrorCode("External edges not found");
716 for (int i=1; i<=edges_e->Length();i++) {
717 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(edges_e->Value(i));
718 anObj->GetLastFunction()->SetDescription("");
721 // search for vertices located on both external pipes
722 aFunction = theShape->GetLastFunction();
723 theDesc = aFunction->GetDescription();
724 Handle(TColStd_HSequenceOfTransient) vertices_e =
725 myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
726 // Recover previous description to get rid of Propagate dump
727 aFunction->SetDescription(theDesc);
728 if (vertices_e.IsNull() || vertices_e->Length() == 0) {
729 SetErrorCode("External vertices not found");
733 for (int i = 1; i <= vertices_e->Length(); i++) {
734 Handle(GEOM_Object) v = Handle(GEOM_Object)::DownCast(vertices_e->Value(i));
735 v->GetLastFunction()->SetDescription("");
736 TopoDS_Vertex aVertex = TopoDS::Vertex(v->GetValue());
737 gp_Pnt aP = BRep_Tool::Pnt(aVertex);
738 if (Abs(aP.X()) <= Precision::Confusion()) {
739 if (Abs(aP.Y()) - theR2 > Precision::Confusion())
741 } else if (Abs(aP.Y()) <= Precision::Confusion()) {
742 if (Abs(aP.X()) - theR2 > Precision::Confusion())
746 Handle(GEOM_Object) edge_e1, edge_e2;
748 #if OCC_VERSION_LARGE > 0x06010000
751 edge_e1 = myBasicOperations->MakeLineTwoPnt(ve1, vi1);
752 if (edge_e1.IsNull()) {
753 SetErrorCode("Edge 1 could not be built");
756 } catch (Standard_Failure) {
757 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
758 SetErrorCode(aFail->GetMessageString());
763 #if OCC_VERSION_LARGE > 0x06010000
766 edge_e2 = myBasicOperations->MakeLineTwoPnt(ve2, vi2);
767 if (edge_e2.IsNull()) {
768 SetErrorCode("Edge 2 could not be built");
771 } catch (Standard_Failure) {
772 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
773 SetErrorCode(aFail->GetMessageString());
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("");
799 Handle(GEOM_Object) P1, P2, P3, P4, P5, P6;
800 int idP1, idP2, idP3, idP4;
805 Handle(GEOM_Object) box_e = my3DPrimOperations->MakeBoxDXDYDZ
806 (theVertCylinderRadius, theVertCylinderRadius, theHoriCylinderRadius);
807 box_e->GetLastFunction()->SetDescription("");
808 box_e = myTransformOperations->TranslateDXDYDZ
809 (box_e, -theVertCylinderRadius, -theVertCylinderRadius, 0);
810 box_e->GetLastFunction()->SetDescription("");
812 aFunction = theShape->GetLastFunction();
813 theDesc = aFunction->GetDescription();
814 Handle(TColStd_HSequenceOfTransient) extremVertices =
815 myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
816 // Recover previous description to get rid of Propagate dump
817 aFunction->SetDescription(theDesc);
819 if (extremVertices.IsNull() || extremVertices->Length() == 0) {
821 SetErrorCode("Vertices on chamfer not found");
823 SetErrorCode("Vertices on fillet not found");
827 theShapes.push_back(theShape);
828 theShapes.push_back(box_e);
829 if (extremVertices->Length() != 6) {
830 // for (int i=1; i<=extremVertices->Length(); i++){
831 // theShapes.push_back(Handle(GEOM_Object)::DownCast(extremVertices->Value(i)));
833 // Handle(GEOM_Object) aCompound = myShapesOperations->MakeCompound(theShapes);
834 // TopoDS_Shape aCompoundShape = aCompound->GetValue();
835 // theShape->GetLastFunction()->SetValue(aCompoundShape);
836 SetErrorCode("Bad number of vertices on chamfer found");
840 for (int i=1; i<=extremVertices->Length(); i++){
841 Handle(GEOM_Object) aV = Handle(GEOM_Object)::DownCast(extremVertices->Value(i));
842 aV->GetLastFunction()->SetDescription("");
843 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aV->GetValue()));
845 if (Abs(aP.X()) <= Precision::Confusion()) {
846 if (Abs(aP.Y()) - theR2 > Precision::Confusion()) {
848 if (aP.Z()-ZX > Precision::Confusion()) {
855 if (Abs(aP.X()) - theR2 > Precision::Confusion()) {
857 if (aP.Z() - ZY > Precision::Confusion()) {
874 P1 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP1));
875 P2 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP2));
876 P3 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP3));
877 P4 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP4));
879 Handle(GEOM_Object) Cote_1 = myBasicOperations->MakeLineTwoPnt(P1, vi1);
880 if (Cote_1.IsNull()) {
881 SetErrorCode("Impossible to build edge in thickness");
884 Cote_1->GetLastFunction()->SetDescription("");
886 Handle(GEOM_Object) Cote_2 = myBasicOperations->MakeLineTwoPnt(vi2, P3);
887 if (Cote_2.IsNull()) {
888 SetErrorCode("Impossible to build edge in thickness");
891 Cote_2->GetLastFunction()->SetDescription("");
893 // edge_chan_princ = arete du chanfrein (ou raccord) sur le tuyau principal
894 // edge_chan_inc = arete du chanfrein (ou raccord) sur le tuyau incident
895 // std::cerr << "Getting chamfer edge on main pipe" << std::endl;
896 Handle(GEOM_Object) edge_chan_princ = myBlocksOperations->GetEdge(theShape, P1, P3);
897 if (edge_chan_princ.IsNull()) {
898 SetErrorCode("Impossible to find edge on main pipe");
901 edge_chan_princ->GetLastFunction()->SetDescription("");
903 Handle(GEOM_Object) edge_chan_inc = myBlocksOperations->GetEdge(theShape, P2, P4);
904 if (edge_chan_inc.IsNull()) {
905 SetErrorCode("Impossible to find edge on incident pipe");
908 edge_chan_inc->GetLastFunction()->SetDescription("");
910 std::list<Handle(GEOM_Object)> edgeList1;
911 edgeList1.push_back(edge_chan_princ);
912 edgeList1.push_back(Cote_1);
913 edgeList1.push_back(arete_intersect_int);
914 edgeList1.push_back(Cote_2);
916 // std::cerr << "Creating wire 1" << std::endl;
917 wire_t = myShapesOperations->MakeWire(edgeList1, 1e-7);
918 if (wire_t.IsNull()) {
919 SetErrorCode("Impossible to build wire");
922 wire_t->GetLastFunction()->SetDescription("");
924 // std::cerr << "Creating face 1" << std::endl;
925 face_t = myShapesOperations->MakeFace(wire_t, false);
926 if (face_t.IsNull()) {
927 SetErrorCode("Impossible to build face");
930 face_t->GetLastFunction()->SetDescription("");
931 theShapes.push_back(face_t);
933 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(P2->GetValue()));
934 gp_Pnt aP5 = BRep_Tool::Pnt(TopoDS::Vertex(vi1->GetValue()));
935 double deltaZ = aP2.Z() - aP5.Z();
936 // std::cerr << "Creating new point from vi1 with deltaZ = " << deltaZ << std::endl;
937 Handle(GEOM_Object) P5bis = myTransformOperations->TranslateDXDYDZCopy(vi1, 0, 0, deltaZ);
938 if (P5bis.IsNull()) {
939 SetErrorCode("Impossible to translate vertex");
942 P5bis->GetLastFunction()->SetDescription("");
944 gp_Pnt aP4 = BRep_Tool::Pnt(TopoDS::Vertex(P4->GetValue()));
945 gp_Pnt aP6 = BRep_Tool::Pnt(TopoDS::Vertex(vi2->GetValue()));
946 deltaZ = aP4.Z() - aP6.Z();
947 // std::cerr << "Creating new point from vi2 with deltaZ = " << deltaZ << std::endl;
948 Handle(GEOM_Object) P6bis = myTransformOperations->TranslateDXDYDZCopy(vi2, 0, 0, deltaZ);
949 if (P6bis.IsNull()) {
950 SetErrorCode("Impossible to translate vertex");
953 P6bis->GetLastFunction()->SetDescription("");
955 // std::cerr << "Creating new line 1 from 2 previous points" << std::endl;
956 Handle(GEOM_Object) Cote_3 = myBasicOperations->MakeLineTwoPnt(P5bis, P2);
957 if (Cote_3.IsNull()) {
958 SetErrorCode("Impossible to build edge in thickness");
961 Cote_3->GetLastFunction()->SetDescription("");
963 // std::cerr << "Creating new line 2 from 2 previous points" << std::endl;
964 Handle(GEOM_Object) Cote_4 = myBasicOperations->MakeLineTwoPnt(P6bis, P4);
965 if (Cote_4.IsNull()) {
966 SetErrorCode("Impossible to build edge in thickness");
969 Cote_4->GetLastFunction()->SetDescription("");
971 // std::cerr << "Creating new line 3 from 2 previous points" << std::endl;
972 Handle(GEOM_Object) Cote_5 = myBasicOperations->MakeLineTwoPnt(P5bis, P6bis);
973 if (Cote_4.IsNull()) {
974 SetErrorCode("Impossible to build edge in thickness");
977 Cote_5->GetLastFunction()->SetDescription("");
979 //std::list<Handle(GEOM_Object)> edgeList2;
980 //edgeList2.push_back(edge_chan_inc);
981 //edgeList2.push_back(Cote_3);
982 //edgeList2.push_back(Cote_5);
983 //edgeList2.push_back(Cote_4);
984 // std::cerr << "Creating wire 2" << std::endl;
985 //wire_t2 = myShapesOperations->MakeWire(edgeList2, 1e-7);
986 //if (wire_t2.IsNull()) {
987 // SetErrorCode("Impossible to build wire");
990 //wire_t2->GetLastFunction()->SetDescription("");
991 // std::cerr << "Creating face 2" << std::endl;
992 //face_t2 = myShapesOperations->MakeFace(wire_t2, false);
993 face_t2 = my3DPrimOperations->MakePrismVecH(edge_chan_inc, Cote_4, - 2.0*theR2);
994 if (face_t2.IsNull()) {
995 SetErrorCode("Impossible to build face");
998 face_t2->GetLastFunction()->SetDescription("");
999 theShapes.push_back(face_t2);
1003 Handle(GEOM_Object) aP0 = myBasicOperations->MakePointXYZ(0, 0, 0);
1004 Handle(GEOM_Object) aVZ = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
1005 Handle(GEOM_Object) aVXZ = myBasicOperations->MakeVectorDXDYDZ(aR1Ext, 0, 0.5*(theL1+theVertCylinderRadius));
1006 Handle(GEOM_Object) aPlnOZ = myBasicOperations->MakePlanePntVec(aP0, aVZ, aSize);
1007 Handle(GEOM_Object) aPlnOXZ = myBasicOperations->MakePlanePntVec(aP0, aVXZ, aSize);
1008 aP0->GetLastFunction()->SetDescription("");
1009 aVZ->GetLastFunction()->SetDescription("");
1010 aVXZ->GetLastFunction()->SetDescription("");
1011 aPlnOZ->GetLastFunction()->SetDescription("");
1012 aPlnOXZ->GetLastFunction()->SetDescription("");
1013 theShapes.push_back(aPlnOZ);
1014 theShapes.push_back(aPlnOXZ);
1017 Handle(TColStd_HSequenceOfTransient) partitionShapes = new TColStd_HSequenceOfTransient;
1018 Handle(TColStd_HSequenceOfTransient) theTools = new TColStd_HSequenceOfTransient;
1019 Handle(TColStd_HSequenceOfTransient) theKeepInside = new TColStd_HSequenceOfTransient;
1020 Handle(TColStd_HSequenceOfTransient) theRemoveInside = new TColStd_HSequenceOfTransient;
1021 Handle(TColStd_HArray1OfInteger) theMaterials;
1022 partitionShapes->Append(theShape);
1023 theTools->Append(aPlnOZ);
1024 if (Abs(aR1Ext - aR2Ext) > Precision::Confusion() )
1025 theTools->Append(aPlnOXZ);
1026 theTools->Append(face_t);
1028 theTools->Append(face_t2);
1030 Handle(GEOM_Object) Te3 = myBooleanOperations->MakePartition
1031 (partitionShapes, theTools, theKeepInside, theRemoveInside,
1032 TopAbs_SOLID, false, theMaterials, 0, false);
1034 SetErrorCode("Impossible to build partition of TShape");
1035 // Handle(GEOM_Object) aCompound = myShapesOperations->MakeCompound(theShapes);
1036 // TopoDS_Shape aCompoundShape = aCompound->GetValue();
1037 // theShape->GetLastFunction()->SetValue(aCompoundShape);
1040 Te3->GetLastFunction()->SetDescription("");
1042 // Last verification: result should be a block
1043 std::list<GEOMImpl_IBlocksOperations::BCError> errList;
1044 if (!myBlocksOperations->CheckCompoundOfBlocks(Te3,errList)) {
1045 SetErrorCode("TShape is not a block");
1048 TopoDS_Shape aShape = Te3->GetValue();
1049 theShape->GetLastFunction()->SetValue(aShape);
1055 // Mirror and glue faces
1056 bool GEOMImpl_IAdvancedOperations::MakePipeTShapeMirrorAndGlue(Handle(GEOM_Object) theShape,
1057 double theR1, double theW1, double theL1,
1058 double theR2, double theW2, double theL2)
1063 double aSize = 2*(theL1 + theL2);
1064 double aR1Ext = theR1 + theW1;
1067 Handle(GEOM_Object) aP0 = myBasicOperations->MakePointXYZ(0, 0, 0);
1068 aP0->GetLastFunction()->SetDescription("");
1069 Handle(GEOM_Object) aVX = myBasicOperations->MakeVectorDXDYDZ(1, 0, 0);
1070 Handle(GEOM_Object) aVY = myBasicOperations->MakeVectorDXDYDZ(0, 1, 0);
1071 aVX->GetLastFunction()->SetDescription("");
1072 aVY->GetLastFunction()->SetDescription("");
1073 Handle(GEOM_Object) aPlane_OX = myBasicOperations->MakePlanePntVec(aP0, aVX, 2*(aR1Ext + theL2));
1074 Handle(GEOM_Object) aPlane_OY = myBasicOperations->MakePlanePntVec(aP0, aVY, aSize);
1075 aPlane_OX->GetLastFunction()->SetDescription("");
1076 aPlane_OY->GetLastFunction()->SetDescription("");
1078 Handle(GEOM_Object) Te4 = myTransformOperations->MirrorPlaneCopy(theShape, aPlane_OX);
1080 SetErrorCode("Impossible to build mirror of quarter TShape");
1084 Handle(GEOM_Object) Te5 = myTransformOperations->MirrorPlaneCopy(theShape, aPlane_OY);
1086 SetErrorCode("Impossible to build mirror of half TShape");
1090 Handle(GEOM_Object) Te6 = myTransformOperations->MirrorPlaneCopy(Te4, aPlane_OY);
1092 SetErrorCode("Impossible to build mirror of half TShape");
1096 std::list<Handle(GEOM_Object)> aShapesList;
1097 aShapesList.push_back(theShape);
1098 aShapesList.push_back(Te4);
1099 aShapesList.push_back(Te5);
1100 aShapesList.push_back(Te6);
1101 Handle(GEOM_Object) Te7 = myShapesOperations->MakeCompound(aShapesList);
1103 SetErrorCode("Impossible to build compound");
1107 Handle(GEOM_Object) Te8 = myShapesOperations->MakeGlueFaces(Te7, 1e-7, true);
1109 SetErrorCode("Impossible to glue faces of TShape");
1113 TopoDS_Shape aShape = Te8->GetValue();
1115 theShape->GetLastFunction()->SetValue(aShape);
1117 Te4->GetLastFunction()->SetDescription("");
1118 Te5->GetLastFunction()->SetDescription("");
1119 Te6->GetLastFunction()->SetDescription("");
1120 Te7->GetLastFunction()->SetDescription("");
1121 Te8->GetLastFunction()->SetDescription("");
1127 //=============================================================================
1130 * Create a T-shape object with specified caracteristics for the main and
1131 * the incident pipes (radius, width, half-length).
1132 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1133 * \param theR1 Internal radius of main pipe
1134 * \param theW1 Width of main pipe
1135 * \param theL1 Half-length of main pipe
1136 * \param theR2 Internal radius of incident pipe (R2 < R1)
1137 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1138 * \param theL2 Half-length of incident pipe
1139 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1140 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1142 //=============================================================================
1143 Handle(TColStd_HSequenceOfTransient)
1144 GEOMImpl_IAdvancedOperations::MakePipeTShape(double theR1, double theW1, double theL1,
1145 double theR2, double theW2, double theL2,
1148 MESSAGE("GEOMImpl_IAdvancedOperations::MakePipeTShape");
1151 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1153 //Add a new shape function with parameters
1154 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_BASIC);
1155 if (aFunction.IsNull()) return NULL;
1157 //Check if the function is set correctly
1158 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1160 GEOMImpl_IPipeTShape aData(aFunction);
1168 aData.SetHexMesh(theHexMesh);
1170 //Compute the resulting value
1172 #if OCC_VERSION_LARGE > 0x06010000
1175 if (!GetSolver()->ComputeFunction(aFunction)) {
1176 SetErrorCode("TShape driver failed");
1179 } catch (Standard_Failure) {
1180 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1181 SetErrorCode(aFail->GetMessageString());
1186 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1188 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1192 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1193 aSeq->Append(aShape);
1197 * Get the groups: BEGIN
1200 if (!MakeGroups(aShape, TSHAPE_BASIC, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1203 catch (Standard_Failure) {
1204 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1205 SetErrorCode(aFail->GetMessageString());
1209 TCollection_AsciiString aListRes, anEntry;
1210 // Iterate over the sequence aSeq
1211 Standard_Integer aNbGroups = aSeq->Length();
1212 Standard_Integer i = 2;
1213 for (; i <= aNbGroups; i++) {
1214 Handle(Standard_Transient) anItem = aSeq->Value(i);
1215 if (anItem.IsNull()) continue;
1216 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1217 if (aGroup.IsNull()) continue;
1218 //Make a Python command
1219 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1220 aListRes += anEntry + ", ";
1223 aListRes.Trunc(aListRes.Length() - 2);
1225 //Make a Python command
1226 GEOM::TPythonDump(aFunction)
1227 << "[" << aShape << ", " << aListRes.ToCString() << "] = geompy.MakePipeTShape("
1228 << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", "
1229 << theHexMesh << ")";
1232 * Get the groups: END
1235 //Make a Python command
1236 GEOM::TPythonDump(aFunction)
1237 << "[" << aShape << "] = geompy.MakePipeTShape(" << theR1 << ", " << theW1 << ", "
1238 << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theHexMesh << ")";
1246 //=============================================================================
1248 * MakePipeTShapeWithPosition
1249 * Create a T-shape object with specified caracteristics for the main and
1250 * the incident pipes (radius, width, half-length).
1251 * The extremities of the main pipe are located on junctions points P1 and P2.
1252 * The extremity of the incident pipe is located on junction point P3.
1253 * \param theR1 Internal radius of main pipe
1254 * \param theW1 Width of main pipe
1255 * \param theL1 Half-length of main pipe
1256 * \param theR2 Internal radius of incident pipe (R2 < R1)
1257 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1258 * \param theL2 Half-length of incident pipe
1259 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1260 * \param theP1 1st junction point of main pipe
1261 * \param theP2 2nd junction point of main pipe
1262 * \param theP3 Junction point of incident pipe
1263 * \return List of GEOM_Objects, containing the created shape and propagation groups..
1265 //=============================================================================
1266 Handle(TColStd_HSequenceOfTransient)
1267 GEOMImpl_IAdvancedOperations::MakePipeTShapeWithPosition(double theR1, double theW1, double theL1,
1268 double theR2, double theW2, double theL2,
1270 Handle(GEOM_Object) theP1,
1271 Handle(GEOM_Object) theP2,
1272 Handle(GEOM_Object) theP3)
1276 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1280 //Add a new shape function with parameters
1281 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_BASIC);
1282 if (aFunction.IsNull()) return NULL;
1284 //Check if the function is set correctly
1285 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1287 // Check new position
1288 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1292 GEOMImpl_IPipeTShape aData(aFunction);
1300 aData.SetHexMesh(theHexMesh);
1302 //Compute the resulting value
1304 #if OCC_VERSION_LARGE > 0x06010000
1307 if (!GetSolver()->ComputeFunction(aFunction)) {
1308 SetErrorCode("TShape driver failed");
1311 } catch (Standard_Failure) {
1312 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1313 SetErrorCode(aFail->GetMessageString());
1318 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1320 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1324 TopoDS_Shape Te = aShape->GetValue();
1327 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
1328 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
1329 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
1330 aFunction->SetValue(aTrsf_Shape);
1331 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1332 aSeq->Append(aShape);
1336 // Get the groups: BEGIN
1339 if (!MakeGroups(aShape,TSHAPE_BASIC, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf)) {
1343 catch (Standard_Failure) {
1344 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1345 SetErrorCode(aFail->GetMessageString());
1349 TCollection_AsciiString aListRes, anEntry;
1350 // Iterate over the sequence aSeq
1351 Standard_Integer aNbGroups = aSeq->Length();
1352 Standard_Integer i = 2;
1353 for (; i <= aNbGroups; i++) {
1354 Handle(Standard_Transient) anItem = aSeq->Value(i);
1355 if (anItem.IsNull()) continue;
1356 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1357 if (aGroup.IsNull()) continue;
1358 //Make a Python command
1359 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1360 aListRes += anEntry + ", ";
1363 aListRes.Trunc(aListRes.Length() - 2);
1365 //Make a Python command
1366 GEOM::TPythonDump(aFunction)
1367 << "[" << aShape << ", " << aListRes.ToCString() << "] = geompy.MakePipeTShape("
1368 << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", "
1369 << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
1372 // Get the groups: END
1376 //Make a Python command
1377 GEOM::TPythonDump(aFunction)
1378 << "[" << aShape << "] = geompy.MakePipeTShape(" << theR1 << ", " << theW1 << ", "
1379 << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theHexMesh << ", " << theP1
1380 << ", " << theP2 << ", " << theP3 << ")";
1388 //=============================================================================
1390 * MakePipeTShapeChamfer
1391 * Create a T-shape object with specified caracteristics for the main and
1392 * the incident pipes (radius, width, half-length). A chamfer is created
1393 * on the junction of the pipes.
1394 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1395 * \param theR1 Internal radius of main pipe
1396 * \param theW1 Width of main pipe
1397 * \param theL1 Half-length of main pipe
1398 * \param theR2 Internal radius of incident pipe (R2 < R1)
1399 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1400 * \param theL2 Half-length of incident pipe
1401 * \param theH Height of chamfer.
1402 * \param theW Width of chamfer.
1403 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1404 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1406 //=============================================================================
1407 Handle(TColStd_HSequenceOfTransient)
1408 GEOMImpl_IAdvancedOperations::MakePipeTShapeChamfer(double theR1, double theW1, double theL1,
1409 double theR2, double theW2, double theL2,
1410 double theH, double theW,
1415 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1416 //Add a new shape function with parameters
1417 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_CHAMFER);
1418 if (aFunction.IsNull()) return NULL;
1420 //Check if the function is set correctly
1421 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1423 GEOMImpl_IPipeTShape aData(aFunction);
1433 aData.SetHexMesh(theHexMesh);
1435 //Compute the resulting value
1437 #if OCC_VERSION_LARGE > 0x06010000
1440 if (!GetSolver()->ComputeFunction(aFunction)) {
1441 SetErrorCode("TShape driver failed");
1444 } catch (Standard_Failure) {
1445 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1446 SetErrorCode(aFail->GetMessageString());
1451 TopoDS_Shape aShapeShape = aShape->GetValue();
1452 TopTools_IndexedMapOfShape anEdgesIndices;
1453 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1454 // Common edges on external cylinders
1455 Handle(GEOM_Object) box_e;
1457 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1460 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1462 box_e->GetLastFunction()->SetDescription("");
1463 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1464 box_e->GetLastFunction()->SetDescription("");
1466 Handle(TColStd_HSequenceOfInteger) edges_e =
1467 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1468 box_e->GetLastFunction()->SetDescription("");
1470 if (edges_e.IsNull() || edges_e->Length() == 0) {
1471 SetErrorCode("External edges not found");
1474 int nbEdgesInChamfer = 0;
1475 std::list<int> theEdges;
1476 for (int i=1; i<=edges_e->Length();i++) {
1477 int edgeID = edges_e->Value(i);
1478 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1479 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1483 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1484 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1485 nbEdgesInChamfer ++;
1486 theEdges.push_back(edgeID);
1490 if (theHexMesh && nbEdgesInChamfer == 1)
1493 Handle(GEOM_Object) aChamfer;
1495 aChamfer = myLocalOperations->MakeChamferEdges(aShape, theW, theH, theEdges);
1497 catch (Standard_Failure) {
1498 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1499 SetErrorCode(aFail->GetMessageString());
1502 if (aChamfer.IsNull()) {
1503 SetErrorCode("Chamfer can not be computed on the given shape with the given parameters");
1506 aChamfer->GetLastFunction()->SetDescription("");
1508 TopoDS_Shape aChamferShape = aChamfer->GetValue();
1509 aFunction->SetValue(aChamferShape);
1512 // bool doMesh = false;
1515 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, 0, false)) {
1516 MESSAGE("PipeTShape partition failed");
1520 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2)) {
1521 MESSAGE("PipeTShape mirrors and glue failed");
1527 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1528 aSeq->Append(aShape);
1533 // Get the groups: BEGIN
1535 //if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf())) {
1536 // //Make a Python command
1537 // GEOM::TPythonDump(aFunction)
1538 // << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1539 // << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1540 // << ", " << theHexMesh << ")";
1544 if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1547 catch (Standard_Failure) {
1548 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1549 SetErrorCode(aFail->GetMessageString());
1553 TCollection_AsciiString aListRes, anEntry;
1554 // Iterate over the sequence aSeq
1555 Standard_Integer aNbGroups = aSeq->Length();
1556 Standard_Integer i = 2;
1557 for (; i <= aNbGroups; i++) {
1558 Handle(Standard_Transient) anItem = aSeq->Value(i);
1559 if (anItem.IsNull()) continue;
1560 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1561 if (aGroup.IsNull()) continue;
1562 //Make a Python command
1563 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1564 aListRes += anEntry + ", ";
1567 aListRes.Trunc(aListRes.Length() - 2);
1569 //Make a Python command
1570 GEOM::TPythonDump(aFunction)
1571 << "[" << aShape << ", " << aListRes.ToCString()
1572 << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1573 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW << ", " << theHexMesh << ")";
1577 // Get the groups: END
1580 //Make a Python command
1581 GEOM::TPythonDump(aFunction)
1582 << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1583 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1584 << ", " << theHexMesh << ")";
1592 //=============================================================================
1594 * MakePipeTShapeChamferWithPosition
1595 * Create a T-shape object with specified caracteristics for the main and
1596 * the incident pipes (radius, width, half-length). A chamfer is created
1597 * on the junction of the pipes.
1598 * The extremities of the main pipe are located on junctions points P1 and P2.
1599 * The extremity of the incident pipe is located on junction point P3.
1600 * \param theR1 Internal radius of main pipe
1601 * \param theW1 Width of main pipe
1602 * \param theL1 Half-length of main pipe
1603 * \param theR2 Internal radius of incident pipe (R2 < R1)
1604 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1605 * \param theL2 Half-length of incident pipe
1606 * \param theH Height of chamfer.
1607 * \param theW Width of chamfer.
1608 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1609 * \param theP1 1st junction point of main pipe
1610 * \param theP2 2nd junction point of main pipe
1611 * \param theP3 Junction point of incident pipe
1612 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1614 //=============================================================================
1615 Handle(TColStd_HSequenceOfTransient)
1616 GEOMImpl_IAdvancedOperations::MakePipeTShapeChamferWithPosition(double theR1, double theW1, double theL1,
1617 double theR2, double theW2, double theL2,
1618 double theH, double theW,
1620 Handle(GEOM_Object) theP1,
1621 Handle(GEOM_Object) theP2,
1622 Handle(GEOM_Object) theP3)
1626 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1627 //Add a new shape function with parameters
1628 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_CHAMFER);
1629 if (aFunction.IsNull()) return NULL;
1631 //Check if the function is set correctly
1632 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1634 // Check new position
1635 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1639 GEOMImpl_IPipeTShape aData(aFunction);
1649 aData.SetHexMesh(theHexMesh);
1651 //Compute the resulting value
1653 #if OCC_VERSION_LARGE > 0x06010000
1656 if (!GetSolver()->ComputeFunction(aFunction)) {
1657 SetErrorCode("TShape driver failed");
1660 } catch (Standard_Failure) {
1661 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1662 SetErrorCode(aFail->GetMessageString());
1667 TopoDS_Shape aShapeShape = aShape->GetValue();
1668 TopTools_IndexedMapOfShape anEdgesIndices;
1669 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1670 // Common edges on external cylinders
1671 Handle(GEOM_Object) box_e;
1673 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1676 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1678 box_e->GetLastFunction()->SetDescription("");
1679 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1680 box_e->GetLastFunction()->SetDescription("");
1682 Handle(TColStd_HSequenceOfInteger) edges_e =
1683 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1684 box_e->GetLastFunction()->SetDescription("");
1686 if (edges_e.IsNull() || edges_e->Length() == 0) {
1687 SetErrorCode("External edges not found");
1690 int nbEdgesInChamfer = 0;
1691 std::list<int> theEdges;
1692 for (int i=1; i<=edges_e->Length();i++) {
1693 int edgeID = edges_e->Value(i);
1694 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1695 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1697 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1698 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1699 nbEdgesInChamfer ++;
1700 theEdges.push_back(edgeID);
1704 if (theHexMesh && nbEdgesInChamfer == 1)
1707 Handle(GEOM_Object) aChamfer;
1709 aChamfer = myLocalOperations->MakeChamferEdges(aShape, theW, theH, theEdges);
1711 catch (Standard_Failure) {
1712 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1713 SetErrorCode(aFail->GetMessageString());
1716 if (aChamfer.IsNull()) {
1717 SetErrorCode("Chamfer can not be computed on the given shape with the given parameters");
1720 aChamfer->GetLastFunction()->SetDescription("");
1722 TopoDS_Shape aChamferShape = aChamfer->GetValue();
1723 aFunction->SetValue(aChamferShape);
1727 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, 0, false))
1729 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1733 TopoDS_Shape Te = aShape->GetValue();
1736 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
1737 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
1738 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
1739 aFunction->SetValue(aTrsf_Shape);
1740 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1741 aSeq->Append(aShape);
1744 * Get the groups: BEGIN
1747 if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf))
1750 catch (Standard_Failure) {
1751 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1752 SetErrorCode(aFail->GetMessageString());
1756 TCollection_AsciiString aListRes, anEntry;
1757 // Iterate over the sequence aSeq
1758 Standard_Integer aNbGroups = aSeq->Length();
1759 Standard_Integer i = 2;
1760 for (; i <= aNbGroups; i++) {
1761 Handle(Standard_Transient) anItem = aSeq->Value(i);
1762 if (anItem.IsNull()) continue;
1763 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1764 if (aGroup.IsNull()) continue;
1765 //Make a Python command
1766 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1767 aListRes += anEntry + ", ";
1770 aListRes.Trunc(aListRes.Length() - 2);
1772 //Make a Python command
1773 GEOM::TPythonDump(aFunction)
1774 << "[" << aShape << ", " << aListRes.ToCString()
1775 << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1776 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW << ", " << theHexMesh << ", "
1777 << theP1 << ", " << theP2 << ", " << theP3 << ")";
1780 * Get the groups: END
1783 //Make a Python command
1784 GEOM::TPythonDump(aFunction)
1785 << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1786 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1787 << ", " << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
1795 //=============================================================================
1797 * MakePipeTShapeFillet
1798 * Create a T-shape object with specified caracteristics for the main and
1799 * the incident pipes (radius, width, half-length). A fillet is created
1800 * on the junction of the pipes.
1801 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1802 * \param theR1 Internal radius of main pipe
1803 * \param theW1 Width of main pipe
1804 * \param theL1 Half-length of main pipe
1805 * \param theR2 Internal radius of incident pipe (R2 < R1)
1806 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1807 * \param theL2 Half-length of incident pipe
1808 * \param theRF Radius of curvature of fillet.
1809 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1810 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1812 //=============================================================================
1813 Handle(TColStd_HSequenceOfTransient)
1814 GEOMImpl_IAdvancedOperations::MakePipeTShapeFillet(double theR1, double theW1, double theL1,
1815 double theR2, double theW2, double theL2,
1816 double theRF, bool theHexMesh)
1820 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1821 //Add a new shape function with parameters
1822 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_FILLET);
1823 if (aFunction.IsNull()) return NULL;
1825 //Check if the function is set correctly
1826 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1828 GEOMImpl_IPipeTShape aData(aFunction);
1837 aData.SetHexMesh(theHexMesh);
1839 //Compute the resulting value
1841 #if OCC_VERSION_LARGE > 0x06010000
1844 if (!GetSolver()->ComputeFunction(aFunction)) {
1845 SetErrorCode("TShape driver failed");
1848 } catch (Standard_Failure) {
1849 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1850 SetErrorCode(aFail->GetMessageString());
1855 TopoDS_Shape aShapeShape = aShape->GetValue();
1856 TopTools_IndexedMapOfShape anEdgesIndices;
1857 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1858 // Common edges on external cylinders
1859 Handle(GEOM_Object) box_e;
1861 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1864 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1866 box_e->GetLastFunction()->SetDescription("");
1867 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1868 box_e->GetLastFunction()->SetDescription("");
1870 Handle(TColStd_HSequenceOfInteger) edges_e =
1871 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1872 box_e->GetLastFunction()->SetDescription("");
1874 if (edges_e.IsNull() || edges_e->Length() == 0) {
1875 SetErrorCode("External edges not found");
1878 int nbEdgesInFillet = 0;
1879 std::list<int> theEdges;
1880 for (int i=1; i<=edges_e->Length();i++) {
1881 int edgeID = edges_e->Value(i);
1882 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1883 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1885 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1886 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1888 theEdges.push_back(edgeID);
1892 if (theHexMesh && nbEdgesInFillet == 1)
1896 Handle(GEOM_Object) aFillet;
1898 aFillet = myLocalOperations->MakeFilletEdges(aShape, theRF, theEdges);
1900 catch (Standard_Failure) {
1901 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1902 SetErrorCode(aFail->GetMessageString());
1905 if (aFillet.IsNull()) {
1906 //SetErrorCode("Fillet can not be computed on the given shape with the given parameters");
1907 SetErrorCode(myLocalOperations->GetErrorCode());
1910 aFillet->GetLastFunction()->SetDescription("");
1912 TopoDS_Shape aFilletShape = aFillet->GetValue();
1913 aFunction->SetValue(aFilletShape);
1916 // BEGIN: Limit tolerances (debug)
1917 Handle(GEOM_Object) aCorr1 = myHealingOperations->LimitTolerance(aShape, 1e-07);
1918 TopoDS_Shape aCorr1Shape = aCorr1->GetValue();
1919 aShape->GetLastFunction()->SetValue(aCorr1Shape);
1920 aCorr1->GetLastFunction()->SetDescription("");
1921 // END: Limit tolerances (debug)
1924 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, 0, 0, theRF, false))
1926 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1930 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1931 aSeq->Append(aShape);
1934 * Get the groups: BEGIN
1937 if (!MakeGroups(aShape, TSHAPE_FILLET, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1940 catch (Standard_Failure) {
1941 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1942 SetErrorCode(aFail->GetMessageString());
1946 TCollection_AsciiString aListRes, anEntry;
1947 // Iterate over the sequence aSeq
1948 Standard_Integer aNbGroups = aSeq->Length();
1949 Standard_Integer i = 2;
1950 for (; i <= aNbGroups; i++) {
1951 Handle(Standard_Transient) anItem = aSeq->Value(i);
1952 if (anItem.IsNull()) continue;
1953 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1954 if (aGroup.IsNull()) continue;
1955 //Make a Python command
1956 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1957 aListRes += anEntry + ", ";
1960 aListRes.Trunc(aListRes.Length() - 2);
1962 //Make a Python command
1963 GEOM::TPythonDump(aFunction)
1964 << "[" << aShape << ", " << aListRes.ToCString()
1965 << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1966 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", " << theHexMesh << ")";
1969 * Get the groups: END
1972 //Make a Python command
1973 GEOM::TPythonDump(aFunction)
1974 << "[" << aShape << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1
1975 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", "
1976 << theHexMesh << ")";
1984 //=============================================================================
1986 * MakePipeTShapeFilletWithPosition
1987 * Create a T-shape object with specified caracteristics for the main and
1988 * the incident pipes (radius, width, half-length). A fillet is created
1989 * on the junction of the pipes.
1990 * The extremities of the main pipe are located on junctions points P1 and P2.
1991 * The extremity of the incident pipe is located on junction point P3.
1992 * \param theR1 Internal radius of main pipe
1993 * \param theW1 Width of main pipe
1994 * \param theL1 Half-length of main pipe
1995 * \param theR2 Internal radius of incident pipe (R2 < R1)
1996 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1997 * \param theL2 Half-length of incident pipe
1998 * \param theRF Radius of curvature of fillet
1999 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
2000 * \param theP1 1st junction point of main pipe
2001 * \param theP2 2nd junction point of main pipe
2002 * \param theP3 Junction point of incident pipe
2003 * \return List of GEOM_Objects, containing the created shape and propagation groups.
2005 //=============================================================================
2006 Handle(TColStd_HSequenceOfTransient)
2007 GEOMImpl_IAdvancedOperations::MakePipeTShapeFilletWithPosition(double theR1, double theW1, double theL1,
2008 double theR2, double theW2, double theL2,
2009 double theRF, bool theHexMesh,
2010 Handle(GEOM_Object) theP1,
2011 Handle(GEOM_Object) theP2,
2012 Handle(GEOM_Object) theP3)
2016 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
2017 //Add a new shape function with parameters
2018 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_FILLET);
2019 if (aFunction.IsNull()) return NULL;
2021 //Check if the function is set correctly
2022 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
2024 // Check new position
2025 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
2029 GEOMImpl_IPipeTShape aData(aFunction);
2038 aData.SetHexMesh(theHexMesh);
2040 //Compute the resulting value
2042 #if OCC_VERSION_LARGE > 0x06010000
2045 if (!GetSolver()->ComputeFunction(aFunction)) {
2046 SetErrorCode("TShape driver failed");
2049 } catch (Standard_Failure) {
2050 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2051 SetErrorCode(aFail->GetMessageString());
2056 TopoDS_Shape aShapeShape = aShape->GetValue();
2057 TopTools_IndexedMapOfShape anEdgesIndices;
2058 TopExp::MapShapes(aShapeShape, anEdgesIndices);
2059 // Common edges on external cylinders
2060 Handle(GEOM_Object) box_e;
2062 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
2065 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
2067 box_e->GetLastFunction()->SetDescription("");
2068 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
2069 box_e->GetLastFunction()->SetDescription("");
2071 Handle(TColStd_HSequenceOfInteger) edges_e =
2072 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
2073 box_e->GetLastFunction()->SetDescription("");
2075 if (edges_e.IsNull() || edges_e->Length() == 0) {
2076 SetErrorCode("External edges not found");
2079 int nbEdgesInFillet = 0;
2080 std::list<int> theEdges;
2081 for (int i=1; i<=edges_e->Length();i++) {
2082 int edgeID = edges_e->Value(i);
2083 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
2084 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
2086 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
2087 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
2089 theEdges.push_back(edgeID);
2093 if (theHexMesh && nbEdgesInFillet == 1)
2097 Handle(GEOM_Object) aFillet;
2099 aFillet = myLocalOperations->MakeFilletEdges(aShape, theRF, theEdges);
2101 catch (Standard_Failure) {
2102 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2103 SetErrorCode(aFail->GetMessageString());
2106 if (aFillet.IsNull()) {
2107 SetErrorCode("Fillet can not be computed on the given shape with the given parameters");
2110 aFillet->GetLastFunction()->SetDescription("");
2112 TopoDS_Shape aFilletShape = aFillet->GetValue();
2113 aFunction->SetValue(aFilletShape);
2116 // BEGIN: Limit tolerances (debug)
2117 Handle(GEOM_Object) aCorr1 = myHealingOperations->LimitTolerance(aShape, 1e-07);
2118 TopoDS_Shape aCorr1Shape = aCorr1->GetValue();
2119 aShape->GetLastFunction()->SetValue(aCorr1Shape);
2120 aCorr1->GetLastFunction()->SetDescription("");
2121 // END: Limit tolerances (debug)
2124 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, 0, 0, theRF, false))
2126 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
2130 TopoDS_Shape Te = aShape->GetValue();
2133 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
2134 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
2135 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
2136 aFunction->SetValue(aTrsf_Shape);
2137 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
2138 aSeq->Append(aShape);
2141 * Get the groups: BEGIN
2144 if (!MakeGroups(aShape, TSHAPE_FILLET, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf))
2147 catch (Standard_Failure) {
2148 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2149 SetErrorCode(aFail->GetMessageString());
2153 TCollection_AsciiString aListRes, anEntry;
2154 // Iterate over the sequence aSeq
2155 Standard_Integer aNbGroups = aSeq->Length();
2156 Standard_Integer i = 2;
2157 for (; i <= aNbGroups; i++) {
2158 Handle(Standard_Transient) anItem = aSeq->Value(i);
2159 if (anItem.IsNull()) continue;
2160 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
2161 if (aGroup.IsNull()) continue;
2162 //Make a Python command
2163 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
2164 aListRes += anEntry + ", ";
2167 aListRes.Trunc(aListRes.Length() - 2);
2169 //Make a Python command
2170 GEOM::TPythonDump(aFunction)
2171 << "[" << aShape << ", " << aListRes.ToCString()
2172 << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
2173 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", " << theHexMesh << ", " << theP1 << ", "
2174 << theP2 << ", " << theP3 << ")";
2177 * Get the groups: END
2180 //Make a Python command
2181 GEOM::TPythonDump(aFunction)
2182 << "[" << aShape << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1
2183 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", "
2184 << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
2192 /*@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@*/