974538b3d6c2d2faf8ea96ec0e727429aa41db8a
[occt.git] / src / Prs3d / Prs3d_DatumAspect.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <Prs3d_DatumAspect.hxx>
16
17 IMPLEMENT_STANDARD_RTTIEXT(Prs3d_DatumAspect, Prs3d_BasicAspect)
18
19 // =======================================================================
20 // function : Prs3d_DatumAspect
21 // purpose  :
22 // =======================================================================
23 Prs3d_DatumAspect::Prs3d_DatumAspect()
24 : myAxes (Prs3d_DA_XYZAxis),
25   myToDrawLabels (Standard_True)
26 {
27   Standard_Real aDefaultLength = 100.0; // default axis lenght, the same as in context
28   Quantity_Color aDefaultColor(Quantity_NOC_LIGHTSTEELBLUE4); // default axis color
29
30   myAttributes.Bind (Prs3d_DA_XAxisLength, aDefaultLength);
31   myAttributes.Bind (Prs3d_DA_YAxisLength, aDefaultLength);
32   myAttributes.Bind (Prs3d_DA_ZAxisLength, aDefaultLength);
33   myAttributes.Bind (Prs3d_DP_ShadingTubeRadiusPercent,   0.02);
34   myAttributes.Bind (Prs3d_DP_ShadingConeRadiusPercent,   0.04);
35   myAttributes.Bind (Prs3d_DP_ShadingConeLengthPercent,   0.1);
36   myAttributes.Bind (Prs3d_DP_ShadingOriginRadiusPercent, 0.015);
37   myAttributes.Bind (Prs3d_DP_ShadingNumberOfFacettes,    12.0);
38
39   Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID;
40   Standard_Real aWidth = 1.0;
41   for (int aPartIter = Prs3d_DP_Origin; aPartIter <= Prs3d_DP_XOZAxis; ++aPartIter)
42   {
43     const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
44     if (aPart != Prs3d_DP_Origin) // origin point is used only in shading mode
45     {
46       myLineAspects.Bind (aPart, new Prs3d_LineAspect (aDefaultColor, aLineType, aWidth));
47     }
48
49     Handle(Prs3d_ShadingAspect) aShadingAspect = new Prs3d_ShadingAspect();
50     aShadingAspect->SetColor (aDefaultColor);
51     myShadedAspects.Bind (aPart, aShadingAspect);
52   }
53   myTextAspect  = new Prs3d_TextAspect();
54   myPointAspect = new Prs3d_PointAspect (Aspect_TOM_EMPTY, aDefaultColor, 1.0);
55   myArrowAspect = new Prs3d_ArrowAspect();
56 }
57
58 // =======================================================================
59 // function : LineAspect
60 // purpose  :
61 // =======================================================================
62 Handle(Prs3d_LineAspect) Prs3d_DatumAspect::LineAspect (Prs3d_DatumParts thePart) const
63 {
64   Handle(Prs3d_LineAspect) aLineAspect;
65   myLineAspects.Find (thePart, aLineAspect);
66   return aLineAspect;
67 }
68
69 // =======================================================================
70 // function : ShadingAspect
71 // purpose  :
72 // =======================================================================
73 Handle(Prs3d_ShadingAspect) Prs3d_DatumAspect::ShadingAspect (Prs3d_DatumParts thePart) const
74 {
75   Handle(Prs3d_ShadingAspect) aShadingAspect;
76   myShadedAspects.Find (thePart, aShadingAspect);
77   return aShadingAspect;
78 }
79
80 // =======================================================================
81 // function : SetDrawFirstAndSecondAxis
82 // purpose  :
83 // =======================================================================
84 void Prs3d_DatumAspect::SetDrawFirstAndSecondAxis (Standard_Boolean theToDraw)
85 {
86   if (theToDraw)
87   {
88     myAxes = Prs3d_DatumAxes(myAxes | Prs3d_DA_XAxis | Prs3d_DA_YAxis);
89   }
90   else
91   {
92     myAxes = Prs3d_DatumAxes(myAxes & !Prs3d_DA_XAxis & !Prs3d_DA_YAxis);
93   }
94 }
95
96 // =======================================================================
97 // function : SetDrawThirdAxis
98 // purpose  :
99 // =======================================================================
100 void Prs3d_DatumAspect::SetDrawThirdAxis (Standard_Boolean theToDraw)
101 {
102   if (theToDraw)
103   {
104     myAxes = Prs3d_DatumAxes(myAxes | Prs3d_DA_ZAxis);
105   }
106   else
107   {
108     myAxes = Prs3d_DatumAxes(myAxes & !Prs3d_DA_ZAxis);
109   }
110 }
111
112 // =======================================================================
113 // function : DrawDatumPart
114 // purpose  :
115 // =======================================================================
116 bool Prs3d_DatumAspect::DrawDatumPart (Prs3d_DatumParts thePart) const
117 {
118   switch (thePart)
119   {
120     case Prs3d_DP_Origin:  return true;
121     case Prs3d_DP_XAxis:
122     case Prs3d_DP_XArrow:  return (myAxes & Prs3d_DA_XAxis) != 0;
123     case Prs3d_DP_YAxis:
124     case Prs3d_DP_YArrow:  return (myAxes & Prs3d_DA_YAxis) != 0;
125     case Prs3d_DP_ZAxis:
126     case Prs3d_DP_ZArrow:  return (myAxes & Prs3d_DA_ZAxis) != 0;
127     case Prs3d_DP_XOYAxis: return DrawDatumPart (Prs3d_DP_XAxis)
128                                && DrawDatumPart (Prs3d_DP_YAxis);
129     case Prs3d_DP_YOZAxis: return DrawDatumPart (Prs3d_DP_YAxis)
130                                && DrawDatumPart (Prs3d_DP_ZAxis);
131     case Prs3d_DP_XOZAxis: return DrawDatumPart (Prs3d_DP_XAxis)
132                                && DrawDatumPart (Prs3d_DP_ZAxis);
133     default: break;
134   }
135   return false;
136 }
137
138 // =======================================================================
139 // function : AxisLength
140 // purpose  :
141 // =======================================================================
142 Standard_Real Prs3d_DatumAspect::AxisLength (Prs3d_DatumParts thePart) const
143 {
144   switch (thePart)
145   {
146     case Prs3d_DP_XAxis: return myAttributes.Find (Prs3d_DA_XAxisLength);
147     case Prs3d_DP_YAxis: return myAttributes.Find (Prs3d_DA_YAxisLength);
148     case Prs3d_DP_ZAxis: return myAttributes.Find (Prs3d_DA_ZAxisLength);
149     default: break;
150   }
151   return 0.0;
152 }
153
154 // =======================================================================
155 // function : ArrowPartForAxis
156 // purpose  :
157 // =======================================================================
158 Prs3d_DatumParts Prs3d_DatumAspect::ArrowPartForAxis (Prs3d_DatumParts thePart) const
159 {
160   switch (thePart)
161   {
162     case Prs3d_DP_XAxis: return Prs3d_DP_XArrow;
163     case Prs3d_DP_YAxis: return Prs3d_DP_YArrow;
164     case Prs3d_DP_ZAxis: return Prs3d_DP_ZArrow;
165     default: break;
166   }
167   return Prs3d_DP_None;
168 }