1 // Created on: 1996-03-07
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16 
17 
18 #include <BRep_Tool.hxx>
19 #include <gp_Pnt.hxx>
20 #include <Standard_NoSuchObject.hxx>
21 #include <Standard_ProgramError.hxx>
22 #include <TCollection_AsciiString.hxx>
23 #include <TopoDS.hxx>
24 #include <TopoDS_Edge.hxx>
25 #include <TopoDS_Face.hxx>
26 #include <TopoDS_Shape.hxx>
27 #include <TopoDS_Vertex.hxx>
28 #include <TopOpeBRepBuild_Builder.hxx>
29 #include <TopOpeBRepBuild_define.hxx>
30 #include <TopOpeBRepBuild_EdgeBuilder.hxx>
31 #include <TopOpeBRepBuild_FaceBuilder.hxx>
32 #include <TopOpeBRepBuild_GTopo.hxx>
33 #include <TopOpeBRepBuild_HBuilder.hxx>
34 #include <TopOpeBRepBuild_PaveSet.hxx>
35 #include <TopOpeBRepBuild_ShapeSet.hxx>
36 #include <TopOpeBRepBuild_ShellFaceSet.hxx>
37 #include <TopOpeBRepBuild_SolidBuilder.hxx>
38 #include <TopOpeBRepBuild_WireEdgeSet.hxx>
39 #include <TopOpeBRepDS.hxx>
40 #include <TopOpeBRepDS_BuildTool.hxx>
41 #include <TopOpeBRepDS_CurveIterator.hxx>
42 #include <TopOpeBRepDS_EXPORT.hxx>
43 #include <TopOpeBRepDS_HDataStructure.hxx>
44 #include <TopOpeBRepDS_PointIterator.hxx>
45 #include <TopOpeBRepDS_SurfaceIterator.hxx>
46 #include <TopOpeBRepTool_2d.hxx>
47 #include <TopOpeBRepTool_defineG.hxx>
48 #include <TopOpeBRepTool_EXPORT.hxx>
49 #include <TopOpeBRepTool_ShapeExplorer.hxx>
50 
51 #ifdef OCCT_DEBUG
debfctwes(const Standard_Integer)52 Standard_EXPORT void debfctwes(const Standard_Integer /*i*/) {}
debfctwesmess(const Standard_Integer i,const TCollection_AsciiString & s="")53 Standard_EXPORT void debfctwesmess(const Standard_Integer i,const TCollection_AsciiString& s = "")
54 {std::cout<<"+ + + debfctwes "<<s<<"F"<<i<<std::endl;debfctwes(i);}
55 extern void debaddpwes(const Standard_Integer iFOR,const TopAbs_State TB1,const Standard_Integer iEG,const TopAbs_Orientation neworiE,
56                        const TopOpeBRepBuild_PBuilder& PB,const TopOpeBRepBuild_PWireEdgeSet& PWES,const TCollection_AsciiString& str1,const TCollection_AsciiString& str2);
57 #endif
58 
59 Standard_Boolean TopOpeBRepBuild_FUN_aresamegeom(const TopoDS_Shape& S1,const TopoDS_Shape& S2);
60 
61 #define M_IN(st )      (st == TopAbs_IN)
62 #define M_OUT(st)      (st == TopAbs_OUT)
63 #define M_FORWARD(st ) (st == TopAbs_FORWARD)
64 #define M_REVERSED(st) (st == TopAbs_REVERSED)
65 #define M_INTERNAL(st) (st == TopAbs_INTERNAL)
66 #define M_EXTERNAL(st) (st == TopAbs_EXTERNAL)
67 
68 //=======================================================================
69 //function : GFillCurveTopologyWES
70 //purpose  :
71 //=======================================================================
GFillCurveTopologyWES(const TopoDS_Shape & F1,const TopOpeBRepBuild_GTopo & G1,TopOpeBRepBuild_WireEdgeSet & WES)72 void TopOpeBRepBuild_Builder::GFillCurveTopologyWES(const TopoDS_Shape& F1,const TopOpeBRepBuild_GTopo& G1,TopOpeBRepBuild_WireEdgeSet& WES)
73 {
74   TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
75   TopAbs_ShapeEnum t1,t2,ShapeInterf; G1.Type(t1,t2); ShapeInterf = t1;
76 
77 #ifdef OCCT_DEBUG
78   Standard_Integer iF; Standard_Boolean tSPS = GtraceSPS(F1,iF);
79   if(tSPS) GdumpSHASTA(iF,TB1,WES,"--- GFillCurveTopologyWES");
80   if(tSPS) {std::cout<<" ShapeInterf ";TopAbs::Print(ShapeInterf,std::cout);std::cout<<std::endl;}
81   if(tSPS) {debfctwesmess(iF);}
82 #endif
83 
84   TopOpeBRepDS_CurveIterator FCit(myDataStructure->FaceCurves(F1));
85   myFaceReference = TopoDS::Face(F1);
86   myFaceToFill = TopoDS::Face(F1);
87   //modified by NIZHNY-MZV  Thu Feb 24 09:15:33 2000
88   //sometimes by the problem of tolerances we have intersection
89   //lines between SameDomain faces, but Same domain faces can not
90   //have intersection lines other than by its original edges
91   //so we skip it if we find that two SameDomain faces have
92   //new intersection edge
93   Standard_Boolean hsd = myDataStructure->HasSameDomain(F1);
94   TopTools_IndexedMapOfShape aSDMap;
95   if(hsd) {
96     TopTools_ListIteratorOfListOfShape it = myDataStructure -> SameDomain(F1);
97     for(; it.More(); it.Next()) {
98       const TopoDS_Shape& SDF = it.Value();
99       aSDMap.Add(SDF);
100     }
101   }
102   //End modified by NIZHNY-MZV  Thu Feb 24 09:21:08 2000
103 
104   for (; FCit.More(); FCit.Next()) {
105     if ( ShapeInterf != TopAbs_SHAPE ) {
106       const Handle(TopOpeBRepDS_Interference)& I = FCit.Value();
107       const TopOpeBRepDS_Transition& T = I->Transition();
108       TopAbs_ShapeEnum shab = T.ShapeBefore(),shaa = T.ShapeAfter();
109       if ( (shaa != ShapeInterf) || (shab != ShapeInterf) ) continue;
110       //modified by NIZHNY-MZV  Thu Feb 24 09:14:31 2000
111 
112       Standard_Integer si = I -> Support();
113       TopoDS_Shape SS = myDataStructure -> Shape(si);
114       //see comment above
115       if(aSDMap.Contains(SS))
116 	continue;
117       //End modified by NIZHNY-MZV  Thu Feb 24 09:21:34 2000
118     }
119     GFillCurveTopologyWES(FCit,G1,WES);
120   }
121 
122   return;
123 } // GFillCurveTopologyWES
124 
125 //=======================================================================
126 //function : GFillCurveTopologyWES
127 //purpose  :
128 //=======================================================================
GFillCurveTopologyWES(const TopOpeBRepDS_CurveIterator & FCit,const TopOpeBRepBuild_GTopo & G1,TopOpeBRepBuild_WireEdgeSet & WES) const129 void TopOpeBRepBuild_Builder::GFillCurveTopologyWES(const TopOpeBRepDS_CurveIterator& FCit,const TopOpeBRepBuild_GTopo& G1,TopOpeBRepBuild_WireEdgeSet& WES) const
130 {
131   Standard_Boolean more = FCit.More();
132   if (!more) return;
133 
134   TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
135   TopOpeBRepDS_Config Conf = G1.Config1();
136   TopAbs_State TB = TB1;
137   if ( Conf == TopOpeBRepDS_DIFFORIENTED ) { // -jyl980525
138 //    if      (TB1 == TopAbs_OUT) TB = TopAbs_IN;
139 //    else if (TB1 == TopAbs_IN ) TB = TopAbs_OUT;
140   }
141 
142   TopoDS_Face& WESF = *((TopoDS_Face*)((void*)&WES.Face()));
143   TopoDS_Face& FTF = *((TopoDS_Face*)((void*)&myFaceToFill));
144 #ifdef OCCT_DEBUG
145 //  Standard_Boolean FTFeqWESF = myFaceReference.IsEqual(WESF);
146 #endif
147 
148 #ifdef OCCT_DEBUG
149   Standard_Integer iWESF = myDataStructure->Shape(WESF);
150   Standard_Integer iref = myDataStructure->Shape(myFaceReference);
151   Standard_Integer ifil = myDataStructure->Shape(myFaceToFill);
152 #endif
153 
154   Standard_Boolean opeCut = Opec12() || Opec21();
155   Standard_Boolean ComOfCut = opeCut && (TB1 == TB2)&& (TB1 == TopAbs_IN);
156 
157   const TopOpeBRepDS_Transition& T = FCit.Value()->Transition();
158   TopAbs_Orientation neworiE = T.Orientation(TB);
159   Standard_Boolean samegeom = TopOpeBRepBuild_FUN_aresamegeom(FTF,WESF);
160   if (!samegeom) {
161     neworiE = TopAbs::Complement(neworiE);
162   }
163 
164 #ifdef OCCT_DEBUG
165   Standard_Boolean tSPS = GtraceSPS(iWESF);
166   if(tSPS){
167     std::cout<<"ifil : "<<ifil<<" iref : "<<iref<<" iwes : "<<iWESF<<std::endl;
168     std::cout<<"face "<<ifil<<" is ";TopOpeBRepDS::Print(Conf,std::cout);std::cout<<std::endl;
169     std::cout<<"ComOfCut "<<ComOfCut<<std::endl;
170     debfctwesmess(iWESF);
171   }
172 #endif
173 
174   if (ComOfCut) return;
175 
176   Standard_Integer iG = FCit.Current();
177   const TopTools_ListOfShape& LnewE = NewEdges(iG);
178   TopTools_ListIteratorOfListOfShape Iti(LnewE);
179   for (; Iti.More(); Iti.Next()) {
180     TopoDS_Shape EE = Iti.Value();
181     TopoDS_Edge& E = TopoDS::Edge(EE);
182 
183     //modified by NIZHNY-MZV  Fri Mar 17 12:51:03 2000
184     if(BRep_Tool::Degenerated(E))
185       continue;
186 
187 //    TopAbs_Orientation neworiE = FCit.Orientation(TB);
188     E.Orientation(neworiE);
189 
190     const Handle(Geom2d_Curve)& PC = FCit.PCurve();
191 
192     Standard_Boolean EhasPConFTF =
193 
194                       FC2D_HasCurveOnSurface(E,FTF);
195     //modified by NIZHNY-MZV  Mon Mar 27 15:24:39 2000
196     if(!EhasPConFTF)
197       myBuildTool.PCurve(FTF,E,PC);
198 
199     Standard_Boolean EhasPConWESF = FC2D_HasCurveOnSurface(E,WESF);
200 
201     if ( !EhasPConWESF) {
202 //      Standard_Real tolE = BRep_Tool::Tolerance(E);
203       Standard_Real f2,l2,tolpc; Handle(Geom2d_Curve) C2D;
204       C2D = FC2D_CurveOnSurface(E,WESF,f2,l2,tolpc);
205       if (C2D.IsNull()) throw Standard_ProgramError("GFillCurveTopologyWES");
206 #ifdef OCCT_DEBUG
207 //      Standard_Real tol = Max(tolE,tolpc);
208 #endif
209 
210       myBuildTool.PCurve(WESF,E,C2D);
211 
212 #ifdef OCCT_DEBUG
213       EhasPConWESF = FC2D_HasCurveOnSurface(E,WESF);
214       if (!EhasPConWESF) std::cout<<"TopOpeBRepBuild_Builder::GFillCurveTopologyWES : Null PCurve on F"<<iWESF<<std::endl;
215 #endif
216     }
217 
218 #ifdef OCCT_DEBUG
219     if (tSPS) debaddpwes(iWESF,TB,iG,neworiE,(TopOpeBRepBuild_Builder* const)this,&WES,"GFillCurveTopology " ,"WES+ EofC ");
220 #endif
221 
222     WES.AddStartElement(E);
223   }
224 
225 } // GFillCurveTopologyWES
226