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 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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
20 #include <Draw_Appli.hxx>
22 #include <HLRAlgo_Projector.hxx>
23 #include <HLRAppli_ReflectLines.hxx>
24 #include <HLRBRep_Algo.hxx>
25 #include <HLRBRep_HLRToShape.hxx>
26 #include <HLRTest.hxx>
27 #include <HLRTest_OutLiner.hxx>
28 #include <HLRTest_Projector.hxx>
29 #include <HLRTopoBRep_OutLiner.hxx>
30 #include <TColStd_ListIteratorOfListOfInteger.hxx>
31 #include <TopoDS_Shape.hxx>
33 static Handle(HLRBRep_Algo) hider;
35 Standard_IMPORT Draw_Viewer dout;
38 #include <BRepTopAdaptor_MapOfShapeTool.hxx>
40 //=======================================================================
43 //=======================================================================
44 void HLRTest::Set (const Standard_CString Name,
45 const HLRAlgo_Projector& P)
47 Draw::Set(Name,new HLRTest_Projector(P));
50 //=======================================================================
51 //function : GetProjector
53 //=======================================================================
54 Standard_Boolean HLRTest::GetProjector (Standard_CString& Name,
57 Handle(HLRTest_Projector) HP =
58 Handle(HLRTest_Projector)::DownCast(Draw::Get(Name));
59 if (HP.IsNull()) return Standard_False;
65 //=======================================================================
68 //=======================================================================
70 void HLRTest::Set (const Standard_CString Name,
71 const TopoDS_Shape& S)
73 Draw::Set(Name,new HLRTest_OutLiner(S));
76 //=======================================================================
77 //function : GetOutLiner
79 //=======================================================================
80 Handle(HLRTopoBRep_OutLiner) HLRTest::GetOutLiner (Standard_CString& Name)
82 Handle(Draw_Drawable3D) D = Draw::Get(Name);
83 Handle(HLRTest_OutLiner) HS = Handle(HLRTest_OutLiner)::DownCast(D);
84 if (!HS.IsNull()) return HS->OutLiner();
85 Handle(HLRTopoBRep_OutLiner) HO;
89 //=======================================================================
92 //=======================================================================
94 static Standard_Integer
95 hprj (Draw_Interpretor& , Standard_Integer n, const char** a)
99 gp_Ax2 anAx2 = gp::XOY();
102 Standard_Real x = Draw::Atof(a[2]);
103 Standard_Real y = Draw::Atof(a[3]);
104 Standard_Real z = Draw::Atof(a[4]);
106 Standard_Real dx = Draw::Atof(a[5]);
107 Standard_Real dy = Draw::Atof(a[6]);
108 Standard_Real dz = Draw::Atof(a[7]);
110 Standard_Real dx1 = Draw::Atof(a[8]);
111 Standard_Real dy1 = Draw::Atof(a[9]);
112 Standard_Real dz1 = Draw::Atof(a[10]);
114 gp_Pnt anOrigin (x, y, z);
115 gp_Dir aNormal (dx, dy, dz);
116 gp_Dir aDX (dx1, dy1, dz1);
117 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
120 HLRAlgo_Projector P(anAx2);
121 HLRTest::Set(a[1],P);
125 //=======================================================================
128 //=======================================================================
130 static Standard_Integer
131 hout (Draw_Interpretor& di, Standard_Integer n, const char** a)
134 const char *name = a[2];
135 TopoDS_Shape S = DBRep::Get(name);
137 di << name << " is not a shape.\n";
140 HLRTest::Set(a[1],S);
144 //=======================================================================
147 //=======================================================================
149 static Standard_Integer
150 hfil (Draw_Interpretor& di, Standard_Integer n, const char** a)
152 Standard_Integer nbIso = 0;
154 if (n > 3) nbIso = Draw::Atoi(a[3]);
155 const char *name1 = a[1];
156 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name1);
158 di << name1 << " is not an OutLiner.\n";
161 const char *name2 = a[2];
163 if (!HLRTest::GetProjector(name2,P)) {
164 di << name2 << " is not a projector.\n";
167 BRepTopAdaptor_MapOfShapeTool MST;
168 HS->Fill(P,MST,nbIso);
172 //=======================================================================
175 //=======================================================================
177 static Standard_Integer
178 sori (Draw_Interpretor& di, Standard_Integer n, const char** a)
181 const char *name1 = a[1];
182 const char *name2 = a[2];
183 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name2);
185 di << name2 << " is not an OutLiner.\n";
188 DBRep::Set(name1,HS->OriginalShape());
192 //=======================================================================
195 //=======================================================================
197 static Standard_Integer
198 sout (Draw_Interpretor& di, Standard_Integer n, const char** a)
201 const char *name1 = a[1];
202 const char *name2 = a[2];
203 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name2);
205 di << name2 << " is not an OutLiner.\n";
208 if (HS->OutLinedShape().IsNull()) {
209 di << name2 << " has no OutLinedShape.\n";
212 DBRep::Set(name1,HS->OutLinedShape());
216 //=======================================================================
219 //=======================================================================
221 static Standard_Integer
222 hloa (Draw_Interpretor& di, Standard_Integer n, const char** a)
225 const char *name1 = a[1];
226 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name1);
228 di << name1 << " is not an OutLiner.\n";
235 //=======================================================================
238 //=======================================================================
240 static Standard_Integer
241 hrem (Draw_Interpretor& di, Standard_Integer n, const char** a)
244 const char *name = a[1];
245 Standard_Integer index;
246 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name);
248 TopoDS_Shape S = DBRep::Get(name);
250 di << name << " is not an OutLiner and not a shape.\n";
254 index = hider->Index(S);
256 di << name << " not loaded shape.\n";
262 index = hider->Index(HS->OriginalShape());
264 di << name << " not loaded outliner.\n";
268 hider->Remove(index);
269 di << name << " removed\n";
272 while (hider->NbShapes() > 0) {
275 di << " all shapes removed\n";
280 //=======================================================================
283 //=======================================================================
285 static Standard_Integer
286 sprj (Draw_Interpretor& di, Standard_Integer n, const char** a)
289 const char *name = a[1];
291 if (!HLRTest::GetProjector(name,P)) {
292 di << name << " is not a projector.\n";
299 //=======================================================================
302 //=======================================================================
304 static Standard_Integer
305 upda (Draw_Interpretor& , Standard_Integer, const char**)
311 //=======================================================================
314 //=======================================================================
316 static Standard_Integer
317 hide (Draw_Interpretor& , Standard_Integer, const char**)
323 //=======================================================================
326 //=======================================================================
328 static Standard_Integer
329 show (Draw_Interpretor& , Standard_Integer, const char**)
335 //=======================================================================
338 //=======================================================================
340 static Standard_Integer
341 hdbg (Draw_Interpretor& di, Standard_Integer, const char**)
343 hider->Debug(!hider->Debug());
351 //=======================================================================
354 //=======================================================================
356 static Standard_Integer
357 hnul (Draw_Interpretor& , Standard_Integer, const char**)
359 hider->OutLinedShapeNullify();
363 //=======================================================================
366 //=======================================================================
368 static Standard_Integer
369 hres (Draw_Interpretor& , Standard_Integer n, const char** a)
371 TopoDS_Shape S,V,V1,VN,VO,VI,H,H1,HN,HO,HI;
373 const char *name = a[1];
374 S = DBRep::Get(name);
376 HLRBRep_HLRToShape HS(hider);
380 V1 = HS.Rg1LineVCompound();
381 VN = HS.RgNLineVCompound();
382 VO = HS.OutLineVCompound();
383 VI = HS.IsoLineVCompound();
385 H1 = HS.Rg1LineHCompound();
386 HN = HS.RgNLineHCompound();
387 HO = HS.OutLineHCompound();
388 HI = HS.IsoLineHCompound();
392 V1 = HS.Rg1LineVCompound(S);
393 VN = HS.RgNLineVCompound(S);
394 VO = HS.OutLineVCompound(S);
395 VI = HS.IsoLineVCompound(S);
397 H1 = HS.Rg1LineHCompound(S);
398 HN = HS.RgNLineHCompound(S);
399 HO = HS.OutLineHCompound(S);
400 HI = HS.IsoLineHCompound(S);
402 if (!V .IsNull()) DBRep::Set("vl",V);
403 if (!V1.IsNull()) DBRep::Set("v1l",V1);
404 if (!VN.IsNull()) DBRep::Set("vnl",VN);
405 if (!VO.IsNull()) DBRep::Set("vol",VO);
406 if (!VI.IsNull()) DBRep::Set("vil",VI);
407 if (!H .IsNull()) DBRep::Set("hl",H);
408 if (!H1.IsNull()) DBRep::Set("h1l",H1);
409 if (!HN.IsNull()) DBRep::Set("hnl",HN);
410 if (!HO.IsNull()) DBRep::Set("hol",HO);
411 if (!HI.IsNull()) DBRep::Set("hil",HI);
415 //=======================================================================
416 //function : reflectlines
418 //=======================================================================
420 static Standard_Integer reflectlines(Draw_Interpretor& , Standard_Integer n, const char** a)
425 TopoDS_Shape aShape = DBRep::Get(a[2]);
429 Standard_Real anAISViewProjX = atof(a[3]);
430 Standard_Real anAISViewProjY = atof(a[4]);
431 Standard_Real anAISViewProjZ = atof(a[5]);
433 gp_Pnt anOrigin(0.,0.,0.);
434 gp_Dir aNormal(anAISViewProjX, anAISViewProjY, anAISViewProjZ);
435 gp_Ax2 theAxes(anOrigin, aNormal);
436 gp_Dir aDX = theAxes.XDirection();
438 HLRAppli_ReflectLines Reflector(aShape);
440 Reflector.SetAxes(aNormal.X(), aNormal.Y(), aNormal.Z(),
441 anOrigin.X(), anOrigin.Y(), anOrigin.Z(),
442 aDX.X(), aDX.Y(), aDX.Z());
446 TopoDS_Shape Result = Reflector.GetResult();
447 DBRep::Set(a[1], Result);
452 //=======================================================================
453 //function : Commands
455 //=======================================================================
457 void HLRTest::Commands (Draw_Interpretor& theCommands)
459 const char* g = "ADVALGOS HLR Commands";
461 theCommands.Add("hprj" ,"hprj name [view-id = 1]" ,__FILE__,hprj,g);
462 theCommands.Add("houtl" ,"houtl name shape" ,__FILE__,hout,g);
463 theCommands.Add("hfill" ,"hfill name proj [nbIso]" ,__FILE__,hfil,g);
464 theCommands.Add("hsin" ,"hsin name outliner" ,__FILE__,sori,g);
465 theCommands.Add("hsout" ,"hsout name outliner" ,__FILE__,sout,g);
466 theCommands.Add("hload" ,"hload outliner" ,__FILE__,hloa,g);
467 theCommands.Add("hremove" ,"hremove [name]" ,__FILE__,hrem,g);
468 theCommands.Add("hsetprj" ,"hsetprj [name]" ,__FILE__,sprj,g);
469 theCommands.Add("hupdate" ,"hupdate" ,__FILE__,upda,g);
470 theCommands.Add("hhide" ,"hhide" ,__FILE__,hide,g);
471 theCommands.Add("hshowall" ,"hshowall" ,__FILE__,show,g);
472 theCommands.Add("hdebug" ,"hdebug" ,__FILE__,hdbg,g);
473 theCommands.Add("hnullify" ,"hnullify" ,__FILE__,hnul,g);
474 theCommands.Add("hres2d" ,"hres2d" ,__FILE__,hres,g);
476 theCommands.Add("reflectlines",
477 "reflectlines res shape proj_X proj_Y proj_Z",
478 __FILE__, reflectlines, g);
480 hider = new HLRBRep_Algo();
483 //=======================================================================
484 //function : save and restore projector
486 //=======================================================================
488 static Standard_Boolean stest(const Handle(Draw_Drawable3D)& d)
490 return d->IsInstance(STANDARD_TYPE(HLRTest_Projector));
493 //=======================================================================
496 //=======================================================================
498 static void ssave (const Handle(Draw_Drawable3D)&d, ostream& OS)
500 Handle(HLRTest_Projector) HP =
501 Handle(HLRTest_Projector)::DownCast(d);
503 const HLRAlgo_Projector& P = HP->Projector();
504 OS << (P.Perspective() ? "1" : "0") << "\n";
506 OS << P.Focus() << "\n";
508 gp_Trsf T = P.Transformation();
509 gp_XYZ V = T.TranslationPart();
510 gp_Mat M = T.VectorialPart();
515 OS << V.Coord(1) << " ";
520 OS << V.Coord(2) << " ";
525 OS << V.Coord(3) << " ";
530 //=======================================================================
531 //function : srestore
533 //=======================================================================
535 static Handle(Draw_Drawable3D) srestore (istream& IS)
537 Standard_Boolean pers;
539 Standard_Real focus = 1;
540 if (pers) IS >> focus;
543 Standard_Real V1[3],V2[3],V3[3];
546 IS >> V1[0] >> V1[1] >> V1[2] >> V[0];
547 IS >> V2[0] >> V2[1] >> V2[2] >> V[1];
548 IS >> V3[0] >> V3[1] >> V3[2] >> V[2];
550 gp_Dir D1(V1[0],V1[1],V1[2]);
551 gp_Dir D2(V2[0],V2[1],V2[2]);
552 gp_Dir D3(V3[0],V3[1],V3[2]);
553 gp_Ax3 axes(gp_Pnt(0,0,0),D3,D1);
555 if (D3.Dot(D2) < 0) axes.YReverse();
556 T.SetTransformation(axes);
558 T.SetTranslationPart(gp_Vec(V[0],V[1],V[2]));
560 HLRAlgo_Projector P(T,pers,focus);
561 Handle(HLRTest_Projector) HP = new HLRTest_Projector(P);
565 //=======================================================================
568 //=======================================================================
570 static Draw_SaveAndRestore ssr("HLRTest_Projector",stest,ssave,srestore);