1 // Created on: 1997-07-28
2 // Created by: Pierre CHALAMET
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 #include <Graphic3d_TextureRoot.ixx>
22 #include <Graphic3d_GraphicDriver.hxx>
24 #include <Image_AlienPixMap.hxx>
26 #include <OSD_Directory.hxx>
27 #include <OSD_Environment.hxx>
28 #include <OSD_Path.hxx>
29 #include <OSD_Protection.hxx>
30 #include <OSD_File.hxx>
31 #include <Standard_Atomic.hxx>
35 static volatile Standard_Integer THE_TEXTURE_COUNTER = 0;
38 // =======================================================================
39 // function : TexturesFolder
41 // =======================================================================
42 TCollection_AsciiString Graphic3d_TextureRoot::TexturesFolder()
44 static Standard_Boolean IsDefined = Standard_False;
45 static TCollection_AsciiString VarName;
48 IsDefined = Standard_True;
49 OSD_Environment aTexDirEnv ("CSF_MDTVTexturesDirectory");
50 VarName = aTexDirEnv.Value();
51 if (VarName.IsEmpty())
53 OSD_Environment aCasRootEnv ("CASROOT");
54 VarName = aCasRootEnv.Value();
55 if (!VarName.IsEmpty())
57 VarName += "/src/Textures";
61 if (VarName.IsEmpty())
63 std::cerr << " CSF_MDTVTexturesDirectory and CASROOT not setted\n";
64 std::cerr << " one of these variable are mandatory to use this functionality\n";
65 Standard_Failure::Raise ("CSF_MDTVTexturesDirectory and CASROOT not setted");
69 const OSD_Path aDirPath (VarName);
70 OSD_Directory aDir (aDirPath);
71 const TCollection_AsciiString aTexture = VarName + "/2d_MatraDatavision.rgb";
72 OSD_File aTextureFile (aTexture);
73 if (!aDir.Exists() || !aTextureFile.Exists())
75 std::cerr << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted\n";
76 std::cerr << " not all files are found in : "<< VarName.ToCString() << std::endl;
77 Standard_Failure::Raise ("CSF_MDTVTexturesDirectory or CASROOT not correctly setted");
84 // =======================================================================
85 // function : Graphic3d_TextureRoot
87 // =======================================================================
88 Graphic3d_TextureRoot::Graphic3d_TextureRoot (const TCollection_AsciiString& theFileName,
89 const Graphic3d_TypeOfTexture theType)
90 : myParams (new Graphic3d_TextureParams()),
94 myTexId = TCollection_AsciiString ("Graphic3d_TextureRoot_") //DynamicType()->Name()
95 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_TEXTURE_COUNTER));
98 // =======================================================================
101 // =======================================================================
102 void Graphic3d_TextureRoot::Destroy() const
107 // =======================================================================
110 // =======================================================================
111 const TCollection_AsciiString& Graphic3d_TextureRoot::GetId() const
116 // =======================================================================
117 // function : GetParams
119 // =======================================================================
120 const Handle(Graphic3d_TextureParams)& Graphic3d_TextureRoot::GetParams() const
125 // =======================================================================
126 // function : GetImage
128 // =======================================================================
129 Handle(Image_PixMap) Graphic3d_TextureRoot::GetImage() const
131 TCollection_AsciiString aFilePath;
132 myPath.SystemName (aFilePath);
133 if (aFilePath.IsEmpty())
135 return Handle(Image_PixMap)();
138 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
139 if (!anImage->Load (aFilePath))
141 return Handle(Image_PixMap)();
147 // =======================================================================
150 // =======================================================================
151 Standard_Boolean Graphic3d_TextureRoot::IsDone() const
153 OSD_File aTextureFile (myPath);
154 return aTextureFile.Exists();
157 // =======================================================================
160 // =======================================================================
161 const OSD_Path& Graphic3d_TextureRoot::Path() const
166 // =======================================================================
169 // =======================================================================
170 Graphic3d_TypeOfTexture Graphic3d_TextureRoot::Type() const