1 // Created on: 1994-03-28
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1994-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 #include <DrawTrSurf_Point.hxx>
18
19 #include <Draw_Color.hxx>
20 #include <Draw_Display.hxx>
21 #include <DrawTrSurf.hxx>
22 #include <DrawTrSurf_Params.hxx>
23 #include <gp_Pnt.hxx>
24 #include <gp_Pnt2d.hxx>
25
IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_Point,Draw_Drawable3D)26 IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_Point, Draw_Drawable3D)
27
28 //=======================================================================
29 //function : DrawTrSurf_Point
30 //purpose :
31 //=======================================================================
32 DrawTrSurf_Point::DrawTrSurf_Point (const gp_Pnt& P,
33 const Draw_MarkerShape Shape,
34 const Draw_Color& Col)
35 : myPoint(P),
36 is3D(Standard_True),
37 myShape(Shape),
38 myColor(Col)
39 {
40 //
41 }
42
43 //=======================================================================
44 //function : DrawTrSurf_Point
45 //purpose :
46 //=======================================================================
DrawTrSurf_Point(const gp_Pnt2d & P,const Draw_MarkerShape Shape,const Draw_Color & Col)47 DrawTrSurf_Point::DrawTrSurf_Point (const gp_Pnt2d& P,
48 const Draw_MarkerShape Shape,
49 const Draw_Color& Col)
50 : myPoint(P.X(),P.Y(),0.),
51 is3D(Standard_False),
52 myShape(Shape),
53 myColor(Col)
54 {
55 //
56 }
57
58 //=======================================================================
59 //function : Is3D
60 //purpose :
61 //=======================================================================
Is3D() const62 Standard_Boolean DrawTrSurf_Point::Is3D() const
63 {
64 return is3D;
65 }
66
67 //=======================================================================
68 //function : DrawOn
69 //purpose :
70 //=======================================================================
DrawOn(Draw_Display & dis) const71 void DrawTrSurf_Point::DrawOn (Draw_Display& dis) const
72 {
73 dis.SetColor(myColor);
74 if (is3D)
75 dis.DrawMarker(myPoint,myShape);
76 else
77 dis.DrawMarker(Point2d(),myShape);
78 }
79
80 //=======================================================================
81 //function : Point
82 //purpose :
83 //=======================================================================
Point(const gp_Pnt & P)84 void DrawTrSurf_Point::Point (const gp_Pnt& P)
85 {
86 myPoint = P;
87 is3D = Standard_True;
88 }
89
90 //=======================================================================
91 //function : Point2d
92 //purpose :
93 //=======================================================================
Point2d(const gp_Pnt2d & P)94 void DrawTrSurf_Point::Point2d(const gp_Pnt2d& P)
95 {
96 myPoint.SetCoord(P.X(),P.Y(),0);
97 is3D = Standard_False;
98 }
99
100 //=======================================================================
101 //function : Copy
102 //purpose :
103 //=======================================================================
Handle(Draw_Drawable3D)104 Handle(Draw_Drawable3D) DrawTrSurf_Point::Copy() const
105 {
106 Handle(DrawTrSurf_Point) P;
107 if (is3D)
108 P = new DrawTrSurf_Point(myPoint,myShape,myColor);
109 else
110 P = new DrawTrSurf_Point(Point2d(),myShape,myColor);
111
112 return P;
113 }
114
115 //=======================================================================
116 //function : Dump
117 //purpose :
118 //=======================================================================
Dump(Standard_OStream & S) const119 void DrawTrSurf_Point::Dump (Standard_OStream& S) const
120 {
121 #if !defined(_MSC_VER) && !defined(__sgi) && !defined(IRIX)
122 std::ios::fmtflags F = S.flags();
123 S.setf(std::ios::scientific,std::ios::floatfield);
124 S.precision(15);
125 #else
126 long form = S.setf(std::ios::scientific);
127 std::streamsize prec = S.precision(15);
128 #endif
129 if (is3D)
130 S << "Point : " << myPoint.X() << ", " << myPoint.Y() << ", " << myPoint.Z() <<std::endl;
131 else
132 S << "Point 2d : " << myPoint.X() << ", " << myPoint.Y() <<std::endl;
133 #if !defined(_MSC_VER) && !defined(__sgi) && !defined(IRIX)
134 S.setf(F);
135 #else
136 S.setf(form);
137 S.precision(prec);
138 #endif
139 }
140
141 //=======================================================================
142 //function : Save
143 //purpose :
144 //=======================================================================
Save(Standard_OStream & theStream) const145 void DrawTrSurf_Point::Save (Standard_OStream& theStream) const
146 {
147 #if !defined(_MSC_VER) && !defined(__sgi) && !defined(IRIX)
148 std::ios::fmtflags aFlags = theStream.flags();
149 theStream.setf (std::ios::scientific, std::ios::floatfield);
150 theStream.precision (15);
151 #else
152 long aForm = theStream.setf (std::ios::scientific);
153 std::streamsize aPrec = theStream.precision (15);
154 #endif
155 if (is3D)
156 {
157 theStream << "1 " << myPoint.X() << " " << myPoint.Y() << " " << myPoint.Z() << "\n";
158 }
159 else
160 {
161 theStream << "0 " << myPoint.X() << " " << myPoint.Y() << "\n";
162 }
163 #if !defined(_MSC_VER) && !defined(__sgi) && !defined(IRIX)
164 theStream.setf (aFlags);
165 #else
166 theStream.setf (aForm);
167 theStream.precision (aPrec);
168 #endif
169 }
170
171 //=======================================================================
172 //function : Restore
173 //purpose :
174 //=======================================================================
Handle(Draw_Drawable3D)175 Handle(Draw_Drawable3D) DrawTrSurf_Point::Restore (Standard_IStream& theStream)
176 {
177 const DrawTrSurf_Params& aParams = DrawTrSurf::Parameters();
178 Standard_Integer is3d = 0;
179 theStream >> is3d;
180 Standard_Real x,y,z = 0.0;
181 if (is3d)
182 {
183 theStream >> x >> y >> z;
184 }
185 else
186 {
187 theStream >> x >> y;
188 }
189 Handle(DrawTrSurf_Point) aDrawPoint;
190 if (is3d)
191 {
192 aDrawPoint = new DrawTrSurf_Point (gp_Pnt (x, y, z), aParams.PntMarker, aParams.PntColor);
193 }
194 else
195 {
196 aDrawPoint = new DrawTrSurf_Point (gp_Pnt2d (x, y), aParams.PntMarker, aParams.PntColor);
197 }
198 return aDrawPoint;
199 }
200
201 //=======================================================================
202 //function : Whatis
203 //purpose :
204 //=======================================================================
Whatis(Draw_Interpretor & S) const205 void DrawTrSurf_Point::Whatis (Draw_Interpretor& S) const
206 {
207 S << "point";
208 }
209