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>
32 #include <TopoDS_Compound.hxx>
33 #include <BRep_Builder.hxx>
35 static Handle(HLRBRep_Algo) hider;
37 Standard_IMPORT Draw_Viewer dout;
40 #include <BRepTopAdaptor_MapOfShapeTool.hxx>
42 //=======================================================================
45 //=======================================================================
46 void HLRTest::Set (const Standard_CString Name,
47 const HLRAlgo_Projector& P)
49 Draw::Set(Name,new HLRTest_Projector(P));
52 //=======================================================================
53 //function : GetProjector
55 //=======================================================================
56 Standard_Boolean HLRTest::GetProjector (Standard_CString& Name,
59 Handle(HLRTest_Projector) HP =
60 Handle(HLRTest_Projector)::DownCast(Draw::Get(Name));
61 if (HP.IsNull()) return Standard_False;
67 //=======================================================================
70 //=======================================================================
72 void HLRTest::Set (const Standard_CString Name,
73 const TopoDS_Shape& S)
75 Draw::Set(Name,new HLRTest_OutLiner(S));
78 //=======================================================================
79 //function : GetOutLiner
81 //=======================================================================
82 Handle(HLRTopoBRep_OutLiner) HLRTest::GetOutLiner (Standard_CString& Name)
84 Handle(Draw_Drawable3D) D = Draw::Get(Name);
85 Handle(HLRTest_OutLiner) HS = Handle(HLRTest_OutLiner)::DownCast(D);
86 if (!HS.IsNull()) return HS->OutLiner();
87 Handle(HLRTopoBRep_OutLiner) HO;
91 //=======================================================================
94 //=======================================================================
96 static Standard_Integer
97 hprj (Draw_Interpretor& , Standard_Integer n, const char** a)
101 gp_Ax2 anAx2 = gp::XOY();
104 Standard_Real x = Draw::Atof(a[2]);
105 Standard_Real y = Draw::Atof(a[3]);
106 Standard_Real z = Draw::Atof(a[4]);
108 Standard_Real dx = Draw::Atof(a[5]);
109 Standard_Real dy = Draw::Atof(a[6]);
110 Standard_Real dz = Draw::Atof(a[7]);
112 Standard_Real dx1 = Draw::Atof(a[8]);
113 Standard_Real dy1 = Draw::Atof(a[9]);
114 Standard_Real dz1 = Draw::Atof(a[10]);
116 gp_Pnt anOrigin (x, y, z);
117 gp_Dir aNormal (dx, dy, dz);
118 gp_Dir aDX (dx1, dy1, dz1);
119 anAx2 = gp_Ax2(anOrigin, aNormal, aDX);
122 HLRAlgo_Projector P(anAx2);
123 HLRTest::Set(a[1],P);
127 //=======================================================================
130 //=======================================================================
132 static Standard_Integer
133 hout (Draw_Interpretor& di, Standard_Integer n, const char** a)
136 const char *name = a[2];
137 TopoDS_Shape S = DBRep::Get(name);
139 di << name << " is not a shape.\n";
142 HLRTest::Set(a[1],S);
146 //=======================================================================
149 //=======================================================================
151 static Standard_Integer
152 hfil (Draw_Interpretor& di, Standard_Integer n, const char** a)
154 Standard_Integer nbIso = 0;
156 if (n > 3) nbIso = Draw::Atoi(a[3]);
157 const char *name1 = a[1];
158 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name1);
160 di << name1 << " is not an OutLiner.\n";
163 const char *name2 = a[2];
165 if (!HLRTest::GetProjector(name2,P)) {
166 di << name2 << " is not a projector.\n";
169 BRepTopAdaptor_MapOfShapeTool MST;
170 HS->Fill(P,MST,nbIso);
174 //=======================================================================
177 //=======================================================================
179 static Standard_Integer
180 sori (Draw_Interpretor& di, Standard_Integer n, const char** a)
183 const char *name1 = a[1];
184 const char *name2 = a[2];
185 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name2);
187 di << name2 << " is not an OutLiner.\n";
190 DBRep::Set(name1,HS->OriginalShape());
194 //=======================================================================
197 //=======================================================================
199 static Standard_Integer
200 sout (Draw_Interpretor& di, Standard_Integer n, const char** a)
203 const char *name1 = a[1];
204 const char *name2 = a[2];
205 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name2);
207 di << name2 << " is not an OutLiner.\n";
210 if (HS->OutLinedShape().IsNull()) {
211 di << name2 << " has no OutLinedShape.\n";
214 DBRep::Set(name1,HS->OutLinedShape());
218 //=======================================================================
221 //=======================================================================
223 static Standard_Integer
224 hloa (Draw_Interpretor& di, Standard_Integer n, const char** a)
227 const char *name1 = a[1];
228 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name1);
230 di << name1 << " is not an OutLiner.\n";
237 //=======================================================================
240 //=======================================================================
242 static Standard_Integer
243 hrem (Draw_Interpretor& di, Standard_Integer n, const char** a)
246 const char *name = a[1];
247 Standard_Integer index;
248 Handle(HLRTopoBRep_OutLiner) HS = HLRTest::GetOutLiner(name);
250 TopoDS_Shape S = DBRep::Get(name);
252 di << name << " is not an OutLiner and not a shape.\n";
256 index = hider->Index(S);
258 di << name << " not loaded shape.\n";
264 index = hider->Index(HS->OriginalShape());
266 di << name << " not loaded outliner.\n";
270 hider->Remove(index);
271 di << name << " removed\n";
274 while (hider->NbShapes() > 0) {
277 di << " all shapes removed\n";
282 //=======================================================================
285 //=======================================================================
287 static Standard_Integer
288 sprj (Draw_Interpretor& di, Standard_Integer n, const char** a)
291 const char *name = a[1];
293 if (!HLRTest::GetProjector(name,P)) {
294 di << name << " is not a projector.\n";
301 //=======================================================================
304 //=======================================================================
306 static Standard_Integer
307 upda (Draw_Interpretor& , Standard_Integer, const char**)
313 //=======================================================================
316 //=======================================================================
318 static Standard_Integer
319 hide (Draw_Interpretor& , Standard_Integer, const char**)
325 //=======================================================================
328 //=======================================================================
330 static Standard_Integer
331 show (Draw_Interpretor& , Standard_Integer, const char**)
337 //=======================================================================
340 //=======================================================================
342 static Standard_Integer
343 hdbg (Draw_Interpretor& di, Standard_Integer, const char**)
345 hider->Debug(!hider->Debug());
353 //=======================================================================
356 //=======================================================================
358 static Standard_Integer
359 hnul (Draw_Interpretor& , Standard_Integer, const char**)
361 hider->OutLinedShapeNullify();
365 //=======================================================================
368 //=======================================================================
370 static Standard_Integer
371 hres (Draw_Interpretor& , Standard_Integer n, const char** a)
373 TopoDS_Shape S,V,V1,VN,VO,VI,H,H1,HN,HO,HI;
375 const char *name = a[1];
376 S = DBRep::Get(name);
378 HLRBRep_HLRToShape HS(hider);
382 V1 = HS.Rg1LineVCompound();
383 VN = HS.RgNLineVCompound();
384 VO = HS.OutLineVCompound();
385 VI = HS.IsoLineVCompound();
387 H1 = HS.Rg1LineHCompound();
388 HN = HS.RgNLineHCompound();
389 HO = HS.OutLineHCompound();
390 HI = HS.IsoLineHCompound();
394 V1 = HS.Rg1LineVCompound(S);
395 VN = HS.RgNLineVCompound(S);
396 VO = HS.OutLineVCompound(S);
397 VI = HS.IsoLineVCompound(S);
399 H1 = HS.Rg1LineHCompound(S);
400 HN = HS.RgNLineHCompound(S);
401 HO = HS.OutLineHCompound(S);
402 HI = HS.IsoLineHCompound(S);
404 if (!V .IsNull()) DBRep::Set("vl",V);
405 if (!V1.IsNull()) DBRep::Set("v1l",V1);
406 if (!VN.IsNull()) DBRep::Set("vnl",VN);
407 if (!VO.IsNull()) DBRep::Set("vol",VO);
408 if (!VI.IsNull()) DBRep::Set("vil",VI);
409 if (!H .IsNull()) DBRep::Set("hl",H);
410 if (!H1.IsNull()) DBRep::Set("h1l",H1);
411 if (!HN.IsNull()) DBRep::Set("hnl",HN);
412 if (!HO.IsNull()) DBRep::Set("hol",HO);
413 if (!HI.IsNull()) DBRep::Set("hil",HI);
417 //=======================================================================
418 //function : reflectlines
420 //=======================================================================
422 static Standard_Integer reflectlines(Draw_Interpretor& , Standard_Integer n, const char** a)
427 TopoDS_Shape aShape = DBRep::Get(a[2]);
431 Standard_Real anAISViewProjX = atof(a[3]);
432 Standard_Real anAISViewProjY = atof(a[4]);
433 Standard_Real anAISViewProjZ = atof(a[5]);
435 gp_Pnt anOrigin(0.,0.,0.);
436 gp_Dir aNormal(anAISViewProjX, anAISViewProjY, anAISViewProjZ);
437 gp_Ax2 theAxes(anOrigin, aNormal);
438 gp_Dir aDX = theAxes.XDirection();
440 HLRAppli_ReflectLines Reflector(aShape);
442 Reflector.SetAxes(aNormal.X(), aNormal.Y(), aNormal.Z(),
443 anOrigin.X(), anOrigin.Y(), anOrigin.Z(),
444 aDX.X(), aDX.Y(), aDX.Z());
448 TopoDS_Shape Result = Reflector.GetResult();
449 DBRep::Set(a[1], Result);
454 //=======================================================================
457 //=======================================================================
459 static Standard_Integer hlrin3d(Draw_Interpretor& , Standard_Integer n, const char** a)
464 TopoDS_Shape aShape = DBRep::Get(a[2]);
468 Standard_Real anAISViewProjX = atof(a[3]);
469 Standard_Real anAISViewProjY = atof(a[4]);
470 Standard_Real anAISViewProjZ = atof(a[5]);
472 gp_Pnt anOrigin(0.,0.,0.);
473 gp_Dir aNormal(anAISViewProjX, anAISViewProjY, anAISViewProjZ);
474 gp_Ax2 theAxes(anOrigin, aNormal);
475 gp_Dir aDX = theAxes.XDirection();
477 HLRAppli_ReflectLines Reflector(aShape);
479 Reflector.SetAxes(aNormal.X(), aNormal.Y(), aNormal.Z(),
480 anOrigin.X(), anOrigin.Y(), anOrigin.Z(),
481 aDX.X(), aDX.Y(), aDX.Z());
485 TopoDS_Compound Result;
487 BB.MakeCompound(Result);
489 TopoDS_Shape SharpEdges = Reflector.GetCompoundOf3dEdges(HLRBRep_Sharp, Standard_True);
490 BB.Add(Result, SharpEdges);
491 TopoDS_Shape OutLines = Reflector.GetCompoundOf3dEdges(HLRBRep_OutLine, Standard_True);
492 BB.Add(Result, OutLines);
493 TopoDS_Shape SmoothEdges = Reflector.GetCompoundOf3dEdges(HLRBRep_Rg1Line, Standard_True);
494 BB.Add(Result, SmoothEdges);
496 DBRep::Set(a[1], Result);
501 //=======================================================================
502 //function : Commands
504 //=======================================================================
506 void HLRTest::Commands (Draw_Interpretor& theCommands)
508 const char* g = "ADVALGOS HLR Commands";
510 theCommands.Add("hprj" ,"hprj name [view-id = 1]" ,__FILE__,hprj,g);
511 theCommands.Add("houtl" ,"houtl name shape" ,__FILE__,hout,g);
512 theCommands.Add("hfill" ,"hfill name proj [nbIso]" ,__FILE__,hfil,g);
513 theCommands.Add("hsin" ,"hsin name outliner" ,__FILE__,sori,g);
514 theCommands.Add("hsout" ,"hsout name outliner" ,__FILE__,sout,g);
515 theCommands.Add("hload" ,"hload outliner" ,__FILE__,hloa,g);
516 theCommands.Add("hremove" ,"hremove [name]" ,__FILE__,hrem,g);
517 theCommands.Add("hsetprj" ,"hsetprj [name]" ,__FILE__,sprj,g);
518 theCommands.Add("hupdate" ,"hupdate" ,__FILE__,upda,g);
519 theCommands.Add("hhide" ,"hhide" ,__FILE__,hide,g);
520 theCommands.Add("hshowall" ,"hshowall" ,__FILE__,show,g);
521 theCommands.Add("hdebug" ,"hdebug" ,__FILE__,hdbg,g);
522 theCommands.Add("hnullify" ,"hnullify" ,__FILE__,hnul,g);
523 theCommands.Add("hres2d" ,"hres2d" ,__FILE__,hres,g);
525 theCommands.Add("reflectlines",
526 "reflectlines res shape proj_X proj_Y proj_Z",
527 __FILE__, reflectlines, g);
529 theCommands.Add("hlrin3d",
530 "hlrin3d res shape proj_X proj_Y proj_Z",
531 __FILE__, hlrin3d, g);
533 hider = new HLRBRep_Algo();
536 //=======================================================================
537 //function : save and restore projector
539 //=======================================================================
541 static Standard_Boolean stest(const Handle(Draw_Drawable3D)& d)
543 return d->IsInstance(STANDARD_TYPE(HLRTest_Projector));
546 //=======================================================================
549 //=======================================================================
551 static void ssave (const Handle(Draw_Drawable3D)&d, ostream& OS)
553 Handle(HLRTest_Projector) HP =
554 Handle(HLRTest_Projector)::DownCast(d);
556 const HLRAlgo_Projector& P = HP->Projector();
557 OS << (P.Perspective() ? "1" : "0") << "\n";
559 OS << P.Focus() << "\n";
561 gp_Trsf T = P.Transformation();
562 gp_XYZ V = T.TranslationPart();
563 gp_Mat M = T.VectorialPart();
568 OS << V.Coord(1) << " ";
573 OS << V.Coord(2) << " ";
578 OS << V.Coord(3) << " ";
583 //=======================================================================
584 //function : srestore
586 //=======================================================================
588 static Handle(Draw_Drawable3D) srestore (istream& IS)
590 Standard_Boolean pers;
592 Standard_Real focus = 1;
593 if (pers) IS >> focus;
596 Standard_Real V1[3],V2[3],V3[3];
599 IS >> V1[0] >> V1[1] >> V1[2] >> V[0];
600 IS >> V2[0] >> V2[1] >> V2[2] >> V[1];
601 IS >> V3[0] >> V3[1] >> V3[2] >> V[2];
603 gp_Dir D1(V1[0],V1[1],V1[2]);
604 gp_Dir D2(V2[0],V2[1],V2[2]);
605 gp_Dir D3(V3[0],V3[1],V3[2]);
606 gp_Ax3 axes(gp_Pnt(0,0,0),D3,D1);
608 if (D3.Dot(D2) < 0) axes.YReverse();
609 T.SetTransformation(axes);
611 T.SetTranslationPart(gp_Vec(V[0],V[1],V[2]));
613 HLRAlgo_Projector P(T,pers,focus);
614 Handle(HLRTest_Projector) HP = new HLRTest_Projector(P);
618 //=======================================================================
621 //=======================================================================
623 static Draw_SaveAndRestore ssr("HLRTest_Projector",stest,ssave,srestore);