Salome HOME
call to ensight write driver
authorsecher <secher>
Tue, 13 Feb 2007 15:12:23 +0000 (15:12 +0000)
committersecher <secher>
Tue, 13 Feb 2007 15:12:23 +0000 (15:12 +0000)
src/FILTERGUI/FilterGUI.cxx
src/FILTERGUI/SelectParams.cxx
src/FILTERGUI/SelectParams.h

index 2526e15814d860cd4bc2c2a86f8634a03a721a9b..a723e638deb57e5abe624a60996d1f419d283383 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" );
 
@@ -283,15 +285,26 @@ bool FilterGUI::OnGUIEvent (int theCommandID)
        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 ) {
+           QMessageBox::information( application()->desktop(),
+                                     "Filtering",
+                                     "Unable to select parameters for filtering.\n"
+                                     "You must select a reference field in a MED file before." );
          }
        }
-       else
+       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;
       }
     case 111:
index b52824a714475c28dfdaf7feedaa350fdd344b86..388b71bd954e03337d3eb3b1f1377d0f016b41ac 100644 (file)
@@ -22,6 +22,9 @@
 #include <math.h>
 #include "SelectParams.h"
 #include "MEDMEM_MedMeshDriver.hxx"
+#include "MEDMEM_EnsightMeshDriver.hxx"
+#include "MEDMEM_Family.hxx"
+#include "MEDMEM_Group.hxx"
 
 #include <SUIT_FileDlg.h>
 
 #include <qradiobutton.h>
 #include <qpushbutton.h>
 #include <qfiledialog.h>
+#include <qmessagebox.h>
+#include <qcursor.h>
 
 SelectParams::SelectParams(FilterGUI* theModule,SelectField *sel,
                           const char* name,
-                          bool modal, WFlags fl)
-  : QDialog(FILTER::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),  _size(1024),_sel(sel),_criteria(NULL),_boundary(NULL)
+                          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),_criteria(NULL)
 {
   if(sel){
 
@@ -115,10 +120,6 @@ SelectParams::~SelectParams()
     delete _criteria;
   }
   
-  // destruction of criteria: support and field
-  if(_boundary)
-    delete _boundary;
-  
   // destruction of SelectField object and MED object in it
   delete _sel;
 }
@@ -608,20 +609,46 @@ void SelectParams::process()
   MESSAGE("Input Time Step : "<<_inputTS);
   MESSAGE("Output file name: " << _myOFN->text() );
 
+  setCursor(QCursor(Qt::WaitCursor));
+
   // generate MED integer field (0 or 1) for filtoo input
-  generateCriteria();
+  try{
+    generateCriteria();
+  }
+  catch ( SALOME_Exception& S_ex ){
+    QMessageBox::information( this,
+                             "Filtering",
+                             "Unable to process filtering.\n"
+                             "You must select a reference field on nodes." );
+    reject();
+    return;
+  }
 
   // generate MED boundary of geometry
-  generateBoundary();
+  SUPPORT *supB = _mesh->getBoundaryElements(MED_FACE);
 
-  // have to call ensight driver MED to generate input ensight mesh ,
+  // call ensight driver MED to generate input ensight mesh ,
   // input ensight boundary mesh and input criteria ensight field for filtoo
 
+  int id;
+  ENSIGHT_MESH_DRIVER myMeshDriver("/tmp/input.geom",_mesh);
+  myMeshDriver.addSupport(supB);
+  id=_mesh->addDriver(myMeshDriver);
+  _mesh->write(id);
+  ENSIGHT_FIELD_DRIVER<int> myFieldDriver("/tmp/input.data",_criteria);
+  id=_criteria->addDriver(myFieldDriver);
+  _criteria->write(id);
+
   // send filtoo command
-  command = "cd /export/home/secher/filtoo/example;filtoo -f s -o sf > /tmp/filter.log";
+  command = "cd /tmp;filtoo -f input -o output > /tmp/filter.log";
   MESSAGE(command);
   system(command.c_str());
 
+  // destroy filtoo input files
+//   command = "cd /tmp;rm -f input.*";
+//   MESSAGE(command);
+//   system(command.c_str());
+
   // have to call ensight driver MED to generate output MED file from filtoo output
 
   // close the window
@@ -629,206 +656,7 @@ void SelectParams::process()
 
 }
 
-void SelectParams::generateBoundary()
-{
-  int nbTria3=0;
-  int nbQuad4=0;
-  int nbTria6=0;
-  int nbQuad8=0;
-  const int *faces3, *faces4, *faces6, *faces8;
-
-  // get support of faces on boundary
-  MEDMEM::SUPPORT *supF = _mesh->getBoundaryElements(MED_EN::MED_FACE);
-
-  // get support of nodes on boundary
-  MEDMEM::SUPPORT *supN = _mesh->getBoundaryElements(MED_EN::MED_NODE);
-
-  // number of faces on boundary
-  int nbFaces = supF->getNumberOfElements(MED_ALL_ELEMENTS);
-
-  // type of face on boundary
-  const MED_EN::medGeometryElement* geotype = supF->getTypes();
-
-  // number of type of face on boundary
-  int nbTypes = supF->getNumberOfTypes();
-  for(int i=0;i<nbTypes;i++){
-    switch(geotype[i]){
-    case MED_TRIA3:
-      // number of tria3 on boundary
-      nbTria3 = supF->getNumberOfElements(MED_TRIA3);
-      // array of number of tria6 of boundary
-      faces3 = supF->getNumber(MED_TRIA3);
-      break;
-    case MED_QUAD4:
-      // number of quad4 on boundary
-      nbQuad4 = supF->getNumberOfElements(MED_QUAD4);
-      // array of number of tria6 of boundary
-      faces4 = supF->getNumber(MED_QUAD4);
-      break;
-    case MED_TRIA6:
-      // number of tria6 on boundary
-      nbTria6 = supF->getNumberOfElements(MED_TRIA6);
-      // array of number of tria6 of boundary
-      faces6 = supF->getNumber(MED_TRIA6);
-      break;
-    case MED_QUAD8:
-      // number of quad8 on boundary
-      nbQuad8 = supF->getNumberOfElements(MED_QUAD8);
-      // array of number of tria6 of boundary
-      faces8 = supF->getNumber(MED_QUAD8);
-      break;
-    default:
-      MESSAGE("OTHER FACE THAN TRIA3 OR QUAD4 : " << geotype[i]);
-      throw SALOME_Exception("Salome Exception");
-      break;
-    }
-  }
-
-  // number of nodes on boundary
-  int nbNodes = supN->getNumberOfElements(MED_ALL_ELEMENTS);
-
-  MESSAGE(nbFaces<< " FACES " << nbTria3 << " TRIA3 " << nbQuad4 << " QUAD4 " << nbTria6 << " TRIA6 " << nbQuad8 << " QUAD8 " << nbNodes << " NODES on BOUNDARY");
-
-  // array of number of faces of boundary
-  const int *faces = supF->getNumber(MED_ALL_ELEMENTS);
-  // array of number of nodes of boundary
-  const int *nodes = supN->getNumber(MED_ALL_ELEMENTS);
-
-  // array of coordinates of nodes in input 3D mesh
-  const double *coord = _mesh->getCoordinates(MED_FULL_INTERLACE);
-
-  // space dimension of input mesh
-  int spaceDim = _mesh->getSpaceDimension();
-
-  // array of coordinates of nodes in boundary
-  double *coordB = new double[spaceDim*nbNodes];
-
-  map<int,int> ONNodes;
-  for(int i=0;i<nbNodes;i++){
-    for(int j=0;j<spaceDim;j++)
-      coordB[spaceDim*i+j] = coord[(nodes[i]-1)*spaceDim+j];
-    ONNodes[nodes[i]] = i+1;
-  }
-
-  // size of nodal connectivity of the faces of boundary
-  int nbElem = 3*nbTria3 + 4*nbQuad4 + 6*nbTria6 + 8*nbQuad8;
-
-  // allocation of array of nodal connectivity of the faces of boudary
-  int *connB = new int[nbElem];
-
-  int ind=0;
-
-  // array of nodal connectivity of the tria3 of input 3D mesh
-  if( nbTria3 > 0 ){
-    const int *conn3 = _mesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_FACE,MED_TRIA3);
-    for(int i=0;i<nbTria3;i++){
-      for(int j=0;j<3;j++)
-       connB[ind+j] = ONNodes[conn3[(faces3[i]-1)*3+j]];
-      ind+=3;
-    }
-  }
-  // array of nodal connectivity of the quad4 of input 3D mesh
-  if( nbQuad4 > 0 ){
-    const int *conn4 = _mesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_FACE,MED_QUAD4);
-    for(int i=0;i<nbQuad4;i++){
-      for(int j=0;j<4;j++)
-       connB[ind+j] = ONNodes[conn4[(faces4[i]-1)*4+j]];
-      ind+=4;
-    }
-  }
-  // array of nodal connectivity of the tria6 of input 3D mesh
-  if( nbTria6 > 0 ){
-    const int *conn6 = _mesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_FACE,MED_TRIA6);
-    for(int i=0;i<nbTria6;i++){
-      for(int j=0;j<6;j++)
-       connB[ind+j] = ONNodes[conn6[(faces6[i]-1)*6+j]];
-      ind+=6;
-    }
-  }
-  // array of nodal connectivity of the quad4 of input 3D mesh
-  if( nbQuad8 > 0 ){
-    const int *conn8 = _mesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_FACE,MED_QUAD8);
-    for(int i=0;i<nbQuad8;i++){
-      for(int j=0;j<8;j++)
-       connB[ind+j] = ONNodes[conn8[(faces8[i]-1)*8+j]];
-      ind+=8;
-    }
-  }
-  // boundary mesh creation   
-  _boundary = new MESHING();
-  
-  _boundary->setName( "Boundary" );
-
-  int nbOfClassicalTypesFace[4];
-  medGeometryElement classicalTypesFace[4];
-  ind=0;
-  if( nbTria3 > 0 ){
-    nbOfClassicalTypesFace[ind] = nbTria3;
-    classicalTypesFace[ind] = MED_EN::MED_TRIA3;
-    ind++;
-  }
-  if( nbQuad4 > 0 ){
-    nbOfClassicalTypesFace[ind] = nbQuad4;
-    classicalTypesFace[ind] = MED_EN::MED_QUAD4;
-    ind++;
-  }
-  if( nbTria6 > 0 ){
-    nbOfClassicalTypesFace[ind] = nbTria6;
-    classicalTypesFace[ind] = MED_EN::MED_TRIA6;
-    ind++;
-  }
-  if( nbQuad8 > 0 ){
-    nbOfClassicalTypesFace[ind] = nbQuad8;
-    classicalTypesFace[ind] = MED_EN::MED_QUAD8;
-    ind++;
-  }
-
-  _boundary->setNumberOfTypes(ind, MED_EN::MED_CELL) ;
-  _boundary->setTypes( classicalTypesFace, MED_EN::MED_CELL) ;
-  _boundary->setNumberOfElements(nbOfClassicalTypesFace, MED_EN::MED_CELL);
-
-  if( nbTria3 > 0 )
-    _boundary->setConnectivity( connB, MED_EN::MED_CELL, MED_EN::MED_TRIA3);
-  if( nbQuad4 > 0 )
-    _boundary->setConnectivity( connB+3*nbTria3, MED_EN::MED_CELL, MED_EN::MED_QUAD4);
-  if( nbTria6 > 0 )
-    _boundary->setConnectivity( connB+3*nbTria3+4*nbQuad4, MED_EN::MED_CELL, MED_EN::MED_TRIA6);
-  if( nbQuad8 > 0 )
-    _boundary->setConnectivity( connB+3*nbTria3+4*nbQuad4+6*nbTria6, MED_EN::MED_CELL, MED_EN::MED_QUAD8);
-
-  _boundary->setMeshDimension(3);
-  _boundary->setSpaceDimension(3);
-  _boundary->setNumberOfNodes(nbNodes);
-  _boundary->setCoordinates(3, nbNodes, coordB, "CARTESIAN",
-                         MED_EN::MED_FULL_INTERLACE);
-
-  // Set coordinates names
-  string coordname[3] = { "x", "y", "z" } ;
-  _boundary->setCoordinatesNames(coordname) ;
-
-  // Set coordinates units
-  string coordunit[3] = { "m", "m", "m" } ;
-  _boundary->setCoordinatesUnits(coordunit) ;
-
-  // write the boundary mesh in a MED file for test
-//   MED_MESH_WRONLY_DRIVER myMeshDriver("/home/secher/mymesh.med",_boundary);
-//   int current=_boundary->addDriver(myMeshDriver);
-//   _boundary->write(current);
-
-  // support destruction
-  delete supF;
-  delete supN;
-
-  // connectivity destruction
-  delete [] connB;
-
-  // coordinate destruction
-  delete [] coordB;
-
-}
-
-void SelectParams::generateCriteria()
+void SelectParams::generateCriteria() throw(SALOME_Exception)
 {
   double val, min, max;
   bool isGVal;
@@ -843,19 +671,23 @@ void SelectParams::generateCriteria()
   switch(typ){
   case MED_CELL:
     MESSAGE("REFERENCE FIELD ON CELL");
-    return;
+    throw SALOME_Exception("Filter run only on reference field on nodes");
+    break;
   case MED_FACE:
     MESSAGE("REFERENCE FIELD ON FACE");
-    return;
+    throw SALOME_Exception("Filter run only on reference field on nodes");
+    break;
   case MED_EDGE:
     MESSAGE("REFERENCE FIELD ON EDGE");
-    return;
+    throw SALOME_Exception("Filter run only on reference field on nodes");
+    break;
   case MED_NODE:
     MESSAGE("REFERENCE FIELD ON NODES");
     break;
   case MED_ALL_ENTITIES:
     MESSAGE("REFERENCE FIELD ON ALL ELEMENTS");
-    return;
+    throw SALOME_Exception("Filter run only on reference field on nodes");
+    break;
   }
 
   // create support on nodes
@@ -864,6 +696,8 @@ void SelectParams::generateCriteria()
   // 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);
 
index d43aa03f41de373127cbad02bb5c5c270b88245c..fe322874a2493da318f33867496afb988dc10d40 100644 (file)
@@ -52,7 +52,7 @@ public:
   SelectParams(FilterGUI*,SelectField *sel,
               const char* name = 0,
               bool modal = FALSE,
-              WFlags fl = 0);
+              WFlags fl = 0) throw(SALOME_Exception);
   virtual ~SelectParams();
 
 protected:
@@ -64,8 +64,7 @@ protected:
   virtual void     displayFThresh();
   virtual void     displaySThresh();
   virtual void     enableWidgets();
-  virtual void     generateCriteria();
-  virtual void     generateBoundary();
+  virtual void     generateCriteria() throw(SALOME_Exception);
 
 protected slots:
   virtual void     enterSHisto();
@@ -105,11 +104,10 @@ private:
   int _inputTS;
   SelectField *_sel;
   ::MEDMEM::MED *_med;
-  MEDMEM::MESH* _mesh;
+  MESH* _mesh;
   FIELD<double> * _myDField;
   FIELD<int> * _myIField;
   FIELD<int> *_criteria;
-  MESHING* _boundary;
 };
 
 #endif