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>
38 #include <TColStd_MapOfInteger.hxx>
40 #include <GEOMImpl_Types.hxx>
42 //=================================================================================
43 // class : TransformationGUI_PositionDlg()
44 // purpose : Constructs a TransformationGUI_PositionDlg which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 TransformationGUI_PositionDlg::TransformationGUI_PositionDlg
50 (GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl)
51 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
54 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
55 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POSITION")));
56 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_POSITION2")));
57 QPixmap imageselect (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
59 setWindowTitle(tr("GEOM_POSITION_TITLE"));
61 /***************************************************************/
62 mainFrame()->GroupConstructors->setTitle(tr("GEOM_POSITION"));
63 mainFrame()->RadioButton1->setIcon(image0);
64 mainFrame()->RadioButton2->setIcon(image1);
65 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
66 mainFrame()->RadioButton3->close();
68 Group1 = new DlgRef_3Sel3Spin1Check(centralWidget());
69 Group1->SpinBox1->hide();
70 Group1->SpinBox2->hide();
71 Group1->SpinBox3->hide();
72 Group1->TextLabel4->hide();
73 Group1->TextLabel5->hide();
74 Group1->TextLabel6->hide();
75 Group1->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
76 Group1->TextLabel1->setText(tr("GEOM_OBJECTS"));
77 Group1->TextLabel2->setText(tr("GEOM_START_LCS"));
78 Group1->TextLabel3->setText(tr("GEOM_END_LCS"));
79 Group1->PushButton1->setIcon(imageselect);
80 Group1->PushButton2->setIcon(imageselect);
81 Group1->PushButton3->setIcon(imageselect);
82 Group1->CheckBox1->setText(tr("GEOM_CREATE_COPY"));
84 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
85 layout->setMargin(0); layout->setSpacing(6);
86 layout->addWidget(Group1);
87 /***************************************************************/
89 setHelpFileName("modify_location_operation_page.html");
91 // Activate Create a Copy mode
92 Group1->CheckBox1->setChecked(true);
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->LineEdit3->setReadOnly(true);
118 Group1->LineEdit1->setText("");
119 Group1->LineEdit2->setText("");
120 Group1->LineEdit3->setText("");
122 myStartLCS = myEndLCS = GEOM::GEOM_Object::_nil();
124 mainFrame()->GroupBoxPublish->show();
126 // signals and slots connections
127 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
128 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
130 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
132 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(Group1->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
134 connect(Group1->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
136 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
137 connect(Group1->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138 connect(Group1->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
140 connect(Group1->CheckBox1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
142 initName(tr("GEOM_POSITION"));
144 ConstructorsClicked(0);
147 //=================================================================================
148 // function : ConstructorsClicked()
149 // purpose : Radio button management
150 //=================================================================================
151 void TransformationGUI_PositionDlg::ConstructorsClicked (int constructorId)
153 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
155 Group1->LineEdit2->clear();
156 Group1->LineEdit3->clear();
157 myStartLCS = GEOM::GEOM_Object::_nil();
158 myEndLCS = GEOM::GEOM_Object::_nil();
160 switch (constructorId) {
163 Group1->LineEdit2->hide();
164 Group1->TextLabel2->hide();
165 Group1->PushButton2->hide();
167 Group1->PushButton1->click();
172 Group1->LineEdit2->show();
173 Group1->TextLabel2->show();
174 Group1->PushButton2->show();
176 Group1->PushButton1->click();
181 qApp->processEvents();
183 resize(minimumSize());
187 SelectionIntoArgument();
194 //=================================================================================
195 // function : ClickOnOk()
197 //=================================================================================
198 void TransformationGUI_PositionDlg::ClickOnOk()
204 //=================================================================================
205 // function : ClickOnApply()
207 //=================================================================================
208 bool TransformationGUI_PositionDlg::ClickOnApply()
210 if (!onAccept(Group1->CheckBox1->isChecked()))
214 // activate selection and connect selection manager
215 ConstructorsClicked(getConstructorId());
219 //=================================================================================
220 // function : SelectionIntoArgument()
221 // purpose : Called when selection is changed or on dialog initialization or activation
222 //=================================================================================
223 void TransformationGUI_PositionDlg::SelectionIntoArgument()
226 myEditCurrentArgument->setText("");
228 if (myEditCurrentArgument == Group1->LineEdit1)
230 else if (myEditCurrentArgument == Group1->LineEdit2)
231 myStartLCS = GEOM::GEOM_Object::_nil();
232 else if (myEditCurrentArgument == Group1->LineEdit3)
233 myEndLCS = GEOM::GEOM_Object::_nil();
235 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
236 SALOME_ListIO aSelList;
237 aSelMgr->selectedObjects(aSelList);
241 if (myEditCurrentArgument == Group1->LineEdit1) {
242 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName);
246 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myObjects);
247 if (!myObjects.length())
250 myEditCurrentArgument->setText(aName);
252 else if (myEditCurrentArgument == Group1->LineEdit2) {
253 if (aSelList.Extent() != 1)
257 Standard_Boolean testResult = Standard_False;
258 myStartLCS = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
259 if (!testResult || CORBA::is_nil(myStartLCS))
262 aName = GEOMBase::GetName(myStartLCS);
263 myEditCurrentArgument->setText(aName);
265 if (!myStartLCS->_is_nil() && myEndLCS->_is_nil())
266 Group1->PushButton3->click();
268 else if (myEditCurrentArgument == Group1->LineEdit3) {
269 myEndLCS = GEOM::GEOM_Object::_nil();
270 if (aSelList.Extent() != 1)
273 Standard_Boolean testResult = Standard_False;
274 myEndLCS = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
275 if (!testResult || CORBA::is_nil(myEndLCS))
278 aName = GEOMBase::GetName(myEndLCS);
279 myEditCurrentArgument->setText(aName);
281 if (!myEndLCS->_is_nil() && !myObjects.length())
282 Group1->PushButton1->click();
286 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
287 myGeomGUI->getApp()->selectionMgr()->clearSelected();
288 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
289 this, SLOT(SelectionIntoArgument()));
294 //=================================================================================
295 // function : SetEditCurrentArgument()
297 //=================================================================================
298 void TransformationGUI_PositionDlg::SetEditCurrentArgument()
300 QPushButton* send = (QPushButton*)sender();
302 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
303 if (send == Group1->PushButton1) {
304 myEditCurrentArgument = Group1->LineEdit1;
308 Group1->PushButton2->setDown(false);
309 Group1->PushButton3->setDown(false);
310 Group1->LineEdit2->setEnabled(false);
311 Group1->LineEdit3->setEnabled(false);
313 else if (send == Group1->PushButton2) {
314 myEditCurrentArgument = Group1->LineEdit2;
316 TColStd_MapOfInteger aMap;
317 aMap.Add(GEOM_PLANE);
318 aMap.Add(GEOM_MARKER);
319 globalSelection(aMap);
321 Group1->PushButton1->setDown(false);
322 Group1->PushButton3->setDown(false);
323 Group1->LineEdit1->setEnabled(false);
324 Group1->LineEdit3->setEnabled(false);
326 else if (send == Group1->PushButton3) {
327 myEditCurrentArgument = Group1->LineEdit3;
329 TColStd_MapOfInteger aMap;
330 aMap.Add(GEOM_PLANE);
331 aMap.Add(GEOM_MARKER);
332 globalSelection(aMap);
334 Group1->PushButton1->setDown(false);
335 Group1->PushButton2->setDown(false);
336 Group1->LineEdit1->setEnabled(false);
337 Group1->LineEdit2->setEnabled(false);
339 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
340 this, SLOT(SelectionIntoArgument()));
343 myEditCurrentArgument->setEnabled(true);
344 myEditCurrentArgument->setFocus();
345 // after setFocus(), because it will be setDown(false) when loses focus
348 // seems we need it only to avoid preview disappearing, caused by selection mode change
352 //=================================================================================
353 // function : LineEditReturnPressed()
355 //=================================================================================
356 void TransformationGUI_PositionDlg::LineEditReturnPressed()
358 QLineEdit* send = (QLineEdit*)sender();
359 if (send == Group1->LineEdit1 ||
360 send == Group1->LineEdit2 ||
361 send == Group1->LineEdit3) {
362 myEditCurrentArgument = send;
363 GEOMBase_Skeleton::LineEditReturnPressed();
367 //=================================================================================
368 // function : ActivateThisDialog()
370 //=================================================================================
371 void TransformationGUI_PositionDlg::ActivateThisDialog()
373 GEOMBase_Skeleton::ActivateThisDialog();
374 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
375 this, SLOT( SelectionIntoArgument() ) );
377 ConstructorsClicked( getConstructorId() );
380 //=================================================================================
381 // function : enterEvent()
382 // purpose : when mouse enter onto the QWidget
383 //=================================================================================
384 void TransformationGUI_PositionDlg::enterEvent (QEvent*)
386 if (!mainFrame()->GroupConstructors->isEnabled())
387 ActivateThisDialog();
390 //=================================================================================
391 // function : createOperation
393 //=================================================================================
394 GEOM::GEOM_IOperations_ptr TransformationGUI_PositionDlg::createOperation()
396 return getGeomEngine()->GetITransformOperations(getStudyId());
399 //=================================================================================
400 // function : isValid
402 //=================================================================================
403 bool TransformationGUI_PositionDlg::isValid (QString& /*msg*/)
406 if (getConstructorId() == 0)
407 res = !(myObjects.length() == 0 || myEndLCS->_is_nil());
409 res = !(myObjects.length() == 0 || myStartLCS->_is_nil() || myEndLCS->_is_nil());
414 //=================================================================================
415 // function : execute
417 //=================================================================================
418 bool TransformationGUI_PositionDlg::execute (ObjectList& objects)
421 bool toCreateCopy = IsPreview() || Group1->CheckBox1->isChecked();
422 GEOM::GEOM_Object_var anObj;
424 switch (getConstructorId()) {
427 for (int i = 0; i < myObjects.length(); i++) {
429 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
430 PositionShapeCopy(myObjects[i], myObjects[i], myEndLCS);
432 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
433 PositionShape(myObjects[i], myObjects[i], myEndLCS);
435 if (!anObj->_is_nil())
436 objects.push_back(anObj._retn());
443 for (int i = 0; i < myObjects.length(); i++) {
445 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
446 PositionShapeCopy(myObjects[i], myStartLCS, myEndLCS);
448 anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
449 PositionShape(myObjects[i], myStartLCS, myEndLCS);
450 if (!anObj->_is_nil())
451 objects.push_back(anObj._retn());
461 //=================================================================================
462 // function : restoreSubShapes
464 //=================================================================================
465 void TransformationGUI_PositionDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
466 SALOMEDS::SObject_ptr theSObject)
468 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
469 // empty list of arguments means that all arguments should be restored
470 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
471 /*theFindMethod=*/GEOM::FSM_Transformed,
472 /*theInheritFirstArg=*/true);
476 //=================================================================================
477 // function : CreateCopyModeChanged()
479 //=================================================================================
480 void TransformationGUI_PositionDlg::CreateCopyModeChanged (bool isCreateCopy)
482 mainFrame()->GroupBoxName->setEnabled(isCreateCopy);