0030948: Configuration, CMake - problem building with CMake 3.15.2
[occt.git] / src / Draw / Draw_Box.cxx
1 // Created on: 1995-03-10
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 <Draw_Box.hxx>
19 #include <Draw_Color.hxx>
20 #include <Draw_Display.hxx>
21 #include <gp_Pnt.hxx>
22 #include <Standard_Type.hxx>
23
24 IMPLEMENT_STANDARD_RTTIEXT(Draw_Box,Draw_Drawable3D)
25
26 //=======================================================================
27 //function : Constructor
28 //purpose  : 
29 //=======================================================================
30 Draw_Box::Draw_Box(const Bnd_OBB& theOBB,
31                    const Draw_Color& theColor) :myOBB(theOBB), myColor(theColor)
32 {
33 }
34
35 //=======================================================================
36 //function : ToWCS
37 //purpose  : 
38 //=======================================================================
39 void Draw_Box::ToWCS(const Standard_Real theX,
40                      const Standard_Real theY,
41                      const Standard_Real theZ,
42                      gp_Pnt& theP) const
43 {
44   const gp_XYZ & aC = myOBB.Center();
45   const gp_XYZ aXDir = myOBB.XDirection(),
46                aYDir = myOBB.YDirection(),
47                aZDir = myOBB.ZDirection();
48
49   theP.SetXYZ(aC + theX*aXDir + theY*aYDir + theZ*aZDir);
50 }
51
52 //=======================================================================
53 //function : MoveX
54 //purpose  : 
55 //=======================================================================
56 void Draw_Box::MoveX(const Standard_Real theShift, gp_Pnt& thePt) const
57 {
58   const gp_XYZ aXDir = myOBB.XDirection();
59   thePt.SetXYZ(thePt.XYZ() + theShift*aXDir);
60 }
61
62 //=======================================================================
63 //function : MoveY
64 //purpose  : 
65 //=======================================================================
66 void Draw_Box::MoveY(const Standard_Real theShift, gp_Pnt& thePt) const
67 {
68   const gp_XYZ aYDir = myOBB.YDirection();
69   thePt.SetXYZ(thePt.XYZ() + theShift*aYDir);
70 }
71
72 //=======================================================================
73 //function : MoveZ
74 //purpose  : 
75 //=======================================================================
76 void Draw_Box::MoveZ(const Standard_Real theShift, gp_Pnt& thePt) const
77 {
78   const gp_XYZ aZDir = myOBB.ZDirection();
79   thePt.SetXYZ(thePt.XYZ() + theShift*aZDir);
80 }
81
82 //=======================================================================
83 //function : DrawOn
84 //purpose  : 
85 //=======================================================================
86 void Draw_Box::DrawOn(Draw_Display& theDIS) const 
87 {
88   if(myOBB.IsVoid())
89   {
90     return;
91   }
92
93   theDIS.SetColor(myColor);
94   
95   const Standard_Real aHx = myOBB.XHSize(),
96                       aHy = myOBB.YHSize(),
97                       aHz = myOBB.ZHSize();
98
99   gp_Pnt aP;
100   ToWCS(-aHx, -aHy, -aHz, aP);
101   theDIS.MoveTo(aP);
102
103   for(Standard_Integer i = 0; i<2; i++)
104   {
105     MoveX(2.0*aHx, aP);
106     theDIS.DrawTo(aP);
107     MoveY(2.0*aHy, aP);
108     theDIS.DrawTo(aP);
109     MoveX(-2.0*aHx, aP);
110     theDIS.DrawTo(aP);
111     MoveY(-2.0*aHy, aP);
112     theDIS.DrawTo(aP);
113
114     ToWCS(-aHx, -aHy, aHz, aP);
115     theDIS.MoveTo(aP);
116   }
117   
118   for(Standard_Integer i = 0; i < 4; i++)
119   {
120     switch(i)
121     {
122       case 0: ToWCS(-aHx, -aHy, -aHz, aP); break;
123       case 1: ToWCS(aHx, -aHy, -aHz, aP); break;
124       case 2: ToWCS(aHx, aHy, -aHz, aP); break;
125       case 3: ToWCS(-aHx, aHy, -aHz, aP); break;
126       default: break;
127     }
128
129     theDIS.MoveTo(aP);
130     MoveZ(2.0*aHz, aP);
131     theDIS.DrawTo(aP);
132   }
133 }
134