Salome HOME
Implementation of the "21187: EDF 1137 GEOM: Performance issue when manipulating...
[modules/geom.git] / src / PrimitiveGUI / PrimitiveGUI_DiskDlg.cxx
index 264dee77249910239517f7574727e49d32476beb..37036ecfdae2b641f3177a67adf0a81aa0cfd6c8 100755 (executable)
@@ -142,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);
@@ -156,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()));
 
@@ -204,7 +201,7 @@ void PrimitiveGUI_DiskDlg::RadioButtonClicked()
     myOrientationType = 2;
   else if (GroupOrientation->RadioButton3->isChecked())
     myOrientationType = 3;
-  displayPreview();
+  displayPreview(true);
 }
 
 //=================================================================================
@@ -254,7 +251,7 @@ void PrimitiveGUI_DiskDlg::ConstructorsClicked (int constructorId)
   resize(minimumSizeHint());
   SelectionIntoArgument();
 
-  displayPreview();
+  displayPreview(true);
 }
 
 //=================================================================================
@@ -299,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->_is_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);
 }
 
 //=================================================================================
@@ -454,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);
 }
 
 //=================================================================================
@@ -503,7 +444,7 @@ void PrimitiveGUI_DiskDlg::enterEvent (QEvent*)
 //=================================================================================
 void PrimitiveGUI_DiskDlg::ValueChangedInSpinBox()
 {
-  displayPreview();
+  displayPreview(true);
 }
 
 //=================================================================================
@@ -530,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;
 }
 
 //=================================================================================
@@ -571,7 +505,7 @@ bool PrimitiveGUI_DiskDlg::execute (ObjectList& objects)
     res = true;
     break;
   case 1:
-    anObj = anOper->MakeDiskPntVecR(myPoint, myDir, getRadius());
+    anObj = anOper->MakeDiskPntVecR(myPoint.get(), myDir.get(), getRadius());
     if (!anObj->_is_nil() && !IsPreview())
     {
       aParameters << GroupPntVecR->SpinBox_DX->text();
@@ -580,7 +514,7 @@ bool PrimitiveGUI_DiskDlg::execute (ObjectList& objects)
     res = true;
     break;
   case 2:
-    anObj = anOper->MakeDiskThreePnt(myPoint1, myPoint2, myPoint3);
+    anObj = anOper->MakeDiskThreePnt(myPoint1.get(), myPoint2.get(), myPoint3.get());
     res = true;
     break;
   }
@@ -613,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);
 }