00001
00002
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00029 #include <exotkMaterial.hxx>
00030
00031 #ifndef _Graphic3d_MaterialAspect_HeaderFile
00032 #include <Graphic3d_MaterialAspect.hxx>
00033 #endif
00034 #ifndef _exotkMaterial_MapOfMaterial_HeaderFile
00035 #include <exotkMaterial_MapOfMaterial.hxx>
00036 #endif
00037 #ifndef _TCollection_AsciiString_HeaderFile
00038 #include <TCollection_AsciiString.hxx>
00039 #endif
00040 #ifndef _exotkMaterial_Material_HeaderFile
00041 #include <exotkMaterial_Material.hxx>
00042 #endif
00043 #ifndef _exotkMaterial_MapIteratorOfMapOfMaterial_HeaderFile
00044 #include <exotkMaterial_MapIteratorOfMapOfMaterial.hxx>
00045 #endif
00046
00052 namespace exotkMaterial_Datas
00053 {
00055 exotkMaterial_MapOfMaterial theMap;
00057 exotkMaterial_MapIteratorOfMapOfMaterial theIterator;
00059 Standard_Boolean theInitIsDone = Standard_False;
00060 }
00061
00062
00063
00071 Standard_Boolean IsSameMaterial(const Graphic3d_MaterialAspect& mat1,const Graphic3d_MaterialAspect& mat2)
00072 {
00073 Quantity_Parameter theOldColorEpsilon = Quantity_Color::Epsilon();
00074 Quantity_Color::SetEpsilon(0.03);
00075
00076 Standard_Boolean theIsEqual = (Abs(mat1.Ambient()- mat2.Ambient())<=0.03 &&
00077 Abs(mat1.Diffuse()- mat2.Diffuse())<=0.03 &&
00078 Abs(mat1.Specular()- mat2.Specular())<=0.03 &&
00079 Abs(mat1.Emissive()- mat2.Emissive())<=0.03 &&
00080 Abs(mat1.Transparency()- mat2.Transparency())<=0.03 &&
00081 Abs(mat1.Shininess ()- mat2.Shininess())<=0.03 &&
00082 Abs(mat1.EnvReflexion()- mat2.EnvReflexion())<=0.03 &&
00083 mat1.AmbientColor() == mat2.AmbientColor() &&
00084 mat1.DiffuseColor() == mat2.DiffuseColor() &&
00085 mat1.SpecularColor() == mat2.SpecularColor() &&
00086 mat1.EmissiveColor() == mat2.EmissiveColor() &&
00087 mat1.ReflectionMode(Graphic3d_TOR_AMBIENT) == mat2.ReflectionMode(Graphic3d_TOR_AMBIENT) &&
00088 mat1.ReflectionMode(Graphic3d_TOR_DIFFUSE) == mat2.ReflectionMode(Graphic3d_TOR_DIFFUSE) &&
00089 mat1.ReflectionMode(Graphic3d_TOR_SPECULAR) == mat2.ReflectionMode(Graphic3d_TOR_SPECULAR) &&
00090 mat1.ReflectionMode(Graphic3d_TOR_EMISSION) == mat2.ReflectionMode(Graphic3d_TOR_EMISSION));
00091
00092 Quantity_Color::SetEpsilon(theOldColorEpsilon);
00093 return theIsEqual;
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 void exotkMaterial::InitStandardMaterials()
00105 {
00106 if (!exotkMaterial_Datas::theInitIsDone)
00107 {
00108 exotkMaterial_Datas::theInitIsDone = Standard_True;
00109 for (Standard_Integer iter = 0; iter <(Standard_Integer)Graphic3d_NOM_DEFAULT; iter++)
00110 {
00111 try
00112 {
00113 Graphic3d_MaterialAspect theMat((Graphic3d_NameOfMaterial)iter);
00114 TCollection_AsciiString theName = Graphic3d_MaterialAspect::MaterialName(iter + 1);
00115 theName.Capitalize();
00116 Handle_exotkMaterial_Material theMaterial = new exotkMaterial_Material(theMat,theName);
00117 theMaterial->SetModifiable(Standard_False);
00118 exotkMaterial_Datas::theMap.Add(theMaterial);
00119 }
00120 catch (Standard_Failure)
00121 {
00122 }
00123 catch (...)
00124 {
00125 }
00126 }
00127 }
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137 Standard_Boolean exotkMaterial::CurrentMaterial(Graphic3d_MaterialAspect& aMaterial)
00138 {
00139 Standard_Boolean success = Standard_False;
00140 Handle_exotkMaterial_Material theMaterial = exotkMaterial_Datas::theIterator.Key();
00141 if ( !theMaterial.IsNull() )
00142 {
00143 aMaterial = theMaterial->Material();
00144 success = Standard_True;
00145 }
00146 return success;
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156 Standard_Boolean exotkMaterial::CurrentName(TCollection_AsciiString& aName)
00157 {
00158 Standard_Boolean success = Standard_False;
00159 Handle_exotkMaterial_Material theMaterial = exotkMaterial_Datas::theIterator.Key();
00160 if ( !theMaterial.IsNull() )
00161 {
00162 aName = theMaterial->Name();
00163 success = Standard_True;
00164 }
00165 return success;
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175 void exotkMaterial::NextMaterialIterator()
00176 {
00177 exotkMaterial_Datas::theIterator.Next();
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
00187 Standard_Boolean exotkMaterial::MoreMaterialIterator()
00188 {
00189 return exotkMaterial_Datas::theIterator.More();
00190 }
00191
00192
00193
00194
00195
00196
00197
00198
00199 void exotkMaterial::InitMaterialIterator()
00200 {
00201 InitStandardMaterials();
00202 exotkMaterial_Datas::theIterator.Initialize(exotkMaterial_Datas::theMap);
00203 }
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 Standard_Boolean exotkMaterial::IsModifiable(const TCollection_AsciiString &aName,Standard_Boolean& aIsModifiable)
00216 {
00217 InitStandardMaterials();
00218 Standard_Boolean theMaterialIsFound = Standard_False;
00219 Handle_exotkMaterial_Material theMaterial = FindMaterial(aName);
00220 if ( !theMaterial.IsNull())
00221 {
00222 theMaterialIsFound = Standard_True;
00223 aIsModifiable = theMaterial->IsModifiable();
00224 }
00225 return theMaterialIsFound;
00226 }
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 Standard_Boolean exotkMaterial::IsModifiable(const Graphic3d_MaterialAspect &aMaterial,Standard_Boolean& aIsModifiable)
00238 {
00239 InitStandardMaterials();
00240 Standard_Boolean theMaterialIsFound = Standard_False;
00241 Handle_exotkMaterial_Material theMaterial = FindMaterial(aMaterial);
00242 if ( !theMaterial.IsNull())
00243 {
00244 theMaterialIsFound = Standard_True;
00245 aIsModifiable = theMaterial->IsModifiable();
00246 }
00247 return theMaterialIsFound;
00248 }
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 Handle_exotkMaterial_Material exotkMaterial::FindMaterial(const Graphic3d_MaterialAspect& aMaterial)
00259 {
00260 InitStandardMaterials();
00261 exotkMaterial_MapIteratorOfMapOfMaterial theMapIterator;
00262 Standard_Boolean theIsFound = Standard_False;
00263 Handle_exotkMaterial_Material theFoundMaterial;
00264 for ( theMapIterator.Initialize(exotkMaterial_Datas::theMap) ; !theIsFound && theMapIterator.More() ; theMapIterator.Next() )
00265 {
00266 Handle_exotkMaterial_Material theMaterial = theMapIterator.Key();
00267 theIsFound = IsSameMaterial(theMaterial->Material(),aMaterial);
00268 if ( theIsFound )
00269 theFoundMaterial = theMaterial;
00270 }
00271 return theFoundMaterial;
00272 }
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282 Handle_exotkMaterial_Material exotkMaterial::FindMaterial(const TCollection_AsciiString& aName)
00283 {
00284 InitStandardMaterials();
00285 exotkMaterial_MapIteratorOfMapOfMaterial theMapIterator;
00286 Standard_Boolean theIsFound = Standard_False;
00287 Handle_exotkMaterial_Material theFoundMaterial;
00288 for ( theMapIterator.Initialize(exotkMaterial_Datas::theMap) ; !theIsFound && theMapIterator.More() ; theMapIterator.Next() )
00289 {
00290 Handle_exotkMaterial_Material theMaterial = theMapIterator.Key();
00291 theIsFound = (theMaterial->Name()==aName);
00292 if ( theIsFound )
00293 theFoundMaterial = theMaterial;
00294 }
00295 return theFoundMaterial;
00296 }
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 Standard_Boolean exotkMaterial::FindName(const Graphic3d_MaterialAspect& aMaterial,TCollection_AsciiString& aFoundName)
00308 {
00309 Standard_Boolean theSuccess = Standard_False;
00310 InitStandardMaterials();
00311 Handle_exotkMaterial_Material theInternMaterial = FindMaterial(aMaterial);
00312 if ( !theInternMaterial.IsNull() )
00313 {
00314 aFoundName = theInternMaterial->Name();
00315 theSuccess = Standard_True;
00316 }
00317 return theSuccess;
00318 }
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329 Standard_Boolean exotkMaterial::FindMaterial(const TCollection_AsciiString& aName,Graphic3d_MaterialAspect& aFoundMaterial)
00330 {
00331 Standard_Boolean theSuccess = Standard_False;
00332 InitStandardMaterials();
00333 Handle_exotkMaterial_Material theInternMaterial = FindMaterial(aName);
00334 if ( !theInternMaterial.IsNull() )
00335 {
00336 aFoundMaterial = theInternMaterial->Material();
00337 theSuccess = Standard_True;
00338 }
00339 return theSuccess;
00340 }
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351 Standard_Boolean exotkMaterial::NameExists(const TCollection_AsciiString &aName)
00352 {
00353 return (!FindMaterial(aName).IsNull());
00354 }
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365 Standard_Boolean exotkMaterial::ReplaceMaterial(const TCollection_AsciiString& aName,const Graphic3d_MaterialAspect& aNewMaterial)
00366 {
00367 InitStandardMaterials();
00368 Standard_Boolean theSuccess = Standard_False;
00369 Handle_exotkMaterial_Material theInternMaterial = FindMaterial(aName);
00370 if ( !theInternMaterial.IsNull() )
00371 {
00372 if ( theInternMaterial->IsModifiable() )
00373 {
00374 theInternMaterial->SetMaterial(aNewMaterial);
00375 theSuccess = Standard_True;
00376 }
00377 }
00378 return theSuccess;
00379 }
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392 Standard_Boolean exotkMaterial::AddMaterial(const TCollection_AsciiString &aName, const Graphic3d_MaterialAspect &aMaterial,const Standard_Boolean aIsModifiable)
00393 {
00394 InitStandardMaterials();
00395 Handle_exotkMaterial_Material theInternMaterial = new exotkMaterial_Material(aMaterial,aName);
00396 theInternMaterial->SetModifiable(aIsModifiable);
00397 return exotkMaterial_Datas::theMap.Add(theInternMaterial);
00398 }