Warnings on vc14 were eliminated
[occt.git] / src / Graphic3d / Graphic3d_Texture2D.cxx
1 // Created on: 1997-07-28
2 // Created by: Pierre CHALAMET
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 #include <Graphic3d_Texture2D.hxx>
18
19 #include <Standard_OutOfRange.hxx>
20
21 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Texture2D,Graphic3d_TextureMap)
22
23 static const char *NameOfTexture_to_FileName[] =
24 {
25   "2d_MatraDatavision.rgb",
26   "2d_alienskin.rgb",
27   "2d_blue_rock.rgb",
28   "2d_bluewhite_paper.rgb",
29   "2d_brushed.rgb",
30   "2d_bubbles.rgb",
31   "2d_bumps.rgb",
32   "2d_cast.rgb",
33   "2d_chipbd.rgb",
34   "2d_clouds.rgb",
35   "2d_flesh.rgb",
36   "2d_floor.rgb",
37   "2d_galvnisd.rgb",
38   "2d_grass.rgb",
39   "2d_aluminum.rgb",
40   "2d_rock.rgb",
41   "2d_knurl.rgb",
42   "2d_maple.rgb",
43   "2d_marble.rgb",
44   "2d_mottled.rgb",
45   "2d_rain.rgb",
46   "2d_chess.rgba"
47 };
48
49 // =======================================================================
50 // function : Graphic3d_Texture2D
51 // purpose  :
52 // =======================================================================
53 Graphic3d_Texture2D::Graphic3d_Texture2D (const TCollection_AsciiString& theFileName,
54                                           const Graphic3d_TypeOfTexture  theType)
55 : Graphic3d_TextureMap (theFileName, theType),
56   myName (Graphic3d_NOT_2D_UNKNOWN)
57 {
58 }
59
60 // =======================================================================
61 // function : Graphic3d_Texture2D
62 // purpose  :
63 // =======================================================================
64 Graphic3d_Texture2D::Graphic3d_Texture2D (const Graphic3d_NameOfTexture2D theNOT,
65                                           const Graphic3d_TypeOfTexture   theType)
66 : Graphic3d_TextureMap (NameOfTexture_to_FileName[theNOT], theType),
67   myName (theNOT)
68 {
69   myPath.SetTrek (Graphic3d_TextureRoot::TexturesFolder());
70   myTexId = TCollection_AsciiString ("Graphic3d_Texture2D_")
71           + NameOfTexture_to_FileName[theNOT];
72 }
73
74 // =======================================================================
75 // function : Graphic3d_Texture2D
76 // purpose  :
77 // =======================================================================
78 Graphic3d_Texture2D::Graphic3d_Texture2D (const Handle(Image_PixMap)&    thePixMap,
79                                           const Graphic3d_TypeOfTexture  theType)
80 : Graphic3d_TextureMap (thePixMap, theType),
81   myName (Graphic3d_NOT_2D_UNKNOWN)
82 {
83 }
84
85 // =======================================================================
86 // function : NumberOfTextures
87 // purpose  :
88 // =======================================================================
89 Standard_Integer Graphic3d_Texture2D::NumberOfTextures()
90 {
91   return sizeof(NameOfTexture_to_FileName)/sizeof(char*);
92 }
93
94 // =======================================================================
95 // function : Name
96 // purpose  :
97 // =======================================================================
98 Graphic3d_NameOfTexture2D Graphic3d_Texture2D::Name() const
99 {
100   return myName;
101 }
102
103 // =======================================================================
104 // function : TextureName
105 // purpose  :
106 // =======================================================================
107 TCollection_AsciiString Graphic3d_Texture2D::TextureName (const Standard_Integer theRank)
108 {
109   if (theRank < 1 || theRank > NumberOfTextures())
110   {
111     throw Standard_OutOfRange("BAD index of texture");
112   }
113
114   TCollection_AsciiString aFileName (NameOfTexture_to_FileName[theRank - 1]);
115   Standard_Integer i = aFileName.SearchFromEnd (".");
116   return aFileName.SubString (4, i - 1);
117 }
118
119 // =======================================================================
120 // function : SetImage
121 // purpose  :
122 // =======================================================================
123 void Graphic3d_Texture2D::SetImage (const Handle(Image_PixMap)& thePixMap)
124 {
125   myPixMap = thePixMap;
126   myPath = OSD_Path();
127   myName = Graphic3d_NOT_2D_UNKNOWN;
128 }