Salome HOME
Merging with WPdev
[modules/geom.git] / src / TransformationGUI / TransformationGUI_RotationDlg.cxx
index 5cb4dc03fd649574b69ffd9b5cff3cb3dfe7e4d4..39f71533bbb9f416445b25d9fd7c161dc64e3029 100644 (file)
@@ -17,7 +17,7 @@
 //  License along with this library; if not, write to the Free Software 
 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
 // 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //
 //
@@ -54,26 +54,35 @@ TransformationGUI_RotationDlg::TransformationGUI_RotationDlg
   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
 {
-  QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_ROTATION")));
-  QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
+  SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
+  QPixmap image0 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_ROTATION")));
+  QPixmap image1 (aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
+  QPixmap image2 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_ROTATION_THREE_POINTS")));
 
   setCaption(tr("GEOM_ROTATION_TITLE"));
 
   /***************************************************************/
   GroupConstructors->setTitle(tr("GEOM_ROTATION"));
   RadioButton1->setPixmap(image0);
-  RadioButton2->close(TRUE);
+  RadioButton2->setPixmap(image2);
   RadioButton3->close(TRUE);
 
-  GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
+  GroupPoints = new DlgRef_4Sel1Spin2Check(this, "GroupPoints");
   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
   GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
   GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
+  GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg("1"));
+  GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg("2"));
+
   GroupPoints->LineEdit1->setReadOnly(true);
   GroupPoints->LineEdit2->setReadOnly(true);
+  GroupPoints->LineEdit4->setReadOnly(true);
+  GroupPoints->LineEdit5->setReadOnly(true);
   GroupPoints->PushButton1->setPixmap(image1);
   GroupPoints->PushButton2->setPixmap(image1);
+  GroupPoints->PushButton4->setPixmap(image1);
+  GroupPoints->PushButton5->setPixmap(image1);
   GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
   GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
 
@@ -82,7 +91,7 @@ TransformationGUI_RotationDlg::TransformationGUI_RotationDlg
   double anAngle = 0;
   double SpecificStep = 5;
   /* min, max, step and decimals for spin boxes & initial values */
-  GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
+  GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, 3);
   GroupPoints->SpinBox_DX->SetValue(anAngle);
 
   // Activate Create a Copy mode
@@ -92,10 +101,13 @@ TransformationGUI_RotationDlg::TransformationGUI_RotationDlg
   /* signals and slots connections */
   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
-  
+  connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
+
   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
-  
+  connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
+  connect(GroupPoints->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
 
@@ -132,11 +144,55 @@ void TransformationGUI_RotationDlg::Init()
   myEditCurrentArgument = GroupPoints->LineEdit1;
   GroupPoints->LineEdit2->clear();
   
-  myAxis = GEOM::GEOM_Object::_nil();
+  myAxis = myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
   
   initName( tr( "GEOM_ROTATION" ) );
+  ConstructorsClicked( 0 );
 }
 
+//=================================================================================
+// function : ConstructorsClicked()
+// purpose  : Radio button management
+//=================================================================================
+void TransformationGUI_RotationDlg::ConstructorsClicked(int constructorId)
+{
+  disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
+  
+  myEditCurrentArgument = GroupPoints->LineEdit1;
+  globalSelection();
+
+  switch (constructorId)
+    {
+    case 0: /* rotation an object angle and axis */
+      {         
+       GroupPoints->ShowRows(2,3,false);
+       resize(0,0);
+       GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
+       GroupPoints->LineEdit2->clear();
+       GroupPoints->ShowRows(4,4,true);
+       myAxis = GEOM::GEOM_Object::_nil();
+       break;
+      }
+    case 1: /* rotation an object by 3 points */
+      {
+       GroupPoints->ShowRows(4,4,false);
+       resize(0,0);
+       GroupPoints->ShowRows(2,3,true);
+       GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
+       GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg("1"));
+       GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg("2"));
+       GroupPoints->LineEdit2->clear();
+       GroupPoints->LineEdit4->clear();
+       GroupPoints->LineEdit5->clear();
+       myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
+       break;
+      } 
+    }
+  
+  myEditCurrentArgument->setFocus();
+  connect(myGeomGUI->getApp()->selectionMgr(), 
+         SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
+}
 
 //=================================================================================
 // function : ClickOnOk()
@@ -158,7 +214,8 @@ bool TransformationGUI_RotationDlg::ClickOnApply()
   if ( !onAccept( GroupPoints->CheckButton1->isChecked()) )
     return false;
   
-  Init();
+  initName();
+  ConstructorsClicked( getConstructorId() );
   return true;
 }
 
@@ -184,18 +241,36 @@ void TransformationGUI_RotationDlg::SelectionIntoArgument()
       if (!myObjects.length())
        return;
     }
-  else if(myEditCurrentArgument == GroupPoints->LineEdit2)
+  else 
     {
       if(IObjectCount() != 1)
        {
-         myAxis = GEOM::GEOM_Object::_nil();
+         if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
+           myAxis = GEOM::GEOM_Object::_nil();
+         else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
+           myCentPoint  = GEOM::GEOM_Object::_nil();
+          else if(myEditCurrentArgument == GroupPoints->LineEdit4)
+           myPoint1 = GEOM::GEOM_Object::_nil();
+         else if(myEditCurrentArgument == GroupPoints->LineEdit5)
+           myPoint2 = GEOM::GEOM_Object::_nil();
          return;
        }
+
       Standard_Boolean testResult = Standard_False;
-      myAxis = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
-      if(!testResult || CORBA::is_nil( myAxis ))
+      GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
+      if(!testResult || CORBA::is_nil( aSelectedObject ))
        return;
-      aName = GEOMBase::GetName( myAxis );
+
+      if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
+       myAxis = aSelectedObject;
+      else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
+       myCentPoint = aSelectedObject;
+      else if(myEditCurrentArgument == GroupPoints->LineEdit4)
+       myPoint1 = aSelectedObject;
+      else if(myEditCurrentArgument == GroupPoints->LineEdit5)
+       myPoint2 = aSelectedObject;
+
+      aName = GEOMBase::GetName( aSelectedObject );
     }
   myEditCurrentArgument->setText( aName );
   
@@ -217,9 +292,20 @@ void TransformationGUI_RotationDlg::SetEditCurrentArgument()
   }
   else if(send == GroupPoints->PushButton2) {
     myEditCurrentArgument = GroupPoints->LineEdit2;
-    globalSelection( GEOM_LINE );
+    getConstructorId() == 0 ? globalSelection( GEOM_LINE ) :
+                              globalSelection( GEOM_POINT  );
   }
-  
+  else if (send == GroupPoints->PushButton4)
+    {
+      myEditCurrentArgument = GroupPoints->LineEdit4;
+      globalSelection( GEOM_POINT );
+    }
+  else if (send == GroupPoints->PushButton5)
+    {
+      myEditCurrentArgument = GroupPoints->LineEdit5;
+      globalSelection( GEOM_POINT );
+    }
+
   myEditCurrentArgument->setFocus();
   SelectionIntoArgument();
 }
@@ -250,11 +336,8 @@ void TransformationGUI_RotationDlg::ActivateThisDialog()
   GEOMBase_Skeleton::ActivateThisDialog();
   connect(myGeomGUI->getApp()->selectionMgr(), 
          SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
-  globalSelection();
-  GroupPoints->LineEdit1->setFocus();
-  myEditCurrentArgument = GroupPoints->LineEdit1;
-  GroupPoints->LineEdit2->clear();
-  myAxis = GEOM::GEOM_Object::_nil();
+
+  ConstructorsClicked( getConstructorId() );
 }
 
 
@@ -295,7 +378,20 @@ GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
 //=================================================================================
 bool TransformationGUI_RotationDlg::isValid( QString& msg )
 {
-  return !(myObjects.length() == 0 || myAxis->_is_nil());
+  switch (getConstructorId())
+    {
+    case 0: 
+      {
+       return !(myObjects.length() == 0 || myAxis->_is_nil());
+       break;
+      }
+    case 1: 
+      {
+       return !(myObjects.length() == 0 || myCentPoint->_is_nil() || myPoint1->_is_nil() || myPoint2->_is_nil() );
+       break;
+      }
+    default: return false;
+    }
 }
 
 
@@ -306,24 +402,51 @@ bool TransformationGUI_RotationDlg::isValid( QString& msg )
 bool TransformationGUI_RotationDlg::execute( ObjectList& objects )
 {
   bool res = false;
-  
+  bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
+
   GEOM::GEOM_Object_var anObj;
   
-  if (GroupPoints->CheckButton1->isChecked() || IsPreview())
-    for (int i = 0; i < myObjects.length(); i++)
+  switch ( getConstructorId() ) 
+    {
+    case 0 :
       {
-       anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateCopy( myObjects[i], myAxis, GetAngle() * PI180 );
-       if ( !anObj->_is_nil() )
-         objects.push_back( anObj._retn() );
+       if (toCreateCopy)
+         for (int i = 0; i < myObjects.length(); i++)
+           {
+             anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateCopy( myObjects[i], myAxis, GetAngle() * PI180 );
+             if ( !anObj->_is_nil() )
+               objects.push_back( anObj._retn() );
+           }
+       else
+         for (int i = 0; i < myObjects.length(); i++)
+           {
+             anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->Rotate( myObjects[i], myAxis, GetAngle() * PI180 );
+             if ( !anObj->_is_nil() )
+               objects.push_back( anObj._retn() );
+           }
+       res = true;
+       break;
       }
-  else
-    for (int i = 0; i < myObjects.length(); i++)
+    case 1 :
       {
-       anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->Rotate( myObjects[i], myAxis, GetAngle() * PI180 );
-       if ( !anObj->_is_nil() )
-         objects.push_back( anObj._retn() );
+       if (toCreateCopy)
+         for (int i = 0; i < myObjects.length(); i++)
+           {
+             anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateThreePointsCopy( myObjects[i], myCentPoint, myPoint1, myPoint2 );
+             if ( !anObj->_is_nil() )
+               objects.push_back( anObj._retn() );
+           }
+       else
+         for (int i = 0; i < myObjects.length(); i++)
+           {
+             anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateThreePoints( myObjects[i], myCentPoint, myPoint1, myPoint2 );   
+             if ( !anObj->_is_nil() )
+               objects.push_back( anObj._retn() );
+           }
+       res = true;
+       break;
       }
-  res = true;
+    }
   
   return res;
 }