b311480e |
1 | // Created on: 1997-07-28 |
2 | // Created by: Pierre CHALAMET |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
7fd59977 |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
d2edda76 |
17 | #include <Graphic3d_TextureRoot.hxx> |
7fd59977 |
18 | |
42cf5bc1 |
19 | #include <Graphic3d_GraphicDriver.hxx> |
20 | #include <Graphic3d_TextureParams.hxx> |
3c3131a0 |
21 | #include <Image_AlienPixMap.hxx> |
bf75be98 |
22 | #include <OSD_Directory.hxx> |
23 | #include <OSD_Environment.hxx> |
42cf5bc1 |
24 | #include <OSD_File.hxx> |
7fd59977 |
25 | #include <OSD_Protection.hxx> |
bf75be98 |
26 | #include <Standard_Atomic.hxx> |
27 | |
d2edda76 |
28 | IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_TextureRoot, Standard_Transient) |
92efcf78 |
29 | |
bf75be98 |
30 | namespace |
31 | { |
32 | static volatile Standard_Integer THE_TEXTURE_COUNTER = 0; |
a3f6f591 |
33 | } |
7fd59977 |
34 | |
3c3131a0 |
35 | // ======================================================================= |
bf75be98 |
36 | // function : TexturesFolder |
3c3131a0 |
37 | // purpose : |
38 | // ======================================================================= |
bf75be98 |
39 | TCollection_AsciiString Graphic3d_TextureRoot::TexturesFolder() |
7fd59977 |
40 | { |
bf75be98 |
41 | static Standard_Boolean IsDefined = Standard_False; |
42 | static TCollection_AsciiString VarName; |
43 | if (!IsDefined) |
7fd59977 |
44 | { |
bf75be98 |
45 | IsDefined = Standard_True; |
46 | OSD_Environment aTexDirEnv ("CSF_MDTVTexturesDirectory"); |
47 | VarName = aTexDirEnv.Value(); |
48 | if (VarName.IsEmpty()) |
49 | { |
50 | OSD_Environment aCasRootEnv ("CASROOT"); |
51 | VarName = aCasRootEnv.Value(); |
52 | if (!VarName.IsEmpty()) |
53 | { |
54 | VarName += "/src/Textures"; |
55 | } |
56 | } |
57 | |
58 | if (VarName.IsEmpty()) |
59 | { |
0797d9d3 |
60 | #ifdef OCCT_DEBUG |
392ac980 |
61 | std::cerr << "Both environment variables CSF_MDTVTexturesDirectory and CASROOT are undefined!\n" |
62 | << "At least one should be defined to use standard Textures.\n"; |
63c629aa |
63 | #endif |
9775fa61 |
64 | throw Standard_Failure("CSF_MDTVTexturesDirectory and CASROOT are undefined"); |
bf75be98 |
65 | } |
66 | |
67 | const OSD_Path aDirPath (VarName); |
68 | OSD_Directory aDir (aDirPath); |
69 | const TCollection_AsciiString aTexture = VarName + "/2d_MatraDatavision.rgb"; |
70 | OSD_File aTextureFile (aTexture); |
71 | if (!aDir.Exists() || !aTextureFile.Exists()) |
72 | { |
0797d9d3 |
73 | #ifdef OCCT_DEBUG |
bf75be98 |
74 | std::cerr << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted\n"; |
75 | std::cerr << " not all files are found in : "<< VarName.ToCString() << std::endl; |
63c629aa |
76 | #endif |
9775fa61 |
77 | throw Standard_Failure("CSF_MDTVTexturesDirectory or CASROOT not correctly setted"); |
bf75be98 |
78 | } |
7fd59977 |
79 | } |
bf75be98 |
80 | return VarName; |
7fd59977 |
81 | } |
82 | |
3c3131a0 |
83 | // ======================================================================= |
bf75be98 |
84 | // function : Graphic3d_TextureRoot |
3c3131a0 |
85 | // purpose : |
86 | // ======================================================================= |
bf75be98 |
87 | Graphic3d_TextureRoot::Graphic3d_TextureRoot (const TCollection_AsciiString& theFileName, |
88 | const Graphic3d_TypeOfTexture theType) |
d2edda76 |
89 | : myParams (new Graphic3d_TextureParams()), |
90 | myPath (theFileName), |
91 | myRevision (0), |
ba00aab7 |
92 | myType (theType), |
93 | myIsColorMap (true) |
7fd59977 |
94 | { |
d2edda76 |
95 | generateId(); |
7fd59977 |
96 | } |
97 | |
f376ac72 |
98 | // ======================================================================= |
99 | // function : Graphic3d_TextureRoot |
100 | // purpose : |
101 | // ======================================================================= |
102 | Graphic3d_TextureRoot::Graphic3d_TextureRoot (const Handle(Image_PixMap)& thePixMap, |
103 | const Graphic3d_TypeOfTexture theType) |
d2edda76 |
104 | : myParams (new Graphic3d_TextureParams()), |
105 | myPixMap (thePixMap), |
106 | myRevision (0), |
ba00aab7 |
107 | myType (theType), |
108 | myIsColorMap (true) |
f376ac72 |
109 | { |
d2edda76 |
110 | generateId(); |
f376ac72 |
111 | } |
112 | |
3c3131a0 |
113 | // ======================================================================= |
d2edda76 |
114 | // function : ~Graphic3d_TextureRoot |
3c3131a0 |
115 | // purpose : |
116 | // ======================================================================= |
d2edda76 |
117 | Graphic3d_TextureRoot::~Graphic3d_TextureRoot() |
7fd59977 |
118 | { |
bf75be98 |
119 | // |
7fd59977 |
120 | } |
121 | |
3c3131a0 |
122 | // ======================================================================= |
d2edda76 |
123 | // function : generateId |
3c3131a0 |
124 | // purpose : |
125 | // ======================================================================= |
d2edda76 |
126 | void Graphic3d_TextureRoot::generateId() |
7fd59977 |
127 | { |
d2edda76 |
128 | myTexId = TCollection_AsciiString ("Graphic3d_TextureRoot_") |
129 | + TCollection_AsciiString (Standard_Atomic_Increment (&THE_TEXTURE_COUNTER)); |
3c3131a0 |
130 | } |
7fd59977 |
131 | |
3c3131a0 |
132 | // ======================================================================= |
bf75be98 |
133 | // function : GetImage |
3c3131a0 |
134 | // purpose : |
135 | // ======================================================================= |
bf75be98 |
136 | Handle(Image_PixMap) Graphic3d_TextureRoot::GetImage() const |
7fd59977 |
137 | { |
f376ac72 |
138 | // Case 1: texture source is specified as pixmap |
139 | if (!myPixMap.IsNull()) |
140 | { |
141 | return myPixMap; |
142 | } |
143 | |
144 | // Case 2: texture source is specified as path |
bf75be98 |
145 | TCollection_AsciiString aFilePath; |
146 | myPath.SystemName (aFilePath); |
147 | if (aFilePath.IsEmpty()) |
148 | { |
149 | return Handle(Image_PixMap)(); |
150 | } |
151 | |
152 | Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap(); |
153 | if (!anImage->Load (aFilePath)) |
154 | { |
155 | return Handle(Image_PixMap)(); |
156 | } |
157 | |
158 | return anImage; |
7fd59977 |
159 | } |
160 | |
3c3131a0 |
161 | // ======================================================================= |
bf75be98 |
162 | // function : IsDone |
3c3131a0 |
163 | // purpose : |
164 | // ======================================================================= |
bf75be98 |
165 | Standard_Boolean Graphic3d_TextureRoot::IsDone() const |
7fd59977 |
166 | { |
f376ac72 |
167 | // Case 1: texture source is specified as pixmap |
168 | if (!myPixMap.IsNull()) |
169 | { |
170 | return !myPixMap->IsEmpty(); |
171 | } |
172 | |
173 | // Case 2: texture source is specified as path |
bf75be98 |
174 | OSD_File aTextureFile (myPath); |
175 | return aTextureFile.Exists(); |
7fd59977 |
176 | } |