Patch for MacOS (from SALOME forum)

This commit is contained in:
vsr 2017-01-20 15:50:46 +03:00
parent 41b3e44333
commit 21af9b3a2c
13 changed files with 54 additions and 39 deletions

View File

@ -25,7 +25,7 @@
// This is not done inside a function of SALOME because allocated memory is not always // This is not done inside a function of SALOME because allocated memory is not always
// returned to the system. (PAL16631) // returned to the system. (PAL16631)
// //
#ifndef WIN32 #if !defined WIN32 && !defined __APPLE__
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#endif #endif
@ -36,7 +36,7 @@
int main (int argc, char ** argv) int main (int argc, char ** argv)
{ {
// To better understand what is going on here, consult bug [SALOME platform 0019911] // To better understand what is going on here, consult bug [SALOME platform 0019911]
#ifndef WIN32 #if !defined WIN32 && !defined __APPLE__
struct sysinfo si; struct sysinfo si;
int err = sysinfo( &si ); int err = sysinfo( &si );
if ( err ) if ( err )

View File

@ -56,7 +56,7 @@
#include <iterator> #include <iterator>
using namespace std; using namespace std;
#ifndef WIN32 #if !defined WIN32 && !defined __APPLE__
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#endif #endif
@ -77,7 +77,7 @@ int SMDS_Mesh::chunkSize = 1024;
int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc) int SMDS_Mesh::CheckMemory(const bool doNotRaise) throw (std::bad_alloc)
{ {
#ifndef WIN32 #if !defined WIN32 && !defined __APPLE__
struct sysinfo si; struct sysinfo si;
int err = sysinfo( &si ); int err = sysinfo( &si );
if ( err ) if ( err )
@ -2819,7 +2819,7 @@ namespace {
IdSortedIterator(const SMDS_MeshElementIDFactory& fact, IdSortedIterator(const SMDS_MeshElementIDFactory& fact,
const SMDSAbs_ElementType type, // SMDSAbs_All NOT allowed!!! const SMDSAbs_ElementType type, // SMDSAbs_All NOT allowed!!!
const int totalNb) const int totalNb)
:myIDFact( fact ), :myIDFact( const_cast<SMDS_MeshElementIDFactory&>(fact) ),
myID(1), myMaxID( myIDFact.GetMaxID() ),myNbFound(0), myTotalNb( totalNb ), myID(1), myMaxID( myIDFact.GetMaxID() ),myNbFound(0), myTotalNb( totalNb ),
myType( type ), myType( type ),
myElem(0) myElem(0)

View File

@ -59,20 +59,20 @@ void counters::stats()
} }
} }
chrono::chrono(int i) : salome_chrono::salome_chrono(int i) :
_run(true), _ctr(i) _run(true), _ctr(i)
{ {
//MESSAGE("chrono::chrono " << _ctr << " " << _run); //MESSAGE("chrono::chrono " << _ctr << " " << _run);
_start = clock(); _start = clock();
} }
chrono::~chrono() salome_chrono::~salome_chrono()
{ {
if (_run) if (_run)
stop(); stop();
} }
void chrono::stop() void salome_chrono::stop()
{ {
//MESSAGE("chrono::stop " << _ctr << " " << _run); //MESSAGE("chrono::stop " << _ctr << " " << _run);
if (_run) if (_run)

View File

@ -46,11 +46,11 @@ protected:
static int _nbChrono; static int _nbChrono;
}; };
class SMDS_EXPORT chrono class SMDS_EXPORT salome_chrono
{ {
public: public:
chrono(int i); salome_chrono(int i);
~chrono(); ~salome_chrono();
void stop(); void stop();
protected: protected:
bool _run; bool _run;
@ -61,7 +61,7 @@ protected:
#ifdef CHRONODEF #ifdef CHRONODEF
#define CHRONO(i) counters::_ctrs[i]._ctrNames = (char *)__FILE__; \ #define CHRONO(i) counters::_ctrs[i]._ctrNames = (char *)__FILE__; \
counters::_ctrs[i]._ctrLines = __LINE__; \ counters::_ctrs[i]._ctrLines = __LINE__; \
chrono aChrono##i(i); salome_chrono aChrono##i(i);
#define CHRONOSTOP(i) aChrono##i.stop(); #define CHRONOSTOP(i) aChrono##i.stop();

View File

@ -4568,7 +4568,11 @@ void SMESH_MeshEditor::sweepElement(const SMDS_MeshElement* elem,
std::swap( itNN[0], itNN[1] ); std::swap( itNN[0], itNN[1] );
std::swap( prevNod[0], prevNod[1] ); std::swap( prevNod[0], prevNod[1] );
std::swap( nextNod[0], nextNod[1] ); std::swap( nextNod[0], nextNod[1] );
#if defined(__APPLE__)
std::swap( isSingleNode[0], isSingleNode[1] );
#else
isSingleNode.swap( isSingleNode[0], isSingleNode[1] ); isSingleNode.swap( isSingleNode[0], isSingleNode[1] );
#endif
if ( nbSame > 0 ) if ( nbSame > 0 )
sames[0] = 1 - sames[0]; sames[0] = 1 - sames[0];
iNotSameNode = 1 - iNotSameNode; iNotSameNode = 1 - iNotSameNode;

View File

@ -20,14 +20,18 @@
#ifndef _MEMOIRE_H_ #ifndef _MEMOIRE_H_
#define _MEMOIRE_H_ #define _MEMOIRE_H_
#ifdef __APPLE__
#include <stdlib.h>
#else
#include <malloc.h> #include <malloc.h>
#endif
#include <iostream> #include <iostream>
void memostat(const char* f, int l); void memostat(const char* f, int l);
void memostat(const char* f, int l) void memostat(const char* f, int l)
{ {
#ifdef WIN32 #if defined WIN32 || defined __APPLE__
//rnv: TODO: find alternative of the malloc_stats() on windows platform //rnv: TODO: find alternative of the malloc_stats() on windows platform
#else #else
struct mallinfo mem = mallinfo(); struct mallinfo mem = mallinfo();

View File

@ -102,7 +102,7 @@
#include <vector> #include <vector>
#include <set> #include <set>
#ifndef WIN32 #if !defined WIN32 && !defined __APPLE__
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#endif #endif
@ -786,7 +786,7 @@ SMESHGUI_ComputeDlg_QThreadQDialog(QWidget * parent,
QLabel * nbElemsName = new QLabel(tr("SMESH_MESHINFO_ELEMENTS"), this ); QLabel * nbElemsName = new QLabel(tr("SMESH_MESHINFO_ELEMENTS"), this );
nbNodesLabel = new QLabel("0", this ); nbNodesLabel = new QLabel("0", this );
nbElemsLabel = new QLabel("0", this ); nbElemsLabel = new QLabel("0", this );
#ifndef WIN32 #if !defined WIN32 && !defined __APPLE__
QLabel * freeRAMName = new QLabel(tr("SMESH_FREERAM"), this ); QLabel * freeRAMName = new QLabel(tr("SMESH_FREERAM"), this );
freeRAMLabel = new QLabel("", this ); freeRAMLabel = new QLabel("", this );
#endif #endif
@ -802,7 +802,7 @@ SMESHGUI_ComputeDlg_QThreadQDialog(QWidget * parent,
layout->addWidget(nbNodesLabel, row++, 1); layout->addWidget(nbNodesLabel, row++, 1);
layout->addWidget(nbElemsName, row, 0); layout->addWidget(nbElemsName, row, 0);
layout->addWidget(nbElemsLabel, row++, 1); layout->addWidget(nbElemsLabel, row++, 1);
#ifndef WIN32 #if !defined WIN32 && !defined __APPLE__
layout->addWidget(freeRAMName, row, 0); layout->addWidget(freeRAMName, row, 0);
layout->addWidget(freeRAMLabel, row++, 1); layout->addWidget(freeRAMLabel, row++, 1);
#endif #endif
@ -842,7 +842,7 @@ void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
{ {
nbNodesLabel->setText( QString("%1").arg( qthread.getMesh()->NbNodes() )); nbNodesLabel->setText( QString("%1").arg( qthread.getMesh()->NbNodes() ));
nbElemsLabel->setText( QString("%1").arg( qthread.getMesh()->NbElements() )); nbElemsLabel->setText( QString("%1").arg( qthread.getMesh()->NbElements() ));
#ifndef WIN32 #if !defined WIN32 && !defined __APPLE__
struct sysinfo si; struct sysinfo si;
const int err = sysinfo( &si ); const int err = sysinfo( &si );
if ( err ) if ( err )

View File

@ -91,11 +91,12 @@ bool SMESHGUI_XmlHandler::startElement (const QString&, const QString&,
*/ */
if( !myClientLib.isEmpty() ) if( !myClientLib.isEmpty() )
{ {
#ifdef WIN32 #if defined(WIN32)
//myServerLib += ".dll"; //myServerLib += ".dll";
myClientLib += ".dll"; myClientLib += ".dll";
#elif defined(__APPLE__)
myClientLib = "lib" + myClientLib + ".dylib";
#else #else
//myServerLib = "lib" + myServerLib + ".so";
myClientLib = "lib" + myClientLib + ".so"; myClientLib = "lib" + myClientLib + ".so";
#endif #endif
} }

View File

@ -54,6 +54,7 @@
#include <process.h> #include <process.h>
#else #else
#include <dlfcn.h> #include <dlfcn.h>
#include <libgen.h> // for basename function
#endif #endif
#ifdef WIN32 #ifdef WIN32
@ -382,8 +383,10 @@ GenericHypothesisCreator_i* SMESH_Gen_i::getHypothesisCreator(const char* theHyp
!strcmp( theLibName+libNameLen-3, ".so" )) !strcmp( theLibName+libNameLen-3, ".so" ))
{ {
//the old format //the old format
#ifdef WIN32 #if defined(WIN32)
aPlatformLibName = std::string( theLibName+3, libNameLen-6 ) + ".dll"; aPlatformLibName = std::string( theLibName+3, libNameLen-6 ) + ".dll";
#elif defined(__APPLE__)
aPlatformLibName = std::string( theLibName, libNameLen-3 ) + ".dylib";
#else #else
aPlatformLibName = theLibName; aPlatformLibName = theLibName;
#endif #endif
@ -391,11 +394,13 @@ GenericHypothesisCreator_i* SMESH_Gen_i::getHypothesisCreator(const char* theHyp
else else
{ {
//try to use new format //try to use new format
#ifdef WIN32 #if defined(WIN32)
aPlatformLibName = theLibName; aPlatformLibName = theLibName;
aPlatformLibName += ".dll"; aPlatformLibName += ".dll";
#elif defined(__APPLE__)
aPlatformLibName = std::string( "lib" ) + std::string( theLibName ) + ".dylib";
#else #else
aPlatformLibName = "lib" + std::string( theLibName ) + ".so"; aPlatformLibName = std::string( "lib" ) + std::string( theLibName ) + ".so";
#endif #endif
} }
} }
@ -1169,7 +1174,7 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMEDorSAUV( const char* theFileNa
_splitpath( theFileNameForPython, NULL, NULL, bname, NULL ); _splitpath( theFileNameForPython, NULL, NULL, bname, NULL );
string aFileName = bname; string aFileName = bname;
#else #else
string aFileName = basename( theFileNameForPython ); string aFileName = basename( const_cast<char *>(theFileNameForPython) );
#endif #endif
// Retrieve mesh names from the file // Retrieve mesh names from the file
DriverMED_R_SMESHDS_Mesh myReader; DriverMED_R_SMESHDS_Mesh myReader;
@ -1318,7 +1323,7 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName
_splitpath( theFileName, NULL, NULL, bname, NULL ); _splitpath( theFileName, NULL, NULL, bname, NULL );
string aFileName = bname; string aFileName = bname;
#else #else
string aFileName = basename( theFileName ); string aFileName = basename( const_cast<char *>(theFileName) );
#endif #endif
// publish mesh in the study // publish mesh in the study
if ( CanPublishInStudy( aMesh ) ) { if ( CanPublishInStudy( aMesh ) ) {
@ -1447,7 +1452,7 @@ SMESH_Gen_i::CreateMeshesFromGMF( const char* theFileName,
_splitpath( theFileName, NULL, NULL, bname, NULL ); _splitpath( theFileName, NULL, NULL, bname, NULL );
string aFileName = bname; string aFileName = bname;
#else #else
string aFileName = basename( theFileName ); string aFileName = basename( const_cast<char *>(theFileName) );
#endif #endif
// publish mesh in the study // publish mesh in the study
if ( CanPublishInStudy( aMesh ) ) { if ( CanPublishInStudy( aMesh ) ) {

View File

@ -180,10 +180,10 @@ int main(int argc, char *argv[])
//int NG[4]; // Num. globaux des sommets //int NG[4]; // Num. globaux des sommets
// Acquisition maillage initial // Acquisition maillage initial
//cout << chrono() << " - Acquisition du maillage initial" << endl; //cout << salome_chrono() << " - Acquisition du maillage initial" << endl;
MAILLAGE1 = new Maillage((string) "TEMP"); MAILLAGE1 = new Maillage((string) "TEMP");
MAILLAGE1->inputMED(ficMEDin); MAILLAGE1->inputMED(ficMEDin);
cout << chrono() << " - End of mesh read" << endl; cout << salome_chrono() << " - End of mesh read" << endl;
indexNouveauxNoeuds = MAILLAGE1->nombreNoeudsMaillage; indexNouveauxNoeuds = MAILLAGE1->nombreNoeudsMaillage;
// Le maillage ne contient aucun TETRA4 : on rend le maillage initial sans modification // Le maillage ne contient aucun TETRA4 : on rend le maillage initial sans modification
@ -192,7 +192,7 @@ int main(int argc, char *argv[])
cout << "WARNING: mesh does not contain tetra4 elements, it will not be modified" << endl; cout << "WARNING: mesh does not contain tetra4 elements, it will not be modified" << endl;
MAILLAGE1->ID = str_id_maillagenew; MAILLAGE1->ID = str_id_maillagenew;
MAILLAGE1->outputMED(ficMEDout); MAILLAGE1->outputMED(ficMEDout);
cout << chrono() << " - Finished!" << endl << endl; cout << salome_chrono() << " - Finished!" << endl << endl;
exit(0); exit(0);
} }
// A partir de cet instant le maillage contient forcément des TETRA4 // A partir de cet instant le maillage contient forcément des TETRA4
@ -202,7 +202,7 @@ int main(int argc, char *argv[])
DNP = (float*) malloc(sizeof(float) * MAILLAGE1->nombreNoeudsMaillage); DNP = (float*) malloc(sizeof(float) * MAILLAGE1->nombreNoeudsMaillage);
for (int k = 0; k < MAILLAGE1->nombreNoeudsMaillage; k++) for (int k = 0; k < MAILLAGE1->nombreNoeudsMaillage; k++)
DNP[k] = distanceNoeudPlan(k + 1); DNP[k] = distanceNoeudPlan(k + 1);
cout << chrono() << " - End of computation of distances between nodes and plane" << endl; cout << salome_chrono() << " - End of computation of distances between nodes and plane" << endl;
// Longueur d'arête moyenne des T4 intersectant le plan de coupe // Longueur d'arête moyenne des T4 intersectant le plan de coupe
float LONGUEURS = 0.0; float LONGUEURS = 0.0;
@ -246,7 +246,7 @@ int main(int argc, char *argv[])
<< endl; << endl;
MAILLAGE1->ID = str_id_maillagenew; MAILLAGE1->ID = str_id_maillagenew;
MAILLAGE1->outputMED(ficMEDout); MAILLAGE1->outputMED(ficMEDout);
cout << chrono() << " - Finished!" << endl << endl; cout << salome_chrono() << " - Finished!" << endl << endl;
exit(0); exit(0);
} }
// A partir de cet instant le maillage contient forcément des TETRA4 intersectant le plan de coupe // A partir de cet instant le maillage contient forcément des TETRA4 intersectant le plan de coupe
@ -256,7 +256,7 @@ int main(int argc, char *argv[])
epsilon = tolerance * longueurMoyenne; epsilon = tolerance * longueurMoyenne;
int nT4coupe = cptLONGUEURS / 6; int nT4coupe = cptLONGUEURS / 6;
cout << chrono() << " - End of computation of mean length of tetra4 edges near the cut plane" << endl; cout << salome_chrono() << " - End of computation of mean length of tetra4 edges near the cut plane" << endl;
cout << "Number of tetra4 to be cut = " << nT4coupe << endl; cout << "Number of tetra4 to be cut = " << nT4coupe << endl;
cout << "Mean length = " << longueurMoyenne << endl; cout << "Mean length = " << longueurMoyenne << endl;
@ -274,7 +274,7 @@ int main(int argc, char *argv[])
else else
POSN[k] = 0; POSN[k] = 0;
} }
cout << chrono() << " - End of nodes qualification above or below the cut plane" << endl; cout << salome_chrono() << " - End of nodes qualification above or below the cut plane" << endl;
cout << "Start of iteration on tetra4" << endl; cout << "Start of iteration on tetra4" << endl;
for (int it4 = 0; it4 < MAILLAGE1->EFFECTIFS_TYPES[TETRA4]; it4++) for (int it4 = 0; it4 < MAILLAGE1->EFFECTIFS_TYPES[TETRA4]; it4++)
@ -993,7 +993,7 @@ int main(int argc, char *argv[])
ERREUR("Case not taken into account"); ERREUR("Case not taken into account");
} }
cout << chrono() << " - End of iteration on tetra4" << endl; cout << salome_chrono() << " - End of iteration on tetra4" << endl;
// cout << "indexNouveauxNoeuds = " << indexNouveauxNoeuds << endl; // cout << "indexNouveauxNoeuds = " << indexNouveauxNoeuds << endl;
newXX.resize(indexNouveauxNoeuds - MAILLAGE1->nombreNoeudsMaillage); newXX.resize(indexNouveauxNoeuds - MAILLAGE1->nombreNoeudsMaillage);
@ -1011,7 +1011,7 @@ int main(int argc, char *argv[])
// 2. Constitution du maillage final // 2. Constitution du maillage final
// ========================================================================================= // =========================================================================================
cout << chrono() << " - Constitution of final mesh" << endl; cout << salome_chrono() << " - Constitution of final mesh" << endl;
MAILLAGE2 = new Maillage(str_id_maillagenew); MAILLAGE2 = new Maillage(str_id_maillagenew);
MAILLAGE2->dimensionMaillage = MAILLAGE1->dimensionMaillage; MAILLAGE2->dimensionMaillage = MAILLAGE1->dimensionMaillage;
@ -1114,10 +1114,10 @@ int main(int argc, char *argv[])
MAILLAGE2->eliminationMailles(TETRA4, cutTetras); MAILLAGE2->eliminationMailles(TETRA4, cutTetras);
cout << chrono() << " - MED file writing" << endl; cout << salome_chrono() << " - MED file writing" << endl;
MAILLAGE2->outputMED(ficMEDout); MAILLAGE2->outputMED(ficMEDout);
cout << chrono() << " - Finished!" << endl << endl; cout << salome_chrono() << " - Finished!" << endl << endl;
return 0; return 0;

View File

@ -589,7 +589,7 @@ med_geometry_type MESHCUT::InstanceMGE(TYPE_MAILLE TYPE)
return typeBanaliseMED; return typeBanaliseMED;
} }
int MESHCUT::chrono() int MESHCUT::salome_chrono()
{ {
return clock() / CLOCKS_PER_SEC; return clock() / CLOCKS_PER_SEC;
} }

View File

@ -57,7 +57,7 @@ namespace MESHCUT
int copieFichier(std::string source, std::string cible); int copieFichier(std::string source, std::string cible);
med_geometry_type InstanceMGE(TYPE_MAILLE TYPE); med_geometry_type InstanceMGE(TYPE_MAILLE TYPE);
int chrono(); int salome_chrono();
TYPE_MAILLE typeMaille(std::string type); TYPE_MAILLE typeMaille(std::string type);
std::string MGE2string(med_geometry_type MGE); std::string MGE2string(med_geometry_type MGE);
std::string TM2string(TYPE_MAILLE MGE); std::string TM2string(TYPE_MAILLE MGE);

View File

@ -129,6 +129,7 @@ MeshJobManager_i::~MeshJobManager_i() {
#include <direct.h> // to get _mkdir #include <direct.h> // to get _mkdir
#else #else
#include <unistd.h> // to get basename #include <unistd.h> // to get basename
#include <libgen.h> // to get basename - as per posix
#include <sys/stat.h> // to get mkdir #include <sys/stat.h> // to get mkdir
#include <sys/types.h> // to get mkdir options #include <sys/types.h> // to get mkdir options
#endif #endif
@ -242,7 +243,7 @@ const char* MeshJobManager_i::_writeScriptFile(const char * dataFileName, const
_splitpath( dataFileName, NULL, NULL, fname, NULL ); _splitpath( dataFileName, NULL, NULL, fname, NULL );
const char* bname = &fname[0]; const char* bname = &fname[0];
#else #else
const char* bname = basename(dataFileName); const char* bname = basename(const_cast<char *>(dataFileName));
#endif #endif