Salome HOME
Fix compilation error (conflict of OK name between OCCT Plate_Plate.hxx and GEOM...
[modules/geom.git] / src / EntityGUI / EntityGUI_FieldDlg.cxx
index 805366427f6e4e403d3b8704f81ef5436692112d..79ad43ee278215b6c2546193c5bbdd62efa2f17b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,6 +18,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 //  File   : EntityGUI_FieldDlg.cxx
 
@@ -41,7 +42,7 @@
 #include <OCCViewer_ViewManager.h>
 #include <SVTK_ViewModel.h>
 #include <SALOME_Prs.h>
-#include <SALOME_ListIteratorOfListIO.hxx>
+#include <SALOME_ListIO.hxx>
 
 #include <SUIT_Desktop.h>
 #include <SUIT_MessageBox.h>
@@ -343,7 +344,7 @@ void EntityGUI_FieldDlg::Delegate::setModelData( QWidget* editor,
 
 void EntityGUI_FieldDlg::Delegate::updateEditorGeometry( QWidget* editor,
                                                          const QStyleOptionViewItem& option, 
-                                                         const QModelIndex& index ) const
+                                                         const QModelIndex& /*index*/ ) const
 {
   editor->setGeometry( option.rect );
 }
@@ -392,7 +393,7 @@ EntityGUI_FieldDlg::StepTable::StepTable (int stepID, int dataType,
     if ( !bs->_is_nil() )
     {
       GEOM::short_array_var vals = bs->GetValues();
-      if ( vals->length() == nbRows * nbComps )
+      if ( (int)vals->length() == nbRows * nbComps )
         for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
           for ( int iC = 1; iC < nbColumns; ++iC )
             setItem( iR, iC, new CheckItem( vals[ iV++ ]));
@@ -406,7 +407,7 @@ EntityGUI_FieldDlg::StepTable::StepTable (int stepID, int dataType,
     if ( !is->_is_nil() )
     {
       GEOM::ListOfLong_var vals = is->GetValues();
-      if ( vals->length() == nbRows * nbComps )
+      if ( (int)vals->length() == nbRows * nbComps )
         for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
           for ( int iC = 1; iC < nbColumns; ++iC )
             setItem( iR, iC, new IntSpinItem( vals[ iV++ ]));
@@ -419,7 +420,7 @@ EntityGUI_FieldDlg::StepTable::StepTable (int stepID, int dataType,
     if ( !ds->_is_nil() )
     {
       GEOM::ListOfDouble_var vals = ds->GetValues();
-      if ( vals->length() == nbRows * nbComps )
+      if ( (int)vals->length() == nbRows * nbComps )
         for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
           for ( int iC = 1; iC < nbColumns; ++iC )
             setItem( iR, iC, new DoubleSpinItem( vals[ iV++ ]));
@@ -431,7 +432,7 @@ EntityGUI_FieldDlg::StepTable::StepTable (int stepID, int dataType,
     if ( !ss->_is_nil() )
     {
       GEOM::string_array_var vals = ss->GetValues();
-      if ( vals->length() == nbRows * nbComps )
+      if ( (int)vals->length() == nbRows * nbComps )
         for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
           for ( int iC = 1; iC < nbColumns; ++iC )
             setItem( iR, iC, new QTableWidgetItem( vals[ iV++ ].in() ));
@@ -484,7 +485,7 @@ void EntityGUI_FieldDlg::StepTable::setEditable (bool isEditable,
 
 //=======================================================================
 // name    : EntityGUI_FieldDlg::StepTable::isEditable
-// Purpose : Verify wheter cell is editable
+// Purpose : Verify whether cell is editable
 //=======================================================================
 bool EntityGUI_FieldDlg::StepTable::isEditable (int row, int col) const
 {
@@ -752,7 +753,7 @@ void EntityGUI_FieldDlg::StepTable::setValues(GEOM::GEOM_FieldStep_var& step)
       vals->length( nbRows * nbComps );
       for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
         for ( int iC = 1; iC < nbColumns; ++iC )
-          vals[ iV++ ] = item( iR, iC )->text().toLatin1().constData();
+          vals[ iV++ ] = item( iR, iC )->text().toUtf8().constData();
       ss->SetValues( vals );
     }
   }
@@ -872,29 +873,32 @@ EntityGUI_FieldDlg::EntityGUI_FieldDlg (GeometryGUI* theGeometryGUI,
   switchTableGrpLayout->setMargin(0);
   switchTableGrpLayout->setSpacing(0);
 
-  // step browse controls
-  myPrevStepBtn = new QPushButton( tr("PREV_STEP"), valsGroup );
+  // step add/rm controls
+  QPushButton* addStepBtn = new QPushButton( tr("ADD_STEP"), valsGroup );
   QLabel* curStepLbl = new QLabel(tr("STEP"), valsGroup );
+  myStepEdit = new QLineEdit( valsGroup );
   myStepsCombo = new QComboBox(valsGroup);
-  myNextStepBtn = new QPushButton( tr("NEXT_STEP"), valsGroup );
+  myStepsCombo->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
+  myRmStepBtn = new QPushButton( tr("REMOVE_STEP"), valsGroup );
 
-  // step add/rm controls
-  QPushButton* addStepBtn = new QPushButton( tr("ADD_STEP"), valsGroup );
+  // step browse controls
+  myPrevStepBtn = new QPushButton( tr("PREV_STEP"), valsGroup );
   QLabel* stampLbl = new QLabel(tr("STAMP"), valsGroup );
   myStampSpin = new SalomeApp_IntSpinBox( -theIntLimit, theIntLimit, 1, valsGroup, true, true);
-  myRmStepBtn = new QPushButton( tr("REMOVE_STEP"), valsGroup );
-
-  valsLayout->addWidget(mySwitchTableWdg,   0, 0, 1, 4);
-  valsLayout->addWidget(myPrevStepBtn,      1, 0);
+  myNextStepBtn = new QPushButton( tr("NEXT_STEP"), valsGroup );
+  
+  valsLayout->addWidget(mySwitchTableWdg,   0, 0, 1, 5);
+  valsLayout->addWidget(addStepBtn,         1, 0);
   valsLayout->addWidget(curStepLbl,         1, 1);
-  valsLayout->addWidget(myStepsCombo,       1, 2);
-  valsLayout->addWidget(myNextStepBtn,      1, 3);
-  valsLayout->addWidget(addStepBtn,         2, 0);
+  valsLayout->addWidget(myStepEdit,         1, 2);
+  valsLayout->addWidget(myStepsCombo,       1, 3);
+  valsLayout->addWidget(myRmStepBtn,        1, 4);
+  valsLayout->addWidget(myPrevStepBtn,      2, 0);
   valsLayout->addWidget(stampLbl,           2, 1);
-  valsLayout->addWidget(myStampSpin,        2, 2);
-  valsLayout->addWidget(myRmStepBtn,        2, 3);
+  valsLayout->addWidget(myStampSpin,        2, 2, 1, 2);
+  valsLayout->addWidget(myNextStepBtn,      2, 4);
 
-  valsLayout->setColumnStretch(2, 5);
+  valsLayout->setColumnStretch(3, 5);
   valsLayout->setRowStretch   (0, 5);
 
   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
@@ -1050,7 +1054,7 @@ void EntityGUI_FieldDlg::Init()
 // function : enterEvent()
 // purpose  :
 //=================================================================================
-void EntityGUI_FieldDlg::enterEvent(QEvent* e)
+void EntityGUI_FieldDlg::enterEvent(QEvent*)
 {
   if (!buttonCancel()->isEnabled())
     ActivateThisDialog();
@@ -1177,8 +1181,8 @@ void EntityGUI_FieldDlg::SelectionIntoArgument()
           myEditCurrentArgument = 0;
 
           // re-fill myDimCombo
-          const int curDim = getDim();
-          updateDims( curDim );
+          //const int curDim = getDim();
+          updateDims( -100 );
 
           // update table
           onDimChange();
@@ -1292,17 +1296,44 @@ void EntityGUI_FieldDlg::onNextStep()
   }
 }
 
+static int findInCombo( QComboBox* where, int what, bool& ok )
+{
+  int idx = 0;
+  ok = false;
+
+  for ( ; idx < where->count() && !ok; idx++ ) {
+    int step = where->itemText( idx ).toInt();
+    if ( step == what ) {
+      ok = true;
+    }
+    else if ( step > what )
+      break;
+  }
+  
+  return idx;
+}
+
 //=======================================================================
 //function : onAddStep
 //purpose  : 
 //=======================================================================
 void EntityGUI_FieldDlg::onAddStep()
 {
-  if ( myStepsCombo->count() > 0 )
-    myCurStepID = myStepsCombo->itemText( myStepsCombo->count()-1 ).toInt() + 1;
+  int step = 0;
+
+  if ( !myStepEdit->text().isEmpty() )
+    step = myStepEdit->text().toInt();
+  bool ok = false;
+  int idx = findInCombo( myStepsCombo, step, ok );
+  
+  if ( ok ) {
+    SUIT_MessageBox::critical(this, QObject::tr("ERR_ERROR"),
+                             tr("ERR_STEP_EXISTS"));
+    return;
+  }
 
-  myStepsCombo->insertItem( myStepsCombo->count(), QString::number( myCurStepID ));
-  myStepsCombo->setCurrentIndex( myStepsCombo->count() - 1 );
+  myStepsCombo->insertItem( idx, QString::number( step ));
+  myStepsCombo->setCurrentIndex( idx );
   myRemovedSteps.remove( getCurStepID() );
   //showCurStep();
 }
@@ -1341,7 +1372,8 @@ void EntityGUI_FieldDlg::onStampChange()
 //=======================================================================
 void EntityGUI_FieldDlg::showCurStep()
 {
-  myCurStepID = getCurStepID();
+  myCurStepID = getCurStepID(); 
+  myStepEdit->setText(QString::number( myCurStepID ));
 
   QStringList headers;
   if ( myCurStepTable )
@@ -1381,7 +1413,7 @@ void EntityGUI_FieldDlg::showCurStep()
       if ( !myIsCreation && !myField->_is_nil() )
       {
         GEOM::string_array_var compNames = myField->GetComponents();
-        for ( int iC = 0; iC < compNames->length(); ++iC )
+        for ( int iC = 0; iC < (int)compNames->length(); ++iC )
           headers << compNames[ iC ].in();
       }
       else
@@ -1445,7 +1477,8 @@ int EntityGUI_FieldDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMa
         if (!appStudy) return 0;
         _PTR(Study) aStudy = appStudy->studyDS();
 
-        _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
+        _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toUtf8().constData()));
+        if ( ! GeometryGUI::IsInGeomComponent( aSObj )) continue;
         GEOM::GEOM_Object_var aGeomObj =
           GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
         TopoDS_Shape aShape;
@@ -1576,15 +1609,15 @@ void EntityGUI_FieldDlg::updateDims(int curDim)
     {
       exp.Init( aShape, getShapeType(&dim));
       if ( exp.More() && !aShape.IsSame( exp.Current() ))
-      {
         myDimCombo->insertItem( dim, tr( subNames[dim] ), dim );
-        if ( dim == curDim )  // restore current dim
-          myDimCombo->setCurrentIndex( myDimCombo->count()-1 );
-      }
     }
     myDimCombo->insertItem( 4, tr("WHOLE"), -1 );
-    if ( getDim() != curDim )
-      myDimCombo->setCurrentIndex( myDimCombo->count()-1 );
+
+    int idx = myDimCombo->findData( curDim );
+    if ( idx != -1 )
+      myDimCombo->setCurrentIndex( idx );
+    else 
+      myDimCombo->setCurrentIndex( myDimCombo->count()-1-(myDimCombo->count()>1?1:0) );
   }
   myDimCombo->blockSignals( false );
 }
@@ -1595,14 +1628,14 @@ void EntityGUI_FieldDlg::updateDims(int curDim)
 //=================================================================================
 void EntityGUI_FieldDlg::activateSelection()
 {
-  bool isApply = ((QPushButton*)sender() == buttonApply());
+  //bool isApply = ((QPushButton*)sender() == buttonApply());
   if(!isApplyAndClose())
     erasePreview(false);
 
   // local selection
   if (!myShape->_is_nil() &&
       !myEditCurrentArgument &&
-      myShapeIDs.size() > 1 ) // shape type is already choosen by user
+      myShapeIDs.size() > 1 ) // shape type is already chosen by user
   {
     GEOM_Displayer*   aDisplayer = getDisplayer();
     CORBA::String_var aMainEntry = myShape->GetStudyEntry();
@@ -1663,7 +1696,7 @@ void EntityGUI_FieldDlg::activateSelection()
         TopoDS_Shape aSubShape = myShapeMap( index );
         QString anEntry = QString( "TEMP_" ) + aMainEntry.in() + QString("_%1").arg(index);
         Handle(SALOME_InteractiveObject) io =
-          new SALOME_InteractiveObject(anEntry.toAscii(), "GEOM", "TEMP_IO");
+          new SALOME_InteractiveObject(anEntry.toUtf8(), "GEOM", "TEMP_IO");
         aDisplayer->SetColor( aCol );
         SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
         if (aPrs) {
@@ -1733,7 +1766,7 @@ void EntityGUI_FieldDlg::highlightSubShapes()
   SALOME_ListIO aSelList;
 
   // To highlight the selected sub-shape in Object Browser, if it's already published under the main shape
-  GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
+  GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations();
   QMap<int, QString> childsMap;
   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
   if (appStudy) {
@@ -1741,20 +1774,21 @@ void EntityGUI_FieldDlg::highlightSubShapes()
     CORBA::String_var aMainEntry = myShape->GetStudyEntry();
     _PTR(SObject) aSObj = aStudy->FindObjectID( aMainEntry.in() );
     _PTR(ChildIterator) anIt = aStudy->NewChildIterator(aSObj);
-    for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
-      GEOM::GEOM_Object_var aChild =
-        GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
-      if (!CORBA::is_nil(aChild)) {
-        int index = aLocOp->GetSubShapeIndex(myShape, aChild);
-        if ( anIds.Contains( index )) {
-          CORBA::String_var aChildEntry = aChild->GetStudyEntry();
-          //childsMap.insert(index, aChildEntry.in());
+    if ( GeometryGUI::IsInGeomComponent( aSObj ))
+      for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
+        GEOM::GEOM_Object_var aChild =
+          GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
+        if (!CORBA::is_nil(aChild)) {
+          int index = aLocOp->GetSubShapeIndex(myShape, aChild);
+          if ( anIds.Contains( index )) {
+            CORBA::String_var aChildEntry = aChild->GetStudyEntry();
+            //childsMap.insert(index, aChildEntry.in());
             Handle(SALOME_InteractiveObject) tmpIO =
               new SALOME_InteractiveObject( aChildEntry.in(), "GEOM", "TEMP_IO");
             aSelList.Append(tmpIO);
+          }
         }
       }
-    }
   }
 
   AIS_ListIteratorOfListOfInteractive ite (List);
@@ -1770,7 +1804,7 @@ void EntityGUI_FieldDlg::highlightSubShapes()
         if (anIds.Contains(anIndex)) {
           aSelList.Append(anIO);
           // if (childsMap.contains (anIndex)) {
-          //   Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO");
+          //   Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toUtf8().constData(), "GEOM", "TEMP_IO");
           //   aSelList.Append(tmpIO);
           // }
         }
@@ -1786,7 +1820,7 @@ void EntityGUI_FieldDlg::highlightSubShapes()
 //=================================================================================
 GEOM::GEOM_IOperations_ptr EntityGUI_FieldDlg::createOperation()
 {
-  return getGeomEngine()->GetIFieldOperations(getStudyId());
+  return getGeomEngine()->GetIFieldOperations();
 }
 
 #define RETURN_WITH_MSG(a, b) \
@@ -1825,7 +1859,7 @@ bool EntityGUI_FieldDlg::isValid(QString& theMessage)
 //=================================================================================
 bool EntityGUI_FieldDlg::execute()
 {
-  SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy( getStudy()->studyDS() );
+  SALOMEDS::Study_var aStudyDS = GeometryGUI::getStudyServant();
   SALOMEDS::StudyBuilder_var aBuilder = aStudyDS->NewBuilder();
 
   QString aName = getNewObjectName().trimmed();
@@ -1838,11 +1872,11 @@ bool EntityGUI_FieldDlg::execute()
     GEOM::string_array_var compNames = new GEOM::string_array();
     compNames->length( nbComps );
     for ( int iC = 0; iC < nbComps; ++iC )
-      compNames[ iC ] = columnNames[ iC+1 ].toLatin1().constData();
+      compNames[ iC ] = columnNames[ iC+1 ].toUtf8().constData();
 
     GEOM::GEOM_IFieldOperations_var anOper = GEOM::GEOM_IFieldOperations::_narrow(getOperation());
     myField = anOper->CreateField( myShape,
-                                   aName.toLatin1().constData(),
+                                   aName.toUtf8().constData(),
                                    GEOM::field_data_type( getDataType() ),
                                    CORBA::Short( getDim() ),
                                    compNames );
@@ -1850,7 +1884,7 @@ bool EntityGUI_FieldDlg::execute()
       return false;
     
     SALOMEDS::SObject_wrap aSO =
-      getGeomEngine()->AddInStudy( aStudyDS, myField, aName.toLatin1().constData(), myShape );
+      getGeomEngine()->AddInStudy( myField, aName.toUtf8().constData(), myShape );
     if ( !aSO->_is_nil() ) {
       myField->UnRegister();
       CORBA::String_var entry = aSO->GetID();
@@ -1859,13 +1893,13 @@ bool EntityGUI_FieldDlg::execute()
   }
   else // update field name
   {
-    myField->SetName( aName.toLatin1().constData() );
+    myField->SetName( aName.toUtf8().constData() );
 
     CORBA::String_var entry = myField->GetStudyEntry();
     if ( entry.in() ) {
       SALOMEDS::SObject_wrap SO = aStudyDS->FindObjectID( entry.in() );
       if ( !SO->_is_nil() ) {
-        aBuilder->SetName(SO, aName.toLatin1().constData());
+        aBuilder->SetName(SO, aName.toUtf8().constData());
       }
     }
   }
@@ -1886,7 +1920,7 @@ bool EntityGUI_FieldDlg::execute()
         step = myField->AddStep( tbl->getStepID(), tbl->getStamp() );
 
         SALOMEDS::SObject_wrap aSO =
-          getGeomEngine()->AddInStudy( aStudyDS, step, stepName.toLatin1().constData(), myField );
+          getGeomEngine()->AddInStudy( step, stepName.toUtf8().constData(), myField );
         if ( /*!myIsCreation &&*/ !aSO->_is_nil() ) {
           step->UnRegister();
           CORBA::String_var entry = aSO->GetID();
@@ -1901,7 +1935,7 @@ bool EntityGUI_FieldDlg::execute()
       if ( entry.in() ) {
         SALOMEDS::SObject_wrap SO = aStudyDS->FindObjectID( entry.in() );
         if ( !SO->_is_nil() )
-          aBuilder->SetName( SO, stepName.toLatin1().constData() );
+          aBuilder->SetName( SO, stepName.toUtf8().constData() );
       }
     }
 
@@ -1950,3 +1984,15 @@ bool EntityGUI_FieldDlg::execute()
 
   return true;
 }
+
+//=================================================================================
+// function : getSourceObjects
+// purpose  : virtual method to get source objects
+//=================================================================================
+QList<GEOM::GeomObjPtr> EntityGUI_FieldDlg::getSourceObjects()
+{
+  QList<GEOM::GeomObjPtr> res;
+  GEOM::GeomObjPtr aGeomObjPtr(myField->GetShape());
+  res << aGeomObjPtr;
+  return res;
+}