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
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>
20 #include <Standard_NoSuchObject.hxx>
21 #include <Standard_ProgramError.hxx>
22 #include <TCollection_AsciiString.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>
52 Standard_EXPORT void debfctwes(const Standard_Integer /*i*/) {}
53 Standard_EXPORT void debfctwesmess(const Standard_Integer i,const TCollection_AsciiString& s = "")
54 {cout<<"+ + + debfctwes "<<s<<"F"<<i<<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);
59 Standard_Boolean TopOpeBRepBuild_FUN_aresamegeom(const TopoDS_Shape& S1,const TopoDS_Shape& S2);
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)
68 //=======================================================================
69 //function : GFillCurveTopologyWES
71 //=======================================================================
72 void TopOpeBRepBuild_Builder::GFillCurveTopologyWES(const TopoDS_Shape& F1,const TopOpeBRepBuild_GTopo& G1,TopOpeBRepBuild_WireEdgeSet& WES)
74 TopAbs_State TB1,TB2; G1.StatesON(TB1,TB2);
75 TopAbs_ShapeEnum t1,t2,ShapeInterf; G1.Type(t1,t2); ShapeInterf = t1;
78 Standard_Integer iF; Standard_Boolean tSPS = GtraceSPS(F1,iF);
79 if(tSPS) GdumpSHASTA(iF,TB1,WES,"--- GFillCurveTopologyWES");
80 if(tSPS) {cout<<" ShapeInterf ";TopAbs::Print(ShapeInterf,cout);cout<<endl;}
81 if(tSPS) {debfctwesmess(iF);}
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;
96 TopTools_ListIteratorOfListOfShape it = myDataStructure -> SameDomain(F1);
97 for(; it.More(); it.Next()) {
98 const TopoDS_Shape& SDF = it.Value();
102 //End modified by NIZHNY-MZV Thu Feb 24 09:21:08 2000
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
112 Standard_Integer si = I -> Support();
113 TopoDS_Shape SS = myDataStructure -> Shape(si);
115 if(aSDMap.Contains(SS))
117 //End modified by NIZHNY-MZV Thu Feb 24 09:21:34 2000
119 GFillCurveTopologyWES(FCit,G1,WES);
123 } // GFillCurveTopologyWES
125 //=======================================================================
126 //function : GFillCurveTopologyWES
128 //=======================================================================
129 void TopOpeBRepBuild_Builder::GFillCurveTopologyWES(const TopOpeBRepDS_CurveIterator& FCit,const TopOpeBRepBuild_GTopo& G1,TopOpeBRepBuild_WireEdgeSet& WES) const
131 Standard_Boolean more = FCit.More();
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;
142 TopoDS_Face& WESF = *((TopoDS_Face*)((void*)&WES.Face()));
143 TopoDS_Face& FTF = *((TopoDS_Face*)((void*)&myFaceToFill));
145 // Standard_Boolean FTFeqWESF = myFaceReference.IsEqual(WESF);
149 Standard_Integer iWESF = myDataStructure->Shape(WESF);
150 Standard_Integer iref = myDataStructure->Shape(myFaceReference);
151 Standard_Integer ifil = myDataStructure->Shape(myFaceToFill);
154 Standard_Boolean opeCut = Opec12() || Opec21();
155 Standard_Boolean ComOfCut = opeCut && (TB1 == TB2)&& (TB1 == TopAbs_IN);
157 const TopOpeBRepDS_Transition& T = FCit.Value()->Transition();
158 TopAbs_Orientation neworiE = T.Orientation(TB);
159 Standard_Boolean samegeom = TopOpeBRepBuild_FUN_aresamegeom(FTF,WESF);
161 neworiE = TopAbs::Complement(neworiE);
165 Standard_Boolean tSPS = GtraceSPS(iWESF);
167 cout<<"ifil : "<<ifil<<" iref : "<<iref<<" iwes : "<<iWESF<<endl;
168 cout<<"face "<<ifil<<" is ";TopOpeBRepDS::Print(Conf,cout);cout<<endl;
169 cout<<"ComOfCut "<<ComOfCut<<endl;
170 debfctwesmess(iWESF);
174 if (ComOfCut) return;
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);
183 //modified by NIZHNY-MZV Fri Mar 17 12:51:03 2000
184 if(BRep_Tool::Degenerated(E))
187 // TopAbs_Orientation neworiE = FCit.Orientation(TB);
188 E.Orientation(neworiE);
190 const Handle(Geom2d_Curve)& PC = FCit.PCurve();
192 Standard_Boolean EhasPConFTF =
194 FC2D_HasCurveOnSurface(E,FTF);
195 //modified by NIZHNY-MZV Mon Mar 27 15:24:39 2000
197 myBuildTool.PCurve(FTF,E,PC);
199 Standard_Boolean EhasPConWESF = FC2D_HasCurveOnSurface(E,WESF);
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");
207 // Standard_Real tol = Max(tolE,tolpc);
210 myBuildTool.PCurve(WESF,E,C2D);
213 EhasPConWESF = FC2D_HasCurveOnSurface(E,WESF);
214 if (!EhasPConWESF) cout<<"TopOpeBRepBuild_Builder::GFillCurveTopologyWES : Null PCurve on F"<<iWESF<<endl;
219 if (tSPS) debaddpwes(iWESF,TB,iG,neworiE,(TopOpeBRepBuild_Builder* const)this,&WES,"GFillCurveTopology " ,"WES+ EofC ");
222 WES.AddStartElement(E);
225 } // GFillCurveTopologyWES