1 // Created on: 1995-03-14
2 // Created by: Laurent PAINNOT
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 #include <DrawTrSurf_Polygon2D.hxx>
18 
19 #include <Draw_Color.hxx>
20 #include <Draw_Display.hxx>
21 #include <Draw_MarkerShape.hxx>
22 #include <Poly.hxx>
23 #include <Poly_Polygon2D.hxx>
24 
IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_Polygon2D,Draw_Drawable2D)25 IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_Polygon2D, Draw_Drawable2D)
26 
27 //=======================================================================
28 //function : DrawTrSurf_Polygon2D
29 //purpose  :
30 //=======================================================================
31 DrawTrSurf_Polygon2D::DrawTrSurf_Polygon2D(const Handle(Poly_Polygon2D)& P)
32 : myPolygon2D(P),
33   myNodes(Standard_False)
34 {
35 }
36 
37 //=======================================================================
38 //function : DrawOn
39 //purpose  :
40 //=======================================================================
DrawOn(Draw_Display & dis) const41 void DrawTrSurf_Polygon2D::DrawOn(Draw_Display& dis) const
42 {
43   dis.SetColor(Draw_jaune);
44 
45   const TColgp_Array1OfPnt2d& Points = myPolygon2D->Nodes();
46   for (Standard_Integer i = Points.Lower(); i <= Points.Upper()-1; i++)
47   {
48     dis.Draw(Points(i), Points(i+1));
49   }
50 
51   if (myNodes)
52   {
53     for (Standard_Integer i = Points.Lower(); i <= Points.Upper(); i++)
54     {
55       dis.DrawMarker(Points(i), Draw_X);
56     }
57   }
58 }
59 
60 //=======================================================================
61 //function : Copy
62 //purpose  :
63 //=======================================================================
Handle(Draw_Drawable3D)64 Handle(Draw_Drawable3D) DrawTrSurf_Polygon2D::Copy() const
65 {
66   return new DrawTrSurf_Polygon2D(myPolygon2D);
67 }
68 
69 //=======================================================================
70 //function : Dump
71 //purpose  :
72 //=======================================================================
Dump(Standard_OStream & S) const73 void DrawTrSurf_Polygon2D::Dump (Standard_OStream& S) const
74 {
75   Poly::Dump(myPolygon2D, S);
76 }
77 
78 //=======================================================================
79 //function : Save
80 //purpose  :
81 //=======================================================================
Save(Standard_OStream & theStream) const82 void DrawTrSurf_Polygon2D::Save (Standard_OStream& theStream) const
83 {
84 #if !defined(_MSC_VER) && !defined(__sgi) && !defined(IRIX)
85   std::ios::fmtflags aFlags = theStream.flags();
86   theStream.setf (std::ios::scientific, std::ios::floatfield);
87   theStream.precision (15);
88 #else
89   long aForm = theStream.setf (std::ios::scientific);
90   std::streamsize aPrec = theStream.precision (15);
91 #endif
92   Poly::Write (myPolygon2D, theStream);
93 #if !defined(_MSC_VER) && !defined(__sgi) && !defined(IRIX)
94   theStream.setf (aFlags);
95 #else
96   theStream.setf (aForm);
97   theStream.precision (aPrec);
98 #endif
99 }
100 
101 //=======================================================================
102 //function : Restore
103 //purpose  :
104 //=======================================================================
Handle(Draw_Drawable3D)105 Handle(Draw_Drawable3D) DrawTrSurf_Polygon2D::Restore (Standard_IStream& theStream)
106 {
107   return new DrawTrSurf_Polygon2D (Poly::ReadPolygon2D (theStream));
108 }
109 
110 //=======================================================================
111 //function : Whatis
112 //purpose  :
113 //=======================================================================
Whatis(Draw_Interpretor & I) const114 void DrawTrSurf_Polygon2D::Whatis (Draw_Interpretor& I) const
115 {
116   I << "polygon2D";
117 }
118