1 // Created on: 1995-04-05
2 // Created by: Christophe MARION
3 // Copyright (c) 1995-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
9 // under the terms of the GNU Lesser General Public 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.
17 #include <HLRTest.ixx>
18 #include <HLRTest_Projector.hxx>
19 #include <HLRTest_OutLiner.hxx>
20 #include <TColStd_ListIteratorOfListOfInteger.hxx>
22 #include <Draw_Appli.hxx>
25 #include <HLRBRep_Algo.hxx>
26 #include <HLRBRep_HLRToShape.hxx>
27 #include <HLRAppli_ReflectLines.hxx>
29 static Handle(HLRBRep_Algo) hider;
31 Standard_IMPORT Draw_Viewer dout;
34 #include <BRepTopAdaptor_MapOfShapeTool.hxx>
36 //=======================================================================
39 //=======================================================================
40 void HLRTest::Set (const Standard_CString Name,
41 const HLRAlgo_Projector& P)
43 Draw::Set(Name,new HLRTest_Projector(P));
46 //=======================================================================
47 //function : GetProjector
49 //=======================================================================
50 Standard_Boolean HLRTest::GetProjector (Standard_CString& Name,
53 Handle(HLRTest_Projector) HP =
54 Handle(HLRTest_Projector)::DownCast(Draw::Get(Name));
55 if (HP.IsNull()) return Standard_False;
61 //=======================================================================
64 //=======================================================================
66 void HLRTest::Set (const Standard_CString Name,
67 const TopoDS_Shape& S)
69 Draw::Set(Name,new HLRTest_OutLiner(S));
72 //=======================================================================
73 //function : GetOutLiner
75 //=======================================================================
76 Handle(HLRTopoBRep_OutLiner) HLRTest::GetOutLiner (Standard_CString& Name)
78 Handle(Draw_Drawable3D) D = Draw::Get(Name);
79 Handle(HLRTest_OutLiner) HS = Handle(HLRTest_OutLiner)::DownCast(D);
80 if (!HS.IsNull()) return HS->OutLiner();
81 Handle(HLRTopoBRep_OutLiner) HO;
85 //=======================================================================
88 //=======================================================================
90 static Standard_Integer
91 hprj (Draw_Interpretor& , Standard_Integer n, const char** a)
95 gp_Ax2 anAx2 = gp::XOY();
98 Standard_Real x = Draw::Atof(a[2]);
99 Standard_Real y = Draw::Atof(a[3]);
100 Standard_Real z = Draw::Atof(a[4]);
102 Standard_Real dx = Draw::Atof(a[5]);
103 Standard_Real dy = Draw::Atof(a[6]);
104 Standard_Real dz = Draw::Atof(a[7]);
106 Standard_Real dx1 = Draw::Atof(a[8]);
107 Standard_Real dy1 = Draw::Atof(a[9]);
108 Standard_Real dz1 = Draw::Atof(a[10]);
110 gp_Pnt anOrigin (x, y, z);
111 gp_Dir aNormal (dx, dy, dz);
112 gp_Dir aDX (dx1, dy1, dz1);
113 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
116 HLRAlgo_Projector P(anAx2);
117 HLRTest::Set(a[1],P);
121 //=======================================================================
124 //=======================================================================
126 static Standard_Integer
127 hout (Draw_Interpretor& di, Standard_Integer n, const char** a)
130 const char *name = a[2];
131 TopoDS_Shape S = DBRep::Get(name);
133 di << name << " is not a shape." << "\n";
136 HLRTest::Set(a[1],S);
140 //=======================================================================
143 //=======================================================================
145 static Standard_Integer
146 hfil (Draw_Interpretor& di, Standard_Integer n, const char** a)
148 Standard_Integer nbIso = 0;
150 if (n > 3) nbIso = Draw::Atoi(a[3]);
151 const char *name1 = a[1];
152 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name1);
154 di << name1 << " is not an OutLiner." << "\n";
157 const char *name2 = a[2];
159 if (!HLRTest::GetProjector(name2,P)) {
160 di << name2 << " is not a projector." << "\n";
163 BRepTopAdaptor_MapOfShapeTool MST;
164 HS->Fill(P,MST,nbIso);
168 //=======================================================================
171 //=======================================================================
173 static Standard_Integer
174 sori (Draw_Interpretor& di, Standard_Integer n, const char** a)
177 const char *name1 = a[1];
178 const char *name2 = a[2];
179 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name2);
181 di << name2 << " is not an OutLiner." << "\n";
184 DBRep::Set(name1,HS->OriginalShape());
188 //=======================================================================
191 //=======================================================================
193 static Standard_Integer
194 sout (Draw_Interpretor& di, Standard_Integer n, const char** a)
197 const char *name1 = a[1];
198 const char *name2 = a[2];
199 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name2);
201 di << name2 << " is not an OutLiner." << "\n";
204 if (HS->OutLinedShape().IsNull()) {
205 di << name2 << " has no OutLinedShape." << "\n";
208 DBRep::Set(name1,HS->OutLinedShape());
212 //=======================================================================
215 //=======================================================================
217 static Standard_Integer
218 hloa (Draw_Interpretor& di, Standard_Integer n, const char** a)
221 const char *name1 = a[1];
222 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name1);
224 di << name1 << " is not an OutLiner." << "\n";
231 //=======================================================================
234 //=======================================================================
236 static Standard_Integer
237 hrem (Draw_Interpretor& di, Standard_Integer n, const char** a)
240 const char *name = a[1];
241 Standard_Integer index;
242 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name);
244 TopoDS_Shape S = DBRep::Get(name);
246 di << name << " is not an OutLiner and not a shape." << "\n";
250 index = hider->Index(S);
252 di << name << " not loaded shape." << "\n";
258 index = hider->Index(HS->OriginalShape());
260 di << name << " not loaded outliner." << "\n";
264 hider->Remove(index);
265 di << name << " removed" << "\n";
268 while (hider->NbShapes() > 0) {
271 di << " all shapes removed" << "\n";
276 //=======================================================================
279 //=======================================================================
281 static Standard_Integer
282 sprj (Draw_Interpretor& di, Standard_Integer n, const char** a)
285 const char *name = a[1];
287 if (!HLRTest::GetProjector(name,P)) {
288 di << name << " is not a projector." << "\n";
295 //=======================================================================
298 //=======================================================================
300 static Standard_Integer
301 upda (Draw_Interpretor& , Standard_Integer, const char**)
307 //=======================================================================
310 //=======================================================================
312 static Standard_Integer
313 hide (Draw_Interpretor& , Standard_Integer, const char**)
319 //=======================================================================
322 //=======================================================================
324 static Standard_Integer
325 show (Draw_Interpretor& , Standard_Integer, const char**)
331 //=======================================================================
334 //=======================================================================
336 static Standard_Integer
337 hdbg (Draw_Interpretor& di, Standard_Integer, const char**)
339 hider->Debug(!hider->Debug());
341 di << "debug" << "\n";
343 di << "no debug" << "\n";
347 //=======================================================================
350 //=======================================================================
352 static Standard_Integer
353 hnul (Draw_Interpretor& , Standard_Integer, const char**)
355 hider->OutLinedShapeNullify();
359 //=======================================================================
362 //=======================================================================
364 static Standard_Integer
365 hres (Draw_Interpretor& , Standard_Integer n, const char** a)
367 TopoDS_Shape S,V,V1,VN,VO,VI,H,H1,HN,HO,HI;
369 const char *name = a[1];
370 S = DBRep::Get(name);
372 HLRBRep_HLRToShape HS(hider);
376 V1 = HS.Rg1LineVCompound();
377 VN = HS.RgNLineVCompound();
378 VO = HS.OutLineVCompound();
379 VI = HS.IsoLineVCompound();
381 H1 = HS.Rg1LineHCompound();
382 HN = HS.RgNLineHCompound();
383 HO = HS.OutLineHCompound();
384 HI = HS.IsoLineHCompound();
388 V1 = HS.Rg1LineVCompound(S);
389 VN = HS.RgNLineVCompound(S);
390 VO = HS.OutLineVCompound(S);
391 VI = HS.IsoLineVCompound(S);
393 H1 = HS.Rg1LineHCompound(S);
394 HN = HS.RgNLineHCompound(S);
395 HO = HS.OutLineHCompound(S);
396 HI = HS.IsoLineHCompound(S);
398 if (!V .IsNull()) DBRep::Set("vl",V);
399 if (!V1.IsNull()) DBRep::Set("v1l",V1);
400 if (!VN.IsNull()) DBRep::Set("vnl",VN);
401 if (!VO.IsNull()) DBRep::Set("vol",VO);
402 if (!VI.IsNull()) DBRep::Set("vil",VI);
403 if (!H .IsNull()) DBRep::Set("hl",H);
404 if (!H1.IsNull()) DBRep::Set("h1l",H1);
405 if (!HN.IsNull()) DBRep::Set("hnl",HN);
406 if (!HO.IsNull()) DBRep::Set("hol",HO);
407 if (!HI.IsNull()) DBRep::Set("hil",HI);
411 //=======================================================================
412 //function : reflectlines
414 //=======================================================================
416 static Standard_Integer reflectlines(Draw_Interpretor& , Standard_Integer n, const char** a)
421 TopoDS_Shape aShape = DBRep::Get(a[2]);
425 Standard_Real anAISViewProjX = atof(a[3]);
426 Standard_Real anAISViewProjY = atof(a[4]);
427 Standard_Real anAISViewProjZ = atof(a[5]);
429 gp_Pnt anOrigin(0.,0.,0.);
430 gp_Dir aNormal(anAISViewProjX, anAISViewProjY, anAISViewProjZ);
431 gp_Ax2 theAxes(anOrigin, aNormal);
432 gp_Dir aDX = theAxes.XDirection();
434 HLRAppli_ReflectLines Reflector(aShape);
436 Reflector.SetAxes(aNormal.X(), aNormal.Y(), aNormal.Z(),
437 anOrigin.X(), anOrigin.Y(), anOrigin.Z(),
438 aDX.X(), aDX.Y(), aDX.Z());
442 TopoDS_Shape Result = Reflector.GetResult();
443 DBRep::Set(a[1], Result);
448 //=======================================================================
449 //function : Commands
451 //=======================================================================
453 void HLRTest::Commands (Draw_Interpretor& theCommands)
455 const char* g = "ADVALGOS HLR Commands";
457 theCommands.Add("hprj" ,"hprj name [view-id = 1]" ,__FILE__,hprj,g);
458 theCommands.Add("houtl" ,"houtl name shape" ,__FILE__,hout,g);
459 theCommands.Add("hfill" ,"hfill name proj [nbIso]" ,__FILE__,hfil,g);
460 theCommands.Add("hsin" ,"hsin name outliner" ,__FILE__,sori,g);
461 theCommands.Add("hsout" ,"hsout name outliner" ,__FILE__,sout,g);
462 theCommands.Add("hload" ,"hload outliner" ,__FILE__,hloa,g);
463 theCommands.Add("hremove" ,"hremove [name]" ,__FILE__,hrem,g);
464 theCommands.Add("hsetprj" ,"hsetprj [name]" ,__FILE__,sprj,g);
465 theCommands.Add("hupdate" ,"hupdate" ,__FILE__,upda,g);
466 theCommands.Add("hhide" ,"hhide" ,__FILE__,hide,g);
467 theCommands.Add("hshowall" ,"hshowall" ,__FILE__,show,g);
468 theCommands.Add("hdebug" ,"hdebug" ,__FILE__,hdbg,g);
469 theCommands.Add("hnullify" ,"hnullify" ,__FILE__,hnul,g);
470 theCommands.Add("hres2d" ,"hres2d" ,__FILE__,hres,g);
472 theCommands.Add("reflectlines",
473 "reflectlines res shape proj_X proj_Y proj_Z",
474 __FILE__, reflectlines, g);
476 hider = new HLRBRep_Algo();
479 //=======================================================================
480 //function : save and restore projector
482 //=======================================================================
484 static Standard_Boolean stest(const Handle(Draw_Drawable3D)& d)
486 return d->IsInstance(STANDARD_TYPE(HLRTest_Projector));
489 //=======================================================================
492 //=======================================================================
494 static void ssave (const Handle(Draw_Drawable3D)&d, ostream& OS)
496 Handle(HLRTest_Projector) HP =
497 Handle(HLRTest_Projector)::DownCast(d);
499 const HLRAlgo_Projector& P = HP->Projector();
500 OS << (P.Perspective() ? "1" : "0") << "\n";
502 OS << P.Focus() << "\n";
504 gp_Trsf T = P.Transformation();
505 gp_XYZ V = T.TranslationPart();
506 gp_Mat M = T.VectorialPart();
511 OS << V.Coord(1) << " ";
516 OS << V.Coord(2) << " ";
521 OS << V.Coord(3) << " ";
526 //=======================================================================
527 //function : srestore
529 //=======================================================================
531 static Handle(Draw_Drawable3D) srestore (istream& IS)
533 Standard_Boolean pers;
535 Standard_Real focus = 1;
536 if (pers) IS >> focus;
539 Standard_Real V1[3],V2[3],V3[3];
542 IS >> V1[0] >> V1[1] >> V1[2] >> V[0];
543 IS >> V2[0] >> V2[1] >> V2[2] >> V[1];
544 IS >> V3[0] >> V3[1] >> V3[2] >> V[2];
546 gp_Dir D1(V1[0],V1[1],V1[2]);
547 gp_Dir D2(V2[0],V2[1],V2[2]);
548 gp_Dir D3(V3[0],V3[1],V3[2]);
549 gp_Ax3 axes(gp_Pnt(0,0,0),D3,D1);
551 if (D3.Dot(D2) < 0) axes.YReverse();
552 T.SetTransformation(axes);
554 T.SetTranslationPart(gp_Vec(V[0],V[1],V[2]));
556 HLRAlgo_Projector P(T,pers,focus);
557 Handle(HLRTest_Projector) HP = new HLRTest_Projector(P);
561 //=======================================================================
564 //=======================================================================
566 static Draw_SaveAndRestore ssr("HLRTest_Projector",stest,ssave,srestore);