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 GroupBoxPublish->show();
126 /* signals and slots connections */
127 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
128 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
129 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
131 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
134 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
135 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
137 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
139 connect(myGeomGUI->getApp()->selectionMgr(),
140 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
142 initName( tr( "GEOM_MIRROR" ) );
143 ConstructorsClicked( 0 );
147 //=================================================================================
148 // function : ConstructorsClicked()
149 // purpose : Radio button management
150 //=================================================================================
151 void TransformationGUI_MirrorDlg::ConstructorsClicked(int constructorId)
153 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
156 myEditCurrentArgument = GroupPoints->LineEdit1;
157 GroupPoints->LineEdit2->clear();
158 myArgument = GEOM::GEOM_Object::_nil();
160 switch (constructorId)
162 case 0: /* mirror an object by point */
164 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
167 case 1: /* mirror an object by axe */
169 GroupPoints->TextLabel2->setText(tr("GEOM_AXE_MIRROR"));
172 case 2: /* mirror an object by plane */
174 GroupPoints->TextLabel2->setText(tr("GEOM_PLANE_MIRROR"));
178 connect(myGeomGUI->getApp()->selectionMgr(),
179 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
184 //=================================================================================
185 // function : ClickOnOk()
187 //=================================================================================
188 void TransformationGUI_MirrorDlg::ClickOnOk()
190 if ( ClickOnApply() )
195 //=================================================================================
196 // function : ClickOnApply()
198 //=================================================================================
199 bool TransformationGUI_MirrorDlg::ClickOnApply()
201 if ( !onAccept(GroupPoints->CheckButton1->isChecked()) )
205 ConstructorsClicked( getConstructorId() );
210 //=================================================================================
211 // function : SelectionIntoArgument()
212 // purpose : Called when selection has changed
213 //=================================================================================
214 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
216 myEditCurrentArgument->setText("");
219 if(myEditCurrentArgument == GroupPoints->LineEdit1)
221 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
227 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
228 if (!myObjects.length())
231 aName = tr("%1_objects").arg(aNbSel);
233 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
235 if(IObjectCount() != 1)
237 myArgument = GEOM::GEOM_Object::_nil();
240 Standard_Boolean testResult = Standard_False;
241 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
242 myArgument = aSelectedObject;
243 if(!testResult || CORBA::is_nil( myArgument ))
246 aName = GEOMBase::GetName( aSelectedObject );
248 if ( testResult && !aSelectedObject->_is_nil() )
251 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
253 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
254 if (getConstructorId() == 1)
255 aNeedType = TopAbs_EDGE;
256 else if (getConstructorId() == 2)
257 aNeedType = TopAbs_FACE;
259 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
260 TColStd_IndexedMapOfInteger aMap;
261 aSelMgr->GetIndexes( firstIObject(), aMap );
262 if ( aMap.Extent() == 1 )
264 int anIndex = aMap( 1 );
265 if (aNeedType == TopAbs_VERTEX)
266 aName += QString(":vertex_%1").arg(anIndex);
268 aName += QString(":edge_%1").arg(anIndex);
270 //Find SubShape Object in Father
271 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
273 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
274 GEOM::GEOM_IShapesOperations_var aShapesOp =
275 getGeomEngine()->GetIShapesOperations( getStudyId() );
276 myArgument = aShapesOp->GetSubShape(aSelectedObject, anIndex);
279 myArgument = aFindedObject; // get Object from study
282 if (aShape.ShapeType() != aNeedType) {
283 myArgument = GEOM::GEOM_Object::_nil();
290 myEditCurrentArgument->setText( aName );
296 //=================================================================================
297 // function : LineEditReturnPressed()
299 //=================================================================================
300 void TransformationGUI_MirrorDlg::LineEditReturnPressed()
302 QLineEdit* send = (QLineEdit*)sender();
303 if(send == GroupPoints->LineEdit1 ||
304 send == GroupPoints->LineEdit2)
306 myEditCurrentArgument = send;
307 GEOMBase_Skeleton::LineEditReturnPressed();
312 //=================================================================================
313 // function : SetEditCurrentArgument()
315 //=================================================================================
316 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
318 QPushButton* send = (QPushButton*)sender();
321 if(send == GroupPoints->PushButton1){
322 myEditCurrentArgument = GroupPoints->LineEdit1;
324 else if(send == GroupPoints->PushButton2) {
325 myEditCurrentArgument = GroupPoints->LineEdit2;
326 switch(getConstructorId())
330 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
335 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
340 globalSelection( GEOM_PLANE );
346 myEditCurrentArgument->setFocus();
347 SelectionIntoArgument();
351 //=================================================================================
352 // function : ActivateThisDialog()
354 //=================================================================================
355 void TransformationGUI_MirrorDlg::ActivateThisDialog()
357 GEOMBase_Skeleton::ActivateThisDialog();
358 connect(myGeomGUI->getApp()->selectionMgr(),
359 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
360 ConstructorsClicked( getConstructorId() );
364 //=================================================================================
365 // function : enterEvent()
366 // purpose : when mouse enter onto the QWidget
367 //=================================================================================
368 void TransformationGUI_MirrorDlg::enterEvent(QEvent * e)
370 if(!GroupConstructors->isEnabled())
371 ActivateThisDialog();
375 //=================================================================================
376 // function : createOperation
378 //=================================================================================
379 GEOM::GEOM_IOperations_ptr TransformationGUI_MirrorDlg::createOperation()
381 return getGeomEngine()->GetITransformOperations( getStudyId() );
385 //=================================================================================
386 // function : isValid
388 //=================================================================================
389 bool TransformationGUI_MirrorDlg::isValid( QString& msg )
391 return !(myObjects.length() == 0 || myArgument->_is_nil());
395 //=================================================================================
396 // function : execute
398 //=================================================================================
399 bool TransformationGUI_MirrorDlg::execute( ObjectList& objects )
402 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
404 GEOM::GEOM_Object_var anObj;
406 switch ( getConstructorId() )
411 for (int i = 0; i < myObjects.length(); i++)
413 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
414 MirrorPointCopy( myObjects[i], myArgument );
415 if ( !anObj->_is_nil() )
416 objects.push_back( anObj._retn() );
419 for (int i = 0; i < myObjects.length(); i++)
421 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
422 MirrorPoint( myObjects[i], myArgument );
423 if ( !anObj->_is_nil() )
424 objects.push_back( anObj._retn() );
432 for (int i = 0; i < myObjects.length(); i++)
434 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
435 MirrorAxisCopy( myObjects[i], myArgument );
436 if ( !anObj->_is_nil() )
437 objects.push_back( anObj._retn() );
440 for (int i = 0; i < myObjects.length(); i++)
442 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
443 MirrorAxis( myObjects[i], myArgument );
444 if ( !anObj->_is_nil() )
445 objects.push_back( anObj._retn() );
453 for (int i = 0; i < myObjects.length(); i++)
455 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
456 MirrorPlaneCopy( myObjects[i], myArgument );
457 if ( !anObj->_is_nil() )
458 objects.push_back( anObj._retn() );
461 for (int i = 0; i < myObjects.length(); i++)
463 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
464 MirrorPlane( myObjects[i], myArgument );
465 if ( !anObj->_is_nil() )
466 objects.push_back( anObj._retn() );
476 //=================================================================================
477 // function : restoreSubShapes
479 //=================================================================================
480 void TransformationGUI_MirrorDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
481 SALOMEDS::SObject_ptr theSObject)
483 if (CheckBoxRestoreSS->isChecked()) {
484 // empty list of arguments means that all arguments should be restored
485 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
486 /*theFindMethod=*/GEOM::FSM_Transformed,
487 /*theInheritFirstArg=*/true);
491 //=================================================================================
492 // function : CreateCopyModeChanged()
494 //=================================================================================
495 void TransformationGUI_MirrorDlg::CreateCopyModeChanged(bool isCreateCopy)
497 this->GroupBoxName->setEnabled(isCreateCopy);
500 //=================================================================================
501 // function : addSubshapeToStudy
502 // purpose : virtual method to add new SubObjects if local selection
503 //=================================================================================
504 void TransformationGUI_MirrorDlg::addSubshapesToStudy()
506 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
508 QMap<QString, GEOM::GEOM_Object_var> objMap;
510 switch (getConstructorId())
513 objMap[GroupPoints->LineEdit2->text()] = myArgument;
516 objMap[GroupPoints->LineEdit2->text()] = myArgument;
521 addSubshapesToFather( objMap );