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