]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_PipeDlg.cxx
Salome HOME
edcbec331bdabc0c7ba8e7ed7ba295a3b5d98fb0
[modules/geom.git] / src / GenerationGUI / GenerationGUI_PipeDlg.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : GenerationGUI_PipeDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 //
27 #include "GenerationGUI_PipeDlg.h"
28
29 #include <DlgRef.h>
30 #include <GeometryGUI.h>
31 #include <GEOMBase.h>
32
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
37
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS.hxx>
40 #include <TopExp.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <TColStd_IndexedMapOfInteger.hxx>
44 #include <TColStd_MapOfInteger.hxx>
45
46 #include <GEOMImpl_Types.hxx>
47
48 //=================================================================================
49 // class    : GenerationGUI_PipeDlg()
50 // purpose  : Constructs a GenerationGUI_PipeDlg which is a child of 'parent', with the
51 //            name 'name' and widget flags set to 'f'.
52 //            The dialog will by default be modeless, unless you set 'modal' to
53 //            TRUE to construct a modal dialog.
54 //=================================================================================
55 GenerationGUI_PipeDlg::GenerationGUI_PipeDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
56                                               bool modal, Qt::WindowFlags fl)
57   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
58 {
59   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE")));
60   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
61   QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE_BINORMAL")));
62   QPixmap image3 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE_SECTION")));
63
64   setWindowTitle(tr("GEOM_PIPE_TITLE"));
65
66   /***************************************************************/
67   mainFrame()->GroupConstructors->setTitle(tr("GEOM_PIPE"));
68   mainFrame()->RadioButton1->setIcon(image0);
69   mainFrame()->RadioButton2->setIcon(image2);
70   mainFrame()->RadioButton3->setIcon(image3);
71   // mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
72   // mainFrame()->RadioButton3->close();
73
74   GroupPoints = new DlgRef_3Sel1Check(centralWidget());
75
76   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
77   GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
78   GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
79   GroupPoints->TextLabel3->setText(tr("GEOM_BINORMAL"));
80   GroupPoints->PushButton1->setIcon(image1);
81   GroupPoints->PushButton2->setIcon(image1);
82   GroupPoints->PushButton3->setIcon(image1);
83   GroupPoints->CheckButton1->setText(tr("GEOM_SELECT_UNPUBLISHED_EDGES"));
84
85   GroupMakePoints = new DlgRef_3Sel2Check3Spin(centralWidget());
86
87   GroupMakePoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
88   GroupMakePoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
89   GroupMakePoints->TextLabel2->setText(tr("GEOM_LOCATIONS"));
90   GroupMakePoints->TextLabel3->setText(tr("GEOM_PATH_OBJECT"));
91   GroupMakePoints->PushButton1->setIcon(image1);
92   GroupMakePoints->PushButton2->setIcon(image1);
93   GroupMakePoints->PushButton3->setIcon(image1);
94   GroupMakePoints->CheckBox1->setText(tr("GEOM_WITH_CONTACT"));
95   GroupMakePoints->CheckBox2->setText(tr("GEOM_WITH_CORRECTION"));
96   GroupMakePoints->SpinBox1->close();
97   GroupMakePoints->SpinBox2->close();
98   GroupMakePoints->SpinBox3->close();
99   GroupMakePoints->TextLabel4->close();
100   GroupMakePoints->TextLabel5->close();
101   GroupMakePoints->TextLabel6->close();
102
103   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
104   layout->setMargin(0); layout->setSpacing(6);
105   layout->addWidget(GroupPoints);
106   layout->addWidget(GroupMakePoints);
107   /***************************************************************/
108
109   setHelpFileName("create_extrusion_alongpath_page.html");
110
111   // Initialisation
112   Init();
113 }
114
115 //=================================================================================
116 // function : ~GenerationGUI_PipeDlg()
117 // purpose  : Destroys the object and frees any allocated resources
118 //=================================================================================
119 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
120 {
121   // no need to delete child widgets, Qt does it all for us
122 }
123
124 //=================================================================================
125 // function : Init()
126 // purpose  :
127 //=================================================================================
128 void GenerationGUI_PipeDlg::Init()
129 {
130   // init variables
131   GroupPoints->LineEdit1->setReadOnly(true);
132   GroupPoints->LineEdit2->setReadOnly(true);
133   GroupPoints->LineEdit3->setReadOnly(true);
134
135   GroupPoints->LineEdit1->setText("");
136   GroupPoints->LineEdit2->setText("");
137   GroupPoints->LineEdit3->setText("");
138   myPath.nullify();
139   myVec.nullify();
140
141   GroupPoints->CheckButton1->setEnabled(false);
142
143   GroupMakePoints->LineEdit1->setReadOnly(true);
144   GroupMakePoints->LineEdit2->setReadOnly(true);
145   GroupMakePoints->LineEdit3->setReadOnly(true);
146
147   GroupMakePoints->LineEdit1->setText("");
148   GroupMakePoints->LineEdit2->setText("");
149   GroupMakePoints->LineEdit3->setText("");
150
151   showOnlyPreviewControl();
152
153   // signals and slots connections
154   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
155   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
156
157   connect(this,          SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
158
159   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
160   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
161   connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
162
163   connect(GroupPoints->CheckButton1,   SIGNAL(toggled(bool)), this, SLOT(SelectionTypeButtonClicked()));
164
165   connect(GroupMakePoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
166   connect(GroupMakePoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
167   connect(GroupMakePoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
168   connect(GroupMakePoints->CheckBox1, SIGNAL(clicked()), this, SLOT(processPreview()));
169   connect(GroupMakePoints->CheckBox2, SIGNAL(clicked()), this, SLOT(processPreview()));
170
171   initName(tr("GEOM_PIPE"));
172   resize(100,100);
173
174   GroupPoints->TextLabel3->hide();
175   GroupPoints->PushButton3->hide();
176   GroupPoints->LineEdit3->hide();
177   ConstructorsClicked(0);
178
179   GroupPoints->PushButton1->click();
180   SelectionIntoArgument();
181 }
182
183 //=================================================================================
184 // function : ConstructorsClicked()
185 // purpose  : Radio button management
186 //=================================================================================
187 void GenerationGUI_PipeDlg::ConstructorsClicked( int constructorId )
188 {
189   erasePreview();
190
191   switch (constructorId) {
192   case 0:
193     GroupMakePoints->hide();
194     GroupPoints->show();
195     GroupPoints->TextLabel3->hide();
196     GroupPoints->PushButton3->hide();
197     GroupPoints->LineEdit3->hide();
198     GroupPoints->PushButton1->click();
199     break;
200   case 1:
201     GroupMakePoints->hide();
202     GroupPoints->show();
203     GroupPoints->TextLabel3->show();
204     GroupPoints->PushButton3->show();
205     GroupPoints->LineEdit3->show();
206     GroupPoints->PushButton1->click();
207     break;
208   case 2:
209     GroupPoints->hide();
210     GroupMakePoints->show();
211     GroupMakePoints->PushButton1->click();
212     break;
213   default:
214     break;
215   }
216
217   qApp->processEvents();
218   updateGeometry();
219   resize(100,100);
220
221   SelectionIntoArgument();
222   processPreview();
223 }
224
225 //=================================================================================
226 // function : SelectionBittonClicked()
227 // purpose  : Selection type Radio button management
228 //=================================================================================
229 void GenerationGUI_PipeDlg::SelectionTypeButtonClicked()
230 {
231   globalSelection();
232   if ( GroupPoints->CheckButton1->isChecked() ) {
233     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
234   } else {
235     TColStd_MapOfInteger aMap;
236     aMap.Add(GEOM_COMPOUND);
237     aMap.Add(GEOM_WIRE);
238     aMap.Add(GEOM_LINE);
239     globalSelection(aMap);
240   }
241   if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
242     myEditCurrentArgument->setText("");
243     myPath.nullify();
244   }
245   processPreview();
246 }
247
248 //=================================================================================
249 // function : ClickOnOk()
250 // purpose  :
251 //=================================================================================
252 void GenerationGUI_PipeDlg::ClickOnOk()
253 {
254   setIsApplyAndClose( true );
255   if (ClickOnApply())
256     ClickOnCancel();
257 }
258
259 //=================================================================================
260 // function : ClickOnApply()
261 // purpose  :
262 //=================================================================================
263 bool GenerationGUI_PipeDlg::ClickOnApply()
264 {
265   if (!onAccept())
266     return false;
267
268   initName();
269
270   return true;
271 }
272
273 //=================================================================================
274 // function : SelectionIntoArgument()
275 // purpose  : Called when selection is changed or on dialog initialization or activation
276 //=================================================================================
277 void GenerationGUI_PipeDlg::SelectionIntoArgument()
278 {
279   erasePreview();
280   myEditCurrentArgument->setText("");
281
282   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
283     myBaseObjects.clear();
284     QList<GEOM::GeomObjPtr> objects = getSelected( TopAbs_SHAPE, -1 );
285     for ( int i = 0; i < objects.count(); i++ ) {
286       GEOM::shape_type stype = objects[i]->GetMaxShapeType();
287       GEOM::shape_type maxallowed = getConstructorId() == 1 ? GEOM::FACE : GEOM::SHELL;
288       GEOM::shape_type minallowed = getConstructorId() == 1 ? GEOM::EDGE : GEOM::VERTEX;
289       if ( stype < maxallowed || stype > minallowed )
290         continue;
291       myBaseObjects << objects[i];
292     }
293     if ( !myBaseObjects.isEmpty() ) {
294       QString aName = myBaseObjects.count() > 1 ? QString( "%1_objects").arg( myBaseObjects.count() ) : GEOMBase::GetName( myBaseObjects[0].get() );
295       myEditCurrentArgument->setText( aName );
296     }
297   }
298   else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
299     QList<TopAbs_ShapeEnum> types;
300     types << TopAbs_EDGE << TopAbs_WIRE;
301     myPath = getSelected( types );
302     if ( myPath ) {
303       QString aName = GEOMBase::GetName( myPath.get() );
304       myEditCurrentArgument->setText( aName );
305       if ( getConstructorId() == 1 && !myVec )
306         GroupPoints->PushButton3->click();
307       else if ( myBaseObjects.isEmpty() )
308         GroupPoints->PushButton1->click();
309     }
310   }
311   else if (myEditCurrentArgument == GroupPoints->LineEdit3) {
312     myVec = getSelected( TopAbs_EDGE );
313     if ( myVec ) {
314       QString aName = GEOMBase::GetName( myVec.get() );
315       myEditCurrentArgument->setText( aName );
316       if ( myBaseObjects.isEmpty() )
317         GroupPoints->PushButton1->click();
318       else if ( !myPath )
319         GroupPoints->PushButton2->click();
320     }
321   }
322   else if ( myEditCurrentArgument == GroupMakePoints->LineEdit1 ) {
323     myBaseObjects.clear();
324     QList<TopAbs_ShapeEnum> types;
325     types << TopAbs_EDGE << TopAbs_WIRE << TopAbs_FACE << TopAbs_SHELL;
326     QList<GEOM::GeomObjPtr> objects = getSelected( types, -1 );
327     GEOMBase::Synchronize( myBaseObjects, objects );
328     if ( !myBaseObjects.isEmpty() ) {
329       QString aName = myBaseObjects.count() > 1 ? QString( "%1_objects").arg( myBaseObjects.count() ) : GEOMBase::GetName( myBaseObjects[0].get() );
330       myEditCurrentArgument->setText( aName );
331     }
332   }
333   else if ( myEditCurrentArgument == GroupMakePoints->LineEdit2 ) {
334     myLocations.clear();
335     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
336     QList<GEOM::GeomObjPtr> objects = getSelected( TopAbs_VERTEX, -1 );
337     GEOMBase::Synchronize( myLocations, objects );
338     if ( !myLocations.isEmpty() ) {
339       QString aName = myLocations.count() > 1 ? QString( "%1_objects").arg( myLocations.count() ) : GEOMBase::GetName( myLocations[0].get() );
340       myEditCurrentArgument->setText( aName );
341     }
342   }
343   else if ( myEditCurrentArgument == GroupMakePoints->LineEdit3 ) {
344     QList<TopAbs_ShapeEnum> types;
345     types << TopAbs_EDGE << TopAbs_WIRE;
346     myPath = getSelected( types );
347     if ( myPath ) {
348       QString aName = GEOMBase::GetName( myPath.get() );
349       myEditCurrentArgument->setText( aName );
350     }
351   }
352
353   processPreview();
354 }
355
356 //=================================================================================
357 // function : SetEditCurrentArgument()
358 // purpose  :
359 //=================================================================================
360 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
361 {
362   QPushButton* send = (QPushButton*)sender();
363
364   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
365   globalSelection(GEOM_ALLSHAPES);
366   GroupPoints->PushButton1->setDown(false);
367   GroupPoints->PushButton2->setDown(false);
368   GroupPoints->PushButton3->setDown(false);
369   GroupPoints->LineEdit1->setEnabled(false);
370   GroupPoints->LineEdit2->setEnabled(false);
371   GroupPoints->LineEdit3->setEnabled(false);
372   if (send == GroupPoints->PushButton1) {
373     myEditCurrentArgument = GroupPoints->LineEdit1;
374     GroupPoints->CheckButton1->setEnabled(false);
375   }
376   else if (send == GroupPoints->PushButton2) {
377     myEditCurrentArgument = GroupPoints->LineEdit2;
378
379     if ( GroupPoints->CheckButton1->isChecked() ) {
380       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
381     } else {
382       TColStd_MapOfInteger aMap;
383       aMap.Add(GEOM_COMPOUND);
384       aMap.Add(GEOM_WIRE);
385       aMap.Add(GEOM_LINE);
386       globalSelection(aMap);
387     }
388     GroupPoints->CheckButton1->setEnabled(true);
389   }
390   else if(send == GroupPoints->PushButton3) {
391     myEditCurrentArgument = GroupPoints->LineEdit3;
392     GroupPoints->CheckButton1->setEnabled(false);
393     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
394   }
395
396   GroupMakePoints->PushButton1->setDown(false);
397   GroupMakePoints->PushButton2->setDown(false);
398   GroupMakePoints->PushButton3->setDown(false);
399   GroupMakePoints->LineEdit1->setEnabled(false);
400   GroupMakePoints->LineEdit2->setEnabled(false);
401   GroupMakePoints->LineEdit3->setEnabled(false);
402   if (send == GroupMakePoints->PushButton1) {
403     myEditCurrentArgument = GroupMakePoints->LineEdit1;
404   }
405   else if(send == GroupMakePoints->PushButton2) {
406     myEditCurrentArgument = GroupMakePoints->LineEdit2;
407   }
408   else if (send == GroupMakePoints->PushButton3) {
409     myEditCurrentArgument = GroupMakePoints->LineEdit3;
410   }
411
412   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
413           this, SLOT(SelectionIntoArgument()));
414
415   // enable line edit
416   myEditCurrentArgument->setEnabled(true);
417   myEditCurrentArgument->setFocus();
418   // after setFocus(), because it will be setDown(false) when loses focus
419   send->setDown(true);
420
421   // seems we need it only to avoid preview disappearing, caused by selection mode change
422   processPreview();
423 }
424
425 //=================================================================================
426 // function : ActivateThisDialog()
427 // purpose  :
428 //=================================================================================
429 void GenerationGUI_PipeDlg::ActivateThisDialog()
430 {
431   GEOMBase_Skeleton::ActivateThisDialog();
432   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
433            this, SLOT( SelectionIntoArgument() ) );
434
435   ConstructorsClicked(getConstructorId());
436 }
437
438 //=================================================================================
439 // function : enterEvent()
440 // purpose  : when mouse enter onto the QWidget
441 //=================================================================================
442 void GenerationGUI_PipeDlg::enterEvent (QEvent*)
443 {
444   if (!mainFrame()->GroupConstructors->isEnabled())
445     ActivateThisDialog();
446 }
447
448 //=================================================================================
449 // function : createOperation
450 // purpose  :
451 //=================================================================================
452 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
453 {
454   return getGeomEngine()->GetI3DPrimOperations(getStudyId());
455 }
456
457 //=================================================================================
458 // function : isValid
459 // purpose  :
460 //=================================================================================
461 bool GenerationGUI_PipeDlg::isValid (QString&)
462 {
463   bool ok = false;
464   switch ( getConstructorId() ) {
465   case 0 :
466     ok = !myBaseObjects.isEmpty() && myPath;
467     break;
468   case 1 :
469     ok = !myBaseObjects.isEmpty() && myPath && myVec;
470     break;
471   case 2 :
472     ok = !myBaseObjects.isEmpty() && ( myLocations.isEmpty() || myBaseObjects.count() == myLocations.count() ) && myPath;
473     break;
474   default:
475     break;
476   }
477   return ok;
478 }
479
480 //=================================================================================
481 // function : execute
482 // purpose  :
483 //=================================================================================
484 bool GenerationGUI_PipeDlg::execute (ObjectList& objects)
485 {
486   GEOM::GEOM_Object_var anObj;
487
488   GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
489   switch( getConstructorId() ) {
490   case 0:
491   case 1:
492     for (int i = 0; i < myBaseObjects.count(); i++) {
493       switch ( getConstructorId() ) {
494       case 0 :
495         anObj = anOper->MakePipe(myBaseObjects[i].get(), myPath.get());
496         break;
497       case 1 :
498         anObj = anOper->MakePipeBiNormalAlongVector(myBaseObjects[i].get(), myPath.get(), myVec.get());
499         break;
500       }
501     
502       if (!anObj->_is_nil())
503         objects.push_back(anObj._retn());
504     }
505     break;
506   case 2:
507     {
508       GEOM::ListOfGO_var myBaseGO = new GEOM::ListOfGO();
509       GEOM::ListOfGO_var myLocationsGO = new GEOM::ListOfGO();
510       myBaseGO->length( myBaseObjects.count() );
511       myLocationsGO->length( myLocations.count() );
512       for (int i = 0; i < myBaseObjects.count(); i++) {
513         myBaseGO[i] = myBaseObjects[i].copy();
514       }
515       for (int i = 0; i < myLocations.count(); i++) {
516         myLocationsGO[i] = myLocations[i].copy();
517       }
518       
519       anObj = anOper->MakePipeWithDifferentSections(myBaseGO.in(), myLocationsGO.in(), myPath.get(), 
520                                                     GroupMakePoints->CheckBox1->isChecked(), 
521                                                     GroupMakePoints->CheckBox2->isChecked());
522       if (!anObj->_is_nil())
523         objects.push_back(anObj._retn());
524     }
525     break;
526   default:
527     break;
528   }
529   return true;
530 }
531
532 //=================================================================================
533 // function : addSubshapeToStudy
534 // purpose  : virtual method to add new SubObjects if local selection
535 //=================================================================================
536 void GenerationGUI_PipeDlg::addSubshapesToStudy()
537 {
538   GEOMBase::PublishSubObject( myPath.get() );
539   GEOMBase::PublishSubObject( myVec.get() );
540 }
541
542 //=================================================================================
543 // function : extractPrefix
544 // purpose  : redefined from GEOMBase_Helper class
545 //=================================================================================
546 bool GenerationGUI_PipeDlg::extractPrefix() const
547 {
548   return myBaseObjects.count() > 1;
549 }