Warnings on vc14 were eliminated
[occt.git] / src / DBRep / DBRep_HideData.cxx
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
40 DBRep_HideData::DBRep_HideData()
41 {}
42
43 //=======================================================================
44 //function : Set
45 //purpose  : 
46 //=======================================================================
47
48 void DBRep_HideData::Set(const Standard_Integer viewID,
49                          const gp_Trsf& TProj,
50                          const Standard_Real focal,
51                          const TopoDS_Shape& S,
52                          const Standard_Real ang)
53 {
54   myView = viewID;
55   myTrsf = TProj;
56   myFocal = focal;
57   myAngle = ang;
58
59   Handle(HLRBRep_PolyAlgo) hider = new HLRBRep_PolyAlgo(S);
60   hider->Angle(ang);
61   hider->Projector(HLRAlgo_Projector(myTrsf,myFocal > 0.,myFocal));
62   hider->Update();
63
64   Standard_Real sta,end,dx,dy,dz;
65   Standard_ShortReal tolsta,tolend;
66   HLRAlgo_EdgeIterator It;
67   myBiPntVis.Clear();
68   myBiPntHid.Clear();
69   TopoDS_Shape Sori;
70   Standard_Boolean reg1,regn,outl,intl;
71   Standard_Address Coordinates;
72   HLRAlgo_EdgeStatus status;
73
74   for (hider->InitHide(); hider->MoreHide(); hider->NextHide()) {
75     Coordinates = &hider->Hide(status,Sori,reg1,regn,outl,intl);
76     dx = PntX2 - PntX1;
77     dy = PntY2 - PntY1;
78     dz = PntZ2 - PntZ1;
79     
80     for (It.InitVisible(status);
81          It.MoreVisible();
82          It.NextVisible()) {
83       It.Visible(sta,tolsta,end,tolend);
84       myBiPntVis.Append
85         (HLRBRep_BiPoint
86          (PntX1 + sta * dx,PntY1 + sta * dy,PntZ1 + sta * dz,
87           PntX1 + end * dx,PntY1 + end * dy,PntZ1 + end * dz,
88           Sori,reg1,regn,outl,intl));
89     }
90     
91     for (It.InitHidden(status);
92          It.MoreHidden();
93          It.NextHidden()) {
94       It.Hidden(sta,tolsta,end,tolend);
95       myBiPntHid.Append
96         (HLRBRep_BiPoint
97          (PntX1 + sta * dx,PntY1 + sta * dy,PntZ1 + sta * dz,
98           PntX1 + end * dx,PntY1 + end * dy,PntZ1 + end * dz,
99           Sori,reg1,regn,outl,intl));
100     }
101   }
102 }
103
104 //=======================================================================
105 //function : IsSame
106 //purpose  : 
107 //=======================================================================
108
109 Standard_Boolean DBRep_HideData::IsSame(const gp_Trsf& TProj,
110                                         const Standard_Real focal) const
111 {
112   if (focal > 0) {
113     if (myFocal <= 0) return Standard_False;
114     if (myFocal != focal) return Standard_False;
115     const gp_XYZ& T1 = TProj .TranslationPart();
116     const gp_XYZ& T2 = myTrsf.TranslationPart();
117
118     for (Standard_Integer i = 1; i <= 3; i++) {
119       if (T1.Coord(i) != T2.Coord(i))
120         return Standard_False;
121     }
122   }
123   const gp_Mat& M1 = TProj .HVectorialPart();
124   const gp_Mat& M2 = myTrsf.HVectorialPart();
125
126   for (Standard_Integer i = 1; i <= 3; i++) {
127
128     for (Standard_Integer j = 1; j <= 3; j++) {
129       if (M1.Value(i,j) != M2.Value(i,j))
130         return Standard_False;
131     }
132   }
133   return Standard_True;
134 }
135
136 //=======================================================================
137 //function : DrawOn
138 //purpose  : 
139 //=======================================================================
140
141 void DBRep_HideData::DrawOn(Draw_Display& D,
142                             const Standard_Boolean withRg1,
143                             const Standard_Boolean withRgN,
144                             const Standard_Boolean withHid,
145                             const Draw_Color& VisCol,
146                             const Draw_Color& HidCol)
147 {
148   Standard_Boolean firstPick = Standard_True;
149   HLRBRep_ListIteratorOfListOfBPoint It;
150 //  Standard_Boolean reg1,regn,outl;
151
152   if (withHid) {
153     D.SetColor(HidCol);
154       
155     for (It.Initialize(myBiPntHid);
156          It.More();
157          It.Next()) {
158       const HLRBRep_BiPoint& BP = It.Value();
159       Standard_Boolean todraw = Standard_True;
160       if ((!withRg1 && BP.Rg1Line() && !BP.OutLine()) ||
161           (!withRgN && BP.RgNLine() && !BP.OutLine()))
162         todraw = Standard_False;
163       if (todraw) {
164         D.MoveTo(BP.P1());
165         D.DrawTo(BP.P2());
166         if (firstPick && D.HasPicked()) {
167           firstPick = Standard_False;
168           myPickShap = BP.Shape();
169         }
170       }
171     }
172   }
173   D.SetColor(VisCol);
174
175   for (It.Initialize(myBiPntVis);
176        It.More();
177        It.Next()) {
178     const HLRBRep_BiPoint& BP = It.Value();
179     Standard_Boolean todraw = Standard_True;
180     if ((!withRg1 && BP.Rg1Line() && !BP.OutLine()) ||
181         (!withRgN && BP.RgNLine() && !BP.OutLine()))
182       todraw = Standard_False;
183     if (todraw) {
184       D.MoveTo(BP.P1());
185       D.DrawTo(BP.P2());
186       if (firstPick && D.HasPicked()) {
187         firstPick = Standard_False;
188         myPickShap = BP.Shape();
189       }
190     }
191   }
192 }
193                             
194 //=======================================================================
195 //function : LastPick
196 //purpose  : 
197 //=======================================================================
198
199 const TopoDS_Shape &  DBRep_HideData::LastPick () const
200 { return myPickShap; }