1 // Created on: 1993-01-18
2 // Created by: Gilles DEBARBOUILLE
3 // Copyright (c) 1993-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.
22 // CRD : 03/07/97 : Portage Windows NT.
27 #include <Materials_MaterialsDictionary.ixx>
29 #ifdef HAVE_SYS_TYPES_H
30 # include <sys/types.h>
32 #if defined (HAVE_SYS_STAT_H) || defined (WNT)
33 # include <sys/stat.h>
42 #include <Standard_Stream.hxx>
44 #include <Materials.hxx>
45 #include <Materials_MaterialsSequence.hxx>
46 #include <Materials_Material.hxx>
47 #include <Materials_Color.hxx>
48 #include <Quantity_Color.hxx>
49 #include <TCollection_AsciiString.hxx>
54 //#define strcasecmp _stricoll
58 //=======================================================================
59 //function : Materials_MaterialsDictionary
61 //=======================================================================
63 Materials_MaterialsDictionary::Materials_MaterialsDictionary()
65 Standard_Integer i,fr,begin,end,lengthname;
71 char value1[80],value2[80],value3[80];
72 Handle(Materials_MaterialsSequence) materialssequence;
73 Handle(Materials_Material) material;
74 Handle(Materials_Color) pcolor;
78 Standard_CString filename = Materials::MaterialsFile();
80 ifstream file(filename);
83 cout<<"unable to open "<<filename<<" for input"<<endl;
87 thefilename = new TCollection_HAsciiString(filename);
89 if(!stat(filename, &buf)) thetime = buf.st_ctime;
91 thematerialssequence = new Materials_MaterialsSequence();
95 for(i=0; i<255; i++) line[i]=0;
96 file.getline(line,255);
100 while( i >= 0 && ( line[i] == ' ' || !line[i]))line[i--] = 0;
106 material = new Materials_Material(line);
107 thematerialssequence->Append(material);
128 for(i=0; i<80; i++)name[i]=0;
131 for(i=begin+1; i<=end-1; i++)name[lengthname++] = line[i];
133 for(i=0; i<80; i++)type [i] = 0;
134 for(i=0; i<80; i++)value1 [i] = 0;
135 for(i=0; i<80; i++)value2 [i] = 0;
136 for(i=0; i<80; i++)value3 [i] = 0;
138 // fr = sscanf(&line[end+1],"%s%s%s%s",&type,&value1,&value2,&value3);
139 fr = sscanf(&line[end+1],"%s%s%s%s",type,value1,value2,value3);
141 if(fr == -1) continue;
143 if (!strcasecmp(type,"Materials_Color"))
146 (Atof(value1),Atof(value2),Atof(value3),Quantity_TOC_RGB);
147 pcolor = new Materials_Color(color);
148 material->Parameter(name,pcolor);
150 else if(!strcasecmp(type,"Standard_Real"))
152 material->Parameter(name,Atof(value1));
154 else if(!strcasecmp(type,"Standard_CString"))
156 material->Parameter(name,value1);
163 //=======================================================================
164 //function : Material
166 //=======================================================================
168 Handle(Materials_Material) Materials_MaterialsDictionary::Material
169 (const Standard_CString amaterial) const
171 Handle(Materials_Material) material;
173 for(Standard_Integer index=1;index<=thematerialssequence->Length();index++)
175 material = thematerialssequence->Value(index);
176 if(material->Name() == amaterial) return material;
178 Standard_NoSuchObject::Raise("Material not in the dictionary");
179 // Pour compil sur NT ....
183 Standard_Boolean Materials_MaterialsDictionary::ExistMaterial(const Standard_CString amaterial) const
185 Handle(Materials_Material) material;
187 for(Standard_Integer index=1;index<=thematerialssequence->Length();index++)
189 material = thematerialssequence->Value(index);
190 if(material->Name() == amaterial) return Standard_True;
192 return Standard_False;
195 //=======================================================================
196 //function : NumberOfMaterials
198 //=======================================================================
200 Standard_Integer Materials_MaterialsDictionary::NumberOfMaterials() const
202 return thematerialssequence->Length();
205 //=======================================================================
206 //function : Material
208 //=======================================================================
210 Handle(Materials_Material) Materials_MaterialsDictionary::Material
211 (const Standard_Integer anindex) const
213 return thematerialssequence->Value(anindex);
216 //=======================================================================
217 //function : UpToDate
219 //=======================================================================
221 Standard_Boolean Materials_MaterialsDictionary::UpToDate() const
225 TCollection_AsciiString string = thefilename->String();
226 if(!stat(string.ToCString(),&buf))
228 if(thetime == buf.st_ctime) return Standard_True;
231 return Standard_False;
234 //=======================================================================
237 //=======================================================================
239 void Materials_MaterialsDictionary::Dump(Standard_OStream& astream) const
241 Standard_Integer index;
242 Handle(Materials_Material) material;
244 for(index=1;index<=thematerialssequence->Length();index++)
246 material = thematerialssequence->Value(index);
247 material->Dump(astream);