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 "QAD_Desktop.h"
33 #include <qcheckbox.h>
35 #include "GEOMImpl_Types.hxx"
37 #include "utilities.h"
41 //=================================================================================
42 // class : TransformationGUI_MirrorDlg()
43 // purpose : Constructs a TransformationGUI_MirrorDlg which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 TransformationGUI_MirrorDlg::TransformationGUI_MirrorDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
49 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
51 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_POINT")));
52 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_AXE")));
53 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_PLANE")));
54 QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
56 setCaption(tr("GEOM_MIRROR_TITLE"));
58 /***************************************************************/
59 GroupConstructors->setTitle(tr("GEOM_MIRROR"));
60 RadioButton1->setPixmap(image0);
61 RadioButton2->setPixmap(image1);
62 RadioButton3->setPixmap(image2);
64 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
65 GroupPoints->SpinBox_DX->hide();
66 GroupPoints->TextLabel3->hide();
67 GroupPoints->CheckButton2->hide();
68 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
69 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
70 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
71 GroupPoints->TextLabel2->setFixedWidth(74);
72 GroupPoints->PushButton1->setPixmap(image3);
73 GroupPoints->PushButton2->setPixmap(image3);
74 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
75 Layout1->addWidget(GroupPoints, 2, 0);
77 /***************************************************************/
83 //=================================================================================
84 // function : ~TransformationGUI_MirrorDlg()
85 // purpose : Destroys the object and frees any allocated resources
86 //=================================================================================
87 TransformationGUI_MirrorDlg::~TransformationGUI_MirrorDlg()
89 /* no need to delete child widgets, Qt does it all for us */
93 //=================================================================================
96 //=================================================================================
97 void TransformationGUI_MirrorDlg::Init()
100 myEditCurrentArgument = GroupPoints->LineEdit1;
101 GroupPoints->LineEdit1->setReadOnly(true);
102 GroupPoints->LineEdit2->setReadOnly(true);
104 myArgument = GEOM::GEOM_Object::_nil();
106 // Activate Create a Copy mode
107 GroupPoints->CheckButton1->setChecked(true);
108 CreateCopyModeChanged(true);
110 /* signals and slots connections */
111 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
112 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
113 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
115 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
116 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
118 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
119 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
121 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
123 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
125 initName( tr( "GEOM_MIRROR" ) );
126 ConstructorsClicked( 0 );
131 //=================================================================================
132 // function : ConstructorsClicked()
133 // purpose : Radio button management
134 //=================================================================================
135 void TransformationGUI_MirrorDlg::ConstructorsClicked(int constructorId)
137 disconnect( mySelection, 0, this, 0 );
140 myEditCurrentArgument = GroupPoints->LineEdit1;
141 GroupPoints->LineEdit2->clear();
142 myArgument = GEOM::GEOM_Object::_nil();
144 switch (constructorId)
146 case 0: /* mirror an object by point */
148 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
151 case 1: /* mirror an object by axe */
153 GroupPoints->TextLabel2->setText(tr("GEOM_AXE_MIRROR"));
156 case 2: /* mirror an object by plane */
158 GroupPoints->TextLabel2->setText(tr("GEOM_PLANE_MIRROR"));
162 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
167 //=================================================================================
168 // function : ClickOnOk()
170 //=================================================================================
171 void TransformationGUI_MirrorDlg::ClickOnOk()
173 if ( ClickOnApply() )
178 //=================================================================================
179 // function : ClickOnApply()
181 //=================================================================================
182 bool TransformationGUI_MirrorDlg::ClickOnApply()
184 if ( !onAccept(GroupPoints->CheckButton1->isChecked()) )
188 ConstructorsClicked( getConstructorId() );
193 //=======================================================================
194 // function : ClickOnCancel()
196 //=======================================================================
197 void TransformationGUI_MirrorDlg::ClickOnCancel()
199 GEOMBase_Skeleton::ClickOnCancel();
203 //=================================================================================
204 // function : SelectionIntoArgument()
205 // purpose : Called when selection has changed
206 //=================================================================================
207 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
209 myEditCurrentArgument->setText("");
212 if(myEditCurrentArgument == GroupPoints->LineEdit1)
214 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(mySelection, aName);
220 GEOMBase::ConvertListOfIOInListOfGO(mySelection->StoredIObjects(), myObjects);
221 if (!myObjects.length())
224 aName = tr("%1_objects").arg(aNbSel);
226 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
228 if(mySelection->IObjectCount() != 1)
230 myArgument = GEOM::GEOM_Object::_nil();
233 Standard_Boolean testResult = Standard_False;
234 myArgument = GEOMBase::ConvertIOinGEOMObject(mySelection->firstIObject(), testResult );
235 if(!testResult || CORBA::is_nil( myArgument ))
237 aName = GEOMBase::GetName( myArgument );
239 myEditCurrentArgument->setText( aName );
245 //=================================================================================
246 // function : LineEditReturnPressed()
248 //=================================================================================
249 void TransformationGUI_MirrorDlg::LineEditReturnPressed()
251 QLineEdit* send = (QLineEdit*)sender();
252 if(send == GroupPoints->LineEdit1 ||
253 send == GroupPoints->LineEdit2)
255 myEditCurrentArgument = send;
256 GEOMBase_Skeleton::LineEditReturnPressed();
261 //=================================================================================
262 // function : SetEditCurrentArgument()
264 //=================================================================================
265 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
267 QPushButton* send = (QPushButton*)sender();
269 if(send == GroupPoints->PushButton1){
270 myEditCurrentArgument = GroupPoints->LineEdit1;
273 else if(send == GroupPoints->PushButton2) {
274 myEditCurrentArgument = GroupPoints->LineEdit2;
275 switch(getConstructorId())
279 globalSelection( GEOM_POINT );
284 globalSelection( GEOM_LINE );
289 globalSelection( GEOM_PLANE );
295 myEditCurrentArgument->setFocus();
296 SelectionIntoArgument();
300 //=================================================================================
301 // function : ActivateThisDialog()
303 //=================================================================================
304 void TransformationGUI_MirrorDlg::ActivateThisDialog()
306 GEOMBase_Skeleton::ActivateThisDialog();
307 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
308 ConstructorsClicked( getConstructorId() );
312 //=================================================================================
313 // function : DeactivateActiveDialog()
314 // purpose : public slot to deactivate if active
315 //=================================================================================
316 void TransformationGUI_MirrorDlg::DeactivateActiveDialog()
318 GEOMBase_Skeleton::DeactivateActiveDialog();
322 //=================================================================================
323 // function : enterEvent()
324 // purpose : when mouse enter onto the QWidget
325 //=================================================================================
326 void TransformationGUI_MirrorDlg::enterEvent(QEvent * e)
328 if(!GroupConstructors->isEnabled())
329 ActivateThisDialog();
333 //=================================================================================
334 // function : createOperation
336 //=================================================================================
337 GEOM::GEOM_IOperations_ptr TransformationGUI_MirrorDlg::createOperation()
339 return getGeomEngine()->GetITransformOperations( getStudyId() );
343 //=================================================================================
344 // function : isValid
346 //=================================================================================
347 bool TransformationGUI_MirrorDlg::isValid( QString& msg )
349 return !(myObjects.length() == 0 || myArgument->_is_nil());
353 //=================================================================================
354 // function : execute
356 //=================================================================================
357 bool TransformationGUI_MirrorDlg::execute( ObjectList& objects )
360 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
362 GEOM::GEOM_Object_var anObj;
364 switch ( getConstructorId() )
369 for (int i = 0; i < myObjects.length(); i++)
371 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPointCopy( myObjects[i], myArgument );
372 if ( !anObj->_is_nil() )
373 objects.push_back( anObj._retn() );
376 for (int i = 0; i < myObjects.length(); i++)
378 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPoint( myObjects[i], myArgument );
379 if ( !anObj->_is_nil() )
380 objects.push_back( anObj._retn() );
388 for (int i = 0; i < myObjects.length(); i++)
390 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorAxisCopy( myObjects[i], myArgument );
391 if ( !anObj->_is_nil() )
392 objects.push_back( anObj._retn() );
395 for (int i = 0; i < myObjects.length(); i++)
397 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorAxis( myObjects[i], myArgument );
398 if ( !anObj->_is_nil() )
399 objects.push_back( anObj._retn() );
407 for (int i = 0; i < myObjects.length(); i++)
409 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPlaneCopy( myObjects[i], myArgument );
410 if ( !anObj->_is_nil() )
411 objects.push_back( anObj._retn() );
414 for (int i = 0; i < myObjects.length(); i++)
416 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPlane( myObjects[i], myArgument );
417 if ( !anObj->_is_nil() )
418 objects.push_back( anObj._retn() );
428 //=================================================================================
429 // function : closeEvent
431 //=================================================================================
432 void TransformationGUI_MirrorDlg::closeEvent( QCloseEvent* e )
434 GEOMBase_Skeleton::closeEvent( e );
438 //=================================================================================
439 // function : CreateCopyModeChanged()
441 //=================================================================================
442 void TransformationGUI_MirrorDlg::CreateCopyModeChanged(bool isCreateCopy)
444 this->GroupBoxName->setEnabled(isCreateCopy);