Salome HOME
IPAL19834: Incorrect result after make Partition of 2 objects. A fix by PKV.
[modules/geom.git] / src / NMTTools / NMTTools_PaveFiller_3.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
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.
8 // 
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.
13 //
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
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 // File:        NMTTools_PaveFiller_3.cxx
21 // Created:     Mon Dec  8 16:06:56 2003
22 // Author:      Peter KURNEV
23 //              <pkv@irinox>
24
25
26 #include <NMTTools_PaveFiller.ixx>
27
28 #include <TopoDS.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopoDS_Vertex.hxx>
31 #include <TopoDS_Face.hxx>
32
33 #include <TopExp_Explorer.hxx>
34
35 #include <BOPTools_VSInterference.hxx>
36 #include <BOPTools_CArray1OfVSInterference.hxx>
37
38 #include <NMTDS_Iterator.hxx>
39 #include <NMTDS_ShapesDataStructure.hxx>
40 #include <NMTDS_InterfPool.hxx>
41
42
43 // Modified  Thu Sep 14 14:35:18 2006 
44 // Contribution of Samtech www.samcef.com BEGIN
45 static
46   Standard_Boolean Contains(const TopoDS_Face& aF,
47                             const TopoDS_Vertex& aV);
48 // Contribution of Samtech www.samcef.com END
49 //=======================================================================
50 // function: PerformVF
51 // purpose: 
52 //=======================================================================
53   void NMTTools_PaveFiller::PerformVF() 
54 {
55   myIsDone=Standard_False;
56   //
57   Standard_Boolean aJustAdd;
58   Standard_Integer n1, n2, anIndexIn, aFlag, aWhat, aWith, aNbVSs, aBlockLength, iSDV;
59   Standard_Real aU, aV;
60   TopoDS_Vertex aV1;
61   TopoDS_Face aF2;
62   //
63   BOPTools_CArray1OfVSInterference& aVSs=myIP->VSInterferences();
64   //
65   // V/E Interferences 
66   myDSIt->Initialize(TopAbs_VERTEX, TopAbs_FACE);
67   //
68   // BlockLength correction
69   aNbVSs=myDSIt->BlockLength();
70   aBlockLength=aVSs.BlockLength();
71   if (aNbVSs > aBlockLength) {
72     aVSs.SetBlockLength(aNbVSs);
73   }
74   //
75   for (; myDSIt->More(); myDSIt->Next()) {
76     myDSIt->Current(n1, n2, aJustAdd);
77     if (! IsSuccessorsComputed(n1, n2)) {
78       anIndexIn=0;
79       aWhat=n1; // Vertex
80       aWith=n2; // Face
81       if (myDS->GetShapeType(n1)==TopAbs_FACE) {
82         aWhat=n2;
83         aWith=n1;
84       }
85       //
86       iSDV=FindSDVertex(aWhat);
87         //
88       if(aJustAdd) {
89         //myIntrPool->AddInterference(aWhat, aWith, BooleanOperations_VertexSurface, anIndexIn);
90         continue;
91       }
92       //
93       aV1=TopoDS::Vertex(myDS->Shape(aWhat));
94       if (iSDV) {
95         aV1=TopoDS::Vertex(myDS->Shape(iSDV));
96       }
97         //
98       aF2=TopoDS::Face(myDS->Shape(aWith));
99       //
100       // Modified  Thu Sep 14 14:35:18 2006 
101       // Contribution of Samtech www.samcef.com BEGIN
102       if (Contains(aF2, aV1)) {
103         continue;
104       }
105       // Contribution of Samtech www.samcef.com END
106       //
107       aFlag=myContext.ComputeVS (aV1, aF2, aU, aV);
108       //
109       if (!aFlag) {
110         //
111         // Add Interference to the Pool
112         BOPTools_VSInterference anInterf (aWhat, aWith, aU, aV);
113         anIndexIn=aVSs.Append(anInterf);
114         //
115         // SetState for Vertex in DS;
116         myDS->SetState (aWhat, BooleanOperations_ON);
117         // Insert Vertex in Interference Object
118         BOPTools_VSInterference& aVS=aVSs(anIndexIn);
119         aVS.SetNewShape(aWhat);
120         // qqf
121         {
122           myIP->Add(aWhat, aWith, Standard_True, NMTDS_TI_VF);
123         }
124         // qqt
125       }
126       //myIntrPool->AddInterference(aWhat, aWith, BooleanOperations_VertexSurface, anIndexIn);
127     }
128   }
129   myIsDone=Standard_True;
130 }
131 // Modified  Thu Sep 14 14:35:18 2006 
132 // Contribution of Samtech www.samcef.com BEGIN
133 //=======================================================================
134 //function : Contains
135 //purpose  : 
136 //=======================================================================
137 Standard_Boolean Contains(const TopoDS_Face& aF,
138                           const TopoDS_Vertex& aV)
139 {
140   Standard_Boolean bRet;
141   TopExp_Explorer aExp;
142   //
143   bRet=Standard_False;
144   aExp.Init(aF, TopAbs_VERTEX);
145   for (; aExp.More(); aExp.Next()) {
146     const TopoDS_Shape& aVF=aExp.Current();
147     if (aVF.IsSame(aV)) {
148       bRet=!bRet;
149       break;
150     }
151   }
152   return bRet;
153 }
154 // Contribution of Samtech www.samcef.com END