0023510: Integration of test grid "vis" into the new testing system
[occt.git] / src / AIS2D / AIS2D.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
7 //
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10 //
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
17
18 #include <AIS2D.hxx>
19 #include <Graphic2d_Primitive.hxx>
20 #include <Graphic2d_DisplayList.hxx>
21 #include <Graphic2d_Circle.hxx>
22 #include <Graphic2d_CircleMarker.hxx>
23 #include <Graphic2d_Ellips.hxx>
24 #include <Graphic2d_EllipsMarker.hxx>
25 #include <Graphic2d_InfiniteLine.hxx>
26 #include <Graphic2d_Marker.hxx>
27 #include <Graphic2d_VectorialMarker.hxx>
28 #include <Graphic2d_PolylineMarker.hxx>
29 #include <Graphic2d_SetOfMarkers.hxx>
30 #include <Graphic2d_SetOfSegments.hxx>
31 #include <Graphic2d_Segment.hxx>
32 #include <Graphic2d_Polyline.hxx>
33 #include <Graphic2d_SetOfPolylines.hxx>
34 #include <Graphic2d_Image.hxx>
35 #include <Graphic2d_ImageFile.hxx>
36 #include <Graphic2d_Text.hxx>
37 #include <Graphic2d_FramedText.hxx>
38 #include <Graphic2d_HidingText.hxx>
39 #include <GGraphic2d_Curve.hxx>
40 #include <GGraphic2d_SetOfCurves.hxx>
41 #include <Graphic2d_View.hxx>
42 #include <Graphic2d_Paragraph.hxx>
43
44 #include <V2d_Viewer.hxx>
45
46 #include <Quantity_Color.hxx>
47
48 #include <Prs2d_AspectRoot.hxx>
49 #include <Prs2d_AspectLine.hxx>
50 #include <Prs2d_AspectText.hxx>
51 #include <Prs2d_Angle.hxx>
52
53 #include <AIS2D_InteractiveContext.hxx>
54 #include <AIS2D_InteractiveObject.hxx>
55 #include <AIS2D_KindOfPrimitive.hxx>
56
57 #ifdef HAVE_CONFIG_H
58 # include <config.h>
59 #endif
60
61 #include <Standard_Stream.hxx>
62 Standard_Boolean AIS2D::Save( const Handle(AIS2D_InteractiveContext)& aCntx,
63                               const Standard_CString aFile ) {
64
65
66  if ( !aCntx.IsNull() ) {
67
68   Handle( Graphic2d_DisplayList ) theDL = aCntx->CurrentViewer()->View()->DisplayList();
69  
70   if ( !theDL->IsEmpty() ) {
71    
72    Aspect_FStream ofs = new ofstream;
73    ofs->open( aFile, ios::out );
74
75    int LnOfDL = theDL->Length();
76    TCollection_AsciiString thestr;
77    for ( int i = 1; i <= LnOfDL; ++i )
78    {
79       Handle(AIS2D_InteractiveObject) theIO = 
80               Handle(AIS2D_InteractiveObject)::DownCast( theDL->Value(i) ); 
81       theIO->Save( ofs );
82
83   /*   int lnOfPr = theIO->Length();
84
85      for ( int j = 1; j <= lnOfPr; j++ ) {
86
87        Handle(Graphic2d_Primitive) thePrm = theIO->Primitive( j );
88        Handle( Prs2d_AspectRoot ) theAsp = theIO->GetAspect( thePrm );
89
90        if ( thePrm->IsKind( STANDARD_TYPE( Graphic2d_Line ) ) ) {
91          Handle(Prs2d_AspectLine) theAL = Handle(Prs2d_AspectLine)::DownCast( theAsp );
92          Quantity_Color theColor;
93          Aspect_TypeOfLine theTOL;
94          Aspect_WidthOfLine theWOL;
95          theAL->ValuesOfLine( theColor, theTOL, theWOL );
96          Standard_Real R1, R2, R3;
97          theColor.Values( R1, R2, R3, Quantity_TOC_RGB );
98          
99        } else if ( thePrm->IsKind( STANDARD_TYPE( Graphic2d_Paragraph ) ) ) {
100        
101        } else if ( thePrm->IsKind( STANDARD_TYPE( Graphic2d_Image ) ) ) {
102
103        } else if ( thePrm->IsKind( STANDARD_TYPE( Graphic2d_ImageFile ) ) ) {
104        
105        } else if ( thePrm->IsKind( STANDARD_TYPE( Graphic2d_Text ) ) ) {     
106
107          Handle(Prs2d_AspectText) theAT = Handle(Prs2d_AspectText)::DownCast( theAsp );
108          Quantity_Color aColor;
109          Aspect_FontStyle aFont;
110          Quantity_PlaneAngle aSlant;
111          Aspect_TypeOfText aType; 
112          Standard_Boolean isUnderlined;
113          theAT->Values( aColor, aFont, aSlant, aType, isUnderlined );
114        }    
115     }*/
116    }
117      ofs->close();
118   } //if sequence of displyed objects isn't empty
119  } // if context isn't NULL
120     return Standard_False;
121 }
122
123  Handle (AIS2D_InteractiveObject)
124  AIS2D::Retrieve( const Handle(AIS2D_InteractiveContext)& /*aCntx*/,
125                   const Standard_CString aFile )
126 {
127         char buf[100];
128         Aspect_IFStream ifs = new ifstream;
129         Handle(AIS2D_InteractiveObject) theIO;
130         ifs->open(aFile, ios::in);
131         ifs->getline(buf, 100);
132         while (! ifs->eof())
133         {
134                 if (! strcmp(buf, "AIS2D_InteractiveObject"))
135                 {
136                         theIO = new AIS2D_InteractiveObject();
137                         theIO->Retrieve(ifs);
138                 }
139                 ifs->getline(buf, 100);
140         }
141         ifs->close();
142
143         return theIO;
144 }