From: gdd Date: Mon, 15 Oct 2012 11:36:19 +0000 (+0000) Subject: Merge V6_main to BR_meshgems X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=27b76ed1590e44a36b904ed7ef530c4b94ece2ed;p=plugins%2Fghs3dplugin.git Merge V6_main to BR_meshgems --- diff --git a/doc/salome/gui/GHS3DPLUGIN/images/ghs3d_parameters_advanced.png b/doc/salome/gui/GHS3DPLUGIN/images/ghs3d_parameters_advanced.png index 74b2be1..e99409e 100644 Binary files a/doc/salome/gui/GHS3DPLUGIN/images/ghs3d_parameters_advanced.png and b/doc/salome/gui/GHS3DPLUGIN/images/ghs3d_parameters_advanced.png differ diff --git a/doc/salome/gui/GHS3DPLUGIN/input/ghs3d_hypo.doc b/doc/salome/gui/GHS3DPLUGIN/input/ghs3d_hypo.doc index 88f50c4..9cececf 100644 --- a/doc/salome/gui/GHS3DPLUGIN/input/ghs3d_hypo.doc +++ b/doc/salome/gui/GHS3DPLUGIN/input/ghs3d_hypo.doc @@ -107,6 +107,9 @@ Note: when using this option, the speed of the meshing process may decrease, quality may change, and the smallest volume may be smaller. By default, the FEM correction is not used. +- Volumic gradation - Defines the volumic ratio between 2 consecutive elements. +WARNING: Changing the default value of this parameter may dramatically decrease the quality of the resulting mesh. + - Option as text - allows to input in the command line any text for ghs3d, for example, advanced options. diff --git a/idl/GHS3DPlugin_Algorithm.idl b/idl/GHS3DPlugin_Algorithm.idl index 7a44669..f930af5 100644 --- a/idl/GHS3DPlugin_Algorithm.idl +++ b/idl/GHS3DPlugin_Algorithm.idl @@ -141,6 +141,11 @@ module GHS3DPlugin */ void SetTextOption(in string option); string GetTextOption(); + /*! + * To define the volumic gradation + */ + void SetGradation(in double gradation); + double GetGradation(); /*! * To set an enforced vertex */ diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx index ef8349a..cb402ee 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx @@ -52,6 +52,7 @@ GHS3DPlugin_Hypothesis::GHS3DPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen myToUseBoundaryRecoveryVersion(DefaultToUseBoundaryRecoveryVersion()), myToUseFemCorrection(DefaultToUseFEMCorrection()), myToRemoveCentralPoint(DefaultToRemoveCentralPoint()), + myGradation(DefaultGradation()), _enfVertexList(DefaultGHS3DEnforcedVertexList()), _enfVertexCoordsSizeList(DefaultGHS3DEnforcedVertexCoordsValues()), _enfVertexEntrySizeList(DefaultGHS3DEnforcedVertexEntryValues()), @@ -328,6 +329,27 @@ std::string GHS3DPlugin_Hypothesis::GetTextOption() const return myTextOption; } +//======================================================================= +//function : SetGradation +//======================================================================= + +void GHS3DPlugin_Hypothesis::SetGradation(double gradation) +{ + if ( myGradation != gradation ) { + myGradation = gradation; + NotifySubMeshesHypothesisModification(); + } +} + +//======================================================================= +//function : GetGradation +//======================================================================= + +double GHS3DPlugin_Hypothesis::GetGradation() const +{ + return myGradation; +} + //======================================================================= //function : SetEnforcedVertex //======================================================================= @@ -839,6 +861,15 @@ bool GHS3DPlugin_Hypothesis::DefaultToRemoveCentralPoint() return false; } +//======================================================================= +//function : DefaultGradation +//======================================================================= + +double GHS3DPlugin_Hypothesis::DefaultGradation() +{ + return 1.05; +} + // //======================================================================= // //function : DefaultID2SizeMap // //======================================================================= @@ -866,6 +897,7 @@ std::ostream & GHS3DPlugin_Hypothesis::SaveTo(std::ostream & save) save << (int)myToUseBoundaryRecoveryVersion << " "; save << (int)myToUseFemCorrection << " "; save << (int)myToRemoveCentralPoint << " "; + save << myGradation << " "; if (!myTextOption.empty()) { save << "__OPTIONS_BEGIN__ "; save << myTextOption << " "; @@ -949,6 +981,7 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load) { bool isOK = true; int i; + double d; isOK = (load >> i); if (isOK) @@ -1026,6 +1059,12 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load) else load.clear(ios::badbit | load.rdstate()); + isOK = (load >> d); + if (isOK) + myGradation = d; + else + load.clear(ios::badbit | load.rdstate()); + std::string separator; bool hasOptions = false; bool hasEnforcedVertices = false; @@ -1271,7 +1310,7 @@ bool GHS3DPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/ //================================================================================ std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* hyp, - const bool hasShapeToMesh) + const bool hasShapeToMesh) { TCollection_AsciiString cmd; cmd = "mg-tetra.exe"; @@ -1285,6 +1324,7 @@ std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* h bool v = hyp ? ( hyp->myTextOption.find("-v") == std::string::npos ) : true; bool fem = hyp ? ( hyp->myTextOption.find("-FEM")== std::string::npos ) : true; bool rem = hyp ? ( hyp->myTextOption.find("-no_initial_central_point")== std::string::npos ) : true; + bool gra = hyp ? ( hyp->myTextOption.find("-Dcpropa")== std::string::npos ) : true; // if use boundary recovery version, few options are allowed bool useBndRecovery = !C; @@ -1367,6 +1407,12 @@ std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* h cmd += (char*) hyp->myTextOption.c_str(); } + // to define volumic gradation. + if ( gra && hyp) { + cmd += " -Dcpropa="; + cmd += hyp->myGradation; + } + #ifdef WNT cmd += " < NUL"; #endif diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx index db3830d..2e1acc5 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx @@ -191,6 +191,11 @@ public: */ void SetTextOption(const std::string& option); std::string GetTextOption() const; + /*! + * To define the volumic gradation + */ + void SetGradation(double gradation); + double GetGradation() const ; // struct TEnforcedEdge { @@ -269,6 +274,7 @@ public: static bool DefaultToUseBoundaryRecoveryVersion(); static bool DefaultToUseFEMCorrection(); static bool DefaultToRemoveCentralPoint(); + static double DefaultGradation(); static TGHS3DEnforcedVertex DefaultGHS3DEnforcedVertex() {return TGHS3DEnforcedVertex();} static TGHS3DEnforcedVertexList DefaultGHS3DEnforcedVertexList() {return TGHS3DEnforcedVertexList();} @@ -316,6 +322,7 @@ private: bool myToUseFemCorrection; bool myToRemoveCentralPoint; std::string myTextOption; + double myGradation; TGHS3DEnforcedVertexList _enfVertexList; TGHS3DEnforcedVertexCoordsValues _enfVertexCoordsSizeList; diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx index c1922ad..b4bf07a 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx @@ -351,6 +351,31 @@ char* GHS3DPlugin_Hypothesis_i::GetTextOption() return CORBA::string_dup( this->GetImpl()->GetTextOption().c_str() ); } +//======================================================================= +//function : SetToRemoveCentralPoint +//======================================================================= + +void GHS3DPlugin_Hypothesis_i::SetGradation(CORBA::Double gradation) +{ + if (gradation <= 1) + THROW_SALOME_CORBA_EXCEPTION( "The volumic gradation must be > 1",SALOME::BAD_PARAM ); + ASSERT(myBaseImpl); + if (gradation != GetGradation()) { + this->GetImpl()->SetGradation(gradation); + SMESH::TPythonDump() << _this() << ".SetGradation( " << gradation << " )"; + } +} + +//======================================================================= +//function : GetToRemoveCentralPoint +//======================================================================= + +CORBA::Double GHS3DPlugin_Hypothesis_i::GetGradation() +{ + ASSERT(myBaseImpl); + return this->GetImpl()->GetGradation(); +} + //======================================================================= //function : SetEnforcedVertex //======================================================================= diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx index 62ae16e..6b1539c 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx @@ -122,6 +122,11 @@ class GHS3DPLUGIN_EXPORT GHS3DPlugin_Hypothesis_i: */ void SetTextOption(const char* option); char* GetTextOption(); + /*! + * To define the volumic gradation + */ + void SetGradation(CORBA::Double gradation); + CORBA::Double GetGradation(); /*! * To set an enforced vertex */ diff --git a/src/GHS3DPlugin/Makefile.am b/src/GHS3DPlugin/Makefile.am index a6e0509..182512d 100644 --- a/src/GHS3DPlugin/Makefile.am +++ b/src/GHS3DPlugin/Makefile.am @@ -27,23 +27,21 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am # header files salomeinclude_HEADERS = \ - libmesh5.h \ - GHS3DPlugin_Defs.hxx \ - GHS3DPlugin_GHS3D.hxx \ - GHS3DPlugin_GHS3D_i.hxx \ - GHS3DPlugin_Hypothesis.hxx \ - GHS3DPlugin_Hypothesis_i.hxx + GHS3DPlugin_Defs.hxx \ + GHS3DPlugin_GHS3D.hxx \ + GHS3DPlugin_GHS3D_i.hxx \ + GHS3DPlugin_Hypothesis.hxx \ + GHS3DPlugin_Hypothesis_i.hxx # Libraries targets lib_LTLIBRARIES = libGHS3DEngine.la dist_libGHS3DEngine_la_SOURCES = \ - libmesh5.c \ - GHS3DPlugin_GHS3D.cxx \ - GHS3DPlugin_GHS3D_i.cxx \ - GHS3DPlugin_i.cxx \ - GHS3DPlugin_Hypothesis.cxx \ - GHS3DPlugin_Hypothesis_i.cxx + GHS3DPlugin_GHS3D.cxx \ + GHS3DPlugin_GHS3D_i.cxx \ + GHS3DPlugin_i.cxx \ + GHS3DPlugin_Hypothesis.cxx \ + GHS3DPlugin_Hypothesis_i.cxx libGHS3DEngine_la_CPPFLAGS = \ $(KERNEL_CXXFLAGS) \ @@ -58,11 +56,11 @@ libGHS3DEngine_la_CPPFLAGS = \ -I$(top_builddir)/idl libGHS3DEngine_la_LDFLAGS = \ - ../../idl/libSalomeIDLGHS3DPLUGIN.la \ - $(CAS_KERNEL) -lTKBRep -lTKG2d -lTKG3d -lTKTopAlgo -lTKGeomBase -lTKGeomAlgo -lTKCDF \ - $(MED_LDFLAGS) -lSalomeIDLMED \ - $(SMESH_LDFLAGS) -lSMESHimpl -lSMESHEngine -lSMESHDS -lSMDS -lStdMeshers \ - $(KERNEL_LDFLAGS) -lSalomeGenericObj -lSALOMELocalTrace -lSALOMEBasics -lSalomeNS -lOpUtil + ../../idl/libSalomeIDLGHS3DPLUGIN.la \ + $(CAS_KERNEL) -lTKBRep -lTKG2d -lTKG3d -lTKTopAlgo -lTKGeomBase -lTKGeomAlgo -lTKCDF \ + $(MED_LDFLAGS) -lSalomeIDLMED \ + $(SMESH_LDFLAGS) -lSMESHimpl -lSMESHEngine -lSMESHDS -lSMDS -lStdMeshers -lMeshDriverGMF \ + $(KERNEL_LDFLAGS) -lSalomeGenericObj -lSALOMELocalTrace -lSALOMEBasics -lSalomeNS -lOpUtil # Scripts to be installed. dist_salomescript_DATA= GHS3DPluginDC.py diff --git a/src/GHS3DPlugin/libmesh5.c b/src/GHS3DPlugin/libmesh5.c deleted file mode 100644 index b16c39c..0000000 --- a/src/GHS3DPlugin/libmesh5.c +++ /dev/null @@ -1,1346 +0,0 @@ - - -/*----------------------------------------------------------*/ -/* */ -/* LIBMESH V 5.46 */ -/* */ -/*----------------------------------------------------------*/ -/* */ -/* Description: handle .meshb file format I/O */ -/* Author: Loic MARECHAL */ -/* Creation date: feb 16 2007 */ -/* Last modification: apr 03 2012 */ -/* */ -/*----------------------------------------------------------*/ - - -/*----------------------------------------------------------*/ -/* Includes */ -/*----------------------------------------------------------*/ - -#include -#include -#include -#include -#include -#include -#include -#include "libmesh5.h" - - -/*----------------------------------------------------------*/ -/* Defines */ -/*----------------------------------------------------------*/ - -#define Asc 1 -#define Bin 2 -#define MshFil 4 -#define SolFil 8 -#define MaxMsh 100 -#define InfKwd 1 -#define RegKwd 2 -#define SolKwd 3 -#define WrdSiz 4 -#define BufSiz 10000 - - -/*----------------------------------------------------------*/ -/* Structures */ -/*----------------------------------------------------------*/ - -typedef struct -{ - int typ, SolSiz, NmbWrd, NmbLin, NmbTyp, TypTab[ GmfMaxTyp ]; - long pos; - char fmt[ GmfMaxTyp*9 ]; -}KwdSct; - -typedef struct -{ - int dim, ver, mod, typ, cod, pos; - long NexKwdPos, siz; - KwdSct KwdTab[ GmfMaxKwd + 1 ]; - FILE *hdl; - int *IntBuf; - float *FltBuf; - unsigned char *buf; - char FilNam[ GmfStrSiz ]; - double DblBuf[1000/8]; - unsigned char blk[ BufSiz + 1000 ]; -}GmfMshSct; - - -/*----------------------------------------------------------*/ -/* Global variables */ -/*----------------------------------------------------------*/ - -static int GmfIniFlg=0; -static GmfMshSct *GmfMshTab[ MaxMsh + 1 ]; -static const char *GmfKwdFmt[ GmfMaxKwd + 1 ][4] = -{ {"Reserved", "", "", ""}, - {"MeshVersionFormatted", "", "", "i"}, - {"Reserved", "", "", ""}, - {"Dimension", "", "", "i"}, - {"Vertices", "Vertex", "i", "dri"}, - {"Edges", "Edge", "i", "iii"}, - {"Triangles", "Triangle", "i", "iiii"}, - {"Quadrilaterals", "Quadrilateral", "i", "iiiii"}, - {"Tetrahedra", "Tetrahedron", "i", "iiiii"}, - {"Prisms", "Prism", "i", "iiiiiii"}, - {"Hexahedra", "Hexahedron", "i", "iiiiiiiii"}, - {"IterationsAll", "IterationAll","","i"}, - {"TimesAll", "TimeAll","","r"}, - {"Corners", "Corner", "i", "i"}, - {"Ridges", "Ridge", "i", "i"}, - {"RequiredVertices", "RequiredVertex", "i", "i"}, - {"RequiredEdges", "RequiredEdge", "i", "i"}, - {"RequiredTriangles", "RequiredTriangle", "i", "i"}, - {"RequiredQuadrilaterals", "RequiredQuadrilateral", "i", "i"}, - {"TangentAtEdgeVertices", "TangentAtEdgeVertex", "i", "iii"}, - {"NormalAtVertices", "NormalAtVertex", "i", "ii"}, - {"NormalAtTriangleVertices", "NormalAtTriangleVertex", "i", "iii"}, - {"NormalAtQuadrilateralVertices", "NormalAtQuadrilateralVertex", "i", "iiii"}, - {"AngleOfCornerBound", "", "", "r"}, - {"TrianglesP2", "TriangleP2", "i", "iiiiiii"}, - {"EdgesP2", "EdgeP2", "i", "iiii"}, - {"SolAtPyramids", "SolAtPyramid", "i", "sr"}, - {"QuadrilateralsQ2", "QuadrilateralQ2", "i", "iiiiiiiiii"}, - {"ISolAtPyramids", "ISolAtPyramid", "i", "iiiii"}, - {"SubDomainFromGeom", "SubDomainFromGeom", "i", "iiii"}, - {"TetrahedraP2", "TetrahedronP2", "i", "iiiiiiiiiii"}, - {"Fault_NearTri", "Fault_NearTri", "i", "i"}, - {"Fault_Inter", "Fault_Inter", "i", "i"}, - {"HexahedraQ2", "HexahedronQ2", "i", "iiiiiiiiiiiiiiiiiiiiiiiiiiii"}, - {"ExtraVerticesAtEdges", "ExtraVerticesAtEdge", "i", "in"}, - {"ExtraVerticesAtTriangles", "ExtraVerticesAtTriangle", "i", "in"}, - {"ExtraVerticesAtQuadrilaterals", "ExtraVerticesAtQuadrilateral", "i", "in"}, - {"ExtraVerticesAtTetrahedra", "ExtraVerticesAtTetrahedron", "i", "in"}, - {"ExtraVerticesAtPrisms", "ExtraVerticesAtPrism", "i", "in"}, - {"ExtraVerticesAtHexahedra", "ExtraVerticesAtHexahedron", "i", "in"}, - {"VerticesOnGeometricVertices", "VertexOnGeometricVertex", "i", "iir"}, - {"VerticesOnGeometricEdges", "VertexOnGeometricEdge", "i", "iirr"}, - {"VerticesOnGeometricTriangles", "VertexOnGeometricTriangle", "i", "iirrr"}, - {"VerticesOnGeometricQuadrilaterals", "VertexOnGeometricQuadrilateral", "i", "iirrr"}, - {"EdgesOnGeometricEdges", "EdgeOnGeometricEdge", "i", "iir"}, - {"Fault_FreeEdge", "Fault_FreeEdge", "i", "i"}, - {"Polyhedra", "Polyhedron", "i", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"}, - {"Polygons", "Polygon", "", "iiiiiiiii"}, - {"Fault_Overlap", "Fault_Overlap", "i", "i"}, - {"Pyramids", "Pyramid", "i", "iiiiii"}, - {"BoundingBox", "", "", "drdr"}, - {"Body","i", "drdrdrdr"}, - {"PrivateTable", "PrivateTable", "i", "i"}, - {"Fault_BadShape", "Fault_BadShape", "i", "i"}, - {"End", "", "", ""}, - {"TrianglesOnGeometricTriangles", "TriangleOnGeometricTriangle", "i", "iir"}, - {"TrianglesOnGeometricQuadrilaterals", "TriangleOnGeometricQuadrilateral", "i", "iir"}, - {"QuadrilateralsOnGeometricTriangles", "QuadrilateralOnGeometricTriangle", "i", "iir"}, - {"QuadrilateralsOnGeometricQuadrilaterals", "QuadrilateralOnGeometricQuadrilateral", "i", "iir"}, - {"Tangents", "Tangent", "i", "dr"}, - {"Normals", "Normal", "i", "dr"}, - {"TangentAtVertices", "TangentAtVertex", "i", "ii"}, - {"SolAtVertices", "SolAtVertex", "i", "sr"}, - {"SolAtEdges", "SolAtEdge", "i", "sr"}, - {"SolAtTriangles", "SolAtTriangle", "i", "sr"}, - {"SolAtQuadrilaterals", "SolAtQuadrilateral", "i", "sr"}, - {"SolAtTetrahedra", "SolAtTetrahedron", "i", "sr"}, - {"SolAtPrisms", "SolAtPrism", "i", "sr"}, - {"SolAtHexahedra", "SolAtHexahedron", "i", "sr"}, - {"DSolAtVertices", "DSolAtVertex", "i", "sr"}, - {"ISolAtVertices", "ISolAtVertex", "i", "i"}, - {"ISolAtEdges", "ISolAtEdge", "i", "ii"}, - {"ISolAtTriangles", "ISolAtTriangle", "i", "iii"}, - {"ISolAtQuadrilaterals", "ISolAtQuadrilateral", "i", "iiii"}, - {"ISolAtTetrahedra", "ISolAtTetrahedron", "i", "iiii"}, - {"ISolAtPrisms", "ISolAtPrism", "i", "iiiiii"}, - {"ISolAtHexahedra", "ISolAtHexahedron", "i", "iiiiiiii"}, - {"Iterations", "","","i"}, - {"Time", "","","r"}, - {"Fault_SmallTri", "Fault_SmallTri","i","i"}, - {"CoarseHexahedra", "CoarseHexahedron", "i", "i"} - }; - - -/*----------------------------------------------------------*/ -/* Prototypes of local procedures */ -/*----------------------------------------------------------*/ - -static void ScaWrd(GmfMshSct *, unsigned char *); -static void ScaDblWrd(GmfMshSct *, unsigned char *); -static void ScaBlk(GmfMshSct *, unsigned char *, int); -static long GetPos(GmfMshSct *); -static void RecWrd(GmfMshSct *, unsigned char *); -static void RecDblWrd(GmfMshSct *, unsigned char *); -static void RecBlk(GmfMshSct *, unsigned char *, int); -static void SetPos(GmfMshSct *, long); -static int ScaKwdTab(GmfMshSct *); -static void ExpFmt(GmfMshSct *, int); -static void ScaKwdHdr(GmfMshSct *, int); - - -/*----------------------------------------------------------*/ -/* Open a mesh file in read or write mod */ -/*----------------------------------------------------------*/ - -int GmfOpenMesh(const char *FilNam, int mod, ...) -{ - int i, KwdCod, res, *PtrVer, *PtrDim, MshIdx=0; - char str[ GmfStrSiz ]; - va_list VarArg; - GmfMshSct *msh; - char *ptr; - int k; - - if(!GmfIniFlg) - { - for(i=0;i<=MaxMsh;i++) - GmfMshTab[i] = NULL; - - GmfIniFlg = 1; - } - - /*---------------------*/ - /* MESH STRUCTURE INIT */ - /*---------------------*/ - - for(i=1;i<=MaxMsh;i++) - if(!GmfMshTab[i]) - { - MshIdx = i; - break; - } - - if( !MshIdx || !(msh = calloc(1, sizeof(GmfMshSct))) ) - return(0); - - /* Copy the FilNam into the structure */ - - if(strlen(FilNam) + 7 >= GmfStrSiz) - { - free (msh); - return(0); - } - - strcpy(msh->FilNam, FilNam); - - /* Store the opening mod (read or write) and guess the filetype (binary or ascii) depending on the extension */ - - msh->mod = mod; - msh->buf = (unsigned char *)msh->DblBuf; - msh->FltBuf = (float *)msh->DblBuf; - msh->IntBuf = (int *)msh->DblBuf; - - k = strlen(msh->FilNam) - 6; - if(k < 0) - k = 0; - ptr = msh->FilNam+k; - if(strstr(ptr, ".meshb")) - msh->typ |= (Bin | MshFil); - else if(strstr(ptr, ".mesh")) - msh->typ |= (Asc | MshFil); - else if(strstr(ptr, ".solb")) - msh->typ |= (Bin | SolFil); - else if(strstr(ptr, ".sol")) - msh->typ |= (Asc | SolFil); - else { - free (msh); - return(0); - } - - /* Open the file in the required mod and initialyse the mesh structure */ - - if(msh->mod == GmfRead) - { - - /*-----------------------*/ - /* OPEN FILE FOR READING */ - /*-----------------------*/ - - va_start(VarArg, mod); - PtrVer = va_arg(VarArg, int *); - PtrDim = va_arg(VarArg, int *); - va_end(VarArg); - - /* Create the name string and open the file */ - - if(!(msh->hdl = fopen(msh->FilNam, "rb"))) - { - free (msh); - return(0); - } - - /* Read the endian coding tag, the mesh version and the mesh dimension (mandatory kwd) */ - - if(msh->typ & Bin) - { - fread((unsigned char *)&msh->cod, WrdSiz, 1, msh->hdl); - - if( (msh->cod != 1) && (msh->cod != 16777216) ) - { - free (msh); - return(0); - } - - ScaWrd(msh, (unsigned char *)&msh->ver); - - if( (msh->ver < 1) || (msh->ver > 3) ) - { - free (msh); - return(0); - } - - if( (msh->ver == 3) && (sizeof(long) == 4) ) - { - free (msh); - return(0); - } - - ScaWrd(msh, (unsigned char *)&KwdCod); - - if(KwdCod != GmfDimension) - { - free (msh); - return(0); - } - - GetPos(msh); - ScaWrd(msh, (unsigned char *)&msh->dim); - } - else - { - do - { - res = fscanf(msh->hdl, "%s", str); - }while( (res != EOF) && strcmp(str, "MeshVersionFormatted") ); - - if(res == EOF) - { - free (msh); - return(0); - } - - fscanf(msh->hdl, "%d", &msh->ver); - - if( (msh->ver < 1) || (msh->ver > 3) ) - { - free (msh); - return(0); - } - - do - { - res = fscanf(msh->hdl, "%s", str); - }while( (res != EOF) && strcmp(str, "Dimension") ); - - if(res == EOF) - { - free (msh); - return(0); - } - - fscanf(msh->hdl, "%d", &msh->dim); - } - - if( (msh->dim != 2) && (msh->dim != 3) ) - { - free (msh); - return(0); - } - - (*PtrVer) = msh->ver; - (*PtrDim) = msh->dim; - - /*------------*/ - /* KW READING */ - /*------------*/ - - /* Read the list of kw present in the file */ - - if(!ScaKwdTab(msh)) - { - free (msh); - return(0); - } - - GmfMshTab[ MshIdx ] = msh; - - return(MshIdx); - } - else if(msh->mod == GmfWrite) - { - - /*-----------------------*/ - /* OPEN FILE FOR WRITING */ - /*-----------------------*/ - - msh->cod = 1; - - /* Check if the user provided a valid version number and dimension */ - - va_start(VarArg, mod); - msh->ver = va_arg(VarArg, int); - msh->dim = va_arg(VarArg, int); - va_end(VarArg); - - if( (msh->ver < 1) || (msh->ver > 3) ) - { - free (msh); - return(0); - } - - if( (msh->ver == 3) && (sizeof(long) == 4) ) - { - free (msh); - return(0); - } - - if( (msh->dim != 2) && (msh->dim != 3) ) - { - free (msh); - return(0); - } - - /* Create the mesh file */ - - if(!(msh->hdl = fopen(msh->FilNam, "wb"))) - { - free (msh); - return(0); - } - - GmfMshTab[ MshIdx ] = msh; - - - /*------------*/ - /* KW WRITING */ - /*------------*/ - - /* Write the mesh version and dimension */ - - if(msh->typ & Asc) - { - fprintf(msh->hdl, "%s %d\n\n", GmfKwdFmt[ GmfVersionFormatted ][0], msh->ver); - fprintf(msh->hdl, "%s %d\n", GmfKwdFmt[ GmfDimension ][0], msh->dim); - } - else - { - RecWrd(msh, (unsigned char *)&msh->cod); - RecWrd(msh, (unsigned char *)&msh->ver); - GmfSetKwd(MshIdx, GmfDimension, 0); - RecWrd(msh, (unsigned char *)&msh->dim); - } - - return(MshIdx); - } - else - { - free (msh); - return(0); - } -} - - -/*----------------------------------------------------------*/ -/* Close a meshfile in the right way */ -/*----------------------------------------------------------*/ - -int GmfCloseMesh(int MshIdx) -{ - int res = 1; - GmfMshSct *msh; - - if( (MshIdx < 1) || (MshIdx > MaxMsh) ) - return(0); - - msh = GmfMshTab[ MshIdx ]; - RecBlk(msh, msh->buf, 0); - - /* In write down the "End" kw in write mode */ - - if(msh->mod == GmfWrite){ - if(msh->typ & Asc) - fprintf(msh->hdl, "\n%s\n", GmfKwdFmt[ GmfEnd ][0]); - else - GmfSetKwd(MshIdx, GmfEnd, 0); - } - /* Close the file and free the mesh structure */ - - if(fclose(msh->hdl)) - res = 0; - - free(msh); - GmfMshTab[ MshIdx ] = NULL; - - return(res); -} - - -/*----------------------------------------------------------*/ -/* Read the number of lines and set the position to this kwd*/ -/*----------------------------------------------------------*/ - -int GmfStatKwd(int MshIdx, int KwdCod, ...) -{ - int i, *PtrNmbTyp, *PtrSolSiz, *TypTab; - GmfMshSct *msh; - KwdSct *kwd; - va_list VarArg; - - if( (MshIdx < 1) || (MshIdx > MaxMsh) ) - return(0); - - msh = GmfMshTab[ MshIdx ]; - - if( (KwdCod < 1) || (KwdCod > GmfMaxKwd) ) - return(0); - - kwd = &msh->KwdTab[ KwdCod ]; - - if(!kwd->NmbLin) - return(0); - - /* Read further arguments if this kw is a sol */ - - if(kwd->typ == SolKwd) - { - va_start(VarArg, KwdCod); - - PtrNmbTyp = va_arg(VarArg, int *); - *PtrNmbTyp = kwd->NmbTyp; - - PtrSolSiz = va_arg(VarArg, int *); - *PtrSolSiz = kwd->SolSiz; - - TypTab = va_arg(VarArg, int *); - - for(i=0;iNmbTyp;i++) - TypTab[i] = kwd->TypTab[i]; - - va_end(VarArg); - } - - return(kwd->NmbLin); -} - - -/*----------------------------------------------------------*/ -/* Set the current file position to a given kwd */ -/*----------------------------------------------------------*/ - -int GmfGotoKwd(int MshIdx, int KwdCod) -{ - GmfMshSct *msh; - KwdSct *kwd; - - if( (MshIdx < 1) || (MshIdx > MaxMsh) ) - return(0); - - msh = GmfMshTab[ MshIdx ]; - - if( (KwdCod < 1) || (KwdCod > GmfMaxKwd) ) - return(0); - - kwd = &msh->KwdTab[ KwdCod ]; - - if(!kwd->NmbLin) - return(0); - - return(fseek(msh->hdl, kwd->pos, SEEK_SET)); -} - - -/*----------------------------------------------------------*/ -/* Write the kwd and set the number of lines */ -/*----------------------------------------------------------*/ - -int GmfSetKwd(int MshIdx, int KwdCod, ...) -{ - int i, NmbLin=0, *TypTab; - long CurPos; - va_list VarArg; - GmfMshSct *msh; - KwdSct *kwd; - - if( (MshIdx < 1) || (MshIdx > MaxMsh) ) - return(0); - - msh = GmfMshTab[ MshIdx ]; - RecBlk(msh, msh->buf, 0); - - if( (KwdCod < 1) || (KwdCod > GmfMaxKwd) ) - return(0); - - kwd = &msh->KwdTab[ KwdCod ]; - - /* Read further arguments if this kw has a header */ - - if(strlen(GmfKwdFmt[ KwdCod ][2])) - { - va_start(VarArg, KwdCod); - NmbLin = va_arg(VarArg, int); - - if(!strcmp(GmfKwdFmt[ KwdCod ][3], "sr")) - { - kwd->NmbTyp = va_arg(VarArg, int); - TypTab = va_arg(VarArg, int *); - - for(i=0;iNmbTyp;i++) - kwd->TypTab[i] = TypTab[i]; - } - - va_end(VarArg); - } - - /* Setup the kwd info */ - - ExpFmt(msh, KwdCod); - - if(!kwd->typ) - return(0); - else if(kwd->typ == InfKwd) - kwd->NmbLin = 1; - else - kwd->NmbLin = NmbLin; - - /* Store the next kwd position in binary file */ - - if( (msh->typ & Bin) && msh->NexKwdPos ) - { - CurPos = ftell(msh->hdl); - fseek(msh->hdl, msh->NexKwdPos, SEEK_SET); - SetPos(msh, CurPos); - fseek(msh->hdl, CurPos, SEEK_SET); - } - - /* Write the header */ - - if(msh->typ & Asc) - { - fprintf(msh->hdl, "\n%s\n", GmfKwdFmt[ KwdCod ][0]); - - if(kwd->typ != InfKwd) - fprintf(msh->hdl, "%d\n", kwd->NmbLin); - - /* In case of solution field, write the extended header */ - - if(kwd->typ == SolKwd) - { - fprintf(msh->hdl, "%d ", kwd->NmbTyp); - - for(i=0;iNmbTyp;i++) - fprintf(msh->hdl, "%d ", kwd->TypTab[i]); - - fprintf(msh->hdl, "\n\n"); - } - } - else - { - RecWrd(msh, (unsigned char *)&KwdCod); - msh->NexKwdPos = ftell(msh->hdl); - SetPos(msh, 0); - - if(kwd->typ != InfKwd) - RecWrd(msh, (unsigned char *)&kwd->NmbLin); - - /* In case of solution field, write the extended header at once */ - - if(kwd->typ == SolKwd) - { - RecWrd(msh, (unsigned char *)&kwd->NmbTyp); - - for(i=0;iNmbTyp;i++) - RecWrd(msh, (unsigned char *)&kwd->TypTab[i]); - } - } - - /* Reset write buffer position */ - msh->pos = 0; - - /* Estimate the total file size and check whether it crosses the 2GB threshold */ - - msh->siz += kwd->NmbLin * kwd->NmbWrd * WrdSiz; - - if(msh->siz > 2E9) - return(0); - else - return(kwd->NmbLin); -} - - -/*----------------------------------------------------------*/ -/* Read a full line from the current kwd */ -/*----------------------------------------------------------*/ - -void GmfGetLin(int MshIdx, int KwdCod, ...) -{ - int i, j; - float *FltSolTab; - double *DblSolTab; - va_list VarArg; - GmfMshSct *msh = GmfMshTab[ MshIdx ]; - KwdSct *kwd = &msh->KwdTab[ KwdCod ]; - - /* Start decoding the arguments */ - - va_start(VarArg, KwdCod); - - if(kwd->typ != SolKwd) - { - int k, nb_repeat = 0; - - if(msh->ver == 1) - { - if(msh->typ & Asc) - { - for(i=0;iSolSiz;i++) - if(kwd->fmt[i] == 'r') - fscanf(msh->hdl, "%f", va_arg(VarArg, float *)); - else if(kwd->fmt[i] == 'n') { - fscanf(msh->hdl, "%d", &nb_repeat); - *(va_arg(VarArg, int *)) = nb_repeat; - for(k=0;khdl, "%d", va_arg(VarArg, int *)); - } - else - fscanf(msh->hdl, "%d", va_arg(VarArg, int *)); - } - else - { - for(i=0;iSolSiz;i++) - if(kwd->fmt[i] == 'r') - ScaWrd(msh, (unsigned char *)va_arg(VarArg, float *)); - else if(kwd->fmt[i] == 'n') { - ScaWrd(msh, (unsigned char *)&nb_repeat); - *(va_arg(VarArg, int *)) = nb_repeat; - for(k=0;ktyp & Asc) - { - for(i=0;iSolSiz;i++) - if(kwd->fmt[i] == 'r') - fscanf(msh->hdl, "%lf", va_arg(VarArg, double *)); - else if(kwd->fmt[i] == 'n') { - fscanf(msh->hdl, "%d", &nb_repeat); - *(va_arg(VarArg, int *)) = nb_repeat; - for(k=0;khdl, "%d", va_arg(VarArg, int *)); - } - else - fscanf(msh->hdl, "%d", va_arg(VarArg, int *)); - } - else - for(i=0;iSolSiz;i++) - if(kwd->fmt[i] == 'r') - ScaDblWrd(msh, (unsigned char *)va_arg(VarArg, double *)); - else if(kwd->fmt[i] == 'n') { - ScaWrd(msh, (unsigned char *)&nb_repeat); - *(va_arg(VarArg, int *)) = nb_repeat; - for(k=0;kver == 1) - { - FltSolTab = va_arg(VarArg, float *); - - if(msh->typ & Asc) - for(j=0;jSolSiz;j++) - fscanf(msh->hdl, "%f", &FltSolTab[j]); - else - ScaBlk(msh, (unsigned char *)FltSolTab, kwd->NmbWrd); - } - else - { - DblSolTab = va_arg(VarArg, double *); - - if(msh->typ & Asc) - for(j=0;jSolSiz;j++) - fscanf(msh->hdl, "%lf", &DblSolTab[j]); - else - for(j=0;jSolSiz;j++) - ScaDblWrd(msh, (unsigned char *)&DblSolTab[j]); - } - } - - va_end(VarArg); -} - - -/*----------------------------------------------------------*/ -/* Write a full line from the current kwd */ -/*----------------------------------------------------------*/ - -void GmfSetLin(int MshIdx, int KwdCod, ...) -{ - int i, j, pos, *IntBuf; - float *FltSolTab; - double *DblSolTab, *DblBuf; - va_list VarArg; - GmfMshSct *msh = GmfMshTab[ MshIdx ]; - KwdSct *kwd = &msh->KwdTab[ KwdCod ]; - - /* Start decoding the arguments */ - - va_start(VarArg, KwdCod); - - if(kwd->typ != SolKwd) - { - int k, nb_repeat = 0; - - if(msh->ver == 1) - { - if(msh->typ & Asc) - { - for(i=0;iSolSiz;i++) - if(kwd->fmt[i] == 'r') - fprintf(msh->hdl, "%g ", (float)va_arg(VarArg, double)); - else if(kwd->fmt[i] == 'n') { - nb_repeat = va_arg(VarArg, int); - fprintf(msh->hdl, "%d ", nb_repeat); - for(k=0;khdl, "%d ", va_arg(VarArg, int)); - } - else - fprintf(msh->hdl, "%d ", va_arg(VarArg, int)); - } - else - { - int size_of_block = kwd->SolSiz; - for(i=0;iSolSiz;i++) - if(kwd->fmt[i] == 'r') - msh->FltBuf[i] = va_arg(VarArg, double); - else if(kwd->fmt[i] == 'n') { - nb_repeat = va_arg(VarArg, int); - msh->FltBuf[i] = nb_repeat; - for(k=0;kIntBuf[i+1+k] = va_arg(VarArg, int); - size_of_block ++; - } - } - else - msh->IntBuf[i] = va_arg(VarArg, int); - - RecBlk(msh, msh->buf, size_of_block); - } - } - else - { - if(msh->typ & Asc) - { - for(i=0;iSolSiz;i++) - if(kwd->fmt[i] == 'r') - fprintf(msh->hdl, "%.15lg ", va_arg(VarArg, double)); - else if(kwd->fmt[i] == 'n') { - nb_repeat = va_arg(VarArg, int); - fprintf(msh->hdl, "%d ", nb_repeat); - for(k=0;khdl, "%d ", va_arg(VarArg, int)); - } - else - fprintf(msh->hdl, "%d ", va_arg(VarArg, int)); - } - else - { - pos = 0; - - for(i=0;iSolSiz;i++) - if(kwd->fmt[i] == 'r') - { - DblBuf = (double *)&msh->buf[ pos ]; - *DblBuf = va_arg(VarArg, double); - pos += 8; - } - else if(kwd->fmt[i] == 'n') - { - IntBuf = (int *)&msh->buf[ pos ]; - nb_repeat = va_arg(VarArg, int); - *IntBuf = nb_repeat; - pos += 4; - for(k=0;kbuf[ pos ]; - *IntBuf = va_arg(VarArg, int); - pos += 4; - } - } - else - { - IntBuf = (int *)&msh->buf[ pos ]; - *IntBuf = va_arg(VarArg, int); - pos += 4; - } - RecBlk(msh, msh->buf, pos/4); - } - } - } - else - { - if(msh->ver == 1) - { - FltSolTab = va_arg(VarArg, float *); - - if(msh->typ & Asc) - for(j=0;jSolSiz;j++) - fprintf(msh->hdl, "%g ", FltSolTab[j]); - else - RecBlk(msh, (unsigned char *)FltSolTab, kwd->NmbWrd); - } - else - { - DblSolTab = va_arg(VarArg, double *); - - if(msh->typ & Asc) - for(j=0;jSolSiz;j++) - fprintf(msh->hdl, "%.15lg ", DblSolTab[j]); - else - RecBlk(msh, (unsigned char *)DblSolTab, kwd->NmbWrd); - } - } - - va_end(VarArg); - - if(msh->typ & Asc) - fprintf(msh->hdl, "\n"); -} - - -/*----------------------------------------------------------*/ -/* Private procedure for transmesh : copy a whole line */ -/*----------------------------------------------------------*/ - -void GmfCpyLin(int InpIdx, int OutIdx, int KwdCod) -{ - double d; - float f; - int i, a; - GmfMshSct *InpMsh = GmfMshTab[ InpIdx ], *OutMsh = GmfMshTab[ OutIdx ]; - KwdSct *kwd = &InpMsh->KwdTab[ KwdCod ]; - - for(i=0;iSolSiz;i++) - { - if(kwd->fmt[i] == 'r') - { - if(InpMsh->ver == 1) - { - if(InpMsh->typ & Asc) - fscanf(InpMsh->hdl, "%f", &f); - else - ScaWrd(InpMsh, (unsigned char *)&f); - - d = f; - } - else - { - if(InpMsh->typ & Asc) - fscanf(InpMsh->hdl, "%lf", &d); - else - ScaDblWrd(InpMsh, (unsigned char *)&d); - - f = (float)d; - } - - if(OutMsh->ver == 1) - if(OutMsh->typ & Asc) - fprintf(OutMsh->hdl, "%g ", f); - else - RecWrd(OutMsh, (unsigned char *)&f); - else - if(OutMsh->typ & Asc) - fprintf(OutMsh->hdl, "%.15g ", d); - else - RecDblWrd(OutMsh, (unsigned char *)&d); - } - else if(kwd->fmt[i] == 'n') - { - int k, nb_repeat = 0; - - if(InpMsh->typ & Asc) - fscanf(InpMsh->hdl, "%d", &a); - else - ScaWrd(InpMsh, (unsigned char *)&a); - - nb_repeat = a; - - if(OutMsh->typ & Asc) - fprintf(OutMsh->hdl, "%d ", a); - else - RecWrd(OutMsh, (unsigned char *)&a); - - for(k=0;ktyp & Asc) - fscanf(InpMsh->hdl, "%d", &a); - else - ScaWrd(InpMsh, (unsigned char *)&a); - - if(OutMsh->typ & Asc) - fprintf(OutMsh->hdl, "%d ", a); - else - RecWrd(OutMsh, (unsigned char *)&a); - } - } - else - { - if(InpMsh->typ & Asc) - fscanf(InpMsh->hdl, "%d", &a); - else - ScaWrd(InpMsh, (unsigned char *)&a); - - if(OutMsh->typ & Asc) - fprintf(OutMsh->hdl, "%d ", a); - else - RecWrd(OutMsh, (unsigned char *)&a); - } - } - - if(OutMsh->typ & Asc) - fprintf(OutMsh->hdl, "\n"); -} - - -/*----------------------------------------------------------*/ -/* Find every kw present in a meshfile */ -/*----------------------------------------------------------*/ - -static int ScaKwdTab(GmfMshSct *msh) -{ - int KwdCod; - long NexPos, CurPos, EndPos; - char str[ GmfStrSiz ]; - - if(msh->typ & Asc) - { - /* Scan each string in the file until the end */ - - while(fscanf(msh->hdl, "%s", str) != EOF) - { - /* Fast test in order to reject quickly the numeric values */ - - if(isalpha(str[0])) - { - /* Search which kwd code this string is associated with, - then get its header and save the curent position in file (just before the data) */ - - for(KwdCod=1; KwdCod<= GmfMaxKwd; KwdCod++) - if(!strcmp(str, GmfKwdFmt[ KwdCod ][0])) - { - ScaKwdHdr(msh, KwdCod); - break; - } - } - else if(str[0] == '#') - while(fgetc(msh->hdl) != '\n'); - } - } - else - { - /* Get file size */ - - CurPos = ftell(msh->hdl); - fseek(msh->hdl, 0, SEEK_END); - EndPos = ftell(msh->hdl); - fseek(msh->hdl, CurPos, SEEK_SET); - - /* Jump through kwd positions in the file */ - - do - { - /* Get the kwd code and the next kwd position */ - - ScaWrd(msh, (unsigned char *)&KwdCod); - NexPos = GetPos(msh); - - if(NexPos > EndPos) - return(0); - - /* Check if this kwd belongs to this mesh version */ - - if( (KwdCod >= 1) && (KwdCod <= GmfMaxKwd) ) - ScaKwdHdr(msh, KwdCod); - - /* Go to the next kwd */ - - if(NexPos) - fseek(msh->hdl, NexPos, SEEK_SET); - }while(NexPos && (KwdCod != GmfEnd)); - } - - return(1); -} - - -/*----------------------------------------------------------*/ -/* Read and setup the keyword's header */ -/*----------------------------------------------------------*/ - -static void ScaKwdHdr(GmfMshSct *msh, int KwdCod) -{ - int i; - KwdSct *kwd = &msh->KwdTab[ KwdCod ]; - - if(!strcmp("i", GmfKwdFmt[ KwdCod ][2])) - { - if(msh->typ & Asc) - fscanf(msh->hdl, "%d", &kwd->NmbLin); - else - ScaWrd(msh, (unsigned char *)&kwd->NmbLin); - } - else - kwd->NmbLin = 1; - - if(!strcmp("sr", GmfKwdFmt[ KwdCod ][3])) - { - if(msh->typ & Asc) - { - fscanf(msh->hdl, "%d", &kwd->NmbTyp); - - for(i=0;iNmbTyp;i++) - fscanf(msh->hdl, "%d", &kwd->TypTab[i]); - } - else - { - ScaWrd(msh, (unsigned char *)&kwd->NmbTyp); - - for(i=0;iNmbTyp;i++) - ScaWrd(msh, (unsigned char *)&kwd->TypTab[i]); - } - } - - ExpFmt(msh, KwdCod); - kwd->pos = ftell(msh->hdl); -} - - -/*----------------------------------------------------------*/ -/* Expand the compacted format and compute the line size */ -/*----------------------------------------------------------*/ - -static void ExpFmt(GmfMshSct *msh, int KwdCod) -{ - int i, j, TmpSiz=0; - char chr; - const char *InpFmt = GmfKwdFmt[ KwdCod ][3]; - KwdSct *kwd = &msh->KwdTab[ KwdCod ]; - - /* Set the kwd's type */ - - if(!strlen(GmfKwdFmt[ KwdCod ][2])) - kwd->typ = InfKwd; - else if(!strcmp(InpFmt, "sr")) - kwd->typ = SolKwd; - else - kwd->typ = RegKwd; - - /* Get the solution-field's size */ - - if(kwd->typ == SolKwd) - for(i=0;iNmbTyp;i++) - switch(kwd->TypTab[i]) - { - case GmfSca : TmpSiz += 1; break; - case GmfVec : TmpSiz += msh->dim; break; - case GmfSymMat : TmpSiz += (msh->dim * (msh->dim+1)) / 2; break; - case GmfMat : TmpSiz += msh->dim * msh->dim; break; - } - - /* Scan each character from the format string */ - - i = kwd->SolSiz = kwd->NmbWrd = 0; - - while(i < strlen(InpFmt)) - { - chr = InpFmt[ i++ ]; - - if(chr == 'd') - { - chr = InpFmt[i++]; - - for(j=0;jdim;j++) - kwd->fmt[ kwd->SolSiz++ ] = chr; - } - else if(chr == 's') - { - chr = InpFmt[i++]; - - for(j=0;jfmt[ kwd->SolSiz++ ] = chr; - } - else - kwd->fmt[ kwd->SolSiz++ ] = chr; - } - - for(i=0;iSolSiz;i++) - if(kwd->fmt[i] == 'i') - kwd->NmbWrd++; - else if(msh->ver >= 2) - kwd->NmbWrd += 2; - else - kwd->NmbWrd++; -} - - -/*----------------------------------------------------------*/ -/* Read a four bytes word from a mesh file */ -/*----------------------------------------------------------*/ - -static void ScaWrd(GmfMshSct *msh, unsigned char *wrd) -{ - unsigned char swp; - - fread(wrd, WrdSiz, 1, msh->hdl); - - if(msh->cod == 1) - return; - - swp = wrd[3]; - wrd[3] = wrd[0]; - wrd[0] = swp; - - swp = wrd[2]; - wrd[2] = wrd[1]; - wrd[1] = swp; -} - - -/*----------------------------------------------------------*/ -/* Read an eight bytes word from a mesh file */ -/*----------------------------------------------------------*/ - -static void ScaDblWrd(GmfMshSct *msh, unsigned char *wrd) -{ - int i; - unsigned char swp; - - fread(wrd, WrdSiz, 2, msh->hdl); - - if(msh->cod == 1) - return; - - for(i=0;i<4;i++) - { - swp = wrd[7-i]; - wrd[7-i] = wrd[i]; - wrd[i] = swp; - } -} - - -/*----------------------------------------------------------*/ -/* Read ablock of four bytes word from a mesh file */ -/*----------------------------------------------------------*/ - -static void ScaBlk(GmfMshSct *msh, unsigned char *blk, int siz) -{ - int i, j; - unsigned char swp, *wrd; - - fread(blk, WrdSiz, siz, msh->hdl); - - if(msh->cod == 1) - return; - - for(i=0;iver >= 3) - ScaDblWrd(msh, (unsigned char*)&pos); - else - { - ScaWrd(msh, (unsigned char*)&IntVal); - pos = IntVal; - } - - return(pos); -} - - -/*----------------------------------------------------------*/ -/* Write a four bytes word to a mesh file */ -/*----------------------------------------------------------*/ - -static void RecWrd(GmfMshSct *msh, unsigned char *wrd) -{ - fwrite(wrd, WrdSiz, 1, msh->hdl); -} - - -/*----------------------------------------------------------*/ -/* Write an eight bytes word to a mesh file */ -/*----------------------------------------------------------*/ - -static void RecDblWrd(GmfMshSct *msh, unsigned char *wrd) -{ - fwrite(wrd, WrdSiz, 2, msh->hdl); -} - - -/*----------------------------------------------------------*/ -/* Write a block of four bytes word to a mesh file */ -/*----------------------------------------------------------*/ - -static void RecBlk(GmfMshSct *msh, unsigned char *blk, int siz) -{ - /* Copy this line-block into the main mesh buffer */ - - if(siz) - { - memcpy(&msh->blk[ msh->pos ], blk, siz * WrdSiz); - msh->pos += siz * WrdSiz; - } - - /* When the buffer is full or this procedure is called with a 0 size, flush the cache on disk */ - - if( (msh->pos > BufSiz) || (!siz && msh->pos) ) - { - fwrite(msh->blk, 1, msh->pos, msh->hdl); - msh->pos = 0; - } -} - - -/*----------------------------------------------------------*/ -/* Write a 4 or 8 bytes position in a mesh file */ -/*----------------------------------------------------------*/ - -static void SetPos(GmfMshSct *msh, long pos) -{ - int IntVal; - - if(msh->ver >= 3) - RecDblWrd(msh, (unsigned char*)&pos); - else - { - IntVal = pos; - RecWrd(msh, (unsigned char*)&IntVal); - } -} diff --git a/src/GHS3DPlugin/libmesh5.h b/src/GHS3DPlugin/libmesh5.h deleted file mode 100755 index eddf200..0000000 --- a/src/GHS3DPlugin/libmesh5.h +++ /dev/null @@ -1,153 +0,0 @@ - - -/*----------------------------------------------------------*/ -/* */ -/* LIBMESH V 5.46 */ -/* */ -/*----------------------------------------------------------*/ -/* */ -/* Description: handle .meshb file format I/O */ -/* Author: Loic MARECHAL */ -/* Creation date: feb 16 2007 */ -/* Last modification: dec 09 2011 */ -/* */ -/*----------------------------------------------------------*/ - - -/*----------------------------------------------------------*/ -/* Defines */ -/*----------------------------------------------------------*/ - -#define GmfStrSiz 1024 -#define GmfMaxTyp 1000 -#define GmfMaxKwd 80 -#define GmfMshVer 1 -#define GmfRead 1 -#define GmfWrite 2 -#define GmfSca 1 -#define GmfVec 2 -#define GmfSymMat 3 -#define GmfMat 4 -#define GmfFloat 1 -#define GmfDouble 2 - -enum GmfKwdCod -{ - GmfReserved1, \ - GmfVersionFormatted, \ - GmfReserved2, \ - GmfDimension, \ - GmfVertices, \ - GmfEdges, \ - GmfTriangles, \ - GmfQuadrilaterals, \ - GmfTetrahedra, \ - GmfPrisms, \ - GmfHexahedra, \ - GmfIterationsAll, \ - GmfTimesAll, \ - GmfCorners, \ - GmfRidges, \ - GmfRequiredVertices, \ - GmfRequiredEdges, \ - GmfRequiredTriangles, \ - GmfRequiredQuadrilaterals, \ - GmfTangentAtEdgeVertices, \ - GmfNormalAtVertices, \ - GmfNormalAtTriangleVertices, \ - GmfNormalAtQuadrilateralVertices, \ - GmfAngleOfCornerBound, \ - GmfTrianglesP2, \ - GmfEdgesP2, \ - GmfSolAtPyramids, \ - GmfQuadrilateralsQ2, \ - GmfISolAtPyramids, \ - GmfSubDomainFromGeom, \ - GmfTetrahedraP2, \ - GmfFault_NearTri, \ - GmfFault_Inter, \ - GmfHexahedraQ2, \ - GmfExtraVerticesAtEdges, \ - GmfExtraVerticesAtTriangles, \ - GmfExtraVerticesAtQuadrilaterals, \ - GmfExtraVerticesAtTetrahedra, \ - GmfExtraVerticesAtPrisms, \ - GmfExtraVerticesAtHexahedra, \ - GmfVerticesOnGeometricVertices, \ - GmfVerticesOnGeometricEdges, \ - GmfVerticesOnGeometricTriangles, \ - GmfVerticesOnGeometricQuadrilaterals, \ - GmfEdgesOnGeometricEdges, \ - GmfFault_FreeEdge, \ - GmfPolyhedra, \ - GmfPolygons, \ - GmfFault_Overlap, \ - GmfPyramids, \ - GmfBoundingBox, \ - GmfBody, \ - GmfPrivateTable, \ - GmfFault_BadShape, \ - GmfEnd, \ - GmfTrianglesOnGeometricTriangles, \ - GmfTrianglesOnGeometricQuadrilaterals, \ - GmfQuadrilateralsOnGeometricTriangles, \ - GmfQuadrilateralsOnGeometricQuadrilaterals, \ - GmfTangents, \ - GmfNormals, \ - GmfTangentAtVertices, \ - GmfSolAtVertices, \ - GmfSolAtEdges, \ - GmfSolAtTriangles, \ - GmfSolAtQuadrilaterals, \ - GmfSolAtTetrahedra, \ - GmfSolAtPrisms, \ - GmfSolAtHexahedra, \ - GmfDSolAtVertices, \ - GmfISolAtVertices, \ - GmfISolAtEdges, \ - GmfISolAtTriangles, \ - GmfISolAtQuadrilaterals, \ - GmfISolAtTetrahedra, \ - GmfISolAtPrisms, \ - GmfISolAtHexahedra, \ - GmfIterations, \ - GmfTime, \ - GmfFault_SmallTri, \ - GmfCoarseHexahedra -}; - - -/*----------------------------------------------------------*/ -/* External procedures */ -/*----------------------------------------------------------*/ - -extern int GmfOpenMesh(const char *, int, ...); -extern int GmfCloseMesh(int); -extern int GmfStatKwd(int, int, ...); -extern int GmfGotoKwd(int, int); -extern int GmfSetKwd(int, int, ...); -extern void GmfGetLin(int, int, ...); -extern void GmfSetLin(int, int, ...); - - -/*----------------------------------------------------------*/ -/* Fortran 77 API */ -/*----------------------------------------------------------*/ - -#if defined(F77_NO_UNDER_SCORE) -#define call(x) x -#else -#define call(x) x ## _ -#endif - - -/*----------------------------------------------------------*/ -/* Transmesh private API */ -/*----------------------------------------------------------*/ - -#ifdef TRANSMESH - -extern char *GmfKwdFmt[ GmfMaxKwd + 1 ][4]; -extern int GmfCpyLin(int, int, int); - -#endif diff --git a/src/GUI/GHS3DPluginGUI_Enums.h b/src/GUI/GHS3DPluginGUI_Enums.h index 2a2aca8..87c2563 100644 --- a/src/GUI/GHS3DPluginGUI_Enums.h +++ b/src/GUI/GHS3DPluginGUI_Enums.h @@ -58,7 +58,7 @@ enum { // Enforced vertices widget inputs enum { ENF_VER_WARNING = 0, - ENF_VER_VERTEX /*= 0*/, + ENF_VER_VERTEX,// = 0, ENF_VER_X_COORD, ENF_VER_Y_COORD, ENF_VER_Z_COORD, diff --git a/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx index 0d67752..eab4b29 100644 --- a/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx +++ b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx @@ -445,28 +445,35 @@ QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame() myBoundaryRecoveryCheck = new QCheckBox( tr( "RECOVERY_VERSION" ), myAdvGroup ); myFEMCorrectionCheck = new QCheckBox( tr( "FEM_CORRECTION" ), myAdvGroup ); + + QLabel* myGradationLabel = new QLabel( tr( "GHS3D_GRADATION" ), myAdvGroup ); + myGradation = new SMESHGUI_SpinBox(myAdvGroup); + myGradation->RangeStepAndValidator(1.05, 5.0, 0.05, "length_precision"); QLabel* aTextOptionLabel = new QLabel( tr( "TEXT_OPTION" ), myAdvGroup ); myTextOption = new QLineEdit( myAdvGroup ); - anAdvLayout->addWidget( myMaximumMemoryCheck, 0, 0, 1, 1 ); - anAdvLayout->addWidget( myMaximumMemorySpin, 0, 1, 1, 1 ); - anAdvLayout->addWidget( aMegabyteLabel, 0, 2, 1, 1 ); - anAdvLayout->addWidget( myInitialMemoryCheck, 1, 0, 1, 1 ); - anAdvLayout->addWidget( myInitialMemorySpin, 1, 1, 1, 1 ); - anAdvLayout->addWidget( aMegabyteLabel2, 1, 2, 1, 1 ); - anAdvLayout->addWidget( aWorkinDirLabel, 2, 0, 1, 1 ); - anAdvLayout->addWidget( myWorkingDir, 2, 1, 1, 2 ); - anAdvLayout->addWidget( dirBtn, 2, 3, 1, 1 ); - anAdvLayout->addWidget( myKeepFiles, 3, 0, 1, 4 ); - anAdvLayout->addWidget( aVerboseLevelLabel, 4, 0, 1, 1 ); - anAdvLayout->addWidget( myVerboseLevelSpin, 4, 1, 1, 1 ); - anAdvLayout->addWidget( myToCreateNewNodesCheck, 5, 0, 1, 4 ); - anAdvLayout->addWidget( myRemoveInitialCentralPointCheck, 6, 0, 1, 4 ); - anAdvLayout->addWidget( myBoundaryRecoveryCheck, 7, 0, 1, 4 ); - anAdvLayout->addWidget( myFEMCorrectionCheck, 8, 0, 1, 4 ); - anAdvLayout->addWidget( aTextOptionLabel, 9, 0, 1, 1 ); - anAdvLayout->addWidget( myTextOption, 9, 1, 1, 2 ); + row = 0; + anAdvLayout->addWidget( myMaximumMemoryCheck, row, 0, 1, 1 ); + anAdvLayout->addWidget( myMaximumMemorySpin, row, 1, 1, 1 ); + anAdvLayout->addWidget( aMegabyteLabel, row++, 2, 1, 1 ); + anAdvLayout->addWidget( myInitialMemoryCheck, row, 0, 1, 1 ); + anAdvLayout->addWidget( myInitialMemorySpin, row, 1, 1, 1 ); + anAdvLayout->addWidget( aMegabyteLabel2, row++, 2, 1, 1 ); + anAdvLayout->addWidget( aWorkinDirLabel, row, 0, 1, 1 ); + anAdvLayout->addWidget( myWorkingDir, row, 1, 1, 2 ); + anAdvLayout->addWidget( dirBtn, row++, 3, 1, 1 ); + anAdvLayout->addWidget( myKeepFiles, row++, 0, 1, 4 ); + anAdvLayout->addWidget( aVerboseLevelLabel, row, 0, 1, 1 ); + anAdvLayout->addWidget( myVerboseLevelSpin, row++, 1, 1, 2 ); + anAdvLayout->addWidget( myToCreateNewNodesCheck, row++, 0, 1, 4 ); + anAdvLayout->addWidget( myRemoveInitialCentralPointCheck, row++, 0, 1, 4 ); + anAdvLayout->addWidget( myBoundaryRecoveryCheck, row++, 0, 1, 4 ); + anAdvLayout->addWidget( myFEMCorrectionCheck, row++, 0, 1, 4 ); + anAdvLayout->addWidget( myGradationLabel, row, 0, 1, 1 ); + anAdvLayout->addWidget( myGradation, row++, 1, 1, 2 ); + anAdvLayout->addWidget( aTextOptionLabel, row, 0, 1, 1 ); + anAdvLayout->addWidget( myTextOption, row++, 1, 1, 2 ); // Enforced vertices parameters myEnfGroup = new QWidget(); @@ -478,10 +485,10 @@ QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame() myEnforcedTableWidget->setColumnCount( ENF_VER_NB_COLUMNS ); myEnforcedTableWidget->setSortingEnabled(true); QStringList enforcedHeaders; - enforcedHeaders << tr( "GHS3D_ENF_NAME_COLUMN" ) - << tr( "GHS3D_ENF_VER_X_COLUMN" )<< tr( "GHS3D_ENF_VER_Y_COLUMN" ) << tr( "GHS3D_ENF_VER_Z_COLUMN" ) + enforcedHeaders << tr( "GHS3D_ENF_NAME_COLUMN" ) + << tr( "GHS3D_ENF_VER_X_COLUMN" )<< tr( "GHS3D_ENF_VER_Y_COLUMN" ) << tr( "GHS3D_ENF_VER_Z_COLUMN" ) << tr( "GHS3D_ENF_SIZE_COLUMN" ) << tr("GHS3D_ENF_ENTRY_COLUMN") << tr("GHS3D_ENF_VER_COMPOUND_COLUMN") << tr( "GHS3D_ENF_GROUP_COLUMN" ); - + myEnforcedTableWidget->setHorizontalHeaderLabels(enforcedHeaders); myEnforcedTableWidget->verticalHeader()->hide(); myEnforcedTableWidget->horizontalHeader()->setStretchLastSection(true); @@ -1431,11 +1438,12 @@ void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const myRemoveInitialCentralPointCheck ->setChecked ( data.myRemoveInitialCentralPoint ); myBoundaryRecoveryCheck ->setChecked ( data.myBoundaryRecovery ); myFEMCorrectionCheck ->setChecked ( data.myFEMCorrection ); + myGradation ->setValue ( data.myGradation ); myTextOption ->setText ( data.myTextOption ); TEnfVertexList::const_iterator it; int rowCount = 0; - myEnforcedTableWidget->clear(); + myEnforcedTableWidget->clearContents(); myEnforcedTableWidget->setSortingEnabled(false); myEnforcedTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *))); for(it = data.myEnforcedVertices.begin() ; it != data.myEnforcedVertices.end(); it++ ) @@ -1515,7 +1523,7 @@ void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const // Update Enforced meshes QTableWidget TEnfMeshList::const_iterator itMesh; rowCount = 0; - myEnforcedMeshTableWidget->clear(); + myEnforcedMeshTableWidget->clearContents(); myEnforcedMeshTableWidget->setSortingEnabled(false); // myEnforcedMeshTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *))); for(itMesh = data.myEnforcedMeshes.begin() ; itMesh != data.myEnforcedMeshes.end(); itMesh++ ) @@ -1619,6 +1627,11 @@ QString GHS3DPluginGUI_HypothesisCreator::storeParams() const if ( data.myFEMCorrection ) valStr += " -FEM"; + if ( data.myGradation != 1.05 ) { + valStr += " -Dcpropa="; + valStr += QString::number( data.myGradation ); + } + valStr += " "; valStr += data.myTextOption; @@ -1666,6 +1679,7 @@ bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& h_data.myRemoveInitialCentralPoint = h->GetToRemoveCentralPoint(); h_data.myBoundaryRecovery = h->GetToUseBoundaryRecoveryVersion(); h_data.myFEMCorrection = h->GetFEMCorrection(); + h_data.myGradation = h->GetGradation(); h_data.myTextOption = h->GetTextOption(); GHS3DPlugin::GHS3DEnforcedVertexList_var vertices = h->GetEnforcedVertices(); @@ -1749,6 +1763,8 @@ bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisD h->SetToUseBoundaryRecoveryVersion( h_data.myBoundaryRecovery ); if ( h->GetFEMCorrection() != h_data.myFEMCorrection ) h->SetFEMCorrection( h_data.myFEMCorrection ); + if ( h->GetGradation() != h_data.myGradation ) + h->SetGradation ( h_data.myGradation ); if ( h->GetTextOption() != h_data.myTextOption ) h->SetTextOption ( h_data.myTextOption.toLatin1().constData() ); @@ -1848,6 +1864,7 @@ bool GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DHypothesisDat h_data.myRemoveInitialCentralPoint = myRemoveInitialCentralPointCheck->isChecked(); h_data.myBoundaryRecovery = myBoundaryRecoveryCheck->isChecked(); h_data.myFEMCorrection = myFEMCorrectionCheck->isChecked(); + h_data.myGradation = myGradation->value(); h_data.myTextOption = myTextOption->text(); // Enforced vertices diff --git a/src/GUI/GHS3DPluginGUI_HypothesisCreator.h b/src/GUI/GHS3DPluginGUI_HypothesisCreator.h index 0aab3e9..5e311ec 100644 --- a/src/GUI/GHS3DPluginGUI_HypothesisCreator.h +++ b/src/GUI/GHS3DPluginGUI_HypothesisCreator.h @@ -143,6 +143,7 @@ typedef struct bool myToMeshHoles,myKeepFiles,myToCreateNewNodes,myBoundaryRecovery,myFEMCorrection,myRemoveInitialCentralPoint; int myMaximumMemory,myInitialMemory,myOptimizationLevel; QString myName,myWorkingDir,myTextOption; + double myGradation; short myVerboseLevel; TEnfVertexList myEnforcedVertices; TEnfMeshList myEnforcedMeshes; @@ -222,6 +223,7 @@ private: QCheckBox* myRemoveInitialCentralPointCheck; QCheckBox* myBoundaryRecoveryCheck; QCheckBox* myFEMCorrectionCheck; + SMESHGUI_SpinBox* myGradation; QLineEdit* myTextOption; QWidget* myEnfGroup; diff --git a/src/GUI/GHS3DPlugin_msg_en.ts b/src/GUI/GHS3DPlugin_msg_en.ts index 65569d8..9c8884b 100644 --- a/src/GUI/GHS3DPlugin_msg_en.ts +++ b/src/GUI/GHS3DPlugin_msg_en.ts @@ -79,6 +79,10 @@ FEM_CORRECTION To use FEM correction + + GHS3D_GRADATION + Volumic gradation + SELECT_DIR ... diff --git a/src/GUI/GHS3DPlugin_msg_fr.ts b/src/GUI/GHS3DPlugin_msg_fr.ts index 86452f3..922e2cc 100755 --- a/src/GUI/GHS3DPlugin_msg_fr.ts +++ b/src/GUI/GHS3DPlugin_msg_fr.ts @@ -79,6 +79,10 @@ FEM_CORRECTION Utiliser correction FEM + + GHS3D_GRADATION + Gradation volumique + SELECT_DIR ...