]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI_MirrorDlg.cxx
Salome HOME
Using files from package LightApp instead of SalomeApp
[modules/geom.git] / src / TransformationGUI / TransformationGUI_MirrorDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : TransformationGUI_MirrorDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "TransformationGUI_MirrorDlg.h"
30
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
35
36 #include <qcheckbox.h>
37 #include <qlabel.h>
38
39 #include "GEOMImpl_Types.hxx"
40
41 #include "utilities.h"
42
43 using namespace std;
44
45 //=================================================================================
46 // class    : TransformationGUI_MirrorDlg()
47 // purpose  : Constructs a TransformationGUI_MirrorDlg which is a child of 'parent', with the 
48 //            name 'name' and widget flags set to 'f'.
49 //            The dialog will by default be modeless, unless you set 'modal' to
50 //            TRUE to construct a modal dialog.
51 //=================================================================================
52 TransformationGUI_MirrorDlg::TransformationGUI_MirrorDlg(QWidget* parent,  const char* name, bool modal, WFlags fl)
53   :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
54 {
55   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_POINT")));
56   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_AXE")));
57   QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_PLANE")));
58   QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
59
60   setCaption(tr("GEOM_MIRROR_TITLE"));
61
62   /***************************************************************/
63   GroupConstructors->setTitle(tr("GEOM_MIRROR"));
64   RadioButton1->setPixmap(image0);
65   RadioButton2->setPixmap(image1);
66   RadioButton3->setPixmap(image2);
67  
68   GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
69   GroupPoints->SpinBox_DX->hide();
70   GroupPoints->TextLabel3->hide();
71   GroupPoints->CheckButton2->hide();
72   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
73   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
74   GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
75   GroupPoints->TextLabel2->setFixedWidth(74);
76   GroupPoints->PushButton1->setPixmap(image3);
77   GroupPoints->PushButton2->setPixmap(image3);
78   GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
79   Layout1->addWidget(GroupPoints, 2, 0);
80   
81   /***************************************************************/
82   
83   Init();
84 }
85
86
87 //=================================================================================
88 // function : ~TransformationGUI_MirrorDlg()
89 // purpose  : Destroys the object and frees any allocated resources
90 //=================================================================================
91 TransformationGUI_MirrorDlg::~TransformationGUI_MirrorDlg()
92 {  
93   /* no need to delete child widgets, Qt does it all for us */
94 }
95
96
97 //=================================================================================
98 // function : Init()
99 // purpose  :
100 //=================================================================================
101 void TransformationGUI_MirrorDlg::Init()
102 {  
103   /* init variables */
104   myEditCurrentArgument = GroupPoints->LineEdit1;
105   GroupPoints->LineEdit1->setReadOnly(true);
106   GroupPoints->LineEdit2->setReadOnly(true);
107   
108   myArgument = GEOM::GEOM_Object::_nil();
109     
110   // Activate Create a Copy mode
111   GroupPoints->CheckButton1->setChecked(true);
112   CreateCopyModeChanged(true);
113
114   /* signals and slots connections */
115   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
116   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
117   connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
118
119   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
120   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
121
122   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
123   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
124   
125   connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
126   
127   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
128           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
129
130   initName( tr( "GEOM_MIRROR" ) );
131   ConstructorsClicked( 0 );
132 }
133
134
135
136 //=================================================================================
137 // function : ConstructorsClicked()
138 // purpose  : Radio button management
139 //=================================================================================
140 void TransformationGUI_MirrorDlg::ConstructorsClicked(int constructorId)
141 {
142   disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
143   
144   globalSelection();
145   myEditCurrentArgument = GroupPoints->LineEdit1;
146   GroupPoints->LineEdit2->clear();
147   myArgument = GEOM::GEOM_Object::_nil();
148   
149   switch (constructorId)
150     {
151     case 0: /* mirror an object by point */
152       { 
153         GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
154         break;
155       }
156     case 1: /* mirror an object by axe */
157       {
158         GroupPoints->TextLabel2->setText(tr("GEOM_AXE_MIRROR"));
159         break;
160       } 
161     case 2: /* mirror an object by plane */
162       {
163         GroupPoints->TextLabel2->setText(tr("GEOM_PLANE_MIRROR"));
164         break;
165       }
166     }
167   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
168           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
169 }
170
171
172
173 //=================================================================================
174 // function : ClickOnOk()
175 // purpose  :
176 //=================================================================================
177 void TransformationGUI_MirrorDlg::ClickOnOk()
178 {
179   if ( ClickOnApply() )
180     ClickOnCancel();
181 }
182
183
184 //=================================================================================
185 // function : ClickOnApply()
186 // purpose  :
187 //=================================================================================
188 bool TransformationGUI_MirrorDlg::ClickOnApply()
189 {
190   if ( !onAccept(GroupPoints->CheckButton1->isChecked()) )
191     return false;
192   
193   initName();
194   ConstructorsClicked( getConstructorId() );
195   return true;
196 }
197
198
199 //=======================================================================
200 // function : ClickOnCancel()
201 // purpose  :
202 //=======================================================================
203 void TransformationGUI_MirrorDlg::ClickOnCancel()
204 {
205   GEOMBase_Skeleton::ClickOnCancel();
206 }
207
208
209 //=================================================================================
210 // function : SelectionIntoArgument()
211 // purpose  : Called when selection has changed
212 //=================================================================================
213 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
214 {
215   myEditCurrentArgument->setText("");
216   QString aName;
217
218   if(myEditCurrentArgument == GroupPoints->LineEdit1)
219     {
220       int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
221       if(aNbSel < 1)
222         {
223           myObjects.length(0);
224           return;
225         }
226       GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
227       if (!myObjects.length())
228         return;
229       if(aNbSel != 1)
230         aName = tr("%1_objects").arg(aNbSel);
231     }
232   else if(myEditCurrentArgument == GroupPoints->LineEdit2)
233     {
234       if(IObjectCount() != 1)
235         {
236           myArgument = GEOM::GEOM_Object::_nil();
237           return;
238         }
239       Standard_Boolean testResult = Standard_False;
240       myArgument = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
241       if(!testResult || CORBA::is_nil( myArgument ))
242         return;
243       aName = GEOMBase::GetName( myArgument );
244     }
245   myEditCurrentArgument->setText( aName );
246    
247   displayPreview(); 
248 }
249
250
251 //=================================================================================
252 // function : LineEditReturnPressed()
253 // purpose  :
254 //=================================================================================
255 void TransformationGUI_MirrorDlg::LineEditReturnPressed()
256 {
257   QLineEdit* send = (QLineEdit*)sender();
258   if(send == GroupPoints->LineEdit1 ||
259      send == GroupPoints->LineEdit2)
260     {
261       myEditCurrentArgument = send;
262       GEOMBase_Skeleton::LineEditReturnPressed();
263     }
264 }
265
266
267 //=================================================================================
268 // function : SetEditCurrentArgument()
269 // purpose  :
270 //=================================================================================
271 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
272 {
273   QPushButton* send = (QPushButton*)sender();
274   
275   if(send == GroupPoints->PushButton1){
276     myEditCurrentArgument = GroupPoints->LineEdit1;
277     globalSelection();
278   }
279   else if(send == GroupPoints->PushButton2) {
280     myEditCurrentArgument = GroupPoints->LineEdit2;
281     switch(getConstructorId())
282       {
283       case 0:
284         {
285           globalSelection( GEOM_POINT );
286           break;
287         }
288       case 1:
289         {
290           globalSelection( GEOM_LINE );
291           break;
292         }
293       case 2:
294         {
295           globalSelection( GEOM_PLANE );
296           break;
297         }
298       }
299   }
300
301   myEditCurrentArgument->setFocus();
302   SelectionIntoArgument();
303 }
304
305
306 //=================================================================================
307 // function : ActivateThisDialog()
308 // purpose  :
309 //=================================================================================
310 void TransformationGUI_MirrorDlg::ActivateThisDialog()
311 {
312   GEOMBase_Skeleton::ActivateThisDialog();
313   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
314           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
315   ConstructorsClicked( getConstructorId() );
316 }
317
318
319 //=================================================================================
320 // function : DeactivateActiveDialog()
321 // purpose  : public slot to deactivate if active
322 //=================================================================================
323 void TransformationGUI_MirrorDlg::DeactivateActiveDialog()
324 {
325   GEOMBase_Skeleton::DeactivateActiveDialog();
326 }
327
328
329 //=================================================================================
330 // function : enterEvent()
331 // purpose  : when mouse enter onto the QWidget
332 //=================================================================================
333 void TransformationGUI_MirrorDlg::enterEvent(QEvent * e)
334 {
335   if(!GroupConstructors->isEnabled())
336     ActivateThisDialog();
337 }
338
339
340 //=================================================================================
341 // function : createOperation
342 // purpose  :
343 //=================================================================================
344 GEOM::GEOM_IOperations_ptr  TransformationGUI_MirrorDlg::createOperation()
345 {
346   return getGeomEngine()->GetITransformOperations( getStudyId() );
347 }
348
349
350 //=================================================================================
351 // function : isValid
352 // purpose  :
353 //=================================================================================
354 bool  TransformationGUI_MirrorDlg::isValid( QString& msg )
355 {
356   return !(myObjects.length() == 0 || myArgument->_is_nil());
357 }
358
359
360 //=================================================================================
361 // function : execute
362 // purpose  :
363 //=================================================================================
364 bool  TransformationGUI_MirrorDlg::execute( ObjectList& objects )
365 {
366   bool res = false;
367   bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
368   
369   GEOM::GEOM_Object_var anObj;
370   
371   switch ( getConstructorId() ) 
372     {
373     case 0 :
374       {
375         if (toCreateCopy)
376           for (int i = 0; i < myObjects.length(); i++)
377             {
378               anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPointCopy( myObjects[i], myArgument );
379               if ( !anObj->_is_nil() )
380                 objects.push_back( anObj._retn() );
381             }
382         else
383           for (int i = 0; i < myObjects.length(); i++)
384             {
385               anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPoint( myObjects[i], myArgument );
386               if ( !anObj->_is_nil() )
387                 objects.push_back( anObj._retn() );
388             }
389         res = true;
390         break;
391       }
392     case 1 :
393       {
394         if (toCreateCopy)
395           for (int i = 0; i < myObjects.length(); i++)
396             {
397               anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorAxisCopy( myObjects[i], myArgument );
398               if ( !anObj->_is_nil() )
399                 objects.push_back( anObj._retn() );
400             }
401         else
402           for (int i = 0; i < myObjects.length(); i++)
403             {
404               anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorAxis( myObjects[i], myArgument );
405               if ( !anObj->_is_nil() )
406                 objects.push_back( anObj._retn() );
407             }
408         res = true;
409         break;
410       }
411     case 2:
412       {
413         if (toCreateCopy)
414            for (int i = 0; i < myObjects.length(); i++)
415             {
416               anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPlaneCopy( myObjects[i], myArgument );
417               if ( !anObj->_is_nil() )
418                 objects.push_back( anObj._retn() );
419             }
420         else
421            for (int i = 0; i < myObjects.length(); i++)
422             {
423               anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPlane( myObjects[i], myArgument );
424               if ( !anObj->_is_nil() )
425                 objects.push_back( anObj._retn() );
426             }
427         res = true;
428         break;
429       }
430     }
431   
432   return res;
433 }
434
435 //=================================================================================
436 // function : closeEvent
437 // purpose  :
438 //=================================================================================
439 void  TransformationGUI_MirrorDlg::closeEvent( QCloseEvent* e )
440 {
441   GEOMBase_Skeleton::closeEvent( e );
442 }
443
444
445 //=================================================================================
446 // function :  CreateCopyModeChanged()
447 // purpose  :
448 //=================================================================================
449 void TransformationGUI_MirrorDlg::CreateCopyModeChanged(bool isCreateCopy)
450 {
451   this->GroupBoxName->setEnabled(isCreateCopy);
452 }