1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : TransformationGUI_MultiTranslationDlg.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
27 #include "TransformationGUI_MultiTranslationDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_ViewWindow.h>
37 #include <SUIT_ViewManager.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
40 #include <GEOM_AISVector.hxx>
42 #include <SOCC_ViewModel.h>
45 #include <TopoDS_Shape.hxx>
46 #include <TopoDS_Edge.hxx>
49 #include <TColStd_IndexedMapOfInteger.hxx>
50 #include <TopTools_IndexedMapOfShape.hxx>
51 #include <ShapeAnalysis_Edge.hxx>
52 #include <BRep_Tool.hxx>
53 #include <BRepBuilderAPI_MakeEdge.hxx>
54 #include <BRep_Builder.hxx>
56 #include <GEOMImpl_Types.hxx>
58 //=================================================================================
59 // class : TransformationGUI_MultiTranslationDlg()
60 // purpose : Constructs a TransformationGUI_MultiTranslationDlg which is a child of 'parent', with the
61 // name 'name' and widget flags set to 'f'.
62 // The dialog will by default be modeless, unless you set 'modal' to
63 // TRUE to construct a modal dialog.
64 //=================================================================================
65 TransformationGUI_MultiTranslationDlg::TransformationGUI_MultiTranslationDlg
66 (GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl)
67 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
70 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
71 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MULTITRANSLATION_SIMPLE")));
72 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MULTITRANSLATION_DOUBLE")));
73 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
75 setWindowTitle(tr("GEOM_MULTITRANSLATION_TITLE"));
77 /***************************************************************/
78 mainFrame()->GroupConstructors->setTitle(tr("GEOM_MULTITRANSLATION"));
79 mainFrame()->RadioButton1->setIcon(image0);
80 mainFrame()->RadioButton2->setIcon(image1);
81 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
82 mainFrame()->RadioButton3->close();
84 GroupPoints = new DlgRef_2Sel2Spin1Check(centralWidget());
85 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_SIMPLE"));
86 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
87 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR_U"));
88 GroupPoints->TextLabel3->setText(tr("GEOM_STEP_U"));
89 GroupPoints->TextLabel4->setText(tr("GEOM_NB_TIMES_U"));
90 GroupPoints->CheckButton1->setText(tr("GEOM_REVERSE_U"));
91 GroupPoints->PushButton1->setIcon(image2);
92 GroupPoints->PushButton2->setIcon(image2);
93 GroupPoints->LineEdit1->setReadOnly(true);
94 GroupPoints->LineEdit2->setReadOnly(true);
96 GroupDimensions = new DlgRef_3Sel4Spin2Check(centralWidget());
97 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_DOUBLE"));
98 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
99 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR_U"));
100 GroupDimensions->TextLabel3->setText(tr("GEOM_VECTOR_V"));
101 GroupDimensions->TextLabel4->setText(tr("GEOM_STEP_U"));
102 GroupDimensions->TextLabel5->setText(tr("GEOM_NB_TIMES_U"));
103 GroupDimensions->TextLabel6->setText(tr("GEOM_STEP_V"));
104 GroupDimensions->TextLabel7->setText(tr("GEOM_NB_TIMES_V"));
105 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE_U"));
106 GroupDimensions->CheckButton2->setText(tr("GEOM_REVERSE_V"));
107 GroupDimensions->PushButton1->setIcon(image2);
108 GroupDimensions->PushButton2->setIcon(image2);
109 GroupDimensions->PushButton3->setIcon(image2);
110 GroupDimensions->LineEdit1->setReadOnly(true);
111 GroupDimensions->LineEdit2->setReadOnly(true);
112 GroupDimensions->LineEdit3->setReadOnly(true);
114 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
115 layout->setMargin(0); layout->setSpacing(6);
116 layout->addWidget(GroupPoints);
117 layout->addWidget(GroupDimensions);
118 /***************************************************************/
120 setHelpFileName("multi_translation_operation_page.html");
125 //=================================================================================
126 // function : ~TransformationGUI_MultiTranslationDlg()
127 // purpose : Destroys the object and frees any allocated resources
128 //=================================================================================
129 TransformationGUI_MultiTranslationDlg::~TransformationGUI_MultiTranslationDlg()
131 // no need to delete child widgets, Qt does it all for us
134 //=================================================================================
137 //=================================================================================
138 void TransformationGUI_MultiTranslationDlg::Init()
140 // Get setting of step value from file configuration
141 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
142 double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
144 int SpecificStep = 1;
145 // min, max, step and decimals for spin boxes & initial values
146 initSpinBox(GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
147 initSpinBox(GroupPoints->SpinBox_DY, 1, 999, SpecificStep);
148 GroupPoints->SpinBox_DX->setValue(myStepU);
149 GroupPoints->SpinBox_DY->setValue(myNbTimesU);
151 initSpinBox(GroupDimensions->SpinBox_DX1, COORD_MIN, COORD_MAX, step, "length_precision" );
152 initSpinBox(GroupDimensions->SpinBox_DY1, 1, 999, SpecificStep);
153 initSpinBox(GroupDimensions->SpinBox_DX2, COORD_MIN, COORD_MAX, step, "length_precision" );
154 initSpinBox(GroupDimensions->SpinBox_DY2, 1, 999, SpecificStep);
155 GroupDimensions->SpinBox_DX1->setValue(myStepU);
156 GroupDimensions->SpinBox_DY1->setValue(myNbTimesU);
157 GroupDimensions->SpinBox_DX2->setValue(myStepV);
158 GroupDimensions->SpinBox_DY2->setValue(myNbTimesV);
161 myStepU = myStepV = 50.0;
162 myNbTimesU = myNbTimesV = 2;
164 GroupPoints->LineEdit1->setText("");
165 GroupPoints->LineEdit2->setText("");
167 GroupDimensions->LineEdit1->setText("");
168 GroupDimensions->LineEdit2->setText("");
169 GroupDimensions->LineEdit3->setText("");
171 myBase = myVectorU = myVectorV = GEOM::GEOM_Object::_nil();
173 mainFrame()->GroupBoxPublish->show();
175 // signals and slots connections
176 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
177 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
179 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
181 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
182 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
183 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
184 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
185 connect(GroupDimensions->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
187 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
188 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
189 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
190 connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
191 connect(GroupDimensions->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
193 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
194 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(int)), this, SLOT(ValueChangedInSpinBox(int)));
195 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
196 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(int)), this, SLOT(ValueChangedInSpinBox(int)));
197 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
198 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(int)), this, SLOT(ValueChangedInSpinBox(int)));
200 connect(GroupPoints->SpinBox_DX, SIGNAL(textChanged(const QString& )),
201 this, SLOT(TextValueChangedInSpinBox(const QString& )));
202 connect(GroupDimensions->SpinBox_DX1, SIGNAL(textChanged(const QString& )),
203 this, SLOT(TextValueChangedInSpinBox(const QString& )));
204 connect(GroupDimensions->SpinBox_DX2, SIGNAL(textChanged(const QString& )),
205 this, SLOT(TextValueChangedInSpinBox(const QString& )));
207 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
209 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
210 connect(GroupDimensions->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(ReverseStepU()));
211 connect(GroupDimensions->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(ReverseStepV()));
213 initName(tr("GEOM_MULTITRANSLATION"));
215 ConstructorsClicked(0);
218 //=================================================================================
219 // function : SetDoubleSpinBoxStep()
220 // purpose : Double spin box management
221 //=================================================================================
222 void TransformationGUI_MultiTranslationDlg::SetDoubleSpinBoxStep (double step)
224 GroupPoints->SpinBox_DX->setSingleStep(step);
225 GroupDimensions->SpinBox_DX1->setSingleStep(step);
226 GroupDimensions->SpinBox_DX2->setSingleStep(step);
228 // san : Commented so as not to override specific step settings
229 //GroupPoints->SpinBox_DY->setSingleStep((int)step);
230 //GroupDimensions->SpinBox_DY1->setSingleStep((int)step);
231 //GroupDimensions->SpinBox_DY2->setSingleStep((int)step);
234 //=================================================================================
235 // function : ConstructorsClicked()
236 // purpose : Radio button management
237 //=================================================================================
238 void TransformationGUI_MultiTranslationDlg::ConstructorsClicked (int constructorId)
240 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
242 switch (constructorId) {
243 case 0: // Translate simple
245 GroupDimensions->hide();
248 GroupPoints->LineEdit1->setText("");
249 GroupPoints->LineEdit2->setText("");
250 myBase = myVectorU = GEOM::GEOM_Object::_nil();
252 GroupPoints->SpinBox_DX->setValue(myStepU);
253 GroupPoints->SpinBox_DY->setValue(myNbTimesU);
255 GroupPoints->PushButton1->click();
258 case 1: // Translate double
261 GroupDimensions->show();
263 GroupDimensions->LineEdit1->setText("");
264 GroupDimensions->LineEdit2->setText("");
265 GroupDimensions->LineEdit3->setText("");
266 myBase = myVectorU = myVectorV = GEOM::GEOM_Object::_nil();
268 GroupDimensions->SpinBox_DX1->setValue(myStepU);
269 GroupDimensions->SpinBox_DY1->setValue(myNbTimesU);
270 GroupDimensions->SpinBox_DX2->setValue(myStepV);
271 GroupDimensions->SpinBox_DY2->setValue(myNbTimesV);
273 GroupDimensions->PushButton1->click();
278 qApp->processEvents();
280 resize(minimumSizeHint());
284 SelectionIntoArgument();
291 //=================================================================================
292 // function : ClickOnOk()
294 //=================================================================================
295 void TransformationGUI_MultiTranslationDlg::ClickOnOk()
301 //=================================================================================
302 // function : ClickOnApply()
304 //=================================================================================
305 bool TransformationGUI_MultiTranslationDlg::ClickOnApply()
311 // activate selection and connect selection manager
312 ConstructorsClicked(getConstructorId());
316 //=================================================================================
317 // function : SelectionIntoArgument()
318 // purpose : Called when selection is changed or on dialog initialization or activation
319 //=================================================================================
320 void TransformationGUI_MultiTranslationDlg::SelectionIntoArgument()
323 myEditCurrentArgument->setText("");
325 if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
326 myEditCurrentArgument == GroupDimensions->LineEdit1)
327 myBase = GEOM::GEOM_Object::_nil();
328 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
329 myEditCurrentArgument == GroupDimensions->LineEdit2)
330 myVectorU = GEOM::GEOM_Object::_nil();
331 else if (myEditCurrentArgument == GroupDimensions->LineEdit3)
332 myVectorV = GEOM::GEOM_Object::_nil();
334 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
335 SALOME_ListIO aSelList;
336 aSelMgr->selectedObjects(aSelList);
338 if (aSelList.Extent() != 1)
342 Standard_Boolean testResult = Standard_False;;
343 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
345 if (!testResult || CORBA::is_nil(aSelectedObject) || !GEOMBase::IsShape(aSelectedObject))
348 QString aName = GEOMBase::GetName(aSelectedObject);
350 if (myEditCurrentArgument == GroupPoints->LineEdit1 ||
351 myEditCurrentArgument == GroupDimensions->LineEdit1)
352 myBase = aSelectedObject;
353 else if (myEditCurrentArgument == GroupPoints->LineEdit2 ||
354 myEditCurrentArgument == GroupDimensions->LineEdit2 ||
355 myEditCurrentArgument == GroupDimensions->LineEdit3) {
358 if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) {
359 TColStd_IndexedMapOfInteger aMap;
360 aSelMgr->GetIndexes(aSelList.First(), aMap);
361 if (aMap.Extent() == 1) {
362 int anIndex = aMap(1);
363 aName += QString(":edge_%1").arg(anIndex);
365 //Find SubShape Object in Father
366 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
368 if (aFindedObject->_is_nil()) { // Object not found in study
369 GEOM::GEOM_IShapesOperations_var aShapesOp =
370 getGeomEngine()->GetIShapesOperations(getStudyId());
371 if (myEditCurrentArgument == GroupDimensions->LineEdit3)
372 myVectorV = aShapesOp->GetSubShape(aSelectedObject, anIndex);
374 myVectorU = aShapesOp->GetSubShape(aSelectedObject, anIndex);
377 if (myEditCurrentArgument == GroupDimensions->LineEdit3)
378 myVectorV = aFindedObject;
380 myVectorU = aFindedObject;
384 if (aShape.ShapeType() != TopAbs_EDGE) {
385 aSelectedObject = GEOM::GEOM_Object::_nil();
388 if (myEditCurrentArgument == GroupDimensions->LineEdit3)
389 myVectorV = aSelectedObject;
391 myVectorU = aSelectedObject;
395 myEditCurrentArgument->setText(aName);
397 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
398 if (!myBase->_is_nil() && myVectorU->_is_nil())
399 GroupPoints->PushButton2->click();
401 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
402 if (!myVectorU->_is_nil() && myBase->_is_nil())
403 GroupPoints->PushButton1->click();
405 else if (myEditCurrentArgument == GroupDimensions->LineEdit1) {
406 if (!myBase->_is_nil() && myVectorU->_is_nil())
407 GroupDimensions->PushButton2->click();
409 else if (myEditCurrentArgument == GroupDimensions->LineEdit2) {
410 if (!myVectorU->_is_nil() && myVectorV->_is_nil())
411 GroupDimensions->PushButton3->click();
413 else if (myEditCurrentArgument == GroupDimensions->LineEdit3) {
414 if (!myVectorV->_is_nil() && myBase->_is_nil())
415 GroupDimensions->PushButton1->click();
419 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
420 myGeomGUI->getApp()->selectionMgr()->clearSelected();
421 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
422 this, SLOT(SelectionIntoArgument()));
427 //=================================================================================
428 // function : SetEditCurrentArgument()
430 //=================================================================================
431 void TransformationGUI_MultiTranslationDlg::SetEditCurrentArgument()
433 QPushButton* send = (QPushButton*)sender();
435 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
436 globalSelection(GEOM_ALLSHAPES);
438 if (send == GroupPoints->PushButton1) {
439 myEditCurrentArgument = GroupPoints->LineEdit1;
441 GroupPoints->PushButton2->setDown(false);
442 GroupPoints->LineEdit2->setEnabled(false);
444 else if (send == GroupPoints->PushButton2) {
445 myEditCurrentArgument = GroupPoints->LineEdit2;
447 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
449 GroupPoints->PushButton1->setDown(false);
450 GroupPoints->LineEdit1->setEnabled(false);
452 else if (send == GroupDimensions->PushButton1) {
453 myEditCurrentArgument = GroupDimensions->LineEdit1;
455 GroupDimensions->PushButton2->setDown(false);
456 GroupDimensions->PushButton3->setDown(false);
457 GroupDimensions->LineEdit2->setEnabled(false);
458 GroupDimensions->LineEdit3->setEnabled(false);
460 else if (send == GroupDimensions->PushButton2) {
461 myEditCurrentArgument = GroupDimensions->LineEdit2;
463 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
465 GroupDimensions->PushButton1->setDown(false);
466 GroupDimensions->PushButton3->setDown(false);
467 GroupDimensions->LineEdit1->setEnabled(false);
468 GroupDimensions->LineEdit3->setEnabled(false);
470 else if (send == GroupDimensions->PushButton3) {
471 myEditCurrentArgument = GroupDimensions->LineEdit3;
473 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
475 GroupDimensions->PushButton1->setDown(false);
476 GroupDimensions->PushButton2->setDown(false);
477 GroupDimensions->LineEdit1->setEnabled(false);
478 GroupDimensions->LineEdit2->setEnabled(false);
480 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
481 this, SLOT(SelectionIntoArgument()));
484 myEditCurrentArgument->setEnabled(true);
485 myEditCurrentArgument->setFocus();
486 // after setFocus(), because it will be setDown(false) when loses focus
489 // seems we need it only to avoid preview disappearing, caused by selection mode change
493 //=================================================================================
494 // function : LineEditReturnPressed()
496 //=================================================================================
497 void TransformationGUI_MultiTranslationDlg::LineEditReturnPressed()
499 QLineEdit* send = (QLineEdit*)sender();
500 if (send == GroupPoints->LineEdit1 || send == GroupDimensions->LineEdit1 ||
501 send == GroupPoints->LineEdit2 || send == GroupDimensions->LineEdit2 ||
502 send == GroupDimensions->LineEdit3) {
503 myEditCurrentArgument = send;
504 GEOMBase_Skeleton::LineEditReturnPressed();
508 //=================================================================================
509 // function : ActivateThisDialog()
511 //=================================================================================
512 void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
514 GEOMBase_Skeleton::ActivateThisDialog();
515 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
516 this, SLOT( SelectionIntoArgument() ) );
518 ConstructorsClicked( getConstructorId() );
521 //=================================================================================
522 // function : enterEvent()
524 //=================================================================================
525 void TransformationGUI_MultiTranslationDlg::enterEvent (QEvent*)
527 if (!mainFrame()->GroupConstructors->isEnabled())
528 ActivateThisDialog();
531 //=================================================================================
532 // function : TextValueChangedInSpinBox
534 //=================================================================================
535 void TransformationGUI_MultiTranslationDlg::TextValueChangedInSpinBox( const QString& s)
537 QObject* send = (QObject*)sender();
540 switch (getConstructorId()) {
542 GroupPoints->SpinBox_DX->text().toDouble(&isDigit);
544 GroupPoints->CheckButton1->setChecked(false);
546 GroupPoints->CheckButton1->setEnabled(isDigit);
549 if (send == GroupDimensions->SpinBox_DX1) {
550 GroupDimensions->SpinBox_DX1->text().toDouble(&isDigit);
552 GroupDimensions->CheckButton1->setChecked(false);
553 GroupDimensions->CheckButton1->setEnabled(isDigit);
555 else if(send == GroupDimensions->SpinBox_DX2){
556 GroupDimensions->SpinBox_DX2->text().toDouble(&isDigit);
558 GroupDimensions->CheckButton2->setChecked(false);
559 GroupDimensions->CheckButton2->setEnabled(isDigit);
565 //=================================================================================
566 // function : ValueChangedInSpinBox()
568 //=================================================================================
569 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox (double newValue)
571 QObject* send = (QObject*)sender();
572 switch (getConstructorId()) {
574 if (send == GroupPoints->SpinBox_DX)
578 if (send == GroupDimensions->SpinBox_DX1)
580 else if (send == GroupDimensions->SpinBox_DX2)
588 //=================================================================================
589 // function : ValueChangedInSpinBox()
591 //=================================================================================
592 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox (int newValue)
594 QObject* send = (QObject*)sender();
595 switch (getConstructorId()) {
597 if (send == GroupPoints->SpinBox_DY)
598 myNbTimesU = newValue;
601 if (send == GroupDimensions->SpinBox_DY1)
602 myNbTimesU = newValue;
603 else if (send == GroupDimensions->SpinBox_DY2)
604 myNbTimesV = newValue;
611 //=================================================================================
612 // function : ReverseStepU()
613 // purpose : 'state' not used here
614 //=================================================================================
615 void TransformationGUI_MultiTranslationDlg::ReverseStepU()
619 int aConstructorId = getConstructorId();
621 if (aConstructorId == 0)
622 GroupPoints->SpinBox_DX->setValue(myStepU);
623 else if (aConstructorId == 1)
624 GroupDimensions->SpinBox_DX1->setValue(myStepU);
629 //=================================================================================
630 // function : ReverseStepV
631 // purpose : 'state' not used here
632 //=================================================================================
633 void TransformationGUI_MultiTranslationDlg::ReverseStepV()
637 GroupDimensions->SpinBox_DX2->setValue(myStepV);
642 //=================================================================================
643 // function : createOperation
645 //=================================================================================
646 GEOM::GEOM_IOperations_ptr TransformationGUI_MultiTranslationDlg::createOperation()
648 return getGeomEngine()->GetITransformOperations(getStudyId());
651 //=================================================================================
652 // function : isValid
654 //=================================================================================
655 bool TransformationGUI_MultiTranslationDlg::isValid (QString& msg)
657 int aConstructorId = getConstructorId();
659 if (aConstructorId == 0) {
661 ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
662 ok = GroupPoints->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
663 return !(myBase->_is_nil() || myVectorU->_is_nil()) && ok;
665 else if (aConstructorId == 1) {
667 ok = GroupDimensions->SpinBox_DX1->isValid( msg, !IsPreview() ) && ok;
668 ok = GroupDimensions->SpinBox_DY1->isValid( msg, !IsPreview() ) && ok;
669 ok = GroupDimensions->SpinBox_DX2->isValid( msg, !IsPreview() ) && ok;
670 ok = GroupDimensions->SpinBox_DY2->isValid( msg, !IsPreview() ) && ok;
671 return !(myBase->_is_nil() || myVectorU->_is_nil() || myVectorV->_is_nil()) && ok;
676 //=================================================================================
677 // function : execute
679 //=================================================================================
680 bool TransformationGUI_MultiTranslationDlg::execute (ObjectList& objects)
684 GEOM::GEOM_Object_var anObj;
686 QStringList aParameters;
688 GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
690 switch (getConstructorId()) {
692 if (!CORBA::is_nil(myBase) && !CORBA::is_nil(myVectorU)) {
693 createPathPreview ( myVectorU );
694 anObj = anOper->MultiTranslate1D(myBase, myVectorU, myStepU, myNbTimesU);
696 aParameters<<GroupPoints->SpinBox_DX->text();
697 aParameters<<GroupPoints->SpinBox_DY->text();
703 if (!CORBA::is_nil(myBase) && !CORBA::is_nil(myVectorU) &&
704 !CORBA::is_nil(myVectorV)) {
705 createPathPreview ( myVectorU );
706 createPathPreview ( myVectorV );
707 anObj = anOper->MultiTranslate2D(myBase,
708 myVectorU, myStepU, myNbTimesU,
709 myVectorV, myStepV, myNbTimesV);
711 aParameters<<GroupDimensions->SpinBox_DX1->text();
712 aParameters<<GroupDimensions->SpinBox_DY1->text();
713 aParameters<<GroupDimensions->SpinBox_DX2->text();
714 aParameters<<GroupDimensions->SpinBox_DY2->text();
721 if (!anObj->_is_nil()) {
723 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
724 objects.push_back(anObj._retn());
730 //=================================================================================
731 // function : addSubshapeToStudy
732 // purpose : virtual method to add new SubObjects if local selection
733 //=================================================================================
734 void TransformationGUI_MultiTranslationDlg::addSubshapesToStudy()
736 QMap<QString, GEOM::GEOM_Object_var> objMap;
738 switch (getConstructorId()) {
740 objMap[GroupPoints->LineEdit2->text()] = myVectorU;
743 objMap[GroupDimensions->LineEdit2->text()] = myVectorU;
744 objMap[GroupDimensions->LineEdit3->text()] = myVectorV;
747 addSubshapesToFather(objMap);
750 //=================================================================================
751 // function : restoreSubShapes
753 //=================================================================================
754 void TransformationGUI_MultiTranslationDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
755 SALOMEDS::SObject_ptr theSObject)
757 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
758 // we pass here the first operation argument (object) through the list of arguments
759 // because the rotation operation place its arguments in the data structure in another order,
760 // and we need to point the first argument directly
761 GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
764 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
765 /*theFindMethod=*/GEOM::FSM_Transformed,
766 /*theInheritFirstArg=*/true,
767 mainFrame()->CheckBoxAddPrefix->isChecked());
771 //=================================================================================
772 // function : createPathPreview
774 //=================================================================================
775 void TransformationGUI_MultiTranslationDlg::createPathPreview ( GEOM::GEOM_Object_var thePath )
779 GEOMBase::GetShape( thePath, aShape, TopAbs_SHAPE );
780 TopoDS_Edge anEdge = TopoDS::Edge( aShape );
781 ShapeAnalysis_Edge aShapeAnal;
782 TopoDS_Vertex aFirst = aShapeAnal.FirstVertex( anEdge );
783 TopoDS_Vertex aLast = aShapeAnal.LastVertex( anEdge );
784 TopoDS_Shape aVector = BRepBuilderAPI_MakeEdge(BRep_Tool::Pnt(aFirst), BRep_Tool::Pnt(aLast)).Shape();
785 const char* aName = "tmpVector";
786 Handle(GEOM_AISVector) anIO = new GEOM_AISVector( aVector, aName );
788 // add Prs to preview
789 SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
790 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
792 aPrs->AddObject(anIO);
793 GEOMBase_Helper::displayPreview( aPrs, false, true );