Salome HOME
Merge from V6_3_BR 06/06/2011
[modules/geom.git] / src / NMTTools / NMTTools_CheckerSI_1.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File:        NMTTools_CheckerSI.cxx
21 // Created:     Mon Feb 19 11:32:08 2007
22 // Author:      Peter KURNEV
23 //
24 #include <NMTTools_CheckerSI.ixx>
25 #include <NMTDS_ShapesDataStructure.hxx>
26 #include <NMTDS_IteratorCheckerSI.hxx>
27
28 #include <NMTDS_InterfPool.hxx>
29 #include <TopoDS_Edge.hxx>
30 #include <TopoDS_Vertex.hxx>
31 #include <BOPTools_ListOfPaveBlock.hxx>
32 #include <TopoDS.hxx>
33 #include <BRep_Tool.hxx>
34 #include <BOPTools_PaveSet.hxx>
35 #include <BOPTools_PaveBlockIterator.hxx>
36 #include <BOPTools_PaveBlock.hxx>
37 #include <IntTools_Range.hxx>
38 #include <BOPTools_Pave.hxx>
39 #include <IntTools_ShrunkRange.hxx>
40 #include <BOPTColStd_Failure.hxx>
41 #include <BOPTColStd_Dump.hxx>
42 #include <Geom_Curve.hxx>
43 #include <gp_Pnt.hxx>
44
45
46
47 static
48   Standard_Boolean IsValid(const TopoDS_Edge& aE,
49                            const TopoDS_Vertex& aV,
50                            const Standard_Real aTV1,
51                            const Standard_Real aTV2);
52
53 //=======================================================================
54 // function: PreparePaveBlocks
55 // purpose: 
56 //=======================================================================
57   void NMTTools_CheckerSI::PreparePaveBlocks(const TopAbs_ShapeEnum aType1, 
58                                              const TopAbs_ShapeEnum aType2)
59 {
60   NMTTools_PaveFiller::PreparePaveBlocks(aType1, aType2);
61 }
62 //=======================================================================
63 // function: PreparePaveBlocks
64 // purpose: 
65 //=======================================================================
66   void NMTTools_CheckerSI::PreparePaveBlocks(const Standard_Integer nE)
67 {
68   myIsDone=Standard_False;
69   //
70   // char buf[32]={"SR"};
71   Standard_Boolean bIsValid;
72   Standard_Integer nV1, nV2, iErr;
73   Standard_Real aT1, aT2;
74   TopoDS_Edge aE;
75   TopoDS_Vertex aV1, aV2;
76   //
77   BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool(myDS->RefEdge(nE));
78   // Edge 
79   aE=TopoDS::Edge(myDS->Shape(nE));
80   if (BRep_Tool::Degenerated(aE)) {
81     myIsDone=Standard_True;
82     return;
83   }
84   //
85   BOPTools_PaveSet& aPS=myPavePool(myDS->RefEdge(nE));
86   
87   BOPTools_PaveBlockIterator aPBIt(nE, aPS);
88   for (; aPBIt.More(); aPBIt.Next()) {
89     BOPTools_PaveBlock& aPB=aPBIt.Value();
90     const IntTools_Range& aRange=aPB.Range();
91     //
92     const BOPTools_Pave& aPave1=aPB.Pave1();
93     nV1=aPave1.Index();
94     aV1=TopoDS::Vertex(myDS->Shape(nV1));
95     aT1=aPave1.Param();
96     //
97     const BOPTools_Pave& aPave2=aPB.Pave2();
98     nV2=aPave2.Index();
99     aV2=TopoDS::Vertex(myDS->Shape(nV2)); 
100     aT2=aPave2.Param();
101     //
102     bIsValid=Standard_True;
103     if (nV1==nV2) {
104       bIsValid=IsValid(aE, aV1, aT1, aT2);
105       if (!bIsValid) {
106         //printf(" pb SR: nV    nE: %d  nV1:( %d %15.10lf ) nV2:( %d %15.10lf )\n", nE, nV1, aT1, nV2, aT2);
107         myStopStatus=1;
108       }
109     }
110     //
111     IntTools_ShrunkRange aSR (aE, aV1, aV2, aRange, myContext);
112     iErr=aSR.ErrorStatus();
113     if (!aSR.IsDone()) {
114       //printf(" pb SR: Done  nE: %d  nV1:( %d %15.10lf ) nV2:( %d %15.10lf )\n", nE, nV1, aT1, nV2, aT2);
115       aSR.SetShrunkRange(aRange);
116       //throw BOPTColStd_Failure(buf) ;
117     }
118     else if (iErr!=6) {
119       CorrectShrunkRanges (0, aPave1, aSR);
120       CorrectShrunkRanges (1, aPave2, aSR);
121     }
122     aPB.SetShrunkRange(aSR);
123     aLPB.Append(aPB);
124   } //for (; aPBIt.More(); aPBIt.Next()) 
125   myIsDone=Standard_True;
126 }
127
128 //=======================================================================
129 //function : IsValid
130 //purpose  : 
131 //=======================================================================
132 Standard_Boolean IsValid(const TopoDS_Edge& aE,
133                          const TopoDS_Vertex& aV,
134                          const Standard_Real aTV1,
135                          const Standard_Real aTV2)
136 {
137   Standard_Boolean bRet;
138   Standard_Integer i, aNbP, aNbP1;
139   Standard_Real aTolV2, aTC1, aTC2, dT, aTC, aD2;
140   Handle(Geom_Curve) aC;
141   gp_Pnt aPV, aPC;
142   //
143   bRet=Standard_False;
144   aTolV2=BRep_Tool::Tolerance(aV);
145   aTolV2=aTolV2*aTolV2;
146   aPV=BRep_Tool::Pnt(aV);
147   aC=BRep_Tool::Curve(aE, aTC1, aTC2);
148   aNbP=7;
149   aNbP1=aNbP-1;
150   dT=(aTV2-aTV1)/aNbP1;
151   //
152   for (i=1; i<aNbP-1 && !bRet ; ++i) {
153     aTC=aTV1+dT*i;
154     aC->D0(aTC, aPC);
155     aD2=aPV.SquareDistance(aPC);
156     bRet=aD2>aTolV2;
157   }
158   return bRet;
159 }