// $Header$
//=============================================================================
//
-using namespace std;
-
#include "GHS3DPlugin_GHS3D.hxx"
#include "GHS3DPlugin_Hypothesis.hxx"
#include "utilities.h"
-#ifndef WIN32
+#ifdef WIN32
+#include <io.h>
+#else
#include <sys/sysinfo.h>
#endif
+using namespace std;
+
//#include <Standard_Stream.hxx>
//=======================================================================
static bool readResultFile(const int fileOpen,
+#ifdef WNT
+ const char* fileName,
+#endif
SMESH_Mesh& theMesh,
TopoDS_Shape tabShape[],
double** tabBox,
length = status.st_size;
// Mapping the result file into memory
+#ifdef WNT
+ HANDLE fd = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ,
+ NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ HANDLE hMapObject = CreateFileMapping(fd, NULL, PAGE_READONLY,
+ 0, (DWORD)length, NULL);
+ ptr = ( char* ) MapViewOfFile(hMapObject, FILE_MAP_READ, 0, 0, 0 );
+#else
ptr = (char *) mmap(0,length,PROT_READ,MAP_PRIVATE,fileOpen,0);
+#endif
mapPtr = ptr;
ptr = readMapIntLine(ptr, tab);
if ( nbElems )
cout << nbElems << " tetrahedrons have been associated to " << nbShape << " shapes" << endl;
+#ifdef WNT
+ UnmapViewOfFile(mapPtr);
+ CloseHandle(hMapObject);
+ CloseHandle(fd);
+#else
munmap(mapPtr, length);
+#endif
close(fileOpen);
delete [] tab;
//=======================================================================
static bool readResultFile(const int fileOpen,
+#ifdef WNT
+ const char* fileName,
+#endif
SMESHDS_Mesh* theMeshDS,
TopoDS_Shape aSolid,
vector <const SMDS_MeshNode*>& theNodeByGhs3dId) {
length = status.st_size;
// Mapping the result file into memory
+#ifdef WNT
+ HANDLE fd = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ,
+ NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ HANDLE hMapObject = CreateFileMapping(fd, NULL, PAGE_READONLY,
+ 0, (DWORD)length, NULL);
+ ptr = ( char* ) MapViewOfFile(hMapObject, FILE_MAP_READ, 0, 0, 0 );
+#else
ptr = (char *) mmap(0,length,PROT_READ,MAP_PRIVATE,fileOpen,0);
+#endif
mapPtr = ptr;
ptr = readMapIntLine(ptr, tab);
}
if ( nbElems )
cout << nbElems << " tetrahedrons have been associated to " << nbTriangle << " shapes" << endl;
+#ifdef WNT
+ UnmapViewOfFile(mapPtr);
+ CloseHandle(hMapObject);
+ CloseHandle(fd);
+#else
munmap(mapPtr, length);
+#endif
close(fileOpen);
delete [] tab;
ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out);
Ok =
-#ifdef WIN32
- aFacesFile->is_open() && aPointsFile->is_open();
-#else
aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open();
-#endif
if (!Ok) {
INFOS( "Can't write into " << aFacesFileName);
return error(SMESH_Comment("Can't write into ") << aFacesFileName);
else {
bool toMeshHoles =
_hyp ? _hyp->GetToMeshHoles(true) : GHS3DPlugin_Hypothesis::DefaultMeshHoles();
- Ok = readResultFile( fileOpen, theMesh, tabShape, tabBox, _nbShape, aGhs3dIdToNodeMap,
+ Ok = readResultFile( fileOpen,
+#ifdef WNT
+ aResultFileName.ToCString(),
+#endif
+ theMesh, tabShape, tabBox, _nbShape, aGhs3dIdToNodeMap,
toMeshHoles );
}
ofstream aFacesFile ( aFacesFileName.ToCString() , ios::out);
ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out);
bool Ok =
-#ifdef WIN32
- aFacesFile->is_open() && aPointsFile->is_open();
-#else
aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open();
-#endif
if (!Ok)
return error( SMESH_Comment("Can't write into ") << aPointsFileName);
Ok = false;
}
else {
- Ok = readResultFile( fileOpen, meshDS, theShape ,aNodeByGhs3dId );
+ Ok = readResultFile( fileOpen,
+#ifdef WNT
+ aResultFileName.ToCString(),
+#endif
+ meshDS, theShape ,aNodeByGhs3dId );
}
// ---------------------
#include <TCollection_AsciiString.hxx>
+#ifdef WNT
+#include <process.h>
+#define getpid _getpid
+#endif
+
//=======================================================================
//function : GHS3DPlugin_Hypothesis
//=======================================================================
#ifndef WIN32
#include <sys/sysinfo.h>
+#else
+#include <windows.h>
#endif
short GHS3DPlugin_Hypothesis::DefaultMaximumMemory()
int ramMB = si.totalram * si.mem_unit / 1024 / 1024;
return (short) ( 0.7 * ramMB );
}
+#else
+ // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
+ MEMORYSTATUSEX statex;
+ statex.dwLength = sizeof (statex);
+ int err = GlobalMemoryStatusEx (&statex);
+ if (err != 0) {
+ int totMB =
+ statex.ullTotalPhys / 1024 / 1024 +
+ statex.ullTotalPageFile / 1024 / 1024 +
+ statex.ullTotalVirtual / 1024 / 1024;
+ return (int) ( 0.7 * totMB );
+ }
#endif
- return -1;
}
//=======================================================================
string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* hyp,
const bool hasShapeToMesh)
{
-#ifndef WIN32
TCollection_AsciiString cmd( "ghs3d" );
-#else
- TCollection_AsciiString cmd( "ghs3d.exe" );
-#endif
// check if any option is overridden by hyp->myTextOption
bool m = hyp ? ( hyp->myTextOption.find("-m") == string::npos ) : true;
bool M = hyp ? ( hyp->myTextOption.find("-M") == string::npos ) : true;
cmd += (char*) hyp->myTextOption.c_str();
}
+#ifdef WNT
+ cmd += " < NUL";
+#endif
+
return cmd.ToCString();
}
TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str();
aGenericName += "GHS3D_";
-#ifdef WIN32
- aGenericName += GetCurrentProcessId();
-#else
aGenericName += getpid();
-#endif
aGenericName += "_";
aGenericName += Abs((Standard_Integer)(long) aGenericName.ToCString());