1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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
22 // File : TransformationGUI_PositionDlg.cxx
23 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 #include "TransformationGUI_PositionDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36 #include <TColStd_IndexedMapOfInteger.hxx>
39 #include <TColStd_MapOfInteger.hxx>
41 #include <GEOMImpl_Types.hxx>
43 //=================================================================================
44 // class : TransformationGUI_PositionDlg()
45 // purpose : Constructs a TransformationGUI_PositionDlg which is a child of 'parent', with the
46 // name 'name' and widget flags set to 'f'.
47 // The dialog will by default be modeless, unless you set 'modal' to
48 // TRUE to construct a modal dialog.
49 //=================================================================================
50 TransformationGUI_PositionDlg::TransformationGUI_PositionDlg
51 (GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl)
52 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
55 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
56 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POSITION")));
57 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POSITION2")));
58 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POSITION3")));
59 QPixmap imageselect (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
61 setWindowTitle(tr("GEOM_POSITION_TITLE"));
63 /***************************************************************/
64 mainFrame()->GroupConstructors->setTitle(tr("GEOM_POSITION"));
65 mainFrame()->RadioButton1->setIcon(image0);
66 mainFrame()->RadioButton2->setIcon(image1);
67 mainFrame()->RadioButton3->setIcon(image2);
69 Group1 = new DlgRef_4Sel1Spin2Check(centralWidget());
70 Group1->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
71 Group1->TextLabel1->setText(tr("GEOM_OBJECTS"));
72 Group1->TextLabel2->setText(tr("GEOM_START_LCS"));
73 Group1->TextLabel3->setText(tr("GEOM_DISTANCE"));
74 Group1->TextLabel4->setText(tr("GEOM_END_LCS"));
75 Group1->TextLabel5->setText(tr("GEOM_PATH_OBJECT"));
76 Group1->PushButton1->setIcon(imageselect);
77 Group1->PushButton2->setIcon(imageselect);
78 Group1->PushButton4->setIcon(imageselect);
79 Group1->PushButton5->setIcon(imageselect);
80 Group1->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
81 Group1->CheckButton2->setText(tr("SELECT_UNPUBLISHED_EDGES"));
83 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
84 layout->setMargin(0); layout->setSpacing(6);
85 layout->addWidget(Group1);
86 /***************************************************************/
88 setHelpFileName("modify_location_operation_page.html");
90 // Activate Create a Copy mode
91 Group1->CheckButton1->setChecked(true);
92 Group1->CheckButton1->setChecked(false);
93 CreateCopyModeChanged(true);
98 //=================================================================================
99 // function : ~TransformationGUI_PositionDlg()
100 // purpose : Destroys the object and frees any allocated resources
101 //=================================================================================
102 TransformationGUI_PositionDlg::~TransformationGUI_PositionDlg()
104 // no need to delete child widgets, Qt does it all for us
107 //=================================================================================
110 //=================================================================================
111 void TransformationGUI_PositionDlg::Init()
114 Group1->LineEdit1->setReadOnly(true);
115 Group1->LineEdit2->setReadOnly(true);
116 Group1->LineEdit4->setReadOnly(true);
117 Group1->LineEdit5->setReadOnly(true);
119 Group1->LineEdit1->setText("");
120 Group1->LineEdit2->setText("");
121 Group1->LineEdit4->setText("");
122 Group1->LineEdit5->setText("");
124 initSpinBox(Group1->SpinBox_DX, 0, 1, 0.05, 6); // VSR:TODO : DBL_DIGITS_DISPLAY
125 Group1->SpinBox_DX->setValue(1);
127 Group1->CheckButton2->setEnabled(false);
129 myStartLCS = myEndLCS = GEOM::GEOM_Object::_nil();
131 mainFrame()->GroupBoxPublish->show();
133 // signals and slots connections
134 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
135 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
137 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
139 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140 connect(Group1->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(Group1->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142 connect(Group1->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
144 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
145 connect(Group1->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146 connect(Group1->LineEdit4, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147 connect(Group1->LineEdit5, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
149 connect(Group1->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
150 connect(Group1->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
152 connect(Group1->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(SelectionTypeButtonClicked()));
154 initName(tr("GEOM_POSITION"));
156 ConstructorsClicked(0);
159 //=================================================================================
160 // function : ConstructorsClicked()
161 // purpose : Radio button management
162 //=================================================================================
163 void TransformationGUI_PositionDlg::ConstructorsClicked (int constructorId)
165 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
167 Group1->LineEdit2->clear();
168 Group1->LineEdit4->clear();
169 Group1->LineEdit5->clear();
170 myStartLCS = GEOM::GEOM_Object::_nil();
171 myEndLCS = GEOM::GEOM_Object::_nil();
172 myPath = GEOM::GEOM_Object::_nil();
174 switch (constructorId) {
177 Group1->LineEdit2->hide();
178 Group1->TextLabel2->hide();
179 Group1->PushButton2->hide();
181 Group1->LineEdit5->hide();
182 Group1->TextLabel5->hide();
183 Group1->PushButton5->hide();
185 Group1->SpinBox_DX->hide();
186 Group1->TextLabel3->hide();
188 Group1->LineEdit4->show();
189 Group1->TextLabel4->show();
190 Group1->PushButton4->show();
192 Group1->PushButton1->click();
194 Group1->CheckButton2->hide();
199 Group1->LineEdit2->show();
200 Group1->TextLabel2->show();
201 Group1->PushButton2->show();
203 Group1->LineEdit5->hide();
204 Group1->TextLabel5->hide();
205 Group1->PushButton5->hide();
207 Group1->SpinBox_DX->hide();
208 Group1->TextLabel3->hide();
210 Group1->PushButton1->click();
212 Group1->CheckButton2->hide();
217 Group1->LineEdit4->hide();
218 Group1->TextLabel4->hide();
219 Group1->PushButton4->hide();
221 Group1->LineEdit2->hide();
222 Group1->TextLabel2->hide();
223 Group1->PushButton2->hide();
225 Group1->LineEdit5->show();
226 Group1->TextLabel5->show();
227 Group1->PushButton5->show();
229 Group1->SpinBox_DX->show();
230 Group1->TextLabel3->show();
232 Group1->PushButton1->click();
234 Group1->CheckButton2->show();
239 qApp->processEvents();
241 resize(minimumSize());
245 SelectionIntoArgument();
252 //=================================================================================
253 // function : SelectionBittonClicked()
254 // purpose : Selection type Radio button management
255 //=================================================================================
256 void TransformationGUI_PositionDlg::SelectionTypeButtonClicked()
258 if ( Group1->CheckButton2->isChecked() ) {
259 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
261 TColStd_MapOfInteger aMap;
264 globalSelection(aMap);
268 //=================================================================================
269 // function : ValueChangedInSpinBox()
271 //=================================================================================
272 void TransformationGUI_PositionDlg::ValueChangedInSpinBox()
277 //=================================================================================
278 // function : ClickOnOk()
280 //=================================================================================
281 void TransformationGUI_PositionDlg::ClickOnOk()
287 //=================================================================================
288 // function : ClickOnApply()
290 //=================================================================================
291 bool TransformationGUI_PositionDlg::ClickOnApply()
293 if (!onAccept(Group1->CheckButton1->isChecked()))
297 // activate selection and connect selection manager
298 ConstructorsClicked(getConstructorId());
302 //=================================================================================
303 // function : SelectionIntoArgument()
304 // purpose : Called when selection is changed or on dialog initialization or activation
305 //=================================================================================
306 void TransformationGUI_PositionDlg::SelectionIntoArgument()
309 myEditCurrentArgument->setText("");
311 if (myEditCurrentArgument == Group1->LineEdit1)
313 else if (myEditCurrentArgument == Group1->LineEdit2)
314 myStartLCS = GEOM::GEOM_Object::_nil();
315 else if (myEditCurrentArgument == Group1->LineEdit4)
316 myEndLCS = GEOM::GEOM_Object::_nil();
317 else if (myEditCurrentArgument == Group1->LineEdit5)
318 myPath = GEOM::GEOM_Object::_nil();
320 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
321 SALOME_ListIO aSelList;
322 aSelMgr->selectedObjects(aSelList);
326 if (myEditCurrentArgument == Group1->LineEdit1) {
327 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName);
331 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myObjects);
332 if (!myObjects.length())
335 myEditCurrentArgument->setText(aName);
337 else if (myEditCurrentArgument == Group1->LineEdit2) {
338 if (aSelList.Extent() != 1)
342 Standard_Boolean testResult = Standard_False;
343 myStartLCS = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
344 if (!testResult || CORBA::is_nil(myStartLCS))
347 aName = GEOMBase::GetName(myStartLCS);
348 myEditCurrentArgument->setText(aName);
350 if (!myStartLCS->_is_nil() && myEndLCS->_is_nil())
351 Group1->PushButton4->click();
353 else if (myEditCurrentArgument == Group1->LineEdit4) {
354 myEndLCS = GEOM::GEOM_Object::_nil();
355 if (aSelList.Extent() != 1)
358 Standard_Boolean testResult = Standard_False;
359 myEndLCS = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
360 if (!testResult || CORBA::is_nil(myEndLCS))
363 aName = GEOMBase::GetName(myEndLCS);
364 myEditCurrentArgument->setText(aName);
366 if (!myEndLCS->_is_nil() && !myObjects.length() && getConstructorId() != 2)
367 Group1->PushButton1->click();
368 else if (getConstructorId() == 2 && !myObjects.length())
369 Group1->PushButton5->click();
371 else if (myEditCurrentArgument == Group1->LineEdit5) {
372 myPath = GEOM::GEOM_Object::_nil();
373 if (aSelList.Extent() != 1)
376 Standard_Boolean testResult = Standard_False;
377 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
378 if (!testResult || aSelectedObject->_is_nil())
381 aName = GEOMBase::GetName(myPath);
384 if (!GEOMBase::GetShape(aSelectedObject, S))
387 TColStd_IndexedMapOfInteger aMap;
388 aSelMgr->GetIndexes(aSelList.First(), aMap);
389 aName = GEOMBase::GetName(aSelectedObject);
390 if (aMap.Extent() == 1) {
391 int anIndex = aMap(1);
392 aName.append(":edge_" + QString::number(anIndex));
394 //Find SubShape Object in Father
395 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
397 if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
398 GEOM::GEOM_IShapesOperations_var aShapesOp =
399 getGeomEngine()->GetIShapesOperations(getStudyId());
400 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
402 else { // get Object from study
403 aSelectedObject = aFindedObject;
407 if (S.ShapeType() != TopAbs_EDGE) {
408 aSelectedObject = GEOM::GEOM_Object::_nil();
414 myEditCurrentArgument->setText(aName);
415 myPath = aSelectedObject;
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_PositionDlg::SetEditCurrentArgument()
433 QPushButton* send = (QPushButton*)sender();
435 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
436 if (send == Group1->PushButton1) {
437 myEditCurrentArgument = Group1->LineEdit1;
441 Group1->PushButton2->setDown(false);
442 Group1->PushButton4->setDown(false);
443 Group1->PushButton5->setDown(false);
444 Group1->LineEdit2->setEnabled(false);
445 Group1->LineEdit4->setEnabled(false);
446 Group1->LineEdit5->setEnabled(false);
448 Group1->CheckButton2->setEnabled(false);
450 else if (send == Group1->PushButton2) {
451 myEditCurrentArgument = Group1->LineEdit2;
453 TColStd_MapOfInteger aMap;
454 aMap.Add(GEOM_PLANE);
455 aMap.Add(GEOM_MARKER);
456 globalSelection(aMap);
458 Group1->PushButton1->setDown(false);
459 Group1->PushButton4->setDown(false);
460 Group1->PushButton5->setDown(false);
461 Group1->LineEdit1->setEnabled(false);
462 Group1->LineEdit4->setEnabled(false);
463 Group1->LineEdit5->setEnabled(false);
465 Group1->CheckButton2->setEnabled(false);
467 else if (send == Group1->PushButton4) {
468 myEditCurrentArgument = Group1->LineEdit4;
470 TColStd_MapOfInteger aMap;
471 aMap.Add(GEOM_PLANE);
472 aMap.Add(GEOM_MARKER);
473 globalSelection(aMap);
475 Group1->PushButton1->setDown(false);
476 Group1->PushButton2->setDown(false);
477 Group1->PushButton5->setDown(false);
478 Group1->LineEdit1->setEnabled(false);
479 Group1->LineEdit2->setEnabled(false);
480 Group1->LineEdit5->setEnabled(false);
482 Group1->CheckButton2->setEnabled(false);
484 else if (send == Group1->PushButton5) {
485 myEditCurrentArgument = Group1->LineEdit5;
487 Group1->CheckButton2->setEnabled(true);
489 if ( Group1->CheckButton2->isChecked() ) {
490 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
492 TColStd_MapOfInteger aMap;
495 globalSelection(aMap);
498 Group1->PushButton1->setDown(false);
499 Group1->PushButton2->setDown(false);
500 Group1->PushButton4->setDown(false);
501 Group1->LineEdit1->setEnabled(false);
502 Group1->LineEdit2->setEnabled(false);
503 Group1->LineEdit4->setEnabled(false);
505 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
506 this, SLOT(SelectionIntoArgument()));
509 myEditCurrentArgument->setEnabled(true);
510 myEditCurrentArgument->setFocus();
511 // after setFocus(), because it will be setDown(false) when loses focus
514 // seems we need it only to avoid preview disappearing, caused by selection mode change
518 //=================================================================================
519 // function : LineEditReturnPressed()
521 //=================================================================================
522 void TransformationGUI_PositionDlg::LineEditReturnPressed()
524 QLineEdit* send = (QLineEdit*)sender();
525 if (send == Group1->LineEdit1 ||
526 send == Group1->LineEdit2 ||
527 send == Group1->LineEdit4 ||
528 send == Group1->LineEdit5 ) {
529 myEditCurrentArgument = send;
530 GEOMBase_Skeleton::LineEditReturnPressed();
533 if (send == Group1->LineEdit5)
534 Group1->CheckButton2->setEnabled(true);
536 Group1->CheckButton2->setEnabled(false);
539 //=================================================================================
540 // function : ActivateThisDialog()
542 //=================================================================================
543 void TransformationGUI_PositionDlg::ActivateThisDialog()
545 GEOMBase_Skeleton::ActivateThisDialog();
547 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
548 this, SLOT( SelectionIntoArgument() ) );
550 ConstructorsClicked( getConstructorId() );
553 //=================================================================================
554 // function : enterEvent()
555 // purpose : when mouse enter onto the QWidget
556 //=================================================================================
557 void TransformationGUI_PositionDlg::enterEvent (QEvent*)
559 if (!mainFrame()->GroupConstructors->isEnabled())
560 ActivateThisDialog();
563 //=================================================================================
564 // function : createOperation
566 //=================================================================================
567 GEOM::GEOM_IOperations_ptr TransformationGUI_PositionDlg::createOperation()
569 return getGeomEngine()->GetITransformOperations(getStudyId());
572 //=================================================================================
573 // function : isValid
575 //=================================================================================
576 bool TransformationGUI_PositionDlg::isValid (QString& /*msg*/)
579 if (getConstructorId() == 0)
580 res = !(myObjects.length() == 0 || myEndLCS->_is_nil());
581 else if ( getConstructorId() == 1 )
582 res = !(myObjects.length() == 0 || myStartLCS->_is_nil() || myEndLCS->_is_nil());
583 else if ( getConstructorId() == 2 )
584 res = !(myObjects.length() == 0 || myPath->_is_nil());
589 //=================================================================================
590 // function : execute
592 //=================================================================================
593 bool TransformationGUI_PositionDlg::execute (ObjectList& objects)
596 bool toCreateCopy = IsPreview() || Group1->CheckButton1->isChecked();
597 GEOM::GEOM_Object_var anObj;
599 switch (getConstructorId()) {
602 for (int i = 0; i < myObjects.length(); i++) {
604 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
605 PositionShapeCopy(myObjects[i], myObjects[i], myEndLCS);
607 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
608 PositionShape(myObjects[i], myObjects[i], myEndLCS);
610 if (!anObj->_is_nil())
611 objects.push_back(anObj._retn());
618 for (int i = 0; i < myObjects.length(); i++) {
620 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
621 PositionShapeCopy(myObjects[i], myStartLCS, myEndLCS);
623 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
624 PositionShape(myObjects[i], myStartLCS, myEndLCS);
625 if (!anObj->_is_nil())
626 objects.push_back(anObj._retn());
633 double aDistance = Group1->SpinBox_DX->value();
634 for (int i = 0; i < myObjects.length(); i++) {
635 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
636 PositionAlongPath(myObjects[i], myPath, aDistance, toCreateCopy);
637 if (!anObj->_is_nil())
638 objects.push_back(anObj._retn());
648 //=================================================================================
649 // function : restoreSubShapes
651 //=================================================================================
652 void TransformationGUI_PositionDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
653 SALOMEDS::SObject_ptr theSObject)
655 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
656 // empty list of arguments means that all arguments should be restored
657 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
658 /*theFindMethod=*/GEOM::FSM_Transformed,
659 /*theInheritFirstArg=*/true);
663 //=================================================================================
664 // function : CreateCopyModeChanged()
666 //=================================================================================
667 void TransformationGUI_PositionDlg::CreateCopyModeChanged (bool isCreateCopy)
669 mainFrame()->GroupBoxName->setEnabled(isCreateCopy);
672 //=================================================================================
673 // function : addSubshapeToStudy
674 // purpose : virtual method to add new SubObjects if local selection
675 //=================================================================================
676 void TransformationGUI_PositionDlg::addSubshapesToStudy()
678 QMap<QString, GEOM::GEOM_Object_var> objMap;
680 objMap[Group1->LineEdit5->text()] = myPath;
682 addSubshapesToFather(objMap);