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 : OperationGUI_GetShapesOnShapeDlg.cxx
25 // Author : Lucien PIGNOLONI
28 #include "OperationGUI_GetShapesOnShapeDlg.h"
30 #include "SUIT_Session.h"
31 #include "SalomeApp_Application.h"
32 #include "LightApp_SelectionMgr.h"
34 #include <qcombobox.h>
37 //using namespace std;
39 //==============================================================================
40 // class : OperationGUI_GetShapesOnShapeDlg()
41 // purpose : Constructs a OperationGUI_GetShapesOnShapeDlg which is a child of
42 // 'parent', with the name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 OperationGUI_GetShapesOnShapeDlg::OperationGUI_GetShapesOnShapeDlg(GeometryGUI* theGeometryGUI,
48 :GEOMBase_Skeleton(theGeometryGUI, parent, "OperationGUI_GetShapesOnShapeDlg", false,
49 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
52 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
53 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_SHAPES_ON_SHAPE")));
54 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
56 setCaption(tr("GEOM_SHAPES_ON_SHAPE_TITLE"));
58 GroupConstructors->setTitle(tr("GEOM_SHAPES_ON_SHAPE"));
60 RadioButton1->setPixmap(image0);
61 RadioButton2->close(TRUE);
62 RadioButton3->close(TRUE);
64 GroupPoints = new DlgRef_2Sel2List_QTD(this, "GroupPoints");
65 //GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
66 GroupPoints->GroupBox1->setTitle("Input data");
67 GroupPoints->TextLabel1->setText(tr("GEOM_SHAPES_ON_SHAPE_ESHAPE"));
68 GroupPoints->TextLabel2->setText(tr("GEOM_SHAPES_ON_SHAPE_CSHAPE"));
69 GroupPoints->TextLabel3->setText(tr("GEOM_RECONSTRUCTION_LIMIT"));
70 GroupPoints->TextLabel4->setText(tr("GEOM_SHAPES_ON_SHAPE_STATE"));
71 GroupPoints->PushButton1->setPixmap(image2);
72 GroupPoints->PushButton2->setPixmap(image2);
73 GroupPoints->LineEdit1->setReadOnly( true );
74 GroupPoints->LineEdit2->setReadOnly( true );
76 Layout1->addWidget(GroupPoints, 2, 0);
78 setHelpFileName("shapesonshape_page.html");
84 //=================================================================================
85 // function : ~OperationGUI_GetShapesOnShapeDlg
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 OperationGUI_GetShapesOnShapeDlg::~OperationGUI_GetShapesOnShapeDlg()
93 //=================================================================================
96 //=================================================================================
97 void OperationGUI_GetShapesOnShapeDlg::Init()
99 /* type for sub shape selection */
100 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SOLID"));
101 // commented by skl for IPAL19949 - finder isn't allowed such type
102 //GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SHELL"));
103 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_FACE"));
104 // commented by skl for IPAL19949 - finder isn't allowed such type
105 //GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_WIRE"));
106 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_EDGE"));
107 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_VERTEX"));
109 /* type for state selection */
110 GroupPoints->ComboBox2->insertItem(tr("GEOM_STATE_IN"));
111 GroupPoints->ComboBox2->insertItem(tr("GEOM_STATE_OUT"));
112 GroupPoints->ComboBox2->insertItem(tr("GEOM_STATE_ON"));
113 GroupPoints->ComboBox2->insertItem(tr("GEOM_STATE_ONIN"));
114 GroupPoints->ComboBox2->insertItem(tr("GEOM_STATE_ONOUT"));
116 GroupPoints->LineEdit1->clear();
117 GroupPoints->LineEdit2->clear();
119 /* signals and slots connections */
120 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
121 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
123 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
124 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
126 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
127 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
129 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
130 connect(GroupPoints->ComboBox2, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
132 connect(myGeomGUI->getApp()->selectionMgr(),
133 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
135 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
136 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
138 globalSelection( GEOM_ALLSHAPES );
140 initName( GroupConstructors->title() );
143 GroupPoints->TextLabel3->show();
144 GroupPoints->ComboBox1->show();
145 GroupPoints->ComboBox1->setCurrentItem(0);
146 GroupPoints->ComboBox2->show();
147 GroupPoints->ComboBox2->setCurrentItem(0);
149 myEditCurrentArgument = GroupPoints->LineEdit1;
150 myEditCurrentArgument->setFocus();
151 connect(myGeomGUI->getApp()->selectionMgr(),
152 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
157 //=================================================================================
158 // function : ClickOnOk()
160 //=================================================================================
161 void OperationGUI_GetShapesOnShapeDlg::ClickOnOk()
163 if ( ClickOnApply() )
168 //=================================================================================
169 // function : ClickOnApply()
171 //=================================================================================
172 bool OperationGUI_GetShapesOnShapeDlg::ClickOnApply()
182 //=================================================================================
183 // function : SelectionIntoArgument()
184 // purpose : Called when selection has changed
185 //=================================================================================
186 void OperationGUI_GetShapesOnShapeDlg::SelectionIntoArgument()
188 myEditCurrentArgument->setText( "" );
189 QString aString = "";
191 int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
194 Standard_Boolean aRes = Standard_False;
195 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
196 if ( !CORBA::is_nil( aSelectedObject ) && aRes && GEOMBase::IsShape( aSelectedObject ) ) {
198 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
199 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myObject1 = aSelectedObject;
200 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myObject2 = aSelectedObject;
205 myEditCurrentArgument->setText( aString );
209 //=================================================================================
210 // function : SetEditCurrentArgument()
212 //=================================================================================
213 void OperationGUI_GetShapesOnShapeDlg::SetEditCurrentArgument()
215 QPushButton* send = (QPushButton*)sender();
217 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
218 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
220 myEditCurrentArgument->setFocus();
221 SelectionIntoArgument();
225 //=================================================================================
226 // function : LineEditReturnPressed()
228 //=================================================================================
229 void OperationGUI_GetShapesOnShapeDlg::LineEditReturnPressed()
231 QLineEdit* send = (QLineEdit*)sender();
232 if ( send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2 )
234 myEditCurrentArgument = send;
235 GEOMBase_Skeleton::LineEditReturnPressed();
240 //=================================================================================
241 // function : ActivateThisDialog()
243 //=================================================================================
244 void OperationGUI_GetShapesOnShapeDlg::ActivateThisDialog()
246 GEOMBase_Skeleton::ActivateThisDialog();
247 globalSelection( GEOM_ALLSHAPES );
248 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
249 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
253 //=================================================================================
254 // function : enterEvent()
255 // purpose : when mouse enter onto the QWidget
256 //=================================================================================
257 void OperationGUI_GetShapesOnShapeDlg::enterEvent(QEvent * e)
259 if ( !GroupConstructors->isEnabled() )
260 ActivateThisDialog();
264 //=================================================================================
265 // function : createOperation
267 //=================================================================================
268 GEOM::GEOM_IOperations_ptr OperationGUI_GetShapesOnShapeDlg::createOperation()
270 return getGeomEngine()->GetIShapesOperations( getStudyId() );
274 //=================================================================================
275 // function : isValid
277 //=================================================================================
278 bool OperationGUI_GetShapesOnShapeDlg::isValid( QString& msg )
280 Handle(SALOME_InteractiveObject) IO = firstIObject();
281 Standard_Boolean testResult;
282 GEOM::GEOM_Object_var anObject = GEOMBase::ConvertIOinGEOMObject( IO, testResult );
283 if ( !testResult || anObject->_is_nil() )
286 return !CORBA::is_nil( myObject1 ) && !CORBA::is_nil( myObject2 );
289 //=================================================================================
290 // function : execute
292 //=================================================================================
293 bool OperationGUI_GetShapesOnShapeDlg::execute( ObjectList& objects )
295 int aLimit = GroupPoints->ComboBox1->currentItem();
298 case 0: aLimit = GEOM::SOLID ; break;
299 case 1: aLimit = GEOM::FACE ; break;
300 case 2: aLimit = GEOM::EDGE ; break;
301 case 3: aLimit = GEOM::VERTEX; break;
302 default: aLimit = GEOM::SHAPE ;
305 GEOM::shape_state aState;
306 switch (GroupPoints->ComboBox2->currentItem())
308 case 0: aState = GEOM::ST_IN; break;
309 case 1: aState = GEOM::ST_OUT; break;
310 case 2: aState = GEOM::ST_ON; break;
311 case 3: aState = GEOM::ST_ONIN; break;
312 case 4: aState = GEOM::ST_ONOUT; break;
316 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::
317 _narrow( getOperation() )->GetShapesOnShapeAsCompound(myObject2, myObject1,
318 (CORBA::Short) aLimit,
321 if (!anObj->_is_nil())
322 objects.push_back( anObj._retn() );
324 return objects.size();
328 //=================================================================================
329 // function : closeEvent
331 //=================================================================================
332 void OperationGUI_GetShapesOnShapeDlg::closeEvent( QCloseEvent* e )
334 GEOMBase_Skeleton::closeEvent( e );
338 //=======================================================================
339 //function : ComboTextChanged
341 //=======================================================================
342 void OperationGUI_GetShapesOnShapeDlg::ComboTextChanged()
344 bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;