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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 "LightApp_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(GeometryGUI* theGeometryGUI, QWidget* parent,
53 const char* name, bool modal, WFlags fl)
54 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
55 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
57 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_POINT")));
58 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_AXE")));
59 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_PLANE")));
60 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
62 setCaption(tr("GEOM_MIRROR_TITLE"));
64 /***************************************************************/
65 GroupConstructors->setTitle(tr("GEOM_MIRROR"));
66 RadioButton1->setPixmap(image0);
67 RadioButton2->setPixmap(image1);
68 RadioButton3->setPixmap(image2);
70 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
71 GroupPoints->SpinBox_DX->hide();
72 GroupPoints->TextLabel3->hide();
73 GroupPoints->CheckButton2->hide();
74 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
75 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
76 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
77 GroupPoints->TextLabel2->setFixedWidth(74);
78 GroupPoints->PushButton1->setPixmap(image3);
79 GroupPoints->PushButton2->setPixmap(image3);
80 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
81 Layout1->addWidget(GroupPoints, 2, 0);
82 /***************************************************************/
84 setHelpFileName("mirror_image.htm");
90 //=================================================================================
91 // function : ~TransformationGUI_MirrorDlg()
92 // purpose : Destroys the object and frees any allocated resources
93 //=================================================================================
94 TransformationGUI_MirrorDlg::~TransformationGUI_MirrorDlg()
96 /* no need to delete child widgets, Qt does it all for us */
100 //=================================================================================
103 //=================================================================================
104 void TransformationGUI_MirrorDlg::Init()
107 myEditCurrentArgument = GroupPoints->LineEdit1;
108 GroupPoints->LineEdit1->setReadOnly(true);
109 GroupPoints->LineEdit2->setReadOnly(true);
111 myArgument = GEOM::GEOM_Object::_nil();
113 // Activate Create a Copy mode
114 GroupPoints->CheckButton1->setChecked(true);
115 CreateCopyModeChanged(true);
117 /* signals and slots connections */
118 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
119 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
120 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
122 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
125 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
126 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
128 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
130 connect(myGeomGUI->getApp()->selectionMgr(),
131 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
133 initName( tr( "GEOM_MIRROR" ) );
134 ConstructorsClicked( 0 );
138 //=================================================================================
139 // function : ConstructorsClicked()
140 // purpose : Radio button management
141 //=================================================================================
142 void TransformationGUI_MirrorDlg::ConstructorsClicked(int constructorId)
144 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
147 myEditCurrentArgument = GroupPoints->LineEdit1;
148 GroupPoints->LineEdit2->clear();
149 myArgument = GEOM::GEOM_Object::_nil();
151 switch (constructorId)
153 case 0: /* mirror an object by point */
155 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
158 case 1: /* mirror an object by axe */
160 GroupPoints->TextLabel2->setText(tr("GEOM_AXE_MIRROR"));
163 case 2: /* mirror an object by plane */
165 GroupPoints->TextLabel2->setText(tr("GEOM_PLANE_MIRROR"));
169 connect(myGeomGUI->getApp()->selectionMgr(),
170 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
175 //=================================================================================
176 // function : ClickOnOk()
178 //=================================================================================
179 void TransformationGUI_MirrorDlg::ClickOnOk()
181 if ( ClickOnApply() )
186 //=================================================================================
187 // function : ClickOnApply()
189 //=================================================================================
190 bool TransformationGUI_MirrorDlg::ClickOnApply()
192 if ( !onAccept(GroupPoints->CheckButton1->isChecked()) )
196 ConstructorsClicked( getConstructorId() );
201 //=================================================================================
202 // function : SelectionIntoArgument()
203 // purpose : Called when selection has changed
204 //=================================================================================
205 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
207 myEditCurrentArgument->setText("");
210 if(myEditCurrentArgument == GroupPoints->LineEdit1)
212 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
218 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
219 if (!myObjects.length())
222 aName = tr("%1_objects").arg(aNbSel);
224 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
226 if(IObjectCount() != 1)
228 myArgument = GEOM::GEOM_Object::_nil();
231 Standard_Boolean testResult = Standard_False;
232 myArgument = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
233 if(!testResult || CORBA::is_nil( myArgument ))
235 aName = GEOMBase::GetName( myArgument );
237 myEditCurrentArgument->setText( aName );
243 //=================================================================================
244 // function : LineEditReturnPressed()
246 //=================================================================================
247 void TransformationGUI_MirrorDlg::LineEditReturnPressed()
249 QLineEdit* send = (QLineEdit*)sender();
250 if(send == GroupPoints->LineEdit1 ||
251 send == GroupPoints->LineEdit2)
253 myEditCurrentArgument = send;
254 GEOMBase_Skeleton::LineEditReturnPressed();
259 //=================================================================================
260 // function : SetEditCurrentArgument()
262 //=================================================================================
263 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
265 QPushButton* send = (QPushButton*)sender();
267 if(send == GroupPoints->PushButton1){
268 myEditCurrentArgument = GroupPoints->LineEdit1;
271 else if(send == GroupPoints->PushButton2) {
272 myEditCurrentArgument = GroupPoints->LineEdit2;
273 switch(getConstructorId())
277 globalSelection( GEOM_POINT );
282 globalSelection( GEOM_LINE );
287 globalSelection( GEOM_PLANE );
293 myEditCurrentArgument->setFocus();
294 SelectionIntoArgument();
298 //=================================================================================
299 // function : ActivateThisDialog()
301 //=================================================================================
302 void TransformationGUI_MirrorDlg::ActivateThisDialog()
304 GEOMBase_Skeleton::ActivateThisDialog();
305 connect(myGeomGUI->getApp()->selectionMgr(),
306 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
307 ConstructorsClicked( getConstructorId() );
311 //=================================================================================
312 // function : enterEvent()
313 // purpose : when mouse enter onto the QWidget
314 //=================================================================================
315 void TransformationGUI_MirrorDlg::enterEvent(QEvent * e)
317 if(!GroupConstructors->isEnabled())
318 ActivateThisDialog();
322 //=================================================================================
323 // function : createOperation
325 //=================================================================================
326 GEOM::GEOM_IOperations_ptr TransformationGUI_MirrorDlg::createOperation()
328 return getGeomEngine()->GetITransformOperations( getStudyId() );
332 //=================================================================================
333 // function : isValid
335 //=================================================================================
336 bool TransformationGUI_MirrorDlg::isValid( QString& msg )
338 return !(myObjects.length() == 0 || myArgument->_is_nil());
342 //=================================================================================
343 // function : execute
345 //=================================================================================
346 bool TransformationGUI_MirrorDlg::execute( ObjectList& objects )
349 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
351 GEOM::GEOM_Object_var anObj;
353 switch ( getConstructorId() )
358 for (int i = 0; i < myObjects.length(); i++)
360 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPointCopy( myObjects[i], myArgument );
361 if ( !anObj->_is_nil() )
362 objects.push_back( anObj._retn() );
365 for (int i = 0; i < myObjects.length(); i++)
367 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPoint( myObjects[i], myArgument );
368 if ( !anObj->_is_nil() )
369 objects.push_back( anObj._retn() );
377 for (int i = 0; i < myObjects.length(); i++)
379 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorAxisCopy( myObjects[i], myArgument );
380 if ( !anObj->_is_nil() )
381 objects.push_back( anObj._retn() );
384 for (int i = 0; i < myObjects.length(); i++)
386 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorAxis( myObjects[i], myArgument );
387 if ( !anObj->_is_nil() )
388 objects.push_back( anObj._retn() );
396 for (int i = 0; i < myObjects.length(); i++)
398 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPlaneCopy( myObjects[i], myArgument );
399 if ( !anObj->_is_nil() )
400 objects.push_back( anObj._retn() );
403 for (int i = 0; i < myObjects.length(); i++)
405 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPlane( myObjects[i], myArgument );
406 if ( !anObj->_is_nil() )
407 objects.push_back( anObj._retn() );
417 //=================================================================================
418 // function : closeEvent
420 //=================================================================================
421 void TransformationGUI_MirrorDlg::closeEvent( QCloseEvent* e )
423 GEOMBase_Skeleton::closeEvent( e );
427 //=================================================================================
428 // function : CreateCopyModeChanged()
430 //=================================================================================
431 void TransformationGUI_MirrorDlg::CreateCopyModeChanged(bool isCreateCopy)
433 this->GroupBoxName->setEnabled(isCreateCopy);