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
20 // File: NMTTools_Tools.cxx
21 // Created: Mon Dec 8 10:35:15 2003
22 // Author: Peter KURNEV
26 #include <NMTTools_Tools.ixx>
28 #include <TColStd_IndexedMapOfInteger.hxx>
32 #include <gp_Pnt2d.hxx>
34 #include <Geom_Surface.hxx>
35 #include <GeomAPI_ProjectPointOnSurf.hxx>
38 #include <TopoDS_Vertex.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Edge.hxx>
44 #include <TopTools_ListIteratorOfListOfShape.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
47 #include <BRep_Tool.hxx>
48 #include <BRep_Builder.hxx>
49 #include <BRepTools.hxx>
51 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
52 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
54 #include <BOPTools_VVInterference.hxx>
55 #include <BOPTools_SSInterference.hxx>
57 #include <BOPTools_Tools2D.hxx>
58 #include <BOPTools_Tools.hxx>
59 #include <NMTTools_ListIteratorOfListOfCoupleOfShape.hxx>
60 #include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
61 #include <NMTTools_CoupleOfShape.hxx>
62 #include <TopTools_IndexedMapOfShape.hxx>
63 #include <Geom2d_Curve.hxx>
64 #include <Geom_Curve.hxx>
65 #include <Geom_TrimmedCurve.hxx>
66 #include <BOPTools_Tools2D.hxx>
67 #include <BRepLib.hxx>
68 #include <BOPTools_Tools3D.hxx>
69 #include <TopExp_Explorer.hxx>
71 #include <TopTools_MapOfShape.hxx>
72 #include <TopTools_MapIteratorOfMapOfShape.hxx>
73 #include <TopoDS_Iterator.hxx>
76 void ProcessBlock(const Standard_Integer iV,
77 const BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMCV,
78 TColStd_IndexedMapOfInteger& aProcessed,
79 TColStd_IndexedMapOfInteger& aChain);
81 void ProcessBlock(const TopoDS_Shape& aF,
82 const NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMCV,
83 TopTools_IndexedMapOfShape& aProcessed,
84 TopTools_IndexedMapOfShape& aChain);
86 //modified by NIZNHY-PKV Thu Nov 16 10:46:53 2006f SKL/PartC5
87 //=======================================================================
88 // function: UpdateEdge
90 //=======================================================================
91 void NMTTools_Tools::UpdateEdge(const TopoDS_Edge& aE,
92 const Standard_Real aTolR)
94 Standard_Real aTolE, aTolES, aTolV;
98 aTolE=BRep_Tool::Tolerance(aE);
99 aTolES=Max(aTolR, aTolE);
100 aBB.UpdateEdge(aE, aTolES);
103 for (; aIt.More(); aIt.Next()) {
104 const TopoDS_Vertex& aV=TopoDS::Vertex(aIt.Value());
105 aTolV=BRep_Tool::Tolerance(aV);
107 aBB.UpdateVertex(aV, aTolES);
111 //=======================================================================
112 // function: MakePCurve
114 //=======================================================================
115 void NMTTools_Tools::MakePCurve(const TopoDS_Edge& aE,
116 const TopoDS_Face& aF,
117 const Handle(Geom2d_Curve)& aC2Dx1)
120 Standard_Real aTolE, aT1, aT2, aOutFirst, aOutLast, aOutTol;
121 Handle(Geom2d_Curve) aC2D, aC2DA;
126 aFFWD.Orientation(TopAbs_FORWARD);
128 aTolE=BRep_Tool::Tolerance(aE);
130 const Handle(Geom_Curve)& aC3DE=BRep_Tool::Curve(aE, aT1, aT2);
131 Handle(Geom_TrimmedCurve)aC3DETrim=new Geom_TrimmedCurve(aC3DE, aT1, aT2);
134 if (aC2D.IsNull()) { // ?
135 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aFFWD);
136 BOPTools_Tools2D::CurveOnSurface(aE, aFFWD, aC2D, aOutFirst, aOutLast, aOutTol, Standard_True);
139 if (aC3DE->IsPeriodic()) {
140 BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aT1, aT2, aC2D, aC2DA);
143 BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aC3DETrim, aC2D, aC2DA);
146 aBB.UpdateEdge(aE, aC2DA, aFFWD, aTolE);
147 BRepLib::SameParameter(aE);
150 //=======================================================================
151 // function: MakePCurve
153 //=======================================================================
154 void NMTTools_Tools::MakePCurve(const TopoDS_Edge& aE,
155 const TopoDS_Face& aF,
156 const Handle(Geom2d_Curve)& aC2Dx,
157 const Standard_Real aTolR2D)
159 Standard_Integer k, aNbV;
160 Standard_Real aTolEdge, aTolFact, aTolV, aTolVmax;
161 Standard_Real aTFirst, aTLast, aOutFirst, aOutLast, aOutTol;
163 TopTools_IndexedMapOfShape aVMap;
167 aFFWD.Orientation(TopAbs_FORWARD);
169 aTolEdge=BRep_Tool::Tolerance(aE);
170 aTolFact=Max(aTolEdge, aTolR2D);
172 TopExp::MapShapes(aE, TopAbs_VERTEX, aVMap);
176 for (k=1; k<=aNbV; ++k) {
177 const TopoDS_Vertex& aV=TopoDS::Vertex(aVMap(k));
178 aTolV=BRep_Tool::Tolerance(aV);
179 if (aTolV>aTolVmax) {
184 if (aTolFact>aTolVmax) {
188 const Handle(Geom_Curve)& aC3DE=BRep_Tool::Curve(aE, aTFirst, aTLast);
189 Handle(Geom_TrimmedCurve)aC3DETrim=new Geom_TrimmedCurve(aC3DE, aTFirst, aTLast);
191 Handle(Geom2d_Curve) aC2D, aC2DA;
195 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aFFWD);
196 BOPTools_Tools2D::CurveOnSurface(aE, aFFWD, aC2D, aOutFirst, aOutLast, aOutTol, Standard_True);
198 if (aC3DE->IsPeriodic()) {
199 BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aTFirst, aTLast, aC2D, aC2DA);
202 BOPTools_Tools2D::AdjustPCurveOnFace(aFFWD, aC3DETrim, aC2D, aC2DA);
205 aBB.UpdateEdge(aE, aC2DA, aFFWD, aTolFact);
206 BRepLib::SameParameter(aE);
209 //modified by NIZNHY-PKV Thu Nov 16 10:46:55 2006t
210 //=======================================================================
211 // function: IsSplitInOnFace
213 //=======================================================================
214 Standard_Boolean NMTTools_Tools::IsSplitInOnFace(const TopoDS_Edge& aE,
215 const TopoDS_Face& aF,
216 IntTools_Context& aContext)
218 Standard_Boolean bFlag;
219 Standard_Real aT, aTolE, aTolF, aTol, aDist, aU, aV;
223 aTolE=BRep_Tool::Tolerance(aE);
224 aTolF=BRep_Tool::Tolerance(aF);
227 GeomAPI_ProjectPointOnSurf& aProjector=aContext.ProjPS(aF);
229 aT=BOPTools_Tools2D::IntermediatePoint(aE);
230 BOPTools_Tools::PointOnEdge(aE, aT, aP);
232 aProjector.Perform(aP);
233 bFlag=aProjector.IsDone();
238 aDist=aProjector.LowerDistance();
239 bFlag=(aDist <= aTol);
244 aProjector.LowerDistanceParameters(aU, aV);
245 aP2D.SetCoord(aU, aV);
246 bFlag=aContext.IsPointInOnFace (aF, aP2D);
249 //=======================================================================
250 // function: NMTTools_Tools::MakeNewVertex
252 //=======================================================================
253 void NMTTools_Tools::MakeNewVertex(const TopTools_ListOfShape& aLVs,
254 TopoDS_Vertex& aNewVertex)
256 Standard_Integer aNb;
257 Standard_Real aTi, aDi, aDmax=-1.e5;
259 gp_XYZ aXYZ(0.,0.,0.), aXYZi;
260 TopTools_ListIteratorOfListOfShape anIt;
267 anIt.Initialize(aLVs);
268 for (; anIt.More(); anIt.Next()) {
269 TopoDS_Vertex aVi=TopoDS::Vertex(anIt.Value());
270 aPi=BRep_Tool::Pnt(aVi);
275 aXYZ.Divide((Standard_Real)aNb);
278 anIt.Initialize(aLVs);
279 for (; anIt.More(); anIt.Next()) {
280 TopoDS_Vertex aVi=TopoDS::Vertex(anIt.Value());
281 aPi=BRep_Tool::Pnt(aVi);
282 aTi=BRep_Tool::Tolerance(aVi);
283 aDi=aP.Distance(aPi);
290 aBB.MakeVertex (aNewVertex, aP, aDmax);
292 //=======================================================================
293 // function: FindChains
295 //=======================================================================
296 void NMTTools_Tools::FindChains(const BOPTools_CArray1OfSSInterference& FFs,
297 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapChains)
299 Standard_Boolean bIsTangentFaces;
300 Standard_Integer j, aNb, anIndex1, anIndex2;
301 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMCV;
304 for (j=1; j<=aNb; ++j) {
305 const BOPTools_SSInterference& aFF=FFs(j);
307 bIsTangentFaces=aFF.IsTangentFaces();
308 if (!bIsTangentFaces) {
312 aFF.Indices(anIndex1, anIndex2);
314 if (aMCV.Contains(anIndex1)) {
315 TColStd_IndexedMapOfInteger& aMV=aMCV.ChangeFromKey(anIndex1);
320 TColStd_IndexedMapOfInteger aMV;
323 aMCV.Add(anIndex1, aMV);
326 if (aMCV.Contains(anIndex2)) {
327 TColStd_IndexedMapOfInteger& aMV=aMCV.ChangeFromKey(anIndex2);
332 TColStd_IndexedMapOfInteger aMV;
335 aMCV.Add(anIndex2, aMV);
338 NMTTools_Tools::FindChains(aMCV, aMapChains);
340 //=======================================================================
341 // function: FindChains
343 //=======================================================================
344 void NMTTools_Tools::FindChains(const BOPTools_CArray1OfVVInterference& VVs,
345 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapChains)
347 Standard_Integer j, aNb, anIndex1, anIndex2;
348 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMCV;
351 for (j=1; j<=aNb; ++j) {
352 const BOPTools_VVInterference& VV=VVs(j);
353 VV.Indices(anIndex1, anIndex2);
355 if (aMCV.Contains(anIndex1)) {
356 TColStd_IndexedMapOfInteger& aMV=aMCV.ChangeFromKey(anIndex1);
361 TColStd_IndexedMapOfInteger aMV;
364 aMCV.Add(anIndex1, aMV);
367 if (aMCV.Contains(anIndex2)) {
368 TColStd_IndexedMapOfInteger& aMV=aMCV.ChangeFromKey(anIndex2);
373 TColStd_IndexedMapOfInteger aMV;
376 aMCV.Add(anIndex2, aMV);
379 NMTTools_Tools::FindChains(aMCV, aMapChains);
382 //=======================================================================
383 // function: FindChains
385 //=======================================================================
386 void NMTTools_Tools::FindChains(const BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMCV,
387 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapChains)
389 Standard_Integer i, j, aNbCV, aNbV, iV, iVx;
390 TColStd_IndexedMapOfInteger aProcessed, aChain;
393 for (i=1; i<=aNbCV; ++i) {
395 if (aProcessed.Contains(iV)) {
402 const TColStd_IndexedMapOfInteger& aMV=aMCV(i);
404 for (j=1; j<=aNbV; ++j) {
406 ProcessBlock(iVx, aMCV, aProcessed, aChain);
408 aMapChains.Add(i, aChain);
412 //=======================================================================
413 // function: ProcessBlock
415 //=======================================================================
416 void ProcessBlock(const Standard_Integer iV,
417 const BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMCV,
418 TColStd_IndexedMapOfInteger& aProcessed,
419 TColStd_IndexedMapOfInteger& aChain)
421 Standard_Integer j, aNbV, iVx;
423 if (aProcessed.Contains(iV)) {
429 const TColStd_IndexedMapOfInteger& aMV=aMCV.FindFromKey(iV);
431 for (j=1; j<=aNbV; ++j) {
433 ProcessBlock(iVx, aMCV, aProcessed, aChain);
436 //=======================================================================
437 // function: AreFacesSameDomain
439 //=======================================================================
440 Standard_Boolean NMTTools_Tools::AreFacesSameDomain(const TopoDS_Face& aF1x,
441 const TopoDS_Face& aF2y,
442 IntTools_Context& aCtx)
444 Standard_Boolean bFlag;
445 // Modified Thu Sep 14 14:35:18 2006
446 // Contribution of Samtech www.samcef.com BEGIN
447 Standard_Integer aNbE1, aNbE2;
448 Standard_Real aTolF1, aTolF2, aTol;
451 TopoDS_Face aF1, aF2;
452 TopExp_Explorer aExp;
453 TopTools_MapOfShape aME1, aME2;
454 TopTools_MapIteratorOfMapOfShape aIt;
456 bFlag=Standard_False;
457 // Contribution of Samtech www.samcef.com END
460 aF1.Orientation(TopAbs_FORWARD);
462 aF2.Orientation(TopAbs_FORWARD);
464 // Modified Thu Sep 14 14:35:18 2006
465 // Contribution of Samtech www.samcef.com BEGIN
468 aExp.Init(aF1, TopAbs_EDGE);
469 for (; aExp.More(); aExp.Next()) {
470 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
471 if (!BRep_Tool::Degenerated(aE)) {
476 aExp.Init(aF2, TopAbs_EDGE);
477 for (; aExp.More(); aExp.Next()) {
478 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
479 if (!BRep_Tool::Degenerated(aE)) {
480 if (!aME1.Contains(aE)) {
487 // Contribution of Samtech www.samcef.com END
492 if(!aNbE1 || !aNbE2){
501 aTolF1=BRep_Tool::Tolerance(aF1);
502 aTolF2=BRep_Tool::Tolerance(aF2);
505 aIt.Initialize(aME1);
506 for (; aIt.More(); aIt.Next()) {
507 const TopoDS_Edge& aE=TopoDS::Edge(aIt.Key());
508 BOPTools_Tools3D::PointNearEdge(aE, aF1, aP2D, aP);
509 bFlag=aCtx.IsValidPointForFace(aP, aF2, aTol);
515 //=======================================================================
516 // function: FindChains
518 //=======================================================================
519 void NMTTools_Tools::FindChains(const NMTTools_ListOfCoupleOfShape& aLCS,
520 NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMapChains)
522 NMTTools_ListIteratorOfListOfCoupleOfShape aItCS;
523 NMTTools_IndexedDataMapOfShapeIndexedMapOfShape aMCV;
525 aItCS.Initialize(aLCS);
526 for (; aItCS.More(); aItCS.Next()) {
527 const NMTTools_CoupleOfShape& aCS=aItCS.Value();
529 const TopoDS_Shape& aF1=aCS.Shape1();
530 const TopoDS_Shape& aF2=aCS.Shape2();
533 if (aMCV.Contains(aF1)) {
534 TopTools_IndexedMapOfShape& aMV=aMCV.ChangeFromKey(aF1);
539 TopTools_IndexedMapOfShape aMV;
545 if (aMCV.Contains(aF2)) {
546 TopTools_IndexedMapOfShape& aMV=aMCV.ChangeFromKey(aF2);
551 TopTools_IndexedMapOfShape aMV;
557 NMTTools_Tools::FindChains(aMCV, aMapChains);
559 //=======================================================================
560 // function: FindChains
562 //=======================================================================
563 void NMTTools_Tools::FindChains(const NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMCV,
564 NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMapChains)
566 Standard_Integer i, j, aNbCV, aNbV;
567 TopTools_IndexedMapOfShape aProcessed, aChain;
570 for (i=1; i<=aNbCV; ++i) {
571 const TopoDS_Shape& aF=aMCV.FindKey(i);
572 if (aProcessed.Contains(aF)) {
579 const TopTools_IndexedMapOfShape& aMV=aMCV(i);
581 for (j=1; j<=aNbV; ++j) {
582 const TopoDS_Shape& aFx=aMV(j);
583 ProcessBlock(aFx, aMCV, aProcessed, aChain);
585 aMapChains.Add(aF, aChain);
589 //=======================================================================
590 // function: ProcessBlock
592 //=======================================================================
593 void ProcessBlock(const TopoDS_Shape& aF,
594 const NMTTools_IndexedDataMapOfShapeIndexedMapOfShape& aMCV,
595 TopTools_IndexedMapOfShape& aProcessed,
596 TopTools_IndexedMapOfShape& aChain)
598 Standard_Integer j, aNbV;
600 if (aProcessed.Contains(aF)) {
606 const TopTools_IndexedMapOfShape& aMV=aMCV.FindFromKey(aF);
608 for (j=1; j<=aNbV; ++j) {
609 const TopoDS_Shape& aFx=aMV(j);
610 ProcessBlock(aFx, aMCV, aProcessed, aChain);