Salome HOME
Porting to OCCT dev version: update version 0x07010000 -> 0x07010001
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_WireSolid.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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
23 // File:        GEOMAlgo_WireSolid.cxx
24 // Created:     Wed Jan 12 10:19:31 2005
25 // Author:      Peter KURNEV
26 //              <pkv@irinox>
27 //
28 #include <GEOMAlgo_WireSolid.hxx>
29
30 #include <Basics_OCCTVersion.hxx>
31
32 #include <Standard_Failure.hxx>
33
34 #include <TopAbs_ShapeEnum.hxx>
35
36 #include <TopTools_ListIteratorOfListOfShape.hxx>
37
38 #include <BOPDS_DS.hxx>
39 #include <BOPDS_IndexRange.hxx>
40 #include <BOPDS_ListOfPaveBlock.hxx>
41 #include <BOPDS_PaveBlock.hxx>
42 #include <TopoDS_Solid.hxx>
43 #if OCC_VERSION_LARGE > 0x06070100
44 #include <IntTools_Context.hxx>
45 #else
46 #include <BOPInt_Context.hxx>
47 #endif
48 #include <BRepClass3d_SolidClassifier.hxx>
49 #include <BRep_Tool.hxx>
50 #include <BOPTools_AlgoTools.hxx>
51
52 #include <Basics_OCCTVersion.hxx>
53
54 //=======================================================================
55 //function : GEOMAlgo_WireSolid
56 //purpose  :
57 //=======================================================================
58 GEOMAlgo_WireSolid::GEOMAlgo_WireSolid()
59 :
60   GEOMAlgo_ShapeSolid()
61 {
62 }
63 //=======================================================================
64 //function : ~
65 //purpose  :
66 //=======================================================================
67 GEOMAlgo_WireSolid::~GEOMAlgo_WireSolid()
68 {
69 }
70 //=======================================================================
71 // function: Perform
72 // purpose:
73 //=======================================================================
74 void GEOMAlgo_WireSolid::Perform()
75 {
76   myErrorStatus=0;
77   //
78   try {
79     if (myDSFiller==NULL) {
80       myErrorStatus=10;
81       return;
82     }
83 #if OCC_VERSION_LARGE > 0x07010001
84     if(myDSFiller->HasErrors()) {
85 #else
86     if(myDSFiller->ErrorStatus()) {
87 #endif
88       myErrorStatus=11;
89       return;
90     }
91     //
92     Standard_Integer aNbArgs;
93     //
94     const BOPDS_DS& aDS=myDSFiller->DS();
95     const BOPCol_ListOfShape& aLS=aDS.Arguments();
96     aNbArgs=aLS.Extent();
97     if (!aNbArgs) {
98       myErrorStatus=13;
99       return;
100     }
101     //
102     BuildResult();
103   }
104   //
105   catch (Standard_Failure) {
106     myErrorStatus= 12;
107   }
108 }
109 //=======================================================================
110 // function: BuildResult
111 // purpose:
112 //=======================================================================
113 void GEOMAlgo_WireSolid::BuildResult()
114 {
115   Standard_Boolean bHasPaveBlocks;
116   Standard_Integer i, iRank, aNbPB,  iBeg, iEnd, aNbArgs, nE;// nSp
117   Standard_Real aTol;
118   TopAbs_ShapeEnum aType;
119   TopAbs_State aState;
120   TopoDS_Edge aE;
121   //
122   myErrorStatus=0;
123   myLSIN.Clear();
124   myLSOUT.Clear();
125   myLSON.Clear();
126   //
127   const BOPDS_DS& aDS=myDSFiller->DS();
128   BOPDS_DS* pDS=(BOPDS_DS*)&aDS;
129   //
130   const BOPCol_ListOfShape& aLS=pDS->Arguments();
131   aNbArgs=aLS.Extent();
132   if (aNbArgs!=2) {
133     myErrorStatus=14;
134     return;
135   }
136   //
137   iRank=-1;
138   const TopoDS_Shape& aObj=aLS.First();
139   if (aObj.ShapeType()==TopAbs_WIRE) {
140     iRank=0;
141   }
142   const TopoDS_Shape& aTool=aLS.Last();
143   if (aTool.ShapeType()==TopAbs_WIRE) {
144     iRank=1;
145   }
146   //
147   if (iRank==-1) {
148     myErrorStatus=15;
149     return;
150   }
151   //
152   aTol=1.e-7;
153   //
154   const TopoDS_Solid& aSolid=(iRank==0) ?  *((TopoDS_Solid*)&aTool) :
155     *((TopoDS_Solid*)&aObj);
156   //
157 #if OCC_VERSION_LARGE > 0x06070100
158   Handle(IntTools_Context) aCtx=myDSFiller->Context();
159 #else
160   Handle(BOPInt_Context) aCtx=myDSFiller->Context();
161 #endif
162   //BRepClass3d_SolidClassifier& aSC=aCtx->SolidClassifier(aSolid);
163   //
164   const BOPDS_IndexRange& aRange=pDS->Range(iRank);
165   aRange.Indices(iBeg, iEnd);
166   //
167   for (i=iBeg; i<=iEnd; ++i) {
168     const TopoDS_Shape& aS=pDS->Shape(i);
169     aType=aS.ShapeType();
170     if (aType!=TopAbs_EDGE) {
171       continue;
172     }
173     //
174     aE=*((TopoDS_Edge*)&pDS->Shape(i));
175     if (BRep_Tool::Degenerated(aE)) {
176       continue;
177     }
178     //
179     bHasPaveBlocks=pDS->HasPaveBlocks(i);
180     if (!bHasPaveBlocks) {
181       continue;
182     }
183     //
184     aState=TopAbs_UNKNOWN;
185     //
186     const BOPDS_ListOfPaveBlock& aLPB=pDS->PaveBlocks(i);
187     aNbPB=aLPB.Extent();
188     if (!aNbPB) {
189       aState=BOPTools_AlgoTools::ComputeStateByOnePoint(aE, aSolid, aTol, aCtx);
190     }
191     else if (aNbPB==1) {
192       const Handle(BOPDS_PaveBlock)& aPB=aLPB.First();
193       if (pDS->IsCommonBlock(aPB)) {
194         aState=TopAbs_ON;
195       }
196       else{
197         nE=aPB->Edge();
198         aE=*((TopoDS_Edge*)&pDS->Shape(nE));
199         aState=BOPTools_AlgoTools::ComputeStateByOnePoint(aE, aSolid, aTol, aCtx);
200       }
201       //----------
202       if (aState==TopAbs_ON) {
203         myLSON.Append(aE);
204       }
205       else if (aState==TopAbs_OUT) {
206         myLSOUT.Append(aE);
207       }
208       else if (aState==TopAbs_IN) {
209         myLSIN.Append(aE);
210       }
211     }
212   }
213 }