]> SALOME platform Git repositories - modules/yacs.git/commitdiff
Salome HOME
DCQ : Merge with Ecole_ete_a6.
authoryfr <yfr@opencascade.com>
Thu, 17 Jun 2004 11:20:15 +0000 (11:20 +0000)
committeryfr <yfr@opencascade.com>
Thu, 17 Jun 2004 11:20:15 +0000 (11:20 +0000)
92 files changed:
src/Event/Makefile.in [new file with mode: 0644]
src/Event/SALOME_Event.cxx [new file with mode: 0644]
src/Event/SALOME_Event.hxx [new file with mode: 0644]
src/MEDWrapper/MEDA_Algorithm.cxx [new file with mode: 0644]
src/MEDWrapper/MEDA_Algorithm.hxx [new file with mode: 0644]
src/MEDWrapper/MEDA_Structures.cxx [new file with mode: 0644]
src/MEDWrapper/MEDA_Structures.hxx [new file with mode: 0644]
src/MEDWrapper/MEDA_Test.cxx [new file with mode: 0644]
src/MEDWrapper/MEDA_Test1.cxx [new file with mode: 0644]
src/MEDWrapper/MEDA_Wrapper.cxx [new file with mode: 0644]
src/MEDWrapper/MEDA_Wrapper.hxx [new file with mode: 0644]
src/MEDWrapper/MED_Common.hxx [new file with mode: 0644]
src/MEDWrapper/MED_Structures.cxx [new file with mode: 0644]
src/MEDWrapper/MED_Structures.hxx [new file with mode: 0644]
src/MEDWrapper/MED_Test.cxx [new file with mode: 0644]
src/MEDWrapper/MED_Utilities.cxx [new file with mode: 0644]
src/MEDWrapper/MED_Utilities.hxx [new file with mode: 0644]
src/MEDWrapper/MED_Wrapper.cxx [new file with mode: 0644]
src/MEDWrapper/MED_Wrapper.hxx [new file with mode: 0644]
src/MEDWrapper/Makefile.in [new file with mode: 0644]
src/SALOME_PY/SalomePy.cxx
src/SALOME_PYQT/Makefile.in
src/SALOME_PYQT/SALOME_PYQT_GUI.cxx
src/SALOME_PYQT/SALOME_PYQT_GUI.h [new file with mode: 0644]
src/SALOME_PYQT/SALOME_PYQT_GUI.hxx [deleted file]
src/SALOME_PYQT/SalomePyQt.cxx
src/SALOME_SWIG/Makefile.in
src/SALOME_SWIG/batchmode_salome.py
src/SALOME_SWIG/salome.py
src/SALOME_SWIG/salome_test.py
src/SALOME_SWIG/test_remove_ref.py [new file with mode: 0755]
src/SUPERVGraph/SUPERVGraph.cxx
src/SUPERVGraph/SUPERVGraph_ViewFrame.cxx
src/SUPERVGraph/SUPERVGraph_ViewFrame.h
src/Session/Makefile.in
src/Session/SALOME_Session_QThread.cxx
src/Session/SALOME_Session_QThread.hxx
src/Session/SALOME_Session_Server.cxx
src/Session/SALOME_Session_i.cxx
src/Session/SALOME_Session_i.hxx
src/Session/Session_ServerLauncher.cxx [new file with mode: 0644]
src/Session/Session_ServerLauncher.hxx [new file with mode: 0644]
src/Session/Session_ServerThread.cxx [new file with mode: 0644]
src/Session/Session_ServerThread.hxx [new file with mode: 0644]
src/TOOLSDS/SALOMEDS_Tool.cxx
src/TOOLSGUI/ToolsGUI.cxx
src/TOOLSGUI/ToolsGUI_CatalogGeneratorDlg.cxx
src/TestContainer/SALOME_TestComponent_i.cxx
src/TestContainer/SALOME_TestComponent_i.hxx
src/TestContainer/TestContainer.cxx
src/TestContainer/TestLogger.cxx
src/Utils/Makefile.in
src/Utils/Utils_CatchSignals.cxx [new file with mode: 0644]
src/Utils/Utils_CatchSignals.h [new file with mode: 0644]
src/Utils/Utils_CommException.cxx
src/Utils/Utils_CorbaException.hxx
src/Utils/Utils_DESTRUCTEUR_GENERIQUE.cxx
src/Utils/Utils_DESTRUCTEUR_GENERIQUE.hxx
src/Utils/Utils_ExceptHandlers.cxx [new file with mode: 0644]
src/Utils/Utils_ExceptHandlers.hxx [new file with mode: 0644]
src/Utils/Utils_ORB_INIT.cxx
src/Utils/Utils_ORB_INIT.hxx
src/Utils/Utils_SALOME_Exception.cxx
src/Utils/Utils_SALOME_Exception.hxx
src/Utils/Utils_Timer.cxx
src/Utils/utilities.h
src/VTKFilter/Makefile.in
src/VTKFilter/SALOME_ExtractUnstructuredGrid.cxx [new file with mode: 0644]
src/VTKFilter/SALOME_ExtractUnstructuredGrid.h [new file with mode: 0644]
src/VTKFilter/SALOME_GeometryFilter.cxx
src/VTKFilter/SALOME_GeometryFilter.h
src/VTKFilter/SALOME_PassThroughFilter.cxx
src/VTKFilter/SALOME_PassThroughFilter.h
src/VTKFilter/SALOME_TransformFilter.cxx
src/VTKViewer/Makefile.in
src/VTKViewer/VTKViewer.cxx
src/VTKViewer/VTKViewer_CellRectPicker.cxx [new file with mode: 0644]
src/VTKViewer/VTKViewer_CellRectPicker.h [new file with mode: 0644]
src/VTKViewer/VTKViewer_Filter.cxx [new file with mode: 0755]
src/VTKViewer/VTKViewer_Filter.h [new file with mode: 0755]
src/VTKViewer/VTKViewer_InteractorStyleSALOME.cxx
src/VTKViewer/VTKViewer_InteractorStyleSALOME.h
src/VTKViewer/VTKViewer_RectPicker.cxx [new file with mode: 0644]
src/VTKViewer/VTKViewer_RectPicker.h [new file with mode: 0644]
src/VTKViewer/VTKViewer_RenderWindow.cxx
src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx
src/VTKViewer/VTKViewer_RenderWindowInteractor.h
src/VTKViewer/VTKViewer_Trihedron.cxx
src/VTKViewer/VTKViewer_Trihedron.h
src/VTKViewer/VTKViewer_Utilities.cxx
src/VTKViewer/VTKViewer_ViewFrame.cxx
src/VTKViewer/VTKViewer_ViewFrame.h

diff --git a/src/Event/Makefile.in b/src/Event/Makefile.in
new file mode 100644 (file)
index 0000000..426af68
--- /dev/null
@@ -0,0 +1,52 @@
+#  SALOME Utils : general SALOME's definitions and tools
+#
+#  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+#
+#
+#
+#  File   : Makefile.in
+#  Author : Marc Tajchman (CEA)
+#  Module : SALOME
+#  $Header$
+
+top_srcdir=@top_srcdir@
+top_builddir=../..
+srcdir=@srcdir@
+VPATH=.:@srcdir@:@top_srcdir@/idl
+
+
+@COMMENCE@
+
+# header files  
+EXPORT_HEADERS= \
+       SALOME_Event.hxx 
+
+EXPORT_PYSCRIPTS = 
+# Libraries targets
+
+LIB = libEvent.la 
+LIB_SRC = SALOME_Event.cxx 
+
+CPPFLAGS+=$(QT_INCLUDES)
+LDFLAGS+=$(QT_MT_LIBS)
+
+@CONCLUDE@
+
+
diff --git a/src/Event/SALOME_Event.cxx b/src/Event/SALOME_Event.cxx
new file mode 100644 (file)
index 0000000..dfebd7b
--- /dev/null
@@ -0,0 +1,140 @@
+//  KERNEL SALOME_Event : Define event posting mechanism
+//
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : SALOME_Event.cxx
+//  Author : Sergey ANIKIN
+//  Module : KERNEL
+//  $Header$
+
+#include "SALOME_Event.hxx"
+
+#include "utilities.h"
+
+#include <qsemaphore.h>
+#include <qapplication.h>
+#include <qthread.h>
+
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+#else
+static int MYDEBUG = 0;
+#endif
+
+//===========================================================
+/*!
+ *  SALOME_Event::SALOME_Event
+ *  Constructor
+ */
+//===========================================================
+SALOME_Event::SALOME_Event(): 
+  myWait( true ),
+  myAutoRelease( false )
+{
+  if(MYDEBUG) MESSAGE( "SALOME_Event::SALOME_Event(): this = "<<this<<", myWait = "<<myWait );
+  if ( myWait ) {
+    // Prepare the semaphore 
+    mySemaphore = new QSemaphore( 2 );
+    mySemaphore->operator+=( 2 );
+  }
+}
+
+//===========================================================
+/*!
+ *  SALOME_Event::~SALOME_Event
+ *  Destructor
+ */
+//===========================================================
+SALOME_Event::~SALOME_Event()
+{
+  if(MYDEBUG) MESSAGE( "SALOME_Event::~SALOME_Event(): this = "<<this<<", myWait = "<<myWait );
+  if ( myWait ) {
+    if ( mySemaphore->available() < mySemaphore->total() )
+      mySemaphore->operator-=( mySemaphore->total() - mySemaphore->available() );
+    delete mySemaphore;
+  }
+}
+
+//===========================================================
+/*!
+ *  SALOME_Event::process
+ *  Posts the event and optionally waits for its completion
+ */
+//===========================================================
+void SALOME_Event::process()
+{
+  if(MYDEBUG) MESSAGE( "SALOME_Event::process(): this = "<<this<<", myWait = "<<myWait );
+  QThread::postEvent( qApp, new QCustomEvent( SALOME_EVENT, (void*)this ) );
+  if ( myWait ) {
+    if(MYDEBUG) MESSAGE( "SALOME_Event::process(): available = " << mySemaphore->available() );
+    if ( !mySemaphore->available() )
+      mySemaphore->operator+=( 1 );
+
+    if(MYDEBUG) MESSAGE( "SALOME_Event::process() COMPLETED: this = "<<this<<", myWait = "<<myWait );
+  }
+  if ( myAutoRelease )
+    release();
+}
+
+//===========================================================
+/*!
+ *  SALOME_Event::processed
+ *  Signals that this event has been processed
+ */
+//===========================================================
+void SALOME_Event::processed()
+{
+  if(MYDEBUG) MESSAGE( "SALOME_Event::processed(): this = "<<this<<", myWait = "<<myWait );
+  if ( myWait ) {
+    if(MYDEBUG) MESSAGE( "SALOME_Event::processed(): available = " << mySemaphore->available() );
+    if ( !mySemaphore->available() ) {
+      // process() takes control over mySemaphore after the next line is executed
+      mySemaphore->operator-=( 1 );
+
+      if(MYDEBUG) MESSAGE( "SALOME_Event::processed(): semaphore DECREMENTED" );
+
+      // Current thread will block here until process() completes
+      mySemaphore->operator+=( mySemaphore->total() );
+    }
+  }
+  if(MYDEBUG) MESSAGE( "SALOME_Event::processed() COMPLETED: this = "<<this<<", myWait = "<<myWait );
+}
+
+//===========================================================
+/*!
+ *  SALOME_Event::release
+ *  Wakes up the desktop
+ */
+//===========================================================
+void SALOME_Event::release()
+{
+  if(MYDEBUG) MESSAGE( "SALOME_Event::release(): this = "<<this<<", myWait = "<<myWait );
+  if ( myWait ) {
+    if(MYDEBUG) MESSAGE( "SALOME_Event::release(): available = " << mySemaphore->available() );
+    mySemaphore->operator-=( mySemaphore->total() - mySemaphore->available() );
+  }
+  if(MYDEBUG) MESSAGE( "SALOME_Event::release() COMPLETED: this = "<<this<<", myWait = "<<myWait );
+}
+
+
+
+
diff --git a/src/Event/SALOME_Event.hxx b/src/Event/SALOME_Event.hxx
new file mode 100644 (file)
index 0000000..2467912
--- /dev/null
@@ -0,0 +1,259 @@
+//  KERNEL SALOME_Event : Define event posting mechanism
+//
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : SALOME_Event.hxx
+//  Author : Sergey ANIKIN
+//  Module : KERNEL
+//  $Header$
+
+
+#ifndef SALOME_Event_HeaderFile
+#define SALOME_Event_HeaderFile
+
+#include <qevent.h>
+
+#define SALOME_EVENT QEvent::Type( QEvent::User + 10000 )
+
+class QSemaphore;
+
+//===========================================================
+/*!
+ *  Class: SALOME_Event
+ *  Description: 
+ *  This class encapsulates data and functionality required for 
+ *  posting component-specific events to perform arbitrary operations in main GUI thread. 
+ *  SALOME_Event objects can be posted by any thread belonging to the GUI process.
+ *
+ *  It is necessary to derive a custom event class from SALOME_Event and 
+ *  re-implement virtual Execute() method. This method should actually perform 
+ *  the desirable operation. To pass all the required data to Execute() and store a return value,
+ *  arbitrary data fields can be added to the custom event class. There is 
+ *  no need to protect such fields with a mutex, for only one thread working with
+ *  a SALOME_Event object is active at any moment.
+ *
+ *  It is possible to make the thread that creates SALOME_Event
+ *  wait until the event is processed by the component GUI, SALOME_Event
+ *  should be constructed with <wait> == TRUE in such a case.
+ *
+ *  SALOME_Event objects should be created on the heap. QAD_Desktop deletes
+ *  these objects as soon as they have been processed.
+ *
+ *  Usage:
+ *  - create SALOME_Event object on the heap with proper <type> and <wait> parameters. 
+ *    Components can derive their own event class from SALOME_Event
+ *    in order to pass custom data to the event handler.
+ *  - call process() method to post the event. Between process() and release()
+ *    it is possible to examine fields of your custom event object.
+ *  - call release() method to wake up the desktop (you can also set <autoRelease>
+ *    parameter to TRUE to automatically wake up desktop after process()
+ * 
+ *  processed() method is used by the desktop to signal that event processing 
+ *  has been completed.
+ *  
+ *  Caveats: 
+ *  1. Never create SALOME_Event with <wait> == TRUE in code that is 
+ *     supposed to be called within main GUI thread, for this will result
+ *     in GUI process deadlock.
+ *  2. Always call release() method after process() if you use <wait> parameters as TRUE,
+ *     otherwise processed() method will never return and main GUI thread will be blocked!
+ *  3. Never use pointers to the event after it has been released (either by calling release()
+ *     or automatically by process() if <autoRelease> == TRUE) to avoid application crashes!
+ */
+//===========================================================
+
+
+class SALOME_Event
+{
+public:
+  SALOME_Event();
+  virtual ~SALOME_Event();
+
+  // To do real work
+  virtual void Execute() = 0;
+
+  void process();
+  void processed();
+
+  void release();
+
+private:
+  bool        myWait;
+  bool        myAutoRelease;
+  QSemaphore* mySemaphore;
+};
+
+
+// Template classes for member function
+//-------------------------------------
+template<class TObject, typename TRes>
+class TMemFunEvent: public SALOME_Event{
+public:
+  typedef TRes TResult;
+  TResult myResult;
+  typedef TResult (TObject::* TAction)();
+  TMemFunEvent(TObject* theObject, TAction theAction, 
+              TResult theResult = TResult()):
+    myObject(theObject),
+    myAction(theAction),
+    myResult(theResult)
+  {}
+  virtual void Execute(){
+    myResult = (myObject->*myAction)();
+  }
+private:
+  TObject* myObject;
+  TAction myAction;
+};
+
+
+template<class TObject>
+class TVoidMemFunEvent: public SALOME_Event{
+public:
+  typedef void (TObject::* TAction)();
+  TVoidMemFunEvent(TObject* theObject, TAction theAction):
+    myObject(theObject),
+    myAction(theAction)
+  {}
+  virtual void Execute(){
+    (myObject->*myAction)();
+  }
+private:
+  TObject* myObject;
+  TAction myAction;
+};
+
+
+// Template for member function with one argument
+//-----------------------------------------------
+template<class TObject, typename TRes, 
+        typename TArg, typename TStoreArg = TArg>
+class TMemFun1ArgEvent: public SALOME_Event{
+public:
+  typedef TRes TResult;
+  TResult myResult;
+  typedef TResult (TObject::* TAction)(TArg);
+  TMemFun1ArgEvent(TObject* theObject, TAction theAction, TArg theArg, 
+                  TResult theResult = TResult()):
+    myObject(theObject),
+    myAction(theAction),
+    myResult(theResult),
+    myArg(theArg)
+  {}
+  virtual void Execute(){
+    myResult = (myObject->*myAction)(myArg);
+  }
+private:
+  TObject* myObject;
+  TAction myAction;
+  TStoreArg myArg;
+};
+
+
+template<class TObject, typename TArg, typename TStoreArg = TArg>
+class TVoidMemFun1ArgEvent: public SALOME_Event{
+public:
+  typedef void (TObject::* TAction)(TArg);
+  TVoidMemFun1ArgEvent(TObject* theObject, TAction theAction, TArg theArg):
+    myObject(theObject),
+    myAction(theAction),
+    myArg(theArg)
+  {}
+  virtual void Execute(){
+    (myObject->*myAction)(myArg);
+  }
+private:
+  TObject* myObject;
+  TAction myAction;
+  TStoreArg myArg;
+};
+
+
+// Template for member function with one argument
+//-----------------------------------------------
+template<class TObject, typename TRes,
+        typename TArg, typename TArg1, 
+        typename TStoreArg = TArg, typename TStoreArg1 = TArg1>
+class TMemFun2ArgEvent: public SALOME_Event{
+public:
+  typedef TRes TResult;
+  TResult myResult;
+  typedef TResult (TObject::* TAction)(TArg,TArg1);
+  TMemFun2ArgEvent(TObject* theObject, TAction theAction, 
+                  TArg theArg, TArg1 theArg1,
+                  TResult theResult = TResult()):
+    myObject(theObject),
+    myAction(theAction),
+    myResult(theResult),
+    myArg(theArg),
+    myArg1(theArg1)
+  {}
+  virtual void Execute(){
+    myResult = (myObject->*myAction)(myArg,myArg1);
+  }
+private:
+  TObject* myObject;
+  TAction myAction;
+  TStoreArg myArg;
+  TStoreArg1 myArg1;
+};
+
+
+template<class TObject, typename TArg, typename TArg1, 
+        typename TStoreArg = TArg, typename TStoreArg1 = TArg1>
+class TVoidMemFun2ArgEvent: public SALOME_Event{
+public:
+  typedef void (TObject::* TAction)(TArg,TArg1);
+  TVoidMemFun2ArgEvent(TObject* theObject, TAction theAction, TArg theArg, TArg1 theArg1):
+    myObject(theObject),
+    myAction(theAction),
+    myArg(theArg),
+    myArg1(theArg1)
+  {}
+  virtual void Execute(){
+    (myObject->*myAction)(myArg,myArg1);
+  }
+private:
+  TObject* myObject;
+  TAction myAction;
+  TStoreArg myArg;
+  TStoreArg1 myArg1;
+};
+
+
+// Template function for processing events with result returing
+template<class TEvent> inline typename TEvent::TResult ProcessEvent(TEvent* theEvent){
+  theEvent->process();
+  typename TEvent::TResult aResult = theEvent->myResult;
+  theEvent->release();
+  return aResult;
+}
+
+
+// Template function for processing events without result
+inline void ProcessVoidEvent(SALOME_Event* theEvent){
+  theEvent->process();
+  theEvent->release();
+}
+
+
+#endif
diff --git a/src/MEDWrapper/MEDA_Algorithm.cxx b/src/MEDWrapper/MEDA_Algorithm.cxx
new file mode 100644 (file)
index 0000000..1f090c0
--- /dev/null
@@ -0,0 +1,252 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.cxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#include "MEDA_Algorithm.hxx"
+#include "MED_Utilities.hxx"
+using namespace std;
+using namespace MEDA;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+//---------------------------------------------------------------
+TCellGroup MEDA::GetCellsByEntity(TWrapper& theWrapper, 
+                                 const PMeshInfo& theMeshInfo,
+                                 const MED::TEntityInfo theEntityInfo)
+{
+  if(MYDEBUG) MESSAGE("GetCellsByEntity(...)");
+  TCellGroup aGroup;
+  MED::TEntityInfo::const_iterator anIter = theEntityInfo.begin();
+  for(; anIter != theEntityInfo.end(); anIter++){
+    const med_entite_maillage& anEntity = anIter->first;
+    if(anEntity == MED_NOEUD) continue;
+    const MED::TGeom& aGeom = anIter->second;
+    TCellSet& aCellSet = aGroup[anEntity];
+    MED::TGeom::const_iterator anGeomIter = aGeom.begin();
+    for(; anGeomIter != aGeom.end(); anGeomIter++){
+      const med_geometrie_element& aGeo = anGeomIter->first;
+      PCellInfo aCellInfo = theWrapper.GetCellInfo(theMeshInfo,anEntity,aGeo);
+      aCellSet.insert(aCellInfo);
+      if(MYDEBUG){
+       med_int aNbElem = aCellInfo->GetNbElem();
+       MED::PrefixPrinter aPrefixPrinter;
+       BEGMSG("aGeo = "<<aGeo<<"; aNbElem = "<<aNbElem<<": ");
+       for(int iElem = 0; iElem < aNbElem; iElem++){
+         int iConnEnd = aCellInfo->GetConnDim();
+         for(int iConn = 0; iConn < iConnEnd; iConn++){
+           ADDMSG(aCellInfo->GetConn(iElem,iConn)<<",");
+         }
+         ADDMSG(" ");
+       }
+       ADDMSG("\n");
+      }
+    }
+  }
+  if(MYDEBUG) ADDMSG("\n");
+  return aGroup;
+}
+
+
+//---------------------------------------------------------------
+TFamilyGroup 
+MEDA::GetFamilies(TWrapper& theWrapper,
+                 const PMeshInfo& theMeshInfo)
+{
+  if(MYDEBUG) MESSAGE("GetFamilies(...)");
+  TFamilyGroup aGroup;
+  int aNbFam = theWrapper.GetNbFamilies(theMeshInfo);
+  MED::PrefixPrinter aPrefixPrinter;
+  if(MYDEBUG) BEGMSG("GetNbFamilies() = "<<aNbFam<<"\n");
+  for(int iFam = 0; iFam < aNbFam; iFam++){
+    PFamilyInfo aFamilyInfo = theWrapper.GetFamilyInfo(theMeshInfo,iFam);
+    aGroup.insert(aFamilyInfo);
+    if(MYDEBUG){
+      MED::PrefixPrinter aPrefixPrinter;
+      string aName = aFamilyInfo->GetName();
+      med_int aNbAttr = aFamilyInfo->GetNbAttr();
+      med_int aNbGroup = aFamilyInfo->GetNbGroup();
+      BEGMSG("aFamilyName = '"<<aName<<"'; andId = "<<aFamilyInfo->GetId()<<
+            "; aNbAttr = "<<aNbAttr<<"; aNbGroup = "<<aNbGroup<<"\n");
+      for(int iGroup = 0; iGroup < aNbGroup; iGroup++){
+       aName = aFamilyInfo->GetGroupName(iGroup);
+       MED::PrefixPrinter aPrefixPrinter;
+       BEGMSG("aGroupName = '"<<aName<<"'\n");
+      }
+    }
+  }
+  if(MYDEBUG) ADDMSG("\n");
+  return aGroup;
+}
+
+
+TGroupInfo 
+MEDA::GetFamiliesByGroup(const TFamilyGroup& theGroupInfo)
+{
+  if(MYDEBUG) MESSAGE("GetFamiliesByGroup(...)");
+  TGroupInfo aGroup;
+  TFamilyGroup::const_iterator anIter = theGroupInfo.begin();
+  for(; anIter != theGroupInfo.end(); anIter++){
+    const PFamilyInfo& aFamilyInfo = *anIter;
+    int aNbGroup = aFamilyInfo->GetNbGroup();
+    for(int iGroup = 0; iGroup < aNbGroup; iGroup++){
+      aGroup[aFamilyInfo->GetGroupName(iGroup)].insert(aFamilyInfo);
+    } 
+  }
+  if(MYDEBUG){
+    TGroupInfo::const_iterator anIter = aGroup.begin();
+    for(; anIter != aGroup.end(); anIter++){
+      string aName = anIter->first;
+      MED::PrefixPrinter aPrefixPrinter;
+      BEGMSG("aGroupName = '"<<aName<<"'\n");
+      const TFamilyGroup& aFamilyGroup = anIter->second;
+      TFamilyGroup::const_iterator anFamIter = aFamilyGroup.begin();
+      for(; anFamIter != aFamilyGroup.end(); anFamIter++){
+       const PFamilyInfo& aFamilyInfo = *anFamIter;
+       MED::PrefixPrinter aPrefixPrinter;
+       BEGMSG("aFamilyName = '"<<aFamilyInfo->GetName()<<"'\n");
+      }
+    }
+    ADDMSG("\n");
+  }
+  return aGroup;
+}
+
+
+//---------------------------------------------------------------
+TTimeStampGroup 
+MEDA::GetFieldsByEntity(TWrapper& theWrapper, 
+                       const PMeshInfo& theMeshInfo,
+                       const MED::TEntityInfo theEntityInfo)
+{
+  if(MYDEBUG) MESSAGE("GetFieldsByEntity(...)");
+  TTimeStampGroup aGroup;
+  med_int aNbFields = theWrapper.GetNbFields(); 
+  MED::PrefixPrinter aPrefixPrinter;
+  if(MYDEBUG) BEGMSG("GetNbFields() = "<<aNbFields<<"\n");
+  for(int iField = 0; iField < aNbFields; iField++){
+    PFieldInfo aFieldInfo = theWrapper.GetFieldInfo(theMeshInfo,iField);
+    med_int aNbComp = aFieldInfo->GetNbComp();
+    string aName = aFieldInfo->GetName();
+    MED::PrefixPrinter aPrefixPrinter;
+    if(MYDEBUG) BEGMSG("aFieldName = '"<<aName<<"'; aNbComp = "<<aNbComp<<"; ");
+    MED::TGeom aGeom;
+    med_entite_maillage anEntity;
+    med_int aNbTimeStamps = theWrapper.GetNbTimeStamps(aFieldInfo,theEntityInfo,anEntity,aGeom);
+    if(MYDEBUG) BEGMSG("anEntity = "<<anEntity<<"; GetNbTimeStamps = "<<aNbTimeStamps<<"\n");
+    for(int iTimeStamp = 0; iTimeStamp < aNbTimeStamps; iTimeStamp++){
+      PTimeStampInfo aTimeStamp = 
+       theWrapper.GetTimeStampInfo(aFieldInfo,iTimeStamp,anEntity,aGeom);
+      aGroup[aFieldInfo].insert(aTimeStamp);
+      med_int aNbGauss = aTimeStamp->GetNbGauss();
+      MED::PrefixPrinter aPrefixPrinter;
+      if(MYDEBUG) BEGMSG("aDt = "<<aTimeStamp->GetDt()<<", "<<aTimeStamp->GetUnitDt()<<"\n");
+    }
+  }
+  if(MYDEBUG) ADDMSG("\n");
+  return aGroup;
+}
+
+
+TFieldGroup 
+MEDA::GetFieldsByEntity(const TTimeStampGroup& theTimeStampGroup)
+{
+  TFieldGroup aGroup;
+  TTimeStampGroup::const_iterator anIter = theTimeStampGroup.begin();
+  for(; anIter != theTimeStampGroup.end(); anIter++){
+    const PFieldInfo& aFieldInfo = anIter->first;
+    const TTimeStampSet& aTimeStampSet = anIter->second;
+    if(aTimeStampSet.empty()) continue;
+    const PTimeStampInfo& aTimeStampInfo = *aTimeStampSet.begin();
+    aGroup[aTimeStampInfo->GetEntity()].insert(*anIter);
+  }
+  return aGroup;
+}
+
+
+TFamilyByEntity
+MEDA::GetFamiliesByEntity(TWrapper& theWrapper, 
+                         const PNodeInfo& theNodeInfo,
+                         const TCellGroup& theCellGroup,
+                         const TFamilyGroup& theFamilyGroup)
+{
+  if(MYDEBUG) MESSAGE("GetFamiliesByEntity(...)");
+  TFamilyByEntity aFamilyByEntity;
+
+  typedef map<med_int,PFamilyInfo> TFamilyByIdMap;
+  TFamilyByIdMap aFamilyByIdMap;
+  TFamilyGroup::const_iterator anIter = theFamilyGroup.begin();
+  for(; anIter != theFamilyGroup.end(); anIter++){
+    const PFamilyInfo& aFamilyInfo = *anIter;
+    aFamilyByIdMap.insert(TFamilyByIdMap::value_type(aFamilyInfo->GetId(),aFamilyInfo));
+  }
+
+  if(!aFamilyByIdMap.empty()){
+    typedef set<med_int> TFamilyIdSet;
+    typedef map<med_entite_maillage,TFamilyIdSet> TFamilyIdByEntity;
+    TFamilyIdByEntity aFamilyIdByEntity;
+
+    if(theNodeInfo!=0){
+      if(med_int aNbElem = theNodeInfo->GetNbElem()){
+       TFamilyIdSet& aFamilyIdSet = aFamilyIdByEntity[MED_NOEUD];
+       for(med_int i = 0; i < aNbElem; i++){
+         aFamilyIdSet.insert(theNodeInfo->GetFamNum(i));
+       }
+      }
+    }
+    
+    if(!theCellGroup.empty()){
+      TCellGroup::const_iterator anIter = theCellGroup.begin();
+      for(; anIter != theCellGroup.end(); anIter++){
+       const med_entite_maillage& anEntity = anIter->first;
+       TFamilyIdSet& aFamilyIdSet = aFamilyIdByEntity[anEntity];
+       const TCellSet& aCellSet = anIter->second;
+       TCellSet::const_iterator anCellIter = aCellSet.begin();
+       for(; anCellIter != aCellSet.end(); anCellIter++){
+         const PCellInfo& aCellInfo = *anCellIter;
+         if(med_int aNbElem = aCellInfo->GetNbElem()){
+           for(med_int i = 0; i < aNbElem; i++){
+             aFamilyIdSet.insert(aCellInfo->GetFamNum(i));
+           }
+         }
+       }
+      }
+    }
+    
+    if(!aFamilyIdByEntity.empty()){
+      TFamilyIdByEntity::const_iterator anIter = aFamilyIdByEntity.begin();
+      for(; anIter != aFamilyIdByEntity.end(); anIter++){
+       const med_entite_maillage& anEntity = anIter->first;
+       MED::PrefixPrinter aPrefixPrinter;
+       if(MYDEBUG) BEGMSG("anEntity = "<<anEntity<<":\n");
+       const TFamilyIdSet& aFamilyIdSet = anIter->second;
+       TFamilyIdSet::const_iterator anFamilyIdIter = aFamilyIdSet.begin();
+       for(; anFamilyIdIter != aFamilyIdSet.end(); anFamilyIdIter++){
+         const med_int& aFamilyId = *anFamilyIdIter;
+         TFamilyByIdMap::const_iterator 
+           anFamilyByIdMapIter = aFamilyByIdMap.find(aFamilyId);
+         if(anFamilyByIdMapIter != aFamilyByIdMap.end()){
+           const PFamilyInfo& aFamilyInfo = anFamilyByIdMapIter->second;
+           aFamilyByEntity[anEntity].insert(aFamilyInfo);
+           MED::PrefixPrinter aPrefixPrinter;
+           if(MYDEBUG) 
+             BEGMSG("aFamilyName = '"<<aFamilyInfo->GetName()<<
+                    "' anId = "<<aFamilyInfo->GetId()<<"\n");
+         }
+       }
+      }
+    }
+  }    
+  if(MYDEBUG) ADDMSG("\n");
+  return aFamilyByEntity;
+}
+
diff --git a/src/MEDWrapper/MEDA_Algorithm.hxx b/src/MEDWrapper/MEDA_Algorithm.hxx
new file mode 100644 (file)
index 0000000..326da0d
--- /dev/null
@@ -0,0 +1,69 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.hxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#ifndef MEDA_Algorithm_HeaderFile
+#define MEDA_Algorithm_HeaderFile
+
+#include "MEDA_Structures.hxx"
+#include "MEDA_Wrapper.hxx"
+
+#include <set>
+
+namespace MEDA{
+  using namespace std;
+  using namespace boost;
+
+
+  //---------------------------------------------------------------
+  typedef set<PCellInfo> TCellSet;
+  typedef map<med_entite_maillage,TCellSet> TCellGroup;
+
+  TCellGroup GetCellsByEntity(TWrapper& theWrapper, 
+                             const PMeshInfo& theMeshInfo,
+                             const MED::TEntityInfo theEntityInfo);
+
+
+  //---------------------------------------------------------------
+  typedef set<PFamilyInfo> TFamilyGroup;
+
+  TFamilyGroup GetFamilies(TWrapper& theWrapper, 
+                          const PMeshInfo& theMeshInfo);
+
+
+  //---------------------------------------------------------------
+  typedef map<med_entite_maillage,TFamilyGroup> TFamilyByEntity;
+  
+  TFamilyByEntity GetFamiliesByEntity(TWrapper& theWrapper, 
+                                     const PNodeInfo& theNodeInfo, 
+                                     const TCellGroup& theCellGroup,
+                                     const TFamilyGroup& theFamilyGroup);
+
+
+  //---------------------------------------------------------------
+  typedef map<string,TFamilyGroup> TGroupInfo;
+  
+  TGroupInfo GetFamiliesByGroup(const TFamilyGroup& theGroupInfo);
+
+
+  //---------------------------------------------------------------
+  typedef set<PTimeStampInfo> TTimeStampSet;
+  typedef map<PFieldInfo,TTimeStampSet> TTimeStampGroup;
+
+  TTimeStampGroup GetFieldsByEntity(TWrapper& theWrapper, 
+                                   const PMeshInfo& theMeshInfo,
+                                   const MED::TEntityInfo theEntityInfo);
+
+
+  //---------------------------------------------------------------
+  typedef map<med_entite_maillage,TTimeStampGroup> TFieldGroup;
+
+  TFieldGroup GetFieldsByEntity(const TTimeStampGroup& theTimeStampGroup);
+
+};
+
+#endif
diff --git a/src/MEDWrapper/MEDA_Structures.cxx b/src/MEDWrapper/MEDA_Structures.cxx
new file mode 100644 (file)
index 0000000..eb10c07
--- /dev/null
@@ -0,0 +1,333 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.cxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#include "MEDA_Structures.hxx"
+#include "MED_Structures.hxx"
+#include "MED_Utilities.hxx"
+
+using namespace std;
+using namespace MEDA;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+//---------------------------------------------------------------
+TNameInfo::TNameInfo(const MED::PNameInfo& theInfo): 
+  myInfo(theInfo) 
+{}
+
+string TNameInfo::GetName() const{
+  return myInfo->GetName();
+}
+
+void TNameInfo::SetName(const string& theValue){
+  myInfo->SetName(theValue);
+}
+
+
+//---------------------------------------------------------------
+TMeshInfo::TMeshInfo(const MED::PMeshInfo& theInfo): 
+  TNameInfo(theInfo),
+  myInfo(theInfo)
+{}
+
+med_int TMeshInfo::GetDim() const{
+  return myInfo->myDim;
+}
+
+
+//---------------------------------------------------------------
+TFamilyInfo::TFamilyInfo(const MED::PFamilyInfo& theInfo): 
+  TNameInfo(theInfo),
+  myInfo(theInfo) 
+{}
+
+med_int TFamilyInfo::GetId() const{
+  return myInfo->myId;
+}
+
+void TFamilyInfo::SetId(med_int theId){
+  myInfo->myId = theId;
+}
+
+med_int TFamilyInfo::GetNbGroup() const{
+  return myInfo->myNbGroup;
+}
+
+string TFamilyInfo::GetGroupName(med_int theId) const{
+  return myInfo->GetGroupName(theId);
+}
+
+void TFamilyInfo::SetGroupName(med_int theId, const string& theValue){
+  myInfo->SetGroupName(theId,theValue);
+}
+
+med_int TFamilyInfo::GetNbAttr() const{
+  return myInfo->myNbAttr;
+}
+
+string TFamilyInfo::GetAttrDesc(med_int theId) const{
+  return myInfo->GetAttrDesc(theId);
+}
+
+void TFamilyInfo::SetAttrDesc(med_int theId, const string& theValue){
+  myInfo->SetAttrDesc(theId,theValue);
+}
+
+med_int TFamilyInfo::GetAttrId(med_int theId) const{
+  return myInfo->myAttrId[theId];
+}
+
+void TFamilyInfo::SetAttrId(med_int theId, med_int theVal){
+  myInfo->myAttrId[theId] = theVal;
+}
+
+med_int TFamilyInfo::GetAttrVal(med_int theId) const{
+  return myInfo->myAttrVal[theId];
+}
+
+void TFamilyInfo::SetAttrVal(med_int theId, med_int theVal){
+  myInfo->myAttrVal[theId] = theVal;
+}
+
+
+//---------------------------------------------------------------
+TElemInfo::TElemInfo(const MED::PElemInfo& theInfo): 
+  myInfo(theInfo) 
+{}
+
+med_int TElemInfo::GetNbElem() const{
+  return myInfo->myNbElem;
+}
+
+med_int TElemInfo::GetFamNum(med_int theId) const{
+  return myInfo->myFamNum[theId];
+}
+
+void TElemInfo::SetFamNum(med_int theId, med_int theValue){
+  myInfo->myFamNum[theId] = theValue;
+}
+
+med_booleen TElemInfo::IsElemNum() const{
+  return myInfo->myIsElemNum;
+}
+
+med_int TElemInfo::GetElemNum(med_int theId) const{
+  if(theId < 0 || myInfo->myElemNum.size() < theId)
+    EXCEPTION(runtime_error,"TElemInfo::GetElemNum - myInfo->myElemNum.size() = "<<
+             myInfo->myElemNum.size()<<"; theId = "<<theId<<")");
+  return myInfo->myElemNum[theId];
+}
+
+void TElemInfo::SetElemNum(med_int theId, med_int theValue){
+  if(theId < 0 || myInfo->myElemNum.size() < theId)
+    EXCEPTION(runtime_error,"TElemInfo::SetElemNum - myInfo->myElemNum.size() = "<<
+             myInfo->myElemNum.size()<<"; theId = "<<theId<<")");
+  myInfo->myElemNum[theId] = theValue;
+}
+
+med_booleen TElemInfo::IsElemNames() const{
+  return myInfo->myIsElemNames;
+}
+
+string TElemInfo::GetElemName(med_int theId) const{
+  return myInfo->GetElemName(theId);
+}
+
+void TElemInfo::SetElemName(med_int theId, const string& theValue){
+  myInfo->SetElemName(theId,theValue);
+}
+
+
+//---------------------------------------------------------------
+TNodeInfo::TNodeInfo(const MED::PNodeInfo& theInfo): 
+  TElemInfo(theInfo),
+  myInfo(theInfo) 
+{}
+
+med_repere TNodeInfo::GetSystem() const{
+  return myInfo->mySystem;
+}
+
+void TNodeInfo::GetSystem(med_repere theSystem){
+  myInfo->mySystem = theSystem;
+}
+
+med_float TNodeInfo::GetNodeCoord(med_int theId, med_int theComp) const{
+  return myInfo->myCoord[myInfo->myMeshInfo->myDim*theId + theComp];
+}
+
+void TNodeInfo::SetNodeCoord(med_int theId, med_int theComp, med_float theVal){
+  myInfo->myCoord[myInfo->myMeshInfo->myDim*theId + theComp] = theVal;
+}
+
+string TNodeInfo::GetCoordName(med_int theId) const{
+  return myInfo->GetCoordName(theId);
+}
+
+void TNodeInfo::SetCoordName(med_int theId, const string& theValue){
+  myInfo->SetCoordName(theId,theValue);
+}
+
+string TNodeInfo::GetCoordUnit(med_int theId) const{
+  return myInfo->GetCoordUnit(theId);
+}
+
+void TNodeInfo::SetCoordUnit(med_int theId, const string& theValue){
+  myInfo->SetCoordUnit(theId,theValue);
+}
+
+
+//---------------------------------------------------------------
+TCellInfo::TCellInfo(const MED::PCellInfo& theInfo): 
+  TElemInfo(theInfo),
+  myInfo(theInfo) 
+{}
+
+med_entite_maillage TCellInfo::GetEntity() const{
+  return myInfo->myTEntity;
+}
+
+med_geometrie_element TCellInfo::GetGeom() const{
+  return myInfo->myTGeom;
+}
+
+med_connectivite TCellInfo::GetConn() const{
+  return myInfo->myTConn;
+}
+
+med_int TCellInfo::GetConnDim() const{
+  return myInfo->myConnDim;
+}
+
+med_int TCellInfo::GetConn(med_int theElemId, med_int theConnId) const{
+  med_int anId = myInfo->myConnDim*theElemId + theConnId;
+  if(anId < 0 || myInfo->myConn.size() < anId)
+    EXCEPTION(runtime_error,"TElemInfo::GetConn - myInfo->myConn.size() = "<<
+             myInfo->myConn.size()<<"; anId = "<<anId<<")");
+  return myInfo->myConn[anId];
+}
+void TCellInfo::SetConn(med_int theElemId, med_int theConnId, med_int theVal){
+  med_int anId = myInfo->myConnDim*theElemId + theConnId;
+  if(anId < 0 || myInfo->myConn.size() < anId)
+    EXCEPTION(runtime_error,"TElemInfo::SetConn - myInfo->myConn.size() = "<<
+             myInfo->myConn.size()<<"; anId = "<<anId<<")");
+  myInfo->myConn[myInfo->myConnDim*theElemId + theConnId] = theVal;
+}
+
+
+//---------------------------------------------------------------
+TFieldInfo::TFieldInfo(const MED::PFieldInfo& theInfo): 
+  TNameInfo(theInfo),
+  myInfo(theInfo) 
+{}
+
+med_type_champ TFieldInfo::GetType() const{
+  return myInfo->myType;
+}
+
+med_int TFieldInfo::GetNbComp() const{
+  return myInfo->myNbComp;
+}
+
+string TFieldInfo::GetCompName(med_int theId) const{
+  return myInfo->GetCompName(theId);
+}
+
+void TFieldInfo::SetCompName(med_int theId, const string& theValue){
+  myInfo->SetCompName(theId,theValue);
+}
+
+string TFieldInfo::GetUnitName(med_int theId) const{
+  return myInfo->GetUnitName(theId);
+}
+
+void TFieldInfo::SetUnitName(med_int theId, const string& theValue){
+  myInfo->SetUnitName(theId,theValue);
+}
+
+
+//---------------------------------------------------------------
+TTimeStampInfo::TTimeStampInfo(const MED::PTimeStampInfo& theInfo): 
+  myInfo(theInfo) 
+{}
+
+med_entite_maillage TTimeStampInfo::GetEntity() const{
+  return myInfo->myEntity;
+}
+
+const MED::TGeom& TTimeStampInfo::GetGeom() const{
+  return myInfo->myGeom;
+}
+
+med_int TTimeStampInfo::GetNbGauss() const{
+  return myInfo->myNbGauss;
+}
+
+med_int TTimeStampInfo::GetNumDt() const{
+  return myInfo->myNumDt;
+}
+
+med_int TTimeStampInfo::GetNumOrd() const{
+  return myInfo->myNumOrd;
+}
+
+med_float TTimeStampInfo::GetDt() const{
+  return myInfo->myDt;
+}
+
+string TTimeStampInfo::GetUnitDt() const{
+  return myInfo->GetUnitDt();
+}
+
+void TTimeStampInfo::SetUnitDt(const string& theValue){
+  myInfo->SetUnitDt(theValue);
+}
+
+
+//---------------------------------------------------------------
+TTimeStampVal::TTimeStampVal(const MED::PTimeStampVal& theInfo): 
+  myInfo(theInfo) 
+{}
+
+med_float TTimeStampVal::GetVal(med_geometrie_element theGeom, 
+                               med_int theId, 
+                               med_int theComp, 
+                               med_int theGauss) const
+{
+  med_int aNbComp = myInfo->myTimeStampInfo->myFieldInfo->myNbComp;
+  med_int aNbGauss = myInfo->myTimeStampInfo->myNbGauss;
+  med_int aStep = aNbComp*aNbGauss;
+  return myInfo->myMeshValue[theGeom][theId*aStep + theComp*aNbGauss + theGauss];
+}
+
+void TTimeStampVal::SetVal(med_geometrie_element theGeom,
+                          med_int theId, 
+                          med_int theComp, 
+                          med_float theVal, 
+                          med_int theGauss)
+{
+  med_int aNbComp = myInfo->myTimeStampInfo->myFieldInfo->myNbComp;
+  med_int aNbGauss = myInfo->myTimeStampInfo->myNbGauss;
+  med_int aStep = aNbComp*aNbGauss;
+  myInfo->myMeshValue[theGeom][theId*aStep + theComp*aNbGauss + theGauss] = theVal;
+}
+
+string TTimeStampVal::GetPflName() const{
+  return myInfo->GetPflName();
+}
+
+void TTimeStampVal::SetPflName(const string& theValue){
+  myInfo->SetPflName(theValue);
+}
+
diff --git a/src/MEDWrapper/MEDA_Structures.hxx b/src/MEDWrapper/MEDA_Structures.hxx
new file mode 100644 (file)
index 0000000..674600a
--- /dev/null
@@ -0,0 +1,205 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.hxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#ifndef MEDA_Structures_HeaderFile
+#define MEDA_Structures_HeaderFile
+
+#include "MED_Common.hxx"
+
+namespace MEDA{
+  using namespace std;
+  using namespace boost;
+
+//---------------------------------------------------------------
+  class TNameInfo{
+    friend class TWrapper;
+    TNameInfo();
+  protected:
+    MED::PNameInfo myInfo;
+    TNameInfo(const MED::PNameInfo& theInfo);
+  public:
+    virtual ~TNameInfo() {} 
+
+    string GetName() const;
+    void SetName(const string& theValue);
+  };
+
+
+//---------------------------------------------------------------
+  class TMeshInfo: public TNameInfo{
+    friend class TWrapper;
+    TMeshInfo();
+  protected:
+    MED::PMeshInfo myInfo;
+    TMeshInfo(const MED::PMeshInfo& theInfo);
+
+  public:
+    med_int GetDim() const;
+  };
+  typedef shared_ptr<TMeshInfo> PMeshInfo;
+
+
+//---------------------------------------------------------------
+  class TFamilyInfo: public TNameInfo{
+    friend class TWrapper;
+    TFamilyInfo();
+  protected:
+    MED::PFamilyInfo myInfo;
+    TFamilyInfo(const MED::PFamilyInfo& theInfo);
+  public:
+    med_int GetId() const;
+    void SetId(med_int theId);
+
+    med_int GetNbGroup() const;
+    string GetGroupName(med_int theId) const;
+    void SetGroupName(med_int theId, const string& theValue);
+
+    med_int GetNbAttr() const;
+    string GetAttrDesc(med_int theId) const;
+    void SetAttrDesc(med_int theId, const string& theValue);
+    
+    med_int GetAttrId(med_int theId) const;
+    void SetAttrId(med_int theId, med_int theVal);
+
+    med_int GetAttrVal(med_int theId) const;
+    void SetAttrVal(med_int theId, med_int theVal);
+  };
+  typedef shared_ptr<TFamilyInfo> PFamilyInfo;
+
+
+//---------------------------------------------------------------
+  class TElemInfo{
+    friend class TWrapper;
+    TElemInfo();
+  protected:
+    MED::PElemInfo myInfo;
+    TElemInfo(const MED::PElemInfo& theInfo);
+  public:
+    virtual ~TElemInfo() {} 
+
+    med_int GetNbElem() const;
+
+    med_int GetFamNum(med_int theId) const;
+    void SetFamNum(med_int theId, med_int theValue);
+
+    med_booleen IsElemNum() const;
+    med_int GetElemNum(med_int theId) const;
+    void SetElemNum(med_int theId, med_int theValue);
+
+    med_booleen IsElemNames() const;
+    string GetElemName(med_int theId) const;
+    void SetElemName(med_int theId, const string& theValue);
+  };
+
+
+//---------------------------------------------------------------
+  class TNodeInfo: public TElemInfo{
+    friend class TWrapper;
+    TNodeInfo();
+  protected:
+    MED::PNodeInfo myInfo;
+    TNodeInfo(const MED::PNodeInfo& theInfo);
+  public:
+    med_repere GetSystem() const;
+    void GetSystem(med_repere theSystem);
+    
+    med_float GetNodeCoord(med_int theId, med_int theComp) const;
+    void SetNodeCoord(med_int theId, med_int theComp, med_float theVal);
+
+    string GetCoordName(med_int theId) const;
+    void SetCoordName(med_int theId, const string& theValue);
+
+    string GetCoordUnit(med_int theId) const;
+    void SetCoordUnit(med_int theId, const string& theValue);
+  };
+  typedef shared_ptr<TNodeInfo> PNodeInfo;
+
+
+//---------------------------------------------------------------
+  class TCellInfo: public TElemInfo{
+    friend class TWrapper;
+    TCellInfo();
+  protected:
+    MED::PCellInfo myInfo;
+    TCellInfo(const MED::PCellInfo& theInfo);
+  public:
+    med_entite_maillage GetEntity() const;
+    med_geometrie_element GetGeom() const;
+    med_connectivite GetConn() const;
+    
+    med_int GetConnDim() const;
+    med_int GetConn(med_int theElemId, med_int theConnId) const;
+    void SetConn(med_int theElemId, med_int theConnId, med_int theVal);
+  };
+  typedef shared_ptr<TCellInfo> PCellInfo;
+
+
+//---------------------------------------------------------------
+  class TFieldInfo: public TNameInfo{
+    friend class TWrapper;
+    TFieldInfo();
+  protected:
+    MED::PFieldInfo myInfo;
+    TFieldInfo(const MED::PFieldInfo& theInfo);
+  public:
+    med_type_champ GetType() const;
+    med_int GetNbComp() const;
+
+    string GetCompName(med_int theId) const;
+    void SetCompName(med_int theId, const string& theValue);
+
+    string GetUnitName(med_int theId) const;
+    void SetUnitName(med_int theId, const string& theValue);
+  };
+  typedef shared_ptr<TFieldInfo> PFieldInfo;
+
+
+//---------------------------------------------------------------
+  class TTimeStampInfo{
+    friend class TWrapper;
+    TTimeStampInfo();
+  protected:
+    MED::PTimeStampInfo myInfo;
+    TTimeStampInfo(const MED::PTimeStampInfo& theInfo);
+  public:
+    med_entite_maillage GetEntity() const;
+    const MED::TGeom& GetGeom() const;
+
+    med_int GetNbGauss() const;
+    med_int GetNumDt() const;
+    med_int GetNumOrd() const;
+
+    med_float GetDt() const;
+
+    string GetUnitDt() const;
+    void SetUnitDt(const string& theValue);
+  };
+  typedef shared_ptr<TTimeStampInfo> PTimeStampInfo;
+  
+
+//---------------------------------------------------------------
+  class TTimeStampVal{
+    friend class TWrapper;
+    TTimeStampVal();
+  protected:
+    MED::PTimeStampVal myInfo;
+    TTimeStampVal(const MED::PTimeStampVal& theInfo);
+  public:
+    med_float GetVal(med_geometrie_element theGeom, med_int theId, 
+                    med_int theComp, med_int theGauss = 0) const;
+    void SetVal(med_geometrie_element theGeom, med_int theId, 
+               med_int theComp, med_float theVal, med_int theGauss = 0);
+    
+    string GetPflName() const;
+    void SetPflName(const string& theValue);
+  };
+  typedef shared_ptr<TTimeStampVal> PTimeStampVal;
+  
+};
+
+#endif
diff --git a/src/MEDWrapper/MEDA_Test.cxx b/src/MEDWrapper/MEDA_Test.cxx
new file mode 100644 (file)
index 0000000..396dd1d
--- /dev/null
@@ -0,0 +1,182 @@
+//  VISU OBJECT : interactive object for VISU entities implementation
+//
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//  File:    VISUConvertor.cxx
+//  Author:  Alexey PETROV
+//  Module : VISU
+
+#include "MEDA_Structures.hxx"
+#include "MEDA_Wrapper.hxx"
+#include "MED_Utilities.hxx"
+
+using namespace std;
+
+#ifdef DEBUG
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+void ReadMed(const char* theFileName){
+  using namespace MEDA;
+  TWrapper aMed(theFileName);
+  string aFileName = theFileName;
+  aFileName += "+";
+  TWrapper aMedW(aFileName);
+
+  int aNbMeshes = aMed.GetNbMeshes();
+  cout<<"GetNbMeshes() = "<<aNbMeshes<<endl;
+
+  string aName;
+  for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
+    PMeshInfo aMeshInfo = aMed.GetMeshInfo(iMesh);
+    int aDim = aMeshInfo->GetDim();
+    PMeshInfo aMeshInfoW = TWrapper::CrMeshInfo(aMeshInfo);
+    aName = aMeshInfoW->GetName();
+    cout<<"GetMeshInfo - aName = '"<<aName<<"'; aDim = "<<aDim<<endl;
+    aName[0] += 1;
+    aMeshInfoW->SetName(aName);
+    aMedW.SetMeshInfo(aMeshInfoW);
+  
+    int aNbFam = aMed.GetNbFamilies(aMeshInfo);
+    cout<<"GetNbFamilies() = "<<aNbFam<<endl;
+    for(int iFam = 0; iFam < aNbFam; iFam++){
+      PFamilyInfo aFamilyInfo = aMed.GetFamilyInfo(aMeshInfo,iFam);
+      PFamilyInfo aFamilyInfoW = TWrapper::CrFamilyInfo(aMeshInfoW,aFamilyInfo);
+      aName = aFamilyInfo->GetName();
+      int aNbAttr = aFamilyInfo->GetNbAttr();
+      int aNbGroup = aFamilyInfo->GetNbGroup();
+      cout<<"\taName = '"<<aName<<"'; aNbAttr = "<<aNbAttr<<"; aNbGroup = "<<aNbGroup<<endl;
+      aName[0] += 1;
+      aFamilyInfoW->SetName(aName);
+      for(int iGroup = 0; iGroup < aNbGroup; iGroup++){
+       aName = aFamilyInfo->GetGroupName(iGroup);
+       cout<<"\t\taGroupName = '"<<aName<<"'\n";
+       aName[0] += 1;
+       aFamilyInfoW->SetGroupName(iGroup,aName);
+      }
+      aMedW.SetFamilyInfo(aFamilyInfoW);
+    }
+
+    MED::TEntityInfo aEntityInfo = aMed.GetEntityInfo(aMeshInfo);
+    cout<<"GetEntityInfo - aNbEntities = "<<aEntityInfo.size()<<endl;
+    MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
+    for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
+      const med_entite_maillage& anEntity = anEntityIter->first;
+      cout<<"\tanEntity = "<<anEntity<<endl;
+      if(anEntity == MED_NOEUD){
+       PNodeInfo aNodeInfo = aMed.GetNodeInfo(aMeshInfo);
+       PNodeInfo aNodeInfoW = TWrapper::CrNodeInfo(aMeshInfoW,aNodeInfo);
+       int aNbNodes = aNodeInfo->GetNbElem();
+       cout<<"\tGetNodeInfo - aNbNodes = "<<aNbNodes<<": ";
+       for(int iNode = 0; iNode < aNbNodes; iNode++){
+         for(int iDim = 0; iDim < aDim; iDim++){
+           //cout<<aNodeInfo->GetNodeCoord(iNode,iDim)<<",";
+         }
+         cout<<" ";
+       }
+       cout<<endl;
+       aMedW.SetNodeInfo(aNodeInfoW);
+       continue;
+      }
+      const MED::TGeom& aTGeom = anEntityIter->second;
+      MED::TGeom::const_iterator anTGeomIter = aTGeom.begin();
+      for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
+       const med_geometrie_element& aGeom = anTGeomIter->first;
+       PCellInfo aCellInfo = aMed.GetCellInfo(aMeshInfo,anEntity,aGeom);
+       PCellInfo aCellInfoW = TWrapper::CrCellInfo(aMeshInfoW,aCellInfo);
+       med_int aNbElem = aCellInfo->GetNbElem();
+       cout<<"\t\taGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<": ";
+       for(int iElem = 0; iElem < aNbElem; iElem++){
+         int iConnEnd = aCellInfo->GetConnDim();
+         for(int iConn = 0; iConn < iConnEnd; iConn++){
+           //cout<<aCellInfo->GetConn(iElem,iConn)<<",";
+         }
+         cout<<" ";
+       }
+       cout<<endl;
+       aMedW.SetCellInfo(aCellInfoW);
+      }
+    }
+
+    med_int aNbFields = aMed.GetNbFields(); 
+    cout<<"GetNbFields() = "<<aNbFields<<endl;
+    for(int iField = 0; iField < aNbFields; iField++){
+      PFieldInfo aFieldInfo = aMed.GetFieldInfo(aMeshInfo,iField);
+      PFieldInfo aFieldInfoW = TWrapper::CrFieldInfo(aMeshInfoW,aFieldInfo);
+      med_int aNbComp = aFieldInfo->GetNbComp();
+      aName = aFieldInfo->GetName();
+      cout<<"\taName = '"<<aName<<"'; aNbComp = "<<aNbComp<<"; ";
+      aName[0] += 1;
+      aFieldInfoW->SetName(aName);
+      aMedW.SetFieldInfo(aFieldInfoW);
+      MED::TGeom aTGeom;
+      med_entite_maillage anEntity;
+      med_int aNbTimeStamps = aMed.GetNbTimeStamps(aFieldInfo,aEntityInfo,anEntity,aTGeom);
+      cout<<"anEntity = "<<anEntity<<"; GetNbTimeStamps = "<<aNbTimeStamps<<endl;
+      for(int iTimeStamp = 0; iTimeStamp < aNbTimeStamps; iTimeStamp++){
+       PTimeStampInfo aTimeStamp = aMed.GetTimeStampInfo(aFieldInfo,iTimeStamp,
+                                                         anEntity,aTGeom);
+       PTimeStampInfo aTimeStampW = TWrapper::CrTimeStampInfo(aFieldInfoW,aTimeStamp);
+       med_int aNbGauss = aTimeStamp->GetNbGauss();
+       cout<<"\t\taDt = "<<aTimeStamp->GetDt()<<", "<<aTimeStamp->GetUnitDt()<<endl;
+       PTimeStampVal aTimeStampVal = aMed.GetTimeStampVal(aTimeStamp);
+       PTimeStampVal aTimeStampValW = TWrapper::CrTimeStampVal(aTimeStampW,aTimeStampVal);
+       MED::TGeom::const_iterator anTGeomIter = aTGeom.begin();
+       for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
+         const med_geometrie_element& aGeom = anTGeomIter->first;
+         med_int aNbElem = anTGeomIter->second;
+         cout<<"\t\taGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<": ";
+         for(int iElem = 0; iElem < aNbElem; iElem++){
+           for(int j = 0; j < aNbComp; j++){
+             for(int k = 0; k < aNbGauss; k++){
+               //cout<<aTimeStampValW->GetVal(aGeom,iElem,j,k)<<",";
+             }
+           }
+           cout<<" ";
+         }
+         cout<<"\n";
+       }
+       aMedW.SetTimeStamp(aTimeStampValW);
+      }
+    }    
+  }
+  cout<<"OK"<<endl;
+}
+
+
+int main(int argc, char** argv){ 
+    if(argc > 1)
+      ReadMed(argv[1]);
+    return 0;
+  try{
+    if(argc > 1)
+      ReadMed(argv[1]);
+    return 0;
+  }catch(std::exception& exc){
+    cout<<"Follow exception was accured :\n"<<exc.what()<<endl;
+  }catch(...){
+    cout<<"Unknown exception was accured in VISU_Convertor_impl"<<endl;
+  } 
+  return 1;
+}
diff --git a/src/MEDWrapper/MEDA_Test1.cxx b/src/MEDWrapper/MEDA_Test1.cxx
new file mode 100644 (file)
index 0000000..4b0158c
--- /dev/null
@@ -0,0 +1,92 @@
+//  VISU OBJECT : interactive object for VISU entities implementation
+//
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//  File:    VISUConvertor.cxx
+//  Author:  Alexey PETROV
+//  Module : VISU
+
+#include "MEDA_Algorithm.hxx"
+#include "MED_Utilities.hxx"
+
+using namespace std;
+using namespace MEDA;
+
+#ifdef DEBUG
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+namespace MEDA{
+  using namespace std;
+  using namespace boost;
+  
+  
+};
+
+void ReadMed(const char* theFileName){
+  TWrapper aMed(theFileName);
+  string aFileName = theFileName;
+  aFileName += "+";
+  TWrapper aMedW(aFileName);
+
+  int aNbMeshes = aMed.GetNbMeshes();
+  cout<<"GetNbMeshes() = "<<aNbMeshes<<endl;
+
+  string aName;
+  for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
+    PMeshInfo aMeshInfo = aMed.GetMeshInfo(iMesh);
+  
+    PNodeInfo aNodeInfo = aMed.GetNodeInfo(aMeshInfo);
+
+    MED::TEntityInfo aEntityInfo = aMed.GetEntityInfo(aMeshInfo);
+
+    TCellGroup aCellGroup = GetCellsByEntity(aMed,aMeshInfo,aEntityInfo);
+
+    TFamilyGroup aFamilyGroup = GetFamilies(aMed,aMeshInfo);
+
+    TFamilyByEntity aFamilyByEntity = GetFamiliesByEntity(aMed,aNodeInfo,aCellGroup,aFamilyGroup);
+
+    TGroupInfo aGroupInfo = GetFamiliesByGroup(aFamilyGroup);
+
+    TTimeStampGroup aTimeStampGroup = GetFieldsByEntity(aMed,aMeshInfo,aEntityInfo);
+
+    TFieldGroup aFieldGroup = GetFieldsByEntity(aTimeStampGroup);
+
+  }
+  cout<<"OK"<<endl;
+}
+
+
+int main(int argc, char** argv){ 
+  try{
+    if(argc > 1)
+      ReadMed(argv[1]);
+    return 0;
+  }catch(std::exception& exc){
+    cout<<"Follow exception was accured :\n"<<exc.what()<<endl;
+  }catch(...){
+    cout<<"Unknown exception was accured in VISU_Convertor_impl"<<endl;
+  } 
+  return 1;
+}
diff --git a/src/MEDWrapper/MEDA_Wrapper.cxx b/src/MEDWrapper/MEDA_Wrapper.cxx
new file mode 100644 (file)
index 0000000..f48e7b4
--- /dev/null
@@ -0,0 +1,355 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.cxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#include "MEDA_Wrapper.hxx"
+#include "MED_Wrapper.hxx"
+#include "MED_Utilities.hxx"
+
+using namespace std;
+using namespace MEDA;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+//---------------------------------------------------------------
+TWrapper::TWrapper(const string& theFileName):
+  myWrapper(new MED::TWrapper(theFileName))
+{}
+
+
+//---------------------------------------------------------------
+PMeshInfo TWrapper::CrMeshInfo(med_int theDim,
+                              const string& theValue)
+{
+  MED::PMeshInfo anInfo(new MED::TMeshInfo(theDim,theValue));
+  return PMeshInfo(new TMeshInfo(anInfo));
+}
+
+PMeshInfo TWrapper::CrMeshInfo(const PMeshInfo& theInfo){
+  MED::PMeshInfo anInfo(new MED::TMeshInfo(*theInfo->myInfo));
+  return PMeshInfo(new TMeshInfo(anInfo));
+}
+
+med_int TWrapper::GetNbMeshes(){
+  return myWrapper->GetNbMeshes();
+}
+
+PMeshInfo TWrapper::GetMeshInfo(med_int theId){
+  PMeshInfo anInfo = CrMeshInfo();
+  myWrapper->GetMeshInfo(theId+1,*anInfo->myInfo);
+  if(MYDEBUG){
+    MESSAGE("GetMeshInfo(...)");
+    MED::PrefixPrinter aPrefixPrinter;
+    BEGMSG("aName = '"<<anInfo->GetName()<<"'; aDim = "<<anInfo->GetDim()<<"\n");
+    ADDMSG("\n");
+  }
+  return anInfo;
+}
+
+void TWrapper::SetMeshInfo(const PMeshInfo& theInfo){
+  myWrapper->SetMeshInfo(*theInfo->myInfo);
+}
+
+
+//---------------------------------------------------------------
+PFamilyInfo TWrapper::CrFamilyInfo(const PMeshInfo& theMeshInfo, 
+                                  med_int theNbGroup,
+                                  med_int theNbAttr,
+                                  med_int theId,
+                                  const string& theValue)
+{
+  const MED::PMeshInfo& aMeshInfo = theMeshInfo->myInfo;
+  MED::PFamilyInfo anInfo(new MED::TFamilyInfo(aMeshInfo,
+                                              theNbGroup,
+                                              theNbAttr,
+                                              theId,
+                                              theValue));
+  return PFamilyInfo(new TFamilyInfo(anInfo));
+}
+
+PFamilyInfo TWrapper::CrFamilyInfo(const PMeshInfo& theMeshInfo,
+                                  const string& theValue,
+                                  med_int theId,
+                                  const MED::TStringSet& theGroupNames, 
+                                  const MED::TStringVector& theAttrDescs, 
+                                  const MED::TIntVector& theAttrIds, 
+                                  const MED::TIntVector& theAttrVals)
+{
+  const MED::PMeshInfo& aMeshInfo = theMeshInfo->myInfo;
+  MED::PFamilyInfo anInfo(new MED::TFamilyInfo(aMeshInfo,
+                                              theValue,
+                                              theId,
+                                              theGroupNames,
+                                              theAttrDescs,
+                                              theAttrIds,
+                                              theAttrVals));
+  return PFamilyInfo(new TFamilyInfo(anInfo));
+}
+
+PFamilyInfo TWrapper::CrFamilyInfo(const PMeshInfo& theMeshInfo,
+                                  const PFamilyInfo& theInfo)
+{
+  MED::PFamilyInfo anInfo(new MED::TFamilyInfo(*theInfo->myInfo));
+  anInfo->myMeshInfo = theMeshInfo->myInfo;
+  return PFamilyInfo(new TFamilyInfo(anInfo));
+}
+
+med_int TWrapper::GetNbFamilies(const PMeshInfo& theMeshInfo){
+  return myWrapper->GetNbFamilies(*theMeshInfo->myInfo);
+}
+
+PFamilyInfo TWrapper::GetFamilyInfo(const PMeshInfo& theMeshInfo, med_int theId){
+  med_int aNbAttr = myWrapper->GetNbFamAttr(theId+1,*theMeshInfo->myInfo);
+  med_int aNbGroup = myWrapper->GetNbFamGroup(theId+1,*theMeshInfo->myInfo);
+  PFamilyInfo anInfo = CrFamilyInfo(theMeshInfo,aNbGroup,aNbAttr);
+  myWrapper->GetFamilyInfo(theId+1,*anInfo->myInfo);
+  if(MYDEBUG){
+    MESSAGE("GetFamilyInfo(...)");
+    MED::PrefixPrinter aPrefixPrinter;
+    BEGMSG("aName = '"<<anInfo->GetName()<<"'; anId = "<<anInfo->GetId()<<"\n");
+    ADDMSG("\n");
+  }
+  return anInfo;
+}
+
+void TWrapper::SetFamilyInfo(const PFamilyInfo& theInfo){
+  myWrapper->SetFamilyInfo(*theInfo->myInfo);
+}
+
+
+//---------------------------------------------------------------
+PNodeInfo TWrapper::CrNodeInfo(const PMeshInfo& theMeshInfo, 
+                              med_int theNbElem,
+                              med_repere theSystem, 
+                              med_booleen theIsElemNum,
+                              med_booleen theIsElemNames)
+{
+  const MED::PMeshInfo& aMeshInfo = theMeshInfo->myInfo;
+  MED::PNodeInfo anInfo(new MED::TNodeInfo(aMeshInfo,
+                                          theNbElem,
+                                          theSystem,
+                                          theIsElemNum,
+                                          theIsElemNames));
+  return PNodeInfo(new TNodeInfo(anInfo));
+}
+
+PNodeInfo TWrapper::CrNodeInfo(const PMeshInfo& theMeshInfo, 
+                              med_repere theSystem, 
+                              const MED::TFloatVector& theNodeCoords,
+                              const MED::TStringVector& theCoordNames,
+                              const MED::TStringVector& theCoordUnits,
+                              const MED::TIntVector& theFamilyNums,
+                              const MED::TIntVector& theElemNums,
+                              const MED::TStringVector& theElemNames)
+{
+  const MED::PMeshInfo& aMeshInfo = theMeshInfo->myInfo;
+  MED::PNodeInfo anInfo(new MED::TNodeInfo(aMeshInfo,
+                                          theSystem,
+                                          theNodeCoords,
+                                          theCoordNames,
+                                          theCoordUnits,
+                                          theFamilyNums,
+                                          theElemNums,
+                                          theElemNames));
+  return PNodeInfo(new TNodeInfo(anInfo));
+}
+
+PNodeInfo TWrapper::CrNodeInfo(const PMeshInfo& theMeshInfo,
+                              const PNodeInfo& theInfo)
+{
+  MED::PNodeInfo anInfo(new MED::TNodeInfo(*theInfo->myInfo));
+  anInfo->myMeshInfo = theMeshInfo->myInfo;
+  return PNodeInfo(new TNodeInfo(anInfo));
+}
+
+PNodeInfo TWrapper::GetNodeInfo(const PMeshInfo& theMeshInfo){
+  med_int aNbElems = myWrapper->GetNbNodes(*theMeshInfo->myInfo);
+  PNodeInfo anInfo = CrNodeInfo(theMeshInfo,aNbElems);
+  myWrapper->GetNodeInfo(*anInfo->myInfo);
+  return anInfo;
+}
+
+void TWrapper::SetNodeInfo(const PNodeInfo& theInfo){
+  myWrapper->SetNodeInfo(*theInfo->myInfo);
+}
+
+
+//---------------------------------------------------------------
+MED::TEntityInfo TWrapper::GetEntityInfo(const PMeshInfo& theMeshInfo){
+  return myWrapper->GetEntityInfo(*theMeshInfo->myInfo);
+}
+
+PCellInfo TWrapper::CrCellInfo(const PMeshInfo& theMeshInfo, 
+                              med_int theNbElem,
+                              med_entite_maillage theEntity, 
+                              med_geometrie_element theGeom,
+                              med_connectivite theConn,
+                              med_booleen theIsElemNum,
+                              med_booleen theIsElemNames)
+{
+  MED::PCellInfo anInfo(new MED::TCellInfo(theMeshInfo->myInfo,
+                                          theNbElem,
+                                          theEntity,
+                                          theGeom,
+                                          theConn,
+                                          theIsElemNum,
+                                          theIsElemNames));
+  return PCellInfo(new TCellInfo(anInfo));
+}
+
+PCellInfo TWrapper::CrCellInfo(const PMeshInfo& theMeshInfo, 
+                              med_entite_maillage theEntity, 
+                              med_geometrie_element theGeom,
+                              med_connectivite theConn,
+                              const MED::TIntVector& theConnectivities,
+                              const MED::TIntVector& theFamilyNums,
+                              const MED::TIntVector& theElemNums,
+                              const MED::TStringVector& theElemNames)
+{
+  MED::PCellInfo anInfo(new MED::TCellInfo(theMeshInfo->myInfo,
+                                          theEntity,
+                                          theGeom,
+                                          theConn,
+                                          theConnectivities,
+                                          theFamilyNums,
+                                          theElemNums,
+                                          theElemNames));
+  return PCellInfo(new TCellInfo(anInfo));
+}
+
+PCellInfo TWrapper::CrCellInfo(const PMeshInfo& theMeshInfo,
+                              const PCellInfo& theInfo)
+{
+  MED::PCellInfo anInfo(new MED::TCellInfo(*theInfo->myInfo));
+  anInfo->myMeshInfo = theMeshInfo->myInfo;
+  return PCellInfo(new TCellInfo(anInfo));
+}
+
+PCellInfo TWrapper::GetCellInfo(const PMeshInfo& theMeshInfo, 
+                               med_entite_maillage theEntity, 
+                               med_geometrie_element theGeom, 
+                               med_connectivite theConn)
+{
+  med_int aNbElem = myWrapper->GetNbCells(*theMeshInfo->myInfo,theEntity,theGeom,theConn);
+  PCellInfo anInfo = CrCellInfo(theMeshInfo,aNbElem,theEntity,theGeom,theConn);
+  myWrapper->GetCellInfo(*anInfo->myInfo);
+  return anInfo;
+}
+
+void TWrapper::SetCellInfo(const PCellInfo& theInfo){
+  myWrapper->SetCellInfo(*theInfo->myInfo);
+}
+
+
+//---------------------------------------------------------------
+PFieldInfo TWrapper::CrFieldInfo(const PMeshInfo& theMeshInfo, 
+                                med_int theNbComp,
+                                med_type_champ theType,
+                                const string& theValue)
+{
+  MED::PFieldInfo anInfo(new MED::TFieldInfo(theMeshInfo->myInfo,
+                                            theNbComp,
+                                            theType,
+                                            theValue));
+  return PFieldInfo(new TFieldInfo(anInfo));
+}
+
+PFieldInfo TWrapper::CrFieldInfo(const PMeshInfo& theMeshInfo,
+                                const PFieldInfo& theInfo)
+{
+  MED::PFieldInfo anInfo(new MED::TFieldInfo(*theInfo->myInfo));
+  anInfo->myMeshInfo = theMeshInfo->myInfo;
+  return PFieldInfo(new TFieldInfo(anInfo));
+}
+
+med_int TWrapper::GetNbFields(){
+  return myWrapper->GetNbFields();
+}
+
+PFieldInfo TWrapper::GetFieldInfo(const PMeshInfo& theMeshInfo, med_int theId){
+  med_int aNbComp = myWrapper->GetNbComp(theId+1);
+  PFieldInfo anInfo = CrFieldInfo(theMeshInfo,aNbComp);
+  myWrapper->GetFieldInfo(theId+1,*anInfo->myInfo);
+  return anInfo;
+}
+
+void TWrapper::SetFieldInfo(const PFieldInfo& theInfo){
+  myWrapper->SetFieldInfo(*theInfo->myInfo);
+}
+
+
+//---------------------------------------------------------------
+PTimeStampInfo TWrapper::CrTimeStampInfo(const PFieldInfo& theFieldInfo, 
+                                        med_entite_maillage theEntity,
+                                        const MED::TGeom& theGeom)
+{
+  MED::PTimeStampInfo anInfo(new MED::TTimeStampInfo(theFieldInfo->myInfo,
+                                                    theEntity,
+                                                    theGeom));
+  return PTimeStampInfo(new TTimeStampInfo(anInfo));
+}
+
+PTimeStampInfo TWrapper::CrTimeStampInfo(const PFieldInfo& theFieldInfo,
+                                        const PTimeStampInfo& theInfo)
+{
+  MED::PTimeStampInfo anInfo(new MED::TTimeStampInfo(*theInfo->myInfo));
+  anInfo->myFieldInfo = theFieldInfo->myInfo;
+  return PTimeStampInfo(new TTimeStampInfo(anInfo));
+}
+
+med_int TWrapper::GetNbTimeStamps(const PFieldInfo& theFieldInfo, 
+                                 const MED::TEntityInfo& theEntityInfo,
+                                 med_entite_maillage& theEntity,
+                                 MED::TGeom& theGeom)
+{
+  return myWrapper->GetNbTimeStamps(*theFieldInfo->myInfo,
+                                   theEntityInfo,
+                                   theEntity,
+                                   theGeom);
+}
+
+PTimeStampInfo TWrapper::GetTimeStampInfo(const PFieldInfo& theFieldInfo,
+                                         med_int theId,
+                                         med_entite_maillage theEntity,
+                                         const MED::TGeom& theGeom)
+{
+  PTimeStampInfo anInfo = CrTimeStampInfo(theFieldInfo,theEntity,theGeom);
+  myWrapper->GetTimeStampInfo(theId+1,*anInfo->myInfo);
+  return anInfo;
+}
+
+
+//---------------------------------------------------------------
+PTimeStampVal TWrapper::CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo)
+{
+  MED::PTimeStampVal anInfo(new MED::TTimeStampVal(theTimeStampInfo->myInfo));
+  return PTimeStampVal(new TTimeStampVal(anInfo));
+}
+
+PTimeStampVal TWrapper::CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
+                                      const PTimeStampVal& theInfo)
+{
+  MED::PTimeStampVal anInfo(new MED::TTimeStampVal(*theInfo->myInfo));
+  anInfo->myTimeStampInfo = theTimeStampInfo->myInfo;
+  return PTimeStampVal(new TTimeStampVal(anInfo));
+}
+
+PTimeStampVal TWrapper::GetTimeStampVal(const PTimeStampInfo& theTimeStampInfo)
+{
+  PTimeStampVal anInfo = CrTimeStampVal(theTimeStampInfo);
+  myWrapper->GetTimeStampVal(*anInfo->myInfo);
+  return anInfo;
+}
+
+void TWrapper::SetTimeStamp(const PTimeStampVal& theTimeStampVal){
+  myWrapper->SetTimeStamp(*theTimeStampVal->myInfo);
+}
diff --git a/src/MEDWrapper/MEDA_Wrapper.hxx b/src/MEDWrapper/MEDA_Wrapper.hxx
new file mode 100644 (file)
index 0000000..e135e21
--- /dev/null
@@ -0,0 +1,161 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.hxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#ifndef MEDA_Wrapper_HeaderFile
+#define MEDA_Wrapper_HeaderFile
+
+#include "MEDA_Structures.hxx"
+
+namespace MEDA{
+  class TWrapper{
+    TWrapper();
+    TWrapper(const TWrapper&);
+  protected:
+    MED::PWrapper myWrapper;
+    
+  public:
+    TWrapper(const string& theFileName);
+
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    static PMeshInfo CrMeshInfo(med_int theDim = 0,
+                               const string& theValue = "");
+
+    static PMeshInfo CrMeshInfo(const PMeshInfo& theMeshInfo);
+
+    med_int GetNbMeshes();
+
+    PMeshInfo GetMeshInfo(med_int theId);
+
+    void SetMeshInfo(const PMeshInfo& theInfo);
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    static PFamilyInfo CrFamilyInfo(const PMeshInfo& theMeshInfo,
+                                   med_int theNbGroup = 0, 
+                                   med_int theNbAttr = 0,
+                                   med_int theId = 0,
+                                   const string& theValue = "");
+
+    static PFamilyInfo CrFamilyInfo(const PMeshInfo& theMeshInfo,
+                                   const string& theValue,
+                                   med_int theId,
+                                   const MED::TStringSet& theGroupNames, 
+                                   const MED::TStringVector& theAttrDescs = MED::TStringVector(), 
+                                   const MED::TIntVector& theAttrIds = MED::TIntVector(), 
+                                   const MED::TIntVector& theAttrVals = MED::TIntVector());
+
+    static PFamilyInfo CrFamilyInfo(const PMeshInfo& theMeshInfo,
+                                   const PFamilyInfo& theInfo);
+
+    med_int GetNbFamilies(const PMeshInfo& theMeshInfo);
+
+    PFamilyInfo GetFamilyInfo(const PMeshInfo& theMeshInfo, med_int theId);
+
+    void SetFamilyInfo(const PFamilyInfo& theInfo);
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    static PNodeInfo CrNodeInfo(const PMeshInfo& theMeshInfo, 
+                               med_int theNbElem,
+                               med_repere theSystem = MED_CART, 
+                               med_booleen theIsElemNum = MED_VRAI,
+                               med_booleen theIsElemNames = MED_VRAI);
+
+    static PNodeInfo CrNodeInfo(const PMeshInfo& theMeshInfo, 
+                               med_repere theSystem, 
+                               const MED::TFloatVector& theNodeCoords,
+                               const MED::TStringVector& theCoordNames,
+                               const MED::TStringVector& theCoordUnits,
+                               const MED::TIntVector& theFamilyNums,
+                               const MED::TIntVector& theElemNums,
+                               const MED::TStringVector& theElemNames = MED::TStringVector());
+
+    static PNodeInfo CrNodeInfo(const PMeshInfo& theMeshInfo,
+                               const PNodeInfo& theInfo);
+
+    PNodeInfo GetNodeInfo(const PMeshInfo& theMeshInfo);
+
+    void SetNodeInfo(const PNodeInfo& theInfo);
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    MED::TEntityInfo GetEntityInfo(const PMeshInfo& theMeshInfo);
+
+    static PCellInfo CrCellInfo(const PMeshInfo& theMeshInfo, 
+                               med_int theNbElem,
+                               med_entite_maillage theEntity, 
+                               med_geometrie_element theGeom,
+                               med_connectivite theConn = MED_NOD,
+                               med_booleen theIsElemNum = MED_VRAI,
+                               med_booleen theIsElemNames = MED_VRAI);
+
+    static PCellInfo CrCellInfo(const PMeshInfo& theMeshInfo, 
+                               med_entite_maillage theEntity, 
+                               med_geometrie_element theGeom,
+                               med_connectivite theConn,
+                               const MED::TIntVector& theConnectivities,
+                               const MED::TIntVector& theFamilyNums,
+                               const MED::TIntVector& theElemNums,
+                               const MED::TStringVector& theElemNames = MED::TStringVector());
+
+    static PCellInfo CrCellInfo(const PMeshInfo& theMeshInfo,
+                               const PCellInfo& theInfo);
+
+    PCellInfo GetCellInfo(const PMeshInfo& theMeshInfo, 
+                         med_entite_maillage theEntity, 
+                         med_geometrie_element theGeom, 
+                         med_connectivite theConn = MED_NOD);
+
+    void SetCellInfo(const PCellInfo& theInfo);
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    static PFieldInfo CrFieldInfo(const PMeshInfo& theMeshInfo, 
+                                 med_int theNbComp = 0,
+                                 med_type_champ theType = MED_REEL64,
+                                 const string& theValue = "");
+
+    static PFieldInfo CrFieldInfo(const PMeshInfo& theMeshInfo,
+                                 const PFieldInfo& theInfo);
+    med_int GetNbFields();
+
+    PFieldInfo GetFieldInfo(const PMeshInfo& theMeshInfo, med_int theId);
+
+    void SetFieldInfo(const PFieldInfo& theInfo);
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    static PTimeStampInfo CrTimeStampInfo(const PFieldInfo& theFieldInfo, 
+                                         med_entite_maillage theEntity,
+                                         const MED::TGeom& theGeom);
+
+    static PTimeStampInfo CrTimeStampInfo(const PFieldInfo& theFieldInfo,
+                                         const PTimeStampInfo& theInfo);
+
+    med_int GetNbTimeStamps(const PFieldInfo& theFieldInfo, 
+                           const MED::TEntityInfo& theEntityInfo,
+                           med_entite_maillage& theEntity,
+                           MED::TGeom& theGeom);
+
+    PTimeStampInfo GetTimeStampInfo(const PFieldInfo& theFieldInfo,
+                                   med_int theId,
+                                   med_entite_maillage theEntity,
+                                   const MED::TGeom& theGeom);
+
+    
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    static PTimeStampVal CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo);
+
+    static PTimeStampVal CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
+                                       const PTimeStampVal& theInfo);
+
+    PTimeStampVal GetTimeStampVal(const PTimeStampInfo& theTimeStampInfo);
+
+    void SetTimeStamp(const PTimeStampVal& theTimeStampVal);
+  };
+
+};
+
+
+#endif
diff --git a/src/MEDWrapper/MED_Common.hxx b/src/MEDWrapper/MED_Common.hxx
new file mode 100644 (file)
index 0000000..0afa3b4
--- /dev/null
@@ -0,0 +1,71 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.hxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#ifndef MED_Common_HeaderFile
+#define MED_Common_HeaderFile
+
+#include <string>
+#include <vector>
+#include <set>
+#include <map>
+
+extern "C"{
+#include <med.h>
+}  
+
+#include <boost/shared_ptr.hpp>
+
+namespace MED{
+  using namespace std;
+  using namespace boost;
+
+  typedef vector<med_float> TFloatVector;
+  typedef vector<string> TStringVector;
+  typedef vector<med_int> TIntVector;
+  typedef set<string> TStringSet;
+
+  typedef map<med_geometrie_element,med_int> TGeom;
+  typedef map<med_entite_maillage,TGeom> TEntityInfo;
+
+  med_int GetNbConn(med_entite_maillage theMedEntity, 
+                   med_geometrie_element theMedType,
+                   med_int theMeshDim);
+
+  struct TNameInfo;
+  typedef shared_ptr<TNameInfo> PNameInfo;
+  
+  struct TMeshInfo;
+  typedef shared_ptr<TMeshInfo> PMeshInfo;
+  
+  struct TFamilyInfo;
+  typedef shared_ptr<TFamilyInfo> PFamilyInfo;
+
+  struct TElemInfo;
+  typedef shared_ptr<TElemInfo> PElemInfo;
+
+  struct TNodeInfo;
+  typedef shared_ptr<TNodeInfo> PNodeInfo;
+
+  struct TCellInfo;
+  typedef shared_ptr<TCellInfo> PCellInfo;
+
+  struct TFieldInfo;
+  typedef shared_ptr<TFieldInfo> PFieldInfo;
+
+  struct TTimeStampInfo;
+  typedef shared_ptr<TTimeStampInfo> PTimeStampInfo;
+  
+  struct TTimeStampVal;
+  typedef shared_ptr<TTimeStampVal> PTimeStampVal;
+
+  class TWrapper;
+  typedef shared_ptr<TWrapper> PWrapper;
+};
+
+
+#endif
diff --git a/src/MEDWrapper/MED_Structures.cxx b/src/MEDWrapper/MED_Structures.cxx
new file mode 100644 (file)
index 0000000..6b940e7
--- /dev/null
@@ -0,0 +1,382 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.cxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#include "MED_Structures.hxx"
+#include "MED_Utilities.hxx"
+#include <string>
+using namespace std;
+using namespace MED;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+#if defined __GNUC__
+  #if __GNUC__ == 2
+    #define __GNUC_2__
+  #endif
+#endif
+
+//---------------------------------------------------------------
+string MED::GetString(med_int theId, med_int theStep,
+                     const TString& theString)
+{
+  const char* aPos = &theString[theId*theStep];
+  med_int aSize = min(med_int(strlen(aPos)),theStep);
+  return string(aPos,aSize);
+}
+
+void MED::SetString(med_int theId, med_int theStep,
+                   TString& theString, const string& theValue)
+{
+  med_int aSize = min(med_int(theValue.size()+1),theStep);
+  if(aSize > theStep)
+    EXCEPTION(runtime_error,"SetString(...): aSize =="<<aSize<<"of '"<<theValue<<"' > theStep");
+  strncpy(&theString[theId*theStep],theValue.c_str(),aSize);
+}
+
+med_int MED::GetNbConn(med_entite_maillage theMedEntity, 
+                      med_geometrie_element theMedType,
+                      med_int theMeshDim)
+{
+  med_int anElemDim = theMedType / 100, nsup = 0;
+  if(theMedEntity == MED_MAILLE && anElemDim < theMeshDim) nsup = 1;
+  return nsup + theMedType % 100;
+}
+
+
+//---------------------------------------------------------------
+TNameInfo::TNameInfo(const string& theValue):
+  myName('\0',MED_TAILLE_NOM+1) 
+{
+  if(theValue != "") SetName(theValue);
+}
+
+string TNameInfo::GetName() const { 
+  return GetString(0,MED_TAILLE_NOM,myName);
+}
+
+void TNameInfo::SetName(const string& theValue){
+  SetString(0,MED_TAILLE_NOM,myName,theValue);
+}
+
+
+//---------------------------------------------------------------
+TMeshInfo::TMeshInfo(med_int theDim,
+                    const string& theValue):
+  TNameInfo(theValue),
+  myDim(theDim)
+{}
+
+//---------------------------------------------------------------
+TFamilyInfo::TFamilyInfo(const PMeshInfo& theMeshInfo, 
+                        med_int theNbGroup, 
+                        med_int theNbAttr,
+                        med_int theId,
+                        const string& theValue):
+  TNameInfo(theValue),
+  myMeshInfo(theMeshInfo),
+  myId(theId),
+  myNbGroup(theNbGroup),
+  myGroupNames('\0',theNbGroup*MED_TAILLE_LNOM+1),
+  myNbAttr(theNbAttr), 
+  myAttrId(theNbAttr), 
+  myAttrVal(theNbAttr),
+  myAttrDesc('\0',theNbAttr*MED_TAILLE_DESC+1)
+{}  
+
+TFamilyInfo::TFamilyInfo(const PMeshInfo& theMeshInfo,
+                        const string& theValue,
+                        med_int theId,
+                        const TStringSet& theGroupNames, 
+                        const TStringVector& theAttrDescs, 
+                        const TIntVector& theAttrIds, 
+                        const TIntVector& theAttrVals):
+  TNameInfo(theValue),
+  myMeshInfo(theMeshInfo),
+  myId(theId),
+  myNbGroup(theGroupNames.size()),
+  myGroupNames('\0',theGroupNames.size()*MED_TAILLE_LNOM+1),
+  myNbAttr(theAttrDescs.size()), 
+  myAttrId(theAttrDescs.size()), 
+  myAttrVal(theAttrDescs.size()),
+  myAttrDesc('\0',theAttrDescs.size()*MED_TAILLE_DESC+1)
+{
+  if(myNbGroup){
+    TStringSet::const_iterator anIter = theGroupNames.begin();
+    for(med_int anId = 0; anIter != theGroupNames.end(); anIter++, anId++){
+      const string& aVal = *anIter;
+      SetGroupName(anId,aVal);
+    }
+  }
+  if(myNbAttr){
+    for(med_int anId = 0, anEnd = theAttrDescs.size(); anId < anEnd; anId++){
+      const string& aVal = theAttrDescs[anId];
+      SetAttrDesc(anId,aVal);
+      myAttrId[anId] = theAttrIds[anId];
+      myAttrVal[anId] = theAttrVals[anId];
+    }
+  }
+}  
+
+string TFamilyInfo::GetGroupName(med_int theId) const { 
+  return GetString(theId,MED_TAILLE_LNOM,myGroupNames);
+}
+
+void TFamilyInfo::SetGroupName(med_int theId, const string& theValue){
+  SetString(theId,MED_TAILLE_LNOM,myGroupNames,theValue);
+}
+
+string TFamilyInfo::GetAttrDesc(med_int theId) const { 
+  return GetString(theId,MED_TAILLE_DESC,myAttrDesc);
+}
+
+void TFamilyInfo::SetAttrDesc(med_int theId, const string& theValue){
+  SetString(theId,MED_TAILLE_DESC,myAttrDesc,theValue);
+}
+
+
+//---------------------------------------------------------------
+TElemInfo::TElemInfo(const PMeshInfo& theMeshInfo, 
+                    med_int theNbElem,
+                    med_booleen theIsElemNum,
+                    med_booleen theIsElemNames):
+  myMeshInfo(theMeshInfo), 
+  myNbElem(theNbElem),
+  myFamNum(theNbElem),
+  myIsElemNum(theIsElemNum), 
+  myElemNum(theIsElemNum == MED_FAUX? 0: theNbElem),
+  myIsElemNames(theIsElemNames),
+  myElemNames('\0',(theIsElemNames == MED_FAUX? 0: theNbElem)*MED_TAILLE_PNOM+1)
+{}
+
+TElemInfo::TElemInfo(const PMeshInfo& theMeshInfo, 
+                    const TIntVector& theFamilyNums,
+                    const TIntVector& theElemNums,
+                    const TStringVector& theElemNames):
+  myMeshInfo(theMeshInfo), 
+  myNbElem(theFamilyNums.size()),
+  myFamNum(theFamilyNums.size()),
+  myIsElemNum(theElemNums.size()? MED_VRAI: MED_FAUX), 
+  myElemNum(theElemNums.size()),
+  myIsElemNames(theElemNames.size()? MED_VRAI: MED_FAUX),
+  myElemNames('\0',theElemNames.size()*MED_TAILLE_PNOM+1)
+{
+  if(myNbElem){
+    for(med_int anId = 0; anId < myNbElem; anId++){
+      myFamNum[anId] = theFamilyNums[anId];
+    }
+    if(myIsElemNum == MED_VRAI){
+      for(med_int anId = 0; anId < myNbElem; anId++){
+       myElemNum[anId] = theElemNums[anId];
+      }
+    }
+    if(myIsElemNames == MED_VRAI){
+      for(med_int anId = 0; anId < myNbElem; anId++){
+       const string& aVal = theElemNames[anId];
+       SetElemName(anId,aVal);
+      }
+    }
+  }
+}
+
+string TElemInfo::GetElemName(med_int theId) const { 
+  return GetString(theId,MED_TAILLE_PNOM,myElemNames);
+}
+
+void TElemInfo::SetElemName(med_int theId, const string& theValue){
+  SetString(theId,MED_TAILLE_PNOM,myElemNames,theValue);
+}
+
+
+//---------------------------------------------------------------
+TNodeInfo::TNodeInfo(const PMeshInfo& theMeshInfo, 
+                    med_int theNbElem,
+                    med_repere theSystem, 
+                    med_booleen theIsElemNum,
+                    med_booleen theIsElemNames):
+  TElemInfo(theMeshInfo,theNbElem,theIsElemNum,theIsElemNames),
+  myCoord(theNbElem*theMeshInfo->myDim), 
+  mySystem(theSystem), 
+  myCoordNames('\0',theMeshInfo->myDim*MED_TAILLE_PNOM+1),
+  myCoordUnits('\0',theMeshInfo->myDim*MED_TAILLE_PNOM+1)
+{}
+
+TNodeInfo::TNodeInfo(const PMeshInfo& theMeshInfo, 
+                    med_repere theSystem, 
+                    const TFloatVector& theNodeCoords,
+                    const TStringVector& theCoordNames,
+                    const TStringVector& theCoordUnits,
+                    const TIntVector& theFamilyNums,
+                    const TIntVector& theElemNums,
+                    const TStringVector& theElemNames):
+  TElemInfo(theMeshInfo,theFamilyNums,theElemNums,theElemNames),
+  myCoord(theNodeCoords.size()), 
+  mySystem(theSystem), 
+  myCoordNames('\0',theMeshInfo->myDim*MED_TAILLE_PNOM+1),
+  myCoordUnits('\0',theMeshInfo->myDim*MED_TAILLE_PNOM+1)
+{
+  if(myCoord.size() == myNbElem*theMeshInfo->myDim){
+    for(med_int anId = 0, anEnd = myCoord.size(); anId < anEnd; anId++){
+      myCoord[anId] = theNodeCoords[anId];
+    }
+  }else 
+    EXCEPTION(runtime_error,"myCoord.size() != myNbElem*theMeshInfo->myDim");
+
+  for(med_int anId = 0; anId < theMeshInfo->myDim; anId++){
+#if defined __GNUC_2__
+    const string& aVal = theCoordNames[anId];
+#else
+    const string& aVal = theCoordNames.at(anId);
+#endif
+    SetCoordName(anId,aVal);
+  }
+
+  for(med_int anId = 0; anId < theMeshInfo->myDim; anId++){
+#if defined __GNUC_2__
+    const string& aVal = theCoordUnits[anId];
+#else
+    const string& aVal = theCoordUnits.at(anId);
+#endif
+    SetCoordUnit(anId,aVal);
+  }
+}
+
+string TNodeInfo::GetCoordName(med_int theId) const { 
+  return GetString(theId,MED_TAILLE_PNOM,myCoordNames);
+}
+
+void TNodeInfo::SetCoordName(med_int theId, const string& theValue){
+  SetString(theId,MED_TAILLE_PNOM,myCoordNames,theValue);
+}
+
+string TNodeInfo::GetCoordUnit(med_int theId) const { 
+  return GetString(theId,MED_TAILLE_PNOM,myCoordUnits);
+}
+
+void TNodeInfo::SetCoordUnit(med_int theId, const string& theValue){
+  SetString(theId,MED_TAILLE_PNOM,myCoordUnits,theValue);
+}
+
+
+//---------------------------------------------------------------
+TCellInfo::TCellInfo(const PMeshInfo& theMeshInfo, 
+                    med_int theNbElem,
+                    med_entite_maillage theTEntity, 
+                    med_geometrie_element theTGeom,
+                    med_connectivite theTConn,
+                    med_booleen theIsElemNum,
+                    med_booleen theIsElemNames):
+  TElemInfo(theMeshInfo,theNbElem,theIsElemNum,theIsElemNames),
+  myTEntity(theTEntity), 
+  myTGeom(theTGeom), 
+  myTConn(theTConn),
+  myConnDim(GetNbConn(myTEntity,myTGeom,theMeshInfo->myDim)),
+  myConn(theNbElem*myConnDim)
+{}
+
+TCellInfo::TCellInfo(const PMeshInfo& theMeshInfo, 
+                    med_entite_maillage theTEntity, 
+                    med_geometrie_element theTGeom,
+                    med_connectivite theTConn,
+                    const TIntVector& theConnectivities,
+                    const TIntVector& theFamilyNums,
+                    const TIntVector& theElemNums,
+                    const TStringVector& theElemNames):
+  TElemInfo(theMeshInfo,theFamilyNums,theElemNums,theElemNames),
+  myTEntity(theTEntity), 
+  myTGeom(theTGeom), 
+  myTConn(theTConn),
+  myConnDim(GetNbConn(myTEntity,myTGeom,theMeshInfo->myDim)),
+  myConn(theConnectivities.size())
+{
+  if(myConn.size() == myConnDim*theFamilyNums.size()){
+    for(med_int anId = 0, anEnd = myConn.size(); anId < anEnd; anId++){
+      myConn[anId] = theConnectivities[anId];
+    }
+  }else 
+    EXCEPTION(runtime_error,"myConn.size() == myConnDim*theFamilyNums.size()");
+}
+
+//---------------------------------------------------------------
+TFieldInfo::TFieldInfo(const PMeshInfo& theMeshInfo, 
+                      med_int theNbComp,
+                      med_type_champ theType,
+                      const string& theValue):
+  TNameInfo(theValue),
+  myMeshInfo(theMeshInfo), 
+  myNbComp(theNbComp),
+  myType(theType),
+  myCompNames('\0',theNbComp*MED_TAILLE_PNOM + 1),
+  myUnitNames('\0',theNbComp*MED_TAILLE_PNOM + 1)
+{}
+
+string TFieldInfo::GetCompName(med_int theId) const { 
+  return GetString(theId,MED_TAILLE_PNOM,myCompNames);
+}
+
+void TFieldInfo::SetCompName(med_int theId, const string& theValue){
+  SetString(theId,MED_TAILLE_PNOM,myCompNames,theValue);
+}
+
+string TFieldInfo::GetUnitName(med_int theId) const { 
+  return GetString(theId,MED_TAILLE_PNOM,myUnitNames);
+}
+
+void TFieldInfo::SetUnitName(med_int theId, const string& theValue){
+  SetString(theId,MED_TAILLE_PNOM,myUnitNames,theValue);
+}
+
+
+//---------------------------------------------------------------
+TTimeStampInfo::TTimeStampInfo(const PFieldInfo& theFieldInfo, 
+                              med_entite_maillage theEntity,
+                              const TGeom& theGeom):
+  myFieldInfo(theFieldInfo), 
+  myEntity(theEntity), 
+  myGeom(theGeom), 
+  myUnitDt('\0',MED_TAILLE_PNOM+1)
+{}
+
+string TTimeStampInfo::GetUnitDt() const { 
+  return GetString(0,MED_TAILLE_PNOM,myUnitDt);
+}
+
+void TTimeStampInfo::SetUnitDt(const string& theValue){
+  SetString(0,MED_TAILLE_PNOM,myUnitDt,theValue);
+}
+
+
+//---------------------------------------------------------------
+TTimeStampVal::TTimeStampVal(const PTimeStampInfo& theTimeStampInfo):
+  myTimeStampInfo(theTimeStampInfo),
+  myPflName('\0',MED_TAILLE_NOM+1)
+{
+  med_int aNbComp = theTimeStampInfo->myFieldInfo->myNbComp;
+  med_int aNbGauss = theTimeStampInfo->myNbGauss;
+  const TGeom& aTGeom = theTimeStampInfo->myGeom;
+  TGeom::const_iterator anIter = aTGeom.begin();
+  for(; anIter != aTGeom.end(); anIter++){
+    const med_geometrie_element& aGeom = anIter->first;
+    med_int aNb = anIter->second*aNbComp*aNbGauss;
+    myMeshValue[aGeom].resize(aNb);
+  }
+}
+
+string TTimeStampVal::GetPflName() const { 
+  return GetString(0,MED_TAILLE_NOM,myPflName);
+}
+
+void TTimeStampVal::SetPflName(const string& theValue){
+  SetString(0,MED_TAILLE_NOM,myPflName,theValue);
+}
+
+
diff --git a/src/MEDWrapper/MED_Structures.hxx b/src/MEDWrapper/MED_Structures.hxx
new file mode 100644 (file)
index 0000000..727e83c
--- /dev/null
@@ -0,0 +1,243 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.hxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#ifndef MED_Structures_HeaderFile
+#define MED_Structures_HeaderFile
+
+#if defined __GNUC__
+  #if __GNUC__ == 2
+    #define __GNUC_2__
+  #endif
+#endif
+
+#if defined __GNUC_2__
+#include <vector>
+#endif
+#include <valarray>
+
+#include "MED_Common.hxx"
+
+namespace MED{
+  using namespace std;
+  using namespace boost;
+
+//---------------------------------------------------------------
+#if defined __GNUC_2__
+  typedef vector<char> TString;
+#else
+  typedef valarray<char> TString;
+#endif
+
+  string GetString(med_int theId, med_int theStep, const TString& theString);
+  void SetString(med_int theId, med_int theStep, TString& theString, 
+                const string& theValue);
+
+
+//---------------------------------------------------------------
+  struct TNameInfo{
+    TNameInfo(const string& theValue = "");
+    virtual ~TNameInfo() {} 
+
+    TString myName;
+    string GetName() const;
+    void SetName(const string& theValue);
+  };
+
+
+//---------------------------------------------------------------
+  struct TMeshInfo: TNameInfo{
+    TMeshInfo(med_int theDim = 0,
+             const string& theValue = "");
+
+    med_int myDim;
+  };
+  
+
+//---------------------------------------------------------------
+  typedef valarray<med_int> TFamAttr;
+
+  struct TFamilyInfo: TNameInfo{
+    TFamilyInfo(const PMeshInfo& theMeshInfo,
+               med_int theNbGroup = 0, 
+               med_int theNbAttr = 0,
+               med_int theId = 0,
+               const string& theValue = "");
+
+    TFamilyInfo(const PMeshInfo& theMeshInfo,
+               const string& theValue,
+               med_int theId,
+               const TStringSet& theGroupNames, 
+               const TStringVector& theAttrDescs = TStringVector(), 
+               const TIntVector& theAttrIds = TIntVector(), 
+               const TIntVector& theAttrVals = TIntVector());
+
+    PMeshInfo myMeshInfo;
+    med_int myId;
+
+    med_int myNbGroup;
+    TString myGroupNames;
+    string GetGroupName(med_int theId) const;
+    void SetGroupName(med_int theId, const string& theValue);
+
+    med_int myNbAttr;
+    TFamAttr myAttrId;
+    TFamAttr myAttrVal;
+
+    TString myAttrDesc;
+    string GetAttrDesc(med_int theId) const;
+    void SetAttrDesc(med_int theId, const string& theValue);
+  };
+
+
+//---------------------------------------------------------------
+  typedef valarray<med_int> TElemNum;
+
+  struct TElemInfo{
+    TElemInfo(const PMeshInfo& theMeshInfo, 
+             med_int theNbElem,
+             med_booleen theIsElemNum = MED_VRAI,
+             med_booleen theIsElemNames = MED_VRAI);
+    TElemInfo(const PMeshInfo& theMeshInfo, 
+             const TIntVector& theFamilyNums,
+             const TIntVector& theElemNums,
+             const TStringVector& theElemNames = TStringVector());
+    virtual ~TElemInfo() {} 
+
+    PMeshInfo myMeshInfo;
+    med_int myNbElem;
+    
+    TElemNum myFamNum;
+
+    med_booleen myIsElemNum;
+    TElemNum myElemNum;
+
+    med_booleen myIsElemNames;
+    TString myElemNames;
+    string GetElemName(med_int theId) const;
+    void SetElemName(med_int theId, const string& theValue);
+  };
+
+
+//---------------------------------------------------------------
+  typedef valarray<med_float> TNodeCoord;
+
+  struct TNodeInfo: TElemInfo{
+    TNodeInfo(const PMeshInfo& theMeshInfo, 
+             med_int theNbElem,
+             med_repere theSystem = MED_CART, 
+             med_booleen theIsElemNum = MED_VRAI,
+             med_booleen theIsElemNames = MED_VRAI);
+
+    TNodeInfo(const PMeshInfo& theMeshInfo, 
+             med_repere theSystem, 
+             const TFloatVector& theNodeCoords,
+             const TStringVector& theCoordNames,
+             const TStringVector& theCoordUnits,
+             const TIntVector& theFamilyNums,
+             const TIntVector& theElemNums,
+             const TStringVector& theElemNames = TStringVector());
+
+    TNodeCoord myCoord;
+    med_repere mySystem;
+
+    TString myCoordNames;
+    string GetCoordName(med_int theId) const;
+    void SetCoordName(med_int theId, const string& theValue);
+
+    TString myCoordUnits;
+    string GetCoordUnit(med_int theId) const;
+    void SetCoordUnit(med_int theId, const string& theValue);
+  };
+
+
+//---------------------------------------------------------------
+  struct TCellInfo: TElemInfo{
+    TCellInfo(const PMeshInfo& theMeshInfo, 
+             med_int theNbElem,
+             med_entite_maillage theTEntity, 
+             med_geometrie_element theTGeom,
+             med_connectivite theTConn = MED_NOD,
+             med_booleen theIsElemNum = MED_VRAI,
+             med_booleen theIsElemNames = MED_VRAI);
+
+    TCellInfo(const PMeshInfo& theMeshInfo, 
+             med_entite_maillage theTEntity, 
+             med_geometrie_element theTGeom,
+             med_connectivite theTConn,
+             const TIntVector& theConnectivities,
+             const TIntVector& theFamilyNums,
+             const TIntVector& theElemNums,
+             const TStringVector& theElemNames = TStringVector());
+
+    med_entite_maillage myTEntity;
+    med_geometrie_element myTGeom;
+    med_connectivite myTConn;
+
+    med_int myConnDim;
+    TElemNum myConn;
+  };
+
+
+//---------------------------------------------------------------
+  struct TFieldInfo: TNameInfo{
+    TFieldInfo(const PMeshInfo& theMeshInfo, 
+              med_int theNbComp = 0,
+              med_type_champ theType = MED_REEL64,
+              const string& theValue = "");
+    
+    PMeshInfo myMeshInfo;
+    med_type_champ myType;
+    med_int myNbComp;
+    
+    TString myCompNames; 
+    string GetCompName(med_int theId) const;
+    void SetCompName(med_int theId, const string& theValue);
+
+    TString myUnitNames; 
+    string GetUnitName(med_int theId) const;
+    void SetUnitName(med_int theId, const string& theValue);
+  };
+
+
+//---------------------------------------------------------------
+  struct TTimeStampInfo{
+    TTimeStampInfo(const PFieldInfo& theFieldInfo, 
+                  med_entite_maillage theEntity,
+                  const TGeom& theGeom);
+
+    PFieldInfo myFieldInfo;
+    med_entite_maillage myEntity;
+    TGeom myGeom;
+
+    med_int myNbGauss, myNumDt, myNumOrd;
+    med_float myDt;
+
+    TString myUnitDt;
+    string GetUnitDt() const;
+    void SetUnitDt(const string& theValue);
+  };
+  
+
+  typedef valarray<med_float> TValue;
+  typedef map<med_geometrie_element,TValue> TMeshValue;
+//---------------------------------------------------------------
+  struct TTimeStampVal{
+    TTimeStampVal(const PTimeStampInfo& theTimeStampInfo);
+
+    PTimeStampInfo myTimeStampInfo;
+    TMeshValue myMeshValue;
+
+    TString myPflName;
+    string GetPflName() const;
+    void SetPflName(const string& theValue);
+  };
+
+};
+
+
+#endif
diff --git a/src/MEDWrapper/MED_Test.cxx b/src/MEDWrapper/MED_Test.cxx
new file mode 100644 (file)
index 0000000..b227bc1
--- /dev/null
@@ -0,0 +1,186 @@
+//  VISU OBJECT : interactive object for VISU entities implementation
+//
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//  File:    VISUConvertor.cxx
+//  Author:  Alexey PETROV
+//  Module : VISU
+
+#include "MED_Structures.hxx"
+#include "MED_Wrapper.hxx"
+#include "MED_Utilities.hxx"
+
+using namespace std;
+
+#ifdef DEBUG
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+void ReadMed(const char* theFileName){
+  using namespace MED;
+  TWrapper aMed(theFileName);
+  string aFileName = theFileName;
+  aFileName += "-";
+  TWrapper aMedW(aFileName);
+
+  int aNbMeshes = aMed.GetNbMeshes();
+  cout<<"GetNbMeshes() = "<<aNbMeshes<<endl;
+
+  string aName;
+  for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
+    PMeshInfo aMeshInfo(new TMeshInfo());
+    PMeshInfo aNewMeshInfo(new TMeshInfo());
+    aMed.GetMeshInfo(iMesh+1,*aMeshInfo);
+    int aDim = aMeshInfo->myDim;
+    aName = aMeshInfo->GetName();
+    cout<<"GetMeshInfo - aName = '"<<aName<<"'; aDim = "<<aDim<<endl;
+    *aNewMeshInfo = *aMeshInfo;
+    aName[0] += 1;
+    aNewMeshInfo->SetName(aName);
+    aMedW.SetMeshInfo(*aNewMeshInfo);
+
+    TEntityInfo aEntityInfo = aMed.GetEntityInfo(*aMeshInfo);
+
+    med_int aNbFields = aMed.GetNbFields(); 
+    cout<<"GetNbFields() = "<<aNbFields<<endl;
+    for(int iField = 0; iField < aNbFields; iField++){
+      med_int aNbComp = aMed.GetNbComp(iField+1);
+      PFieldInfo aFieldInfo(new TFieldInfo(aMeshInfo,aNbComp));
+      aMed.GetFieldInfo(iField+1,*aFieldInfo);
+      cout<<"\taName = '"<<aFieldInfo->GetName()<<"'; aNbComp = "<<aNbComp<<"; ";
+      aMedW.SetFieldInfo(*aFieldInfo);
+      med_entite_maillage anEntity;
+      TGeom aTGeom;
+      med_int aNbTimeStamps = aMed.GetNbTimeStamps(*aFieldInfo,aEntityInfo,
+                                                  anEntity,aTGeom);
+      cout<<"GetNbTimeStamps = "<<aNbTimeStamps<<endl;
+      PTimeStampInfo aTimeStampInfo(new TTimeStampInfo(aFieldInfo,anEntity,aTGeom));
+      for(int iTimeStamp = 0; iTimeStamp < aNbTimeStamps; iTimeStamp++){
+       aMed.GetTimeStampInfo(iTimeStamp+1, *aTimeStampInfo);
+
+       TTimeStampVal aTimeStampVal(aTimeStampInfo);
+       aMed.GetTimeStampVal(aTimeStampVal);
+       aMedW.SetTimeStamp(aTimeStampVal);
+
+       TMeshValue& aMeshValue = aTimeStampVal.myMeshValue;
+       TMeshValue::iterator aMeshValueIter = aMeshValue.begin();
+       for(; aMeshValueIter != aMeshValue.end(); aMeshValueIter++){
+         med_geometrie_element aGeom = aMeshValueIter->first;
+         TValue aValue = aMeshValueIter->second;
+         cout<<"\t\taGeom = "<<aGeom<<"; aValue = "<<aValue.size()<<": ";
+         for(int i = 0, iEnd = aValue.size()/aNbComp; i < iEnd; i++){
+           for(int j = 0, ij = i*aNbComp; j < aNbComp; j++, ij++){
+             //cout<<aValue[ij]<<",";
+           }
+           //cout<<" ";
+         }
+         cout<<"\n";
+       }
+      }
+    }
+
+    int aNbFam = aMed.GetNbFamilies(*aMeshInfo);
+    cout<<"GetNbFamilies() = "<<aNbFam<<endl;
+    for(int iFam = 0; iFam < aNbFam; iFam++){
+      int aNbAttr = aMed.GetNbFamAttr(iFam+1,*aMeshInfo);
+      int aNbGroup = aMed.GetNbFamGroup(iFam+1,*aMeshInfo);
+      PFamilyInfo aFamilyInfo(new TFamilyInfo(aMeshInfo,aNbGroup,aNbAttr));
+      aMed.GetFamilyInfo(iFam+1,*aFamilyInfo);
+      aName = aFamilyInfo->GetName();
+      cout<<"\taName = '"<<aName<<"'; aNbAttr = "<<aNbAttr<<"; aNbGroup = "<<aNbGroup<<endl;
+      aName[0] += 1;
+      aFamilyInfo->SetName(aName);
+      aFamilyInfo->myMeshInfo = aNewMeshInfo;
+      aName = aFamilyInfo->GetName();
+      for(int iGroup = 0; iGroup < aNbGroup; iGroup++){
+       aName = aFamilyInfo->GetGroupName(iGroup);
+       cout<<"\t\taGroupName = '"<<aName<<"'\n";
+       aName[0] += 1;
+       aFamilyInfo->SetGroupName(iGroup,aName);
+      }
+
+      aMedW.SetFamilyInfo(*aFamilyInfo);
+    }
+
+    cout<<"GetEntityInfo - aNbEntities = "<<aEntityInfo.size()<<endl;
+    TEntityInfo::iterator anEntityInfoIter = aEntityInfo.begin();
+    for(; anEntityInfoIter != aEntityInfo.end(); anEntityInfoIter++){
+      const med_entite_maillage& anEntity = anEntityInfoIter->first;
+      cout<<"\tanEntity = "<<anEntity<<endl;
+      if(anEntity == MED_NOEUD){
+       int aNbNodes = aMed.GetNbNodes(*aMeshInfo);
+       PNodeInfo aNodeInfo(new TNodeInfo(aMeshInfo,aNbNodes));
+       aMed.GetNodeInfo(*aNodeInfo);
+       cout<<"\tGetNodeInfo - aNbNodes = "<<aNbNodes<<": ";
+       TNodeCoord& aCoord = aNodeInfo->myCoord;
+       for(int iNode = 0; iNode < aNbNodes; iNode++){
+         for(int iDim = 0, anId = iNode*aDim; iDim < aDim; iDim++, anId++){
+           //cout<<aCoord[anId]<<",";
+           aCoord[anId] += 1.0;
+         }
+         //cout<<" ";
+       }
+       cout<<endl;
+       aNodeInfo->myMeshInfo = aNewMeshInfo;
+       aMedW.SetNodeInfo(*aNodeInfo);
+       continue;
+      }
+      TGeom& aTGeom = anEntityInfoIter->second;
+      TGeom::iterator anTGeomIter = aTGeom.begin();
+      for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
+       const med_geometrie_element& aGeom = anTGeomIter->first;
+       med_int& aNbElem = anTGeomIter->second;
+       cout<<"\t\taGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<": ";
+       PCellInfo aCellInfo(new TCellInfo(aMeshInfo,aNbElem,anEntity,aGeom));
+       aMed.GetCellInfo(*aCellInfo);
+       for(int iElem = 0; iElem < aCellInfo->myNbElem; iElem++){
+         int i = iElem*aCellInfo->myConnDim;
+         for(int iConn = 0; iConn < aCellInfo->myConnDim; iConn++, i++){
+           //cout<<aCellInfo->myConn[i]<<",";
+         }
+         //cout<<" ";
+       }
+       cout<<endl;
+       aCellInfo->myMeshInfo = aNewMeshInfo;
+       aMedW.SetCellInfo(*aCellInfo);
+      }
+    }
+    
+  }
+  cout<<"OK"<<endl;
+}
+
+
+int main(int argc, char** argv){ 
+  try{
+    if(argc > 1)
+      ReadMed(argv[1]);
+    return 0;
+  }catch(std::exception& exc){
+    cout<<"Follow exception was accured :\n"<<exc.what()<<endl;
+  }catch(...){
+    cout<<"Unknown exception was accured in VISU_Convertor_impl"<<endl;
+  } 
+  return 1;
+}
diff --git a/src/MEDWrapper/MED_Utilities.cxx b/src/MEDWrapper/MED_Utilities.cxx
new file mode 100644 (file)
index 0000000..e09d642
--- /dev/null
@@ -0,0 +1,37 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.cxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#include "MED_Utilities.hxx"
+
+using namespace std;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+int MED::PrefixPrinter::myCounter = 0;
+
+MED::PrefixPrinter::PrefixPrinter()
+{
+  myCounter++;
+}
+
+MED::PrefixPrinter::~PrefixPrinter()
+{
+  myCounter--;
+}
+
+string MED::PrefixPrinter::GetPrefix()
+{
+  if(myCounter)
+    return string(myCounter*2,' ');
+  return "";
+}
diff --git a/src/MEDWrapper/MED_Utilities.hxx b/src/MEDWrapper/MED_Utilities.hxx
new file mode 100644 (file)
index 0000000..a7cf092
--- /dev/null
@@ -0,0 +1,52 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.hxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#ifndef MED_Utilities_HeaderFile
+#define MED_Utilities_HeaderFile
+
+#include <iostream>    
+#include <sstream>     
+#include <string>
+#include <stdexcept>
+
+
+namespace MED{
+  using namespace std;
+  class PrefixPrinter{
+    static int myCounter;
+  public:
+    PrefixPrinter();
+    ~PrefixPrinter();
+
+    static string GetPrefix();
+  };
+};
+
+
+#ifndef MESSAGE
+
+#define MESSAGE(msg) std::cout<<__FILE__<<"["<<__LINE__<<"]::"<<msg<<endl;
+
+#define BEGMSG(msg) std::cout<<MED::PrefixPrinter::GetPrefix()<<msg
+
+#define ADDMSG(msg) std::cout<<msg
+
+#endif
+
+
+#ifndef EXCEPTION
+
+#define EXCEPTION(TYPE, MSG) {\
+  std::ostringstream aStream;\
+  aStream<<__FILE__<<"["<<__LINE__<<"]::"<<MSG;\
+  throw TYPE(aStream.str());\
+}
+
+#endif
+
+#endif
diff --git a/src/MEDWrapper/MED_Wrapper.cxx b/src/MEDWrapper/MED_Wrapper.cxx
new file mode 100644 (file)
index 0000000..d732fb0
--- /dev/null
@@ -0,0 +1,624 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.cxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#include "MED_Wrapper.hxx"
+#include "MED_Utilities.hxx"
+
+using namespace std;
+using namespace MED;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+
+//---------------------------------------------------------------
+static med_geometrie_element NODEGEOM[1] = {MED_POINT1};
+
+static med_geometrie_element EDGEGEOM[MED_NBR_GEOMETRIE_ARETE] = {
+  MED_SEG2, MED_SEG3
+};
+
+static med_geometrie_element FACEGEOM[MED_NBR_GEOMETRIE_FACE] = {
+  MED_TRIA3, MED_QUAD4, MED_TRIA6, MED_QUAD8
+};
+
+static med_geometrie_element  CELLGEOM[MED_NBR_GEOMETRIE_MAILLE] = {
+  MED_POINT1, MED_SEG2, MED_SEG3, MED_TRIA3,
+  MED_QUAD4, MED_TRIA6, MED_QUAD8, MED_TETRA4,
+  MED_PYRA5, MED_PENTA6, MED_HEXA8, MED_TETRA10, 
+  MED_PYRA13, MED_PENTA15, MED_HEXA20
+};
+
+void GetEntity2Geom(med_entite_maillage theEntity, med_geometrie_element*& theVector, int* theEnd){
+  switch(theEntity){
+  case MED_MAILLE: theVector = CELLGEOM; *theEnd = MED_NBR_GEOMETRIE_MAILLE; break;
+  case MED_FACE: theVector = FACEGEOM; *theEnd = MED_NBR_GEOMETRIE_FACE; break;
+  case MED_ARETE: theVector = EDGEGEOM; *theEnd = MED_NBR_GEOMETRIE_ARETE; break;
+  case MED_NOEUD: theVector = NODEGEOM; *theEnd = 1; break;
+  default:
+    EXCEPTION(runtime_error,"GetEntity2Geom - theEntity == "<<theEntity<<" is uncorrect");
+  }
+}
+
+
+//---------------------------------------------------------------
+TFile::TFile(const std::string& theFileName): 
+  myFid(0), 
+  myCount(0),
+  myFileName(strdup(theFileName.c_str()))
+{}
+
+TFile::~TFile(){ 
+  free(myFileName);
+  Close();
+}
+
+
+void TFile::Open(med_mode_acces theMode){
+  if(myCount++ == 0){
+    myFid = MEDouvrir(myFileName,theMode);
+    if(myFid < 0)
+      EXCEPTION(runtime_error,"TFile - MEDouvrir('"<<myFileName<<"',"<<theMode<<")");
+  }
+}
+void TFile::Close(){ 
+  if(--myCount == 0) {
+    MEDfermer(myFid);
+  }
+}
+
+const med_idt& TFile::Id() const { 
+  if(myFid < 0)
+    EXCEPTION(runtime_error,"TFile - GetFid() < 0");
+  return myFid;
+}
+
+
+//---------------------------------------------------------------
+TWrapper::TWrapper(const std::string& theFileName): 
+  myFile(theFileName)
+{}
+
+
+med_int TWrapper::GetNbMeshes(){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  return MEDnMaa(myFile.Id());
+}
+
+
+void TWrapper::GetMeshInfo(med_int theMeshId, TMeshInfo& theInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  med_err ret = MEDmaaInfo(myFile.Id(),
+                          theMeshId,
+                          &theInfo.myName[0],
+                          &theInfo.myDim);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"GetMeshInfo - MEDmaaInfo(...)");
+}
+
+
+void TWrapper::SetMeshInfo(const TMeshInfo& theInfo){
+  med_err ret = -1;
+  try{
+    TFileWrapper aFileWrapper(myFile,MED_ECRI);
+    
+    TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
+    ret = MEDmaaCr(myFile.Id(),
+                  &anInfo.myName[0],
+                  anInfo.myDim);
+  }catch(...){}
+  if(ret < 0){
+    TFileWrapper aFileWrapper(myFile,MED_REMP);
+    
+    TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
+    ret = MEDmaaCr(myFile.Id(),
+                  &anInfo.myName[0],
+                  anInfo.myDim);
+  }
+  if(ret < 0)
+    EXCEPTION(runtime_error,"SetMeshInfo - MEDmaaCr(...)");
+}
+
+
+med_int TWrapper::GetNbFamilies(const TMeshInfo& theInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
+  return MEDnFam(myFile.Id(),
+                &anInfo.myName[0],
+                0,
+                MED_FAMILLE);
+}
+
+
+med_int TWrapper::GetNbFamAttr(med_int theFamId, const TMeshInfo& theInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
+  return MEDnFam(myFile.Id(),
+                &anInfo.myName[0],
+                theFamId,
+                MED_ATTR);
+}
+
+
+med_int TWrapper::GetNbFamGroup(med_int theFamId, const TMeshInfo& theInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
+  return MEDnFam(myFile.Id(),
+                &anInfo.myName[0],
+                theFamId,
+                MED_GROUPE);
+}
+
+
+void TWrapper::GetFamilyInfo(med_int theFamId, TFamilyInfo& theInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
+
+  med_err ret = MEDfamInfo(myFile.Id(),
+                          &aMeshInfo.myName[0],
+                          theFamId,
+                          &theInfo.myName[0],
+                          &theInfo.myId,
+                          &theInfo.myAttrId[0],
+                          &theInfo.myAttrVal[0],
+                          &theInfo.myAttrDesc[0],
+                          &theInfo.myNbAttr,
+                          &theInfo.myGroupNames[0],
+                          &theInfo.myNbGroup);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"GetFamilyInfo - MEDfamInfo(...)");
+}
+
+
+void TWrapper::SetFamilyInfo(const TFamilyInfo& theInfo){
+  TFileWrapper aFileWrapper(myFile,MED_ECRI);
+
+  TFamilyInfo& anInfo = const_cast<TFamilyInfo&>(theInfo);
+  TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
+
+  med_err ret = MEDfamCr(myFile.Id(),
+                        &aMeshInfo.myName[0],
+                        &anInfo.myName[0],
+                        anInfo.myId,
+                        &anInfo.myAttrId[0],
+                        &anInfo.myAttrVal[0],
+                        &anInfo.myAttrDesc[0],
+                        anInfo.myNbAttr,
+                        &anInfo.myGroupNames[0],
+                        anInfo.myNbGroup);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"SetFamilyInfo - MEDfamCr(...)");
+}
+
+
+med_int TWrapper::GetNbNodes(const TMeshInfo& theMeshInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TMeshInfo& aMeshInfo = const_cast<TMeshInfo&>(theMeshInfo);
+
+  return MEDnEntMaa(myFile.Id(),
+                   &aMeshInfo.myName[0],
+                   MED_COOR,MED_NOEUD,
+                   med_geometrie_element(0),
+                   med_connectivite(0));
+}
+
+
+void TWrapper::GetNodeInfo(TNodeInfo& theInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
+
+  med_err ret = MEDnoeudsLire(myFile.Id(),
+                             &aMeshInfo.myName[0],
+                             aMeshInfo.myDim,
+                             &theInfo.myCoord[0],
+                             MED_FULL_INTERLACE,
+                             &theInfo.mySystem,
+                             &theInfo.myCoordNames[0],
+                             &theInfo.myCoordUnits[0],
+                             &theInfo.myElemNames[0],
+                             &theInfo.myIsElemNames,
+                             &theInfo.myElemNum[0],
+                             &theInfo.myIsElemNum,
+                             &theInfo.myFamNum[0],
+                             theInfo.myNbElem);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"GetNodeInfo - MEDnoeudsLire(...)");
+}
+
+
+void TWrapper::SetNodeInfo(const TNodeInfo& theInfo)
+{
+  TFileWrapper aFileWrapper(myFile,MED_ECRI);
+
+  TNodeInfo& anInfo = const_cast<TNodeInfo&>(theInfo);
+  TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
+
+  med_err ret = MEDnoeudsEcr(myFile.Id(),
+                            &aMeshInfo.myName[0],
+                            aMeshInfo.myDim,
+                            &anInfo.myCoord[0],
+                            MED_FULL_INTERLACE,
+                            anInfo.mySystem,
+                            &anInfo.myCoordNames[0],
+                            &anInfo.myCoordUnits[0],
+                            &anInfo.myElemNames[0],
+                            anInfo.myIsElemNames,
+                            &anInfo.myElemNum[0],
+                            anInfo.myIsElemNum,
+                            &anInfo.myFamNum[0],
+                            anInfo.myNbElem,
+                            MED_REMP);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"SetNodeInfo - MEDnoeudsEcr(...)");
+}
+
+
+TEntityInfo TWrapper::GetEntityInfo(const TMeshInfo& theMeshInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TEntityInfo anInfo;
+  if(med_int aNbElem = GetNbNodes(theMeshInfo)){
+    anInfo[MED_NOEUD][MED_POINT1] = aNbElem;
+    med_entite_maillage anEntityVector[3] = {MED_MAILLE, MED_FACE, MED_ARETE};
+    for(med_int iEntity = 0; iEntity < 3; iEntity++){
+      med_int iGeomEnd;
+      med_entite_maillage& anEntity = anEntityVector[iEntity];
+      med_geometrie_element* aGeomVector;
+      GetEntity2Geom(anEntity,aGeomVector,&iGeomEnd);
+      for(med_int iGeom = 0; iGeom < iGeomEnd; iGeom++) {
+       med_geometrie_element& aGeom = aGeomVector[iGeom];
+       if(med_int aNb = GetNbCells(theMeshInfo,anEntity,aGeom)){
+         anInfo[anEntity][aGeom] = aNb;
+       }
+      }
+    }
+  }
+  return anInfo;
+}
+
+
+med_int TWrapper::GetNbCells(const TMeshInfo& theMeshInfo, 
+                            med_entite_maillage theTEntity, 
+                            med_geometrie_element theTGeom, 
+                            med_connectivite theTConn)
+{
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TMeshInfo& aMeshInfo = const_cast<TMeshInfo&>(theMeshInfo);
+
+  return MEDnEntMaa(myFile.Id(),
+                   &aMeshInfo.myName[0],
+                   MED_CONN,
+                   theTEntity,
+                   theTGeom,
+                   theTConn); 
+}
+
+
+void TWrapper::GetCellInfo(TCellInfo& theInfo)
+{
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
+  med_int aNbElem = theInfo.myElemNum.size();
+
+  med_err ret = MEDelementsLire(myFile.Id(),
+                               &aMeshInfo.myName[0],
+                               aMeshInfo.myDim,
+                               &theInfo.myConn[0],
+                               MED_FULL_INTERLACE,
+                               &theInfo.myElemNames[0],
+                               &theInfo.myIsElemNames,
+                               &theInfo.myElemNum[0],
+                               &theInfo.myIsElemNum,
+                               &theInfo.myFamNum[0],
+                               aNbElem,
+                               theInfo.myTEntity,
+                               theInfo.myTGeom,
+                               theInfo.myTConn);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"GetCellInfo - MEDelementsLire(...)");
+}
+
+
+void TWrapper::SetCellInfo(const TCellInfo& theInfo)
+{
+  TFileWrapper aFileWrapper(myFile,MED_ECRI);
+
+  TCellInfo& anInfo = const_cast<TCellInfo&>(theInfo);
+  TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
+  med_int aNbElem = anInfo.myElemNum.size();
+
+  med_err ret = MEDelementsEcr(myFile.Id(),
+                              &aMeshInfo.myName[0],
+                              aMeshInfo.myDim,
+                              &anInfo.myConn[0],
+                              MED_FULL_INTERLACE,
+                              &anInfo.myElemNames[0],
+                              anInfo.myIsElemNames,
+                              &anInfo.myElemNum[0],
+                              anInfo.myIsElemNum,
+                              &anInfo.myFamNum[0],
+                              anInfo.myNbElem,
+                              anInfo.myTEntity,
+                              anInfo.myTGeom,
+                              anInfo.myTConn,
+                              MED_REMP);
+
+  if(ret < 0)
+    EXCEPTION(runtime_error,"GetCellInfo - MEDelementsLire(...)");
+}
+
+
+med_int TWrapper::GetNbFields(){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  return MEDnChamp(myFile.Id(),0);
+}
+
+
+med_int TWrapper::GetNbComp(med_int theFieldId){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  return MEDnChamp(myFile.Id(),theFieldId);
+}
+
+
+void TWrapper::GetFieldInfo(med_int theFieldId, TFieldInfo& theInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+  
+  med_err ret = MEDchampInfo(myFile.Id(),
+                            theFieldId,
+                            &theInfo.myName[0],
+                            &theInfo.myType,
+                            &theInfo.myCompNames[0],
+                            &theInfo.myUnitNames[0],
+                            theInfo.myNbComp);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"GetFieldInfo - MEDchampInfo(...)");
+}
+
+
+void TWrapper::SetFieldInfo(const TFieldInfo& theInfo)
+{
+  TFileWrapper aFileWrapper(myFile,MED_ECRI);
+  
+  TFieldInfo& anInfo = const_cast<TFieldInfo&>(theInfo);
+  med_err ret = MEDchampCr(myFile.Id(),
+                          &anInfo.myName[0],
+                          anInfo.myType,
+                          &anInfo.myCompNames[0],
+                          &anInfo.myUnitNames[0],
+                          anInfo.myNbComp);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"SetFieldInfo - MEDchampEcr(...)");
+}
+
+
+med_int TWrapper::GetNbTimeStamps(const TFieldInfo& theInfo, 
+                                 const TEntityInfo& theEntityInfo,
+                                 med_entite_maillage& theEntity,
+                                 TGeom& theGeom)
+{
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  if(theEntityInfo.empty()) 
+    EXCEPTION(runtime_error,"GetNbTimeStamps - There is no any Entity on the Mesh");
+
+  theGeom.clear();
+  med_int aNbTimeStamps = 0;
+  TFieldInfo& anInfo = const_cast<TFieldInfo&>(theInfo);
+  TEntityInfo::const_iterator anIter = theEntityInfo.begin();
+  for(; anIter != theEntityInfo.end(); anIter++){
+    const med_entite_maillage& anEntity = anIter->first;
+    const TGeom& aTGeom = anIter->second;
+    TGeom::const_iterator anGeomIter = aTGeom.begin();
+    for(; anGeomIter != aTGeom.end(); anGeomIter++){
+      const med_geometrie_element& aGeom = anGeomIter->first;
+      aNbTimeStamps = MEDnPasdetemps(myFile.Id(),&anInfo.myName[0],anEntity,aGeom);
+      if(aNbTimeStamps){
+       theEntity = anEntity;
+       theGeom[aGeom] = anGeomIter->second;
+      }
+    }
+    if(aNbTimeStamps) break;
+  }
+  return aNbTimeStamps;
+}
+
+
+void TWrapper::GetTimeStampInfo(med_int theTimeStampId, TTimeStampInfo& theInfo)
+{
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+  med_idt anId = myFile.Id();
+
+  TFieldInfo& aFieldInfo = *theInfo.myFieldInfo;
+  TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo;
+
+  med_entite_maillage anEntity = theInfo.myEntity;
+  TGeom& aTGeom = theInfo.myGeom;
+  if(aTGeom.empty())
+    EXCEPTION(runtime_error,"GetTimeStampInfo - There is no any cell");
+
+  TGeom::iterator anIter = aTGeom.begin();
+  med_geometrie_element aGeom = anIter->first;
+
+  med_err ret = MEDpasdetempsInfo(anId,
+                                 &aFieldInfo.myName[0],
+                                 anEntity,
+                                 aGeom,
+                                 theTimeStampId,
+                                 &aMeshInfo.myName[0],
+                                 &theInfo.myNbGauss,
+                                 &theInfo.myNumDt,
+                                 &theInfo.myUnitDt[0],
+                                 &theInfo.myDt,
+                                 &theInfo.myNumOrd);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"GetTimeStampInfo - MEDpasdetempsInfo(...)");
+
+  static med_int MAX_NB_GAUSS_POINTS = 32;
+  if(theInfo.myNbGauss > MAX_NB_GAUSS_POINTS) 
+    theInfo.myNbGauss = 1;
+}
+
+void TWrapper::SetTimeStamp(const TTimeStampVal& theVal)
+{
+  TFileWrapper aFileWrapper(myFile,MED_ECRI);
+  
+  TTimeStampVal& aVal = const_cast<TTimeStampVal&>(theVal);
+  TTimeStampInfo& aTimeStampInfo = *aVal.myTimeStampInfo;
+  TFieldInfo& aFieldInfo = *aTimeStampInfo.myFieldInfo;
+  TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo;
+  TMeshValue& aMeshValue = aVal.myMeshValue;
+  
+  med_entite_maillage anEntity = aTimeStampInfo.myEntity;
+  TMeshValue::iterator anIter = aMeshValue.begin();
+  for(; anIter != aMeshValue.end(); anIter++){
+    const med_geometrie_element& aGeom = anIter->first;
+    TValue& aValue = aVal.myMeshValue[aGeom];
+    med_int iEnd = aValue.size();
+    med_int aNbVal = iEnd / aFieldInfo.myNbComp;
+    
+    med_err ret;
+    switch(aFieldInfo.myType){
+    case MED_REEL64: {
+      valarray<med_float>& anArray = aValue;
+
+      ret = MEDchampEcr(myFile.Id(),
+                       &aMeshInfo.myName[0],
+                       &aFieldInfo.myName[0],
+                       (unsigned char*)&anArray[0],
+                       MED_FULL_INTERLACE,
+                       aNbVal,
+                       aTimeStampInfo.myNbGauss,
+                       MED_ALL,
+                       &aVal.myPflName[0],
+                       MED_ECRI, 
+                       anEntity,
+                       aGeom,
+                       aTimeStampInfo.myNumDt,
+                       &aTimeStampInfo.myUnitDt[0],
+                       aTimeStampInfo.myDt,
+                       aTimeStampInfo.myNumOrd);
+      break;
+    }
+    case MED_INT32:
+    case MED_INT: {
+      valarray<med_int> anArray(iEnd);
+      for(med_int i = 0; i< iEnd; i++) anArray[i] = med_int(aValue[i]);
+
+      ret = MEDchampEcr(myFile.Id(),
+                       &aMeshInfo.myName[0],
+                       &aFieldInfo.myName[0],
+                       (unsigned char*)&anArray[0],
+                       MED_FULL_INTERLACE,
+                       aNbVal,
+                       aTimeStampInfo.myNbGauss,
+                       MED_ALL,
+                       &aVal.myPflName[0],
+                       MED_ECRI, 
+                       anEntity,
+                       aGeom,
+                       aTimeStampInfo.myNumDt,
+                       &aTimeStampInfo.myUnitDt[0],
+                       aTimeStampInfo.myDt,
+                       aTimeStampInfo.myNumOrd);
+      break;
+    }
+    default: 
+      EXCEPTION(runtime_error,"SetTimeStamp - Type of the field == "<<aFieldInfo.myType<<" is wrong");
+    }
+    if(ret < 0)
+      EXCEPTION(runtime_error,"SetTimeStamp - MEDchampEcr(...)");
+  }
+}
+
+void TWrapper::GetTimeStampVal(TTimeStampVal& theVal)
+{
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+  med_idt anId = myFile.Id();
+
+  TTimeStampInfo& aTimeStampInfo = *theVal.myTimeStampInfo;
+  TFieldInfo& aFieldInfo = *aTimeStampInfo.myFieldInfo;
+  TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo;
+  TMeshValue& aMeshValue = theVal.myMeshValue;
+
+  med_entite_maillage anEntity = aTimeStampInfo.myEntity;
+  TGeom& aTGeom = aTimeStampInfo.myGeom;
+  TGeom::iterator anIter = aTGeom.begin();
+  for(; anIter != aTGeom.end(); anIter++){
+    const med_geometrie_element& aGeom = anIter->first;
+    med_int aNbVal = MEDnVal(anId,&aFieldInfo.myName[0],anEntity,aGeom,
+                            aTimeStampInfo.myNumDt,aTimeStampInfo.myNumOrd);
+    if(aNbVal <= 0)
+      EXCEPTION(runtime_error,"GetTimeStampInfo - MEDnVal(...) - aNbVal == "<<aNbVal<<" <= 0");
+
+    TValue& aValue = theVal.myMeshValue[aGeom];
+    med_int iEnd = aNbVal * aFieldInfo.myNbComp;
+
+    if(iEnd != aValue.size())
+      EXCEPTION(runtime_error,"GetTimeStampInfo - iEnd == "<<iEnd<<" != aValue.size() == "<<aValue.size());
+
+    med_err ret;
+    switch(aFieldInfo.myType){
+    case MED_REEL64: {
+      valarray<med_float> anArray(iEnd);
+      ret = MEDchampLire(myFile.Id(),
+                        &aMeshInfo.myName[0],
+                        &aFieldInfo.myName[0],
+                        (unsigned char*)&anArray[0],
+                        MED_FULL_INTERLACE,
+                        MED_ALL,
+                        &theVal.myPflName[0],
+                        anEntity,
+                        aGeom,
+                        aTimeStampInfo.myNumDt,
+                        aTimeStampInfo.myNumOrd);
+      if(ret >= 0) 
+       for(med_int i = 0; i < iEnd; i++) aValue[i] = anArray[i];
+      break;
+    }
+    case MED_INT32:
+    case MED_INT: {
+      valarray<med_int> anArray(iEnd);
+      ret = MEDchampLire(myFile.Id(),
+                        &aMeshInfo.myName[0],
+                        &aFieldInfo.myName[0],
+                        (unsigned char*)&anArray[0],
+                        MED_FULL_INTERLACE,
+                        MED_ALL,
+                        &theVal.myPflName[0],
+                        anEntity,
+                        aGeom,
+                        aTimeStampInfo.myNumDt,
+                        aTimeStampInfo.myNumOrd);
+      if(ret >= 0) 
+       for(med_int i = 0; i < iEnd; i++) aValue[i] = anArray[i];
+      break;
+    }
+    default:
+      EXCEPTION(runtime_error,"GetValTimeStamp - Type of the field == "<<aFieldInfo.myType<<" is wrong");
+    }
+    if(ret < 0)
+      EXCEPTION(runtime_error,"GetValTimeStamp - MEDchampLire(...)");
+  }
+}
diff --git a/src/MEDWrapper/MED_Wrapper.hxx b/src/MEDWrapper/MED_Wrapper.hxx
new file mode 100644 (file)
index 0000000..efb5c5e
--- /dev/null
@@ -0,0 +1,125 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.hxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#ifndef MED_Wrapper_HeaderFile
+#define MED_Wrapper_HeaderFile
+
+extern "C"{
+#include <med.h>
+}  
+#include "MED_Structures.hxx"
+
+
+namespace MED{
+//---------------------------------------------------------------
+  class TFile{
+    TFile();
+    TFile(const TFile&);
+  public:
+    TFile(const string& theFileName);
+    ~TFile();
+    
+    void Open(med_mode_acces theMode);
+    const med_idt& Id() const;
+    void Close();
+
+  protected:
+    char* myFileName;
+    med_idt myFid;
+    int myCount;
+  };
+
+
+//---------------------------------------------------------------
+  class TFileWrapper{
+    TFile& myFile;
+  public:
+    TFileWrapper(TFile& theFile, med_mode_acces theMode): 
+      myFile(theFile)
+    {
+      myFile.Open(theMode);
+    }
+
+    ~TFileWrapper(){
+      myFile.Close();
+    }
+  };
+
+
+//---------------------------------------------------------------
+  class TWrapper{
+    TWrapper();
+    TWrapper(const TWrapper&);
+    
+  public:
+    TWrapper(const string& theFileName);
+
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    med_int GetNbMeshes();
+    
+    void GetMeshInfo(med_int theMeshId, TMeshInfo&);
+    void SetMeshInfo(const TMeshInfo& theInfo);
+    
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    med_int GetNbFamilies(const TMeshInfo& theMeshInfo);
+    med_int GetNbFamAttr(med_int theFamId, const TMeshInfo& theInfo);
+    med_int GetNbFamGroup(med_int theFamId, const TMeshInfo& theInfo);
+    
+    void GetFamilyInfo(med_int theFamId, TFamilyInfo& theInfo);
+    void SetFamilyInfo(const TFamilyInfo& theInfo);
+
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    med_int GetNbNodes(const TMeshInfo& theMeshInfo);
+    
+    void GetNodeInfo(TNodeInfo&);
+    void SetNodeInfo(const TNodeInfo&);
+    
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    TEntityInfo GetEntityInfo(const TMeshInfo& theMeshInfo);
+    
+    med_int GetNbCells(const TMeshInfo& theMeshInfo, 
+                      med_entite_maillage, 
+                      med_geometrie_element, 
+                      med_connectivite theTConn = MED_NOD);
+    
+    void GetCellInfo(TCellInfo& theInfo);
+    void SetCellInfo(const TCellInfo& theInfo);
+    
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    med_int GetNbFields();
+    
+    med_int GetNbComp(med_int theFieldId);
+    
+    void GetFieldInfo(med_int theFieldId, TFieldInfo& theInfo);
+    void SetFieldInfo(const TFieldInfo& theInfo);
+
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    med_int GetNbTimeStamps(const TFieldInfo& theInfo, 
+                           const TEntityInfo& theEntityInfo,
+                           med_entite_maillage& theEntity,
+                           TGeom& theGeom);
+
+    void GetTimeStampInfo(med_int theTimeStampId, TTimeStampInfo&);
+
+    void GetTimeStampVal(TTimeStampVal& theTimeStampVal);
+
+    void SetTimeStamp(const TTimeStampVal& theTimeStampVal);
+
+  protected:
+    TFile myFile;
+  };
+
+};
+
+#endif
diff --git a/src/MEDWrapper/Makefile.in b/src/MEDWrapper/Makefile.in
new file mode 100644 (file)
index 0000000..71cbd7c
--- /dev/null
@@ -0,0 +1,51 @@
+#  VISU OBJECT : interactive object for VISU entities implementation
+#
+#  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+#
+#
+#
+#  File   : Makefile.in
+#  Module : VISU
+
+top_srcdir=@top_srcdir@
+top_builddir=../..
+srcdir=@srcdir@
+VPATH=.:@srcdir@:@top_srcdir@/idl
+
+
+@COMMENCE@
+
+EXPORT_HEADERS = MED_Common.hxx MED_Utilities.hxx MEDA_Structures.hxx MEDA_Wrapper.hxx MEDA_Algorithm.hxx
+
+# Libraries targets
+
+LIB = libMEDWrapper.la
+LIB_SRC = MED_Structures.cxx MED_Wrapper.cxx MED_Utilities.cxx \
+         MEDA_Structures.cxx MEDA_Wrapper.cxx MEDA_Algorithm.cxx 
+
+# Executables targets
+BIN = MED_Test MEDA_Test MEDA_Test1
+BIN_SRC = 
+
+CPPFLAGS+= $(BOOST_CPPFLAGS)  $(MED2_INCLUDES)
+
+LDFLAGS+= $(MED2_LIBS) $(HDF5_LIBS)
+
+@CONCLUDE@
index 76e643d9f90e312016feca16acac3b02b08d5241..017c546470270ffd23e42b5515bb92ca3a77616e 100644 (file)
@@ -26,6 +26,7 @@
 //  Module : SALOME
 //  $Header$
 
+using namespace std;
 #include <Python.h>
 #include <vtkRenderer.h>
 #include <vtkRenderWindowInteractor.h>
@@ -37,7 +38,6 @@
 #include "QAD_Application.h"
 #include "QAD_Desktop.h"
 #include "VTKViewer_ViewFrame.h"
-using namespace std;
 
 extern "C"
 { 
@@ -125,7 +125,7 @@ void initlibSalomePy()
       if ((viewId >=0) && (viewId <nbStudyFrames))
        renderer = ((VTKViewer_ViewFrame*)myStudy->getStudyFrame(viewId)->getRightFrame()->getViewFrame())->getRenderer();
     }
-  if (renderer == NULL) INFOS("No VTK Renderer available !");
+  if (renderer == NULL) MESSAGE("No VTK Renderer available !");
   //san:T3.13 - move getRenderer() implementation here
 
   MESSAGE("---");
index 06a168bd7879347cf376ebe30b5380e8ba8266f4..7c1de51a1d385650d549891ef80a05b961d98177 100644 (file)
@@ -20,7 +20,7 @@ VPATH=.:@srcdir@:@top_srcdir@/idl
 
 # SIP C++ Python
 # SIP defined in make_commence.in
-SIP_FLAGS    = -t WS_X11 -t Qt_3_0_5 -s ".cc" -c $(CURDIR) $(PYQT_INCLUDES)
+SIP_FLAGS    = -t WS_X11 -t Qt_3_0_5 -s ".cc" -c $(CURDIR) -I $(PYQT_SIPS)
 
 
 # SIP input file(s)
@@ -41,6 +41,7 @@ LIB = libSalomePyQtcmodule.la
 MOC_SRC = sipSalomePyQtProxySalomePyQt_moc.cxx
 
 LIB_SRC += SalomePyQt.cxx SALOME_PYQT_GUI.cxx $(SIP_SRC) $(MOC_SRC) 
+LIB_MOC = SALOME_PYQT_GUI.h
 
 #LIB_MOC += sipSalomePyQtProxySalomePyQt.h
 
@@ -50,7 +51,7 @@ LIB_CLIENT_IDL = SALOME_Exception.idl
 
 CPPFLAGS+=$(QT_INCLUDES) $(PYTHON_INCLUDES) $(SIP_INCLUDES) $(OCC_INCLUDES) $(VTK_INCLUDES) $(OGL_INCLUDES)
 LIBS+= $(PYTHON_LIBS) $(SIP_LIBS) $(PYQT_LIBS) $(VTK_LIBS) $(OGL_LIBS)
-LDFLAGS+= -lSalomeGUI
+LDFLAGS+= -lSalomeGUI -lqtcmodule
 
 
 # Custom build step: generate C++ wrapping according to $(SIP_FILES)
index f2a23e6a97a184df38e42bcd5428552742ae3939..73e33fd0527db93bb64f39b54903b7d91e118b43 100644 (file)
@@ -1,3 +1,4 @@
+using namespace std;
 //=============================================================================
 // File      : SALOME_PYQT_GUI.cxx
 // Created   : mer jun  4 17:17:20 UTC 2003
@@ -7,17 +8,14 @@
 // $Header$
 //=============================================================================
 
-#include "SALOME_PYQT_GUI.hxx"
+#include "SALOME_PYQT_GUI.h"
 
 #include "QAD_Desktop.h"
 
-#include "QAD_MessageBox.h"
 #include "SALOME_Selection.h"
 #include "SALOME_InteractiveObject.hxx"
 #include "SALOMEGUI_QtCatchCorbaException.hxx"
 #include "utilities.h"
-#include "PyInterp_PyQt.h"
-//#include <cStringIO.h>
 
 #include <sipSalomePyQtDeclSalomePyQt.h>
 #include <sipqtQWorkspace.h>
 
 #include <map>
 #include <string>
-using namespace std;
 
 static PyInterp_PyQt *interp = NULL;
 static map<int,PyInterp_PyQt*> mapInterp;
-static PyObject *module;
-static string _moduleName;
 
 //=============================================================================
 /*!
@@ -39,26 +34,43 @@ static string _moduleName;
  */
 //=============================================================================
 
-static void setWorkSpace()
+void SALOME_PYQT_GUI::setWorkSpace()
 {
   MESSAGE("setWorkSpace");
-  PyObject *res,*pyws;
-
-  interp->enter();
-  pyws=sipMapCppToSelf( QAD_Application::getDesktop()->getMainFrame(),
-                       sipClass_QWorkspace);
-  res=PyObject_CallMethod(module,"setWorkSpace","O",pyws);
+  PyLockWrapper aLock = interp->GetLockWrapper();
+
+  //   Try to import qt module. If it's not possible don't go on
+  PyObjWrapper qtmodule(PyImport_ImportModule("qt"));
+  if(!qtmodule){
+    PyErr_Print();
+    return ;
+  }  
+
+  PyObjWrapper pyws(sipMapCppToSelf( QAD_Application::getDesktop()->getMainFrame(),
+                                    sipClass_QWorkspace));
+  PyObjWrapper res(PyObject_CallMethod(_module,"setWorkSpace","O",pyws.get()));
   SCRUTE(pyws->ob_refcnt);
-  Py_DECREF(pyws);
-  if (res == NULL)
-    {
-      PyErr_Print();
-      interp->quit();
-      return ;
-    }
-  Py_DECREF(res);
-  interp->quit();
-  return ;
+  if(!res){
+    PyErr_Print();
+    return ;
+  }
+}
+
+//=============================================================================
+/*!
+ *  Import Python module (from _moduleName)                   
+ */
+//=============================================================================
+void SALOME_PYQT_GUI::importModule()
+{
+  PyLockWrapper aLock = interp->GetLockWrapper();
+
+  _module=PyImport_ImportModule((char*)_moduleName.c_str());
+  if(!_module){
+    MESSAGE ( " Problem... " );
+    PyErr_Print();
+    return;
+  }
 }
 
 //=============================================================================
@@ -69,35 +81,47 @@ static void setWorkSpace()
  */
 //=============================================================================
 
-static void initInterp(int StudyID)
+void SALOME_PYQT_GUI::initInterp(int StudyID)
 {
-  MESSAGE("initInterp");
-  if (mapInterp.find(StudyID) != mapInterp.end())
-    {
-      MESSAGE ( " StudyID is found " << StudyID );
-      interp = mapInterp[StudyID];
-      return;
-    }
-  else 
-    {
-      MESSAGE ( " StudyID is not found " << StudyID );
-      interp=new PyInterp_PyQt();
-      mapInterp[StudyID] = interp;
-    }
-
-  interp->enter();
-
-  module=PyImport_ImportModule((char*)_moduleName.c_str());
-  if(module == NULL)
-    {
-      INFOS ( " Problem... " );
-      PyErr_Print();
-      interp->quit();
-      return;
-    }
-  // PyQt import is OK
-  interp->quit();
+  MESSAGE("SALOME_PYQT_GUI::initInterp");
+  if(mapInterp.find(StudyID) != mapInterp.end()){
+    MESSAGE ( "SALOME_PYQT_GUI::initInterp StudyID is found " << StudyID );
+    interp = mapInterp[StudyID];
+    return;
+  }else{
+    MESSAGE ( "SALOME_PYQT_GUI::initInterp StudyID is not found " << StudyID );
+    /*
+     * The creation of Python interpretor must be protected par a C++ Lock because of C threads
+     */
+    ThreadLock aPyLock = GetPyThreadLock("SALOME_PYQT_GUI::initInterp");
+    interp=new PyInterp_PyQt();
+    mapInterp[StudyID] = interp;
+  }
+  // imports Python GUI module and puts it in _module attribute
+  importModule();
+  // calls _module.setWorkspace and passes the SIP object main workspace
   setWorkSpace();
+
+}
+
+//=============================================================================
+/*!
+ * constructor : only calls SALOMEGUI constructor
+ */
+//=============================================================================
+SALOME_PYQT_GUI::SALOME_PYQT_GUI( const QString& theName, QObject* theParent ) :
+    SALOMEGUI( theName, theParent ),_module(0)
+{
+    MESSAGE("SALOME_PYQT_GUI::SALOME_PYQT_GUI");
+}
+
+//=============================================================================
+/*!
+ * destructor : do nothing
+ */
+//=============================================================================
+SALOME_PYQT_GUI::~SALOME_PYQT_GUI()
+{
 }
 
 //=============================================================================
@@ -110,18 +134,13 @@ bool SALOME_PYQT_GUI::OnGUIEvent (int theCommandID,
                                  QAD_Desktop* parent)
 {
   MESSAGE("SALOME_PYQT_GUI::OnGUIEvent");
-  PyObject *res;
-  
-  interp->enter();
-  res=PyObject_CallMethod(module,"OnGUIEvent","i",theCommandID);
-  if (res == NULL)
-    {
-      PyErr_Print();
-      interp->quit();
-      return false;
-    }
-  Py_DECREF(res);
-  interp->quit();
+  PyLockWrapper aLock = interp->GetLockWrapper();
+
+  PyObjWrapper res(PyObject_CallMethod(_module,"OnGUIEvent","i",theCommandID));
+  if(!res){
+    PyErr_Print();
+    return false;
+  }
   return true;
 }
 
@@ -163,8 +182,8 @@ bool SALOME_PYQT_GUI::OnMouseMove (QMouseEvent* pe ,
                                   QAD_Desktop* parent, 
                                   QAD_StudyFrame* studyFrame)
 {
-  // La ligne suivante est commentée sinon multiple traces ...
-  // MESSAGE("SALOME_PYQT_GUI::OnMouseMouve");
+  // Commented out to avoid multiple traces ...
+  // MESSAGE("SALOME_PYQT_GUI::OnMouseMove");
   return true;
 }
 
@@ -178,23 +197,29 @@ bool SALOME_PYQT_GUI::OnMouseMove (QMouseEvent* pe ,
 bool SALOME_PYQT_GUI::SetSettings (QAD_Desktop* parent, char* moduleName)
 {
   MESSAGE("SALOME_PYQT_GUI::SetSettings");
-  PyObject *res;
   int StudyID = QAD_Application::getDesktop()->getActiveStudy()->getStudyId();
   SCRUTE ( StudyID );
   _moduleName = moduleName + string("GUI");
   SCRUTE(_moduleName);
+
+  // initializes one Python interpreter by study and puts it in interp global variable
+  // imports Python GUI module and puts it in _module attribute
+  // calls _module.setWorkspace and passes the SIP object main workspace
   initInterp(StudyID);
   
-  interp->enter();
-  res=PyObject_CallMethod(module,"setSettings","");
-  if (res == NULL)
-    {
-      PyErr_Print();
-      interp->quit();
-      return false;
-    }
-  Py_DECREF(res);
-  interp->quit();
+  PyLockWrapper aLock = interp->GetLockWrapper();
+
+  _module = PyImport_ImportModule((char*)_moduleName.c_str());
+  if(!_module){
+    PyErr_Print();
+    return false;
+  }
+
+  PyObjWrapper res(PyObject_CallMethod(_module,"setSettings",""));
+  if(!res){
+    PyErr_Print();
+    return false;
+  }
   return true;
 }
 
@@ -218,25 +243,19 @@ bool SALOME_PYQT_GUI::CustomPopup ( QAD_Desktop* parent,
   MESSAGE ( " theParent : " << theParent.latin1() );
   MESSAGE ( " theObject : " << theObject.latin1() );
 
-  PyObject *res,*pypop;
-  interp->enter();
-  pypop=sipMapCppToSelf( popup,
-                       sipClass_QPopupMenu);
-
-  res=PyObject_CallMethod(module,"customPopup","Osss",pypop,
-                         theContext.latin1(), theObject.latin1(), theParent.latin1());
-  Py_DECREF(pypop);
-  if (res == NULL)
-    {
-      PyErr_Print();
-      interp->quit();
-      return false;
-    }
-
-  Py_DECREF(res);
-  interp->quit();
+  PyLockWrapper aLock = interp->GetLockWrapper();
 
+  PyObjWrapper pypop(sipMapCppToSelf( popup, sipClass_QPopupMenu));
 
+  PyObjWrapper res(PyObject_CallMethod(_module,"customPopup",
+                                      "Osss",pypop.get(),
+                                      theContext.latin1(), 
+                                      theObject.latin1(), 
+                                      theParent.latin1()));
+  if(!res){
+    PyErr_Print();
+    return false;
+  }
   return true;
 }
 
@@ -253,36 +272,37 @@ void SALOME_PYQT_GUI::DefinePopup( QString & theContext,
                                   QString & theObject )
 {
   MESSAGE("SALOME_PYQT_GUI::DefinePopup");
-  theContext = "";
-  theObject = "";
-  theParent = "";
+  //theContext = "";
+  //theObject = "";
+  //theParent = "";
   
-  PyObject *res;
-  interp->enter();
-  res=PyObject_CallMethod(module,"definePopup","sss",
-                         theContext.latin1(), theObject.latin1(), theParent.latin1());
-  if (res == NULL)
-    {
-      PyErr_Print();
-      interp->quit();
-      return ;
-    }
+  PyLockWrapper aLock = interp->GetLockWrapper();
+
+  PyObjWrapper res(PyObject_CallMethod(_module,"definePopup","sss",
+                                      theContext.latin1(), 
+                                      theObject.latin1(), 
+                                      theParent.latin1()));
+  if(!res){
+    PyErr_Print();
+    return;
+  }
   char *co, *ob, *pa;
-  int parseOk = PyArg_ParseTuple(res, "sss", &co, &ob, &pa);
+  if(!PyArg_ParseTuple(res, "sss", &co, &ob, &pa))
+  {
+    // It's not a valid tuple. Do nothing.
+    return;
+  }
 
-  MESSAGE ("parseOk " << parseOk);
+  MESSAGE ("parseOk ");
   MESSAGE (" --- " << co << " " << ob << " " << pa);
 
   theContext = co;
   theObject = ob;
   theParent = pa;
-  Py_DECREF(res);
-  interp->quit();
 
   MESSAGE ( " theContext : " << theContext.latin1() );
   MESSAGE ( " theParent : " << theParent.latin1() );
   MESSAGE ( " theObject : " << theObject.latin1() );
-
 }
 
 //=============================================================================
@@ -292,76 +312,64 @@ void SALOME_PYQT_GUI::DefinePopup( QString & theContext,
  */
 //=============================================================================
 
-void SALOME_PYQT_GUI::ActiveStudyChanged( QAD_Desktop* parent )
+bool SALOME_PYQT_GUI::ActiveStudyChanged( QAD_Desktop* parent )
 {
-  MESSAGE("SALOME_PYQT_GUI::ActiveStudyChanged");
-  PyObject *res;
   
   int StudyID = parent->getActiveApp()->getActiveStudy()->getStudyId();
+  MESSAGE("SALOME_PYQT_GUI::ActiveStudyChanged"<<StudyID<<" - " <<this);
   initInterp(StudyID);
   
-  interp->enter();
-  res=PyObject_CallMethod(module,"activeStudyChanged","i", StudyID );
-  if (res == NULL)
-    {
-      PyErr_Print();
-      interp->quit();
-      return ;
-    }
-  Py_DECREF(res);
-  interp->quit();
-  return;
+  PyLockWrapper aLock = interp->GetLockWrapper();
+
+  PyObjWrapper res(PyObject_CallMethod(_module,"activeStudyChanged","i", StudyID ));
+  if(!res){
+    PyErr_Print();
+    return false;
+  }
+  return true;
 }
 
+//=============================================================================
+/*!
+ *  no call to python module.BuildPresentation() (not yet ???)
+ */
+//=============================================================================
+void SALOME_PYQT_GUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& theIO )
+{
+}
 
 //=============================================================================
 /*!
- *  
+ *  no call to python module.SupportedViewType() (not yet ???)
  */
 //=============================================================================
+void SALOME_PYQT_GUI::SupportedViewType(int* buffer, int bufferSize)
+{
+}
 
+//=============================================================================
+/*!
+ *  no call to python module.Deactivate() (not yet ???)
+ */
+//=============================================================================
+void SALOME_PYQT_GUI::Deactivate()
+{
+}
+
+
+
+
+//=============================================================================
+/*!
+ *  Component GUI Factory : returns a new GUI obj at each call
+ */
+//=============================================================================
 
 extern "C"
 {
-  bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
-  {
-    return SALOME_PYQT_GUI::OnGUIEvent(theCommandID, parent);
-  }
-  
-  bool OnKeyPress(QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
-  {
-    return SALOME_PYQT_GUI::OnKeyPress(pe, parent, studyFrame);
-  }
-  
-  bool OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
-  {
-    return SALOME_PYQT_GUI::OnMousePress(pe, parent, studyFrame);
-  }
-  
-  bool OnMouseMove(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
-  {
-    return SALOME_PYQT_GUI::OnMouseMove(pe, parent, studyFrame);
-  }
-  
-  bool SetSettings(QAD_Desktop* parent, char* moduleName)
-  {
-    return SALOME_PYQT_GUI::SetSettings(parent, moduleName);
-  }
-  
-  bool customPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
-                  const QString & theParent, const QString & theObject)
-  {
-    return SALOME_PYQT_GUI::CustomPopup( parent, popup, theContext, theParent, theObject );
-  }
-  
-  void definePopup(QString & theContext, QString & theParent, QString & theObject)
-  {
-    SALOME_PYQT_GUI::DefinePopup(theContext, theParent, theObject);
-  }
-  
-  void activeStudyChanged ( QAD_Desktop* parent )
-  {
-    SALOME_PYQT_GUI::ActiveStudyChanged(parent);
+  Standard_EXPORT SALOMEGUI* GetComponentGUI() {
+    MESSAGE("SALOME_PYQT_GUI::GetComponentGUI");
+    SALOMEGUI* aGUI = new SALOME_PYQT_GUI("");
+    return aGUI;
   }
 }
-
diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI.h b/src/SALOME_PYQT/SALOME_PYQT_GUI.h
new file mode 100644 (file)
index 0000000..2e7617d
--- /dev/null
@@ -0,0 +1,52 @@
+//=============================================================================
+// File      : SALOME_PYQT_GUI.hxx
+// Created   : mer jun  4 17:17:20 UTC 2003
+// Author    : Paul RASCLE, EDF 
+// Project   : SALOME
+// Copyright : EDF 2003
+// $Header$
+//=============================================================================
+
+#ifndef _SALOME_PYQT_GUI_HXX_
+#define _SALOME_PYQT_GUI_HXX_
+
+#include "QAD_Desktop.h"
+#include "PyInterp_PyQt.h"
+#include "SALOMEGUI.h"
+
+class SALOME_PYQT_GUI: public SALOMEGUI
+{
+  Q_OBJECT;
+  
+private:
+  // save the current Python module in the attribute _module
+  PyObjWrapper _module;
+  // save the current Python module name in the attribute _moduleName
+  string _moduleName;
+  
+public:
+  
+  SALOME_PYQT_GUI( const QString& name = "", QObject* parent = 0 );
+  virtual ~SALOME_PYQT_GUI();
+
+  virtual bool OnGUIEvent        (int theCommandID, QAD_Desktop* parent);
+  virtual bool OnKeyPress        (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame);
+  virtual bool OnMousePress      (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame);
+  virtual bool OnMouseMove       (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame);
+  virtual bool SetSettings       ( QAD_Desktop* parent, char* moduleName );
+  virtual bool CustomPopup       ( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
+                                   const QString & theParent, const QString & theObject );
+  virtual void DefinePopup       ( QString & theContext, QString & theParent, QString & theObject );
+  virtual bool ActiveStudyChanged( QAD_Desktop* parent);
+  virtual void BuildPresentation ( const Handle(SALOME_InteractiveObject)& theIO );
+  virtual void SupportedViewType (int* buffer, int bufferSize);
+  virtual void Deactivate        ();
+  void initInterp(int studyId);
+  void importModule();
+  void setWorkSpace();
+  
+protected:
+  
+};
+
+#endif
diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI.hxx b/src/SALOME_PYQT/SALOME_PYQT_GUI.hxx
deleted file mode 100644 (file)
index fe0f6ff..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-//=============================================================================
-// File      : SALOME_PYQT_GUI.hxx
-// Created   : mer jun  4 17:17:20 UTC 2003
-// Author    : Paul RASCLE, EDF 
-// Project   : SALOME
-// Copyright : EDF 2003
-// $Header$
-//=============================================================================
-
-#ifndef _SALOME_PYQT_GUI_HXX_
-#define _SALOME_PYQT_GUI_HXX_
-
-#include "QAD_Desktop.h"
-
-class SALOME_PYQT_GUI: public QObject
-{
-  Q_OBJECT
-    
-private:
-  
-public:
-  
-  static bool OnGUIEvent   (int theCommandID, QAD_Desktop* parent);
-  static bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent,
-                           QAD_StudyFrame* studyFrame);
-  static bool OnMouseMove  (QMouseEvent* pe, QAD_Desktop* parent,
-                           QAD_StudyFrame* studyFrame);
-  static bool OnKeyPress   (QKeyEvent* pe, QAD_Desktop* parent,
-                           QAD_StudyFrame* studyFrame);
-  static bool SetSettings  (QAD_Desktop* parent, char* moduleName);
-  static bool CustomPopup  (QAD_Desktop* parent, QPopupMenu* popup,
-                           const QString & theContext,
-                           const QString & theParent,
-                           const QString & theObject);
-  static void DefinePopup  (QString & theContext, QString & theParent,
-                           QString & theObject) ;
-  static void ActiveStudyChanged (QAD_Desktop* parent);
-  
-protected:
-  
-};
-
-#endif
index d6421eb3159f5ff8b9826ded7b27c7f64734d15b..11d2fe9ce73e3329537ca214d3ffce506d829d45 100644 (file)
@@ -5,6 +5,7 @@
 //  File   : SalomePyQt.cxx
 //  Module : SALOME
 
+using namespace std;
 #include "SalomePyQt.hxx"
 
 #include "QAD_Application.h"
@@ -14,7 +15,6 @@
 
 #include "QAD_Config.h"
 #include "QAD_Settings.h"
-using namespace std;
 
 QWidget* SalomePyQt::getDesktop()
 {
index ddd2ccfbda8f6924945ec084c46b6c58d62d5f9d..2a6f6933abcec44bde9babca20df9e3dd9be6a1c 100644 (file)
@@ -38,7 +38,7 @@ LIB = libSALOME_Swigcmodule.la
 LIB_SRC = 
 
 SWIG_DEF = libSALOME_Swig.i
-EXPORT_PYSCRIPTS = libSALOME_Swig.py Help.py PyInterp.py salome.py examplevtk1.py supervisionexample.py supervisiongeomexample.py salome_shared_modules.py batchmode_salome.py test_table.py test_big_table.py test_many_objects.py import_hook.py salome_test.py
+EXPORT_PYSCRIPTS = libSALOME_Swig.py Help.py PyInterp.py salome.py examplevtk1.py supervisionexample.py supervisiongeomexample.py salome_shared_modules.py batchmode_salome.py test_table.py test_big_table.py test_many_objects.py import_hook.py salome_test.py test_remove_ref.py
 
 EXPORT_SHAREDPYSCRIPTS=kernel_shared_modules.py
 
index 463aff9be6c2d591178304af84c9e6fe76226c04..7cf6757561ef8e3c9144f7d9225523c14fc4906b 100644 (file)
@@ -57,14 +57,30 @@ class SalomeGUI(SALOMEGUI_Swig):
     #--------------------------------------------------------------------------
 
 def IDToObject(id):
+    myObj = None
     mySO = myStudy.FindObjectID(id);
-    print id
-    Builder = myStudy.NewBuilder()
-    anAttr = Builder.FindOrCreateAttribute(mySO, "AttributeIOR")
-    AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
-    myObj = orb.string_to_object(AtIOR.Value())
+    if mySO is not None:
+        ok, anAttr = mySO.FindAttribute("AttributeIOR")
+        if ok:
+            AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
+            if AtIOR.Value() != "":
+                myObj = orb.string_to_object(AtIOR.Value())
     return myObj
 
+def ObjectToSObject(obj):
+    mySO = None
+    if obj is not None:
+        ior =  orb.object_to_string(obj)
+        if ior != "":
+            mySO = myStudy.FindObjectIOR(ior)
+    return mySO
+
+def ObjectToID(obj):
+    mySO = ObjectToSObject(obj)
+    if mySO:
+        return mySO.GetID()
+    return ""
+
 def IDToSObject(id):
     mySO = myStudy.FindObjectID(id);
     return mySO
@@ -210,8 +226,13 @@ obj = naming_service.Resolve('myStudyManager')
 myStudyManager = obj._narrow(SALOMEDS.StudyManager)
 
 # create new study
-myStudy = myStudyManager.NewStudy("Study1")
-
+aListOfOpenStudies = myStudyManager.GetOpenStudies();
+myStudy = None;
+if len(aListOfOpenStudies) == 0 :
+    myStudy = myStudyManager.NewStudy("Study1")
+else:
+    myStudy = aListOfOpenStudies[0]
+    
 myStudyName = myStudy._get_Name()
 
 myStudyId = myStudy._get_StudyId()
index 92a99f11f2b1e3e4de6d6634c8092a2e45753c3d..9d45865db4dcbee1c1ce40609c671a340de07534 100644 (file)
@@ -99,13 +99,30 @@ class SalomeGUI(SALOMEGUI_Swig):
     #--------------------------------------------------------------------------
 
 def IDToObject(id):
+    myObj = None
     mySO = myStudy.FindObjectID(id);
-    Builder = myStudy.NewBuilder()
-    anAttr = Builder.FindOrCreateAttribute(mySO, "AttributeIOR")
-    AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
-    myObj = orb.string_to_object(AtIOR.Value())
+    if mySO is not None:
+        ok, anAttr = mySO.FindAttribute("AttributeIOR")
+        if ok:
+            AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
+            if AtIOR.Value() != "":
+                myObj = orb.string_to_object(AtIOR.Value())
     return myObj
 
+def ObjectToSObject(obj):
+    mySO = None
+    if obj is not None:
+        ior =  orb.object_to_string(obj)
+        if ior != "":
+            mySO = myStudy.FindObjectIOR(ior)
+    return mySO
+
+def ObjectToID(obj):
+    mySO = ObjectToSObject(obj)
+    if mySO:
+        return mySO.GetID()
+    return ""
+
 def IDToSObject(id):
     mySO = myStudy.FindObjectID(id);
     return mySO
index 31b7f308f475f09679164ac33cc48f63d99b9dca..2a8196dc0aaf3d8cb8574ea814e438e515acc535 100644 (file)
@@ -59,6 +59,8 @@ print
 print "=============  Test SMESH  ============================="
 print
 
+import StdMeshers
+
 comp = catalog.GetComponent("SMESH")
 if comp is None:
        raise RuntimeError,"Component SMESH not found in Module Catalog."
@@ -68,11 +70,11 @@ if comp is None:
        raise RuntimeError,"Component MED not found in Module Catalog."
 
 import SMESH
-import smeshpy
 
 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
 myBuilder = salome.myStudy.NewBuilder()
 
+smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
 smeshgui = salome.ImportComponentGUI("SMESH")
 smeshgui.Init(salome.myStudyId);
 
@@ -113,138 +115,107 @@ name = geompy.SubShapeName( edge._get_Name(), face._get_Name() )
 print name
 idedge=geompy.addToStudyInFather(face,edge,name)
 
-# ---- launch SMESH, init a Mesh with the box
-gen=smeshpy.smeshpy()
-mesh=gen.Init(idbox)
 
-idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) )
-smeshgui.SetName(idmesh, "Meshbox");
-smeshgui.SetShape(idbox, idmesh);
+# ---- SMESH 
 
 # ---- create Hypothesis
 
 print "-------------------------- create Hypothesis"
 print "-------------------------- LocalLength"
-hyp1=gen.CreateHypothesis("LocalLength")
-hypLen1 = hyp1._narrow(SMESH.SMESH_LocalLength)
+hypLen1 = smesh.CreateHypothesis( "LocalLength", "libStdMeshersEngine.so" )
 hypLen1.SetLength(100)
 print hypLen1.GetName()
 print hypLen1.GetId()
 print hypLen1.GetLength()
 
-idlength = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypLen1) );
-smeshgui.SetName(idlength, "Local_Length_100");
+smeshgui.SetName(salome.ObjectToID(hypLen1), "Local_Length_100")
 
 print "-------------------------- NumberOfSegments"
-hyp2=gen.CreateHypothesis("NumberOfSegments")
-hypNbSeg1=hyp2._narrow(SMESH.SMESH_NumberOfSegments)
+hypNbSeg1= smesh.CreateHypothesis( "NumberOfSegments", "libStdMeshersEngine.so" )
 hypNbSeg1.SetNumberOfSegments(7)
 print hypNbSeg1.GetName()
 print hypNbSeg1.GetId()
 print hypNbSeg1.GetNumberOfSegments()
 
-idseg = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSeg1) );
-smeshgui.SetName(idseg, "NumberOfSegments_7");
+smeshgui.SetName(salome.ObjectToID(hypNbSeg1), "NumberOfSegments_7")
 
 print "-------------------------- MaxElementArea"
-hyp3=gen.CreateHypothesis("MaxElementArea")
-hypArea1=hyp3._narrow(SMESH.SMESH_MaxElementArea)
+hypArea1 = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" )
 hypArea1.SetMaxElementArea(2500)
 print hypArea1.GetName()
 print hypArea1.GetId()
 print hypArea1.GetMaxElementArea()
 
-idarea1 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea1) );
-smeshgui.SetName(idarea1, "MaxElementArea_2500");
+smeshgui.SetName(salome.ObjectToID(hypArea1), "MaxElementArea_2500")
 
 print "-------------------------- MaxElementArea"
-hyp3=gen.CreateHypothesis("MaxElementArea")
-hypArea2=hyp3._narrow(SMESH.SMESH_MaxElementArea)
+hypArea2 = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" )
 hypArea2.SetMaxElementArea(500)
 print hypArea2.GetName()
 print hypArea2.GetId()
 print hypArea2.GetMaxElementArea()
 
-idarea2 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea2) );
-smeshgui.SetName(idarea2, "MaxElementArea_500");
+smeshgui.SetName(salome.ObjectToID(hypArea2), "MaxElementArea_500")
 
 print "-------------------------- Regular_1D"
-alg1=gen.CreateHypothesis("Regular_1D")
-algo1=alg1._narrow(SMESH.SMESH_Algo)
-listHyp=algo1.GetCompatibleHypothesis()
+algoReg = smesh.CreateHypothesis( "Regular_1D", "libStdMeshersEngine.so" )
+listHyp=algoReg.GetCompatibleHypothesis()
 for hyp in listHyp:
     print hyp
-algoReg=alg1._narrow(SMESH.SMESH_Regular_1D)
 print algoReg.GetName()
 print algoReg.GetId()
 
-idreg = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoReg) );
-smeshgui.SetName(idreg, "Regular_1D");
+smeshgui.SetName(salome.ObjectToID(algoReg), "Regular_1D" )
 
 print "-------------------------- MEFISTO_2D"
-alg2=gen.CreateHypothesis("MEFISTO_2D")
-algo2=alg2._narrow(SMESH.SMESH_Algo)
-listHyp=algo2.GetCompatibleHypothesis()
+algoMef = smesh.CreateHypothesis( "MEFISTO_2D", "libStdMeshersEngine.so" )
+listHyp=algoMef.GetCompatibleHypothesis()
 for hyp in listHyp:
     print hyp
-algoMef=alg2._narrow(SMESH.SMESH_MEFISTO_2D)
 print algoMef.GetName()
 print algoMef.GetId()
 
-idmef = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoMef) );
-smeshgui.SetName(idmef, "MEFISTO_2D");
+smeshgui.SetName(salome.ObjectToID(algoMef), "MEFISTO_2D" )
+
+# ---- add hypothesis to box
+
+print "-------------------------- add hypothesis to box"
+box=salome.IDToObject(idbox)
+mesh = smesh.CreateMesh(box)
+
+smeshgui.SetName( salome.ObjectToID(mesh), "MeshBox" );
+
+ret=mesh.AddHypothesis(box,algoReg)
+print ret
+ret=mesh.AddHypothesis(box,algoMef)
+print ret
+
+
+ret=mesh.AddHypothesis(box,hypNbSeg1)
+print ret
+ret=mesh.AddHypothesis(box,hypArea1)
+print ret
+
 
 # ---- add hypothesis to edge
 
 print "-------------------------- add hypothesis to edge"
 edge=salome.IDToObject(idedge)
-submesh=mesh.GetElementsOnShape(edge)
+submesh=mesh.GetSubMesh(edge, "SubMeshEdge")
+
 ret=mesh.AddHypothesis(edge,algoReg)
 print ret
 ret=mesh.AddHypothesis(edge,hypLen1)
 print ret
 
-idsm1 = smeshgui.AddSubMeshOnShape( idmesh,
-                                    idedge,
-                                    salome.orb.object_to_string(submesh),
-                                    ShapeTypeEdge )
-smeshgui.SetName(idsm1, "SubMeshEdge")
-smeshgui.SetAlgorithms( idsm1, idreg );
-smeshgui.SetHypothesis( idsm1, idlength );
-
 print "-------------------------- add hypothesis to face"
 face=salome.IDToObject(idface)
-submesh=mesh.GetElementsOnShape(face)
-ret=mesh.AddHypothesis(face,hypArea2)
-print ret
-
-idsm2 = smeshgui.AddSubMeshOnShape( idmesh,
-                                    idface,
-                                    salome.orb.object_to_string(submesh),
-                                    ShapeTypeFace )
-smeshgui.SetName(idsm2, "SubMeshFace")
-smeshgui.SetHypothesis( idsm2, idarea2 );
+submesh   = mesh.GetSubMesh(face, "SubMeshFace")
 
-# ---- add hypothesis to box
-
-print "-------------------------- add hypothesis to box"
-box=salome.IDToObject(idbox)
-submesh=mesh.GetElementsOnShape(box)
-ret=mesh.AddHypothesis(box,algoReg)
-print ret
-ret=mesh.AddHypothesis(box,hypNbSeg1)
-print ret
-ret=mesh.AddHypothesis(box,algoMef)
-print ret
-ret=mesh.AddHypothesis(box,hypArea1)
+ret=mesh.AddHypothesis(face,hypArea2)
 print ret
 
-smeshgui.SetAlgorithms( idmesh, idreg );
-smeshgui.SetHypothesis( idmesh, idseg );
-smeshgui.SetAlgorithms( idmesh, idmef );
-smeshgui.SetHypothesis( idmesh, idarea1 );
-
-gen.Compute(mesh, idbox)
+smesh.Compute(mesh, box)
 sg.updateObjBrowser(1);
 
 print
@@ -273,7 +244,7 @@ if father is None:
        myBuilder.DefineComponentInstance(father,SuperVision)
 
 def addStudy(ior):
-    dataflow = SuperVision.getGraph(ior)
+    dataflow = SuperVision.getStreamGraph(ior)
     name=dataflow.Name()
     itr = myStudy.NewChildIterator(father)
     while itr.More():
@@ -309,7 +280,7 @@ print "Load dataflow from the file : "
 print xmlfile
 print
 
-myGraph = Graph ( xmlfile )
+myGraph = StreamGraph ( xmlfile )
 
 # This DataFlow is "valid" : no loop, correct links between Nodes etc...
 print "myGraph.IsValid() = ", myGraph.IsValid()
@@ -371,7 +342,7 @@ for node in nodes:
 print names
 
 # Graph creation 
-GraphInLines = Graph( 'GraphInLines' )
+GraphInLines = StreamGraph( 'GraphInLines' )
 GraphInLines.SetName( 'GraphInLines' )
 GraphInLines.SetAuthor( '' )
 GraphInLines.SetComment( '' )
@@ -460,8 +431,8 @@ import VISU
 
 import visu_gui
 
-medFile = "pointe.med"
-medFile = os.getenv('KERNEL_ROOT_DIR') + '/examples/' + medFile
+medFileName = "pointe.med"
+medFile = os.getenv('KERNEL_ROOT_DIR') + '/examples/' + medFileName
 print "Load ", medFile
 
 studyCurrent = salome.myStudyName
@@ -473,10 +444,11 @@ try:
     if os.access(medFile, os.R_OK) :
        if not os.access(medFile, os.W_OK) :
               import random
-              medFileNew = "/tmp/" + str(random.randint(0,1000000)) + "_" + medfile
+              medFileNew = "/tmp/" + str(random.randint(0,1000000)) + "_" + medFileName
               print " -- Copy " + medFile + " to " + medFileNew
               os.system("cp "+ medFile + " " + medFileNew)
               medFile = medFileNew
+              os.system("chmod 755 " + medFile)
 
        if os.access(medFile, os.W_OK) :
            med_comp.readStructFileWithFieldType(medFile,studyCurrent)
diff --git a/src/SALOME_SWIG/test_remove_ref.py b/src/SALOME_SWIG/test_remove_ref.py
new file mode 100755 (executable)
index 0000000..7842a0e
--- /dev/null
@@ -0,0 +1,49 @@
+#  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+#
+#
+#
+#  File   : test_remove_ref.py
+#  Module : SALOMEDS     
+
+from salome import *
+
+myBuilder = myStudy.NewBuilder()
+
+
+obj1 = myStudy.FindObjectID("0:1")
+if obj1 is None: print "Is null obj1 "
+else: print obj1.GetID()
+
+obj2 = myBuilder.NewObject(obj1)
+print "Obj2 ID = "+obj2.GetID()
+
+myBuilder.Addreference(obj1, obj2)
+
+(f, obj3) = obj1.ReferencedObject()
+
+print "Ref obj ID = "+obj3.GetID()
+
+
+myBuilder.RemoveReference(obj1)
+
+(f, obj4) = obj1.ReferencedObject()
+
+print "Ref is found ", f
\ No newline at end of file
index 70524b0619d7be2f225a5c638c1d28f1bba99c9b..140853bb9302c7901a5c924bc02b047119a45efb 100644 (file)
@@ -26,9 +26,9 @@
 //  Module : SALOME
 //  $Header$
 
+using namespace std;
 #include "SUPERVGraph.h"
 #include "SUPERVGraph_ViewFrame.h"
-using namespace std;
 
 QAD_ViewFrame* SUPERVGraph::createView(QAD_RightFrame* parent)
 {
index 439ffa15ae932f76821f039c9afe0c4b00f36362..7a73fff3efa17bd3f579fd9221624fd2fb1a5b22 100644 (file)
@@ -26,6 +26,7 @@
 //  Module : SALOME
 //  $Header$
 
+using namespace std;
 #include "SUPERVGraph_ViewFrame.h"
 
 #include "QAD_Settings.h"
@@ -39,7 +40,6 @@
 //QT Include
 #include <qlayout.h>
 #include <qcolordialog.h>
-using namespace std;
 
 SUPERVGraph_View::SUPERVGraph_View(QWidget* theParent): QWidget(theParent){
   init(theParent);
@@ -249,7 +249,7 @@ QColor SUPERVGraph_ViewFrame::backgroundColor() const
 }
 
 
-void SUPERVGraph_ViewFrame::SetSelectionMode( int mode )
+void SUPERVGraph_ViewFrame::SetSelectionMode( Selection_Mode mode )
 {
   MESSAGE ( "SUPERVGraph_ViewFrame::SetSelectionMode" )
 }
index 8c62cc436096492c2dcfc4ef079f19af9620b1b1..42aeafdf3a73e460bac6a82d04bb3155bd3c1981 100644 (file)
@@ -34,6 +34,7 @@
 #include "QAD_Application.h"
 
 #include "SALOME_InteractiveObject.hxx"
+#include "SALOME_Selection.h" 
 
 class QAD_EXPORT SUPERVGraph_View: public QWidget, public QAD_PopupClientServer{
   Q_OBJECT;
@@ -62,7 +63,7 @@ class QAD_EXPORT SUPERVGraph_ViewFrame : public QAD_ViewFrame {
   void                           setBackgroundColor( const QColor& );
   QColor                         backgroundColor() const;
   
-  void                           SetSelectionMode( int mode );
+  void                           SetSelectionMode( Selection_Mode mode );
 
   void                           onAdjustTrihedron( );
   
index 36ba65ddefbc20d6d1a9c185bf2f56d881192498..2072c8e84d02cb3464bcfa7d2497693095fbb50b 100644 (file)
@@ -40,8 +40,9 @@ EXPORT_HEADERS= SALOME_Session_i.hxx
 # Libraries targets
 LIB = libSalomeSession.la
 LIB_SRC=\
-       SALOME_Session_QThread.cxx \
-       SALOME_Session_i.cxx
+       SALOME_Session_i.cxx \
+       Session_ServerThread.cxx \
+       Session_ServerLauncher.cxx
 
 # Executables targets
 BIN = SALOME_Session_Server
@@ -49,9 +50,9 @@ BIN_SRC =
 BIN_SERVER_IDL = SALOME_Session.idl
 BIN_CLIENT_IDL = SALOMEDS.idl SALOMEDS_Attributes.idl SALOME_Component.idl SALOME_Registry.idl SALOME_ModuleCatalog.idl SALOME_Exception.idl
 
-CPPFLAGS+=$(QT_MT_INCLUDES) $(OCC_INCLUDES) $(PYTHON_INCLUDES)
+CPPFLAGS+=$(QT_MT_INCLUDES) $(OCC_INCLUDES) $(PYTHON_INCLUDES) $(HDF5_INCLUDES)
 CXXFLAGS+=$(OCC_CXXFLAGS)
-LDFLAGS+=$(QT_MT_LIBS)  -lSalomeNS -lSalomeGUI -lSalomeObject -lSalomeLifeCycleCORBA -lqsplitterP -lOpUtil -lPlot2d -lSalomeVTKFilter -lSALOMELocalTrace
+LDFLAGS+=$(QT_MT_LIBS) $(HDF5_LIBS) -lSalomeHDFPersist -lSalomeNS -lSalomeGUI -lSalomeObject -lSalomeLifeCycleCORBA -lqsplitterP -lOpUtil -lPlot2d -lSalomeVTKFilter -lSALOMELocalTrace -lSalomeContainer -lRegistry -lSalomeNotification -lSalomeDS -lTOOLSDS -lSalomeGenericObj -lSalomeCatalog -lEvent
 
 
 @CONCLUDE@
index bdd9910f25af29600546d136fa596e6826db7035..9229ba2741372b5e9688a48eca9ed00f70844b53 100644 (file)
@@ -26,6 +26,7 @@
 //  Module : SALOME
 //  $Header$
 
+using namespace std;
 #include <qapplication.h>
 #include <qlabel.h>
 
 // only to use findFile method : perhaps put it in QAD_Tools ???
 #include "QAD_ResourceMgr.h"
 #include <qlabel.h>
-using namespace std;
-
 
+#include "Utils_CatchSignals.h"
+#include "Utils_CorbaException.hxx"
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SALOMEDS)
 
-SALOME_Session_QThread* SALOME_Session_QThread::_singleton = 0;
-
 //=============================================================================
 /*! SALOME_Session_QThread
  *  constructor
@@ -58,7 +57,6 @@ SALOME_Session_QThread* SALOME_Session_QThread::_singleton = 0;
 
 SALOME_Session_QThread::SALOME_Session_QThread(int argc, char ** argv) : QThread()
 {
-  INFOS("Creation SALOME_Session_QThread");
   _qappl = 0 ;
   _mw = 0 ;
   _argc = argc ;
@@ -66,18 +64,6 @@ SALOME_Session_QThread::SALOME_Session_QThread(int argc, char ** argv) : QThread
   _NS = 0 ;
 } ;
 
-//=============================================================================
-/*!
- *  
- */
-//=============================================================================
-
-  SALOME_Session_QThread* SALOME_Session_QThread::Instance(int argc, char ** argv)
-{
-  if (_singleton == 0) _singleton = new SALOME_Session_QThread(argc, argv);
-  return _singleton;
-
-}
 
 //=============================================================================
 /*! run
@@ -85,18 +71,17 @@ SALOME_Session_QThread::SALOME_Session_QThread(int argc, char ** argv) : QThread
  *  Executes the Qt main window of the GUI on a separate thread
  */
 //=============================================================================
-
 void SALOME_Session_QThread::run()
 {
   if (_qappl == 0)
     {
       _qappl = new QApplication(_argc, _argv );
-      INFOS("creation QApplication");
+      MESSAGE("creation QApplication");
     }
 
   QAD_ASSERT ( QObject::connect(_qappl, SIGNAL(lastWindowClosed()), _qappl, SLOT(quit()) ) );
   _mw = new SALOMEGUI_Application ( "MDTV-Standard", "HDF", "hdf" );
-  INFOS("creation SALOMEGUI_Application");
+  MESSAGE("creation SALOMEGUI_Application");
   
   if ( !SALOMEGUI_Application::addToDesktop ( _mw, _NS ) )
     {
@@ -116,26 +101,59 @@ void SALOME_Session_QThread::run()
 
       _qappl->setPalette( QAD_Application::getPalette() ); 
 
+      Utils_CatchSignals aCatch;
+      aCatch.Activate();
+      
       /* Run 'SALOMEGUI' application */
       QAD_Application::run();
-
+     
       // T2.12 - catch exceptions thrown on attempts to modified a locked study
       while (1) {
        try {
-         MESSAGE("run(): starting the main event loop")
+         MESSAGE("run(): starting the main event loop");
          _ret = _qappl->exec();
          break;
        }
+       catch (SALOME::SALOME_Exception& e) {
+         INFOS("run(): SALOME::SALOME_Exception is caught");
+         QApplication::restoreOverrideCursor();
+         QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
+                                 QObject::tr("ERR_ERROR"), 
+                                 QObject::tr("ERR_APP_EXCEPTION")+ QObject::tr(" SALOME::SALOME_Exception is caught") ,
+                                 QObject::tr("BUT_OK") );
+         
+       }
        catch(SALOMEDS::StudyBuilder::LockProtection&) {
-         MESSAGE("run(): An attempt to modify a locked study has not been handled by QAD_Operation")
+         INFOS("run(): An attempt to modify a locked study has not been handled by QAD_Operation");
          QApplication::restoreOverrideCursor();
          QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
-                              QObject::tr("WRN_WARNING"), 
-                              QObject::tr("WRN_STUDY_LOCKED"),
+                                QObject::tr("WRN_WARNING"), 
+                                QObject::tr("WRN_STUDY_LOCKED"),
+                                QObject::tr("BUT_OK") );
+       }
+       catch (const CORBA::Exception& e) {
+         CORBA::Any tmp;
+         tmp<<= e;
+         CORBA::TypeCode_var tc = tmp.type();
+         const char *p = tc->name();
+         INFOS ("run(): CORBA exception of the kind : "<<p<< " is caught");
+
+         QApplication::restoreOverrideCursor();
+         QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
+                              QObject::tr("ERR_ERROR"), 
+                              QObject::tr("ERR_APP_EXCEPTION")+ QObject::tr(" CORBA exception ") + QObject::tr(p),
+                              QObject::tr("BUT_OK") );
+       }
+       catch(std::exception& e) {
+         INFOS("run(): An exception has been caught");
+         QApplication::restoreOverrideCursor();
+         QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
+                              QObject::tr("ERR_ERROR"), 
+                              QObject::tr("ERR_APP_EXCEPTION")+ " " +QObject::tr(e.what()),
                               QObject::tr("BUT_OK") );
        }
        catch(...) {
-         MESSAGE("run(): An exception has been caught")
+         INFOS("run(): An exception has been caught")
          QApplication::restoreOverrideCursor();
          QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
                               QObject::tr("ERR_ERROR"), 
@@ -143,7 +161,8 @@ void SALOME_Session_QThread::run()
                               QObject::tr("BUT_OK") );
        }
       }
-
+      
+      aCatch.Deactivate();
       QString confMsg = "Settings create $HOME/." + QObject::tr("MEN_APPNAME") + "/" + QObject::tr("MEN_APPNAME") + ".conf";
       MESSAGE (confMsg )
       QAD_CONFIG->createConfigFile(true);
index eac1da8d65ceb0be7fe031e362d872e5f2271783..9e9941bd7814552fbc47286b31d00b2b4e4bd7b7 100644 (file)
@@ -41,7 +41,7 @@ class SALOME_Session_QThread: public QThread
 {
 
 public:
-  static SALOME_Session_QThread* Instance(int argc, char ** argv);
+  SALOME_Session_QThread(int argc, char ** argv) ;
 
   //! launch the Qt main window of the GUI on a separate thread
   virtual void run() ;
@@ -57,10 +57,6 @@ protected:
   QApplication *_qappl ;
 
   SALOMEGUI_Application* _mw ;
-  SALOME_Session_QThread(int argc, char ** argv);
-
-private:
-  static SALOME_Session_QThread* _singleton;
 } ;
 
 #endif
index 2b00367c27fd2e68b62b9e2b4aed275d87a00817..ff9a6cf3c20d22bc4258a65411887e366fbc4047 100644 (file)
 #include <unistd.h>
 using namespace std;
 
+#include <qthread.h> 
+#include <qapplication.h>
+#include <qlabel.h>
+#include <qwaitcondition.h>
+
+#include "SALOMEGUI_Application.h"
+#include "QAD.h"
+#include "QAD_MessageBox.h"
+#include "QAD_Application.h"
+#include "QAD_Settings.h"
+#include "QAD_Config.h"
+#include "QAD_Tools.h"
+#include "QAD_ResourceMgr.h"
+#include "Utils_CatchSignals.h"
+#include "Utils_SALOME_Exception.hxx"
+#include "Utils_CorbaException.hxx"
+#include "SALOMEGUI_QtCatchCorbaException.hxx"
+
+
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SALOME_Session)
+#include CORBA_SERVER_HEADER(SALOMEDS)
 
 #include "utilities.h"
 
 #include "SALOME_Session_i.hxx"
 
+#include "Session_ServerLauncher.hxx"
+
+/*! - read arguments, define list of server to launch with their arguments.
+ *  - wait for naming service
+ *  - create and run a thread for launch of all servers
+ *  
+ */
+
+// ----------------------------------------------------------------------------
+
+
+
+// ----------------------------------------------------------------------------
+
 //! CORBA server for SALOME Session
 /*!
  *  SALOME_Session Server launches a SALOME session servant.
@@ -54,120 +88,169 @@ using namespace std;
 
 int main(int argc, char **argv)
 {
-
   try
     {
       ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
       ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
-      CORBA::ORB_var &orb = init( argc , argv ) ;
-
-      //
-      long TIMESleep = 250000000;
-      int NumberOfTries = 40;
-      int a;
-      timespec ts_req;
-      ts_req.tv_nsec=TIMESleep;
-      ts_req.tv_sec=0;
-      timespec ts_rem;
-      ts_rem.tv_nsec=0;
-      ts_rem.tv_sec=0;
-      CosNaming::NamingContext_var inc;
-      PortableServer::POA_var poa;
-      CORBA::Object_var theObj;
-      CORBA::Object_var obj;
-      CORBA::Object_var object;
-      SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
-      int SESSION=0;
-      const char * Env = getenv("USE_LOGGER"); 
-      int EnvL =0;
-      if ((Env!=NULL) && (strlen(Env)))
-       EnvL=1;
-      CosNaming::Name name;
-      name.length(1);
-      name[0].id=CORBA::string_dup("Logger");    
-      PortableServer::POAManager_var pman; 
-      for (int i = 1; i<=NumberOfTries; i++){
-       if (i!=1) 
-         a=nanosleep(&ts_req,&ts_rem);
-       try
-         { 
-           obj = orb->resolve_initial_references("RootPOA");
-            if(!CORBA::is_nil(obj))
-             poa = PortableServer::POA::_narrow(obj);
-            if(!CORBA::is_nil(poa))
-             pman = poa->the_POAManager();
-           if(!CORBA::is_nil(orb)) 
-             theObj = orb->resolve_initial_references("NameService");
-           if (!CORBA::is_nil(theObj))
-             inc = CosNaming::NamingContext::_narrow(theObj);
-         }
-       catch( CORBA::COMM_FAILURE& )
-         {
-           MESSAGE( "Session Server: CORBA::COMM_FAILURE: Unable to contact the Naming Service" );
-         }
-       if(!CORBA::is_nil(inc))
-         {
-           MESSAGE( "Session Server: Naming Service was found" );
-           if(EnvL==1)
-             {
-               for(int j=1; j<=NumberOfTries; j++)
-                 {
-                   if (j!=1) 
-                     a=nanosleep(&ts_req, &ts_rem);
-                   try
-                     {
-                       object = inc->resolve(name);
-                     }
-                   catch(CosNaming::NamingContext::NotFound)
-                     { MESSAGE( "Session Server: Logger Server wasn't found" );
-                     }
-                   catch(...)
-                     {
-                       MESSAGE( "Session Server: Unknown exception" ); 
-                     }
-                   if (!CORBA::is_nil(object))
-                     {
-                       MESSAGE( "Session Server: Loger Server was found" );
-                       SESSION=1;
-                       break;
-                     }
-                 }
-             }
-         }
-       if ((SESSION==1)||((EnvL==0)&&(!CORBA::is_nil(inc))))
-         break;
-      }
-   
-      // servant
-      SALOME_Session_i * mySALOME_Session = new SALOME_Session_i(argc, argv, orb, poa) ;
-      PortableServer::ObjectId_var mySALOME_Sessionid = poa->activate_object(mySALOME_Session) ;
-      MESSAGE("poa->activate_object(mySALOME_Session)")
-
-       obj = mySALOME_Session->_this() ;
-      CORBA::String_var sior(orb->object_to_string(obj)) ;
-
-      mySALOME_Session->NSregister();
-
-      mySALOME_Session->_remove_ref() ;
-
-      //DECOMMENT PortableServer::POAManager_var pman = poa->the_POAManager() ;
+      int orbArgc = 1;
+      CORBA::ORB_var &orb = init( orbArgc , argv ) ;
+
+      CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
+      PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
+
+      PortableServer::POAManager_var pman = poa->the_POAManager() ;
       pman->activate() ;
-      MESSAGE("pman->activate()")
+      INFOS("pman->activate()");
+
+      SALOME_NamingService *_NS = new SALOME_NamingService(orb);
+
+      Utils_CatchSignals aCatch;
+      aCatch.Activate();
 
-       orb->run() ;
-      orb->destroy() ;
+      // CORBA Servant Launcher
+
+      QMutex _GUIMutex ;
+      QWaitCondition _ServerLaunch;
+      _GUIMutex.lock();     // to block Launch server thread until wait(mutex)
+
+      Session_ServerLauncher* myServerLauncher
+       = new Session_ServerLauncher(argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch);
+      myServerLauncher->start();
+
+      MESSAGE("waiting wakeAll()");
+      _ServerLaunch.wait(&_GUIMutex); // to be reseased by Launch server thread when ready:
+      // atomic operation lock - unlock on mutex
+      // unlock mutex: serverThread runs, calls  _ServerLaunch->wakeAll()
+      // this thread wakes up, and lock mutex
+
+      INFOS("Session activated, Launch IAPP...");
+
+      int qappArgc = 1;
+      QApplication *_qappl = new QApplication(qappArgc, argv );
+      INFOS("creation QApplication");
+      _GUIMutex.unlock();
+
+      QAD_ASSERT ( QObject::connect(_qappl, SIGNAL(lastWindowClosed()), _qappl, SLOT(quit()) ) );
+      SALOMEGUI_Application* _mw = new SALOMEGUI_Application ( "MDTV-Standard", "HDF", "hdf" );
+      INFOS("creation SALOMEGUI_Application");
+      
+      SCRUTE(_NS);
+      if ( !SALOMEGUI_Application::addToDesktop ( _mw, _NS ) )
+       {
+         QAD_MessageBox::error1 ( 0,
+                                  QObject::tr("ERR_ERROR"), 
+                                  QObject::tr("ERR_APP_INITFAILED"),
+                                  QObject::tr("BUT_OK") );
+       }
+      else
+       {
+         
+         QFileInfo prgInfo(argv[0]);
+         QDir prgDir(prgInfo.dirPath(true));
+         QAD_CONFIG->setPrgDir(prgDir);        // CWD is program directory
+         QAD_CONFIG->createConfigFile(false);  // Create config file
+                                               // ~/.tr(MEN_APPNAME)/tr(MEN_APPNAME).conf if there's none
+         QAD_CONFIG->readConfigFile();         // Read config file
+         
+         _qappl->setPalette( QAD_Application::getPalette() ); 
+
+         //Utils_CatchSignals aCatch;
+         //aCatch.Activate();
+
+         /* Run 'SALOMEGUI' application */
+         QAD_Application::run();
+
+         // T2.12 - catch exceptions thrown on attempts to modified a locked study
+         while (1) 
+           {
+             try 
+               {
+                 MESSAGE("run(): starting the main event loop");
+                 int _ret = _qappl->exec();
+                 break;
+               }
+             catch (SALOME::SALOME_Exception& e)
+               {
+                 QtCatchCorbaException(e);
+               }
+             catch(SALOMEDS::StudyBuilder::LockProtection&)
+               {
+                 INFOS("run(): An attempt to modify a locked study has not been handled by QAD_Operation");
+                 QApplication::restoreOverrideCursor();
+                 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
+                                         QObject::tr("WRN_WARNING"), 
+                                         QObject::tr("WRN_STUDY_LOCKED"),
+                                         QObject::tr("BUT_OK") );
+               }
+             catch (const CORBA::Exception& e)
+               {
+                 CORBA::Any tmp;
+                 tmp<<= e;
+                 CORBA::TypeCode_var tc = tmp.type();
+                 const char *p = tc->name();
+                 INFOS ("run(): CORBA exception of the kind : "<<p<< " is caught");
+
+                 QApplication::restoreOverrideCursor();
+                 QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
+                                          QObject::tr("ERR_ERROR"), 
+                                          QObject::tr("ERR_APP_EXCEPTION")
+                                          + QObject::tr(" CORBA exception ") + QObject::tr(p),
+                                          QObject::tr("BUT_OK") );
+               }
+             catch(std::exception& e)
+               {
+                 INFOS("run(): An exception has been caught");
+                 QApplication::restoreOverrideCursor();
+                 QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
+                                          QObject::tr("ERR_ERROR"), 
+                                          QObject::tr("ERR_APP_EXCEPTION")+ " " +QObject::tr(e.what()),
+                                          QObject::tr("BUT_OK") );
+               }
+             catch(...)
+               {
+                 INFOS("run(): An exception has been caught");
+                 QApplication::restoreOverrideCursor();
+                 QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
+                                          QObject::tr("ERR_ERROR"), 
+                                          QObject::tr("ERR_APP_EXCEPTION"),
+                                          QObject::tr("BUT_OK") );
+               }
+           }
+         //aCatch.Deactivate();
+         QString confMsg = "Settings create $HOME/." 
+           + QObject::tr("MEN_APPNAME") + "/" + QObject::tr("MEN_APPNAME") + ".conf";
+         MESSAGE (confMsg );
+         QAD_CONFIG->createConfigFile(true);
+       }
+      //orb->shutdown(0);
+      myServerLauncher->KillAll();
+      aCatch.Deactivate();
     }
-  catch (CORBA::SystemException&)
+  catch (SALOME_Exception& e)
+    {
+      INFOS("run(): SALOME::SALOME_Exception is caught: "<<e.what());
+    }
+  catch (CORBA::SystemException& e)
     {
       INFOS("Caught CORBA::SystemException.");
     }
-  catch (CORBA::Exception&)
+  catch (CORBA::Exception& e)
     {
       INFOS("Caught CORBA::Exception.");
+      CORBA::Any tmp;
+      tmp<<= e;
+      CORBA::TypeCode_var tc = tmp.type();
+      const char *p = tc->name();
+      INFOS ("run(): CORBA exception of the kind : "<<p<< " is caught");
+    }
+  catch(std::exception& e)
+    {
+      INFOS("run(): An exception has been caught: " <<e.what());
     }
   catch (...)
     {
       INFOS("Caught unknown exception.");
     }
+  MESSAGE("End of SALOME_Session_Server");
   return 0 ;
 }
index dc16fae7deceae32874412b7906e3a3f963d2b5d..89002812778d13903f45145f887d4affe473bb1b 100644 (file)
@@ -48,15 +48,15 @@ using namespace std;
  */ 
 //=============================================================================
 
-SALOME_Session_i::SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
+SALOME_Session_i::SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, QMutex* GUIMutex)
 {
   _argc = argc ;
   _argv = argv ;
-  _IAPPThread = SALOME_Session_QThread::Instance(_argc, _argv);
   _isGUI = FALSE ;
   _runningStudies= 0 ;
   _orb = CORBA::ORB::_duplicate(orb) ;
   _poa = PortableServer::POA::_duplicate(poa) ;
+  _GUIMutex = GUIMutex;
   MESSAGE("constructor end");
 }
 
@@ -66,14 +66,16 @@ SALOME_Session_i::SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, P
  */ 
 //=============================================================================
 
-Engines::Component_ptr SALOME_Session_i::GetVisuComponent() {
+Engines::Component_ptr SALOME_Session_i::GetVisuComponent()
+{
   MESSAGE("SALOME_Session_i::GetVisuGen");
-  typedef Engines::Component_ptr VisuGen(CORBA::ORB_ptr,PortableServer::POA_ptr,
+  typedef Engines::Component_ptr TGetImpl(CORBA::ORB_ptr,
+                                        PortableServer::POA_ptr,
                                         SALOME_NamingService*,QMutex*);
-  OSD_SharedLibrary  visuSharedLibrary("libVISUEngine.so");
-  if(visuSharedLibrary.DlOpen(OSD_RTLD_LAZY))
-    if(OSD_Function osdFun = visuSharedLibrary.DlSymb("GetVisuGen"))
-      return ((VisuGen (*)) osdFun)(_orb,_poa,_NS,&_GUIMutex);
+  OSD_SharedLibrary  aSharedLibrary("libVISUEngineImpl.so");
+  if(aSharedLibrary.DlOpen(OSD_RTLD_LAZY))
+    if(OSD_Function anOSDFun = aSharedLibrary.DlSymb("GetImpl"))
+      return ((TGetImpl (*)) anOSDFun)(_orb,_poa,_NS,_GUIMutex);
   return Engines::Component::_nil();
 }
 
@@ -102,7 +104,6 @@ void SALOME_Session_i::NSregister()
     {
       _NS = new SALOME_NamingService(_orb);
       _NS->Register(pSession, "/Kernel/Session");
-      _IAPPThread->setNamingService(_NS);
     }
   catch (ServiceUnreachable&)
     {
@@ -113,7 +114,7 @@ void SALOME_Session_i::NSregister()
     {
       INFOS("Caught unknown exception from Naming Service");
     }
-  MESSAGE("NSregister end"); 
+  MESSAGE("Session registered in Naming Service"); 
 }
 
 //=============================================================================
@@ -125,13 +126,14 @@ void SALOME_Session_i::NSregister()
 
 void SALOME_Session_i::GetInterface()
 {
-  _GUIMutex.lock() ;       // get access to boolean _isGUI
-  _isGUI = _IAPPThread->running();
-  if(!_isGUI){
-    _isGUI = TRUE ; 
-    _IAPPThread->start() ;
-  }
-  _GUIMutex.unlock() ; // release access to boolean _isGUI 
+  _GUIMutex->lock() ;       // get access to boolean _isGUI
+  //_isGUI = _IAPPThread->running();
+  if(!_isGUI)
+    {
+      _isGUI = TRUE ; 
+      //_IAPPThread->start() ;
+    }
+  _GUIMutex->unlock() ; // release access to boolean _isGUI 
 }
 
 //=============================================================================
@@ -145,21 +147,6 @@ void SALOME_Session_i::StopSession()
   qApp->lock();
   QAD_Application::getDesktop()->closeDesktop( true );
   qApp->unlock();
-/*
-  _GUIMutex.lock();         // get access to boolean _isGUI
-  if ((! _isGUI) && (! _runningStudies))
-    {
-      MESSAGE("Ask for Session Kill, OK");
-      exit(0);
-    }
-  else
-    {
-      _GUIMutex.unlock() ;  // release access to boolean _isGUI
-      MESSAGE("Ask for Session Kill, NOK");
-      if (_isGUI) throw SALOME::Session::GUIActive();   
-      if (_runningStudies) throw SALOME::Session::RunningStudies();
-    }
-*/
 }
  
 //=============================================================================
@@ -173,16 +160,18 @@ SALOME::StatSession SALOME_Session_i::GetStatSession()
 {
   // update Session state
   //qApp->lock(); // rollback bug 
-  _GUIMutex.lock();    
-  _isGUI = _IAPPThread->running();
+  _GUIMutex->lock();    
+  //_isGUI = _IAPPThread->running();
+  _isGUI = 1;
   _runningStudies = 0;
-  if (_isGUI) {
-    qApp->lock();
-    if ( QAD_Application::getDesktop() && QAD_Application::getDesktop()->getActiveApp() )
-      _runningStudies = QAD_Application::getDesktop()->getActiveApp()->getStudies().count();
-    qApp->unlock();
-  }
-  _GUIMutex.unlock();
+  if (_isGUI)
+    {
+      qApp->lock();
+      if ( QAD_Application::getDesktop() && QAD_Application::getDesktop()->getActiveApp() )
+       _runningStudies = QAD_Application::getDesktop()->getActiveApp()->getStudies().count();
+      qApp->unlock();
+    }
+  _GUIMutex->unlock();
   //qApp->unlock();
   // getting stat info
   SALOME::StatSession_var myStats = new SALOME::StatSession ;
index 0d52f118eb04ff5a452fed0ce0943b08e6a6465b..438b93f62aeb2c105f35bb9eeca361ac9980e4a2 100644 (file)
@@ -41,8 +41,8 @@ class SALOME_Session_i:  public virtual POA_SALOME::Session,
                         public virtual PortableServer::RefCountServantBase
 {
 public:
-  SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa;
-  ~SALOME_Session_i() ;
+  SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, QMutex* GUIMutex);
+  ~SALOME_Session_i();
 
   //! Launch Graphical User Interface
   void GetInterface();
@@ -62,8 +62,6 @@ public:
   void ping(){};
 
 protected:
-  //! A QT Thread for the GUI
-  SALOME_Session_QThread *_IAPPThread ;
 
   //! Naming service interface
   SALOME_NamingService *_NS;
@@ -71,7 +69,7 @@ protected:
   int _argc ;
   char **_argv;
   CORBA::Boolean _isGUI ;
-  QMutex _GUIMutex ;
+  QMutex* _GUIMutex ;
   int _runningStudies ;
   CORBA::ORB_var _orb;
   PortableServer::POA_var _poa;
diff --git a/src/Session/Session_ServerLauncher.cxx b/src/Session/Session_ServerLauncher.cxx
new file mode 100644 (file)
index 0000000..4f27819
--- /dev/null
@@ -0,0 +1,231 @@
+//  SALOME Session : implementation of Session_ServerLauncher.cxx
+//
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : Session_ServerLauncher.xx
+//  Author : Paul RASCLE, EDF
+//  Module : SALOME
+//  $Header$
+
+#include "Session_ServerLauncher.hxx"
+
+#include "Utils_SALOME_Exception.hxx"
+#include "utilities.h"
+
+//=============================================================================
+/*! 
+ *  default constructor not for use
+ */
+//=============================================================================
+
+Session_ServerLauncher::Session_ServerLauncher()
+{
+  ASSERT(0); // must not be called
+}
+
+//=============================================================================
+/*! 
+ *  constructor
+ */
+//=============================================================================
+
+Session_ServerLauncher::Session_ServerLauncher(int argc,
+                                              char ** argv, 
+                                              CORBA::ORB_ptr orb, 
+                                              PortableServer::POA_ptr poa,
+                                              QMutex *GUIMutex,
+                                              QWaitCondition *ServerLaunch)
+{
+  _argc = argc;
+  _argv = argv;
+  _orb = CORBA::ORB::_duplicate(orb);
+  _root_poa = PortableServer::POA::_duplicate(poa);
+  _GUIMutex = GUIMutex;
+  _ServerLaunch = ServerLaunch;
+}
+
+//=============================================================================
+/*! 
+ *  destructor
+ */
+//=============================================================================
+
+Session_ServerLauncher::~Session_ServerLauncher()
+{
+}
+
+//=============================================================================
+/*! 
+ *  Check args and activate servers
+ */
+//=============================================================================
+
+void Session_ServerLauncher::run()
+{
+  MESSAGE("Session_ServerLauncher::run");
+  _GUIMutex->lock(); // lock released by calling thread when ready: wait(mutex)
+   MESSAGE("Server Launcher thread free to go...");
+   _GUIMutex->unlock();
+
+  CheckArgs();
+  ActivateAll();
+
+  _ServerLaunch->wakeAll();
+  _orb->run();       // this thread wait, during omniORB process events
+}
+
+//=============================================================================
+/*! 
+ *  controls and dispatchs arguments given with command
+ */
+//=============================================================================
+
+void Session_ServerLauncher::CheckArgs()
+{
+  int argState = 0;
+  ServArg aServArg(0,0,0);
+  _argCopy.reserve(_argc);
+  for (int iarg=0; iarg <_argc; iarg++)
+    {
+      SCRUTE(iarg);
+      SCRUTE(_argv[iarg]);
+      _argCopy.push_back(_argv[iarg]);
+      switch (argState)
+       {
+       case 0: // looking for "--with"
+         {
+           if (strcmp(_argv[iarg],"--with")==0)
+             argState = 1;
+           break;
+         }
+       case 1: // looking for server type
+         {
+           for (int i=0; i<Session_ServerThread::NB_SRV_TYP; i++)
+               if (strcmp(_argv[iarg],Session_ServerThread::_serverTypes[i])==0)
+                 {
+                   aServArg._servType = i;
+                   argState = 2;
+                   break;
+                 }
+           break;
+         }
+       case 2: // looking for "("
+         {
+           if (strcmp(_argv[iarg],"(")!=0)
+             {
+               INFOS("parenthesis '(' is required here...");
+               for (int i=0; i<iarg; i++)
+                 cerr << _argv[i] << " ";
+               cerr << endl;
+               throw SALOME_Exception(LOCALIZED("Error in command arguments, missing prenthesis"));
+             } 
+           else
+             {
+               aServArg._firstArg=iarg+1;    // arg after '('
+               argState = 3;
+             }
+           break;
+         }
+       case 3: // looking for arguments
+         {
+           if (strcmp(_argv[iarg],")")==0)   // end of arguments = ')'
+             {
+               aServArg._lastArg=iarg-1;     // arg before ')'
+               MESSAGE("server : "<< Session_ServerThread::_serverTypes[aServArg._servType]);
+               for (int i=aServArg._firstArg; i<=aServArg._lastArg; i++)
+                 MESSAGE("  arg : " << _argCopy[i]);
+               _argServToLaunch.push_back(aServArg);
+               argState = 0;
+             } 
+           break;
+         }
+       default:
+         {
+           ASSERT(0);
+           break;
+         }
+       }
+    }
+  if (argState == 1)
+    throw SALOME_Exception(LOCALIZED("Error in command arguments, missing server type"));
+  if (argState == 2)
+    throw SALOME_Exception(LOCALIZED("Error in command arguments, missing parenthesis '('"));
+  if (argState == 3)
+    throw SALOME_Exception(LOCALIZED("Error in command arguments, missing parenthesis ')'"));
+}
+
+//=============================================================================
+/*! 
+ *  
+ */
+//=============================================================================
+
+void Session_ServerLauncher::ActivateAll()
+{
+  list<ServArg>::iterator itServ;
+  for (itServ = _argServToLaunch.begin(); itServ !=_argServToLaunch.end(); itServ++)
+    {
+      int argc = 2 + (*itServ)._lastArg - (*itServ)._firstArg;
+      char** argv = new char*[argc+1];
+      argv[argc]=0; // for Engines_Container_i constructor...
+      int servType = (*itServ)._servType;
+      argv[0]=strdup(Session_ServerThread::_serverTypes[servType]);
+      if (argc>1)
+       {
+         for (int i=0; i<argc-1; i++)
+           //argv[i+1] = _argCopy[(*itServ)._firstArg + i].c_str();
+           argv[i+1] = _argv[(*itServ)._firstArg + i];
+       }
+      Session_ServerThread* aServerThread
+       = new Session_ServerThread(argc, argv, _orb,_root_poa,_GUIMutex);
+      _serverThreads.push_front(aServerThread);
+
+      aServerThread->Init();
+    }
+
+  // Always launch Session Server
+
+  int argc=1;
+  char** argv = new char*[argc];
+  argv[0] = "Session";
+  Session_ServerThread* aServerThread
+    = new Session_ServerThread(argc, argv, _orb,_root_poa,_GUIMutex);
+  _serverThreads.push_front(aServerThread);
+
+  aServerThread->Init();
+}
+
+//=============================================================================
+/*! 
+ *  Destruction des classes serveur dans l'ordre inverse de creation
+ */
+//=============================================================================
+
+void Session_ServerLauncher::KillAll()
+{
+  MESSAGE("Session_ServerLauncher::KillAll()");
+  list<Session_ServerThread*>::reverse_iterator itServ;
+  for (itServ = _serverThreads.rbegin(); itServ !=_serverThreads.rend(); itServ++)
+    {
+      delete (*itServ);
+    }
+}
diff --git a/src/Session/Session_ServerLauncher.hxx b/src/Session/Session_ServerLauncher.hxx
new file mode 100644 (file)
index 0000000..45804e1
--- /dev/null
@@ -0,0 +1,87 @@
+//  SALOME Session : implementation of Session_ServerLauncher.hxx
+//
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : Session_ServerLauncher.hxx
+//  Author : Paul RASCLE, EDF
+//  Module : SALOME
+//  $Header$
+
+#ifndef _SESSION_SERVERLAUNCHER_HXX_
+#define _SESSION_SERVERLAUNCHER_HXX_
+
+#include "Session_ServerThread.hxx"
+
+#include <CORBA.h> 
+#include <list>
+#include <vector>
+#include <string>
+#include <qthread.h>
+#include <qwaitcondition.h>
+
+using namespace std;
+
+class ServArg
+  {
+  public:
+    int _servType;
+    int _firstArg;
+    int _lastArg;
+    inline ServArg(int servType=0, int firstArg=0, int lastArg=0);
+};
+
+inline ServArg::ServArg(int servType, int firstArg, int lastArg):
+  _servType(servType),_firstArg(firstArg),_lastArg(lastArg)
+{}
+
+class Session_ServerLauncher: public QThread
+{
+public:
+  Session_ServerLauncher();
+  Session_ServerLauncher(int argc,
+                        char ** argv, 
+                        CORBA::ORB_ptr orb, 
+                        PortableServer::POA_ptr poa,
+                        QMutex *GUIMutex,
+                        QWaitCondition *ServerLaunch);
+  virtual ~Session_ServerLauncher();
+  void run();
+  void KillAll();
+
+protected:
+  void CheckArgs();
+  void ActivateAll();
+
+private:
+  int _argc;
+  char ** _argv;
+  CORBA::ORB_var _orb;
+  PortableServer::POA_var _root_poa;
+  QMutex* _GUIMutex;
+  QWaitCondition *_ServerLaunch;
+  list<ServArg> _argServToLaunch;
+  vector<string> _argCopy;
+  list<Session_ServerThread*> _serverThreads;
+};
+
+#endif
+
diff --git a/src/Session/Session_ServerThread.cxx b/src/Session/Session_ServerThread.cxx
new file mode 100644 (file)
index 0000000..e5e4f05
--- /dev/null
@@ -0,0 +1,503 @@
+//  SALOME Session : implementation of Session_ServerThread.cxx
+//
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : Session_ServerThread.cxx
+//  Author : Paul RASCLE, EDF
+//  Module : SALOME
+//  $Header$
+
+// #include <SALOMEconfig.h>
+// #include CORBA_SERVER_HEADER(SALOME_Session)
+// #include CORBA_SERVER_HEADER(SALOMEDS)
+
+#include "Session_ServerThread.hxx"
+
+#include "SALOME_Container_i.hxx"
+#include "SALOMEDS_StudyManager_i.hxx"
+#include "SALOME_ModuleCatalog_impl.hxx"
+#include "RegistryService.hxx"
+#include "SALOME_Session_i.hxx"
+
+#include "Utils_ORB_INIT.hxx"
+#include "Utils_SINGLETON.hxx"
+#include "Utils_SALOME_Exception.hxx"
+#include "OpUtil.hxx"
+#include "utilities.h"
+
+#include <cstdlib>
+#include <ctime>
+
+using namespace std;
+
+const int Session_ServerThread::NB_SRV_TYP = 5;
+const char* Session_ServerThread::_serverTypes[NB_SRV_TYP] = {"Container",
+                                                             "ModuleCatalog",
+                                                             "Registry",
+                                                             "SALOMEDS",
+                                                             "Session"};
+
+//=============================================================================
+/*! 
+ * Wait until the given server is ready i.e. is name is found in namingService.
+ * Try 40 times, with 250 ms sleep between each try.
+ * If Logger is used for traces, it must be ready before this call, because
+ * SALOME_NamingService client uses SALOME traces. So, Logger readiness must be
+ * checked in Launch script before execution of WaitForServerReadiness.
+ */
+//=============================================================================
+
+void WaitForServerReadiness(SALOME_NamingService* NS, string serverName)
+{
+  long TIMESleep = 250000000; // 250 ms.
+  int NumberOfTries = 40;     // total wait = 10 s.
+  int found = 0;
+
+  timespec ts_req;
+  ts_req.tv_nsec=TIMESleep;
+  ts_req.tv_sec=0;
+  timespec ts_rem;
+  ts_rem.tv_nsec=0;
+  ts_rem.tv_sec=0;
+
+  for (int itry=0; itry < NumberOfTries; itry++)
+    {
+      try
+       {
+         if (serverName.length() == 0)
+           {
+             string curdir = NS->Current_Directory(); // to wait for naming service
+             found = 1;
+             break; // naming service found
+           }
+         else
+           {
+             CORBA::Object_ptr obj = NS->Resolve(serverName.c_str());
+             if (! CORBA::is_nil(obj))
+               {
+                 found =1;
+                 break; // server found, no more try to do
+               }
+             MESSAGE("Server "<< serverName <<" not yet ready, waiting...");
+             int a = nanosleep(&ts_req,&ts_rem); // wait before retry
+           }
+       }
+      catch( ServiceUnreachable& )
+       {
+         MESSAGE("CORBA::COMM_FAILURE: Naming Service not yet ready, waiting...");
+         int a = nanosleep(&ts_req,&ts_rem); // wait before retry
+       }
+    }
+  if (!found)
+    {
+    INFOS("Server "<< serverName <<" not found, abort...");
+    exit(EXIT_FAILURE);
+    }
+}
+
+//=============================================================================
+/*! 
+ *  default constructor not for use
+ */
+//=============================================================================
+
+Session_ServerThread::Session_ServerThread()
+{
+  ASSERT(0); // must not be called
+}
+
+//=============================================================================
+/*! 
+ *  constructor
+ */
+//=============================================================================
+
+Session_ServerThread::Session_ServerThread(int argc,
+                                          char ** argv, 
+                                          CORBA::ORB_ptr orb, 
+                                          PortableServer::POA_ptr poa,
+                                          QMutex *GUIMutex)
+{
+  MESSAGE("Session_ServerThread Constructor " << argv[0]);
+  _argc = argc;
+  _argv = argv;
+  _orb = CORBA::ORB::_duplicate(orb);
+  _root_poa = PortableServer::POA::_duplicate(poa);
+  _GUIMutex = GUIMutex;
+  _servType =-1;
+  _NS = new SALOME_NamingService(_orb); // one instance per server to limit
+                                        // multi thread coherence problems
+}
+
+//=============================================================================
+/*! 
+ *  destructor 
+ */
+//=============================================================================
+
+Session_ServerThread::~Session_ServerThread()
+{
+  MESSAGE("~Session_ServerThread "<< _argv[0]);
+}
+
+//=============================================================================
+/*! 
+ *  run the thread : activate one servant, the servant type is given by
+ *  argument _argv[0]
+ */
+//=============================================================================
+
+void Session_ServerThread::Init()
+{
+  MESSAGE("Session_ServerThread::Init "<< _argv[0]); 
+
+  for (int i=0; i<_argc; i++) SCRUTE(_argv[i]);
+  for (int i=0; i<NB_SRV_TYP; i++)
+    if (strcmp(_argv[0],_serverTypes[i])==0)
+      {
+       _servType = i;
+       MESSAGE("Server Thread type : "<<_serverTypes[i]);
+       switch (_servType)
+         {
+         case 0:  // Container
+           {
+             WaitForServerReadiness(_NS,"/Registry");
+             ActivateContainer(_argc, _argv);
+             break;
+           }
+         case 1:  // ModuleCatalog
+           {
+             WaitForServerReadiness(_NS,"/Registry");
+             ActivateModuleCatalog(_argc, _argv);
+             break;
+           }
+         case 2:  // Registry
+           {
+             WaitForServerReadiness(_NS,"");
+             ActivateRegistry(_argc, _argv);
+             break;
+           }
+         case 3:  // SALOMEDS
+           {
+             WaitForServerReadiness(_NS,"/Kernel/ModulCatalog");
+             ActivateSALOMEDS(_argc, _argv);
+             break;
+           }
+         case 4:  // Session
+           {
+             WaitForServerReadiness(_NS,"/myStudyManager");
+             string containerName = "/Containers/";
+             containerName = containerName + GetHostname();
+             containerName = containerName + "/FactoryServer";
+             WaitForServerReadiness(_NS,containerName);
+             ActivateSession(_argc, _argv);
+             break;
+           }
+         default:
+           {
+             ASSERT(0);
+             break;
+           }
+         }
+      }
+}
+
+//=============================================================================
+/*! 
+ *  
+ */
+//=============================================================================
+
+void Session_ServerThread::ActivateModuleCatalog(int argc,
+                                                char ** argv)
+{
+  try
+    {
+      INFOS("ModuleCatalog thread started");
+      // allocation on heap to allow destruction by POA
+
+      SALOME_ModuleCatalogImpl* Catalogue_i
+       = new SALOME_ModuleCatalogImpl(argc, argv);
+
+      // Tell the POA that the objects are ready to accept requests.
+
+      _root_poa->activate_object (Catalogue_i);
+
+      CORBA::Object_ptr myCata = Catalogue_i->_this();
+      _NS->Register(myCata ,"/Kernel/ModulCatalog");
+    }
+  catch(CORBA::SystemException&)
+    {
+      INFOS( "Caught CORBA::SystemException." );
+    }
+  catch(CORBA::Exception&)
+    {
+      INFOS( "Caught CORBA::Exception." );
+    }
+  catch(omniORB::fatalException& fe)
+    {
+      INFOS( "Caught omniORB::fatalException:" );
+      INFOS( "  file: " << fe.file() );
+      INFOS( "  line: " << fe.line() );
+      INFOS( "  mesg: " << fe.errmsg() );
+    }
+  catch(...) 
+    {
+      INFOS( "Caught unknown exception." );
+    }
+}
+
+//=============================================================================
+/*! 
+ *  
+ */
+//=============================================================================
+
+void Session_ServerThread::ActivateSALOMEDS(int argc,
+                                           char ** argv)
+{
+  try
+    {
+      INFOS("SALOMEDS thread started");
+      // We allocate the objects on the heap.  Since these are reference
+      // counted objects, they will be deleted by the POA when they are no
+      // longer needed.    
+
+      SALOMEDS_StudyManager_i * myStudyManager_i
+       = new  SALOMEDS_StudyManager_i(_orb);
+      
+      // Activate the objects.  This tells the POA that the objects are
+      // ready to accept requests.
+
+      PortableServer::ObjectId_var myStudyManager_iid
+       = _root_poa->activate_object(myStudyManager_i);
+      myStudyManager_i->register_name("/myStudyManager");
+    }
+  catch(CORBA::SystemException&)
+    {
+      INFOS( "Caught CORBA::SystemException." );
+    }
+  catch(CORBA::Exception&)
+    {
+      INFOS( "Caught CORBA::Exception." );
+    }
+  catch(omniORB::fatalException& fe)
+    {
+      INFOS( "Caught omniORB::fatalException:" );
+      INFOS( "  file: " << fe.file() );
+      INFOS( "  line: " << fe.line() );
+      INFOS( "  mesg: " << fe.errmsg() );
+    }
+  catch(...) 
+    {
+      INFOS( "Caught unknown exception." );
+    }
+}
+
+//=============================================================================
+/*! 
+ *  
+ */
+//=============================================================================
+
+void Session_ServerThread::ActivateRegistry(int argc,
+                                           char ** argv)
+{
+  INFOS("Registry thread started");
+  SCRUTE(argc); 
+  if( argc<3 )
+    {
+      INFOS("you must provide the Salome session name when you call SALOME_Registry_Server");
+      throw CommException("you must provide the Salome session name when you call SALOME_Registry_Server");
+    }
+  const char *ptrSessionName=0;
+
+  int k=0 ;
+  for ( k=1 ; k<argc ; k++ )
+    {
+      if( strcmp(argv[k],"--salome_session")==0 )
+       {
+         ptrSessionName=argv[k+1];
+         break;
+       }
+    }
+  ASSERT(ptrSessionName) ;
+  ASSERT(strlen( ptrSessionName )>0);
+  const char *registryName = "Registry";
+  Registry::Components_var varComponents;
+  try
+    {
+      RegistryService *ptrRegistry = SINGLETON_<RegistryService>::Instance();
+      ptrRegistry->SessionName( ptrSessionName );
+      varComponents = ptrRegistry->_this();
+      // The RegistryService must not already exist.
+           
+      try
+       {
+         CORBA::Object_var pipo = _NS->Resolve( registryName );
+         if (CORBA::is_nil(pipo) )  throw ServiceUnreachable();
+         INFOS("RegistryService servant already existing" );
+         ASSERT(0);
+       }
+      catch( const ServiceUnreachable &ex )
+       {
+       }
+      catch( const CORBA::Exception &exx )
+       {
+       }
+      string absoluteName = string("/") + registryName;
+      _NS->Register( varComponents , absoluteName.c_str() );
+      MESSAGE("On attend les requetes des clients");
+    }
+  catch( const SALOME_Exception &ex )
+    {
+      INFOS( "Communication Error : " << ex.what() );
+      ASSERT(0);
+    }
+}
+
+//=============================================================================
+/*! 
+ *  
+ */
+//=============================================================================
+
+void Session_ServerThread::ActivateContainer(int argc,
+                                            char ** argv)
+{
+  try
+    {
+      INFOS("Container thread started");
+
+      // get or create the child POA
+
+      PortableServer::POA_var factory_poa;
+      try
+       {
+         factory_poa = _root_poa->find_POA("factory_poa",0);
+         // 0 = no activation (already done if exists)
+       }
+      catch (PortableServer::POA::AdapterNonExistent&)
+       {
+         INFOS("factory_poa does not exists, create...");
+         // define policy objects     
+         PortableServer::ImplicitActivationPolicy_var implicitActivation =
+           _root_poa->create_implicit_activation_policy(
+                               PortableServer::NO_IMPLICIT_ACTIVATION);
+         // default = NO_IMPLICIT_ACTIVATION
+         PortableServer::ThreadPolicy_var threadPolicy =
+           _root_poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL);
+         // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL
+      
+         // create policy list
+         CORBA::PolicyList policyList;
+         policyList.length(2);
+         policyList[0] = PortableServer::ImplicitActivationPolicy::
+           _duplicate(implicitActivation);
+         policyList[1] = PortableServer::ThreadPolicy::
+           _duplicate(threadPolicy);
+      
+         PortableServer::POAManager_var nil_mgr
+           = PortableServer::POAManager::_nil();
+         factory_poa = _root_poa->create_POA("factory_poa",
+                                             nil_mgr,
+                                             policyList);
+         //with nil_mgr instead of pman,
+         //a new POA manager is created with the new POA
+      
+         // destroy policy objects
+         implicitActivation->destroy();
+         threadPolicy->destroy();
+
+         // obtain the factory poa manager
+         PortableServer::POAManager_var pmanfac = factory_poa->the_POAManager();
+         pmanfac->activate();
+         MESSAGE("pmanfac->activate()");
+       }
+      
+      char *containerName = "";
+      if (argc >1) 
+       {
+         containerName = argv[1];
+       }
+      
+      Engines_Container_i * myContainer 
+       = new Engines_Container_i(_orb, factory_poa, containerName , argc , argv );
+    }
+  catch(CORBA::SystemException&)
+    {
+      INFOS("Caught CORBA::SystemException.");
+    }
+  catch(PortableServer::POA::WrongPolicy&)
+    {
+      INFOS("Caught CORBA::WrongPolicyException.");
+    }
+  catch(PortableServer::POA::ServantAlreadyActive&)
+    {
+      INFOS("Caught CORBA::ServantAlreadyActiveException");
+    }
+  catch(CORBA::Exception&)
+    {
+      INFOS("Caught CORBA::Exception.");
+    }
+  catch(...)
+    {
+      INFOS("Caught unknown exception.");
+    }
+}
+
+//=============================================================================
+/*! 
+ *  
+ */
+//=============================================================================
+
+void Session_ServerThread::ActivateSession(int argc,
+                                          char ** argv)
+{
+    try
+      {
+       INFOS("Session thread started");
+       SALOME_Session_i * mySALOME_Session
+         = new SALOME_Session_i(argc, argv, _orb, _root_poa, _GUIMutex) ;
+       PortableServer::ObjectId_var mySALOME_Sessionid
+         = _root_poa->activate_object(mySALOME_Session);
+       INFOS("poa->activate_object(mySALOME_Session)");
+      
+       CORBA::Object_var obj = mySALOME_Session->_this();
+       CORBA::String_var sior(_orb->object_to_string(obj));
+      
+       mySALOME_Session->NSregister();
+         }
+    catch (CORBA::SystemException&)
+      {
+       INFOS("Caught CORBA::SystemException.");
+      }
+    catch (CORBA::Exception&)
+      {
+       INFOS("Caught CORBA::Exception.");
+      }
+    catch (...)
+      {
+       INFOS("Caught unknown exception.");
+      }  
+}
diff --git a/src/Session/Session_ServerThread.hxx b/src/Session/Session_ServerThread.hxx
new file mode 100644 (file)
index 0000000..3c12b13
--- /dev/null
@@ -0,0 +1,80 @@
+//  SALOME Session : implementation of Session_ServerThread.hxx
+//
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : Session_ServerThread.hxx
+//  Author : Paul RASCLE, EDF
+//  Module : SALOME
+//  $Header$
+
+#ifndef _SESSION_SERVERTHREAD_HXX_
+#define _SESSION_SERVERTHREAD_HXX_
+
+#include <CORBA.h> 
+#include <string>
+
+#include "SALOME_NamingService.hxx"
+#include <qthread.h>
+
+using namespace std;
+
+void WaitForServerReadiness(string serverName);
+
+
+class Session_ServerThread
+{
+public:
+  static const int NB_SRV_TYP;
+  static const char* _serverTypes[];
+
+  Session_ServerThread();
+  Session_ServerThread(int argc,
+                      char ** argv, 
+                      CORBA::ORB_ptr orb, 
+                      PortableServer::POA_ptr poa,
+                      QMutex *GUIMutex);
+  virtual ~Session_ServerThread();
+  void Init();
+protected:
+  void ActivateModuleCatalog(int argc,
+                            char ** argv);
+  void ActivateSALOMEDS(int argc,
+                       char ** argv);
+  void ActivateRegistry(int argc,
+                       char ** argv);
+  void ActivateContainer(int argc,
+                       char ** argv);
+  void ActivateSession(int argc,
+                       char ** argv);
+
+private:
+  int _argc;
+  char ** _argv;
+  int _servType;
+  CORBA::ORB_var _orb;
+  PortableServer::POA_var _root_poa;
+  QMutex* _GUIMutex;
+  SALOME_NamingService *_NS;
+};
+
+#endif
+
index ae7937d7d322dec523669b40dce4a5eacd8da80f..210c4273940dd87f805f6bcb09f2db8f3f3ec543 100644 (file)
@@ -1,3 +1,4 @@
+using namespace std;
 //  File      : SALOMEDS_Tool.cxx
 //  Created   : Mon Oct 21 16:24:34 2002
 //  Author    : Sergey RUIN
@@ -12,8 +13,8 @@
 
 #include <TCollection_AsciiString.hxx> 
 #include <stdio.h>
-#include <iostream> 
-#include <fstream>
+#include <iostream.h
+#include <fstream.h>
 #include <OSD_Path.hxx>
 #include <OSD_File.hxx>
 #include <OSD_Directory.hxx>
@@ -22,7 +23,6 @@
 #include <OSD_Protection.hxx>
 #include <OSD_SingleProtection.hxx>
 #include <OSD_FileIterator.hxx>
-using namespace std;
 
 #include <sys/time.h>
 #include <stdlib.h>
index 7e98ad7b18f263ca97ddd501adfec5a1e483795e..4b2f470890a966e09e208406670ed9221d515a00 100644 (file)
 //  Module : SALOME
 //  $Header$
 
+using namespace std;
 #include "ToolsGUI.h"
 #include "ToolsGUI_CatalogGeneratorDlg.h"
 
 #include "utilities.h"
 
 #include <stdlib.h>
-using namespace std;
 
 int ToolsGUI::runCommand(string & arg)
 { 
index 9dc3c696af30a22467045a5a16448ba2fa1c1ecd..abe1d147d33bacb0be2a48aa69e8185f77710bce 100644 (file)
@@ -27,6 +27,7 @@
 //  Module : SALOME
 //  $Header$
 
+using namespace std;
 #include "ToolsGUI_CatalogGeneratorDlg.h"
 
 #include "QAD_Application.h"
@@ -48,7 +49,6 @@
 #include <OSD_Path.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <Standard_CString.hxx>
-using namespace std;
 
 #define SPACING_SIZE             6
 #define MARGIN_SIZE             11
@@ -123,8 +123,6 @@ ToolsGUI_CatalogGeneratorDlg::ToolsGUI_CatalogGeneratorDlg( QWidget* parent, con
   myVersionEdit->setMinimumSize( myMinimumSize );
   QStringList aList = QStringList::split(QRegExp("\\s+"),tr( "INF_VERSION" ));
   myVersionEdit->setText(aList.last());
-  QDoubleValidator *validator = new QDoubleValidator(myVersionEdit);
-  myVersionEdit->setValidator(validator);
 
   myPngEdit = new QLineEdit(supplGrp , "myCompIcon" );
   myPngEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
@@ -396,7 +394,7 @@ void ToolsGUI_CatalogGeneratorDlg::onApply()
     else {
       QString command = "";
       if ( getenv("KERNEL_ROOT_DIR")  )
-       command = QString( getenv( "KERNEL_ROOT_DIR" ) ) + "/bin/salome/runIDLparser " + IDLpath + " -Wbcatalog=" + XmlFile;
+       command = QString( getenv( "KERNEL_ROOT_DIR" ) ) + "/bin/salome/runIDLparser -K " + IDLpath + " -Wbcatalog=" + XmlFile;
       else {
        QAD_MessageBox::error1( this, 
                                tr("TOOLS_ERR_ERROR"), 
index 0bb4fa7858905074a3ecdf075660478df17932bb..cca19c31a84f6b0c0b107be2b9262b5b12f9e950 100644 (file)
 //  Module : SALOME
 //  $Header$
 
+using namespace std;
 #include "utilities.h"
 #include "SALOME_TestComponent_i.hxx"
 #include <stdio.h>
-using namespace std;
+#include <cstdlib>
+#include <map>
 
 Engines_TestComponent_i::Engines_TestComponent_i(CORBA::ORB_ptr orb,
                                                 PortableServer::POA_ptr poa,
@@ -60,6 +62,32 @@ char* Engines_TestComponent_i::Coucou(CORBA::Long L)
   return CORBA::string_dup(s);
 }
 
+void Engines_TestComponent_i::Setenv()
+{
+  bool overwrite = true;
+  map<std::string,CORBA::Any>::iterator it;
+  MESSAGE("set environment associated with keys in map _fieldsDict");
+  for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
+    {
+      std::string cle((*it).first);
+      if ((*it).second.type()->kind() == CORBA::tk_string)
+       {
+         const char* value;
+         (*it).second >>= value;
+         int ret = setenv(cle.c_str(), value, overwrite);
+         MESSAGE("--- setenv: "<<cle<<" = "<< value);
+       }
+    }
+  MESSAGE("read environment associated with keys in map _fieldsDict");
+  for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++)
+    {
+      std::string cle((*it).first);
+      char* valenv= getenv(cle.c_str());
+      if (valenv)
+       MESSAGE("--- getenv: "<<cle<<" = "<< valenv);
+    }
+}
+
 extern "C"
 {
   PortableServer::ObjectId * SalomeTestComponentEngine_factory(
index b5bddc3dfd24dcd8ac6c4bcc3ae217c2e0e7882a..1f135d3d4ca4f95a40a089d2ea5d58d0e2e234d8 100644 (file)
@@ -49,6 +49,7 @@ public:
   virtual ~Engines_TestComponent_i();
 
   char* Coucou(CORBA::Long L);
+  void Setenv();
   
 private:
 
index 3ebb10ee22dd1d415df54c0efbba365c13df06ea..8fc899ec08a65002ce7626244d943cb61dc63ea1 100644 (file)
@@ -98,7 +98,7 @@ int main (int argc, char * argv[])
            }
          catch( CORBA::COMM_FAILURE& )
            {
-             MESSAGE( "Test Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" )
+             INFOS( "Test Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" )
                }
          if(!CORBA::is_nil(inc))
            {
@@ -115,11 +115,11 @@ int main (int argc, char * argv[])
                          }
                        catch(CosNaming::NamingContext::NotFound)
                          {
-                           MESSAGE( "Test Container: Logger Server wasn't found" );
+                           INFOS( "Test Container: Logger Server wasn't found" );
                          }
                        catch(...)
                          {
-                           MESSAGE( "Test Container: Unknown exception" );
+                           INFOS( "Test Container: Unknown exception" );
                          }
                        if (!CORBA::is_nil(object))
                          {
@@ -147,14 +147,41 @@ int main (int argc, char * argv[])
     
       for (int iter = 0; iter < 3 ; iter++)
        {
-         INFOS("----------------------------------------------------" << iter);   
+         MESSAGE("----------------------------------------------------" << iter);   
           string dirn = getenv("KERNEL_ROOT_DIR");
           dirn += "/lib/salome/libSalomeTestComponentEngine.so";
           obj = iGenFact->load_impl("SalomeTestComponent",dirn.c_str());
          m1 = Engines::TestComponent::_narrow(obj);
-         INFOS("recup m1");
+         MESSAGE("recup m1");
          SCRUTE(m1->instanceName());
-         INFOS("Coucou " << m1->Coucou(1L));
+
+         Engines::FieldsDict_var dico = new Engines::FieldsDict;
+         dico->length(3);
+         dico[0].key=CORBA::string_dup("key_0");
+         dico[0].value <<="value_0";
+         dico[1].key=CORBA::string_dup("key_1");
+         dico[1].value <<=(CORBA::UShort)72;
+         dico[2].key=CORBA::string_dup("key_2");
+         dico[2].value <<="value_2";
+         m1->setProperties(dico);
+
+         MESSAGE("Coucou " << m1->Coucou(1L));
+
+         m1->Setenv();
+
+         Engines::FieldsDict_var dico2 =  m1->getProperties();
+         for (CORBA::ULong i=0; i<dico2->length(); i++)
+           {
+             MESSAGE("dico2["<<i<<"].key="<<dico2[i].key);
+             MESSAGE("dico2["<<i<<"].value type ="<<dico2[i].value.type()->kind());
+             if (dico2[i].value.type()->kind() == CORBA::tk_string)
+               {
+                 const char* value;
+                 dico2[i].value >>= value;
+                 MESSAGE("dico2["<<i<<"].value="<<value);
+               }
+           }
+
          iGenFact->remove_impl(m1) ;
          //iGenFact->finalize_removal() ; // unpredictable results ...
           sleep(5);
index 989537652e3b12b12dd3c5745f3645b3fac1a781..8b73720de009de979c819988f9fbf330d93860db 100644 (file)
 //  Module : SALOME
 //  $Header$
 
+using namespace std;
 #include "utilities.h"
 #include <iostream>
 #include <unistd.h>
 #include <SALOMEconfig.h>
 #include "SALOME_NamingService.hxx"
 #include "OpUtil.hxx"
-using namespace std;
 
 int main (int argc, char * argv[])
 {
-  INFOS("It's OK");
+  MESSAGE("It's OK");
   return 0;
 }
 
index 86ebc70efd27ab429b48388e04df32a8c1eb2d4e..fbbd1527fdb6c617c4518b3783ca3bd35f261578 100644 (file)
@@ -45,7 +45,9 @@ EXPORT_HEADERS= \
        Utils_ORB_INIT.hxx \
        Utils_Identity.hxx \
        Utils_SINGLETON.hxx \
-       Utils_DESTRUCTEUR_GENERIQUE.hxx
+       Utils_DESTRUCTEUR_GENERIQUE.hxx \
+       Utils_ExceptHandlers.hxx \
+       Utils_CatchSignals.h
 
 EXPORT_PYSCRIPTS = Utils_Identity.py SALOME_utilities.py
 # Libraries targets
@@ -55,9 +57,13 @@ LIB_SRC = OpUtil.cxx Utils_Timer.cxx duplicate.cxx \
        Utils_CommException.cxx \
        Utils_SALOME_Exception.cxx \
        Utils_Identity.cxx Utils_ORB_INIT.cxx \
-       Utils_DESTRUCTEUR_GENERIQUE.cxx
+       Utils_DESTRUCTEUR_GENERIQUE.cxx \
+       Utils_ExceptHandlers.cxx \
+       Utils_CatchSignals.cxx
 
-LDFLAGS+= 
+LIB_SERVER_IDL = SALOME_Exception.idl
+
+LDFLAGS+= -lSALOMELocalTrace
 
 @CONCLUDE@
 
diff --git a/src/Utils/Utils_CatchSignals.cxx b/src/Utils/Utils_CatchSignals.cxx
new file mode 100644 (file)
index 0000000..5ffc4f9
--- /dev/null
@@ -0,0 +1,236 @@
+//  KERNEL Utils : common utils for KERNEL
+//  Copyright (C) 2003  CEA
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
+//
+//
+//
+//  File   : Utils_CatchSignals.cxx
+//  Author : Oksana Tchebanova
+//  Module : KERNEL
+//  $Header:
+
+
+#include "Utils_CatchSignals.h"
+#include "utilities.h"
+
+#include <stdexcept>
+
+#define RESERVE_SIZE 100000
+
+static void* theCallBack = NULL;
+static int *myReserve = NULL;
+using namespace std;
+//=======================================================================
+//function : Utils_CatchSignals
+//purpose  : Constructor
+//=======================================================================
+Utils_CatchSignals::Utils_CatchSignals() 
+     :myIsActivated(false)
+{
+  
+  for(int i = 0; i<SIG_MAX_NUM; i++)
+    mySigStates[i] = NULL;
+
+  theCallBack = NULL; 
+}
+
+#ifndef WNT
+
+//================================ UNIX part ==================================================
+
+
+//==============================
+typedef void (ACT_SIGIO_HANDLER)(void) ;
+
+ACT_SIGIO_HANDLER *ADR_ACT_SIGIO_HANDLER = NULL ;
+
+typedef void (* SIG_PFV) (int);
+
+#ifdef SUN
+# include <floatingpoint.h>
+#endif
+
+#ifdef SOLARIS
+# include <floatingpoint.h>
+# include <sys/machsig.h>
+# include <stdlib.h>
+# include <stdio.h>
+#endif
+
+#include <signal.h>
+#include <sys/signal.h>
+
+#ifdef LIN
+# include <stdlib.h>
+# include <stdio.h>
+#else
+# ifdef SA_SIGINFO 
+#   ifndef AIX
+# include <bits/siginfo.h>
+#    endif
+# endif
+#endif
+
+
+#ifdef IRIX
+# include <sigfpe.h>
+# include <sys/siginfo.h>
+#endif 
+
+#include <unistd.h>
+//============================================================================
+//function : Handler 
+//purpose  : univisal handler for signals
+//============================================================================
+static void Handler(const int theSig )
+{
+  if (myReserve) {
+    delete myReserve; 
+    myReserve = NULL;
+  }
+  char aMessage[1000];
+
+#if defined __GNUC__
+  #if __GNUC__ == 2
+    #define __GNUC_2__
+  #endif
+#endif
+#if defined __GNUC_2__
+  const char* message = "La fonction strsignal n'est pas supportée par gcc2.95.4";
+  sprintf (aMessage, "%d signal cautch : %s", theSig, message);
+#else
+  sprintf (aMessage, "%d signal cautch : %s", theSig, strsignal(theSig));
+#endif
+
+
+  MESSAGE("Utils_CatchSignal  Handler :: " << aMessage );
+  if(theCallBack == NULL) {
+    MESSAGE("Utils_CatchSignal  Handler : throw std::runtime_error()");
+    throw (std::runtime_error(aMessage));
+  }
+  else ((void (*)())theCallBack)();  
+}
+//=======================================================================
+//function : TryHandlerReset
+//purpose  : Redefine signal handlers. If the handler of the signal is
+//           set as SIG_IGN. That's why the shells often ignore some 
+//           signal when starting child processes. We keep it.
+//=======================================================================
+static SIG_PFV TryHandlerReset( int theSigNum )
+{
+  if (signal(theSigNum, (SIG_PFV) &Handler) == SIG_IGN)
+    {
+      signal(theSigNum, SIG_IGN);  
+      MESSAGE("signal "<<theSigNum <<" is kept as ignored");
+      return SIG_IGN;
+    } 
+  else return signal(theSigNum, (SIG_PFV) &Handler);
+}
+//=======================================================================
+//function : Activate
+//purpose  : 
+//=======================================================================
+
+void Utils_CatchSignals::Activate() 
+{  
+  if(myIsActivated) return;
+
+  if (myReserve) delete myReserve;
+  myReserve = new int[RESERVE_SIZE];
+
+    
+  mySigStates[0] = TryHandlerReset(SIGHUP);   // ...... floating point exception
+  mySigStates[1] = TryHandlerReset(SIGFPE);   // ...... floating point exception
+  
+  mySigStates[2] = TryHandlerReset(SIGINT);   // ...... interrupt
+  mySigStates[3] = TryHandlerReset(SIGQUIT);  // ...... quit
+  mySigStates[4] = TryHandlerReset(SIGBUS);   // ...... bus error
+  mySigStates[5] = TryHandlerReset(SIGILL);   // ...... illegal instruction
+  mySigStates[6] = TryHandlerReset(SIGTERM);  // ...... termination
+  mySigStates[7] = TryHandlerReset(SIGSEGV);  // ...... segmentation 
+  //mySigStates[8] = TryHandlerReset (SIGABRT); // ...... abort (ANSI).  
+  mySigStates[9] = TryHandlerReset(SIGSTKFLT);// ...... stack fault.  
+
+  myIsActivated = true;
+}
+
+//=======================================================================
+//function : Deactivate
+//purpose  : 
+//=======================================================================
+void Utils_CatchSignals::Deactivate() 
+{
+  if(!myIsActivated) return;
+
+  signal(SIGHUP, (SIG_PFV)mySigStates[0]);   // ...... hangup
+  signal(SIGFPE, (SIG_PFV)mySigStates[1]);   // ...... floating point exception
+  signal(SIGINT, (SIG_PFV)mySigStates[2]);   // ...... interrupt
+  signal(SIGQUIT,(SIG_PFV)mySigStates[3]);   // ...... quit
+  signal(SIGBUS, (SIG_PFV)mySigStates[4]);   // ...... bus error
+  signal(SIGILL, (SIG_PFV)mySigStates[5]);   // ...... illegal instruction
+  signal(SIGTERM,(SIG_PFV)mySigStates[6]);   // ...... illegal instruction
+  signal(SIGSEGV,(SIG_PFV)mySigStates[7]);   // ...... segmentation violation
+  //signal(SIGABRT,(SIG_PFV)mySigStates[8] );  // ...... abort (ANSI).     
+  signal(SIGSTKFLT,(SIG_PFV)mySigStates[9]); // ...... stack fault.  
+
+  myIsActivated = false;
+  delete myReserve;
+  myReserve = NULL;
+}
+#endif // ifndef WNT
+
+//=======================================================================
+//function : SetCallBack
+//purpose  : Sets pointer to (void (*)()
+//=======================================================================
+void Utils_CatchSignals::SetCallBack(const int theAddressHiPart, 
+                                        const int theAddressLowPart) 
+{
+  theCallBack = (void *)((theAddressHiPart << 32 ) + theAddressLowPart); 
+}
+
+//=======================================================================
+//function : UnsetCallBack
+//purpose  : 
+//=======================================================================
+void Utils_CatchSignals::UnsetCallBack()
+{
+  theCallBack = NULL;
+}
+
+//=======================================================================
+//function : Destroy
+//purpose  : 
+//=======================================================================
+void Utils_CatchSignals::Destroy() 
+{
+  if(myIsActivated) Deactivate();
+}
+
+bool Utils_CatchSignals::ReserveMemory()
+{
+  if (!myReserve) myReserve = new int [RESERVE_SIZE];
+  return true;
+}
+
+void Utils_CatchSignals::FreeReserved()
+{
+  if (myReserve) 
+    {delete myReserve ; myReserve = NULL;}
+}
diff --git a/src/Utils/Utils_CatchSignals.h b/src/Utils/Utils_CatchSignals.h
new file mode 100644 (file)
index 0000000..bf45e7b
--- /dev/null
@@ -0,0 +1,60 @@
+//  KERNEL Utils : common utils for KERNEL
+//  Copyright (C) 2003  CEA
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
+//
+//
+//
+//  File   : Utils_CatchSignals.h
+//  Author : Oksana Tchebanova
+//  Module : KERNEL
+//  $Header:
+
+#ifndef _UTILS_CATCHSIGNALS_H_
+#define _UTILS_CATCHSIGNALS_H_
+
+#include <stdio.h>
+#define SIG_MAX_NUM 11 
+
+typedef void (* SIG_PFV) (int);
+
+class Utils_CatchSignals {
+
+ public:
+  Utils_CatchSignals();
+  void Destroy() ;
+  ~Utils_CatchSignals()
+    {
+      Destroy();
+    }
+
+  static  void SetCallBack(const int theAddressHiPart,const int theAddressLowPart) ;
+  static  void UnsetCallBack() ;
+  void Activate();
+  void Deactivate() ;
+  bool ReserveMemory();
+  void FreeReserved();
+
+private: 
+
+  SIG_PFV mySigStates[SIG_MAX_NUM];
+  int  myFloatOpWord;
+  bool myIsActivated;
+};
+
+#endif
index 0dae2c1bfddc037495c75eefe113f945e455981c..d4e953d863a94632d0bfe03015068f4845ac4e2d 100644 (file)
@@ -26,6 +26,7 @@
 //  Module : SALOME
 //  $Header$
 
+using namespace std;
 # include "Utils_CommException.hxx"
 
 CommException::CommException( void ): SALOME_Exception( "CommException" )
index 8bffa2d18f4fdbbf3914c68530d8b68757d53476..d785f16d103250a0c33228c917b93dcceeff5136 100644 (file)
                 throw SALOME::SALOME_Exception(ExDescription); \
               }
 
+#include <ostream.h>
+//Dump the CORBA exception type.
+static ostream& operator<<(ostream& os, const CORBA::Exception& e)
+{
+  CORBA::Any tmp;
+  tmp<<= e;
+  CORBA::TypeCode_var tc = tmp.type();
+  const char *p = tc->name();
+  os<<"CORBA Exception was catch of the kind : ";
+  if ( *p != '\0' ) {
+    os<<p;
+  } 
+  else  { 
+    os << tc->id();
+  }
+  
+  return os;
+}
 #endif
index 650d8dfe10f68840455965f970f6ad29709cad16..50737af05e9757d8f224dcc4b9c89b75befef29e 100644 (file)
 //  Module : SALOME
 //  $Header$
 
+using namespace std;
 void Nettoyage( void ) ;
 
 # include <iostream>
 # include "utilities.h"
 # include "Utils_DESTRUCTEUR_GENERIQUE.hxx"
 # include <list>
-using namespace std;
 extern "C"
 {
 # include <stdlib.h>
index 5962e8e994729705dae67713fca8fea7747a07be..6cf3432c1a46a8a7e2fc43a7826dd11dbc2dc0f7 100644 (file)
@@ -29,6 +29,7 @@
 # if !defined( __DESTRUCTEUR_GENERIQUE__H__ )
 # define __DESTRUCTEUR_GENERIQUE__H__
 
+# include <CORBA.h>
 # include "utilities.h"
 
 /*!\class DESTRUCTEUR_GENERIQUE_
 class DESTRUCTEUR_GENERIQUE_
 {
 public :
-       virtual ~DESTRUCTEUR_GENERIQUE_() {}//!< virtual destructor
-       static const int Ajout( DESTRUCTEUR_GENERIQUE_ &objet );//!< adds a destruction object to the list of destructions
-       virtual void operator()( void )=0 ;//!< performs the destruction
+  virtual ~DESTRUCTEUR_GENERIQUE_() {}//!< virtual destructor
+  static const int Ajout( DESTRUCTEUR_GENERIQUE_ &objet );//!< adds a destruction object to the list of destructions
+  virtual void operator()( void )=0 ;//!< performs the destruction
 } ;
 
 
-
-
-
-
 /*!\class DESTRUCTEUR_DE_
  *
  * <B>Purpose</B>
@@ -87,49 +84,48 @@ public :
  *     destruction to be performed at the end of the process.
  * 
  */
-
 template <class TYPE> class DESTRUCTEUR_DE_ : public DESTRUCTEUR_GENERIQUE_
 {
 public :
+  /* Programs the destruction at the end of the process, of the object objet.
+     This method records in _PtrObjet the address of an object to be destroyed 
+     at the end of the process
+  */
+  DESTRUCTEUR_DE_(TYPE &objet):
+    _PtrObjet( &objet )
+  {
+    ASSERT(DESTRUCTEUR_GENERIQUE_::Ajout( *this ) >= 0) ;
+  }
+
+  /* Performs the destruction of the object.
+     This method really destroys the object pointed by _PtrObjet. 
+     It should be called at the end of the process (i.e. at exit).
+  */
+  virtual void operator()(void){
+    typedef PortableServer::ServantBase TServant;
+    if(_PtrObjet){
+      if(TServant* aServant = dynamic_cast<TServant*>(_PtrObjet)){
+       MESSAGE("deleting ServantBase's _PtrObjet");
+       PortableServer::POA_var aPOA = aServant->_default_POA();
+       PortableServer::ObjectId_var anObjectId = aPOA->servant_to_id(aServant);
+       aPOA->deactivate_object(anObjectId.in());
+       aServant->_remove_ref();
+      }else{
+       MESSAGE("deleting _PtrObjet");
+       TYPE* aPtr = static_cast<TYPE*>(_PtrObjet);
+       delete aPtr;
+      }
+      _PtrObjet = NULL ;
+    }
+  } 
+
+  virtual ~DESTRUCTEUR_DE_(){
+    ASSERT(!_PtrObjet) ;
+  }
 
-       inline DESTRUCTEUR_DE_( TYPE &objet ); //! programs the destruction at the end of the process, of the object objet
-       virtual void operator()( void ) ; //!< performs the destruction of the object
-       virtual ~DESTRUCTEUR_DE_() ;
 private :
-       const TYPE *_PtrObjet ;
-} ;
-
-
+  TYPE *_PtrObjet ;
+};
 
 
-
-
-/*!
-This method records in _PtrObjet the address of an object to be destroyed at the end of the process
-*/
-template <class TYPE> DESTRUCTEUR_DE_<TYPE>::DESTRUCTEUR_DE_( TYPE &objet ): _PtrObjet( &objet )
-{
-       int k = DESTRUCTEUR_GENERIQUE_::Ajout( *this ) ;        
-       ASSERT(k>=0) ;
-}
-
-template <class TYPE> DESTRUCTEUR_DE_<TYPE>::~DESTRUCTEUR_DE_()
-{
-       ASSERT(_PtrObjet==NULL) ;
-}
-
-/*!
-This method really destroys the object pointed by _PtrObjet. It should be called at the end of the process
-(i.e. at exit).
-*/
-template <class TYPE> void DESTRUCTEUR_DE_<TYPE>::operator()( void )
-{
-       if ( _PtrObjet )
-       {
-                 MESSAGE("deleting _PtrObjet") ;
-               delete (TYPE*)_PtrObjet ;
-               _PtrObjet = NULL ;
-       }
-}
-
 # endif                /* # if !defined( __SINGLETON__H__ ) */
diff --git a/src/Utils/Utils_ExceptHandlers.cxx b/src/Utils/Utils_ExceptHandlers.cxx
new file mode 100644 (file)
index 0000000..4037ebd
--- /dev/null
@@ -0,0 +1,21 @@
+// File:       Utils_ExceptHandler.cxx
+// Created:    Mon Mar 15 10:23:41 2004
+// Author:     Oksana TCHEBANOVA
+//             <ota@localhost.localdomain>
+
+
+#include <Utils_ExceptHandlers.hxx>
+#include "Utils_CorbaException.hxx"
+#include "Utils_SALOME_Exception.hxx"
+#include <SALOMEconfig.h>
+#include CORBA_SERVER_HEADER(SALOME_Exception)
+
+void SalomeException ()
+{
+  throw SALOME_Exception("Salome Exception");
+}
+
+void SALOME_SalomeException() {
+  THROW_SALOME_CORBA_EXCEPTION("INTERNAL ERROR", SALOME::INTERNAL_ERROR);
+}
+
diff --git a/src/Utils/Utils_ExceptHandlers.hxx b/src/Utils/Utils_ExceptHandlers.hxx
new file mode 100644 (file)
index 0000000..5555824
--- /dev/null
@@ -0,0 +1,75 @@
+//  KERNEL Utils : common utils for KERNEL
+//  Copyright (C) 2003  CEA
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
+//
+//
+//
+//  File   : Utils_ExceptHandlers.hxx
+//  Author : Oksana Tchebanova
+//  Module : KERNEL
+//  $Header:
+
+
+#ifndef Utils_ExceptHandlers_HeaderFile
+#define Utils_ExceptHandlers_HeaderFile
+
+#include <stdexcept>
+#include <utilities.h>
+
+typedef void (*PVF)();
+
+class Unexpect { //save / retrieve unexpected exceptions treatment
+  PVF old;
+  public :
+    Unexpect( PVF f ) 
+      { old = set_unexpected(f); }
+  ~Unexpect() { set_unexpected(old); }
+};
+
+class Terminate {//save / retrieve terminate function
+  
+  PVF old;
+  public :
+    Terminate( PVF f ) 
+      { old = set_terminate(f); }
+  ~Terminate() { set_terminate(old); }
+};
+
+#define UNEXPECT_CATCH(FuncName, ExceptionConstructor) \
+void FuncName () {\
+   throw ExceptionConstructor (); \
+}
+//Example of the usage 
+
+// void DTC_NotFound () {
+//   throw (SALOME_DataTypeCatalog::NotFound());
+// }
+// or the same :
+//
+// UNEXPECT_CATCH( DTC_NotFound , SALOME_DataTypeCatalog::NotFound)
+// in the function body :
+// ....
+// Unexpect aCatch(DTC_NotFound) // redefinition of the unexpect exceptions handler
+// ....
+
+
+//Definitions :
+extern void SalomeException();
+extern void SALOME_SalomeException();
+#endif
index c91a525e64024764bd298ef85e364a482a144d3e..5ac63924653aa1ae1119ea7942f621ce9a0466c0 100644 (file)
@@ -28,6 +28,7 @@
 
 # include "Utils_ORB_INIT.hxx" 
 # include "utilities.h" 
+using namespace std;
 
 ORB_INIT::ORB_INIT( void ): _orb( CORBA::ORB::_nil() )
 {
@@ -48,24 +49,27 @@ ORB_INIT::~ORB_INIT()
 
 CORBA::ORB_var &ORB_INIT::operator() ( int argc , char **argv ) throw( CommException )
 {
-       if ( CORBA::is_nil( _orb ) )
-       {
-               try
-               {
+  try {
+    if ( CORBA::is_nil( _orb ) )
+      {
+       try
+         {
 #if OMNIORB_VERSION >= 4
-                 const char* options[][2] = { { "giopMaxMsgSize", "104857600" }, { 0, 0 } };
-                 _orb = CORBA::ORB_init( argc , argv , "omniORB4", options) ;
+           const char* options[][2] = { { "giopMaxMsgSize", "104857600" }, { 0, 0 } };
+           _orb = CORBA::ORB_init( argc , argv , "omniORB4", options) ;
 #else
-                 _orb = CORBA::ORB_init( argc , argv ) ;
-                 //set GIOP message size equal to 50Mb for transferring brep shapes as 
-                 //sequence of bytes using C++ streams
-                 omniORB::MaxMessageSize(100*1024*1024);
+           _orb = CORBA::ORB_init( argc , argv ) ;
+           //set GIOP message size equal to 50Mb for transferring brep shapes as 
+           //sequence of bytes using C++ streams
+           omniORB::MaxMessageSize(100*1024*1024);
 #endif
-               }
-               catch( const CORBA::Exception &ex )
-               {
-                       throw CommException( "Unable to create an ORB connexion" ) ;
-               }
-       }
-       return _orb ;
+         }
+       catch( const CORBA::Exception &ex )
+         {
+           throw CommException( "Unable to create an ORB connexion" ) ;
+         }
+      }
+    return _orb ;
+  } catch ( CommException& e) {throw e;}
+  catch (...) { throw CommException( "ORB_INIT::operator() : Unknown exception was caught" ) ;}
 }
index 2bcccf0a77399dd55e2ea3bae00a408d1a91c193..1a5c822db23ffbe4e6f2c0dde60ac126352a5325 100644 (file)
@@ -47,7 +47,7 @@ private :
 
 public :
        ORB_INIT( void );
-       ~ORB_INIT();
+       virtual ~ORB_INIT();
        CORBA::ORB_var & operator() ( int argc , char **argv ) throw( CommException ) ;
 
        inline CORBA::ORB_var &orb( void );
index d91ca119f1f1522e467e32b72a324296420f091d..8f26985a1b21d4963ebf23c016adedd964b29e28 100644 (file)
@@ -26,6 +26,7 @@
 //  Module : SALOME
 //  $Header$
 
+using namespace std;
 #include <iostream>
 #include "Utils_SALOME_Exception.hxx"
 #include "utilities.h"
@@ -33,9 +34,9 @@ extern "C"
 {
 #include <math.h>
 #include <stdio.h>
+#include <string.h>
 }
-#include <string>
-using namespace std;
+
 
 const char* duplicate( const char *const str ) ;
 
@@ -47,7 +48,7 @@ SALOME_Exception::SALOME_Exception( void ): exception() , _text(0)
 
 
 
-char *makeText( const char *text, const char *fileName, const unsigned int lineNumber )
+const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber )
 {
        char *newText = 0 ;
 
@@ -88,14 +89,15 @@ SALOME_Exception::~SALOME_Exception() throw ()
 {
        if ( _text )
        {
-         delete [] _text ;
-         _text = NULL;
+               delete [] _text ;
+               _text = 0 ;
        }
+       ASSERT(_text==NULL) ;
 }
 
 
 
-SALOME_Exception::SALOME_Exception( const SALOME_Exception &ex ): _text((char*)duplicate(ex._text))
+SALOME_Exception::SALOME_Exception( const SALOME_Exception &ex ): _text(duplicate(ex._text))
 {
        ;
 }
index a60f61d1c3adf1e3c017e19899766ee637a31319..9202df72ea405899902149c0cc9bbeac613ecf7a 100644 (file)
 
 # include <exception>
 # include <iostream>
+
 using namespace std;
 
 # define LOCALIZED(message) #message , __FILE__ , __LINE__
 
-class SALOME_Exception : public std::exception
+class SALOME_Exception : public exception
 {
 
 private :
        SALOME_Exception( void );
 
 protected :
-       char* _text ;   // pointeur
+       const char* _text ;     // non constant pointer but read only char variable
 
 public :
        SALOME_Exception( const char *text, const char *fileName=0, const unsigned int lineNumber=0 );
index 82dd013f19a958fd12c4f0b1a42ff6d515c307ab..c2748f6ecb783525412bd5bfcc7ed28f170e8d46 100644 (file)
@@ -25,7 +25,7 @@
 //  Module : SALOME
 
 # include "Utils_Timer.hxx"
-# include <iostream>
+# include <stream.h>
 using namespace std;
 
 static struct timezone *tz=(struct timezone*) malloc(sizeof(struct timezone));
index f8b86b71e62814c71c318f8736524db66ddfffc3..1cf18d27a2eaae1704e0db31b77fd63af5f58982 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <string>
 #include <iostream>
+#include <cstdlib>
 #include "SALOME_Log.hxx"
 
 /* ---  INFOS is always defined (without _DEBUG_): to be used for warnings, with release version --- */
@@ -82,7 +83,7 @@
 
 #define HERE {cout<<flush ;cerr<<"- Trace "<<__FILE__<<" ["<<__LINE__<<"] : "<<flush ;}
 
-#define INTERRUPTION(code) {HERE;cerr<<"INTERRUPTION return code= "<<code<< endl;exit(code);}
+#define INTERRUPTION(code) {HERE;cerr<<"INTERRUPTION return code= "<<code<< endl;std::exit(code);}
 
 #ifndef ASSERT
 #define ASSERT(condition) \
index 3d848bd0d2a923b5d75603b634840ce4460cf2d1..44ab60836460c408ad920680518838da807906bd 100644 (file)
@@ -35,7 +35,8 @@ VPATH=.:@srcdir@:@top_srcdir@/idl
 EXPORT_HEADERS = SALOME_Transform.h \
                 SALOME_TransformFilter.h \
                 SALOME_PassThroughFilter.h \
-                SALOME_GeometryFilter.h
+                SALOME_GeometryFilter.h \
+                SALOME_ExtractUnstructuredGrid.h
 
 # Libraries targets
 
@@ -43,7 +44,8 @@ LIB = libSalomeVTKFilter.la
 LIB_SRC = SALOME_Transform.cxx \
           SALOME_TransformFilter.cxx \
          SALOME_PassThroughFilter.cxx \
-         SALOME_GeometryFilter.cxx
+         SALOME_GeometryFilter.cxx \
+         SALOME_ExtractUnstructuredGrid.cxx
 
 # Executables targets
 
@@ -51,6 +53,6 @@ BIN =
 BIN_SRC        = 
 
 CPPFLAGS+= $(VTK_INCLUDES)
-LDFLAGS+= $(VTK_LIBS)
+LDFLAGS+= $(VTK_LIBS) -lOpUtil
 
 @CONCLUDE@
diff --git a/src/VTKFilter/SALOME_ExtractUnstructuredGrid.cxx b/src/VTKFilter/SALOME_ExtractUnstructuredGrid.cxx
new file mode 100644 (file)
index 0000000..dd9b1b9
--- /dev/null
@@ -0,0 +1,348 @@
+//  VISU CONVERTOR :
+//
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+// File:    VISU_ExtractUnstructuredGrid.cxx
+// Author:  Alexey PETROV
+// Module : VISU
+
+
+#include "SALOME_ExtractUnstructuredGrid.h"
+#include "utilities.h"
+
+#include <vtkUnsignedCharArray.h>
+#include <vtkUnstructuredGrid.h>
+#include <vtkObjectFactory.h>
+#include <vtkCellArray.h>
+#include <vtkIntArray.h>
+#include <vtkIdList.h>
+#include <vtkCell.h>
+
+using namespace std;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+#if defined __GNUC__
+  #if __GNUC__ == 2
+    #define __GNUC_2__
+  #endif
+#endif
+
+vtkStandardNewMacro(SALOME_ExtractUnstructuredGrid);
+
+
+SALOME_ExtractUnstructuredGrid::SALOME_ExtractUnstructuredGrid():
+  myExtractionMode(eCells), myChangeMode(ePassAll)
+{}
+
+
+SALOME_ExtractUnstructuredGrid::~SALOME_ExtractUnstructuredGrid(){}
+
+
+void SALOME_ExtractUnstructuredGrid::RegisterCell(vtkIdType theCellId){
+  if(0 && MYDEBUG) MESSAGE("RegisterCell - theCellId = "<<theCellId);
+  myCellIds.insert(theCellId);
+  Modified();
+}
+
+
+void SALOME_ExtractUnstructuredGrid::RegisterCellsWithType(vtkIdType theCellType){
+  if(0 && MYDEBUG) MESSAGE("RegisterCellsWithType - theCellType = "<<theCellType);
+  myCellTypes.insert(theCellType);
+  Modified();
+}
+
+
+void SALOME_ExtractUnstructuredGrid::SetStoreMapping(int theStoreMapping){
+  myStoreMapping = theStoreMapping;
+  this->Modified();
+}
+
+vtkIdType SALOME_ExtractUnstructuredGrid::GetOutId(int theOutId) const{
+  if(myCellIds.empty() && myCellTypes.empty()) return theOutId;
+  if(myOut2InId.empty() || theOutId > myOut2InId.size()) return -1;
+#if defined __GNUC_2__
+  return myOut2InId[theOutId];
+#else
+  return myOut2InId.at(theOutId);
+#endif
+}
+
+vtkIdType SALOME_ExtractUnstructuredGrid::GetInId(int theInId) const{
+  if(myCellIds.empty() && myCellTypes.empty()) return theInId;
+  TMapId::const_iterator anIter = myIn2OutId.find(theInId);
+  if(anIter == myIn2OutId.end()) return -1;
+  return anIter->second;
+}
+
+
+inline void InsertCell(vtkUnstructuredGrid *theInput,
+                      vtkCellArray *theConnectivity, 
+                      vtkUnsignedCharArray* theCellTypesArray,
+                      vtkIdType theCellId, 
+                      vtkIdList *theIdList,
+                      bool theStoreMapping,
+                      vtkIdType theOutId, 
+                      SALOME_ExtractUnstructuredGrid::TVectorId& theOut2InId,
+                      SALOME_ExtractUnstructuredGrid::TMapId& theIn2OutId)
+{
+  vtkCell *aCell = theInput->GetCell(theCellId);
+  vtkIdList *aPntIds = aCell->GetPointIds();
+  vtkIdType aNbIds = aPntIds->GetNumberOfIds();
+  theIdList->SetNumberOfIds(aNbIds);
+  for(vtkIdType i = 0; i < aNbIds; i++){
+    theIdList->SetId(i,aPntIds->GetId(i));
+  }
+  theConnectivity->InsertNextCell(theIdList);
+
+  vtkIdType aCellType = aCell->GetCellType();
+  theCellTypesArray->InsertNextValue(aCellType);
+  if(theStoreMapping){
+    theOut2InId.push_back(theCellId);
+    theIn2OutId[theCellId] = theOutId;
+  }
+}
+
+inline void InsertPointCell(vtkCellArray *theConnectivity, 
+                           vtkUnsignedCharArray* theCellTypesArray,
+                           vtkIdType theCellId, 
+                           vtkIdList *theIdList,
+                           bool theStoreMapping,
+                           vtkIdType theOutId, 
+                           SALOME_ExtractUnstructuredGrid::TVectorId& theOut2InId,
+                           SALOME_ExtractUnstructuredGrid::TMapId& theIn2OutId)
+{
+  theIdList->SetId(0,theCellId);
+  theConnectivity->InsertNextCell(theIdList);
+  theCellTypesArray->InsertNextValue(VTK_VERTEX);
+  if(theStoreMapping){
+    theOut2InId.push_back(theCellId);
+    theIn2OutId[theCellId] = theOutId;
+  }
+}
+
+void SALOME_ExtractUnstructuredGrid::Execute(){
+  vtkUnstructuredGrid *anInput = this->GetInput();
+  vtkUnstructuredGrid *anOutput = this->GetOutput();
+  myOut2InId.clear();  myIn2OutId.clear();
+
+  if(MYDEBUG){
+    MESSAGE("Execute - anInput->GetNumberOfCells() = "<<anInput->GetNumberOfCells());
+    MESSAGE("Execute - myCellTypes.size() = "<<myCellTypes.size());
+    MESSAGE("Execute - myCellIds.size() = "<<myCellIds.size());
+    MESSAGE("Execute - myExtractionMode = "<<myExtractionMode);
+    MESSAGE("Execute - myChangeMode = "<<myChangeMode);
+  }
+  if(myExtractionMode == eCells){
+    if(myChangeMode == ePassAll || myCellIds.empty() && myCellTypes.empty() && myChangeMode == eRemoving){
+      if(vtkIdType aNbElems = anInput->GetNumberOfCells()){
+       if(myStoreMapping) myOut2InId.reserve(aNbElems);
+       anOutput->ShallowCopy(anInput);
+       for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+         if(myStoreMapping){
+           myOut2InId.push_back(aCellId);
+           myIn2OutId[aCellId] = anOutId;
+         }
+       }
+      }
+    }else{
+      vtkIdList *anIdList = vtkIdList::New();
+      vtkCellArray *aConnectivity = vtkCellArray::New();
+      vtkIdType aNbElems = anInput->GetNumberOfCells();
+      aConnectivity->Allocate(2*aNbElems,0);
+      vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
+      aCellTypesArray->SetNumberOfComponents(1);
+      aCellTypesArray->Allocate(aNbElems*aCellTypesArray->GetNumberOfComponents());
+      if(!myCellIds.empty() && myCellTypes.empty()){
+       if(myStoreMapping) myOut2InId.reserve(myCellIds.size());
+       if(myChangeMode == eAdding){
+         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+           if(myCellIds.find(aCellId) != myCellIds.end()){
+             InsertCell(anInput,aConnectivity,aCellTypesArray,aCellId,anIdList,
+                        myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+           }
+         }
+       }else{
+         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+           if(myCellIds.find(aCellId) == myCellIds.end()){
+             InsertCell(anInput,aConnectivity,aCellTypesArray,aCellId,anIdList,
+                        myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+           }
+         }
+       }
+      }else if(myCellIds.empty() && !myCellTypes.empty()){
+       if(myChangeMode == eAdding){
+         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+           vtkIdType aType = anInput->GetCellType(aCellId);
+           if(myCellTypes.find(aType) != myCellTypes.end()){
+             InsertCell(anInput,aConnectivity,aCellTypesArray,aCellId,anIdList,
+                        myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+           }
+         }
+       }else{
+         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+           vtkIdType aType = anInput->GetCellType(aCellId);
+           if(myCellTypes.find(aType) == myCellTypes.end()){
+             InsertCell(anInput,aConnectivity,aCellTypesArray,aCellId,anIdList,
+                        myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+           }
+         }
+       }
+      }else if(!myCellIds.empty() && !myCellTypes.empty()){
+       if(myChangeMode == eAdding){
+         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+           vtkIdType aType = anInput->GetCellType(aCellId);
+           if(myCellTypes.find(aType) != myCellTypes.end()){
+             if(myCellIds.find(aCellId) != myCellIds.end()){
+               InsertCell(anInput,aConnectivity,aCellTypesArray,aCellId,anIdList,
+                          myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+             }
+           }
+         }
+       }else{
+         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+           vtkIdType aType = anInput->GetCellType(aCellId);
+           if(myCellTypes.find(aType) == myCellTypes.end()){
+             if(myCellIds.find(aCellId) == myCellIds.end()){
+               InsertCell(anInput,aConnectivity,aCellTypesArray,aCellId,anIdList,
+                          myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+             }
+           }
+         }
+       }
+      }
+      if(aNbElems = aConnectivity->GetNumberOfCells()){
+       vtkIntArray* aCellLocationsArray = vtkIntArray::New();
+       aCellLocationsArray->SetNumberOfComponents(1);
+       aCellLocationsArray->SetNumberOfTuples(aNbElems);
+       aConnectivity->InitTraversal();
+       for(vtkIdType i = 0, *pts, npts; aConnectivity->GetNextCell(npts,pts); i++){
+         aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts));
+       }
+       anOutput->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity);
+       anOutput->SetPoints(anInput->GetPoints());
+       aCellLocationsArray->Delete();
+      }
+      aCellTypesArray->Delete();
+      aConnectivity->Delete();
+      anIdList->Delete();
+    }
+  }else{
+    vtkIdList *anIdList = vtkIdList::New();
+    anIdList->SetNumberOfIds(1);
+    vtkCellArray *aConnectivity = vtkCellArray::New();
+    vtkIdType aNbElems = anInput->GetNumberOfPoints();
+    aConnectivity->Allocate(2*aNbElems,0);
+    vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
+    aCellTypesArray->SetNumberOfComponents(1);
+    aCellTypesArray->Allocate(aNbElems*aCellTypesArray->GetNumberOfComponents());
+    if(myChangeMode == ePassAll || myCellIds.empty() && myCellTypes.empty() && myChangeMode == eRemoving){
+      if(myStoreMapping) myOut2InId.reserve(aNbElems);
+      for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+       InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
+                       myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+      }
+    }else if(!myCellIds.empty() && myCellTypes.empty()){
+      if(myStoreMapping) myOut2InId.reserve(myCellIds.size());
+      if(myChangeMode == eAdding){
+       for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+         if(myCellIds.find(aCellId) != myCellIds.end()){
+           InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
+                           myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+         }
+       }
+      }else{
+       for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+         if(myCellIds.find(aCellId) == myCellIds.end()){
+           InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
+                           myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+         }
+       }
+      }
+    }else if(myCellIds.empty() && !myCellTypes.empty()){
+      if(myChangeMode == eAdding){
+       for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+         vtkIdType aType = anInput->GetCellType(aCellId);
+         if(myCellTypes.find(aType) != myCellTypes.end()){
+           InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
+                           myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+         }
+       }
+      }else{
+       for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+         vtkIdType aType = anInput->GetCellType(aCellId);
+         if(myCellTypes.find(aType) == myCellTypes.end()){
+           InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
+                           myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+         }
+       }
+      }
+    }else if(!myCellIds.empty() && !myCellTypes.empty()){
+      if(myChangeMode == eAdding){
+       for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+         vtkIdType aType = anInput->GetCellType(aCellId);
+         if(myCellTypes.find(aType) != myCellTypes.end()){
+           if(myCellIds.find(aCellId) != myCellIds.end()){
+             InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
+                             myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+           }
+         }
+       }
+      }else{
+       for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+         vtkIdType aType = anInput->GetCellType(aCellId);
+         if(myCellTypes.find(aType) == myCellTypes.end()){
+           if(myCellIds.find(aCellId) == myCellIds.end()){
+             InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
+                             myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+           }
+         }
+       }
+      }
+    }
+    if(aNbElems = aConnectivity->GetNumberOfCells()){
+      vtkIntArray* aCellLocationsArray = vtkIntArray::New();
+      aCellLocationsArray->SetNumberOfComponents(1);
+      aCellLocationsArray->SetNumberOfTuples(aNbElems);
+      aConnectivity->InitTraversal();
+      for(vtkIdType i = 0, *pts, npts; aConnectivity->GetNextCell(npts,pts); i++){
+       aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts));
+      }
+      anOutput->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity);
+      anOutput->SetPoints(anInput->GetPoints());
+      aCellLocationsArray->Delete();
+    }
+    aCellTypesArray->Delete();
+    aConnectivity->Delete();
+    anIdList->Delete();
+  }
+  if(MYDEBUG){
+    MESSAGE("Execute - anOutput->GetNumberOfCells() = "<<anOutput->GetNumberOfCells());
+    if(myStoreMapping){
+      MESSAGE("Execute - myOut2InId.size() = "<<myOut2InId.size());
+      MESSAGE("Execute - myIn2OutId.size() = "<<myIn2OutId.size());
+    }
+  }
+}
diff --git a/src/VTKFilter/SALOME_ExtractUnstructuredGrid.h b/src/VTKFilter/SALOME_ExtractUnstructuredGrid.h
new file mode 100644 (file)
index 0000000..2e91379
--- /dev/null
@@ -0,0 +1,111 @@
+//  VISU CONVERTOR :
+//
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//  File   : SALOME_ExtractUnstructuredGrid.hxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#ifndef SALOME_ExtractUnstructuredGrid_HeaderFile
+#define SALOME_ExtractUnstructuredGrid_HeaderFile
+
+#include <vtkUnstructuredGridToUnstructuredGridFilter.h>
+
+#include <set>
+#include <map>
+#include <vector>
+
+class SALOME_ExtractUnstructuredGrid : public vtkUnstructuredGridToUnstructuredGridFilter{
+public:
+  vtkTypeMacro(SALOME_ExtractUnstructuredGrid,vtkUnstructuredGridToUnstructuredGridFilter);
+
+  // Description:
+  // Construct with all types of clipping turned off.
+  static SALOME_ExtractUnstructuredGrid *New();
+
+  enum EExtraction{ eCells, ePoints};
+  void SetModeOfExtraction(EExtraction theExtractionMode){
+    myExtractionMode = theExtractionMode; Modified();
+  }
+  EExtraction GetModeOfExtraction(){ return myExtractionMode;}
+
+  enum EChanging{ ePassAll, eAdding, eRemoving};
+  void SetModeOfChanging(EChanging theChangeMode){
+    myChangeMode = theChangeMode; 
+    Modified();
+  }
+  EChanging GetModeOfChanging(){ return myChangeMode;}
+
+  // Remove the cell from the output
+  void RegisterCell(vtkIdType theCellId);
+  int IsCellsRegistered() { return !myCellIds.empty();}
+  int ClearRegisteredCells() { 
+    myCellIds.clear();
+    Modified();
+  }
+  
+  // Remove every cells with the type from the output
+  void RegisterCellsWithType(vtkIdType theCellType);
+  int IsCellsWithTypeRegistered() { return !myCellTypes.empty();}
+  int ClearRegisteredCellsWithType() { 
+    myCellTypes.clear();
+    Modified();
+  }
+
+  // Do the filter do some real work
+  int IsChanging() { return IsCellsRegistered() || IsCellsWithTypeRegistered();}
+
+  // Do it keep the mapping between input's and output's UnstructuredGrid
+  void SetStoreMapping(int theStoreMapping);
+  int GetStoreMapping(){ return myStoreMapping;}
+
+  vtkIdType GetOutId(int theOutId) const;
+  vtkIdType GetInId(int theInId) const;
+
+  typedef std::vector<vtkIdType> TVectorId;
+  typedef std::map<vtkIdType,vtkIdType> TMapId;
+
+protected:
+  SALOME_ExtractUnstructuredGrid();
+  ~SALOME_ExtractUnstructuredGrid();
+
+  void Execute();
+
+  EExtraction myExtractionMode;
+  
+  EChanging myChangeMode;
+  typedef std::set<vtkIdType> TSetId;
+  TSetId myCellIds;
+  TSetId myCellTypes;
+
+  bool myStoreMapping;
+  TVectorId myOut2InId;
+  TMapId myIn2OutId;
+
+private:
+  SALOME_ExtractUnstructuredGrid(const SALOME_ExtractUnstructuredGrid&);  // Not implemented.
+  void operator=(const SALOME_ExtractUnstructuredGrid&);  // Not implemented.
+};
+
+
+#endif
+
+
index 1bf6904bef0e20b44c09c831d1119c685b1d0786..c618187501faee8e2cd101994f985474143b23d2 100644 (file)
@@ -24,7 +24,7 @@
 //  File   : SALOME_GeometryFilter.cxx
 //  Author : Michael ZORIN
 //  Module : SALOME
-//  $Header: /dn05/salome/CVS/SALOME_ROOT/SALOME/src/OBJECT/SALOME_GeometryFilter.cxx
+//  $Header$
 
 #include "SALOME_GeometryFilter.h"
 
 #include <vtkVoxel.h>
 #include <vtkWedge.h>
 
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+static int MYDEBUGWITHFILES = 0;
+#else
+static int MYDEBUG = 0;
+static int MYDEBUGWITHFILES = 0;
+#endif
+
+#if defined __GNUC__
+  #if __GNUC__ == 2
+    #define __GNUC_2__
+  #endif
+#endif
+
 vtkCxxRevisionMacro(SALOME_GeometryFilter, "$Revision$");
 vtkStandardNewMacro(SALOME_GeometryFilter);
 
 
-SALOME_GeometryFilter::SALOME_GeometryFilter(): myShowInside(0)
+SALOME_GeometryFilter::SALOME_GeometryFilter(): 
+  myShowInside(0),
+  myStoreMapping(0)
 {}
 
+
 SALOME_GeometryFilter::~SALOME_GeometryFilter()
 {}
 
+
 void SALOME_GeometryFilter::Execute()
 {
   vtkDataSet *input= this->GetInput();
@@ -71,6 +89,34 @@ void SALOME_GeometryFilter::Execute()
     vtkGeometryFilter::Execute();
 }
 
+
+void SALOME_GeometryFilter::SetStoreMapping(int theStoreMapping){
+  myStoreMapping = theStoreMapping;
+  this->Modified();
+}
+
+
+vtkIdType SALOME_GeometryFilter::GetObjId(int theVtkID){
+  if(myVTK2ObjIds.empty() || theVtkID > myVTK2ObjIds.size()) return -1;
+#if defined __GNUC_2__
+  return myVTK2ObjIds[theVtkID];
+#else
+  return myVTK2ObjIds.at(theVtkID);
+#endif
+}
+
+
+SALOME_GeometryFilter::TVectorId SALOME_GeometryFilter::GetVtkId(int theObjID){
+  TVectorId aVect;
+  if(myObj2VTKIds.empty() || theObjID > myObj2VTKIds.size()) return aVect;
+#if defined __GNUC_2__
+  return myObj2VTKIds[theObjID];
+#else
+  return myObj2VTKIds.at(theObjID);
+#endif
+}
+
+
 void SALOME_GeometryFilter::UnstructuredGridExecute()
 {
   vtkUnstructuredGrid *input= (vtkUnstructuredGrid *)this->GetInput();
@@ -95,7 +141,7 @@ void SALOME_GeometryFilter::UnstructuredGridExecute()
   vtkIdType newCellId;
   int faceId, *faceVerts, numFacePts;
   float *x;
-  int PixelConvert[4];
+  int PixelConvert[4], aNewPts[VTK_CELL_SIZE];
   // ghost cell stuff
   unsigned char  updateLevel = (unsigned char)(output->GetUpdateGhostLevel());
   unsigned char  *cellGhostLevels = 0;  
@@ -150,14 +196,15 @@ void SALOME_GeometryFilter::UnstructuredGridExecute()
 
   outputCD->CopyAllocate(cd,numCells,numCells/2);
 
-  Verts = vtkCellArray::New();
-  Verts->Allocate(numCells/4+1,numCells);
-  Lines = vtkCellArray::New();
-  Lines->Allocate(numCells/4+1,numCells);
-  Polys = vtkCellArray::New();
-  Polys->Allocate(numCells/4+1,numCells);
-  Strips = vtkCellArray::New();
-  Strips->Allocate(numCells/4+1,numCells);
+  output->Allocate(numCells/4+1,numCells);
+  //Verts = vtkCellArray::New();
+  //Verts->Allocate(numCells/4+1,numCells);
+  //Lines = vtkCellArray::New();
+  //Lines->Allocate(numCells/4+1,numCells);
+  //Polys = vtkCellArray::New();
+  //Polys->Allocate(numCells/4+1,numCells);
+  //Strips = vtkCellArray::New();
+  //Strips->Allocate(numCells/4+1,numCells);
   
   // Loop over the cells determining what's visible
   if (!allVisible)
@@ -195,6 +242,11 @@ void SALOME_GeometryFilter::UnstructuredGridExecute()
   // Loop over all cells now that visibility is known
   // (Have to compute visibility first for 3D cell boundarys)
   int progressInterval = numCells/20 + 1;
+  if(myStoreMapping){
+    myVTK2ObjIds.clear();  myObj2VTKIds.clear(); //apo
+    myVTK2ObjIds.reserve(numCells);
+    myObj2VTKIds.resize(numCells);
+  }
   for (cellId=0, Connectivity->InitTraversal(); 
        Connectivity->GetNextCell(npts,pts); 
        cellId++)
@@ -216,45 +268,62 @@ void SALOME_GeometryFilter::UnstructuredGridExecute()
       {
       //special code for nonlinear cells - rarely occurs, so right now it
       //is slow.
-      switch (input->GetCellType(cellId))
+      vtkIdType aCellType = input->GetCellType(cellId);
+      switch (aCellType)
         {
         case VTK_EMPTY_CELL:
           break;
 
         case VTK_VERTEX:
         case VTK_POLY_VERTEX:
-          newCellId = Verts->InsertNextCell(npts,pts);
+          newCellId = output->InsertNextCell(aCellType,npts,pts);
+         if(myStoreMapping){
+           myVTK2ObjIds.push_back(cellId); //apo
+           myObj2VTKIds[cellId].push_back(newCellId);
+         }
           outputCD->CopyData(cd,cellId,newCellId);
           break;
 
         case VTK_LINE: 
         case VTK_POLY_LINE:
-          newCellId = Lines->InsertNextCell(npts,pts);
+          newCellId = output->InsertNextCell(VTK_LINE,npts,pts);
+         if(myStoreMapping){
+           myVTK2ObjIds.push_back(cellId); //apo
+           myObj2VTKIds[cellId].push_back(newCellId);
+         }
           outputCD->CopyData(cd,cellId,newCellId);
           break;
 
         case VTK_TRIANGLE:
         case VTK_QUAD:
         case VTK_POLYGON:
-          newCellId = Polys->InsertNextCell(npts,pts);
+          newCellId = output->InsertNextCell(aCellType,npts,pts);
+         if(myStoreMapping){
+           myVTK2ObjIds.push_back(cellId); //apo
+           myObj2VTKIds[cellId].push_back(newCellId);
+         }
           outputCD->CopyData(cd,cellId,newCellId);
           break;
 
         case VTK_TRIANGLE_STRIP:
-          newCellId = Strips->InsertNextCell(npts,pts);
+          newCellId = output->InsertNextCell(aCellType,npts,pts);
+         if(myStoreMapping){
+           myVTK2ObjIds.push_back(cellId); //apo
+           myObj2VTKIds[cellId].push_back(newCellId);
+         }
           outputCD->CopyData(cd,cellId,newCellId);
           break;
 
         case VTK_PIXEL:
-          newCellId = Polys->InsertNextCell(npts);
-          for ( i=0; i < npts; i++)
-            {
-            Polys->InsertCellPoint(pts[PixelConvert[i]]);
-            }
-          outputCD->CopyData(cd,cellId,newCellId);
+          newCellId = output->InsertNextCell(aCellType,npts,pts);
+         if(myStoreMapping){
+           myVTK2ObjIds.push_back(cellId); //apo
+           myObj2VTKIds[cellId].push_back(newCellId);
+         }
+         outputCD->CopyData(cd,cellId,newCellId);
           break;
 
-        case VTK_TETRA:
+        case VTK_TETRA: {
           for (faceId = 0; faceId < 4; faceId++)
             {
             faceIds->Reset();
@@ -263,21 +332,26 @@ void SALOME_GeometryFilter::UnstructuredGridExecute()
             faceIds->InsertNextId(pts[faceVerts[1]]);
             faceIds->InsertNextId(pts[faceVerts[2]]);
             numFacePts = 3;
+           aCellType = VTK_TRIANGLE;
             input->GetCellNeighbors(cellId, faceIds, cellIds);
             if ( cellIds->GetNumberOfIds() <= 0 || myShowInside == 1 ||
                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
               {
-              newCellId = Polys->InsertNextCell(numFacePts);
               for ( i=0; i < numFacePts; i++)
                 {
-                Polys->InsertCellPoint(pts[faceVerts[i]]);
+                aNewPts[i] = pts[faceVerts[i]];
                 }
+              newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+             if(myStoreMapping){
+               myVTK2ObjIds.push_back(cellId); //apo
+               myObj2VTKIds[cellId].push_back(newCellId);
+             }
               outputCD->CopyData(cd,cellId,newCellId);
               }
             }
           break;
-
-        case VTK_VOXEL:
+       }
+        case VTK_VOXEL: {
           for (faceId = 0; faceId < 6; faceId++)
             {
             faceIds->Reset();
@@ -287,21 +361,26 @@ void SALOME_GeometryFilter::UnstructuredGridExecute()
             faceIds->InsertNextId(pts[faceVerts[2]]);
             faceIds->InsertNextId(pts[faceVerts[3]]);
             numFacePts = 4;
+           aCellType = VTK_QUAD;
             input->GetCellNeighbors(cellId, faceIds, cellIds);
             if ( cellIds->GetNumberOfIds() <= 0 || myShowInside == 1 || 
                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
               {
-              newCellId = Polys->InsertNextCell(numFacePts);
               for ( i=0; i < numFacePts; i++)
                 {
-                Polys->InsertCellPoint(pts[faceVerts[PixelConvert[i]]]);
+                aNewPts[i] = pts[faceVerts[PixelConvert[i]]];
                 }
+              newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+             if(myStoreMapping){
+               myVTK2ObjIds.push_back(cellId); //apo
+               myObj2VTKIds[cellId].push_back(newCellId);
+             }
               outputCD->CopyData(cd,cellId,newCellId);
               }
             }
           break;
-
-        case VTK_HEXAHEDRON:
+       }
+        case VTK_HEXAHEDRON: {
           for (faceId = 0; faceId < 6; faceId++)
             {
             faceIds->Reset();
@@ -311,21 +390,26 @@ void SALOME_GeometryFilter::UnstructuredGridExecute()
             faceIds->InsertNextId(pts[faceVerts[2]]);
             faceIds->InsertNextId(pts[faceVerts[3]]);
             numFacePts = 4;
+           aCellType = VTK_QUAD;
             input->GetCellNeighbors(cellId, faceIds, cellIds);
             if ( cellIds->GetNumberOfIds() <= 0 || myShowInside == 1 ||
                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
               {
-              newCellId = Polys->InsertNextCell(numFacePts);
               for ( i=0; i < numFacePts; i++)
                 {
-                Polys->InsertCellPoint(pts[faceVerts[i]]);
+                aNewPts[i] = pts[faceVerts[i]];
                 }
+              newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+             if(myStoreMapping){
+               myVTK2ObjIds.push_back(cellId); //apo
+               myObj2VTKIds[cellId].push_back(newCellId);
+             }
               outputCD->CopyData(cd,cellId,newCellId);
               }
             }
           break;
-
-        case VTK_WEDGE:
+       }
+        case VTK_WEDGE: {
           for (faceId = 0; faceId < 5; faceId++)
             {
             faceIds->Reset();
@@ -334,26 +418,32 @@ void SALOME_GeometryFilter::UnstructuredGridExecute()
             faceIds->InsertNextId(pts[faceVerts[1]]);
             faceIds->InsertNextId(pts[faceVerts[2]]);
             numFacePts = 3;
+           aCellType = VTK_TRIANGLE;
             if (faceVerts[3] >= 0)
               {
               faceIds->InsertNextId(pts[faceVerts[3]]);
               numFacePts = 4;
+             aCellType = VTK_QUAD;
               }
             input->GetCellNeighbors(cellId, faceIds, cellIds);
             if ( cellIds->GetNumberOfIds() <= 0 || myShowInside == 1 || 
                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
               {
-              newCellId = Polys->InsertNextCell(numFacePts);
               for ( i=0; i < numFacePts; i++)
                 {
-                Polys->InsertCellPoint(pts[faceVerts[i]]);
+                aNewPts[i] = pts[faceVerts[i]];
                 }
+              newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+             if(myStoreMapping){
+               myVTK2ObjIds.push_back(cellId); //apo
+               myObj2VTKIds[cellId].push_back(newCellId);
+             }
               outputCD->CopyData(cd,cellId,newCellId);
               }
             }
           break;
-
-        case VTK_PYRAMID:
+       }
+        case VTK_PYRAMID: {
           for (faceId = 0; faceId < 5; faceId++)
             {
             faceIds->Reset();
@@ -362,104 +452,70 @@ void SALOME_GeometryFilter::UnstructuredGridExecute()
             faceIds->InsertNextId(pts[faceVerts[1]]);
             faceIds->InsertNextId(pts[faceVerts[2]]);
             numFacePts = 3;
+           aCellType = VTK_TRIANGLE;
             if (faceVerts[3] >= 0)
               {
               faceIds->InsertNextId(pts[faceVerts[3]]);
               numFacePts = 4;
+             aCellType = VTK_QUAD;
               }
             input->GetCellNeighbors(cellId, faceIds, cellIds);
             if ( cellIds->GetNumberOfIds() <= 0 || myShowInside == 1 || 
                  (!allVisible && !cellVis[cellIds->GetId(0)]) )
               {
-              newCellId = Polys->InsertNextCell(numFacePts);
               for ( i=0; i < numFacePts; i++)
                 {
-                Polys->InsertCellPoint(pts[faceVerts[i]]);
+                aNewPts[i] = pts[faceVerts[i]];
                 }
+              newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts);
+             if(myStoreMapping){
+               myVTK2ObjIds.push_back(cellId); //apo
+               myObj2VTKIds[cellId].push_back(newCellId);
+             }
               outputCD->CopyData(cd,cellId,newCellId);
               }
             }
           break;
-
+       }
         //Quadratic cells
         case VTK_QUADRATIC_EDGE:
         case VTK_QUADRATIC_TRIANGLE:
         case VTK_QUADRATIC_QUAD:
         case VTK_QUADRATIC_TETRA:
         case VTK_QUADRATIC_HEXAHEDRON:
-          {
-          vtkGenericCell *cell = vtkGenericCell::New();
-          input->GetCell(cellId,cell);
-          vtkIdList *pts = vtkIdList::New();  
-          vtkPoints *coords = vtkPoints::New();
-          vtkIdList *cellIds = vtkIdList::New();
-          vtkIdType newCellId;
-
-          if ( cell->GetCellDimension() == 1 )
-            {
-            cell->Triangulate(0,pts,coords);
-            for (i=0; i < pts->GetNumberOfIds(); i+=2)
-              {
-              newCellId = Lines->InsertNextCell(2);
-              Lines->InsertCellPoint(pts->GetId(i));
-              Lines->InsertCellPoint(pts->GetId(i+1));
-              outputCD->CopyData(cd,cellId,newCellId);
-              }
-            }
-          else if ( cell->GetCellDimension() == 2 )
-            {
-            cell->Triangulate(0,pts,coords);
-            for (i=0; i < pts->GetNumberOfIds(); i+=3)
-              {
-              newCellId = Lines->InsertNextCell(2);
-              Polys->InsertCellPoint(pts->GetId(i));
-              Polys->InsertCellPoint(pts->GetId(i+1));
-              Polys->InsertCellPoint(pts->GetId(i+2));
-              outputCD->CopyData(cd,cellId,newCellId);
-              }
-            } 
-          else //3D nonlinear cell
-            {
-            vtkCell *face;
-            for (int j=0; j < cell->GetNumberOfFaces(); j++)
-              {
-              face = cell->GetFace(j);
-              input->GetCellNeighbors(cellId, face->PointIds, cellIds);
-              if ( cellIds->GetNumberOfIds() <= 0)
-                {
-                face->Triangulate(0,pts,coords);
-                for (i=0; i < pts->GetNumberOfIds(); i+=3)
-                  {
-                  newCellId = Lines->InsertNextCell(2);
-                  Polys->InsertCellPoint(pts->GetId(i));
-                  Polys->InsertCellPoint(pts->GetId(i+1));
-                  Polys->InsertCellPoint(pts->GetId(i+2));
-                  outputCD->CopyData(cd,cellId,newCellId);
-                  }
-                }
-              }
-            } //3d cell
-          cellIds->Delete();
-          coords->Delete();
-          pts->Delete();
-          cell->Delete();
-          }
+          
           break; //done with quadratic cells
           
         } //switch
       } //if visible
     } //for all cells
   
+  if(MYDEBUG && myStoreMapping){
+    for(int i = 0, iEnd = myVTK2ObjIds.size(); i < iEnd; i++){
+      cout<<myVTK2ObjIds[i]<<", ";
+    }
+    cout<<"\n";
+    for(int i = 0, iEnd = myObj2VTKIds.size(); i < iEnd; i++){
+      TVectorId& aVectorId = myObj2VTKIds[i];
+      cout<<aVectorId.size()<<": ";
+      for(int j = 0, jEnd = aVectorId.size(); j < jEnd; j++){
+       cout<<aVectorId[j]<<", ";
+      }
+      cout<<"\n";
+    }
+    cout<<"\n";
+  }
+
   // Update ourselves and release memory
   //
-  output->SetVerts(Verts);
-  Verts->Delete();
-  output->SetLines(Lines);
-  Lines->Delete();
-  output->SetPolys(Polys);
-  Polys->Delete();
-  output->SetStrips(Strips);
-  Strips->Delete();
+  //output->SetVerts(Verts);
+  //Verts->Delete();
+  //output->SetLines(Lines);
+  //Lines->Delete();
+  //output->SetPolys(Polys);
+  //Polys->Delete();
+  //output->SetStrips(Strips);
+  //Strips->Delete();
   
   output->Squeeze();
 
index f6edf6b78f5421e0a62fc125cd09cc4eb965dc9c..bce9d27d76ba13678a5bf124119a741f2c9efcd3 100644 (file)
 //  File   : SALOME_GeometryFilter.h
 //  Author : Michael ZORIN
 //  Module : SALOME
-//  $Header: /dn05/salome/CVS/SALOME_ROOT/SALOME/src/OBJECT/SALOME_GeometryFilter.h
+//  $Header$
 
 
 #ifndef __SALOME_GeometryFilter_h
 #define __SALOME_GeometryFilter_h
 
 #include <vtkGeometryFilter.h>
+#include <vector>
 
 class SALOME_GeometryFilter : public vtkGeometryFilter 
 {
@@ -40,6 +41,13 @@ public:
   void SetInside(int theShowInside);
   int GetInside();
 
+  void SetStoreMapping(int theStoreMapping);
+  int GetStoreMapping(){ return myStoreMapping;}
+
+  typedef std::vector<vtkIdType> TVectorId;
+  virtual vtkIdType GetObjId(int theVtkID);
+  virtual TVectorId GetVtkId(int theObjID);
+
 protected:
   SALOME_GeometryFilter();
   ~SALOME_GeometryFilter();
@@ -48,7 +56,12 @@ protected:
   void UnstructuredGridExecute();
     
 private:
-  int myShowInside;      
+  int myShowInside;   
+
+  int myStoreMapping;   
+  TVectorId myVTK2ObjIds;
+  typedef std::vector<TVectorId> TVecVectorId;
+  TVecVectorId myObj2VTKIds;
 };
 
 #endif
index 3557b625984babe34f9df957b0cff027704e0596..f1ee7c5e90de3cd617ef21a2c48bd1f3d54ca6d7 100644 (file)
 
 
 #include "SALOME_PassThroughFilter.h"
-#include "SALOME_GeometryFilter.h"
 
+#include <vtkCellData.h>
+#include <vtkDataSet.h>
 #include <vtkObjectFactory.h>
-#include <vtkPointSet.h>
 #include <vtkPointData.h>
-#include <vtkCellData.h>
-#include <vtkPoints.h>
-#include <vtkMatrix4x4.h>
-
-using namespace std;
 
+vtkCxxRevisionMacro(SALOME_PassThroughFilter, "$Revision$");
 vtkStandardNewMacro(SALOME_PassThroughFilter);
 
-SALOME_PassThroughFilter::SALOME_PassThroughFilter(){
-  this->vtkProcessObject::SetNthInput(0, NULL);
-  myGeomFilter = SALOME_GeometryFilter::New();
-}
-
-SALOME_PassThroughFilter::~SALOME_PassThroughFilter(){
-  myGeomFilter->Delete();
-}
-
-void SALOME_PassThroughFilter::Execute(){
+void SALOME_PassThroughFilter::Execute()
+{
   vtkDataSet *input = static_cast<vtkDataSet*>(this->GetInput());
   vtkDataSet *output = static_cast<vtkDataSet*>(this->GetOutput());
+
+  // This has to be here because it initialized all field datas.
   output->CopyStructure( input );
+  
+  // Pass all. (data object's field data is passed by the
+  // superclass after this method)
   output->GetPointData()->PassData( input->GetPointData() );
   output->GetCellData()->PassData( input->GetCellData() );
-}
-
 
-void SALOME_PassThroughFilter::SetInput(vtkDataSet *input){
-  myGeomFilter->SetInput(input);
-  vtkDataSet *oldInput = this->GetInput();
-  if(oldInput != NULL)
-    if(input == NULL || oldInput->GetDataObjectType() != input->GetDataObjectType()){
-      vtkWarningMacro("Changing input type.  Deleting output");
-      this->SetOutput(NULL);
-    }
-  if (input != NULL && this->vtkSource::GetOutput(0) == NULL){
-    this->vtkSource::SetNthOutput(0, input->NewInstance());
-    this->Outputs[0]->ReleaseData();
-    this->Outputs[0]->Delete();
-  }
-  this->vtkProcessObject::SetNthInput(0, input);
 }
-vtkPolyData *SALOME_PassThroughFilter::GetPolyDataOutput() {
-  vtkDataSet *ds = this->GetOutput();
-  if(!ds) return NULL;
-  if(ds->GetDataObjectType() == VTK_POLY_DATA) return (vtkPolyData *)ds;
-  myGeomFilter->SetInput(this->GetOutput());
-  return myGeomFilter->GetOutput();
-}
-
 
-void SALOME_PassThroughFilter::SetInside(int theShowInside){
-  myGeomFilter->SetInside(theShowInside);
-  Modified();
-}
-int SALOME_PassThroughFilter::GetInside(){
-  return myGeomFilter->GetInside();
+void SALOME_PassThroughFilter::PrintSelf(ostream& os, vtkIndent indent)
+{
+  this->Superclass::PrintSelf(os,indent);
 }
index 51e1124e59edb463f7f814a66e9971f739615f32..bc625a8d337222dbf57a58f1a90ebaebff7bf135 100644 (file)
 
 #include <vtkDataSetToDataSetFilter.h>
 
-class SALOME_GeometryFilter;
-
-class SALOME_PassThroughFilter : public vtkDataSetToDataSetFilter{
- public:
-  vtkTypeMacro(SALOME_PassThroughFilter,vtkDataSetToDataSetFilter);
+class SALOME_PassThroughFilter : public vtkDataSetToDataSetFilter
+{
+public:
+  vtkTypeRevisionMacro(SALOME_PassThroughFilter,vtkDataSetToDataSetFilter);
+  void PrintSelf(ostream& os, vtkIndent indent);
+
+  // Description:
+  // Create a new SALOME_PassThroughFilter.
   static SALOME_PassThroughFilter *New();
 
-  void SetInput(vtkDataSet *input);
-  vtkPolyData *GetPolyDataOutput();
 
-  void SetInside(int theShowInside);
-  int GetInside();
+protected:
 
- protected:
-  SALOME_PassThroughFilter();
-  virtual ~SALOME_PassThroughFilter();
-  void Execute();
+  SALOME_PassThroughFilter() {};
+  virtual ~SALOME_PassThroughFilter() {};
 
-  SALOME_GeometryFilter* myGeomFilter;
+  void Execute();
 
- private:
+private:
   SALOME_PassThroughFilter(const SALOME_PassThroughFilter&);  // Not implemented.
   void operator=(const SALOME_PassThroughFilter&);  // Not implemented.
 };
index de14593873f0d32cf6776c1e7ee7cb6e02c003b1..a7b1b2bc50812beaa2021615a7ddb479c81349ff 100644 (file)
@@ -48,24 +48,22 @@ void SALOME_TransformFilter::Execute(){
   vtkPointData *pd=input->GetPointData(), *outPD=output->GetPointData();
   vtkCellData *cd=input->GetCellData(), *outCD=output->GetCellData();
   output->CopyStructure( input );
-  int anIdentity = 0;
-  if(SALOME_Transform* aTransform = dynamic_cast<SALOME_Transform*>(this->Transform))
-    anIdentity = aTransform->IsIdentity();
-  if(!anIdentity && this->Transform != NULL){
+  if(Transform){
+    bool anIsIdentity = true;
+    if(SALOME_Transform* aTransform = dynamic_cast<SALOME_Transform*>(Transform))
+      anIsIdentity = aTransform->IsIdentity();
     inPts = input->GetPoints();
-    if(!inPts){
-      vtkErrorMacro(<<"No input data");
-      return;
+    if(!anIsIdentity && inPts){
+      numPts = inPts->GetNumberOfPoints();
+      numCells = input->GetNumberOfCells();
+      newPts = vtkPoints::New();
+      newPts->Allocate(numPts);
+      this->UpdateProgress(.2);
+      this->Transform->TransformPoints(inPts,newPts);
+      this->UpdateProgress(.8);
+      output->SetPoints(newPts);
+      newPts->Delete();
     }
-    numPts = inPts->GetNumberOfPoints();
-    numCells = input->GetNumberOfCells();
-    newPts = vtkPoints::New();
-    newPts->Allocate(numPts);
-    this->UpdateProgress(.2);
-    this->Transform->TransformPoints(inPts,newPts);
-    this->UpdateProgress(.8);
-    output->SetPoints(newPts);
-    newPts->Delete();
   }
   outPD->PassData(pd);
   outCD->PassData(cd);
index 0733c58b9711ee4cb49890f8b6832c9a956f1c00..40ca16b5263b8511c49a399bc835877aee86bfc7 100644 (file)
@@ -38,7 +38,8 @@ VPATH=.:@srcdir@:$(top_builddir)/inc:$(top_builddir)/idl
 EXPORT_HEADERS=  VTKViewer_RenderWindow.h \
                 VTKViewer_ViewFrame.h \
                 VTKViewer_RenderWindowInteractor.h \
-                VTKViewer_InteractorStyleSALOME.h 
+                VTKViewer_InteractorStyleSALOME.h \
+                VTKViewer_Filter.h
                     
 # Libraries targets
 LIB = libVTKViewer.la
@@ -49,7 +50,10 @@ LIB_SRC= VTKViewer.cxx \
         VTKViewer_InteractorStyleSALOME.cxx \
         VTKViewer_Trihedron.cxx \
         VTKViewer_VectorText.cxx \
-        VTKViewer_Utilities.cxx
+        VTKViewer_RectPicker.cxx \
+        VTKViewer_CellRectPicker.cxx \
+        VTKViewer_Utilities.cxx \
+        VTKViewer_Filter.cxx
 
 LIB_MOC = \
         VTKViewer.h \
index a0c60854ebb1f9c76b2a409542bbc7f7446ffc13..79602806011070ee8c61eb1a38915424347ec11e 100644 (file)
@@ -26,9 +26,9 @@
 //  Module : SALOME
 //  $Header$
 
+using namespace std;
 #include "VTKViewer.h"
 #include "VTKViewer_ViewFrame.h"
-using namespace std;
 
 QAD_ViewFrame* VTKViewer::createView(QAD_RightFrame* parent)
 {
diff --git a/src/VTKViewer/VTKViewer_CellRectPicker.cxx b/src/VTKViewer/VTKViewer_CellRectPicker.cxx
new file mode 100644 (file)
index 0000000..6e05537
--- /dev/null
@@ -0,0 +1,433 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : VTKViewer_CellRectPicker.cxx
+//  Author : Natalia KOPNOVA
+//  Module : SALOME
+
+#include <VTKViewer_CellRectPicker.h>
+
+#include "vtkGenericCell.h"
+#include "vtkAssemblyNode.h"
+#include "vtkAssemblyPath.h"
+#include "vtkObjectFactory.h"
+#include "vtkImageData.h"
+#include "vtkMapper.h"
+#include "vtkVolumeMapper.h"
+#include "vtkMath.h"
+#include "vtkLine.h"
+#include "vtkQuad.h"
+#include "vtkPoints.h"
+#include "vtkPlane.h"
+#include "vtkActor.h"
+
+using namespace std;
+
+//----------------------------------------------------------------------------
+vtkStandardNewMacro(VTKViewer_CellRectPicker);
+//----------------------------------------------------------------------------
+
+VTKViewer_CellRectPicker::VTKViewer_CellRectPicker()
+{
+  this->Cell = vtkGenericCell::New();
+  this->Quad1 = vtkQuad::New();
+  this->Quad2 = vtkQuad::New();
+}
+
+VTKViewer_CellRectPicker::~VTKViewer_CellRectPicker()
+{
+  this->Cell->Delete();
+  this->Quad1->Delete();
+  this->Quad2->Delete();
+}
+
+void VTKViewer_CellRectPicker::Initialize()
+{
+  ActorData.clear();
+  this->VTKViewer_RectPicker::Initialize();
+}
+
+//----------------------------------------------------------------------------
+float VTKViewer_CellRectPicker::IntersectWithHex(float p1[4][4], float p2[4][4], float tol, 
+                                                vtkAssemblyPath *path, vtkProp3D *prop3D, 
+                                                vtkAbstractMapper3D *m)
+{
+  vtkDataSet *input;
+  vtkMapper *mapper;
+  vtkVolumeMapper *volumeMapper;
+
+  // Get the underlying dataset
+  if ( (mapper=vtkMapper::SafeDownCast(m)) != NULL ) {
+    input = mapper->GetInput();
+  }
+  else if ( (volumeMapper=vtkVolumeMapper::SafeDownCast(m)) != NULL ) {
+    input = volumeMapper->GetInput();
+  }
+  else {
+    return VTK_LARGE_FLOAT;
+  }
+
+  vtkIdType numCells;
+  if ( (numCells = input->GetNumberOfCells()) < 1 ) {
+    return 2.0;
+  }
+
+  int i, k, subId;
+  float bounds[6], center[3], cp1[3], cp2[3];
+  float pcoord[3], weight[4], dist;
+  float t1[2], t2[2], x[3], t;
+
+  for (k = 0; k < 4; k++) {
+    this->Quad1->PointIds->SetId(k, k);
+    this->Quad1->Points->SetPoint(k, p1[k]);
+    this->Quad2->PointIds->SetId(k, k);
+    this->Quad2->Points->SetPoint(k, p2[k]);
+  }
+
+  /*
+  cout << "---> Selection area:"   << endl;
+  for (k = 0; k < 4; k++)
+    cout << "\t(" << p1[k][0] << ", " << p1[k][1] << ", " << p1[k][2] << ")";
+  cout << endl;
+  for (k = 0; k < 4; k++)
+    cout << "\t(" << p2[k][0] << ", " << p2[k][1] << ", " << p2[k][2] << ")";
+  cout << endl;
+  */
+
+  vtkIdType cellId;
+  VTKViewer_CellData cellData;
+  VTKViewer_CellDataSet dataList;
+
+  char inside; int n; float *point;
+  float tMin = VTK_LARGE_FLOAT, xMin[3];
+  for (cellId = 0; cellId < numCells; cellId++) {
+    input->GetCell(cellId, this->Cell);
+
+    this->Cell->GetBounds(bounds);
+    for (i = 0; i < 3; i++)
+      center[i] = (bounds[2*i]+bounds[2*i+1])/2;
+
+    /*
+    if (!VTKViewer_RectPicker::PointInside(center, p1, p2, 0.01))
+      continue;
+    */
+
+    inside = 1;
+    n = this->Cell->Points->GetNumberOfPoints();
+    //cout << "---> Info cell " << cellId << " (" << n << "): " << endl;
+    for (k = 0; k < n; k++) {
+      point = this->Cell->Points->GetPoint(k);
+      //cout << "  P (" << point[0] << ", " << point[1] << ", " << point[2] << ")";
+      if (!VTKViewer_RectPicker::PointInside(point, p1, p2)) {
+       inside = 0; break;
+      }
+    }
+    //cout << endl;
+    if (!inside) continue;
+
+    //cout << "---> Inside cell " << cellId << endl;
+
+    this->Quad1->EvaluatePosition(center, 0, subId, pcoord, dist, weight);
+    t1[0] = pcoord[0]; t1[1] = pcoord[1];
+    this->Quad2->EvaluatePosition(center, 0, subId, pcoord, dist, weight);
+    t2[0] = pcoord[0]; t2[1] = pcoord[1];
+
+    pcoord[0] = (t1[0]+t2[0])/2; pcoord[1] = (t1[1]+t2[1])/2; pcoord[2] = 0;
+
+    this->Quad1->EvaluateLocation(subId, pcoord, cp1, weight);
+    this->Quad2->EvaluateLocation(subId, pcoord, cp2, weight);
+
+    if (this->Cell->IntersectWithLine(cp1, cp2, tol, t, x, pcoord, subId)) {
+      cellData.cellId = cellId;
+      cellData.subId = subId;
+      cellData.depth = t;
+      for (i = 0; i < 3; i++) {
+       cellData.p1[i] = cp1[i];
+       cellData.p2[i] = cp2[i];
+      }
+      /*
+      cout << "---> Include cell " << cellId << ", depth = " << t   << endl;
+      cout << "     P1 = (" << cp1[0] << ", " << cp1[1] << ", " << cp1[2] << ")"  << endl;
+      cout << "     P2 = (" << cp2[0] << ", " << cp2[1] << ", " << cp2[2] << ")"  << endl;
+      */
+      IncludeCell(input, cellData, dataList);
+      if (t < tMin) {
+       tMin = t;
+       for (i = 0; i < 3; i++)
+         xMin[i] = x[i];
+      }
+    }
+  }
+
+  if (!dataList.empty()) {
+    // compare against other actors
+    IncludeActor(prop3D, input, dataList);
+    if (tMin < this->GlobalTMin) {
+      this->MarkPicked(path, prop3D, m, tMin, xMin);
+    }
+  }
+
+  return tMin;
+}
+
+
+//----------------------------------------------------------------------------
+void VTKViewer_CellRectPicker::IncludeCell(vtkDataSet* input, 
+                                          VTKViewer_CellData cellData, 
+                                          VTKViewer_CellDataSet& dataList)
+{
+  vtkGenericCell* cell1 = vtkGenericCell::New();
+  vtkGenericCell* cell2 = vtkGenericCell::New();
+  vtkCell* sub1 = 0;
+  vtkCell* sub2 = 0;
+  
+  input->GetCell(cellData.cellId, cell1);
+  if (cell1->GetNumberOfFaces() > 0)
+    sub1 = cell1->GetFace(cellData.subId);
+
+  int i, result;
+  float p1[3], p2[3], dir[3];
+  char add = 1;
+
+  VTKViewer_CellData curData;
+  VTKViewer_CellDataSet::iterator it;
+  for (it = dataList.begin(); it != dataList.end();) {
+    curData = *it;
+    for (i = 0; i < 3; i++) {
+      p1[i] = (cellData.p1[i]+curData.p1[i])/2;
+      p2[i] = (cellData.p2[i]+curData.p2[i])/2;
+      dir[i] = p2[i] - p1[i];
+    }
+
+    input->GetCell(curData.cellId, cell2);
+    sub2 = 0;
+    if (cell2->GetNumberOfFaces() > 0)
+      sub2 = cell2->GetFace(curData.subId);
+
+    if (sub1) {
+      if (sub2)
+       result = IntersectCells(sub1, cellData.depth, 
+                               sub2, curData.depth, dir);
+      else 
+       result = IntersectCells(sub1, cellData.depth, 
+                               cell2, curData.depth, dir);
+    }
+    else {
+      if (sub2)
+       result = IntersectCells(cell1, cellData.depth, 
+                               sub2, curData.depth, dir);
+      else
+       result = IntersectCells(cell1, cellData.depth, 
+                               cell2, curData.depth, dir);
+    }
+    /*
+    cout << "     Direction = (" << dir[0] << ", " << dir[1] << ", " << dir[2] << ")";
+    cout << "     depth = " << cellData.depth << ", " << curData.depth << ", " << result << endl;
+    */
+    if (result > 0) {
+      if (result == 1) {
+       it = dataList.erase(it);
+       continue;
+      } 
+      else {
+       add = 0;
+       break;
+      }
+    }
+    ++it;
+  }
+  if (add) {
+    //cout << "     add "   << endl;
+    dataList.push_back(cellData);
+  }
+
+  cell1->Delete();
+  cell2->Delete();
+}
+
+//----------------------------------------------------------------------------
+void VTKViewer_CellRectPicker::IncludeActor(vtkProp3D* prop, 
+                                           vtkDataSet* input, 
+                                           VTKViewer_CellDataSet& dataList)
+{
+  vtkGenericCell* cell1 = vtkGenericCell::New();
+  vtkGenericCell* cell2 = vtkGenericCell::New();
+
+  int i, result;
+  float p1[3], p2[3], dir[3];
+  char removed;
+
+  VTKViewer_CellDataSet actorData;
+  VTKViewer_CellData curData, cellData;
+  VTKViewer_CellDataSet::iterator it1, it2;
+  VTKViewer_ActorDataMap::iterator it;
+
+  for (it1 = dataList.begin(); it1 != dataList.end();) {
+    cellData = *it1;
+    input->GetCell(cellData.cellId, cell1);
+    removed = 0;
+
+    for (it = ActorData.begin(); it != ActorData.end(); ++it) {
+      vtkActor* actor = (*it).first;
+      actorData = (*it).second;
+
+      for (it2 = actorData.begin(); it2 != actorData.end();) {
+       curData = *it2;
+       for (i = 0; i < 3; i++) {
+         p1[i] = (cellData.p1[i]+curData.p1[i])/2;
+         p2[i] = (cellData.p2[i]+curData.p2[i])/2;
+         dir[i] = p2[i] - p1[i];
+       }
+
+       input->GetCell(curData.cellId, cell2);
+       result = IntersectCells(cell1, cellData.depth,
+                               cell2, curData.depth, dir);
+       if (result > 0) {
+         if (result == 1) {
+           it2 = actorData.erase(it2);
+           continue;
+         }
+         else {
+           removed = 1;
+           it1 = dataList.erase(it1);
+           break;
+         }
+         break;
+       }
+       ++it2;
+      }
+      if (removed) break;
+    } // by actors
+    if (!removed) ++it1;
+  }
+
+  if (!dataList.empty()) {
+    vtkActor* actor;
+    if ((actor = vtkActor::SafeDownCast(prop)) != NULL)
+      ActorData[actor] = dataList;
+  }
+
+  cell1->Delete();
+  cell2->Delete();
+}
+
+int VTKViewer_CellRectPicker::IntersectCells(vtkCell* c1, float d1, vtkCell* c2, float d2, float dir[3])
+{
+  int i, k;
+  float *orig, cp[3], bounds[6];
+  vtkCell* cell = 0;
+  vtkCell* tcell = 0;
+
+  // define the central point and cell for projection
+  if (fabs(d1-d2) < 1.e-7) return 0;
+
+  if (d1 < d2) {
+    orig = c1->Points->GetPoint(0);
+    cell = c1;
+    tcell = c2;
+    c2->GetBounds(bounds);
+    for (i = 0; i < 3; i++)
+      cp[i] = (bounds[2*i] + bounds[2*i+1])/2;
+  }
+  else if (d1 > d2) {
+    orig = c2->Points->GetPoint(0);
+    cell = c2;
+    tcell = c1;
+    c1->GetBounds(bounds);
+    for (i = 0; i < 3; i++)
+      cp[i] = (bounds[2*i] + bounds[2*i+1])/2;
+  }
+
+  float proj[3];
+  vtkPlane::GeneralizedProjectPoint(cp, orig, dir, proj);
+
+  float *p, pp[3];
+  vtkPoints* aPoints = vtkPoints::New();
+  for (k = 0; k < cell->Points->GetNumberOfPoints(); k++) {
+    p = cell->Points->GetPoint(k);
+    vtkPlane::GeneralizedProjectPoint(p, orig, dir, pp);
+    aPoints->InsertNextPoint(pp[0], pp[1], pp[2]);
+  }
+
+  int result = 0;
+  if (PointInside(proj, aPoints)) {
+    result = (d1<d2) ? 1 : 2;
+  }
+
+  if (result == 0) {
+    // test for boundary cells
+    for (k = 0; k < tcell->Points->GetNumberOfPoints(); k++) {
+      p = tcell->Points->GetPoint(k);
+      vtkPlane::GeneralizedProjectPoint(p, orig, dir, pp);
+      if (PointInside(pp, aPoints)) {
+       result = 1; break;
+      }
+    }
+    if (result && d2<d1) result = 2;
+  }
+
+  aPoints->Delete();
+  return result;
+}
+
+char VTKViewer_CellRectPicker::PointInside(float point[3], vtkPoints* list)
+{
+  int i, k, l, n;
+  float x[3], *a1, *a2, v[3], p[3], q[3];
+
+  n = list->GetNumberOfPoints();
+  if (n < 3) return 0;
+
+  for (k = 0; k < n; k++) {
+    l = k+1; if (l == n) l = 0;
+    a1 = list->GetPoint(k);
+    a2 = list->GetPoint(l);
+
+    // compute vectors
+    for (i = 0; i < 3; i++) {
+      x[i] = point[i] - a1[i];
+      v[i] = a2[i]-a1[i];
+    }
+
+    // check if point coincides with vertex
+    if (x[0]*x[0] + x[1]*x[1] + x[2]*x[2] < 1.e-7) return 0;
+
+    // compute normal
+    vtkMath::Cross(x, v, p);
+
+    // check if point lays on edge
+    if (p[0]*p[0] + p[1]*p[1] + p[2]*p[2] < 1.e-7) return 0;
+
+    // check if normals are in the same direction
+    if (k > 0) {
+      if (vtkMath::Dot(p, q) < 0.0) return 0;
+    }
+
+    // remember normal direction
+    for (i = 0; i < 3; i++) {
+      q[i] = p[i];
+    }
+  }
+
+  return 1;
+}
diff --git a/src/VTKViewer/VTKViewer_CellRectPicker.h b/src/VTKViewer/VTKViewer_CellRectPicker.h
new file mode 100644 (file)
index 0000000..76b0b8c
--- /dev/null
@@ -0,0 +1,94 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : VTKViewer_CellRectPicker.h
+//  Author : Natalia KOPNOVA
+//  Module : SALOME
+
+#ifndef __VTKViewer_CellRectPicker_h
+#define __VTKViewer_CellRectPicker_h
+
+#include "VTKViewer_RectPicker.h"
+#include <map>
+#include <vector>
+
+typedef struct {
+  vtkIdType cellId;
+  int subId;
+  float depth;
+  float p1[3];
+  float p2[3];
+} VTKViewer_CellData;
+
+typedef std::vector<VTKViewer_CellData> VTKViewer_CellDataSet;
+typedef std::map<vtkActor*, VTKViewer_CellDataSet> VTKViewer_ActorDataMap;
+
+class vtkCell;
+class vtkGenericCell;
+class vtkQuad;
+
+class VTK_EXPORT VTKViewer_CellRectPicker : public VTKViewer_RectPicker
+{
+public:
+  static VTKViewer_CellRectPicker *New();
+  vtkTypeMacro(VTKViewer_CellRectPicker,VTKViewer_RectPicker);
+
+  // Description:
+  // Get the id of the picked cells. 
+  // (Notes: use GetActors() to get picked actors list)
+  VTKViewer_CellDataSet GetCellData(vtkActor* actor) 
+    { return this->ActorData[actor]; }
+
+  // Description:
+  // The method returns a non-zero value if the cells intersect each other 
+  // in the direction dir[3]. Returned value is 1 if the first cell is top of 
+  // the second one according to direction and 2 if the second cell is top.
+  static int IntersectCells(vtkCell* c1, float d1, vtkCell* c2, float d2, float dir[3]);
+
+  // Description:
+  // The method returns a non-zero value if the point is inlide point data set
+  static char PointInside(float point[3], vtkPoints* list);
+
+protected:
+  VTKViewer_CellRectPicker();
+  ~VTKViewer_CellRectPicker();
+
+  VTKViewer_ActorDataMap ActorData;
+
+  virtual float IntersectWithHex(float p1[4][4], float p2[4][4], float tol, 
+                          vtkAssemblyPath *path, vtkProp3D *p, 
+                          vtkAbstractMapper3D *m);
+  void Initialize();
+
+  void IncludeCell(vtkDataSet* input, VTKViewer_CellData cellData, VTKViewer_CellDataSet& dalaList);
+  void IncludeActor(vtkProp3D* prop, vtkDataSet* input, VTKViewer_CellDataSet& dataList);
+
+private:
+  vtkGenericCell *Cell;
+  vtkQuad* Quad1;
+  vtkQuad* Quad2;
+};
+
+#endif
+
+
diff --git a/src/VTKViewer/VTKViewer_Filter.cxx b/src/VTKViewer/VTKViewer_Filter.cxx
new file mode 100755 (executable)
index 0000000..8c09a46
--- /dev/null
@@ -0,0 +1,57 @@
+//  VTKViewer_Filter : Filter for VTK viewer\r
+//\r
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,\r
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS \r
+// \r
+//  This library is free software; you can redistribute it and/or \r
+//  modify it under the terms of the GNU Lesser General Public \r
+//  License as published by the Free Software Foundation; either \r
+//  version 2.1 of the License. \r
+// \r
+//  This library is distributed in the hope that it will be useful, \r
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of \r
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU \r
+//  Lesser General Public License for more details. \r
+// \r
+//  You should have received a copy of the GNU Lesser General Public \r
+//  License along with this library; if not, write to the Free Software \r
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA \r
+// \r
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org \r
+//\r
+//\r
+//\r
+//  File   : VTKViewer_Filter.cxx\r
+//  Author : Sergey LITONIN\r
+//  Module : SALOME\r
+\r
+#include "VTKViewer_Filter.h"\r
+\r
+IMPLEMENT_STANDARD_HANDLE(VTKViewer_Filter, MMgt_TShared)\r
+IMPLEMENT_STANDARD_RTTIEXT(VTKViewer_Filter, MMgt_TShared)\r
+\r
+/*\r
+  Class       : VTKViewer_Filter\r
+  Description : Base class of filters of for VTK viewer. Method IsValid \r
+                should be redefined in derived classes\r
+*/\r
+\r
+VTKViewer_Filter::VTKViewer_Filter()\r
+{\r
+  myActor = 0;\r
+}\r
+\r
+VTKViewer_Filter::~VTKViewer_Filter()\r
+{\r
+}\r
+\r
+bool VTKViewer_Filter::IsValid( SALOME_Actor* theActor, const int theCellId )\r
+{\r
+  SetActor( theActor );\r
+  return IsValid( theCellId );\r
+}\r
+\r
+void VTKViewer_Filter::SetActor( SALOME_Actor* theActor )\r
+{\r
+  myActor = theActor;\r
+}\r
diff --git a/src/VTKViewer/VTKViewer_Filter.h b/src/VTKViewer/VTKViewer_Filter.h
new file mode 100755 (executable)
index 0000000..d9d9831
--- /dev/null
@@ -0,0 +1,64 @@
+//  SMESHGUI_Filter : Filter for VTK viewer\r
+//\r
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,\r
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS \r
+// \r
+//  This library is free software; you can redistribute it and/or \r
+//  modify it under the terms of the GNU Lesser General Public \r
+//  License as published by the Free Software Foundation; either \r
+//  version 2.1 of the License. \r
+// \r
+//  This library is distributed in the hope that it will be useful, \r
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of \r
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU \r
+//  Lesser General Public License for more details. \r
+// \r
+//  You should have received a copy of the GNU Lesser General Public \r
+//  License along with this library; if not, write to the Free Software \r
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA \r
+// \r
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org \r
+//\r
+//\r
+//\r
+//  File   : VTKViewer_Filter.h\r
+//  Author : Sergey LITONIN\r
+//  Module : SALOME\r
+\r
+#ifndef VTKViewer_Filter_HeaderFile\r
+#define VTKViewer_Filter_HeaderFile\r
+\r
+#include <MMgt_TShared.hxx>\r
+#include <Standard_DefineHandle.hxx>\r
+\r
+class SALOME_Actor;\r
+\r
+DEFINE_STANDARD_HANDLE(VTKViewer_Filter, MMgt_TShared)\r
+\r
+/*\r
+  Class       : VTKViewer_Filter\r
+  Description : Base class of filters of for VTK viewer. Method IsValid \r
+                should be redefined in derived classes\r
+*/\r
+\r
+class VTKViewer_Filter : public MMgt_TShared\r
+{\r
+\r
+public:\r
+                              VTKViewer_Filter();\r
+  virtual                     ~VTKViewer_Filter();\r
+\r
+  bool                        IsValid( SALOME_Actor*, const int theCellId );\r
+  virtual bool                IsValid( const int theCellId ) const = 0;\r
+\r
+  virtual void                SetActor( SALOME_Actor* );\r
+\r
+protected:\r
+\r
+  SALOME_Actor*               myActor;\r
+\r
+public:  \r
+  DEFINE_STANDARD_RTTI(VTKViewer_Filter)\r
+};\r
+\r
+#endif\r
index 329e055acb0f731bdfec14ebdcfef92737bc510b..d7cbfb5c2fa642648a2390e7fedc3391014dd028 100644 (file)
 //  $Header$
 
 #include "VTKViewer_InteractorStyleSALOME.h"
+#include "VTKViewer_RenderWindowInteractor.h"
 #include "VTKViewer_RenderWindow.h"
 #include "VTKViewer_Utilities.h"
 #include "VTKViewer_Trihedron.h"
+#include "VTKViewer_RectPicker.h"
+#include "VTKViewer_CellRectPicker.h"
 
 #include "QAD_Config.h"
 #include "QAD_Application.h"
@@ -52,7 +55,6 @@
 #include <vtkPolyDataMapper.h>
 #include <vtkDataSetCollection.h>
 #include <vtkImageData.h>
-#include <vtkFollower.h>
 
 #include <qapplication.h>
 //VRV: porting on Qt 3.0.5
@@ -60,6 +62,9 @@
 #include <qpainter.h>
 #endif
 //VRV: porting on Qt 3.0.5
+#include <algorithm>
+
+#include "utilities.h"
 
 using namespace std;
 
@@ -78,6 +83,12 @@ VTKViewer_InteractorStyleSALOME::VTKViewer_InteractorStyleSALOME()
   this->RadianToDegree = 180.0 / vtkMath::Pi();
   this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
   loadCursors();
+
+  myPActor = vtkActor::New();
+  myPActor->PickableOff();
+  myPActor->GetProperty()->SetColor(0,1,1);
+  myPActor->GetProperty()->SetLineWidth(5);
+  myPActor->GetProperty()->SetPointSize(5);
 }
 
 //----------------------------------------------------------------------------
@@ -85,6 +96,15 @@ VTKViewer_InteractorStyleSALOME::~VTKViewer_InteractorStyleSALOME()
 {
 }
 
+//----------------------------------------------------------------------------
+void VTKViewer_InteractorStyleSALOME::setPreselectionProp(const double& theRed, const double& theGreen, 
+                                                         const double& theBlue, const int& theWidth) 
+{
+  myPActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
+  myPActor->GetProperty()->SetLineWidth(theWidth);
+  myPActor->GetProperty()->SetPointSize(theWidth);
+}
+
 //----------------------------------------------------------------------------
 void VTKViewer_InteractorStyleSALOME::setTriedron(VTKViewer_Trihedron* theTrihedron){
   m_Trihedron = theTrihedron;
@@ -515,8 +535,7 @@ void VTKViewer_InteractorStyleSALOME::startFitArea()
 void  VTKViewer_InteractorStyleSALOME::ViewFitAll() {
   int aTriedronWasVisible = false;
   if(m_Trihedron){
-    aTriedronWasVisible = 
-      m_Trihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
+    aTriedronWasVisible = m_Trihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
     if(aTriedronWasVisible) m_Trihedron->VisibilityOff();
   }
 
@@ -529,6 +548,7 @@ void  VTKViewer_InteractorStyleSALOME::ViewFitAll() {
   }
   if(aTriedronWasVisible) m_Trihedron->VisibilityOn();
   else m_Trihedron->VisibilityOff();
+  ::ResetCameraClippingRange(CurrentRenderer);
 }
 
 
@@ -723,7 +743,7 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation()
   // VSV: LOD actor activisation
   //  rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate());
 
-  int aSelectionMode = aSel->SelectionMode();
+  Selection_Mode aSelectionMode = aSel->SelectionMode();
   bool aSelActiveCompOnly = aSel->IsSelectActiveCompOnly();
 
   switch (State) {
@@ -767,16 +787,17 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation()
           if ( rwi->GetPicker()->IsA("vtkCellPicker") ) {
             vtkCellPicker* picker;
             if ( (picker = vtkCellPicker::SafeDownCast(rwi->GetPicker())) ) {
-             MESSAGE ( " CellId : " << picker->GetCellId() );
-              if ( picker->GetCellId() >= 0 ) {
+             int aVtkId = picker->GetCellId();
+             // INFOS ( " CellId : " << aVtkId );
+              if ( aVtkId >= 0 ) {
                 vtkActor* ac = picker->GetActor();
                 if ( ac->IsA("SALOME_Actor") ) {
                   SALOME_Actor* SActor = SALOME_Actor::SafeDownCast( ac );
-                  MESSAGE ( " NAME Actor : " << SActor->getName() );
+                  INFOS ( " NAME Actor : " << SActor->getName() << ", CellId : " << aVtkId );
 
-                  //Cell selection //////////////////////////////////// NB
-                  if ( aSelectionMode == 3 ) {
-                    if ( SActor->hasIO() ) {
+                  //Cell selection /////////////////////////////// NB
+                  if ( aSelectionMode == CellSelection ) {
+                    if ( SActor->hasIO() && isValid( SActor, aVtkId, aSelectionMode ) ) {
                       Handle(SALOME_InteractiveObject) IO = SActor->getIO();
                       // Look in the current selection
                       SALOME_ListIteratorOfListIO It(aSel->StoredIObjects());
@@ -789,91 +810,135 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation()
                           break;
                        }
                       }
-                     if(IsSelected) {
-                        // This IO is already in the selection
-                       //if(shift) {
-                         bool add = aSel->AddOrRemoveIndex( IO, picker->GetCellId(), myShiftState, false );
-                         //Sel->RemoveIObject(IO);
-                       //}
+
+                     int anObjId = SActor->GetObjId(aVtkId);
+                     std::vector<int> aVtkList;
+                     if (anObjId != -1) {
+                       aVtkList = SActor->GetVtkId(anObjId);
+                     }
+
+                     if (IsSelected) {
+                       // This IO is already in the selection
+                       if (aVtkList.size() > 0)
+                         bool add = aSel->AddOrRemoveIndex( IO, aVtkList, myShiftState, false );
+                       else
+                         bool add = aSel->AddOrRemoveIndex( IO, aVtkId, myShiftState, false );
                      } else {
-                       if(!myShiftState) {
-                         this->HighlightProp( NULL );
-                         aSel->ClearIObjects();
-                        }
-                        bool add = aSel->AddOrRemoveIndex( IO, picker->GetCellId(), myShiftState, false );
-                        aSel->AddIObject( IO, false );
+                       if (!myShiftState) {
+                         this->HighlightProp( NULL );
+                         aSel->ClearIObjects();
+                       }
+                       if (aVtkList.size() > 0)
+                         bool add = aSel->AddOrRemoveIndex( IO, aVtkList, myShiftState, false );
+                       else
+                         bool add = aSel->AddOrRemoveIndex( IO, aVtkId, myShiftState, false );
+                       aSel->AddIObject( IO, false );
                      }
                     }
                  }
-                  //Edge selection ////////////////////////// NB
-                  else if ( aSelectionMode == 2 ) {
-                    if(SActor->hasIO()){
-                      Handle(SALOME_InteractiveObject) IO = SActor->getIO();
-                      float pickPosition[3],pcoords[3],closestPoint[3],weights[3],dist1=1000000.0,dist2=0;
-                      int subId,edgeId=-10,pickedID,result;
-                      pickedID = picker->GetCellId();
-                      picker->GetPickPosition(pickPosition);
-                     if (vtkDataSet* UGrid = SActor->GetMapper()->GetInput()){
-                       if (vtkCell* pickedCell = UGrid->GetCell(pickedID)){
-                         edgeId = -1;
-                         for (int i = 0, iEnd = pickedCell->GetNumberOfEdges(); i < iEnd; i++){
-                           vtkCell* edge = pickedCell->GetEdge(i);
-                           if(vtkLine* line = vtkLine::SafeDownCast(edge)){
-                             result = line->EvaluatePosition(pickPosition,closestPoint,subId,pcoords,dist2,weights);
-                             if (dist2 < dist1) {
-                               dist1  = dist2;
-                               edgeId = i;
+                 //Edge, Face, Volume and EdgeOfCell selection ////////////////////////// NB
+                  else if ( aSelectionMode == EdgeSelection || 
+                           aSelectionMode == FaceSelection || 
+                           aSelectionMode == VolumeSelection  ||
+                           aSelectionMode == EdgeOfCellSelection ) {
+                   if ( SActor->hasIO() && isValid( SActor, aVtkId, aSelectionMode ) ) {
+                     Handle(SALOME_InteractiveObject) IO = SActor->getIO();
+                     if (vtkDataSet* UGrid = SActor->GetMapper()->GetInput()) {
+                       if (vtkCell* pickedCell = UGrid->GetCell(aVtkId)) {
+                         bool result = false;
+                         int edgeId = -1;
+                         int anObjId = SActor->GetObjId(aVtkId);
+                         std::vector<int> aVtkList;
+                         if (anObjId > -1)
+                           aVtkList = SActor->GetVtkId(anObjId);
+
+                         if (aSelectionMode == EdgeSelection) {
+                           if ( SActor->GetObjDimension( anObjId ) == 1 )
+                             result = true;
+                         }
+                         else if ( aSelectionMode == FaceSelection ) {
+                           if ( SActor->GetObjDimension( anObjId ) == 2 )
+                             result = true;
+                         }
+                         else if (aSelectionMode == VolumeSelection) {
+                           if ( SActor->GetObjDimension( anObjId ) == 3 )
+                             result = true;
+                         }
+                         else {
+                           float pickPosition[3];
+                           picker->GetPickPosition(pickPosition);
+                           float distMin = 1000000.0, dist = 0;
+                           for (int i = 0, iEnd = pickedCell->GetNumberOfEdges(); i < iEnd; i++){
+                             vtkCell* edge = pickedCell->GetEdge(i);
+                             if (vtkLine* line = vtkLine::SafeDownCast(edge)){
+                               float pcoords[3],closestPoint[3],weights[3];
+                               int subId;
+                               line->EvaluatePosition(pickPosition,closestPoint,subId,pcoords,dist,weights);
+                               if (dist < distMin) {
+                                 distMin = dist;
+                                 edgeId = i;
+                               }
                              }
                            }
+                           if (edgeId != -1 || pickedCell->GetCellDimension() == 1) 
+                             result = true;
+                           INFOS("edgeID transformed = "<<edgeId);
                          }
-                         MESSAGE("edgeID transformed = "<<edgeId);
-                         // Look in the current selection
-                         SALOME_ListIteratorOfListIO It(aSel->StoredIObjects());
-                         Standard_Boolean IsSelected = false;
-                         for(;It.More();It.Next()) {
-                           Handle(SALOME_InteractiveObject) IOS = It.Value();
-                           if(IO->isSame(IOS)) {
-                             IO = IOS; //Added by SRN, fix SAL1307
-                             IsSelected = true;
-                             break;
+                         if (result) {
+                           // Look in the current selection
+                           SALOME_ListIteratorOfListIO It(aSel->StoredIObjects());
+                           Standard_Boolean IsSelected = false;
+                           for(;It.More();It.Next()) {
+                             Handle(SALOME_InteractiveObject) IOS = It.Value();
+                             if(IO->isSame(IOS)) {
+                               IO = IOS; //Added by SRN, fix SAL1307
+                               IsSelected = true;
+                               break;
+                             }
                            }
+                           if (!myShiftState) {
+                             this->HighlightProp( NULL );
+                             aSel->ClearIObjects();
+                           }
+                           // aSel->SetSelectionMode(EdgeSelection, true);
+                           if (aVtkList.size() > 0)
+                             aSel->AddOrRemoveIndex( IO, aVtkList, true, false);
+                           else
+                             aSel->AddOrRemoveIndex( IO, aVtkId, true, false);
+                           if (edgeId >= 0)
+                             aSel->AddOrRemoveIndex( IO, -edgeId-1, true, true );
+                           aSel->AddIObject( IO, false );
                          }
-                         if(!myShiftState) {
-                           this->HighlightProp( NULL );
-                           aSel->ClearIObjects();
-                         }
-                         aSel->SetSelectionMode(2, true);
-                         bool add = aSel->AddOrRemoveIndex( IO, pickedID, true, false);
-                         if(edgeId >= 0)
-                           add = aSel->AddOrRemoveIndex( IO, -edgeId-1, true, true );
-                         aSel->AddIObject( IO, false );
                        }
                      }
                    }
                  }
-                } else {
-                  this->HighlightProp( NULL );
-                  aSel->ClearIObjects();
                 }
+             } else {
+               this->HighlightProp( NULL );
+               aSel->ClearIObjects();
               }
             }
           } else if ( rwi->GetPicker()->IsA("vtkPointPicker") ) {
             vtkPointPicker* picker;
             if ( (picker = vtkPointPicker::SafeDownCast(rwi->GetPicker())) ) {
-              MESSAGE ( " PointId : " << picker->GetPointId() );
+              INFOS ( " PointId : " << picker->GetPointId() );
               if ( picker->GetPointId() >= 0 ) {
                 vtkActor* ac = picker->GetActor();
                 if ( ac->IsA("SALOME_Actor") ) {
                   SALOME_Actor* SActor = SALOME_Actor::SafeDownCast( ac );
-                  MESSAGE ( " NAME Actor : " << SActor->getName() );
+                  INFOS ( " NAME Actor : " << SActor->getName() );
                   if ( SActor->hasIO() ) {
                     Handle(SALOME_InteractiveObject) IO = SActor->getIO();
-/*                 if (IO.IsNull()) 
+                   /*
+                   if (IO.IsNull()) 
                      break;
                    if (aSelActiveCompOnly && 
-                       strcmp(aActiveComponent->ComponentDataType(), IO->getComponentDataType()) != 0) {
+                       strcmp(aActiveComponent->ComponentDataType(), 
+                              IO->getComponentDataType()) != 0) {
                      break;
-                   }*/
+                   }
+                   */
                     // Look in the current selection
                     SALOME_ListIteratorOfListIO It(aSel->StoredIObjects());
                     Standard_Boolean IsSelected = false;
@@ -949,13 +1014,13 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation()
                 }
               }
             }
-           rwi->EndPickCallback();
           }
+         rwi->EndPickCallback();
         } else {
           //processing rectangle selection
-         SALOMEDS::SComponent_var aActiveComponent = SALOMEDS::SComponent::
-           _narrow(aActiveStudy->getStudyDocument()->
-                   FindObject(QAD_Application::getDesktop()->getActiveComponent()));
+         SALOMEDS::SComponent_var aActiveComponent = 
+           SALOMEDS::SComponent::_narrow(aActiveStudy->getStudyDocument()->
+                                         FindObject(QAD_Application::getDesktop()->getActiveComponent()));
          if(aSelActiveCompOnly && aActiveComponent->_is_nil()) return;
          rwi->StartPickCallback();
 
@@ -966,7 +1031,7 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation()
          }
 
          // Compute bounds
-         vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
+         //      vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
          QRect rect(myPoint, myOtherPoint);
          rect = rect.normalize();
          int w, h, x, y;
@@ -978,7 +1043,7 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation()
          y2 = h - rect.bottom() - 1;
 
          switch (aSelectionMode) {
-         case 1: // Nodes selection
+         case NodeSelection: // Nodes selection
            {
              if (! rwi->GetPicker()->IsA("vtkPointPicker") ) break;
              vtkPointPicker* aPointPicker = vtkPointPicker::SafeDownCast(rwi->GetPicker());
@@ -999,7 +1064,8 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation()
                      if (IO.IsNull()) 
                        continue;
                      if (aSelActiveCompOnly && 
-                              strcmp(aActiveComponent->ComponentDataType(), IO->getComponentDataType()) != 0) {
+                         strcmp(aActiveComponent->ComponentDataType(), 
+                                IO->getComponentDataType()) != 0) {
                        continue;
                      }
 
@@ -1015,6 +1081,8 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation()
                        continue;
                      }
                      if (aDataSet) {
+
+                       std::vector<int> anIndices;
                        for (int i=0; i < aDataSet->GetNumberOfPoints(); i++) {
                          float* aPoint;
                          aPoint = aDataSet->GetPoint(i);
@@ -1024,12 +1092,21 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation()
                                                  aPoint[1],
                                                  aPoint[2], aDisp);
                            aPointPicker->Pick(aDisp[0], aDisp[1], 0.0, CurrentRenderer);
-                           if ( aPointPicker->GetPointId() >= 0) { // && (!aSel->IsIndexSelected(IO, aPointPicker->GetPointId()))) {
-                             aSel->AddOrRemoveIndex(IO, aPointPicker->GetPointId(), true, false);
-                             aSel->AddIObject(IO, false);
-                           }
+
+                           int pid = aPointPicker->GetPointId();
+                           if ( pid >= 0) { // && (!aSel->IsIndexSelected(IO, aPointPicker->GetPointId()))) {
+                             std::vector<int>::iterator found = 
+                               find(anIndices.begin(), anIndices.end(), pid);
+                             if (found == anIndices.end())
+                               anIndices.push_back(pid);
+                           }
                          }
                        }
+                       if (!anIndices.empty()) {
+                         aSel->AddOrRemoveIndex(IO, anIndices, true, false);
+                         aSel->AddIObject(IO, false);
+                         anIndices.clear();
+                       }
                      }
                    }
                  }
@@ -1037,91 +1114,140 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation()
              }
            }
            break;
-         case 2: // edges selection
-         case 3: // triangles selection
+         case CellSelection:
+         case EdgeOfCellSelection:
+         case EdgeSelection:
+         case FaceSelection:
+         case VolumeSelection: 
            {
-             aSel->SetSelectionMode(aSelectionMode,true);
-             if (!rwi->GetPicker()->IsA("vtkCellPicker") ) break;
-             vtkCellPicker* aCellPicker = vtkCellPicker::SafeDownCast(rwi->GetPicker());
-             vtkActorCollection* aListActors = this->CurrentRenderer->GetActors();
-             aListActors->InitTraversal();
+             VTKViewer_CellRectPicker* picker = VTKViewer_CellRectPicker::New();
+             picker->SetTolerance(0.001);
+             picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
+
+             vtkActorCollection* aListActors = picker->GetActors();
              vtkActor* aActor;
-             for (int k = 0, kEnd = aListActors->GetNumberOfItems(); k < kEnd; k++){
-               vtkActor* aActor = aListActors->GetNextActor();
-               if (vtkActor* aActor = aListActors->GetNextActor()){
-                 if (aActor->GetVisibility() == 0) continue;
-                 if(SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aActor)) {
-                   if(SActor->hasIO()) {
-                     Handle(SALOME_InteractiveObject) IO = SActor->getIO();
-                     if(IO.IsNull()) continue;
-                     if(aSelActiveCompOnly) {
-                       if(strcmp(aActiveComponent->ComponentDataType(),IO->getComponentDataType()) != 0)
-                         continue;
+             aListActors->InitTraversal();
+             while(aActor = aListActors->GetNextActor()) {
+               if (aActor->IsA("SALOME_Actor")) {
+                 SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor);
+                 if (aSActor->hasIO()) {
+                   Handle(SALOME_InteractiveObject) aIO = aSActor->getIO();
+                   // INFOS ( " NAME Object : " << aIO->getName() << " from " << aIO->getComponentDataType() );
+                   if (aSelActiveCompOnly &&
+                       strcmp(aActiveComponent->ComponentDataType(), 
+                              aIO->getComponentDataType()) != 0) {
+                     continue;
+                   }
+                   VTKViewer_CellDataSet cellList = picker->GetCellData(aActor);
+                   if ( !cellList.empty() ) {
+                     INFOS ( " NAME Actor : " << aSActor->getName() );
+                     std::vector<int> anIndexes;
+                     if (aSelectionMode == CellSelection) {
+                       VTKViewer_CellDataSet::iterator it;
+                       for (it = cellList.begin(); it != cellList.end(); ++it) {
+                         int aCellId = (*it).cellId;
+                         if ( !isValid( aSActor, aCellId, aSelectionMode ) )
+                           continue;
+                                     
+                         int aObjId = aSActor->GetObjId(aCellId);
+                         std::vector<int> aVtkList;
+                         if ( aObjId != -1 )
+                           aVtkList = aSActor->GetVtkId(aObjId);
+                                     
+                         if (aVtkList.size() > 0) {
+                           std::vector<int>::iterator it;
+                           for (it = aVtkList.begin(); it != aVtkList.end(); ++it) {
+                             std::vector<int>::iterator found = 
+                               find(anIndexes.begin(), anIndexes.end(), *it);
+                             if (found == anIndexes.end())
+                               anIndexes.push_back(*it);
+                           }
+                         }
+                         else
+                           anIndexes.push_back(aCellId);
+                       }
                      }
-                     if(vtkDataSet* aDataSet = SActor->GetMapper()->GetInput()){
-                       for(int i = 0, iEnd = aDataSet->GetNumberOfCells(); i < iEnd; i++){
-                         if(vtkCell* aCell = aDataSet->GetCell(i)){
-                           if(IsInRect(aCell,  x1, y1, x2, y2)){
-                             float* aBounds = aCell->GetBounds();
-                             float aCenter[3];
-                             aCenter[0] =(aBounds[0] + aBounds[1])/2; // Center X
-                             aCenter[1] =(aBounds[2] + aBounds[3])/2; // Center Y
-                             aCenter[2] =(aBounds[4] + aBounds[5])/2; // Center Z
-                             float aDisp[3];
-                             ComputeWorldToDisplay(aCenter[0],aCenter[1],aCenter[2],aDisp);
-                             aCellPicker->Pick(aDisp[0], aDisp[1], 0.0, CurrentRenderer);
-                             if(aCellPicker->GetCellId() >= 0 && !aSel->IsIndexSelected(IO,aCellPicker->GetCellId())){
-                               aSel->AddOrRemoveIndex( IO, aCellPicker->GetCellId(), true, false);
-                               aSel->AddIObject( IO, false );
+                     else {
+                       if ( vtkDataSet* aDataSet = aSActor->GetMapper()->GetInput() ) {
+                         VTKViewer_CellDataSet::iterator it;
+                         for ( it = cellList.begin(); it != cellList.end(); ++it ) {
+                           int aCellId = (*it).cellId;
+                                         
+                           if ( !isValid( aSActor, aCellId, aSelectionMode ) )
+                             continue;
+                                         
+                           int aObjId = aSActor->GetObjId(aCellId);
+                           std::vector<int> aVtkList;
+                           if (aObjId != -1)
+                             aVtkList = aSActor->GetVtkId(aObjId);
+                           bool result = false;
+                           if (vtkCell* aCell = aDataSet->GetCell(aCellId)) {
+                             if ( aSelectionMode == EdgeSelection ) {
+                               if ( aSActor->GetObjDimension( aObjId ) == 1 )
+                                 result = true;
+                             }
+                             else if ( aSelectionMode == FaceSelection ) {
+                               if ( aSActor->GetObjDimension( aObjId ) == 2 )
+                                 result = true;
+                             }
+                             else if ( aSelectionMode == VolumeSelection ) {
+                               if ( aSActor->GetObjDimension( aObjId ) == 3 )
+                                 result = true;
                              }
                            }
+                           if ( result ) {
+                             if (aVtkList.size() > 0) {
+                               std::vector<int>::iterator it;
+                               for (it = aVtkList.begin(); it != aVtkList.end(); ++it) {
+                                 std::vector<int>::iterator found =
+                                   find(anIndexes.begin(), anIndexes.end(), *it);
+                                 if (found == anIndexes.end())
+                                   anIndexes.push_back(*it);
+                               }
+                             }
+                             else
+                               anIndexes.push_back(aCellId);
+                           }
                          }
                        }
                      }
+                     aSel->AddOrRemoveIndex(aIO, anIndexes, true, false);
+                     aSel->AddIObject(aIO, false);
                    }
                  }
                }
              }
            }
-           break;
-         case 4: // objects selection
+           break;          
+         case ActorSelection: // objects selection
            {
-             vtkActorCollection* aListActors = this->CurrentRenderer->GetActors();
-             aListActors->InitTraversal();
+             VTKViewer_RectPicker* picker = VTKViewer_RectPicker::New();
+             picker->SetTolerance(0.001);
+             picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
+
+             vtkActorCollection* aListActors = picker->GetActors();
              vtkActor* aActor;
              SALOME_ListIO aListIO;
-             for (int k = 0; k < aListActors->GetNumberOfItems(); k++) {
-               aActor = aListActors->GetNextActor();
-               if (aActor) {
-                 if (aActor->GetVisibility() == 0) 
-                   continue;
-                 if ( aActor->IsA("SALOME_Actor") ) {
-                   SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor);
-                   if ( aSActor->hasIO() && IsInRect(aSActor, x1, y1, x2, y2)) {   
-                     Handle(SALOME_InteractiveObject) aIO = aSActor->getIO();
-                     if (aIO.IsNull())
-                       continue;
-                     if (aSelActiveCompOnly && 
-                              strcmp(aActiveComponent->ComponentDataType(), aIO->getComponentDataType()) != 0) {
-                       continue;
-                     }
-                     if (aListIO.IsEmpty()) {
-                       aListIO.Append( aIO );
-                     } else {
-                       SALOME_ListIteratorOfListIO It(aListIO);
-                       bool isStored = false;
-                       for(;It.More();It.Next()) {
-                         Handle(SALOME_InteractiveObject) IOS = It.Value();
-                         if( aIO->isSame(IOS) ) {
-                           aIO = IOS; //Added by SRN, fix SAL1307
-                           isStored = true;
-                           break;
-                         }
+             aListActors->InitTraversal();
+             while(aActor = aListActors->GetNextActor()) {
+               if (aActor->IsA("SALOME_Actor")) {
+                 SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor);
+                 if (aSActor->hasIO()) {
+                   Handle(SALOME_InteractiveObject) aIO = aSActor->getIO();
+                   bool isStored = false;
+                   if (!aListIO.IsEmpty()) {
+                     SALOME_ListIteratorOfListIO It(aListIO);
+                     for(;It.More();It.Next()) {
+                       Handle(SALOME_InteractiveObject) IOS = It.Value();
+                       if( aIO->isSame(IOS) ) {
+                         aIO = IOS; //Added by SRN, fix SAL1307
+                         isStored = true;
+                         break;
                        }
-                       if (!isStored)
-                         aListIO.Append( aIO );
                      }
                    }
+                   if (!isStored)
+                     aListIO.Append(aIO);
                  }
                }
              }
@@ -1223,12 +1349,21 @@ void VTKViewer_InteractorStyleSALOME::onOperation(QPoint mousePos)
   this->LastPos[1] = h - mousePos.y() - 1;
 }
 
+// called when selection mode changed (!put necessary initialization here!)
+void VTKViewer_InteractorStyleSALOME::OnSelectionModeChanged()
+{
+  myPActor->VisibilityOff();
+}
+
 // called when user moves mouse inside viewer window and there is no active viewer operation 
 // (!put necessary processing here!)
 void VTKViewer_InteractorStyleSALOME::onCursorMove(QPoint mousePos) {
   // processing highlighting
-  QAD_Study* myActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
-  SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
+  QAD_Study* anActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
+  SALOME_Selection* Sel = SALOME_Selection::Selection( anActiveStudy->getSelection() );
+
+  Selection_Mode aSelectionMode = Sel->SelectionMode();
+  myPActor->VisibilityOff();
       
   vtkRenderWindowInteractor *rwi = this->Interactor;
   int w, h, x, y;
@@ -1238,8 +1373,140 @@ void VTKViewer_InteractorStyleSALOME::onCursorMove(QPoint mousePos) {
   this->FindPokedRenderer(x,y);
   rwi->StartPickCallback();
   rwi->GetPicker()->Pick(x, y, 0.0, this->CurrentRenderer);
+  
+  if (rwi->GetPicker()->IsA("vtkCellPicker")) {
+    vtkCellPicker* picker = vtkCellPicker::SafeDownCast(rwi->GetPicker());
+    int aVtkId = picker->GetCellId();
+    // INFOS ( " Preselected CellId : " << picker->GetCellId() );
+    if ( aVtkId >= 0 ) {
+      vtkActor* ac = picker->GetActor();
+      if ( ac->IsA("SALOME_Actor") ) {
+       SALOME_Actor* SActor = SALOME_Actor::SafeDownCast( ac );
+       // INFOS ( " NAME Actor : " << SActor->getName() );
+
+       if (rwi->IsA("VTKViewer_RenderWindowInteractor")) {
+         VTKViewer_RenderWindowInteractor* aRWI = 
+           VTKViewer_RenderWindowInteractor::SafeDownCast(rwi);
+
+         //Cell selection //////////////////////////////////// NB
+         if ( aSelectionMode == CellSelection )
+    {
+      if ( SActor->hasIO() && isValid( SActor, aVtkId, CellSelection ) )
+      {
+             int anObjId = SActor->GetObjId(aVtkId);
+             std::vector<int> aVtkList;
+             if (anObjId != -1)
+          aVtkList = SActor->GetVtkId(anObjId);
+
+             if (aVtkList.size() > 0)
+                     aRWI->setCellData(SActor->getIO(), aVtkList, myPActor);
+             else
+          aRWI->setCellData(SActor->getIO(), aVtkId, myPActor);
+
+             this->CurrentRenderer->AddActor(myPActor);
+             myPActor->GetProperty()->SetRepresentationToSurface();
+             myPActor->VisibilityOn();
+           }
+         }
+       
+         //Edge, Face, Volume and EdgeOfCell selection ////////////////////////// NB
+         else if ( aSelectionMode == EdgeSelection || 
+                   aSelectionMode == FaceSelection || 
+                   aSelectionMode == VolumeSelection  ||
+                   aSelectionMode == EdgeOfCellSelection ) {
+           if ( SActor->hasIO() && isValid( SActor, aVtkId, aSelectionMode ) )
+      {
+             if (vtkDataSet* UGrid = SActor->GetMapper()->GetInput()) {
+               if (vtkCell* pickedCell = UGrid->GetCell(aVtkId)) {
+                 bool result = false;
+                 int edgeId = -1;
+                 int anObjId = SActor->GetObjId(aVtkId);
+                 std::vector<int> aVtkList;
+                 if (anObjId > -1)
+                   aVtkList = SActor->GetVtkId(anObjId);
+
+                 if ( aSelectionMode == EdgeSelection ) {
+                   if ( SActor->GetObjDimension( anObjId ) == 1 )
+                     result = true;
+                 }
+                 else if ( aSelectionMode == FaceSelection ) {
+                   if ( SActor->GetObjDimension( anObjId ) == 2 )
+                     result = true;
+                 }
+                 else if ( aSelectionMode == VolumeSelection ) {
+                   if ( SActor->GetObjDimension( anObjId ) == 3 )
+                     result = true;
+                 }
+                 else {
+                   float pickPosition[3];
+                   picker->GetPickPosition(pickPosition);
+                   float distMin = 1000000.0, dist = 0;
+                   for (int i = 0, iEnd = pickedCell->GetNumberOfEdges(); i < iEnd; i++){
+                     vtkCell* edge = pickedCell->GetEdge(i);
+                     if(vtkLine* line = vtkLine::SafeDownCast(edge)){
+                       float pcoords[3],closestPoint[3],weights[3];
+                       int subId;
+                       line->EvaluatePosition(pickPosition,closestPoint,subId,pcoords,dist,weights);
+                       if (dist < distMin) {
+                         distMin = dist;
+                         edgeId = i;
+                       }
+                     }
+                   }
+                   if (edgeId != -1 || pickedCell->GetCellDimension() == 1) 
+                     result = true;
+                   // INFOS("edgeID transformed = "<<edgeId);
+                 }
+                 if (result)
+      {
+                   this->CurrentRenderer->RemoveActor(myPActor);
+                   if (edgeId == -1) {
+                     if (aVtkList.size() > 0)
+                       aRWI->setCellData(SActor->getIO(), aVtkList, myPActor);
+                     else
+                             aRWI->setCellData(SActor->getIO(), aVtkId, myPActor);
+                   }
+                   else
+                     aRWI->setEdgeData(SActor->getIO(), aVtkId, -edgeId-1, myPActor);
+          
+                   this->CurrentRenderer->AddActor(myPActor);
+                   myPActor->GetProperty()->SetRepresentationToSurface();
+                   myPActor->VisibilityOn();
+                 }
+               }
+             }
+           }
+         }
+       }
+      }
+    }
+  }
+  else if (rwi->GetPicker()->IsA("vtkPointPicker")) {
+    vtkPointPicker* picker = vtkPointPicker::SafeDownCast(rwi->GetPicker());
+    // INFOS ( " Preselected PointId : " << picker->GetPointId() );
+    if (picker->GetPointId() >= 0) {
+      vtkActor* ac = picker->GetActor();
+      if ( ac->IsA("SALOME_Actor") ) {
+       SALOME_Actor* SActor = SALOME_Actor::SafeDownCast( ac );
+       // INFOS ( " NAME Actor : " << SActor->getName() );
 
-  if ( rwi->GetPicker()->IsA("vtkPicker") ) {
+       if (rwi->IsA("VTKViewer_RenderWindowInteractor")) {
+         VTKViewer_RenderWindowInteractor* aRWI = 
+           VTKViewer_RenderWindowInteractor::SafeDownCast(rwi);
+
+         if ( SActor->hasIO() ) {
+           myPActor->VisibilityOff();
+           this->CurrentRenderer->RemoveActor(myPActor);
+           aRWI->setPointData(SActor->getIO(), picker->GetPointId(), myPActor);
+           this->CurrentRenderer->AddActor(myPActor);
+           myPActor->GetProperty()->SetRepresentationToSurface();
+           myPActor->VisibilityOn();
+         }
+       }
+      }
+    }
+  }
+  else if ( rwi->GetPicker()->IsA("vtkPicker") ) {
     vtkPicker* picker = vtkPicker::SafeDownCast(rwi->GetPicker());
     vtkActor* ac = picker->GetActor();
     
@@ -1282,7 +1549,7 @@ void VTKViewer_InteractorStyleSALOME::onCursorMove(QPoint mousePos) {
                 }
                 ac = theActors->GetNextActor();
               }
-              // MESSAGE ( " NAME PREVIEW " << SActor->getName() );
+              // INFOS ( " NAME PREVIEW " << SActor->getName() );
             }
           }
         }
@@ -1301,6 +1568,9 @@ void VTKViewer_InteractorStyleSALOME::onCursorMove(QPoint mousePos) {
       }
     }
   }
+  rwi->EndPickCallback();
+  rwi->Render();
+
   this->LastPos[0] = x;
   this->LastPos[1] = y;
 }
@@ -1425,3 +1695,59 @@ bool VTKViewer_InteractorStyleSALOME::IsInRect(float* thePoint,
 
   return ((aPnt[0]>left) && (aPnt[0]<right) && (aPnt[1]>bottom) && (aPnt[1]<top));
 }
+
+void VTKViewer_InteractorStyleSALOME::SetFaceFilter( const Handle(VTKViewer_Filter)& f )
+{
+  myFaceFilter = f;
+}
+
+void VTKViewer_InteractorStyleSALOME::RemoveFaceFilter()
+{
+  myFaceFilter.Nullify();
+}
+
+void VTKViewer_InteractorStyleSALOME::SetEdgeFilter( const Handle(VTKViewer_Filter)& f )
+{
+  myEdgeFilter = f;
+}
+
+void VTKViewer_InteractorStyleSALOME::RemoveEdgeFilter()
+{
+  myEdgeFilter.Nullify();
+}
+
+bool VTKViewer_InteractorStyleSALOME::isValid( SALOME_Actor*        theActor,
+                                               const int            theId,
+                                               const Selection_Mode theSelMode )
+{
+  if ( theSelMode != CellSelection &&
+       theSelMode != FaceSelection &&
+       theSelMode != EdgeSelection )
+    return true;
+
+  if ( theSelMode == CellSelection )
+  {
+    vtkDataSet* aUGrid = theActor->GetMapper()->GetInput();
+    if ( aUGrid != 0 )
+    {
+      vtkCell* aCell = aUGrid->GetCell( theId );
+      if ( aCell != 0 )
+      {
+        int nbPoints = aCell->GetNumberOfPoints();
+        if ( nbPoints == 2 )
+          return myEdgeFilter.IsNull() || myEdgeFilter->IsValid( theActor, theId );
+        else
+          return myFaceFilter.IsNull() || myFaceFilter->IsValid( theActor, theId );
+
+        return true;
+      }
+    }
+    return false;
+  }
+  else if ( theSelMode == FaceSelection )
+    return myFaceFilter.IsNull() || myFaceFilter->IsValid( theActor, theId );
+  else if ( theSelMode == EdgeSelection )
+    return myEdgeFilter.IsNull() || myEdgeFilter->IsValid( theActor, theId );
+    
+  return true;
+}
index 62438e91e2d4fd16f0af7bdcf0c7c42a57601aeb..ce55fdfc8d98c4fa1a3f0297e6af914927649afe 100644 (file)
@@ -33,6 +33,8 @@
 #include <qobject.h>
 #include <qcursor.h>
 #include "SALOME_Actor.h"
+#include "VTKViewer_Filter.h"
+#include "SALOME_Selection.h"
 
 class VTKViewer_Trihedron;
 
@@ -55,6 +57,8 @@ class VTKViewer_InteractorStyleSALOME : public QObject, public vtkInteractorStyl
   static VTKViewer_InteractorStyleSALOME *New();
 
   void setTriedron(VTKViewer_Trihedron* theTrihedron);
+  void setPreselectionProp(const double& theRed = 0, const double& theGreen = 1,
+                          const double& theBlue = 1, const int& theWidth = 5);
 
   vtkTypeMacro(VTKViewer_InteractorStyleSALOME, vtkObject);
   void PrintSelf(ostream& os, vtkIndent indent);
@@ -68,8 +72,15 @@ class VTKViewer_InteractorStyleSALOME : public QObject, public vtkInteractorStyl
   void OnRightButtonDown(int ctrl, int shift, int x, int y);
   void OnRightButtonUp  (int ctrl, int shift, int x, int y);
 
+  void OnSelectionModeChanged();
+
   void  ViewFitAll();
 
+  void  SetEdgeFilter( const Handle(VTKViewer_Filter)& );
+  void  SetFaceFilter( const Handle(VTKViewer_Filter)& );
+  void  RemoveFaceFilter();
+  void  RemoveEdgeFilter();
+
  protected:
   VTKViewer_InteractorStyleSALOME();
   ~VTKViewer_InteractorStyleSALOME();
@@ -93,12 +104,15 @@ class VTKViewer_InteractorStyleSALOME : public QObject, public vtkInteractorStyl
                const int left, const int top, 
                const int right, const int bottom);
 
+  bool isValid( SALOME_Actor* theActor, const int theCellId, const Selection_Mode theSelMode );
+
   int State;
   float MotionFactor;
   float RadianToDegree;                 // constant: for conv from deg to rad
   double myScale;
 
   SALOME_Actor* preview;
+  vtkActor*     myPActor;
 
 public:
   bool eventFilter(QObject* object, QEvent* event);
@@ -123,26 +137,30 @@ protected:
   void setCursor(const int operation);
 
 protected:
-  QCursor      myDefCursor;
-  QCursor      myPanCursor;
-  QCursor      myZoomCursor;
-  QCursor      myRotateCursor;
-  QCursor      mySpinCursor;
-  QCursor      myHandCursor;
-  QCursor      myGlobalPanCursor;
-  QPoint       myPoint;
-  QPoint       myOtherPoint;
-  bool         myCursorState;
-  bool         myShiftState;
-  int ForcedState;
-  VTKViewer_Trihedron* m_Trihedron;  
-
-  QWidget*     myGUIWindow;
+  QCursor                   myDefCursor;
+  QCursor                   myPanCursor;
+  QCursor                   myZoomCursor;
+  QCursor                   myRotateCursor;
+  QCursor                   mySpinCursor;
+  QCursor                   myHandCursor;
+  QCursor                   myGlobalPanCursor;
+  QPoint                    myPoint;
+  QPoint                    myOtherPoint;
+  bool                      myCursorState;
+  bool                      myShiftState;
+  int                       ForcedState;
+  
+  VTKViewer_Trihedron*      m_Trihedron;
+  
+  QWidget*                  myGUIWindow;
+  
+  Handle(VTKViewer_Filter)  myEdgeFilter;
+  Handle(VTKViewer_Filter)  myFaceFilter;
 
   //  members from old version
-  double DeltaElevation;
-  double DeltaAzimuth;
-  int LastPos[2];
+  double                    DeltaElevation;
+  double                    DeltaAzimuth;
+  int                       LastPos[2];
 };
 
 #endif
diff --git a/src/VTKViewer/VTKViewer_RectPicker.cxx b/src/VTKViewer/VTKViewer_RectPicker.cxx
new file mode 100644 (file)
index 0000000..6453097
--- /dev/null
@@ -0,0 +1,881 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : VTKViewer_RectPicker.cxx
+//  Author : Natalia KOPNOVA
+//  Module : SALOME
+
+#include <VTKViewer_RectPicker.h>
+
+#include "vtkActor.h"
+#include "vtkAssemblyNode.h"
+#include "vtkAssemblyPath.h"
+#include "vtkCamera.h"
+#include "vtkCommand.h"
+#include "vtkImageData.h"
+#include "vtkLODProp3D.h"
+#include "vtkMapper.h"
+#include "vtkMath.h"
+#include "vtkObjectFactory.h"
+#include "vtkPoints.h"
+#include "vtkProp3DCollection.h"
+#include "vtkProperty.h"
+#include "vtkRenderWindow.h"
+#include "vtkRenderer.h"
+#include "vtkTransform.h"
+#include "vtkVertex.h"
+#include "vtkVolume.h"
+#include "vtkVolumeMapper.h"
+
+using namespace std;
+
+//----------------------------------------------------------------------------
+vtkStandardNewMacro(VTKViewer_RectPicker);
+//----------------------------------------------------------------------------
+
+VTKViewer_RectPicker::VTKViewer_RectPicker()
+{
+}
+
+//----------------------------------------------------------------------------
+int VTKViewer_RectPicker::Pick(float selectionX1, float selectionY1, float selectionZ1,
+                              float selectionX2, float selectionY2, float selectionZ2,
+                              vtkRenderer *renderer)
+{
+  int k, i;
+  vtkProp *prop;
+  vtkCamera *camera;
+  vtkAbstractMapper3D *mapper = NULL;
+  float p1World[4][4], p2World[4][4], p1Mapper[4][4], p2Mapper[4][4];
+  float c1[3], c2[3];
+  int picked=0;
+  int *winSize;
+  float x, y, t, p;
+  float *viewport;
+  float cameraPos[4], cameraFP[4];
+  float *displayCoords, *worldCoords;
+  float pickPosition[4][3];
+  double *clipRange;
+  float ray[4][3], rayLength[4];
+  int pickable;
+  int LODId;
+  float windowLowerLeft[4], windowUpperRight[4];
+  float bounds[6], tol;
+  float tF, tB;
+  float hitPosition[3];
+  float cameraDOP[3];
+  
+  //  Initialize picking process
+  this->Initialize();
+  this->Renderer = renderer;
+
+  /* Selection point is not defined for the rectangle
+  this->SelectionPoint[0] = 
+  this->SelectionPoint[1] = 
+  this->SelectionPoint[2] = 
+  */
+
+  // Invoke start pick method if defined
+  this->InvokeEvent(vtkCommand::StartPickEvent,NULL);
+
+  if ( renderer == NULL )
+    {
+    vtkErrorMacro(<<"Must specify renderer!");
+    return 0;
+    }
+
+  // Get camera focal point and position. Convert to display (screen) 
+  // coordinates. We need a depth value for z-buffer.
+  //
+  camera = renderer->GetActiveCamera();
+  camera->GetPosition((float *)cameraPos); cameraPos[3] = 1.0;
+  camera->GetFocalPoint((float *)cameraFP); cameraFP[3] = 1.0;
+
+  renderer->SetWorldPoint(cameraFP);
+  renderer->WorldToDisplay();
+  displayCoords = renderer->GetDisplayPoint();
+  selectionZ1 = selectionZ2 = displayCoords[2];
+
+  // Convert the selection rectangle into world coordinates.
+  //
+  renderer->SetDisplayPoint(selectionX1, selectionY1, selectionZ1);
+  renderer->DisplayToWorld();
+  worldCoords = renderer->GetWorldPoint();
+  if ( worldCoords[3] == 0.0 )
+    {
+    vtkErrorMacro(<<"Bad homogeneous coordinates");
+    return 0;
+    }
+  for (i=0; i < 3; i++) 
+    {
+    pickPosition[0][i] = worldCoords[i] / worldCoords[3];
+    }
+
+  renderer->SetDisplayPoint(selectionX1, selectionY2, (selectionZ1+selectionZ2)/2);
+  renderer->DisplayToWorld();
+  worldCoords = renderer->GetWorldPoint();
+  if ( worldCoords[3] == 0.0 )
+    {
+    vtkErrorMacro(<<"Bad homogeneous coordinates");
+    return 0;
+    }
+  for (i=0; i < 3; i++) 
+    {
+    pickPosition[1][i] = worldCoords[i] / worldCoords[3];
+    }
+  
+  renderer->SetDisplayPoint(selectionX2, selectionY2, selectionZ2);
+  renderer->DisplayToWorld();
+  worldCoords = renderer->GetWorldPoint();
+  if ( worldCoords[3] == 0.0 )
+    {
+    vtkErrorMacro(<<"Bad homogeneous coordinates");
+    return 0;
+    }
+  for (i=0; i < 3; i++) 
+    {
+    pickPosition[2][i] = worldCoords[i] / worldCoords[3];
+    }
+
+  renderer->SetDisplayPoint(selectionX2, selectionY1, (selectionZ1+selectionZ2)/2);
+  renderer->DisplayToWorld();
+  worldCoords = renderer->GetWorldPoint();
+  if ( worldCoords[3] == 0.0 )
+    {
+    vtkErrorMacro(<<"Bad homogeneous coordinates");
+    return 0;
+    }
+  for (i=0; i < 3; i++) 
+    {
+    pickPosition[3][i] = worldCoords[i] / worldCoords[3];
+    }
+  
+  //  Compute the ray endpoints.  The ray is along the line running from
+  //  the camera position to the selection point, starting where this line
+  //  intersects the front clipping plane, and terminating where this
+  //  line intersects the back clipping plane.
+  for (k=0; k < 4; k++) {
+    for (i=0; i<3; i++)
+      {
+       ray[k][i] = pickPosition[k][i] - cameraPos[i];
+      }
+  }
+  for (i=0; i<3; i++)
+    {
+      cameraDOP[i] = cameraFP[i] - cameraPos[i];
+    }
+
+  vtkMath::Normalize(cameraDOP);
+
+  for (k=0; k < 4; k++) {
+    if (( rayLength[k] = vtkMath::Dot(cameraDOP,ray[k])) == 0.0 ) 
+      {
+       vtkWarningMacro("Cannot process points");
+       return 0;
+      } 
+  }
+
+  clipRange = camera->GetClippingRange();
+
+  if ( camera->GetParallelProjection() )
+    {
+      for (k=0; k < 4; k++) {
+       tF = clipRange[0] - rayLength[k];
+       tB = clipRange[1] - rayLength[k];
+       for (i=0; i<3; i++) 
+         {
+           p1World[k][i] = pickPosition[k][i] + tF*cameraDOP[i];
+           p2World[k][i] = pickPosition[k][i] + tB*cameraDOP[i];
+         }
+       p1World[k][3] = p2World[k][3] = 1.0;
+      }
+    }
+  else
+    {
+      for (k=0; k < 4; k++) {
+       tF = clipRange[0] / rayLength[k];
+       tB = clipRange[1] / rayLength[k];
+       for (i=0; i<3; i++) 
+         {
+           p1World[k][i] = cameraPos[i] + tF*ray[k][i];
+           p2World[k][i] = cameraPos[i] + tB*ray[k][i];
+         }
+       p1World[k][3] = p2World[k][3] = 1.0;
+      }
+    }
+
+  // Compute the center points of ray rectangle
+  for (i=0; i<3; i++) {
+    c1[i] = c2[i] = 0;
+    for (k=0; k<4; k++) {
+      c1[i] += p1World[k][i];
+      c2[i] += p2World[k][i];
+    }
+    c1[i] = c1[i]/4;
+    c2[i] = c2[i]/4;
+  }
+  
+  // Compute the tolerance in world coordinates.  Do this by
+  // determining the world coordinates of the diagonal points of the
+  // window, computing the width of the window in world coordinates, and 
+  // multiplying by the tolerance.
+  //
+  viewport = renderer->GetViewport();
+  winSize = renderer->GetRenderWindow()->GetSize();
+  x = winSize[0] * viewport[0];
+  y = winSize[1] * viewport[1];
+  renderer->SetDisplayPoint(x, y, selectionZ1);
+  renderer->DisplayToWorld();
+  renderer->GetWorldPoint(windowLowerLeft);
+
+  x = winSize[0] * viewport[2];
+  y = winSize[1] * viewport[3];
+  renderer->SetDisplayPoint(x, y, selectionZ2);
+  renderer->DisplayToWorld();
+  renderer->GetWorldPoint(windowUpperRight);
+
+  for (tol=0.0,i=0; i<3; i++) 
+    {
+    tol += (windowUpperRight[i] - windowLowerLeft[i]) *
+      (windowUpperRight[i] - windowLowerLeft[i]);
+    }
+  
+  tol = sqrt (tol) * this->Tolerance;
+
+  //  Loop over all props.  Transform ray (defined from position of
+  //  camera to selection point) into coordinates of mapper (not
+  //  transformed to actors coordinates!  Reduces overall computation!!!).
+  //  Note that only vtkProp3D's can be picked by vtkPicker.
+  //
+  vtkPropCollection *props;
+  vtkProp *propCandidate;
+  if ( this->PickFromList ) 
+    {
+    props = this->GetPickList();
+    }
+  else 
+    {
+    props = renderer->GetProps();
+    }
+
+  vtkActor *actor;
+  vtkLODProp3D *prop3D;
+  vtkVolume *volume;
+  vtkAssemblyPath *path;
+  vtkProperty *tempProperty;
+  this->Transform->PostMultiply();
+  for ( props->InitTraversal(); (prop=props->GetNextProp()); )
+    {
+    for ( prop->InitPathTraversal(); (path=prop->GetNextPath()); )
+      {
+      pickable = 0;
+      actor = NULL;
+      propCandidate = path->GetLastNode()->GetProp();
+      if ( propCandidate->GetPickable() && propCandidate->GetVisibility() )
+        {
+        pickable = 1;
+        if ( (actor=vtkActor::SafeDownCast(propCandidate)) != NULL )
+          {
+          mapper = actor->GetMapper();
+          if ( actor->GetProperty()->GetOpacity() <= 0.0 )
+            {
+            pickable = 0;
+            }
+          }
+        else if ( (prop3D=vtkLODProp3D::SafeDownCast(propCandidate)) != NULL )
+          {
+          LODId = prop3D->GetPickLODID();
+          mapper = prop3D->GetLODMapper(LODId);
+
+          // if the mapper is a vtkMapper (as opposed to a vtkVolumeMapper), 
+          // then check the transparency to see if the object is pickable
+          if ( vtkMapper::SafeDownCast(mapper) != NULL)
+            {
+            prop3D->GetLODProperty(LODId, &tempProperty);
+            if ( tempProperty->GetOpacity() <= 0.0 )
+              {
+              pickable = 0;
+              }
+            }
+          }
+        else if ( (volume=vtkVolume::SafeDownCast(propCandidate)) != NULL )
+          {
+          mapper = volume->GetMapper();
+          }
+        else
+          {
+          pickable = 0; //only vtkProp3D's (actors and volumes) can be picked
+          }
+        }
+      //  If actor can be picked, get its composite matrix, invert it, and
+      //  use the inverted matrix to transform the ray points into mapper
+      //  coordinates. 
+      if ( pickable  &&  mapper != NULL )
+        {
+        vtkMatrix4x4 *LastMatrix = path->GetLastNode()->GetMatrix();
+        if (LastMatrix == NULL)
+          {
+          vtkErrorMacro (<< "Pick: Null matrix.");
+          return 0;
+          }
+        this->Transform->SetMatrix(LastMatrix);
+        this->Transform->Push();
+        this->Transform->Inverse();
+
+       for (k=0; k < 4; k++) {
+         this->Transform->TransformPoint(p1World[k],p1Mapper[k]);
+         this->Transform->TransformPoint(p2World[k],p2Mapper[k]);
+
+         for (i=0; i<3; i++) 
+           {
+             ray[k][i] = p2Mapper[k][i] - p1Mapper[k][i];
+           }
+       }
+
+        this->Transform->Pop();
+
+        //  Have the ray endpoints in mapper space, now need to compare this
+        //  with the mapper bounds to see whether intersection is possible.
+        //
+        //  Get the bounding box of the modeller.  Note that the tolerance is
+        //  added to the bounding box to make sure things on the edge of the
+        //  bounding box are picked correctly.
+        mapper->GetBounds(bounds);
+        bounds[0] -= tol; bounds[1] += tol; 
+        bounds[2] -= tol; bounds[3] += tol; 
+        bounds[4] -= tol; bounds[5] += tol; 
+        if ( HitBBox(bounds, p1Mapper, ray) ) {
+         t = this->IntersectWithHex(p1Mapper, p2Mapper, tol, path, 
+                                    (vtkProp3D *)propCandidate, mapper);
+         if ( t >= 0.0 && t <= 1.0 /*t < VTK_LARGE_FLOAT*/ ) {
+           picked = 1;
+           this->Prop3Ds->AddItem((vtkProp3D *)prop);
+           this->PickedPositions->InsertNextPoint
+             ((1.0 - t)*c1[0] + t*c2[0],
+              (1.0 - t)*c1[1] + t*c2[1],
+              (1.0 - t)*c1[2] + t*c2[2]);
+           
+           // backwards compatibility: also add to this->Actors
+           if (actor) {
+             this->Actors->AddItem(actor);
+           }
+         }
+       }
+
+        }//if visible and pickable not transparent and has mapper
+      }//for all parts
+    }//for all actors
+  
+  // Invoke end pick method if defined
+  this->InvokeEvent(vtkCommand::EndPickEvent,NULL);
+  
+  return picked;
+}
+
+#define SIDE_LEFT 0
+#define SIDE_RIGHT 1
+#define SIDE_MIDDLE 2
+
+float GetParameterValue(float start, float end, float point)
+{
+  if (start == end) return -VTK_LARGE_FLOAT;
+  return (point-start)/(end-start);
+}
+
+void GetPointCoord(const float start[3], const float end[3], float t, float point[3])
+{
+  int i;
+  for (i = 0; i < 3; i++) {
+    point[i] = start[i] + t*(end[i]-start[i]);
+  }
+}
+
+char GetIntersectionPoint(const float start[3], const float end[3], 
+                         const int& index, const float p, float point[3])
+{
+  float t = GetParameterValue(start[index], end[index], p);
+  char result = 0;
+  if (t >= 0.0 && t <= 1.0) {
+    result = 1;
+    GetPointCoord(start, end, t, point);
+  }
+  return result;
+}
+
+//----------------------------------------------------------------------------
+char VTKViewer_RectPicker::HitBBox (float bounds[6], float origin[4][4], float dir[4][3])
+{
+  int i, j, k, n;
+  float endray[4][3];
+
+  for (k = 0; k < 4; k++) {
+    for (i = 0; i < 3; i++) {
+      endray[k][i] = origin[k][i] + dir[k][i];
+    }
+  }
+
+  // Compute hex bounding box, center point and center direction
+  float hbounds[6], center[3], ray[3];
+  for (i = 0; i < 3; i++) {
+    hbounds[2*i] = hbounds[2*i+1] = origin[0][i];
+    center[i] = ray[i] = 0;
+    for (k = 0; k < 4; k++) {
+      center[i] += origin[k][i];
+      ray[i] += endray[k][i];
+      if (origin[k][i] < hbounds[2*i]) {
+       hbounds[2*i] = origin[k][i];
+      }
+      else if (origin[k][i] > hbounds[2*i+1])
+       hbounds[2*i+1] = origin[k][i];
+      if (endray[k][i] < hbounds[2*i])
+       hbounds[2*i] = endray[k][i];
+      else if (endray[k][i] > hbounds[2*i+1])
+       hbounds[2*i+1] = endray[k][i];
+    }
+    center[i] = center[i]/4;
+    ray[i] = ray[i]/4;
+    ray[i] = ray[i] - center[i];
+  }
+
+  // Check for intersection between bouning boxes
+  for (i = 0; i < 3; i++) {
+    if (bounds[2*i+1] < hbounds[2*i] || bounds[2*i] > hbounds[2*i+1])
+      return 0;
+  }
+
+  // Check if one of the origin point lays inside bbox
+  char inside;
+  for (k = 0; k < 4; k++) {
+    inside = 1;
+    for (i = 0; i < 3; i++) {
+      if (origin[k][i] < bounds[2*i] || origin[k][i] > bounds[2*i+1]) {
+       inside = 0;
+       break;
+      }
+    }
+    if (inside) return 1;
+  }
+
+  // Find the closest coord plane for the center point
+  char side[3];
+  float coordPlane[3];
+  inside = 1;
+  for (i = 0; i < 3; i++) {
+    if (center[i] < bounds[2*i]) {
+      inside = 0;
+      coordPlane[i] = bounds[2*i];
+      side[i] = SIDE_LEFT;
+    }
+    else if (center[i] > bounds[2*i+1]) {
+      inside = 0;
+      coordPlane[i] = bounds[2*i+1];
+      side[i] = SIDE_RIGHT;
+    }
+    else {
+      coordPlane[i] = (ray[i]<0.0) ? bounds[2*i] : bounds[2*i+1];
+      side[i] = SIDE_MIDDLE;
+    }
+  }
+  if (inside) return 1;
+
+  // Calculate parametric distances to the planes and find the max
+  float maxT[3];
+  int whichPlane = 0;
+  char defined = 0;
+  for (i = 0; i < 3; i++) {
+    if (side[i] != SIDE_MIDDLE && ray[i] != 0.0) {
+      maxT[i] = (coordPlane[i]-center[i])/ray[i];
+      defined = 1;
+    }
+    else
+      maxT[i] = -1.0;
+  }
+  for (i = 0; i < 3; i++) {
+    if (maxT[whichPlane] < maxT[i])
+      whichPlane = i;
+  }
+
+  // Check for intersection along the center ray
+  float coord;
+  if (maxT[whichPlane] <= 1.0 && maxT[whichPlane] >= 0.0) {
+    inside = 1;
+    for (i = 0; i < 3; i++) {
+      if (i != whichPlane) {
+       coord = center[i] + maxT[whichPlane]*ray[i];
+       if (coord < bounds[2*i] || coord > bounds[2*i+1])
+         inside = 0;
+      }
+    }
+    if (inside) return 1;
+  }
+
+  // Define the intersection plane
+  if (!defined) {
+    for (i = 0; i < 3; i++) {
+      if (ray[i] != 0.0) {
+       maxT[i] = (coordPlane[i]-center[i])/ray[i];
+      }
+      else 
+       maxT[i] = VTK_LARGE_FLOAT;
+    }
+    for (i = 0; i < 3; i++) {
+      if (maxT[whichPlane] > maxT[i])
+       whichPlane = i;
+    }
+  }
+
+  // Compute the intersection between hex and coord plane
+  float t[4];
+  for (k = 0; k < 4; k++) {
+    if (dir[k][whichPlane] != 0.0) {
+      t[k] = (coordPlane[whichPlane]-origin[k][whichPlane])/dir[k][whichPlane];
+    }
+    else {
+      t[k] = VTK_LARGE_FLOAT;
+    }
+  }
+
+  vtkPoints* aPoints = vtkPoints::New();
+  float p[3], q[3], t1;
+  for (k = 0; k < 4; k++) {
+    n = (k+1)%4; // next point
+    if (t[k] > 1.0) {
+      if (t[n] < 1.0) {
+       // find intersection point
+       t1 = GetParameterValue(endray[k][whichPlane], endray[n][whichPlane], coordPlane[whichPlane]);
+       if (t1 > 0.0 && t1 < 1.0) {
+         GetPointCoord(endray[k], endray[n], t1, p);
+         aPoints->InsertNextPoint(p[0], p[1], p[2]);
+       }
+      }
+      if (t[n] < 0.0) {
+       // find second intersection point
+       t1 = GetParameterValue(origin[k][whichPlane], origin[n][whichPlane], coordPlane[whichPlane]);
+       if (t1 > 0.0 && t1 < 1.0) {
+         GetPointCoord(origin[k], origin[n], t1, p);
+         aPoints->InsertNextPoint(p[0], p[1], p[2]);
+       }
+      }
+    }
+    else if (t[k] < 0.0) {
+      if (t[n] > 0.0) {
+       // find intersection point
+       t1 = GetParameterValue(origin[k][whichPlane], origin[n][whichPlane], coordPlane[whichPlane]);
+       if (t1 > 0.0 && t1 < 1.0) {
+         GetPointCoord(origin[k], origin[n], t1, p);
+         aPoints->InsertNextPoint(p[0], p[1], p[2]);
+       }
+      }
+    }
+    else {
+      // find intersection point
+      GetPointCoord(origin[k], endray[k], t[k], p);
+      aPoints->InsertNextPoint(p[0], p[1], p[2]);
+
+      if (t[n] < 0.0) {
+       // find second intersection point
+       t1 = GetParameterValue(origin[k][whichPlane], origin[n][whichPlane], coordPlane[whichPlane]);
+       if (t1 > 0.0 && t1 < 1.0) {
+         GetPointCoord(origin[k], origin[n], t1, p);
+         aPoints->InsertNextPoint(p[0], p[1], p[2]);
+       }
+      }
+      else if (t[n] > 1.0) {
+       // find second intersection point
+       t1 = GetParameterValue(endray[k][whichPlane], endray[n][whichPlane], coordPlane[whichPlane]);
+       if (t1 > 0.0 && t1 < 1.0) {
+         GetPointCoord(endray[k], endray[n], t1, p);
+         aPoints->InsertNextPoint(p[0], p[1], p[2]);
+       }
+      }
+    }
+  }
+  n = aPoints->GetNumberOfPoints();
+  if (n == 0) {
+    aPoints->Delete();
+    return 0;
+  }
+
+  if (n == 1) {
+    aPoints->GetPoint(0, p);
+    inside = 1;
+    for (i = 0; i < 3; i++) {
+      if (i != whichPlane) {
+       if (p[i] < bounds[2*i] || p[i] > bounds[2*i+1]) {
+         inside = 0; break;
+       }
+      }
+    }
+    aPoints->Delete();
+    return inside;
+  }
+
+  // Analize intersection
+  int nearPlane, boundPlane = -1;
+  float boundCoord, boundMin, boundMax;
+  char intersect = 0;
+  for (k = 0; k < n; k++) {
+    aPoints->GetPoint(k, p);
+    j = k+1; if (j == n) j = 0;
+    aPoints->GetPoint(j, q);
+    inside = 1;
+    nearPlane = 0;
+    // if the point is inside bbox
+    for (i = 0; i < 3; i++) {
+      if (i != whichPlane) {
+       if (p[i] < bounds[2*i]) {
+         side[i] = SIDE_LEFT;
+         maxT[i] = GetParameterValue(p[i], q[i], bounds[2*i]);
+         inside = 0; 
+       }
+       else if (p[i] > bounds[2*i+1]) {
+         side[i] = SIDE_RIGHT;
+         maxT[i] = GetParameterValue(p[i], q[i], bounds[2*i+1]);
+         inside = 0; 
+       }
+       else {
+         side[i] = SIDE_MIDDLE;
+         maxT[i] = -1.0;
+       }
+      }
+      else maxT[i] = -1.0;
+      if (maxT[i] > maxT[nearPlane]) nearPlane = i;
+    }
+    if (inside) break;
+    // if segment intersects bbox
+    if (maxT[nearPlane] >= 0.0 && maxT[nearPlane] <= 1.0) {
+      for (i = 0; i < 3; i++) {
+       if (i != whichPlane && i != nearPlane) {
+         coord = p[i] + maxT[nearPlane]*(q[i]-p[i]);
+         if (coord >= bounds[2*i] && coord <= bounds[2*i+1]) {
+           intersect = 1; break;
+         }
+       }
+      }
+      // intersect with boundPlane
+      if (boundPlane == -1) {
+       boundCoord = p[nearPlane] + maxT[nearPlane]*(q[nearPlane]-p[nearPlane]);
+       boundPlane = nearPlane;
+       for (i = 0; i < 3; i++) {
+         if (i != whichPlane && i != boundPlane) {
+           coord = p[i] + maxT[nearPlane]*(q[i]-p[i]);
+           boundMin = boundMax = coord;
+         }
+       }
+      }
+      else {
+       t1 = GetParameterValue(p[boundPlane], q[boundPlane], boundCoord);
+       if (t1 >= 0.0 && t1 <= 1.0) {
+         for (i = 0; i < 3; i++) {
+           if (i != whichPlane && i != boundPlane) {
+             coord = p[i] + t1*(q[i]-p[i]);
+             if (coord < boundMin) boundMin = coord;
+             if (coord > boundMax) boundMax = coord;
+           }
+         }
+       }
+      }
+    }
+    if (intersect) break;
+  }
+  aPoints->Delete();
+  if (inside || intersect) {
+    return 1;
+  }
+
+  inside = 1;
+  for (i = 0; i < 3; i++) {
+    if (i != whichPlane && i != boundPlane) {
+      if (boundMin > bounds[2*i+1] || boundMax < bounds[2*i])
+       inside = 0;
+    }
+  }
+
+  return inside;
+}
+
+//----------------------------------------------------------------------------
+char VTKViewer_RectPicker::PointInside (float p[3], float p1[4][4], float p2[4][4], float tol)
+{
+  int i, j, k;
+  float t, coord[3];
+
+  // Fix one coordinate (x, for example) and 
+  // compute intersection with coordinate plane
+  vtkPoints* aPoints = vtkPoints::New();
+  int mode = 0;
+  for (k = 0; k < 4; k++) {
+    j = k+1; if (j == 4) j = 0;
+    switch (mode) {
+    case 0:
+      if (GetIntersectionPoint(p1[k], p1[j], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 0;
+      }
+      if (GetIntersectionPoint(p1[k], p2[k], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 1;
+      }
+      if (GetIntersectionPoint(p2[k], p2[j], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 2;
+      }
+      /*
+      if ((p1[k][0]-p[0])*(p2[k][0]-p[0]) <= 0) {
+       t = GetParameterValue(p1[k][0], p2[k][0], p[0]);
+       if (t >= 0.0 && t <= 1.0) {
+         GetPointCoord(p1[k], p2[k], t, coord);
+         aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       }
+      }
+      */
+      break;
+    case 1:
+      if (GetIntersectionPoint(p1[k], p2[k], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 1;
+      }
+      if (GetIntersectionPoint(p2[k], p2[j], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 2;
+      }
+      if (GetIntersectionPoint(p1[k], p1[j], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 0;
+      }
+      /*
+      if ((p1[k][0]-p[0])*(p1[j][0]-p[0]) <= 0) {
+       t = GetParameterValue(p1[k][0], p1[j][0], p[0]);
+       if (t > 0.0 && t < 1.0) {
+         GetPointCoord(p1[k], p1[j], t, coord);
+         aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       }
+      }
+      */
+      break;
+    case 2:
+      if (GetIntersectionPoint(p2[k], p2[j], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 2;
+      }
+      if (GetIntersectionPoint(p1[k], p2[k], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 1;
+      }
+      if (GetIntersectionPoint(p1[k], p1[j], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 0;
+      }
+      /*
+      if ((p2[k][0]-p[0])*(p2[j][0]-p[0]) <= 0) {
+       t = GetParameterValue(p2[k][0], p2[j][0], p[0]);
+       if (t > 0.0 && t < 1.0) {
+         GetPointCoord(p2[k], p2[j], t, coord);
+         aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       }
+      }
+      */
+      break;
+    }
+  }
+  int n = aPoints->GetNumberOfPoints();
+  //cout << "---> Points in X projection " << n << endl;
+  if (n == 0) {
+    aPoints->Delete();
+    return 0;
+  }
+
+  // Fix the second coord and define bounds
+  float zMin = VTK_LARGE_FLOAT, zMax = -VTK_LARGE_FLOAT, z, ncoord[3];
+  char inside = 0;
+  for (k = 0; k < n; k++) {
+    aPoints->GetPoint(k, coord);
+    //cout << "  P" << k << " (" << coord[0] << ", " << coord[1] << ", " << coord[2] << ")";
+    j = k+1; if (j == n) j = 0;
+    if (j == k) {
+      if (p[1] == coord[1] && p[2] == coord[2]) {
+       inside = 1;
+      }
+      break;
+    }
+    aPoints->GetPoint(j, ncoord);
+    t = GetParameterValue(coord[1], ncoord[1], p[1]);
+    if (t >= 0.0 && t <= 1) {
+      z = coord[2] + t*(ncoord[2]-coord[2]);
+      if (z < zMin) zMin = z;
+      if (z > zMax) zMax = z;
+    }
+  }
+  //cout << endl << " Zmin = " << zMin << ", Zmax = " << zMax  << endl;
+  if (!inside) {
+    if (p[2] <= (zMax+tol) && p[2] >= (zMin-tol))
+      inside = 1;
+  }
+  
+  aPoints->Delete();
+  return inside;
+}
+
+//----------------------------------------------------------------------------
+float VTKViewer_RectPicker::IntersectWithHex(float p1[4][4], float p2[4][4], float tol, 
+                                            vtkAssemblyPath *path, vtkProp3D *prop3D, 
+                                            vtkAbstractMapper3D *mapper)
+{
+  int i, k;
+  float *center, p0[3], ray[3], rayFactor, t;
+
+  // Get the data from the modeler
+  //
+  center = mapper->GetCenter();
+
+  if (!PointInside(center, p1, p2)) {
+    return 2.0;
+  }
+
+  //   Determine appropriate info
+  //
+  for (i = 0; i < 3; i++) {
+    p0[i] = ray[i] = 0;
+    for (k = 0; k < 4; k++) {
+      p0[i] += p1[k][i];
+      ray[i] += p2[k][i];
+    }
+    p0[i] = p0[i]/4;
+    ray[i] = ray[i]/4;
+    ray[i] = ray[i] - p0[i];
+  }
+  if (( rayFactor = vtkMath::Dot(ray,ray)) == 0.0 ) {
+    vtkErrorMacro("Cannot process points");
+    return 2.0;
+  }
+
+  // Project the center point onto the ray and determine its parametric value
+  //
+  t = (ray[0]*(center[0]-p0[0]) + ray[1]*(center[1]-p0[1])
+       + ray[2]*(center[2]-p0[2])) / rayFactor;
+
+  if ( t >= 0.0 && t <= 1.0 && t < this->GlobalTMin ) {
+    this->MarkPicked(path, prop3D, mapper, t, center);
+  }
+  return t;
+}
diff --git a/src/VTKViewer/VTKViewer_RectPicker.h b/src/VTKViewer/VTKViewer_RectPicker.h
new file mode 100644 (file)
index 0000000..44b7e07
--- /dev/null
@@ -0,0 +1,84 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : VTKViewer_RectPicker.h
+//  Author : Natalia KOPNOVA
+//  Module : SALOME
+
+#ifndef __VTKViewer_RectPicker_h
+#define __VTKViewer_RectPicker_h
+
+#include <vtkPicker.h>
+
+class VTK_EXPORT VTKViewer_RectPicker : public vtkPicker
+{
+public:
+  static VTKViewer_RectPicker *New();
+  vtkTypeMacro(VTKViewer_RectPicker,vtkPicker);
+  
+  // Description:
+  // Perform pick operation with selection rectangle provided. Normally the 
+  // first two values for the selection top-left and right-bottom points are 
+  // x-y pixel coordinate, and the third value is =0. 
+  // Return non-zero if something was successfully picked.
+  virtual int Pick(float selectionX1, float selectionY1, float selectionZ1, 
+                  float selectionX2, float selectionY2, float selectionZ2,
+                   vtkRenderer *renderer);  
+
+  // Description: 
+  // Perform pick operation with selection rectangle provided. Normally the first
+  // two values for the selection top-left and right-bottom points are x-y pixel 
+  // coordinate, and the third value is =0. 
+  // Return non-zero if something was successfully picked.
+  int Pick(float selectionPt1[3], float selectionPt2[3], vtkRenderer *ren)
+    {return this->Pick(selectionPt1[0], selectionPt1[1], selectionPt1[2], 
+                      selectionPt2[0], selectionPt2[1], selectionPt2[2],
+                      ren);};
+
+  // Description:
+  // Bounding box intersection with hexahedron. The method returns a non-zero value 
+  // if the bounding box is hit. Origin[4][4] starts the ray from corner points, 
+  // dir[4][3] is the vector components of the ray in the x-y-z directions. 
+  // (Notes: the intersection ray dir[4][3] is NOT normalized.)
+  static char HitBBox(float bounds[6], float origin[4][4], float dir[4][3]);
+
+  // Description:
+  // Position of point relative to hexahedron. The method returns a non-zero value 
+  // if the point is inside. p1[4][4] is the corner points of top face, 
+  // p2[4][4] is the corner points of bottom face. 
+  static char PointInside(float point[3], float p1[4][4], float p2[4][4], float tol=0);
+
+protected:
+  VTKViewer_RectPicker();
+  ~VTKViewer_RectPicker() {};
+
+  virtual float IntersectWithHex(float p1[4][4], float p2[4][4], float tol, 
+                          vtkAssemblyPath *path, vtkProp3D *p, 
+                          vtkAbstractMapper3D *m);
+
+private:
+};
+
+#endif
+
+
index 6aef5fb7a242feb60b446abab31af2dde50731b2..46e3dba3f6085e15f3d82125a985b9c28e3534f3 100644 (file)
@@ -26,6 +26,7 @@
 //  Module : SALOME
 //  $Header$
 
+using namespace std;
 #include "VTKViewer_RenderWindow.h"
 #include "utilities.h"
 #include "QAD_Settings.h"
@@ -45,7 +46,6 @@
 #include <vtkRendererCollection.h>
 #include <vtkXOpenGLRenderWindow.h>
 #include <vtkCamera.h>
-using namespace std;
 
 //#include <GL/gl.h>
 //#include <GL/glu.h>
@@ -194,8 +194,10 @@ void VTKViewer_RenderWindow::onChangeBackgroundColor()
   QColor selColor = QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL );    
   if ( selColor.isValid() ) {
     theRenderer->SetBackground( selColor.red()/255., selColor.green()/255., selColor.blue()/255. ); 
+    /* VSR : PAL5420 ---------------------------------------------------
     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorRed",   selColor.red() );
     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorGreen", selColor.green() );
     QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorBlue",  selColor.blue() );
+    VSR : PAL5420 --------------------------------------------------- */
   }
 }
index 2e4ce4b961dcb5fb8b46b4256e109f7f83cc8b8d..9658ef5e52e8506d57dc2e2123c4dd9323d5b4b1 100644 (file)
@@ -33,7 +33,7 @@
 #include "QAD_Application.h"
 #include "QAD_Desktop.h"
 
-#include "SALOME_Selection.h"
+//#include "SALOME_Selection.h"
 #include "SALOME_Actor.h"
 
 #include <stdio.h>
@@ -147,6 +147,9 @@ void VTKViewer_RenderWindowInteractor::Initialize() {
   //
   this->Initialized = 1 ;
 
+  myTolNodes = 0.025;
+  myTolItems = 0.001;
+
   Cell_Actor = vtkActor::New(); 
   Cell_Actor->PickableOff();
   Cell_Actor->GetProperty()->SetColor(1,1,0);
@@ -175,32 +178,63 @@ void VTKViewer_RenderWindowInteractor::SetInteractorStyle(vtkInteractorObserver
 }
 
 
-void VTKViewer_RenderWindowInteractor::SetSelectionMode(int mode)
+void VTKViewer_RenderWindowInteractor::SetSelectionMode(Selection_Mode mode)
 {
   Cell_Actor->VisibilityOff();
   Edge_Actor->VisibilityOff();
   Point_Actor->VisibilityOff();
 
   selectionmode = mode;
-  if ( mode == 1 ) {
+  if ( mode == NodeSelection ) {
     vtkPointPicker* thepicker = vtkPointPicker::New();
-    //    thepicker->SetTolerance(0.001);
+    thepicker->SetTolerance(myTolNodes);
     this->SetPicker(thepicker);
-  } else if ( mode == 2 ) {
+  } else if ( mode == EdgeOfCellSelection ) {
     vtkCellPicker* thepicker = vtkCellPicker::New();
-    thepicker->SetTolerance(0.001);
+    thepicker->SetTolerance(myTolItems);
     this->SetPicker(thepicker);
-  } else if ( mode == 3 ) {
+  } else if ( mode == CellSelection || mode == EdgeSelection || 
+             mode == FaceSelection || mode == VolumeSelection ) {
     vtkCellPicker* thepicker = vtkCellPicker::New();
-    thepicker->SetTolerance(0.001); 
+    thepicker->SetTolerance(myTolItems); 
     this->SetPicker(thepicker);
-  } else if ( mode == 4 ) {
+  } else if ( mode == ActorSelection ) {
     vtkPicker* thepicker = vtkPicker::New();
-    thepicker->SetTolerance(0.001);
+    thepicker->SetTolerance(myTolItems);
     this->SetPicker(thepicker);
   }
+
+  VTKViewer_InteractorStyleSALOME* Style = 0;
+  if (this->InteractorStyle->IsA("VTKViewer_InteractorStyleSALOME"))
+    Style = VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
+  else 
+    return;
+  Style->OnSelectionModeChanged();
 }
 
+void VTKViewer_RenderWindowInteractor::SetSelectionProp(const double& theRed, const double& theGreen, 
+                                                       const double& theBlue, const int& theWidth) 
+{
+  Cell_Actor->GetProperty()->SetColor(theRed, theGreen, theBlue);
+  Cell_Actor->GetProperty()->SetLineWidth(theWidth);
+
+  Point_Actor->GetProperty()->SetColor(theRed, theGreen, theBlue);
+  Point_Actor->GetProperty()->SetPointSize(theWidth);
+}
+
+void VTKViewer_RenderWindowInteractor::SetSelectionTolerance(const double& theTolNodes, const double& theTolItems)
+{
+  myTolNodes = theTolNodes;
+  myTolItems = theTolItems;
+  if (this->GetPicker()->IsA("vtkPointPicker")) {
+    vtkPointPicker* picker = vtkPointPicker::SafeDownCast(this->GetPicker());
+    picker->SetTolerance(theTolNodes);
+  }
+  else if (this->GetPicker()->IsA("vtkPicker")) {
+    vtkPicker* picker = vtkPicker::SafeDownCast(this->GetPicker());
+    picker->SetTolerance(theTolItems);
+  }
+}
 
 void VTKViewer_RenderWindowInteractor::Enable() {
   //
@@ -604,13 +638,31 @@ void VTKViewer_RenderWindowInteractor::DisplayAll()
   emit RenderWindowModified() ;
 }
 
+void VTKViewer_RenderWindowInteractor::Erase( SALOME_Actor* SActor, bool update)
+{
+  SActor->SetVisibility( false );
+
+  // Erase dependent actors
+  vtkActorCollection* theChildActors = vtkActorCollection::New(); 
+  SActor->GetChildActors(theChildActors);
+
+  theChildActors->InitTraversal();
+  vtkActor *ac = theChildActors->GetNextActor();
+  while(!(ac==NULL)) {
+    ac->SetVisibility( false );
+    ac = theChildActors->GetNextActor();
+  }
+
+  if (update) 
+    emit RenderWindowModified();
+}
+
 void VTKViewer_RenderWindowInteractor::Erase(const Handle(SALOME_InteractiveObject)& IObject, bool update)
 {
   vtkRenderer* aren;
   for (this->RenderWindow->GetRenderers()->InitTraversal(); 
        (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
     vtkActorCollection* theActors = aren->GetActors();
-    vtkActorCollection* theChildActors = vtkActorCollection::New(); 
     theActors->InitTraversal();
     vtkActor *ac = theActors->GetNextActor();
     while(!(ac==NULL)) {
@@ -618,21 +670,12 @@ void VTKViewer_RenderWindowInteractor::Erase(const Handle(SALOME_InteractiveObje
        SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
        if ( anActor->hasIO() ) {
          if ( IObject->isSame( anActor->getIO() ) ) {
-           anActor->SetVisibility( false );
-           anActor->GetChildActors(theChildActors);
+           Erase(anActor, false);
          }
        }
       }
       ac = theActors->GetNextActor();
     }
-
-    // Erase dependent actors
-    theChildActors->InitTraversal();
-    ac = theChildActors->GetNextActor();
-    while(!(ac==NULL)) {
-      ac->SetVisibility( false );
-      ac = theChildActors->GetNextActor();
-    }
   } 
   if (update)
     emit RenderWindowModified() ;
@@ -828,14 +871,14 @@ bool VTKViewer_RenderWindowInteractor::unHighlightAll(){
   aRenColl->InitTraversal();
   while(vtkRenderer* aRen = this->RenderWindow->GetRenderers()->GetNextItem()){
     vtkActorCollection* theActors = aRen->GetActors();
-    theActors->InitTraversal();
     if(theActors->IsItemPresent(Point_Actor)) 
       aRen->RemoveActor(Point_Actor);
     if(theActors->IsItemPresent(Edge_Actor)) 
       aRen->RemoveActor(Edge_Actor); 
     if(theActors->IsItemPresent(Cell_Actor)) 
       aRen->RemoveActor(Cell_Actor);
-    vtkActor *anActor = theActors->GetNextActor();
+
+    theActors->InitTraversal();
     while(vtkActor *anAct = theActors->GetNextActor()) {
       if(SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(anAct)){
        if(anActor->hasIO()){
@@ -995,43 +1038,54 @@ bool VTKViewer_RenderWindowInteractor::highlight(const Handle(SALOME_Interactive
                                                 vtkActor *theActor, bool hilight, bool update )
 {
   if(MapIndex.Extent() == 0) return false;
-  vtkRenderer* aRen;
-  this->RenderWindow->GetRenderers()->InitTraversal();
-  for (; aRen = this->RenderWindow->GetRenderers()->GetNextItem(); ) {
-    vtkActorCollection* anActorColl = aRen->GetActors();
-    if ( anActorColl->IsItemPresent(theActor) != 0 ) 
-      aRen->RemoveActor(theActor);
-    anActorColl->InitTraversal();
-    vtkActor *ac = NULL;
-    for(; (ac = anActorColl->GetNextActor()) != NULL; ){
-      if(ac->IsA("SALOME_Actor")){
-       SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(ac);
-       if(anActor->hasIO()){
-         if(IObject->isSame(anActor->getIO())){
-           if(vtkPolyData* aSourcePolyData = anActor->GetPolyDataInput()){
-             vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New();
-             (*theFun)(aSourcePolyData,aMapper,MapIndex);
-             theActor->SetMapper(aMapper);   
-             aMapper->Delete();
-             if(anActorColl->IsItemPresent(theActor) == 0) 
-               aRen->AddActor(theActor);             
-             if(hilight)
-               theActor->VisibilityOn();
-             else
-               theActor->VisibilityOff();
-             break;
-           }
-         }
-       }
-      }
-    }
+  vtkRenderer* aRen = GetRenderer();
+  vtkActorCollection* anActorColl = aRen->GetActors();
+  if ( anActorColl->IsItemPresent(theActor) != 0 ) 
+    aRen->RemoveActor(theActor);
+  
+  if (hilight) {
+    setActorData(IObject, MapIndex, theFun, theActor);
+    aRen->AddActor(theActor);        
+    theActor->VisibilityOn();
+  }
+  else {
+    theActor->VisibilityOff();
   }
+
   if(update){
     this->RenderWindow->Render();  
     emit RenderWindowModified() ;
   }
+
   return false;
 }
+  
+void VTKViewer_RenderWindowInteractor::setActorData(const Handle(SALOME_InteractiveObject)& IObject,
+                                                   const TColStd_MapOfInteger& MapIndex, 
+                                                   VTKViewer_RenderWindowInteractor::TCreateMapperFun theFun,
+                                                   vtkActor* theActor)
+{
+  vtkActorCollection* anActorColl = GetRenderer()->GetActors();
+  anActorColl->InitTraversal();
+  vtkActor *ac = NULL;
+  while ((ac = anActorColl->GetNextActor()) != NULL) {
+    if (ac->IsA("SALOME_Actor")){
+      SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(ac);
+      if (anActor->hasIO()) {
+       if (IObject->isSame(anActor->getIO())) {
+         if (vtkPolyData* aSourcePolyData = anActor->GetPolyDataInput()) {
+           vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New();
+           (*theFun)(aSourcePolyData,aMapper,MapIndex);
+           theActor->SetMapper(aMapper);   
+           aMapper->Delete();
+           break;
+         }
+       }
+      }
+    }
+  }
+}
+
 
 static void CellCreateMapper(vtkPolyData *theSourcePolyData, vtkPolyDataMapper* theMapper, 
                      const TColStd_MapOfInteger& theMapIndex)
@@ -1041,7 +1095,7 @@ static void CellCreateMapper(vtkPolyData *theSourcePolyData, vtkPolyDataMapper*
 
   vtkIdList *ptIds = vtkIdList::New(); 
   ptIds->Allocate(theSourcePolyData->GetMaxCellSize());
-  vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New();
+  //  vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New();
   aPolyData->SetPoints(theSourcePolyData->GetPoints());
   TColStd_MapIteratorOfMapOfInteger ite(theMapIndex);
   int aNbOfParts = theSourcePolyData->GetNumberOfCells();
@@ -1068,6 +1122,23 @@ bool VTKViewer_RenderWindowInteractor::highlightCell(const Handle(SALOME_Interac
 {
   return highlight(IObject,MapIndex,&CellCreateMapper,Cell_Actor,hilight,update);
 }
+  
+void VTKViewer_RenderWindowInteractor::setCellData(const Handle(SALOME_InteractiveObject)& IObject, 
+                                                  const int& theIndex, vtkActor* theActor )
+{
+  TColStd_MapOfInteger MapIndex; MapIndex.Add(theIndex);
+  return setActorData(IObject,MapIndex,&CellCreateMapper,theActor);
+}
+  
+void VTKViewer_RenderWindowInteractor::setCellData(const Handle(SALOME_InteractiveObject)& IObject, 
+                                                  const std::vector<int>& theIndexes, vtkActor* theActor )
+{
+  TColStd_MapOfInteger MapIndex; 
+  std::vector<int>::const_iterator it;
+  for (it = theIndexes.begin(); it != theIndexes.end(); ++it)
+    MapIndex.Add(*it);
+  return setActorData(IObject,MapIndex,&CellCreateMapper,theActor);
+}
 
 
 static void PointCreateMapper(vtkPolyData *theSourcePolyData, vtkPolyDataMapper* theMapper, 
@@ -1101,6 +1172,14 @@ bool VTKViewer_RenderWindowInteractor::highlightPoint(const Handle(SALOME_Intera
 {
   return highlight(IObject,MapIndex,&PointCreateMapper,Point_Actor,hilight,update);
 }
+  
+  
+void VTKViewer_RenderWindowInteractor::setPointData(const Handle(SALOME_InteractiveObject)& IObject, 
+                                                   const int& theIndex, vtkActor* theActor )
+{
+  TColStd_MapOfInteger MapIndex; MapIndex.Add(theIndex);
+  return setActorData(IObject,MapIndex,&PointCreateMapper,theActor);
+}
 
   
 static void EdgeCreateMapper(vtkPolyData *theSourcePolyData, vtkPolyDataMapper* theMapper, 
@@ -1160,3 +1239,11 @@ bool VTKViewer_RenderWindowInteractor::highlightEdge( const Handle(SALOME_Intera
 {
   return highlight(IObject,MapIndex,&EdgeCreateMapper,Edge_Actor,hilight,update);
 }
+  
+void VTKViewer_RenderWindowInteractor::setEdgeData(const Handle(SALOME_InteractiveObject)& IObject, 
+                                                  const int& theCellIndex, const int& theEdgeIndex, 
+                                                  vtkActor* theActor )
+{
+  TColStd_MapOfInteger MapIndex; MapIndex.Add(theCellIndex); MapIndex.Add(theEdgeIndex);
+  return setActorData(IObject,MapIndex,&EdgeCreateMapper,theActor);
+}
index e5fa4088529c8953db29d6d2f77083117cc0e8e7..3a22e676aa2093cbfa04b50c2be6bfaafcc58723 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "SALOME_InteractiveObject.hxx"
 #include "SALOME_Actor.h"
+#include "SALOME_Selection.h"
 
 // QT Includes
 #include <qobject.h>
@@ -141,8 +142,20 @@ public:
   bool isVisible( const Handle(SALOME_InteractiveObject)& IObject);
   void rename(const Handle(SALOME_InteractiveObject)& IObject, QString newName);
 
-
-  void SetSelectionMode(int mode);
+  void SetSelectionMode(Selection_Mode mode);
+  void SetSelectionProp(const double& theRed = 1, const double& theGreen = 1,
+                       const double& theBlue = 0, const int& theWidth = 5);
+  void SetSelectionTolerance(const double& theTolNodes = 0.025, const double& theTolCell = 0.001);
+
+  void setCellData(const Handle(SALOME_InteractiveObject)& IObject,
+                  const int& theIndex, vtkActor* theActor );
+  void setCellData(const Handle(SALOME_InteractiveObject)& IObject,
+                  const std::vector<int>& theIndexes, vtkActor* theActor );
+  void setEdgeData(const Handle(SALOME_InteractiveObject)& IObject,
+                  const int& theCellIndex, const int& theEdgeIndex, 
+                  vtkActor* theActor ); //NB
+  void setPointData(const Handle(SALOME_InteractiveObject)& IObject, 
+                   const int& theIndex, vtkActor* theActor );
 
   // Displaymode management
   int GetDisplayMode();
@@ -167,6 +180,7 @@ public:
   void Display(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly=true);
 
   void Display( SALOME_Actor* SActor, bool immediatly = true );
+  void Erase( SALOME_Actor* SActor, bool immediatly = true );
 
   // Transparency
   void SetTransparency(const Handle(SALOME_InteractiveObject)& IObject,float trans);
@@ -196,6 +210,9 @@ public:
   bool highlight(const Handle(SALOME_InteractiveObject)& IObject, 
                 const TColStd_MapOfInteger& MapIndex, TCreateMapperFun theFun,
                 vtkActor *theActor, bool hilight, bool update );
+  void setActorData(const Handle(SALOME_InteractiveObject)& IObject, 
+                   const TColStd_MapOfInteger& MapIndex, TCreateMapperFun theFun,
+                   vtkActor *theActor );
 
   // Timer used during various mouse events to figure 
   // out mouse movements. 
@@ -205,7 +222,7 @@ public:
   int displaymode;
 
   //NRI: Selection mode
-  int selectionmode;
+  Selection_Mode selectionmode;
   vtkActor* Point_Actor;
   vtkActor* Edge_Actor; //NB
   vtkActor* Cell_Actor;
@@ -243,6 +260,8 @@ public:
 
  private:
   QWidget*     myGUIWindow;  
+  double       myTolNodes;
+  double       myTolItems;
 };
 
 #endif
index be2d1889461fefb4f683091820e869289107415f..9a278d4a6b764c7419120f4336599f98dec6f58c 100644 (file)
@@ -63,6 +63,7 @@ public:
 
 protected:
   VTKViewer_UnScaledActor();
+  ~VTKViewer_UnScaledActor(){}
   int mySize;
 };
 
@@ -82,8 +83,12 @@ void VTKViewer_UnScaledActor::Render(vtkRenderer *theRenderer){
     float aWinDiag = sqrt(float(aSize[0]*aSize[0]+aSize[1]*aSize[1]));
     vtkDataSet* aDataSet = GetMapper()->GetInput();
     float aLength = aDataSet->GetLength();
+    float aPrecision = 1.0E-3;
+    float anOldScale = GetScale()[0];
     float aScale = mySize*aWorldDiag/aWinDiag/aLength*sqrt(float(aSize[0])/float(aSize[1]));
-    SetScale(aScale);
+    if(fabs(aScale - anOldScale)/aScale > aPrecision){
+      SetScale(aScale);
+    }
   }
   vtkFollower::Render(theRenderer);
 }
@@ -94,6 +99,50 @@ void VTKViewer_UnScaledActor::SetSize(int theSize){
 
 //==============================================================================
 
+class VTKViewer_LineActor: public vtkFollower{
+  VTKViewer_LineActor(const VTKViewer_LineActor&);
+
+public:
+  vtkTypeMacro(VTKViewer_LineActor,vtkFollower);
+  static VTKViewer_LineActor *New();
+
+  void SetLabelActor(VTKViewer_UnScaledActor* theLabelActor);
+  void SetArrowActor(VTKViewer_UnScaledActor* theLabelActor);
+  virtual void Render(vtkRenderer *theRenderer);
+
+protected:
+  VTKViewer_LineActor(){
+    LabelActor = NULL;
+    ArrowActor = NULL;
+  }
+  ~VTKViewer_LineActor(){
+    SetLabelActor(NULL);
+    SetArrowActor(NULL);
+  }
+
+  VTKViewer_UnScaledActor* LabelActor;
+  VTKViewer_UnScaledActor* ArrowActor;
+};
+
+vtkStandardNewMacro(VTKViewer_LineActor);
+
+vtkCxxSetObjectMacro(VTKViewer_LineActor,LabelActor,VTKViewer_UnScaledActor);
+vtkCxxSetObjectMacro(VTKViewer_LineActor,ArrowActor,VTKViewer_UnScaledActor);
+
+void VTKViewer_LineActor::Render(vtkRenderer *theRenderer){
+  if(LabelActor && LabelActor->GetVisibility()){
+    LabelActor->Modified();
+    LabelActor->Render(theRenderer);
+  }
+  if(ArrowActor && ArrowActor->GetVisibility()){
+    ArrowActor->Modified();
+    ArrowActor->Render(theRenderer);
+  }
+  vtkFollower::Render(theRenderer);
+}
+
+//==============================================================================
+
 // The base class for concreate Axis
 // Its only duty is to give correct initialization and destruction
 //   of its pipe-lines
@@ -106,9 +155,10 @@ protected:
   vtkTypeMacro(VTKViewer_Axis,vtkObject);
   
   virtual void AddToRender(vtkRenderer* theRenderer){
+    //Order of the calls are important
+    theRenderer->AddActor(myLineActor);
     theRenderer->AddActor(myLabelActor);
     theRenderer->AddActor(myArrowActor);
-    theRenderer->AddActor(myLineActor);
   }
 
   virtual void SetVisibility(VTKViewer_Trihedron::TVisibility theVis);
@@ -140,7 +190,8 @@ protected:
   VTKViewer_Trihedron::TVisibility myVisibility;
   float myDir[3], myRot[3];
 
-  vtkActor *myLineActor;
+  VTKViewer_LineActor *myLineActor;
+  //vtkActor *myLineActor;
   VTKViewer_UnScaledActor *myArrowActor;
   VTKViewer_UnScaledActor *myLabelActor;
 
@@ -158,7 +209,7 @@ VTKViewer_Axis::VTKViewer_Axis(){
   myMapper[0] = vtkPolyDataMapper::New();
   myMapper[0]->SetInput(myLineSource->GetOutput());
 
-  myLineActor = vtkActor::New();
+  myLineActor = VTKViewer_LineActor::New();
   myLineActor->SetMapper(myMapper[0]);
   myLineActor->PickableOff();
 
@@ -176,6 +227,8 @@ VTKViewer_Axis::VTKViewer_Axis(){
   myArrowActor->SetSize(aArrowActorSize);
   myArrowActor->PickableOff();
 
+  myLineActor->SetArrowActor(myArrowActor);
+
   // Initialize the Label pipe-line representation
   myVectorText = VTKViewer_VectorText::New();
 
@@ -187,6 +240,9 @@ VTKViewer_Axis::VTKViewer_Axis(){
   static int aLabelActorSize = 12;
   myLabelActor->SetSize(aLabelActorSize);
   myLabelActor->PickableOff();
+  //myLabelActor->DebugOn();
+
+  myLineActor->SetLabelActor(myLabelActor);
 
   // Initialise visibility param.
   myVisibility = VTKViewer_Trihedron::eOn;
@@ -379,12 +435,3 @@ int VTKViewer_Trihedron::GetVisibleActorCount(vtkRenderer* theRenderer){
   //SetVisibility(aVis);
   return aCount;
 }
-
-void VTKViewer_Trihedron::Render(vtkRenderer* theRenderer){
-  for(int i = 0; i < 3; i++)
-    {
-      myAxis[i]->GetLabel()->Render(theRenderer);
-      myAxis[i]->GetArrow()->Render(theRenderer);
-    }
-}
-
index 056ea158f23f74d47b2650f98838a80ced7faa39..d53a602c32a8b1d23c54f1e87bb8644cdd07e184 100644 (file)
@@ -58,8 +58,6 @@ class VTKViewer_Trihedron : public vtkObject{
 
   virtual int GetVisibleActorCount(vtkRenderer* theRenderer);
   
-  virtual void  Render(vtkRenderer *theRenderer);
-  
 protected:
   vtkActorCollection* myPresent;
   VTKViewer_Axis* myAxis[3];
index ce64a1e4c835805881ebf4cf3a151932dfd494cb..b8b61997f5b29f0c66785ec5343b0ee608d9dae0 100644 (file)
@@ -52,7 +52,7 @@ void ResetCamera(vtkRenderer* theRenderer, int theUsingZeroFocalPoint){
     if ( theRenderer->GetActiveCamera() != NULL )
       theRenderer->GetActiveCamera()->GetViewPlaneNormal(vn);
     else{
-      INFOS("Trying to reset non-existant camera");
+      MESSAGE("Trying to reset non-existant camera");
       return;
     }
     
index 4e059ce38461a490b152d42570398b051e8aa971..b68158db7374a2b735edf84261a5794d334119d9 100644 (file)
 #include "VTKViewer_Utilities.h"
 #include "VTKViewer_Trihedron.h"
 #include "VTKViewer_RenderWindow.h"
-//#include "VTKViewer_InteractorStyleSALOME.h"
+#include "VTKViewer_InteractorStyleSALOME.h"
 
 #include "SALOME_Transform.h"
 #include "SALOME_TransformFilter.h"
-#include "SALOME_PassThroughFilter.h"
 #include "SALOME_GeometryFilter.h"
 
 #include "QAD_Settings.h"
@@ -43,7 +42,6 @@
 #include "QAD_Desktop.h"
 #include "SALOME_Selection.h"
 #include "SALOME_InteractiveObject.hxx"
-#include "VTKViewer_InteractorStyleSALOME.h"
 
 #include "utilities.h"
 
@@ -169,10 +167,10 @@ void VTKViewer_ViewFrame::onAdjustTrihedron(){
     float aSize = m_Triedron->GetSize();
     float aNewSize = aLength*aSizeInPercents/100.0;
     // if the new trihedron size have sufficient difference, then apply the value
-    if(fabs(aNewSize-aSize) > aSize*EPS_SIZE || fabs(aNewSize-aSize) > aNewSize*EPS_SIZE)
+    if(fabs(aNewSize-aSize) > aSize*EPS_SIZE || fabs(aNewSize-aSize) > aNewSize*EPS_SIZE){
       m_Triedron->SetSize(aNewSize);
+    }
   }
-  m_Triedron->Render(m_Renderer);
   ::ResetCameraClippingRange(m_Renderer);
 }
 
@@ -351,7 +349,7 @@ QColor VTKViewer_ViewFrame::backgroundColor() const
 }
 
 
-void VTKViewer_ViewFrame::SetSelectionMode( int mode )
+void VTKViewer_ViewFrame::SetSelectionMode( Selection_Mode mode )
 {
   m_RWInteractor->SetSelectionMode( mode );
 }
@@ -372,31 +370,33 @@ void VTKViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IOb
 {
   QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
   SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() );
-  if ( Sel->SelectionMode() == 4 )
-    m_RWInteractor->highlight(IObject, highlight, update);
-  else if ( Sel->SelectionMode() == 3 ) {
-    m_RWInteractor->highlight(IObject, highlight, update);
+  m_RWInteractor->highlight(IObject, highlight, update);
+
+  switch (Sel->SelectionMode()) {
+  case NodeSelection:
     if ( Sel->HasIndex( IObject ) ) {
       TColStd_MapOfInteger MapIndex;
       Sel->GetIndex( IObject, MapIndex );
-      m_RWInteractor->highlightCell(IObject, highlight, MapIndex, update);
+      m_RWInteractor->highlightPoint(IObject, highlight, MapIndex, update);
     }
-  } 
-  else if ( Sel->SelectionMode() == 2 ) {
-    m_RWInteractor->highlight(IObject, highlight, update);
+    break;
+  case EdgeOfCellSelection:
     if ( Sel->HasIndex( IObject ) ) {
       TColStd_MapOfInteger MapIndex;
       Sel->GetIndex( IObject, MapIndex );
       m_RWInteractor->highlightEdge(IObject, highlight, MapIndex, update);
     }
-  }
-  else if ( Sel->SelectionMode() == 1 ) {
-    m_RWInteractor->highlight(IObject, highlight, update);
+    break;
+  case CellSelection:
+  case EdgeSelection:
+  case FaceSelection:
+  case VolumeSelection:
     if ( Sel->HasIndex( IObject ) ) {
       TColStd_MapOfInteger MapIndex;
       Sel->GetIndex( IObject, MapIndex );
-      m_RWInteractor->highlightPoint(IObject, highlight, MapIndex, update);
+      m_RWInteractor->highlightCell(IObject, highlight, MapIndex, update);
     }
+    break;
   }
 }
 
@@ -622,5 +622,3 @@ void VTKViewer_ViewFrame::RemoveActor( SALOME_Actor* theActor, bool update /*=fa
   theActor->RemoveFromRender(m_Renderer);
   if(update) Repaint();
 }
-
-
index 83fc35ab1feb680b404e48efa4dded7804bfc75c..5547699faffb714c50d91cad05837a62dc88e0e6 100644 (file)
@@ -58,7 +58,7 @@ class QAD_EXPORT VTKViewer_ViewFrame : public QAD_ViewFrame{
   void                           setBackgroundColor( const QColor& );
   QColor                         backgroundColor() const;
   
-  void                           SetSelectionMode( int mode );
+  void                           SetSelectionMode( Selection_Mode mode );
 
   /*  popup management */
   void                           setPopupServer( QAD_Application* );