]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_PipeDlg.cxx
Salome HOME
Additional minor fix of issue 0017431: unset the MODAL behavior for the 'Basic Proper...
[modules/geom.git] / src / GenerationGUI / GenerationGUI_PipeDlg.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   : GenerationGUI_PipeDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
24 //
25
26 #include "GenerationGUI_PipeDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36
37 #include <TopoDS_Shape.hxx>
38 #include <TopoDS.hxx>
39 #include <TopExp.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
42
43 #include <GEOMImpl_Types.hxx>
44
45 //=================================================================================
46 // class    : GenerationGUI_PipeDlg()
47 // purpose  : Constructs a GenerationGUI_PipeDlg which is a child of 'parent', with the 
48 //            name 'name' and widget flags set to 'f'.
49 //            The dialog will by default be modeless, unless you set 'modal' to
50 //            TRUE to construct a modal dialog.
51 //=================================================================================
52 GenerationGUI_PipeDlg::GenerationGUI_PipeDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
53                                               bool modal, Qt::WindowFlags fl )
54   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
55 {
56   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PIPE" ) ) );
57   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
58
59   setWindowTitle( tr( "GEOM_PIPE_TITLE" ) );
60
61   /***************************************************************/
62   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PIPE" ) );
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();
68
69   GroupPoints = new DlgRef_2Sel( centralWidget() );
70
71   GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
72   GroupPoints->TextLabel1->setText( tr( "GEOM_BASE_OBJECT" ) );
73   GroupPoints->TextLabel2->setText( tr( "GEOM_PATH_OBJECT" ) );
74   GroupPoints->PushButton1->setIcon( image1 );
75   GroupPoints->PushButton2->setIcon( image1 );
76   GroupPoints->LineEdit1->setReadOnly( true );
77   GroupPoints->LineEdit2->setReadOnly( true );
78
79   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
80   layout->setMargin( 0 ); layout->setSpacing( 6 );
81   layout->addWidget( GroupPoints );
82   /***************************************************************/
83
84   setHelpFileName( "create_extrusion_alongpath_page.html" );
85
86   /* Initialisations */
87   Init();
88 }
89
90
91 //=================================================================================
92 // function : ~GenerationGUI_PipeDlg()
93 // purpose  : Destroys the object and frees any allocated resources
94 //=================================================================================
95 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
96 {
97   /* no need to delete child widgets, Qt does it all for us */
98 }
99
100
101 //=================================================================================
102 // function : Init()
103 // purpose  :
104 //=================================================================================
105 void GenerationGUI_PipeDlg::Init()
106 {
107   /* init variables */
108   myEditCurrentArgument = GroupPoints->LineEdit1;
109   GroupPoints->LineEdit1->setReadOnly( true );
110   GroupPoints->LineEdit2->setReadOnly( true );
111
112   myOkBase = myOkPath = false;
113
114   /* signals and slots connections */
115   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
116   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
117
118   connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
119   connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
120
121   connect( GroupPoints->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
122   connect( GroupPoints->LineEdit2,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
123   
124   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
125            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
126
127   initName( tr( "GEOM_PIPE" ) );
128
129   //globalSelection( GEOM_ALLSHAPES );
130 }
131
132
133 //=================================================================================
134 // function : ClickOnOk()
135 // purpose  :
136 //=================================================================================
137 void GenerationGUI_PipeDlg::ClickOnOk()
138 {
139   if ( ClickOnApply() )
140     ClickOnCancel();
141 }
142
143
144 //=================================================================================
145 // function : ClickOnAply()
146 // purpose  :
147 //=================================================================================
148 bool GenerationGUI_PipeDlg::ClickOnApply()
149 {
150   if ( !onAccept() )
151     return false;
152
153   initName();
154   return true;
155 }
156
157
158 //=================================================================================
159 // function : SelectionIntoArgument()
160 // purpose  : Called when selection has changed
161 //=================================================================================
162 void GenerationGUI_PipeDlg::SelectionIntoArgument()
163 {
164   erasePreview();
165   myEditCurrentArgument->setText( "" );
166
167   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
168   SALOME_ListIO aSelList;
169   aSelMgr->selectedObjects(aSelList);
170
171   if (aSelList.Extent() != 1) {
172     if      (myEditCurrentArgument == GroupPoints->LineEdit1) myOkBase = false;
173     else if (myEditCurrentArgument == GroupPoints->LineEdit2) myOkPath = false;
174     return;
175   }
176
177   // nbSel == 1
178   Standard_Boolean testResult = Standard_False;
179   GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
180
181   if (!testResult)
182     return;
183
184   TopoDS_Shape S;
185
186   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
187     myOkBase = false;
188     
189     if (!GEOMBase::GetShape(aSelectedObject, S) ||
190         S.ShapeType() == TopAbs_COMPSOLID ||
191         S.ShapeType() == TopAbs_COMPOUND ||
192         S.ShapeType() == TopAbs_SOLID ||
193         S.ShapeType() == TopAbs_SHAPE)
194       return;
195
196     myBase = aSelectedObject;
197     myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject));
198     myOkBase = true;
199   }
200   else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
201     myOkPath = false;
202
203     if (!GEOMBase::GetShape(aSelectedObject, S)) 
204       return;
205
206     QString aName = GEOMBase::GetName(aSelectedObject);
207
208     if (testResult && !aSelectedObject->_is_nil() && aSelectedObject != myBase) {
209       TColStd_IndexedMapOfInteger aMap;
210       aSelMgr->GetIndexes(aSelList.First(), aMap);
211       if (aMap.Extent() == 1) {
212         int anIndex = aMap(1);
213         aName.append(":edge_" + QString::number(anIndex));
214
215         //Find SubShape Object in Father
216         GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
217
218         if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
219           GEOM::GEOM_IShapesOperations_var aShapesOp =
220             getGeomEngine()->GetIShapesOperations(getStudyId());
221           myPath = aShapesOp->GetSubShape(aSelectedObject, anIndex);
222           myOkPath = true;
223         }
224         else { // get Object from study
225           myPath = aFindedObject;
226           myOkPath = true;
227         }
228       }
229       else {
230         myOkPath = true;
231         if (S.ShapeType() != TopAbs_EDGE) {
232           aSelectedObject = GEOM::GEOM_Object::_nil();
233           aName = "";
234           myOkPath = false;
235         }
236         myPath = aSelectedObject;
237       }
238     }
239     myEditCurrentArgument->setText(aName);
240   }
241
242   displayPreview();
243 }
244
245 //=================================================================================
246 // function : SetEditCurrentArgument()
247 // purpose  :
248 //=================================================================================
249 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
250 {
251   QPushButton* send = (QPushButton*)sender();
252   globalSelection();
253
254   if ( send == GroupPoints->PushButton1 ) {
255     GroupPoints->LineEdit1->setFocus();
256     globalSelection( GEOM_ALLSHAPES );
257     myEditCurrentArgument = GroupPoints->LineEdit1;
258   }
259   else if ( send == GroupPoints->PushButton2 ) {
260     GroupPoints->LineEdit2->setFocus();
261     myEditCurrentArgument = GroupPoints->LineEdit2;
262     globalSelection();
263     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
264   }
265   SelectionIntoArgument();
266 }
267
268
269 //=================================================================================
270 // function : LineEditReturnPressed()
271 // purpose  :
272 //=================================================================================
273 void GenerationGUI_PipeDlg::LineEditReturnPressed()
274 {
275   QLineEdit* send = (QLineEdit*)sender();
276   if ( send == GroupPoints->LineEdit1 ||
277        send == GroupPoints->LineEdit2 ) {
278     myEditCurrentArgument = send;
279     GEOMBase_Skeleton::LineEditReturnPressed();
280   }
281 }
282
283
284 //=================================================================================
285 // function : enterEvent()
286 // purpose  : when mouse enter onto the QWidget
287 //=================================================================================
288 void GenerationGUI_PipeDlg::enterEvent( QEvent* )
289 {
290   if ( !mainFrame()->GroupConstructors->isEnabled() )
291     ActivateThisDialog();
292 }
293
294
295 //=================================================================================
296 // function : ActivateThisDialog()
297 // purpose  :
298 //=================================================================================
299 void GenerationGUI_PipeDlg::ActivateThisDialog()
300 {
301   GEOMBase_Skeleton::ActivateThisDialog();
302   globalSelection( GEOM_ALLSHAPES );
303   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
304            SIGNAL( currentSelectionChanged() ), this, SLOT(SelectionIntoArgument() ) );
305   displayPreview();
306 }
307
308
309 //=================================================================================
310 // function : createOperation
311 // purpose  :
312 //=================================================================================
313 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
314 {
315   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
316 }
317
318 //=================================================================================
319 // function : isValid
320 // purpose  :
321 //=================================================================================
322 bool GenerationGUI_PipeDlg::isValid( QString& )
323 {
324   return myOkBase && myOkPath;
325 }
326
327 //=================================================================================
328 // function : execute
329 // purpose  :
330 //=================================================================================
331 bool GenerationGUI_PipeDlg::execute( ObjectList& objects )
332 {
333   GEOM::GEOM_Object_var anObj;
334
335   anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
336     getOperation() )->MakePipe( myBase, myPath );
337
338   if ( !anObj->_is_nil() )
339     objects.push_back( anObj._retn() );
340
341   return true;
342 }
343
344
345 //=================================================================================
346 // function : addSubshapeToStudy
347 // purpose  : virtual method to add new SubObjects if local selection
348 //=================================================================================
349 void GenerationGUI_PipeDlg::addSubshapesToStudy()
350 {
351   QMap<QString, GEOM::GEOM_Object_var> objMap;
352
353   objMap[GroupPoints->LineEdit2->text()] = myPath;
354
355   addSubshapesToFather( objMap );
356 }
357