Salome HOME
CMake porting.
[modules/geom.git] / src / NMTTools / NMTTools_CheckerSI_1.cxx
1 // Copyright (C) 2007-2013  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.hxx>
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 // function: PreparePaveBlocks
47 // purpose:
48 //=======================================================================
49   void NMTTools_CheckerSI::PreparePaveBlocks(const TopAbs_ShapeEnum aType1,
50                                              const TopAbs_ShapeEnum aType2)
51 {
52   NMTTools_PaveFiller::PreparePaveBlocks(aType1, aType2);
53 }
54 //=======================================================================
55 // function: PreparePaveBlocks
56 // purpose:
57 //=======================================================================
58   void NMTTools_CheckerSI::PreparePaveBlocks(const Standard_Integer nE)
59 {
60   //Standard_Boolean bIsValid;
61   Standard_Integer nV1, nV2, iErr;
62   Standard_Real aT1, aT2;
63   TopoDS_Edge aE;
64   TopoDS_Vertex aV1, aV2;
65   // 
66   myIsDone=Standard_False;
67   //
68   BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool(myDS->RefEdge(nE));
69   // Edge
70   aE=TopoDS::Edge(myDS->Shape(nE));
71   if (BRep_Tool::Degenerated(aE)) {
72     myIsDone=Standard_True;
73     return;
74   }
75   //
76   BOPTools_PaveSet& aPS=myPavePool(myDS->RefEdge(nE));
77
78   BOPTools_PaveBlockIterator aPBIt(nE, aPS);
79   for (; aPBIt.More(); aPBIt.Next()) {
80     BOPTools_PaveBlock& aPB=aPBIt.Value();
81     const IntTools_Range& aRange=aPB.Range();
82     //
83     const BOPTools_Pave& aPave1=aPB.Pave1();
84     nV1=aPave1.Index();
85     aV1=TopoDS::Vertex(myDS->Shape(nV1));
86     aT1=aPave1.Param();
87     //
88     const BOPTools_Pave& aPave2=aPB.Pave2();
89     nV2=aPave2.Index();
90     aV2=TopoDS::Vertex(myDS->Shape(nV2));
91     aT2=aPave2.Param();
92     //
93     //modified by NIZNHY-PKV Thu Nov 01 13:46:00 2012f
94     //w/a: http://salome.mantis.opencascade.com/view.php?id=21835 
95     /*
96     bIsValid=Standard_True;
97     if (nV1==nV2) {
98       bIsValid=IsValid(aE, aV1, aT1, aT2);
99       if (!bIsValid) {
100         myStopStatus=1;
101       }
102     }
103     */
104     //modified by NIZNHY-PKV Thu Nov 01 13:46:09 2012t
105     //
106     IntTools_ShrunkRange aSR (aE, aV1, aV2, aRange, myContext);
107     iErr=aSR.ErrorStatus();
108     if (!aSR.IsDone()) {
109       aSR.SetShrunkRange(aRange);
110     }
111     else if (iErr!=6) {
112       CorrectShrunkRanges (0, aPave1, aSR);
113       CorrectShrunkRanges (1, aPave2, aSR);
114     }
115     aPB.SetShrunkRange(aSR);
116     aLPB.Append(aPB);
117   } //for (; aPBIt.More(); aPBIt.Next())
118   myIsDone=Standard_True;
119 }
120 //modified by NIZNHY-PKV Thu Nov 01 13:46:55 2012f
121 //w/a: http://salome.mantis.opencascade.com/view.php?id=21835 
122 /*
123 //=======================================================================
124 //function : IsValid
125 //purpose  :
126 //=======================================================================
127 Standard_Boolean IsValid(const TopoDS_Edge& aE,
128                          const TopoDS_Vertex& aV,
129                          const Standard_Real aTV1,
130                          const Standard_Real aTV2)
131 {
132   Standard_Boolean bRet;
133   Standard_Integer i, aNbP, aNbP1;
134   Standard_Real aTolV2, aTC1, aTC2, dT, aTC, aD2;
135   Handle(Geom_Curve) aC;
136   gp_Pnt aPV, aPC;
137   //
138   bRet=Standard_False;
139   aTolV2=BRep_Tool::Tolerance(aV);
140   aTolV2=aTolV2*aTolV2;
141   aPV=BRep_Tool::Pnt(aV);
142   aC=BRep_Tool::Curve(aE, aTC1, aTC2);
143   aNbP=7;
144   aNbP1=aNbP-1;
145   dT=(aTV2-aTV1)/aNbP1;
146   //
147   for (i=1; i<aNbP-1 && !bRet ; ++i) {
148     aTC=aTV1+dT*i;
149     aC->D0(aTC, aPC);
150     aD2=aPV.SquareDistance(aPC);
151     bRet=aD2>aTolV2;
152   }
153   return bRet;
154 }
155 */
156 //modified by NIZNHY-PKV Thu Nov 01 13:47:07 2012t