]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_PositionDlg.cxx
Salome HOME
Update copyright information
[modules/geom.git] / src / TransformationGUI / TransformationGUI_PositionDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : TransformationGUI_PositionDlg.cxx
24 // Author : Damien COQUERET, Open CASCADE S.A.S.
25 //
26 #include "TransformationGUI_PositionDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36
37 // OCCT Includes
38 #include <TColStd_MapOfInteger.hxx>
39
40 #include <GEOMImpl_Types.hxx>
41
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),
52     myInitial(true)
53 {
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")));
58
59   setWindowTitle(tr("GEOM_POSITION_TITLE"));
60
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();
67
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"));
83
84   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
85   layout->setMargin(0); layout->setSpacing(6);
86   layout->addWidget(Group1);
87   /***************************************************************/
88
89   setHelpFileName("modify_location_operation_page.html");
90
91   // Activate Create a Copy mode
92   Group1->CheckBox1->setChecked(true);
93   CreateCopyModeChanged(true);
94
95   Init();
96 }
97
98 //=================================================================================
99 // function : ~TransformationGUI_PositionDlg()
100 // purpose  : Destroys the object and frees any allocated resources
101 //=================================================================================
102 TransformationGUI_PositionDlg::~TransformationGUI_PositionDlg()
103 {
104   // no need to delete child widgets, Qt does it all for us
105 }
106
107 //=================================================================================
108 // function : Init()
109 // purpose  :
110 //=================================================================================
111 void TransformationGUI_PositionDlg::Init()
112 {
113   // init variables
114   Group1->LineEdit1->setReadOnly(true);
115   Group1->LineEdit2->setReadOnly(true);
116   Group1->LineEdit3->setReadOnly(true);
117
118   Group1->LineEdit1->setText("");
119   Group1->LineEdit2->setText("");
120   Group1->LineEdit3->setText("");
121
122   myStartLCS = myEndLCS = GEOM::GEOM_Object::_nil();
123
124   mainFrame()->GroupBoxPublish->show();
125
126   // signals and slots connections
127   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
128   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
129
130   connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
131
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()));
135
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()));
139
140   connect(Group1->CheckBox1,   SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
141
142   initName(tr("GEOM_POSITION"));
143
144   ConstructorsClicked(0);
145 }
146
147 //=================================================================================
148 // function : ConstructorsClicked()
149 // purpose  : Radio button management
150 //=================================================================================
151 void TransformationGUI_PositionDlg::ConstructorsClicked (int constructorId)
152 {
153   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
154
155   Group1->LineEdit2->clear();
156   Group1->LineEdit3->clear();
157   myStartLCS = GEOM::GEOM_Object::_nil();
158   myEndLCS = GEOM::GEOM_Object::_nil();
159
160   switch (constructorId) {
161   case 0:
162     {
163       Group1->LineEdit2->hide();
164       Group1->TextLabel2->hide();
165       Group1->PushButton2->hide();
166
167       Group1->PushButton1->click();
168     }
169     break;
170   case 1:
171     {
172       Group1->LineEdit2->show();
173       Group1->TextLabel2->show();
174       Group1->PushButton2->show();
175
176       Group1->PushButton1->click();
177     }
178     break;
179   }
180
181   qApp->processEvents();
182   updateGeometry();
183   resize(minimumSize());
184
185   if (myInitial) {
186     myInitial = false;
187     SelectionIntoArgument();
188   }
189   else {
190     displayPreview();
191   }
192 }
193
194 //=================================================================================
195 // function : ClickOnOk()
196 // purpose  :
197 //=================================================================================
198 void TransformationGUI_PositionDlg::ClickOnOk()
199 {
200   if (ClickOnApply())
201     ClickOnCancel();
202 }
203
204 //=================================================================================
205 // function : ClickOnApply()
206 // purpose  :
207 //=================================================================================
208 bool TransformationGUI_PositionDlg::ClickOnApply()
209 {
210   if (!onAccept(Group1->CheckBox1->isChecked()))
211     return false;
212
213   initName();
214   // activate selection and connect selection manager
215   ConstructorsClicked(getConstructorId());
216   return true;
217 }
218
219 //=================================================================================
220 // function : SelectionIntoArgument()
221 // purpose  : Called when selection is changed or on dialog initialization or activation
222 //=================================================================================
223 void TransformationGUI_PositionDlg::SelectionIntoArgument()
224 {
225   erasePreview();
226   myEditCurrentArgument->setText("");
227
228   if (myEditCurrentArgument == Group1->LineEdit1)
229     myObjects.length(0);
230   else if (myEditCurrentArgument == Group1->LineEdit2)
231     myStartLCS = GEOM::GEOM_Object::_nil();
232   else if (myEditCurrentArgument == Group1->LineEdit3)
233     myEndLCS = GEOM::GEOM_Object::_nil();
234
235   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
236   SALOME_ListIO aSelList;
237   aSelMgr->selectedObjects(aSelList);
238
239   QString aName;
240
241   if (myEditCurrentArgument == Group1->LineEdit1) {
242     int aNbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName);
243     if (aNbSel < 1)
244       return;
245
246     GEOMBase::ConvertListOfIOInListOfGO(aSelList, myObjects);
247     if (!myObjects.length())
248       return;
249     else
250       myEditCurrentArgument->setText(aName);
251   }
252   else if (myEditCurrentArgument == Group1->LineEdit2) {
253     if (aSelList.Extent() != 1)
254       return;
255
256     // nbSel == 1
257     Standard_Boolean testResult = Standard_False;
258     myStartLCS = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
259     if (!testResult || CORBA::is_nil(myStartLCS))
260       return;
261
262     aName = GEOMBase::GetName(myStartLCS);
263     myEditCurrentArgument->setText(aName);
264
265     if (!myStartLCS->_is_nil() && myEndLCS->_is_nil())
266       Group1->PushButton3->click();
267   }
268   else if (myEditCurrentArgument == Group1->LineEdit3) {
269     myEndLCS = GEOM::GEOM_Object::_nil();
270     if (aSelList.Extent() != 1)
271       return;
272
273     Standard_Boolean testResult = Standard_False;
274     myEndLCS = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
275     if (!testResult || CORBA::is_nil(myEndLCS))
276       return;
277
278     aName = GEOMBase::GetName(myEndLCS);
279     myEditCurrentArgument->setText(aName);
280
281     if (!myEndLCS->_is_nil() && !myObjects.length())
282       Group1->PushButton1->click();
283   }
284
285   // clear selection
286   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
287   myGeomGUI->getApp()->selectionMgr()->clearSelected();
288   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
289           this, SLOT(SelectionIntoArgument()));
290
291   displayPreview();
292 }
293
294 //=================================================================================
295 // function : SetEditCurrentArgument()
296 // purpose  :
297 //=================================================================================
298 void TransformationGUI_PositionDlg::SetEditCurrentArgument()
299 {
300   QPushButton* send = (QPushButton*)sender();
301
302   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
303   if (send == Group1->PushButton1) {
304     myEditCurrentArgument = Group1->LineEdit1;
305
306     globalSelection();
307
308     Group1->PushButton2->setDown(false);
309     Group1->PushButton3->setDown(false);
310     Group1->LineEdit2->setEnabled(false);
311     Group1->LineEdit3->setEnabled(false);
312   }
313   else if (send == Group1->PushButton2) {
314     myEditCurrentArgument = Group1->LineEdit2;
315
316     TColStd_MapOfInteger aMap;
317     aMap.Add(GEOM_PLANE);
318     aMap.Add(GEOM_MARKER);
319     globalSelection(aMap);
320
321     Group1->PushButton1->setDown(false);
322     Group1->PushButton3->setDown(false);
323     Group1->LineEdit1->setEnabled(false);
324     Group1->LineEdit3->setEnabled(false);
325   }
326   else if (send == Group1->PushButton3) {
327     myEditCurrentArgument = Group1->LineEdit3;
328
329     TColStd_MapOfInteger aMap;
330     aMap.Add(GEOM_PLANE);
331     aMap.Add(GEOM_MARKER);
332     globalSelection(aMap);
333
334     Group1->PushButton1->setDown(false);
335     Group1->PushButton2->setDown(false);
336     Group1->LineEdit1->setEnabled(false);
337     Group1->LineEdit2->setEnabled(false);
338   }
339   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
340           this, SLOT(SelectionIntoArgument()));
341
342   // enable line edit
343   myEditCurrentArgument->setEnabled(true);
344   myEditCurrentArgument->setFocus();
345   // after setFocus(), because it will be setDown(false) when loses focus
346   send->setDown(true);
347
348   // seems we need it only to avoid preview disappearing, caused by selection mode change
349   displayPreview();
350 }
351
352 //=================================================================================
353 // function : LineEditReturnPressed()
354 // purpose  :
355 //=================================================================================
356 void TransformationGUI_PositionDlg::LineEditReturnPressed()
357 {
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();
364   }
365 }
366
367 //=================================================================================
368 // function : ActivateThisDialog()
369 // purpose  :
370 //=================================================================================
371 void TransformationGUI_PositionDlg::ActivateThisDialog()
372 {
373   GEOMBase_Skeleton::ActivateThisDialog();
374   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
375            this, SLOT( SelectionIntoArgument() ) );
376
377   ConstructorsClicked( getConstructorId() );
378 }
379
380 //=================================================================================
381 // function : enterEvent()
382 // purpose  : when mouse enter onto the QWidget
383 //=================================================================================
384 void TransformationGUI_PositionDlg::enterEvent (QEvent*)
385 {
386   if (!mainFrame()->GroupConstructors->isEnabled())
387     ActivateThisDialog();
388 }
389
390 //=================================================================================
391 // function : createOperation
392 // purpose  :
393 //=================================================================================
394 GEOM::GEOM_IOperations_ptr TransformationGUI_PositionDlg::createOperation()
395 {
396   return getGeomEngine()->GetITransformOperations(getStudyId());
397 }
398
399 //=================================================================================
400 // function : isValid
401 // purpose  :
402 //=================================================================================
403 bool TransformationGUI_PositionDlg::isValid (QString& /*msg*/)
404 {
405   bool res;
406   if (getConstructorId() == 0)
407     res = !(myObjects.length() == 0 || myEndLCS->_is_nil());
408   else
409     res = !(myObjects.length() == 0 || myStartLCS->_is_nil() || myEndLCS->_is_nil());
410
411   return res;
412 }
413
414 //=================================================================================
415 // function : execute
416 // purpose  :
417 //=================================================================================
418 bool TransformationGUI_PositionDlg::execute (ObjectList& objects)
419 {
420   bool res = false;
421   bool toCreateCopy = IsPreview() || Group1->CheckBox1->isChecked();
422   GEOM::GEOM_Object_var anObj;
423
424   switch (getConstructorId()) {
425   case 0:
426     {
427       for (int i = 0; i < myObjects.length(); i++) {
428         if (toCreateCopy)
429           anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
430             PositionShapeCopy(myObjects[i], myObjects[i], myEndLCS);
431         else
432           anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
433             PositionShape(myObjects[i], myObjects[i], myEndLCS);
434
435         if (!anObj->_is_nil())
436           objects.push_back(anObj._retn());
437       }
438       res = true;
439       break;
440     }
441   case 1:
442     {
443       for (int i = 0; i < myObjects.length(); i++) {
444         if (toCreateCopy)
445           anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
446             PositionShapeCopy(myObjects[i], myStartLCS, myEndLCS);
447         else
448           anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
449             PositionShape(myObjects[i], myStartLCS, myEndLCS);
450         if (!anObj->_is_nil())
451           objects.push_back(anObj._retn());
452       }
453       res = true;
454       break;
455     }
456   }
457
458   return res;
459 }
460
461 //=================================================================================
462 // function : restoreSubShapes
463 // purpose  :
464 //=================================================================================
465 void TransformationGUI_PositionDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
466                                                       SALOMEDS::SObject_ptr theSObject)
467 {
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);
473   }
474 }
475
476 //=================================================================================
477 // function :  CreateCopyModeChanged()
478 // purpose  :
479 //=================================================================================
480 void TransformationGUI_PositionDlg::CreateCopyModeChanged (bool isCreateCopy)
481 {
482   mainFrame()->GroupBoxName->setEnabled(isCreateCopy);
483 }