Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / VISUGUI / VisuGUI_EditContainerDlg.cxx
index 58212511c9c64c0f97ebe6ff743c9c7cc4556769..eed32a53721cc81c373f3585e982af23bb5df15d 100644 (file)
@@ -1,5 +1,3 @@
-using namespace std;
-
 //  VISU VISUGUI : GUI of VISU component
 //
 //  Copyright (C) 2003  CEA/DEN, EDF R&D
@@ -12,22 +10,22 @@ using namespace std;
 
 
 #include "VisuGUI_EditContainerDlg.h"
+
 #include "VisuGUI.h"
+#include "VisuGUI_Tools.h"
+
 #include "VISU_Table_i.hh"
 
-#include "QAD_Application.h"
-#include "QAD_Desktop.h"
+#include "SalomeApp_Application.h"
+#include "SUIT_Desktop.h"
 
 #include <qlayout.h>
 #include <qcheckbox.h>
 #include <qgroupbox.h>
+#include <qpushbutton.h>
+#include <qlabel.h>
 
-
-#include CORBA_SERVER_HEADER(VISU_Gen)
-#include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
-
-extern VisuGUI *visuGUI;
-
+using namespace std;
 
 
 /* XPM */
@@ -195,98 +193,104 @@ static const char * right_xpm[] = {
 static QPixmap MYRightPix(right_xpm);
 
 
-VisuGUI_EditContainerDlg::VisuGUI_EditContainerDlg()    
-  : QDialog( QAD_Application::getDesktop(), "VisuGUI_EditContainerDlg", true, 
-            WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
+VisuGUI_EditContainerDlg::VisuGUI_EditContainerDlg (VisuGUI* theModule, bool theIsModal)
+     : QDialog(VISU::GetDesktop(theModule), "VisuGUI_EditContainerDlg", theIsModal,
+               WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
+       myVisuGUI(theModule)
 {
-  setCaption( "Edit Plot 2D Presentation" );
-  setSizeGripEnabled( true );
-  QVBoxLayout* TopLayout = new QVBoxLayout(this, 6, 11);
+  if (!theIsModal) {
+    setWFlags(getWFlags() | WDestructiveClose);
+  }
+  setCaption("Edit Plot 2D Presentation");
+  setSizeGripEnabled(true);
+
+  QVBoxLayout* TopLayout = new QVBoxLayout (this, 6, 11);
 
   /***************************************************************/
-  QFrame* aControlFrame = new QFrame(this);
+  QFrame* aControlFrame = new QFrame (this);
   aControlFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
 
-  QGridLayout* aControlLay = new QGridLayout(aControlFrame);
-  aControlLay->setSpacing( 6 );
-  aControlLay->setMargin( 11 );
-  aControlLay->addRowSpacing( 1, 30 );
-  aControlLay->addRowSpacing( 4, 30 );
-  aControlLay->setRowStretch( 1, 1 );
-  aControlLay->setRowStretch( 4, 1 );
-  aControlLay->addColSpacing( 0, 180 );
-  aControlLay->addColSpacing( 2, 180 );
-
-  QLabel* aSelectLbl = new QLabel(tr("Study"), aControlFrame);
+  QGridLayout* aControlLay = new QGridLayout (aControlFrame);
+  aControlLay->setSpacing(6);
+  aControlLay->setMargin(11);
+  aControlLay->addRowSpacing(1, 30);
+  aControlLay->addRowSpacing(4, 30);
+  aControlLay->setRowStretch(1, 1);
+  aControlLay->setRowStretch(4, 1);
+  aControlLay->addColSpacing(0, 180);
+  aControlLay->addColSpacing(2, 180);
+
+  QLabel* aSelectLbl = new QLabel (tr("LBL_STUDY"), aControlFrame);
   aControlLay->addWidget(aSelectLbl, 0, 0);
 
-  myStudyLst = new QListView(aControlFrame);
+  myStudyLst = new QListView (aControlFrame);
   myStudyLst->setSelectionMode(QListView::Extended);
-  myStudyLst->addColumn(tr("Table"), 80);
-  myStudyLst->addColumn(tr("Curve"), 50);
+  myStudyLst->addColumn(tr("TXT_TABLE"), 80);
+  myStudyLst->addColumn(tr("TXT_CURVE"), 50);
   myStudyLst->addColumn(tr(""), 0);
   myStudyLst->setAllColumnsShowFocus(true);
   myStudyLst->setMinimumHeight(130);
-  connect(myStudyLst, SIGNAL( selectionChanged()), this, SLOT( onLeftSelected() ));
+  connect(myStudyLst, SIGNAL(selectionChanged()), this, SLOT(onLeftSelected()));
   aControlLay->addMultiCellWidget(myStudyLst, 1, 4, 0, 0);
-  
-  myRightBtn = new QToolButton(aControlFrame);
+
+  myRightBtn = new QToolButton (aControlFrame);
   myRightBtn->setIconSet(MYRightPix);
   myRightBtn->setEnabled(false);
-  connect(myRightBtn, SIGNAL( clicked()), this, SLOT( onRightClicked() ));
+  connect(myRightBtn, SIGNAL(clicked()), this, SLOT(onRightClicked()));
   aControlLay->addWidget(myRightBtn, 2, 1);
-  
+
   myLeftBtn = new QToolButton(aControlFrame);
   myLeftBtn->setIconSet(MYLeftPix);
   myLeftBtn->setEnabled(false);
-  connect(myLeftBtn, SIGNAL( clicked()), this, SLOT( onLeftClicked() ));
+  connect(myLeftBtn, SIGNAL(clicked()), this, SLOT(onLeftClicked()));
   aControlLay->addWidget(myLeftBtn, 3, 1);
-  
-  QLabel* aForceLbl = new QLabel(tr("Container"), aControlFrame);
+
+  QLabel* aForceLbl = new QLabel (tr("LBL_CONTAINER"), aControlFrame);
   aControlLay->addWidget(aForceLbl, 0, 2);
 
   myContainerLst = new QListView(aControlFrame);
   myContainerLst->setSelectionMode(QListView::Extended);
-  myContainerLst->addColumn(tr("Table"), 80);
-  myContainerLst->addColumn(tr("Curve"), 50);
+  myContainerLst->addColumn(tr("TXT_TABLE"), 80);
+  myContainerLst->addColumn(tr("TXT_CURVE"), 50);
   myContainerLst->addColumn(tr(""), 0);
   myContainerLst->setMinimumWidth(130);
-  connect(myContainerLst, SIGNAL( selectionChanged()), this, SLOT( onRightSelected() ));
+  connect(myContainerLst, SIGNAL(selectionChanged()), this, SLOT(onRightSelected()));
   aControlLay->addMultiCellWidget(myContainerLst, 1, 4, 2, 2);
-  
-  TopLayout->addWidget( aControlFrame );
+
+  TopLayout->addWidget(aControlFrame);
 
   // Common buttons ===========================================================
-  QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
-  GroupButtons->setColumnLayout(0, Qt::Vertical );
-  GroupButtons->layout()->setSpacing( 0 );
-  GroupButtons->layout()->setMargin( 0 );
-  QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
-  GroupButtonsLayout->setAlignment( Qt::AlignTop );
-  GroupButtonsLayout->setSpacing( 6 );
-  GroupButtonsLayout->setMargin( 11 );
-
-  QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
-  buttonOk->setAutoDefault( TRUE );
-  buttonOk->setDefault( TRUE );
-  GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
-  GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
-
-  QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
-  buttonCancel->setAutoDefault( TRUE );
-  GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
-
-  TopLayout->addWidget( GroupButtons );
-
-  connect( buttonOk,     SIGNAL( clicked() ),      this, SLOT( accept() ) );
-  connect( buttonCancel, SIGNAL( clicked() ),      this, SLOT( reject() ) );
+  QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
+  GroupButtons->setColumnLayout(0, Qt::Vertical);
+  GroupButtons->layout()->setSpacing(0);
+  GroupButtons->layout()->setMargin(0);
+  QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
+  GroupButtonsLayout->setAlignment(Qt::AlignTop);
+  GroupButtonsLayout->setSpacing(6);
+  GroupButtonsLayout->setMargin(11);
+
+  QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons, "buttonOk");
+  buttonOk->setAutoDefault(TRUE);
+  buttonOk->setDefault(TRUE);
+  GroupButtonsLayout->addWidget(buttonOk, 0, 0);
+  GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding,
+                                              QSizePolicy::Minimum), 0, 1);
+
+  QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons, "buttonCancel");
+  buttonCancel->setAutoDefault(TRUE);
+  GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
+
+  TopLayout->addWidget(GroupButtons);
+
+  connect(buttonOk,     SIGNAL(clicked()),      this, SLOT(accept()));
+  connect(buttonCancel, SIGNAL(clicked()),      this, SLOT(reject()));
 }
 
-
-void VisuGUI_EditContainerDlg::initFromPrsObject(VISU::Container_i* theContainer) {
-  SALOMEDS::Study_var aStudy = visuGUI->GetStudyDocument();
-  SALOMEDS::SComponent_var aVisuSO = aStudy->FindComponent("VISU");
-  if (aVisuSO->_is_nil()) {
+void VisuGUI_EditContainerDlg::initFromPrsObject (VISU::Container_i* theContainer)
+{
+  _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
+  _PTR(SComponent) aVisuSO = aStudy->FindComponent("VISU");
+  if (!aVisuSO) {
     return;
   }
   QValueList<CurveStruct> aStudyCurves;
@@ -298,25 +302,25 @@ void VisuGUI_EditContainerDlg::initFromPrsObject(VISU::Container_i* theContainer
     CurveStruct aEntry;
     aEntry.CurveName = aCurve->GetTitle();
     aEntry.CurveEntry = aCurve->GetEntry();
-    SALOMEDS::SObject_var aTableSO = aStudy->FindObjectID(aCurve->GetTableID());
-    if (CORBA::is_nil(aTableSO)) continue;
+    _PTR(SObject) aTableSO = aStudy->FindObjectID(aCurve->GetTableID());
+    if (!aTableSO) continue;
     aEntry.TableName = getSObjectName(aTableSO);
     aContainerCurves.append(aEntry);
     new QListViewItem(myContainerLst, aEntry.TableName, aEntry.CurveName, aEntry.CurveEntry);
   }
   // Find curves in study
-  SALOMEDS::ChildIterator_var aIter = aStudy->NewChildIterator( aVisuSO );
+  _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aVisuSO);
   for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
-    SALOMEDS::SObject_var aSObject = aIter->Value();
-    CORBA::Object_var anObject = VISU::SObjectToObject(aSObject);
+    _PTR(SObject) aSObject = aIter->Value();
+    CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject);
     VISU::Base_var aVisuObj = VISU::Base::_narrow(anObject);
     if (!CORBA::is_nil(aVisuObj)) {
       if (aVisuObj->GetType() == VISU::TCURVE) {
-       SALOMEDS::SObject_var aTableSO = aSObject->GetFather();
+       _PTR(SObject) aTableSO = aSObject->GetFather();
        CurveStruct aEntry;
        aEntry.TableName = getSObjectName(aTableSO);
        aEntry.CurveName = getSObjectName(aSObject);
-       aEntry.CurveEntry = aSObject->GetID();
+       aEntry.CurveEntry = aSObject->GetID().c_str();
        aStudyCurves.append(aEntry);
       }
     }
@@ -325,8 +329,8 @@ void VisuGUI_EditContainerDlg::initFromPrsObject(VISU::Container_i* theContainer
   QValueList<CurveStruct>::iterator it;
   QValueList<CurveStruct>::iterator it2;
   bool isExist = false;
-  for (it = aStudyCurves.begin(); it != aStudyCurves.end(); ++it ) {
-    for (it2 = aContainerCurves.begin(); it2 != aContainerCurves.end(); ++it2 ) {
+  for (it = aStudyCurves.begin(); it != aStudyCurves.end(); ++it) {
+    for (it2 = aContainerCurves.begin(); it2 != aContainerCurves.end(); ++it2) {
       if (isExist = ((*it).CurveEntry == (*it2).CurveEntry))
        break;
     }
@@ -335,18 +339,18 @@ void VisuGUI_EditContainerDlg::initFromPrsObject(VISU::Container_i* theContainer
   }
 }
 
-
-void VisuGUI_EditContainerDlg::storeToPrsObject(VISU::Container_i* theContainer) {
+void VisuGUI_EditContainerDlg::storeToPrsObject (VISU::Container_i* theContainer)
+{
   theContainer->Clear();
 
-  SALOMEDS::Study_var aStudy = visuGUI->GetStudyDocument();
+  _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
   QListViewItem* anItem = myContainerLst->firstChild();
   while (anItem) {
-    SALOMEDS::SObject_var aCurveSO = aStudy->FindObjectID(anItem->text(2));
-    if (!aCurveSO->_is_nil()) {
-      CORBA::Object_var aObject = VISU::SObjectToObject(aCurveSO);
+    _PTR(SObject) aCurveSO = aStudy->FindObjectID(anItem->text(2).latin1());
+    if (aCurveSO) {
+      CORBA::Object_var aObject = VISU::ClientSObjectToObject(aCurveSO);
       if (!CORBA::is_nil(aObject)) {
-       VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>( VISU::GetServant(aObject).in() );
+       VISU::Curve_i* aCurve = dynamic_cast<VISU::Curve_i*>(VISU::GetServant(aObject).in());
        if (aCurve) theContainer->AddCurve(aCurve->_this());
       }
     }
@@ -354,21 +358,20 @@ void VisuGUI_EditContainerDlg::storeToPrsObject(VISU::Container_i* theContainer)
   }
 }
 
+QString VisuGUI_EditContainerDlg::getSObjectName (_PTR(SObject) theSObject)
+{
+  if (!theSObject) return QString("");
 
-QString VisuGUI_EditContainerDlg::getSObjectName(SALOMEDS::SObject_var theSObject) {
-  if (theSObject->_is_nil()) return QString("");
-
-  SALOMEDS::GenericAttribute_var anAttr;  
-  SALOMEDS::AttributeName_var    aName;
-  if ( theSObject->FindAttribute(anAttr, "AttributeName") ) {
-    aName = SALOMEDS::AttributeName::_narrow( anAttr );
-    return QString(strdup( aName->Value() ));
-  } 
+  _PTR(GenericAttribute) anAttr;
+  if (theSObject->FindAttribute(anAttr, "AttributeName")) {
+    _PTR(AttributeName) aName (anAttr);
+    return QString(aName->Value().c_str());
+  }
   return QString("");
 }
 
-
-void VisuGUI_EditContainerDlg::onLeftClicked() {
+void VisuGUI_EditContainerDlg::onLeftClicked()
+{
   QListViewItem* anItem = myContainerLst->firstChild();
   while (anItem) {
     if (anItem->isSelected()) {
@@ -382,8 +385,8 @@ void VisuGUI_EditContainerDlg::onLeftClicked() {
   }
 }
 
-
-void VisuGUI_EditContainerDlg::onRightClicked() {
+void VisuGUI_EditContainerDlg::onRightClicked()
+{
   QListViewItem* anItem = myStudyLst->firstChild();
   while (anItem) {
     if (anItem->isSelected()) {
@@ -397,8 +400,8 @@ void VisuGUI_EditContainerDlg::onRightClicked() {
   }
 }
 
-
-void VisuGUI_EditContainerDlg::onLeftSelected() {
+void VisuGUI_EditContainerDlg::onLeftSelected()
+{
   QListViewItem* anItem = myStudyLst->firstChild();
   bool isSelected = false;
   while (anItem) {
@@ -411,8 +414,8 @@ void VisuGUI_EditContainerDlg::onLeftSelected() {
   myRightBtn->setEnabled(isSelected);
 }
 
-
-void VisuGUI_EditContainerDlg::onRightSelected() {
+void VisuGUI_EditContainerDlg::onRightSelected()
+{
   QListViewItem* anItem = myContainerLst->firstChild();
   bool isSelected = false;
   while (anItem) {