1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : Material_ResourceMgr.cxx
21 // Author : Margarita KARPUNINA, Open CASCADE S.A.S. (margarita.karpunina@opencascade.com)
23 #include "Material_ResourceMgr.h"
26 \class Material_ResourceMgr
27 \brief Material properties resources manager.
29 This class is used to manage the material properties throughout the application
30 in the similar way as QtxResourceMgr does it with application preferences.
32 Standard material types are stored in the global application settings files
33 (named as SalomeMaterial.xml). User-defined materials are stored in user's home
34 directory - in the file .SalomeMaterialrc.
36 The Material_ResourceMgr class is used by material properties dialog box
37 (GEOMToolsGUI_MaterialPropertiesDlg class).
43 Material_ResourceMgr::Material_ResourceMgr()
44 : QtxResourceMgr( "SalomeMaterial", "%1Config" )
46 if ( dirList().isEmpty() && ::getenv( "GEOM_ROOT_DIR" ) )
47 setDirList( QStringList() << Qtx::addSlash( ::getenv( "GEOM_ROOT_DIR" ) ) + "share/salome/resources/geom" );
48 setCurrentFormat( "xml" );
54 Material_ResourceMgr::~Material_ResourceMgr()
59 \brief Get list of avaiable materials
60 \param theType material type
61 \param theSort if \c true (default), returns a list of materials sorted by name
62 \return list of avaiable materials names
64 QStringList Material_ResourceMgr::materials( MaterialType theType, bool theSort )
66 // store original working mode
67 WorkingMode m = workingMode();
69 QStringList slglobal, sluser;
71 // retrieve all materials : global + user
72 setWorkingMode( AllowUserValues );
75 // retrieve only global materials
76 setWorkingMode( IgnoreUserValues );
77 slglobal = sections();
79 // remove global materials from user list to obtain only user materials
80 QMutableListIterator<QString> it( sluser );
81 while ( it.hasNext() ) {
82 QString s = it.next();
83 if ( slglobal.contains( s ) ) it.remove();
86 // remove 'common' material
87 slglobal.removeAll("[common]");
89 // restore original working mode
92 // sort if necessary (separately global and user materials)
98 // combine the materials to obtain result list
109 result = slglobal + sluser;