1 // Copyright (C) 2007-2010 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 : OperationGUI_GetSharedShapesDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "OperationGUI_GetSharedShapesDlg.h"
29 #include <GeometryGUI.h>
32 #include <GEOMImpl_Types.hxx>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SUIT_MessageBox.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
41 #include <TopoDS_Iterator.hxx>
42 #include <TopoDS_Shape.hxx>
44 //=================================================================================
45 // class : OperationGUI_GetSharedShapesDlg()
46 // purpose : Constructs a OperationGUI_GetSharedShapesDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 OperationGUI_GetSharedShapesDlg::OperationGUI_GetSharedShapesDlg
52 (GeometryGUI* theGeometryGUI, QWidget* parent)
53 : GEOMBase_Skeleton(theGeometryGUI, parent, false)
55 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
56 QPixmap image0(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_SHARED_SHAPES")));
57 QPixmap image2(aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
59 setWindowTitle(tr("GEOM_SHARED_SHAPES_TITLE"));
61 /***************************************************************/
62 mainFrame()->GroupConstructors->setTitle(tr("GEOM_GET_SHARED_SHAPES"));
63 mainFrame()->RadioButton1->setIcon(image0);
64 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
65 mainFrame()->RadioButton2->close();
66 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
67 mainFrame()->RadioButton3->close();
69 GroupPoints = new DlgRef_2Sel1List1Check(centralWidget());
70 GroupPoints->GroupBox1->setTitle(tr("GEOM_SHARED_SHAPES_INPUT"));
71 GroupPoints->TextLabel1->setText(tr("GEOM_SHAPES"));
72 GroupPoints->TextLabel2->hide();
73 GroupPoints->TextLabel3->setText(tr("GEOM_SUBSHAPE_TYPE"));
74 GroupPoints->PushButton1->setIcon(image2);
75 GroupPoints->PushButton2->hide();
76 GroupPoints->LineEdit1->setReadOnly(true);
77 GroupPoints->LineEdit2->hide();
78 GroupPoints->LineEdit1->setEnabled(true);
79 GroupPoints->CheckButton1->hide();
81 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
82 layout->setMargin(0); layout->setSpacing(6);
83 layout->addWidget(GroupPoints);
85 /***************************************************************/
87 setHelpFileName("shared_shapes_page.html");
92 //=================================================================================
93 // function : ~OperationGUI_GetSharedShapesDlg()
94 // purpose : Destroys the object and frees any allocated resources
95 //=================================================================================
96 OperationGUI_GetSharedShapesDlg::~OperationGUI_GetSharedShapesDlg()
98 // no need to delete child widgets, Qt does it all for us
101 //=================================================================================
104 //=================================================================================
105 void OperationGUI_GetSharedShapesDlg::Init()
107 /* type for sub shape selection */
108 GroupPoints->ComboBox1->addItem(tr("GEOM_SOLID"));
109 GroupPoints->ComboBox1->addItem(tr("GEOM_SHELL"));
110 GroupPoints->ComboBox1->addItem(tr("GEOM_FACE"));
111 GroupPoints->ComboBox1->addItem(tr("GEOM_WIRE"));
112 GroupPoints->ComboBox1->addItem(tr("GEOM_EDGE"));
113 GroupPoints->ComboBox1->addItem(tr("GEOM_VERTEX"));
115 GroupPoints->ComboBox1->setCurrentIndex(0);
117 /* signals and slots connections */
118 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
119 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
121 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
123 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
125 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
127 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
129 connect(myGeomGUI->getApp()->selectionMgr(),
130 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
132 initName(getNewObjectName());
134 ConstructorsClicked(0);
135 GroupPoints->PushButton1->click();
138 //=================================================================================
139 // function : ConstructorsClicked()
140 // purpose : Radio button management
141 //=================================================================================
142 void OperationGUI_GetSharedShapesDlg::ConstructorsClicked (int constructorId)
144 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
147 myListShapes.length(0);
149 GroupPoints->ComboBox1->setCurrentIndex(0);
150 GroupPoints->PushButton1->setDown(true);
152 myEditCurrentArgument = GroupPoints->LineEdit1;
153 GroupPoints->LineEdit1->clear();
155 qApp->processEvents();
157 resize(minimumSizeHint());
159 myEditCurrentArgument->setFocus();
160 connect(myGeomGUI->getApp()->selectionMgr(),
161 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
162 SelectionIntoArgument();
165 //=================================================================================
166 // function : ClickOnOk()
168 //=================================================================================
169 void OperationGUI_GetSharedShapesDlg::ClickOnOk()
175 //=================================================================================
176 // function : ClickOnApply()
178 //=================================================================================
179 bool OperationGUI_GetSharedShapesDlg::ClickOnApply()
184 initName(getNewObjectName());
189 //=================================================================================
190 // function : SelectionIntoArgument()
191 // purpose : Called when selection as changed or other case
192 //=================================================================================
193 void OperationGUI_GetSharedShapesDlg::SelectionIntoArgument()
195 myEditCurrentArgument->setText("");
196 QString aString = "";
198 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
199 SALOME_ListIO aSelList;
200 aSelMgr->selectedObjects(aSelList);
202 int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
205 myListShapes.length(0);
208 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListShapes, true);
209 if (!myListShapes.length())
212 myEditCurrentArgument->setText(aString);
215 //=================================================================================
216 // function : SetEditCurrentArgument()
218 //=================================================================================
219 void OperationGUI_GetSharedShapesDlg::SetEditCurrentArgument()
221 QPushButton* send = (QPushButton*)sender();
223 if (send == GroupPoints->PushButton1) {
224 myEditCurrentArgument = GroupPoints->LineEdit1;
225 GroupPoints->LineEdit1->setEnabled(true);
228 globalSelection(GEOM_ALLSHAPES);
230 myEditCurrentArgument->setFocus();
231 SelectionIntoArgument();
235 //=================================================================================
236 // function : ActivateThisDialog()
238 //=================================================================================
239 void OperationGUI_GetSharedShapesDlg::ActivateThisDialog()
241 GEOMBase_Skeleton::ActivateThisDialog();
242 connect(myGeomGUI->getApp()->selectionMgr(),
243 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
245 ConstructorsClicked(getConstructorId());
248 //=================================================================================
249 // function : enterEvent()
251 //=================================================================================
252 void OperationGUI_GetSharedShapesDlg::enterEvent(QEvent*)
254 if (!mainFrame()->GroupConstructors->isEnabled())
255 this->ActivateThisDialog();
258 //=======================================================================
259 //function : ComboTextChanged
261 //=======================================================================
262 void OperationGUI_GetSharedShapesDlg::ComboTextChanged()
264 initName(getNewObjectName());
267 //=================================================================================
268 // function : GetType()
270 //=================================================================================
271 int OperationGUI_GetSharedShapesDlg::GetType() const
273 int aLimit = GroupPoints->ComboBox1->currentIndex();
276 case 0: aLimit = GEOM::SOLID ; break;
277 case 1: aLimit = GEOM::SHELL ; break;
278 case 2: aLimit = GEOM::FACE ; break;
279 case 3: aLimit = GEOM::WIRE ; break;
280 case 4: aLimit = GEOM::EDGE ; break;
281 case 5: aLimit = GEOM::VERTEX; break;
282 default: aLimit = GEOM::SHAPE ;
288 //=================================================================================
289 // function : createOperation
291 //=================================================================================
292 GEOM::GEOM_IOperations_ptr OperationGUI_GetSharedShapesDlg::createOperation()
294 return getGeomEngine()->GetIShapesOperations(getStudyId());
297 //=================================================================================
298 // function : isValid
300 //=================================================================================
301 bool OperationGUI_GetSharedShapesDlg::isValid (QString& msg)
303 if (myListShapes.length() < 2) {
304 msg = tr("MSG_SHARED_SHAPES_TOO_FEW_SHAPES");
310 //=================================================================================
311 // function : execute
313 //=================================================================================
314 bool OperationGUI_GetSharedShapesDlg::execute (ObjectList& objects)
316 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
317 GEOM::ListOfGO_var aList = anOper->GetSharedShapesMulti(myListShapes, GetType());
319 if (!aList->length())
322 for (int i = 0, n = aList->length(); i < n; i++)
323 objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
325 return objects.size();
328 //================================================================
329 // Function : getFather
330 // Purpose : Get father object for object to be added in study
331 // ( called with addInStudy method )
332 //================================================================
333 GEOM::GEOM_Object_ptr OperationGUI_GetSharedShapesDlg::getFather (GEOM::GEOM_Object_ptr)
335 if (myListShapes.length() > 0)
336 //return myListShapes[0]._retn();
337 return myListShapes[0];
341 //================================================================
342 // Function : getNewObjectName
344 //================================================================
345 QString OperationGUI_GetSharedShapesDlg::getNewObjectName() const
347 int aLimit = GroupPoints->ComboBox1->currentIndex();
348 //QString aName = tr("GEOM_SHARED_SHAPE");
352 case 0: aName = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_SOLID")) ; break;
353 case 1: aName = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_SHELL")) ; break;
354 case 2: aName = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_FACE")) ; break;
355 case 3: aName = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_WIRE")) ; break;
356 case 4: aName = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_EDGE")) ; break;
357 case 5: aName = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_VERTEX")); break;
358 default: aName = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_SHAPE")) ;