Salome HOME
This commit was generated by cvs2git to create branch 'V4_1_0_maintainance'.
authoradmin <salome-admin@opencascade.com>
Thu, 21 Feb 2008 11:31:17 +0000 (11:31 +0000)
committeradmin <salome-admin@opencascade.com>
Thu, 21 Feb 2008 11:31:17 +0000 (11:31 +0000)
Sprout from VENDOR 2008-01-22 14:16:27 UTC secher <secher> 'add test on filter module'
Cherrypick from master 2008-02-21 11:31:12 UTC maintenance team <salome-mnt@opencascade.com> 'Porting to CAS-6.2.sp1':
    adm_local/unix/config_files/check_filtoo.m4
    adm_local/unix/make_commence.in
    adm_local/unix/make_omniorb.in
    build_configure
    configure.in.base
    doc/salome/doxyfile
    doc/salome/filter.dox
    doc/salome/images/img1.jpg
    doc/salome/images/img2.jpg
    doc/salome/images/img3.jpg
    idl/FILTER_Gen.idl
    resources/xx.aa.med
    src/FILTER/Filter_Gen_i.cxx
    src/FILTER/Filter_Gen_i.hxx
    src/FILTER/Makefile.in
    src/FILTER/field2nodes.cxx
    src/FILTER/test_filter.py
    src/FILTERGUI/FILTERGUI_Utils.cxx
    src/FILTERGUI/FILTERGUI_Utils.h
    src/FILTERGUI/FILTER_msg_en.po
    src/FILTERGUI/FilterGUI.cxx
    src/FILTERGUI/FilterGUI.h
    src/FILTERGUI/Makefile.in
    src/FILTERGUI/SelectField.cxx
    src/FILTERGUI/SelectField.h
    src/FILTERGUI/SelectParams.cxx
    src/FILTERGUI/SelectParams.h

21 files changed:
adm_local/unix/config_files/check_filtoo.m4 [new file with mode: 0644]
adm_local/unix/make_commence.in
adm_local/unix/make_omniorb.in
build_configure
configure.in.base
idl/FILTER_Gen.idl
src/FILTER/Filter_Gen_i.cxx
src/FILTER/Filter_Gen_i.hxx
src/FILTER/Makefile.in
src/FILTER/field2nodes.cxx [new file with mode: 0644]
src/FILTER/test_filter.py
src/FILTERGUI/FILTERGUI_Utils.cxx [new file with mode: 0644]
src/FILTERGUI/FILTERGUI_Utils.h [new file with mode: 0644]
src/FILTERGUI/FILTER_msg_en.po
src/FILTERGUI/FilterGUI.cxx
src/FILTERGUI/FilterGUI.h
src/FILTERGUI/Makefile.in
src/FILTERGUI/SelectField.cxx
src/FILTERGUI/SelectField.h
src/FILTERGUI/SelectParams.cxx
src/FILTERGUI/SelectParams.h

diff --git a/adm_local/unix/config_files/check_filtoo.m4 b/adm_local/unix/config_files/check_filtoo.m4
new file mode 100644 (file)
index 0000000..a312f0b
--- /dev/null
@@ -0,0 +1,27 @@
+AC_DEFUN([CHECK_FILTOO],[
+
+filtoo_ok=no
+
+AC_CHECK_PROG(FILTOO, filtoo,yes,no)
+
+if test "x$FILTOO" == xno ; then
+  AC_MSG_WARN(filtoo program not found in PATH variable)
+else
+  AC_CHECK_PROG(FILGHS3D, filghs3d,yes,no)
+
+  if test "x$FILGHS3D" == xno ; then
+    AC_MSG_WARN(filghs3d program not found in PATH variable)
+  else
+    AC_CHECK_PROG(FILYAMS, filyams,yes,no)
+
+    if test "x$FILYAMS" == xno ; then
+      AC_MSG_WARN(filyams program not found in PATH variable)
+    else
+      filtoo_ok=yes
+   fi
+ fi
+fi
+
+AC_MSG_RESULT(for filtoo: $filtoo_ok)
+
+])dnl
index 43dfcdd8ddb00628af1d1438266222ab45ffa6e6..95af6a6502ad9720124e2d1b42f1234925dc54ab 100644 (file)
@@ -152,7 +152,7 @@ OMNIORB_CXXFLAGS    = @OMNIORB_CXXFLAGS@
 
 OMNIORB_IDL         = @OMNIORB_IDL@
 OMNIORB_IDLCXXFLAGS = @OMNIORB_IDLCXXFLAGS@
-OMNIORB_IDLPYFLAGS  = @OMNIORB_IDLPYFLAGS@ -I$(top_srcdir)/idl -I$(top_builddir)/salome/idl -I$(KERNEL_ROOT_DIR)/idl/salome
+OMNIORB_IDLPYFLAGS  = @OMNIORB_IDLPYFLAGS@ -I$(top_srcdir)/idl -I$(top_builddir)/idl -I$(KERNEL_ROOT_DIR)/idl/salome
 
 OMNIORB_IDL_CLN_H   = @OMNIORB_IDL_CLN_H@
 OMNIORB_IDL_CLN_CXX = @OMNIORB_IDL_CLN_CXX@
@@ -169,7 +169,7 @@ CORBA_INCLUDES    = @CORBA_INCLUDES@
 CORBA_LIBS        = @CORBA_LIBS@
 CORBA_CXXFLAGS    = @CORBA_CXXFLAGS@
 
-IDLCXXFLAGS = -bcxx @IDLCXXFLAGS@ -I$(top_srcdir)/idl -I$(top_builddir)/idl/salome -I$(KERNEL_ROOT_DIR)/idl/salome
+IDLCXXFLAGS = -bcxx @IDLCXXFLAGS@ -I$(top_srcdir)/idl -I$(top_builddir)/idl -I$(KERNEL_ROOT_DIR)/idl/salome -I$(MED_ROOT_DIR)/idl
 IDLPYFLAGS  = @IDLPYFLAGS@
 
 IDL = @IDL@
@@ -182,12 +182,12 @@ IDL_SRV_H   = @IDL_SRV_H@
 IDL_SRV_CXX = @IDL_SRV_CXX@
 IDL_SRV_OBJ = @IDL_SRV_OBJ@
 
-  CPPFLAGS+= $(CORBA_INCLUDES) 
-  CXXFLAGS+= $(CORBA_CXXFLAGS)
+CPPFLAGS+= $(CORBA_INCLUDES) 
+CXXFLAGS+= $(CORBA_CXXFLAGS)
 
-  # add corba libs when link salome application ! 
-  #LDFLAGS+= $(CORBA_LIBS)
-  LIBS+=$(CORBA_LIBS)
+# add corba libs when link salome application ! 
+#LDFLAGS+= $(CORBA_LIBS)
+LIBS+=$(CORBA_LIBS)
 
 DOXYGEN = @DOXYGEN@
 DOXYGEN_WITH_PYTHON = @DOXYGEN_WITH_PYTHON@
@@ -295,19 +295,24 @@ $(top_srcdir)/configure.in: $(top_srcdir)/configure.in.base
 
 
 ACLOCAL_SRC = \
-ac_cxx_bool.m4                    check_corba.m4                        \
-ac_cxx_depend_flag.m4             check_hdf5.m4      enable_pthreads.m4        \
-ac_cxx_mutable.m4                 check_mico.m4      libtool.m4                \
-ac_cxx_namespaces.m4              check_omniorb.m4   pyembed.m4                \
-ac_cxx_partial_specialization.m4  python.m4                             \
-ac_cxx_typename.m4                check_pthreads.m4  check_cas.m4      \
-ac_cc_warnings.m4                 check_swig.m4      check_qt.m4 
+check_corba.m4                  ac_cxx_depend_flag.m4           check_hdf5.m4     \
+enable_pthreads.m4             ac_cxx_namespaces.m4            check_omniorb.m4  \
+pyembed.m4                     python.m4                       check_cas.m4      \
+check_swig.m4
+
+ACLOCAL_SRC_DEPR = \
+ac_cxx_bool.m4                  ac_cxx_mutable.m4      ac_cxx_partial_specialization.m4 \
+check_mico.m4                   libtool.m4             ac_cxx_typename.m4               \
+check_pthreads.m4               ac_cc_warnings.m4
 
 ACLOCAL_GUI = \
-check_vtk.m4                     check_opengl.m4       \
+check_vtk.m4                     check_opengl.m4       check_qt.m4 \
 check_GUI.m4                     check_corba_in_GUI.m4
 
 $(top_srcdir)/aclocal.m4: $(ACLOCAL_SRC:%=@KERNEL_ROOT_DIR@/salome_adm/unix/config_files/%) \
+                          $(ACLOCAL_SRC_DEPR:%=@KERNEL_ROOT_DIR@/salome_adm/unix/config_files/DEPRECATED/%) \
                           $(ACLOCAL_GUI:%=@GUI_ROOT_DIR@/adm_local/unix/config_files/%)
-       cd $(top_srcdir) ; aclocal -I adm_local/unix/config_files -I @KERNEL_ROOT_DIR@/salome_adm/unix/config_files \
-                                                                  -I @GUI_ROOT_DIR@/adm_local/unix/config_files
+       cd $(top_srcdir) ; aclocal -I adm_local/unix/config_files \
+                                   -I @KERNEL_ROOT_DIR@/salome_adm/unix/config_files \
+                                   -I @KERNEL_ROOT_DIR@/salome_adm/unix/config_files/DEPRECATED \
+                                   -I @GUI_ROOT_DIR@/adm_local/unix/config_files
index 84679a9eae2714fb62791581229ae25e6874523d..01055d37fff77ad7136705057c441db84b88d5b5 100644 (file)
@@ -22,6 +22,9 @@
 %$(OMNIORB_IDL_CLN_CXX) %$(OMNIORB_IDL_CLN_H): ${top_srcdir}/idl/%.idl
        $(OMNIORB_IDL) $(IDLCXXFLAGS) $(OMNIORB_IDLCXXFLAGS) $<
 
+%$(OMNIORB_IDL_CLN_CXX) %$(OMNIORB_IDL_CLN_H): ${MED_ROOT_DIR}/idl/salome/%.idl
+       $(OMNIORB_IDL) $(IDLCXXFLAGS) $(OMNIORB_IDLCXXFLAGS) $<
+
 # dependncies between idl files
 depend_idl: .depidl
 
index 212e7d8b0e292dc8c6a5431bd7bcdc906ee73d48..952ce5b6ed6a93ec835098343737f97b6ee889bb 100755 (executable)
@@ -220,9 +220,12 @@ else
        echo -n "Creating 'configure' script ...  "
 fi
 
-aclocal -I adm_local/unix/config_files -I ${KERNEL_ROOT_DIR}/salome_adm/unix/config_files \
-                                       -I ${GUI_ROOT_DIR}/adm_local/unix/config_files \
-                                       -I ${MED_ROOT_DIR}/adm_local/unix/config_files
+aclocal -I adm_local/unix/config_files \
+        -I ${KERNEL_ROOT_DIR}/salome_adm/unix/config_files \
+        -I ${KERNEL_ROOT_DIR}/salome_adm/unix/config_files/DEPRECATED \
+        -I ${GUI_ROOT_DIR}/adm_local/unix/config_files \
+        -I ${MED_ROOT_DIR}/adm_local/unix/config_files
+       
 if autoconf
 then
        echo "done"
index 6d26a43196d7fff6a47de99b58b0fce1d5081bf2..777fec1bbd683f53cdbcfba4f99efc90ff662698 100644 (file)
 #
 
 AC_INIT(src)
-AC_CONFIG_AUX_DIR(${KERNEL_ROOT_DIR}/salome_adm/unix/config_files)
+AC_CONFIG_AUX_DIR(${KERNEL_ROOT_DIR}/salome_adm/unix/config_files/DEPRECATED)
 AC_CANONICAL_HOST
 
 PACKAGE=salome
 AC_SUBST(PACKAGE)
 
-VERSION=3.2.4
-XVERSION=0x030204
+VERSION=4.1.1
+XVERSION=0x040101
 AC_SUBST(VERSION)
 AC_SUBST(XVERSION)
 
@@ -88,7 +88,7 @@ dnl Fix up the INSTALL macro if it s a relative path. We want the
 dnl full-path to the binary instead.
 case "$INSTALL" in
    *install-sh*)
-      INSTALL='\${KERNEL_ROOT_DIR}'/salome_adm/unix/config_files/install-sh
+      INSTALL='\${KERNEL_ROOT_DIR}'/salome_adm/unix/config_files/DEPRECATED/install-sh
       ;;
 esac
 
@@ -130,17 +130,6 @@ dnl
 
 CHECK_MPICH
 
-echo
-echo ---------------------------------------------
-echo testing LEX \& YACC
-echo ---------------------------------------------
-echo
-
-lex_yacc_ok=no
-AC_PROG_YACC
-AC_PROG_LEX
-lex_yacc_ok=yes
-
 echo
 echo ---------------------------------------------
 echo testing python
@@ -149,14 +138,6 @@ echo
 
 CHECK_PYTHON
 
-dnl echo
-dnl echo ---------------------------------------------
-dnl echo testing java
-dnl echo ---------------------------------------------
-dnl echo
-
-dnl CHECK_JAVA
-
 echo
 echo ---------------------------------------------
 echo testing swig
@@ -181,14 +162,6 @@ echo
 
 CHECK_OMNIORB
 
-dnl echo
-dnl echo ---------------------------------------------
-dnl echo testing mico
-dnl echo ---------------------------------------------
-dnl echo
-
-dnl CHECK_MICO
-
 echo
 echo ---------------------------------------------
 echo default ORB : omniORB
@@ -202,14 +175,6 @@ AC_SUBST_FILE(CORBA)
 corba=make_$ORB
 CORBA=adm_local/unix/$corba
 
-echo
-echo ---------------------------------------------
-echo testing openGL
-echo ---------------------------------------------
-echo
-
-CHECK_OPENGL
-
 echo
 echo ---------------------------------------------
 echo testing QT
@@ -318,6 +283,14 @@ echo
 
 CHECK_MED
 
+echo
+echo ---------------------------------------------
+echo Testing filtoo
+echo ---------------------------------------------
+echo
+
+CHECK_FILTOO
+
 echo
 echo ---------------------------------------------
 echo Summary
@@ -325,7 +298,7 @@ echo ---------------------------------------------
 echo
 
 echo Configure
-variables="cc_ok boost_ok lex_yacc_ok python_ok swig_ok threads_ok OpenGL_ok qt_ok vtk_ok hdf5_ok med2_ok omniORB_ok occ_ok qwt_ok doxygen_ok graphviz_ok Kernel_ok Med_ok"
+variables="cc_ok boost_ok python_ok swig_ok threads_ok qt_ok vtk_ok hdf5_ok med2_ok omniORB_ok occ_ok qwt_ok doxygen_ok graphviz_ok Kernel_ok Med_ok filtoo_ok"
 
 for var in $variables
 do
index ea89d2148fd5e677ee08a96446543e4c464b5769..7b43f52943dd7e437f5161bb9f9dd1fb6334e03f 100644 (file)
 
 #include "SALOME_Exception.idl"
 #include "SALOME_Component.idl"
-#include "SALOMEDS.idl"
 
 module SALOME_FILTER
 {
-  interface FILTER_Gen : Engines::Component, SALOMEDS::Driver
-  {
-//     /*!
-//       it returns a Corba pointer %MESH on the mesh stored in the .med file
-//       <VAR>fileName</VAR> with the name <VAR>meshName</VAR>.
-//      */
-//     SALOME_FILTER::MESH readMeshInFile(in string fileName, in string studyName,
-//                                 in string meshName)
-//       raises(SALOME::SALOME_Exception);
+  struct DT_IT {
+    long dt;
+    long it;
+  };
 
-//     /*!
-//       it returns a Corba pointer %FIELD on the field instance with the order
-//       <VAR>ordre</VAR> at the iteration <VAR>iter</VAR>, stored in the .med
-//       file <VAR>fileName</VAR> with the name <VAR>fieldName</VAR>.
-//      */
-//     SALOME_FILTER::FIELD readFieldInFile(in string fileName, in string studyName,
-//                                   in string fieldName, in long ordre,
-//                                   in long iter)
-//       raises (SALOME::SALOME_Exception);
+  enum rfunc {F_FIELD,F_GRAD};
+  typedef rfunc ref_func;
+  typedef sequence<long> LongSeq;
+  typedef sequence<string> StrSeq;
+  typedef sequence<DT_IT> DTITSeq;
 
-//     /*!
-//       it returns a Corba pointer on the %MED object regrouping all objects
-//       (%MESH and %FIELD) stored in the file <VAR>fileName</VAR>. All instances
-//       of the fields are stored without their type.
-//     */
-//     SALOME_FILTER::MED readStructFile(in string fileName,
-//                                in string studyName)
-//       raises (SALOME::SALOME_Exception);
+  interface FILTER_Gen : Engines::Component
+  {
+    exception FilterError{
+      string error_msg;
+    };
 
-//     /*!
-//       It pushes all Corba pointers (%MED, %MESH, %FIELD) in the study named
-//       <VAR>studyName</VAR>. The %MED object regroups all objects
-//       (%MESH and %FIELD) stored in the file <VAR>fileName</VAR> and all
-//       instances of the fields are stored with their own type.
-//     */
-//     void readStructFileWithFieldType(in string fileName,
-//                                  in string studyName)
-//       raises (SALOME::SALOME_Exception);
+    void loadMED(in string inMEDFile);
+    void unloadMED();
+    StrSeq getMeshNames();
+    StrSeq getFieldNames();
+    long getMeshDimension(in string meshName);
+    long getFieldEntity(in string fieldName,in long dt,in long it);
+    boolean fieldIsOnAllElements(in string fieldName,in long dt,in long it);
+    DTITSeq getFieldIteration(in string fieldName);
+    string getMeshName(in string fieldName,in long dt,in long it);
+    void readReferenceField(in string meshName,in string fieldName,in long ts);
+    void buildGradient() raises(FilterError);
+    void getMinMax(out double min,out double max,in ref_func rf);
+    LongSeq getHistogram(in long size,in ref_func rf);
+    void generateCriteria(in long nbthresh,in double fthresh,in double sthresh,in boolean areaFlag,in ref_func rf) raises(FilterError);
+    void createEnsightInputFiles() raises(FilterError);
+    void filtering() raises(FilterError);
+    void projectFieldsOnDecimateMesh() raises(FilterError);
+    void createMedOutputFile(in string outMedFile);
   };
 
 };
index 34be897408e635fb890a3a347c6ed0180765bb40..175af67e05818e4105828ec10c338ecc6cf8700b 100755 (executable)
@@ -33,6 +33,7 @@
 #include "Utils_CorbaException.hxx"
 #include "utilities.h"
 
+#include "MEDMEM_EnsightMeshDriver.hxx"
 #include <string>
 #include <deque>
 #include <map>
 #include <TCollection_AsciiString.hxx>
 #include <TColStd_SequenceOfAsciiString.hxx>
 #include <HDFascii.hxx>
-#include "SALOMEDS_Tool.hxx"
 
 using namespace std;
- Filter_Gen_i* Filter_Gen_i::_FILTERGen = NULL;
+using namespace SALOME_FILTER;
+Filter_Gen_i* Filter_Gen_i::_FILTERGen = NULL;
 
 //=============================================================================
 /*!
@@ -67,7 +68,7 @@ Filter_Gen_i:: Filter_Gen_i(CORBA::ORB_ptr orb,
                                PortableServer::ObjectId * contId,
                                const char *instanceName,
                                const char *interfaceName) :
-  Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
+  Engines_Component_i(orb, poa, contId, instanceName, interfaceName),_med(NULL),_newMed(NULL),_mesh(NULL),_newMesh(NULL),_myGradient(NULL),_myDField(NULL),_myIField(NULL),_criteria(NULL),_map(NULL)
 {
   MESSAGE("activate object");
   _thisObj = this ;
@@ -79,7 +80,6 @@ Filter_Gen_i:: Filter_Gen_i(CORBA::ORB_ptr orb,
   ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
   _NS->init_orb( _orb ) ;
 
-  //_myFilterI = 0;
   _FILTERGen = this;
 }
 
@@ -92,5 +92,603 @@ Filter_Gen_i:: Filter_Gen_i(CORBA::ORB_ptr orb,
 Filter_Gen_i::~Filter_Gen_i()
 {
   MESSAGE("Filter_Gen_i::~Filter_Gen_i");
+
+  // destruction of gradient field
+  if(_myGradient)
+    delete _myGradient;
+
+  // destruction of support of reference field: reference field is destroyed
+  // by destruction of med object
+  if(_myIField)
+    delete _myIField->getSupport();
+  if(_myDField)
+    delete _myDField->getSupport();
+
+ // destruction of criteria: support and field
+  if(_criteria){
+    delete _criteria->getSupport();
+    delete _criteria;
+  }
+
+  if(_map)
+    delete [] _map;
+  if(_med)
+    delete _med;
+  if(_newMed)
+    delete _newMed;
+}
+
+void Filter_Gen_i::loadMED(const char* inMedFile)
+{
+  SCRUTE(inMedFile);
+  _file = inMedFile;
+  _med = new ::MED(MED_DRIVER,_file);
+}
+
+void Filter_Gen_i::unloadMED()
+{
+  MESSAGE("unloadMED called");
+  // destruction of gradient field
+  if(_myGradient){
+    delete _myGradient;
+    _myGradient=NULL;
+  }
+
+  // destruction of support of reference field: reference field is destroyed
+  // by destruction of med object
+  if(_myIField){
+    delete _myIField->getSupport();
+    _myIField=NULL;
+  }
+  if(_myDField){
+    delete _myDField->getSupport();
+    _myDField=NULL;
+  }
+
+ // destruction of criteria: support and field
+  if(_criteria){
+    delete _criteria->getSupport();
+    delete _criteria;
+    _criteria=NULL;
+  }
+
+  if(_med){
+    delete _med;
+    _med=NULL;
+  }
+}
+
+StrSeq* Filter_Gen_i::getMeshNames()
+{
+  StrSeq *seq = new StrSeq();
+  deque<string> deq = _med->getMeshNames();
+  seq->length(deq.size());
+  for(int i=0;i<deq.size();i++)
+    (*seq)[i] = deq[i].c_str();
+  return seq;
+}
+  
+StrSeq * Filter_Gen_i::getFieldNames()
+{
+  StrSeq *seq = new StrSeq();
+  deque<string> deq = _med->getFieldNames();
+  seq->length(deq.size());
+  for(int i=0;i<deq.size();i++)
+     (*seq)[i] = deq[i].c_str();
+  return seq;
+}
+
+CORBA::Long  Filter_Gen_i::getMeshDimension(const char* meshName)
+{
+  return _med->getMesh(meshName)->getMeshDimension();
+}
+
+CORBA::Long  Filter_Gen_i::getFieldEntity(const char* fieldName,CORBA::Long dt,CORBA::Long it)
+{
+  return _med->getField(fieldName,dt,it)->getSupport()->getEntity();
+}
+
+CORBA::Boolean Filter_Gen_i::fieldIsOnAllElements(const char* fieldName,CORBA::Long dt,CORBA::Long it)
+{
+  return _med->getField(fieldName,dt,it)->getSupport()->isOnAllElements();
+}
+
+DTITSeq* Filter_Gen_i::getFieldIteration(const char* fieldName)
+{
+  DTITSeq *seq = new DTITSeq();
+  deque<DT_IT_> deq = _med->getFieldIteration(fieldName);
+  seq->length(deq.size());
+  for(int i=0;i<deq.size();i++){
+    (*seq)[i].dt = deq[i].dt;
+    (*seq)[i].it = deq[i].it;
+  }
+  return seq;
+}
+
+char* Filter_Gen_i::getMeshName(const char* fieldName,CORBA::Long dt,CORBA::Long it)
+{
+  return (char*)(_med->getField(fieldName,dt,it)->getSupport()->getMesh()->getName().c_str());
+}
+
+void Filter_Gen_i::readReferenceField(const char* meshName, const char* fieldName, CORBA::Long ts)
+{
+  // read of input mesh
+  _mesh = _med->getMesh(meshName);
+  _mesh->read();
+  
+  // read of input field
+  deque<DT_IT_> myIteration = _med->getFieldIteration (fieldName);
+  MEDMEM::FIELD_* field = _med->getField(fieldName,myIteration[ts].dt,myIteration[ts].it);
+  if (dynamic_cast<MEDMEM::FIELD<double>*>(field)){
+    _myDField = (MEDMEM::FIELD<double>*)field;
+    _myDField->read();
+    _myIField = NULL;
+  }
+  else{
+    _myIField = (MEDMEM::FIELD<int>*)field;
+    _myIField->read();
+    _myDField = NULL;
+  }
+}
+
+void Filter_Gen_i::buildGradient() throw(SALOME_FILTER::FILTER_Gen::FilterError)
+{
+  if(!_myGradient){
+    FIELD<double> * gradient;
+    try{
+      if(_myDField)
+       gradient = _myDField->buildGradient();
+      else
+       gradient = _myIField->buildGradient();
+      _myGradient = gradient->buildNorm2Field();
+      delete gradient;
+    }
+    catch(MEDEXCEPTION& Mex){
+      MESSAGE("SALOME_Exception: Can't calculate gradient");
+      throw SALOME_FILTER::FILTER_Gen::FilterError("Can't calculate gradient");
+    }
+  }
+}
+
+void Filter_Gen_i::getMinMax(CORBA::Double& imin, CORBA::Double& imax,ref_func rf)
+{
+  double min, max;
+
+  switch(rf){
+  case F_FIELD:
+    if (_myDField)
+      _myDField->getMinMax(min,max);
+    else{
+      int xmin, xmax;
+      _myIField->getMinMax(xmin,xmax);
+      min = (double)xmin;
+      max = (double)xmax;
+    }
+    break;
+  case F_GRAD:
+    _myGradient->getMinMax(min,max);
+    break;
+  }
+  imin = min;
+  imax = max;
+}
+
+LongSeq* Filter_Gen_i::getHistogram(CORBA::Long size,ref_func rf)
+{
+  int mysize = size;
+  vector<int> myh;
+
+  switch(rf){
+  case F_FIELD:
+    if (_myDField)
+      myh = _myDField->getHistogram(mysize);
+    else
+      myh = _myIField->getHistogram(mysize);
+    break;
+  case F_GRAD:
+    myh = _myGradient->getHistogram(mysize);
+    break;
+  }
+
+  LongSeq *seq = new LongSeq();
+  seq->length(myh.size());
+  for(int i=0;i<myh.size();i++)
+    (*seq)[i] = myh[i];
+  return seq;
+}
+
+void Filter_Gen_i::generateCriteria(CORBA::Long nbthresh,CORBA::Double fthresh,CORBA::Double sthresh,CORBA::Boolean areaFlag,ref_func rf) throw(SALOME_FILTER::FILTER_Gen::FilterError)
+{
+  double val, min, max;
+  bool isGVal;
+  MED_EN::medEntityMesh typ;
+
+  try{
+    if(_myDField)
+      typ = _myDField->getSupport()->getEntity();
+    else
+      typ = _myIField->getSupport()->getEntity();
+
+    // create support on nodes
+    SUPPORT *sup = new SUPPORT(_mesh,"Support",MED_NODE);
+
+    // create integer field on nodes
+    _criteria = new FIELD<int>(sup,1);
+
+    _criteria->setName("Criteria");
+
+    // read number of nodes
+    int NumberOf = sup->getNumberOfElements(MED_ALL_ELEMENTS);
+
+    for (int i=1; i<NumberOf+1; i++){
+
+      // if reference field is on elements get reference field on nodes
+      switch(typ){
+      case MED_CELL:
+       throw SALOME_FILTER::FILTER_Gen::FilterError("Filter doesn't run on reference field on cells");
+       break;
+      case MED_FACE:
+       throw SALOME_FILTER::FILTER_Gen::FilterError("Filter doesn't run on reference field on faces");
+       break;
+      case MED_EDGE:
+       throw SALOME_FILTER::FILTER_Gen::FilterError("Filter doesn't run on reference field on edges");
+       break;
+      case MED_NODE:
+       // read reference field value
+       switch(rf){
+       case F_FIELD:
+         if(_myDField)
+           val = _myDField->getValueIJ(i,1);
+         else
+           val = (double)_myIField->getValueIJ(i,1);
+         break;
+       case F_GRAD:
+         val = _myGradient->getValueIJ(i,1);
+         break;
+       }
+       break;
+      case MED_ALL_ENTITIES:
+       throw SALOME_FILTER::FILTER_Gen::FilterError("Filter doesn't run on reference field on all entities");
+       break;
+      }
+
+      // set criteria field value
+      if( nbthresh == 1 ){
+       if( areaFlag )
+         if( val >= fthresh ) isGVal = true;
+         else isGVal = false;
+       else
+         if( val <= fthresh ) isGVal = true;
+         else isGVal = false;
+      }
+      else{
+       min = fthresh;
+       max = sthresh;
+       if(sthresh < fthresh){ 
+         min = sthresh;
+         max = fthresh;
+       }
+       if( areaFlag )
+         if( (val <= min) || (val >= max) ) isGVal = true;
+         else isGVal = false;  
+       else
+         if( (val >= min) && (val <= max) ) isGVal = true;
+         else isGVal = false;  
+      }
+      if( isGVal )
+       _criteria->setValueIJ(i,1,1);
+      else
+       _criteria->setValueIJ(i,1,0);
+    }
+  }
+  catch(SALOME_Exception& ex){
+    throw SALOME_FILTER::FILTER_Gen::FilterError(ex.what());
+  }
+}
+
+void Filter_Gen_i::createEnsightInputFiles() throw(SALOME_FILTER::FILTER_Gen::FilterError)
+{
+  try{
+    // call ensight driver MED to generate input ensight mesh ,
+    // input ensight boundary mesh and input criteria ensight field for filtoo
+    MESSAGE("Create ensight mesh");
+    ENSIGHT_MESH_WRONLY_DRIVER myMeshDriver("/tmp/input.case",_mesh);
+    myMeshDriver.open();
+    myMeshDriver.write();
+    myMeshDriver.close();
+
+    MESSAGE("Create ensight field");
+    ENSIGHT_FIELD_WRONLY_DRIVER<int> myFieldDriver("/tmp/input.case",_criteria);
+    myFieldDriver.open();
+    myFieldDriver.write();
+    myFieldDriver.close();
+  }
+  catch(SALOME_Exception& ex){
+    throw SALOME_FILTER::FILTER_Gen::FilterError(ex.what());
+  }
+}
+
+void Filter_Gen_i::filtering() throw(SALOME_FILTER::FILTER_Gen::FilterError)
+{
+  string command;
+
+  MESSAGE("call filtoo");
+  // send filtoo command
+  command = "cd /tmp;filtoo -s -m 1 -f input -o output > /tmp/filter.log";
+  MESSAGE(command);
+  int status = system(command.c_str());
+  if(status != 0)
+    throw SALOME_FILTER::FILTER_Gen::FilterError("filtoo error");    
+
+  // destroy filtoo input files
+  command = "cd /tmp;rm -f input.*";
+  MESSAGE(command);
+  system(command.c_str());
+}
+
+void Filter_Gen_i::projectFieldsOnDecimateMesh() throw(SALOME_FILTER::FILTER_Gen::FilterError)
+{
+  string command;
+
+  // read of new mesh in ensight file
+  MESH* myMesh = new MESH();
+  ENSIGHT_MESH_RDONLY_DRIVER myEnsightMeshDriver("/tmp/output.case", myMesh) ;
+  myMesh->addDriver(ENSIGHT_DRIVER,"/tmp/output.case","myMesh",MED_EN::MED_LECT);
+  myMesh->read() ;
+
+  // have to call ensight driver MED to generate output MED file from filtoo output
+  _newMed = new ::MED();
+  _newMed->addMesh(myMesh);
+
+  // get new mesh name
+  deque<string> meshesNames = _newMed->getMeshNames();
+  int numberOfMeshes = meshesNames.size();
+  if( numberOfMeshes != 1)
+    throw SALOME_FILTER::FILTER_Gen::FilterError("Unvalid number of meshes in filtoo output");
+
+  // new mesh generated by filtoo
+  _newMesh = _newMed->getMesh(meshesNames[0]);
+
+  // create support on nodes on all new mesh
+  SUPPORT *newSup = new SUPPORT(_newMesh,"Support",MED_NODE);
+
+  // read the id of nodes of output mesh, in input mesh
+  readMapping();
+
+  // read connectivity of new mesh to get neighbour node of created node
+  _connL = _newMesh->getConnectivityLength(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_ALL_ELEMENTS);
+  _conn = _newMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_ALL_ELEMENTS);
+  _connI = _newMesh->getConnectivityIndex(MED_NODAL,MED_CELL);
+
+  // read number of nodes on new mesh
+  int numberOfNodes = newSup->getNumberOfElements(MED_ALL_ELEMENTS);
+  int numberOfComponents;
+
+  deque<string> fieldsNames = _med->getFieldNames();
+  int numberOfFields = fieldsNames.size();
+
+  try{
+
+    // loop on fields
+    for (int i=0; i<numberOfFields; i++){
+
+      // is the input field the reference field?
+      bool isReferenceField= false;
+      if(_myDField){
+       if( strcmp(_myDField->getName().c_str(),fieldsNames[i].c_str()) == 0)
+         isReferenceField = true;
+      }
+      else
+       if( strcmp(_myIField->getName().c_str(),fieldsNames[i].c_str()) == 0)
+         isReferenceField = true;
+
+      deque<DT_IT_> myIteration = _med->getFieldIteration (fieldsNames[i]);
+      string meshName = _med->getField(fieldsNames[i],myIteration[0].dt,myIteration[0].it)->getSupport()->getMesh()->getName();
+
+      // we process only fields on input mesh
+      if( strcmp(meshName.c_str(),_mesh->getName().c_str()) == 0){
+
+       // loop on time steps
+       int numberOfIteration = myIteration.size();
+       for(int j=0;j<numberOfIteration;j++){
+
+         // select input field
+         MEDMEM::FIELD_* field = _med->getField(fieldsNames[i],myIteration[j].dt,myIteration[j].it);
+
+         // if field not on nodes, take following field
+         if( field->getSupport()->getEntity() != MED_NODE )
+           break;
+
+         FIELD<double> *myDField = NULL;
+         FIELD<double> *newDField = NULL;
+         FIELD<int> *myIField = NULL;
+         FIELD<int> *newIField = NULL;
+
+         if (dynamic_cast<MEDMEM::FIELD<double>*>(field)){
+           if(!isReferenceField){
+             // read input field on input file
+             myDField = new FIELD<double>(MEDMEM::MED_DRIVER,_file,fieldsNames[i],myIteration[j].dt,myIteration[j].it);
+           }
+           else{
+             myDField = _myDField;
+           }
+           // create new output field
+           newDField = new FIELD<double>(newSup,field->getNumberOfComponents());
+           newDField->setName(myDField->getName());
+           newDField->setIterationNumber(myIteration[j].dt);
+           newDField->setOrderNumber(myIteration[j].it);
+           newDField->setTime(myDField->getTime());
+         }
+         else{
+           if(!isReferenceField)
+             // read input field on input file
+             myIField = new FIELD<int>(MEDMEM::MED_DRIVER,_file,fieldsNames[i],myIteration[j].dt,myIteration[j].it);
+           else
+             myIField = _myIField;
+           // create new output field
+           newIField = new FIELD<int>(newSup,field->getNumberOfComponents());
+           newIField->setName(myIField->getName());
+           newIField->setIterationNumber(myIteration[j].dt);
+           newIField->setOrderNumber(myIteration[j].it);
+           newIField->setTime(myIField->getTime());
+         }
+         numberOfComponents = field->getNumberOfComponents();
+         
+         // loop on nodes on new field
+         for (int k=1; k<=numberOfNodes; k++){
+           // read number of nodes on input field
+           int l = getNodeNumber(k);
+           double dval;
+           int ival;
+           
+           for(int c=1;c<=numberOfComponents;c++){
+             // read value on input field
+             if(myDField)
+               dval = myDField->getValueIJ(l,c);
+             else
+               ival = myIField->getValueIJ(l,c);
+             
+             // write value on new field
+             if(newDField){
+               newDField->setValueIJ(k,c,dval);
+             }
+             else
+               newIField->setValueIJ(k,c,ival);
+           }
+         
+         }
+         if(newDField)
+           _newMed->addField(newDField);
+         else
+           _newMed->addField(newIField);
+         
+         // Destroy input field if not reference field
+         if(!isReferenceField)
+           if(myDField){
+             delete myDField->getSupport();
+             delete myDField;
+           }
+           else{
+             delete myIField->getSupport();
+             delete myIField;
+           }
+         
+       }
+      }
+    }
+  }
+  catch(SALOME_Exception){
+    throw SALOME_FILTER::FILTER_Gen::FilterError("Unvalid decimate mlesh created by filtoo");
+  }
+
+  // destroy filtoo output files
+  command = "cd /tmp;rm -f output.*";
+  MESSAGE(command);
+  system(command.c_str());
+
+}
+
+void Filter_Gen_i::readMapping()
+{
+  double tmp;
+  string firstline;
+  ifstream mapFile("/tmp/output.renum");
+
+  // read first line of file
+  getline(mapFile, firstline);
+
+  // read number of vertices to map
+  string::size_type pos = firstline.find(":");
+  istringstream iss(firstline.substr(pos+1));
+  iss >> _nbvmap;
+
+  // read each vertices in array
+  _map = new int[_nbvmap];
+  
+  for(int i=0;i<_nbvmap;i++){
+    mapFile >> tmp;
+    _map[i] = (int)tmp;
+  }
+
+}
+
+int Filter_Gen_i::getNodeNumber(int num)
+{
+  int oldnum = _map[num-1];
+
+  // if new node get neighbour node
+  if(oldnum == 0)
+    oldnum = _map[getNeighbourVertex(num)-1];
+  
+  return oldnum;
 }
 
+int Filter_Gen_i::getNeighbourVertex(int num) throw(SALOME_Exception)
+{
+  int nnum;
+  int numberOfElements = _newMesh->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
+
+  int index;
+  // get index of created node in connectivity array
+  for(index=0;index<_connL;index++){
+    if(_conn[index] == num){
+
+      // get index of element which contain created node
+      int i;
+      for(i=1;i<=numberOfElements;i++)
+       if(_connI[i] > index)
+         break;
+
+      // search neighbour node which are in old mesh
+      for(int j=_connI[i-1];j<_connI[i];j++){
+       nnum = _conn[j-1];
+       if( _map[nnum-1] != 0)
+         break;
+      }
+
+      // if neighbour node in old mesh: go out loop, else continue
+      if(_map[nnum-1]!=0)
+       break;
+    }
+  }
+
+  // if no neighbour node in old mesh: throw exception
+  if(_map[nnum-1]==0)
+    throw SALOME_Exception("None of the neighbour node are in old mesh!!");
+
+  return nnum;
+}
+
+void Filter_Gen_i::createMedOutputFile(const char *outMedFile)
+{
+  int id;
+
+  MESSAGE("Create MED mesh: "<<outMedFile);
+  id = _newMed->addDriver(MED_DRIVER,outMedFile,MED_EN::MED_ECRI);
+  _newMed->write(id);
+}
+
+
+//=============================================================================
+/*!
+ * C factory, accessible with dlsym, after dlopen
+ */
+//=============================================================================
+
+extern "C"
+{
+  PortableServer::ObjectId * FILTEREngine_factory(
+                              CORBA::ORB_ptr orb,
+                              PortableServer::POA_ptr poa,
+                              PortableServer::ObjectId * contId,
+                              const char *instanceName,
+                              const char *interfaceName)
+  {
+    MESSAGE("PortableServer::ObjectId * FilterEngine_factory()");
+    SCRUTE(interfaceName);
+    Filter_Gen_i * myFilter_Gen
+      = new Filter_Gen_i(orb, poa, contId, instanceName, interfaceName);
+    return myFilter_Gen->getId() ;
+  }
+}
index 53205294510da30cef1f4cb89124a7f303bb39b4..3005f27c2af28909ddc6224d4d86d631f30e0c7e 100644 (file)
 #include <SALOMEconfig.h>
 #include <map>
 #include CORBA_SERVER_HEADER(FILTER_Gen)
-#include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
+
+#include "utilities.h"
+#include "MEDMEM_Med.hxx"
+#include "Utils_SALOME_Exception.hxx"
 
 #include "SALOME_Component_i.hxx"
 #include "SALOME_NamingService.hxx"
 
-#include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
-
 class Filter_Gen_i:
   public POA_SALOME_FILTER::FILTER_Gen,
   public Engines_Component_i 
 {
-private:
-
 public:
   Filter_Gen_i();
   Filter_Gen_i(CORBA::ORB_ptr orb,
@@ -54,13 +53,56 @@ public:
            const char *interfaceName);
   virtual ~Filter_Gen_i();
 
+  void loadMED(const char* inMedFile);
+  void unloadMED();
+  SALOME_FILTER::StrSeq* getMeshNames();
+  SALOME_FILTER::StrSeq* getFieldNames();
+  CORBA::Long getMeshDimension(const char* meshName);
+  CORBA::Long getFieldEntity(const char* fieldName,CORBA::Long dt,CORBA::Long it);
+  CORBA::Boolean fieldIsOnAllElements(const char* fieldName,CORBA::Long dt,CORBA::Long it);
+  SALOME_FILTER::DTITSeq* getFieldIteration(const char* fieldName);
+  char* getMeshName(const char* fieldName,CORBA::Long dt,CORBA::Long it);
+  void readReferenceField(const char* meshName, const char* fieldName, CORBA::Long ts);
+  void buildGradient()  throw(SALOME_FILTER::FILTER_Gen::FilterError);
+  void getMinMax(CORBA::Double& imin, CORBA::Double& imax,SALOME_FILTER::ref_func rf);
+  SALOME_FILTER::LongSeq* getHistogram(CORBA::Long size,SALOME_FILTER::ref_func rf);
+  void generateCriteria(CORBA::Long nbthresh,CORBA::Double fthresh,CORBA::Double thresh,CORBA::Boolean areaFlag,SALOME_FILTER::ref_func rf) throw(SALOME_FILTER::FILTER_Gen::FilterError);
+  void createEnsightInputFiles() throw(SALOME_FILTER::FILTER_Gen::FilterError);
+  void filtering() throw(SALOME_FILTER::FILTER_Gen::FilterError);
+  void projectFieldsOnDecimateMesh() throw(SALOME_FILTER::FILTER_Gen::FilterError);
+  void createMedOutputFile(const char* outMedFile);
 
 private :
+  void readMapping();
+  int getNodeNumber(int);
+  int getNeighbourVertex(int) throw(SALOME_Exception);
+
   static Filter_Gen_i*  _FILTERGen;    // Point to last created instance of the class
 
-  private:
   bool   _duringLoad;
   SALOME_NamingService *_NS;
+
+  int _nbvmap;
+  int *_map;
+  int _connL;
+  const int *_conn;
+  const int *_connI;
+  string _file;
+
+  ::MEDMEM::MED *_med, *_newMed;
+  MESH* _mesh, *_newMesh;
+  FIELD<double> * _myGradient;
+  FIELD<double> * _myDField;
+  FIELD<int> * _myIField;
+  FIELD<int> *_criteria;
+
 };
 
+extern "C"
+    PortableServer::ObjectId * FilterMEDEngine_factory(
+            CORBA::ORB_ptr orb,
+            PortableServer::POA_ptr poa,
+            PortableServer::ObjectId * contId,
+            const char *instanceName,
+            const char *interfaceName);
 #endif
index 8a345336b0cdee74de414858c0f4dbee727657f4..b0c8f21a47e89ab38673457c6065ecd14f41258d 100644 (file)
@@ -43,23 +43,29 @@ LIB_SRC = Filter_Gen_i.cxx
 LIB_SERVER_IDL = FILTER_Gen.idl SALOME_Component.idl SALOME_ContainerManager.idl \
                 SALOME_Exception.idl 
 
-LIB_CLIENT_IDL = SALOMEDS.idl SALOMEDS_Attributes.idl SALOME_ModuleCatalog.idl SALOME_Comm.idl SALOME_GenericObj.idl
+LIB_CLIENT_IDL = SALOMEDS.idl SALOMEDS_Attributes.idl SALOME_ModuleCatalog.idl SALOME_Comm.idl SALOME_GenericObj.idl MED_Gen.idl
 
 EXPORT_HEADERS = Filter_Gen_i.hxx
 
 # Executables targets
-BIN =
+BIN = field2nodes
 BIN_SRC =
 
 LDFLAGS= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome
-LDFLAGSFORBIN= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome
+LDFLAGSFORBIN= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome 
+#LDFLAGSFORBIN+=-lm $(MED2_LIBS) $(HDF5_LIBS)
 
 # additionnal information to compil and link file
 
-CPPFLAGS += $(OCC_INCLUDES) $(MED2_INCLUDES)  $(HDF5_INCLUDES) ${KERNEL_CXXFLAGS}
+CPPFLAGS += $(OCC_INCLUDES) $(MED2_INCLUDES)  $(HDF5_INCLUDES) ${KERNEL_CXXFLAGS} $(MED_CXXFLAGS)
 CXXFLAGS += $(OCC_CXXFLAGS) ${KERNEL_CXXFLAGS}
 
-LDFLAGS+=  $(OCC_LIBS) $(HDF5_LIBS) ${KERNEL_LDFLAGS} \
-       -lSalomeContainer -lSalomeHDFPersist -lSalomeDS -lSalomeNS -lRegistry -lOpUtil
+LDFLAGS += $(OCC_LIBS) $(HDF5_LIBS) ${KERNEL_LDFLAGS} \
+       -lSalomeContainer -lSalomeHDFPersist -lSalomeDS -lSalomeNS -lRegistry -lOpUtil \
+       ${MED_LDFLAGS} -lMEDMEMImpl -lmedmem -lmed_V2_1
+
+LDFLAGSFORBIN += $(OCC_LIBS) $(HDF5_LIBS) ${KERNEL_LDFLAGS} \
+       -lSalomeContainer -lSalomeHDFPersist -lSalomeDS -lSalomeNS -lRegistry -lOpUtil \
+       ${MED_LDFLAGS} -lMEDMEMImpl -lmedmem -lmed_V2_1
 
 @CONCLUDE@
diff --git a/src/FILTER/field2nodes.cxx b/src/FILTER/field2nodes.cxx
new file mode 100644 (file)
index 0000000..95f206f
--- /dev/null
@@ -0,0 +1,290 @@
+// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// 
+// 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
+//
+#include<string>
+#include<deque>
+
+#include "MEDMEM_Exception.hxx"
+#include "MEDMEM_define.hxx"
+
+#include "MEDMEM_Med.hxx"
+#include "MEDMEM_Mesh.hxx"
+#include "MEDMEM_Family.hxx"
+#include "MEDMEM_Support.hxx"
+#include "MEDMEM_Field.hxx"
+
+using namespace std;
+using namespace MEDMEM;
+
+void usage(char * name)
+{
+  cout << " ERROR ABOUT SYNTAX " << endl ;
+  cout << "  " << name << " <input med file> <output med file> " << endl ;
+  exit(-1);
+}
+
+int main (int argc, char ** argv) {
+
+  string filenameIN ;
+  string filenameOUT;
+  set <int> listElements, supset;
+  set <int>::iterator elemIt, ssIt;
+  
+  if ( argc == 3 ) {
+    filenameIN  = argv[1] ;
+    filenameOUT = argv[2] ;
+    cout << "-> reading all into the Med file " << filenameIN << " and writing all into the Ensight file " << filenameOUT <<  endl ;
+
+    MED myMed(MED_DRIVER,filenameIN) ;
+
+    cout << "-> Read all meshes "  ;
+    int NumberOfMeshes = myMed.getNumberOfMeshes() ;
+    cout << "( "<<NumberOfMeshes << " ) :" << endl ;
+    FIELD<double> **volume = new FIELD<double>*[NumberOfMeshes];
+    deque<string> MeshName = myMed.getMeshNames() ;
+    for (int i=0; i<NumberOfMeshes; i++) {
+      volume[i] = NULL;
+      myMed.getMesh(MeshName[i])->read() ;
+      cout << "-> Mesh "<<i+1<<", named "<<MeshName[i]<<" is read !" << endl;
+      int id = myMed.getMesh(MeshName[i])->addDriver(MED_DRIVER,filenameOUT,MeshName[i],MED_EN::MED_ECRI);
+      myMed.getMesh(MeshName[i])->write(id);
+      cout << "-> Mesh "<<i+1<<", named "<<MeshName[i]<<" is written !" << endl;
+    }
+
+    myMed.updateSupport() ;
+    
+    cout << "-> Read all fields " ;
+    int NumberOfFields = myMed.getNumberOfFields() ;
+    cout << "( "<<NumberOfFields << " ) :" << endl;
+    deque<string> FieldName = myMed.getFieldNames() ;
+    for (int i=0; i<NumberOfFields; i++) {
+      deque<DT_IT_> FieldIteration = myMed.getFieldIteration(FieldName[i]) ;
+      cout << "-> Field "<<i+1<<", named "<<FieldName[i] << " :" << endl ;
+      int NumberOfIteration = FieldIteration.size() ;
+      cout << "    Number of iteration pair : "<< NumberOfIteration << endl;
+      for (int j=0; j<NumberOfIteration; j++) {
+       FIELD_ * myField = myMed.getField(FieldName[i],FieldIteration[j].dt,FieldIteration[j].it) ;
+       
+       myField->read() ;
+       cout << "    * Iteration "<<FieldIteration[j].dt<<" and  order number "<<FieldIteration[j].it<<" ) is read !" << endl;
+
+       int NumberOfComponents = myField->getNumberOfComponents();
+       switch(myField->getSupport()->getEntity()){
+       case MED_CELL:
+          {
+            cout << "*************************** CHAMP AUX CELLULES" << endl;
+            MESH *mesh = myField->getSupport()->getMesh();
+
+            // create new support for new field
+            SUPPORT *newSup;
+            if( myField->getSupport()->isOnAllElements() )
+              newSup = new SUPPORT(mesh,"Support",MED_NODE);
+            else{
+              int nbe = myField->getSupport()->getNumberOfElements(MED_ALL_ELEMENTS);
+              const int *numb = myField->getSupport()->getNumber(MED_ALL_ELEMENTS);
+              list<int> myList;
+              for(int k=0;k<nbe;k++){
+                myList.push_back(numb[k]);
+                supset.insert(numb[k]);
+              }
+              newSup = mesh->buildSupportOnNodeFromElementList(myList,MED_CELL);
+            }
+
+            // read number of nodes
+            int NumberOfNodes = newSup->getNumberOfElements(MED_ALL_ELEMENTS);
+            // calculate reverse connectivity to have the list of elements which contains node i
+            const int *revC = myField->getSupport()->getMesh()->getReverseConnectivity(MED_NODAL,MED_CELL);
+            const int *indC = myField->getSupport()->getMesh()->getReverseConnectivityIndex(MED_NODAL,MED_CELL);
+            int ivol;
+            // calculate volume field on mesh
+            for(int k=0;k<NumberOfMeshes;k++)
+              if(strcmp(mesh->getName().c_str(),MeshName[k].c_str())==0)
+                ivol = k;
+            if( volume[ivol] == NULL )
+              volume[ivol] = myField->getSupport()->getMesh()->getVolume(myField->getSupport());
+            if (dynamic_cast<MEDMEM::FIELD<double>*>(myField)){
+              FIELD<double> *myDField = (MEDMEM::FIELD<double>*)myField;
+              FIELD<double> *newDField = new FIELD<double>(newSup,NumberOfComponents);
+              newDField->setName(myField->getName());
+              newDField->setIterationNumber(FieldIteration[j].dt);
+              newDField->setOrderNumber(FieldIteration[j].it);
+              newDField->setTime(myDField->getTime());
+              double *val = new double[NumberOfComponents];
+              if( newSup->isOnAllElements() ){
+                for (int k=1; k<NumberOfNodes+1; k++){
+                  // listElements contains elements which contains a node of element i
+                  listElements.clear();
+                  for(int l=indC[k-1];l<indC[k];l++){
+                    // c element contains node k
+                    int c=revC[l-1];
+                    listElements.insert(c);
+                  }
+
+                  // calculate field value on node k 
+                  double sigmaV = 0.;
+                  for(int l=0;l<NumberOfComponents;l++)
+                    val[l] = 0.;
+                  for(elemIt=listElements.begin();elemIt!=listElements.end();elemIt++){
+                    int elem = *elemIt;
+                    double vol = volume[ivol]->getValueIJ(elem,1);
+                    if( vol != 0. ){
+                      sigmaV += 1./vol;
+                      for(int l=1;l<=NumberOfComponents;l++)
+                        val[l-1] += myDField->getValueIJ(elem,l)/vol;
+                    }
+                  }
+                  for(int l=1;l<=NumberOfComponents;l++)
+                    newDField->setValueIJ(k,l,val[l-1]/sigmaV);
+                }
+              }
+              else{
+                const int *numb = newSup->getNumber(MED_ALL_ELEMENTS);
+                for (int k=1; k<=NumberOfNodes; k++){
+                  int kk = numb[k-1];
+                  // listElements contains elements which contains a node of element i
+                  listElements.clear();
+                  for(int l=indC[kk-1];l<indC[kk];l++){
+                    // c element contains node k
+                    int c=revC[l-1];
+                    // add c element only if it is in partial support
+                    ssIt = supset.find(c);
+                    if(ssIt!=supset.end())
+                      listElements.insert(c);
+                  }
+
+                  // calculate field value on node k 
+                  double sigmaV = 0.;
+                  for(int l=0;l<NumberOfComponents;l++)
+                    val[l] = 0.;
+                  for(elemIt=listElements.begin();elemIt!=listElements.end();elemIt++){
+                    int elem = *elemIt;
+                    double vol = volume[ivol]->getValueIJ(elem,1);
+                    if( vol != 0. ){
+                      sigmaV += 1./vol;
+                      for(int l=1;l<=NumberOfComponents;l++)
+                        val[l-1] += myDField->getValueIJ(elem,l)/vol;
+                    }
+                  }
+                  for(int l=1;l<=NumberOfComponents;l++)
+                    newDField->setValueIJ(k,l,val[l-1]/sigmaV);
+                }
+              }
+              delete [] val;
+              int id = newDField->addDriver(MED_DRIVER,filenameOUT,FieldName[i],MED_EN::MED_ECRI);
+              newDField->write(id);
+              delete newSup;
+              delete newDField;
+              cout << "    * Iteration "<<FieldIteration[j].dt<<" and  order number "<<FieldIteration[j].it<<" ) is written !" << endl;
+            }
+            else{
+              FIELD<int> *myIField = (MEDMEM::FIELD<int>*)myField;
+              FIELD<int> *newIField = new FIELD<int>(newSup,NumberOfComponents);
+              newIField->setName(myField->getName());
+              newIField->setIterationNumber(FieldIteration[j].dt);
+              newIField->setOrderNumber(FieldIteration[j].it);
+              newIField->setTime(myIField->getTime());
+              double *val = new double[NumberOfComponents];
+              if( newSup->isOnAllElements() ){
+                for (int k=1; k<NumberOfNodes+1; k++){
+                  // listElements contains elements which contains a node of element i
+                  listElements.clear();
+                  for(int l=indC[k-1];l<indC[k];l++){
+                    // c element contains node i
+                    int c=revC[l-1];
+                    listElements.insert(c);
+                  }
+
+                  // calculate field value on node k 
+                  double sigmaV = 0.;
+                  for(int l=0;l<NumberOfComponents;l++)
+                    val[l] = 0.;
+                  for(elemIt=listElements.begin();elemIt!=listElements.end();elemIt++){
+                    int elem = *elemIt;
+                    double vol = volume[ivol]->getValueIJ(elem,1);
+                    if( vol != 0. ){
+                      sigmaV += 1./vol;
+                      for(int l=1;l<=NumberOfComponents;l++)
+                        val[l-1] += ((double)myIField->getValueIJ(elem,l))/vol;
+                    }
+                  }
+                  for(int l=1;l<=NumberOfComponents;l++)
+                    newIField->setValueIJ(k,l,(int)(val[l-1]/sigmaV));
+                }
+              }
+              else{
+                const int *numb = newSup->getNumber(MED_ALL_ELEMENTS);
+                for (int k=1; k<=NumberOfNodes; k++){
+                  int kk = numb[k-1];
+                  // listElements contains elements which contains a node of element i
+                  listElements.clear();
+                  for(int l=indC[kk-1];l<indC[kk];l++){
+                    // c element contains node k
+                    int c=revC[l-1];
+                    // add c element only if it is in partial support
+                    ssIt = supset.find(c);
+                    if(ssIt!=supset.end())
+                      listElements.insert(c);
+                  }
+
+                  // calculate field value on node k 
+                  double sigmaV = 0.;
+                  for(int l=0;l<NumberOfComponents;l++)
+                    val[l] = 0.;
+                  for(elemIt=listElements.begin();elemIt!=listElements.end();elemIt++){
+                    int elem = *elemIt;
+                    double vol = volume[ivol]->getValueIJ(elem,1);
+                    if( vol != 0. ){
+                      sigmaV += 1./vol;
+                      for(int l=1;l<=NumberOfComponents;l++)
+                        val[l-1] += myIField->getValueIJ(elem,l)/vol;
+                    }
+                  }
+                  for(int l=1;l<=NumberOfComponents;l++)
+                    newIField->setValueIJ(k,l,(int)(val[l-1]/sigmaV));
+                }
+              }
+              delete [] val;
+              int id = newIField->addDriver(MED_DRIVER,filenameOUT,FieldName[i],MED_EN::MED_ECRI);
+              newIField->write(id);
+              delete newSup;
+              delete newIField;
+              cout << "    * Iteration "<<FieldIteration[j].dt<<" and  order number "<<FieldIteration[j].it<<" ) is written !" << endl;
+            }
+          }
+         break;
+       case MED_FACE:
+         cout << "*************************** CHAMP AUX FACES" << endl;
+         break;
+       case MED_EDGE:
+         cout << "*************************** CHAMP AUX ARETES" << endl;
+         break;
+       case MED_NODE:
+         cout << "*************************** CHAMP AUX NOEUDS" << endl;
+         int id = myField->addDriver(MED_DRIVER,filenameOUT,FieldName[i],MED_EN::MED_ECRI);
+         myField->write(id);
+         cout << "    * Iteration "<<FieldIteration[j].dt<<" and  order number "<<FieldIteration[j].it<<" ) is written !" << endl;
+         break;
+       }
+
+      }
+    }
+
+  }
+  else usage(argv[0]);
+}
index ad06ffe5a3229ebc76a3e3a6ed7c424c408dc997..73577abe79e7f0a01673642b568ac79e6e4c2613 100644 (file)
@@ -23,22 +23,23 @@ import salome
 import SALOME_FILTER
 import libSALOME_LifeCycleCORBA
 lcc=libSALOME_LifeCycleCORBA.SALOME_LifeCycleCORBA()
-filter=lcc.FindOrLoad_Component("FactoryServer","FILTER")
+# load FILTER module
+filter=lcc.FindOrLoad_Component("","FILTER")
 inputFile=os.getenv("FILTER_ROOT_DIR")+"/share/salome/resources/filter/xx.aa.med"
-inputMesh="MeshFromEnsight"
-inputField="FieldFromEnsight"
-inputTS=0
-nbth=1
-fth=2.2
-sth=0.0
-flag=True
-rf=SALOME_FILTER.F_FIELD
 outputFile="filtered.med"
+# load input MED file
 filter.loadMED(inputFile)
-filter.readReferenceField(inputMesh,inputField,inputTS)
-filter.generateCriteria(nbth,fth,sth,flag,rf)
+# read reference field for filtering
+filter.readReferenceField("MeshFromEnsight","FieldFromEnsight",0)
+# generate filtering criteria from thersholds on reference filed
+filter.generateCriteria(1,2.2,0.,True,SALOME_FILTER.F_FIELD)
+# create ensight input files for DISTENE filtoo tool
 filter.createEnsightInputFiles()
+# call DISTENNE filtoo tool
 filter.filtering()
+# project input fileds on new mesh
 filter.projectFieldsOnDecimateMesh()
+# create output MED file
 filter.createMedOutputFile(outputFile)
+# unload MED object
 filter.unloadMED()
diff --git a/src/FILTERGUI/FILTERGUI_Utils.cxx b/src/FILTERGUI/FILTERGUI_Utils.cxx
new file mode 100644 (file)
index 0000000..246b282
--- /dev/null
@@ -0,0 +1,249 @@
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  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
+
+
+#include <qstring.h>
+
+#include "FILTERGUI_Utils.h"
+
+#include "OB_Browser.h"
+
+#include "SUIT_Desktop.h"
+#include "SUIT_Application.h"
+#include "SUIT_Session.h"
+
+#include "LightApp_SelectionMgr.h"
+#include "SalomeApp_Application.h"
+#include "SalomeApp_Module.h"
+#include "SalomeApp_Study.h"
+
+#include "SALOME_ListIO.hxx"
+
+#include "SALOMEconfig.h"
+// #include CORBA_CLIENT_HEADER(GEOM_Gen)
+
+#include "utilities.h"
+
+//using namespace std;
+
+namespace FILTER{
+
+  SUIT_Desktop*
+  GetDesktop(const CAM_Module* theModule)
+  {
+    return theModule->application()->desktop();
+  }
+
+  LightApp_SelectionMgr*
+  GetSelectionMgr(const SalomeApp_Module* theModule)
+  {
+    return theModule->getApp()->selectionMgr();
+  }
+
+  SUIT_ResourceMgr*
+  GetResourceMgr( const SalomeApp_Module* )
+  {
+    return SUIT_Session::session()->resourceMgr();
+  }
+
+  _PTR(Study)
+  GetCStudy(const SalomeApp_Study* theStudy)
+  {
+    return theStudy->studyDS();
+  }
+
+  CORBA::Object_var 
+  DataOwnerToObject(const LightApp_DataOwnerPtr& theOwner)
+  {
+    CORBA::Object_var anObj;
+    if(theOwner){
+      const Handle(SALOME_InteractiveObject)& anIO = theOwner->IO();
+      if(!anIO.IsNull()){
+       if(anIO->hasEntry()){
+         _PTR(Study) aStudy = GetActiveStudyDocument();
+         _PTR(SObject) aSObj = aStudy->FindObjectID(anIO->getEntry());
+         anObj = SObjectToObject(aSObj,aStudy);
+       }
+      }
+    }
+    return anObj;
+  }
+
+
+  SUIT_Study* GetActiveStudy()
+  {
+    SUIT_Application* app = SUIT_Session::session()->activeApplication();
+    if (app)
+      return app->activeStudy();
+    else
+      return NULL;
+  }
+
+  SUIT_ViewWindow* GetActiveWindow()
+  {
+    SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
+      (SUIT_Session::session()->activeApplication());
+    if (app && app->desktop() )
+      return app->desktop()->activeWindow();
+    else
+      return NULL;
+  }
+
+  _PTR(Study) GetActiveStudyDocument()
+  {
+    SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(GetActiveStudy());
+    if (aStudy)
+      return aStudy->studyDS();
+    else
+      return _PTR(Study)();
+  }
+
+  _PTR(SObject) FindSObject (CORBA::Object_ptr theObject)
+  {
+    SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
+      (SUIT_Session::session()->activeApplication());
+    if (app && !CORBA::is_nil(theObject)) {
+      if(_PTR(Study) aStudy = GetActiveStudyDocument()){
+       CORBA::String_var anIOR = app->orb()->object_to_string(theObject);
+       if (strcmp(anIOR.in(), "") != 0)
+         return aStudy->FindObjectIOR(anIOR.in());
+      }
+    }
+    return _PTR(SObject)();
+  }
+
+  void SetName (_PTR(SObject) theSObject, const char* theName)
+  {
+    _PTR(Study) aStudy = GetActiveStudyDocument();
+    if (aStudy->GetProperties()->IsLocked())
+      return;
+    _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
+    _PTR(GenericAttribute) anAttr =
+      aBuilder->FindOrCreateAttribute(theSObject, "AttributeName");
+    _PTR(AttributeName) aName = anAttr;
+    if (aName)
+      aName->SetValue(theName);
+  }
+
+  void SetValue (_PTR(SObject) theSObject, const char* theValue)
+  {
+    _PTR(Study) aStudy = GetActiveStudyDocument();
+    if (aStudy->GetProperties()->IsLocked())
+      return;
+    _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
+    _PTR(GenericAttribute) anAttr =
+      aBuilder->FindOrCreateAttribute(theSObject, "AttributeComment");
+    _PTR(AttributeComment) aComment = anAttr;
+    if (aComment)
+      aComment->SetValue(theValue);
+  }
+  
+  void setFileName (_PTR(SObject) theSObject, const char* theValue)
+  {
+    _PTR(Study) aStudy = GetActiveStudyDocument();
+    if (aStudy->GetProperties()->IsLocked())
+      return;
+    _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
+    _PTR(GenericAttribute) anAttr =
+      aBuilder->FindOrCreateAttribute(theSObject, "AttributeExternalFileDef");
+    _PTR(AttributeExternalFileDef) aFileName = anAttr;
+    if (aFileName)
+      aFileName->SetValue(theValue);
+  }
+  
+  void setFileType (_PTR(SObject) theSObject, const char* theValue)
+  {
+    _PTR(Study) aStudy = GetActiveStudyDocument();
+    if (aStudy->GetProperties()->IsLocked())
+      return;
+    _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
+    _PTR(GenericAttribute) anAttr =
+      aBuilder->FindOrCreateAttribute(theSObject, "AttributeFileType");
+    _PTR(AttributeFileType) aFileType = anAttr;
+    if (aFileType)
+      aFileType->SetValue(theValue);
+  }
+
+  CORBA::Object_var SObjectToObject (_PTR(SObject) theSObject,
+                                     _PTR(Study)   theStudy)
+  {
+    SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
+      (SUIT_Session::session()->activeApplication());
+    if (theSObject) {
+      _PTR(GenericAttribute) anAttr;
+      if (theSObject->FindAttribute(anAttr, "AttributeIOR")) {
+       _PTR(AttributeIOR) anIOR = anAttr;
+       CORBA::String_var aVal = anIOR->Value().c_str();
+       return app->orb()->string_to_object(aVal);
+      }
+    }
+    return CORBA::Object::_nil();
+  }
+
+  CORBA::Object_var SObjectToObject (_PTR(SObject) theSObject)
+  {
+    _PTR(Study) aStudy = GetActiveStudyDocument();
+    return SObjectToObject(theSObject,aStudy);
+  }
+
+  CORBA::Object_var IObjectToObject (const Handle(SALOME_InteractiveObject)& theIO)
+  {
+    if (!theIO.IsNull()) {
+      if (theIO->hasEntry()) {
+       _PTR(Study) aStudy = GetActiveStudyDocument();
+       _PTR(SObject) anObj = aStudy->FindObjectID(theIO->getEntry());
+       return SObjectToObject(anObj,aStudy);
+      }
+    }
+    return CORBA::Object::_nil();
+  }
+
+  CORBA::Object_var IORToObject (const char* theIOR)
+  {
+    SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
+      (SUIT_Session::session()->activeApplication());
+    return app->orb()->string_to_object(theIOR);
+  }
+
+  int GetNameOfSelectedIObjects(LightApp_SelectionMgr* theMgr, QString& theName)
+  {
+    if (!theMgr)
+      return 0;
+
+    SALOME_ListIO selected;
+    theMgr->selectedObjects(selected);
+    int aNbSel = selected.Extent();
+    if (aNbSel == 1) {
+      Handle(SALOME_InteractiveObject) anIObject = selected.First();
+      theName = anIObject->getName();
+    } else {
+      theName = QObject::tr("FILTER_OBJECTS_SELECTED").arg(aNbSel);
+    }
+    return aNbSel;
+  }
+
+//  void UpdateObjBrowser (bool)
+//  {
+//    //FILTERGUI::activeStudy()->updateObjBrowser(true);
+//    //SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
+//    //  (SUIT_Session::session()->activeApplication());
+//    //if (anApp) anApp->objectBrowser()->updateTree();
+//    FILTERGUI::GetSMESHGUI()->updateObjBrowser();
+//  }
+}
diff --git a/src/FILTERGUI/FILTERGUI_Utils.h b/src/FILTERGUI/FILTERGUI_Utils.h
new file mode 100644 (file)
index 0000000..076256f
--- /dev/null
@@ -0,0 +1,128 @@
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  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
+
+#ifndef FILTERGUI_Utils_HeaderFile
+#define FILTERGUI_Utils_HeaderFile
+
+#include <CORBA.h>
+
+#include "SALOMEDSClient_definitions.hxx"
+#include "SALOME_InteractiveObject.hxx"
+#include "LightApp_DataOwner.h"
+
+class QString;
+
+class SUIT_ViewWindow;
+class SUIT_Desktop;
+class SUIT_Study;
+class SUIT_ResourceMgr;
+
+class CAM_Module;
+
+class SALOMEDSClient_Study;
+class SALOMEDSClient_SObject;
+
+class SalomeApp_Study;
+class SalomeApp_Module;
+class LightApp_SelectionMgr;
+
+namespace FILTER {
+
+  SUIT_Desktop*
+  GetDesktop(const CAM_Module* theModule);
+
+  LightApp_SelectionMgr*
+  GetSelectionMgr(const SalomeApp_Module* theModule);
+
+  SalomeApp_Study*
+  GetAppStudy(const CAM_Module* theModule);
+
+  SUIT_ResourceMgr*
+  GetResourceMgr( const SalomeApp_Module* );
+  
+  _PTR(Study)
+  GetCStudy(const SalomeApp_Study* theStudy);
+
+  CORBA::Object_var DataOwnerToObject(const LightApp_DataOwnerPtr& theOwner);
+
+  template<class TInterface> typename TInterface::_var_type
+    DataOwnerToInterface(const LightApp_DataOwnerPtr& theDataOwner)
+    {
+      CORBA::Object_var anObj = DataOwnerToObject(theDataOwner);
+      if(!CORBA::is_nil(anObj))
+       return TInterface::_narrow(anObj);
+      return TInterface::_nil();
+    }
+
+
+  SUIT_Study* GetActiveStudy();
+
+  SUIT_ViewWindow* GetActiveWindow();
+
+  _PTR(Study) GetActiveStudyDocument();
+
+  _PTR(SObject) FindSObject(CORBA::Object_ptr theObject);
+
+  void SetName  (_PTR(SObject) theSObject, const char* theName);
+  void SetValue (_PTR(SObject) theSObject, const char* theValue);
+  void setFileType (_PTR(SObject) theSObject, const char* theValue);
+  void setFileName (_PTR(SObject) theSObject, const char* theValue);
+
+  CORBA::Object_var SObjectToObject (_PTR(SObject) theSObject,
+                                    _PTR(Study) theStudy);
+
+  CORBA::Object_var SObjectToObject(_PTR(SObject) theSObject);
+
+  template<class TInterface> typename TInterface::_var_type
+    SObjectToInterface(_PTR(SObject) theSObject)
+    {
+      CORBA::Object_var anObj = SObjectToObject(theSObject);
+      if(!CORBA::is_nil(anObj))
+       return TInterface::_narrow(anObj);
+      return TInterface::_nil();
+    }
+
+  CORBA::Object_var IObjectToObject(const Handle(SALOME_InteractiveObject)& theIO);
+
+  template<class TInterface> typename TInterface::_var_type
+    IObjectToInterface(const Handle(SALOME_InteractiveObject)& theIO)
+    {
+      CORBA::Object_var anObj = IObjectToObject(theIO);
+      if(!CORBA::is_nil(anObj))
+       return TInterface::_narrow(anObj);
+      return TInterface::_nil();
+    }
+
+  CORBA::Object_var IORToObject(const char* theIOR);
+
+  template<class TInterface> typename TInterface::_var_type
+    IORToInterface(const char* theIOR)
+    {
+      CORBA::Object_var anObj = IORToObject(theIOR);
+      if(!CORBA::is_nil(anObj))
+       return TInterface::_narrow(anObj);
+      return TInterface::_nil();
+    }
+
+  int GetNameOfSelectedIObjects (LightApp_SelectionMgr*, QString& theName);
+
+//  void UpdateObjBrowser (bool);
+}
+
+#endif
index f2d7f2bae56cfa2bc608e8b9e88a88f8420af165..68ce9a69cf40736dd30997d8cc907526f001f010 100644 (file)
@@ -7,7 +7,7 @@
 #  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 
@@ -32,124 +32,191 @@ msgstr ""
 "Last-Translator: FULLNAME <EMAIL@ADDRESS>\n"
 "Content-Type: text/plain; charset=iso-8859-1\n"
 
-
 #: FilterGUI.cxx:271
 msgid "FilterGUI::FILTER_MEN_ALL_FILES"
 msgstr "All Files ( * )"
 
 #: FilterGUI.cxx:300
-#, fuzzy
-msgid "FilterGUI::MEN_OPEN"
+msgid "FilterGUI::FILTER_MEN_IMPORT"
 msgstr "Open a MED file"
 
-msgid "FilterGUI::FILTER_MEN_IMPORT"
+#: FilterGUI.cxx:143
+msgid "FilterGUI::MEN_OPEN"
 msgstr "Open a MED file"
 
 #: FilterGUI.cxx:270
 msgid "FilterGUI::FILTER_MEN_IMPORT_MED"
 msgstr "MED Files ( *.med )"
 
-#: FilterGUI.cxx:296
-msgid "FILTER_WRN_WARNING"
-msgstr "Warning"
+#: SelectParams.cxx:123
+msgid "FILTER_PARAMS"
+msgstr "Filtering parameters"
 
-#: FilterGUI.cxx:280
-msgid "FILTER_INF_NOTIMPL"
-msgstr "Not Implemented for this Object"
+#: SelectParams.cxx:136
+msgid "FILTER_INPUT_FILE"
+msgstr "Input File : "
 
-#: FilterGUI.cxx:298
-msgid "FILTER_BUT_OK"
-msgstr "OK"
+#: SelectParams.cxx:141
+msgid "FILTER_INPUT_MESH"
+msgstr "Input Mesh : "
 
-#: FilterGUI.cxx:297
-msgid "FILTER_INF_NOIOR"
-msgstr "Object has no IOR"
+#: SelectParams.cxx:146
+msgid "FILTER_INPUT_FIELD"
+msgstr "Input Field : "
 
-#: FilterGUI.cxx:297
-msgid "FILTER_INF_MESHNAME"
-msgstr "Please enter the name of the mesh you want to read"
+#: SelectParams.cxx:151
+msgid "FILTER_INPUT_TS"
+msgstr "Input Time Step : "
 
-#: FilterGUI.cxx:297
-msgid "FILTER_INF_FIELDNAME"
-msgstr "Please enter the name of the field you want to read"
+#: SelectParams.cxx:159
+msgid "FILTER_SELECT_FUNC"
+msgstr "Select function on field"
 
+#: SelectParams.cxx:163
+msgid "FILTER_FIELD"
+msgstr "Field"
 
-# Menu items
+#: SelectParams.cxx:168
+msgid "FILTER_GRADIENT"
+msgstr "Gradient"
 
-msgid "TOP_MESHSEL"
-msgstr "Mesh selection"
+#: SelectParams.cxx:162
+msgid "FILTER_SIZE_HISTO"
+msgstr "Histogram size  "
 
-msgid "MEN_FILTERING"
-msgstr "Filtering"
+#: SelectParams.cxx:174
+msgid "FILTER_DISPLAY_HISTO"
+msgstr "Display Histogram"
+
+#: SelectParams.cxx:181
+msgid "FILTER_TYPE_DISPLAY"
+msgstr "Type of display"
 
-msgid "STB_MESHSEL"
-msgstr "Read a mesh"
+#: SelectParams.cxx:185
+msgid "FILTER_LINEAR"
+msgstr "Linear"
 
-msgid "TOP_FIELDSEL"
-msgstr "Field selection"
+#: SelectParams.cxx:187
+msgid "FILTER_LOG"
+msgstr "Logarithm"
 
-msgid "MEN_FIELDSEL"
-msgstr "Field selection"
+#: SelectParams.cxx:197
+msgid "FILTER_SEL_THRESH"
+msgstr "Select number of thresholds"
 
-msgid "STB_FIELDSEL"
-msgstr "Read a field"
+#: SelectParams.cxx:201
+msgid "FILTER_ONE_THRESH"
+msgstr "One threshold"
 
-msgid "TOP_EXPLORE"
-msgstr "Explore Med File"
+#: SelectParams.cxx:203
+msgid "FILTER_TWO_THRESH"
+msgstr "Two thresholds"
 
-msgid "MEN_EXPLORE"
-msgstr "Explore Med File"
+#: SelectParams.cxx:210
+msgid "FILTER_REF_AREA"
+msgstr "Select reference area"
 
-msgid "STB_EXPLORE"
-msgstr "Explore Med File"
+#: SelectParams.cxx:214 and 321
+msgid "FILTER_BOTTOM"
+msgstr "Bottom"
 
-msgid "TOP_DUMPMESH"
-msgstr "Dump Mesh"
+#: SelectParams.cxx:215 and 322
+msgid "FILTER_UP"
+msgstr "Up"
 
-msgid "MEN_DUMPMESH"
-msgstr "Dump Mesh"
+#: SelectParams.cxx:330
+msgid "FILTER_INT"
+msgstr "Interior"
 
-msgid "STB_DUMPMESH"
-msgstr "dump Mesh"
+#: SelectParams.cxx:331
+msgid "FILTER_EXT"
+msgstr "Exterior"
 
-msgid "TOP_DUMPSUBMESH"
-msgstr "Dump SubMesh"
+#: SelectParams.cxx:223
+msgid "FILTER_TRESH_VAL"
+msgstr "Threshold values"
 
-msgid "MEN_DUMPSUBMESH"
-msgstr "Dump SubMesh"
+#: SelectParams.cxx:227 and 323
+msgid "FILTER_VAL_TRESH"
+msgstr "threshold value   "
 
-msgid "STB_DUMPSUBMESH"
-msgstr "dump Mesh"
+#: SelectParams.cxx:332
+msgid "FILTER_VAL_1_TRESH"
+msgstr "1st threshold value"
 
-msgid "TOP_POPUPTEST"
-msgstr "Popup test"
+#: SelectParams.cxx:229
+msgid "FILTER_VAL_2_TRESH"
+msgstr "2d threshold value"
 
-msgid "MEN_POPUPTEST"
-msgstr "Popup test"
+#: SelectParams.cxx:239
+msgid "FILTER_OUT_FILE"
+msgstr "Output file name"
 
-msgid "STB_POPUPTEST"
-msgstr "Popup test"
+#: SelectParams.cxx:244
+msgid "FILTER_BROWSE"
+msgstr "Browse"
 
-msgid "TOP_ERASE"
-msgstr "Erase"
+#: SelectParams.cxx:257
+msgid "FILTER_PROCESS"
+msgstr "Process"
 
-msgid "MEN_ERASE"
-msgstr "Erase"
+#: SelectParams.cxx:266
+msgid "FILTER_HISTO"
+msgstr "Histogram"
 
-msgid "STB_ERASE"
-msgstr "Erase"
+#: SelectParams.cxx:281 and 534
+msgid "FILTER_RED_RATE"
+msgstr "Reduction rate"
 
-msgid "TOP_DISPLAY"
-msgstr "Display"
+#: SelectField.cxx:67
+msgid "FILTER_FILE"
+msgstr "File : "
 
-msgid "MEN_DISPLAY"
-msgstr "Display"
+#: SelectField.cxx:87
+msgid "FILTER_NAME"
+msgstr "Name"
 
-msgid "STB_DISPLAY"
-msgstr "Display"
+#: SelectField.cxx:88
+msgid "FILTER_TYPE"
+msgstr "Type"
 
+#: SelectField.cxx:74
+msgid "FILTER_SEL_3D"
+msgstr "Select a reference field on a 3D mesh"
 
+#: SelectField.cxx:78
+msgid "FILTER_DIM"
+msgstr "Dimension"
+
+#: SelectField.cxx:91
+msgid "FILTER_MESH"
+msgstr "Mesh"
+
+#: SelectField.cxx:99
+msgid "FILTER_FIELD"
+msgstr "Field"
+
+#: SelectField.cxx:108
+msgid "FILTER_SEL_TS"
+msgstr "Select a time step:"
+
+# Menu items
+msgid "MEN_FILTERING"
+msgstr "Filtering"
+
+#-------------------------------------------------------------------------
+# BUTTON
+#-------------------------------------------------------------------------
+
+#Close
+msgid "FILTER_BUT_CANCEL"
+msgstr "&Cancel"
+
+#Help
+msgid "FILTER_BUT_OK"
+msgstr "&Ok"
 
-msgid "TB_MED"
-msgstr "Med Toolbar"
+#Help
+msgid "FILTER_BUT_HELP"
+msgstr "&Help"
 
index d78565512a04146bbc9255be49d83657d38829e7..5735dcddc28dcc6335a4219eff39ece3b2f90602 100644 (file)
@@ -57,6 +57,8 @@
 
 // QT Includes
 #include <qinputdialog.h>
+#include <qmessagebox.h>
+#include <qcursor.h>
 
 //VRV: porting on Qt 3.0.5
 #if QT_VERSION >= 0x030005
@@ -138,7 +140,7 @@ void FilterGUI::initialize( CAM_Application* app )
 {
   SalomeApp_Module::initialize( app );
 
-  QWidget* parent = application()->desktop();
+//   QWidget* parent = application()->desktop();
 
   createFilterAction(  111, "OPEN" );
 
@@ -164,12 +166,32 @@ void FilterGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QStri
   }
 }
 
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+SALOME_FILTER::FILTER_Gen_ptr FilterGUI::InitFilterGen() const
+{
+  SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
+  Engines::Component_var comp =
+    SALOME_LifeCycleCORBA(app->namingService()).FindOrLoad_Component( "FactoryServer", "FILTER" );
+
+  MESSAGE("_________________________________________");
+  SALOME_FILTER::FILTER_Gen_var clr = SALOME_FILTER::FILTER_Gen::_narrow(comp);
+  ASSERT(!CORBA::is_nil(clr));
+  return clr._retn();
+}
+
 QString FilterGUI::engineIOR() const
 {
-//   SALOME_FILTER::MED_Gen_ptr aMedGen = InitMedGen();
-//   if ( !CORBA::is_nil( aMedGen) )
-//     return QString( getApp()->orb()->object_to_string( aMedGen ));
-  return QString( "" );
+  QString anIOR( "" );
+  SALOME_FILTER::FILTER_Gen_ptr aFilterGen = InitFilterGen();
+  if ( !CORBA::is_nil( aFilterGen) ){
+    CORBA::String_var objStr = getApp()->orb()->object_to_string( aFilterGen );
+    anIOR = QString( objStr.in() );
+  }
+  return anIOR;
 }
 
 void FilterGUI::windows( QMap<int, int>& mappa ) const
@@ -280,12 +302,31 @@ bool FilterGUI::OnGUIEvent (int theCommandID)
       {
        MESSAGE("command " << theCommandID << " activated");
 
-       try {
-         SelectParams *filter = new SelectParams(_sel);
-         QFrame *fr = filter->buildFrame();
-         fr->show();
+       if(_sel){
+         SelectParams *filter;
+         try {
+           application()->desktop()->setCursor(QCursor(Qt::WaitCursor));
+           filter = new SelectParams(this,_sel);
+           filter->exec();
+           application()->desktop()->setCursor(QCursor(Qt::ArrowCursor));
+           _sel = NULL;
+         }
+         catch ( SALOME_Exception& S_ex ) {
+           delete _sel;
+           _sel=NULL;
+           MESSAGE("Select an input Field in MED file before filtering!!");
+           QMessageBox::information( application()->desktop(),
+                                     "Filtering",
+                                     "Unable to select parameters for filtering.\n"
+                                     "You must select a reference field in a MED file before." );
+         }
        }
-       catch ( SALOME_Exception& S_ex ) {
+       else{
+         MESSAGE("Select an input Field in MED file before filtering!!");
+         QMessageBox::information( application()->desktop(),
+                                   "Filtering",
+                                   "Unable to select parameters for filtering.\n"
+                                   "You must select a reference field in a MED file before." );
        }
        break;
       }
@@ -299,17 +340,14 @@ bool FilterGUI::OnGUIEvent (int theCommandID)
                                        filtersList,
                                        tr("FILTER_MEN_IMPORT"),
                                        true);
-       if (!file.isEmpty() )
-         {
-           if(_sel) delete _sel;
-           _sel = new SelectField(file);
-           QFrame *fr = _sel->buildFrame();
-           fr->show();
+       if (!file.isEmpty() ){
+         _sel = new SelectField(this,file);
+         if ( _sel->exec() == QDialog::Rejected ){
+           delete _sel;
+           _sel = NULL;
          }
-       else{
-         if(_sel) delete _sel;
-         _sel = NULL;
        }
+
         break;
       }
     }
index 9ec37d3876094a798bc3e21f8a78742f5042a119..6dd8229e38a237fd9045030b2de0c75d198f4bd2 100644 (file)
@@ -39,6 +39,8 @@ public:
 
   virtual void contextMenuPopup( const QString&, QPopupMenu*, QString& );
 
+  SALOME_FILTER::FILTER_Gen_ptr InitFilterGen() const;
+
   static void setOrb();
 
   void EmitSignalCloseAllDialogs();
index c795c9807fd11073af46625302809175b7efc897..7bada7fe70c77f1845e13bce3950ebcf32d9ea54 100644 (file)
@@ -45,8 +45,8 @@ PO_FILES = \
 
 # Libraries targets
 LIB = libFILTER.la
-LIB_SRC = FilterGUI.cxx FilterGUI_Selection.cxx SelectParams.cxx SelectField.cxx
-LIB_MOC = FilterGUI.h SelectParams.h SelectField.h
+LIB_SRC = FilterGUI.cxx FilterGUI_Selection.cxx SelectParams.cxx SelectField.cxx FILTERGUI_Utils.cxx
+LIB_MOC = FilterGUI.h SelectParams.h SelectField.h FILTERGUI_Utils.h
 
 LIB_CLIENT_IDL = SALOMEDS.idl SALOME_Exception.idl SALOME_Component.idl \
                  FILTER_Gen.idl \
index 164e7a6e85d88eb44407c041c43c75630b5846e6..202588101bada200f2145708908f205e633d4234 100644 (file)
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
+using namespace std;
+
 #include "SelectField.h"
+#include "MEDMEM_define.hxx"
 
 #include <qgroupbox.h>
 #include <qframe.h>
 #include <qlistview.h>
 #include <qslider.h>
 #include <qlabel.h>
-
-SelectField::SelectField(const QString& file)
-  : _file(file),
-    _mesh(0),
-    _field(0),
+#include <qpushbutton.h>
+
+SelectField::SelectField(FilterGUI* theModule,const QString& file, 
+                        const char* name,
+                        bool modal, WFlags fl)
+  : QDialog(FILTER::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
+    myFilterGUI( theModule ),
+    _file(file),
+    _mesh(NULL),
+    _field(NULL),
     _ts(0),
-    _myList( 0 ),
-    _myLab( 0 ),
-    _mySlider( 0 ),
-  _fr( 0 )
-{
-}
-
-SelectField::~SelectField()
-{
-  cout << "destructor called" << endl;
-}
-
-QFrame* SelectField::buildFrame()
+    _dimMesh(-1)
 {
   QListViewItem *element;
 
-  cout << "File: " << _file << endl;
   SCRUTE(_file);
-  _med = new ::MED(MED_DRIVER,_file);
-  deque<string> meshesNames = _med->getMeshNames();
-  int numberOfMeshes = meshesNames.size();
-  
-  deque<string> fieldsNames = _med->getFieldNames();
-  int numberOfFields = fieldsNames.size();
+  _filter = myFilterGUI->InitFilterGen();
+  _filter->loadMED(_file);
+  SALOME_FILTER::StrSeq* meshesNames = _filter->getMeshNames();
+  int numberOfMeshes = (*meshesNames).length();
 
-  QFrame* _fr = new QFrame( 0, "myframe" );
+  SALOME_FILTER::StrSeq* fieldsNames = _filter->getFieldNames();
+  int numberOfFields = (*fieldsNames).length();
 
-  QGridLayout* _lay = new QGridLayout( _fr, 1, 1 );
+  QGridLayout* _lay = new QGridLayout( this, 1, 1 );
 
-  QGroupBox* _GroupC1 = new QGroupBox( _fr, "GroupC1" );
+  QGroupBox* _GroupC1 = new QGroupBox( this, "GroupC1" );
   _lay->addWidget( _GroupC1,0,0 );
 
-  MESSAGE(basename(_file));
-  QString qs("File : ");
-  qs.append(basename(_file));
+  MESSAGE(basename((char*)(_file.ascii())));
+  QString qs(tr("FILTER_FILE"));
+  qs.append(basename((char*)(_file.ascii())));
   _GroupC1->setTitle(qs);
   _GroupC1->setColumnLayout(0, Qt::Vertical );
   _GroupC1->layout()->setSpacing( 0 );
@@ -79,38 +74,67 @@ QFrame* SelectField::buildFrame()
 
   int row = 0;
 
-  // 0)  tree to visualize meshes and fields
+  // 0)  label to select field on 3D mesh
+  _myGroupLayout->addWidget( new QLabel(tr("FILTER_SEL_3D"),_GroupC1), row, 0 );
+  row++;
+
+  // 1)  tree to visualize meshes and fields
   _myList = new QListView( _GroupC1, "List of fields" );
-  _myList->setMinimumSize( 400, 400 );
-  _myList->setMaximumSize( 400, 400 );
+  _myList->setMinimumSize( 500, 500 );
+  _myList->setMaximumSize( 500, 500 );
   _myList->setRootIsDecorated(true);
-  _myList->addColumn("Name");
-  _myList->addColumn("Type");
+  _myList->addColumn(tr("FILTER_NAME"));
+  _myList->addColumn(tr("FILTER_TYPE"));
+  _myList->addColumn(tr("FILTER_DIM"));
 
   for(int i=0;i<numberOfMeshes;i++){
-    element = new QListViewItem( _myList, meshesNames[i], "Mesh" );
+    _dimMesh = _filter->getMeshDimension((*meshesNames)[i]);
+    char strd[4];
+    sprintf(strd,"%dD\0",_dimMesh);
+    element = new QListViewItem( _myList, QString((*meshesNames)[i]), tr("FILTER_MESH") ,strd);
     element->setExpandable(true);
     _myList->setOpen(element,true);
 
     for (int j=0; j<numberOfFields; j++){
-      deque<DT_IT_> myIteration = _med->getFieldIteration (fieldsNames[j]);
-      string meshName = _med->getField(fieldsNames[j],myIteration[0].dt,myIteration[0].it)->getSupport()->getMesh()->getName();
-      if( strcmp(meshName.c_str(),meshesNames[i].c_str()) == 0)
-       new QListViewItem( element, fieldsNames[j], "Field" );
+      SALOME_FILTER::DTITSeq *myIteration = _filter->getFieldIteration((*fieldsNames)[j]);
+      string meshName = _filter->getMeshName((*fieldsNames)[j],(*myIteration)[0].dt,(*myIteration)[0].it);
+      if( strcmp(meshName.c_str(),(*meshesNames)[i]) == 0){
+       int ent = _filter->getFieldEntity((*fieldsNames)[j],(*myIteration)[0].dt,(*myIteration)[0].it);
+       bool isOnAllElements = _filter->fieldIsOnAllElements((*fieldsNames)[j],(*myIteration)[0].dt,(*myIteration)[0].it);
+
+       char stre[10];
+       switch(ent){
+       case MED_EN::MED_CELL:
+         strcpy(stre,"on cells");
+         break;
+       case MED_EN::MED_FACE:
+         strcpy(stre,"on faces");
+         break;
+       case MED_EN::MED_EDGE:
+         strcpy(stre,"on edges");
+         break;
+       case MED_EN::MED_NODE:
+         strcpy(stre,"on nodes");
+         break;
+       }
+       QListViewItem *elem = new QListViewItem( element, QString((*fieldsNames)[j]), tr("FILTER_FIELD"),stre );
+       if( (_dimMesh != 3) || (ent != MED_EN::MED_NODE) || !isOnAllElements )
+         elem->setSelectable(false);
+      }
     }
 
     element->setSelectable(false);
-    _myGroupLayout->addWidget( _myList, row, 0 );
   }
+  _myGroupLayout->addWidget( _myList, row, 0 );
   row++;
 
-  // 1)  label for time steps
-  _myLab = new QLabel("Select a time step:",_GroupC1);
+  // 2)  label for time steps
+  _myLab = new QLabel(tr("FILTER_SEL_TS"),_GroupC1);
   _myLab->hide();
   _myGroupLayout->addWidget( _myLab, row, 0 );
   row++;
 
-  // 2)  slider to visualize time steps
+  // 3)  slider to visualize time steps
   _mySlider = new QSlider(_GroupC1);
   _mySlider->setOrientation(Qt::Horizontal);
   _mySlider->setTickmarks(QSlider::Below);
@@ -119,23 +143,60 @@ QFrame* SelectField::buildFrame()
   _mySlider->hide();
   row++;
 
+  // 4) buttons Ok, Cancel and Help
+  _GroupButtons = new QGroupBox(_GroupC1, "GroupButtons");
+  _GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, _GroupButtons->sizePolicy().hasHeightForWidth()));
+//   _GroupButtons->setGeometry(QRect(10, 10, 281, 48));
+  _GroupButtons->setTitle(tr("" ));
+  _GroupButtons->setColumnLayout(0, Qt::Vertical);
+  _GroupButtons->layout()->setSpacing(0);
+  _GroupButtons->layout()->setMargin(0);
+  _GroupButtonsLayout = new QGridLayout(_GroupButtons->layout());
+  _GroupButtonsLayout->setAlignment(Qt::AlignTop);
+  _GroupButtonsLayout->setSpacing(6);
+  _GroupButtonsLayout->setMargin(11);
+  _buttonHelp = new QPushButton(_GroupButtons, "buttonHelp");
+  _buttonHelp->setText(tr("FILTER_BUT_HELP" ));
+  _buttonHelp->setAutoDefault(TRUE);
+  _GroupButtonsLayout->addWidget(_buttonHelp, 0, 2);
+  _buttonCancel = new QPushButton(_GroupButtons, "buttonClose");
+  _buttonCancel->setText(tr("FILTER_BUT_CANCEL" ));
+  _buttonCancel->setAutoDefault(TRUE);
+  _GroupButtonsLayout->addWidget(_buttonCancel, 0, 1);
+  _buttonOk = new QPushButton(_GroupButtons, "buttonOk");
+  _buttonOk->setText(tr("FILTER_BUT_OK" ));
+  _buttonOk->setAutoDefault(TRUE);
+  _GroupButtonsLayout->addWidget(_buttonOk, 0, 0);
+  _myGroupLayout->addWidget( _GroupButtons, row, 0 );
+  row++;
+
   connect( _myList, SIGNAL(clicked(QListViewItem *)), this, SLOT(fieldSelected(QListViewItem *)));
   connect( _mySlider, SIGNAL(sliderReleased()), this, SLOT(tsSelected()));
+  connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
+  connect(_buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
+  connect(_buttonHelp, SIGNAL(clicked()),   this, SLOT(ClickOnHelp()));
 
-  return _fr;
+}
+
+SelectField::~SelectField()
+{
+  // no need to delete child widgets, Qt does it all for us
+  cout << "SelectField: destructor called" << endl;
+  _filter->unloadMED();
 }
 
 void SelectField::fieldSelected(QListViewItem *lvi)
 {
   if(lvi){
-    if( strcmp(lvi->text(1),"Field") == 0){
+    if( (strcmp(lvi->text(1),"Field") == 0) && (_dimMesh == 3) ){
       _field = lvi->text(0);
       _mesh = lvi->parent()->text(0);
-      deque<DT_IT_> myIteration = _med->getFieldIteration (lvi->text(0));
-      int numberOfIteration = myIteration.size();
+//       deque<DT_IT_> myIteration = _filterMED->getFieldIteration(lvi->text(0));
+      SALOME_FILTER::DTITSeq *myIteration = _filter->getFieldIteration(lvi->text(0));
+      int numberOfIteration = (*myIteration).length();
       if( numberOfIteration > 1 ){
-       _mySlider->setRange(myIteration[0].dt,
-                           myIteration[numberOfIteration-1].dt);
+       _mySlider->setRange((*myIteration)[0].dt,
+                           (*myIteration)[numberOfIteration-1].dt);
        _myLab->show();
        _mySlider->show();
       }
@@ -156,3 +217,20 @@ void SelectField::tsSelected()
   MESSAGE("Field " << _field );
   MESSAGE("Time step " << _ts );
 }
+
+void SelectField::ClickOnOk()
+{
+  MESSAGE("click on Ok");
+  accept();
+}
+
+void SelectField::ClickOnCancel()
+{
+  MESSAGE("click on Cancel");
+  reject();
+}
+
+void SelectField::ClickOnHelp()
+{
+  MESSAGE("click on Help");
+}
index 18f0ab96f98fa301adc40b023d3bf3df3f59baf1..7b7ef941cbb7b9db1604262fd5c52465b6a4f67d 100644 (file)
 #define SELECTFIELD_HEADER
 
 #include "utilities.h"
-#include "MEDMEM_Med.hxx"
+#include "SalomeApp_Application.h"
 #include <SalomeApp_Module.h>
 #include <SUIT_Desktop.h>
+#include <qdialog.h>
+#include "FilterGUI.h"
+#include "FILTERGUI_Utils.h"
+#include CORBA_SERVER_HEADER(FILTER_Gen)
 
 #include <SALOMEconfig.h>
 class QListView;
@@ -34,37 +38,47 @@ class QSlider;
 class QGridLayout;
 class QGroupBox;
 class QLabel;
+class QPushButton;
 
-class SelectField: public QObject
+class SelectField: public QDialog
 {
   Q_OBJECT
 
 public:
-  SelectField(const QString& file);
+  SelectField(FilterGUI*,
+             const QString& file,
+             const char* name = 0,
+             bool modal = FALSE,
+             WFlags fl = 0);
   virtual ~SelectField();
 
-  virtual QFrame*  buildFrame();
   QString getFile() { return _file; }
   QString getMesh() { return _mesh; }
   QString getField() { return _field; }
   int getTimeStep() { return _ts; }
+  SALOME_FILTER::FILTER_Gen_ptr getFilter() {return _filter;} /* current filter object */
+  FilterGUI* myFilterGUI;              /* Current FilterGUI object */
 
 protected:
 
 protected slots:
   virtual void     fieldSelected(QListViewItem *lvi);
   virtual void     tsSelected();
+  virtual void     ClickOnOk();
+  virtual void     ClickOnCancel();
+  virtual void     ClickOnHelp();
 
 private:
-  int _ts;
-  QGridLayout *_myGroupLayout, *_lay;
-  QGroupBox* _GroupC1;
+  int _ts, _dimMesh;
+  QGridLayout *_myGroupLayout, *_GroupButtonsLayout, *_lay;
+  QGroupBox* _GroupC1, *_GroupButtons;
   QFrame *_fr;
   QString _file, _mesh, _field;
   QListView *_myList;
   QLabel *_myLab;
   QSlider *_mySlider;
-  ::MEDMEM::MED *_med;
+  QPushButton* _buttonCancel, * _buttonHelp, * _buttonOk;
+  SALOME_FILTER::FILTER_Gen_ptr _filter;
 };
 
 #endif
index f959ef4f43a2efd36b9c5ffb07c0bc3e1ae6bf23..5d5e167122ede322ac0bb036a2702b93bff9d048 100644 (file)
@@ -21,7 +21,8 @@
 #include <stdlib.h>
 #include <math.h>
 #include "SelectParams.h"
-#include "utilities.h"
+#include "MEDMEM_MedMeshDriver.hxx"
+#include "MEDMEM_EnsightMeshDriver.hxx"
 
 #include <SUIT_FileDlg.h>
 
 #include <qradiobutton.h>
 #include <qpushbutton.h>
 #include <qfiledialog.h>
+#include <qmessagebox.h>
+#include <qcursor.h>
 
-SelectParams::SelectParams(SelectField *sel)
-  : _size(1024),
-  _myExpr( 0 ),
-  _myFunc( 0 ),
-  _myFieldB( 0 ),
-  _myLinear( 0 ),
-  _myHisto( 0 ),
-  _myNbThresh( 0 ),
-  _myCutNeg( 0 ),
-  _myOneThresh( 0 ),
-  _myTwoThresh( 0 ),
-  _myArea( 0 ),
-  _myVThresh( 0 ),
-  _myOutFile( 0 ),
-  _myOFB( 0 ),
-  _myProc( 0 ),
-  _myFScale( 0 ),
-  _myGroupLayout( 0 ),
-  _myGroupLayout2( 0 ),
-  _myPlot( 0 ),
-  _GroupC1( 0 ),
-  _GroupC2( 0 ),
-  _lay( 0 ),
-  _fr( 0 )
+SelectParams::SelectParams(FilterGUI* theModule,SelectField *sel,
+                          const char* name,
+                          bool modal, WFlags fl) throw(SALOME_Exception)
+  : QDialog(FILTER::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),_size(1024),_sel(sel)
 {
-  _x = new double[_size];
-  _y = new double[_size];
+  MESSAGE("SelectParams constructor");
   if(sel){
+    // read reference field values
+    _filter = sel->getFilter();
+
+    // Get reference field and time step
     _inputFile = sel->getFile();
     _inputMesh = sel->getMesh();
     _inputField = sel->getField();
     _inputTS = sel->getTimeStep();
-    if( _inputMesh.isNull() || _inputField.isNull() ){
-      MESSAGE("Select an input Field in MED file before filtering!!");
-      throw SALOME_Exception("Salome Exception");
-    }
-  }
-  else{
-    MESSAGE("Select an input Field in MED file before filtering!!");
-    throw SALOME_Exception("Salome Exception");
+
+    if( _inputFile.isEmpty() || _inputMesh.isEmpty() || _inputField.isEmpty())
+      throw SALOME_Exception("Select an input Field in MED file before filtering!!");
+    
+    _filter->readReferenceField(_inputMesh,_inputField,_inputTS);
+
+    // Build QT widgets
+    buildFrame();
   }
+  // if no reference field selection: throw exception
+  else
+    throw SALOME_Exception("Select an input Field in MED file before filtering!!");
+
+  // Allocate histogram arrays
+  _x = new double[_size];
+  _y = new double[_size];
 
 }
 
 SelectParams::~SelectParams()
 {
-  cout << "destructor called" << endl;
-//   delete _x;
-//   delete _y;
-//   delete _myExpr;
-//   delete _myFunc;
-//   delete _myFieldB;
-//   delete _myLinear;
-//   delete _myHisto;
-//   delete _myNbThresh;
-//   delete _myCutNeg;
-//   delete _myOneThresh;
-//   delete _myTwoThresh;
-//   delete _myArea;
-//   delete _myVThresh;
-//   delete _myOutFile;
-//   delete _myOFB;
-//   delete _myProc;
-//   delete _myFScale;
-//   delete _myGroupLayout;
-//   delete _myGroupLayout2;
-//   delete _myPlot;
-//   delete _GroupC1;
-//   delete _GroupC2;
-//   delete _lay;
-//   delete _fr;
+  cout << "SelectParams: destructor called" << endl;
+
+  // destrcution of histogram arrays
+  delete _x;
+  delete _y;
+  
+  // destruction of SelectField object and Filter object in it
+  delete _sel;
 }
 
-QFrame* SelectParams::buildFrame()
+void SelectParams::buildFrame()
 {
-  QFrame* _fr = new QFrame( 0, "myframe" );
-  QGridLayout* _lay = new QGridLayout( _fr, 1, 2 );
+  // build widgets for select filtering parameters
+  QGridLayout* _lay = new QGridLayout( this, 1, 2 );
 
-  QGroupBox* _GroupC1 = new QGroupBox( _fr, "GroupC1" );
+  QGroupBox* _GroupC1 = new QGroupBox( this, "GroupC1" );
   _lay->addWidget( _GroupC1,0,0 );
 
-  _GroupC1->setTitle( tr( "Filtering parameters"  ) );
+  _GroupC1->setTitle( tr( "FILTER_PARAMS"  ) );
   _GroupC1->setColumnLayout(0, Qt::Vertical );
   _GroupC1->layout()->setSpacing( 0 );
   _GroupC1->layout()->setMargin( 0 );
@@ -132,139 +108,171 @@ QFrame* SelectParams::buildFrame()
 
   int row = 0;
 
-  QString qs1("Input File : ");
-  qs1.append(basename(_inputFile));
+  QString qs1(tr("FILTER_INPUT_FILE"));
+  qs1.append(basename((char*)(_inputFile.ascii())));
   _myGroupLayout->addWidget( new QLabel( qs1, _GroupC1 ), row, 0 );
   row++;
 
-  QString qs2("Input Mesh : ");
+  QString qs2(tr("FILTER_INPUT_MESH"));
   qs2.append(_inputMesh);
   _myGroupLayout->addWidget( new QLabel( qs2, _GroupC1 ), row, 0 );
   row++;
 
-  QString qs3("Input Field : ");
+  QString qs3(tr("FILTER_INPUT_FIELD"));
   qs3.append(_inputField);
   _myGroupLayout->addWidget( new QLabel( qs3, _GroupC1 ), row, 0 );
   row++;
 
+  QString qs4(tr("FILTER_INPUT_TS"));
   char strTS[128];
-  sprintf(strTS,"Input Time Step : %d\0",_inputTS);
-  QString qs4(strTS);
+  sprintf(strTS,"%d\0",_inputTS);
+  qs4.append(strTS);
   _myGroupLayout->addWidget( new QLabel( qs4, _GroupC1 ), row, 0 );
   row++;
 
   // 0)  field function to calculate histogram (radiogroup)
-  _myFunc = new QButtonGroup( "Select function on field", _GroupC1 );
+  _myFunc = new QButtonGroup( tr("FILTER_SELECT_FUNC"), _GroupC1 );
   _myFunc->setExclusive( true );
   _myFunc->setColumnLayout( 0, Qt::Horizontal );
 
-  _myFieldB = new QRadioButton( "Field", _myFunc );
+  _myFieldB = new QRadioButton( tr("FILTER_FIELD"), _myFunc );
   _myFieldB->setChecked(true);
 
   QGridLayout* convLay = new QGridLayout( _myFunc->layout() );
   convLay->addWidget( _myFieldB, 0, 0 );
-  convLay->addWidget( _myCutNeg = new QRadioButton( "Gradient", _myFunc ), 0, 1 );
+  convLay->addWidget( _myGradB = new QRadioButton( tr("FILTER_GRADIENT"), _myFunc ), 0, 1 );
   _myGroupLayout->addWidget( _myFunc, row, 0 );
   row++;
 
-  // 1)  scale of histogram (radiogroup)
-  _myFScale = new QButtonGroup( "Type of display", _GroupC1 );
+  // 01)  histogram size (line edit)
+  _myHSize = new QButtonGroup( tr(""), _GroupC1 );
+  _myHSize->setExclusive( true );
+  _myHSize->setColumnLayout( 0, Qt::Horizontal );
+  QGridLayout* shLay = new QGridLayout( _myHSize->layout() );
+  shLay->addWidget( _myLSH = new QLabel( tr("FILTER_SIZE_HISTO") , _myHSize ), 0, 0 );
+  shLay->addWidget( _myLESH = new QLineEdit( "1024", _myHSize ), 0, 1 );
+  _myGroupLayout->addWidget( _myHSize, row, 0 );
+  row++;
+
+  // 1)  display histogram button (pushbutton)
+  _myHisto = new QPushButton( "", _GroupC1 );
+  _myHisto->setText(tr("FILTER_DISPLAY_HISTO"));
+  _myHisto->setAutoDefault(FALSE);
+  _myGroupLayout->addWidget( _myHisto, row, 0 );
+  row++;
+
+  // 2)  scale of histogram (radiogroup)
+  _myFScale = new QButtonGroup( tr("FILTER_TYPE_DISPLAY"), _GroupC1 );
   _myFScale->setExclusive( true );
   _myFScale->setColumnLayout( 0, Qt::Horizontal );
 
-  _myLinear = new QRadioButton( "Linear", _myFScale );
+  _myLinear = new QRadioButton( tr("FILTER_LINEAR"), _myFScale );
   _myLinear->setChecked(true);
+  _myLog = new QRadioButton( tr("FILTER_LOG"), _myFScale );
+  _myFScale->setDisabled(true);
 
   QGridLayout* scaleLay = new QGridLayout( _myFScale->layout() );
   scaleLay->addWidget( _myLinear, 0, 0 );
-  scaleLay->addWidget( new QRadioButton( "Logarithm", _myFScale ), 0, 1 );
+  scaleLay->addWidget( _myLog, 0, 1 );
   _myGroupLayout->addWidget( _myFScale, row, 0 );
   row++;
 
-  // 2)  display histogram button (pushbutton)
-  _myHisto = new QPushButton( "Display Histogram", _GroupC1 );
-  _myHisto->setText("Display Histogram");
-  _myHisto->setAutoDefault(TRUE);
-  _myHisto->setDefault(TRUE);
-  _myGroupLayout->addWidget( _myHisto, row, 0 );
-  row++;
-
   // 3)  number of thresholds (radiogroup)
-  _myNbThresh = new QButtonGroup( "Select number of thresholds", _GroupC1 );
+  _myNbThresh = new QButtonGroup( tr("FILTER_SEL_THRESH"), _GroupC1 );
   _myNbThresh->setExclusive( true );
   _myNbThresh->setColumnLayout( 0, Qt::Horizontal );
   QGridLayout* nbtLay = new QGridLayout( _myNbThresh->layout() );
-  nbtLay->addWidget( _myOneThresh = new QRadioButton( "One threshold", _myNbThresh ), 0, 0 );
-  nbtLay->addWidget( _myTwoThresh = new QRadioButton( "Two thresholds", _myNbThresh ), 0, 1 );
+  nbtLay->addWidget( _myOneThresh = new QRadioButton( tr("FILTER_ONE_THRESH"), _myNbThresh ), 0, 0 );
+  nbtLay->addWidget( _myTwoThresh = new QRadioButton( tr("FILTER_TWO_THRESH"), _myNbThresh ), 0, 1 );
   _myGroupLayout->addWidget( _myNbThresh, row, 0 );
 
-//   _myOneThresh->setChecked(true);
-  _myNbThresh->hide();
+  _myOneThresh->setChecked(true);
+  _myNbThresh->setDisabled(true);
   row++;
 
   // 4)  reference area on thresholds (radiogroup)
-  _myArea = new QButtonGroup( "Select reference area", _GroupC1 );
+  _myArea = new QButtonGroup( tr("FILTER_REF_AREA"), _GroupC1 );
   _myArea->setExclusive( true );
   _myArea->setColumnLayout( 0, Qt::Horizontal );
   QGridLayout* areaLay = new QGridLayout( _myArea->layout() );
-  areaLay->addWidget( _myInt = new QRadioButton( "Interior", _myArea ), 0, 0 );
-  areaLay->addWidget( _myExt = new QRadioButton( "Exterior", _myArea ), 0, 1 );
+  areaLay->addWidget( _myInt = new QRadioButton( tr("FILTER_BOTTOM"), _myArea ), 0, 0 );
+  areaLay->addWidget( _myExt = new QRadioButton( tr("FILTER_UP"), _myArea ), 0, 1 );
   _myGroupLayout->addWidget( _myArea, row, 0 );
 
   _myExt->setChecked(true);
-  _myArea->hide();
+  _myArea->setDisabled(true);
   row++;
 
   // 5)  threshold values (line edit)
-  _myVThresh = new QButtonGroup( "Threshold values", _GroupC1 );
+  _myVThresh = new QButtonGroup( tr("FILTER_TRESH_VAL"), _GroupC1 );
   _myVThresh->setExclusive( true );
   _myVThresh->setColumnLayout( 0, Qt::Horizontal );
   QGridLayout* ftLay = new QGridLayout( _myVThresh->layout() );
-  ftLay->addWidget( _myLFT = new QLabel( "threshold value   " , _myVThresh ), 0, 0 );
+  ftLay->addWidget( _myLFT = new QLabel( tr("FILTER_VAL_TRESH") , _myVThresh ), 0, 0 );
   ftLay->addWidget( _myLEFT = new QLineEdit( "", _myVThresh ), 0, 1 );
-  ftLay->addWidget( _myLST = new QLabel( "2d threshold value" , _myVThresh ), 1, 0 );
+  ftLay->addWidget( _myLST = new QLabel( tr("FILTER_VAL_2_TRESH") , _myVThresh ), 1, 0 );
   ftLay->addWidget( _myLEST = new QLineEdit( "", _myVThresh ), 1, 1 );
   _myGroupLayout->addWidget( _myVThresh, row, 0 );
 
-  _myVThresh->hide();
+  _myVThresh->setDisabled(true);
   _myLST->hide();
   _myLEST->hide();
   row++;
 
   // 6)  output file name (line edit)
-  _myOutFile = new QButtonGroup( "Output file name", _GroupC1 );
+  _myOutFile = new QButtonGroup( tr("FILTER_OUT_FILE"), _GroupC1 );
   _myOutFile->setExclusive( true );
   _myOutFile->setColumnLayout( 0, Qt::Horizontal );
 
-  _myOFB = new QPushButton( "Browse", _myOutFile );
-  _myOFB->setText("Browse");
-  _myOFB->setAutoDefault(TRUE);
+  _myOFB = new QPushButton( "", _myOutFile );
+  _myOFB->setText(tr("FILTER_BROWSE"));
+  _myOFB->setAutoDefault(FALSE);
 
   QGridLayout* outLay = new QGridLayout( _myOutFile->layout() );
   outLay->addWidget( _myOFB, 0, 0 );
   outLay->addWidget( _myOFN = new QLineEdit( "", _myOutFile ), 0, 1 );
   _myGroupLayout->addWidget( _myOutFile, row, 0 );
 
-  _myOutFile->hide();
+  _myOutFile->setDisabled(true);
   row++;
 
-  // 8)  process button (pushbutton)
-  _myProc = new QPushButton( "Process", _GroupC1 );
-  _myProc->setText("Process");
-  _myProc->setAutoDefault(TRUE);
-  _myGroupLayout->addWidget( _myProc, row, 0 );
-  _myProc->hide();
+  // 8)  buttons Process, Close and Help 
+  _GroupButtons = new QGroupBox(_GroupC1, "GroupButtons");
+  _GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, _GroupButtons->sizePolicy().hasHeightForWidth()));
+  _GroupButtons->setTitle(tr("" ));
+  _GroupButtons->setColumnLayout(0, Qt::Vertical);
+  _GroupButtons->layout()->setSpacing(0);
+  _GroupButtons->layout()->setMargin(0);
+  _GroupButtonsLayout = new QGridLayout(_GroupButtons->layout());
+  _GroupButtonsLayout->setAlignment(Qt::AlignTop);
+  _GroupButtonsLayout->setSpacing(6);
+  _GroupButtonsLayout->setMargin(11);
+  _myProc = new QPushButton(_GroupButtons, "buttonProcess");
+  _myProc->setText(tr("FILTER_PROCESS"));
+  _myProc->setAutoDefault(FALSE);
+  _GroupButtonsLayout->addWidget(_myProc, 0, 0);
+  _buttonHelp = new QPushButton(_GroupButtons, "buttonHelp");
+  _buttonHelp->setText(tr("FILTER_BUT_HELP" ));
+  _buttonHelp->setAutoDefault(FALSE);
+  _GroupButtonsLayout->addWidget(_buttonHelp, 0, 2);
+  _buttonCancel = new QPushButton(_GroupButtons, "buttonCancel");
+  _buttonCancel->setText(tr("FILTER_BUT_CANCEL" ));
+  _buttonCancel->setAutoDefault(FALSE);
+  _GroupButtonsLayout->addWidget(_buttonCancel, 0, 1);
+  _myGroupLayout->addWidget( _GroupButtons, row, 0 );
+  _GroupButtons->setDisabled(true);
   row++;
 
-  _GroupC2 = new QGroupBox( _fr, "GroupC2" );
+  _GroupC2 = new QGroupBox( this, "GroupC2" );
   _lay->addWidget( _GroupC2,0,1 );
 
-  _GroupC2->setTitle( tr( "Histogram"  ) );
+  _GroupC2->setTitle( tr( "FILTER_HISTO" ) );
   _GroupC2->setColumnLayout(0, Qt::Vertical );
   _GroupC2->layout()->setSpacing( 0 );
   _GroupC2->layout()->setMargin( 0 );
   _myGroupLayout2 = new QGridLayout( _GroupC2->layout() );
 
+  // 9)  histogram curve
   _myPlot = new QwtPlot(_GroupC2);
   _myHistoCurve = _myPlot->insertCurve( QString() );
   _myPlot->setCurvePen( _myHistoCurve, QPen( Qt::red, 1 ) );
@@ -272,90 +280,182 @@ QFrame* SelectParams::buildFrame()
 
   _myGroupLayout2->addWidget( _myPlot, 0, 0 );
 
-  // 9)  reduction rate (label)
-  _myGroupLayout2->addWidget( _myLRR = new QLabel( "reduction rate = 0.23", _GroupC2 ), 1, 0 );
+  // 10)  reduction rate (label)
+  QString qs5(tr("FILTER_RED_RATE"));
+  qs5.append(" = 0.5");
+  _myLRR = new QLabel( qs5, _GroupC2 );
+  _myGroupLayout2->addWidget( _myLRR, 1, 0 );
 
   _GroupC2->hide();
-  _myLRR->hide();
 
   _myHistoFThresh = _myPlot->insertCurve( QString() );
   _myPlot->setCurvePen( _myHistoFThresh, QPen( Qt::black, 1 ) );
   _myHistoSThresh = _myPlot->insertCurve( QString() );
   _myPlot->setCurvePen( _myHistoSThresh, QPen( Qt::black, 1 ) );
 
-  connect( _myHisto, SIGNAL(clicked()), this, SLOT(displayHisto()));
+  connect( _myGradB, SIGNAL(clicked()), this, SLOT(gradSelected()));
+  connect( _myLESH, SIGNAL(returnPressed()), this, SLOT(enterSHisto()));
+  connect( _myHisto, SIGNAL(clicked()), this, SLOT(updateHisto()));
+  connect( _myLinear, SIGNAL(clicked()), this, SLOT(scaleSelected()));
+  connect( _myLog, SIGNAL(clicked()), this, SLOT(scaleSelected()));
   connect( _myOneThresh, SIGNAL(clicked()), this, SLOT(nbThreshSelected()));
   connect( _myTwoThresh, SIGNAL(clicked()), this, SLOT(nbThreshSelected()));
   connect( _myInt, SIGNAL(clicked()), this, SLOT(areaSelected()));
   connect( _myExt, SIGNAL(clicked()), this, SLOT(areaSelected()));
-  connect( _myLEFT, SIGNAL(returnPressed()), this, SLOT(displayFThresh()));
-  connect( _myLEST, SIGNAL(returnPressed()), this, SLOT(displaySThresh()));
+  connect( _myLEFT, SIGNAL(returnPressed()), this, SLOT(enterFThresh()));
+  connect( _myLEST, SIGNAL(returnPressed()), this, SLOT(enterSThresh()));
   connect( _myPlot, SIGNAL(plotMouseMoved(const QMouseEvent &)), this, SLOT(moveThresh(const QMouseEvent &)));
   connect( _myOFB, SIGNAL(clicked()), this, SLOT(getOutFileName()));
   connect( _myProc, SIGNAL(clicked()), this, SLOT(process()));
+  connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
+  connect(_buttonHelp, SIGNAL(clicked()),   this, SLOT(ClickOnHelp()));
 
-  calcHisto();
+  _GroupC2->setMinimumSize( 500, 500 );
+  _GroupC2->setMaximumSize( 500, 500 );
+  setMinimumSize( 750, 500 );
+  setMaximumSize( 750, 500 );
+
+}
+
+void SelectParams::gradSelected()
+{
+  try{
+    setCursor(QCursor(Qt::WaitCursor));
+    _filter->buildGradient();
+    setCursor(QCursor(Qt::ArrowCursor));
+  }
+  catch(SALOME_FILTER::FILTER_Gen::FilterError){
+    _myFieldB->setChecked(true);
+    QMessageBox::information( this,
+                             "Filtering",
+                             "Unable to calculate gradient on vector field.\n"
+                             "You must select a reference scalar field." );
+  }
+  catch(...){
+    MESSAGE("unknownException");
+  }
+}
+
+void SelectParams::enterSHisto()
+{
+  // Deallocate old histogram arrays
+  delete _x;
+  delete _y;
+
+  // get new histogram size
+  _size = atoi(_myLESH->text());
 
-  return _fr;
+  // Allocate new histogram arrays
+  _x = new double[_size];
+  _y = new double[_size];
+}
+
+void SelectParams::scaleSelected()
+{
+  // draw linear or log Y scale depend on user
+  if( _myLinear->isChecked() ){
+    _ymin = 0.0;
+    _myPlot->setAxisOptions(_myPlot->curveYAxis( _myHistoCurve ), QwtAutoScale::None );
+  }
+  else{
+    // set min to 0.1 for log scale
+    _ymin = 0.1;
+    _myPlot->setAxisOptions(_myPlot->curveYAxis( _myHistoCurve ), QwtAutoScale::Logarithmic );
+  }
+  _myPlot->setAxisScale( _myPlot->curveYAxis( _myHistoCurve ), _ymin, _ymax );
+  _myPlot->replot();
 }
 
 void SelectParams::nbThreshSelected()
 {
   if( _myOneThresh->isChecked() ){
-    _myInt->setText("bottom");
-    _myExt->setText("up");
-    _myLFT->setText("threshold value   ");
+    // if one threshold choice between bottom and up for reference area
+    _myInt->setText(tr("FILTER_BOTTOM"));
+    _myExt->setText(tr("FILTER_UP"));
+    _myLFT->setText(tr("FILTER_VAL_TRESH"));
     _myLST->hide();
     _myLEST->hide();
+    // draw first threshold
     displayFThresh();
+    // erase second threshold
     clearSThresh();
   }
   else{
-    _myInt->setText("interior");
-    _myExt->setText("exterior");
-    _myLFT->setText("1st threshold value");
+    // if two thresholds choice between interior and exterior fir reference area
+    _myInt->setText(tr("FILTER_INT"));
+    _myExt->setText(tr("FILTER_EXT"));
+    _myLFT->setText(tr("FILTER_VAL_1_TRESH"));
     if(_myLST->isHidden())
       _myLST->show();
     if(_myLEST->isHidden())
       _myLEST->show();
+    // draw two thresholds
     displayFThresh();
     displaySThresh();
   }
   calcRateRed();
-  if(_myArea->isHidden())
-    _myArea->show();
-  if(_myVThresh->isHidden())
-    _myVThresh->show();
-  if(_myLRR->isHidden())
-    _myLRR->show();
-  if(_myOutFile->isHidden())
-    _myOutFile->show();
-  if(_myProc->isHidden())
-    _myProc->show();
 }
 
 void SelectParams::areaSelected()
 {
+  // calculate reduction rate after thresholds selection
+  calcRateRed();
+}
+
+void SelectParams::enterFThresh()
+{
+  displayFThresh();
+  calcRateRed();
+}
+
+void SelectParams::enterSThresh()
+{
+  displaySThresh();
   calcRateRed();
 }
 
 void SelectParams::calcHisto()
 {
   char strth[128];
-  _xmin = -50.0;
-  _xmax = 50.0;
-  _ymax = 100.0;
-  _ymin = _ymax;
+  CORBA::Double min, max;
+  CORBA::Long size = _size;
+  SALOME_FILTER::LongSeq* histo;
+
+  if( _myFieldB->isChecked() ){
+    // calculate histogram values on field
+    _filter->getMinMax(min,max,SALOME_FILTER::F_FIELD);
+    histo = _filter->getHistogram(size,SALOME_FILTER::F_FIELD);
+  }
+  else{
+    // calculate histogram values on gradient
+     _filter->getMinMax(min,max,SALOME_FILTER::F_GRAD);
+    histo = _filter->getHistogram(size,SALOME_FILTER::F_GRAD);
+  }
+  _xmin = min;
+  _xmax = max;
+  vector<int> myh(_size);
+  for(int i=0;i<_size;i++)
+    myh[i] = (*histo)[i];
+
+  if( _myLinear->isChecked() )
+    _ymin = 0.0;
+  else
+    _ymin = 0.1;
+  _ymax = 0.0;
 
   for(int i=0;i<_size;i++){
+    // calculate absisses for histogram values
     _x[i]=_xmin+(i*(_xmax-_xmin))/_size;
-    _y[i]=80.*exp(-_x[i]*_x[i]/400.);
-    if( (_y[i] < _ymin) && (_y[i] != 0.0) )
-      _ymin = _y[i];
+    // set zero to 0.01 because pb of zeros in log display with qwt
+    if(myh[i])
+      _y[i]=(double)myh[i];
+    else
+      _y[i]=0.01;
+    if( _y[i] > _ymax )
+      _ymax = _y[i];
   }
-  _myPlot->setAxisScale( _myPlot->curveXAxis( _myHistoCurve ), _xmin, _xmax );
-  _myPlot->setAxisScale( _myPlot->curveYAxis( _myHistoCurve ), _ymin, _ymax );
-  _myPlot->setCurveData( _myHistoCurve, _x, _y, _size );
+
+  // init thresholds values
   _fthresh = (_xmin + _xmax)/2.0;
   _sthresh = (_xmin + 3.*_xmax)/4.0;
   sprintf(strth,"%g",_fthresh);
@@ -366,23 +466,50 @@ void SelectParams::calcHisto()
 
 void SelectParams::displayHisto()
 {
-  _qmap = _myPlot->canvasMap(_myPlot->curveXAxis( _myHistoCurve ));
-  _qmap.setDblRange(_xmin,_xmax);
+  // associate values to curve
+  _myPlot->setCurveData( _myHistoCurve, _x, _y, _size );
+  // give extrema values for each axis
+  _myPlot->setAxisScale( _myPlot->curveXAxis( _myHistoCurve ), _xmin, _xmax );
+  _myPlot->setAxisScale( _myPlot->curveYAxis( _myHistoCurve ), _ymin, _ymax );
   if( _myLinear->isChecked() )
     _myPlot->setAxisOptions(_myPlot->curveYAxis( _myHistoCurve ), QwtAutoScale::None );
   else
     _myPlot->setAxisOptions(_myPlot->curveYAxis( _myHistoCurve ), QwtAutoScale::Logarithmic );
+  // associate mapping to plot to move thresholds on display
+  _qmap = _myPlot->canvasMap(_myPlot->curveXAxis( _myHistoCurve ));
+  _qmap.setDblRange(_xmin,_xmax);
   _myPlot->replot();
-  if(_GroupC2->isHidden())
+}
+
+void SelectParams::enableWidgets()
+{
+  if(_GroupC2->isHidden()){
+    _myFScale->setEnabled(true);
+    _myNbThresh->setEnabled(true);
+    _myArea->setEnabled(true);
+    _myVThresh->setEnabled(true);
+    _myOutFile->setEnabled(true);
+    _GroupButtons->setEnabled(true);
     _GroupC2->show();
-  if(_myNbThresh->isHidden())
-    _myNbThresh->show();
+  }
+}
+
+void SelectParams::updateHisto()
+{
+  calcHisto();
+  displayHisto();
+  displayFThresh();
+  if( _myTwoThresh->isChecked() )
+    displaySThresh();
+  calcRateRed();
+  enableWidgets();
 }
 
 void SelectParams::displayFThresh()
 {
   _fthresh = atof(_myLEFT->text());
 
+  // draw first threshold curve
   for(int i=0;i<100;i++){
     _xft[i]=_fthresh;
     _yft[i]=((i-1)*_ymax)/100.0;
@@ -395,6 +522,7 @@ void SelectParams::displaySThresh()
 {
   _sthresh = atof(_myLEST->text());
 
+  // draw second threshold curve
   for(int i=0;i<100;i++){
     _xst[i]=_sthresh;
     _yst[i]=((i-1)*_ymax)/100.0;
@@ -407,6 +535,7 @@ void SelectParams::clearSThresh()
 {
   _sthresh = atof(_myLEST->text());
 
+  // erase second threshold curve
   for(int i=0;i<100;i++){
     _xst[i]=_sthresh;
     _yst[i]=0.0;
@@ -418,8 +547,11 @@ void SelectParams::clearSThresh()
 void SelectParams::moveThresh(const QMouseEvent &e)
 {
   char strth[128];
+
+  // move threshold curve with mouse
   int delta = abs(e.x()-_qmap.transform(_fthresh));
   if( delta < 5 ){
+    // moving first threshold curve
     sprintf(strth,"%g",_qmap.invTransform(e.x()));
     _myLEFT->setText(QString(strth));
     displayFThresh();
@@ -427,6 +559,7 @@ void SelectParams::moveThresh(const QMouseEvent &e)
   else if( _myTwoThresh->isChecked() ){
     delta = abs(e.x()-_qmap.transform(_sthresh));
     if( delta < 5 ){
+      // moving second threshold curve
       sprintf(strth,"%g",_qmap.invTransform(e.x()));
       _myLEST->setText(QString(strth));
       displaySThresh();
@@ -437,7 +570,8 @@ void SelectParams::moveThresh(const QMouseEvent &e)
 
 void SelectParams::getOutFileName()
 {
-  QString file = QFileDialog::getSaveFileName("/home",
+  // get output MED file name
+  QString file = QFileDialog::getSaveFileName("",
                                              "*.med",
                                              _myOFB,
                                              "save file dialog",
@@ -453,8 +587,9 @@ void SelectParams::getOutFileName()
 //                                true);
 }
 
-void SelectParams::process()
+void SelectParams::process() throw(SALOME_Exception)
 {
+  int nbthresh;
   string command;
 
   MESSAGE("Input MED File : "<<_inputFile);
@@ -462,10 +597,71 @@ void SelectParams::process()
   MESSAGE("Input Field : "<<_inputField);
   MESSAGE("Input Time Step : "<<_inputTS);
   MESSAGE("Output file name: " << _myOFN->text() );
-  command = "cd /export/home/secher/filtoo/example;filtoo -f s -o sf > /tmp/filter.log";
-  MESSAGE(command);
-  system(command.c_str());
-//   delete this;
+
+  setCursor(QCursor(Qt::WaitCursor));
+
+  MESSAGE("Generate Criteria");
+  // generate MED integer field (0 or 1) for filtoo input
+  try{
+    if( _myOneThresh->isChecked() )
+      nbthresh = 1;
+    else
+      nbthresh = 2;
+    SALOME_FILTER::ref_func rf;
+    if(_myFieldB->isChecked())
+      rf = SALOME_FILTER::F_FIELD;
+    else
+      rf = SALOME_FILTER::F_GRAD;
+    _filter->generateCriteria(nbthresh,_fthresh,_sthresh,_myExt->isChecked(),rf);
+  }
+  catch (SALOME_FILTER::FILTER_Gen::FilterError){
+    QMessageBox::information( this,
+                             "Filtering",
+                             "Unable to process filtering.\n"
+                             "You must select a reference field on nodes." );
+    reject();
+    return;
+  }
+
+  // create ensight input files to filtoo
+  try{
+    _filter->createEnsightInputFiles();
+  }
+  catch (SALOME_FILTER::FILTER_Gen::FilterError& ex){
+    throw SALOME_Exception(ex.error_msg);
+  }
+
+  // call filtoo
+  try{
+    _filter->filtering();
+  }
+  catch (SALOME_FILTER::FILTER_Gen::FilterError){
+    QMessageBox::information( this,
+                             "Filtering",
+                             "Unable to process filtering.\n"
+                             "FILTOO ERROR see /tmp/filter.log file." );
+    reject();
+    return;
+  }
+  // project input fields on new mesh
+  try{
+    _filter->projectFieldsOnDecimateMesh();
+  }
+  catch (SALOME_FILTER::FILTER_Gen::FilterError& ex){
+    throw SALOME_Exception(ex.error_msg);
+  }
+
+  // create new MED file with new mesh and fields
+  _filter->createMedOutputFile(_myOFN->text());
+
+  QMessageBox::information( this,
+                           "Filtering",
+                           "Filtering done.\n"
+                           "" );
+  // close the window
+  accept();
+
 }
 
 void SelectParams::calcRateRed()
@@ -473,8 +669,8 @@ void SelectParams::calcRateRed()
   int i1, i2, i;
   int atot=0, asel=0, atot1;
   double rateRed=0.0;
-  char strth[128];
 
+  // calculate reduction rate depend on reference area defined by threshold values
   i1 = (int)((double)_size * ( _fthresh - _xmin ) / ( _xmax - _xmin ));
   if( _myOneThresh->isChecked() ){
     for(i=0;i<i1;i++)
@@ -504,9 +700,23 @@ void SelectParams::calcRateRed()
       asel = atot - asel;
   }
   rateRed = (double)asel / (double) atot;
-  sprintf(strth,"reduction rate = %4.2g",rateRed);
-  _myLRR->setText( strth );
 
+  // display reduction rate value
+  QString qs(tr("FILTER_RED_RATE"));
+  char str[128];
+  sprintf(str," = %4.2g",rateRed);
+  qs.append(str);
+  _myLRR->setText( qs );
+
+}
 
+void SelectParams::ClickOnCancel()
+{
+  MESSAGE("click on Cancel");
+  reject();
 }
 
+void SelectParams::ClickOnHelp()
+{
+  MESSAGE("click on Help");
+}
index 54eee208a2a1bc70dc1d87ea22ec3a32d5bf378e..6771b5b6f95f398b0722d30fca80ca0e0bab0a34 100644 (file)
 #ifndef SELECTPARAMS_HEADER
 #define SELECTPARAMS_HEADER
 
+#include "utilities.h"
+
 #include "SelectField.h"
 #include <qwt_plot.h>
 #include <vector>
 #include <SalomeApp_Module.h>
 #include <SUIT_Desktop.h>
+#include <qdialog.h>
 
 #include <SALOMEconfig.h>
-/* #include CORBA_CLIENT_HEADER(MED_Gen) */
 
 class QLineEdit;
 class QLabel;
@@ -39,32 +41,41 @@ class QPushButton;
 class QGroupBox;
 class QFrame;
 
-class SelectParams: public QObject
+class SelectParams: public QDialog
 {
   Q_OBJECT
 
 public:
-  SelectParams(SelectField *sel);
+  SelectParams(FilterGUI*,SelectField *sel,
+              const char* name = 0,
+              bool modal = FALSE,
+              WFlags fl = 0) throw(SALOME_Exception);
   virtual ~SelectParams();
 
-  virtual QFrame*  buildFrame();
-
 protected:
+  virtual void     buildFrame();
   virtual void     calcHisto();
+  virtual void     displayHisto();
   virtual void     calcRateRed();
   virtual void     clearSThresh();
+  virtual void     displayFThresh();
+  virtual void     displaySThresh();
+  virtual void     enableWidgets();
 
 protected slots:
-  virtual void     displayHisto();
+  virtual void     gradSelected();
+  virtual void     enterSHisto();
+  virtual void     updateHisto();
+  virtual void     scaleSelected();
   virtual void     nbThreshSelected();
   virtual void     areaSelected();
-  virtual void     displayFThresh();
-  virtual void     displaySThresh();
+  virtual void     enterFThresh();
+  virtual void     enterSThresh();
   virtual void     moveThresh(const QMouseEvent &e);
   virtual void     getOutFileName();
-  virtual void     process();
-
-private:
+  virtual void     process() throw(SALOME_Exception);
+  virtual void     ClickOnCancel();
+  virtual void     ClickOnHelp();
 
 private:
   int _size;
@@ -74,19 +85,20 @@ private:
   double *_x, *_y;
   double _xft[100], _yft[100], _xst[100], _yst[100];
 
-  QLineEdit *_myFThresh, *_myExpr, *_myLEST, *_myLEFT, *_myOFN;
-  QButtonGroup *_myFunc, *_myFScale, *_myNbThresh, *_myArea, *_myVThresh, *_myOutFile;
-  QGridLayout *_myGroupLayout, *_myGroupLayout2, *_lay;
-  QRadioButton *_myCutNeg, *_myInt, *_myExt, *_myOneThresh, *_myTwoThresh, *_myFieldB, *_myLinear;
-  QPushButton *_myHisto, *_myOFB, *_myProc;
-  QGroupBox* _GroupC1, *_GroupC2;
+  QLineEdit *_myLESH, *_myFThresh, *_myExpr, *_myLEST, *_myLEFT, *_myOFN;
+  QButtonGroup *_myHSize, *_myFunc, *_myFScale, *_myNbThresh, *_myArea, *_myVThresh, *_myOutFile;
+  QGridLayout *_myGroupLayout, *_myGroupLayout2, *_lay, *_GroupButtonsLayout;
+  QRadioButton *_myFieldB, *_myGradB, *_myInt, *_myExt, *_myOneThresh, *_myTwoThresh, *_myLinear, *_myLog;
+  QPushButton *_myHisto, *_myOFB, *_myProc, * _buttonCancel, * _buttonHelp;
+  QGroupBox* _GroupC1, *_GroupC2, *_GroupButtons;
   QwtPlot *_myPlot;
-  QLabel *_myLFT, *_myLST, *_myLRR;
+  QLabel *_myLSH, *_myLFT, *_myLST, *_myLRR;
   QwtDiMap _qmap;
   QFrame *_fr;
   QString _inputFile, _inputMesh, _inputField;
   int _inputTS;
-
+  SelectField *_sel;
+  SALOME_FILTER::FILTER_Gen_ptr _filter;
 };
 
 #endif