2004-03-15 18:42:16 +00:00
|
|
|
// SMESH Driver : implementation of driver for reading and writing
|
2003-07-10 09:06:41 +00:00
|
|
|
//
|
|
|
|
// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
|
|
|
|
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2.1 of the License.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
//
|
|
|
|
// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
|
|
|
|
|
2003-05-19 14:07:00 +00:00
|
|
|
#include "SMESHDriver.h"
|
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <utilities.h>
|
|
|
|
|
2004-03-15 18:42:16 +00:00
|
|
|
Document_Reader* SMESHDriver::GetDocumentReader(string Extension)
|
|
|
|
{
|
|
|
|
// if there is not document reader in the driver create a default
|
|
|
|
// one with the mesh reader.
|
|
|
|
Document_Reader * docReader=
|
|
|
|
(Document_Reader*)getMeshDocumentDriver(Extension);
|
|
|
|
|
|
|
|
if(docReader==NULL)
|
|
|
|
{
|
|
|
|
Mesh_Reader * reader=GetMeshReader(Extension);
|
|
|
|
if(reader==NULL)
|
|
|
|
{
|
|
|
|
MESSAGE("No driver known for this extension");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return new Document_Reader(reader);
|
|
|
|
}
|
|
|
|
else return docReader;
|
2003-05-19 14:07:00 +00:00
|
|
|
}
|
|
|
|
|
2004-03-15 18:42:16 +00:00
|
|
|
Document_Writer* SMESHDriver::GetDocumentWriter(string Extension)
|
|
|
|
{
|
|
|
|
Mesh_Writer * writer=GetMeshWriter(Extension);
|
|
|
|
if(writer==NULL)
|
|
|
|
{
|
|
|
|
MESSAGE("No driver known for this extension");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return new Document_Writer(writer);
|
2003-05-19 14:07:00 +00:00
|
|
|
}
|
|
|
|
|
2004-03-15 18:42:16 +00:00
|
|
|
Mesh_Reader* SMESHDriver::GetMeshReader(string extension)
|
|
|
|
{
|
|
|
|
void * driver = getMeshDriver(extension, string("Reader"));
|
|
|
|
return (Mesh_Reader*)driver;
|
2003-05-19 14:07:00 +00:00
|
|
|
}
|
|
|
|
|
2004-03-15 18:42:16 +00:00
|
|
|
Mesh_Writer* SMESHDriver::GetMeshWriter(string extension)
|
|
|
|
{
|
|
|
|
void * driver = getMeshDriver(extension, string("Writer"));
|
|
|
|
return (Mesh_Writer*)driver;
|
|
|
|
}
|
2003-05-19 14:07:00 +00:00
|
|
|
|
2004-03-15 18:42:16 +00:00
|
|
|
void * SMESHDriver::getMeshDriver(string extension, string type)
|
|
|
|
{
|
|
|
|
string libName = string("libMeshDriver")+extension+string(".so");
|
|
|
|
void * handle = dlopen(libName.c_str(), RTLD_LAZY);
|
|
|
|
if(!handle)
|
|
|
|
{
|
2004-03-24 17:31:44 +00:00
|
|
|
cerr << dlerror() << endl;
|
2004-03-15 18:42:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
void * (*factory)();
|
|
|
|
string symbol = string("SMESH_create")+extension+string("Mesh")+type;
|
|
|
|
factory = (void * (*)()) dlsym(handle, symbol.c_str());
|
|
|
|
if(factory==NULL)
|
|
|
|
{
|
2004-03-24 17:31:44 +00:00
|
|
|
cerr << dlerror() << endl;
|
2004-03-15 18:42:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else return factory();
|
|
|
|
}
|
2003-05-19 14:07:00 +00:00
|
|
|
}
|
|
|
|
|
2004-03-15 18:42:16 +00:00
|
|
|
void * SMESHDriver::getMeshDocumentDriver(string extension)
|
|
|
|
{
|
|
|
|
string libName = string("libMeshDriver")+extension+string(".so");
|
|
|
|
void * handle = dlopen(libName.c_str(), RTLD_LAZY);
|
|
|
|
if(!handle)
|
|
|
|
{
|
2004-03-24 17:31:44 +00:00
|
|
|
cerr << dlerror() << endl;
|
2004-03-15 18:42:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
void * (*factory)();
|
|
|
|
string symbol = string("SMESH_create")+extension+string("DocumentReader");
|
|
|
|
factory = (void * (*)()) dlsym(handle, symbol.c_str());
|
|
|
|
if(factory==NULL)
|
|
|
|
{
|
2004-03-24 17:31:44 +00:00
|
|
|
cerr << dlerror() << endl;
|
2004-03-15 18:42:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else return factory();
|
|
|
|
}
|
|
|
|
}
|