]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_PositionDlg.cxx
Salome HOME
0020327: EDF 1018 GEOM : Missing MakeTangentPlaneOnFace in geompy
[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
25 //  Module : GEOM
26 //  $Header$
27 //
28 #include "TransformationGUI_PositionDlg.h"
29
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
34
35 #include <qlabel.h>
36 #include <qcheckbox.h>
37
38 #include "TColStd_MapOfInteger.hxx"
39
40 #include "GEOMImpl_Types.hxx"
41
42 #include "utilities.h"
43
44 using namespace std;
45
46 //=================================================================================
47 // class    : TransformationGUI_PositionDlg()
48 // purpose  : Constructs a TransformationGUI_PositionDlg which is a child of 'parent', with the
49 //            name 'name' and widget flags set to 'f'.
50 //            The dialog will by default be modeless, unless you set 'modal' to
51 //            TRUE to construct a modal dialog.
52 //=================================================================================
53 TransformationGUI_PositionDlg::TransformationGUI_PositionDlg
54   (GeometryGUI* theGeometryGUI, QWidget* parent,  const char* name, bool modal, WFlags fl)
55   : GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
56                       WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
57 {
58   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
59   QPixmap image0(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_POSITION")));
60   QPixmap image1(aResMgr->loadPixmap("GEOM",tr("ICON_DLG_POSITION2")));
61   QPixmap imageselect(aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
62
63   setCaption(tr("GEOM_POSITION_TITLE"));
64
65   /***************************************************************/
66   GroupConstructors->setTitle(tr("GEOM_POSITION"));
67   RadioButton1->setPixmap(image0);
68   RadioButton2->setPixmap(image1);
69   RadioButton3->close(TRUE);
70
71   Group1 = new DlgRef_3Sel3Spin1Check(this, "Group1");
72   Group1->SpinBox1->hide();
73   Group1->SpinBox2->hide();
74   Group1->SpinBox3->hide();
75   Group1->TextLabel4->hide();
76   Group1->TextLabel5->hide();
77   Group1->TextLabel6->hide();
78   Group1->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
79   Group1->TextLabel1->setText(tr("GEOM_OBJECTS"));
80   Group1->TextLabel2->setText(tr("GEOM_START_LCS"));
81   Group1->TextLabel3->setText(tr("GEOM_END_LCS"));
82   Group1->PushButton1->setPixmap(imageselect);
83   Group1->PushButton2->setPixmap(imageselect);
84   Group1->PushButton3->setPixmap(imageselect);
85   Group1->CheckBox1->setText(tr("GEOM_CREATE_COPY"));
86
87   Layout1->addWidget(Group1, 2, 0);
88
89   /***************************************************************/
90
91   setHelpFileName("modify_location_operation_page.html");
92
93   Init();
94 }
95
96
97 //=================================================================================
98 // function : ~TransformationGUI_PositionDlg()
99 // purpose  : Destroys the object and frees any allocated resources
100 //=================================================================================
101 TransformationGUI_PositionDlg::~TransformationGUI_PositionDlg()
102 {
103   /* no need to delete child widgets, Qt does it all for us */
104 }
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   myStartLCS = GEOM::GEOM_Object::_nil();
119   myEndLCS = GEOM::GEOM_Object::_nil();
120
121   // Activate Create a Copy mode
122   Group1->CheckBox1->setChecked(true);
123   CreateCopyModeChanged(true);
124
125   GroupBoxPublish->show();
126
127   /* signals and slots connections */
128   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
129   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
130   connect(GroupConstructors, SIGNAL(clicked(int)), 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   connect(myGeomGUI->getApp()->selectionMgr(),
143           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
144
145   initName( tr( "GEOM_POSITION" ) );
146   ConstructorsClicked( 0 );
147 }
148
149
150
151 //=================================================================================
152 // function : ConstructorsClicked()
153 // purpose  : Radio button management
154 //=================================================================================
155 void TransformationGUI_PositionDlg::ConstructorsClicked(int constructorId)
156 {
157   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
158
159   globalSelection();
160   myEditCurrentArgument = Group1->LineEdit1;
161   Group1->LineEdit2->clear();
162   Group1->LineEdit3->clear();
163   myStartLCS = GEOM::GEOM_Object::_nil();
164   myEndLCS = GEOM::GEOM_Object::_nil();
165
166   switch (constructorId)
167     {
168     case 0:
169       { 
170         Group1->LineEdit2->hide();
171         Group1->TextLabel2->hide();
172         Group1->PushButton2->hide();
173         break;
174       }
175     case 1:
176       {
177         Group1->LineEdit2->show();
178         Group1->TextLabel2->show();
179         Group1->PushButton2->show();
180         break;
181       }
182     }
183   connect(myGeomGUI->getApp()->selectionMgr(),
184           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
185   SelectionIntoArgument();
186 }
187
188
189 //=================================================================================
190 // function : ClickOnOk()
191 // purpose  :
192 //=================================================================================
193 void TransformationGUI_PositionDlg::ClickOnOk()
194 {
195   if ( ClickOnApply() )
196     ClickOnCancel();
197 }
198
199
200 //=================================================================================
201 // function : ClickOnApply()
202 // purpose  :
203 //=================================================================================
204 bool TransformationGUI_PositionDlg::ClickOnApply()
205 {
206   if ( !onAccept(Group1->CheckBox1->isChecked()) )
207     return false;
208
209   initName();
210   ConstructorsClicked( getConstructorId() );
211   return true;
212 }
213
214
215 //=================================================================================
216 // function : SelectionIntoArgument()
217 // purpose  : Called when selection has changed
218 //=================================================================================
219 void TransformationGUI_PositionDlg::SelectionIntoArgument()
220 {
221   myEditCurrentArgument->setText("");
222   QString aName;
223
224   if(myEditCurrentArgument == Group1->LineEdit1) {
225     int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
226     if(aNbSel < 1) {
227       myObjects.length(0);
228       displayPreview();
229       return;
230     }
231     GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
232     if (!myObjects.length()) {
233       displayPreview();
234       return;
235     }
236   }
237   else if(myEditCurrentArgument == Group1->LineEdit2) {
238     myStartLCS = GEOM::GEOM_Object::_nil();
239     if(IObjectCount() != 1) {
240       displayPreview();
241       return;
242     }
243
244     Standard_Boolean testResult = Standard_False;
245     myStartLCS = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
246     if(!testResult || CORBA::is_nil( myStartLCS )) {
247       displayPreview();
248       return;
249     }
250     aName = GEOMBase::GetName( myStartLCS );
251   }
252   else if(myEditCurrentArgument == Group1->LineEdit3) {
253     myEndLCS = GEOM::GEOM_Object::_nil();
254     if(IObjectCount() != 1) {
255       displayPreview();
256       return;
257     }
258
259     Standard_Boolean testResult = Standard_False;
260     myEndLCS = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
261     if(!testResult || CORBA::is_nil( myEndLCS )) {
262       displayPreview();
263       return;
264     }
265     aName = GEOMBase::GetName( myEndLCS );
266   }
267
268   myEditCurrentArgument->setText( aName );
269   displayPreview();
270 }
271
272
273 //=================================================================================
274 // function : LineEditReturnPressed()
275 // purpose  :
276 //=================================================================================
277 void TransformationGUI_PositionDlg::LineEditReturnPressed()
278 {
279   QLineEdit* send = (QLineEdit*)sender();
280   if(send == Group1->LineEdit1 || send == Group1->LineEdit2 || send == Group1->LineEdit3) {
281     myEditCurrentArgument = send;
282     GEOMBase_Skeleton::LineEditReturnPressed();
283   }
284 }
285
286
287 //=================================================================================
288 // function : SetEditCurrentArgument()
289 // purpose  :
290 //=================================================================================
291 void TransformationGUI_PositionDlg::SetEditCurrentArgument()
292 {
293   QPushButton* send = (QPushButton*)sender();
294
295   if(send == Group1->PushButton1){
296     myEditCurrentArgument = Group1->LineEdit1;
297     globalSelection();
298   }
299   else if(send == Group1->PushButton2) {
300     myEditCurrentArgument = Group1->LineEdit2;
301     TColStd_MapOfInteger aMap;
302     aMap.Add( GEOM_PLANE );
303     aMap.Add( GEOM_MARKER );
304     globalSelection( aMap );
305   }
306   else if(send == Group1->PushButton3) {
307     myEditCurrentArgument = Group1->LineEdit3;
308     TColStd_MapOfInteger aMap;
309     aMap.Add( GEOM_PLANE );
310     aMap.Add( GEOM_MARKER );
311     globalSelection( aMap );
312   }
313
314   myEditCurrentArgument->setFocus();
315   SelectionIntoArgument();
316 }
317
318
319 //=================================================================================
320 // function : ActivateThisDialog()
321 // purpose  :
322 //=================================================================================
323 void TransformationGUI_PositionDlg::ActivateThisDialog()
324 {
325   GEOMBase_Skeleton::ActivateThisDialog();
326   connect(myGeomGUI->getApp()->selectionMgr(),
327           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
328   ConstructorsClicked( getConstructorId() );
329 }
330
331
332 //=================================================================================
333 // function : enterEvent()
334 // purpose  : when mouse enter onto the QWidget
335 //=================================================================================
336 void TransformationGUI_PositionDlg::enterEvent(QEvent * e)
337 {
338   if(!GroupConstructors->isEnabled())
339     ActivateThisDialog();
340 }
341
342
343 //=================================================================================
344 // function : createOperation
345 // purpose  :
346 //=================================================================================
347 GEOM::GEOM_IOperations_ptr  TransformationGUI_PositionDlg::createOperation()
348 {
349   return getGeomEngine()->GetITransformOperations( getStudyId() );
350 }
351
352
353 //=================================================================================
354 // function : isValid
355 // purpose  :
356 //=================================================================================
357 bool  TransformationGUI_PositionDlg::isValid( QString& msg )
358 {
359   bool res;
360   if (getConstructorId() == 0)
361     res = !(myObjects.length() == 0 || myEndLCS->_is_nil());
362   else
363     res = !(myObjects.length() == 0 || myStartLCS->_is_nil() || myEndLCS->_is_nil());
364
365   return res;
366 }
367
368
369 //=================================================================================
370 // function : execute
371 // purpose  :
372 //=================================================================================
373 bool  TransformationGUI_PositionDlg::execute( ObjectList& objects )
374 {
375   bool res = false;
376   bool toCreateCopy = IsPreview() || Group1->CheckBox1->isChecked();
377   GEOM::GEOM_Object_var anObj;
378
379   switch ( getConstructorId() )
380     {
381     case 0 :
382       {
383         for (int i = 0; i < myObjects.length(); i++) {
384           if (toCreateCopy)
385             anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
386               PositionShapeCopy( myObjects[i], myObjects[i], myEndLCS );
387           else
388             anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
389               PositionShape( myObjects[i], myObjects[i], myEndLCS );
390
391           if ( !anObj->_is_nil() )
392             objects.push_back( anObj._retn() );
393         }
394         res = true;
395         break;
396       }
397     case 1 :
398       {
399         for (int i = 0; i < myObjects.length(); i++) {
400           if (toCreateCopy)
401             anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
402               PositionShapeCopy( myObjects[i], myStartLCS, myEndLCS );
403           else
404             anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
405               PositionShape( myObjects[i], myStartLCS, myEndLCS );
406           if ( !anObj->_is_nil() )
407             objects.push_back( anObj._retn() );
408         }
409         res = true;
410         break;
411       }
412     }
413
414   return res;
415 }
416
417 //=================================================================================
418 // function : restoreSubShapes
419 // purpose  :
420 //=================================================================================
421 void TransformationGUI_PositionDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStudy,
422                                                       SALOMEDS::SObject_ptr theSObject)
423 {
424   if (CheckBoxRestoreSS->isChecked()) {
425     // empty list of arguments means that all arguments should be restored
426     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
427                                         /*theFindMethod=*/GEOM::FSM_Transformed,
428                                         /*theInheritFirstArg=*/true);
429   }
430 }
431
432 //=================================================================================
433 // function :  CreateCopyModeChanged()
434 // purpose  :
435 //=================================================================================
436 void TransformationGUI_PositionDlg::CreateCopyModeChanged(bool isCreateCopy)
437 {
438   this->GroupBoxName->setEnabled(isCreateCopy);
439 }