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_PositionDlg.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
27 #include "TransformationGUI_PositionDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
37 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TColStd_MapOfInteger.hxx>
42 #include <GEOMImpl_Types.hxx>
44 //=================================================================================
45 // class : TransformationGUI_PositionDlg()
46 // purpose : Constructs a TransformationGUI_PositionDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 TransformationGUI_PositionDlg::TransformationGUI_PositionDlg
52 (GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl)
53 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
56 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
57 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POSITION")));
58 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POSITION2")));
59 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POSITION3")));
60 QPixmap imageselect (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
62 setWindowTitle(tr("GEOM_POSITION_TITLE"));
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle(tr("GEOM_POSITION"));
66 mainFrame()->RadioButton1->setIcon(image0);
67 mainFrame()->RadioButton2->setIcon(image1);
68 mainFrame()->RadioButton3->setIcon(image2);
70 Group1 = new DlgRef_4Sel1Spin3Check(centralWidget());
71 Group1->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
72 Group1->TextLabel1->setText(tr("GEOM_OBJECTS"));
73 Group1->TextLabel2->setText(tr("GEOM_START_LCS"));
74 Group1->TextLabel3->setText(tr("GEOM_DISTANCE"));
75 Group1->TextLabel4->setText(tr("GEOM_END_LCS"));
76 Group1->TextLabel5->setText(tr("GEOM_PATH_OBJECT"));
77 Group1->PushButton1->setIcon(imageselect);
78 Group1->PushButton2->setIcon(imageselect);
79 Group1->PushButton4->setIcon(imageselect);
80 Group1->PushButton5->setIcon(imageselect);
81 Group1->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
82 Group1->CheckButton2->setText(tr("SELECT_UNPUBLISHED_EDGES"));
83 Group1->CheckButton3->setText(tr("GEOM_REVERSE_DIRECTION"));
85 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
86 layout->setMargin(0); layout->setSpacing(6);
87 layout->addWidget(Group1);
88 /***************************************************************/
90 setHelpFileName("modify_location_operation_page.html");
92 // Activate Create a Copy mode
93 Group1->CheckButton1->setChecked(true);
94 Group1->CheckButton1->setChecked(false);
95 CreateCopyModeChanged(true);
100 //=================================================================================
101 // function : ~TransformationGUI_PositionDlg()
102 // purpose : Destroys the object and frees any allocated resources
103 //=================================================================================
104 TransformationGUI_PositionDlg::~TransformationGUI_PositionDlg()
106 // no need to delete child widgets, Qt does it all for us
109 //=================================================================================
112 //=================================================================================
113 void TransformationGUI_PositionDlg::Init()
116 Group1->LineEdit1->setReadOnly(true);
117 Group1->LineEdit2->setReadOnly(true);
118 Group1->LineEdit4->setReadOnly(true);
119 Group1->LineEdit5->setReadOnly(true);
121 Group1->LineEdit1->setText("");
122 Group1->LineEdit2->setText("");
123 Group1->LineEdit4->setText("");
124 Group1->LineEdit5->setText("");
126 initSpinBox(Group1->SpinBox_DX, 0, 1, 0.05, "parametric_precision" );
127 Group1->SpinBox_DX->setValue(0);
129 Group1->CheckButton2->setEnabled(false);
131 myStartLCS = myEndLCS = GEOM::GEOM_Object::_nil();
133 mainFrame()->GroupBoxPublish->show();
135 // signals and slots connections
136 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
137 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
139 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
141 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142 connect(Group1->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
143 connect(Group1->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
144 connect(Group1->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147 connect(Group1->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
148 connect(Group1->LineEdit4, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
149 connect(Group1->LineEdit5, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
151 connect(Group1->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
152 connect(Group1->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
154 connect(Group1->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(SelectionTypeButtonClicked()));
155 connect(Group1->CheckButton3, SIGNAL(toggled(bool)), this, SLOT(ValueChangedInSpinBox()));
157 initName(tr("GEOM_POSITION"));
159 ConstructorsClicked(0);
162 //=================================================================================
163 // function : ConstructorsClicked()
164 // purpose : Radio button management
165 //=================================================================================
166 void TransformationGUI_PositionDlg::ConstructorsClicked (int constructorId)
168 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
170 Group1->LineEdit2->clear();
171 Group1->LineEdit4->clear();
172 Group1->LineEdit5->clear();
173 myStartLCS = GEOM::GEOM_Object::_nil();
174 myEndLCS = GEOM::GEOM_Object::_nil();
175 myPath = GEOM::GEOM_Object::_nil();
177 switch (constructorId) {
180 Group1->LineEdit2->hide();
181 Group1->TextLabel2->hide();
182 Group1->PushButton2->hide();
184 Group1->LineEdit5->hide();
185 Group1->TextLabel5->hide();
186 Group1->PushButton5->hide();
188 Group1->SpinBox_DX->hide();
189 Group1->TextLabel3->hide();
191 Group1->LineEdit4->show();
192 Group1->TextLabel4->show();
193 Group1->PushButton4->show();
195 Group1->PushButton1->click();
197 Group1->CheckButton2->hide();
198 Group1->CheckButton3->hide();
203 Group1->LineEdit2->show();
204 Group1->TextLabel2->show();
205 Group1->PushButton2->show();
207 Group1->LineEdit5->hide();
208 Group1->TextLabel5->hide();
209 Group1->PushButton5->hide();
211 Group1->SpinBox_DX->hide();
212 Group1->TextLabel3->hide();
214 Group1->PushButton1->click();
216 Group1->CheckButton2->hide();
217 Group1->CheckButton3->hide();
222 Group1->LineEdit4->hide();
223 Group1->TextLabel4->hide();
224 Group1->PushButton4->hide();
226 Group1->LineEdit2->hide();
227 Group1->TextLabel2->hide();
228 Group1->PushButton2->hide();
230 Group1->LineEdit5->show();
231 Group1->TextLabel5->show();
232 Group1->PushButton5->show();
234 Group1->SpinBox_DX->show();
235 Group1->TextLabel3->show();
237 Group1->PushButton1->click();
239 Group1->CheckButton2->show();
240 Group1->CheckButton3->show();
245 qApp->processEvents();
247 resize(minimumSizeHint());
251 SelectionIntoArgument();
258 //=================================================================================
259 // function : SelectionBittonClicked()
260 // purpose : Selection type Radio button management
261 //=================================================================================
262 void TransformationGUI_PositionDlg::SelectionTypeButtonClicked()
264 if ( Group1->CheckButton2->isChecked() ) {
265 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
267 TColStd_MapOfInteger aMap;
270 globalSelection(aMap);
274 //=================================================================================
275 // function : ValueChangedInSpinBox()
277 //=================================================================================
278 void TransformationGUI_PositionDlg::ValueChangedInSpinBox()
283 //=================================================================================
284 // function : ClickOnOk()
286 //=================================================================================
287 void TransformationGUI_PositionDlg::ClickOnOk()
293 //=================================================================================
294 // function : ClickOnApply()
296 //=================================================================================
297 bool TransformationGUI_PositionDlg::ClickOnApply()
299 if (!onAccept(Group1->CheckButton1->isChecked()))
303 // activate selection and connect selection manager
304 ConstructorsClicked(getConstructorId());
308 //=================================================================================
309 // function : SelectionIntoArgument()
310 // purpose : Called when selection is changed or on dialog initialization or activation
311 //=================================================================================
312 void TransformationGUI_PositionDlg::SelectionIntoArgument()
315 myEditCurrentArgument->setText("");
317 if (myEditCurrentArgument == Group1->LineEdit1)
319 else if (myEditCurrentArgument == Group1->LineEdit2)
320 myStartLCS = GEOM::GEOM_Object::_nil();
321 else if (myEditCurrentArgument == Group1->LineEdit4)
322 myEndLCS = GEOM::GEOM_Object::_nil();
323 else if (myEditCurrentArgument == Group1->LineEdit5)
324 myPath = GEOM::GEOM_Object::_nil();
326 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
327 SALOME_ListIO aSelList;
328 aSelMgr->selectedObjects(aSelList);
332 if (myEditCurrentArgument == Group1->LineEdit1) {
333 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName);
337 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myObjects);
338 if (!myObjects.length())
341 myEditCurrentArgument->setText(aName);
343 if (getConstructorId() == 2)
344 Group1->PushButton5->click();
346 else if (myEditCurrentArgument == Group1->LineEdit2) {
347 if (aSelList.Extent() != 1)
351 Standard_Boolean testResult = Standard_False;
352 myStartLCS = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
353 if (!testResult || CORBA::is_nil(myStartLCS))
356 aName = GEOMBase::GetName(myStartLCS);
357 myEditCurrentArgument->setText(aName);
359 if (!myStartLCS->_is_nil() && myEndLCS->_is_nil())
360 Group1->PushButton4->click();
362 else if (myEditCurrentArgument == Group1->LineEdit4) {
363 myEndLCS = GEOM::GEOM_Object::_nil();
364 if (aSelList.Extent() != 1)
367 Standard_Boolean testResult = Standard_False;
368 myEndLCS = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
369 if (!testResult || CORBA::is_nil(myEndLCS))
372 aName = GEOMBase::GetName(myEndLCS);
373 myEditCurrentArgument->setText(aName);
375 if (!myEndLCS->_is_nil() && !myObjects.length())
376 Group1->PushButton1->click();
378 else if (myEditCurrentArgument == Group1->LineEdit5) {
379 myPath = GEOM::GEOM_Object::_nil();
380 if (aSelList.Extent() != 1)
383 Standard_Boolean testResult = Standard_False;
384 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
385 if (!testResult || aSelectedObject->_is_nil())
388 aName = GEOMBase::GetName(myPath);
391 if (!GEOMBase::GetShape(aSelectedObject, S))
394 TColStd_IndexedMapOfInteger aMap;
395 aSelMgr->GetIndexes(aSelList.First(), aMap);
396 aName = GEOMBase::GetName(aSelectedObject);
397 if (aMap.Extent() == 1) {
398 int anIndex = aMap(1);
399 aName.append(":edge_" + QString::number(anIndex));
401 //Find SubShape Object in Father
402 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
404 if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
405 GEOM::GEOM_IShapesOperations_var aShapesOp =
406 getGeomEngine()->GetIShapesOperations(getStudyId());
407 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
409 else { // get Object from study
410 aSelectedObject = aFindedObject;
414 if (S.ShapeType() != TopAbs_EDGE && S.ShapeType() != TopAbs_WIRE) {
415 aSelectedObject = GEOM::GEOM_Object::_nil();
421 myEditCurrentArgument->setText(aName);
422 myPath = aSelectedObject;
424 if (!myPath->_is_nil() && !myObjects.length())
425 Group1->PushButton1->click();
429 /* disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
430 myGeomGUI->getApp()->selectionMgr()->clearSelected();
431 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
432 this, SLOT(SelectionIntoArgument()));*/
433 // here commented, because multiple objects can be selected IPAL 21437
438 //=================================================================================
439 // function : SetEditCurrentArgument()
441 //=================================================================================
442 void TransformationGUI_PositionDlg::SetEditCurrentArgument()
444 QPushButton* send = (QPushButton*)sender();
446 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
447 if (send == Group1->PushButton1) {
448 myEditCurrentArgument = Group1->LineEdit1;
452 Group1->PushButton2->setDown(false);
453 Group1->PushButton4->setDown(false);
454 Group1->PushButton5->setDown(false);
455 Group1->LineEdit2->setEnabled(false);
456 Group1->LineEdit4->setEnabled(false);
457 Group1->LineEdit5->setEnabled(false);
459 Group1->CheckButton2->setEnabled(false);
461 else if (send == Group1->PushButton2) {
462 myEditCurrentArgument = Group1->LineEdit2;
464 TColStd_MapOfInteger aMap;
465 aMap.Add(GEOM_PLANE);
466 aMap.Add(GEOM_MARKER);
467 globalSelection(aMap);
469 Group1->PushButton1->setDown(false);
470 Group1->PushButton4->setDown(false);
471 Group1->PushButton5->setDown(false);
472 Group1->LineEdit1->setEnabled(false);
473 Group1->LineEdit4->setEnabled(false);
474 Group1->LineEdit5->setEnabled(false);
476 Group1->CheckButton2->setEnabled(false);
478 else if (send == Group1->PushButton4) {
479 myEditCurrentArgument = Group1->LineEdit4;
481 TColStd_MapOfInteger aMap;
482 aMap.Add(GEOM_PLANE);
483 aMap.Add(GEOM_MARKER);
484 globalSelection(aMap);
486 Group1->PushButton1->setDown(false);
487 Group1->PushButton2->setDown(false);
488 Group1->PushButton5->setDown(false);
489 Group1->LineEdit1->setEnabled(false);
490 Group1->LineEdit2->setEnabled(false);
491 Group1->LineEdit5->setEnabled(false);
493 Group1->CheckButton2->setEnabled(false);
495 else if (send == Group1->PushButton5) {
496 myEditCurrentArgument = Group1->LineEdit5;
498 Group1->CheckButton2->setEnabled(true);
500 if ( Group1->CheckButton2->isChecked() ) {
501 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
503 TColStd_MapOfInteger aMap;
506 globalSelection(aMap);
509 Group1->PushButton1->setDown(false);
510 Group1->PushButton2->setDown(false);
511 Group1->PushButton4->setDown(false);
512 Group1->LineEdit1->setEnabled(false);
513 Group1->LineEdit2->setEnabled(false);
514 Group1->LineEdit4->setEnabled(false);
516 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
517 this, SLOT(SelectionIntoArgument()));
520 myEditCurrentArgument->setEnabled(true);
521 myEditCurrentArgument->setFocus();
522 // after setFocus(), because it will be setDown(false) when loses focus
525 // seems we need it only to avoid preview disappearing, caused by selection mode change
529 //=================================================================================
530 // function : LineEditReturnPressed()
532 //=================================================================================
533 void TransformationGUI_PositionDlg::LineEditReturnPressed()
535 QLineEdit* send = (QLineEdit*)sender();
536 if (send == Group1->LineEdit1 ||
537 send == Group1->LineEdit2 ||
538 send == Group1->LineEdit4 ||
539 send == Group1->LineEdit5 ) {
540 myEditCurrentArgument = send;
541 GEOMBase_Skeleton::LineEditReturnPressed();
544 if (send == Group1->LineEdit5)
545 Group1->CheckButton2->setEnabled(true);
547 Group1->CheckButton2->setEnabled(false);
550 //=================================================================================
551 // function : ActivateThisDialog()
553 //=================================================================================
554 void TransformationGUI_PositionDlg::ActivateThisDialog()
556 GEOMBase_Skeleton::ActivateThisDialog();
557 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
558 this, SLOT( SelectionIntoArgument() ) );
560 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
561 this, SLOT( SelectionIntoArgument() ) );
563 ConstructorsClicked( getConstructorId() );
566 //=================================================================================
567 // function : enterEvent()
568 // purpose : when mouse enter onto the QWidget
569 //=================================================================================
570 void TransformationGUI_PositionDlg::enterEvent (QEvent*)
572 if (!mainFrame()->GroupConstructors->isEnabled())
573 ActivateThisDialog();
576 //=================================================================================
577 // function : createOperation
579 //=================================================================================
580 GEOM::GEOM_IOperations_ptr TransformationGUI_PositionDlg::createOperation()
582 return getGeomEngine()->GetITransformOperations(getStudyId());
585 //=================================================================================
586 // function : isValid
588 //=================================================================================
589 bool TransformationGUI_PositionDlg::isValid (QString& /*msg*/)
592 if (getConstructorId() == 0)
593 res = !(myObjects.length() == 0 || myEndLCS->_is_nil());
594 else if ( getConstructorId() == 1 )
595 res = !(myObjects.length() == 0 || myStartLCS->_is_nil() || myEndLCS->_is_nil());
596 else if ( getConstructorId() == 2 )
597 res = !(myObjects.length() == 0 || myPath->_is_nil());
602 //=================================================================================
603 // function : execute
605 //=================================================================================
606 bool TransformationGUI_PositionDlg::execute (ObjectList& objects)
609 bool toCreateCopy = IsPreview() || Group1->CheckButton1->isChecked();
610 GEOM::GEOM_Object_var anObj;
612 GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
614 switch (getConstructorId()) {
617 for (int i = 0; i < myObjects.length(); i++) {
618 anObj = toCreateCopy ?
619 anOper->PositionShapeCopy(myObjects[i], myObjects[i], myEndLCS) :
620 anOper->PositionShape(myObjects[i], myObjects[i], myEndLCS);
622 if (!anObj->_is_nil())
623 objects.push_back(anObj._retn());
630 for (int i = 0; i < myObjects.length(); i++) {
632 anObj = toCreateCopy ?
633 anOper->PositionShapeCopy(myObjects[i], myStartLCS, myEndLCS) :
634 anOper->PositionShape(myObjects[i], myStartLCS, myEndLCS);
635 if (!anObj->_is_nil())
636 objects.push_back(anObj._retn());
643 double aDistance = Group1->SpinBox_DX->value();
644 bool toReverse = Group1->CheckButton3->isChecked();
645 for (int i = 0; i < myObjects.length(); i++) {
646 anObj = anOper->PositionAlongPath(myObjects[i], myPath, aDistance, toCreateCopy, toReverse);
647 if (!anObj->_is_nil())
648 objects.push_back(anObj._retn());
658 //=================================================================================
659 // function : restoreSubShapes
661 //=================================================================================
662 void TransformationGUI_PositionDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
663 SALOMEDS::SObject_ptr theSObject)
665 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
666 // empty list of arguments means that all arguments should be restored
667 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
668 /*theFindMethod=*/GEOM::FSM_Transformed,
669 /*theInheritFirstArg=*/true,
670 mainFrame()->CheckBoxAddPrefix->isChecked());
674 //=================================================================================
675 // function : CreateCopyModeChanged()
677 //=================================================================================
678 void TransformationGUI_PositionDlg::CreateCopyModeChanged (bool isCreateCopy)
680 mainFrame()->GroupBoxName->setEnabled(isCreateCopy);
683 //=================================================================================
684 // function : addSubshapeToStudy
685 // purpose : virtual method to add new SubObjects if local selection
686 //=================================================================================
687 void TransformationGUI_PositionDlg::addSubshapesToStudy()
689 QMap<QString, GEOM::GEOM_Object_var> objMap;
691 objMap[Group1->LineEdit5->text()] = myPath;
693 addSubshapesToFather(objMap);