1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // GEOM GEOMGUI : GUI for Geometry component
21 // File : OperationGUI_GetShapesOnShapeDlg.cxx
22 // Author : Sergey KUUL, Open CASCADE S.A.S. (sergey.kuul@opencascade.com)
24 #include "OperationGUI_GetShapesOnShapeDlg.h"
27 #include <GeometryGUI.h>
30 #include <SUIT_Session.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
35 //==============================================================================
36 // class : OperationGUI_GetShapesOnShapeDlg()
37 // purpose : Constructs a OperationGUI_GetShapesOnShapeDlg which is a child of
38 // 'parent', with the name 'name' and widget flags set to 'f'.
39 // The dialog will by default be modeless, unless you set 'modal' to
40 // TRUE to construct a modal dialog.
41 //=================================================================================
42 OperationGUI_GetShapesOnShapeDlg::OperationGUI_GetShapesOnShapeDlg (GeometryGUI* theGeometryGUI,
44 : GEOMBase_Skeleton(theGeometryGUI, parent, false)
46 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
47 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_SHAPES_ON_SHAPE")));
48 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
50 setWindowTitle(tr("GEOM_SHAPES_ON_SHAPE_TITLE"));
52 /***************************************************************/
53 mainFrame()->GroupConstructors->setTitle(tr("GEOM_SHAPES_ON_SHAPE"));
54 mainFrame()->RadioButton1->setIcon(image0);
55 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
56 mainFrame()->RadioButton2->close();
57 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
58 mainFrame()->RadioButton3->close();
60 GroupPoints = new DlgRef_2Sel2List(centralWidget());
61 //GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
62 GroupPoints->GroupBox1->setTitle("Input data");
63 GroupPoints->TextLabel1->setText(tr("GEOM_SHAPES_ON_SHAPE_ESHAPE"));
64 GroupPoints->TextLabel2->setText(tr("GEOM_SHAPES_ON_SHAPE_CSHAPE"));
65 GroupPoints->TextLabel3->setText(tr("GEOM_RECONSTRUCTION_LIMIT"));
66 GroupPoints->TextLabel4->setText(tr("GEOM_SHAPES_ON_SHAPE_STATE"));
67 GroupPoints->PushButton1->setIcon(image2);
68 GroupPoints->PushButton2->setIcon(image2);
69 GroupPoints->LineEdit1->setReadOnly(true);
70 GroupPoints->LineEdit2->setReadOnly(true);
72 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
73 layout->setMargin(0); layout->setSpacing(6);
74 layout->addWidget(GroupPoints);
75 /***************************************************************/
77 setHelpFileName("shapesonshape_page.html");
82 //=================================================================================
83 // function : ~OperationGUI_GetShapesOnShapeDlg
84 // purpose : Destroys the object and frees any allocated resources
85 //=================================================================================
86 OperationGUI_GetShapesOnShapeDlg::~OperationGUI_GetShapesOnShapeDlg()
90 //=================================================================================
93 //=================================================================================
94 void OperationGUI_GetShapesOnShapeDlg::Init()
96 // type for sub shape selection
97 GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_SOLID"));
98 // commented by skl for IPAL19949 - finder isn't allowed such type
99 //GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_SHELL"));
100 GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_FACE"));
101 // commented by skl for IPAL19949 - finder isn't allowed such type
102 //GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_WIRE"));
103 GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_EDGE"));
104 GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_VERTEX"));
106 // type for state selection
107 GroupPoints->ComboBox2->addItem(tr("GEOM_STATE_IN"));
108 GroupPoints->ComboBox2->addItem(tr("GEOM_STATE_OUT"));
109 GroupPoints->ComboBox2->addItem(tr("GEOM_STATE_ON"));
110 GroupPoints->ComboBox2->addItem(tr("GEOM_STATE_ONIN"));
111 GroupPoints->ComboBox2->addItem(tr("GEOM_STATE_ONOUT"));
113 GroupPoints->LineEdit1->clear();
114 GroupPoints->LineEdit2->clear();
115 myObject1 = myObject2 = GEOM::GEOM_Object::_nil();
117 // signals and slots connections
118 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
119 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
121 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
122 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
124 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
125 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
127 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
128 connect(GroupPoints->ComboBox2, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
130 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
131 this, SLOT(SelectionIntoArgument()));
133 initName(mainFrame()->GroupConstructors->title());
135 GroupPoints->TextLabel3->show();
136 GroupPoints->ComboBox1->show();
137 GroupPoints->ComboBox1->setCurrentIndex(0);
138 GroupPoints->ComboBox2->show();
139 GroupPoints->ComboBox2->setCurrentIndex(0);
141 globalSelection(GEOM_ALLSHAPES);
143 GroupPoints->PushButton1->click();
144 SelectionIntoArgument();
148 //=================================================================================
149 // function : ClickOnOk()
151 //=================================================================================
152 void OperationGUI_GetShapesOnShapeDlg::ClickOnOk()
158 //=================================================================================
159 // function : ClickOnApply()
161 //=================================================================================
162 bool OperationGUI_GetShapesOnShapeDlg::ClickOnApply()
168 // activate first line edit
169 GroupPoints->PushButton1->click();
173 //=================================================================================
174 // function : SelectionIntoArgument()
175 // purpose : Called when selection is changed or on dialog initialization or activation
176 //=================================================================================
177 void OperationGUI_GetShapesOnShapeDlg::SelectionIntoArgument()
179 myEditCurrentArgument->setText("");
181 if (myEditCurrentArgument == GroupPoints->LineEdit1) myObject1 = GEOM::GEOM_Object::_nil();
182 else if (myEditCurrentArgument == GroupPoints->LineEdit2) myObject2 = GEOM::GEOM_Object::_nil();
184 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
185 SALOME_ListIO aSelList;
186 aSelMgr->selectedObjects(aSelList);
189 int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName, true);
192 Standard_Boolean aRes = Standard_False;
193 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aRes);
194 if (!CORBA::is_nil(aSelectedObject) && aRes && GEOMBase::IsShape(aSelectedObject)) {
195 myEditCurrentArgument->setText(aName);
198 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
199 myGeomGUI->getApp()->selectionMgr()->clearSelected();
200 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
201 this, SLOT(SelectionIntoArgument()));
203 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
204 myObject1 = aSelectedObject;
205 if (myObject2->_is_nil())
206 GroupPoints->PushButton2->click();
208 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
209 myObject2 = aSelectedObject;
210 if (myObject1->_is_nil())
211 GroupPoints->PushButton1->click();
217 //=================================================================================
218 // function : SetEditCurrentArgument()
220 //=================================================================================
221 void OperationGUI_GetShapesOnShapeDlg::SetEditCurrentArgument()
223 QPushButton* send = (QPushButton*)sender();
225 if (send == GroupPoints->PushButton1) {
226 myEditCurrentArgument = GroupPoints->LineEdit1;
228 GroupPoints->PushButton2->setDown(false);
229 GroupPoints->LineEdit2->setEnabled(false);
231 else if (send == GroupPoints->PushButton2) {
232 myEditCurrentArgument = GroupPoints->LineEdit2;
234 GroupPoints->PushButton1->setDown(false);
235 GroupPoints->LineEdit1->setEnabled(false);
239 myEditCurrentArgument->setEnabled(true);
240 myEditCurrentArgument->setFocus();
241 // after setFocus(), because it will be setDown(false) when loses focus
245 //=================================================================================
246 // function : LineEditReturnPressed()
248 //=================================================================================
249 void OperationGUI_GetShapesOnShapeDlg::LineEditReturnPressed()
251 QLineEdit* send = (QLineEdit*)sender();
252 if (send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2)
254 myEditCurrentArgument = send;
255 GEOMBase_Skeleton::LineEditReturnPressed();
259 //=================================================================================
260 // function : ActivateThisDialog()
262 //=================================================================================
263 void OperationGUI_GetShapesOnShapeDlg::ActivateThisDialog()
265 GEOMBase_Skeleton::ActivateThisDialog();
266 globalSelection(GEOM_ALLSHAPES);
267 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
268 this, SLOT( SelectionIntoArgument() ) );
271 //=================================================================================
272 // function : enterEvent()
273 // purpose : when mouse enter onto the QWidget
274 //=================================================================================
275 void OperationGUI_GetShapesOnShapeDlg::enterEvent (QEvent*)
277 if (!mainFrame()->GroupConstructors->isEnabled())
278 ActivateThisDialog();
281 //=================================================================================
282 // function : createOperation
284 //=================================================================================
285 GEOM::GEOM_IOperations_ptr OperationGUI_GetShapesOnShapeDlg::createOperation()
287 return getGeomEngine()->GetIShapesOperations(getStudyId());
290 //=================================================================================
291 // function : isValid
293 //=================================================================================
294 bool OperationGUI_GetShapesOnShapeDlg::isValid(QString&)
296 //Handle(SALOME_InteractiveObject) IO = firstIObject();
297 //Standard_Boolean testResult;
298 //GEOM::GEOM_Object_var anObject = GEOMBase::ConvertIOinGEOMObject(IO, testResult);
299 //if (!testResult || anObject->_is_nil())
302 return !CORBA::is_nil(myObject1) && !CORBA::is_nil(myObject2);
305 //=================================================================================
306 // function : execute
308 //=================================================================================
309 bool OperationGUI_GetShapesOnShapeDlg::execute (ObjectList& objects)
311 int aLimit = GroupPoints->ComboBox1->currentIndex();
314 case 0: aLimit = GEOM::SOLID ; break;
315 case 1: aLimit = GEOM::FACE ; break;
316 case 2: aLimit = GEOM::EDGE ; break;
317 case 3: aLimit = GEOM::VERTEX; break;
318 default: aLimit = GEOM::SHAPE ; break;
321 GEOM::shape_state aState;
322 switch (GroupPoints->ComboBox2->currentIndex())
324 case 0: aState = GEOM::ST_IN; break;
325 case 1: aState = GEOM::ST_OUT; break;
326 case 2: aState = GEOM::ST_ON; break;
327 case 3: aState = GEOM::ST_ONIN; break;
328 case 4: aState = GEOM::ST_ONOUT; break;
332 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
333 GEOM::GEOM_Object_var anObj = anOper->GetShapesOnShapeAsCompound(myObject2, myObject1,
334 (CORBA::Short) aLimit,
337 if (!anObj->_is_nil())
338 objects.push_back(anObj._retn());
340 return objects.size();
343 //=======================================================================
344 //function : ComboTextChanged
346 //=======================================================================
347 void OperationGUI_GetShapesOnShapeDlg::ComboTextChanged()
349 // VRS ???? What is it for ??? commented for a while...
350 //bool IsEnabled = GroupPoints->ComboBox1->currentIndex() < 3;