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 <TopoDS_Shape.hxx>
37 #include <TopoDS_Edge.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <qcheckbox.h>
46 #include "GEOMImpl_Types.hxx"
48 #include "utilities.h"
52 //=================================================================================
53 // class : TransformationGUI_MirrorDlg()
54 // purpose : Constructs a TransformationGUI_MirrorDlg which is a child of 'parent', with the
55 // name 'name' and widget flags set to 'f'.
56 // The dialog will by default be modeless, unless you set 'modal' to
57 // TRUE to construct a modal dialog.
58 //=================================================================================
59 TransformationGUI_MirrorDlg::TransformationGUI_MirrorDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
60 const char* name, bool modal, WFlags fl)
61 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
62 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
64 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_POINT")));
65 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_AXE")));
66 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_PLANE")));
67 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
69 setCaption(tr("GEOM_MIRROR_TITLE"));
71 /***************************************************************/
72 GroupConstructors->setTitle(tr("GEOM_MIRROR"));
73 RadioButton1->setPixmap(image0);
74 RadioButton2->setPixmap(image1);
75 RadioButton3->setPixmap(image2);
77 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
78 GroupPoints->SpinBox_DX->hide();
79 GroupPoints->TextLabel3->hide();
80 GroupPoints->CheckButton2->hide();
81 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
82 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
83 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
84 GroupPoints->TextLabel2->setFixedWidth(74);
85 GroupPoints->PushButton1->setPixmap(image3);
86 GroupPoints->PushButton2->setPixmap(image3);
87 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
88 Layout1->addWidget(GroupPoints, 2, 0);
89 /***************************************************************/
91 setHelpFileName("mirror_operation_page.html");
97 //=================================================================================
98 // function : ~TransformationGUI_MirrorDlg()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 TransformationGUI_MirrorDlg::~TransformationGUI_MirrorDlg()
103 /* no need to delete child widgets, Qt does it all for us */
107 //=================================================================================
110 //=================================================================================
111 void TransformationGUI_MirrorDlg::Init()
114 myEditCurrentArgument = GroupPoints->LineEdit1;
115 GroupPoints->LineEdit1->setReadOnly(true);
116 GroupPoints->LineEdit2->setReadOnly(true);
118 myArgument = GEOM::GEOM_Object::_nil();
120 // Activate Create a Copy mode
121 GroupPoints->CheckButton1->setChecked(true);
122 CreateCopyModeChanged(true);
124 /* signals and slots connections */
125 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
126 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
127 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
129 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
130 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
133 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
135 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
137 connect(myGeomGUI->getApp()->selectionMgr(),
138 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
140 initName( tr( "GEOM_MIRROR" ) );
141 ConstructorsClicked( 0 );
145 //=================================================================================
146 // function : ConstructorsClicked()
147 // purpose : Radio button management
148 //=================================================================================
149 void TransformationGUI_MirrorDlg::ConstructorsClicked(int constructorId)
151 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
154 myEditCurrentArgument = GroupPoints->LineEdit1;
155 GroupPoints->LineEdit2->clear();
156 myArgument = GEOM::GEOM_Object::_nil();
158 switch (constructorId)
160 case 0: /* mirror an object by point */
162 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
165 case 1: /* mirror an object by axe */
167 GroupPoints->TextLabel2->setText(tr("GEOM_AXE_MIRROR"));
170 case 2: /* mirror an object by plane */
172 GroupPoints->TextLabel2->setText(tr("GEOM_PLANE_MIRROR"));
176 connect(myGeomGUI->getApp()->selectionMgr(),
177 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
182 //=================================================================================
183 // function : ClickOnOk()
185 //=================================================================================
186 void TransformationGUI_MirrorDlg::ClickOnOk()
188 if ( ClickOnApply() )
193 //=================================================================================
194 // function : ClickOnApply()
196 //=================================================================================
197 bool TransformationGUI_MirrorDlg::ClickOnApply()
199 if ( !onAccept(GroupPoints->CheckButton1->isChecked()) )
203 ConstructorsClicked( getConstructorId() );
208 //=================================================================================
209 // function : SelectionIntoArgument()
210 // purpose : Called when selection has changed
211 //=================================================================================
212 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
214 myEditCurrentArgument->setText("");
217 if(myEditCurrentArgument == GroupPoints->LineEdit1)
219 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
225 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
226 if (!myObjects.length())
229 aName = tr("%1_objects").arg(aNbSel);
231 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
233 if(IObjectCount() != 1)
235 myArgument = GEOM::GEOM_Object::_nil();
238 Standard_Boolean testResult = Standard_False;
239 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
240 myArgument = aSelectedObject;
241 if(!testResult || CORBA::is_nil( myArgument ))
244 aName = GEOMBase::GetName( aSelectedObject );
246 if ( testResult && !aSelectedObject->_is_nil() )
249 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
251 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
252 if (getConstructorId() == 1)
253 aNeedType = TopAbs_EDGE;
254 else if (getConstructorId() == 2)
255 aNeedType = TopAbs_FACE;
257 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
258 TColStd_IndexedMapOfInteger aMap;
259 aSelMgr->GetIndexes( firstIObject(), aMap );
260 if ( aMap.Extent() == 1 )
262 int anIndex = aMap( 1 );
263 if (aNeedType == TopAbs_VERTEX)
264 aName += QString(":vertex_%1").arg(anIndex);
266 aName += QString(":edge_%1").arg(anIndex);
268 //Find SubShape Object in Father
269 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
271 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
272 GEOM::GEOM_IShapesOperations_var aShapesOp =
273 getGeomEngine()->GetIShapesOperations( getStudyId() );
274 myArgument = aShapesOp->GetSubShape(aSelectedObject, anIndex);
277 myArgument = aFindedObject; // get Object from study
280 if (aShape.ShapeType() != aNeedType) {
281 myArgument = GEOM::GEOM_Object::_nil();
288 myEditCurrentArgument->setText( aName );
294 //=================================================================================
295 // function : LineEditReturnPressed()
297 //=================================================================================
298 void TransformationGUI_MirrorDlg::LineEditReturnPressed()
300 QLineEdit* send = (QLineEdit*)sender();
301 if(send == GroupPoints->LineEdit1 ||
302 send == GroupPoints->LineEdit2)
304 myEditCurrentArgument = send;
305 GEOMBase_Skeleton::LineEditReturnPressed();
310 //=================================================================================
311 // function : SetEditCurrentArgument()
313 //=================================================================================
314 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
316 QPushButton* send = (QPushButton*)sender();
319 if(send == GroupPoints->PushButton1){
320 myEditCurrentArgument = GroupPoints->LineEdit1;
322 else if(send == GroupPoints->PushButton2) {
323 myEditCurrentArgument = GroupPoints->LineEdit2;
324 switch(getConstructorId())
328 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
333 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
338 globalSelection( GEOM_PLANE );
344 myEditCurrentArgument->setFocus();
345 SelectionIntoArgument();
349 //=================================================================================
350 // function : ActivateThisDialog()
352 //=================================================================================
353 void TransformationGUI_MirrorDlg::ActivateThisDialog()
355 GEOMBase_Skeleton::ActivateThisDialog();
356 connect(myGeomGUI->getApp()->selectionMgr(),
357 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
358 ConstructorsClicked( getConstructorId() );
362 //=================================================================================
363 // function : enterEvent()
364 // purpose : when mouse enter onto the QWidget
365 //=================================================================================
366 void TransformationGUI_MirrorDlg::enterEvent(QEvent * e)
368 if(!GroupConstructors->isEnabled())
369 ActivateThisDialog();
373 //=================================================================================
374 // function : createOperation
376 //=================================================================================
377 GEOM::GEOM_IOperations_ptr TransformationGUI_MirrorDlg::createOperation()
379 return getGeomEngine()->GetITransformOperations( getStudyId() );
383 //=================================================================================
384 // function : isValid
386 //=================================================================================
387 bool TransformationGUI_MirrorDlg::isValid( QString& msg )
389 return !(myObjects.length() == 0 || myArgument->_is_nil());
393 //=================================================================================
394 // function : execute
396 //=================================================================================
397 bool TransformationGUI_MirrorDlg::execute( ObjectList& objects )
400 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
402 GEOM::GEOM_Object_var anObj;
404 switch ( getConstructorId() )
409 for (int i = 0; i < myObjects.length(); i++)
411 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPointCopy( myObjects[i], myArgument );
412 if ( !anObj->_is_nil() )
413 objects.push_back( anObj._retn() );
416 for (int i = 0; i < myObjects.length(); i++)
418 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPoint( myObjects[i], myArgument );
419 if ( !anObj->_is_nil() )
420 objects.push_back( anObj._retn() );
428 for (int i = 0; i < myObjects.length(); i++)
430 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorAxisCopy( myObjects[i], myArgument );
431 if ( !anObj->_is_nil() )
432 objects.push_back( anObj._retn() );
435 for (int i = 0; i < myObjects.length(); i++)
437 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorAxis( myObjects[i], myArgument );
438 if ( !anObj->_is_nil() )
439 objects.push_back( anObj._retn() );
447 for (int i = 0; i < myObjects.length(); i++)
449 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPlaneCopy( myObjects[i], myArgument );
450 if ( !anObj->_is_nil() )
451 objects.push_back( anObj._retn() );
454 for (int i = 0; i < myObjects.length(); i++)
456 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->MirrorPlane( myObjects[i], myArgument );
457 if ( !anObj->_is_nil() )
458 objects.push_back( anObj._retn() );
468 //=================================================================================
469 // function : closeEvent
471 //=================================================================================
472 void TransformationGUI_MirrorDlg::closeEvent( QCloseEvent* e )
474 GEOMBase_Skeleton::closeEvent( e );
478 //=================================================================================
479 // function : CreateCopyModeChanged()
481 //=================================================================================
482 void TransformationGUI_MirrorDlg::CreateCopyModeChanged(bool isCreateCopy)
484 this->GroupBoxName->setEnabled(isCreateCopy);
487 //=================================================================================
488 // function : addSubshapeToStudy
489 // purpose : virtual method to add new SubObjects if local selection
490 //=================================================================================
491 void TransformationGUI_MirrorDlg::addSubshapesToStudy()
493 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
495 QMap<QString, GEOM::GEOM_Object_var> objMap;
497 switch (getConstructorId())
500 objMap[GroupPoints->LineEdit2->text()] = myArgument;
503 objMap[GroupPoints->LineEdit2->text()] = myArgument;
508 addSubshapesToFather( objMap );