Integration of OCCT 6.5.0 from SVN
[occt.git] / src / HLRTest / HLRTest.cxx
CommitLineData
7fd59977 1// File: HLRTest.cxx
2// Created: Wed Apr 5 17:10:51 1995
3// Author: Christophe MARION
4// <cma@ecolox>
5
6#include <HLRTest.ixx>
7#include <HLRTest_Projector.hxx>
8#include <HLRTest_OutLiner.hxx>
9#include <TColStd_ListIteratorOfListOfInteger.hxx>
10#include <gp_Ax3.hxx>
11#include <Draw_Appli.hxx>
12#include <Draw.hxx>
13#include <DBRep.hxx>
14#include <HLRBRep_Algo.hxx>
15#include <HLRBRep_HLRToShape.hxx>
16static Handle(HLRBRep_Algo) hider;
17#ifdef WNT
18Standard_IMPORT Draw_Viewer dout;
19#endif
20
21#include <BRepTopAdaptor_MapOfShapeTool.hxx>
22
23//=======================================================================
24//function : Set
25//purpose :
26//=======================================================================
27void HLRTest::Set (const Standard_CString Name,
28 const HLRAlgo_Projector& P)
29{
30 Draw::Set(Name,new HLRTest_Projector(P));
31}
32
33//=======================================================================
34//function : GetProjector
35//purpose :
36//=======================================================================
37Standard_Boolean HLRTest::GetProjector (Standard_CString& Name,
38 HLRAlgo_Projector& P)
39{
40 Handle(HLRTest_Projector) HP =
41 Handle(HLRTest_Projector)::DownCast(Draw::Get(Name));
42 if (HP.IsNull()) return Standard_False;
43 P = HP->Projector();
44 return Standard_True;
45
46}
47
48//=======================================================================
49//function : Set
50//purpose :
51//=======================================================================
52
53void HLRTest::Set (const Standard_CString Name,
54 const TopoDS_Shape& S)
55{
56 Draw::Set(Name,new HLRTest_OutLiner(S));
57}
58
59//=======================================================================
60//function : GetOutLiner
61//purpose :
62//=======================================================================
63Handle(HLRTopoBRep_OutLiner) HLRTest::GetOutLiner (Standard_CString& Name)
64{
65 Handle(Draw_Drawable3D) D = Draw::Get(Name);
66 Handle(HLRTest_OutLiner) HS = Handle(HLRTest_OutLiner)::DownCast(D);
67 if (!HS.IsNull()) return HS->OutLiner();
68 Handle(HLRTopoBRep_OutLiner) HO;
69 return HO;
70}
71
72//=======================================================================
73//function : hprj
74//purpose :
75//=======================================================================
76
77static Standard_Integer
78hprj (Draw_Interpretor& , Standard_Integer n, const char** a)
79{
80 Standard_Integer id = 1;
81 if (n < 2) return 1;
82 if (n > 2) id = atoi(a[2]);
83 //
84 gp_Ax2 anAx2 = gp::XOY();
85 if (n == 11)
86 {
87 Standard_Real x = atof(a[2]);
88 Standard_Real y = atof(a[3]);
89 Standard_Real z = atof(a[4]);
90
91 Standard_Real dx = atof(a[5]);
92 Standard_Real dy = atof(a[6]);
93 Standard_Real dz = atof(a[7]);
94
95 Standard_Real dx1 = atof(a[8]);
96 Standard_Real dy1 = atof(a[9]);
97 Standard_Real dz1 = atof(a[10]);
98
99 gp_Pnt anOrigin (x, y, z);
100 gp_Dir aNormal (dx, dy, dz);
101 gp_Dir aDX (dx1, dy1, dz1);
102 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
103 }
104
105 HLRAlgo_Projector P(anAx2);
106 HLRTest::Set(a[1],P);
107 return 0;
108}
109
110//=======================================================================
111//function : hout
112//purpose :
113//=======================================================================
114
115static Standard_Integer
116hout (Draw_Interpretor& di, Standard_Integer n, const char** a)
117{
118 if (n < 2) return 1;
119 const char *name = a[2];
120 TopoDS_Shape S = DBRep::Get(name);
121 if (S.IsNull()) {
122 di << name << " is not a shape." << "\n";
123 return 1;
124 }
125 HLRTest::Set(a[1],S);
126 return 0;
127}
128
129//=======================================================================
130//function : hfil
131//purpose :
132//=======================================================================
133
134static Standard_Integer
135hfil (Draw_Interpretor& di, Standard_Integer n, const char** a)
136{
137 Standard_Integer nbIso = 0;
138 if (n < 3) return 1;
139 if (n > 3) nbIso = atoi(a[3]);
140 const char *name1 = a[1];
141 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name1);
142 if (HS.IsNull()) {
143 di << name1 << " is not an OutLiner." << "\n";
144 return 1;
145 }
146 const char *name2 = a[2];
147 HLRAlgo_Projector P;
148 if (!HLRTest::GetProjector(name2,P)) {
149 di << name2 << " is not a projector." << "\n";
150 return 1;
151 }
152 BRepTopAdaptor_MapOfShapeTool MST;
153 HS->Fill(P,MST,nbIso);
154 return 0;
155}
156
157//=======================================================================
158//function : sori
159//purpose :
160//=======================================================================
161
162static Standard_Integer
163sori (Draw_Interpretor& di, Standard_Integer n, const char** a)
164{
165 if (n < 3) return 1;
166 const char *name1 = a[1];
167 const char *name2 = a[2];
168 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name2);
169 if (HS.IsNull()) {
170 di << name2 << " is not an OutLiner." << "\n";
171 return 1;
172 }
173 DBRep::Set(name1,HS->OriginalShape());
174 return 0;
175}
176
177//=======================================================================
178//function : sout
179//purpose :
180//=======================================================================
181
182static Standard_Integer
183sout (Draw_Interpretor& di, Standard_Integer n, const char** a)
184{
185 if (n < 3) return 1;
186 const char *name1 = a[1];
187 const char *name2 = a[2];
188 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name2);
189 if (HS.IsNull()) {
190 di << name2 << " is not an OutLiner." << "\n";
191 return 1;
192 }
193 if (HS->OutLinedShape().IsNull()) {
194 di << name2 << " has no OutLinedShape." << "\n";
195 return 1;
196 }
197 DBRep::Set(name1,HS->OutLinedShape());
198 return 0;
199}
200
201//=======================================================================
202//function : hloa
203//purpose :
204//=======================================================================
205
206static Standard_Integer
207hloa (Draw_Interpretor& di, Standard_Integer n, const char** a)
208{
209 if (n < 2) return 1;
210 const char *name1 = a[1];
211 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name1);
212 if (HS.IsNull()) {
213 di << name1 << " is not an OutLiner." << "\n";
214 return 1;
215 }
216 hider->Load(HS);
217 return 0;
218}
219
220//=======================================================================
221//function : hrem
222//purpose :
223//=======================================================================
224
225static Standard_Integer
226hrem (Draw_Interpretor& di, Standard_Integer n, const char** a)
227{
228 if (n > 1) {
229 const char *name = a[1];
230 Standard_Integer index;
231 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name);
232 if (HS.IsNull()) {
233 TopoDS_Shape S = DBRep::Get(name);
234 if (S.IsNull()) {
235 di << name << " is not an OutLiner and not a shape." << "\n";
236 return 1;
237 }
238 else {
239 index = hider->Index(S);
240 if (index == 0) {
241 di << name << " not loaded shape." << "\n";
242 return 1;
243 }
244 }
245 }
246 else {
247 index = hider->Index(HS->OriginalShape());
248 if (index == 0) {
249 di << name << " not loaded outliner." << "\n";
250 return 1;
251 }
252 }
253 hider->Remove(index);
254 di << name << " removed" << "\n";
255 }
256 else {
257 while (hider->NbShapes() > 0) {
258 hider->Remove(1);
259 }
260 di << " all shapes removed" << "\n";
261 }
262 return 0;
263}
264
265//=======================================================================
266//function : sprj
267//purpose :
268//=======================================================================
269
270static Standard_Integer
271sprj (Draw_Interpretor& di, Standard_Integer n, const char** a)
272{
273 if (n < 2) return 1;
274 const char *name = a[1];
275 HLRAlgo_Projector P;
276 if (!HLRTest::GetProjector(name,P)) {
277 di << name << " is not a projector." << "\n";
278 return 1;
279 }
280 hider->Projector(P);
281 return 0;
282}
283
284//=======================================================================
285//function : upda
286//purpose :
287//=======================================================================
288
289static Standard_Integer
290upda (Draw_Interpretor& , Standard_Integer, const char**)
291{
292 hider->Update();
293 return 0;
294}
295
296//=======================================================================
297//function : hide
298//purpose :
299//=======================================================================
300
301static Standard_Integer
302hide (Draw_Interpretor& , Standard_Integer, const char**)
303{
304 hider->Hide();
305 return 0;
306}
307
308//=======================================================================
309//function : show
310//purpose :
311//=======================================================================
312
313static Standard_Integer
314show (Draw_Interpretor& , Standard_Integer, const char**)
315{
316 hider->ShowAll();
317 return 0;
318}
319
320//=======================================================================
321//function : hdbg
322//purpose :
323//=======================================================================
324
325static Standard_Integer
326hdbg (Draw_Interpretor& di, Standard_Integer, const char**)
327{
328 hider->Debug(!hider->Debug());
329 if (hider->Debug())
330 di << "debug" << "\n";
331 else
332 di << "no debug" << "\n";
333 return 0;
334}
335
336//=======================================================================
337//function : hnul
338//purpose :
339//=======================================================================
340
341static Standard_Integer
342hnul (Draw_Interpretor& , Standard_Integer, const char**)
343{
344 hider->OutLinedShapeNullify();
345 return 0;
346}
347
348//=======================================================================
349//function : hres
350//purpose :
351//=======================================================================
352
353static Standard_Integer
354hres (Draw_Interpretor& , Standard_Integer n, const char** a)
355{
356 TopoDS_Shape S,V,V1,VN,VO,VI,H,H1,HN,HO,HI;
357 if (n > 1) {
358 const char *name = a[1];
359 S = DBRep::Get(name);
360 }
361 HLRBRep_HLRToShape HS(hider);
362
363 if (S.IsNull()) {
364 V = HS.VCompound();
365 V1 = HS.Rg1LineVCompound();
366 VN = HS.RgNLineVCompound();
367 VO = HS.OutLineVCompound();
368 VI = HS.IsoLineVCompound();
369 H = HS.HCompound();
370 H1 = HS.Rg1LineHCompound();
371 HN = HS.RgNLineHCompound();
372 HO = HS.OutLineHCompound();
373 HI = HS.IsoLineHCompound();
374 }
375 else {
376 V = HS.VCompound(S);
377 V1 = HS.Rg1LineVCompound(S);
378 VN = HS.RgNLineVCompound(S);
379 VO = HS.OutLineVCompound(S);
380 VI = HS.IsoLineVCompound(S);
381 H = HS.HCompound(S);
382 H1 = HS.Rg1LineHCompound(S);
383 HN = HS.RgNLineHCompound(S);
384 HO = HS.OutLineHCompound(S);
385 HI = HS.IsoLineHCompound(S);
386 }
387 if (!V .IsNull()) DBRep::Set("vl",V);
388 if (!V1.IsNull()) DBRep::Set("v1l",V1);
389 if (!VN.IsNull()) DBRep::Set("vnl",VN);
390 if (!VO.IsNull()) DBRep::Set("vol",VO);
391 if (!VI.IsNull()) DBRep::Set("vil",VI);
392 if (!H .IsNull()) DBRep::Set("hl",H);
393 if (!H1.IsNull()) DBRep::Set("h1l",H1);
394 if (!HN.IsNull()) DBRep::Set("hnl",HN);
395 if (!HO.IsNull()) DBRep::Set("hol",HO);
396 if (!HI.IsNull()) DBRep::Set("hil",HI);
397 return 0;
398}
399
400//=======================================================================
401//function : Commands
402//purpose :
403//=======================================================================
404
405void HLRTest::Commands (Draw_Interpretor& theCommands)
406{
407 const char* g = "ADVALGOS HLR Commands";
408
409 theCommands.Add("hprj" ,"hprj name [view-id = 1]" ,__FILE__,hprj,g);
410 theCommands.Add("houtl" ,"houtl name shape" ,__FILE__,hout,g);
411 theCommands.Add("hfill" ,"hfill name proj [nbIso]" ,__FILE__,hfil,g);
412 theCommands.Add("hsin" ,"hsin name outliner" ,__FILE__,sori,g);
413 theCommands.Add("hsout" ,"hsout name outliner" ,__FILE__,sout,g);
414 theCommands.Add("hload" ,"hload outliner" ,__FILE__,hloa,g);
415 theCommands.Add("hremove" ,"hremove [name]" ,__FILE__,hrem,g);
416 theCommands.Add("hsetprj" ,"hsetprj [name]" ,__FILE__,sprj,g);
417 theCommands.Add("hupdate" ,"hupdate" ,__FILE__,upda,g);
418 theCommands.Add("hhide" ,"hhide" ,__FILE__,hide,g);
419 theCommands.Add("hshowall" ,"hshowall" ,__FILE__,show,g);
420 theCommands.Add("hdebug" ,"hdebug" ,__FILE__,hdbg,g);
421 theCommands.Add("hnullify" ,"hnullify" ,__FILE__,hnul,g);
422 theCommands.Add("hres2d" ,"hres2d" ,__FILE__,hres,g);
423 hider = new HLRBRep_Algo();
424}
425
426//=======================================================================
427//function : save and restore projector
428//purpose :
429//=======================================================================
430
431static Standard_Boolean stest(const Handle(Draw_Drawable3D)& d)
432{
433 return d->IsInstance(STANDARD_TYPE(HLRTest_Projector));
434}
435
436//=======================================================================
437//function : ssave
438//purpose :
439//=======================================================================
440
441static void ssave (const Handle(Draw_Drawable3D)&d, ostream& OS)
442{
443 Handle(HLRTest_Projector) HP =
444 Handle(HLRTest_Projector)::DownCast(d);
445
446 const HLRAlgo_Projector& P = HP->Projector();
447 OS << (P.Perspective() ? "1" : "0") << "\n";
448 if (P.Perspective())
449 OS << P.Focus() << "\n";
450
451 gp_Trsf T = P.Transformation();
452 gp_XYZ V = T.TranslationPart();
453 gp_Mat M = T.VectorialPart();
454
455 OS << M(1,1) << " ";
456 OS << M(1,2) << " ";
457 OS << M(1,3) << " ";
458 OS << V.Coord(1) << " ";
459 OS << "\n";
460 OS << M(2,1) << " ";
461 OS << M(2,2) << " ";
462 OS << M(2,3) << " ";
463 OS << V.Coord(2) << " ";
464 OS << "\n";
465 OS << M(3,1) << " ";
466 OS << M(3,2) << " ";
467 OS << M(3,3) << " ";
468 OS << V.Coord(3) << " ";
469 OS << "\n";
470
471}
472
473//=======================================================================
474//function : srestore
475//purpose :
476//=======================================================================
477
478static Handle(Draw_Drawable3D) srestore (istream& IS)
479{
480 Standard_Boolean pers;
481 IS >> pers;
482 Standard_Real focus = 1;
483 if (pers) IS >> focus;
484
485 gp_Trsf T;
486 Standard_Real V1[3],V2[3],V3[3];
487 Standard_Real V[3];
488
489 IS >> V1[0] >> V1[1] >> V1[2] >> V[0];
490 IS >> V2[0] >> V2[1] >> V2[2] >> V[1];
491 IS >> V3[0] >> V3[1] >> V3[2] >> V[2];
492
493 gp_Dir D1(V1[0],V1[1],V1[2]);
494 gp_Dir D2(V2[0],V2[1],V2[2]);
495 gp_Dir D3(V3[0],V3[1],V3[2]);
496 gp_Ax3 axes(gp_Pnt(0,0,0),D3,D1);
497 D3.Cross(D1);
498 if (D3.Dot(D2) < 0) axes.YReverse();
499 T.SetTransformation(axes);
500
501 T.SetTranslationPart(gp_Vec(V[0],V[1],V[2]));
502
503 HLRAlgo_Projector P(T,pers,focus);
504 Handle(HLRTest_Projector) HP = new HLRTest_Projector(P);
505 return HP;
506}
507
508//=======================================================================
509//function : ssr
510//purpose :
511//=======================================================================
512
513static Draw_SaveAndRestore ssr("HLRTest_Projector",stest,ssave,srestore);
514