0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / DrawDim / DrawDim_Dimension.cxx
1 // Created on: 1997-04-21
2 // Created by: Denis PASCAL
3 // Copyright (c) 1997-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_Color.hxx>
19 #include <Draw_Display.hxx>
20 #include <Draw_Interpretor.hxx>
21 #include <DrawDim_Dimension.hxx>
22 #include <gp_Pnt.hxx>
23 #include <Standard_DomainError.hxx>
24 #include <Standard_Type.hxx>
25 #include <TCollection_AsciiString.hxx>
26
27 IMPLEMENT_STANDARD_RTTIEXT(DrawDim_Dimension,Draw_Drawable3D)
28
29 //=======================================================================
30 //function : DrawDim_Dimension
31 //purpose  : 
32 //=======================================================================
33 DrawDim_Dimension::DrawDim_Dimension()
34      : is_valued(Standard_False),
35        myTextColor(Draw_blanc)
36 {
37 }
38
39 //=======================================================================
40 //function : SetValue
41 //purpose  : 
42 //=======================================================================
43
44 void DrawDim_Dimension::SetValue (const Standard_Real avalue)
45 {
46   is_valued = Standard_True;
47   myValue = avalue;
48 }
49
50 //=======================================================================
51 //function : GetValue
52 //purpose  : 
53 //=======================================================================
54
55 Standard_Real DrawDim_Dimension::GetValue() const 
56 {
57   if (!is_valued) throw Standard_DomainError();
58   return myValue;
59 }
60
61 //=======================================================================
62 //function : IsValued
63 //purpose  : 
64 //=======================================================================
65
66 Standard_Boolean DrawDim_Dimension::IsValued() const 
67 {
68   return is_valued;
69 }
70
71 //=======================================================================
72 //function : TextColor
73 //purpose  : 
74 //=======================================================================
75
76 Draw_Color DrawDim_Dimension::TextColor() const
77 {
78   return myTextColor;
79 }
80
81 //=======================================================================
82 //function : TextColor
83 //purpose  : 
84 //=======================================================================
85
86 void DrawDim_Dimension::TextColor(const Draw_Color& C)
87 {
88    myTextColor = C;
89 }
90
91 //=======================================================================
92 //function : DrawText
93 //purpose  : 
94 //=======================================================================
95
96 void DrawDim_Dimension::DrawText(const gp_Pnt& P, Draw_Display& D) const
97 {
98   TCollection_AsciiString t = Name();
99   if (is_valued) {
100     t+="=";
101     Standard_Integer l = t.Length();
102     t+= myValue;
103     for (Standard_Integer i = l; i <= t.Length(); i++) {
104       if (t.Value(i) == '.') { t.Trunc(i+2); break; }
105     }
106   }
107
108   D.SetColor(myTextColor);
109   D.DrawString(P,t.ToCString());
110 }