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 // Modified 22-12-97 : FMN ; Ajout Modulate
23 // Modified : GG 10/01/2000 IMP
24 // Adds Name(),NumberOfTextures() and TextureName() methods
26 #include <Graphic3d_Texture1D.ixx>
29 #include <TCollection_AsciiString.hxx>
30 #include <OSD_Directory.hxx>
31 #include <OSD_File.hxx>
32 #include <OSD_Path.hxx>
34 static const char *NameOfTexture_to_FileName[] =
40 static TCollection_AsciiString GetEnvir ( ) {
42 static Standard_Boolean IsDefined=Standard_False ;
43 static TCollection_AsciiString VarName;
45 char *envir, *casroot ;
46 envir = getenv("CSF_MDTVTexturesDirectory") ;
48 Standard_Boolean HasDefinition = Standard_False ;
50 casroot = getenv("CASROOT");
52 VarName = TCollection_AsciiString (casroot);
53 VarName += "/src/Textures" ;
54 HasDefinition = Standard_True ;
57 VarName = TCollection_AsciiString (envir);
58 HasDefinition = Standard_True ;
60 if ( HasDefinition ) {
61 OSD_Path aPath ( VarName );
62 OSD_Directory aDir(aPath);
63 if ( aDir.Exists () ) {
64 TCollection_AsciiString aTexture = VarName + "/2d_MatraDatavision.rgb" ;
65 OSD_File TextureFile ( aTexture );
66 if ( !TextureFile.Exists() ) {
67 cout << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << endl;
68 cout << " not all files are found in : "<<VarName.ToCString() << endl;
69 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
72 cout << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << endl;
73 cout << " Directory : "<< VarName.ToCString() << " not exist " << endl;
74 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " );
78 cout << " CSF_MDTVTexturesDirectory and CASROOT not setted " << endl;
79 cout << " one of these variable are mandatory to use this fonctionnality" << endl;
80 Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory and CASROOT not setted " );
83 IsDefined = Standard_True ;
88 Graphic3d_Texture1D::Graphic3d_Texture1D(const Handle(Graphic3d_StructureManager)& SM,const Standard_CString FileName,const Graphic3d_TypeOfTexture Type)
89 : Graphic3d_TextureMap(SM,"", FileName, Type),
90 myName(Graphic3d_NOT_1D_UNKNOWN)
95 Graphic3d_Texture1D::Graphic3d_Texture1D(const Handle(Graphic3d_StructureManager)& SM,const Graphic3d_NameOfTexture1D NOT, const Graphic3d_TypeOfTexture Type)
96 : Graphic3d_TextureMap(SM, GetEnvir().ToCString(), NameOfTexture_to_FileName[NOT], Type),
101 Graphic3d_NameOfTexture1D Graphic3d_Texture1D::Name() const {
106 Standard_Integer Graphic3d_Texture1D::NumberOfTextures() {
108 return sizeof(NameOfTexture_to_FileName)/sizeof(char*);
111 Standard_CString Graphic3d_Texture1D::TextureName(const Standard_Integer aRank)
114 if( aRank < 1 || aRank > NumberOfTextures() )
115 Standard_OutOfRange::Raise(" BAD index of texture");
116 TCollection_AsciiString filename(NameOfTexture_to_FileName[aRank-1]);
117 Standard_Integer i = filename.SearchFromEnd(".");
119 static TCollection_AsciiString name;
120 name = filename.SubString(4,i-1);
121 return name.ToCString();