1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include <BRepOffsetAPI_MakeFilling.hxx>
25 #include <GEOMImpl_BlockDriver.hxx>
26 #include <GEOMImpl_IBlocks.hxx>
27 #include <GEOMImpl_IBlockTrsf.hxx>
28 #include <GEOMImpl_GlueDriver.hxx>
29 #include <GEOMImpl_Types.hxx>
30 #include <GEOMImpl_ILocalOperations.hxx>
31 #include <GEOMImpl_Block6Explorer.hxx>
32 #include <GEOMImpl_IBlocksOperations.hxx>
34 #include <GEOM_Function.hxx>
36 #include <ShHealOper_Sewing.hxx>
37 #include <NMTAlgo_Splitter1.hxx>
38 #include <BlockFix_BlockFixAPI.hxx>
40 #include "utilities.h"
42 #include <TNaming_CopyShape.hxx>
44 #include <BRepLib.hxx>
45 #include <BRep_Tool.hxx>
46 #include <BRepTools.hxx>
47 #include <BRepGProp.hxx>
48 #include <BRep_Builder.hxx>
49 #include <BRepTools_Quilt.hxx>
50 #include <BRepTools_WireExplorer.hxx>
51 #include <BRepBuilderAPI_MakeEdge.hxx>
52 #include <BRepBuilderAPI_MakeWire.hxx>
53 #include <BRepBuilderAPI_MakePolygon.hxx>
54 #include <BRepBuilderAPI_Transform.hxx>
55 #include <BRepClass_FaceClassifier.hxx>
56 #include <BRepClass3d_SolidClassifier.hxx>
57 #include <BRepExtrema_ExtPF.hxx>
58 #include <BRepExtrema_DistShapeShape.hxx>
62 #include <TopoDS_Shape.hxx>
63 #include <TopoDS_Edge.hxx>
64 #include <TopoDS_Wire.hxx>
65 #include <TopoDS_Shell.hxx>
66 #include <TopoDS_Solid.hxx>
67 #include <TopoDS_Compound.hxx>
68 #include <TopoDS_Iterator.hxx>
70 #include <TopExp_Explorer.hxx>
71 #include <TopTools_MapOfShape.hxx>
72 #include <TopTools_MapIteratorOfMapOfShape.hxx>
73 #include <TopTools_Array1OfShape.hxx>
74 #include <TopTools_SequenceOfShape.hxx>
75 #include <TopTools_ListOfShape.hxx>
76 #include <TopTools_ListIteratorOfListOfShape.hxx>
77 #include <TopTools_IndexedMapOfShape.hxx>
78 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
80 #include <GProp_GProps.hxx>
85 #include <Precision.hxx>
86 #include <TColgp_Array1OfPnt.hxx>
87 #include <TColStd_Array1OfInteger.hxx>
88 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
89 #include <StdFail_NotDone.hxx>
90 #include <Standard_NullObject.hxx>
91 #include <Standard_TypeMismatch.hxx>
92 #include <Standard_ConstructionError.hxx>
94 //=======================================================================
97 //=======================================================================
98 const Standard_GUID& GEOMImpl_BlockDriver::GetID()
100 static Standard_GUID aBlockDriver("FF1BBB67-5D14-4df2-980B-3A668264EA16");
105 //=======================================================================
106 //function : GEOMImpl_BlockDriver
108 //=======================================================================
109 GEOMImpl_BlockDriver::GEOMImpl_BlockDriver()
113 //=======================================================================
116 //=======================================================================
117 Standard_Integer GEOMImpl_BlockDriver::Execute(TFunction_Logbook& log) const
119 if (Label().IsNull()) return 0;
120 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
122 Standard_Integer aType = aFunction->GetType();
127 Standard_Real prec = Precision::Confusion();
129 Standard_Integer aNbSub = 0;
130 if (aType == BLOCK_COMPOUND_GLUE) {
134 } else if (aType == BLOCK_FACE_TWO_EDGES ||
135 aType == BLOCK_TWO_FACES) {
139 } else if (aType == BLOCK_FACE_FOUR_PNT ||
140 aType == BLOCK_FACE_FOUR_EDGES) {
144 } else if (aType == BLOCK_SIX_FACES) {
152 GEOMImpl_IBlocks aCI (aFunction);
153 Handle(TColStd_HSequenceOfTransient) aShapes = aCI.GetShapes();
154 Standard_Integer nbshapes = aShapes->Length();
156 if (nbshapes != aNbSub) {
157 Standard_TypeMismatch::Raise
158 ("Number of elements for object construction does not correspond to the used constructor");
161 TopTools_Array1OfShape anArgs (1, aNbSub);
162 Standard_Integer argi;
163 for (argi = 1; argi <= aNbSub; argi++) {
164 Handle(GEOM_Function) aRef = Handle(GEOM_Function)::DownCast(aShapes->Value(argi));
165 TopoDS_Shape anArg = aRef->GetValue();
166 if (anArg.IsNull()) {
167 Standard_NullObject::Raise("Null shape is given as argument");
169 anArgs(argi) = anArg;
172 if (aType == BLOCK_FACE_FOUR_EDGES) {
174 // Make face from four edges
175 if (anArgs(1).ShapeType() != TopAbs_EDGE || anArgs(2).ShapeType() != TopAbs_EDGE ||
176 anArgs(3).ShapeType() != TopAbs_EDGE || anArgs(4).ShapeType() != TopAbs_EDGE) {
177 Standard_TypeMismatch::Raise("Shape for face construction is not an edge");
180 // count corner vertices
181 TopTools_MapOfShape aVertMap;
182 for (Standard_Integer ii = 1; ii <= 4; ii++) {
183 TopoDS_Edge anEdge = TopoDS::Edge(anArgs(ii));
184 TopoDS_Vertex V1, V2;
185 TopExp::Vertices(anEdge, V1, V2, Standard_True);
186 if (V1.IsNull() || V2.IsNull()) {
187 Standard_NullObject::Raise("Bad edge for face construction: vertex is not defined");
189 if (BRepTools::Compare(V1,V2)) {
190 Standard_ConstructionError::Raise("Edge ends are too close");
192 Standard_Boolean isCoin1 = Standard_False, isCoin2 = Standard_False;
193 TopTools_MapIteratorOfMapOfShape anIter (aVertMap);
194 for (; anIter.More(); anIter.Next()) {
195 TopoDS_Vertex V = TopoDS::Vertex(anIter.Key());
196 if (BRepTools::Compare(V,V1)) isCoin1 = Standard_True;
197 if (BRepTools::Compare(V,V2)) isCoin2 = Standard_True;
199 if (!isCoin1) aVertMap.Add(V1);
200 if (!isCoin2) aVertMap.Add(V2);
202 if (aVertMap.Extent() != 4) {
203 Standard_ConstructionError::Raise("The edges must form a closed wire");
206 TopoDS_Edge anEdge1 = TopoDS::Edge(anArgs(1));
207 TopoDS_Edge anEdge2 = TopoDS::Edge(anArgs(2));
208 TopoDS_Edge anEdge3 = TopoDS::Edge(anArgs(3));
209 TopoDS_Edge anEdge4 = TopoDS::Edge(anArgs(4));
211 // check, if anEdge1 has common/coincident vertex with anEdge2,
212 Standard_Boolean isConnected12 = Standard_False;
213 TopoDS_Vertex V11, V12, V21, V22;
214 TopExp::Vertices(anEdge1, V11, V12, Standard_True);
215 TopExp::Vertices(anEdge2, V21, V22, Standard_True);
216 if (BRepTools::Compare(V11,V21) || BRepTools::Compare(V11,V22) ||
217 BRepTools::Compare(V12,V21) || BRepTools::Compare(V12,V22)) {
218 // the edges have common vertex
219 isConnected12 = Standard_True;
222 // build wire in right order, corresponding to edges connexity
223 BRepBuilderAPI_MakeWire* MW;
225 MW = new BRepBuilderAPI_MakeWire(anEdge1, anEdge2, anEdge3, anEdge4);
227 MW = new BRepBuilderAPI_MakeWire(anEdge1, anEdge3, anEdge2, anEdge4);
230 Standard_ConstructionError::Raise
231 ("Impossible to build a connected wire from the given edges");
233 TopoDS_Wire aWire = *MW;
235 if (!aWire.Closed()) {
236 Standard_ConstructionError::Raise
237 ("Impossible to build a closed wire from the given edges");
240 // try to build face on the wire
241 GEOMImpl_Block6Explorer::MakeFace(aWire, Standard_False, aShape);
242 if (aShape.IsNull()) {
243 Standard_ConstructionError::Raise("Face construction failed");
246 } else if (aType == BLOCK_FACE_TWO_EDGES) {
248 // Make face from two opposite edges
249 if (anArgs(1).ShapeType() != TopAbs_EDGE ||
250 anArgs(2).ShapeType() != TopAbs_EDGE) {
251 Standard_TypeMismatch::Raise("Shape for face construction is not an edge");
254 TopoDS_Edge anEdge1 = TopoDS::Edge(anArgs(1));
255 TopoDS_Edge anEdge2 = TopoDS::Edge(anArgs(2));
257 if (anEdge1.IsSame(anEdge2)) {
258 Standard_ConstructionError::Raise("The edges must be different");
261 // create two edges, linking ends of the given edges
262 TopoDS_Vertex V11, V12, V21, V22;
263 TopExp::Vertices(anEdge1, V11, V12, Standard_True);
264 TopExp::Vertices(anEdge2, V21, V22, Standard_True);
265 if (V11.IsNull() || V12.IsNull() ||
266 V21.IsNull() || V22.IsNull()) {
267 Standard_NullObject::Raise("Bad edge for face construction: vertex is not defined");
269 gp_Pnt P11 = BRep_Tool::Pnt(V11);
270 gp_Pnt P12 = BRep_Tool::Pnt(V12);
271 gp_Pnt P21 = BRep_Tool::Pnt(V21);
272 gp_Pnt P22 = BRep_Tool::Pnt(V22);
274 if (P11.Distance(P21) < prec || P12.Distance(P22) < prec ||
275 P11.Distance(P22) < prec || P12.Distance(P21) < prec) {
276 Standard_ConstructionError::Raise("Given edges have too close ends");
279 Standard_Real per11 = P11.Distance(P21) + P12.Distance(P22);
280 Standard_Real per12 = P11.Distance(P22) + P12.Distance(P21);
285 anEdge3 = BRepBuilderAPI_MakeEdge(V11, V21);
286 anEdge4 = BRepBuilderAPI_MakeEdge(V12, V22);
288 anEdge3 = BRepBuilderAPI_MakeEdge(V11, V22);
289 anEdge4 = BRepBuilderAPI_MakeEdge(V12, V21);
293 BRepBuilderAPI_MakeWire MW (anEdge1, anEdge3, anEdge2, anEdge4);
295 Standard_ConstructionError::Raise("Wire construction failed");
298 // try to build face on the wire
299 GEOMImpl_Block6Explorer::MakeFace(MW, Standard_False, aShape);
300 if (aShape.IsNull()) {
301 Standard_ConstructionError::Raise("Face construction failed");
304 } else if (aType == BLOCK_FACE_FOUR_PNT) {
306 // Make face from four corner vertices
307 if (anArgs(1).ShapeType() != TopAbs_VERTEX ||
308 anArgs(2).ShapeType() != TopAbs_VERTEX ||
309 anArgs(3).ShapeType() != TopAbs_VERTEX ||
310 anArgs(4).ShapeType() != TopAbs_VERTEX) {
311 Standard_TypeMismatch::Raise("Shape for face construction is not a vertex");
314 TopoDS_Vertex V1 = TopoDS::Vertex(anArgs(1));
315 TopoDS_Vertex V2 = TopoDS::Vertex(anArgs(2));
316 TopoDS_Vertex V3 = TopoDS::Vertex(anArgs(3));
317 TopoDS_Vertex V4 = TopoDS::Vertex(anArgs(4));
319 gp_Pnt P1 = BRep_Tool::Pnt(V1);
320 gp_Pnt P2 = BRep_Tool::Pnt(V2);
321 gp_Pnt P3 = BRep_Tool::Pnt(V3);
322 gp_Pnt P4 = BRep_Tool::Pnt(V4);
324 if (P1.Distance(P2) < prec || P1.Distance(P3) < prec ||
325 P1.Distance(P4) < prec || P2.Distance(P3) < prec ||
326 P2.Distance(P4) < prec || P3.Distance(P4) < prec) {
327 Standard_ConstructionError::Raise("Four not coincident points must be given");
330 // calculate perimeters
331 Standard_Real per1234 = P1.Distance(P2) + P2.Distance(P3) +
332 P3.Distance(P4) + P4.Distance(P1);
333 Standard_Real per1243 = P1.Distance(P2) + P2.Distance(P4) +
334 P4.Distance(P3) + P3.Distance(P1);
335 Standard_Real per1324 = P1.Distance(P3) + P3.Distance(P2) +
336 P2.Distance(P4) + P4.Distance(P1);
339 if (per1243 < per1234 && per1243 < per1324) {
340 TopoDS_Vertex Vtmp = V3;
343 } else if (per1324 < per1234 && per1324 < per1243) {
344 TopoDS_Vertex Vtmp = V3;
351 BRepBuilderAPI_MakePolygon aMkPoly (V1, V2, V3, V4, Standard_True);
352 if (!aMkPoly.IsDone()) {
353 Standard_ConstructionError::Raise("Polygon construction failed");
356 // try to build face on the wire
357 GEOMImpl_Block6Explorer::MakeFace(aMkPoly, Standard_False, aShape);
358 if (aShape.IsNull()) {
359 Standard_ConstructionError::Raise("Face construction failed");
362 } else if (aType == BLOCK_SIX_FACES || aType == BLOCK_TWO_FACES) {
364 BRepTools_Quilt Glue;
366 if (aType == BLOCK_SIX_FACES) {
368 // Make block (hexahedral solid) from six faces
369 for (Standard_Integer ind = 1; ind <= nbshapes; ind++) {
370 if (anArgs(ind).ShapeType() != TopAbs_FACE) {
371 Standard_TypeMismatch::Raise("Shape for block construction is not a face");
373 Glue.Add(anArgs(ind));
378 // Make block (hexahedral solid) from two opposite faces
379 if (anArgs(1).ShapeType() != TopAbs_FACE ||
380 anArgs(2).ShapeType() != TopAbs_FACE) {
381 Standard_TypeMismatch::Raise("Shape for block construction is not a face");
384 // Get wires of the given faces
385 TopExp_Explorer wires1 (anArgs(1), TopAbs_WIRE);
386 TopExp_Explorer wires2 (anArgs(2), TopAbs_WIRE);
387 if (!wires1.More() || !wires2.More()) {
388 Standard_ConstructionError::Raise("A face for the block has no wires");
390 TopoDS_Shape aWire1 = wires1.Current();
391 TopoDS_Shape aWire2 = wires2.Current();
394 if (wires1.More() || wires2.More()) {
395 Standard_ConstructionError::Raise("A face for the block has more than one wire");
398 GEOMImpl_Block6Explorer aBlockTool;
399 aBlockTool.InitByTwoFaces(anArgs(1), anArgs(2));
401 // Construct the linking faces and add them in the gluing tool
403 Glue.Add(aBlockTool.GetFace(3, Standard_True));
404 Glue.Add(aBlockTool.GetFace(4, Standard_True));
405 Glue.Add(aBlockTool.GetFace(5, Standard_True));
406 Glue.Add(aBlockTool.GetFace(6, Standard_True));
410 TopExp_Explorer exp (Glue.Shells(), TopAbs_SHELL);
411 Standard_Integer ish = 0;
412 TopTools_MapOfShape mapShape;
413 for (; exp.More(); exp.Next()) {
414 if (mapShape.Add(exp.Current())) {
415 aShape = exp.Current();
421 aShape = Glue.Shells();
422 Standard_Real aTol = prec; // Precision::Confusion()
423 TopExp_Explorer expF (aShape, TopAbs_FACE);
424 TopTools_MapOfShape mapF;
427 for (; expF.More(); expF.Next()) {
428 if (mapF.Add(expF.Current())) {
429 B.Add(Shell, expF.Current());
430 Standard_Real aToler = BRep_Tool::Tolerance(TopoDS::Face(expF.Current()));
435 ShHealOper_Sewing aHealer (Shell, aTol);
436 if (aHealer.Perform())
437 aShape = aHealer.GetResultShape();
439 Standard_ConstructionError::Raise
440 ("Impossible to build a connected shell on the given faces");
443 if (aType == BLOCK_SIX_FACES) {
444 if (!aShape.Closed()) {
445 Standard_ConstructionError::Raise
446 ("Impossible to build a closed shell on the given faces");
453 BRepClass3d_SolidClassifier SC (Sol);
454 SC.PerformInfinitePoint(prec);
455 if (SC.State() == TopAbs_IN) {
457 B.Add(Sol, aShape.Reversed());
460 BRepLib::SameParameter(aShape, 1.E-5, Standard_True);
462 } else if (aType == BLOCK_COMPOUND_GLUE) {
464 // Make blocks compound from a compound
465 if (anArgs(1).ShapeType() != TopAbs_COMPOUND &&
466 anArgs(2).ShapeType() != TopAbs_COMPSOLID) {
467 Standard_TypeMismatch::Raise("Not a compound given");
470 TopoDS_Shape aCompound = anArgs(1);
472 // Glue coincident faces and edges (with Partition algorithm).
473 NMTAlgo_Splitter1 PS;
474 PS.AddShape(aCompound);
476 PS.SetRemoveWebs(Standard_False);
477 // PS.Build(aCompound.ShapeType());
478 PS.Build(TopAbs_SOLID);
484 } else { // Multi-transformations and compound improving
486 if (aType == BLOCK_REMOVE_EXTRA ||
487 aType == BLOCK_COMPOUND_IMPROVE) {
489 GEOMImpl_IBlockTrsf aCI (aFunction);
490 Handle(GEOM_Function) aRefShape = aCI.GetOriginal();
491 TopoDS_Shape aBlockOrComp = aRefShape->GetValue();
492 if (aBlockOrComp.IsNull()) {
493 Standard_NullObject::Raise("Null Shape given");
496 // 1. Improve solids with seam and/or degenerated edges
497 BlockFix_BlockFixAPI aTool;
498 //aTool.Tolerance() = toler;
499 aTool.SetShape(aBlockOrComp);
502 if (aType == BLOCK_REMOVE_EXTRA) {
504 aShape = aTool.Shape();
505 if (aShape == aBlockOrComp) {
506 MESSAGE("No modifications have been done");
509 } else { // aType == BLOCK_COMPOUND_IMPROVE
511 TopoDS_Shape aFixedExtra = aTool.Shape();
513 // 2. Separate non-blocks
514 TopTools_ListOfShape BLO; // All blocks from the given compound
515 TopTools_ListOfShape NOT; // Not blocks
516 TopTools_ListOfShape EXT; // Hexahedral solids, having degenerated and/or seam edges
517 GEOMImpl_IBlocksOperations::AddBlocksFrom(aFixedExtra, BLO, NOT, EXT);
519 if (NOT.Extent() > 0) {
520 MESSAGE("Some non-blocks have been removed");
523 // 3. Warn about staying extra-edges
524 if (EXT.Extent() > 0) {
525 MESSAGE("Warning: Not all seam or degenerated edges was removed");
528 // ??? Throw away standalone blocks ???
530 // 4. Create compound of all blocks
531 TopoDS_Compound aComp;
533 BB.MakeCompound(aComp);
534 TopTools_ListIteratorOfListOfShape BLOit (BLO);
535 for (; BLOit.More(); BLOit.Next()) {
536 BB.Add(aComp, BLOit.Value());
540 aShape = GEOMImpl_GlueDriver::GlueFaces(aComp, Precision::Confusion());
543 } else if (aType == BLOCK_MULTI_TRANSFORM_1D ||
544 aType == BLOCK_MULTI_TRANSFORM_2D) {
547 GEOMImpl_IBlockTrsf aCI (aFunction);
548 Handle(GEOM_Function) aRefShape = aCI.GetOriginal();
549 TopoDS_Shape aBlockIni = aRefShape->GetValue();
550 if (aBlockIni.IsNull()) {
551 Standard_NullObject::Raise("Null Block");
554 // Copy block to avoid problems (PAL6706)
555 TColStd_IndexedDataMapOfTransientTransient aMap;
557 TNaming_CopyShape::CopyTool(aBlockIni, aMap, aBlock);
559 // Block tolerance in vertices
560 Standard_Real aTol = prec;
561 TopExp_Explorer expV (aBlock, TopAbs_VERTEX);
562 TopTools_MapOfShape mapShape;
563 for (; expV.More(); expV.Next()) {
564 if (mapShape.Add(expV.Current())) {
565 TopoDS_Vertex aV = TopoDS::Vertex(expV.Current());
566 aTol = Max(BRep_Tool::Tolerance(aV), aTol);
570 if (aType == BLOCK_MULTI_TRANSFORM_1D) {
571 // Retrieve a faces by Ids
572 Standard_Integer aFace1Id = aCI.GetFace1U();
573 Standard_Integer aFace2Id = aCI.GetFace2U();
574 TopoDS_Shape aFace1, aFace2;
575 if (!GEOMImpl_ILocalOperations::GetSubShape(aBlock, aFace1Id, aFace1)) {
576 Standard_NullObject::Raise("Can not retrieve a sub-shape with given Id");
578 if (aFace1.ShapeType() != TopAbs_FACE) {
579 Standard_TypeMismatch::Raise("Sub-shape with given Id is not a face");
583 if (!GEOMImpl_ILocalOperations::GetSubShape(aBlock, aFace2Id, aFace2)) {
584 Standard_NullObject::Raise("Can not retrieve a sub-shape with given Id");
586 if (aFace2.ShapeType() != TopAbs_FACE) {
587 Standard_TypeMismatch::Raise("Sub-shape with given Id is not a face");
591 Standard_Integer aNbIter = aCI.GetNbIterU();
593 MultiTransformate1D(aBlock, aFace1, aFace2, aNbIter, aMulti);
595 } else { // aType == BLOCK_MULTI_TRANSFORM_2D
596 // Retrieve a faces by Ids
597 Standard_Integer aFace1UId = aCI.GetFace1U();
598 Standard_Integer aFace2UId = aCI.GetFace2U();
599 Standard_Integer aFace1VId = aCI.GetFace1V();
600 Standard_Integer aFace2VId = aCI.GetFace2V();
602 TopoDS_Shape aFace1U, aFace2U, aFace1V, aFace2V;
603 if (!GEOMImpl_ILocalOperations::GetSubShape(aBlock, aFace1UId, aFace1U) ||
604 !GEOMImpl_ILocalOperations::GetSubShape(aBlock, aFace1VId, aFace1V)) {
605 Standard_NullObject::Raise("Can not retrieve a sub-shape with given Id");
608 if (aFace1U.ShapeType() != TopAbs_FACE ||
609 aFace1V.ShapeType() != TopAbs_FACE) {
610 Standard_TypeMismatch::Raise("Sub-shape with given Id is not a face");
614 if (!GEOMImpl_ILocalOperations::GetSubShape(aBlock, aFace2UId, aFace2U)) {
615 Standard_NullObject::Raise("Can not retrieve a sub-shape with given Id");
618 if (aFace2U.ShapeType() != TopAbs_FACE) {
619 Standard_TypeMismatch::Raise("Sub-shape with given Id is not a face");
624 if (!GEOMImpl_ILocalOperations::GetSubShape(aBlock, aFace2VId, aFace2V)) {
625 Standard_NullObject::Raise("Can not retrieve a sub-shape with given Id");
628 if (aFace2V.ShapeType() != TopAbs_FACE) {
629 Standard_TypeMismatch::Raise("Sub-shape with given Id is not a face");
633 Standard_Integer aNbIterU = aCI.GetNbIterU();
634 Standard_Integer aNbIterV = aCI.GetNbIterV();
636 MultiTransformate2D(aBlock,
637 aFace1U, aFace2U, aNbIterU,
638 aFace1V, aFace2V, aNbIterV, aMulti);
641 if (aMulti.IsNull()) {
642 StdFail_NotDone::Raise("Multi-transformation failed");
645 // Glue faces of the multi-block
646 aShape = GEOMImpl_GlueDriver::GlueFaces(aMulti, aTol);
648 } else { // unknown function type
653 if (aShape.IsNull()) return 0;
655 aFunction->SetValue(aShape);
657 log.SetTouched(Label());
662 //=======================================================================
663 //function : MultiTransformate1D
665 //=======================================================================
666 void GEOMImpl_BlockDriver::MultiTransformate1D (const TopoDS_Shape& theBlock,
667 const TopoDS_Shape& theFace1,
668 const TopoDS_Shape& theFace2,
669 const Standard_Integer theNbIter,
670 TopoDS_Shape& theResult) const
672 // Construct Tool, where <theFace1> will be the first face,
673 // and a face, opposite to <theFace1>, will be the second face
674 GEOMImpl_Block6Explorer aBlockTool;
675 aBlockTool.InitByBlockAndFace(theBlock, theFace1);
677 // Find IDs of the faces
678 Standard_Integer dir_face1 = 1, dir_face2 = 2;
679 if (!theFace2.IsNull()) {
680 dir_face2 = aBlockTool.GetFaceID(theFace2);
683 // Find three pairs of points
684 Standard_Integer v11_id = 0, v12_id = 0, v13_id = 0; // vertices of the first face
685 Standard_Integer v21_id = 0, v22_id = 0, v23_id = 0; // vertices of the second face
687 if (dir_face2 == 2) { // <theFace2> is opposite to <theFace1>
689 // We will take vertices with equal local numbers on the faces,
690 // as the Block6Explorer gives equal local numbers
691 // to the linked vertices on the opposite faces,
692 // i.e. v1* is linked with the v2* by an edge:
696 // / | / | dir_face1 - bottom
698 // /________ / | dir_face2 - top
707 v11_id = aBlockTool.GetVertexID(dir_face1, 1);
708 v12_id = aBlockTool.GetVertexID(dir_face1, 2);
709 v13_id = aBlockTool.GetVertexID(dir_face1, 4);
711 v21_id = aBlockTool.GetVertexID(dir_face2, 1);
712 v22_id = aBlockTool.GetVertexID(dir_face2, 2);
713 v23_id = aBlockTool.GetVertexID(dir_face2, 4);
719 // / | / | dir_face1 - bottom
721 // /________ / | dir_face2 - right (for example)
724 // | / | /v12 = v22 (common_vertex2)
728 // v13 v11 = v21 (common_vertex1)
730 Standard_Integer common_edge_id = aBlockTool.FindCommonEdgeID(dir_face1, dir_face2);
731 Standard_Integer common_vertex1 = aBlockTool.GetVertexOnEdgeID(common_edge_id, 1);
732 Standard_Integer common_vertex2 = aBlockTool.GetVertexOnEdgeID(common_edge_id, 2);
734 Standard_Integer not_common_v1 = 0;
735 Standard_Integer vid = 1;
736 Standard_Boolean isFound = Standard_False;
737 while (!isFound && vid <= 4) {
738 not_common_v1 = aBlockTool.GetVertexID(dir_face1, vid);
739 isFound = (not_common_v1 != common_vertex2 &&
740 aBlockTool.FindEdgeID(not_common_v1, common_vertex1) != 0);
744 Standard_Integer not_common_v2 = 0;
746 isFound = Standard_False;
747 while (!isFound && vid <= 4) {
748 not_common_v2 = aBlockTool.GetVertexID(dir_face2, vid);
749 isFound = (not_common_v2 != common_vertex2 &&
750 aBlockTool.FindEdgeID(not_common_v2, common_vertex1) != 0);
754 v11_id = common_vertex1;
755 v12_id = common_vertex2;
756 v13_id = not_common_v1;
758 v21_id = common_vertex1;
759 v22_id = common_vertex2;
760 v23_id = not_common_v2;
763 // Construct a transformation operator
764 TopoDS_Vertex V11 = TopoDS::Vertex(aBlockTool.GetVertex(v11_id));
765 TopoDS_Vertex V12 = TopoDS::Vertex(aBlockTool.GetVertex(v12_id));
766 TopoDS_Vertex V13 = TopoDS::Vertex(aBlockTool.GetVertex(v13_id));
768 TopoDS_Vertex V21 = TopoDS::Vertex(aBlockTool.GetVertex(v21_id));
769 TopoDS_Vertex V22 = TopoDS::Vertex(aBlockTool.GetVertex(v22_id));
770 TopoDS_Vertex V23 = TopoDS::Vertex(aBlockTool.GetVertex(v23_id));
772 // Axes of the first direction face
773 gp_Pnt P1 = BRep_Tool::Pnt(V11);
774 gp_Vec VecN1 (P1, BRep_Tool::Pnt(V12));
775 gp_Vec VecX1 (P1, BRep_Tool::Pnt(V13));
776 gp_Ax3 Ax1 (P1, VecN1, VecX1);
778 // Axes of the second direction face
779 gp_Pnt P2 = BRep_Tool::Pnt(V21);
780 gp_Vec VecN2 (P2, BRep_Tool::Pnt(V22));
781 gp_Vec VecX2 (P2, BRep_Tool::Pnt(V23));
782 gp_Ax3 Ax2 (P2, VecN2, VecX2);
785 aTrsf.SetDisplacement(Ax1, Ax2);
787 // Check, that <theFace2> is similar to <theFace1>.
788 // Actually, we need only to check right position of one
789 // vertex, not involved into the transformation construction.
790 if (!aBlockTool.IsSimilarFaces(dir_face1, dir_face2, aTrsf)) {
791 Standard_ConstructionError::Raise("The direction faces are not similar");
794 // Perform multi-transformation
795 TopoDS_Compound aCompound;
797 B.MakeCompound(aCompound);
799 TopoDS_Shape aPrevShape = theBlock;
800 for (Standard_Integer i = 0; i < theNbIter; i++) {
801 B.Add(aCompound, aPrevShape);
802 BRepBuilderAPI_Transform aTransformation (aPrevShape, aTrsf, Standard_False);
803 aPrevShape = aTransformation.Shape();
805 theResult = aCompound;
808 //=======================================================================
809 //function : MultiTransformate2D
811 //=======================================================================
812 void GEOMImpl_BlockDriver::MultiTransformate2D (const TopoDS_Shape& theBlock,
813 const TopoDS_Shape& theFace1U,
814 const TopoDS_Shape& theFace2U,
815 const Standard_Integer theNbIterU,
816 const TopoDS_Shape& theFace1V,
817 const TopoDS_Shape& theFace2V,
818 const Standard_Integer theNbIterV,
819 TopoDS_Shape& theResult) const
821 // Construct Tool, where <theFace1U> will be the first face,
822 // and a face, opposite to <theFace1U>, will be the second face
823 GEOMImpl_Block6Explorer aBlockTool;
824 aBlockTool.InitByBlockAndFace(theBlock, theFace1U);
826 gp_Trsf aTrsfU, aTrsfV;
828 for (Standard_Integer uv = 1; uv <= 2; uv++) {
830 TopoDS_Shape theFace1 = theFace1U;
831 TopoDS_Shape theFace2 = theFace2U;
834 theFace1 = theFace1V;
835 theFace2 = theFace2V;
838 // Find IDs of the faces
839 Standard_Integer dir_face1 = aBlockTool.GetFaceID(theFace1);
840 Standard_Integer dir_face2 = 0;
841 Standard_Integer opp_face1 = aBlockTool.GetOppositeFaceID(dir_face1);
842 if (theFace2.IsNull()) {
843 dir_face2 = opp_face1;
845 dir_face2 = aBlockTool.GetFaceID(theFace2);
848 // Find three pairs of points
849 Standard_Integer v11_id = 0, v12_id = 0, v13_id = 0; // vertices of the first face
850 Standard_Integer v21_id = 0, v22_id = 0, v23_id = 0; // vertices of the second face
852 if (dir_face2 == opp_face1) { // <theFace2> is opposite to <theFace1>
854 // We will take vertices with equal local numbers on the faces,
855 // as the Block6Explorer gives equal local numbers
856 // to the linked vertices on the opposite faces,
857 // i.e. v1* is linked with the v2* by an edge:
859 v11_id = aBlockTool.GetVertexID(dir_face1, 1);
860 v12_id = aBlockTool.GetVertexID(dir_face1, 2);
861 v13_id = aBlockTool.GetVertexID(dir_face1, 4);
863 v21_id = aBlockTool.GetVertexID(dir_face2, 1);
864 v22_id = aBlockTool.GetVertexID(dir_face2, 2);
865 v23_id = aBlockTool.GetVertexID(dir_face2, 4);
869 Standard_Integer common_edge_id = aBlockTool.FindCommonEdgeID(dir_face1, dir_face2);
870 Standard_Integer common_vertex1 = aBlockTool.GetVertexOnEdgeID(common_edge_id, 1);
871 Standard_Integer common_vertex2 = aBlockTool.GetVertexOnEdgeID(common_edge_id, 2);
873 Standard_Integer not_common_v1 = 0;
874 Standard_Integer vid = 1;
875 Standard_Boolean isFound = Standard_False;
876 while (!isFound && vid <= 4) {
877 not_common_v1 = aBlockTool.GetVertexID(dir_face1, vid);
878 isFound = (not_common_v1 != common_vertex2 &&
879 aBlockTool.FindEdgeID(not_common_v1, common_vertex1) != 0);
883 Standard_Integer not_common_v2 = 0;
885 isFound = Standard_False;
886 while (!isFound && vid <= 4) {
887 not_common_v2 = aBlockTool.GetVertexID(dir_face2, vid);
888 isFound = (not_common_v2 != common_vertex2 &&
889 aBlockTool.FindEdgeID(not_common_v2, common_vertex1) != 0);
893 v11_id = common_vertex1;
894 v12_id = common_vertex2;
895 v13_id = not_common_v1;
897 v21_id = common_vertex1;
898 v22_id = common_vertex2;
899 v23_id = not_common_v2;
902 // Construct a transformation operator
903 TopoDS_Vertex V11 = TopoDS::Vertex(aBlockTool.GetVertex(v11_id));
904 TopoDS_Vertex V12 = TopoDS::Vertex(aBlockTool.GetVertex(v12_id));
905 TopoDS_Vertex V13 = TopoDS::Vertex(aBlockTool.GetVertex(v13_id));
907 TopoDS_Vertex V21 = TopoDS::Vertex(aBlockTool.GetVertex(v21_id));
908 TopoDS_Vertex V22 = TopoDS::Vertex(aBlockTool.GetVertex(v22_id));
909 TopoDS_Vertex V23 = TopoDS::Vertex(aBlockTool.GetVertex(v23_id));
911 // Axes of the first direction face
912 gp_Pnt P1 = BRep_Tool::Pnt(V11);
913 gp_Vec VecN1 (P1, BRep_Tool::Pnt(V12));
914 gp_Vec VecX1 (P1, BRep_Tool::Pnt(V13));
915 gp_Ax3 Ax1 (P1, VecN1, VecX1);
917 // Axes of the second direction face
918 gp_Pnt P2 = BRep_Tool::Pnt(V21);
919 gp_Vec VecN2 (P2, BRep_Tool::Pnt(V22));
920 gp_Vec VecX2 (P2, BRep_Tool::Pnt(V23));
921 gp_Ax3 Ax2 (P2, VecN2, VecX2);
924 aTrsf.SetDisplacement(Ax1, Ax2);
933 // Check, that <theFace2> is similar to <theFace1>.
934 // Actually, we need only to check right position of one
935 // vertex, not involved into the transformation construction.
936 if (!aBlockTool.IsSimilarFaces(dir_face1, dir_face2, aTrsf)) {
937 Standard_ConstructionError::Raise("The direction faces are not similar");
941 // Perform multi-transformation
942 TopoDS_Compound aCompound;
944 B.MakeCompound(aCompound);
946 TopoDS_Shape aPrevShapeU = theBlock;
947 for (int i = 0; i < theNbIterU; i++) {
948 TopoDS_Shape aPrevShapeV = aPrevShapeU;
949 for (int j = 0; j < theNbIterV; j++) {
950 B.Add(aCompound, aPrevShapeV);
951 BRepBuilderAPI_Transform aTransformationV (aPrevShapeV, aTrsfV, Standard_False);
952 aPrevShapeV = aTransformationV.Shape();
954 BRepBuilderAPI_Transform aTransformationU (aPrevShapeU, aTrsfU, Standard_False);
955 aPrevShapeU = aTransformationU.Shape();
956 // Correction of the second transformation according to the first transformation
957 Ax1V.Transform(aTrsfU);
958 Ax2V.Transform(aTrsfU);
959 aTrsfV.SetDisplacement(Ax1V, Ax2V);
962 theResult = aCompound;
965 //=======================================================================
966 //function : GEOMImpl_BlockDriver_Type_
968 //=======================================================================
969 Standard_EXPORT Handle_Standard_Type& GEOMImpl_BlockDriver_Type_()
972 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
973 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
974 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
975 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
976 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
977 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
980 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
981 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_BlockDriver",
982 sizeof(GEOMImpl_BlockDriver),
984 (Standard_Address)_Ancestors,
985 (Standard_Address)NULL);
990 //=======================================================================
991 //function : DownCast
993 //=======================================================================
994 const Handle(GEOMImpl_BlockDriver) Handle(GEOMImpl_BlockDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
996 Handle(GEOMImpl_BlockDriver) _anOtherObject;
998 if (!AnObject.IsNull()) {
999 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_BlockDriver))) {
1000 _anOtherObject = Handle(GEOMImpl_BlockDriver)((Handle(GEOMImpl_BlockDriver)&)AnObject);
1004 return _anOtherObject ;