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, Open CASCADE S.A.S.
26 #include "TransformationGUI_MirrorDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Edge.hxx>
42 #include <TColStd_IndexedMapOfInteger.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
45 #include <GEOMImpl_Types.hxx>
47 //=================================================================================
48 // class : TransformationGUI_MirrorDlg()
49 // purpose : Constructs a TransformationGUI_MirrorDlg which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 TransformationGUI_MirrorDlg::TransformationGUI_MirrorDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
55 bool modal, Qt::WindowFlags fl)
56 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
59 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
60 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MIRROR_POINT")));
61 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MIRROR_AXE")));
62 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MIRROR_PLANE")));
63 QPixmap image3 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
65 setWindowTitle(tr("GEOM_MIRROR_TITLE"));
67 /***************************************************************/
68 mainFrame()->GroupConstructors->setTitle(tr("GEOM_MIRROR"));
69 mainFrame()->RadioButton1->setIcon(image0);
70 mainFrame()->RadioButton2->setIcon(image1);
71 mainFrame()->RadioButton3->setIcon(image2);
73 GroupPoints = new DlgRef_2Sel1Spin2Check(centralWidget());
74 GroupPoints->SpinBox_DX->hide();
75 GroupPoints->TextLabel3->hide();
76 GroupPoints->CheckButton2->hide();
77 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
78 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
79 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
80 GroupPoints->TextLabel2->setFixedWidth(74);
81 GroupPoints->PushButton1->setIcon(image3);
82 GroupPoints->PushButton2->setIcon(image3);
83 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
85 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
86 layout->setMargin(0); layout->setSpacing(6);
87 layout->addWidget(GroupPoints);
88 /***************************************************************/
90 setHelpFileName("mirror_operation_page.html");
92 // Activate Create a Copy mode
93 GroupPoints->CheckButton1->setChecked(true);
94 CreateCopyModeChanged(true);
99 //=================================================================================
100 // function : ~TransformationGUI_MirrorDlg()
101 // purpose : Destroys the object and frees any allocated resources
102 //=================================================================================
103 TransformationGUI_MirrorDlg::~TransformationGUI_MirrorDlg()
105 // no need to delete child widgets, Qt does it all for us
108 //=================================================================================
111 //=================================================================================
112 void TransformationGUI_MirrorDlg::Init()
115 GroupPoints->LineEdit1->setReadOnly(true);
116 GroupPoints->LineEdit2->setReadOnly(true);
118 GroupPoints->LineEdit1->setText("");
119 GroupPoints->LineEdit2->setText("");
121 myArgument = GEOM::GEOM_Object::_nil();
123 mainFrame()->GroupBoxPublish->show();
125 // signals and slots connections
126 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
127 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
129 connect(this, SIGNAL(constructorsClicked(int)), this, 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 initName(tr("GEOM_MIRROR"));
141 ConstructorsClicked(0);
142 resize(minimumSizeHint());
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);
153 GroupPoints->LineEdit2->clear();
154 myArgument = GEOM::GEOM_Object::_nil();
156 switch (constructorId) {
157 case 0: // mirror an object by point
158 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_MIRROR"));
160 case 1: // mirror an object by axe
161 GroupPoints->TextLabel2->setText(tr("GEOM_AXE_MIRROR"));
163 case 2: // mirror an object by plane
164 GroupPoints->TextLabel2->setText(tr("GEOM_PLANE_MIRROR"));
168 GroupPoints->PushButton1->click();
172 SelectionIntoArgument();
179 //=================================================================================
180 // function : ClickOnOk()
182 //=================================================================================
183 void TransformationGUI_MirrorDlg::ClickOnOk()
189 //=================================================================================
190 // function : ClickOnApply()
192 //=================================================================================
193 bool TransformationGUI_MirrorDlg::ClickOnApply()
195 if (!onAccept(GroupPoints->CheckButton1->isChecked()))
199 // activate selection and connect selection manager
200 ConstructorsClicked(getConstructorId());
204 //=================================================================================
205 // function : SelectionIntoArgument()
206 // purpose : Called when selection is changed or on dialog initialization or activation
207 //=================================================================================
208 void TransformationGUI_MirrorDlg::SelectionIntoArgument()
211 myEditCurrentArgument->setText("");
213 if (myEditCurrentArgument == GroupPoints->LineEdit1)
215 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
216 myArgument = GEOM::GEOM_Object::_nil();
218 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
219 SALOME_ListIO aSelList;
220 aSelMgr->selectedObjects(aSelList);
224 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
225 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName);
229 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myObjects);
230 if (!myObjects.length())
233 myEditCurrentArgument->setText(aName);
235 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
236 if (aSelList.Extent() != 1)
240 Standard_Boolean testResult = Standard_False;
241 myArgument = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
242 if (!testResult || CORBA::is_nil(myArgument))
245 aName = GEOMBase::GetName(myArgument);
247 if (testResult && !myArgument->_is_nil()) {
249 if (GEOMBase::GetShape(myArgument, aShape, TopAbs_SHAPE) && !aShape.IsNull()) {
250 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
251 if (getConstructorId() == 1)
252 aNeedType = TopAbs_EDGE;
253 else if (getConstructorId() == 2)
254 aNeedType = TopAbs_FACE;
256 TColStd_IndexedMapOfInteger aMap;
257 aSelMgr->GetIndexes(aSelList.First(), aMap);
258 if (aMap.Extent() == 1) {
259 int anIndex = aMap(1);
260 if (aNeedType == TopAbs_VERTEX)
261 aName += QString(":vertex_%1").arg(anIndex);
263 aName += QString(":edge_%1").arg(anIndex);
265 //Find SubShape Object in Father
266 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(myArgument, aName);
268 if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
269 GEOM::GEOM_IShapesOperations_var aShapesOp =
270 getGeomEngine()->GetIShapesOperations(getStudyId());
271 myArgument = aShapesOp->GetSubShape(myArgument, anIndex);
274 myArgument = aFindedObject; // get Object from study
278 if (aShape.ShapeType() != aNeedType) {
279 myArgument = GEOM::GEOM_Object::_nil();
285 myEditCurrentArgument->setText(aName);
287 if (!myArgument->_is_nil() && !myObjects.length())
288 GroupPoints->PushButton1->click();
292 /* disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
293 myGeomGUI->getApp()->selectionMgr()->clearSelected();
294 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
295 this, SLOT(SelectionIntoArgument()));*/
296 // here commented, because multiple objects can be selected IPAL 21437
301 //=================================================================================
302 // function : SetEditCurrentArgument()
304 //=================================================================================
305 void TransformationGUI_MirrorDlg::SetEditCurrentArgument()
307 QPushButton* send = (QPushButton*)sender();
309 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
312 if (send == GroupPoints->PushButton1) {
313 myEditCurrentArgument = GroupPoints->LineEdit1;
315 GroupPoints->PushButton2->setDown(false);
316 GroupPoints->LineEdit2->setEnabled(false);
318 else if (send == GroupPoints->PushButton2) {
319 myEditCurrentArgument = GroupPoints->LineEdit2;
321 switch (getConstructorId()) {
323 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
326 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
329 globalSelection(GEOM_PLANE);
333 GroupPoints->PushButton1->setDown(false);
334 GroupPoints->LineEdit1->setEnabled(false);
336 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
337 this, SLOT(SelectionIntoArgument()));
340 myEditCurrentArgument->setEnabled(true);
341 myEditCurrentArgument->setFocus();
342 // after setFocus(), because it will be setDown(false) when loses focus
345 // seems we need it only to avoid preview disappearing, caused by selection mode change
349 //=================================================================================
350 // function : LineEditReturnPressed()
352 //=================================================================================
353 void TransformationGUI_MirrorDlg::LineEditReturnPressed()
355 QLineEdit* send = (QLineEdit*)sender();
356 if (send == GroupPoints->LineEdit1 ||
357 send == GroupPoints->LineEdit2) {
358 myEditCurrentArgument = send;
359 GEOMBase_Skeleton::LineEditReturnPressed();
363 //=================================================================================
364 // function : ActivateThisDialog()
366 //=================================================================================
367 void TransformationGUI_MirrorDlg::ActivateThisDialog()
369 GEOMBase_Skeleton::ActivateThisDialog();
370 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
371 this, SLOT( SelectionIntoArgument() ) );
373 ConstructorsClicked( getConstructorId() );
376 //=================================================================================
377 // function : enterEvent()
378 // purpose : when mouse enter onto the QWidget
379 //=================================================================================
380 void TransformationGUI_MirrorDlg::enterEvent (QEvent*)
382 if (!mainFrame()->GroupConstructors->isEnabled())
383 ActivateThisDialog();
386 //=================================================================================
387 // function : createOperation
389 //=================================================================================
390 GEOM::GEOM_IOperations_ptr TransformationGUI_MirrorDlg::createOperation()
392 return getGeomEngine()->GetITransformOperations(getStudyId());
395 //=================================================================================
396 // function : isValid
398 //=================================================================================
399 bool TransformationGUI_MirrorDlg::isValid (QString& /*msg*/)
401 return !(myObjects.length() == 0 || myArgument->_is_nil());
404 //=================================================================================
405 // function : execute
407 //=================================================================================
408 bool TransformationGUI_MirrorDlg::execute (ObjectList& objects)
411 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
413 GEOM::GEOM_Object_var anObj;
415 GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
417 switch (getConstructorId()) {
421 for (int i = 0; i < myObjects.length(); i++) {
422 anObj = anOper->MirrorPointCopy(myObjects[i], myArgument);
423 if (!anObj->_is_nil())
424 objects.push_back(anObj._retn());
428 for (int i = 0; i < myObjects.length(); i++) {
429 anObj = anOper->MirrorPoint(myObjects[i], myArgument);
430 if (!anObj->_is_nil())
431 objects.push_back(anObj._retn());
440 for (int i = 0; i < myObjects.length(); i++) {
441 anObj = anOper->MirrorAxisCopy(myObjects[i], myArgument);
442 if (!anObj->_is_nil())
443 objects.push_back(anObj._retn());
447 for (int i = 0; i < myObjects.length(); i++) {
448 anObj = anOper->MirrorAxis(myObjects[i], myArgument);
449 if (!anObj->_is_nil())
450 objects.push_back(anObj._retn());
459 for (int i = 0; i < myObjects.length(); i++) {
460 anObj = anOper->MirrorPlaneCopy(myObjects[i], myArgument);
461 if (!anObj->_is_nil())
462 objects.push_back(anObj._retn());
466 for (int i = 0; i < myObjects.length(); i++) {
467 anObj = anOper->MirrorPlane(myObjects[i], myArgument);
468 if (!anObj->_is_nil())
469 objects.push_back(anObj._retn());
480 //=================================================================================
481 // function : restoreSubShapes
483 //=================================================================================
484 void TransformationGUI_MirrorDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
485 SALOMEDS::SObject_ptr theSObject)
487 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
488 // empty list of arguments means that all arguments should be restored
489 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
490 /*theFindMethod=*/GEOM::FSM_Transformed,
491 /*theInheritFirstArg=*/true);
495 //=================================================================================
496 // function : CreateCopyModeChanged()
498 //=================================================================================
499 void TransformationGUI_MirrorDlg::CreateCopyModeChanged (bool isCreateCopy)
501 mainFrame()->GroupBoxName->setEnabled(isCreateCopy);
504 //=================================================================================
505 // function : addSubshapeToStudy
506 // purpose : virtual method to add new SubObjects if local selection
507 //=================================================================================
508 void TransformationGUI_MirrorDlg::addSubshapesToStudy()
510 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
512 QMap<QString, GEOM::GEOM_Object_var> objMap;
514 switch (getConstructorId()) {
516 objMap[GroupPoints->LineEdit2->text()] = myArgument;
519 objMap[GroupPoints->LineEdit2->text()] = myArgument;
524 addSubshapesToFather(objMap);