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
22 // File : OperationGUI_GetShapesOnShapeDlg.cxx
23 // Author : Sergey KUUL, Open CASCADE S.A.S. (sergey.kuul@opencascade.com)
26 #include "OperationGUI_GetShapesOnShapeDlg.h"
28 #include <SUIT_Session.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <SalomeApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
34 #include <GeometryGUI.h>
37 //==============================================================================
38 // class : OperationGUI_GetShapesOnShapeDlg()
39 // purpose : Constructs a OperationGUI_GetShapesOnShapeDlg which is a child of
40 // 'parent', with the name 'name' and widget flags set to 'f'.
41 // The dialog will by default be modeless, unless you set 'modal' to
42 // TRUE to construct a modal dialog.
43 //=================================================================================
44 OperationGUI_GetShapesOnShapeDlg::OperationGUI_GetShapesOnShapeDlg( GeometryGUI* theGeometryGUI,
46 : GEOMBase_Skeleton( theGeometryGUI, parent, false )
48 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
49 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_SHAPES_ON_SHAPE" ) ) );
50 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
52 setWindowTitle( tr( "GEOM_SHAPES_ON_SHAPE_TITLE" ) );
54 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SHAPES_ON_SHAPE" ) );
55 mainFrame()->RadioButton1->setIcon(image0);
56 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
57 mainFrame()->RadioButton2->close();
58 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
59 mainFrame()->RadioButton3->close();
61 GroupPoints = new DlgRef_2Sel2List( centralWidget() );
62 //GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
63 GroupPoints->GroupBox1->setTitle( "Input data" );
64 GroupPoints->TextLabel1->setText( tr( "GEOM_SHAPES_ON_SHAPE_ESHAPE" ) );
65 GroupPoints->TextLabel2->setText( tr( "GEOM_SHAPES_ON_SHAPE_CSHAPE" ) );
66 GroupPoints->TextLabel3->setText( tr( "GEOM_RECONSTRUCTION_LIMIT" ) );
67 GroupPoints->TextLabel4->setText( tr( "GEOM_SHAPES_ON_SHAPE_STATE" ) );
68 GroupPoints->PushButton1->setIcon( image2 );
69 GroupPoints->PushButton2->setIcon( image2 );
70 GroupPoints->LineEdit1->setReadOnly( true );
71 GroupPoints->LineEdit2->setReadOnly( true );
73 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
74 layout->setMargin( 0 ); layout->setSpacing( 6 );
75 layout->addWidget( GroupPoints );
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();
116 /* signals and slots connections */
117 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
118 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
120 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
121 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
123 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
124 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
126 connect( GroupPoints->ComboBox1, SIGNAL( activated( int ) ), this, SLOT( ComboTextChanged() ) );
127 connect( GroupPoints->ComboBox2, SIGNAL( activated( int ) ), this, SLOT( ComboTextChanged() ) );
129 connect( myGeomGUI->getApp()->selectionMgr(),
130 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
132 globalSelection( GEOM_ALLSHAPES );
134 initName( mainFrame()->GroupConstructors->title() );
136 GroupPoints->TextLabel3->show();
137 GroupPoints->ComboBox1->show();
138 GroupPoints->ComboBox1->setCurrentIndex( 0 );
139 GroupPoints->ComboBox2->show();
140 GroupPoints->ComboBox2->setCurrentIndex( 0 );
142 myEditCurrentArgument = GroupPoints->LineEdit1;
143 myEditCurrentArgument->setFocus();
146 //=================================================================================
147 // function : ClickOnOk()
149 //=================================================================================
150 void OperationGUI_GetShapesOnShapeDlg::ClickOnOk()
152 if ( ClickOnApply() )
156 //=================================================================================
157 // function : ClickOnApply()
159 //=================================================================================
160 bool OperationGUI_GetShapesOnShapeDlg::ClickOnApply()
169 //=================================================================================
170 // function : SelectionIntoArgument()
171 // purpose : Called when selection has changed
172 //=================================================================================
173 void OperationGUI_GetShapesOnShapeDlg::SelectionIntoArgument()
175 myEditCurrentArgument->setText( "" );
176 QString aString = "";
178 int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
181 Standard_Boolean aRes = Standard_False;
182 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
183 if ( !CORBA::is_nil( aSelectedObject ) && aRes && GEOMBase::IsShape( aSelectedObject ) ) {
185 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
186 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myObject1 = aSelectedObject;
187 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myObject2 = aSelectedObject;
192 myEditCurrentArgument->setText( aString );
195 //=================================================================================
196 // function : SetEditCurrentArgument()
198 //=================================================================================
199 void OperationGUI_GetShapesOnShapeDlg::SetEditCurrentArgument()
201 QPushButton* send = (QPushButton*)sender();
203 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
204 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
206 myEditCurrentArgument->setFocus();
207 SelectionIntoArgument();
210 //=================================================================================
211 // function : LineEditReturnPressed()
213 //=================================================================================
214 void OperationGUI_GetShapesOnShapeDlg::LineEditReturnPressed()
216 QLineEdit* send = (QLineEdit*)sender();
217 if ( send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2 )
219 myEditCurrentArgument = send;
220 GEOMBase_Skeleton::LineEditReturnPressed();
224 //=================================================================================
225 // function : ActivateThisDialog()
227 //=================================================================================
228 void OperationGUI_GetShapesOnShapeDlg::ActivateThisDialog()
230 GEOMBase_Skeleton::ActivateThisDialog();
231 globalSelection( GEOM_ALLSHAPES );
232 connect( myGeomGUI->getApp()->selectionMgr(),
233 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
236 //=================================================================================
237 // function : enterEvent()
238 // purpose : when mouse enter onto the QWidget
239 //=================================================================================
240 void OperationGUI_GetShapesOnShapeDlg::enterEvent(QEvent * e)
242 if ( !mainFrame()->GroupConstructors->isEnabled() )
243 ActivateThisDialog();
246 //=================================================================================
247 // function : createOperation
249 //=================================================================================
250 GEOM::GEOM_IOperations_ptr OperationGUI_GetShapesOnShapeDlg::createOperation()
252 return getGeomEngine()->GetIShapesOperations( getStudyId() );
255 //=================================================================================
256 // function : isValid
258 //=================================================================================
259 bool OperationGUI_GetShapesOnShapeDlg::isValid( QString& msg )
261 Handle(SALOME_InteractiveObject) IO = firstIObject();
262 Standard_Boolean testResult;
263 GEOM::GEOM_Object_var anObject = GEOMBase::ConvertIOinGEOMObject( IO, testResult );
264 if ( !testResult || anObject->_is_nil() )
267 return !CORBA::is_nil( myObject1 ) && !CORBA::is_nil( myObject2 );
270 //=================================================================================
271 // function : execute
273 //=================================================================================
274 bool OperationGUI_GetShapesOnShapeDlg::execute( ObjectList& objects )
276 int aLimit = GroupPoints->ComboBox1->currentIndex();
279 case 0: aLimit = GEOM::SOLID ; break;
280 case 1: aLimit = GEOM::FACE ; break;
281 case 2: aLimit = GEOM::EDGE ; break;
282 case 3: aLimit = GEOM::VERTEX; break;
283 default: aLimit = GEOM::SHAPE ; break;
286 GEOM::shape_state aState;
287 switch ( GroupPoints->ComboBox2->currentIndex() )
289 case 0: aState = GEOM::ST_IN; break;
290 case 1: aState = GEOM::ST_OUT; break;
291 case 2: aState = GEOM::ST_ON; break;
292 case 3: aState = GEOM::ST_ONIN; break;
293 case 4: aState = GEOM::ST_ONOUT; break;
297 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::
298 _narrow( getOperation() )->GetShapesOnShapeAsCompound( myObject2, myObject1,
299 (CORBA::Short) aLimit,
302 if ( !anObj->_is_nil() )
303 objects.push_back( anObj._retn() );
305 return objects.size();
308 //=======================================================================
309 //function : ComboTextChanged
311 //=======================================================================
312 void OperationGUI_GetShapesOnShapeDlg::ComboTextChanged()
314 // VRS ???? What is it for ??? commented for a while...
315 //bool IsEnabled = GroupPoints->ComboBox1->currentIndex() < 3;