1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : GEOMImpl_IAdvancedOperations.cxx
20 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
22 #include <Standard_Stream.hxx>
24 #include "GEOMImpl_Types.hxx"
25 #include "GEOMImpl_IAdvancedOperations.hxx"
26 #include "GEOMImpl_IBasicOperations.hxx"
27 #include "GEOMImpl_IBooleanOperations.hxx"
28 #include "GEOMImpl_IShapesOperations.hxx"
29 #include "GEOMImpl_ITransformOperations.hxx"
30 #include "GEOMImpl_IBlocksOperations.hxx"
31 #include "GEOMImpl_I3DPrimOperations.hxx"
32 #include "GEOMImpl_ILocalOperations.hxx"
33 #include "GEOMImpl_IHealingOperations.hxx"
35 #include "GEOMImpl_Gen.hxx"
37 #include <Basics_OCCTVersion.hxx>
39 #include <utilities.h>
41 #include <Utils_ExceptHandlers.hxx>
43 #include "GEOM_Function.hxx"
44 #include "GEOM_PythonDump.hxx"
46 #include "GEOMImpl_PipeTShapeDriver.hxx"
47 #include "GEOMImpl_IPipeTShape.hxx"
48 /*@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@*/
51 #include <TopExp_Explorer.hxx>
53 #include <TopoDS_Vertex.hxx>
54 #include <TopTools_IndexedMapOfShape.hxx>
59 #include <BRepBuilderAPI_Transform.hxx>
60 #include <BRep_Tool.hxx>
63 #include <TFunction_DriverTable.hxx>
64 #include <TFunction_Driver.hxx>
65 #include <TFunction_Logbook.hxx>
66 #include <TDF_Tool.hxx>
67 #include <Standard_Failure.hxx>
68 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
70 #define HALF_LENGTH_MAIN_PIPE "Main pipe half length" //"Tuyau principal - demi longueur"
71 #define HALF_LENGTH_INCIDENT_PIPE "Incident pipe half length" //"Tuyau incident - demi longueur"
72 #define CIRCULAR_QUARTER_PIPE "Circular quarter of pipe" //"Circulaire - quart de tuyau"
73 #define THICKNESS "Thickness" //"Epaisseur"
74 #define FLANGE "Flange" // "Collerette"
75 #define CHAMFER_OR_FILLET "Chamfer or fillet" //"Chanfrein ou Raccord"
76 #define JUNCTION_FACE_1 "Junction 1" //"Face de jonction 1"
77 #define JUNCTION_FACE_2 "Junction 2" //"Face de jonction 2"
78 #define JUNCTION_FACE_3 "Junction 3" //"Face de jonction 3"
80 //=============================================================================
84 //=============================================================================
85 GEOMImpl_IAdvancedOperations::GEOMImpl_IAdvancedOperations(GEOM_Engine* theEngine, int theDocID) :
86 GEOM_IOperations(theEngine, theDocID)
88 MESSAGE("GEOMImpl_IAdvancedOperations::GEOMImpl_IAdvancedOperations");
89 myBasicOperations = new GEOMImpl_IBasicOperations(GetEngine(), GetDocID());
90 myBooleanOperations = new GEOMImpl_IBooleanOperations(GetEngine(), GetDocID());
91 myShapesOperations = new GEOMImpl_IShapesOperations(GetEngine(), GetDocID());
92 myTransformOperations = new GEOMImpl_ITransformOperations(GetEngine(), GetDocID());
93 myBlocksOperations = new GEOMImpl_IBlocksOperations(GetEngine(), GetDocID());
94 my3DPrimOperations = new GEOMImpl_I3DPrimOperations(GetEngine(), GetDocID());
95 myLocalOperations = new GEOMImpl_ILocalOperations(GetEngine(), GetDocID());
96 myHealingOperations = new GEOMImpl_IHealingOperations(GetEngine(), GetDocID());
99 //=============================================================================
103 //=============================================================================
104 GEOMImpl_IAdvancedOperations::~GEOMImpl_IAdvancedOperations()
106 MESSAGE("GEOMImpl_IAdvancedOperations::~GEOMImpl_IAdvancedOperations");
107 delete myBasicOperations;
108 delete myBooleanOperations;
109 delete myShapesOperations;
110 delete myTransformOperations;
111 delete myBlocksOperations;
112 delete my3DPrimOperations;
113 delete myLocalOperations;
114 delete myHealingOperations;
117 //=============================================================================
121 //=============================================================================
122 gp_Trsf GEOMImpl_IAdvancedOperations::GetPositionTrsf(double theL1, double theL2,
123 Handle(GEOM_Object) theP1,
124 Handle(GEOM_Object) theP2,
125 Handle(GEOM_Object) theP3)
127 // Old Local Coordinates System oldLCS
129 gp_Pnt P1(-theL1, 0, 0);
130 gp_Pnt P2(theL1, 0, 0);
131 gp_Pnt P3(0, 0, theL2);
133 gp_Dir oldX(gp_Vec(P1, P2));
134 gp_Dir oldZ(gp_Vec(P0, P3));
135 gp_Ax3 oldLCS(P0, oldZ, oldX);
137 // New Local Coordinates System newLCS
138 double LocX, LocY, LocZ;
139 gp_Pnt newP1 = BRep_Tool::Pnt(TopoDS::Vertex(theP1->GetValue()));
140 gp_Pnt newP2 = BRep_Tool::Pnt(TopoDS::Vertex(theP2->GetValue()));
141 gp_Pnt newP3 = BRep_Tool::Pnt(TopoDS::Vertex(theP3->GetValue()));
142 LocX = (newP1.X() + newP2.X()) / 2.;
143 LocY = (newP1.Y() + newP2.Y()) / 2.;
144 LocZ = (newP1.Z() + newP2.Z()) / 2.;
145 gp_Pnt newO(LocX, LocY, LocZ);
147 gp_Dir newX(gp_Vec(newP1, newP2)); // P1P2 Vector
148 gp_Dir newZ(gp_Vec(newO, newP3)); // OP3 Vector
149 gp_Ax3 newLCS = gp_Ax3(newO, newZ, newX);
152 aTrsf.SetDisplacement(oldLCS, newLCS);
157 //=============================================================================
159 * CheckCompatiblePosition
162 //=============================================================================
163 bool GEOMImpl_IAdvancedOperations::CheckCompatiblePosition(double& theL1, double& theL2,
164 Handle(GEOM_Object) theP1,
165 Handle(GEOM_Object) theP2,
166 Handle(GEOM_Object) theP3,
170 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(theP1->GetValue()));
171 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(theP2->GetValue()));
172 gp_Pnt P3 = BRep_Tool::Pnt(TopoDS::Vertex(theP3->GetValue()));
174 double d12 = P1.Distance(P2);
175 double d13 = P1.Distance(P3);
176 double d23 = P2.Distance(P3);
177 // double d2 = newO.Distance(P3);
179 if (Abs(d12) <= Precision::Confusion()) {
180 SetErrorCode("Junctions points P1 and P2 are identical");
183 if (Abs(d13) <= Precision::Confusion()) {
184 SetErrorCode("Junctions points P1 and P3 are identical");
187 if (Abs(d23) <= Precision::Confusion()) {
188 SetErrorCode("Junctions points P2 and P3 are identical");
193 double newL1 = 0.5 * d12;
194 double newL2 = sqrt(pow(d13,2)-pow(newL1,2));
196 // theL1*(1-theTolerance) <= newL1 <= theL1*(1+theTolerance)
198 if (fabs(newL1 - theL1) > Precision::Approximation()) {
199 if ( (newL1 * (1 - theTolerance) -theL1 <= Precision::Approximation()) &&
200 (newL1 * (1 + theTolerance) -theL1 >= Precision::Approximation()) ) {
201 // std::cerr << "theL1 = newL1" << std::endl;
205 SetErrorCode("Dimension for main pipe (L1) is incompatible with new position");
211 // theL2*(1-theTolerance) <= newL2 <= theL2*(1+theTolerance)
213 if (fabs(newL2 - theL2) > Precision::Approximation()) {
214 if ( (newL2 * (1 - theTolerance) -theL2 <= Precision::Approximation()) &&
215 (newL2 * (1 + theTolerance) -theL2 >= Precision::Approximation()) ) {
219 SetErrorCode("Dimension for incident pipe (L2) is incompatible with new position");
229 //=============================================================================
231 * Generate the propagation groups of a Pipe T-Shape used for hexa mesh
233 //=============================================================================
234 bool GEOMImpl_IAdvancedOperations::MakeGroups(Handle(GEOM_Object) theShape, int shapeType,
235 double theR1, double theW1, double theL1,
236 double theR2, double theW2, double theL2,
237 Handle(TColStd_HSequenceOfTransient) theSeq,
242 if (theShape.IsNull()) return false;
244 TopoDS_Shape aShape = theShape->GetValue();
245 if (aShape.IsNull()) {
246 SetErrorCode("Shape is not defined");
250 gp_Trsf aTrsfInv = aTrsf.Inverted();
252 // int expectedGroups = 0;
253 // if (shapeType == TSHAPE_BASIC)
254 // if (Abs(theR2+theW2-theR1-theW1) <= Precision::Approximation())
255 // expectedGroups = 10;
257 // expectedGroups = 11;
258 // else if (shapeType == TSHAPE_CHAMFER || shapeType == TSHAPE_FILLET)
259 // expectedGroups = 12;
261 double aR1Ext = theR1 + theW1;
262 double aR2Ext = theR2 + theW2;
264 /////////////////////////
265 //// Groups of Faces ////
266 /////////////////////////
269 // Comment the following lines when GetInPlace bug is solved
271 // Workaround of GetInPlace bug
272 // Create a bounding box that fits the shape
273 Handle(GEOM_Object) aBox = my3DPrimOperations->MakeBoxDXDYDZ(2*theL1, 2*aR1Ext, aR1Ext+theL2);
274 aBox->GetLastFunction()->SetDescription("");
275 myTransformOperations->TranslateDXDYDZ(aBox, -theL1, -aR1Ext, -aR1Ext);
276 aBox->GetLastFunction()->SetDescription("");
277 // Apply transformation to box
278 BRepBuilderAPI_Transform aTransformationBox(aBox->GetValue(), aTrsf, Standard_False);
279 TopoDS_Shape aBoxShapeTrsf = aTransformationBox.Shape();
280 aBox->GetLastFunction()->SetValue(aBoxShapeTrsf);
282 // Get the shell of the box
283 Handle(GEOM_Object) aShell = Handle(GEOM_Object)::DownCast
284 (myShapesOperations->MakeExplode(aBox, TopAbs_SHELL, true)->Value(1));
285 aBox->GetLastFunction()->SetDescription("");
286 aShell->GetLastFunction()->SetDescription("");
287 // Get the common shapes between shell and shape
288 Handle(GEOM_Object) aCommonCompound = myBooleanOperations->MakeBoolean (theShape, aShell, 1); // MakeCommon
289 if (aCommonCompound.IsNull()) {
290 SetErrorCode(myBooleanOperations->GetErrorCode());
293 aCommonCompound->GetLastFunction()->SetDescription("");
294 // Explode the faces of common shapes => 3 faces
295 Handle(TColStd_HSequenceOfTransient) aCommonFaces =
296 myShapesOperations->MakeExplode(aCommonCompound, TopAbs_FACE, true);
297 aCommonCompound->GetLastFunction()->SetDescription("");
298 std::list<Handle(GEOM_Object)> aCompoundOfFacesList;
300 for (int i=0 ; i<= aCommonFaces->Length()-4 ; i+=4) {
301 std::list<Handle(GEOM_Object)> aFacesList;
302 for (int j = 1 ; j <= 4 ; j++) {
303 Handle(GEOM_Object) aFace = Handle(GEOM_Object)::DownCast(aCommonFaces->Value(i+j)); // Junction faces
304 if (!aFace.IsNull()) {
305 aFace->GetLastFunction()->SetDescription("");
306 aFacesList.push_back(aFace);
309 Handle(GEOM_Object) aCompoundOfFaces = myShapesOperations->MakeCompound(aFacesList);
310 if (!aCompoundOfFaces.IsNull()) {
311 aCompoundOfFaces->GetLastFunction()->SetDescription("");
312 aCompoundOfFacesList.push_back(aCompoundOfFaces);
316 if (aCompoundOfFacesList.size() == 3) {
317 Handle(GEOM_Object) aPln1 = aCompoundOfFacesList.front();
318 aCompoundOfFacesList.pop_front();
319 Handle(GEOM_Object) aPln2 = aCompoundOfFacesList.front();
320 aCompoundOfFacesList.pop_front();
321 Handle(GEOM_Object) aPln3 = aCompoundOfFacesList.front();
322 aCompoundOfFacesList.pop_front();
327 // Uncomment the following lines when GetInPlace bug is solved
329 // Handle(GEOM_Object) aP1 = myBasicOperations->MakePointXYZ(-theL1, 0, 0);
330 // Handle(GEOM_Object) aP2 = myBasicOperations->MakePointXYZ(-0, 0, theL2);
331 // Handle(GEOM_Object) aP3 = myBasicOperations->MakePointXYZ(theL1, 0, 0);
332 // aP1->GetLastFunction()->SetDescription("");
333 // aP2->GetLastFunction()->SetDescription("");
334 // aP3->GetLastFunction()->SetDescription("");
335 // Handle(GEOM_Object) aV1 = myBasicOperations->MakeVectorDXDYDZ(-1, 0, 0);
336 // Handle(GEOM_Object) aV2 = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
337 // Handle(GEOM_Object) aV3 = myBasicOperations->MakeVectorDXDYDZ(1, 0, 0);
338 // aV1->GetLastFunction()->SetDescription("");
339 // aV2->GetLastFunction()->SetDescription("");
340 // aV3->GetLastFunction()->SetDescription("");
341 // Handle(GEOM_Object) aPln1 = myBasicOperations->MakePlanePntVec(aP1, aV1, 2*(aR1Ext+theL2));
342 // Handle(GEOM_Object) aPln2 = myBasicOperations->MakePlanePntVec(aP2, aV2, 2*(aR2Ext));
343 // Handle(GEOM_Object) aPln3 = myBasicOperations->MakePlanePntVec(aP3, aV3, 2*(aR1Ext+theL2));
344 // aPln1->GetLastFunction()->SetDescription("");
345 // aPln2->GetLastFunction()->SetDescription("");
346 // aPln3->GetLastFunction()->SetDescription("");
348 // BRepBuilderAPI_Transform aTransformation1(aPln1->GetValue(), aTrsf, Standard_False);
349 // TopoDS_Shape aTrsf_Shape1 = aTransformation1.Shape();
350 // aPln1->GetLastFunction()->SetValue(aTrsf_Shape1);
351 // BRepBuilderAPI_Transform aTransformation2(aPln2->GetValue(), aTrsf, Standard_False);
352 // TopoDS_Shape aTrsf_Shape2 = aTransformation2.Shape();
353 // aPln2->GetLastFunction()->SetValue(aTrsf_Shape2);
354 // BRepBuilderAPI_Transform aTransformation3(aPln3->GetValue(), aTrsf, Standard_False);
355 // TopoDS_Shape aTrsf_Shape3 = aTransformation3.Shape();
356 // aPln3->GetLastFunction()->SetValue(aTrsf_Shape3);
360 Handle(GEOM_Object) junctionFaces1 = myShapesOperations->GetInPlace(theShape, aPln1);
361 if (junctionFaces1.IsNull())
362 junctionFaces1 = myShapesOperations->GetShapesOnShapeAsCompound
363 (aPln1, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
364 if (!junctionFaces1.IsNull()) {
365 junctionFaces1->GetLastFunction()->SetDescription("");
366 junctionFaces1->SetName("JUNCTION_FACE_1");
367 theSeq->Append(junctionFaces1);
370 SetErrorCode("Junction face 1 not found");
371 // theSeq->Append(aPln1);
374 Handle(GEOM_Object) junctionFaces2 = myShapesOperations->GetInPlace(theShape, aPln2);
375 if (junctionFaces2.IsNull())
376 junctionFaces2 = myShapesOperations->GetShapesOnShapeAsCompound
377 (aPln2, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
378 if (!junctionFaces2.IsNull()) {
379 junctionFaces2->GetLastFunction()->SetDescription("");
380 junctionFaces2->SetName("JUNCTION_FACE_2");
381 theSeq->Append(junctionFaces2);
384 SetErrorCode("Junction face 2 not found");
385 // theSeq->Append(aPln2);
388 Handle(GEOM_Object) junctionFaces3 = myShapesOperations->GetInPlace(theShape, aPln3);
389 if (junctionFaces3.IsNull())
390 junctionFaces3 = myShapesOperations->GetShapesOnShapeAsCompound
391 (aPln3, theShape, TopAbs_FACE, GEOMAlgo_ST_ONIN);
392 if (!junctionFaces3.IsNull()) {
393 junctionFaces3->GetLastFunction()->SetDescription("");
394 junctionFaces3->SetName("JUNCTION_FACE_3");
395 theSeq->Append(junctionFaces3);
398 SetErrorCode("Junction face 3 not found");
399 // theSeq->Append(aPln3);
402 // Comment the following lines when GetInPlace bug is solved
406 /////////////////////////
407 //// Groups of Edges ////
408 /////////////////////////
409 // Result of propagate
411 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
413 TCollection_AsciiString theDesc = aFunction->GetDescription();
414 Handle(TColStd_HSequenceOfTransient) aSeqPropagate = myBlocksOperations->Propagate(theShape);
415 if (aSeqPropagate.IsNull() || aSeqPropagate->Length() == 0) {
416 SetErrorCode("Propagation groups not found");
419 Standard_Integer nbEdges, aNbGroups = aSeqPropagate->Length();
420 // Recover previous description to get rid of Propagate dump
421 aFunction->SetDescription(theDesc);
424 bool circularFoundAndAdded = false;
425 bool circularFound10 = false;
426 bool incidentPipeFound = false;
427 bool mainPipeFound = false;
428 bool mainPipeFoundAndAdded = false;
429 bool radialFound =false;
430 bool flangeFound = false;
431 bool flangeFoundAndAdded = false;
432 bool chamferOrFilletFound = false;
434 for (int i=1 ; i<= aNbGroups; i++) {
437 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(aSeqPropagate->Value(i));
441 TopoDS_Shape aGroupShape = aGroup->GetValue();
442 BRepBuilderAPI_Transform aTransformationShapeInv(aGroupShape, aTrsfInv, Standard_False);
443 TopoDS_Shape aGroupShapeTrsfInv = aTransformationShapeInv.Shape();
445 TopTools_IndexedMapOfShape anEdgesMap;
446 TopExp::MapShapes(aGroupShapeTrsfInv,TopAbs_EDGE, anEdgesMap);
447 nbEdges = anEdgesMap.Extent();
449 if (shapeType == TSHAPE_BASIC) {
450 if ((nbEdges == 21) || /*R1Ext = R2Ext*/(nbEdges == 17)){
452 aGroup->SetName("THICKNESS");
454 else if (nbEdges == 6) {
455 if (!circularFoundAndAdded) {
456 circularFoundAndAdded = true;
458 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
461 else if (nbEdges == 8) {
462 incidentPipeFound = true;
463 mainPipeFound = false;
467 TopExp_Explorer Ex(aGroupShapeTrsfInv,TopAbs_VERTEX);
469 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
470 double x=aP.X(), y=aP.Y(), z=aP.Z();
473 if ((Abs(x) > aR2Ext + Precision::Confusion()) ||
474 (Abs(y) > aR2Ext + Precision::Confusion())) {
475 incidentPipeFound = false;
478 if ( z < -Precision::Confusion()) {
479 // length of main pipe
480 mainPipeFound = true;
481 if (!mainPipeFoundAndAdded) {
482 mainPipeFoundAndAdded = true;
484 aGroup->SetName("HALF_LENGTH_MAIN_PIPE");
488 else if (Abs(x) > (theL1-Precision::Confusion())) {
489 // discretisation circulaire
491 if (!circularFoundAndAdded) {
492 circularFoundAndAdded = true;
494 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
499 if (incidentPipeFound) {
501 aGroup->SetName("HALF_LENGTH_INCIDENT_PIPE");
503 if (!addGroup && (!incidentPipeFound &&
507 // Flange (collerette)
510 aGroup->SetName("FLANGE");
516 else if (shapeType == TSHAPE_CHAMFER || shapeType == TSHAPE_FILLET) {
519 aGroup->SetName("THICKNESS");
521 else if ((nbEdges == 10) || (nbEdges == 6)) {
522 if (!circularFoundAndAdded) {
524 circularFoundAndAdded = true;
525 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
527 circularFound10 = true;
530 else if (!circularFound10 && nbEdges == 10) {
531 circularFound10 = true;
533 aGroup->SetName("CIRCULAR_QUARTER_PIPE");
536 else if (nbEdges == 8) {
537 incidentPipeFound = true;
538 mainPipeFound = true;
541 bool isNearZ0 = false;
542 bool isBelowZ0 = false;
544 TopExp_Explorer Ex (aGroupShapeTrsfInv,TopAbs_VERTEX);
546 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
547 double x=aP.X(), y=aP.Y(), z=aP.Z();
549 // tuy_princ_long_avant & tuy_princ_long_apres
550 //bool isMain = (((z < Precision::Confusion()) || (x < Precision::Confusion())) &&
551 // ((y <= aR1Ext + Precision::Confusion()) ||
552 // (y <= -(aR1Ext + Precision::Confusion())) ||
553 // (y <= theR1 + Precision::Confusion()) ||
554 // (y == -(theR1 + Precision::Confusion()))));
555 bool isMain = ((z < Precision::Confusion() || x < Precision::Confusion()) &&
556 (fabs(y) > theR1 - Precision::Confusion() ||
557 fabs(y) < Precision::Confusion()));
560 mainPipeFound = false;
564 //if (z < Precision::Confusion() && !isMain) {
565 // flangeFound = true;
566 // if (!flangeFoundAndAdded) {
567 // flangeFoundAndAdded = true;
569 // aGroup->SetName("FLANGE");
572 if (fabs(z) < Precision::Confusion()) isNearZ0 = true;
573 if (z < - Precision::Confusion()) isBelowZ0 = true;
576 if ((Abs(x) > aR2Ext + Precision::Confusion()) ||
577 (Abs(y) > aR2Ext + Precision::Confusion())) {
578 incidentPipeFound = false;
584 aGroup->SetName("HALF_LENGTH_MAIN_PIPE");
586 if (incidentPipeFound) {
588 aGroup->SetName("HALF_LENGTH_INCIDENT_PIPE");
590 if (isNearZ0 && !isBelowZ0) {
592 if (!flangeFoundAndAdded) {
593 flangeFoundAndAdded = true;
595 aGroup->SetName("FLANGE");
598 if (!addGroup && (!incidentPipeFound &&
601 !chamferOrFilletFound)) {
603 chamferOrFilletFound = true;
604 if (shapeType == TSHAPE_CHAMFER)
605 aGroup->SetName("CHAMFER");
607 aGroup->SetName("FILLET");
613 // Add group to the list
615 theSeq->Append(aGroup);
622 bool GEOMImpl_IAdvancedOperations::MakePipeTShapePartition(Handle(GEOM_Object) theShape,
623 double theR1, double theW1, double theL1,
624 double theR2, double theW2, double theL2,
625 double theH, double theW,
626 double theRF, bool isNormal)
630 // Build tools for partition operation:
631 // 1 face and 2 planes
633 Handle(GEOM_Object) arete_intersect_int;
634 Handle(GEOM_Object) wire_t, wire_t2, face_t, face_t2;
635 Handle(GEOM_Object) chan_racc;
636 Handle(GEOM_Object) vi1, vi2;
637 Handle(GEOM_Object) Te3;
640 #if OCC_VERSION_LARGE > 0x06010000
643 Handle(GEOM_Object) Vector_Z = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
644 Vector_Z->GetLastFunction()->SetDescription("");
647 double aSize = 2*(theL1 + theL2);
648 double aR1Ext = theR1 + theW1;
649 double aR2Ext = theR2 + theW2;
650 double theVertCylinderRadius = aR2Ext + theW + theRF;
651 double theHoriCylinderRadius = aR1Ext + theH + theRF;
653 // Common edges on internal cylinder
654 Handle(GEOM_Object) box_i = my3DPrimOperations->MakeBoxDXDYDZ(theR2, theR2, theR1);
655 box_i->GetLastFunction()->SetDescription("");
656 box_i = myTransformOperations->TranslateDXDYDZ(box_i, -theR2, -theR2, 0);
657 box_i->GetLastFunction()->SetDescription("");
659 Handle(GEOM_Function) aFunction = theShape->GetLastFunction();
660 TCollection_AsciiString theDesc = aFunction->GetDescription();
661 Handle(TColStd_HSequenceOfTransient) edges_i =
662 myShapesOperations->GetShapesOnBox(box_i, theShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
663 // Recover previous description to get rid of Propagate dump
664 aFunction->SetDescription(theDesc);
665 if (edges_i.IsNull() || edges_i->Length() == 0) {
666 SetErrorCode("Internal edges not found");
669 for (int i=1; i<=edges_i->Length();i++) {
670 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(edges_i->Value(i));
671 anObj->GetLastFunction()->SetDescription("");
673 arete_intersect_int = Handle(GEOM_Object)::DownCast(edges_i->Value(1));
675 // search for vertices located on both internal pipes
676 aFunction = theShape->GetLastFunction();
677 theDesc = aFunction->GetDescription();
678 Handle(TColStd_HSequenceOfTransient) vertices_i =
679 myShapesOperations->GetShapesOnBox(box_i, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
680 // Recover previous description to get rid of Propagate dump
681 aFunction->SetDescription(theDesc);
682 if (vertices_i.IsNull() || vertices_i->Length() == 0) {
683 SetErrorCode("Internal vertices not found");
687 for (int i = 1; i <= vertices_i->Length(); i++) {
688 Handle(GEOM_Object) v = Handle(GEOM_Object)::DownCast(vertices_i->Value(i));
689 v->GetLastFunction()->SetDescription("");
690 TopoDS_Vertex aVertex = TopoDS::Vertex(v->GetValue());
691 gp_Pnt aP = BRep_Tool::Pnt(aVertex);
692 if (Abs(aP.X()) <= Precision::Confusion()) {
693 if (Abs(aP.Y()) - theR2 <= Precision::Confusion())
695 } else if (Abs(aP.Y()) <= Precision::Confusion()) {
696 if (Abs(aP.X()) - theR1 <= Precision::Confusion())
701 std::list<Handle(GEOM_Object)> theShapes;
704 Handle(GEOM_Object) ve1, ve2;
706 Handle(GEOM_Object) box_e = my3DPrimOperations->MakeBoxDXDYDZ(aR2Ext, aR2Ext, aR1Ext);
707 box_e->GetLastFunction()->SetDescription("");
708 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -aR2Ext, -aR2Ext, 0);
709 box_e->GetLastFunction()->SetDescription("");
710 // Common edges on external cylinder
711 aFunction = theShape->GetLastFunction();
712 theDesc = aFunction->GetDescription();
713 Handle(TColStd_HSequenceOfTransient) edges_e =
714 myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
715 // Recover previous description to get rid of Propagate dump
716 aFunction->SetDescription(theDesc);
717 if (edges_e.IsNull() || edges_e->Length() == 0) {
718 SetErrorCode("External edges not found");
721 for (int i=1; i<=edges_e->Length();i++) {
722 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(edges_e->Value(i));
723 anObj->GetLastFunction()->SetDescription("");
726 // search for vertices located on both external pipes
727 aFunction = theShape->GetLastFunction();
728 theDesc = aFunction->GetDescription();
729 Handle(TColStd_HSequenceOfTransient) vertices_e =
730 myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
731 // Recover previous description to get rid of Propagate dump
732 aFunction->SetDescription(theDesc);
733 if (vertices_e.IsNull() || vertices_e->Length() == 0) {
734 SetErrorCode("External vertices not found");
738 for (int i = 1; i <= vertices_e->Length(); i++) {
739 Handle(GEOM_Object) v = Handle(GEOM_Object)::DownCast(vertices_e->Value(i));
740 v->GetLastFunction()->SetDescription("");
741 TopoDS_Vertex aVertex = TopoDS::Vertex(v->GetValue());
742 gp_Pnt aP = BRep_Tool::Pnt(aVertex);
743 if (Abs(aP.X()) <= Precision::Confusion()) {
744 if (Abs(aP.Y()) - theR2 > Precision::Confusion())
746 } else if (Abs(aP.Y()) <= Precision::Confusion()) {
747 if (Abs(aP.X()) - theR2 > Precision::Confusion())
751 Handle(GEOM_Object) edge_e1, edge_e2;
753 edge_e1 = myBasicOperations->MakeLineTwoPnt(ve1, vi1);
754 if (edge_e1.IsNull()) {
755 SetErrorCode("Edge 1 could not be built");
759 edge_e2 = myBasicOperations->MakeLineTwoPnt(ve2, vi2);
760 if (edge_e2.IsNull()) {
761 SetErrorCode("Edge 2 could not be built");
765 edge_e1->GetLastFunction()->SetDescription("");
766 edge_e2->GetLastFunction()->SetDescription("");
768 std::list<Handle(GEOM_Object)> edge_e_elist;
769 edge_e_elist.push_back(arete_intersect_int);
770 edge_e_elist.push_back(edge_e1);
771 edge_e_elist.push_back(Handle(GEOM_Object)::DownCast(edges_e->Value(1)));
772 edge_e_elist.push_back(edge_e2);
773 wire_t = myShapesOperations->MakeWire(edge_e_elist, 1e-7);
774 if (wire_t.IsNull()) {
775 SetErrorCode("Impossible to build wire");
778 wire_t->GetLastFunction()->SetDescription("");
779 face_t = myShapesOperations->MakeFace(wire_t, false);
780 if (face_t.IsNull()) {
781 SetErrorCode("Impossible to build face");
784 face_t->GetLastFunction()->SetDescription("");
787 Handle(GEOM_Object) P1, P2, P3, P4, P5, P6;
788 int idP1, idP2, idP3, idP4;
793 Handle(GEOM_Object) box_e = my3DPrimOperations->MakeBoxDXDYDZ
794 (theVertCylinderRadius, theVertCylinderRadius, theHoriCylinderRadius);
795 box_e->GetLastFunction()->SetDescription("");
796 box_e = myTransformOperations->TranslateDXDYDZ
797 (box_e, -theVertCylinderRadius, -theVertCylinderRadius, 0);
798 box_e->GetLastFunction()->SetDescription("");
800 aFunction = theShape->GetLastFunction();
801 theDesc = aFunction->GetDescription();
802 Handle(TColStd_HSequenceOfTransient) extremVertices =
803 myShapesOperations->GetShapesOnBox(box_e, theShape, TopAbs_VERTEX, GEOMAlgo_ST_ONIN);
804 // Recover previous description to get rid of Propagate dump
805 aFunction->SetDescription(theDesc);
807 if (extremVertices.IsNull() || extremVertices->Length() == 0) {
809 SetErrorCode("Vertices on chamfer not found");
811 SetErrorCode("Vertices on fillet not found");
815 theShapes.push_back(theShape);
816 theShapes.push_back(box_e);
817 if (extremVertices->Length() != 6) {
818 // for (int i=1; i<=extremVertices->Length(); i++){
819 // theShapes.push_back(Handle(GEOM_Object)::DownCast(extremVertices->Value(i)));
821 // Handle(GEOM_Object) aCompound = myShapesOperations->MakeCompound(theShapes);
822 // TopoDS_Shape aCompoundShape = aCompound->GetValue();
823 // theShape->GetLastFunction()->SetValue(aCompoundShape);
824 SetErrorCode("Bad number of vertices on chamfer found");
828 for (int i=1; i<=extremVertices->Length(); i++){
829 Handle(GEOM_Object) aV = Handle(GEOM_Object)::DownCast(extremVertices->Value(i));
830 aV->GetLastFunction()->SetDescription("");
831 gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aV->GetValue()));
833 if (Abs(aP.X()) <= Precision::Confusion()) {
834 if (Abs(aP.Y()) - theR2 > Precision::Confusion()) {
836 if (aP.Z()-ZX > Precision::Confusion()) {
843 if (Abs(aP.X()) - theR2 > Precision::Confusion()) {
845 if (aP.Z() - ZY > Precision::Confusion()) {
862 P1 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP1));
863 P2 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP2));
864 P3 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP3));
865 P4 = Handle(GEOM_Object)::DownCast(extremVertices->Value(idP4));
867 Handle(GEOM_Object) Cote_1 = myBasicOperations->MakeLineTwoPnt(P1, vi1);
868 if (Cote_1.IsNull()) {
869 SetErrorCode("Impossible to build edge in thickness");
872 Cote_1->GetLastFunction()->SetDescription("");
874 Handle(GEOM_Object) Cote_2 = myBasicOperations->MakeLineTwoPnt(vi2, P3);
875 if (Cote_2.IsNull()) {
876 SetErrorCode("Impossible to build edge in thickness");
879 Cote_2->GetLastFunction()->SetDescription("");
881 // edge_chan_princ = arete du chanfrein (ou raccord) sur le tuyau principal
882 // edge_chan_inc = arete du chanfrein (ou raccord) sur le tuyau incident
883 // std::cerr << "Getting chamfer edge on main pipe" << std::endl;
884 Handle(GEOM_Object) edge_chan_princ = myBlocksOperations->GetEdge(theShape, P1, P3);
885 if (edge_chan_princ.IsNull()) {
886 SetErrorCode("Impossible to find edge on main pipe");
889 edge_chan_princ->GetLastFunction()->SetDescription("");
891 Handle(GEOM_Object) edge_chan_inc = myBlocksOperations->GetEdge(theShape, P2, P4);
892 if (edge_chan_inc.IsNull()) {
893 SetErrorCode("Impossible to find edge on incident pipe");
896 edge_chan_inc->GetLastFunction()->SetDescription("");
898 std::list<Handle(GEOM_Object)> edgeList1;
899 edgeList1.push_back(edge_chan_princ);
900 edgeList1.push_back(Cote_1);
901 edgeList1.push_back(arete_intersect_int);
902 edgeList1.push_back(Cote_2);
904 // std::cerr << "Creating wire 1" << std::endl;
905 wire_t = myShapesOperations->MakeWire(edgeList1, 1e-7);
906 if (wire_t.IsNull()) {
907 SetErrorCode("Impossible to build wire");
910 wire_t->GetLastFunction()->SetDescription("");
912 // std::cerr << "Creating face 1" << std::endl;
913 face_t = myShapesOperations->MakeFace(wire_t, false);
914 if (face_t.IsNull()) {
915 SetErrorCode("Impossible to build face");
918 face_t->GetLastFunction()->SetDescription("");
919 theShapes.push_back(face_t);
921 gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(P2->GetValue()));
922 gp_Pnt aP5 = BRep_Tool::Pnt(TopoDS::Vertex(vi1->GetValue()));
923 double deltaZ = aP2.Z() - aP5.Z();
924 // std::cerr << "Creating new point from vi1 with deltaZ = " << deltaZ << std::endl;
925 Handle(GEOM_Object) P5bis = myTransformOperations->TranslateDXDYDZCopy(vi1, 0, 0, deltaZ);
926 if (P5bis.IsNull()) {
927 SetErrorCode("Impossible to translate vertex");
930 P5bis->GetLastFunction()->SetDescription("");
932 gp_Pnt aP4 = BRep_Tool::Pnt(TopoDS::Vertex(P4->GetValue()));
933 gp_Pnt aP6 = BRep_Tool::Pnt(TopoDS::Vertex(vi2->GetValue()));
934 deltaZ = aP4.Z() - aP6.Z();
935 // std::cerr << "Creating new point from vi2 with deltaZ = " << deltaZ << std::endl;
936 Handle(GEOM_Object) P6bis = myTransformOperations->TranslateDXDYDZCopy(vi2, 0, 0, deltaZ);
937 if (P6bis.IsNull()) {
938 SetErrorCode("Impossible to translate vertex");
941 P6bis->GetLastFunction()->SetDescription("");
943 // std::cerr << "Creating new line 1 from 2 previous points" << std::endl;
944 Handle(GEOM_Object) Cote_3 = myBasicOperations->MakeLineTwoPnt(P5bis, P2);
945 if (Cote_3.IsNull()) {
946 SetErrorCode("Impossible to build edge in thickness");
949 Cote_3->GetLastFunction()->SetDescription("");
951 // std::cerr << "Creating new line 2 from 2 previous points" << std::endl;
952 Handle(GEOM_Object) Cote_4 = myBasicOperations->MakeLineTwoPnt(P6bis, P4);
953 if (Cote_4.IsNull()) {
954 SetErrorCode("Impossible to build edge in thickness");
957 Cote_4->GetLastFunction()->SetDescription("");
959 // std::cerr << "Creating new line 3 from 2 previous points" << std::endl;
960 Handle(GEOM_Object) Cote_5 = myBasicOperations->MakeLineTwoPnt(P5bis, P6bis);
961 if (Cote_4.IsNull()) {
962 SetErrorCode("Impossible to build edge in thickness");
965 Cote_5->GetLastFunction()->SetDescription("");
967 //std::list<Handle(GEOM_Object)> edgeList2;
968 //edgeList2.push_back(edge_chan_inc);
969 //edgeList2.push_back(Cote_3);
970 //edgeList2.push_back(Cote_5);
971 //edgeList2.push_back(Cote_4);
972 // std::cerr << "Creating wire 2" << std::endl;
973 //wire_t2 = myShapesOperations->MakeWire(edgeList2, 1e-7);
974 //if (wire_t2.IsNull()) {
975 // SetErrorCode("Impossible to build wire");
978 //wire_t2->GetLastFunction()->SetDescription("");
979 // std::cerr << "Creating face 2" << std::endl;
980 //face_t2 = myShapesOperations->MakeFace(wire_t2, false);
981 face_t2 = my3DPrimOperations->MakePrismVecH(edge_chan_inc, Cote_4, - 2.0*theR2);
982 if (face_t2.IsNull()) {
983 SetErrorCode("Impossible to build face");
986 face_t2->GetLastFunction()->SetDescription("");
987 theShapes.push_back(face_t2);
991 Handle(GEOM_Object) aP0 = myBasicOperations->MakePointXYZ(0, 0, 0);
992 Handle(GEOM_Object) aVZ = myBasicOperations->MakeVectorDXDYDZ(0, 0, 1);
993 Handle(GEOM_Object) aVXZ = myBasicOperations->MakeVectorDXDYDZ(aR1Ext, 0, 0.5*(theL1+theVertCylinderRadius));
994 Handle(GEOM_Object) aPlnOZ = myBasicOperations->MakePlanePntVec(aP0, aVZ, aSize);
995 Handle(GEOM_Object) aPlnOXZ = myBasicOperations->MakePlanePntVec(aP0, aVXZ, aSize);
996 aP0->GetLastFunction()->SetDescription("");
997 aVZ->GetLastFunction()->SetDescription("");
998 aVXZ->GetLastFunction()->SetDescription("");
999 aPlnOZ->GetLastFunction()->SetDescription("");
1000 aPlnOXZ->GetLastFunction()->SetDescription("");
1001 theShapes.push_back(aPlnOZ);
1002 theShapes.push_back(aPlnOXZ);
1005 Handle(TColStd_HSequenceOfTransient) partitionShapes = new TColStd_HSequenceOfTransient;
1006 Handle(TColStd_HSequenceOfTransient) theTools = new TColStd_HSequenceOfTransient;
1007 Handle(TColStd_HSequenceOfTransient) theKeepInside = new TColStd_HSequenceOfTransient;
1008 Handle(TColStd_HSequenceOfTransient) theRemoveInside = new TColStd_HSequenceOfTransient;
1009 Handle(TColStd_HArray1OfInteger) theMaterials;
1010 partitionShapes->Append(theShape);
1011 theTools->Append(aPlnOZ);
1012 if (Abs(aR1Ext - aR2Ext) > Precision::Confusion() )
1013 theTools->Append(aPlnOXZ);
1014 theTools->Append(face_t);
1016 theTools->Append(face_t2);
1018 Te3 = myBooleanOperations->MakePartition
1019 (partitionShapes, theTools, theKeepInside, theRemoveInside,
1020 TopAbs_SOLID, false, theMaterials, 0, false);
1022 SetErrorCode("Impossible to build partition of TShape");
1023 // Handle(GEOM_Object) aCompound = myShapesOperations->MakeCompound(theShapes);
1024 // TopoDS_Shape aCompoundShape = aCompound->GetValue();
1025 // theShape->GetLastFunction()->SetValue(aCompoundShape);
1028 Te3->GetLastFunction()->SetDescription("");
1030 // Last verification: result should be a block
1031 std::list<GEOMImpl_IBlocksOperations::BCError> errList;
1032 if (!myBlocksOperations->CheckCompoundOfBlocks(Te3,errList)) {
1033 SetErrorCode("TShape is not a block");
1036 TopoDS_Shape aShape = Te3->GetValue();
1037 theShape->GetLastFunction()->SetValue(aShape);
1038 } catch (Standard_Failure) {
1039 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1040 SetErrorCode(aFail->GetMessageString());
1048 // Mirror and glue faces
1049 bool GEOMImpl_IAdvancedOperations::MakePipeTShapeMirrorAndGlue(Handle(GEOM_Object) theShape,
1050 double theR1, double theW1, double theL1,
1051 double theR2, double theW2, double theL2)
1056 double aSize = 2*(theL1 + theL2);
1057 double aR1Ext = theR1 + theW1;
1060 Handle(GEOM_Object) aP0 = myBasicOperations->MakePointXYZ(0, 0, 0);
1061 aP0->GetLastFunction()->SetDescription("");
1062 Handle(GEOM_Object) aVX = myBasicOperations->MakeVectorDXDYDZ(1, 0, 0);
1063 Handle(GEOM_Object) aVY = myBasicOperations->MakeVectorDXDYDZ(0, 1, 0);
1064 aVX->GetLastFunction()->SetDescription("");
1065 aVY->GetLastFunction()->SetDescription("");
1066 Handle(GEOM_Object) aPlane_OX = myBasicOperations->MakePlanePntVec(aP0, aVX, 2*(aR1Ext + theL2));
1067 Handle(GEOM_Object) aPlane_OY = myBasicOperations->MakePlanePntVec(aP0, aVY, aSize);
1068 aPlane_OX->GetLastFunction()->SetDescription("");
1069 aPlane_OY->GetLastFunction()->SetDescription("");
1071 Handle(GEOM_Object) Te4 = myTransformOperations->MirrorPlaneCopy(theShape, aPlane_OX);
1073 SetErrorCode("Impossible to build mirror of quarter TShape");
1077 Handle(GEOM_Object) Te5 = myTransformOperations->MirrorPlaneCopy(theShape, aPlane_OY);
1079 SetErrorCode("Impossible to build mirror of half TShape");
1083 Handle(GEOM_Object) Te6 = myTransformOperations->MirrorPlaneCopy(Te4, aPlane_OY);
1085 SetErrorCode("Impossible to build mirror of half TShape");
1089 std::list<Handle(GEOM_Object)> aShapesList;
1090 aShapesList.push_back(theShape);
1091 aShapesList.push_back(Te4);
1092 aShapesList.push_back(Te5);
1093 aShapesList.push_back(Te6);
1094 Handle(GEOM_Object) Te7 = myShapesOperations->MakeCompound(aShapesList);
1096 SetErrorCode("Impossible to build compound");
1100 Handle(GEOM_Object) Te8 = myShapesOperations->MakeGlueFaces(Te7, 1e-7, true);
1102 SetErrorCode("Impossible to glue faces of TShape");
1106 TopoDS_Shape aShape = Te8->GetValue();
1108 theShape->GetLastFunction()->SetValue(aShape);
1110 Te4->GetLastFunction()->SetDescription("");
1111 Te5->GetLastFunction()->SetDescription("");
1112 Te6->GetLastFunction()->SetDescription("");
1113 Te7->GetLastFunction()->SetDescription("");
1114 Te8->GetLastFunction()->SetDescription("");
1120 //=============================================================================
1123 * \brief Create a T-shape object with specified caracteristics for the main and
1124 * the incident pipes (radius, width, half-length).
1125 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1126 * \param theR1 Internal radius of main pipe
1127 * \param theW1 Width of main pipe
1128 * \param theL1 Half-length of main pipe
1129 * \param theR2 Internal radius of incident pipe (R2 < R1)
1130 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1131 * \param theL2 Half-length of incident pipe
1132 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1133 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1135 //=============================================================================
1136 Handle(TColStd_HSequenceOfTransient)
1137 GEOMImpl_IAdvancedOperations::MakePipeTShape(double theR1, double theW1, double theL1,
1138 double theR2, double theW2, double theL2,
1141 MESSAGE("GEOMImpl_IAdvancedOperations::MakePipeTShape");
1144 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1146 //Add a new shape function with parameters
1147 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_BASIC);
1148 if (aFunction.IsNull()) return NULL;
1150 //Check if the function is set correctly
1151 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1153 GEOMImpl_IPipeTShape aData(aFunction);
1161 aData.SetHexMesh(theHexMesh);
1163 //Compute the resulting value
1165 #if OCC_VERSION_LARGE > 0x06010000
1168 if (!GetSolver()->ComputeFunction(aFunction)) {
1169 SetErrorCode("TShape driver failed");
1173 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1175 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1178 } catch (Standard_Failure) {
1179 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1180 SetErrorCode(aFail->GetMessageString());
1185 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1186 aSeq->Append(aShape);
1190 * Get the groups: BEGIN
1193 if (!MakeGroups(aShape, TSHAPE_BASIC, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1196 catch (Standard_Failure) {
1197 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1198 SetErrorCode(aFail->GetMessageString());
1202 TCollection_AsciiString aListRes, anEntry;
1203 // Iterate over the sequence aSeq
1204 Standard_Integer aNbGroups = aSeq->Length();
1205 Standard_Integer i = 2;
1206 for (; i <= aNbGroups; i++) {
1207 Handle(Standard_Transient) anItem = aSeq->Value(i);
1208 if (anItem.IsNull()) continue;
1209 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1210 if (aGroup.IsNull()) continue;
1211 //Make a Python command
1212 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1213 aListRes += anEntry + ", ";
1216 aListRes.Trunc(aListRes.Length() - 2);
1218 //Make a Python command
1219 GEOM::TPythonDump(aFunction)
1220 << "[" << aShape << ", " << aListRes.ToCString() << "] = geompy.MakePipeTShape("
1221 << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", "
1222 << theHexMesh << ")";
1225 * Get the groups: END
1228 //Make a Python command
1229 GEOM::TPythonDump(aFunction)
1230 << "[" << aShape << "] = geompy.MakePipeTShape(" << theR1 << ", " << theW1 << ", "
1231 << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theHexMesh << ")";
1239 //=============================================================================
1241 * MakePipeTShapeWithPosition
1242 * Create a T-shape object with specified caracteristics for the main and
1243 * the incident pipes (radius, width, half-length).
1244 * The extremities of the main pipe are located on junctions points P1 and P2.
1245 * The extremity of the incident pipe is located on junction point P3.
1246 * \param theR1 Internal radius of main pipe
1247 * \param theW1 Width of main pipe
1248 * \param theL1 Half-length of main pipe
1249 * \param theR2 Internal radius of incident pipe (R2 < R1)
1250 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1251 * \param theL2 Half-length of incident pipe
1252 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1253 * \param theP1 1st junction point of main pipe
1254 * \param theP2 2nd junction point of main pipe
1255 * \param theP3 Junction point of incident pipe
1256 * \return List of GEOM_Objects, containing the created shape and propagation groups..
1258 //=============================================================================
1259 Handle(TColStd_HSequenceOfTransient)
1260 GEOMImpl_IAdvancedOperations::MakePipeTShapeWithPosition(double theR1, double theW1, double theL1,
1261 double theR2, double theW2, double theL2,
1263 Handle(GEOM_Object) theP1,
1264 Handle(GEOM_Object) theP2,
1265 Handle(GEOM_Object) theP3)
1269 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1273 //Add a new shape function with parameters
1274 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_BASIC);
1275 if (aFunction.IsNull()) return NULL;
1277 //Check if the function is set correctly
1278 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1280 // Check new position
1281 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1285 GEOMImpl_IPipeTShape aData(aFunction);
1293 aData.SetHexMesh(theHexMesh);
1295 //Compute the resulting value
1297 #if OCC_VERSION_LARGE > 0x06010000
1300 if (!GetSolver()->ComputeFunction(aFunction)) {
1301 SetErrorCode("TShape driver failed");
1304 } catch (Standard_Failure) {
1305 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1306 SetErrorCode(aFail->GetMessageString());
1311 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1313 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1317 TopoDS_Shape Te = aShape->GetValue();
1320 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
1321 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
1322 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
1323 aFunction->SetValue(aTrsf_Shape);
1324 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1325 aSeq->Append(aShape);
1329 // Get the groups: BEGIN
1332 if (!MakeGroups(aShape,TSHAPE_BASIC, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf)) {
1336 catch (Standard_Failure) {
1337 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1338 SetErrorCode(aFail->GetMessageString());
1342 TCollection_AsciiString aListRes, anEntry;
1343 // Iterate over the sequence aSeq
1344 Standard_Integer aNbGroups = aSeq->Length();
1345 Standard_Integer i = 2;
1346 for (; i <= aNbGroups; i++) {
1347 Handle(Standard_Transient) anItem = aSeq->Value(i);
1348 if (anItem.IsNull()) continue;
1349 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1350 if (aGroup.IsNull()) continue;
1351 //Make a Python command
1352 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1353 aListRes += anEntry + ", ";
1356 aListRes.Trunc(aListRes.Length() - 2);
1358 //Make a Python command
1359 GEOM::TPythonDump(aFunction)
1360 << "[" << aShape << ", " << aListRes.ToCString() << "] = geompy.MakePipeTShape("
1361 << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", "
1362 << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
1365 // Get the groups: END
1369 //Make a Python command
1370 GEOM::TPythonDump(aFunction)
1371 << "[" << aShape << "] = geompy.MakePipeTShape(" << theR1 << ", " << theW1 << ", "
1372 << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theHexMesh << ", " << theP1
1373 << ", " << theP2 << ", " << theP3 << ")";
1381 //=============================================================================
1383 * MakePipeTShapeChamfer
1384 * Create a T-shape object with specified caracteristics for the main and
1385 * the incident pipes (radius, width, half-length). A chamfer is created
1386 * on the junction of the pipes.
1387 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1388 * \param theR1 Internal radius of main pipe
1389 * \param theW1 Width of main pipe
1390 * \param theL1 Half-length of main pipe
1391 * \param theR2 Internal radius of incident pipe (R2 < R1)
1392 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1393 * \param theL2 Half-length of incident pipe
1394 * \param theH Height of chamfer.
1395 * \param theW Width of chamfer.
1396 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1397 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1399 //=============================================================================
1400 Handle(TColStd_HSequenceOfTransient)
1401 GEOMImpl_IAdvancedOperations::MakePipeTShapeChamfer(double theR1, double theW1, double theL1,
1402 double theR2, double theW2, double theL2,
1403 double theH, double theW,
1408 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1409 //Add a new shape function with parameters
1410 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_CHAMFER);
1411 if (aFunction.IsNull()) return NULL;
1413 //Check if the function is set correctly
1414 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1416 GEOMImpl_IPipeTShape aData(aFunction);
1426 aData.SetHexMesh(theHexMesh);
1428 //Compute the resulting value
1430 #if OCC_VERSION_LARGE > 0x06010000
1433 if (!GetSolver()->ComputeFunction(aFunction)) {
1434 SetErrorCode("TShape driver failed");
1437 } catch (Standard_Failure) {
1438 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1439 SetErrorCode(aFail->GetMessageString());
1444 TopoDS_Shape aShapeShape = aShape->GetValue();
1445 TopTools_IndexedMapOfShape anEdgesIndices;
1446 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1447 // Common edges on external cylinders
1448 Handle(GEOM_Object) box_e;
1450 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1453 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1455 box_e->GetLastFunction()->SetDescription("");
1456 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1457 box_e->GetLastFunction()->SetDescription("");
1459 Handle(TColStd_HSequenceOfInteger) edges_e =
1460 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1461 box_e->GetLastFunction()->SetDescription("");
1463 if (edges_e.IsNull() || edges_e->Length() == 0) {
1464 SetErrorCode("External edges not found");
1467 int nbEdgesInChamfer = 0;
1468 std::list<int> theEdges;
1469 for (int i=1; i<=edges_e->Length();i++) {
1470 int edgeID = edges_e->Value(i);
1471 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1472 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1476 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1477 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1478 nbEdgesInChamfer ++;
1479 theEdges.push_back(edgeID);
1483 if (theHexMesh && nbEdgesInChamfer == 1)
1486 Handle(GEOM_Object) aChamfer;
1488 aChamfer = myLocalOperations->MakeChamferEdges(aShape, theW, theH, theEdges);
1490 catch (Standard_Failure) {
1491 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1492 SetErrorCode(aFail->GetMessageString());
1495 if (aChamfer.IsNull()) {
1496 SetErrorCode("Chamfer can not be computed on the given shape with the given parameters");
1499 aChamfer->GetLastFunction()->SetDescription("");
1501 TopoDS_Shape aChamferShape = aChamfer->GetValue();
1502 aFunction->SetValue(aChamferShape);
1505 // bool doMesh = false;
1508 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, 0, false)) {
1509 MESSAGE("PipeTShape partition failed");
1513 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2)) {
1514 MESSAGE("PipeTShape mirrors and glue failed");
1520 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1521 aSeq->Append(aShape);
1526 // Get the groups: BEGIN
1528 //if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf())) {
1529 // //Make a Python command
1530 // GEOM::TPythonDump(aFunction)
1531 // << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1532 // << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1533 // << ", " << theHexMesh << ")";
1537 if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1540 catch (Standard_Failure) {
1541 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1542 SetErrorCode(aFail->GetMessageString());
1546 TCollection_AsciiString aListRes, anEntry;
1547 // Iterate over the sequence aSeq
1548 Standard_Integer aNbGroups = aSeq->Length();
1549 Standard_Integer i = 2;
1550 for (; i <= aNbGroups; i++) {
1551 Handle(Standard_Transient) anItem = aSeq->Value(i);
1552 if (anItem.IsNull()) continue;
1553 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1554 if (aGroup.IsNull()) continue;
1555 //Make a Python command
1556 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1557 aListRes += anEntry + ", ";
1560 aListRes.Trunc(aListRes.Length() - 2);
1562 //Make a Python command
1563 GEOM::TPythonDump(aFunction)
1564 << "[" << aShape << ", " << aListRes.ToCString()
1565 << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1566 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW << ", " << theHexMesh << ")";
1570 // Get the groups: END
1573 //Make a Python command
1574 GEOM::TPythonDump(aFunction)
1575 << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1576 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1577 << ", " << theHexMesh << ")";
1585 //=============================================================================
1587 * MakePipeTShapeChamferWithPosition
1588 * Create a T-shape object with specified caracteristics for the main and
1589 * the incident pipes (radius, width, half-length). A chamfer is created
1590 * on the junction of the pipes.
1591 * The extremities of the main pipe are located on junctions points P1 and P2.
1592 * The extremity of the incident pipe is located on junction point P3.
1593 * \param theR1 Internal radius of main pipe
1594 * \param theW1 Width of main pipe
1595 * \param theL1 Half-length of main pipe
1596 * \param theR2 Internal radius of incident pipe (R2 < R1)
1597 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1598 * \param theL2 Half-length of incident pipe
1599 * \param theH Height of chamfer.
1600 * \param theW Width of chamfer.
1601 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1602 * \param theP1 1st junction point of main pipe
1603 * \param theP2 2nd junction point of main pipe
1604 * \param theP3 Junction point of incident pipe
1605 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1607 //=============================================================================
1608 Handle(TColStd_HSequenceOfTransient)
1609 GEOMImpl_IAdvancedOperations::MakePipeTShapeChamferWithPosition(double theR1, double theW1, double theL1,
1610 double theR2, double theW2, double theL2,
1611 double theH, double theW,
1613 Handle(GEOM_Object) theP1,
1614 Handle(GEOM_Object) theP2,
1615 Handle(GEOM_Object) theP3)
1619 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1620 //Add a new shape function with parameters
1621 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_CHAMFER);
1622 if (aFunction.IsNull()) return NULL;
1624 //Check if the function is set correctly
1625 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1627 // Check new position
1628 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
1632 GEOMImpl_IPipeTShape aData(aFunction);
1642 aData.SetHexMesh(theHexMesh);
1644 //Compute the resulting value
1646 #if OCC_VERSION_LARGE > 0x06010000
1649 if (!GetSolver()->ComputeFunction(aFunction)) {
1650 SetErrorCode("TShape driver failed");
1653 } catch (Standard_Failure) {
1654 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1655 SetErrorCode(aFail->GetMessageString());
1660 TopoDS_Shape aShapeShape = aShape->GetValue();
1661 TopTools_IndexedMapOfShape anEdgesIndices;
1662 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1663 // Common edges on external cylinders
1664 Handle(GEOM_Object) box_e;
1666 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1669 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1671 box_e->GetLastFunction()->SetDescription("");
1672 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1673 box_e->GetLastFunction()->SetDescription("");
1675 Handle(TColStd_HSequenceOfInteger) edges_e =
1676 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1677 box_e->GetLastFunction()->SetDescription("");
1679 if (edges_e.IsNull() || edges_e->Length() == 0) {
1680 SetErrorCode("External edges not found");
1683 int nbEdgesInChamfer = 0;
1684 std::list<int> theEdges;
1685 for (int i=1; i<=edges_e->Length();i++) {
1686 int edgeID = edges_e->Value(i);
1687 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1688 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1690 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1691 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1692 nbEdgesInChamfer ++;
1693 theEdges.push_back(edgeID);
1697 if (theHexMesh && nbEdgesInChamfer == 1)
1700 Handle(GEOM_Object) aChamfer;
1702 aChamfer = myLocalOperations->MakeChamferEdges(aShape, theW, theH, theEdges);
1704 catch (Standard_Failure) {
1705 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1706 SetErrorCode(aFail->GetMessageString());
1709 if (aChamfer.IsNull()) {
1710 SetErrorCode("Chamfer can not be computed on the given shape with the given parameters");
1713 aChamfer->GetLastFunction()->SetDescription("");
1715 TopoDS_Shape aChamferShape = aChamfer->GetValue();
1716 aFunction->SetValue(aChamferShape);
1720 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, 0, false))
1722 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1726 TopoDS_Shape Te = aShape->GetValue();
1729 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
1730 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
1731 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
1732 aFunction->SetValue(aTrsf_Shape);
1733 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1734 aSeq->Append(aShape);
1737 * Get the groups: BEGIN
1740 if (!MakeGroups(aShape, TSHAPE_CHAMFER, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf))
1743 catch (Standard_Failure) {
1744 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1745 SetErrorCode(aFail->GetMessageString());
1749 TCollection_AsciiString aListRes, anEntry;
1750 // Iterate over the sequence aSeq
1751 Standard_Integer aNbGroups = aSeq->Length();
1752 Standard_Integer i = 2;
1753 for (; i <= aNbGroups; i++) {
1754 Handle(Standard_Transient) anItem = aSeq->Value(i);
1755 if (anItem.IsNull()) continue;
1756 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1757 if (aGroup.IsNull()) continue;
1758 //Make a Python command
1759 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1760 aListRes += anEntry + ", ";
1763 aListRes.Trunc(aListRes.Length() - 2);
1765 //Make a Python command
1766 GEOM::TPythonDump(aFunction)
1767 << "[" << aShape << ", " << aListRes.ToCString()
1768 << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1769 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW << ", " << theHexMesh << ", "
1770 << theP1 << ", " << theP2 << ", " << theP3 << ")";
1773 * Get the groups: END
1776 //Make a Python command
1777 GEOM::TPythonDump(aFunction)
1778 << "[" << aShape << "] = geompy.MakePipeTShapeChamfer(" << theR1 << ", " << theW1
1779 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theH << ", " << theW
1780 << ", " << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
1788 //=============================================================================
1790 * MakePipeTShapeFillet
1791 * Create a T-shape object with specified caracteristics for the main and
1792 * the incident pipes (radius, width, half-length). A fillet is created
1793 * on the junction of the pipes.
1794 * Center of the shape is (0,0,0). The main plane of the T-shape is XOY.
1795 * \param theR1 Internal radius of main pipe
1796 * \param theW1 Width of main pipe
1797 * \param theL1 Half-length of main pipe
1798 * \param theR2 Internal radius of incident pipe (R2 < R1)
1799 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1800 * \param theL2 Half-length of incident pipe
1801 * \param theRF Radius of curvature of fillet.
1802 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1803 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1805 //=============================================================================
1806 Handle(TColStd_HSequenceOfTransient)
1807 GEOMImpl_IAdvancedOperations::MakePipeTShapeFillet(double theR1, double theW1, double theL1,
1808 double theR2, double theW2, double theL2,
1809 double theRF, bool theHexMesh)
1813 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
1814 //Add a new shape function with parameters
1815 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_FILLET);
1816 if (aFunction.IsNull()) return NULL;
1818 //Check if the function is set correctly
1819 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
1821 GEOMImpl_IPipeTShape aData(aFunction);
1830 aData.SetHexMesh(theHexMesh);
1832 //Compute the resulting value
1834 #if OCC_VERSION_LARGE > 0x06010000
1837 if (!GetSolver()->ComputeFunction(aFunction)) {
1838 SetErrorCode("TShape driver failed");
1841 } catch (Standard_Failure) {
1842 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1843 SetErrorCode(aFail->GetMessageString());
1848 TopoDS_Shape aShapeShape = aShape->GetValue();
1849 TopTools_IndexedMapOfShape anEdgesIndices;
1850 TopExp::MapShapes(aShapeShape, anEdgesIndices);
1851 // Common edges on external cylinders
1852 Handle(GEOM_Object) box_e;
1854 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
1857 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
1859 box_e->GetLastFunction()->SetDescription("");
1860 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
1861 box_e->GetLastFunction()->SetDescription("");
1863 Handle(TColStd_HSequenceOfInteger) edges_e =
1864 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
1865 box_e->GetLastFunction()->SetDescription("");
1867 if (edges_e.IsNull() || edges_e->Length() == 0) {
1868 SetErrorCode("External edges not found");
1871 int nbEdgesInFillet = 0;
1872 std::list<int> theEdges;
1873 for (int i=1; i<=edges_e->Length();i++) {
1874 int edgeID = edges_e->Value(i);
1875 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
1876 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
1878 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
1879 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
1881 theEdges.push_back(edgeID);
1885 if (theHexMesh && nbEdgesInFillet == 1)
1889 Handle(GEOM_Object) aFillet;
1891 aFillet = myLocalOperations->MakeFilletEdges(aShape, theRF, theEdges);
1893 catch (Standard_Failure) {
1894 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1895 SetErrorCode(aFail->GetMessageString());
1898 if (aFillet.IsNull()) {
1899 //SetErrorCode("Fillet can not be computed on the given shape with the given parameters");
1900 SetErrorCode(myLocalOperations->GetErrorCode());
1903 aFillet->GetLastFunction()->SetDescription("");
1905 TopoDS_Shape aFilletShape = aFillet->GetValue();
1906 aFunction->SetValue(aFilletShape);
1909 // BEGIN: Limit tolerances (debug)
1910 Handle(GEOM_Object) aCorr1 = myHealingOperations->LimitTolerance(aShape, 1e-07);
1911 TopoDS_Shape aCorr1Shape = aCorr1->GetValue();
1912 aShape->GetLastFunction()->SetValue(aCorr1Shape);
1913 aCorr1->GetLastFunction()->SetDescription("");
1914 // END: Limit tolerances (debug)
1917 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, 0, 0, theRF, false))
1919 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
1923 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
1924 aSeq->Append(aShape);
1927 * Get the groups: BEGIN
1930 if (!MakeGroups(aShape, TSHAPE_FILLET, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, gp_Trsf()))
1933 catch (Standard_Failure) {
1934 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1935 SetErrorCode(aFail->GetMessageString());
1939 TCollection_AsciiString aListRes, anEntry;
1940 // Iterate over the sequence aSeq
1941 Standard_Integer aNbGroups = aSeq->Length();
1942 Standard_Integer i = 2;
1943 for (; i <= aNbGroups; i++) {
1944 Handle(Standard_Transient) anItem = aSeq->Value(i);
1945 if (anItem.IsNull()) continue;
1946 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
1947 if (aGroup.IsNull()) continue;
1948 //Make a Python command
1949 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
1950 aListRes += anEntry + ", ";
1953 aListRes.Trunc(aListRes.Length() - 2);
1955 //Make a Python command
1956 GEOM::TPythonDump(aFunction)
1957 << "[" << aShape << ", " << aListRes.ToCString()
1958 << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
1959 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", " << theHexMesh << ")";
1962 * Get the groups: END
1965 //Make a Python command
1966 GEOM::TPythonDump(aFunction)
1967 << "[" << aShape << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1
1968 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", "
1969 << theHexMesh << ")";
1977 //=============================================================================
1979 * MakePipeTShapeFilletWithPosition
1980 * \brief Create a T-shape object with specified caracteristics for the main and
1981 * the incident pipes (radius, width, half-length). A fillet is created
1982 * on the junction of the pipes.
1983 * The extremities of the main pipe are located on junctions points P1 and P2.
1984 * The extremity of the incident pipe is located on junction point P3.
1985 * \param theR1 Internal radius of main pipe
1986 * \param theW1 Width of main pipe
1987 * \param theL1 Half-length of main pipe
1988 * \param theR2 Internal radius of incident pipe (R2 < R1)
1989 * \param theW2 Width of incident pipe (R2+W2 < R1+W1)
1990 * \param theL2 Half-length of incident pipe
1991 * \param theRF Radius of curvature of fillet
1992 * \param theHexMesh Boolean indicating if shape is prepared for hex mesh
1993 * \param theP1 1st junction point of main pipe
1994 * \param theP2 2nd junction point of main pipe
1995 * \param theP3 Junction point of incident pipe
1996 * \return List of GEOM_Objects, containing the created shape and propagation groups.
1998 //=============================================================================
1999 Handle(TColStd_HSequenceOfTransient)
2000 GEOMImpl_IAdvancedOperations::MakePipeTShapeFilletWithPosition(double theR1, double theW1, double theL1,
2001 double theR2, double theW2, double theL2,
2002 double theRF, bool theHexMesh,
2003 Handle(GEOM_Object) theP1,
2004 Handle(GEOM_Object) theP2,
2005 Handle(GEOM_Object) theP3)
2009 Handle(GEOM_Object) aShape = GetEngine()->AddObject(GetDocID(), GEOM_TSHAPE);
2010 //Add a new shape function with parameters
2011 Handle(GEOM_Function) aFunction = aShape->AddFunction(GEOMImpl_PipeTShapeDriver::GetID(), TSHAPE_FILLET);
2012 if (aFunction.IsNull()) return NULL;
2014 //Check if the function is set correctly
2015 if (aFunction->GetDriverGUID() != GEOMImpl_PipeTShapeDriver::GetID()) return NULL;
2017 // Check new position
2018 if (!CheckCompatiblePosition(theL1, theL2, theP1, theP2, theP3, 0.01)) {
2022 GEOMImpl_IPipeTShape aData(aFunction);
2031 aData.SetHexMesh(theHexMesh);
2033 //Compute the resulting value
2035 #if OCC_VERSION_LARGE > 0x06010000
2038 if (!GetSolver()->ComputeFunction(aFunction)) {
2039 SetErrorCode("TShape driver failed");
2042 } catch (Standard_Failure) {
2043 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2044 SetErrorCode(aFail->GetMessageString());
2049 TopoDS_Shape aShapeShape = aShape->GetValue();
2050 TopTools_IndexedMapOfShape anEdgesIndices;
2051 TopExp::MapShapes(aShapeShape, anEdgesIndices);
2052 // Common edges on external cylinders
2053 Handle(GEOM_Object) box_e;
2055 box_e = my3DPrimOperations->MakeBoxDXDYDZ(theR2+theW2, theR2+theW2, theR1+theW1);
2058 box_e = my3DPrimOperations->MakeBoxDXDYDZ(2*(theR2+theW2), 2*(theR2+theW2), theR1+theW1);
2060 box_e->GetLastFunction()->SetDescription("");
2061 box_e = myTransformOperations->TranslateDXDYDZ(box_e, -(theR2+theW2), -(theR2+theW2), 0);
2062 box_e->GetLastFunction()->SetDescription("");
2064 Handle(TColStd_HSequenceOfInteger) edges_e =
2065 myShapesOperations->GetShapesOnBoxIDs(box_e, aShape, TopAbs_EDGE, GEOMAlgo_ST_IN);
2066 box_e->GetLastFunction()->SetDescription("");
2068 if (edges_e.IsNull() || edges_e->Length() == 0) {
2069 SetErrorCode("External edges not found");
2072 int nbEdgesInFillet = 0;
2073 std::list<int> theEdges;
2074 for (int i=1; i<=edges_e->Length();i++) {
2075 int edgeID = edges_e->Value(i);
2076 TopoDS_Shape theEdge = anEdgesIndices.FindKey(edgeID);
2077 TopExp_Explorer Ex(theEdge,TopAbs_VERTEX);
2079 gp_Pnt aPt = BRep_Tool::Pnt(TopoDS::Vertex(Ex.Current()));
2080 if (Abs(aPt.Z() - (theR1+theW1)) <= Precision::Confusion()) {
2082 theEdges.push_back(edgeID);
2086 if (theHexMesh && nbEdgesInFillet == 1)
2090 Handle(GEOM_Object) aFillet;
2092 aFillet = myLocalOperations->MakeFilletEdges(aShape, theRF, theEdges);
2094 catch (Standard_Failure) {
2095 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2096 SetErrorCode(aFail->GetMessageString());
2099 if (aFillet.IsNull()) {
2100 SetErrorCode("Fillet can not be computed on the given shape with the given parameters");
2103 aFillet->GetLastFunction()->SetDescription("");
2105 TopoDS_Shape aFilletShape = aFillet->GetValue();
2106 aFunction->SetValue(aFilletShape);
2109 // BEGIN: Limit tolerances (debug)
2110 Handle(GEOM_Object) aCorr1 = myHealingOperations->LimitTolerance(aShape, 1e-07);
2111 TopoDS_Shape aCorr1Shape = aCorr1->GetValue();
2112 aShape->GetLastFunction()->SetValue(aCorr1Shape);
2113 aCorr1->GetLastFunction()->SetDescription("");
2114 // END: Limit tolerances (debug)
2117 if (!MakePipeTShapePartition(aShape, theR1, theW1, theL1, theR2, theW2, theL2, 0, 0, theRF, false))
2119 if (!MakePipeTShapeMirrorAndGlue(aShape, theR1, theW1, theL1, theR2, theW2, theL2))
2123 TopoDS_Shape Te = aShape->GetValue();
2126 gp_Trsf aTrsf = GetPositionTrsf(theL1, theL2, theP1, theP2, theP3);
2127 BRepBuilderAPI_Transform aTransformation(Te, aTrsf, Standard_False);
2128 TopoDS_Shape aTrsf_Shape = aTransformation.Shape();
2129 aFunction->SetValue(aTrsf_Shape);
2130 Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
2131 aSeq->Append(aShape);
2134 * Get the groups: BEGIN
2137 if (!MakeGroups(aShape, TSHAPE_FILLET, theR1, theW1, theL1, theR2, theW2, theL2, aSeq, aTrsf))
2140 catch (Standard_Failure) {
2141 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
2142 SetErrorCode(aFail->GetMessageString());
2146 TCollection_AsciiString aListRes, anEntry;
2147 // Iterate over the sequence aSeq
2148 Standard_Integer aNbGroups = aSeq->Length();
2149 Standard_Integer i = 2;
2150 for (; i <= aNbGroups; i++) {
2151 Handle(Standard_Transient) anItem = aSeq->Value(i);
2152 if (anItem.IsNull()) continue;
2153 Handle(GEOM_Object) aGroup = Handle(GEOM_Object)::DownCast(anItem);
2154 if (aGroup.IsNull()) continue;
2155 //Make a Python command
2156 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
2157 aListRes += anEntry + ", ";
2160 aListRes.Trunc(aListRes.Length() - 2);
2162 //Make a Python command
2163 GEOM::TPythonDump(aFunction)
2164 << "[" << aShape << ", " << aListRes.ToCString()
2165 << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1 << ", " << theL1 << ", " << theR2
2166 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", " << theHexMesh << ", " << theP1 << ", "
2167 << theP2 << ", " << theP3 << ")";
2170 * Get the groups: END
2173 //Make a Python command
2174 GEOM::TPythonDump(aFunction)
2175 << "[" << aShape << "] = geompy.MakePipeTShapeFillet(" << theR1 << ", " << theW1
2176 << ", " << theL1 << ", " << theR2 << ", " << theW2 << ", " << theL2 << ", " << theRF << ", "
2177 << theHexMesh << ", " << theP1 << ", " << theP2 << ", " << theP3 << ")";
2185 /*@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@*/