1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : TransformationGUI_MirrorDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "TransformationGUI_MirrorDlg.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Edge.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
42 #include <qcheckbox.h>
45 #include "GEOMImpl_Types.hxx"
47 #include "utilities.h"
51 //=================================================================================
52 // class : TransformationGUI_MirrorDlg()
53 // purpose : Constructs a TransformationGUI_MirrorDlg which is a child of 'parent', with the
54 // name 'name' and widget flags set to 'f'.
55 // The dialog will by default be modeless, unless you set 'modal' to
56 // TRUE to construct a modal dialog.
57 //=================================================================================
58 TransformationGUI_MirrorDlg::TransformationGUI_MirrorDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
59 const char* name, bool modal, WFlags fl)
60 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
61 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
63 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_POINT")));
64 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_AXE")));
65 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_MIRROR_PLANE")));
66 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
68 setCaption(tr("GEOM_MIRROR_TITLE"));
70 /***************************************************************/
71 GroupConstructors->setTitle(tr("GEOM_MIRROR"));
72 RadioButton1->setPixmap(image0);
73 RadioButton2->setPixmap(image1);
74 RadioButton3->setPixmap(image2);
76 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
77 GroupPoints->SpinBox_DX->hide();
78 GroupPoints->TextLabel3->hide();
79 GroupPoints->CheckButton2->hide();
80 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
81 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
82 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
83 GroupPoints->TextLabel2->setFixedWidth(74);
84 GroupPoints->PushButton1->setPixmap(image3);
85 GroupPoints->PushButton2->setPixmap(image3);
86 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
87 Layout1->addWidget(GroupPoints, 2, 0);
88 /***************************************************************/
90 setHelpFileName("mirror_operation_page.html");
96 //=================================================================================
97 // function : ~TransformationGUI_MirrorDlg()
98 // purpose : Destroys the object and frees any allocated resources
99 //=================================================================================
100 TransformationGUI_MirrorDlg::~TransformationGUI_MirrorDlg()
102 /* no need to delete child widgets, Qt does it all for us */
106 //=================================================================================
109 //=================================================================================
110 void TransformationGUI_MirrorDlg::Init()
113 myEditCurrentArgument = GroupPoints->LineEdit1;
114 GroupPoints->LineEdit1->setReadOnly(true);
115 GroupPoints->LineEdit2->setReadOnly(true);
117 myArgument = GEOM::GEOM_Object::_nil();
119 // Activate Create a Copy mode
120 GroupPoints->CheckButton1->setChecked(true);
121 CreateCopyModeChanged(true);
123 GroupBoxPublish->show();
125 /* signals and slots connections */
126 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
127 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
128 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
130 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
138 connect(myGeomGUI->getApp()->selectionMgr(),
139 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
141 initName( tr( "GEOM_MIRROR" ) );
142 ConstructorsClicked( 0 );
146 //=================================================================================
147 // function : ConstructorsClicked()
148 // purpose : Radio button management
149 //=================================================================================
150 void TransformationGUI_MirrorDlg::ConstructorsClicked(int constructorId)
152 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
155 myEditCurrentArgument = GroupPoints->LineEdit1;
156 GroupPoints->LineEdit2->clear();
157 myArgument = GEOM::GEOM_Object::_nil();
159 switch (constructorId)
161 case 0: /* mirror an object by point */
163 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
166 case 1: /* mirror an object by axe */
168 GroupPoints->TextLabel2->setText(tr("GEOM_AXE_MIRROR"));
171 case 2: /* mirror an object by plane */
173 GroupPoints->TextLabel2->setText(tr("GEOM_PLANE_MIRROR"));
177 connect(myGeomGUI->getApp()->selectionMgr(),
178 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
183 //=================================================================================
184 // function : ClickOnOk()
186 //=================================================================================
187 void TransformationGUI_MirrorDlg::ClickOnOk()
189 if ( ClickOnApply() )
194 //=================================================================================
195 // function : ClickOnApply()
197 //=================================================================================
198 bool TransformationGUI_MirrorDlg::ClickOnApply()
200 if ( !onAccept(GroupPoints->CheckButton1->isChecked()) )
204 ConstructorsClicked( getConstructorId() );
209 //=================================================================================
210 // function : SelectionIntoArgument()
211 // purpose : Called when selection has changed
212 //=================================================================================
213 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
215 myEditCurrentArgument->setText("");
218 if(myEditCurrentArgument == GroupPoints->LineEdit1)
220 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
226 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
227 if (!myObjects.length())
230 aName = tr("%1_objects").arg(aNbSel);
232 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
234 if(IObjectCount() != 1)
236 myArgument = GEOM::GEOM_Object::_nil();
239 Standard_Boolean testResult = Standard_False;
240 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
241 myArgument = aSelectedObject;
242 if(!testResult || CORBA::is_nil( myArgument ))
245 aName = GEOMBase::GetName( aSelectedObject );
247 if ( testResult && !aSelectedObject->_is_nil() )
250 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
252 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
253 if (getConstructorId() == 1)
254 aNeedType = TopAbs_EDGE;
255 else if (getConstructorId() == 2)
256 aNeedType = TopAbs_FACE;
258 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
259 TColStd_IndexedMapOfInteger aMap;
260 aSelMgr->GetIndexes( firstIObject(), aMap );
261 if ( aMap.Extent() == 1 )
263 int anIndex = aMap( 1 );
264 if (aNeedType == TopAbs_VERTEX)
265 aName += QString(":vertex_%1").arg(anIndex);
267 aName += QString(":edge_%1").arg(anIndex);
269 //Find SubShape Object in Father
270 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
272 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
273 GEOM::GEOM_IShapesOperations_var aShapesOp =
274 getGeomEngine()->GetIShapesOperations( getStudyId() );
275 myArgument = aShapesOp->GetSubShape(aSelectedObject, anIndex);
278 myArgument = aFindedObject; // get Object from study
281 if (aShape.ShapeType() != aNeedType) {
282 myArgument = GEOM::GEOM_Object::_nil();
289 myEditCurrentArgument->setText( aName );
295 //=================================================================================
296 // function : LineEditReturnPressed()
298 //=================================================================================
299 void TransformationGUI_MirrorDlg::LineEditReturnPressed()
301 QLineEdit* send = (QLineEdit*)sender();
302 if(send == GroupPoints->LineEdit1 ||
303 send == GroupPoints->LineEdit2)
305 myEditCurrentArgument = send;
306 GEOMBase_Skeleton::LineEditReturnPressed();
311 //=================================================================================
312 // function : SetEditCurrentArgument()
314 //=================================================================================
315 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
317 QPushButton* send = (QPushButton*)sender();
320 if(send == GroupPoints->PushButton1){
321 myEditCurrentArgument = GroupPoints->LineEdit1;
323 else if(send == GroupPoints->PushButton2) {
324 myEditCurrentArgument = GroupPoints->LineEdit2;
325 switch(getConstructorId())
329 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
334 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
339 globalSelection( GEOM_PLANE );
345 myEditCurrentArgument->setFocus();
346 SelectionIntoArgument();
350 //=================================================================================
351 // function : ActivateThisDialog()
353 //=================================================================================
354 void TransformationGUI_MirrorDlg::ActivateThisDialog()
356 GEOMBase_Skeleton::ActivateThisDialog();
357 connect(myGeomGUI->getApp()->selectionMgr(),
358 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
359 ConstructorsClicked( getConstructorId() );
363 //=================================================================================
364 // function : enterEvent()
365 // purpose : when mouse enter onto the QWidget
366 //=================================================================================
367 void TransformationGUI_MirrorDlg::enterEvent(QEvent * e)
369 if(!GroupConstructors->isEnabled())
370 ActivateThisDialog();
374 //=================================================================================
375 // function : createOperation
377 //=================================================================================
378 GEOM::GEOM_IOperations_ptr TransformationGUI_MirrorDlg::createOperation()
380 return getGeomEngine()->GetITransformOperations( getStudyId() );
384 //=================================================================================
385 // function : isValid
387 //=================================================================================
388 bool TransformationGUI_MirrorDlg::isValid( QString& msg )
390 return !(myObjects.length() == 0 || myArgument->_is_nil());
394 //=================================================================================
395 // function : execute
397 //=================================================================================
398 bool TransformationGUI_MirrorDlg::execute( ObjectList& objects )
401 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
403 GEOM::GEOM_Object_var anObj;
405 switch ( getConstructorId() )
410 for (int i = 0; i < myObjects.length(); i++)
412 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
413 MirrorPointCopy( myObjects[i], myArgument );
414 if ( !anObj->_is_nil() )
415 objects.push_back( anObj._retn() );
418 for (int i = 0; i < myObjects.length(); i++)
420 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
421 MirrorPoint( myObjects[i], myArgument );
422 if ( !anObj->_is_nil() )
423 objects.push_back( anObj._retn() );
431 for (int i = 0; i < myObjects.length(); i++)
433 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
434 MirrorAxisCopy( myObjects[i], myArgument );
435 if ( !anObj->_is_nil() )
436 objects.push_back( anObj._retn() );
439 for (int i = 0; i < myObjects.length(); i++)
441 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
442 MirrorAxis( myObjects[i], myArgument );
443 if ( !anObj->_is_nil() )
444 objects.push_back( anObj._retn() );
452 for (int i = 0; i < myObjects.length(); i++)
454 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
455 MirrorPlaneCopy( myObjects[i], myArgument );
456 if ( !anObj->_is_nil() )
457 objects.push_back( anObj._retn() );
460 for (int i = 0; i < myObjects.length(); i++)
462 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
463 MirrorPlane( myObjects[i], myArgument );
464 if ( !anObj->_is_nil() )
465 objects.push_back( anObj._retn() );
475 //=================================================================================
476 // function : restoreSubShapes
478 //=================================================================================
479 void TransformationGUI_MirrorDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
480 SALOMEDS::SObject_ptr theSObject)
482 if (CheckBoxRestoreSS->isChecked()) {
483 // empty list of arguments means that all arguments should be restored
484 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
485 /*theFindMethod=*/GEOM::FSM_Transformed,
486 /*theInheritFirstArg=*/true);
490 //=================================================================================
491 // function : CreateCopyModeChanged()
493 //=================================================================================
494 void TransformationGUI_MirrorDlg::CreateCopyModeChanged(bool isCreateCopy)
496 this->GroupBoxName->setEnabled(isCreateCopy);
499 //=================================================================================
500 // function : addSubshapeToStudy
501 // purpose : virtual method to add new SubObjects if local selection
502 //=================================================================================
503 void TransformationGUI_MirrorDlg::addSubshapesToStudy()
505 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
507 QMap<QString, GEOM::GEOM_Object_var> objMap;
509 switch (getConstructorId())
512 objMap[GroupPoints->LineEdit2->text()] = myArgument;
515 objMap[GroupPoints->LineEdit2->text()] = myArgument;
520 addSubshapesToFather( objMap );