Salome HOME
untabify
[modules/geom.git] / src / NMTTools / NMTTools_CheckerSI_1.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:        NMTTools_CheckerSI.cxx
23 // Created:     Mon Feb 19 11:32:08 2007
24 // Author:      Peter KURNEV
25 //
26 #include <NMTTools_CheckerSI.ixx>
27 #include <NMTDS_ShapesDataStructure.hxx>
28 #include <NMTDS_IteratorCheckerSI.hxx>
29
30 #include <NMTDS_InterfPool.hxx>
31 #include <TopoDS_Edge.hxx>
32 #include <TopoDS_Vertex.hxx>
33 #include <BOPTools_ListOfPaveBlock.hxx>
34 #include <TopoDS.hxx>
35 #include <BRep_Tool.hxx>
36 #include <BOPTools_PaveSet.hxx>
37 #include <BOPTools_PaveBlockIterator.hxx>
38 #include <BOPTools_PaveBlock.hxx>
39 #include <IntTools_Range.hxx>
40 #include <BOPTools_Pave.hxx>
41 #include <IntTools_ShrunkRange.hxx>
42 #include <BOPTColStd_Failure.hxx>
43 #include <BOPTColStd_Dump.hxx>
44 #include <Geom_Curve.hxx>
45 #include <gp_Pnt.hxx>
46
47
48
49 static
50   Standard_Boolean IsValid(const TopoDS_Edge& aE,
51                            const TopoDS_Vertex& aV,
52                            const Standard_Real aTV1,
53                            const Standard_Real aTV2);
54
55 //=======================================================================
56 // function: PreparePaveBlocks
57 // purpose: 
58 //=======================================================================
59   void NMTTools_CheckerSI::PreparePaveBlocks(const TopAbs_ShapeEnum aType1, 
60                                              const TopAbs_ShapeEnum aType2)
61 {
62   NMTTools_PaveFiller::PreparePaveBlocks(aType1, aType2);
63 }
64 //=======================================================================
65 // function: PreparePaveBlocks
66 // purpose: 
67 //=======================================================================
68   void NMTTools_CheckerSI::PreparePaveBlocks(const Standard_Integer nE)
69 {
70   myIsDone=Standard_False;
71   //
72   char buf[32]={"SR"};
73   Standard_Boolean bIsValid;
74   Standard_Integer nV1, nV2, iErr;
75   Standard_Real aT1, aT2;
76   TopoDS_Edge aE;
77   TopoDS_Vertex aV1, aV2;
78   //
79   BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool(myDS->RefEdge(nE));
80   // Edge 
81   aE=TopoDS::Edge(myDS->Shape(nE));
82   if (BRep_Tool::Degenerated(aE)) {
83     myIsDone=Standard_True;
84     return;
85   }
86   //
87   BOPTools_PaveSet& aPS=myPavePool(myDS->RefEdge(nE));
88   
89   BOPTools_PaveBlockIterator aPBIt(nE, aPS);
90   for (; aPBIt.More(); aPBIt.Next()) {
91     BOPTools_PaveBlock& aPB=aPBIt.Value();
92     const IntTools_Range& aRange=aPB.Range();
93     //
94     const BOPTools_Pave& aPave1=aPB.Pave1();
95     nV1=aPave1.Index();
96     aV1=TopoDS::Vertex(myDS->Shape(nV1));
97     aT1=aPave1.Param();
98     //
99     const BOPTools_Pave& aPave2=aPB.Pave2();
100     nV2=aPave2.Index();
101     aV2=TopoDS::Vertex(myDS->Shape(nV2)); 
102     aT2=aPave2.Param();
103     //
104     bIsValid=Standard_True;
105     if (nV1==nV2) {
106       bIsValid=IsValid(aE, aV1, aT1, aT2);
107       if (!bIsValid) {
108         //printf(" pb SR: nV    nE: %d  nV1:( %d %15.10lf ) nV2:( %d %15.10lf )\n", nE, nV1, aT1, nV2, aT2);
109         myStopStatus=1;
110       }
111     }
112     //
113     IntTools_ShrunkRange aSR (aE, aV1, aV2, aRange, myContext);
114     iErr=aSR.ErrorStatus();
115     if (!aSR.IsDone()) {
116       //printf(" pb SR: Done  nE: %d  nV1:( %d %15.10lf ) nV2:( %d %15.10lf )\n", nE, nV1, aT1, nV2, aT2);
117       aSR.SetShrunkRange(aRange);
118       //throw BOPTColStd_Failure(buf) ;
119     }
120     else if (iErr!=6) {
121       CorrectShrunkRanges (0, aPave1, aSR);
122       CorrectShrunkRanges (1, aPave2, aSR);
123     }
124     aPB.SetShrunkRange(aSR);
125     aLPB.Append(aPB);
126   } //for (; aPBIt.More(); aPBIt.Next()) 
127   myIsDone=Standard_True;
128 }
129
130 //=======================================================================
131 //function : IsValid
132 //purpose  : 
133 //=======================================================================
134 Standard_Boolean IsValid(const TopoDS_Edge& aE,
135                          const TopoDS_Vertex& aV,
136                          const Standard_Real aTV1,
137                          const Standard_Real aTV2)
138 {
139   Standard_Boolean bRet;
140   Standard_Integer i, aNbP, aNbP1;
141   Standard_Real aTolV2, aTC1, aTC2, dT, aTC, aD2;
142   Handle(Geom_Curve) aC;
143   gp_Pnt aPV, aPC;
144   //
145   bRet=Standard_False;
146   aTolV2=BRep_Tool::Tolerance(aV);
147   aTolV2=aTolV2*aTolV2;
148   aPV=BRep_Tool::Pnt(aV);
149   aC=BRep_Tool::Curve(aE, aTC1, aTC2);
150   aNbP=7;
151   aNbP1=aNbP-1;
152   dT=(aTV2-aTV1)/aNbP1;
153   //
154   for (i=1; i<aNbP-1 && !bRet ; ++i) {
155     aTC=aTV1+dT*i;
156     aC->D0(aTC, aPC);
157     aD2=aPV.SquareDistance(aPC);
158     bRet=aD2>aTolV2;
159   }
160   return bRet;
161 }