Back to index

salome-geom  6.5.0
TransformationGUI_MultiTranslationDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 //  File   : TransformationGUI_MultiTranslationDlg.cxx
00023 //  Author : Damien COQUERET, Open CASCADE S.A.S.
00024 
00025 #include "TransformationGUI_MultiTranslationDlg.h"
00026 
00027 #include <DlgRef.h>
00028 #include <GeometryGUI.h>
00029 #include <GEOMBase.h>
00030 
00031 #include <SUIT_Session.h>
00032 #include <SUIT_ResourceMgr.h>
00033 #include <SUIT_Desktop.h>
00034 #include <SUIT_ViewWindow.h>
00035 #include <SUIT_ViewManager.h>
00036 #include <SalomeApp_Application.h>
00037 #include <LightApp_SelectionMgr.h>
00038 #include <GEOM_AISVector.hxx>
00039 #include <SOCC_Prs.h>
00040 #include <SOCC_ViewModel.h>
00041 
00042 // OCCT Includes
00043 #include <TopoDS_Shape.hxx>
00044 #include <TopoDS_Edge.hxx>
00045 #include <TopoDS.hxx>
00046 #include <TopExp.hxx>
00047 #include <TColStd_IndexedMapOfInteger.hxx>
00048 #include <TopTools_IndexedMapOfShape.hxx>
00049 #include <ShapeAnalysis_Edge.hxx>
00050 #include <BRep_Tool.hxx>
00051 #include <BRepBuilderAPI_MakeEdge.hxx>
00052 #include <BRep_Builder.hxx>
00053 
00054 #include <GEOMImpl_Types.hxx>
00055 
00056 //=================================================================================
00057 // class    : TransformationGUI_MultiTranslationDlg()
00058 // purpose  : Constructs a TransformationGUI_MultiTranslationDlg which is a child of 'parent', with the
00059 //            name 'name' and widget flags set to 'f'.
00060 //            The dialog will by default be modeless, unless you set 'modal' to
00061 //            TRUE to construct a modal dialog.
00062 //=================================================================================
00063 TransformationGUI_MultiTranslationDlg::TransformationGUI_MultiTranslationDlg
00064 (GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl)
00065   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
00066     myInitial(true)
00067 {
00068   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
00069   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MULTITRANSLATION_SIMPLE")));
00070   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MULTITRANSLATION_DOUBLE")));
00071   QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
00072 
00073   setWindowTitle(tr("GEOM_MULTITRANSLATION_TITLE"));
00074 
00075   /***************************************************************/
00076   mainFrame()->GroupConstructors->setTitle(tr("GEOM_MULTITRANSLATION"));
00077   mainFrame()->RadioButton1->setIcon(image0);
00078   mainFrame()->RadioButton2->setIcon(image1);
00079   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
00080   mainFrame()->RadioButton3->close();
00081 
00082   GroupPoints = new DlgRef_2Sel2Spin1Check(centralWidget());
00083   GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_SIMPLE"));
00084   GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
00085   GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR_U"));
00086   GroupPoints->TextLabel3->setText(tr("GEOM_STEP_U"));
00087   GroupPoints->TextLabel4->setText(tr("GEOM_NB_TIMES_U"));
00088   GroupPoints->CheckButton1->setText(tr("GEOM_REVERSE_U"));
00089   GroupPoints->PushButton1->setIcon(image2);
00090   GroupPoints->PushButton2->setIcon(image2);
00091   GroupPoints->LineEdit1->setReadOnly(true);
00092   GroupPoints->LineEdit2->setReadOnly(true);
00093 
00094   GroupDimensions = new DlgRef_3Sel4Spin2Check(centralWidget());
00095   GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_DOUBLE"));
00096   GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
00097   GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR_U"));
00098   GroupDimensions->TextLabel3->setText(tr("GEOM_VECTOR_V"));
00099   GroupDimensions->TextLabel4->setText(tr("GEOM_STEP_U"));
00100   GroupDimensions->TextLabel5->setText(tr("GEOM_NB_TIMES_U"));
00101   GroupDimensions->TextLabel6->setText(tr("GEOM_STEP_V"));
00102   GroupDimensions->TextLabel7->setText(tr("GEOM_NB_TIMES_V"));
00103   GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE_U"));
00104   GroupDimensions->CheckButton2->setText(tr("GEOM_REVERSE_V"));
00105   GroupDimensions->PushButton1->setIcon(image2);
00106   GroupDimensions->PushButton2->setIcon(image2);
00107   GroupDimensions->PushButton3->setIcon(image2);
00108   GroupDimensions->LineEdit1->setReadOnly(true);
00109   GroupDimensions->LineEdit2->setReadOnly(true);
00110   GroupDimensions->LineEdit3->setReadOnly(true);
00111 
00112   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00113   layout->setMargin(0); layout->setSpacing(6);
00114   layout->addWidget(GroupPoints);
00115   layout->addWidget(GroupDimensions);
00116   /***************************************************************/
00117 
00118   setHelpFileName("multi_translation_operation_page.html");
00119 
00120   Init();
00121 }
00122 
00123 //=================================================================================
00124 // function : ~TransformationGUI_MultiTranslationDlg()
00125 // purpose  : Destroys the object and frees any allocated resources
00126 //=================================================================================
00127 TransformationGUI_MultiTranslationDlg::~TransformationGUI_MultiTranslationDlg()
00128 {
00129   // no need to delete child widgets, Qt does it all for us
00130 }
00131 
00132 //=================================================================================
00133 // function : Init()
00134 // purpose  :
00135 //=================================================================================
00136 void TransformationGUI_MultiTranslationDlg::Init()
00137 {
00138   // Get setting of step value from file configuration
00139   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00140   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
00141 
00142   int SpecificStep = 1;
00143   // init variables
00144   myStepU = myStepV = 50.0;
00145   myNbTimesU = myNbTimesV = 2;
00146 
00147   // min, max, step and decimals for spin boxes & initial values
00148   initSpinBox(GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
00149   initSpinBox(GroupPoints->SpinBox_DY, 1, 999, SpecificStep);
00150   GroupPoints->SpinBox_DX->setValue(myStepU);
00151   GroupPoints->SpinBox_DY->setValue(myNbTimesU);
00152 
00153   initSpinBox(GroupDimensions->SpinBox_DX1, COORD_MIN, COORD_MAX, step, "length_precision" );
00154   initSpinBox(GroupDimensions->SpinBox_DY1, 1, 999, SpecificStep);
00155   initSpinBox(GroupDimensions->SpinBox_DX2, COORD_MIN, COORD_MAX, step, "length_precision" );
00156   initSpinBox(GroupDimensions->SpinBox_DY2, 1, 999, SpecificStep);
00157   GroupDimensions->SpinBox_DX1->setValue(myStepU);
00158   GroupDimensions->SpinBox_DY1->setValue(myNbTimesU);
00159   GroupDimensions->SpinBox_DX2->setValue(myStepV);
00160   GroupDimensions->SpinBox_DY2->setValue(myNbTimesV);
00161 
00162   GroupPoints->LineEdit1->setText("");
00163   GroupPoints->LineEdit2->setText("");
00164 
00165   GroupDimensions->LineEdit1->setText("");
00166   GroupDimensions->LineEdit2->setText("");
00167   GroupDimensions->LineEdit3->setText("");
00168 
00169   myBase.nullify();
00170   myVectorU.nullify();
00171   myVectorV.nullify();
00172 
00173   mainFrame()->GroupBoxPublish->show();
00174 
00175   // signals and slots connections
00176   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00177   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00178 
00179   connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
00180 
00181   connect(GroupPoints->PushButton1,     SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00182   connect(GroupPoints->PushButton2,     SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00183   connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00184   connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00185   connect(GroupDimensions->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00186 
00187   connect(GroupPoints->SpinBox_DX,      SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
00188   connect(GroupPoints->SpinBox_DY,      SIGNAL(valueChanged(int)),    this, SLOT(ValueChangedInSpinBox(int)));
00189   connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
00190   connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(int)),    this, SLOT(ValueChangedInSpinBox(int)));
00191   connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
00192   connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(int)),    this, SLOT(ValueChangedInSpinBox(int)));
00193 
00194   connect(GroupPoints->SpinBox_DX,      SIGNAL(textChanged(const QString& )),
00195           this, SLOT(TextValueChangedInSpinBox(const QString& )));
00196   connect(GroupDimensions->SpinBox_DX1, SIGNAL(textChanged(const QString& )),
00197           this, SLOT(TextValueChangedInSpinBox(const QString& )));
00198   connect(GroupDimensions->SpinBox_DX2, SIGNAL(textChanged(const QString& )),
00199           this, SLOT(TextValueChangedInSpinBox(const QString& )));
00200 
00201   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
00202 
00203   connect(GroupPoints->CheckButton1,     SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
00204   connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
00205   connect(GroupDimensions->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(ReverseStepV()));
00206 
00207   initName(tr("GEOM_MULTITRANSLATION"));
00208 
00209   ConstructorsClicked(0);
00210 }
00211 
00212 //=================================================================================
00213 // function : SetDoubleSpinBoxStep()
00214 // purpose  : Double spin box management
00215 //=================================================================================
00216 void TransformationGUI_MultiTranslationDlg::SetDoubleSpinBoxStep (double step)
00217 {
00218   GroupPoints->SpinBox_DX->setSingleStep(step);
00219   GroupDimensions->SpinBox_DX1->setSingleStep(step);
00220   GroupDimensions->SpinBox_DX2->setSingleStep(step);
00221 
00222   // san : Commented so as not to override specific step settings
00223   //GroupPoints->SpinBox_DY->setSingleStep((int)step);
00224   //GroupDimensions->SpinBox_DY1->setSingleStep((int)step);
00225   //GroupDimensions->SpinBox_DY2->setSingleStep((int)step);
00226 }
00227 
00228 //=================================================================================
00229 // function : ConstructorsClicked()
00230 // purpose  : Radio button management
00231 //=================================================================================
00232 void TransformationGUI_MultiTranslationDlg::ConstructorsClicked (int constructorId)
00233 {
00234   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00235 
00236   switch (constructorId) {
00237   case 0: // Translate simple
00238     {
00239       GroupDimensions->hide();
00240       GroupPoints->show();
00241 
00242       GroupPoints->LineEdit1->setText("");
00243       GroupPoints->LineEdit2->setText("");
00244       myBase.nullify();
00245       myVectorU.nullify();
00246 
00247       GroupPoints->SpinBox_DX->setValue(myStepU);
00248       GroupPoints->SpinBox_DY->setValue(myNbTimesU);
00249 
00250       GroupPoints->PushButton1->click();
00251       break;
00252     }
00253   case 1: // Translate double
00254     {
00255       GroupPoints->hide();
00256       GroupDimensions->show();
00257 
00258       GroupDimensions->LineEdit1->setText("");
00259       GroupDimensions->LineEdit2->setText("");
00260       GroupDimensions->LineEdit3->setText("");
00261       myBase.nullify();
00262       myVectorU.nullify();
00263       myVectorV.nullify();
00264 
00265       GroupDimensions->SpinBox_DX1->setValue(myStepU);
00266       GroupDimensions->SpinBox_DY1->setValue(myNbTimesU);
00267       GroupDimensions->SpinBox_DX2->setValue(myStepV);
00268       GroupDimensions->SpinBox_DY2->setValue(myNbTimesV);
00269 
00270       GroupDimensions->PushButton1->click();
00271       break;
00272     }
00273   }
00274 
00275   qApp->processEvents();
00276   updateGeometry();
00277   resize(minimumSizeHint());
00278 
00279   if (myInitial) {
00280     myInitial = false;
00281     SelectionIntoArgument();
00282   }
00283   else {
00284     processPreview();
00285   }
00286 }
00287 
00288 //=================================================================================
00289 // function : ClickOnOk()
00290 // purpose  :
00291 //=================================================================================
00292 void TransformationGUI_MultiTranslationDlg::ClickOnOk()
00293 {
00294   setIsApplyAndClose( true );
00295   if (ClickOnApply())
00296     ClickOnCancel();
00297 }
00298 
00299 //=================================================================================
00300 // function : ClickOnApply()
00301 // purpose  :
00302 //=================================================================================
00303 bool TransformationGUI_MultiTranslationDlg::ClickOnApply()
00304 {
00305   if (!onAccept())
00306     return false;
00307 
00308   initName();
00309   // activate selection and connect selection manager
00310   ConstructorsClicked(getConstructorId());
00311   return true;
00312 }
00313 
00314 //=================================================================================
00315 // function : SelectionIntoArgument()
00316 // purpose  : Called when selection is changed or on dialog initialization or activation
00317 //=================================================================================
00318 void TransformationGUI_MultiTranslationDlg::SelectionIntoArgument()
00319 {
00320   erasePreview();
00321 
00322   TopAbs_ShapeEnum aNeedType = ( myEditCurrentArgument == GroupPoints->LineEdit2 ||
00323                              myEditCurrentArgument == GroupDimensions->LineEdit2 ||
00324                              myEditCurrentArgument == GroupDimensions->LineEdit3 ) ?
00325     TopAbs_EDGE : TopAbs_SHAPE;
00326   GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
00327   TopoDS_Shape aShape;
00328   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
00329     QString aName = GEOMBase::GetName( aSelectedObject.get() );
00330     myEditCurrentArgument->setText( aName );
00331     if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
00332       myBase = aSelectedObject;
00333       if ( !myVectorU )
00334        GroupPoints->PushButton2->click();
00335     }
00336     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
00337       myVectorU = aSelectedObject;
00338       if ( !myBase )
00339        GroupPoints->PushButton1->click();
00340     }
00341     else if ( myEditCurrentArgument == GroupDimensions->LineEdit1 ) {
00342       myBase = aSelectedObject;
00343       if ( !myVectorU )
00344        GroupDimensions->PushButton2->click();
00345       else if ( !myVectorV )
00346        GroupDimensions->PushButton3->click();
00347     }
00348     else if ( myEditCurrentArgument == GroupDimensions->LineEdit2 ) {
00349       myVectorU = aSelectedObject;
00350       if ( !myVectorV )
00351        GroupDimensions->PushButton3->click();
00352       else if ( !myBase )
00353        GroupDimensions->PushButton1->click();
00354     }
00355     else if ( myEditCurrentArgument == GroupDimensions->LineEdit3 ) {
00356       myVectorV = aSelectedObject;
00357       if ( !myBase )
00358        GroupDimensions->PushButton1->click();
00359       else if ( !myVectorU )
00360        GroupDimensions->PushButton2->click();
00361     }
00362 
00363     // clear selection
00364     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00365     myGeomGUI->getApp()->selectionMgr()->clearSelected();
00366     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00367            this, SLOT(SelectionIntoArgument()));
00368   }
00369   else {
00370     if ( myEditCurrentArgument == GroupPoints->LineEdit1 ||
00371         myEditCurrentArgument == GroupDimensions->LineEdit1 )
00372       myBase.nullify();
00373     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ||
00374              myEditCurrentArgument == GroupDimensions->LineEdit2 )
00375       myVectorU.nullify();
00376     else if ( myEditCurrentArgument == GroupDimensions->LineEdit3 )
00377       myVectorV.nullify();
00378     myEditCurrentArgument->setText("");
00379   }
00380 
00381   processPreview();
00382 }
00383 
00384 //=================================================================================
00385 // function : SetEditCurrentArgument()
00386 // purpose  :
00387 //=================================================================================
00388 void TransformationGUI_MultiTranslationDlg::SetEditCurrentArgument()
00389 {
00390   QPushButton* send = (QPushButton*)sender();
00391 
00392   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00393   globalSelection(GEOM_ALLSHAPES);
00394 
00395   if (send == GroupPoints->PushButton1) {
00396     myEditCurrentArgument = GroupPoints->LineEdit1;
00397 
00398     GroupPoints->PushButton2->setDown(false);
00399     GroupPoints->LineEdit2->setEnabled(false);
00400   }
00401   else if (send == GroupPoints->PushButton2) {
00402     myEditCurrentArgument = GroupPoints->LineEdit2;
00403 
00404     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
00405 
00406     GroupPoints->PushButton1->setDown(false);
00407     GroupPoints->LineEdit1->setEnabled(false);
00408   }
00409   else if (send == GroupDimensions->PushButton1) {
00410     myEditCurrentArgument = GroupDimensions->LineEdit1;
00411 
00412     GroupDimensions->PushButton2->setDown(false);
00413     GroupDimensions->PushButton3->setDown(false);
00414     GroupDimensions->LineEdit2->setEnabled(false);
00415     GroupDimensions->LineEdit3->setEnabled(false);
00416   }
00417   else if (send == GroupDimensions->PushButton2) {
00418     myEditCurrentArgument = GroupDimensions->LineEdit2;
00419 
00420     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
00421 
00422     GroupDimensions->PushButton1->setDown(false);
00423     GroupDimensions->PushButton3->setDown(false);
00424     GroupDimensions->LineEdit1->setEnabled(false);
00425     GroupDimensions->LineEdit3->setEnabled(false);
00426   }
00427   else if (send == GroupDimensions->PushButton3) {
00428     myEditCurrentArgument = GroupDimensions->LineEdit3;
00429 
00430     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
00431 
00432     GroupDimensions->PushButton1->setDown(false);
00433     GroupDimensions->PushButton2->setDown(false);
00434     GroupDimensions->LineEdit1->setEnabled(false);
00435     GroupDimensions->LineEdit2->setEnabled(false);
00436   }
00437   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00438           this, SLOT(SelectionIntoArgument()));
00439 
00440   // enable line edit
00441   myEditCurrentArgument->setEnabled(true);
00442   myEditCurrentArgument->setFocus();
00443   // after setFocus(), because it will be setDown(false) when loses focus
00444   send->setDown(true);
00445 
00446   // seems we need it only to avoid preview disappearing, caused by selection mode change
00447   processPreview();
00448 }
00449 
00450 //=================================================================================
00451 // function : ActivateThisDialog()
00452 // purpose  :
00453 //=================================================================================
00454 void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
00455 {
00456   GEOMBase_Skeleton::ActivateThisDialog();
00457   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00458            this, SLOT( SelectionIntoArgument() ) );
00459 
00460   ConstructorsClicked( getConstructorId() );
00461 }
00462 
00463 //=================================================================================
00464 // function : enterEvent()
00465 // purpose  :
00466 //=================================================================================
00467 void TransformationGUI_MultiTranslationDlg::enterEvent (QEvent*)
00468 {
00469   if (!mainFrame()->GroupConstructors->isEnabled())
00470     ActivateThisDialog();
00471 }
00472 
00473 //=================================================================================
00474 // function : TextValueChangedInSpinBox
00475 // purpose  :
00476 //=================================================================================
00477 void TransformationGUI_MultiTranslationDlg::TextValueChangedInSpinBox( const QString& s)
00478 {
00479   QObject* send = (QObject*)sender();
00480   bool isDigit = true;
00481 
00482   switch (getConstructorId()) {
00483   case 0:
00484     GroupPoints->SpinBox_DX->text().toDouble(&isDigit);
00485     if(!isDigit){
00486       GroupPoints->CheckButton1->setChecked(false);
00487     }
00488     GroupPoints->CheckButton1->setEnabled(isDigit);
00489     break;
00490   case 1:
00491     if (send == GroupDimensions->SpinBox_DX1) {
00492       GroupDimensions->SpinBox_DX1->text().toDouble(&isDigit);
00493       if(!isDigit)
00494         GroupDimensions->CheckButton1->setChecked(false);
00495       GroupDimensions->CheckButton1->setEnabled(isDigit);
00496     }
00497     else if(send == GroupDimensions->SpinBox_DX2){
00498       GroupDimensions->SpinBox_DX2->text().toDouble(&isDigit);
00499       if(!isDigit)
00500         GroupDimensions->CheckButton2->setChecked(false);
00501       GroupDimensions->CheckButton2->setEnabled(isDigit);
00502     }
00503     break;
00504   }
00505 }
00506 
00507 //=================================================================================
00508 // function : ValueChangedInSpinBox()
00509 // purpose  :
00510 //=================================================================================
00511 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox (double newValue)
00512 {
00513   QObject* send = (QObject*)sender();
00514   switch (getConstructorId()) {
00515   case 0:
00516     if (send == GroupPoints->SpinBox_DX)
00517       myStepU = newValue;
00518     break;
00519   case 1:
00520     if (send == GroupDimensions->SpinBox_DX1)
00521       myStepU = newValue;
00522     else if (send == GroupDimensions->SpinBox_DX2)
00523       myStepV = newValue;
00524     break;
00525   }
00526 
00527   processPreview();
00528 }
00529 
00530 //=================================================================================
00531 // function : ValueChangedInSpinBox()
00532 // purpose  :
00533 //=================================================================================
00534 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox (int newValue)
00535 {
00536   QObject* send = (QObject*)sender();
00537   switch (getConstructorId()) {
00538   case 0:
00539     if (send == GroupPoints->SpinBox_DY)
00540       myNbTimesU = newValue;
00541     break;
00542   case 1:
00543     if (send == GroupDimensions->SpinBox_DY1)
00544       myNbTimesU = newValue;
00545     else if (send == GroupDimensions->SpinBox_DY2)
00546       myNbTimesV = newValue;
00547     break;
00548   }
00549 
00550   processPreview();
00551 }
00552 
00553 //=================================================================================
00554 // function : ReverseStepU()
00555 // purpose  : 'state' not used here
00556 //=================================================================================
00557 void TransformationGUI_MultiTranslationDlg::ReverseStepU()
00558 {
00559   myStepU = -myStepU;
00560 
00561   int aConstructorId = getConstructorId();
00562 
00563   if (aConstructorId == 0)
00564     GroupPoints->SpinBox_DX->setValue(myStepU);
00565   else if (aConstructorId == 1)
00566     GroupDimensions->SpinBox_DX1->setValue(myStepU);
00567 
00568   processPreview();
00569 }
00570 
00571 //=================================================================================
00572 // function : ReverseStepV
00573 // purpose  : 'state' not used here
00574 //=================================================================================
00575 void TransformationGUI_MultiTranslationDlg::ReverseStepV()
00576 {
00577   myStepV = -myStepV;
00578 
00579   GroupDimensions->SpinBox_DX2->setValue(myStepV);
00580 
00581   processPreview();
00582 }
00583 
00584 //=================================================================================
00585 // function : createOperation
00586 // purpose  :
00587 //=================================================================================
00588 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiTranslationDlg::createOperation()
00589 {
00590   return getGeomEngine()->GetITransformOperations(getStudyId());
00591 }
00592 
00593 //=================================================================================
00594 // function : isValid
00595 // purpose  :
00596 //=================================================================================
00597 bool TransformationGUI_MultiTranslationDlg::isValid (QString& msg)
00598 {
00599   bool ok = false;
00600   switch ( getConstructorId() ) {
00601   case 0:
00602     ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) &&
00603          GroupPoints->SpinBox_DY->isValid( msg, !IsPreview() ) &&
00604          myBase && myVectorU;
00605     break;
00606   case 1:
00607     ok = GroupDimensions->SpinBox_DX1->isValid( msg, !IsPreview() ) &&
00608          GroupDimensions->SpinBox_DY1->isValid( msg, !IsPreview() ) &&
00609          GroupDimensions->SpinBox_DX2->isValid( msg, !IsPreview() ) &&
00610          GroupDimensions->SpinBox_DY2->isValid( msg, !IsPreview() ) &&
00611          myBase && myVectorU && myVectorV;
00612     break;
00613   default:
00614     break;
00615   }
00616   return ok;
00617 }
00618 
00619 //=================================================================================
00620 // function : execute
00621 // purpose  :
00622 //=================================================================================
00623 bool TransformationGUI_MultiTranslationDlg::execute (ObjectList& objects)
00624 {
00625   bool res = false;
00626 
00627   GEOM::GEOM_Object_var anObj;
00628 
00629   QStringList aParameters;
00630 
00631   GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
00632 
00633   switch (getConstructorId()) {
00634   case 0:
00635     if ( myBase && myVectorU ) {
00636       createPathPreview ( myVectorU.get() );
00637       anObj = anOper->MultiTranslate1D(myBase.get(), myVectorU.get(), myStepU, myNbTimesU);
00638       if(!IsPreview()) {
00639         aParameters<<GroupPoints->SpinBox_DX->text();
00640         aParameters<<GroupPoints->SpinBox_DY->text();
00641       }
00642       res = true;
00643     }
00644     break;
00645   case 1:
00646     if ( myBase && myVectorU && myVectorV ) {
00647       createPathPreview ( myVectorU.get() );
00648       createPathPreview ( myVectorV.get() );
00649       anObj = anOper->MultiTranslate2D(myBase.get(),
00650                                        myVectorU.get(), myStepU, myNbTimesU,
00651                                        myVectorV.get(), myStepV, myNbTimesV);
00652       if(!IsPreview()) {
00653         aParameters<<GroupDimensions->SpinBox_DX1->text();
00654         aParameters<<GroupDimensions->SpinBox_DY1->text();
00655         aParameters<<GroupDimensions->SpinBox_DX2->text();
00656         aParameters<<GroupDimensions->SpinBox_DY2->text();
00657       }
00658       res = true;
00659     }
00660     break;
00661   }
00662 
00663   if (!anObj->_is_nil()) {
00664     if(!IsPreview())
00665       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00666     objects.push_back(anObj._retn());
00667   }
00668 
00669   return res;
00670 }
00671 
00672 //=================================================================================
00673 // function : addSubshapeToStudy
00674 // purpose  : virtual method to add new SubObjects if local selection
00675 //=================================================================================
00676 void TransformationGUI_MultiTranslationDlg::addSubshapesToStudy()
00677 {
00678   switch (getConstructorId()) {
00679   case 0:
00680     GEOMBase::PublishSubObject( myVectorU.get() );
00681     break;
00682   case 1:
00683     GEOMBase::PublishSubObject( myVectorU.get() );
00684     GEOMBase::PublishSubObject( myVectorV.get() );
00685     break;
00686   default:
00687     break;
00688   }
00689 }
00690 
00691 //=================================================================================
00692 // function : restoreSubShapes
00693 // purpose  :
00694 //=================================================================================
00695 void TransformationGUI_MultiTranslationDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
00696                                                               SALOMEDS::SObject_ptr theSObject)
00697 {
00698   if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
00699     // we pass here the first operation argument (object) through the list of arguments
00700     // because the rotation operation place its arguments in the data structure in another order,
00701     // and we need to point the first argument directly
00702     GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
00703     anArgs->length(1);
00704     anArgs[0] = myBase.copy();
00705     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
00706                                         /*theFindMethod=*/GEOM::FSM_MultiTransformed,
00707                                         /*theInheritFirstArg=*/true,
00708                                         mainFrame()->CheckBoxAddPrefix->isChecked());
00709   }
00710 }
00711 
00712 //=================================================================================
00713 // function : createPathPreview
00714 // purpose  :
00715 //=================================================================================
00716 void TransformationGUI_MultiTranslationDlg::createPathPreview ( GEOM::GEOM_Object_ptr thePath )
00717 {
00718   if ( IsPreview() ) {
00719     TopoDS_Shape aShape;
00720     GEOMBase::GetShape( thePath, aShape, TopAbs_SHAPE );
00721     TopoDS_Edge anEdge = TopoDS::Edge( aShape );
00722     ShapeAnalysis_Edge aShapeAnal;
00723     TopoDS_Vertex aFirst = aShapeAnal.FirstVertex( anEdge );
00724     TopoDS_Vertex aLast = aShapeAnal.LastVertex( anEdge );
00725     TopoDS_Shape aVector = BRepBuilderAPI_MakeEdge(BRep_Tool::Pnt(aFirst), BRep_Tool::Pnt(aLast)).Shape();
00726     const char* aName = "tmpVector";
00727     Handle(GEOM_AISVector) anIO = new GEOM_AISVector( aVector, aName );
00728 
00729     // add Prs to preview
00730     SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
00731     SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
00732     if (aPrs)
00733       aPrs->AddObject(anIO);
00734     GEOMBase_Helper::displayPreview( aPrs, false, true );
00735   }
00736 }