Salome HOME
0021031: EDF 1646 GEOM: Modify Location leads to Position driver failed
[modules/geom.git] / src / TransformationGUI / TransformationGUI_MultiTranslationDlg.cxx
index e4c81518b93c8e3a4799f741adc95d19a15c71f0..36f2a54dc729fe47e58df0d638710f19079b1806 100644 (file)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//  Copyright (C) 2007-2010  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
@@ -19,6 +19,7 @@
 //
 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 // GEOM GEOMGUI : GUI for Geometry component
 // File   : TransformationGUI_MultiTranslationDlg.cxx
 // Author : Damien COQUERET, Open CASCADE S.A.S.
 
 #include <SUIT_Session.h>
 #include <SUIT_ResourceMgr.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_ViewWindow.h>
+#include <SUIT_ViewManager.h>
 #include <SalomeApp_Application.h>
 #include <LightApp_SelectionMgr.h>
+#include <GEOM_AISVector.hxx>
+#include <SOCC_Prs.h>
+#include <SOCC_ViewModel.h>
 
 // OCCT Includes
 #include <TopoDS_Shape.hxx>
 #include <TopExp.hxx>
 #include <TColStd_IndexedMapOfInteger.hxx>
 #include <TopTools_IndexedMapOfShape.hxx>
+#include <ShapeAnalysis_Edge.hxx>
+#include <BRep_Tool.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRep_Builder.hxx>
 
 #include <GEOMImpl_Types.hxx>
 
@@ -130,24 +141,21 @@ void TransformationGUI_MultiTranslationDlg::Init()
   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
 
-  double SpecificStep = 1;
+  int SpecificStep = 1;
   // min, max, step and decimals for spin boxes & initial values
-  initSpinBox(GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, step, 10); // VSR: TODO: DBL_DIGITS_DISPLAY
-  initSpinBox(GroupPoints->SpinBox_DY, 1, 999, SpecificStep, 10);
+  initSpinBox(GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
+  initSpinBox(GroupPoints->SpinBox_DY, 1, 999, SpecificStep);
   GroupPoints->SpinBox_DX->setValue(myStepU);
   GroupPoints->SpinBox_DY->setValue(myNbTimesU);
-  GroupPoints->SpinBox_DY->setDecimals(0);
 
-  initSpinBox(GroupDimensions->SpinBox_DX1, COORD_MIN, COORD_MAX, step, 10); // VSR: TODO: DBL_DIGITS_DISPLAY
-  initSpinBox(GroupDimensions->SpinBox_DY1, 1, 999, SpecificStep, 10);
-  initSpinBox(GroupDimensions->SpinBox_DX2, COORD_MIN, COORD_MAX, step, 10); // VSR: TODO: DBL_DIGITS_DISPLAY
-  initSpinBox(GroupDimensions->SpinBox_DY2, 1, 999, SpecificStep, 10);
+  initSpinBox(GroupDimensions->SpinBox_DX1, COORD_MIN, COORD_MAX, step, "length_precision" );
+  initSpinBox(GroupDimensions->SpinBox_DY1, 1, 999, SpecificStep);
+  initSpinBox(GroupDimensions->SpinBox_DX2, COORD_MIN, COORD_MAX, step, "length_precision" );
+  initSpinBox(GroupDimensions->SpinBox_DY2, 1, 999, SpecificStep);
   GroupDimensions->SpinBox_DX1->setValue(myStepU);
   GroupDimensions->SpinBox_DY1->setValue(myNbTimesU);
   GroupDimensions->SpinBox_DX2->setValue(myStepV);
   GroupDimensions->SpinBox_DY2->setValue(myNbTimesV);
-  GroupDimensions->SpinBox_DY1->setDecimals(0);
-  GroupDimensions->SpinBox_DY2->setDecimals(0);
 
   // init variables
   myStepU = myStepV = 50.0;
@@ -162,6 +170,8 @@ void TransformationGUI_MultiTranslationDlg::Init()
 
   myBase = myVectorU = myVectorV = GEOM::GEOM_Object::_nil();
 
+  mainFrame()->GroupBoxPublish->show();
+
   // signals and slots connections
   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
@@ -181,11 +191,11 @@ void TransformationGUI_MultiTranslationDlg::Init()
   connect(GroupDimensions->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
 
   connect(GroupPoints->SpinBox_DX,      SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
-  connect(GroupPoints->SpinBox_DY,      SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
+  connect(GroupPoints->SpinBox_DY,      SIGNAL(valueChanged(int)),    this, SLOT(ValueChangedInSpinBox(int)));
   connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
-  connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
+  connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(int)),    this, SLOT(ValueChangedInSpinBox(int)));
   connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
-  connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
+  connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(int)),    this, SLOT(ValueChangedInSpinBox(int)));
 
   connect(GroupPoints->SpinBox_DX,      SIGNAL(textChanged(const QString& )), 
           this, SLOT(TextValueChangedInSpinBox(const QString& )));
@@ -212,11 +222,13 @@ void TransformationGUI_MultiTranslationDlg::Init()
 void TransformationGUI_MultiTranslationDlg::SetDoubleSpinBoxStep (double step)
 {
   GroupPoints->SpinBox_DX->setSingleStep(step);
-  GroupPoints->SpinBox_DY->setSingleStep(step);
-  GroupDimensions->SpinBox_DX1->setSingleStep(step);
-  GroupDimensions->SpinBox_DY1->setSingleStep(step);
+  GroupDimensions->SpinBox_DX1->setSingleStep(step);  
   GroupDimensions->SpinBox_DX2->setSingleStep(step);
-  GroupDimensions->SpinBox_DY2->setSingleStep(step);
+  
+  // san : Commented so as not to override specific step settings
+  //GroupPoints->SpinBox_DY->setSingleStep((int)step);
+  //GroupDimensions->SpinBox_DY1->setSingleStep((int)step);
+  //GroupDimensions->SpinBox_DY2->setSingleStep((int)step);
 }
 
 //=================================================================================
@@ -353,7 +365,7 @@ void TransformationGUI_MultiTranslationDlg::SelectionIntoArgument()
         //Find SubShape Object in Father
         GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
 
-        if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
+        if (aFindedObject->_is_nil()) { // Object not found in study
           GEOM::GEOM_IShapesOperations_var aShapesOp =
             getGeomEngine()->GetIShapesOperations(getStudyId());
           if (myEditCurrentArgument == GroupDimensions->LineEdit3)
@@ -501,7 +513,7 @@ void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
 {
   GEOMBase_Skeleton::ActivateThisDialog();
   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
-          this, SLOT( SelectionIntoArgument() ) );
+           this, SLOT( SelectionIntoArgument() ) );
 
   ConstructorsClicked( getConstructorId() );
 }
@@ -561,18 +573,35 @@ void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox (double newVal
   case 0:
     if (send == GroupPoints->SpinBox_DX)
       myStepU = newValue;
-    else if (send == GroupPoints->SpinBox_DY)
-      myNbTimesU = (int)newValue;
     break;
   case 1:
     if (send == GroupDimensions->SpinBox_DX1)
       myStepU = newValue;
-    else if (send == GroupDimensions->SpinBox_DY1)
-      myNbTimesU = (int)newValue;
     else if (send == GroupDimensions->SpinBox_DX2)
       myStepV = newValue;
+    break;
+  }
+
+  displayPreview();
+}
+
+//=================================================================================
+// function : ValueChangedInSpinBox()
+// purpose  :
+//=================================================================================
+void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox (int newValue)
+{
+  QObject* send = (QObject*)sender();
+  switch (getConstructorId()) {
+  case 0:
+    if (send == GroupPoints->SpinBox_DY)
+      myNbTimesU = newValue;
+    break;
+  case 1:
+    if (send == GroupDimensions->SpinBox_DY1)
+      myNbTimesU = newValue;
     else if (send == GroupDimensions->SpinBox_DY2)
-      myNbTimesV = (int)newValue;
+      myNbTimesV = newValue;
     break;
   }
 
@@ -656,11 +685,13 @@ bool TransformationGUI_MultiTranslationDlg::execute (ObjectList& objects)
 
   QStringList aParameters;
 
+  GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
+
   switch (getConstructorId()) {
   case 0:
     if (!CORBA::is_nil(myBase) && !CORBA::is_nil(myVectorU)) {
-      anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
-        MultiTranslate1D(myBase, myVectorU, myStepU, myNbTimesU);
+      createPathPreview ( myVectorU );
+      anObj = anOper->MultiTranslate1D(myBase, myVectorU, myStepU, myNbTimesU);
       if(!IsPreview()) {
         aParameters<<GroupPoints->SpinBox_DX->text();
         aParameters<<GroupPoints->SpinBox_DY->text();
@@ -671,9 +702,11 @@ bool TransformationGUI_MultiTranslationDlg::execute (ObjectList& objects)
   case 1:
     if (!CORBA::is_nil(myBase) && !CORBA::is_nil(myVectorU) &&
         !CORBA::is_nil(myVectorV)) {
-      anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
-        MultiTranslate2D(myBase, myVectorU, myStepU, myNbTimesU,
-                          myVectorV, myStepV, myNbTimesV);
+      createPathPreview ( myVectorU );
+      createPathPreview ( myVectorV );
+      anObj = anOper->MultiTranslate2D(myBase,
+                                       myVectorU, myStepU, myNbTimesU,
+                                       myVectorV, myStepV, myNbTimesV);
       if(!IsPreview()) {
         aParameters<<GroupDimensions->SpinBox_DX1->text();
         aParameters<<GroupDimensions->SpinBox_DY1->text();
@@ -687,7 +720,7 @@ bool TransformationGUI_MultiTranslationDlg::execute (ObjectList& objects)
 
   if (!anObj->_is_nil()) {
     if(!IsPreview())
-      anObj->SetParameters(GeometryGUI::JoinObjectParameters(aParameters));
+      anObj->SetParameters(aParameters.join(":").toLatin1().constData());
     objects.push_back(anObj._retn());
   }
 
@@ -713,3 +746,50 @@ void TransformationGUI_MultiTranslationDlg::addSubshapesToStudy()
   }
   addSubshapesToFather(objMap);
 }
+
+//=================================================================================
+// function : restoreSubShapes
+// purpose  :
+//=================================================================================
+void TransformationGUI_MultiTranslationDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
+                                                              SALOMEDS::SObject_ptr theSObject)
+{
+  if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
+    // we pass here the first operation argument (object) through the list of arguments
+    // because the rotation operation place its arguments in the data structure in another order,
+    // and we need to point the first argument directly
+    GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
+    anArgs->length(1);
+    anArgs[0] = myBase;
+    getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
+                                        /*theFindMethod=*/GEOM::FSM_Transformed,
+                                        /*theInheritFirstArg=*/true,
+                                        mainFrame()->CheckBoxAddPrefix->isChecked());
+  }
+}
+
+//=================================================================================
+// function : createPathPreview
+// purpose  :
+//=================================================================================
+void TransformationGUI_MultiTranslationDlg::createPathPreview ( GEOM::GEOM_Object_var thePath )
+{
+  if ( IsPreview() ) {
+    TopoDS_Shape aShape;
+    GEOMBase::GetShape( thePath, aShape, TopAbs_SHAPE );
+    TopoDS_Edge anEdge = TopoDS::Edge( aShape );
+    ShapeAnalysis_Edge aShapeAnal;
+    TopoDS_Vertex aFirst = aShapeAnal.FirstVertex( anEdge );
+    TopoDS_Vertex aLast = aShapeAnal.LastVertex( anEdge );
+    TopoDS_Shape aVector = BRepBuilderAPI_MakeEdge(BRep_Tool::Pnt(aFirst), BRep_Tool::Pnt(aLast)).Shape();
+    const char* aName = "tmpVector";
+    Handle(GEOM_AISVector) anIO = new GEOM_AISVector( aVector, aName );
+    
+    // add Prs to preview
+    SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
+    SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
+    if (aPrs)
+      aPrs->AddObject(anIO);
+    GEOMBase_Helper::displayPreview( aPrs, false, true );
+  }
+}