0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / Graphic3d / Graphic3d_TextureRoot.cxx
CommitLineData
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
7fd59977 17
42cf5bc1 18#include <Graphic3d_GraphicDriver.hxx>
19#include <Graphic3d_TextureParams.hxx>
20#include <Graphic3d_TextureRoot.hxx>
3c3131a0 21#include <Image_AlienPixMap.hxx>
bf75be98 22#include <OSD_Directory.hxx>
23#include <OSD_Environment.hxx>
42cf5bc1 24#include <OSD_File.hxx>
bf75be98 25#include <OSD_Path.hxx>
7fd59977 26#include <OSD_Protection.hxx>
bf75be98 27#include <Standard_Atomic.hxx>
42cf5bc1 28#include <Standard_Type.hxx>
29#include <TCollection_AsciiString.hxx>
bf75be98 30
92efcf78 31IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_TextureRoot,MMgt_TShared)
32
bf75be98 33namespace
34{
35 static volatile Standard_Integer THE_TEXTURE_COUNTER = 0;
36};
7fd59977 37
3c3131a0 38// =======================================================================
bf75be98 39// function : TexturesFolder
3c3131a0 40// purpose :
41// =======================================================================
bf75be98 42TCollection_AsciiString Graphic3d_TextureRoot::TexturesFolder()
7fd59977 43{
bf75be98 44 static Standard_Boolean IsDefined = Standard_False;
45 static TCollection_AsciiString VarName;
46 if (!IsDefined)
7fd59977 47 {
bf75be98 48 IsDefined = Standard_True;
49 OSD_Environment aTexDirEnv ("CSF_MDTVTexturesDirectory");
50 VarName = aTexDirEnv.Value();
51 if (VarName.IsEmpty())
52 {
53 OSD_Environment aCasRootEnv ("CASROOT");
54 VarName = aCasRootEnv.Value();
55 if (!VarName.IsEmpty())
56 {
57 VarName += "/src/Textures";
58 }
59 }
60
61 if (VarName.IsEmpty())
62 {
0797d9d3 63#ifdef OCCT_DEBUG
392ac980 64 std::cerr << "Both environment variables CSF_MDTVTexturesDirectory and CASROOT are undefined!\n"
65 << "At least one should be defined to use standard Textures.\n";
63c629aa 66#endif
392ac980 67 Standard_Failure::Raise ("CSF_MDTVTexturesDirectory and CASROOT are undefined");
bf75be98 68 return VarName;
69 }
70
71 const OSD_Path aDirPath (VarName);
72 OSD_Directory aDir (aDirPath);
73 const TCollection_AsciiString aTexture = VarName + "/2d_MatraDatavision.rgb";
74 OSD_File aTextureFile (aTexture);
75 if (!aDir.Exists() || !aTextureFile.Exists())
76 {
0797d9d3 77#ifdef OCCT_DEBUG
bf75be98 78 std::cerr << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted\n";
79 std::cerr << " not all files are found in : "<< VarName.ToCString() << std::endl;
63c629aa 80#endif
bf75be98 81 Standard_Failure::Raise ("CSF_MDTVTexturesDirectory or CASROOT not correctly setted");
82 return VarName;
83 }
7fd59977 84 }
bf75be98 85 return VarName;
7fd59977 86}
87
3c3131a0 88// =======================================================================
bf75be98 89// function : Graphic3d_TextureRoot
3c3131a0 90// purpose :
91// =======================================================================
bf75be98 92Graphic3d_TextureRoot::Graphic3d_TextureRoot (const TCollection_AsciiString& theFileName,
93 const Graphic3d_TypeOfTexture theType)
94: myParams (new Graphic3d_TextureParams()),
95 myPath (theFileName),
96 myType (theType)
7fd59977 97{
bf75be98 98 myTexId = TCollection_AsciiString ("Graphic3d_TextureRoot_") //DynamicType()->Name()
99 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_TEXTURE_COUNTER));
7fd59977 100}
101
3c3131a0 102// =======================================================================
f376ac72 103// function : Graphic3d_TextureRoot
104// purpose :
105// =======================================================================
106Graphic3d_TextureRoot::Graphic3d_TextureRoot (const Handle(Image_PixMap)& thePixMap,
107 const Graphic3d_TypeOfTexture theType)
108: myParams (new Graphic3d_TextureParams()),
109 myPixMap (thePixMap),
110 myType (theType)
111{
112 myTexId = TCollection_AsciiString ("Graphic3d_TextureRoot_")
113 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_TEXTURE_COUNTER));
114}
115
116// =======================================================================
bf75be98 117// function : Destroy
3c3131a0 118// purpose :
119// =======================================================================
bf75be98 120void Graphic3d_TextureRoot::Destroy() const
7fd59977 121{
bf75be98 122 //
7fd59977 123}
124
3c3131a0 125// =======================================================================
bf75be98 126// function : GetId
3c3131a0 127// purpose :
128// =======================================================================
fd4a6963 129const TCollection_AsciiString& Graphic3d_TextureRoot::GetId() const
7fd59977 130{
bf75be98 131 return myTexId;
7fd59977 132}
133
3c3131a0 134// =======================================================================
bf75be98 135// function : GetParams
3c3131a0 136// purpose :
137// =======================================================================
bf75be98 138const Handle(Graphic3d_TextureParams)& Graphic3d_TextureRoot::GetParams() const
3c3131a0 139{
bf75be98 140 return myParams;
3c3131a0 141}
7fd59977 142
3c3131a0 143// =======================================================================
bf75be98 144// function : GetImage
3c3131a0 145// purpose :
146// =======================================================================
bf75be98 147Handle(Image_PixMap) Graphic3d_TextureRoot::GetImage() const
7fd59977 148{
f376ac72 149 // Case 1: texture source is specified as pixmap
150 if (!myPixMap.IsNull())
151 {
152 return myPixMap;
153 }
154
155 // Case 2: texture source is specified as path
bf75be98 156 TCollection_AsciiString aFilePath;
157 myPath.SystemName (aFilePath);
158 if (aFilePath.IsEmpty())
159 {
160 return Handle(Image_PixMap)();
161 }
162
163 Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap();
164 if (!anImage->Load (aFilePath))
165 {
166 return Handle(Image_PixMap)();
167 }
168
169 return anImage;
7fd59977 170}
171
3c3131a0 172// =======================================================================
bf75be98 173// function : IsDone
3c3131a0 174// purpose :
175// =======================================================================
bf75be98 176Standard_Boolean Graphic3d_TextureRoot::IsDone() const
7fd59977 177{
f376ac72 178 // Case 1: texture source is specified as pixmap
179 if (!myPixMap.IsNull())
180 {
181 return !myPixMap->IsEmpty();
182 }
183
184 // Case 2: texture source is specified as path
bf75be98 185 OSD_File aTextureFile (myPath);
186 return aTextureFile.Exists();
7fd59977 187}
188
3c3131a0 189// =======================================================================
190// function : Path
191// purpose :
192// =======================================================================
193const OSD_Path& Graphic3d_TextureRoot::Path() const
194{
195 return myPath;
7fd59977 196}
197
3c3131a0 198// =======================================================================
199// function : Type
200// purpose :
201// =======================================================================
202Graphic3d_TypeOfTexture Graphic3d_TextureRoot::Type() const
203{
204 return myType;
7fd59977 205}