+ // make a unique working file name
+ // to avoid access to the same files by eg different users
+
+ TCollection_AsciiString aGenericName, aTmpDir = getTmpDir();
+ aGenericName = aTmpDir + "GHS3D_";
+#ifdef WIN32
+ aGenericName += GetCurrentProcessId();
+#else
+ aGenericName += getpid();
+#endif
+ aGenericName += "_";
+ aGenericName += meshDS->ShapeToIndex( theShape );
+
+ TCollection_AsciiString aFacesFileName, aPointsFileName, aResultFileName;
+ TCollection_AsciiString aBadResFileName, aBbResFileName, aLogFileName;
+ aFacesFileName = aGenericName + ".faces"; // in faces
+ aPointsFileName = aGenericName + ".points"; // in points
+ aResultFileName = aGenericName + ".noboite";// out points and volumes
+ aBadResFileName = aGenericName + ".boite"; // out bad result
+ aBbResFileName = aGenericName + ".bb"; // out vertex stepsize
+ aLogFileName = aGenericName + ".log"; // log
+
+ // -----------------
+ // make input files
+ // -----------------
+
+ 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 ") << aTmpDir.ToCString());
+
+ vector <const SMDS_MeshNode*> aNodeByGhs3dId;
+
+ Ok = (writeFaces ( aFacesFile, meshDS, aNodeByGhs3dId ) &&
+ writePoints( aPointsFile, meshDS, aNodeByGhs3dId));
+
+ aFacesFile.close();
+ aPointsFile.close();
+
+ if ( ! Ok ) {
+ if ( !getenv("GHS3D_KEEP_FILES") ) {
+ OSD_File( aFacesFileName ).Remove();
+ OSD_File( aPointsFileName ).Remove();
+ }
+ return error(COMPERR_BAD_INPUT_MESH);
+ }
+
+ // -----------------
+ // run ghs3d mesher WIN32???
+ // -----------------
+
+ // ghs3d need to know amount of memory it may use (MB).
+ // Default memory is defined at ghs3d installation but it may be not enough,
+ // so allow to use about all available memory
+ TCollection_AsciiString memory;
+#ifdef WIN32
+ // ????
+#else
+ struct sysinfo si;
+ int err = sysinfo( &si );
+ if ( !err ) {
+ int freeMem = si.totalram * si.mem_unit / 1024 / 1024;
+ memory = "-m ";
+ memory += int( 0.7 * freeMem );
+ }
+#endif
+
+ TCollection_AsciiString cmd( "ghs3d " ); // command to run
+ cmd +=
+ memory + // memory
+ " -f " + aGenericName + // file to read
+ " 1>" + aLogFileName; // dump into file
+
+
+
+ system( cmd.ToCString() ); // run
+
+ // --------------
+ // read a result
+ // --------------
+ int fileOpen;
+ fileOpen = open( aResultFileName.ToCString(), O_RDONLY);
+ if ( fileOpen < 0 ) {
+ cout << endl;
+ cout << "Error when opening the " << aResultFileName.ToCString() << " file" << endl;
+ cout << endl;
+ Ok = false;
+ }
+ else {
+ Ok = readResultFile( fileOpen, meshDS, theShape ,aNodeByGhs3dId );
+ }
+