From: adam Date: Mon, 21 Sep 2009 08:29:23 +0000 (+0000) Subject: windows port X-Git-Tag: V5_1_3rc1~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=92ff781ac4ced9149e990c6d42e8285e52c566a7;p=plugins%2Fghs3dplugin.git windows port --- diff --git a/src/GHS3DPlugin_Defs.hxx b/src/GHS3DPlugin_Defs.hxx index 5476008..b41e0d7 100644 --- a/src/GHS3DPlugin_Defs.hxx +++ b/src/GHS3DPlugin_Defs.hxx @@ -24,7 +24,7 @@ #define _GHS3DPlugin_DEFS_HXX_ #ifdef WIN32 - #ifdef GHS3DPLUGIN_EXPORTS + #if defined GHS3DPLUGIN_EXPORTS || defined GHS3DEngine_EXPORTS #define GHS3DPLUGIN_EXPORT __declspec( dllexport ) #else #define GHS3DPLUGIN_EXPORT __declspec( dllimport ) diff --git a/src/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin_GHS3D.cxx index 23ef2c5..4ebeb38 100644 --- a/src/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin_GHS3D.cxx @@ -24,8 +24,6 @@ // $Header$ //============================================================================= // -using namespace std; - #include "GHS3DPlugin_GHS3D.hxx" #include "GHS3DPlugin_Hypothesis.hxx" @@ -64,10 +62,14 @@ using namespace std; #include "utilities.h" -#ifndef WIN32 +#ifdef WIN32 +#include +#else #include #endif +using namespace std; + //#include @@ -638,6 +640,9 @@ static int findShapeID(SMESH_Mesh& mesh, //======================================================================= static bool readResultFile(const int fileOpen, +#ifdef WNT + const char* fileName, +#endif SMESH_Mesh& theMesh, TopoDS_Shape tabShape[], double** tabBox, @@ -686,7 +691,15 @@ static bool readResultFile(const int fileOpen, 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); @@ -833,7 +846,13 @@ static bool readResultFile(const int fileOpen, 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; @@ -863,6 +882,9 @@ static bool readResultFile(const int fileOpen, //======================================================================= static bool readResultFile(const int fileOpen, +#ifdef WNT + const char* fileName, +#endif SMESHDS_Mesh* theMeshDS, TopoDS_Shape aSolid, vector & theNodeByGhs3dId) { @@ -897,7 +919,15 @@ static bool readResultFile(const int fileOpen, 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); @@ -945,7 +975,13 @@ static bool readResultFile(const int fileOpen, } 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; @@ -1019,11 +1055,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, 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); @@ -1080,7 +1112,11 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, 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 ); } @@ -1161,11 +1197,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, 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); @@ -1211,7 +1243,11 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, Ok = false; } else { - Ok = readResultFile( fileOpen, meshDS, theShape ,aNodeByGhs3dId ); + Ok = readResultFile( fileOpen, +#ifdef WNT + aResultFileName.ToCString(), +#endif + meshDS, theShape ,aNodeByGhs3dId ); } // --------------------- diff --git a/src/GHS3DPlugin_GHS3D_i.cxx b/src/GHS3DPlugin_GHS3D_i.cxx index 21469d3..83c3ae7 100644 --- a/src/GHS3DPlugin_GHS3D_i.cxx +++ b/src/GHS3DPlugin_GHS3D_i.cxx @@ -22,13 +22,14 @@ // Module : GHS3DPlugin // $Header$ // -using namespace std; #include "GHS3DPlugin_GHS3D_i.hxx" #include "SMESH_Gen.hxx" #include "GHS3DPlugin_GHS3D.hxx" #include "utilities.h" +using namespace std; + //============================================================================= /*! * GHS3DPlugin_GHS3D_i::GHS3DPlugin_GHS3D_i diff --git a/src/GHS3DPlugin_Hypothesis.cxx b/src/GHS3DPlugin_Hypothesis.cxx index 3a29541..2a0096e 100644 --- a/src/GHS3DPlugin_Hypothesis.cxx +++ b/src/GHS3DPlugin_Hypothesis.cxx @@ -26,6 +26,11 @@ #include +#ifdef WNT +#include +#define getpid _getpid +#endif + //======================================================================= //function : GHS3DPlugin_Hypothesis //======================================================================= @@ -280,6 +285,8 @@ bool GHS3DPlugin_Hypothesis::DefaultMeshHoles() #ifndef WIN32 #include +#else +#include #endif short GHS3DPlugin_Hypothesis::DefaultMaximumMemory() @@ -291,8 +298,19 @@ 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; } //======================================================================= @@ -510,11 +528,7 @@ bool GHS3DPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/ 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; @@ -595,6 +609,10 @@ string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* hyp, cmd += (char*) hyp->myTextOption.c_str(); } +#ifdef WNT + cmd += " < NUL"; +#endif + return cmd.ToCString(); } @@ -616,11 +634,7 @@ string GHS3DPlugin_Hypothesis::GetFileName(const GHS3DPlugin_Hypothesis* hyp) 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()); diff --git a/src/GHS3DPlugin_i.cxx b/src/GHS3DPlugin_i.cxx index 20188c2..309ef5a 100644 --- a/src/GHS3DPlugin_i.cxx +++ b/src/GHS3DPlugin_i.cxx @@ -22,7 +22,6 @@ // Module : SMESH // $Header$ // -using namespace std; #include "SMESH_Hypothesis_i.hxx" #include "utilities.h" @@ -30,6 +29,8 @@ using namespace std; #include "GHS3DPlugin_GHS3D_i.hxx" #include "GHS3DPlugin_Hypothesis_i.hxx" +using namespace std; + template class GHS3DPlugin_Creator_i:public HypothesisCreator_i { // as we have 'module GHS3DPlugin' in GHS3DPlugin_Algorithm.idl @@ -44,6 +45,7 @@ template class GHS3DPlugin_Creator_i:public HypothesisCreator_i extern "C" { + GHS3DPLUGIN_EXPORT GenericHypothesisCreator_i* GetHypothesisCreator (const char* aHypName) { MESSAGE("GetHypothesisCreator " << aHypName); diff --git a/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx index 411036e..97b4775 100644 --- a/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx +++ b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx @@ -54,13 +54,27 @@ enum { namespace { -#ifndef WIN32 +#ifdef WIN32 +#include +#else #include #endif int maxAvailableMemory() { -#ifndef WIN32 +#ifdef WIN32 + // 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 ); + } +#else struct sysinfo si; int err = sysinfo( &si ); if ( err == 0 ) { @@ -70,7 +84,6 @@ namespace { return (int) ( 0.7 * totMB ); } #endif - return 100000; } } @@ -397,7 +410,7 @@ QString GHS3DPluginGUI_HypothesisCreator::helpPage() const //============================================================================= extern "C" { - GHS3DPLUGIN_EXPORT + GHS3DPLUGINGUI_EXPORT SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator( const QString& aHypType ) { if ( aHypType == "GHS3D_Parameters" ) diff --git a/src/GUI/GHS3DPluginGUI_HypothesisCreator.h b/src/GUI/GHS3DPluginGUI_HypothesisCreator.h index 55c7433..87a9c56 100644 --- a/src/GUI/GHS3DPluginGUI_HypothesisCreator.h +++ b/src/GUI/GHS3DPluginGUI_HypothesisCreator.h @@ -24,7 +24,16 @@ #ifndef GHS3DPLUGINGUI_HypothesisCreator_HeaderFile #define GHS3DPLUGINGUI_HypothesisCreator_HeaderFile -#include "GHS3DPlugin_Defs.hxx" +#ifdef WIN32 + #if defined GHS3DPluginGUI_EXPORTS + #define GHS3DPLUGINGUI_EXPORT __declspec( dllexport ) + #else + #define GHS3DPLUGINGUI_EXPORT __declspec( dllimport ) + #endif +#else + #define GHS3DPLUGINGUI_EXPORT +#endif + #include class QWidget; @@ -52,7 +61,7 @@ typedef struct /*! \brief Class for creation of GHS3D2D and GHS3D3D hypotheses */ -class GHS3DPLUGIN_EXPORT GHS3DPluginGUI_HypothesisCreator : public SMESHGUI_GenericHypothesisCreator +class GHS3DPLUGINGUI_EXPORT GHS3DPluginGUI_HypothesisCreator : public SMESHGUI_GenericHypothesisCreator { Q_OBJECT diff --git a/src/GUI/Makefile.am b/src/GUI/Makefile.am index d7747cc..0bf2ab9 100644 --- a/src/GUI/Makefile.am +++ b/src/GUI/Makefile.am @@ -51,7 +51,9 @@ libGHS3DPluginGUI_la_CPPFLAGS = \ libGHS3DPluginGUI_la_LDFLAGS = \ ../../idl/libSalomeIDLGHS3DPLUGIN.la \ + $(QT_LIBS) \ $(SMESH_LDFLAGS) -lSMESH \ + $(GUI_LDFLAGS) -lsuit -lqtx -lSalomeApp \ $(CAS_KERNEL) # resources files diff --git a/src/Makefile.am b/src/Makefile.am index a3cd580..1986df6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -61,5 +61,6 @@ libGHS3DEngine_la_CPPFLAGS = \ libGHS3DEngine_la_LDFLAGS = \ ../idl/libSalomeIDLGHS3DPLUGIN.la \ - $(SMESH_LDFLAGS) -lSMESHimpl -lSMESHEngine - $(KERNEL_LDFLAGS) -lSalomeGenericObj + $(CAS_KERNEL) -lTKBRep -lTKG2d -lTKG3d -lTKTopAlgo -lTKGeomBase -lTKGeomAlgo \ + $(SMESH_LDFLAGS) -lSMESHimpl -lSMESHEngine -lSMESHDS -lSMDS \ + $(KERNEL_LDFLAGS) -lSalomeGenericObj -lSALOMELocalTrace