1 // Created on: 1995-09-22
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16 
17 
18 #include <DBRep_HideData.hxx>
19 #include <Draw_Color.hxx>
20 #include <Draw_Display.hxx>
21 #include <gp_Trsf.hxx>
22 #include <HLRAlgo_EdgeIterator.hxx>
23 #include <HLRBRep_BiPoint.hxx>
24 #include <HLRBRep_ListIteratorOfListOfBPoint.hxx>
25 #include <HLRBRep_PolyAlgo.hxx>
26 #include <TopoDS_Shape.hxx>
27 
28 #define PntX1 ((Standard_Real*)Coordinates)[0]
29 #define PntY1 ((Standard_Real*)Coordinates)[1]
30 #define PntZ1 ((Standard_Real*)Coordinates)[2]
31 #define PntX2 ((Standard_Real*)Coordinates)[3]
32 #define PntY2 ((Standard_Real*)Coordinates)[4]
33 #define PntZ2 ((Standard_Real*)Coordinates)[5]
34 
35 //=======================================================================
36 //function : DBRep_HideData
37 //purpose  :
38 //=======================================================================
39 
DBRep_HideData()40 DBRep_HideData::DBRep_HideData()
41 : myView(-1),
42   myFocal(0.0),
43   myAngle(0.0)
44 {
45 }
46 
47 //=======================================================================
48 //function : Set
49 //purpose  :
50 //=======================================================================
51 
Set(const Standard_Integer viewID,const gp_Trsf & TProj,const Standard_Real focal,const TopoDS_Shape & S,const Standard_Real ang)52 void DBRep_HideData::Set(const Standard_Integer viewID,
53 			 const gp_Trsf& TProj,
54 			 const Standard_Real focal,
55 			 const TopoDS_Shape& S,
56                          const Standard_Real ang)
57 {
58   myView = viewID;
59   myTrsf = TProj;
60   myFocal = focal;
61   myAngle = ang;
62 
63   Handle(HLRBRep_PolyAlgo) hider = new HLRBRep_PolyAlgo(S);
64   hider->Projector(HLRAlgo_Projector(myTrsf,myFocal > 0.,myFocal));
65   hider->Update();
66 
67   Standard_Real sta,end,dx,dy,dz;
68   Standard_ShortReal tolsta,tolend;
69   HLRAlgo_EdgeIterator It;
70   myBiPntVis.Clear();
71   myBiPntHid.Clear();
72   TopoDS_Shape Sori;
73   Standard_Boolean reg1,regn,outl,intl;
74   Standard_Address Coordinates;
75   HLRAlgo_EdgeStatus status;
76 
77   for (hider->InitHide(); hider->MoreHide(); hider->NextHide()) {
78     Coordinates = &hider->Hide(status,Sori,reg1,regn,outl,intl);
79     dx = PntX2 - PntX1;
80     dy = PntY2 - PntY1;
81     dz = PntZ2 - PntZ1;
82 
83     for (It.InitVisible(status);
84 	 It.MoreVisible();
85 	 It.NextVisible()) {
86       It.Visible(sta,tolsta,end,tolend);
87       myBiPntVis.Append
88 	(HLRBRep_BiPoint
89 	 (PntX1 + sta * dx,PntY1 + sta * dy,PntZ1 + sta * dz,
90 	  PntX1 + end * dx,PntY1 + end * dy,PntZ1 + end * dz,
91 	  Sori,reg1,regn,outl,intl));
92     }
93 
94     for (It.InitHidden(status);
95 	 It.MoreHidden();
96 	 It.NextHidden()) {
97       It.Hidden(sta,tolsta,end,tolend);
98       myBiPntHid.Append
99 	(HLRBRep_BiPoint
100 	 (PntX1 + sta * dx,PntY1 + sta * dy,PntZ1 + sta * dz,
101 	  PntX1 + end * dx,PntY1 + end * dy,PntZ1 + end * dz,
102 	  Sori,reg1,regn,outl,intl));
103     }
104   }
105 }
106 
107 //=======================================================================
108 //function : IsSame
109 //purpose  :
110 //=======================================================================
111 
IsSame(const gp_Trsf & TProj,const Standard_Real focal) const112 Standard_Boolean DBRep_HideData::IsSame(const gp_Trsf& TProj,
113 					const Standard_Real focal) const
114 {
115   if (focal > 0) {
116     if (myFocal <= 0) return Standard_False;
117     if (myFocal != focal) return Standard_False;
118     const gp_XYZ& T1 = TProj .TranslationPart();
119     const gp_XYZ& T2 = myTrsf.TranslationPart();
120 
121     for (Standard_Integer i = 1; i <= 3; i++) {
122       if (T1.Coord(i) != T2.Coord(i))
123 	return Standard_False;
124     }
125   }
126   const gp_Mat& M1 = TProj .HVectorialPart();
127   const gp_Mat& M2 = myTrsf.HVectorialPart();
128 
129   for (Standard_Integer i = 1; i <= 3; i++) {
130 
131     for (Standard_Integer j = 1; j <= 3; j++) {
132       if (M1.Value(i,j) != M2.Value(i,j))
133 	return Standard_False;
134     }
135   }
136   return Standard_True;
137 }
138 
139 //=======================================================================
140 //function : DrawOn
141 //purpose  :
142 //=======================================================================
143 
DrawOn(Draw_Display & D,const Standard_Boolean withRg1,const Standard_Boolean withRgN,const Standard_Boolean withHid,const Draw_Color & VisCol,const Draw_Color & HidCol)144 void DBRep_HideData::DrawOn(Draw_Display& D,
145 			    const Standard_Boolean withRg1,
146 			    const Standard_Boolean withRgN,
147 			    const Standard_Boolean withHid,
148 			    const Draw_Color& VisCol,
149 			    const Draw_Color& HidCol)
150 {
151   Standard_Boolean firstPick = Standard_True;
152   HLRBRep_ListIteratorOfListOfBPoint It;
153 //  Standard_Boolean reg1,regn,outl;
154 
155   if (withHid) {
156     D.SetColor(HidCol);
157 
158     for (It.Initialize(myBiPntHid);
159 	 It.More();
160 	 It.Next()) {
161       const HLRBRep_BiPoint& BP = It.Value();
162       Standard_Boolean todraw = Standard_True;
163       if ((!withRg1 && BP.Rg1Line() && !BP.OutLine()) ||
164 	  (!withRgN && BP.RgNLine() && !BP.OutLine()))
165 	todraw = Standard_False;
166       if (todraw) {
167 	D.MoveTo(BP.P1());
168 	D.DrawTo(BP.P2());
169 	if (firstPick && D.HasPicked()) {
170 	  firstPick = Standard_False;
171 	  myPickShap = BP.Shape();
172 	}
173       }
174     }
175   }
176   D.SetColor(VisCol);
177 
178   for (It.Initialize(myBiPntVis);
179        It.More();
180        It.Next()) {
181     const HLRBRep_BiPoint& BP = It.Value();
182     Standard_Boolean todraw = Standard_True;
183     if ((!withRg1 && BP.Rg1Line() && !BP.OutLine()) ||
184 	(!withRgN && BP.RgNLine() && !BP.OutLine()))
185       todraw = Standard_False;
186     if (todraw) {
187       D.MoveTo(BP.P1());
188       D.DrawTo(BP.P2());
189       if (firstPick && D.HasPicked()) {
190 	firstPick = Standard_False;
191 	myPickShap = BP.Shape();
192       }
193     }
194   }
195 }
196 
197 //=======================================================================
198 //function : LastPick
199 //purpose  :
200 //=======================================================================
201 
LastPick() const202 const TopoDS_Shape &  DBRep_HideData::LastPick () const
203 { return myPickShap; }
204