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"
30 #include "DlgRef_2Sel1Spin2Check.h"
31 #include "DlgRef_SpinBox.h"
33 #include "GeometryGUI.h"
36 #include "SUIT_ResourceMgr.h"
37 #include "SUIT_Session.h"
38 #include "SalomeApp_Application.h"
39 #include "LightApp_SelectionMgr.h"
41 #include "GEOMImpl_Types.hxx"
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, Qt::WindowFlags fl)
54 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
56 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_POINT")));
57 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_AXE")));
58 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_PLANE")));
59 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
61 setWindowTitle(tr("GEOM_MIRROR_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_MIRROR"));
65 RadioButton1->setIcon(image0);
66 RadioButton2->setIcon(image1);
67 RadioButton3->setIcon(image2);
69 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
70 GroupPoints->SpinBox_DX->hide();
71 GroupPoints->TextLabel3->hide();
72 GroupPoints->CheckButton2->hide();
73 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
74 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
75 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
76 GroupPoints->TextLabel2->setFixedWidth(74);
77 GroupPoints->PushButton1->setIcon(image3);
78 GroupPoints->PushButton2->setIcon(image3);
79 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
80 gridLayout1->addWidget(GroupPoints, 2, 0);
81 /***************************************************************/
83 setHelpFileName("mirror_image.htm");
89 //=================================================================================
90 // function : ~TransformationGUI_MirrorDlg()
91 // purpose : Destroys the object and frees any allocated resources
92 //=================================================================================
93 TransformationGUI_MirrorDlg::~TransformationGUI_MirrorDlg()
95 /* no need to delete child widgets, Qt does it all for us */
99 //=================================================================================
102 //=================================================================================
103 void TransformationGUI_MirrorDlg::Init()
106 myEditCurrentArgument = GroupPoints->LineEdit1;
107 GroupPoints->LineEdit1->setReadOnly(true);
108 GroupPoints->LineEdit2->setReadOnly(true);
110 myArgument = GEOM::GEOM_Object::_nil();
112 // Activate Create a Copy mode
113 GroupPoints->CheckButton1->setChecked(true);
114 CreateCopyModeChanged(true);
116 /* signals and slots connections */
117 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
118 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
119 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
121 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
122 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
124 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
125 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
127 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
129 connect(myGeomGUI->getApp()->selectionMgr(),
130 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
132 initName( tr( "GEOM_MIRROR" ).toLatin1().constData() );
133 ConstructorsClicked( 0 );
137 //=================================================================================
138 // function : ConstructorsClicked()
139 // purpose : Radio button management
140 //=================================================================================
141 void TransformationGUI_MirrorDlg::ConstructorsClicked(int constructorId)
143 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
146 myEditCurrentArgument = GroupPoints->LineEdit1;
147 GroupPoints->LineEdit2->clear();
148 myArgument = GEOM::GEOM_Object::_nil();
150 switch (constructorId)
152 case 0: /* mirror an object by point */
154 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
157 case 1: /* mirror an object by axe */
159 GroupPoints->TextLabel2->setText(tr("GEOM_AXE_MIRROR"));
162 case 2: /* mirror an object by plane */
164 GroupPoints->TextLabel2->setText(tr("GEOM_PLANE_MIRROR"));
168 connect(myGeomGUI->getApp()->selectionMgr(),
169 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
174 //=================================================================================
175 // function : ClickOnOk()
177 //=================================================================================
178 void TransformationGUI_MirrorDlg::ClickOnOk()
180 if ( ClickOnApply() )
185 //=================================================================================
186 // function : ClickOnApply()
188 //=================================================================================
189 bool TransformationGUI_MirrorDlg::ClickOnApply()
191 if ( !onAccept(GroupPoints->CheckButton1->isChecked()) )
195 ConstructorsClicked( getConstructorId() );
200 //=================================================================================
201 // function : SelectionIntoArgument()
202 // purpose : Called when selection has changed
203 //=================================================================================
204 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
206 myEditCurrentArgument->setText("");
209 if(myEditCurrentArgument == GroupPoints->LineEdit1)
211 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
217 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
218 if (!myObjects.length())
221 aName = tr("%1_objects").arg(aNbSel);
223 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
225 if(IObjectCount() != 1)
227 myArgument = GEOM::GEOM_Object::_nil();
230 Standard_Boolean testResult = Standard_False;
231 myArgument = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
232 if(!testResult || CORBA::is_nil( myArgument ))
234 aName = GEOMBase::GetName( myArgument );
236 myEditCurrentArgument->setText( aName );
242 //=================================================================================
243 // function : LineEditReturnPressed()
245 //=================================================================================
246 void TransformationGUI_MirrorDlg::LineEditReturnPressed()
248 QLineEdit* send = (QLineEdit*)sender();
249 if(send == GroupPoints->LineEdit1 ||
250 send == GroupPoints->LineEdit2)
252 myEditCurrentArgument = send;
253 GEOMBase_Skeleton::LineEditReturnPressed();
258 //=================================================================================
259 // function : SetEditCurrentArgument()
261 //=================================================================================
262 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
264 QPushButton* send = (QPushButton*)sender();
266 if(send == GroupPoints->PushButton1){
267 myEditCurrentArgument = GroupPoints->LineEdit1;
270 else if(send == GroupPoints->PushButton2) {
271 myEditCurrentArgument = GroupPoints->LineEdit2;
272 switch(getConstructorId())
276 globalSelection( GEOM_POINT );
281 globalSelection( GEOM_LINE );
286 globalSelection( GEOM_PLANE );
292 myEditCurrentArgument->setFocus();
293 SelectionIntoArgument();
297 //=================================================================================
298 // function : ActivateThisDialog()
300 //=================================================================================
301 void TransformationGUI_MirrorDlg::ActivateThisDialog()
303 GEOMBase_Skeleton::ActivateThisDialog();
304 connect(myGeomGUI->getApp()->selectionMgr(),
305 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
306 ConstructorsClicked( getConstructorId() );
310 //=================================================================================
311 // function : enterEvent()
312 // purpose : when mouse enter onto the QWidget
313 //=================================================================================
314 void TransformationGUI_MirrorDlg::enterEvent(QEvent * e)
316 if(!GroupConstructors->isEnabled())
317 ActivateThisDialog();
321 //=================================================================================
322 // function : createOperation
324 //=================================================================================
325 GEOM::GEOM_IOperations_ptr TransformationGUI_MirrorDlg::createOperation()
327 return getGeomEngine()->GetITransformOperations( getStudyId() );
331 //=================================================================================
332 // function : isValid
334 //=================================================================================
335 bool TransformationGUI_MirrorDlg::isValid( QString& msg )
337 return !(myObjects.length() == 0 || myArgument->_is_nil());
341 //=================================================================================
342 // function : execute
344 //=================================================================================
345 bool TransformationGUI_MirrorDlg::execute( ObjectList& objects )
348 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
350 GEOM::GEOM_Object_var anObj;
352 switch ( getConstructorId() )
357 for (int i = 0; i < myObjects.length(); i++)
359 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPointCopy( myObjects[i], myArgument );
360 if ( !anObj->_is_nil() )
361 objects.push_back( anObj._retn() );
364 for (int i = 0; i < myObjects.length(); i++)
366 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPoint( myObjects[i], myArgument );
367 if ( !anObj->_is_nil() )
368 objects.push_back( anObj._retn() );
376 for (int i = 0; i < myObjects.length(); i++)
378 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorAxisCopy( 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() )->MirrorAxis( 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() )->MirrorPlaneCopy( 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() )->MirrorPlane( myObjects[i], myArgument );
405 if ( !anObj->_is_nil() )
406 objects.push_back( anObj._retn() );
416 //=================================================================================
417 // function : closeEvent
419 //=================================================================================
420 void TransformationGUI_MirrorDlg::closeEvent( QCloseEvent* e )
422 GEOMBase_Skeleton::closeEvent( e );
426 //=================================================================================
427 // function : CreateCopyModeChanged()
429 //=================================================================================
430 void TransformationGUI_MirrorDlg::CreateCopyModeChanged(bool isCreateCopy)
432 this->GroupBoxName->setEnabled(isCreateCopy);