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 Standard_Failure::Raise ("CSF_MDTVTexturesDirectory and CASROOT are undefined");
68 const OSD_Path aDirPath (VarName);
69 OSD_Directory aDir (aDirPath);
70 const TCollection_AsciiString aTexture = VarName + "/2d_MatraDatavision.rgb";
71 OSD_File aTextureFile (aTexture);
72 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;
78 Standard_Failure::Raise ("CSF_MDTVTexturesDirectory or CASROOT not correctly setted");
85 // =======================================================================
86 // function : Graphic3d_TextureRoot
88 // =======================================================================
89 Graphic3d_TextureRoot::Graphic3d_TextureRoot (const TCollection_AsciiString& theFileName,
90 const Graphic3d_TypeOfTexture theType)
91 : myParams (new Graphic3d_TextureParams()),
99 // =======================================================================
100 // function : Graphic3d_TextureRoot
102 // =======================================================================
103 Graphic3d_TextureRoot::Graphic3d_TextureRoot (const Handle(Image_PixMap)& thePixMap,
104 const Graphic3d_TypeOfTexture theType)
105 : myParams (new Graphic3d_TextureParams()),
106 myPixMap (thePixMap),
113 // =======================================================================
114 // function : ~Graphic3d_TextureRoot
116 // =======================================================================
117 Graphic3d_TextureRoot::~Graphic3d_TextureRoot()
122 // =======================================================================
123 // function : generateId
125 // =======================================================================
126 void Graphic3d_TextureRoot::generateId()
128 myTexId = TCollection_AsciiString ("Graphic3d_TextureRoot_")
129 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_TEXTURE_COUNTER));
132 // =======================================================================
133 // function : GetImage
135 // =======================================================================
136 Handle(Image_PixMap) Graphic3d_TextureRoot::GetImage() const
138 // Case 1: texture source is specified as pixmap
139 if (!myPixMap.IsNull())
144 // Case 2: texture source is specified as path
145 TCollection_AsciiString aFilePath;
146 myPath.SystemName (aFilePath);
147 if (aFilePath.IsEmpty())
149 return Handle(Image_PixMap)();
152 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
153 if (!anImage->Load (aFilePath))
155 return Handle(Image_PixMap)();
161 // =======================================================================
164 // =======================================================================
165 Standard_Boolean Graphic3d_TextureRoot::IsDone() const
167 // Case 1: texture source is specified as pixmap
168 if (!myPixMap.IsNull())
170 return !myPixMap->IsEmpty();
173 // Case 2: texture source is specified as path
174 OSD_File aTextureFile (myPath);
175 return aTextureFile.Exists();