0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / TopOpeBRep / TopOpeBRep_FFDumper.cxx
1 // Created on: 1996-10-23
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_Dir.hxx>
20 #include <gp_Pnt.hxx>
21 #include <IntPatch_GLine.hxx>
22 #include <Standard_Type.hxx>
23 #include <TopAbs.hxx>
24 #include <TopExp_Explorer.hxx>
25 #include <TopoDS.hxx>
26 #include <TopoDS_Edge.hxx>
27 #include <TopoDS_Face.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <TopOpeBRep.hxx>
30 #include <TopOpeBRep_define.hxx>
31 #include <TopOpeBRep_FacesFiller.hxx>
32 #include <TopOpeBRep_FacesIntersector.hxx>
33 #include <TopOpeBRep_FFDumper.hxx>
34 #include <TopOpeBRep_FFTransitionTool.hxx>
35 #include <TopOpeBRep_LineInter.hxx>
36 #include <TopOpeBRep_VPointInter.hxx>
37 #include <TopOpeBRep_VPointInterIterator.hxx>
38 #include <TopOpeBRepTool_ShapeTool.hxx>
39
40 IMPLEMENT_STANDARD_RTTIEXT(TopOpeBRep_FFDumper,Standard_Transient)
41
42 #ifdef OCCT_DEBUG
43 static TCollection_AsciiString PRODINP("dinp ");
44 #endif
45
46 //=======================================================================
47 //function : TopOpeBRep_FFDumper
48 //purpose  : 
49 //=======================================================================
50 #ifndef OCCT_DEBUG
51 TopOpeBRep_FFDumper::TopOpeBRep_FFDumper(const TopOpeBRep_PFacesFiller& )
52 {
53 #else
54 TopOpeBRep_FFDumper::TopOpeBRep_FFDumper(const TopOpeBRep_PFacesFiller& PFF)
55 {
56   Init(PFF);
57 #endif
58 }
59
60 //=======================================================================
61 //function : Init
62 //purpose  : 
63 //=======================================================================
64 #ifndef OCCT_DEBUG
65 void TopOpeBRep_FFDumper::Init(const TopOpeBRep_PFacesFiller& )
66 {
67   // just shut up compiler warnings
68   (void)myEn1;
69   (void)myEn2;
70   (void)myLineIndex;
71 }
72 #else
73 void TopOpeBRep_FFDumper::Init(const TopOpeBRep_PFacesFiller& PFF)
74 {
75   myPFF = PFF;
76   const TopoDS_Face& fpff1 = myPFF->Face(1);
77   const TopoDS_Face& fpff2 = myPFF->Face(2);
78   Standard_Boolean f1diff = (!myF1.IsEqual(fpff1));
79   Standard_Boolean f2diff = (!myF2.IsEqual(fpff2));
80   Standard_Boolean init = f1diff || f2diff;
81   if (init) {
82     myF1 = myPFF->Face(1);
83     myF2 = myPFF->Face(2);
84     myEM1.Clear(); myEn1 = 0;
85     myEM2.Clear(); myEn2 = 0;
86     TopExp_Explorer x;
87     for (x.Init(myF1,TopAbs_EDGE);x.More();x.Next()) myEM1.Bind(x.Current(),++myEn1);
88     for (x.Init(myF2,TopAbs_EDGE);x.More();x.Next()) myEM2.Bind(x.Current(),++myEn2);
89     myLineIndex = 0;
90   }
91 }
92 #endif
93
94 //=======================================================================
95 //function : DumpLine
96 //purpose  : 
97 //=======================================================================
98 #ifndef OCCT_DEBUG
99 void TopOpeBRep_FFDumper::DumpLine(const Standard_Integer )
100 {
101 #else
102 void TopOpeBRep_FFDumper::DumpLine(const Standard_Integer I)
103 {
104   const TopOpeBRep_LineInter& L = myPFF->ChangeFacesIntersector().ChangeLine(I);
105   DumpLine(L);
106 #endif
107 }
108
109 //=======================================================================
110 //function : DumpLine
111 //purpose  : 
112 //=======================================================================
113 #ifndef OCCT_DEBUG
114 void TopOpeBRep_FFDumper::DumpLine(const TopOpeBRep_LineInter& )
115 {
116 #else
117 void TopOpeBRep_FFDumper::DumpLine(const TopOpeBRep_LineInter& LI)
118 {
119   Standard_Integer il = LI.Index();
120   myLineIndex = il;
121   Standard_Integer nl = myPFF->ChangeFacesIntersector().NbLines();
122   Standard_Boolean HasVPonR = LI.HasVPonR();
123   Standard_Boolean IsVClosed  = LI.IsVClosed();
124   Standard_Boolean IsPeriodic = LI.IsPeriodic();
125   Standard_Boolean isrest = (LI.TypeLineCurve() == TopOpeBRep_RESTRICTION);
126   
127   std::cout<<std::endl<<"--------------------------------------------------"<<std::endl;
128   std::cout<<"line "<<il<<"/"<<nl<<" is a "; LI.DumpType(); 
129   if ( isrest) { 
130     Standard_Boolean isedge1 = LI.ArcIsEdge(1);
131     Standard_Boolean isedge2 = LI.ArcIsEdge(2);
132     if      ( isedge1 ) std::cout<<" of 1";
133     else if ( isedge2 ) std::cout<<" of 2";
134     else std::cout<<"of 0(BUG)";
135   }
136   std::cout<<std::endl;
137   if ( isrest) { 
138     const TopoDS_Shape& Erest = LI.Arc();
139     Standard_Boolean FIisrest = myPFF->ChangeFacesIntersector().IsRestriction(Erest);
140     std::cout<<"++++ line restriction"; 
141     if (FIisrest) {
142       std::cout<<" edge restriction";
143       Standard_Integer iErest = 0; 
144       if (myPFF->ChangeDataStructure().HasShape(Erest)) 
145         iErest = myPFF->ChangeDataStructure().Shape(Erest);
146       std::cout<<" "<<iErest;
147     }
148     std::cout<<std::endl;
149   }
150   if (HasVPonR) std::cout<<"has vertex on restriction"<<std::endl;
151   else         std::cout<<"has no vertex on restriction"<<std::endl;
152   if (IsVClosed)  std::cout<<"is closed by vertices"<<std::endl;
153   else         std::cout<<"is not closed by vertices"<<std::endl;
154   if (IsPeriodic) std::cout<<"is periodic"<<std::endl;
155   else         std::cout<<"is not periodic"<<std::endl;
156   
157   TopOpeBRep_VPointInterIterator VPI;
158   
159   VPI.Init(LI); if (VPI.More()) std::cout<<std::endl;
160   for (;VPI.More();VPI.Next()) {
161     TCollection_AsciiString stol("; #draw ");
162     stol = stol + VPI.CurrentVP().Tolerance() + "\n";
163     LI.DumpVPoint(VPI.CurrentVPIndex(),PRODINP,stol);
164   }
165   
166   VPI.Init(LI);
167   if (VPI.More()) std::cout<<std::endl;
168   for (;VPI.More();VPI.Next()) {
169     const TopOpeBRep_VPointInter& VP = VPI.CurrentVP();
170     Standard_Boolean dump = VP.Keep();
171     if (dump) { DumpVP(VP); std::cout<<std::endl; }
172   }
173   
174   if (LI.TypeLineCurve() == TopOpeBRep_LINE) {
175     gp_Dir D = LI.LineG()->Line().Direction();
176     TopOpeBRep::Print(LI.TypeLineCurve(),std::cout); Standard_Real x,y,z; D.Coord(x,y,z);
177     std::cout<<" dir : "<<x<<" "<<y<<" "<<z<<std::endl;
178   }
179   
180   LI.DumpLineTransitions(std::cout);
181   
182   std::cout<<std::endl<<"--------------------------------------------------"<<std::endl;
183 #endif
184 }
185
186 //=======================================================================
187 //function : DumpVP
188 //purpose  : 
189 //=======================================================================
190 #ifndef OCCT_DEBUG
191 void TopOpeBRep_FFDumper::DumpVP(const TopOpeBRep_VPointInter& )
192 {
193 #else
194 void TopOpeBRep_FFDumper::DumpVP(const TopOpeBRep_VPointInter& VP)
195 {
196   Standard_Integer il = myLineIndex;
197   std::cout<<"VP "<<VP.Index()<<" on "<<VP.ShapeIndex()<<" :";
198   Standard_Real Cpar = VP.ParameterOnLine(); std::cout<<" on curve : "<<Cpar; 
199   if (!VP.Keep()) std::cout<<" NOT kept";
200   std::cout<<std::endl;
201   Standard_Boolean k = VP.Keep();
202   const gp_Pnt& P = VP.Value();
203   std::cout<<PRODINP<<"L"<<il<<"P"<<VP.Index();if (k) std::cout<<"K";std::cout<<" "<<P.X()<<" "<<P.Y()<<" "<<P.Z();
204   std::cout<<"; #draw"<<std::endl;
205   
206   if      (VP.ShapeIndex() == 1) 
207     DumpVP(VP,1);
208   else if (VP.ShapeIndex() == 2)
209     DumpVP(VP,2);
210   else if (VP.ShapeIndex() == 3) {
211     DumpVP(VP,1);
212     DumpVP(VP,2);
213   }
214 #endif
215 }
216
217 //=======================================================================
218 //function : DumpVP
219 //purpose  : 
220 //=======================================================================
221 #ifndef OCCT_DEBUG
222 void TopOpeBRep_FFDumper::DumpVP(const TopOpeBRep_VPointInter& ,const Standard_Integer )
223 {
224 #else
225 void TopOpeBRep_FFDumper::DumpVP(const TopOpeBRep_VPointInter& VP,const Standard_Integer ISI)
226 {
227   const Handle(TopOpeBRepDS_HDataStructure)& HDS = myPFF->HDataStructure();
228   const TopoDS_Edge& E = TopoDS::Edge(VP.Edge(ISI)); 
229   Standard_Real Epar = VP.EdgeParameter(ISI);
230   TopAbs_Orientation O = E.Orientation(); 
231   TopOpeBRep_FFTransitionTool::ProcessLineTransition(VP,ISI,O);
232   const TopoDS_Face F = myPFF->Face(ISI);
233   Standard_Boolean Closed = TopOpeBRepTool_ShapeTool::Closed(E,F);
234   Standard_Boolean Degen = BRep_Tool::Degenerated(E);
235   Standard_Integer exi = ExploreIndex(E,ISI);
236   Standard_Integer dsi = (HDS->HasShape(E)) ? HDS->Shape(E) : 0;
237   Standard_Boolean isv = VP.IsVertex(ISI);
238   if (isv) std::cout<<"is vertex of "<<ISI<<std::endl;
239   if (Closed) std::cout<<"on closing edge "; else std::cout<<"on edge "; 
240   if (Degen) std::cout<<" on degenerated edge ";
241   TopAbs::Print(O,std::cout); std::cout<<" (ds"<<dsi<<") (ex"<<exi<<") of face of "<<ISI;
242   std::cout<<" : par : "<<Epar<<std::endl;  
243   if (Closed) std::cout<<"on closing edge "; else std::cout<<"on edge "; 
244   if (Degen) std::cout<<" on degenerated edge ";
245   TopAbs::Print(O,std::cout); std::cout<<" (ds"<<dsi<<") (ex"<<exi<<") of face of "<<ISI;
246 #endif
247 }
248
249 //=======================================================================
250 //function : ExploreIndex
251 //purpose  : 
252 //=======================================================================
253 #ifndef OCCT_DEBUG
254 Standard_Integer TopOpeBRep_FFDumper::ExploreIndex(const TopoDS_Shape& , const Standard_Integer ) const
255 {
256     return 0;
257 }
258 #else
259 Standard_Integer TopOpeBRep_FFDumper::ExploreIndex(const TopoDS_Shape& S, const Standard_Integer ISI) const
260 {
261   Standard_Integer r = 0;
262   if (ISI == 1) r = myEM1.Find(S);
263   if (ISI == 2) r = myEM2.Find(S);
264   return r;
265 }
266 #endif
267
268 //=======================================================================
269 //function : DumpDSP
270 //purpose  : 
271 //=======================================================================
272 #ifndef OCCT_DEBUG
273 void TopOpeBRep_FFDumper::DumpDSP(const TopOpeBRep_VPointInter& ,const TopOpeBRepDS_Kind ,const Standard_Integer ,
274                                   const Standard_Boolean ) const
275 {
276 #else
277 void TopOpeBRep_FFDumper::DumpDSP(const TopOpeBRep_VPointInter& VP,const TopOpeBRepDS_Kind GK,const Standard_Integer G,
278                                   const Standard_Boolean newinDS) const
279 {
280   std::cout<<"VP "<<VP.Index()<<" on "<<VP.ShapeIndex();
281   if (newinDS) {
282     if      (GK == TopOpeBRepDS_VERTEX) std::cout<<" gives new DSV";
283     else if (GK == TopOpeBRepDS_POINT)  std::cout<<" gives new DSP";
284     else                                std::cout<<" gives new DS???";
285   }
286   else {
287     if      (GK == TopOpeBRepDS_VERTEX) std::cout<<" equals new DSV";
288     else if (GK == TopOpeBRepDS_POINT)  std::cout<<" equals new DSP";
289     else                                std::cout<<" equals new DS???";
290   }
291   std::cout<<" "<<G;
292   
293   const Handle(TopOpeBRepDS_HDataStructure)& HDS = myPFF->HDataStructure();
294   Standard_Real tol = Precision::Confusion();
295   if      (GK == TopOpeBRepDS_VERTEX) tol = BRep_Tool::Tolerance(TopoDS::Vertex(HDS->Shape(G)));
296   else if (GK == TopOpeBRepDS_POINT)  tol = HDS->Point(G).Tolerance();
297   std::cout<<" tol = "<<tol;
298   std::cout<<std::endl;
299 #endif
300 }
301
302 TopOpeBRep_PFacesFiller TopOpeBRep_FFDumper::PFacesFillerDummy() const {return myPFF;}