0024157: Parallelization of assembly part of BO
[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-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 #include <TopOpeBRep_FFDumper.ixx>
23 #include <TopExp_Explorer.hxx>
24 #include <TopAbs.hxx>
25 #include <TopOpeBRep_FacesIntersector.hxx>
26 #include <TopOpeBRep_VPointInterIterator.hxx>
27 #include <TopOpeBRep_VPointInter.hxx>
28 #include <TopOpeBRep.hxx>
29 #include <TopoDS.hxx>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopOpeBRepTool_ShapeTool.hxx>
34 #include <BRep_Tool.hxx>
35 #include <TopOpeBRep_FFTransitionTool.hxx>
36 #include <gp_Dir.hxx>
37 #include <gp_Pnt.hxx>
38 #include <TopOpeBRep_FacesFiller.hxx>
39 #include <TopOpeBRep_define.hxx>
40 #include <IntPatch_GLine.hxx>
41
42 #ifdef DEB
43 extern Standard_Boolean TopOpeBRepDS_GettraceDSNC(); 
44 extern Standard_Boolean TopOpeBRepDS_GettraceDSF(); 
45 extern Standard_Boolean TopOpeBRepDS_GettraceDSFK(); 
46 static TCollection_AsciiString PRODINP("dinp ");
47 #endif
48
49 //=======================================================================
50 //function : TopOpeBRep_FFDumper
51 //purpose  : 
52 //=======================================================================
53 #ifndef DEB
54 TopOpeBRep_FFDumper::TopOpeBRep_FFDumper(const TopOpeBRep_PFacesFiller& )
55 {
56 #else
57 TopOpeBRep_FFDumper::TopOpeBRep_FFDumper(const TopOpeBRep_PFacesFiller& PFF)
58 {
59   Init(PFF);
60 #endif
61 }
62
63 //=======================================================================
64 //function : Init
65 //purpose  : 
66 //=======================================================================
67 #ifndef DEB
68 void TopOpeBRep_FFDumper::Init(const TopOpeBRep_PFacesFiller& )
69 {
70 #else
71 void TopOpeBRep_FFDumper::Init(const TopOpeBRep_PFacesFiller& PFF)
72 {
73   myPFF = PFF;
74   const TopoDS_Face& fpff1 = myPFF->Face(1);
75   const TopoDS_Face& fpff2 = myPFF->Face(2);
76   Standard_Boolean f1diff = (!myF1.IsEqual(fpff1));
77   Standard_Boolean f2diff = (!myF2.IsEqual(fpff2));
78   Standard_Boolean init = f1diff || f2diff;
79   if (init) {
80     myF1 = myPFF->Face(1);
81     myF2 = myPFF->Face(2);
82     myEM1.Clear(); myEn1 = 0;
83     myEM2.Clear(); myEn2 = 0;
84     TopExp_Explorer x;
85     for (x.Init(myF1,TopAbs_EDGE);x.More();x.Next()) myEM1.Bind(x.Current(),++myEn1);
86     for (x.Init(myF2,TopAbs_EDGE);x.More();x.Next()) myEM2.Bind(x.Current(),++myEn2);
87     myLineIndex = 0;
88   }
89 #endif
90 }
91
92 //=======================================================================
93 //function : DumpLine
94 //purpose  : 
95 //=======================================================================
96 #ifndef DEB
97 void TopOpeBRep_FFDumper::DumpLine(const Standard_Integer )
98 {
99 #else
100 void TopOpeBRep_FFDumper::DumpLine(const Standard_Integer I)
101 {
102   const TopOpeBRep_LineInter& L = myPFF->ChangeFacesIntersector().ChangeLine(I);
103   DumpLine(L);
104 #endif
105 }
106
107 //=======================================================================
108 //function : DumpLine
109 //purpose  : 
110 //=======================================================================
111 #ifndef DEB
112 void TopOpeBRep_FFDumper::DumpLine(const TopOpeBRep_LineInter& )
113 {
114 #else
115 void TopOpeBRep_FFDumper::DumpLine(const TopOpeBRep_LineInter& LI)
116 {
117   Standard_Integer il = LI.Index();
118   myLineIndex = il;
119   Standard_Integer nl = myPFF->ChangeFacesIntersector().NbLines();
120   Standard_Boolean HasVPonR = LI.HasVPonR();
121   Standard_Boolean IsVClosed  = LI.IsVClosed();
122   Standard_Boolean IsPeriodic = LI.IsPeriodic();
123   Standard_Boolean isrest = (LI.TypeLineCurve() == TopOpeBRep_RESTRICTION);
124   
125   cout<<endl<<"--------------------------------------------------"<<endl;
126   cout<<"line "<<il<<"/"<<nl<<" is a "; LI.DumpType(); 
127   if ( isrest) { 
128     Standard_Boolean isedge1 = LI.ArcIsEdge(1);
129     Standard_Boolean isedge2 = LI.ArcIsEdge(2);
130     if      ( isedge1 ) cout<<" of 1";
131     else if ( isedge2 ) cout<<" of 2";
132     else cout<<"of 0(BUG)";
133   }
134   cout<<endl;
135   if ( isrest) { 
136     const TopoDS_Shape& Erest = LI.Arc();
137     Standard_Boolean FIisrest = myPFF->ChangeFacesIntersector().IsRestriction(Erest);
138     cout<<"++++ line restriction"; 
139     if (FIisrest) {
140       cout<<" edge restriction";
141       Standard_Integer iErest = 0; 
142       if (myPFF->ChangeDataStructure().HasShape(Erest)) 
143         iErest = myPFF->ChangeDataStructure().Shape(Erest);
144       cout<<" "<<iErest;
145     }
146     cout<<endl;
147   }
148   if (HasVPonR) cout<<"has vertex on restriction"<<endl;
149   else         cout<<"has no vertex on restriction"<<endl;
150   if (IsVClosed)  cout<<"is closed by vertices"<<endl;
151   else         cout<<"is not closed by vertices"<<endl;
152   if (IsPeriodic) cout<<"is periodic"<<endl;
153   else         cout<<"is not periodic"<<endl;
154   
155   TopOpeBRep_VPointInterIterator VPI;
156   
157   VPI.Init(LI); if (VPI.More()) cout<<endl;
158   for (;VPI.More();VPI.Next()) {
159     TCollection_AsciiString stol("; #draw ");
160     stol = stol + VPI.CurrentVP().Tolerance() + "\n";
161     LI.DumpVPoint(VPI.CurrentVPIndex(),PRODINP,stol);
162   }
163   
164   VPI.Init(LI);
165   if (VPI.More()) cout<<endl;
166   for (;VPI.More();VPI.Next()) {
167     const TopOpeBRep_VPointInter& VP = VPI.CurrentVP();
168     Standard_Boolean dump = VP.Keep() || TopOpeBRepDS_GettraceDSFK();
169     if (dump) { DumpVP(VP); cout<<endl; }
170   }
171   
172   if (LI.TypeLineCurve() == TopOpeBRep_LINE) {
173     gp_Dir D = LI.LineG()->Line().Direction();
174     TopOpeBRep::Print(LI.TypeLineCurve(),cout); Standard_Real x,y,z; D.Coord(x,y,z);
175     cout<<" dir : "<<x<<" "<<y<<" "<<z<<endl;
176   }
177   
178   LI.DumpLineTransitions(cout);
179   
180   cout<<endl<<"--------------------------------------------------"<<endl;
181 #endif
182 }
183
184 //=======================================================================
185 //function : DumpVP
186 //purpose  : 
187 //=======================================================================
188 #ifndef DEB
189 void TopOpeBRep_FFDumper::DumpVP(const TopOpeBRep_VPointInter& )
190 {
191 #else
192 void TopOpeBRep_FFDumper::DumpVP(const TopOpeBRep_VPointInter& VP)
193 {
194   Standard_Integer il = myLineIndex;
195   cout<<"VP "<<VP.Index()<<" on "<<VP.ShapeIndex()<<" :";
196   Standard_Real Cpar = VP.ParameterOnLine(); cout<<" on curve : "<<Cpar; 
197   if (!VP.Keep()) cout<<" NOT kept";
198   cout<<endl;
199   Standard_Boolean k = VP.Keep();
200   const gp_Pnt& P = VP.Value();
201   cout<<PRODINP<<"L"<<il<<"P"<<VP.Index();if (k) cout<<"K";cout<<" "<<P.X()<<" "<<P.Y()<<" "<<P.Z();
202   cout<<"; #draw"<<endl;
203   
204   if (TopOpeBRepDS_GettraceDSFK()) { 
205     Standard_Real u,v;
206     VP.ParametersOnS1(u,v); cout<<"u1,v1 : "<<u<<" "<<v; cout<<"   ";
207     VP.ParametersOnS2(u,v); cout<<"u2,v2 : "<<u<<" "<<v; cout<<endl;
208   }
209   
210   if      (VP.ShapeIndex() == 1) 
211     DumpVP(VP,1);
212   else if (VP.ShapeIndex() == 2)
213     DumpVP(VP,2);
214   else if (VP.ShapeIndex() == 3) {
215     DumpVP(VP,1);
216     DumpVP(VP,2);
217   }
218 #endif
219 }
220
221 //=======================================================================
222 //function : DumpVP
223 //purpose  : 
224 //=======================================================================
225 #ifndef DEB
226 void TopOpeBRep_FFDumper::DumpVP(const TopOpeBRep_VPointInter& ,const Standard_Integer )
227 {
228 #else
229 void TopOpeBRep_FFDumper::DumpVP(const TopOpeBRep_VPointInter& VP,const Standard_Integer ISI)
230 {
231   const Handle(TopOpeBRepDS_HDataStructure)& HDS = myPFF->HDataStructure();
232   const TopoDS_Edge& E = TopoDS::Edge(VP.Edge(ISI)); 
233   Standard_Real Epar = VP.EdgeParameter(ISI);
234   TopAbs_Orientation O = E.Orientation(); 
235   TopOpeBRepDS_Transition T = TopOpeBRep_FFTransitionTool::ProcessLineTransition(VP,ISI,O);
236   const TopoDS_Face F = myPFF->Face(ISI);
237   Standard_Boolean Closed = TopOpeBRepTool_ShapeTool::Closed(E,F);
238   Standard_Boolean Degen = BRep_Tool::Degenerated(E);
239   Standard_Integer exi = ExploreIndex(E,ISI);
240   Standard_Integer dsi = (HDS->HasShape(E)) ? HDS->Shape(E) : 0;
241   Standard_Boolean isv = VP.IsVertex(ISI);
242   if (isv) cout<<"is vertex of "<<ISI<<endl;
243   if (Closed) cout<<"on closing edge "; else cout<<"on edge "; 
244   if (Degen) cout<<" on degenerated edge ";
245   TopAbs::Print(O,cout); cout<<" (ds"<<dsi<<") (ex"<<exi<<") of face of "<<ISI;
246   cout<<" : par : "<<Epar<<endl;  
247   if (Closed) cout<<"on closing edge "; else cout<<"on edge "; 
248   if (Degen) cout<<" on degenerated edge ";
249   TopAbs::Print(O,cout); cout<<" (ds"<<dsi<<") (ex"<<exi<<") of face of "<<ISI;
250   cout<<" : line transition : ";T.Dump(cout);cout<<endl;
251 #endif
252 }
253
254 //=======================================================================
255 //function : ExploreIndex
256 //purpose  : 
257 //=======================================================================
258 #ifndef DEB
259 Standard_Integer TopOpeBRep_FFDumper::ExploreIndex(const TopoDS_Shape& , const Standard_Integer ) const
260 {
261     return 0;
262 }
263 #else
264 Standard_Integer TopOpeBRep_FFDumper::ExploreIndex(const TopoDS_Shape& S, const Standard_Integer ISI) const
265 {
266   Standard_Integer r = 0;
267   if (ISI == 1) r = myEM1.Find(S);
268   if (ISI == 2) r = myEM2.Find(S);
269   return r;
270 }
271 #endif
272
273 //=======================================================================
274 //function : DumpDSP
275 //purpose  : 
276 //=======================================================================
277 #ifndef DEB
278 void TopOpeBRep_FFDumper::DumpDSP(const TopOpeBRep_VPointInter& ,const TopOpeBRepDS_Kind ,const Standard_Integer ,
279                                   const Standard_Boolean ) const
280 {
281 #else
282 void TopOpeBRep_FFDumper::DumpDSP(const TopOpeBRep_VPointInter& VP,const TopOpeBRepDS_Kind GK,const Standard_Integer G,
283                                   const Standard_Boolean newinDS) const
284 {
285   cout<<"VP "<<VP.Index()<<" on "<<VP.ShapeIndex();
286   if (newinDS) {
287     if      (GK == TopOpeBRepDS_VERTEX) cout<<" gives new DSV";
288     else if (GK == TopOpeBRepDS_POINT)  cout<<" gives new DSP";
289     else                                cout<<" gives new DS???";
290   }
291   else {
292     if      (GK == TopOpeBRepDS_VERTEX) cout<<" equals new DSV";
293     else if (GK == TopOpeBRepDS_POINT)  cout<<" equals new DSP";
294     else                                cout<<" equals new DS???";
295   }
296   cout<<" "<<G;
297   
298   const Handle(TopOpeBRepDS_HDataStructure)& HDS = myPFF->HDataStructure();
299   Standard_Real tol = Precision::Confusion();
300   if      (GK == TopOpeBRepDS_VERTEX) tol = BRep_Tool::Tolerance(TopoDS::Vertex(HDS->Shape(G)));
301   else if (GK == TopOpeBRepDS_POINT)  tol = HDS->Point(G).Tolerance();
302   cout<<" tol = "<<tol;
303   cout<<endl;
304 #endif
305 }
306
307 TopOpeBRep_PFacesFiller TopOpeBRep_FFDumper::PFacesFillerDummy() const {return myPFF;}