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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Graphic3d_TextureRoot.hxx>
19 #include <Graphic3d_GraphicDriver.hxx>
20 #include <Graphic3d_TextureParams.hxx>
21 #include <Image_AlienPixMap.hxx>
22 #include <OSD_Directory.hxx>
23 #include <OSD_Environment.hxx>
24 #include <OSD_File.hxx>
25 #include <OSD_Protection.hxx>
26 #include <Standard_Atomic.hxx>
28 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_TextureRoot, Standard_Transient)
32 static volatile Standard_Integer THE_TEXTURE_COUNTER = 0;
35 // =======================================================================
36 // function : TexturesFolder
38 // =======================================================================
39 TCollection_AsciiString Graphic3d_TextureRoot::TexturesFolder()
41 static Standard_Boolean IsDefined = Standard_False;
42 static TCollection_AsciiString VarName;
45 IsDefined = Standard_True;
46 OSD_Environment aTexDirEnv ("CSF_MDTVTexturesDirectory");
47 VarName = aTexDirEnv.Value();
48 if (VarName.IsEmpty())
50 OSD_Environment aCasRootEnv ("CASROOT");
51 VarName = aCasRootEnv.Value();
52 if (!VarName.IsEmpty())
54 VarName += "/src/Textures";
58 if (VarName.IsEmpty())
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";
64 throw Standard_Failure("CSF_MDTVTexturesDirectory and CASROOT are undefined");
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())
74 std::cerr << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted\n";
75 std::cerr << " not all files are found in : "<< VarName.ToCString() << std::endl;
77 throw Standard_Failure("CSF_MDTVTexturesDirectory or CASROOT not correctly setted");
83 // =======================================================================
84 // function : Graphic3d_TextureRoot
86 // =======================================================================
87 Graphic3d_TextureRoot::Graphic3d_TextureRoot (const TCollection_AsciiString& theFileName,
88 const Graphic3d_TypeOfTexture theType)
89 : myParams (new Graphic3d_TextureParams()),
97 // =======================================================================
98 // function : Graphic3d_TextureRoot
100 // =======================================================================
101 Graphic3d_TextureRoot::Graphic3d_TextureRoot (const Handle(Image_PixMap)& thePixMap,
102 const Graphic3d_TypeOfTexture theType)
103 : myParams (new Graphic3d_TextureParams()),
104 myPixMap (thePixMap),
111 // =======================================================================
112 // function : ~Graphic3d_TextureRoot
114 // =======================================================================
115 Graphic3d_TextureRoot::~Graphic3d_TextureRoot()
120 // =======================================================================
121 // function : generateId
123 // =======================================================================
124 void Graphic3d_TextureRoot::generateId()
126 myTexId = TCollection_AsciiString ("Graphic3d_TextureRoot_")
127 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_TEXTURE_COUNTER));
130 // =======================================================================
131 // function : GetImage
133 // =======================================================================
134 Handle(Image_PixMap) Graphic3d_TextureRoot::GetImage() const
136 // Case 1: texture source is specified as pixmap
137 if (!myPixMap.IsNull())
142 // Case 2: texture source is specified as path
143 TCollection_AsciiString aFilePath;
144 myPath.SystemName (aFilePath);
145 if (aFilePath.IsEmpty())
147 return Handle(Image_PixMap)();
150 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
151 if (!anImage->Load (aFilePath))
153 return Handle(Image_PixMap)();
159 // =======================================================================
162 // =======================================================================
163 Standard_Boolean Graphic3d_TextureRoot::IsDone() const
165 // Case 1: texture source is specified as pixmap
166 if (!myPixMap.IsNull())
168 return !myPixMap->IsEmpty();
171 // Case 2: texture source is specified as path
172 OSD_File aTextureFile (myPath);
173 return aTextureFile.Exists();