0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / ChFi3d / ChFi3d_Debug.cxx
CommitLineData
b311480e 1// Created on: 1994-09-21
2// Created by: Laurent BOURESCHE
3// Copyright (c) 1994-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <stdio.h>
18
19#include <TopOpeBRepDS_DataStructure.hxx>
20#include <ChFiDS_SurfData.hxx>
21#include <TopOpeBRepDS_Surface.hxx>
22#include <BRep_Builder.hxx>
23#include <TopoDS_Vertex.hxx>
24#include <TopoDS_Edge.hxx>
25#include <TopoDS_Wire.hxx>
26#include <TopoDS_Face.hxx>
27#include <Geom_Surface.hxx>
28#include <Geom2d_Line.hxx>
29#include <gp_Pnt.hxx>
30#include <gp_Pnt2d.hxx>
31#include <gp_Dir.hxx>
32#include <gp_Dir2d.hxx>
33#include <gp_Vec.hxx>
34#include <gp_Vec2d.hxx>
35#include <gp_Ax1.hxx>
7fd59977 36
37#ifdef DRAW
38#include <DBRep.hxx>
39#endif
40
0797d9d3 41#ifdef OCCT_DEBUG
742cc8b0 42#include <OSD_Chronometer.hxx>
7fd59977 43OSD_Chronometer simul,elspine,chemine;
44#endif
45
46//*********************************
81bba717 47// timing of the simulation
7fd59977 48//*********************************
49
50static Standard_Boolean ChFi3d_traceCHRON = Standard_False;
51void ChFi3d_SettraceCHRON(const Standard_Boolean b)
52{ ChFi3d_traceCHRON = b; }
53Standard_Boolean ChFi3d_GettraceCHRON()
54{ return ChFi3d_traceCHRON; }
55
56//*********************************
81bba717 57// trace a line of path
7fd59977 58//*********************************
59
60static Standard_Boolean ChFi3d_traceDRAWWALK = Standard_False;
61void ChFi3d_SettraceDRAWWALK(const Standard_Boolean b)
62{ ChFi3d_traceDRAWWALK = b; }
63Standard_Boolean ChFi3d_GettraceDRAWWALK()
64{ return ChFi3d_traceDRAWWALK; }
65
66//**********************************
81bba717 67// trace a line of intersection
7fd59977 68//**********************************
69
70static Standard_Boolean ChFi3d_traceDRAWINT = Standard_False;
71void ChFi3d_SettraceDRAWINT(const Standard_Boolean b)
72{ ChFi3d_traceDRAWINT = b; }
73Standard_Boolean ChFi3d_GettraceDRAWINT()
74{ return ChFi3d_traceDRAWINT; }
75
76//*************************************************
81bba717 77// return surfaces of approximated fillets.
7fd59977 78//*************************************************
79
80static Standard_Boolean ChFi3d_traceDRAWFIL = Standard_False;
81void ChFi3d_SettraceDRAWFIL(const Standard_Boolean b)
82{ ChFi3d_traceDRAWFIL = b; }
83Standard_Boolean ChFi3d_GettraceDRAWFIL()
84{ return ChFi3d_traceDRAWFIL; }
85
86
87//*************************************************
81bba717 88// return extended faces for the path.
7fd59977 89//*************************************************
90
91static Standard_Boolean ChFi3d_traceDRAWENLARGE = Standard_False;
92void ChFi3d_SettraceDRAWENLARGE(const Standard_Boolean b)
93{ ChFi3d_traceDRAWENLARGE = b; }
94Standard_Boolean ChFi3d_GettraceDRAWENLARGE()
95{ return ChFi3d_traceDRAWENLARGE; }
96
97//*************************************************
81bba717 98// return the guideline for the triple corners.
7fd59977 99//*************************************************
100
101static Standard_Boolean ChFi3d_traceDRAWSPINE = Standard_False;
102void ChFi3d_SettraceDRAWSPINE(const Standard_Boolean b)
103{ ChFi3d_traceDRAWSPINE = b; }
104Standard_Boolean ChFi3d_GettraceDRAWSPINE()
105{ return ChFi3d_traceDRAWSPINE; }
106
107//*************************************************
81bba717 108// set the type of guideline for the triple corners.
7fd59977 109//*************************************************
110
111void ChFi3d_SetcontextSPINEBEZIER(const Standard_Boolean b);
112void ChFi3d_SetcontextSPINECIRCLE(const Standard_Boolean b);
113void ChFi3d_SetcontextSPINECE(const Standard_Boolean b);
114
115static Standard_Boolean ChFi3d_contextSPINEBEZIER = Standard_False;
116void ChFi3d_SetcontextSPINEBEZIER(const Standard_Boolean b){
117 ChFi3d_contextSPINEBEZIER = b;
118 if(b){
119 ChFi3d_SetcontextSPINECIRCLE(Standard_False);
120 ChFi3d_SetcontextSPINECE(Standard_False);
121 }
122}
123Standard_Boolean ChFi3d_GetcontextSPINEBEZIER()
124{ return ChFi3d_contextSPINEBEZIER; }
125
126static Standard_Boolean ChFi3d_contextSPINECIRCLE = Standard_False;
127void ChFi3d_SetcontextSPINECIRCLE(const Standard_Boolean b){
128 ChFi3d_contextSPINECIRCLE = b;
129 if(b){
130 ChFi3d_SetcontextSPINEBEZIER(Standard_False);
131 ChFi3d_SetcontextSPINECE(Standard_False);
132 }
133}
134Standard_Boolean ChFi3d_GetcontextSPINECIRCLE()
135{ return ChFi3d_contextSPINECIRCLE; }
136
137static Standard_Boolean ChFi3d_contextSPINECE = Standard_False;
138void ChFi3d_SetcontextSPINECE(const Standard_Boolean b){
139 ChFi3d_contextSPINECE = b;
140 if(b){
141 ChFi3d_SetcontextSPINEBEZIER(Standard_False);
142 ChFi3d_SetcontextSPINECIRCLE(Standard_False);
143 }
144}
145Standard_Boolean ChFi3d_GetcontextSPINECE()
146{ return ChFi3d_contextSPINECE; }
147
148//*************************************************
81bba717 149// Forced passage by the path for KPart
7fd59977 150//*************************************************
151static Standard_Boolean ChFi3d_contextFORCEBLEND = Standard_False;
152void ChFi3d_SetcontextFORCEBLEND(const Standard_Boolean b)
153{ ChFi3d_contextFORCEBLEND = b; }
154Standard_Boolean ChFi3d_GetcontextFORCEBLEND()
155{ return ChFi3d_contextFORCEBLEND; }
156
157static Standard_Boolean ChFi3d_contextFORCEFILLING = Standard_False;
158void ChFi3d_SetcontextFORCEFILLING(const Standard_Boolean b)
159{ ChFi3d_contextFORCEFILLING = b; }
160Standard_Boolean ChFi3d_GetcontextFORCEFILLING()
161{ return ChFi3d_contextFORCEFILLING; }
162
163//*************************************************
81bba717 164// No optimization for approx
7fd59977 165//*************************************************
166static Standard_Boolean ChFi3d_contextNOOPT = Standard_False;
167void ChFi3d_SetcontextNOOPT(const Standard_Boolean b)
168{ ChFi3d_contextNOOPT = b; }
169Standard_Boolean ChFi3d_GetcontextNOOPT()
170{ return ChFi3d_contextNOOPT; }
171
742cc8b0 172#ifdef OCCT_DEBUG
7fd59977 173// ***********************************************
81bba717 174// initialization and result of a chrono
7fd59977 175//************************************************
176Standard_EXPORT void ChFi3d_InitChron(OSD_Chronometer& ch)
177{
178 ch.Reset();
179 ch.Start();
180}
181
182Standard_EXPORT void ChFi3d_ResultChron( OSD_Chronometer & ch,
183 Standard_Real & time)
184{
185 Standard_Real tch ;
186 ch.Stop();
187 ch.Show(tch);
188 time=time +tch;
189}
742cc8b0 190#endif
7fd59977 191
192//==============================================================
193// function : ChFi3d_CheckSurfData
81bba717 194// purpose : function allows to trace SurfData to check
195// construction of all elements, namely pcurves
7fd59977 196//==============================================================
197#ifdef DRAW
198static Standard_Integer NbSD = 0;
199#endif
200void ChFi3d_CheckSurfData(const TopOpeBRepDS_DataStructure& DStr,
201 const Handle(ChFiDS_SurfData)& Data)
202{
81bba717 203 //trace of the surface defined by the chamfer or the fillet
204 // corresponding to SurfData
7fd59977 205
206 Handle(Geom_Surface) surf = (DStr.Surface( Data->Surf())).Surface();
207 if (!surf.IsNull()){
208 BRep_Builder B;
209 TopoDS_Face F;
210 B.MakeFace(F,surf,0.);
211 TopoDS_Wire W;
212 B.MakeWire(W);
213
214 TopoDS_Vertex V1,V2,V3,V4;
215 B.MakeVertex(V1,Data->VertexFirstOnS1().Point(),0.);
216 B.MakeVertex(V2,Data->VertexLastOnS1().Point(),0.);
217 B.MakeVertex(V3,Data->VertexLastOnS2().Point(),0.);
218 B.MakeVertex(V4,Data->VertexFirstOnS2().Point(),0.);
219
220 TopoDS_Edge E1,E2,E3,E4;
221 B.MakeEdge(E1);
222 B.MakeEdge(E2);
223 B.MakeEdge(E3);
224 B.MakeEdge(E4);
225
226 B.UpdateEdge(E1,Data->InterferenceOnS1().PCurveOnSurf(),F,0.);
227 B.UpdateEdge(E3,Data->InterferenceOnS2().PCurveOnSurf(),F,0.);
228 V1.Orientation(TopAbs_FORWARD);
229 B.Add(E1,V1);
230 B.UpdateVertex(V1,Data->InterferenceOnS1().FirstParameter(),E1,0.);
231 V2.Orientation(TopAbs_REVERSED);
232 B.Add(E1,V2);
233 B.UpdateVertex(V2,Data->InterferenceOnS1().LastParameter(),E1,0.);
234
235
236 V4.Orientation(TopAbs_FORWARD);
237 B.Add(E3,V4);
238 B.UpdateVertex(V4,Data->InterferenceOnS2().FirstParameter(),E3,0.);
239 V3.Orientation(TopAbs_REVERSED);
240 B.Add(E3,V3);
241 B.UpdateVertex(V3,Data->InterferenceOnS2().LastParameter(),E3,0.);
242
243 gp_Pnt2d pp1,pp2,pp3,pp4;
244 pp1 = Data->InterferenceOnS1().PCurveOnSurf()->
245 Value(Data->InterferenceOnS1().FirstParameter());
246 pp2 = Data->InterferenceOnS1().PCurveOnSurf()->
247 Value(Data->InterferenceOnS1().LastParameter());
248 pp3 = Data->InterferenceOnS2().PCurveOnSurf()->
249 Value(Data->InterferenceOnS2().LastParameter());
250 pp4 = Data->InterferenceOnS2().PCurveOnSurf()->
251 Value(Data->InterferenceOnS2().FirstParameter());
252 gp_Dir2d d1(gp_Vec2d(pp1,pp4));
253 gp_Dir2d d2(gp_Vec2d(pp2,pp3));
254 Handle(Geom2d_Line) l1 = new Geom2d_Line(pp1,d1);
255 Handle(Geom2d_Line) l2 = new Geom2d_Line(pp2,d2);
256
257 B.UpdateEdge(E4,l1,F,0.);
258 V1.Orientation(TopAbs_FORWARD);
259 B.Add(E4,V1);
260 B.UpdateVertex(V1,0.,E4,0.);
261 V4.Orientation(TopAbs_REVERSED);
262 B.Add(E4,V4);
263 B.UpdateVertex(V4,pp4.Distance(pp1),E4,0.);
264
265 B.UpdateEdge(E2,l2,F,0.);
266 V2.Orientation(TopAbs_FORWARD);
267 B.Add(E2,V2);
268 B.UpdateVertex(V2,0.,E2,0.);
269 V3.Orientation(TopAbs_REVERSED);
270 B.Add(E2,V3);
271 B.UpdateVertex(V3,pp3.Distance(pp2),E2,0.);
272
273 gp_Pnt pw1,pw2,ppp;
274 ppp = surf->Value(pp1.X(),pp1.Y());
275 pw1 = surf->Value(0.9*pp1.X()+0.1*pp2.X(),0.9*pp1.Y()+0.1*pp2.Y());
276 pw2 = surf->Value(0.9*pp1.X()+0.1*pp4.X(),0.9*pp1.Y()+0.1*pp4.Y());
277 gp_Vec vv1(ppp,pw1);
278 gp_Vec vv2(ppp,pw2);
279 gp_Vec Vwire = vv1^vv2;
280
281 surf->D1(pp1.X(),pp1.Y(),pw1,vv1,vv2);
282 gp_Vec Vsurf = vv1^vv2;
283 Standard_Boolean rev = Vsurf.Dot(Vwire)<=0.;
284
285 E1.Orientation(TopAbs_FORWARD);
286 E2.Orientation(TopAbs_FORWARD);
287 E3.Orientation(TopAbs_REVERSED);
288 E4.Orientation(TopAbs_REVERSED);
289 if(rev){
290 E1.Orientation(TopAbs_REVERSED);
291 E2.Orientation(TopAbs_REVERSED);
292 E3.Orientation(TopAbs_FORWARD);
293 E4.Orientation(TopAbs_FORWARD);
294 }
295 B.Add(W,E1);
296 B.Add(W,E2);
297 B.Add(W,E3);
298 B.Add(W,E4);
299
300 W.Orientation(TopAbs_FORWARD);
301 B.Add(F,W);
302
303#ifdef DRAW
304// char name[100];
305 char* name = new char[100];
306 sprintf(name,"fillet_%d",NbSD++);
307 DBRep::Set(name,F);
308#endif
309 }
310}