Back to index

salome-geom  6.5.0
Material_ResourceMgr.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // File   : Material_ResourceMgr.cxx
00021 // Author : Margarita KARPUNINA, Open CASCADE S.A.S. (margarita.karpunina@opencascade.com)
00022 
00023 #include "Material_ResourceMgr.h"
00024 
00043 Material_ResourceMgr::Material_ResourceMgr()
00044   : QtxResourceMgr( "SalomeMaterial", "%1Config" )
00045 {
00046   if ( dirList().isEmpty() && ::getenv( "GEOM_ROOT_DIR" ) )
00047     setDirList( QStringList() << Qtx::addSlash( ::getenv( "GEOM_ROOT_DIR" ) ) + "share/salome/resources/geom" );
00048   setCurrentFormat( "xml" );
00049 }
00050 
00054 Material_ResourceMgr::~Material_ResourceMgr()
00055 {
00056 }
00057 
00064 QStringList Material_ResourceMgr::materials( MaterialType theType, bool theSort )
00065 {
00066   // store original working mode
00067   WorkingMode m = workingMode();
00068 
00069   QStringList slglobal, sluser;
00070 
00071   // retrieve all materials : global + user
00072   setWorkingMode( AllowUserValues );
00073   sluser = sections();
00074 
00075   // retrieve only global materials
00076   setWorkingMode( IgnoreUserValues );
00077   slglobal = sections();
00078 
00079   // remove global materials from user list to obtain only user materials
00080   QMutableListIterator<QString> it( sluser );
00081   while ( it.hasNext() ) {
00082     QString s = it.next();
00083     if ( slglobal.contains( s ) ) it.remove();
00084   }
00085 
00086   // remove 'common' material 
00087   slglobal.removeAll("[common]");
00088 
00089   // restore original working mode
00090   setWorkingMode( m );
00091 
00092   // sort if necessary (separately global and user materials)
00093   if ( theSort ) {
00094     qSort( slglobal );
00095     qSort( sluser );
00096   }
00097 
00098   // combine the materials to obtain result list
00099   QStringList result;
00100   
00101   switch ( theType ) {
00102   case Global:
00103     result = slglobal;
00104     break;
00105   case User:
00106     result = sluser;
00107     break;
00108   case All:
00109     result = slglobal + sluser;
00110     break;
00111   default:
00112     break;
00113   }
00114 
00115   return result;
00116 }