0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / Vrml / Vrml_Texture2.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <TCollection_AsciiString.hxx>
16 #include <TColStd_HArray1OfInteger.hxx>
17 #include <Vrml_SFImage.hxx>
18 #include <Vrml_Texture2.hxx>
19
20 Vrml_Texture2::Vrml_Texture2()
21 {
22   myFilename = "";
23
24   myImage = new Vrml_SFImage;
25
26   myImage->SetWidth(0);
27   myImage->SetHeight(0);
28   myImage->SetNumber(Vrml_NULL);
29
30   myWrapS = Vrml_REPEAT;
31   myWrapT = Vrml_REPEAT; 
32 }
33
34 Vrml_Texture2::Vrml_Texture2(const TCollection_AsciiString& aFilename,
35                              const Handle(Vrml_SFImage)& aImage,
36                              const Vrml_Texture2Wrap aWrapS,
37                              const Vrml_Texture2Wrap aWrapT)
38 {
39   myFilename = aFilename;
40   myImage = aImage;
41   myWrapS = aWrapS;
42   myWrapT = aWrapT;
43 }
44
45  void Vrml_Texture2::SetFilename(const TCollection_AsciiString& aFilename) 
46 {
47   myFilename = aFilename;
48 }
49
50  TCollection_AsciiString Vrml_Texture2::Filename() const
51 {
52   return myFilename;
53 }
54
55  void Vrml_Texture2::SetImage(const Handle(Vrml_SFImage)& aImage) 
56 {
57   myImage = aImage;
58 }
59
60  Handle(Vrml_SFImage) Vrml_Texture2::Image() const
61 {
62   return  myImage;
63 }
64
65  void Vrml_Texture2::SetWrapS(const Vrml_Texture2Wrap aWrapS) 
66 {
67   myWrapS = aWrapS;
68 }
69
70  Vrml_Texture2Wrap Vrml_Texture2::WrapS() const
71 {
72   return myWrapS;
73 }
74
75  void Vrml_Texture2::SetWrapT(const Vrml_Texture2Wrap aWrapT) 
76 {
77   myWrapT = aWrapT;
78 }
79
80  Vrml_Texture2Wrap Vrml_Texture2::WrapT() const
81 {
82   return myWrapT;
83 }
84
85  Standard_OStream& Vrml_Texture2::Print(Standard_OStream& anOStream) const
86 {
87  Standard_Integer i;
88  anOStream  << "Texture2 {\n";
89
90  if ( !(myFilename.IsEqual("") ) )
91    {
92     anOStream  << "    filename\t";
93     anOStream << '"' << myFilename << '"' << "\n";
94    }
95
96  if ( myImage->Width() != 0 || myImage->Height() != 0 || myImage->Number() != Vrml_NULL ) 
97    {
98     anOStream  << "    image\t";
99     anOStream <<  myImage->Width() << " " << myImage->Height() << " ";
100
101     switch ( myImage->Number() )
102       {
103       case Vrml_NULL:  anOStream  << "0"; break;
104       case Vrml_ONE:   anOStream  << "1"; break;
105       case Vrml_TWO:   anOStream  << "2"; break; 
106       case Vrml_THREE: anOStream  << "3"; break;  
107       case Vrml_FOUR:  anOStream  << "4"; break; 
108       }
109
110     if ( myImage->ArrayFlag() == Standard_True )
111       { 
112         for ( i = myImage->Array()->Lower(); i <= myImage->Array()->Upper(); i++ )
113           {
114 //          anOStream << " " << hex(myImage->Array()->Value(i),0);
115             anOStream << " " << myImage->Array()->Value(i);
116           }
117       }
118     anOStream  <<  "\n";
119   }
120
121   switch ( myWrapS )
122     {
123      case Vrml_REPEAT: break; // anOStream  << "    wrapS\tREPEAT ";
124      case Vrml_CLAMP: anOStream  << "    wrapS\tCLAMP\n"; break;
125     }
126
127   switch ( myWrapT )
128     {
129      case Vrml_REPEAT: break; // anOStream  << "    wrapT\tREPEAT ";
130      case Vrml_CLAMP: anOStream  << "    wrapT\tCLAMP\n"; break;
131     }
132
133  anOStream  << "}\n";
134  return anOStream;
135 }