Salome HOME
de7a848fe6d0e46bdcb8794e0e5875a9e2f42b7e
[modules/geom.git] / src / GenerationGUI / GenerationGUI_PipeDlg.cxx
1 // Copyright (C) 2007-2023  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 #include <GEOMUtils.hxx>
33
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38
39 #include <TopoDS_Shape.hxx>
40 #include <TColStd_MapOfInteger.hxx>
41
42 #include <GEOMImpl_Types.hxx>
43
44 //=================================================================================
45 // class    : GenerationGUI_PipeDlg()
46 // purpose  : Constructs a GenerationGUI_PipeDlg which is a child of 'parent', with the
47 //            name 'name' and widget flags set to 'f'.
48 //            The dialog will by default be modeless, unless you set 'modal' to
49 //            TRUE to construct a modal dialog.
50 //=================================================================================
51 GenerationGUI_PipeDlg::GenerationGUI_PipeDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
52                                               bool modal, Qt::WindowFlags fl)
53   : GEOMBase_Skeleton    (theGeometryGUI, parent, modal, fl),
54     myGenGroupCheckGP    (0),
55     myPrefixLblGP        (0),
56     myPrefixEditGP       (0),
57     myStepByStepCheckGMP (0),
58     myGenGroupCheckGMP   (0),
59     myPrefixLblGMP       (0),
60     myPrefixEditGMP      (0)
61 {
62   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE")));
63   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
64   QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE_BINORMAL")));
65   QPixmap image3 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE_SECTION")));
66
67   setWindowTitle(tr("GEOM_PIPE_TITLE"));
68
69   /***************************************************************/
70   mainFrame()->GroupConstructors->setTitle(tr("GEOM_PIPE"));
71   mainFrame()->RadioButton1->setIcon(image0);
72   mainFrame()->RadioButton2->setIcon(image2);
73   mainFrame()->RadioButton3->setIcon(image3);
74   // mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
75   // mainFrame()->RadioButton3->close();
76
77   GroupPoints = new DlgRef_3Sel1Check(centralWidget());
78
79   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
80   GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
81   GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
82   GroupPoints->TextLabel3->setText(tr("GEOM_BINORMAL"));
83   GroupPoints->PushButton1->setIcon(image1);
84   GroupPoints->PushButton2->setIcon(image1);
85   GroupPoints->PushButton3->setIcon(image1);
86   GroupPoints->CheckButton1->setText(tr("GEOM_SELECT_UNPUBLISHED_EDGES"));
87
88   // Add widgets for group generation
89   QGridLayout *aLayoutGP = (QGridLayout *)GroupPoints->GroupBox1->layout();
90
91   myGenGroupCheckGP =
92     new QCheckBox(tr("GEOM_GENERATE_GROUPS"), GroupPoints->GroupBox1);
93   myPrefixLblGP     =
94     new QLabel (tr("GEOM_GROUP_NAME_PREFIX"), GroupPoints->GroupBox1);
95   myPrefixEditGP    = new QLineEdit(GroupPoints->GroupBox1);
96
97   aLayoutGP->addWidget(myGenGroupCheckGP, 4, 0, 1, 3);
98   aLayoutGP->addWidget(myPrefixLblGP,     5, 0, 1, 2);
99   aLayoutGP->addWidget(myPrefixEditGP,    5, 2);
100
101   GroupMakePoints = new DlgRef_3Sel2Check3Spin(centralWidget());
102
103   GroupMakePoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
104   GroupMakePoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
105   GroupMakePoints->TextLabel2->setText(tr("GEOM_LOCATIONS"));
106   GroupMakePoints->TextLabel3->setText(tr("GEOM_PATH_OBJECT"));
107   GroupMakePoints->PushButton1->setIcon(image1);
108   GroupMakePoints->PushButton2->setIcon(image1);
109   GroupMakePoints->PushButton3->setIcon(image1);
110   GroupMakePoints->CheckBox1->setText(tr("GEOM_WITH_CONTACT"));
111   GroupMakePoints->CheckBox2->setText(tr("GEOM_WITH_CORRECTION"));
112   GroupMakePoints->SpinBox1->setAttribute(Qt::WA_DeleteOnClose);
113   GroupMakePoints->SpinBox2->setAttribute(Qt::WA_DeleteOnClose);
114   GroupMakePoints->SpinBox3->setAttribute(Qt::WA_DeleteOnClose);
115   GroupMakePoints->TextLabel4->setAttribute(Qt::WA_DeleteOnClose);
116   GroupMakePoints->TextLabel5->setAttribute(Qt::WA_DeleteOnClose);
117   GroupMakePoints->TextLabel6->setAttribute(Qt::WA_DeleteOnClose);
118   GroupMakePoints->SpinBox1->close();
119   GroupMakePoints->SpinBox2->close();
120   GroupMakePoints->SpinBox3->close();
121   GroupMakePoints->TextLabel4->close();
122   GroupMakePoints->TextLabel5->close();
123   GroupMakePoints->TextLabel6->close();
124
125   // Add widgets for group generation
126   QGridLayout *aLayoutGMP = (QGridLayout *)GroupMakePoints->GroupBox1->layout();
127
128   myStepByStepCheckGMP =
129     new QCheckBox(tr("GEOM_STEP_BY_STEP"), GroupMakePoints->GroupBox1);
130   myGenGroupCheckGMP   =
131     new QCheckBox(tr("GEOM_GENERATE_GROUPS"), GroupMakePoints->GroupBox1);
132   myPrefixLblGMP       =
133     new QLabel (tr("GEOM_GROUP_NAME_PREFIX"), GroupMakePoints->GroupBox1);
134   myPrefixEditGMP      = new QLineEdit(GroupMakePoints->GroupBox1);
135
136   aLayoutGMP->addWidget(myStepByStepCheckGMP, 8,  0, 1, 3);
137   aLayoutGMP->addWidget(myGenGroupCheckGMP,   9,  0, 1, 3);
138   aLayoutGMP->addWidget(myPrefixLblGMP,       10, 0, 1, 2);
139   aLayoutGMP->addWidget(myPrefixEditGMP,      10, 2);
140
141   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
142   layout->setMargin(0); layout->setSpacing(6);
143   layout->addWidget(GroupPoints);
144   layout->addWidget(GroupMakePoints);
145   /***************************************************************/
146
147   setHelpFileName("create_extrusion_alongpath_page.html");
148
149   // Initialisation
150   Init();
151 }
152
153 //=================================================================================
154 // function : ~GenerationGUI_PipeDlg()
155 // purpose  : Destroys the object and frees any allocated resources
156 //=================================================================================
157 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
158 {
159   // no need to delete child widgets, Qt does it all for us
160 }
161
162 //=================================================================================
163 // function : Init()
164 // purpose  :
165 //=================================================================================
166 void GenerationGUI_PipeDlg::Init()
167 {
168   // init variables
169   GroupPoints->LineEdit1->setReadOnly(true);
170   GroupPoints->LineEdit2->setReadOnly(true);
171   GroupPoints->LineEdit3->setReadOnly(true);
172
173   GroupPoints->LineEdit1->setText("");
174   GroupPoints->LineEdit2->setText("");
175   GroupPoints->LineEdit3->setText("");
176   myPath.nullify();
177   myVec.nullify();
178
179   GroupPoints->CheckButton1->setEnabled(false);
180
181   GroupMakePoints->LineEdit1->setReadOnly(true);
182   GroupMakePoints->LineEdit2->setReadOnly(true);
183   GroupMakePoints->LineEdit3->setReadOnly(true);
184
185   GroupMakePoints->LineEdit1->setText("");
186   GroupMakePoints->LineEdit2->setText("");
187   GroupMakePoints->LineEdit3->setText("");
188
189   showOnlyPreviewControl();
190
191   // signals and slots connections
192   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
193   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
194
195   connect(this,          SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
196
197   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
198   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
199   connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
200
201   connect(GroupPoints->CheckButton1,   SIGNAL(toggled(bool)), this, SLOT(SelectionTypeButtonClicked()));
202
203   connect(GroupMakePoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
204   connect(GroupMakePoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
205   connect(GroupMakePoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
206   connect(GroupMakePoints->CheckBox1, SIGNAL(clicked()), this, SLOT(processPreview()));
207   connect(GroupMakePoints->CheckBox2, SIGNAL(clicked()), this, SLOT(processPreview()));
208   connect(myStepByStepCheckGMP,       SIGNAL(clicked()), this, SLOT(processPreview()));
209   connect(myGenGroupCheckGP,    SIGNAL(toggled(bool)), this, SLOT(GenGroupClicked(bool)));
210   connect(myGenGroupCheckGMP,   SIGNAL(toggled(bool)), this, SLOT(GenGroupClicked(bool)));
211   connect(myStepByStepCheckGMP, SIGNAL(toggled(bool)), this, SLOT(StepByStepClicked(bool)));
212
213   initName(tr("GEOM_PIPE"));
214   resize(100,100);
215
216   GroupPoints->TextLabel3->hide();
217   GroupPoints->PushButton3->hide();
218   GroupPoints->LineEdit3->hide();
219   ConstructorsClicked(0);
220
221   GroupPoints->PushButton1->click();
222   SelectionIntoArgument();
223   updateGenGroup();
224 }
225
226 //=================================================================================
227 // function : ConstructorsClicked()
228 // purpose  : Radio button management
229 //=================================================================================
230 void GenerationGUI_PipeDlg::ConstructorsClicked( int constructorId )
231 {
232   erasePreview();
233
234   switch (constructorId) {
235   case 0:
236     GroupMakePoints->hide();
237     GroupPoints->show();
238     GroupPoints->TextLabel3->hide();
239     GroupPoints->PushButton3->hide();
240     GroupPoints->LineEdit3->hide();
241     GroupPoints->PushButton1->click();
242     myGenGroupCheckGP->setChecked(false);
243     resetGenGroup(myGenGroupCheckGP, false, true);
244     break;
245   case 1:
246     GroupMakePoints->hide();
247     GroupPoints->show();
248     GroupPoints->TextLabel3->show();
249     GroupPoints->PushButton3->show();
250     GroupPoints->LineEdit3->show();
251     GroupPoints->PushButton1->click();
252     myGenGroupCheckGP->setChecked(false);
253     resetGenGroup(myGenGroupCheckGP, false, true);
254     break;
255   case 2:
256     GroupPoints->hide();
257     GroupMakePoints->show();
258     GroupMakePoints->PushButton1->click();
259     myStepByStepCheckGMP->setChecked(false);
260     myGenGroupCheckGMP->setChecked(false);
261     resetGenGroup(myGenGroupCheckGMP, false, true);
262     break;
263   default:
264     break;
265   }
266
267   qApp->processEvents();
268   updateGeometry();
269   resize(100,100);
270
271   SelectionIntoArgument();
272   processPreview();
273 }
274
275 //=================================================================================
276 // function : SelectionBittonClicked()
277 // purpose  : Selection type Radio button management
278 //=================================================================================
279 void GenerationGUI_PipeDlg::SelectionTypeButtonClicked()
280 {
281   globalSelection();
282   if ( GroupPoints->CheckButton1->isChecked() ) {
283     localSelection( TopAbs_EDGE );
284   } else {
285     TColStd_MapOfInteger aMap;
286     aMap.Add(GEOM_COMPOUND);
287     aMap.Add(GEOM_WIRE);
288     aMap.Add(GEOM_LINE);
289     globalSelection(aMap);
290   }
291   if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
292     myEditCurrentArgument->setText("");
293     myPath.nullify();
294     updateGenGroup();
295   }
296   processPreview();
297 }
298
299 //=================================================================================
300 // function : ClickOnOk()
301 // purpose  :
302 //=================================================================================
303 void GenerationGUI_PipeDlg::ClickOnOk()
304 {
305   setIsApplyAndClose( true );
306   if (ClickOnApply())
307     ClickOnCancel();
308 }
309
310 //=================================================================================
311 // function : ClickOnApply()
312 // purpose  :
313 //=================================================================================
314 bool GenerationGUI_PipeDlg::ClickOnApply()
315 {
316   if (!onAccept())
317     return false;
318
319   initName();
320
321   return true;
322 }
323
324 //=================================================================================
325 // function : SelectionIntoArgument()
326 // purpose  : Called when selection is changed or on dialog initialization or activation
327 //=================================================================================
328 void GenerationGUI_PipeDlg::SelectionIntoArgument()
329 {
330   erasePreview();
331   myEditCurrentArgument->setText("");
332
333   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
334     myBaseObjects.clear();
335     QList<GEOM::GeomObjPtr> objects = getSelected( TopAbs_SHAPE, -1 );
336     for ( int i = 0; i < objects.count(); i++ ) {
337       GEOM::shape_type stype = objects[i]->GetMaxShapeType();
338       GEOM::shape_type maxallowed = getConstructorId() == 1 ? GEOM::FACE : GEOM::SHELL;
339       GEOM::shape_type minallowed = getConstructorId() == 1 ? GEOM::EDGE : GEOM::VERTEX;
340       if ( stype < maxallowed || stype > minallowed )
341         continue;
342       myBaseObjects << objects[i];
343     }
344     if ( !myBaseObjects.isEmpty() ) {
345       QString aName = myBaseObjects.count() > 1 ? QString( "%1_objects").arg( myBaseObjects.count() ) : GEOMBase::GetName( myBaseObjects[0].get() );
346       myEditCurrentArgument->setText( aName );
347     }
348   }
349   else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
350     QList<TopAbs_ShapeEnum> types;
351     types << TopAbs_EDGE << TopAbs_WIRE;
352     myPath = getSelected( types );
353     if ( myPath ) {
354       QString aName = GEOMBase::GetName( myPath.get() );
355       myEditCurrentArgument->setText( aName );
356       if ( getConstructorId() == 1 && !myVec )
357         GroupPoints->PushButton3->click();
358       else if ( myBaseObjects.isEmpty() )
359         GroupPoints->PushButton1->click();
360     }
361     updateGenGroup();
362   }
363   else if (myEditCurrentArgument == GroupPoints->LineEdit3) {
364     myVec = getSelected( TopAbs_EDGE );
365     if ( myVec ) {
366       QString aName = GEOMBase::GetName( myVec.get() );
367       myEditCurrentArgument->setText( aName );
368       if ( myBaseObjects.isEmpty() )
369         GroupPoints->PushButton1->click();
370       else if ( !myPath )
371         GroupPoints->PushButton2->click();
372     }
373   }
374   else if ( myEditCurrentArgument == GroupMakePoints->LineEdit1 ) {
375     QList<TopAbs_ShapeEnum> types;
376     types << TopAbs_EDGE << TopAbs_WIRE << TopAbs_FACE << TopAbs_SHELL;
377     QList<GEOM::GeomObjPtr> objects = getSelected( types, -1 );
378     GEOMBase::Synchronize( myBaseObjects, objects );
379     if ( !myBaseObjects.isEmpty() ) {
380       QString aName = myBaseObjects.count() > 1 ? QString( "%1_objects").arg( myBaseObjects.count() ) : GEOMBase::GetName( myBaseObjects[0].get() );
381       myEditCurrentArgument->setText( aName );
382     }
383   }
384   else if ( myEditCurrentArgument == GroupMakePoints->LineEdit2 ) {
385     localSelection( TopAbs_VERTEX );
386     QList<GEOM::GeomObjPtr> objects = getSelected( TopAbs_VERTEX, -1 );
387     GEOMBase::Synchronize( myLocations, objects );
388     if ( !myLocations.isEmpty() ) {
389       QString aName = myLocations.count() > 1 ? QString( "%1_objects").arg( myLocations.count() ) : GEOMBase::GetName( myLocations[0].get() );
390       myEditCurrentArgument->setText( aName );
391     }
392   }
393   else if ( myEditCurrentArgument == GroupMakePoints->LineEdit3 ) {
394     QList<TopAbs_ShapeEnum> types;
395     types << TopAbs_EDGE << TopAbs_WIRE;
396     myPath = getSelected( types );
397     if ( myPath ) {
398       QString aName = GEOMBase::GetName( myPath.get() );
399       myEditCurrentArgument->setText( aName );
400     }
401     updateGenGroup();
402   }
403
404   processPreview();
405 }
406
407 //=================================================================================
408 // function : SetEditCurrentArgument()
409 // purpose  :
410 //=================================================================================
411 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
412 {
413   QPushButton* send = (QPushButton*)sender();
414
415   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
416   globalSelection(GEOM_ALLSHAPES);
417   GroupPoints->PushButton1->setDown(false);
418   GroupPoints->PushButton2->setDown(false);
419   GroupPoints->PushButton3->setDown(false);
420   GroupPoints->LineEdit1->setEnabled(false);
421   GroupPoints->LineEdit2->setEnabled(false);
422   GroupPoints->LineEdit3->setEnabled(false);
423   if (send == GroupPoints->PushButton1) {
424     myEditCurrentArgument = GroupPoints->LineEdit1;
425     GroupPoints->CheckButton1->setEnabled(false);
426   }
427   else if (send == GroupPoints->PushButton2) {
428     myEditCurrentArgument = GroupPoints->LineEdit2;
429
430     if ( GroupPoints->CheckButton1->isChecked() ) {
431       localSelection( TopAbs_EDGE );
432     } else {
433       TColStd_MapOfInteger aMap;
434       aMap.Add(GEOM_COMPOUND);
435       aMap.Add(GEOM_WIRE);
436       aMap.Add(GEOM_LINE);
437       globalSelection(aMap);
438     }
439     GroupPoints->CheckButton1->setEnabled(true);
440   }
441   else if(send == GroupPoints->PushButton3) {
442     myEditCurrentArgument = GroupPoints->LineEdit3;
443     GroupPoints->CheckButton1->setEnabled(false);
444     localSelection(TopAbs_EDGE);
445   }
446
447   GroupMakePoints->PushButton1->setDown(false);
448   GroupMakePoints->PushButton2->setDown(false);
449   GroupMakePoints->PushButton3->setDown(false);
450   GroupMakePoints->LineEdit1->setEnabled(false);
451   GroupMakePoints->LineEdit2->setEnabled(false);
452   GroupMakePoints->LineEdit3->setEnabled(false);
453   if (send == GroupMakePoints->PushButton1) {
454     myEditCurrentArgument = GroupMakePoints->LineEdit1;
455   }
456   else if(send == GroupMakePoints->PushButton2) {
457     myEditCurrentArgument = GroupMakePoints->LineEdit2;
458   }
459   else if (send == GroupMakePoints->PushButton3) {
460     myEditCurrentArgument = GroupMakePoints->LineEdit3;
461   }
462
463   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
464           this, SLOT(SelectionIntoArgument()));
465
466   // enable line edit
467   myEditCurrentArgument->setEnabled(true);
468   myEditCurrentArgument->setFocus();
469   // after setFocus(), because it will be setDown(false) when loses focus
470   send->setDown(true);
471
472   // seems we need it only to avoid preview disappearing, caused by selection mode change
473   processPreview();
474 }
475
476 //=================================================================================
477 // function : ActivateThisDialog()
478 // purpose  :
479 //=================================================================================
480 void GenerationGUI_PipeDlg::ActivateThisDialog()
481 {
482   GEOMBase_Skeleton::ActivateThisDialog();
483   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
484            this, SLOT( SelectionIntoArgument() ) );
485
486   ConstructorsClicked(getConstructorId());
487 }
488
489 //=================================================================================
490 // function : enterEvent()
491 // purpose  : when mouse enter onto the QWidget
492 //=================================================================================
493 void GenerationGUI_PipeDlg::enterEvent (QEvent*)
494 {
495   if (!mainFrame()->GroupConstructors->isEnabled())
496     ActivateThisDialog();
497 }
498
499 //=================================================================================
500 // function : createOperation
501 // purpose  :
502 //=================================================================================
503 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
504 {
505   return getGeomEngine()->GetI3DPrimOperations();
506 }
507
508 //=================================================================================
509 // function : isValid
510 // purpose  :
511 //=================================================================================
512 bool GenerationGUI_PipeDlg::isValid (QString&)
513 {
514   bool ok = false;
515   switch ( getConstructorId() ) {
516   case 0 :
517     ok = !myBaseObjects.isEmpty() && myPath;
518     break;
519   case 1 :
520     ok = !myBaseObjects.isEmpty() && myPath && myVec;
521     break;
522   case 2 :
523     ok = !myBaseObjects.isEmpty() && ( myLocations.isEmpty() || myBaseObjects.count() == myLocations.count() ) && myPath;
524     break;
525   default:
526     break;
527   }
528   return ok;
529 }
530
531 //=================================================================================
532 // function : execute
533 // purpose  :
534 //=================================================================================
535 bool GenerationGUI_PipeDlg::execute (ObjectList& objects)
536 {
537   GEOM::ListOfGO_var aList;
538
539   GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
540   bool doGroups = !IsPreview();
541
542   myGroupObjectsMap.clear();
543
544   switch( getConstructorId() ) {
545   case 0:
546   case 1:
547     if (doGroups) {
548       doGroups = myGenGroupCheckGP->isEnabled() &&
549                  myGenGroupCheckGP->isChecked();
550     }
551
552     for (int i = 0; i < myBaseObjects.count(); i++) {
553       switch ( getConstructorId() ) {
554       case 0 :
555         aList = anOper->MakePipe(myBaseObjects[i].get(),
556                                  myPath.get(), doGroups);
557         break;
558       case 1 :
559         aList = anOper->MakePipeBiNormalAlongVector
560               (myBaseObjects[i].get(), myPath.get(), myVec.get(), doGroups);
561         break;
562       }
563
564       if (aList->length() > 0) {
565         if (doGroups) {
566           addGroups(aList);
567         }
568
569         if (!aList[0]->_is_nil()) {
570           objects.push_back(aList[0]._retn());
571         }
572       }
573     }
574     break;
575   case 2:
576     {
577       GEOM::ListOfGO_var myBaseGO = new GEOM::ListOfGO();
578       GEOM::ListOfGO_var myLocationsGO = new GEOM::ListOfGO();
579       myBaseGO->length( myBaseObjects.count() );
580       myLocationsGO->length( myLocations.count() );
581       for (int i = 0; i < myBaseObjects.count(); i++) {
582         myBaseGO[i] = myBaseObjects[i].copy();
583       }
584       for (int i = 0; i < myLocations.count(); i++) {
585         myLocationsGO[i] = myLocations[i].copy();
586       }
587
588       if (doGroups) {
589         doGroups = myGenGroupCheckGMP->isEnabled() &&
590                    myGenGroupCheckGMP->isChecked();
591       }
592
593       bool isWithContact    = GroupMakePoints->CheckBox1->isEnabled() &&
594                               GroupMakePoints->CheckBox1->isChecked();
595       bool isWithCorrection = GroupMakePoints->CheckBox2->isEnabled() &&
596                               GroupMakePoints->CheckBox2->isChecked();
597
598       aList = anOper->MakePipeWithDifferentSections
599                           (myBaseGO.in(), myLocationsGO.in(), myPath.get(),
600                            isWithContact, isWithCorrection,
601                            myStepByStepCheckGMP->isChecked(),
602                            doGroups);
603
604       if (aList->length() > 0) {
605         if (doGroups) {
606           addGroups(aList);
607         }
608
609         if (!aList[0]->_is_nil()) {
610           objects.push_back(aList[0]._retn());
611         }
612       }
613     }
614     break;
615   default:
616     break;
617   }
618   return true;
619 }
620
621 //=================================================================================
622 // function : addSubshapeToStudy
623 // purpose  : virtual method to add new SubObjects if local selection
624 //=================================================================================
625 void GenerationGUI_PipeDlg::addSubshapesToStudy()
626 {
627   GEOMBase::PublishSubObject( myPath.get() );
628   GEOMBase::PublishSubObject( myVec.get() );
629 }
630
631 //=================================================================================
632 // function : extractPrefix
633 // purpose  : redefined from GEOMBase_Helper class
634 //=================================================================================
635 bool GenerationGUI_PipeDlg::extractPrefix() const
636 {
637   return myBaseObjects.count() > 1;
638 }
639
640 //=================================================================================
641 // function : restoreSubShapes
642 // purpose  : virtual method to restore tree of argument's sub-shapes under
643 //            the resulting shape. Redefined from GEOMBase_Helper class.
644 //=================================================================================
645 void GenerationGUI_PipeDlg::restoreSubShapes(SALOMEDS::SObject_ptr theSObject)
646 {
647   QCheckBox *aGenGroupCheck = NULL;
648   QLineEdit *aPrefixEdit    = NULL;
649
650   switch (getConstructorId()) {
651   case 0 :
652   case 1 :
653     aGenGroupCheck = myGenGroupCheckGP;
654     aPrefixEdit    = myPrefixEditGP;
655     break;
656   case 2 :
657     aGenGroupCheck = myGenGroupCheckGMP;
658     aPrefixEdit    = myPrefixEditGMP;
659     break;
660   default:
661     break;
662   }
663
664   if (aGenGroupCheck == NULL || !aGenGroupCheck->isChecked()) {
665     return;
666   }
667
668   // get Object from SObject
669   GEOM::GEOM_Object_var aFather = GEOM::GEOM_Object::_narrow
670             (theSObject->GetObject());
671
672   if (CORBA::is_nil(aFather)) {
673     return;
674   }
675
676   ObjectMap::const_iterator anIter    =
677     myGroupObjectsMap.find(aFather->GetEntry());
678   QString                   aPrefix   = aPrefixEdit->text();
679   bool                      hasPrefix = !aPrefix.isEmpty();
680
681   if (anIter != myGroupObjectsMap.end()) {
682     QList<GEOM::GeomObjPtr>::const_iterator it = anIter->second.begin();
683
684     for (; it != anIter->second.end(); it++) {
685       // Compose the name
686       QString aName;
687
688       if (hasPrefix) {
689         aName = aPrefix + "_";
690       }
691
692       aName += tr((*it)->GetName());
693       getGeomEngine()->AddInStudy((*it).get(), aName.toStdString().c_str(), aFather);
694     }
695   }
696 }
697
698 //=================================================================================
699 // function : getSourceObjects
700 // purpose  : virtual method to get source objects
701 //=================================================================================
702 QList<GEOM::GeomObjPtr> GenerationGUI_PipeDlg::getSourceObjects()
703 {
704   QList<GEOM::GeomObjPtr> res(myBaseObjects);
705   res << myPath << myVec;
706   for (int i = 0; i < myLocations.count(); i++)
707     res << myLocations[i];
708   return res;
709 }
710
711 //=================================================================================
712 // function : GenGroupClicked
713 // purpose  : Slot to treat checking "Generate groups" check box.
714 //=================================================================================
715 void GenerationGUI_PipeDlg::GenGroupClicked(bool isChecked)
716 {
717   resetGenGroup((QCheckBox *)sender(), isChecked, false);
718 }
719
720 //=================================================================================
721 // function : StepByStepClicked
722 // purpose  : Slot to treat checking "Step-by-step generation" check box.
723 //=================================================================================
724 void GenerationGUI_PipeDlg::StepByStepClicked(bool isChecked)
725 {
726   GroupMakePoints->CheckBox1->setEnabled(!isChecked);
727   GroupMakePoints->CheckBox2->setEnabled(!isChecked);
728 }
729
730 //=================================================================================
731 // function : updateGenGroup
732 // purpose  : Update "Generate groups" widgets depending on the path.
733 //=================================================================================
734 void GenerationGUI_PipeDlg::updateGenGroup()
735 {
736   bool isEnable = true;
737
738   if (myPath) {
739     // Check if the path is closed.
740     TopoDS_Shape aShapePath;
741
742     if (GEOMBase::GetShape(myPath.get(), aShapePath)) {
743       isEnable = GEOMUtils::IsOpenPath(aShapePath);
744     }
745   }
746
747   QCheckBox *aGenGroupCheck = NULL;
748
749   switch (getConstructorId()) {
750   case 0 :
751   case 1 :
752     aGenGroupCheck = myGenGroupCheckGP;
753     break;
754   case 2 :
755     aGenGroupCheck = myGenGroupCheckGMP;
756     break;
757   default:
758     break;
759   }
760
761   if (aGenGroupCheck != NULL) {
762     const bool isChecked = aGenGroupCheck->isChecked();
763
764     aGenGroupCheck->setEnabled(isEnable);
765     resetGenGroup(aGenGroupCheck, isEnable && isChecked, false);
766   }
767 }
768
769 //=================================================================================
770 // function : resetGenGroup
771 // purpose  : Resets data of "Generate groups" widgets.
772 //=================================================================================
773 void GenerationGUI_PipeDlg::resetGenGroup(QCheckBox  *theGenGroup,
774                                           const bool  isChecked,
775                                           const bool  isClearPrefix)
776 {
777   QLabel    *aPrefixLbl  = NULL;
778   QLineEdit *aPrefixEdit = NULL;
779
780   if (theGenGroup == myGenGroupCheckGP) {
781     aPrefixLbl  = myPrefixLblGP;
782     aPrefixEdit = myPrefixEditGP;
783   } else if (theGenGroup == myGenGroupCheckGMP) {
784     aPrefixLbl  = myPrefixLblGMP;
785     aPrefixEdit = myPrefixEditGMP;
786   }
787
788   if (aPrefixLbl != NULL) {
789     aPrefixLbl->setEnabled(isChecked);
790     aPrefixEdit->setEnabled(isChecked);
791
792     if (isClearPrefix) {
793       aPrefixEdit->setText("");
794     }
795   }
796 }
797
798 //=================================================================================
799 // function : addGroups
800 // purpose  : Add result groups to the list of groups.
801 //=================================================================================
802 void GenerationGUI_PipeDlg::addGroups(GEOM::ListOfGO_var &theResult)
803 {
804   const int aNbObj = theResult->length();
805
806   if (aNbObj > 0) {
807     if (!theResult[0]->_is_nil()) {
808       QString anEntry = theResult[0]->GetEntry();
809       int     i;
810
811       for (i = 1; i < aNbObj; ++i) {
812         if (!theResult[i]->_is_nil()) {
813           myGroupObjectsMap[anEntry].append(GEOM::GeomObjPtr(theResult[i]));
814         }
815       }
816     }
817   }
818 }