From 89215601f2cfee8ee29bdf192d7347991556b206 Mon Sep 17 00:00:00 2001 From: eap Date: Thu, 17 Apr 2008 08:01:58 +0000 Subject: [PATCH] create GHS3D_Parameters hypothesis --- idl/GHS3DPlugin_Algorithm.idl | 40 ++ resources/GHS3DPlugin.xml | 13 +- resources/Makefile.am | 4 +- resources/mesh_hypo_ghs3d.png | Bin 0 -> 616 bytes resources/mesh_tree_hypo_ghs3d.png | Bin 0 -> 278 bytes src/GHS3DPlugin_Defs.hxx | 37 ++ src/GHS3DPlugin_GHS3D.cxx | 216 +++------- src/GHS3DPlugin_GHS3D.hxx | 20 +- src/GHS3DPlugin_Hypothesis.cxx | 413 +++++++++++++++++++ src/GHS3DPlugin_Hypothesis.hxx | 112 +++++ src/GHS3DPlugin_Hypothesis_i.cxx | 213 ++++++++++ src/GHS3DPlugin_Hypothesis_i.hxx | 92 +++++ src/GHS3DPlugin_i.cxx | 6 +- src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx | 336 +++++++++++++++ src/GUI/GHS3DPluginGUI_HypothesisCreator.h | 99 +++++ src/GUI/GHS3DPlugin_images.po | 47 +++ src/GUI/GHS3DPlugin_msg_en.po | 85 ++++ src/GUI/Makefile.am | 63 +++ src/Makefile.am | 31 +- 19 files changed, 1635 insertions(+), 192 deletions(-) create mode 100644 resources/mesh_hypo_ghs3d.png create mode 100644 resources/mesh_tree_hypo_ghs3d.png create mode 100644 src/GHS3DPlugin_Defs.hxx create mode 100644 src/GHS3DPlugin_Hypothesis.cxx create mode 100644 src/GHS3DPlugin_Hypothesis.hxx create mode 100644 src/GHS3DPlugin_Hypothesis_i.cxx create mode 100644 src/GHS3DPlugin_Hypothesis_i.hxx create mode 100644 src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx create mode 100644 src/GUI/GHS3DPluginGUI_HypothesisCreator.h create mode 100644 src/GUI/GHS3DPlugin_images.po create mode 100755 src/GUI/GHS3DPlugin_msg_en.po create mode 100644 src/GUI/Makefile.am diff --git a/idl/GHS3DPlugin_Algorithm.idl b/idl/GHS3DPlugin_Algorithm.idl index f698e9f..ec7b0a0 100644 --- a/idl/GHS3DPlugin_Algorithm.idl +++ b/idl/GHS3DPlugin_Algorithm.idl @@ -26,6 +26,7 @@ #ifndef _GHS3D_Algorithm_IDL_ #define _GHS3D_Algorithm_IDL_ +#include "SALOME_Exception.idl" #include "SMESH_Hypothesis.idl" /*! @@ -40,6 +41,45 @@ module GHS3DPlugin { }; + /*! + * Parameters of "Tetrahedron (GHS3D)" algorithm + */ + interface GHS3DPlugin_Hypothesis : SMESH::SMESH_Hypothesis + { + /*! + * To mesh "holes" in a solid or not. Default is to mesh. + */ + void SetToMeshHoles(in boolean toMesh); + boolean GetToMeshHoles(); + /*! + * Maximal size of memory to be used by the algorithm (in Megabytes). + * Negative value means not to use this option + */ + void SetMaximumMemory(in short MB); + short GetMaximumMemory(); + /*! + * Initial size of memory to be used by the algorithm (in Megabytes) in + * automatic memory adjustment mode. Default is zero. + * Negative value means not to use this option + */ + void SetInitialMemory(in short MB); + short GetInitialMemory(); + /*! + * Optimization level: 0-none, 1-light, 2-medium, 3-strong. Default is medium + */ + void SetOptimizationLevel(in short level) raises (SALOME::SALOME_Exception); + short GetOptimizationLevel(); + /*! + * Path to working directory + */ + void SetWorkingDirectory(in string path) raises (SALOME::SALOME_Exception); + string GetWorkingDirectory(); + /*! + * To keep working files or remove them. Log file remains in case of errors anyway. + */ + void SetKeepFiles(in boolean toKeep); + boolean GetKeepFiles(); + }; }; #endif diff --git a/resources/GHS3DPlugin.xml b/resources/GHS3DPlugin.xml index 16ea42c..37876f4 100644 --- a/resources/GHS3DPlugin.xml +++ b/resources/GHS3DPlugin.xml @@ -7,14 +7,21 @@ + server-lib="GHS3DEngine" + gui-lib="GHS3DPluginGUI"> + + + diff --git a/resources/Makefile.am b/resources/Makefile.am index 82f19e6..f990b2c 100644 --- a/resources/Makefile.am +++ b/resources/Makefile.am @@ -28,4 +28,6 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am dist_salomeres_DATA = \ - GHS3DPlugin.xml + GHS3DPlugin.xml \ + mesh_hypo_ghs3d.png \ + mesh_tree_hypo_ghs3d.png diff --git a/resources/mesh_hypo_ghs3d.png b/resources/mesh_hypo_ghs3d.png new file mode 100644 index 0000000000000000000000000000000000000000..3fb67d507bc568b7a406c497e52e76a68b61262b GIT binary patch literal 616 zcmV-u0+;=XP)gk0*WI5 zYK&P=DhHv(ok~os#Qtm3x^86>yemH)59hsgylw%-5w$PvREIIfYF)Q-`fH7We5-B-}HkHZ%;m1IbZ_q{%pYlPG9F?n-(n>+z0&(EC&>c_wn@oZe_JbH65Rw zS9n*crw5Y(iX$o#pYX0S_t~=-@pm}yX>vn~;)vESZJs|7=D9u}E-L)$PGAMbK??wt za*0y8^e9MDc4CVqgi{EoO8^Rwc}@pa)+^iv9qxiIrfIC)J^UX_pJp>T<@kMCfK_W$ zb7gI-I<%g2zv*ZY>djVZ`}|7mE4psdQ$ z-6Y5-Q9-heuUp3sl~+H>~rToA)Pq!JRcbY~o};nfq4fXC4-u RA_a6VgQu&X%Q~loCIDO& hyps = GetUsedHypothesis(aMesh, aShape); + if ( !hyps.empty() ) + _hyp = static_cast ( hyps.front() ); + if ( _hyp ) + _keepFiles = _hyp->GetKeepFiles(); + return true; } @@ -503,7 +515,8 @@ static bool readResultFile(const int fileOpen, int nbTriangle; int ID, shapeID, ghs3dShapeID; int IdShapeRef = 1; - int compoundID = theMeshDS->ShapeToIndex( theMeshDS->ShapeToMesh() ); + int compoundID = + nbShape ? theMeshDS->ShapeToIndex( tabShape[0] ) : theMeshDS->ShapeToIndex( theMeshDS->ShapeToMesh() ); int *tab, *tabID, *nodeID, *nodeAssigne; double *coord; @@ -592,9 +605,9 @@ static bool readResultFile(const int fileOpen, theMeshDS->SetNodeInVolume( node[i], shapeID ); } theMeshDS->SetMeshElementOnShape( aTet, shapeID ); - if ( (iElem + 1) == nbElems ) - cout << nbElems << " tetrahedrons have been associated to " << nbShape << " shapes" << endl; } + if ( nbElems ) + cout << nbElems << " tetrahedrons have been associated to " << nbShape << " shapes" << endl; munmap(mapPtr, length); close(fileOpen); @@ -705,34 +718,6 @@ static bool readResultFile(const int fileOpen, return true; } -//======================================================================= -//function : getTmpDir -//purpose : -//======================================================================= - -static TCollection_AsciiString getTmpDir() -{ - TCollection_AsciiString aTmpDir; - - char *Tmp_dir = getenv("SALOME_TMP_DIR"); - if(Tmp_dir != NULL) { - aTmpDir = Tmp_dir; -#ifdef WIN32 - if(aTmpDir.Value(aTmpDir.Length()) != '\\') aTmpDir+='\\'; -#else - if(aTmpDir.Value(aTmpDir.Length()) != '/') aTmpDir+='/'; -#endif - } - else { -#ifdef WIN32 - aTmpDir = TCollection_AsciiString("C:\\"); -#else - aTmpDir = TCollection_AsciiString("/tmp/"); -#endif - } - return aTmpDir; -} - //================================================================================ /*! * \brief Look for a line containing a text in a file @@ -800,21 +785,10 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, iShape++; } - cout << endl; - cout << "Ghs3d execution..." << endl; - - // make a unique working file name + // 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 aGenericName + = (char*) GHS3DPlugin_Hypothesis::GetFileName(_hyp).c_str(); TCollection_AsciiString aFacesFileName, aPointsFileName, aResultFileName; TCollection_AsciiString aBadResFileName, aBbResFileName, aLogFileName; @@ -839,8 +813,8 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open(); #endif if (!Ok) { - INFOS( "Can't write into " << aTmpDir.ToCString()); - return error(SMESH_Comment("Can't write into ") << aTmpDir); + INFOS( "Can't write into " << aFacesFileName); + return error(SMESH_Comment("Can't write into ") << aFacesFileName); } map aSmdsToGhs3dIdMap; map aGhs3dIdToNodeMap; @@ -852,7 +826,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, aPointsFile.close(); if ( ! Ok ) { - if ( !getenv("GHS3D_KEEP_FILES") ) { + if ( !_keepFiles ) { OSD_File( aFacesFileName ).Remove(); OSD_File( aPointsFileName ).Remove(); } @@ -860,30 +834,16 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, } // ----------------- - // run ghs3d mesher WIN32??? + // run ghs3d mesher // ----------------- - // 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; -#ifndef WIN32 - struct sysinfo si; - int err = sysinfo( &si ); - if ( err == 0 ) { - int freeMem = si.totalram * si.mem_unit / 1024 / 1024; - memory = "-m "; - memory += int( 0.7 * freeMem ); - } -#endif + TCollection_AsciiString cmd( (char*)GHS3DPlugin_Hypothesis::CommandToRun( _hyp ).c_str() ); + cmd += TCollection_AsciiString(" -f ") + aGenericName; // file to read + cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file - MESSAGE("GHS3DPlugin_GHS3D::Compute"); - TCollection_AsciiString cmd( "ghs3d " ); // command to run - cmd += - memory + // memory - " -c0 -f " + aGenericName + // file to read - " 1>" + aLogFileName; // dump into file + cout << endl; + cout << "Ghs3d execution..." << endl; + cout << cmd << endl; system( cmd.ToCString() ); // run @@ -912,7 +872,8 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, if ( Ok ) { - OSD_File( aLogFileName ).Remove(); + if ( !_keepFiles ) + OSD_File( aLogFileName ).Remove(); } else if ( OSD_File( aLogFileName ).Size() > 0 ) { @@ -927,12 +888,13 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, foundLine.LeftAdjust(); comment << foundLine; } - if ( findLineContaing( "%% ERROR",aLogFileName,foundLine)) + if ( findLineContaing( "%% ERROR",aLogFileName,foundLine) || + findLineContaing( " ERR ",aLogFileName,foundLine)) { foundLine.LeftAdjust(); comment << foundLine; } - if ( findLineContaing( "%% NO SAVING OPERATION",aLogFileName,foundLine)) + else if ( findLineContaing( "%% NO SAVING OPERATION",aLogFileName,foundLine)) { comment << "Too many elements generated for a trial version.\n"; } @@ -950,7 +912,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, error(COMPERR_ALGO_FAILED, "ghs3d: command not found" ); } - if ( !getenv("GHS3D_KEEP_FILES") ) { + if ( !_keepFiles ) { OSD_File( aFacesFileName ).Remove(); OSD_File( aPointsFileName ).Remove(); OSD_File( aResultFileName ).Remove(); @@ -983,18 +945,10 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, SMESHDS_Mesh* meshDS = theMesh.GetMeshDS(); TopoDS_Shape theShape = aHelper->GetSubShape(); - // make a unique working file name + // 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 aGenericName + = (char*) GHS3DPlugin_Hypothesis::GetFileName(_hyp).c_str(); TCollection_AsciiString aFacesFileName, aPointsFileName, aResultFileName; TCollection_AsciiString aBadResFileName, aBbResFileName, aLogFileName; @@ -1019,7 +973,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, #endif if (!Ok) - return error( SMESH_Comment("Can't write into ") << aTmpDir.ToCString()); + return error( SMESH_Comment("Can't write into ") << aPointsFileName); vector aNodeByGhs3dId; @@ -1030,7 +984,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, aPointsFile.close(); if ( ! Ok ) { - if ( !getenv("GHS3D_KEEP_FILES") ) { + if ( !_keepFiles ) { OSD_File( aFacesFileName ).Remove(); OSD_File( aPointsFileName ).Remove(); } @@ -1038,32 +992,12 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, } // ----------------- - // run ghs3d mesher WIN32??? + // run ghs3d mesher // ----------------- - // 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 - - + TCollection_AsciiString cmd( (char*)GHS3DPlugin_Hypothesis::CommandToRun( _hyp ).c_str() ); + cmd += TCollection_AsciiString(" -f ") + aGenericName; // file to read + cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file system( cmd.ToCString() ); // run @@ -1088,7 +1022,8 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, if ( Ok ) { - OSD_File( aLogFileName ).Remove(); + if ( !_keepFiles ) + OSD_File( aLogFileName ).Remove(); } else if ( OSD_File( aLogFileName ).Size() > 0 ) { @@ -1103,12 +1038,13 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, foundLine.LeftAdjust(); comment << foundLine; } - if ( findLineContaing( "%% ERROR",aLogFileName,foundLine)) + if ( findLineContaing( "%% ERROR",aLogFileName,foundLine) || + findLineContaing( " ERR ",aLogFileName,foundLine)) { foundLine.LeftAdjust(); comment << foundLine; } - if ( findLineContaing( "%% NO SAVING OPERATION",aLogFileName,foundLine)) + else if ( findLineContaing( "%% NO SAVING OPERATION",aLogFileName,foundLine)) { comment << "Too many elements generated for a trial version.\n"; } @@ -1125,7 +1061,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, error(COMPERR_ALGO_FAILED, "ghs3d: command not found" ); } - if ( !getenv("GHS3D_KEEP_FILES") ) + if ( !_keepFiles ) { OSD_File( aFacesFileName ).Remove(); OSD_File( aPointsFileName ).Remove(); @@ -1136,47 +1072,3 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, return Ok; } - -//============================================================================= -/*! - * - */ -//============================================================================= - -ostream & GHS3DPlugin_GHS3D::SaveTo(ostream & save) -{ - return save; -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -istream & GHS3DPlugin_GHS3D::LoadFrom(istream & load) -{ - return load; -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -ostream & operator << (ostream & save, GHS3DPlugin_GHS3D & hyp) -{ - return hyp.SaveTo( save ); -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -istream & operator >> (istream & load, GHS3DPlugin_GHS3D & hyp) -{ - return hyp.LoadFrom( load ); -} diff --git a/src/GHS3DPlugin_GHS3D.hxx b/src/GHS3DPlugin_GHS3D.hxx index 05a3e10..082fbbf 100644 --- a/src/GHS3DPlugin_GHS3D.hxx +++ b/src/GHS3DPlugin_GHS3D.hxx @@ -30,6 +30,7 @@ #include "SMESH_3D_Algo.hxx" class SMESH_Mesh; +class GHS3DPlugin_Hypothesis; class GHS3DPlugin_GHS3D: public SMESH_3D_Algo { @@ -37,24 +38,21 @@ public: GHS3DPlugin_GHS3D(int hypId, int studyId, SMESH_Gen* gen); virtual ~GHS3DPlugin_GHS3D(); - virtual bool CheckHypothesis(SMESH_Mesh& aMesh, - const TopoDS_Shape& aShape, - SMESH_Hypothesis::Hypothesis_Status& aStatus); + virtual bool CheckHypothesis(SMESH_Mesh& aMesh, + const TopoDS_Shape& aShape, + Hypothesis_Status& aStatus); virtual bool Compute(SMESH_Mesh& aMesh, - const TopoDS_Shape& aShape); + const TopoDS_Shape& aShape); virtual bool Compute(SMESH_Mesh& theMesh, SMESH_MesherHelper* aHelper); - ostream & SaveTo(ostream & save); - istream & LoadFrom(istream & load); - friend ostream & operator << (ostream & save, GHS3DPlugin_GHS3D & hyp); - friend istream & operator >> (istream & load, GHS3DPlugin_GHS3D & hyp); - private: - int _iShape; - int _nbShape; + int _iShape; + int _nbShape; + bool _keepFiles; + const GHS3DPlugin_Hypothesis* _hyp; }; #endif diff --git a/src/GHS3DPlugin_Hypothesis.cxx b/src/GHS3DPlugin_Hypothesis.cxx new file mode 100644 index 0000000..69e2302 --- /dev/null +++ b/src/GHS3DPlugin_Hypothesis.cxx @@ -0,0 +1,413 @@ +// Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +//============================================================================= +// File : GHS3DPlugin_Hypothesis.cxx +// Created : Wed Apr 2 12:36:29 2008 +// Author : Edward AGAPOV (eap) +//============================================================================= + + +#include "GHS3DPlugin_Hypothesis.hxx" + +#include + +//======================================================================= +//function : GHS3DPlugin_Hypothesis +//======================================================================= + +GHS3DPlugin_Hypothesis::GHS3DPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen) + : SMESH_Hypothesis(hypId, studyId, gen) +{ + _name = "GHS3D_Parameters"; + _param_algo_dim = 3; + + myToMeshHoles = DefaultMeshHoles(); + myMaximumMemory = -1;//DefaultMaximumMemory(); + myInitialMemory = -1;//DefaultInitialMemory(); + myOptimizationLevel = DefaultOptimizationLevel(); + myWorkingDirectory = DefaultWorkingDirectory(); + myKeepFiles = DefaultKeepFiles(); +} + +//======================================================================= +//function : SetToMeshHoles +//======================================================================= + +void GHS3DPlugin_Hypothesis::SetToMeshHoles(bool toMesh) +{ + if ( myToMeshHoles != toMesh ) { + myToMeshHoles = toMesh; + NotifySubMeshesHypothesisModification(); + } +} + +//======================================================================= +//function : GetToMeshHoles +//======================================================================= + +bool GHS3DPlugin_Hypothesis::GetToMeshHoles() const +{ + return myToMeshHoles; +} + +//======================================================================= +//function : SetMaximumMemory +//======================================================================= + +void GHS3DPlugin_Hypothesis::SetMaximumMemory(short MB) +{ + if ( myMaximumMemory != MB ) { + myMaximumMemory = MB; + NotifySubMeshesHypothesisModification(); + } +} + +//======================================================================= +//function : GetMaximumMemory +// * automatic memory adjustment mode. Default is zero +//======================================================================= + +short GHS3DPlugin_Hypothesis::GetMaximumMemory() const +{ + return myMaximumMemory; +} + +//======================================================================= +//function : SetInitialMemory +//======================================================================= + +void GHS3DPlugin_Hypothesis::SetInitialMemory(short MB) +{ + if ( myInitialMemory != MB ) { + myInitialMemory = MB; + NotifySubMeshesHypothesisModification(); + } +} + +//======================================================================= +//function : GetInitialMemory +//======================================================================= + +short GHS3DPlugin_Hypothesis::GetInitialMemory() const +{ + return myInitialMemory; +} + +//======================================================================= +//function : SetOptimizationLevel +//======================================================================= + +void GHS3DPlugin_Hypothesis::SetOptimizationLevel(OptimizationLevel level) +{ + if ( myOptimizationLevel != level ) { + myOptimizationLevel = level; + NotifySubMeshesHypothesisModification(); + } +} + +//======================================================================= +//function : GetOptimizationLevel +//======================================================================= + +GHS3DPlugin_Hypothesis::OptimizationLevel GHS3DPlugin_Hypothesis::GetOptimizationLevel() const +{ + return (OptimizationLevel) myOptimizationLevel; +} + +//======================================================================= +//function : SetWorkingDirectory +//======================================================================= + +void GHS3DPlugin_Hypothesis::SetWorkingDirectory(string path) +{ + if ( myWorkingDirectory != path ) { + myWorkingDirectory = path; + NotifySubMeshesHypothesisModification(); + } +} + +//======================================================================= +//function : GetWorkingDirectory +//======================================================================= + +string GHS3DPlugin_Hypothesis::GetWorkingDirectory() const +{ + return myWorkingDirectory; +} + +//======================================================================= +//function : SetKeepFiles +//======================================================================= + +void GHS3DPlugin_Hypothesis::SetKeepFiles(bool toKeep) +{ + if ( myKeepFiles != toKeep ) { + myKeepFiles = toKeep; + NotifySubMeshesHypothesisModification(); + } +} + +//======================================================================= +//function : GetKeepFiles +//======================================================================= + +bool GHS3DPlugin_Hypothesis::GetKeepFiles() const +{ + return myKeepFiles; +} + +//======================================================================= +//function : DefaultMeshHoles +//======================================================================= + +bool GHS3DPlugin_Hypothesis::DefaultMeshHoles() +{ + return true; +} + +//======================================================================= +//function : DefaultMaximumMemory +//======================================================================= + +#ifndef WIN32 +#include +#endif + +short GHS3DPlugin_Hypothesis::DefaultMaximumMemory() +{ +#ifndef WIN32 + struct sysinfo si; + int err = sysinfo( &si ); + if ( err == 0 ) { + int ramMB = si.totalram * si.mem_unit / 1024 / 1024; + return (short) ( 0.7 * ramMB ); + } +#endif + return -1; +} + +//======================================================================= +//function : DefaultInitialMemory +//======================================================================= + +short GHS3DPlugin_Hypothesis::DefaultInitialMemory() +{ + return DefaultMaximumMemory(); +} + +//======================================================================= +//function : DefaultOptimizationLevel +//======================================================================= + +short GHS3DPlugin_Hypothesis::DefaultOptimizationLevel() +{ + return Medium; +} + +//======================================================================= +//function : DefaultWorkingDirectory +//======================================================================= + +string GHS3DPlugin_Hypothesis::DefaultWorkingDirectory() +{ + TCollection_AsciiString aTmpDir; + + char *Tmp_dir = getenv("SALOME_TMP_DIR"); + if(Tmp_dir != NULL) { + aTmpDir = Tmp_dir; + } + else { +#ifdef WIN32 + aTmpDir = TCollection_AsciiString("C:\\"); +#else + aTmpDir = TCollection_AsciiString("/tmp/"); +#endif + } + return aTmpDir.ToCString(); +} + +//======================================================================= +//function : DefaultKeepFiles +//======================================================================= + +bool GHS3DPlugin_Hypothesis::DefaultKeepFiles() +{ + return false; +} + +//======================================================================= +//function : SaveTo +//======================================================================= + +ostream & GHS3DPlugin_Hypothesis::SaveTo(ostream & save) +{ + save << (int) myToMeshHoles << " "; + save << myMaximumMemory << " "; + save << myInitialMemory << " "; + save << myOptimizationLevel << " "; + save << myWorkingDirectory << " "; + save << (int)myKeepFiles << " "; + return save; +} + +//======================================================================= +//function : LoadFrom +//======================================================================= + +istream & GHS3DPlugin_Hypothesis::LoadFrom(istream & load) +{ + bool isOK = true; + int i; + + isOK = (load >> i); + if (isOK) + myToMeshHoles = i; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = (load >> i); + if (isOK) + myMaximumMemory = i; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = (load >> i); + if (isOK) + myInitialMemory = i; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = (load >> i); + if (isOK) + myOptimizationLevel = i; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = (load >> myWorkingDirectory); + if (isOK) { + if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty + myKeepFiles = false; + myWorkingDirectory.clear(); + return load; + } + else if ( myWorkingDirectory == "1" ) { + myKeepFiles = true; + myWorkingDirectory.clear(); + return load; + } + } + else + load.clear(ios::badbit | load.rdstate()); + + isOK = (load >> i); + if (isOK) + myKeepFiles = i; + else + load.clear(ios::badbit | load.rdstate()); + + return load; +} + +//======================================================================= +//function : SetParametersByMesh +//======================================================================= + +bool GHS3DPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* ,const TopoDS_Shape&) +{ + return false; +} + +//================================================================================ +/*! + * \brief Return command to run ghs3d mesher excluding file prefix (-f) + */ +//================================================================================ + +string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* hyp) +{ +#ifndef WIN32 + TCollection_AsciiString cmd( "ghs3d" ); +#else + TCollection_AsciiString cmd( "ghs3d.exe" ); +#endif + + // ghs3d needs 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 + short aMaximumMemory = hyp ? hyp->myMaximumMemory : -1; + cmd += " -m "; + if ( aMaximumMemory < 0 ) + cmd += DefaultMaximumMemory(); + else + cmd += aMaximumMemory; + short aInitialMemory = hyp ? hyp->myInitialMemory : -1; + cmd += " -M "; + if ( aInitialMemory > 0 ) + cmd += aInitialMemory; + else + cmd += "100"; + + // component to mesh + // 0 , all components to be meshed + // 1 , only the main ( outermost ) component to be meshed + bool aToMeshHoles = hyp ? hyp->myToMeshHoles : DefaultMeshHoles(); + if ( aToMeshHoles ) + cmd += " -c 0"; + else + cmd += " -c 1"; + + // optimization level + short aOptimizationLevel = hyp ? hyp->myOptimizationLevel : DefaultOptimizationLevel(); + if ( aOptimizationLevel >= 0 && aOptimizationLevel < 4 ) { + char* level[] = { "none" , "light" , "standard" , "strong" }; + cmd += " -o "; + cmd += level[ aOptimizationLevel ]; + } + + return cmd.ToCString(); +} + +//================================================================================ +/*! + * \brief Return a unique file name + */ +//================================================================================ + +string GHS3DPlugin_Hypothesis::GetFileName(const GHS3DPlugin_Hypothesis* hyp) +{ + string aTmpDir = hyp ? hyp->GetWorkingDirectory() : DefaultWorkingDirectory(); + const char lastChar = *aTmpDir.rbegin(); +#ifdef WIN32 + if(lastChar != '\\') aTmpDir+='\\'; +#else + if(lastChar != '/') aTmpDir+='/'; +#endif + + TCollection_AsciiString aGenericName = (char*)aTmpDir.c_str(); + aGenericName += "GHS3D_"; +#ifdef WIN32 + aGenericName += GetCurrentProcessId(); +#else + aGenericName += getpid(); +#endif + aGenericName += "_"; + aGenericName += Abs((Standard_Integer) & aGenericName); + + return aGenericName.ToCString(); +} diff --git a/src/GHS3DPlugin_Hypothesis.hxx b/src/GHS3DPlugin_Hypothesis.hxx new file mode 100644 index 0000000..2bba333 --- /dev/null +++ b/src/GHS3DPlugin_Hypothesis.hxx @@ -0,0 +1,112 @@ +// GHS3DPlugin : C++ implementation +// +// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +// File : GHS3DPlugin_Hypothesis.hxx +// Created : Wed Apr 2 12:21:17 2008 +// Author : Edward AGAPOV (eap) + +#ifndef GHS3DPlugin_Hypothesis_HeaderFile +#define GHS3DPlugin_Hypothesis_HeaderFile + +#include "GHS3DPlugin_Defs.hxx" + +#include + +using namespace std; + +class GHS3DPLUGIN_EXPORT GHS3DPlugin_Hypothesis: public SMESH_Hypothesis +{ +public: + + GHS3DPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen); + + /*! + * To mesh "holes" in a solid or not. Default is to mesh. + */ + void SetToMeshHoles(bool toMesh); + bool GetToMeshHoles() const; + /*! + * Maximal size of memory to be used by the algorithm (in Megabytes) + */ + void SetMaximumMemory(short MB); + short GetMaximumMemory() const; + /*! + * Initial size of memory to be used by the algorithm (in Megabytes) in + * automatic memory adjustment mode. Default is zero + */ + void SetInitialMemory(short MB); + short GetInitialMemory() const; + /*! + * Optimization level: 0-none, 1-light, 2-medium, 3-strong. Default is medium + */ + enum OptimizationLevel { None = 0, Light, Medium, Strong }; + void SetOptimizationLevel(OptimizationLevel level); + OptimizationLevel GetOptimizationLevel() const; + /*! + * Path to working directory + */ + void SetWorkingDirectory(string path); + string GetWorkingDirectory() const; + /*! + * To keep working files or remove them. Log file remains in case of errors anyway. + */ + void SetKeepFiles(bool toKeep); + bool GetKeepFiles() const; + + static bool DefaultMeshHoles(); + static short DefaultMaximumMemory(); + static short DefaultInitialMemory(); + static short DefaultOptimizationLevel(); + static string DefaultWorkingDirectory(); + static bool DefaultKeepFiles(); + + /*! + * \brief Return command to run ghs3d mesher excluding file prefix (-f) + */ + static std::string CommandToRun(const GHS3DPlugin_Hypothesis* hyp); + /*! + * \brief Return a unique file name + */ + static std::string GetFileName(const GHS3DPlugin_Hypothesis* hyp); + + // Persistence + virtual ostream & SaveTo(ostream & save); + virtual istream & LoadFrom(istream & load); + friend GHS3DPLUGIN_EXPORT ostream & operator <<(ostream & save, GHS3DPlugin_Hypothesis & hyp); + friend GHS3DPLUGIN_EXPORT istream & operator >>(istream & load, GHS3DPlugin_Hypothesis & hyp); + + /*! + * \brief Does nothing + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - always false + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + +private: + + bool myToMeshHoles; + short myMaximumMemory; + short myInitialMemory; + short myOptimizationLevel; + std::string myWorkingDirectory; + bool myKeepFiles; +}; + + +#endif diff --git a/src/GHS3DPlugin_Hypothesis_i.cxx b/src/GHS3DPlugin_Hypothesis_i.cxx new file mode 100644 index 0000000..7d805ca --- /dev/null +++ b/src/GHS3DPlugin_Hypothesis_i.cxx @@ -0,0 +1,213 @@ +// File : GHS3DPlugin_Hypothesis_i.cxx +// Created : Wed Apr 2 13:53:01 2008 +// Author : Edward AGAPOV (eap) + + +#include "GHS3DPlugin_Hypothesis_i.hxx" + +#include +#include + +#include +#include +#include + +//======================================================================= +//function : GHS3DPlugin_Hypothesis_i +//======================================================================= + +GHS3DPlugin_Hypothesis_i::GHS3DPlugin_Hypothesis_i (PortableServer::POA_ptr thePOA, + int theStudyId, + ::SMESH_Gen* theGenImpl) + : SALOME::GenericObj_i( thePOA ), + SMESH_Hypothesis_i( thePOA ) +{ + MESSAGE( "GHS3DPlugin_Hypothesis_i::GHS3DPlugin_Hypothesis_i" ); + myBaseImpl = new ::GHS3DPlugin_Hypothesis (theGenImpl->GetANewId(), + theStudyId, + theGenImpl); +} + +//======================================================================= +//function : ~GHS3DPlugin_Hypothesis_i +//======================================================================= + +GHS3DPlugin_Hypothesis_i::~GHS3DPlugin_Hypothesis_i() +{ + MESSAGE( "GHS3DPlugin_Hypothesis_i::~GHS3DPlugin_Hypothesis_i" ); +} + +//======================================================================= +//function : SetToMeshHoles +//======================================================================= + +void GHS3DPlugin_Hypothesis_i::SetToMeshHoles(CORBA::Boolean toMesh) +{ + ASSERT(myBaseImpl); + this->GetImpl()->SetToMeshHoles(toMesh); + SMESH::TPythonDump() << _this() << ".SetToMeshHoles( " << toMesh << " )"; +} + +//======================================================================= +//function : GetToMeshHoles +//======================================================================= + +CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetToMeshHoles() +{ + ASSERT(myBaseImpl); + return this->GetImpl()->GetToMeshHoles(); +} + +//======================================================================= +//function : SetMaximumMemory +//======================================================================= + +void GHS3DPlugin_Hypothesis_i::SetMaximumMemory(CORBA::Short MB) +{ + ASSERT(myBaseImpl); + this->GetImpl()->SetMaximumMemory(MB); + SMESH::TPythonDump() << _this() << ".SetMaximumMemory( " << MB << " )"; +} + +//======================================================================= +//function : GetMaximumMemory +//======================================================================= + +CORBA::Short GHS3DPlugin_Hypothesis_i::GetMaximumMemory() +{ + ASSERT(myBaseImpl); + return this->GetImpl()->GetMaximumMemory(); +} + +//======================================================================= +//function : SetInitialMemory +//======================================================================= + +void GHS3DPlugin_Hypothesis_i::SetInitialMemory(CORBA::Short MB) +{ + ASSERT(myBaseImpl); + this->GetImpl()->SetInitialMemory(MB); + SMESH::TPythonDump() << _this() << ".SetInitialMemory( " << MB << " )"; +} + +//======================================================================= +//function : GetInitialMemory +//======================================================================= + +CORBA::Short GHS3DPlugin_Hypothesis_i::GetInitialMemory() +{ + ASSERT(myBaseImpl); + return this->GetImpl()->GetInitialMemory(); +} + +//======================================================================= +//function : SetOptimizationLevel +//======================================================================= + +void GHS3DPlugin_Hypothesis_i::SetOptimizationLevel(CORBA::Short level) + throw ( SALOME::SALOME_Exception ) +{ + ::GHS3DPlugin_Hypothesis::OptimizationLevel l = + (::GHS3DPlugin_Hypothesis::OptimizationLevel) level; + if ( l < ::GHS3DPlugin_Hypothesis::None || + l > ::GHS3DPlugin_Hypothesis::Strong ) + THROW_SALOME_CORBA_EXCEPTION( "Invalid optimization level",SALOME::BAD_PARAM ); + + ASSERT(myBaseImpl); + this->GetImpl()->SetOptimizationLevel(l); + SMESH::TPythonDump() << _this() << ".SetOptimizationLevel( " << level << " )"; +} + +//======================================================================= +//function : GetOptimizationLevel +//======================================================================= + +CORBA::Short GHS3DPlugin_Hypothesis_i::GetOptimizationLevel() +{ + ASSERT(myBaseImpl); + return this->GetImpl()->GetOptimizationLevel(); +} + +//======================================================================= +//function : SetWorkingDirectory +//======================================================================= + +void GHS3DPlugin_Hypothesis_i::SetWorkingDirectory(const char* path) throw ( SALOME::SALOME_Exception ) +{ + if (!path ) + THROW_SALOME_CORBA_EXCEPTION( "Null working directory",SALOME::BAD_PARAM ); + + string file(path); + const char lastChar = *file.rbegin(); +#ifdef WIN32 + if ( lastChar != '\\' ) file += '\\'; +#else + if ( lastChar != '/' ) file += '/'; +#endif + file += "GHS3D.log"; + SMESH_Mesh_i::PrepareForWriting (file.c_str()); + + ASSERT(myBaseImpl); + this->GetImpl()->SetWorkingDirectory(path); + SMESH::TPythonDump() << _this() << ".SetWorkingDirectory( '" << path << "' )"; +} + +//======================================================================= +//function : GetWorkingDirectory +//======================================================================= + +char* GHS3DPlugin_Hypothesis_i::GetWorkingDirectory() +{ + ASSERT(myBaseImpl); + return CORBA::string_dup( this->GetImpl()->GetWorkingDirectory().c_str() ); +} + +//======================================================================= +//function : SetKeepFiles +//======================================================================= + +void GHS3DPlugin_Hypothesis_i::SetKeepFiles(CORBA::Boolean toKeep) +{ + ASSERT(myBaseImpl); + this->GetImpl()->SetKeepFiles(toKeep); + SMESH::TPythonDump() << _this() << ".SetKeepFiles( " << toKeep << " )"; +} + +//======================================================================= +//function : GetKeepFiles +//======================================================================= + +CORBA::Boolean GHS3DPlugin_Hypothesis_i::GetKeepFiles() +{ + ASSERT(myBaseImpl); + return this->GetImpl()->GetKeepFiles(); +} + +//============================================================================= +/*! + * GHS3DPlugin_Hypothesis_i::GetImpl + * + * Get implementation + */ +//============================================================================= + +::GHS3DPlugin_Hypothesis* GHS3DPlugin_Hypothesis_i::GetImpl() +{ + return (::GHS3DPlugin_Hypothesis*)myBaseImpl; +} + +//================================================================================ +/*! + * \brief Verify whether hypothesis supports given entity type + * \param type - dimension (see SMESH::Dimension enumeration) + * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise + * + * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration) + */ +//================================================================================ + +CORBA::Boolean GHS3DPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type ) +{ + return type == SMESH::DIM_3D; +} + diff --git a/src/GHS3DPlugin_Hypothesis_i.hxx b/src/GHS3DPlugin_Hypothesis_i.hxx new file mode 100644 index 0000000..97dc574 --- /dev/null +++ b/src/GHS3DPlugin_Hypothesis_i.hxx @@ -0,0 +1,92 @@ +// GHS3DPlugin : C++ implementation +// +// Copyright (C) 2006 OPEN CASCADE, CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// File : GHS3DPlugin_Hypothesis_i.hxx +// Date : 03/04/2006 +// Project : SALOME + +#ifndef _GHS3DPlugin_Hypothesis_i_HXX_ +#define _GHS3DPlugin_Hypothesis_i_HXX_ + +#include "GHS3DPlugin_Defs.hxx" + +#include +#include CORBA_SERVER_HEADER(GHS3DPlugin_Algorithm) + +#include "SMESH_Hypothesis_i.hxx" +#include "GHS3DPlugin_Hypothesis.hxx" + +class SMESH_Gen; + +// GHS3DPlugin parameters hypothesis + +class GHS3DPLUGIN_EXPORT GHS3DPlugin_Hypothesis_i: + public virtual POA_GHS3DPlugin::GHS3DPlugin_Hypothesis, + public virtual SMESH_Hypothesis_i +{ + public: + // Constructor + GHS3DPlugin_Hypothesis_i (PortableServer::POA_ptr thePOA, + int theStudyId, + ::SMESH_Gen* theGenImpl); + // Destructor + virtual ~GHS3DPlugin_Hypothesis_i(); + + /*! + * To mesh "holes" in a solid or not. Default is to mesh. + */ + void SetToMeshHoles(CORBA::Boolean toMesh); + CORBA::Boolean GetToMeshHoles(); + /*! + * Maximal size of memory to be used by the algorithm (in Megabytes) + */ + void SetMaximumMemory(CORBA::Short MB); + CORBA::Short GetMaximumMemory(); + /*! + * Initial size of memory to be used by the algorithm (in Megabytes) in + * automatic memory adjustment mode. Default is zero + */ + void SetInitialMemory(CORBA::Short MB); + CORBA::Short GetInitialMemory(); + /*! + * Optimization level: 0-none, 1-light, 2-medium, 3-strong. Default is medium + */ + void SetOptimizationLevel(CORBA::Short level) throw ( SALOME::SALOME_Exception ); + CORBA::Short GetOptimizationLevel(); + /*! + * Path to working directory + */ + void SetWorkingDirectory(const char* path) throw ( SALOME::SALOME_Exception ); + char* GetWorkingDirectory(); + /*! + * To keep working files or remove them. Log file remains in case of errors anyway. + */ + void SetKeepFiles(CORBA::Boolean toKeep); + CORBA::Boolean GetKeepFiles(); + + // Get implementation + ::GHS3DPlugin_Hypothesis* GetImpl(); + + // Verify whether hypothesis supports given entity type + CORBA::Boolean IsDimSupported( SMESH::Dimension type ); +}; + +#endif diff --git a/src/GHS3DPlugin_i.cxx b/src/GHS3DPlugin_i.cxx index 1622f60..ff53dba 100644 --- a/src/GHS3DPlugin_i.cxx +++ b/src/GHS3DPlugin_i.cxx @@ -32,6 +32,7 @@ using namespace std; #include "utilities.h" #include "GHS3DPlugin_GHS3D_i.hxx" +#include "GHS3DPlugin_Hypothesis_i.hxx" template class GHS3DPlugin_Creator_i:public HypothesisCreator_i { @@ -55,9 +56,12 @@ extern "C" // Hypotheses - // Algorithms + // Algorithm if (strcmp(aHypName, "GHS3D_3D") == 0) aCreator = new GHS3DPlugin_Creator_i; + // Hypothesis + else if (strcmp(aHypName, "GHS3D_Parameters") == 0) + aCreator = new GHS3DPlugin_Creator_i; else ; return aCreator; diff --git a/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx new file mode 100644 index 0000000..5e84952 --- /dev/null +++ b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx @@ -0,0 +1,336 @@ +// GHS3DPlugin GUI: GUI for plugged-in mesher GHS3DPlugin +// +// Copyright (C) 2003 CEA +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : GHS3DPluginGUI_HypothesisCreator.cxx +// Author : Michael Zorin +// Module : GHS3DPlugin +// $Header: + +#include "GHS3DPluginGUI_HypothesisCreator.h" + +#include +#include + +#include CORBA_SERVER_HEADER(GHS3DPlugin_Algorithm) + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include + +enum { + STD_TAB = 0, + ADV_TAB +}; + +namespace { + +#ifndef WIN32 +#include +#endif + + int maxAvailableMemory() + { +#ifndef WIN32 + struct sysinfo si; + int err = sysinfo( &si ); + if ( err == 0 ) { + int totMB = + si.totalram * si.mem_unit / 1024 / 1024 + + si.totalswap * si.mem_unit / 1024 / 1024 ; + return (int) ( 0.7 * totMB ); + } +#endif + return 100000; + } +} + +GHS3DPluginGUI_HypothesisCreator::GHS3DPluginGUI_HypothesisCreator( const QString& theHypType ) +: SMESHGUI_GenericHypothesisCreator( theHypType ) +{ +} + +GHS3DPluginGUI_HypothesisCreator::~GHS3DPluginGUI_HypothesisCreator() +{ +} + +QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame() +{ + QFrame* fr = new QFrame( 0, "myframe" ); + QVBoxLayout* lay = new QVBoxLayout( fr, 5, 0 ); + + // tab + QTabBar* tab = new QTabBar( fr, "QTabBar"); + tab->setShape( QTabBar::RoundedAbove ); + tab->insertTab( new QTab( tr( "SMESH_ARGUMENTS")), STD_TAB); + tab->insertTab( new QTab( tr( "GHS3D_ADV_ARGS")), ADV_TAB); + lay->addWidget( tab ); + + // basic parameters + myStdGroup = new QGroupBox( 2, Qt::Horizontal, fr, "myStdGroup" ); + myStdGroup->layout()->setSpacing( 6 ); + myStdGroup->layout()->setMargin( 11 ); + lay->addWidget( myStdGroup ); + + myName = 0; + if( isCreation() ) + { + new QLabel( tr( "SMESH_NAME" ), myStdGroup ); + myName = new QLineEdit( myStdGroup ); + } + + myToMeshHolesCheck = new QCheckBox( tr( "GHS3D_TO_MESH_HOLES" ), myStdGroup ); + myStdGroup->addSpace(0); + + new QLabel( tr( "GHS3D_OPTIMIZATIOL_LEVEL" ), myStdGroup ); + myOptimizationLevelCombo = new QtxComboBox( myStdGroup ); + QStringList types; + types.append( QObject::tr( "LEVEL_NONE" ) ); + types.append( QObject::tr( "LEVEL_LIGHT" ) ); + types.append( QObject::tr( "LEVEL_MEDIUM" ) ); + types.append( QObject::tr( "LEVEL_STRONG" ) ); + myOptimizationLevelCombo->insertStringList( types ); + + // advanced parameters + myAdvGroup = new QGroupBox( 3, Qt::Horizontal, fr, "myAdvGroup" ); + lay->addWidget( myAdvGroup ); + + myMaximumMemoryCheck = new QCheckBox( tr("MAX_MEMORY_SIZE"), myAdvGroup ); + + myMaximumMemorySpin = new QSpinBox( myAdvGroup ); + myMaximumMemorySpin->setMinValue( 20 ); + myMaximumMemorySpin->setMaxValue( maxAvailableMemory() ); + myMaximumMemorySpin->setLineStep( 10 ); + new QLabel( tr("MEGABYTE"), myAdvGroup); + + myInitialMemoryCheck = new QCheckBox( tr("INIT_MEMORY_SIZE"), myAdvGroup ); + + myInitialMemorySpin = new QSpinBox( myAdvGroup ); + myInitialMemorySpin->setMinValue( 20 ); + myInitialMemorySpin->setMaxValue( maxAvailableMemory() ); + myInitialMemorySpin->setLineStep( 10 ); + new QLabel( tr("MEGABYTE"), myAdvGroup); + + new QLabel( tr( "WORKING_DIR" ), myAdvGroup ); + QPushButton* dirBtn = new QPushButton( tr( "SELECT_DIR"), myAdvGroup, "dirBtn"); + myWorkingDir = new QLineEdit( myAdvGroup, "myWorkingDir"); + myWorkingDir->setReadOnly( true ); + + myKeepFiles = new QCheckBox( tr( "KEEP_WORKING_FILES" ), myAdvGroup ); + + connect( tab, SIGNAL( selected(int) ), this, SLOT( onTabSelected(int) ) ); + connect( myMaximumMemoryCheck, SIGNAL( toggled(bool) ), this, SLOT( onMemCheckToggled(bool) )); + connect( myInitialMemoryCheck, SIGNAL( toggled(bool) ), this, SLOT( onMemCheckToggled(bool) )); + connect( dirBtn, SIGNAL( clicked() ), this, SLOT( onDirBtnClicked() ) ); + + return fr; +} + +void GHS3DPluginGUI_HypothesisCreator::onTabSelected(int tab) +{ + if ( tab == STD_TAB ) { + myAdvGroup->hide(); + myStdGroup->show(); + } + else { + myStdGroup->hide(); + myAdvGroup->show(); + } +// qApp->processEvents(); + dlg()->adjustSize(); +} + +void GHS3DPluginGUI_HypothesisCreator::onMemCheckToggled(bool on) +{ + if ( sender() == myMaximumMemoryCheck ) + myMaximumMemorySpin->setEnabled( on ); + else + myInitialMemorySpin->setEnabled( on ); +} + +void GHS3DPluginGUI_HypothesisCreator::onDirBtnClicked() +{ + QString dir = SUIT_FileDlg::getExistingDirectory(dlg(),QString::null, QString::null ); + if ( dir ) + myWorkingDir->setText( dir ); +} + + +bool GHS3DPluginGUI_HypothesisCreator::checkParams() const +{ + if ( !QFileInfo( myWorkingDir->text() ).isWritable() ) { + SUIT_MessageBox::warn1(dlg(), + QObject::tr("SMESH_WRN_WARNING"), + QObject::tr("GHS3D_PERMISSION_DENIED"), + QObject::tr("SMESH_BUT_OK")); + return false; + } + return true; +} + +void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const +{ + GHS3DHypothesisData data; + readParamsFromHypo( data ); + + if( myName ) + myName->setText( data.myName ); + + myToMeshHolesCheck ->setChecked ( data.myToMeshHoles ); + myOptimizationLevelCombo->setCurrentItem( data.myOptimizationLevel ); + myMaximumMemoryCheck ->setChecked ( data.myMaximumMemory > 0 ); + myMaximumMemorySpin ->setValue ( std::max( data.myMaximumMemory, myMaximumMemorySpin->minValue() )); + myInitialMemoryCheck ->setChecked ( data.myInitialMemory > 0 ); + myInitialMemorySpin ->setValue ( std::max( data.myInitialMemory, myInitialMemorySpin->minValue() )); + myWorkingDir ->setText ( data.myWorkingDir ); + myKeepFiles ->setChecked ( data.myKeepFiles ); + + myMaximumMemorySpin->setEnabled( myMaximumMemoryCheck->isChecked() ); + myInitialMemorySpin->setEnabled( myInitialMemoryCheck->isChecked() ); +} + +QString GHS3DPluginGUI_HypothesisCreator::storeParams() const +{ + GHS3DHypothesisData data; + readParamsFromWidgets( data ); + storeParamsToHypo( data ); + + QString valStr = " -c " + QString::number( !data.myToMeshHoles ); + if ( data.myOptimizationLevel >= 0 && data.myOptimizationLevel < 4 ) { + char* level[] = { "none" , "light" , "standard" , "strong" }; + valStr += " -o "; + valStr += level[ data.myOptimizationLevel ]; + } + + return valStr; +} + +bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& h_data ) const +{ + GHS3DPlugin::GHS3DPlugin_Hypothesis_var h = + GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( initParamsHypothesis() ); + + HypothesisData* data = SMESH::GetHypothesisData( hypType() ); + h_data.myName = isCreation() && data ? hypName() : ""; + + h_data.myToMeshHoles = h->GetToMeshHoles(); + h_data.myMaximumMemory = h->GetMaximumMemory(); + h_data.myInitialMemory = h->GetInitialMemory(); + h_data.myInitialMemory = h->GetInitialMemory(); + h_data.myOptimizationLevel = h->GetOptimizationLevel(); + h_data.myKeepFiles = h->GetKeepFiles(); + h_data.myWorkingDir = h->GetWorkingDirectory(); + + return true; +} + +bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisData& h_data ) const +{ + GHS3DPlugin::GHS3DPlugin_Hypothesis_var h = + GHS3DPlugin::GHS3DPlugin_Hypothesis::_narrow( hypothesis() ); + + bool ok = true; + try + { + if( isCreation() ) + SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.latin1() ); + + h->SetToMeshHoles ( h_data.myToMeshHoles ); + h->SetMaximumMemory ( h_data.myMaximumMemory ); + h->SetInitialMemory ( h_data.myInitialMemory ); + h->SetInitialMemory ( h_data.myInitialMemory ); + h->SetOptimizationLevel( h_data.myOptimizationLevel ); + h->SetKeepFiles ( h_data.myKeepFiles ); + h->SetWorkingDirectory ( h_data.myWorkingDir ); + } + catch(const SALOME::SALOME_Exception& ex) + { + SalomeApp_Tools::QtCatchCorbaException(ex); + ok = false; + } + return ok; +} + +bool GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DHypothesisData& h_data ) const +{ + h_data.myName = myName ? myName->text() : ""; + h_data.myToMeshHoles = myToMeshHolesCheck->isChecked(); + h_data.myMaximumMemory = myMaximumMemoryCheck->isChecked() ? myMaximumMemorySpin->value() : -1; + h_data.myInitialMemory = myInitialMemoryCheck->isChecked() ? myInitialMemorySpin->value() : -1; + h_data.myOptimizationLevel = myOptimizationLevelCombo->currentItem(); + h_data.myKeepFiles = myKeepFiles->isChecked(); + h_data.myWorkingDir = myWorkingDir->text(); + + return true; +} + +QString GHS3DPluginGUI_HypothesisCreator::caption() const +{ + return tr( "GHS3D_TITLE" ); +} + +QPixmap GHS3DPluginGUI_HypothesisCreator::icon() const +{ + QString hypIconName = tr( QString("ICON_DLG_GHS3D_PARAMETERS" )); + return SUIT_Session::session()->resourceMgr()->loadPixmap( "GHS3DPlugin", hypIconName ); +} + +QString GHS3DPluginGUI_HypothesisCreator::type() const +{ + return tr( "GHS3D_HYPOTHESIS" ); +} + +QString GHS3DPluginGUI_HypothesisCreator::helpPage() const +{ + return "ghs3d_hypo_page.html"; +} + +//============================================================================= +/*! GetHypothesisCreator + * + */ +//============================================================================= +extern "C" +{ + GHS3DPLUGIN_EXPORT + SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator( const QString& aHypType ) + { + if( aHypType=="GHS3D_Parameters" ) + return new GHS3DPluginGUI_HypothesisCreator( aHypType ); + return 0; + } +} diff --git a/src/GUI/GHS3DPluginGUI_HypothesisCreator.h b/src/GUI/GHS3DPluginGUI_HypothesisCreator.h new file mode 100644 index 0000000..ca3e508 --- /dev/null +++ b/src/GUI/GHS3DPluginGUI_HypothesisCreator.h @@ -0,0 +1,99 @@ +// GHS3DPlugin GUI: GUI for plugged-in mesher GHS3DPlugin +// +// Copyright (C) 2003 CEA +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : GHS3DPluginGUI_HypothesisCreator.h +// Author : Michael Zorin +// Module : GHS3DPlugin + +#ifndef GHS3DPLUGINGUI_HypothesisCreator_HeaderFile +#define GHS3DPLUGINGUI_HypothesisCreator_HeaderFile + +#include "../GHS3DPlugin_Defs.hxx" +#include + +class QtxComboBox; +class QCheckBox; +class QLineEdit; +class QSpinBox; + +typedef struct +{ + bool myToMeshHoles; + int myMaximumMemory; + int myInitialMemory; + int myOptimizationLevel; + bool myKeepFiles; + QString myWorkingDir; + QString myName; +} GHS3DHypothesisData; + +/*! + * \brief Class for creation of GHS3D2D and GHS3D3D hypotheses +*/ +class GHS3DPLUGIN_EXPORT GHS3DPluginGUI_HypothesisCreator : public SMESHGUI_GenericHypothesisCreator +{ + Q_OBJECT + +public: + GHS3DPluginGUI_HypothesisCreator( const QString& ); + virtual ~GHS3DPluginGUI_HypothesisCreator(); + + virtual bool checkParams() const; + virtual QString helpPage() const; + +protected: + virtual QFrame* buildFrame (); + virtual void retrieveParams() const; + virtual QString storeParams () const; + + virtual QString caption() const; + virtual QPixmap icon() const; + virtual QString type() const; + +protected slots: + + void onTabSelected(int); + void onMemCheckToggled(bool); + void onDirBtnClicked(); + +private: + bool readParamsFromHypo( GHS3DHypothesisData& ) const; + bool readParamsFromWidgets( GHS3DHypothesisData& ) const; + bool storeParamsToHypo( const GHS3DHypothesisData& ) const; + +private: + + QGroupBox* myStdGroup; + QLineEdit* myName; + QCheckBox* myToMeshHolesCheck; + QtxComboBox* myOptimizationLevelCombo; + + QGroupBox* myAdvGroup; + QCheckBox* myMaximumMemoryCheck; + QSpinBox* myMaximumMemorySpin; + QCheckBox* myInitialMemoryCheck; + QSpinBox* myInitialMemorySpin; + QLineEdit* myWorkingDir; + QCheckBox* myKeepFiles; +}; + +#endif diff --git a/src/GUI/GHS3DPlugin_images.po b/src/GUI/GHS3DPlugin_images.po new file mode 100644 index 0000000..6a78382 --- /dev/null +++ b/src/GUI/GHS3DPlugin_images.po @@ -0,0 +1,47 @@ +# Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# This is a Qt message file in .po format. Each msgid starts with +# a scope. This scope should *NOT* be translated - eg. "Foo::Bar" +# would be translated to "Pub", not "Foo::Pub". +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"POT-Creation-Date: 2002-05-28 10:57:43 AM CEST\n" +"PO-Revision-Date: 2004-03-30 17:24+0400\n" +"Last-Translator: FULLNAME \n" +"Content-Type: text/plain; charset=iso-8859-1\n" + + +#----------------------------------------------------------- +# ObjectBrowser +#----------------------------------------------------------- + +msgid "ICON_SMESH_TREE_ALGO_GHS3D_3D" +msgstr "mesh_tree_hypo_ghs3d.png" + +msgid "ICON_SMESH_TREE_HYPO_GHS3D_Parameters" +msgstr "mesh_tree_hypo_ghs3d.png" + +#----------------------------------------------------------- +# Hypothesis +#----------------------------------------------------------- + +msgid "ICON_DLG_GHS3D_PARAMETERS" +msgstr "mesh_hypo_ghs3d.png" + diff --git a/src/GUI/GHS3DPlugin_msg_en.po b/src/GUI/GHS3DPlugin_msg_en.po new file mode 100755 index 0000000..b5b1d39 --- /dev/null +++ b/src/GUI/GHS3DPlugin_msg_en.po @@ -0,0 +1,85 @@ +# Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS, L3S, LJLL, MENSI +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# This is a Qt message file in .po format. Each msgid starts with +# a scope. This scope should *NOT* be translated - eg. "Foo::Bar" +# would be translated to "Pub", not "Foo::Pub". +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"POT-Creation-Date: 2002-05-28 10:46:48 AM CEST\n" +"PO-Revision-Date: YYYY-MM-DD\n" +"Last-Translator: FULLNAME \n" +"Content-Type: text/plain; charset=iso-8859-1\n" + + +msgid "GHS3D_STD_ARGS" +msgstr "Parameters" + +msgid "GHS3D_ADV_ARGS" +msgstr "Advanced" + +msgid "GHS3D_TO_MESH_HOLES" +msgstr "To mesh holes" + +msgid "GHS3D_OPTIMIZATIOL_LEVEL" +msgstr "Optimization level" + +msgid "LEVEL_NONE" +msgstr "None" + +msgid "LEVEL_LIGHT" +msgstr "Light" + +msgid "LEVEL_MEDIUM" +msgstr "Medium (standard)" + +msgid "LEVEL_STRONG" +msgstr "Strong" + +msgid "MAX_MEMORY_SIZE" +msgstr "Maximum memory size" + +msgid "INIT_MEMORY_SIZE" +msgstr "Initial memory size" + +msgid "MEGABYTE" +msgstr "Megabytes" + +msgid "WORKING_DIR" +msgstr "Working directory" + +msgid "GHS3D_PERMISSION_DENIED" +msgstr "Working directory is not writable" + +msgid "SELECT_DIR" +msgstr "..." + +msgid "KEEP_WORKING_FILES" +msgstr "To keep working files" + +msgid "" +msgstr "" + + +msgid "GHS3D_HYPOTHESIS" +msgstr "GHS3D" + +msgid "GHS3D_TITLE" +msgstr "Hypothesis Construction" diff --git a/src/GUI/Makefile.am b/src/GUI/Makefile.am new file mode 100644 index 0000000..5928a7c --- /dev/null +++ b/src/GUI/Makefile.am @@ -0,0 +1,63 @@ +# Copyright (C) 2005 CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# -* Makefile *- +# +# Author : Edward AGAPOV (OCC) +# Modified by : Alexander BORODIN (OCN) - autotools usage +# Module : GHS3DPLUGIN +# Date : 10/01/2004 +# +# + +include $(top_srcdir)/adm_local/unix/make_common_starter.am + +# header files +salomeinclude_HEADERS = + +# Libraries targets +lib_LTLIBRARIES = libGHS3DPluginGUI.la + +dist_libGHS3DPluginGUI_la_SOURCES = GHS3DPluginGUI_HypothesisCreator.cxx + +MOC_FILES = GHS3DPluginGUI_HypothesisCreator_moc.cxx +nodist_libGHS3DPluginGUI_la_SOURCES= $(MOC_FILES) + +libGHS3DPluginGUI_la_CPPFLAGS = \ + $(QT_INCLUDES) \ + $(KERNEL_CXXFLAGS) \ + $(GUI_CXXFLAGS) \ + $(GEOM_CXXFLAGS) \ + $(MED_CXXFLAGS) \ + $(SMESH_CXXFLAGS) \ + $(BOOST_CPPFLAGS) \ + $(CORBA_CXXFLAGS) \ + $(CORBA_INCLUDES) \ + $(CAS_CPPFLAGS) \ + -I$(top_builddir)/idl \ + -I$(top_builddir)/salome_adm/unix + +libGHS3DPluginGUI_la_LDFLAGS = \ + ../../idl/libSalomeIDLGHS3DPLUGIN.la \ + $(SMESH_LDFLAGS) -lSMESH \ + $(CAS_KERNEL) + +# resources files +nodist_salomeres_DATA= \ + GHS3DPlugin_images.qm \ + GHS3DPlugin_msg_en.qm diff --git a/src/Makefile.am b/src/Makefile.am index e7f6fea..043971b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -27,6 +27,10 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am +if GHS3DPLUGIN_ENABLE_GUI + SUBDIRS = GUI +endif + # header files salomeinclude_HEADERS = @@ -36,24 +40,23 @@ lib_LTLIBRARIES = libGHS3DEngine.la dist_libGHS3DEngine_la_SOURCES = \ GHS3DPlugin_GHS3D.cxx \ GHS3DPlugin_GHS3D_i.cxx \ - GHS3DPlugin_i.cxx + GHS3DPlugin_i.cxx \ + GHS3DPlugin_Hypothesis.cxx \ + GHS3DPlugin_Hypothesis_i.cxx -libGHS3DEngine_la_CPPFLAGS = \ - $(KERNEL_CXXFLAGS) \ - $(GUI_CXXFLAGS) \ - $(GEOM_CXXFLAGS) \ - $(SMESH_CXXFLAGS) \ - $(BOOST_CPPFLAGS) \ - $(CORBA_CXXFLAGS) \ - $(CORBA_INCLUDES) \ - $(CAS_CPPFLAGS) \ +libGHS3DEngine_la_CPPFLAGS = \ + $(KERNEL_CXXFLAGS) \ + $(GEOM_CXXFLAGS) \ + $(MED_CXXFLAGS) \ + $(SMESH_CXXFLAGS) \ + $(BOOST_CPPFLAGS) \ + $(CORBA_CXXFLAGS) \ + $(CORBA_INCLUDES) \ + $(CAS_CPPFLAGS) \ -I$(top_builddir)/idl \ -I$(top_builddir)/salome_adm/unix libGHS3DEngine_la_LDFLAGS = \ ../idl/libSalomeIDLGHS3DPLUGIN.la \ - $(SMESH_LDFLAGS) -lSMESHimpl -lSMESHEngine \ + $(SMESH_LDFLAGS) -lSMESHimpl -lSMESHEngine $(KERNEL_LDFLAGS) -lSalomeGenericObj - -# resources files -nodist_salomeres_DATA = GHS3DPlugin_icons.qm -- 2.39.2