Salome HOME
Implementation of the "21187: EDF 1137 GEOM: Performance issue when manipulating...
[modules/geom.git] / src / PrimitiveGUI / PrimitiveGUI_DiskDlg.cxx
index 9344092c872b93cb65eea459d0f955270ae068d2..37036ecfdae2b641f3177a67adf0a81aa0cfd6c8 100755 (executable)
@@ -1,7 +1,4 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 //  This library is free software; you can redistribute it and/or
 //  modify it under the terms of the GNU Lesser General Public
@@ -19,6 +16,7 @@
 //
 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 // GEOM GEOMGUI : GUI for Geometry component
 // File   : PrimitiveGUI_DiskDlg.cxx
 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
@@ -51,8 +49,7 @@
 //=================================================================================
 PrimitiveGUI_DiskDlg::PrimitiveGUI_DiskDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
                                             bool modal, Qt::WindowFlags fl)
-  : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
-    myInitial(true)
+  : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
 {
   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_DISK_PNT_VEC_R")));
@@ -132,8 +129,8 @@ void PrimitiveGUI_DiskDlg::Init()
   double aStep = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
 
   // min, max, step and decimals for spin boxes & initial values
-  initSpinBox(GroupPntVecR->SpinBox_DX, 0.00001, COORD_MAX, aStep, 5); // VSR: TODO: DBL_DIGITS_DISPLAY
-  initSpinBox(GroupDimensions->SpinBox_DX, 0.00001, COORD_MAX, aStep, 5); // VSR: TODO: DBL_DIGITS_DISPLAY
+  initSpinBox(GroupPntVecR->SpinBox_DX, 0.00001, COORD_MAX, aStep, "length_precision" );
+  initSpinBox(GroupDimensions->SpinBox_DX, 0.00001, COORD_MAX, aStep, "length_precision" );
 
   // init variables
   myEditCurrentArgument = GroupPntVecR->LineEdit1;
@@ -145,7 +142,11 @@ void PrimitiveGUI_DiskDlg::Init()
   Group3Pnts->LineEdit1->setText("");
   Group3Pnts->LineEdit2->setText("");
   Group3Pnts->LineEdit3->setText("");
-  myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
+  myPoint.nullify();
+  myDir.nullify();
+  myPoint1.nullify();
+  myPoint2.nullify();
+  myPoint3.nullify();
 
   GroupPntVecR->SpinBox_DX->setValue(100);
   GroupDimensions->SpinBox_DX->setValue(100);
@@ -159,17 +160,10 @@ void PrimitiveGUI_DiskDlg::Init()
   connect(GroupPntVecR->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
   connect(GroupPntVecR->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
 
-  connect(GroupPntVecR->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
-  connect(GroupPntVecR->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
-
   connect(Group3Pnts->PushButton1,   SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
   connect(Group3Pnts->PushButton2,   SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
   connect(Group3Pnts->PushButton3,   SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
 
-  connect(Group3Pnts->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
-  connect(Group3Pnts->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
-  connect(Group3Pnts->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
-
   connect(GroupPntVecR->SpinBox_DX,    SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
   connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
 
@@ -207,7 +201,7 @@ void PrimitiveGUI_DiskDlg::RadioButtonClicked()
     myOrientationType = 2;
   else if (GroupOrientation->RadioButton3->isChecked())
     myOrientationType = 3;
-  displayPreview();
+  displayPreview(true);
 }
 
 //=================================================================================
@@ -255,20 +249,9 @@ void PrimitiveGUI_DiskDlg::ConstructorsClicked (int constructorId)
   qApp->processEvents();
   updateGeometry();
   resize(minimumSizeHint());
+  SelectionIntoArgument();
 
-  if (myInitial) {
-    myInitial = false;
-    if (constructorId == 1 || constructorId == 2) {
-      // on dialog initialization we init the first field with a selected object (if any)
-      SelectionIntoArgument();
-    }
-    else {
-      displayPreview();
-    }
-  }
-  else {
-    displayPreview();
-  }
+  displayPreview(true);
 }
 
 //=================================================================================
@@ -313,95 +296,56 @@ void PrimitiveGUI_DiskDlg::SelectionIntoArgument()
   aSelMgr->selectedObjects(aSelList);
 
   if (aSelList.Extent() != 1) {
-    if      (myEditCurrentArgument == GroupPntVecR->LineEdit1) myPoint  = GEOM::GEOM_Object::_nil();
-    else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) myDir    = GEOM::GEOM_Object::_nil();
-    else if (myEditCurrentArgument == Group3Pnts->LineEdit1)   myPoint1 = GEOM::GEOM_Object::_nil();
-    else if (myEditCurrentArgument == Group3Pnts->LineEdit2)   myPoint2 = GEOM::GEOM_Object::_nil();
-    else if (myEditCurrentArgument == Group3Pnts->LineEdit3)   myPoint3 = GEOM::GEOM_Object::_nil();
+    if      (myEditCurrentArgument == GroupPntVecR->LineEdit1) myPoint.nullify();
+    else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) myDir.nullify();
+    else if (myEditCurrentArgument == Group3Pnts->LineEdit1)   myPoint1.nullify();
+    else if (myEditCurrentArgument == Group3Pnts->LineEdit2)   myPoint2.nullify();
+    else if (myEditCurrentArgument == Group3Pnts->LineEdit3)   myPoint3.nullify();
     return;
   }
 
-  // nbSel == 1
-  Handle(SALOME_InteractiveObject) anIO = aSelList.First();
-  Standard_Boolean testResult = Standard_False;
-  GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(anIO, testResult);
-
-  if (!testResult || CORBA::is_nil(aSelectedObject))
-    return;
-
-  QString aName = GEOMBase::GetName(aSelectedObject);
-
-  // If selected Vertex or Edge on the some Shape Get selection Subshape
+  TopAbs_ShapeEnum aNeedType = myEditCurrentArgument == GroupPntVecR->LineEdit2 ? TopAbs_EDGE : TopAbs_VERTEX;
+  GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
   TopoDS_Shape aShape;
-  if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
-  {
-    TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
-    if (myEditCurrentArgument == GroupPntVecR->LineEdit2)
-      aNeedType = TopAbs_EDGE;
-
-    TColStd_IndexedMapOfInteger aMap;
-    aSelMgr->GetIndexes(anIO, aMap);
-    if (aMap.Extent() == 1) { // Local Selection
-      int anIndex = aMap(1);
-      if (aNeedType == TopAbs_EDGE)
-        aName += QString(":edge_%1").arg(anIndex);
-      else
-        aName += QString(":vertex_%1").arg(anIndex);
-
-      //Find SubShape Object in Father
-      GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
-
-      if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
-        GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
-        aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
-      }
-      else {
-        aSelectedObject = aFindedObject; // get Object from study
-      }
+  if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
+    QString aName = GEOMBase::GetName( aSelectedObject.get() );
+
+    myEditCurrentArgument->setText(aName);
+    
+    // clear selection
+    disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
+    myGeomGUI->getApp()->selectionMgr()->clearSelected();
+    connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
+           this, SLOT(SelectionIntoArgument()));
+    
+    if (myEditCurrentArgument == GroupPntVecR->LineEdit1) {
+      myPoint = aSelectedObject;
+      if (myPoint && !myDir)
+       GroupPntVecR->PushButton2->click();
     }
-    else { // Global Selection
-      if (aShape.ShapeType() != aNeedType) {
-        aSelectedObject = GEOM::GEOM_Object::_nil();
-        aName = "";
-      }
+    else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
+      myDir = aSelectedObject;
+      if (myDir && !myPoint)
+       GroupPntVecR->PushButton1->click();
+    }
+    else if (myEditCurrentArgument == Group3Pnts->LineEdit1) {
+      myPoint1 = aSelectedObject;
+      if (myPoint1 && !myPoint2)
+       Group3Pnts->PushButton2->click();
+    }
+    else if (myEditCurrentArgument == Group3Pnts->LineEdit2) {
+      myPoint2 = aSelectedObject;
+      if (myPoint2 && !myPoint3)
+       Group3Pnts->PushButton3->click();
+    }
+    else if (myEditCurrentArgument == Group3Pnts->LineEdit3) {
+      myPoint3 = aSelectedObject;
+      if (myPoint3 && !myPoint1)
+       Group3Pnts->PushButton1->click();
     }
   }
 
-  myEditCurrentArgument->setText(aName);
-
-  // clear selection
-  disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
-  myGeomGUI->getApp()->selectionMgr()->clearSelected();
-  connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
-          this, SLOT(SelectionIntoArgument()));
-
-  if (myEditCurrentArgument == GroupPntVecR->LineEdit1) {
-    myPoint = aSelectedObject;
-    if (!myPoint->_is_nil() && myDir->_is_nil())
-      GroupPntVecR->PushButton2->click();
-  }
-  else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
-    myDir = aSelectedObject;
-    if (!myDir->_is_nil() && myPoint->_is_nil())
-      GroupPntVecR->PushButton1->click();
-  }
-  else if (myEditCurrentArgument == Group3Pnts->LineEdit1) {
-    myPoint1 = aSelectedObject;
-    if (!myPoint1->_is_nil() && myPoint2->_is_nil())
-      Group3Pnts->PushButton2->click();
-  }
-  else if (myEditCurrentArgument == Group3Pnts->LineEdit2) {
-    myPoint2 = aSelectedObject;
-    if (!myPoint2->_is_nil() && myPoint3->_is_nil())
-      Group3Pnts->PushButton3->click();
-  }
-  else if (myEditCurrentArgument == Group3Pnts->LineEdit3) {
-    myPoint3 = aSelectedObject;
-    if (!myPoint3->_is_nil() && myPoint1->_is_nil())
-      Group3Pnts->PushButton1->click();
-  }
-
-  displayPreview();
+  displayPreview(true);
 }
 
 //=================================================================================
@@ -468,24 +412,7 @@ void PrimitiveGUI_DiskDlg::SetEditCurrentArgument()
   send->setDown(true);
 
   // seems we need it only to avoid preview disappearing, caused by selection mode change
-  displayPreview();
-}
-
-//=================================================================================
-// function : LineEditReturnPressed()
-// purpose  :
-//=================================================================================
-void PrimitiveGUI_DiskDlg::LineEditReturnPressed()
-{
-QLineEdit* send = (QLineEdit*)sender();
-  if (send == GroupPntVecR->LineEdit1 ||
-      send == GroupPntVecR->LineEdit2 ||
-      send == Group3Pnts->LineEdit1 ||
-      send == Group3Pnts->LineEdit2 ||
-      send == Group3Pnts->LineEdit3) {
-    myEditCurrentArgument = send;
-    GEOMBase_Skeleton::LineEditReturnPressed();
-  }
+  displayPreview(true);
 }
 
 //=================================================================================
@@ -496,7 +423,7 @@ void PrimitiveGUI_DiskDlg::ActivateThisDialog()
 {
   GEOMBase_Skeleton::ActivateThisDialog();
   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
-          this, SLOT( SelectionIntoArgument() ) );
+           this, SLOT( SelectionIntoArgument() ) );
 
   ConstructorsClicked( getConstructorId() );
 }
@@ -517,7 +444,7 @@ void PrimitiveGUI_DiskDlg::enterEvent (QEvent*)
 //=================================================================================
 void PrimitiveGUI_DiskDlg::ValueChangedInSpinBox()
 {
-  displayPreview();
+  displayPreview(true);
 }
 
 //=================================================================================
@@ -544,21 +471,14 @@ static bool isEqual (const GEOM::GEOM_Object_var& thePnt1, const GEOM::GEOM_Obje
 //=================================================================================
 bool PrimitiveGUI_DiskDlg::isValid (QString& msg)
 {
-  bool ok = true;
-  if( getConstructorId() == 0 )
-    ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
-  else if( getConstructorId() == 1 )
-    ok = GroupPntVecR->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
-
-  const int id = getConstructorId();
-  if (id == 0)
-    return ok;
-  else if (id == 1)
-    return !myPoint->_is_nil() && !myDir->_is_nil() && getRadius() > 0 && ok;
-  else if (id == 2)
-    return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
-      !isEqual(myPoint1, myPoint2) && !isEqual(myPoint1, myPoint3) && !isEqual(myPoint2, myPoint3);
-  return false;
+  bool ok = false;
+  if ( getConstructorId() == 0 )
+    ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) && getRadius() > 0;
+  else if ( getConstructorId() == 1 )
+    ok = GroupPntVecR->SpinBox_DX->isValid( msg, !IsPreview() ) && myPoint && myDir && getRadius() > 0;
+  else if ( getConstructorId() == 2 )
+    ok = myPoint1 && myPoint2 && myPoint3 && myPoint1 != myPoint2 && myPoint1 != myPoint3 && myPoint2 != myPoint3;
+  return ok;
 }
 
 //=================================================================================
@@ -572,30 +492,29 @@ bool PrimitiveGUI_DiskDlg::execute (ObjectList& objects)
 
   GEOM::GEOM_Object_var anObj;
 
+  GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
+
   switch (getConstructorId()) {
   case 0:
-    anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
-      MakeDiskR(getRadius(), myOrientationType);
+    anObj = anOper->MakeDiskR(getRadius(), myOrientationType);
     if (!anObj->_is_nil() && !IsPreview())
     {
       aParameters << GroupDimensions->SpinBox_DX->text();
-      anObj->SetParameters(GeometryGUI::JoinObjectParameters(aParameters));
+      anObj->SetParameters(aParameters.join(":").toLatin1().constData());
     }
     res = true;
     break;
   case 1:
-    anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
-      MakeDiskPntVecR(myPoint, myDir, getRadius());
+    anObj = anOper->MakeDiskPntVecR(myPoint.get(), myDir.get(), getRadius());
     if (!anObj->_is_nil() && !IsPreview())
     {
       aParameters << GroupPntVecR->SpinBox_DX->text();
-      anObj->SetParameters(GeometryGUI::JoinObjectParameters(aParameters));
+      anObj->SetParameters(aParameters.join(":").toLatin1().constData());
     }
     res = true;
     break;
   case 2:
-    anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
-      MakeDiskThreePnt(myPoint1, myPoint2, myPoint3);
+    anObj = anOper->MakeDiskThreePnt(myPoint1.get(), myPoint2.get(), myPoint3.get());
     res = true;
     break;
   }
@@ -628,18 +547,17 @@ double PrimitiveGUI_DiskDlg::getRadius() const
 //=================================================================================
 void PrimitiveGUI_DiskDlg::addSubshapesToStudy()
 {
-  QMap<QString, GEOM::GEOM_Object_var> objMap;
-
   switch (getConstructorId()) {
   case 1:
-    objMap[GroupPntVecR->LineEdit1->text()] = myPoint;
-    objMap[GroupPntVecR->LineEdit2->text()] = myDir;
+    GEOMBase::PublishSubObject( myPoint.get() );
+    GEOMBase::PublishSubObject( myDir.get() );
     break;
   case 2:
-    objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
-    objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
-    objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
+    GEOMBase::PublishSubObject( myPoint1.get() );
+    GEOMBase::PublishSubObject( myPoint2.get() );
+    GEOMBase::PublishSubObject( myPoint3.get() );
+    break;
+  default:
     break;
   }
-  addSubshapesToFather(objMap);
 }