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