0024023: Revamp the OCCT Handle -- downcast (automatic)
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_BuilderON2d.cxx
CommitLineData
b311480e 1// Created on: 1998-05-07
2// Created by: Xuan PHAM PHU
3// Copyright (c) 1998-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <TopOpeBRepBuild_BuilderON.jxx>
18
19#include <TopOpeBRepTool_EXPORT.hxx>
20#include <TopOpeBRepTool_SC.hxx>
21#include <TopOpeBRepDS_InterferenceTool.hxx>
22#include <TopOpeBRepDS_EXPORT.hxx>
23#include <TopOpeBRepDS_connex.hxx>
24#include <TopOpeBRepDS.hxx>
25#include <TopOpeBRepBuild_define.hxx>
26#include <BRep_Tool.hxx>
27#include <TopoDS.hxx>
28#include <TopExp.hxx>
29#include <Precision.hxx>
ec357c5c 30#include <TopOpeBRepDS_ShapeShapeInterference.hxx>
7fd59977 31
32
33#define M_OUT(st) (st == TopAbs_OUT)
34#define M_IN( st) (st == TopAbs_IN)
35#define M_FORWARD(st) (st == TopAbs_FORWARD)
36#define M_REVERSED(st) (st == TopAbs_REVERSED)
37
0797d9d3 38#ifdef OCCT_DEBUG
7fd59977 39Standard_EXPORT Standard_Boolean TopOpeBRepBuild_GetcontextEINTERNAL();
40Standard_EXPORT Standard_Boolean TopOpeBRepBuild_GetcontextEEXTERNAL();
41Standard_EXPORT void debfillonf(const Standard_Integer iF);
42Standard_EXPORT void debON2d(const Standard_Integer iF)
43{cout<<"++ debON2d "<<iF<<" "<<endl;}
44#endif
45
46Standard_EXPORT TopAbs_State FUN_build_TB(const TopOpeBRepBuild_PBuilder& PB,const Standard_Integer rank); // xpu290698
47Standard_EXPORT Standard_Boolean FUN_keepEON(const TopOpeBRepBuild_Builder& B,
48 const TopoDS_Shape& sEG,const TopoDS_Shape& sFOR,const TopoDS_Shape& sFS,
49 const Standard_Boolean EGBoundFOR,
50 const TopOpeBRepDS_Transition& TFE,const TopAbs_State TB1,const TopAbs_State TB2);
51Standard_EXPORT void FUN_coutmess(const TCollection_AsciiString& m);
52
53Standard_EXPORTEXTERN TopOpeBRepDS_PDataStructure GLOBAL_DS2d;
54
55//=======================================================================
56//function : Perform2d
57//purpose :
58//=======================================================================
59void TopOpeBRepBuild_BuilderON::Perform2d
60(const TopOpeBRepBuild_PBuilder& PB,
61 const TopoDS_Shape& FOR,const TopOpeBRepBuild_PGTopo& PG,
62 const TopOpeBRepTool_Plos& PLSclass, const TopOpeBRepBuild_PWireEdgeSet& PWES)
63{
64 myPB = PB;
65 myFace = FOR;
66 myPG = PG;
67 myPLSclass = PLSclass;
68 myPWES = PWES;
69
70 const TopOpeBRepDS_DataStructure& BDS=myPB->DataStructure()->DS();
71 if (GLOBAL_DS2d == NULL) GLOBAL_DS2d = (TopOpeBRepDS_PDataStructure)new TopOpeBRepDS_DataStructure();
72 const TopOpeBRepDS_ListOfInterference& lFEI = GLOBAL_DS2d->ShapeInterferences(FOR);
73
0797d9d3 74#ifdef OCCT_DEBUG
7fd59977 75 Standard_Integer iFOR;Standard_Boolean tFOR=myPB->GtraceSPS(FOR,iFOR);
76 if (tFOR) debfillonf(iFOR);
77 if (tFOR) {cout<<endl<<"LI on F"<<iFOR<<":"<<endl;
78 for (TopOpeBRepDS_ListIteratorOfListOfInterference iit(lFEI); iit.More(); iit.Next())
79 {iit.Value()->Dump(cout);cout<<endl;}}
80#endif
81
82 for (TopOpeBRepDS_ListIteratorOfListOfInterference itI(lFEI); itI.More(); itI.Next()){
83 const Handle(TopOpeBRepDS_Interference)& I = itI.Value();
84 TopOpeBRepDS_Kind GT,ST;Standard_Integer GI,SI;FDS_data(I,GT,GI,ST,SI);
85
86 const TopoDS_Edge& EG=TopoDS::Edge(BDS.Shape(GI));
0797d9d3 87#ifdef OCCT_DEBUG
7fd59977 88// Standard_Integer iEG=BDS.Shape(EG);
89#endif
90 const TopTools_ListOfShape& lEspON=myPB->Splits(EG,TopAbs_ON);
0797d9d3 91#ifdef OCCT_DEBUG
7fd59977 92// Standard_Integer nEspON=lEspON.Extent();
93#endif
94 for(TopTools_ListIteratorOfListOfShape it(lEspON);it.More();it.Next()) {
95 const TopoDS_Shape& EspON=it.Value();
96 GFillONParts2dWES2(I,EspON);
97 }
98 }
99}
100
101//=======================================================================
102//function : GFillONPartsWES2
103//purpose :
104//=======================================================================
105void TopOpeBRepBuild_BuilderON::GFillONParts2dWES2(const Handle(TopOpeBRepDS_Interference)& I,const TopoDS_Shape& EspON)
106{
107 const Handle(TopOpeBRepDS_HDataStructure)& HDS=myPB->DataStructure();
108 const TopOpeBRepDS_DataStructure& BDS= HDS->DS();
c5f3a425 109 Handle(TopOpeBRepDS_ShapeShapeInterference) SSI (Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(I));
7fd59977 110 TopAbs_State TB1,TB2;myPG->StatesON(TB1,TB2);
111 TopOpeBRepDS_Kind GT,ST;Standard_Integer GI,SI;FDS_data(SSI,GT,GI,ST,SI);
112// const TopOpeBRepDS_Transition& TFE=SSI->Transition();
113 Standard_Boolean EGBoundFOR=SSI->GBound();
114 const TopoDS_Face& FOR=TopoDS::Face(myFace); Standard_Integer iFOR=BDS.Shape(FOR);
115 const TopoDS_Edge& EG=TopoDS::Edge(BDS.Shape(GI));
0797d9d3 116#ifdef OCCT_DEBUG
7fd59977 117// Standard_Integer iEG=BDS.Shape(EG);
118#endif
119 const TopoDS_Face& FS=TopoDS::Face(BDS.Shape(SI));
0797d9d3 120#ifdef OCCT_DEBUG
7fd59977 121// Standard_Integer iFS=BDS.Shape(FS);
122// Standard_Boolean isclosedFF=BRep_Tool::IsClosed(EG,FOR);
123// Standard_Boolean isclosedFS=BRep_Tool::IsClosed(EG,FS);
124// Standard_Boolean isclosed=(isclosedFF || isclosedFS);
125// Standard_Boolean isrest=BDS.IsSectionEdge(EG);
126// Standard_Boolean issplit=myPB->IsSplit(EG,TopAbs_ON);
127// Standard_Integer rankFS=myPB->GShapeRank(FS);
128#endif
129 Standard_Integer rankEG=myPB->GShapeRank(EG);
0797d9d3 130#ifdef OCCT_DEBUG
7fd59977 131// Standard_Integer rankFOR=myPB->GShapeRank(FOR);
132#endif
133
134// TopAbs_State TBEG = (rankEG == 1) ? TB1 : TB2;
135 TopAbs_State TBEG = FUN_build_TB(myPB,rankEG);
0797d9d3 136#ifdef OCCT_DEBUG
7fd59977 137// TopAbs_State TFEbef = TFE.Before();
138// TopAbs_State TFEaft = TFE.After();
139// Standard_Boolean EGboundFOR =
140// Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(I)->GBound();
141#endif
142 Standard_Boolean eghassd = HDS->HasSameDomain(EG);
143
0797d9d3 144#ifdef OCCT_DEBUG
7fd59977 145 Standard_Boolean tFOR=myPB->GtraceSPS(iFOR);
146// Standard_Boolean tE=myPB->GtraceSPS(GI);
147// Standard_Boolean tEFOR = (tE && tFOR);
148 if (tFOR) {debON2d(iFOR);}
149 if (tFOR) {I->Dump(cout);cout<<endl;}
150#endif
151
152 Standard_Integer iFCX=SI;
153 Standard_Boolean FFinSDSO = Standard_True;
0797d9d3 154#ifdef OCCT_DEBUG
7fd59977 155// Standard_Boolean FFinSDDO = Standard_False;
156#endif
157 Standard_Boolean FFinSD= Standard_True;
158 TopoDS_Face FCX = FS;
159
0797d9d3 160#ifdef OCCT_DEBUG
7fd59977 161// TopAbs_Orientation oFOR = BDS.Shape(iFOR).Orientation();
162// TopAbs_Orientation oFS = BDS.Shape(iFS).Orientation();
163// TopAbs_Orientation oFCX = BDS.Shape(iFCX).Orientation();
164// Standard_Integer irefFOR = BDS.SameDomainRef(FOR);
165// Standard_Integer irefFCX = BDS.SameDomainRef(FCX);
166// Standard_Boolean FORisref = (irefFOR == iFOR);
167// Standard_Boolean FCXisref = (irefFCX == iFCX);
168#endif
169
170 TopAbs_Orientation oegFCXF;Standard_Boolean EGBoundFCX = FUN_tool_orientEinFFORWARD(EG,FCX,oegFCXF);
171 TopAbs_Orientation oegFCX ;
0797d9d3 172#ifdef OCCT_DEBUG
7fd59977 173// Standard_Boolean ok2 =
174#endif
175 FUN_tool_orientEinF(EG,FCX,oegFCX);
176
177 Standard_Boolean opeFus = myPB->Opefus();
178 Standard_Boolean opeCut = myPB->Opec12() || myPB->Opec21();
179 Standard_Boolean opeCom = myPB->Opecom();
180
181
182 Standard_Boolean yap6 = Standard_True;
183 yap6 = yap6 && FFinSD;
184// yap6 = yap6 && (!EGBoundFOR);
185// yap6 = yap6 && EGBoundFCX;
186 yap6 = yap6 && (EGBoundFOR || EGBoundFCX);
187 yap6 = yap6 && eghassd;
188
189 //=========================================
190 if ( yap6) {
0797d9d3 191#ifdef OCCT_DEBUG
7fd59977 192 if (tFOR) cout<<"* yap6 = 1"<<endl;
193#endif
1d47d8d0 194 TopAbs_Orientation neworiE = TopAbs_FORWARD;
7fd59977 195 // FF est samedomain avec FCX
196 // on evalue la transition de FOR par rapport a la matiere 2d de la face FCX
197 // au lieu de la transition par rapport a la matiere 3d de la face FS
198 // EG est une arete de FCX, oegFCXF=O.T. de EG dans FCX orientee FORWARD
199
200 Standard_Boolean b = Standard_False;
201
202 Standard_Boolean SO = FFinSDSO;//(FFinSDSO && (oFOR == oFCX)) || (FFinSDDO && (oFOR != oFCX));
0797d9d3 203#ifdef OCCT_DEBUG
7fd59977 204// Standard_Integer rkToFill = BDS.AncestorRank(myFace); //DEB
205#endif
206 Standard_Boolean rk1 = (rankEG == 1);
207 if (!rk1) return;
208
209 TopAbs_Orientation oegFOR;
1d47d8d0 210 Standard_Boolean shareG = Standard_False;
7fd59977 211 Standard_Boolean ok = Standard_False;
212 if (EGBoundFCX)
213 ok = FUN_ds_shareG(myPB->DataStructure(),iFOR,iFCX,GI,TopoDS::Edge(EspON),shareG);
214 else if (EGBoundFOR)
215 ok = FUN_ds_shareG(myPB->DataStructure(),iFCX,iFOR,GI,TopoDS::Edge(EspON),shareG);
216 if (!ok) return; // nyiFUNRAISE
0797d9d3 217#ifdef OCCT_DEBUG
7fd59977 218 if (tFOR) cout<<" shareG="<<shareG<<endl;
219#endif
220
221 if (SO) {
222 // FOR and FCX share geometric domain.
223 if (opeFus) b = shareG;
224 else if (opeCut) b = (!shareG) && M_OUT(TBEG);
225 else if (opeCom) b = shareG;
226 }
227 if (!b) return;
228
229 if (!EGBoundFOR) {
230 TopAbs_Orientation oegFCXF1; FUN_tool_orientEinFFORWARD(EG,FCX,oegFCXF1);
231 neworiE = oegFCXF;
232 }
233 else if (EGBoundFOR) {
234 FUN_tool_orientEinFFORWARD(EG,TopoDS::Face(FOR),oegFOR);
235 neworiE = oegFOR;
236 }
237
238// Standard_Real f,l; FUN_tool_bounds(EG,f,l); Standard_Real parON = (f+l)*.4352;
239 Standard_Real f,l; FUN_tool_bounds(TopoDS::Edge(EspON),f,l); Standard_Real parON = (f+l)*.4352; // xpu120698
240 Standard_Boolean ESO; ok = FUN_tool_curvesSO(TopoDS::Edge(EspON),parON,EG,ESO);
241 if (!ok) return; // xpu120698
242 if (!ESO) neworiE = TopAbs::Complement(neworiE);
243
244 TopAbs_Orientation oFOR = BDS.Shape(iFOR).Orientation();
245 TopAbs_Orientation oFCX = BDS.Shape(iFCX).Orientation();
246 if (oFOR != oFCX) neworiE = TopAbs::Complement(neworiE);
247
248 TopoDS_Shape newE = EspON;
249 newE.Orientation(neworiE);
250 myPWES->AddStartElement(newE);
0797d9d3 251#ifdef OCCT_DEBUG
7fd59977 252 if (tFOR) cout<<" add spON e"<<GI<<endl;
253#endif
254 return;
255 } // yap6
256
257} // GFillONPartsWES2