Salome HOME
Implement 'make dist' and 'make distcheck' steps support
[modules/geom.git] / src / OperationGUI / OperationGUI_GetShapesOnShapeDlg.cxx
1 // GEOM GEOMGUI : GUI for Geometry component
2 //
3 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 //
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. 
10 //
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. 
15 //
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 
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : OperationGUI_GetShapesOnShapeDlg.cxx
23 // Author : Sergey KUUL, Open CASCADE S.A.S. (sergey.kuul@opencascade.com)
24 //
25
26 #include "OperationGUI_GetShapesOnShapeDlg.h"
27
28 #include <SUIT_Session.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <SalomeApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
32
33 #include <DlgRef.h>
34 #include <GeometryGUI.h>
35 #include <GEOMBase.h>
36
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,
45                                                                     QWidget* parent )
46   : GEOMBase_Skeleton( theGeometryGUI, parent, false )
47 {
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" ) ) );
51
52   setWindowTitle( tr( "GEOM_SHAPES_ON_SHAPE_TITLE" ) );
53
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();
60
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 );
72
73   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
74   layout->setMargin( 0 ); layout->setSpacing( 6 );
75   layout->addWidget( GroupPoints );
76
77   setHelpFileName( "shapesonshape_page.html" );
78   
79   Init();
80 }
81
82 //=================================================================================
83 // function : ~OperationGUI_GetShapesOnShapeDlg
84 // purpose  : Destroys the object and frees any allocated resources
85 //=================================================================================
86 OperationGUI_GetShapesOnShapeDlg::~OperationGUI_GetShapesOnShapeDlg()
87 {
88 }
89
90 //=================================================================================
91 // function : Init()
92 // purpose  :
93 //=================================================================================
94 void OperationGUI_GetShapesOnShapeDlg::Init()
95 {
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" ) );
105
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" ) );
112
113   GroupPoints->LineEdit1->clear();
114   GroupPoints->LineEdit2->clear();
115
116    /* signals and slots connections */
117   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
118   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
119
120   connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
121   connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
122
123   connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
124   connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
125   
126   connect( GroupPoints->ComboBox1, SIGNAL( activated( int ) ), this, SLOT( ComboTextChanged() ) );
127   connect( GroupPoints->ComboBox2, SIGNAL( activated( int ) ), this, SLOT( ComboTextChanged() ) );
128
129   connect( myGeomGUI->getApp()->selectionMgr(),
130            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
131
132   globalSelection( GEOM_ALLSHAPES );
133
134   initName( mainFrame()->GroupConstructors->title() );
135
136   GroupPoints->TextLabel3->show();
137   GroupPoints->ComboBox1->show();
138   GroupPoints->ComboBox1->setCurrentIndex( 0 );
139   GroupPoints->ComboBox2->show();
140   GroupPoints->ComboBox2->setCurrentIndex( 0 );
141
142   myEditCurrentArgument = GroupPoints->LineEdit1;
143   myEditCurrentArgument->setFocus();
144 }
145
146 //=================================================================================
147 // function : ClickOnOk()
148 // purpose  :
149 //=================================================================================
150 void OperationGUI_GetShapesOnShapeDlg::ClickOnOk()
151 {
152   if ( ClickOnApply() )
153     ClickOnCancel();
154 }
155
156 //=================================================================================
157 // function : ClickOnApply()
158 // purpose  :
159 //=================================================================================
160 bool OperationGUI_GetShapesOnShapeDlg::ClickOnApply()
161 {
162   if ( !onAccept() )
163     return false;  
164
165   initName();
166   return true;
167 }
168
169 //=================================================================================
170 // function : SelectionIntoArgument()
171 // purpose  : Called when selection has changed
172 //=================================================================================
173 void OperationGUI_GetShapesOnShapeDlg::SelectionIntoArgument()
174 {
175   myEditCurrentArgument->setText( "" );
176   QString aString = "";
177
178   int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
179
180   if ( nbSel > 0 ) {
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 ) ) {
184     {
185       myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
186       if      ( myEditCurrentArgument == GroupPoints->LineEdit1 )   myObject1 = aSelectedObject;
187       else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )   myObject2 = aSelectedObject;
188       }
189     }
190   }
191
192   myEditCurrentArgument->setText( aString );
193 }
194
195 //=================================================================================
196 // function : SetEditCurrentArgument()
197 // purpose  :
198 //=================================================================================
199 void OperationGUI_GetShapesOnShapeDlg::SetEditCurrentArgument()
200 {
201   QPushButton* send = (QPushButton*)sender();
202
203   if      ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
204   else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
205
206   myEditCurrentArgument->setFocus();
207   SelectionIntoArgument();
208 }
209
210 //=================================================================================
211 // function : LineEditReturnPressed()
212 // purpose  :
213 //=================================================================================
214 void OperationGUI_GetShapesOnShapeDlg::LineEditReturnPressed()
215 {
216   QLineEdit* send = (QLineEdit*)sender();
217   if ( send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2 )
218   {
219     myEditCurrentArgument = send;
220     GEOMBase_Skeleton::LineEditReturnPressed();
221   }
222 }
223
224 //=================================================================================
225 // function : ActivateThisDialog()
226 // purpose  :
227 //=================================================================================
228 void OperationGUI_GetShapesOnShapeDlg::ActivateThisDialog()
229 {
230   GEOMBase_Skeleton::ActivateThisDialog();
231   globalSelection( GEOM_ALLSHAPES );
232   connect( myGeomGUI->getApp()->selectionMgr(),
233            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
234 }
235
236 //=================================================================================
237 // function : enterEvent()
238 // purpose  : when mouse enter onto the QWidget
239 //=================================================================================
240 void OperationGUI_GetShapesOnShapeDlg::enterEvent(QEvent * e)
241 {
242   if ( !mainFrame()->GroupConstructors->isEnabled() )
243     ActivateThisDialog();
244 }
245
246 //=================================================================================
247 // function : createOperation
248 // purpose  :
249 //=================================================================================
250 GEOM::GEOM_IOperations_ptr OperationGUI_GetShapesOnShapeDlg::createOperation()
251 {
252   return getGeomEngine()->GetIShapesOperations( getStudyId() );
253 }
254
255 //=================================================================================
256 // function : isValid
257 // purpose  :
258 //=================================================================================
259 bool OperationGUI_GetShapesOnShapeDlg::isValid( QString& msg )
260 {
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() )
265     return false;
266
267   return !CORBA::is_nil( myObject1 ) && !CORBA::is_nil( myObject2 );
268 }
269
270 //=================================================================================
271 // function : execute
272 // purpose  :
273 //=================================================================================
274 bool OperationGUI_GetShapesOnShapeDlg::execute( ObjectList& objects )
275 {
276   int aLimit = GroupPoints->ComboBox1->currentIndex();
277   switch ( aLimit )
278   {
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;
284   }
285
286   GEOM::shape_state aState;
287   switch ( GroupPoints->ComboBox2->currentIndex() )
288   {
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;
294     default: break;
295   }
296
297   GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::
298     _narrow( getOperation() )->GetShapesOnShapeAsCompound( myObject2, myObject1,
299                                                            (CORBA::Short) aLimit,
300                                                            aState );
301
302   if ( !anObj->_is_nil() )
303     objects.push_back( anObj._retn() );
304
305   return objects.size();
306 }
307
308 //=======================================================================
309 //function : ComboTextChanged
310 //purpose  : 
311 //=======================================================================
312 void OperationGUI_GetShapesOnShapeDlg::ComboTextChanged()
313 {
314   // VRS ???? What is it for ??? commented for a while...
315   //bool IsEnabled = GroupPoints->ComboBox1->currentIndex() < 3;
316 }