1 // Created on: 1999-01-25
2 // Created by: Xuan PHAM PHU
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRep_Tool.hxx>
19 #include <TopExp_Explorer.hxx>
21 #include <TopoDS_Edge.hxx>
22 #include <TopoDS_Shape.hxx>
23 #include <TopOpeBRepDS.hxx>
24 #include <TopOpeBRepDS_DataMapOfShapeListOfShapeOn1State.hxx>
25 #include <TopOpeBRepDS_define.hxx>
26 #include <TopOpeBRepDS_HDataStructure.hxx>
27 #include <TopOpeBRepDS_ListOfShapeOn1State.hxx>
28 #include <TopOpeBRepDS_ProcessInterferencesTool.hxx>
29 #include <TopOpeBRepDS_ShapeShapeInterference.hxx>
30 #include <TopOpeBRepDS_TOOL.hxx>
31 #include <TopOpeBRepTool_EXPORT.hxx>
32 #include <TopOpeBRepTool_TOOL.hxx>
34 #define M_REVERSED(O) (O == TopAbs_REVERSED)
36 static void FDS_sortGb(const Handle(TopOpeBRepDS_HDataStructure)& HDS,const TopOpeBRepDS_ListOfInterference& LI, TopOpeBRepDS_ListOfInterference& LIGb0,TopOpeBRepDS_ListOfInterference& LIGb1,TopOpeBRepDS_ListOfInterference& LIGbsd)
38 const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
39 LIGb0.Clear(); LIGb1.Clear(); LIGbsd.Clear();
40 TopOpeBRepDS_ListIteratorOfListOfInterference it(LI);
41 for (; it.More(); it.Next()){
42 const Handle(TopOpeBRepDS_Interference)& I = it.Value();
43 Handle(TopOpeBRepDS_ShapeShapeInterference) SSI = Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(I);
44 if (SSI.IsNull()) {LIGb0.Append(I);continue;}
46 Standard_Boolean gb1 = SSI->GBound();
47 Standard_Integer G = I->Geometry();
48 Standard_Boolean hsd = HDS->HasSameDomain(BDS.Shape(G));
49 if (hsd) {LIGbsd.Append(I);continue;}
51 if (gb1) LIGb1.Append(I);
56 //=======================================================================
59 //=======================================================================
66 Standard_Integer TopOpeBRepDS_TOOL::EShareG(const Handle(TopOpeBRepDS_HDataStructure)& HDS,const TopoDS_Edge& E,TopTools_ListOfShape& lEsd)
69 Standard_Boolean dgE = BRep_Tool::Degenerated(E);
71 Standard_Boolean hsd = HDS->HasSameDomain(E);
73 TopTools_ListIteratorOfListOfShape itsd(HDS->SameDomain(E));
74 for (; itsd.More(); itsd.Next()) lEsd.Append(itsd.Value());
78 const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
79 const TopOpeBRepDS_ListOfInterference& LI = BDS.ShapeInterferences(E);
80 TopOpeBRepDS_ListOfInterference LII; FDS_copy(LI,LII);
81 TopOpeBRepDS_ListOfInterference L1d; Standard_Integer n1d = FUN_selectTRASHAinterference(LII,TopAbs_EDGE,L1d);
82 if (n1d == 0) return 0;
84 TopTools_MapOfShape mapesd;
85 TopOpeBRepDS_ListOfInterference l1gb0,l1gb1,l1gbsd; FDS_sortGb(HDS,L1d,l1gb0,l1gb1,l1gbsd);
86 TopOpeBRepDS_ListIteratorOfListOfInterference it0(l1gb0);
87 for (; it0.More(); it0.Next()) mapesd.Add(BDS.Shape(it0.Value()->Support()));
89 TopOpeBRepDS_ListIteratorOfListOfInterference it1(l1gb1);
90 for (; it1.More(); it1.Next()) mapesd.Add(BDS.Shape(it1.Value()->Support()));
92 TopOpeBRepDS_ListIteratorOfListOfInterference itsd(l1gbsd);
93 for (; itsd.More(); itsd.Next()) {
94 const Handle(TopOpeBRepDS_Interference)& I = itsd.Value();
95 const TopoDS_Edge& Esd = TopoDS::Edge(BDS.Shape(I->Support()));
96 Standard_Boolean isb = mapesd.Contains(Esd);
99 Standard_Integer G = I->Geometry();
100 const TopoDS_Vertex& vG = TopoDS::Vertex(BDS.Shape(G));
101 TopoDS_Vertex vsd; Standard_Boolean ok = FUN_ds_getoov(vG,BDS,vsd);
103 Standard_Boolean Gb1 = Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(I)->GBound();
104 TopoDS_Vertex vE = Gb1 ? vG : vsd;
105 TopoDS_Vertex vEsd = Gb1 ? vsd : vG;
107 Standard_Integer ovE; gp_Vec tgE;
108 ok = TopOpeBRepTool_TOOL::TgINSIDE(vE,E,tgE,ovE);
110 Standard_Integer ovEsd; gp_Vec tgEsd;
111 ok = TopOpeBRepTool_TOOL::TgINSIDE(vEsd,Esd,tgEsd,ovEsd);
113 Standard_Boolean inE = (ovE == CLOSING)||(ovE == INTERNAL);
114 Standard_Boolean inEsd = (ovEsd == CLOSING)||(ovEsd == INTERNAL);
115 if (inE || inEsd) {mapesd.Add(Esd); continue;}
116 Standard_Real dot = gp_Dir(tgE).Dot(gp_Dir(tgEsd));
117 if (dot > 0.) mapesd.Add(Esd);
119 TopTools_MapIteratorOfMapOfShape itm(mapesd);
120 for (; itm.More(); itm.Next()) lEsd.Append(itm.Key());
121 return (lEsd.Extent());
126 //=======================================================================
129 //=======================================================================
131 Standard_Boolean TopOpeBRepDS_TOOL::ShareG(const Handle(TopOpeBRepDS_HDataStructure)& HDS, const Standard_Integer i1, const Standard_Integer i2)
133 const TopoDS_Shape& s1 = HDS->Shape(i1);
134 const TopoDS_Shape& s2 = HDS->Shape(i2);
136 Standard_Boolean hsd1 = HDS->HasSameDomain(s1);
137 if (!hsd1) return Standard_False;
138 TopTools_ListIteratorOfListOfShape it1(HDS->SameDomain(s1));
139 for (; it1.More(); it1.Next()){
140 Standard_Boolean same = it1.Value().IsSame(s2);
142 return Standard_True;
144 return Standard_False;
149 //=======================================================================
152 //=======================================================================
154 Standard_Boolean TopOpeBRepDS_TOOL::GetEsd(const Handle(TopOpeBRepDS_HDataStructure)& HDS,
155 const TopoDS_Shape& S, const Standard_Integer ie, Standard_Integer& iesd)
157 // recall : method ::SameDomain(s) returns an iterator on the list of shapes
158 // sdm to s (ie actually sharing geometric domain with s)
160 TopTools_MapOfShape mesdS;
161 TopExp_Explorer ex(S, TopAbs_EDGE);
162 for (; ex.More(); ex.Next()){
163 const TopoDS_Shape& e = ex.Current();
164 Standard_Boolean hs = HDS->HasShape(e);
166 Standard_Boolean hsd = HDS->HasSameDomain(e);
169 // TopTools_ListIteratorOfListOfShape itt(HDS->SameDomain(e));
170 // for (; itt.More(); itt.Next()) mesdS.Add(itt.Value());
173 TopTools_ListIteratorOfListOfShape it(HDS->SameDomain(HDS->Shape(ie)));
174 for (; it.More(); it.Next()){
175 const TopoDS_Shape& esd = it.Value();
176 Standard_Boolean isb = mesdS.Contains(esd);
178 iesd = HDS->Shape(esd);
179 return Standard_True;
181 return Standard_False;
184 //=======================================================================
185 //function : ShareSplitON
187 //=======================================================================
189 Standard_Boolean TopOpeBRepDS_TOOL::ShareSplitON(const Handle(TopOpeBRepDS_HDataStructure)& HDS,
190 const TopOpeBRepDS_DataMapOfShapeListOfShapeOn1State& MEspON,
191 const Standard_Integer i1, const Standard_Integer i2, TopoDS_Shape& spON)
194 Standard_Boolean shareg = TopOpeBRepDS_TOOL::ShareG(HDS,i1,i2);
195 if (!shareg) return Standard_False;
197 const TopoDS_Shape& s1 = HDS->Shape(i1);
198 const TopoDS_Shape& s2 = HDS->Shape(i2);
200 const TopOpeBRepDS_ListOfShapeOn1State& los1 = MEspON.Find(s1);
201 Standard_Boolean issp = los1.IsSplit();
202 if (!issp) return Standard_False;
203 const TopTools_ListOfShape& lsp1 = los1.ListOnState();
204 Standard_Integer nsp1 = lsp1.Extent();
205 if (nsp1 == 0) return Standard_False;
206 TopTools_MapOfShape mesp1; // map of splits on of <s1>
207 TopTools_ListIteratorOfListOfShape it(lsp1);
208 for (; it.More(); it.Next()) mesp1.Add(it.Value());
210 const TopOpeBRepDS_ListOfShapeOn1State& los2 = MEspON.Find(s2);
211 Standard_Boolean issp2 = los2.IsSplit();
212 if (!issp2) return Standard_False;
213 const TopTools_ListOfShape& lsp2 = los2.ListOnState();
214 Standard_Integer nsp2 = lsp2.Extent();
215 if (nsp2 == 0) return Standard_False;
218 for (; it.More(); it.Next()) {
219 const TopoDS_Shape& esp = it.Value();
220 Standard_Boolean isb = mesp1.Contains(esp);
222 spON = esp; return Standard_True;
224 return Standard_False;
229 //=======================================================================
230 //function : GetConfig
231 //purpose : returns relative geometric config
232 //=======================================================================
233 #define SAMEORIENTED (1)
234 #define DIFFORIENTED (2)
235 Standard_Boolean TopOpeBRepDS_TOOL::GetConfig(const Handle(TopOpeBRepDS_HDataStructure)& HDS,
236 const TopOpeBRepDS_DataMapOfShapeListOfShapeOn1State& MEspON,
237 const Standard_Integer ie,const Standard_Integer iesd,
238 Standard_Integer& config)
241 Standard_Boolean shareg = TopOpeBRepDS_TOOL::ShareG(HDS,ie,iesd);
242 if (!shareg) return Standard_False;
244 const TopoDS_Edge& e = TopoDS::Edge(HDS->Shape(ie)); TopAbs_Orientation oe = e.Orientation();
245 const TopoDS_Edge& esd = TopoDS::Edge(HDS->Shape(iesd)); TopAbs_Orientation oesd = esd.Orientation();
246 TopOpeBRepDS_Config conf = HDS->SameDomainOrientation(e); Standard_Boolean unsh = (conf == TopOpeBRepDS_UNSHGEOMETRY);
247 TopOpeBRepDS_Config confsd = HDS->SameDomainOrientation(esd); Standard_Boolean unshsd = (confsd == TopOpeBRepDS_UNSHGEOMETRY);
248 if (!unsh && !unshsd) {
249 Standard_Boolean sameori = (conf == confsd);
250 if (M_REVERSED(oe)) sameori = !sameori;
251 if (M_REVERSED(oesd)) sameori = !sameori;
252 config = sameori ? SAMEORIENTED : DIFFORIENTED;
253 return Standard_True;
256 TopoDS_Shape eON; shareg = TopOpeBRepDS_TOOL::ShareSplitON(HDS,MEspON,ie,iesd,eON);
257 if (!shareg) return Standard_False;
259 Standard_Real f,l; FUN_tool_bounds(TopoDS::Edge(eON),f,l);
260 Standard_Real x = 0.45678; Standard_Real parON = (1-x)*f+x*l;
261 Standard_Real tole = BRep_Tool::Tolerance(TopoDS::Edge(e));
262 Standard_Real pare; Standard_Boolean ok = FUN_tool_parE(TopoDS::Edge(eON),parON, e,pare, tole);
263 if (!ok) return Standard_False;
264 Standard_Real tolesd = BRep_Tool::Tolerance(TopoDS::Edge(esd));
265 Standard_Real paresd; ok = FUN_tool_parE(TopoDS::Edge(eON),parON, esd,paresd, tolesd);
266 if (!ok) return Standard_False;
267 Standard_Boolean so; ok = FUN_tool_curvesSO(e,pare,esd,paresd,so);
268 if (!ok) return Standard_False;
269 config = (so)? SAMEORIENTED : DIFFORIENTED;
270 return Standard_True;