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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : TransformationGUI_MirrorDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "TransformationGUI_MirrorDlg.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "SalomeApp_SelectionMgr.h"
36 #include <qcheckbox.h>
39 #include "GEOMImpl_Types.hxx"
41 #include "utilities.h"
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)
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")));
60 setCaption(tr("GEOM_MIRROR_TITLE"));
62 /***************************************************************/
63 GroupConstructors->setTitle(tr("GEOM_MIRROR"));
64 RadioButton1->setPixmap(image0);
65 RadioButton2->setPixmap(image1);
66 RadioButton3->setPixmap(image2);
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);
81 /***************************************************************/
87 //=================================================================================
88 // function : ~TransformationGUI_MirrorDlg()
89 // purpose : Destroys the object and frees any allocated resources
90 //=================================================================================
91 TransformationGUI_MirrorDlg::~TransformationGUI_MirrorDlg()
93 /* no need to delete child widgets, Qt does it all for us */
97 //=================================================================================
100 //=================================================================================
101 void TransformationGUI_MirrorDlg::Init()
104 myEditCurrentArgument = GroupPoints->LineEdit1;
105 GroupPoints->LineEdit1->setReadOnly(true);
106 GroupPoints->LineEdit2->setReadOnly(true);
108 myArgument = GEOM::GEOM_Object::_nil();
110 // Activate Create a Copy mode
111 GroupPoints->CheckButton1->setChecked(true);
112 CreateCopyModeChanged(true);
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)));
119 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
120 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
122 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
123 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
125 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
127 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
128 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
130 initName( tr( "GEOM_MIRROR" ) );
131 ConstructorsClicked( 0 );
136 //=================================================================================
137 // function : ConstructorsClicked()
138 // purpose : Radio button management
139 //=================================================================================
140 void TransformationGUI_MirrorDlg::ConstructorsClicked(int constructorId)
142 disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0 );
145 myEditCurrentArgument = GroupPoints->LineEdit1;
146 GroupPoints->LineEdit2->clear();
147 myArgument = GEOM::GEOM_Object::_nil();
149 switch (constructorId)
151 case 0: /* mirror an object by point */
153 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
156 case 1: /* mirror an object by axe */
158 GroupPoints->TextLabel2->setText(tr("GEOM_AXE_MIRROR"));
161 case 2: /* mirror an object by plane */
163 GroupPoints->TextLabel2->setText(tr("GEOM_PLANE_MIRROR"));
167 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
168 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
173 //=================================================================================
174 // function : ClickOnOk()
176 //=================================================================================
177 void TransformationGUI_MirrorDlg::ClickOnOk()
179 if ( ClickOnApply() )
184 //=================================================================================
185 // function : ClickOnApply()
187 //=================================================================================
188 bool TransformationGUI_MirrorDlg::ClickOnApply()
190 if ( !onAccept(GroupPoints->CheckButton1->isChecked()) )
194 ConstructorsClicked( getConstructorId() );
199 //=======================================================================
200 // function : ClickOnCancel()
202 //=======================================================================
203 void TransformationGUI_MirrorDlg::ClickOnCancel()
205 GEOMBase_Skeleton::ClickOnCancel();
209 //=================================================================================
210 // function : SelectionIntoArgument()
211 // purpose : Called when selection has changed
212 //=================================================================================
213 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
215 myEditCurrentArgument->setText("");
218 if(myEditCurrentArgument == GroupPoints->LineEdit1)
220 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
226 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
227 if (!myObjects.length())
230 aName = tr("%1_objects").arg(aNbSel);
232 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
234 if(IObjectCount() != 1)
236 myArgument = GEOM::GEOM_Object::_nil();
239 Standard_Boolean testResult = Standard_False;
240 myArgument = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
241 if(!testResult || CORBA::is_nil( myArgument ))
243 aName = GEOMBase::GetName( myArgument );
245 myEditCurrentArgument->setText( aName );
251 //=================================================================================
252 // function : LineEditReturnPressed()
254 //=================================================================================
255 void TransformationGUI_MirrorDlg::LineEditReturnPressed()
257 QLineEdit* send = (QLineEdit*)sender();
258 if(send == GroupPoints->LineEdit1 ||
259 send == GroupPoints->LineEdit2)
261 myEditCurrentArgument = send;
262 GEOMBase_Skeleton::LineEditReturnPressed();
267 //=================================================================================
268 // function : SetEditCurrentArgument()
270 //=================================================================================
271 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
273 QPushButton* send = (QPushButton*)sender();
275 if(send == GroupPoints->PushButton1){
276 myEditCurrentArgument = GroupPoints->LineEdit1;
279 else if(send == GroupPoints->PushButton2) {
280 myEditCurrentArgument = GroupPoints->LineEdit2;
281 switch(getConstructorId())
285 globalSelection( GEOM_POINT );
290 globalSelection( GEOM_LINE );
295 globalSelection( GEOM_PLANE );
301 myEditCurrentArgument->setFocus();
302 SelectionIntoArgument();
306 //=================================================================================
307 // function : ActivateThisDialog()
309 //=================================================================================
310 void TransformationGUI_MirrorDlg::ActivateThisDialog()
312 GEOMBase_Skeleton::ActivateThisDialog();
313 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
314 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
315 ConstructorsClicked( getConstructorId() );
319 //=================================================================================
320 // function : DeactivateActiveDialog()
321 // purpose : public slot to deactivate if active
322 //=================================================================================
323 void TransformationGUI_MirrorDlg::DeactivateActiveDialog()
325 GEOMBase_Skeleton::DeactivateActiveDialog();
329 //=================================================================================
330 // function : enterEvent()
331 // purpose : when mouse enter onto the QWidget
332 //=================================================================================
333 void TransformationGUI_MirrorDlg::enterEvent(QEvent * e)
335 if(!GroupConstructors->isEnabled())
336 ActivateThisDialog();
340 //=================================================================================
341 // function : createOperation
343 //=================================================================================
344 GEOM::GEOM_IOperations_ptr TransformationGUI_MirrorDlg::createOperation()
346 return getGeomEngine()->GetITransformOperations( getStudyId() );
350 //=================================================================================
351 // function : isValid
353 //=================================================================================
354 bool TransformationGUI_MirrorDlg::isValid( QString& msg )
356 return !(myObjects.length() == 0 || myArgument->_is_nil());
360 //=================================================================================
361 // function : execute
363 //=================================================================================
364 bool TransformationGUI_MirrorDlg::execute( ObjectList& objects )
367 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
369 GEOM::GEOM_Object_var anObj;
371 switch ( getConstructorId() )
376 for (int i = 0; i < myObjects.length(); i++)
378 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPointCopy( myObjects[i], myArgument );
379 if ( !anObj->_is_nil() )
380 objects.push_back( anObj._retn() );
383 for (int i = 0; i < myObjects.length(); i++)
385 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPoint( myObjects[i], myArgument );
386 if ( !anObj->_is_nil() )
387 objects.push_back( anObj._retn() );
395 for (int i = 0; i < myObjects.length(); i++)
397 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorAxisCopy( myObjects[i], myArgument );
398 if ( !anObj->_is_nil() )
399 objects.push_back( anObj._retn() );
402 for (int i = 0; i < myObjects.length(); i++)
404 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorAxis( myObjects[i], myArgument );
405 if ( !anObj->_is_nil() )
406 objects.push_back( anObj._retn() );
414 for (int i = 0; i < myObjects.length(); i++)
416 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPlaneCopy( myObjects[i], myArgument );
417 if ( !anObj->_is_nil() )
418 objects.push_back( anObj._retn() );
421 for (int i = 0; i < myObjects.length(); i++)
423 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPlane( myObjects[i], myArgument );
424 if ( !anObj->_is_nil() )
425 objects.push_back( anObj._retn() );
435 //=================================================================================
436 // function : closeEvent
438 //=================================================================================
439 void TransformationGUI_MirrorDlg::closeEvent( QCloseEvent* e )
441 GEOMBase_Skeleton::closeEvent( e );
445 //=================================================================================
446 // function : CreateCopyModeChanged()
448 //=================================================================================
449 void TransformationGUI_MirrorDlg::CreateCopyModeChanged(bool isCreateCopy)
451 this->GroupBoxName->setEnabled(isCreateCopy);