#include "utilities.h"
-#include <qdir.h>
+#include <qfile.h>
#ifdef _DEBUG_
#define DUMP(txt) \
SMESHDS_Mesh * theMesh,
const map <int,int> & theSmdsToGhs3dIdMap)
{
- // structure:
+ // record structure:
//
// NB_ELEMS DUMMY_INT
// Loop from 1 to NB_ELEMS
map <int,int> & theSmdsToGhs3dIdMap,
map <int,const SMDS_MeshNode*> & theGhs3dIdToNodeMap)
{
- // structure:
+ // record structure:
//
// NB_NODES
// Loop from 1 to NB_NODES
// get shell to set nodes in
TopExp_Explorer exp( theShape, TopAbs_SHELL );
TopoDS_Shell aShell = TopoDS::Shell( exp.Current() );
+ if ( aShell.IsNull() )
+ return false;
- // -------------------------------------
+ // ----------------------------------------
// record 1:
- // read nb generated elements and nodes
- // -------------------------------------
+ // read nb of generated elements and nodes
+ // ----------------------------------------
int nbElems = 0 , nbNodes = 0, nbInputNodes = 0;
GHS3DPlugin_ReadLine( aPtr, aBuffer, theFile, aLineNb );
if (!aPtr ||
theMesh->MoveNode( node, coord[0], coord[1], coord[2] );
}
- return true;
+ return nbElems;
}
//=============================================================================
MESSAGE("GHS3DPlugin_GHS3D::Compute");
// working dir
- const char* wdName = "tmp";
- QDir wd = QDir::root(); // "/"
- if ( !wd.cd( wdName ) ) { // "/tmp"
- MESSAGE( "Cannot find the " << wdName << " directory" );
- return false;
+ QString aTmpDir ( getenv("SALOME_TMP_DIR") );
+ if ( !aTmpDir.isEmpty() ) {
+#ifdef WIN32
+ if(aTmpDir.at(aTmpDir.length()-1) != '\\') aTmpDir+='\\';
+#else
+ if(aTmpDir.at(aTmpDir.length()-1) != '/') aTmpDir+='/';
+#endif
}
+ else {
+#ifdef WIN32
+ aTmpDir = "C:\\";
+#else
+ aTmpDir = "/tmp/";
+#endif
+ }
+ // a unique name helps to avoid access to the same files by eg different users
+ int aUniqueNb;
+#ifdef WIN32
+ aUniqueNb = GetCurrentProcessId();
+#else
+ aUniqueNb = getpid();
+#endif
- const QString aGenericName = wd.filePath( "GHS3DTMP" );
+ const QString aGenericName = (aTmpDir + ( "GHS3D_%1" )).arg( aUniqueNb );
const QString aFacesFileName = aGenericName + ".faces";
const QString aPointsFileName = aGenericName + ".points";
const QString aResultFileName = aGenericName + ".noboite";
- const QString aErrorFileName = aGenericName + ".error";
+ const QString aErrorFileName = aGenericName + ".log";
// remove old files
QFile( aFacesFileName ).remove();
ofstream aFacesFile ( aFacesFileName.latin1() , ios::out);
ofstream aPointsFile ( aPointsFileName.latin1() , ios::out);
- if (!aFacesFile || !aFacesFile.rdbuf()->is_open() ||
- !aPointsFile || !aPointsFile.rdbuf()->is_open())
+ bool Ok =
+#ifdef WIN32
+ aFacesFile->is_open() && aPointsFile->is_open();
+#else
+ aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open();
+#endif
+ if (!Ok)
{
- MESSAGE( "Can't write into " << wdName << " directory");
+ MESSAGE( "Can't write into " << aTmpDir << " directory");
return false;
}
SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
map <int,int> aSmdsToGhs3dIdMap;
map <int,const SMDS_MeshNode*> aGhs3dIdToNodeMap;
- bool Ok =
+ Ok =
(writePoints( aPointsFile, meshDS, aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap ) &&
writeFaces ( aFacesFile, meshDS, aSmdsToGhs3dIdMap ));
return false;
// -----------------
- // run ghs3d mesher
+ // run ghs3d mesher WIN32???
// -----------------
QString cmd = "ghs3d "
" 1>" + aErrorFileName; // dump into file
if (system(cmd.latin1()))
{
- MESSAGE ("Failed: <" << cmd.latin1() << ">");
+ MESSAGE ("command failed: " << cmd.latin1() );
return false;
}
Ok = readResult( aResultFile, meshDS, theShape, aGhs3dIdToNodeMap );
fclose(aResultFile);
+ if ( Ok ) {
+ QFile( aFacesFileName ).remove();
+ QFile( aPointsFileName ).remove();
+ QFile( aResultFileName ).remove();
+ QFile( aErrorFileName ).remove();
+ }
return Ok;
}
//=============================================================================
// File : GHS3DPlugin_GHS3D.hxx
-// Moved here from SMESH_GHS3D_3D.hxx
-// Created : lundi 27 Janvier 2003
-// Author : Nadir BOUHAMOU (CEA)
// Project : SALOME
// Copyright : CEA 2003
// $Header$
#define _GHS3DPlugin_GHS3D_HXX_
#include "SMESH_3D_Algo.hxx"
-//#include "SMESH_Mesh.hxx"
class SMESH_Mesh;
GHS3DPlugin_GHS3D(int hypId, int studyId, SMESH_Gen* gen);
virtual ~GHS3DPlugin_GHS3D();
- virtual bool CheckHypothesis(SMESH_Mesh& aMesh,
- const TopoDS_Shape& aShape,
+ virtual bool CheckHypothesis(SMESH_Mesh& aMesh,
+ const TopoDS_Shape& aShape,
SMESH_Hypothesis::Hypothesis_Status& aStatus);
- virtual bool Compute(SMESH_Mesh& aMesh,
+ virtual bool Compute(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape);
ostream & SaveTo(ostream & save);