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