Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/visu.git] / src / VISUGUI / VisuGUI_StreamLinesDlg.cxx
index 1fe7f08358f05613133ae85c135353d2c9dd18c2..e6fa3cc2990d31d80e38b22352cb6d40a2045515 100644 (file)
@@ -11,7 +11,7 @@
 #include "VisuGUI_StreamLinesDlg.h"
 
 #include "VisuGUI.h"
-//#include "VisuGUI_Selection.h"
+#include "VisuGUI_Tools.h"
 
 #include "VISU_Mesh_i.hh"
 #include "VISU_Gen_i.hh"
@@ -20,7 +20,9 @@
 #include "VISU_Actor.h"
 
 #include "SalomeApp_Application.h"
-#include "SalomeApp_SelectionMgr.h"
+#include "LightApp_SelectionMgr.h"
+
+#include "SVTK_ViewWindow.h"
 
 #include "SUIT_Desktop.h"
 #include "SUIT_ResourceMgr.h"
@@ -28,7 +30,7 @@
 
 #include "SALOME_ListIO.hxx"
 
-#include "SVTK_ViewWindow.h"
+#include <SALOMEDSClient_SObject.hxx>
 
 #include <limits.h>
 #include <qlayout.h>
 #include <qcolordialog.h>
 #include <qtabwidget.h>
 
-#include <SALOMEDSClient_SObject.hxx>
-#include <SALOMEDS_SObject.hxx>
-
 using namespace std;
 
-VisuGUI_StreamLinesDlg::VisuGUI_StreamLinesDlg (QWidget* parent)
-     : QDialog(parent, "VisuGUI_StreamLinesDlg", false,
-               WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
+VisuGUI_StreamLinesDlg::VisuGUI_StreamLinesDlg (SalomeApp_Module* theModule)
+     : QDialog(VISU::GetDesktop(theModule), "VisuGUI_StreamLinesDlg", false,
+               WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
+       myVisuGUI(theModule)
 {
   myPrs = NULL;
-  setCaption("Stream lines Preferences");
-  setSizeGripEnabled( TRUE );
+  setCaption(tr("DLG_TITLE"));
+  setSizeGripEnabled(TRUE);
 
   QVBoxLayout* aBoxLayout = new QVBoxLayout(this);
   aBoxLayout->setSpacing( 6 );
@@ -63,7 +63,7 @@ VisuGUI_StreamLinesDlg::VisuGUI_StreamLinesDlg (QWidget* parent)
   TopLayout->setMargin( 11 );
 
   // Source box
-  QGroupBox* aSourceBox = new QGroupBox(tr("Source"), aTopBox);
+  QGroupBox* aSourceBox = new QGroupBox (tr("SOURCE_GRP"), aTopBox);
   aSourceBox->setColumnLayout(0, Qt::Vertical);
   QGridLayout* aSrcLayout = new QGridLayout( aSourceBox->layout() );
   aSrcLayout->setSpacing( 6 );
@@ -82,88 +82,131 @@ VisuGUI_StreamLinesDlg::VisuGUI_StreamLinesDlg (QWidget* parent)
 
   connect(myUseSrcCombo, SIGNAL(activated(int)), this, SLOT(onSourceTypeChange(int)));
 
-  // Find All prs obj
-/*
-  SUIT_Study* aActiveStudy =  VisuGUI::GetActiveStudy();
-  SalomeApp_SelectionMgr* aSel = VisuGUI::application()->selectionMgr();
-  SALOME_ListIO selected; aSel->selectedObjects( selected );
-  if( selected.Extent() > 0 ) {
+  // Find all fields and time stamps on it
+  _PTR(Study) aActiveStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
+  LightApp_SelectionMgr* aSel = VISU::GetSelectionMgr(myVisuGUI);
+  SALOME_ListIO selected;
+  aSel->selectedObjects(selected);
+  if (selected.Extent() > 0) {
     Handle(SALOME_InteractiveObject) aIO = selected.First();
-    if (aIO->hasEntry()){
-      SALOMEDSClient_SObject* aSObject = VisuGUI::GetStudyDocument()->FindObjectID(aIO->getEntry());
-      aSObject = aSObject->GetFather();
-      aSObject = aSObject->GetFather();
+    if (aIO->hasEntry()) {
+      _PTR(SObject) aSObject = aActiveStudy->FindObjectID(aIO->getEntry());
+
+      _PTR(GenericAttribute) anTmpAttr;
+      if (aSObject->FindAttribute(anTmpAttr, "AttributeComment")) {
+        _PTR(AttributeComment) aTmpComment (anTmpAttr);
+        string aTmpComm = aTmpComment->Value();
+        QString aTmpstrIn (aTmpComm.c_str());
+        VISU::Storable::TRestoringMap aTmpaMap;
+        VISU::Storable::StrToMap(aTmpstrIn,aTmpaMap);
+        bool aTmpisExist;
+        VISU::VISUType aTmpType =
+          (VISU::VISUType)VISU::Storable::FindValue(aTmpaMap,"myType",&aTmpisExist).toInt();
+        switch (aTmpType) {
+        case VISU::TTIMESTAMP:
+          {
+            aSObject = aSObject->GetFather();
+            aSObject = aSObject->GetFather();
+            break;
+          }
+        case VISU::TFIELD:
+          {
+            _PTR(SObject) newSObject;
+            if(aSObject->ReferencedObject(newSObject)) aSObject = newSObject;
+            aSObject = aSObject->GetFather();
+            break;
+          }
+        case VISU::TANIMATION:
+          {
+            _PTR(ChildIterator) aTmpIter = aActiveStudy->NewChildIterator(aSObject);
+            for (aTmpIter->InitEx(true); aTmpIter->More(); aTmpIter->Next()) {
+              _PTR(SObject) aTmpChildSObj = aTmpIter->Value();
+              _PTR(SObject) newSObject;
+              if(aTmpChildSObj->ReferencedObject(newSObject)){
+                aSObject = newSObject;
+                aSObject->GetFather();
+                break;
+              }
+            }
+            break;
+          }
+        }
+      }
+
       aSObject = aSObject->GetFather();
       aSObject = aSObject->GetFather();
+
       mySelectionObj = aSObject;
-      CORBA::Object_var anObject = VISU::ClientSObjectToObject( mySelectionObj );
-      VISU::Result_var aResult;
+      CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
       if (CORBA::is_nil(anObject)) {
        mySelectionObj = mySelectionObj->GetFather();
       }
-      SALOMEDSClient_ChildIterator* aIter = VisuGUI::GetStudyDocument()->NewChildIterator( mySelectionObj );
-
-      for (aIter->InitEx(true); aIter->More(); aIter->Next() ) {
-       SALOMEDSClient_SObject* aChildSObj = aIter->Value();
-       CORBA::Object_var aChildObject = VISU::ClientSObjectToObject( aChildSObj );
-
-       if(!CORBA::is_nil( aChildObject ) ) {
-         VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow( aChildObject );
-         if( !CORBA::is_nil( aPrsObj ) ) { // if this is a Prs object
-           if ((aPrsObj->GetType() != VISU::TSTREAMLINES) &&
-               (aPrsObj->GetType() != VISU::TMESH)) {
-             SALOMEDSClient_GenericAttribute* anAttr;
-             if ( aChildSObj->FindAttribute(anAttr, "AttributeName") ) {
-               SALOMEDSClient_AttributeName* aName = dynamic_cast<SALOMEDSClient_AttributeName*>( anAttr );
-               myPrsLst += QString(aName->Value());
-               myPrsList.append(aPrsObj);
-               continue;
-             }
-           }
-         }
-       }
-       // else { // This is not a Prs object
-       SALOMEDSClient_GenericAttribute* anAttr;
-       if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
-         SALOMEDSClient_AttributeComment* aComment = dynamic_cast<SALOMEDSClient_AttributeComment*>( anAttr );
-         string aComm = aComment->Value();
-         QString strIn(aComm.c_str());
-         VISU::Storable::TRestoringMap aMap;
-         VISU::Storable::StrToMap(strIn,aMap);
-         bool isExist;
-         VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
-         if (isExist) {
-           if ((aType == VISU::TFAMILY) || (aType == VISU::TGROUP) || (aType == VISU::TENTITY)) {
-             SALOMEDSClient_GenericAttribute* aNameAttr;
-             if ( aChildSObj->FindAttribute(aNameAttr, "AttributeName") ) {
-               SALOMEDSClient_AttributeName* aName = dynamic_cast<SALOMEDSClient_AttributeName*>( aNameAttr );
-               VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow( aChildObject );
-               switch(aType) {
-               case VISU::TFAMILY:
-                 myFamilisLst += QString(aName->Value());
-                 myFamilyList.append(aPrsObj);
-                 break;
-               case VISU::TGROUP:
-                 myGroupsLst += QString(aName->Value());
-                 myGroupList.append(aPrsObj);
-                 break;
-               case VISU::TENTITY:
-                 myEntitiesLst += QString(aName->Value());
-                 myEntityList.append(aPrsObj);
-                 break;
-               }
-             }
-           }
-         }
-       }
+    }
+  }
+
+  if (mySelectionObj) {
+    _PTR(ChildIterator) aIter = aActiveStudy->NewChildIterator(mySelectionObj);
+
+    for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
+      _PTR(SObject) aChildSObj = aIter->Value();
+      CORBA::Object_var aChildObject = VISU::ClientSObjectToObject(aChildSObj);
+
+      if (!CORBA::is_nil(aChildObject)) {
+        VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject);
+        if (!CORBA::is_nil(aPrsObj)) { // if this is a Prs object
+          if ((aPrsObj->GetType() != VISU::TSTREAMLINES) &&
+              (aPrsObj->GetType() != VISU::TMESH)) {
+            _PTR(GenericAttribute) anAttr;
+            if (aChildSObj->FindAttribute(anAttr, "AttributeName")) {
+              _PTR(AttributeName) aName (anAttr);
+              myPrsLst += QString(aName->Value().c_str());
+              myPrsList.append(aPrsObj);
+              continue;
+            }
+          }
+        }
+      }
+
+      _PTR(GenericAttribute) anAttr;
+      if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
+        _PTR(AttributeComment) aComment (anAttr);
+        string aComm = aComment->Value();
+        QString strIn (aComm.c_str());
+        VISU::Storable::TRestoringMap aMap;
+        VISU::Storable::StrToMap(strIn,aMap);
+        bool isExist;
+        VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
+        if (isExist) {
+          if ((aType == VISU::TFAMILY) || (aType == VISU::TGROUP) || (aType == VISU::TENTITY)) {
+            _PTR(GenericAttribute) aNameAttr;
+            if (aChildSObj->FindAttribute(aNameAttr, "AttributeName")) {
+              _PTR(AttributeName) aName (aNameAttr);
+              VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject);
+              switch (aType) {
+              case VISU::TFAMILY:
+                myFamilisLst += QString(aName->Value().c_str());
+                myFamilyList.append(aPrsObj);
+                break;
+              case VISU::TGROUP:
+                myGroupsLst += QString(aName->Value().c_str());
+                myGroupList.append(aPrsObj);
+                break;
+              case VISU::TENTITY:
+                myEntitiesLst += QString(aName->Value().c_str());
+                myEntityList.append(aPrsObj);
+                break;
+              }
+            }
+          }
+        }
       }
     }
   }
-*/
+
   //  connect(myUseSrcChk, SIGNAL(toggled(bool)), mySrcCombo, SLOT(setEnabled(bool)));
   aSrcLayout->addMultiCellWidget(mySrcCombo, 1, 1, 0, 1);
 
-  QLabel* aPercentLbl = new QLabel( tr( "Used points (0..1)" ), aSourceBox);
+  QLabel* aPercentLbl = new QLabel (tr("LBL_USED_POINTS"), aSourceBox);
   aSrcLayout->addWidget(aPercentLbl, 2, 0);
 
   myPntPercent = new QtxDblSpinBox( 0, 1, 0.1, aSourceBox );
@@ -171,29 +214,28 @@ VisuGUI_StreamLinesDlg::VisuGUI_StreamLinesDlg (QWidget* parent)
 
   TopLayout->addMultiCellWidget(aSourceBox, 0, 0, 0, 1);
 
-
-  QLabel* aStepLenLbl = new QLabel( tr( "Step Length" ), aTopBox);
+  QLabel* aStepLenLbl = new QLabel (tr("LBL_STEP_LENGTH"), aTopBox);
   TopLayout->addWidget(aStepLenLbl, 1, 0);
   myStepLen = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 0.1, aTopBox );
   myStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
   TopLayout->addWidget(myStepLen, 1, 1);
   connect(myStepLen, SIGNAL(valueChanged(double)), this, SLOT(StepLengthChanged(double)));
 
-  QLabel* aIntegStepLenLbl = new QLabel( tr( "Integration Step" ), aTopBox);
+  QLabel* aIntegStepLenLbl = new QLabel (tr("LBL_INTEGRATION_STEP"), aTopBox);
   TopLayout->addWidget(aIntegStepLenLbl, 2, 0);
   myIntegStepLen = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 0.1, aTopBox );
   myIntegStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
   TopLayout->addWidget(myIntegStepLen, 2, 1);
   connect(myIntegStepLen, SIGNAL(valueChanged(double)), this, SLOT(IntegrationStepChanged(double)));
 
-  QLabel* aPropagationLbl = new QLabel( tr( "Propagation Time" ), aTopBox);
+  QLabel* aPropagationLbl = new QLabel (tr("LBL_PROPAGATION_TIME"), aTopBox);
   TopLayout->addWidget(aPropagationLbl, 3, 0);
   myPropTime = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 1, aTopBox );
   myPropTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
   TopLayout->addWidget(myPropTime, 3, 1);
   connect(myPropTime, SIGNAL(valueChanged(double)), this, SLOT(PropagationTimeChanged(double)));
 
-  QLabel* aDirLbl = new QLabel( tr( "Direction" ),aTopBox);
+  QLabel* aDirLbl = new QLabel (tr("LBL_DIRECTION"),aTopBox);
   TopLayout->addWidget(aDirLbl, 4, 0);
   myDirCombo = new QComboBox(aTopBox);
   myDirCombo->insertItem("Forward");
@@ -201,11 +243,11 @@ VisuGUI_StreamLinesDlg::VisuGUI_StreamLinesDlg (QWidget* parent)
   myDirCombo->insertItem("Both");
   TopLayout->addWidget(myDirCombo, 4, 1);
 
-  myUseScalar = new QCheckBox( tr( "Magnitude coloring" ), aTopBox, "UseMagn" );
+  myUseScalar = new QCheckBox (tr("MAGNITUDE_COLORING_CHK"), aTopBox, "UseMagn");
   connect( myUseScalar, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
   TopLayout->addWidget(myUseScalar, 5, 0);
 
-  SelColor = new QPushButton( tr( "Use Color" ), aTopBox, "SelColor" );
+  SelColor = new QPushButton (tr("USE_COLOR_BTN"), aTopBox, "SelColor");
   connect( SelColor,     SIGNAL( clicked() ), this, SLOT( setVColor() ) );
   TopLayout->addWidget( SelColor, 5, 1);
 
@@ -244,7 +286,6 @@ VisuGUI_StreamLinesDlg::VisuGUI_StreamLinesDlg (QWidget* parent)
 }
 
 
-
 void VisuGUI_StreamLinesDlg::initFromPrsObject (VISU::StreamLines_i* thePrs)
 {
   myScalarPane->initFromPrsObject(thePrs);
@@ -377,9 +418,9 @@ int VisuGUI_StreamLinesDlg::storeToPrsObject (VISU::StreamLines_i* thePrs)
                                   aDirection);
   }
   //if (!isAccepted)
-  //  SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("VISU_WARNING"),
+  //  SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("WRN_VISU"),
   //                         tr("ERR_CANT_BUILD_PRESENTATION"),
-  //                         tr("VISU_BUT_OK"));
+  //                         tr("BUT_OK"));
   return isAccepted;
 }
 
@@ -468,7 +509,7 @@ VISU::Mesh_ptr VisuGUI_StreamLinesDlg::createMesh (VISU::VISUType theType, QStri
   if (CORBA::is_nil(aResult)) {
     SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("VISU_WARNING"),
                            tr("WRN_NO_AVAILABLE_DATA"),
-                           tr("VISU_BUT_OK"));
+                           tr("BUT_OK"));
     return VISU::Mesh::_nil();
   }
   SALOMEDSClient_ChildIterator* aIter = VisuGUI::GetStudyDocument()->NewChildIterator( mySelectionObj );
@@ -519,21 +560,21 @@ VISU::Mesh_ptr VisuGUI_StreamLinesDlg::createMesh (VISU::VISUType theType, QStri
   }
   if(!CORBA::is_nil(aMesh)){ // Create Actor
     VISU::Mesh_i* pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
-    if(VTKViewer_ViewWindow* vf = VisuGUI::GetVtkViewWindow()){
+    if(SVTK_ViewWindow* vf = VISU::GetViewWindow()){
       try{
        pPresent->SetPresentationType(VISU::POINT);
        VISU_Actor *anActor = pPresent->CreateActor();
        vf->AddActor(anActor);
       }catch(...){
-       SUIT_MessageBox::warn1 ( VisuGUI::application()->desktop(), tr ("VISU_WARNING"),
-                               tr ("ERR_CANT_CREATE_ACTOR"),
-                               tr ("VISU_BUT_OK") );
+       SUIT_MessageBox::warn1 ( VisuGUI::application()->desktop(), tr("VISU_WARNING"),
+                               tr("ERR_CANT_CREATE_ACTOR"),
+                               tr("BUT_OK") );
       }
     }
   } else {
     SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("VISU_WARNING"),
                            tr("ERR_CANT_BUILD_PRESENTATION"),
-                           tr("VISU_BUT_OK"));
+                           tr("BUT_OK"));
   }
   return aMesh._retn();
 */
@@ -541,5 +582,14 @@ VISU::Mesh_ptr VisuGUI_StreamLinesDlg::createMesh (VISU::VISUType theType, QStri
 
 void VisuGUI_StreamLinesDlg::accept() {
   if (myScalarPane->check())
-    QDialog::accept();
+    {
+      myScalarPane->deletePreview();
+      QDialog::accept();
+    }
+}
+
+void VisuGUI_StreamLinesDlg::reject()
+{
+  myScalarPane->deletePreview();
+  QDialog::reject();
 }