Salome HOME
Additional fix for the issue "16219: EDF PAL 469: "RemoveFromStudy" Function": dump...
[modules/geom.git] / src / AdvancedGUI / AdvancedGUI_PipeTShapeDlg.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "AdvancedGUI_PipeTShapeDlg.h"
21
22 #include <DlgRef.h>
23 #include <GeometryGUI.h>
24 #include <GEOMBase.h>
25
26 #include <SUIT_Session.h>
27 #include <SUIT_ResourceMgr.h>
28 #include <SUIT_OverrideCursor.h>
29 #include <SalomeApp_Application.h>
30 #include <SalomeApp_Tools.h>
31 #include <LightApp_SelectionMgr.h>
32
33 // OCCT Includes
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS.hxx>
36 #include <TopExp.hxx>
37 #include <TColStd_IndexedMapOfInteger.hxx>
38 #include <TopTools_IndexedMapOfShape.hxx>
39 #include <gp_Pnt.hxx>
40 #include <BRep_Tool.hxx>
41
42 #include <GEOMImpl_Types.hxx>
43
44 //=================================================================================
45 // Constructor
46 //=================================================================================
47 AdvancedGUI_PipeTShapeDlg::AdvancedGUI_PipeTShapeDlg(GeometryGUI* theGeometryGUI, QWidget* parent) :
48         GEOMBase_Skeleton(theGeometryGUI, parent, false) {
49         QPixmap imageOp(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPETSHAPE")));
50         QPixmap imageSel(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
51         imageImp = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICO_PIPETSHAPE_IMPORT"));
52         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE"));
53
54         setWindowTitle(tr("GEOM_PIPE_TSHAPE_TITLE"));
55
56         /***************************************************************/
57         mainFrame()->GroupConstructors->setTitle(tr("GEOM_PIPE_TSHAPE"));
58         mainFrame()->RadioButton1->setIcon(imageOp);
59         mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
60         mainFrame()->RadioButton2->close();
61         mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
62         mainFrame()->RadioButton3->close();
63
64         QGridLayout* myMainLayout = new QGridLayout(centralWidget());
65         myMainLayout->setMargin(0);
66         myMainLayout->setSpacing(6);
67
68     tshapeScreenShotLabel = new QLabel();
69     tshapeScreenShotLabel->setSizePolicy(QSizePolicy::Expanding,
70                                          QSizePolicy::Expanding);
71     tshapeScreenShotLabel->setAlignment(Qt::AlignCenter);
72     tshapeScreenShotLabel->setMinimumSize(100, 100);
73
74         MainTubeGroupParams = new DlgRef_3Spin();
75         MainTubeGroupParams->GroupBox1->setTitle(tr("GEOM_PIPE_TSHAPE_MPIPE"));
76         MainTubeGroupParams->TextLabel1->setText(tr("GEOM_PIPE_TSHAPE_R"));
77         MainTubeGroupParams->TextLabel2->setText(tr("GEOM_PIPE_TSHAPE_W"));
78         MainTubeGroupParams->TextLabel3->setText(tr("GEOM_PIPE_TSHAPE_L"));
79
80         IncidentTubeGroupParams = new DlgRef_3Spin();
81         IncidentTubeGroupParams->GroupBox1->setTitle(tr("GEOM_PIPE_TSHAPE_IPIPE"));
82         IncidentTubeGroupParams->TextLabel1->setText(tr("GEOM_PIPE_TSHAPE_R"));
83         IncidentTubeGroupParams->TextLabel2->setText(tr("GEOM_PIPE_TSHAPE_W"));
84         IncidentTubeGroupParams->TextLabel3->setText(tr("GEOM_PIPE_TSHAPE_L"));
85
86         ChamferGroupParams = new DlgRef_2Spin();
87         ChamferGroupParams->GroupBox1->setCheckable(true);
88         ChamferGroupParams->GroupBox1->setChecked(false);
89         ChamferGroupParams->GroupBox1->setTitle(tr("GEOM_PIPE_TSHAPE_CHAMFER"));
90         ChamferGroupParams->TextLabel1->setText(tr("GEOM_PIPE_TSHAPE_CHAMFER_H"));
91         ChamferGroupParams->TextLabel2->setText(tr("GEOM_PIPE_TSHAPE_CHAMFER_W"));
92
93         FilletGroupParams = new DlgRef_1Spin();
94         FilletGroupParams->GroupBox1->setCheckable(true);
95         FilletGroupParams->GroupBox1->setChecked(false);
96         FilletGroupParams->GroupBox1->setTitle(tr("GEOM_PIPE_TSHAPE_FILLET"));
97         FilletGroupParams->TextLabel1->setText(tr("GEOM_PIPE_TSHAPE_R"));
98
99         HexMeshCheckBox = new QCheckBox();
100         HexMeshCheckBox->setText(tr("GEOM_PIPE_TSHAPE_HEX"));
101         HexMeshCheckBox->setChecked(true);
102
103         JunctionPointsSel = new DlgRef_6Sel();
104         JunctionPointsSel->GroupBox1->setTitle(tr("GEOM_PIPE_TSHAPE_POSITION"));
105         JunctionPointsSel->GroupBox1->setCheckable(true);
106         JunctionPointsSel->GroupBox1->setChecked(false);
107         JunctionPointsSel->PushButton1->setIcon(imageSel);
108         JunctionPointsSel->LineEdit1->setReadOnly(true);
109         JunctionPointsSel->LineEdit1->setText("");
110         JunctionPointsSel->TextLabel1->setText(tr("GEOM_PIPE_TSHAPE_POSITION_P1"));
111
112         JunctionPointsSel->PushButton2->setIcon(imageSel);
113         JunctionPointsSel->LineEdit2->setReadOnly(true);
114         JunctionPointsSel->LineEdit2->setText("");
115         JunctionPointsSel->TextLabel2->setText(tr("GEOM_PIPE_TSHAPE_POSITION_P2"));
116
117         JunctionPointsSel->PushButton3->setIcon(imageSel);
118         JunctionPointsSel->LineEdit3->setReadOnly(true);
119         JunctionPointsSel->LineEdit3->setText("");
120         JunctionPointsSel->TextLabel3->setText(tr("GEOM_PIPE_TSHAPE_POSITION_P3"));
121
122     JunctionPointsSel->PushButton4->setIcon(imageImp);
123     JunctionPointsSel->LineEdit4->setReadOnly(true);
124     JunctionPointsSel->LineEdit4->setText("");
125     JunctionPointsSel->TextLabel4->setText(tr("GEOM_PIPE_TSHAPE_POSITION_LBL_L1"));
126
127     JunctionPointsSel->PushButton5->setIcon(imageImp);
128     JunctionPointsSel->LineEdit5->setReadOnly(true);
129     JunctionPointsSel->LineEdit5->setText("");
130     JunctionPointsSel->TextLabel5->setText(tr("GEOM_PIPE_TSHAPE_POSITION_LBL_L2"));
131
132     JunctionPointsSel->PushButton6->setAttribute(Qt::WA_DeleteOnClose);
133     JunctionPointsSel->PushButton6->close();
134     JunctionPointsSel->LineEdit6->setAttribute(Qt::WA_DeleteOnClose);
135     JunctionPointsSel->LineEdit6->close();
136     JunctionPointsSel->TextLabel6->setAttribute(Qt::WA_DeleteOnClose);
137     JunctionPointsSel->TextLabel6->close();
138
139         // 1st row, height = 1, colspan = 3
140         int rowPict = 0, colPict = 0, rowspanPict = 1, colspanPict = 3;
141         // 2nd row, height = 4, col 1
142         int rowMain = rowspanPict,                           colMain = 0,      rowspanMain = 2,      colspanMain = 1;
143         int rowCham = rowspanPict + rowspanMain,             colCham = 0,      rowspanCham = 2,      colspanCham = 1;
144         // 2nd row, height = 4, col 2
145         int rowInc = rowspanPict,                            colInc  = 1,      rowspanInc = 2,       colspanInc = 1;
146         int rowFill = rowspanPict + rowspanInc,              colFill = 1,      rowspanFill = 1,      colspanFill = 1;
147         int rowHex = rowspanPict + rowspanInc + rowspanFill, colHex  = 1,      rowspanHex = 1,       colspanHex = 1;
148         // 2nd row, height = 4, col 3
149         int rowNewPosVal = rowspanPict,                      colNewPosVal = 2, rowspanNewPosVal = 4, colspanNewPosVal = 1;
150
151     myMainLayout->addWidget(tshapeScreenShotLabel, rowPict, colPict, rowspanPict, colspanPict);
152
153         myMainLayout->addWidget(MainTubeGroupParams, rowMain, colMain, rowspanMain, colspanMain);
154         myMainLayout->addWidget(FilletGroupParams, rowFill, colFill, rowspanFill, colspanFill);
155         myMainLayout->addWidget(HexMeshCheckBox, rowHex, colHex, rowspanHex, colspanHex);
156
157         myMainLayout->addWidget(IncidentTubeGroupParams, rowInc, colInc, rowspanInc, colspanInc);
158         myMainLayout->addWidget(ChamferGroupParams, rowCham, colCham, rowspanCham, colspanCham);
159
160         myMainLayout->addWidget(JunctionPointsSel, rowNewPosVal, colNewPosVal, rowspanNewPosVal, colspanNewPosVal);
161         /***************************************************************/
162
163         setHelpFileName("create_pipetshape_page.html");
164
165         Init();
166 }
167
168 //=================================================================================
169 // Destructor
170 //=================================================================================
171 AdvancedGUI_PipeTShapeDlg::~AdvancedGUI_PipeTShapeDlg() {
172         // no need to delete child widgets, Qt does it all for us
173 }
174
175 //=================================================================================
176 // function : Init()
177 // purpose  :
178 //=================================================================================
179 void AdvancedGUI_PipeTShapeDlg::Init() {
180         // Get setting of step value from file configuration
181         SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
182         double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
183
184         myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
185         myOkPoint1 = myOkPoint2 = myOkPoint3 = false;
186
187         pipeTShapeGroupObjects.clear();
188
189         // min, max, step and decimals for spin boxes
190         initSpinBox(MainTubeGroupParams->SpinBox_DX, Precision::Approximation(), COORD_MAX, step, "length_precision");
191         initSpinBox(MainTubeGroupParams->SpinBox_DY, Precision::Approximation(), COORD_MAX, step, "length_precision");
192         initSpinBox(MainTubeGroupParams->SpinBox_DZ, Precision::Approximation(), COORD_MAX, step, "length_precision");
193         initSpinBox(IncidentTubeGroupParams->SpinBox_DX, Precision::Approximation(), COORD_MAX, step, "length_precision");
194         initSpinBox(IncidentTubeGroupParams->SpinBox_DY, Precision::Approximation(), COORD_MAX, step, "length_precision");
195         initSpinBox(IncidentTubeGroupParams->SpinBox_DZ, Precision::Approximation(), COORD_MAX, step, "length_precision");
196         initSpinBox(ChamferGroupParams->SpinBox_DX, Precision::Approximation(), COORD_MAX, step, "length_precision");
197         initSpinBox(ChamferGroupParams->SpinBox_DY, Precision::Approximation(), COORD_MAX, step, "length_precision");
198         initSpinBox(FilletGroupParams->SpinBox_DX, Precision::Approximation(), COORD_MAX, step, "length_precision");
199
200         // init variables
201         MainTubeGroupParams->SpinBox_DX->setValue(80);
202         MainTubeGroupParams->SpinBox_DY->setValue(20);
203         MainTubeGroupParams->SpinBox_DZ->setValue(200);
204         IncidentTubeGroupParams->SpinBox_DX->setValue(50);
205         IncidentTubeGroupParams->SpinBox_DY->setValue(20);
206         IncidentTubeGroupParams->SpinBox_DZ->setValue(200);
207         ChamferGroupParams->SpinBox_DX->setValue(20);
208         ChamferGroupParams->SpinBox_DY->setValue(10);
209         FilletGroupParams->SpinBox_DX->setValue(20);
210
211     CssNormal = QString("QDoubleSpinBox {");
212     CssNormal.append(MainTubeGroupParams->SpinBox_DZ->styleSheet());
213     CssNormal.append("}");
214     CssNormal.append("\nQPushButton {");
215     CssNormal.append(JunctionPointsSel->PushButton4->styleSheet());
216     CssNormal.append("}");
217     CssAcceptable = "QDoubleSpinBox, QPushButton {background-color: rgb(85, 170, 127)}";
218     CssRefused = "QDoubleSpinBox, QPushButton {background-color: rgb(255, 0, 0)}";
219
220     showOnlyPreviewControl();
221
222         // Signal/slot connections
223         connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
224         connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
225         connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
226         // ValueChangedInSpinBox
227         connect(MainTubeGroupParams->SpinBox_DX, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
228         connect(MainTubeGroupParams->SpinBox_DY, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
229         connect(MainTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
230         connect(IncidentTubeGroupParams->SpinBox_DX, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
231         connect(IncidentTubeGroupParams->SpinBox_DY, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
232         connect(IncidentTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
233         connect(ChamferGroupParams->SpinBox_DX, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
234         connect(ChamferGroupParams->SpinBox_DY, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
235         connect(FilletGroupParams->SpinBox_DX, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
236         // ChamferOrFillet
237         connect(ChamferGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, SLOT(ChamferOrFillet(bool)));
238         connect(FilletGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, SLOT(ChamferOrFillet(bool)));
239         // Preview
240 //      connect(PreviewPushButton, SIGNAL(clicked()), this, SLOT(DisplayPreview()));
241         // Position
242         connect(JunctionPointsSel->GroupBox1, SIGNAL(toggled(bool)), this, SLOT(SetPosition(bool)));
243         connect(JunctionPointsSel->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
244         connect(JunctionPointsSel->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
245         connect(JunctionPointsSel->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
246     // ApplyNewDimensions
247     connect(JunctionPointsSel->PushButton4, SIGNAL(clicked()), this, SLOT(ApplyNewDimensions()));
248     connect(JunctionPointsSel->PushButton5, SIGNAL(clicked()), this, SLOT(ApplyNewDimensions()));
249         connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(UpdatePicture(QWidget*, QWidget*)));
250         //@@ put additional signal/slot connections here @@//
251
252         initName(tr("GEOM_PIPE_TSHAPE"));
253     updateTshapeScreenshotLabel();
254     processPreview();
255 }
256
257 //=================================================================================
258 // function : ApplyNewDimensions()
259 // purpose  :
260 //=================================================================================
261 void AdvancedGUI_PipeTShapeDlg::ApplyNewDimensions() {
262     QPushButton* send = (QPushButton*) sender();
263
264     bool ok = false;
265     double newVal;
266     if (send == JunctionPointsSel->PushButton4) {
267         if (!JunctionPointsSel->LineEdit4->text().isEmpty()) {
268             newVal = JunctionPointsSel->LineEdit4->text().toDouble(&ok);
269             if (ok) {
270                 disconnect(MainTubeGroupParams->SpinBox_DZ, 0, this, 0);
271                 MainTubeGroupParams->SpinBox_DZ->setValue(newVal);
272                 connect(MainTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
273                 MainTubeGroupParams->SpinBox_DZ->setToolTip("");
274                 MainTubeGroupParams->SpinBox_DZ->setStyleSheet("background-color: rgb(255, 255, 255);");
275                 CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
276                 processPreview();
277             }
278         }
279     }
280     else if (send == JunctionPointsSel->PushButton5) {
281         if (!JunctionPointsSel->LineEdit5->text().isEmpty()) {
282             newVal = JunctionPointsSel->LineEdit5->text().toDouble(&ok);
283             if (ok) {
284                 disconnect(IncidentTubeGroupParams->SpinBox_DZ, 0, this, 0);
285                 IncidentTubeGroupParams->SpinBox_DZ->setValue(newVal);
286                 connect(IncidentTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
287                 IncidentTubeGroupParams->SpinBox_DZ->setToolTip("");
288                 IncidentTubeGroupParams->SpinBox_DZ->setStyleSheet("background-color: rgb(255, 255, 255);");
289                 CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
290                 processPreview();
291             }
292         }
293     }
294 }
295
296 //=================================================================================
297 // function : UpdatePicture()
298 // purpose  :
299 //=================================================================================
300 void AdvancedGUI_PipeTShapeDlg::UpdatePicture(QWidget* old, QWidget* now) {
301
302         if (ChamferGroupParams->GroupBox1->isChecked())
303                 if (now == MainTubeGroupParams->SpinBox_DX)
304                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_R1"));
305                 else if (now == MainTubeGroupParams->SpinBox_DY)
306                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_W1"));
307                 else if (now == MainTubeGroupParams->SpinBox_DZ)
308                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_L1"));
309                 else if (now == IncidentTubeGroupParams->SpinBox_DX)
310                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_R2"));
311                 else if (now == IncidentTubeGroupParams->SpinBox_DY)
312                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_W2"));
313                 else if (now == IncidentTubeGroupParams->SpinBox_DZ)
314                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_L2"));
315                 else if (now == ChamferGroupParams->SpinBox_DX)
316                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_H"));
317                 else if (now == ChamferGroupParams->SpinBox_DY)
318                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_W"));
319                 else
320                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER"));
321         else if (FilletGroupParams->GroupBox1->isChecked())
322                 if (now == MainTubeGroupParams->SpinBox_DX)
323                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_R1"));
324                 else if (now == MainTubeGroupParams->SpinBox_DY)
325                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_W1"));
326                 else if (now == MainTubeGroupParams->SpinBox_DZ)
327                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_L1"));
328                 else if (now == IncidentTubeGroupParams->SpinBox_DX)
329                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_R2"));
330                 else if (now == IncidentTubeGroupParams->SpinBox_DY)
331                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_W2"));
332                 else if (now == IncidentTubeGroupParams->SpinBox_DZ)
333                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_L2"));
334                 else if (now == FilletGroupParams->SpinBox_DX)
335                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_RF"));
336                 else
337                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET"));
338         else
339                 if (now == MainTubeGroupParams->SpinBox_DX)
340                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_R1"));
341                 else if (now == MainTubeGroupParams->SpinBox_DY)
342                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_W1"));
343                 else if (now == MainTubeGroupParams->SpinBox_DZ)
344                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_L1"));
345                 else if (now == IncidentTubeGroupParams->SpinBox_DX)
346                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_R2"));
347                 else if (now == IncidentTubeGroupParams->SpinBox_DY)
348                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_W2"));
349                 else if (now == IncidentTubeGroupParams->SpinBox_DZ)
350                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_L2"));
351                 else
352                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE"));
353
354     updateTshapeScreenshotLabel();
355 }
356
357 //=================================================================================
358 // function : SetPosition()
359 // purpose  :
360 //=================================================================================
361 void AdvancedGUI_PipeTShapeDlg::SetPosition(bool isChecked) {
362         if (isChecked) {
363                 erasePreview();
364         JunctionPointsSel->LineEdit4->setText("");
365         JunctionPointsSel->LineEdit5->setText("");
366 //              connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(
367 //                              SelectionIntoArgument()));
368                 JunctionPointsSel->PushButton1->click();
369                 SelectionIntoArgument();
370         } else {
371                 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
372                 JunctionPointsSel->LineEdit4->setText("");
373                 JunctionPointsSel->LineEdit5->setText("");
374                 processPreview();
375         }
376 }
377
378 //=================================================================================
379 // function : ValueChangedInSpinBox()
380 // purpose  :
381 //=================================================================================
382 void AdvancedGUI_PipeTShapeDlg::ValueChangedInSpinBox(double newValue)
383 {
384     if (JunctionPointsSel->GroupBox1->isChecked() && myOkPoint1 && myOkPoint2 && myOkPoint3)
385         CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
386     processPreview();
387 }
388
389 //=================================================================================
390 // function : SelectionIntoArgument()
391 // purpose  : Called when selection as changed or other case
392 //=================================================================================
393 void AdvancedGUI_PipeTShapeDlg::SelectionIntoArgument() {
394
395         erasePreview();
396 //      myEditCurrentArgument->setText("");
397
398         LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
399         SALOME_ListIO aSelList;
400         aSelMgr->selectedObjects(aSelList);
401
402         if (aSelList.Extent() != 1) {
403                 if (myEditCurrentArgument == JunctionPointsSel->LineEdit1)
404                         myOkPoint1 = false;
405                 else if (myEditCurrentArgument == JunctionPointsSel->LineEdit2)
406                         myOkPoint2 = false;
407                 else if (myEditCurrentArgument == JunctionPointsSel->LineEdit3)
408                         myOkPoint3 = false;
409                 return;
410                 myEditCurrentArgument->setText("");
411         }
412
413         // nbSel == 1
414         if (aSelList.Extent() == 1) {
415                 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
416                 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(anIO);
417                 if (!CORBA::is_nil(aSelectedObject)) {
418                         QString aName = GEOMBase::GetName(aSelectedObject);
419                         TopoDS_Shape aShape;
420                         if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) {
421
422                                 TColStd_IndexedMapOfInteger aMap;
423                                 aSelMgr->GetIndexes(anIO, aMap);
424                                 if (aMap.Extent() == 1) { // Local Selection
425                                         int anIndex = aMap(1);
426                                         aName += QString(":vertex_%1").arg(anIndex);
427
428                                         //Find SubShape Object in Father
429                                         GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
430
431                                         if (aFindedObject->_is_nil()) { // Object not found in study
432                                                 GEOM::GEOM_IShapesOperations_var aShapesOp =
433                                                                 getGeomEngine()->GetIShapesOperations(getStudyId());
434                                                 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
435                                         } else {
436                                                 aSelectedObject = aFindedObject; // get Object from study
437                                         }
438                                         GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE);
439                                 } else { // Global Selection
440                                         if (aShape.ShapeType() != TopAbs_VERTEX) {
441                                                 aSelectedObject = GEOM::GEOM_Object::_nil();
442                                                 aName = "";
443                                         }
444                                 }
445                         }
446
447                         if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX) {
448                                 return;
449                         }
450                         myEditCurrentArgument->setText(aName);
451                         if (myEditCurrentArgument == JunctionPointsSel->LineEdit1) {
452                                 myPoint1 = aSelectedObject;
453                                 myOkPoint1 = true;
454                                 if (!myOkPoint2)
455                                         JunctionPointsSel->PushButton2->click();
456                         } else if (myEditCurrentArgument == JunctionPointsSel->LineEdit2) {
457                                 myPoint2 = aSelectedObject;
458                                 myOkPoint2 = true;
459                                 if (!myOkPoint3)
460                                         JunctionPointsSel->PushButton3->click();
461                         } else if (myEditCurrentArgument == JunctionPointsSel->LineEdit3) {
462                                 myPoint3 = aSelectedObject;
463                                 myOkPoint3 = true;
464                                 if (!myOkPoint1)
465                                         JunctionPointsSel->PushButton1->click();
466                         }
467                 }
468         }
469
470         if (myOkPoint1 && myOkPoint2 && myOkPoint3) {
471         CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
472         processPreview();
473     }
474
475 //      GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First());
476 //      if (aSelectedObject->_is_nil())
477 //              return;
478 //
479 //      myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject));
480 //
481 //      // clear selection
482 //      disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
483 //      myGeomGUI->getApp()->selectionMgr()->clearSelected();
484 //      connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
485 //
486 //      if (myEditCurrentArgument == JunctionPointsSel->LineEdit1) {
487 //              myPoint1 = aSelectedObject;
488 //              myOkPoint1 = true;
489 //              if (!myOkPoint2)
490 //                      JunctionPointsSel->PushButton2->click();
491 //              //                      P2GroupParams->PushButton1->click();
492 //      } else if (myEditCurrentArgument == JunctionPointsSel->LineEdit2) {
493 //              //      } else if (myEditCurrentArgument == P2GroupParams->LineEdit1) {
494 //              myPoint2 = aSelectedObject;
495 //              myOkPoint2 = true;
496 //              if (!myOkPoint3)
497 //                      JunctionPointsSel->PushButton3->click();
498 //              //                      P3GroupParams->PushButton1->click();
499 //      } else if (myEditCurrentArgument == JunctionPointsSel->LineEdit3) {
500 //              //      } else if (myEditCurrentArgument == P3GroupParams->LineEdit1) {
501 //              myPoint3 = aSelectedObject;
502 //              myOkPoint3 = true;
503 //              if (!myOkPoint1)
504 //                      JunctionPointsSel->PushButton1->click();
505 //      }
506 }
507
508 //=================================================================================
509 // function : SetEditCurrentArgument()
510 // purpose  :
511 //=================================================================================
512 void AdvancedGUI_PipeTShapeDlg::SetEditCurrentArgument() {
513         QPushButton* send = (QPushButton*) sender();
514
515         if (send == JunctionPointsSel->PushButton1) {
516                 myEditCurrentArgument = JunctionPointsSel->LineEdit1;
517                 JunctionPointsSel->PushButton2->setDown(false);
518                 JunctionPointsSel->LineEdit2->setEnabled(false);
519                 JunctionPointsSel->PushButton3->setDown(false);
520                 JunctionPointsSel->LineEdit3->setEnabled(false);
521         } else if (send == JunctionPointsSel->PushButton2) {
522                 myEditCurrentArgument = JunctionPointsSel->LineEdit2;
523                 JunctionPointsSel->PushButton1->setDown(false);
524                 JunctionPointsSel->LineEdit1->setEnabled(false);
525                 JunctionPointsSel->PushButton3->setDown(false);
526                 JunctionPointsSel->LineEdit3->setEnabled(false);
527         } else if (send == JunctionPointsSel->PushButton3) {
528                 myEditCurrentArgument = JunctionPointsSel->LineEdit3;
529                 JunctionPointsSel->PushButton1->setDown(false);
530                 JunctionPointsSel->LineEdit1->setEnabled(false);
531                 JunctionPointsSel->PushButton2->setDown(false);
532                 JunctionPointsSel->LineEdit2->setEnabled(false);
533         }
534
535         // enable line edit
536         myEditCurrentArgument->setEnabled(true);
537         myEditCurrentArgument->setFocus();
538         myEditCurrentArgument->setText("");
539         // after setFocus(), because it will be setDown(false) when loses focus
540         send->setDown(true);
541
542     JunctionPointsSel->LineEdit4->setText("");
543     JunctionPointsSel->LineEdit5->setText("");
544
545         disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
546 //      globalSelection(GEOM_POINT);
547     globalSelection(); // close local contexts, if any
548     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
549         connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
550 }
551
552 //=================================================================================
553 // function : SetDoubleSpinBoxStep()
554 // purpose  : Double spin box management
555 //=================================================================================
556 void AdvancedGUI_PipeTShapeDlg::SetDoubleSpinBoxStep(double step) {
557         MainTubeGroupParams->SpinBox_DX->setSingleStep(step);
558         MainTubeGroupParams->SpinBox_DY->setSingleStep(step);
559         MainTubeGroupParams->SpinBox_DZ->setSingleStep(step);
560         IncidentTubeGroupParams->SpinBox_DX->setSingleStep(step);
561         IncidentTubeGroupParams->SpinBox_DY->setSingleStep(step);
562         IncidentTubeGroupParams->SpinBox_DZ->setSingleStep(step);
563         ChamferGroupParams->SpinBox_DX->setSingleStep(step);
564         ChamferGroupParams->SpinBox_DY->setSingleStep(step);
565         FilletGroupParams->SpinBox_DX->setSingleStep(step);
566 }
567
568 //=================================================================================
569 // function : ClickOnOk()
570 // purpose  :
571 //=================================================================================
572 void AdvancedGUI_PipeTShapeDlg::ClickOnOk() {
573   setIsApplyAndClose( true );
574         if (ClickOnApply())
575                 ClickOnCancel();
576 }
577
578 //=================================================================================
579 // function : ClickOnApply()
580 // purpose  :
581 //=================================================================================
582 bool AdvancedGUI_PipeTShapeDlg::ClickOnApply() {
583         if (!onAccept())
584                 return false;
585
586         initName();
587
588         return true;
589 }
590
591 //=================================================================================
592 // function : ActivateThisDialog()
593 // purpose  :
594 //=================================================================================
595 void AdvancedGUI_PipeTShapeDlg::ActivateThisDialog() {
596         GEOMBase_Skeleton::ActivateThisDialog();
597         //      globalSelection( GEOM_POINT);
598         //      connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(
599         //                      currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
600     if (myOkPoint1 && myOkPoint2 && myOkPoint3)
601         CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
602     processPreview();
603 }
604
605 //=================================================================================
606 // function : enterEvent [REDEFINED]
607 // purpose  :
608 //=================================================================================
609 void AdvancedGUI_PipeTShapeDlg::enterEvent(QEvent*) {
610         if (!mainFrame()->GroupConstructors->isEnabled())
611                 ActivateThisDialog();
612 }
613
614 //=================================================================================
615 // function : resizeEvent [REDEFINED]
616 // purpose  :
617 //=================================================================================
618 void AdvancedGUI_PipeTShapeDlg::resizeEvent(QResizeEvent */*event*/) {
619     QSize scaledSize = imagePipeTShape.size();
620     scaledSize.scale(tshapeScreenShotLabel->size(), Qt::KeepAspectRatio);
621     if (!tshapeScreenShotLabel->pixmap()
622       || scaledSize != tshapeScreenShotLabel->pixmap()->size())
623         updateTshapeScreenshotLabel();
624 }
625
626 //=================================================================================
627 // function : updateTshapeScreenshotLabel
628 // purpose  :
629 //=================================================================================
630 void AdvancedGUI_PipeTShapeDlg::updateTshapeScreenshotLabel() {
631     tshapeScreenShotLabel->setPixmap(imagePipeTShape.scaled(tshapeScreenShotLabel->size(),
632                                                       Qt::KeepAspectRatio,
633                                                       Qt::SmoothTransformation));
634 }
635
636 //=================================================================================
637 // function : ChamferOrFillet()
638 // purpose  :
639 //=================================================================================
640 void AdvancedGUI_PipeTShapeDlg::ChamferOrFillet(bool) {
641         QGroupBox* send = (QGroupBox*) sender();
642
643         if (send == ChamferGroupParams->GroupBox1) {
644                 if (send->isChecked()) {
645                         disconnect(FilletGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, 0);
646                         FilletGroupParams->GroupBox1->setChecked(false);
647                         connect(FilletGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, SLOT(ChamferOrFillet(bool)));
648                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER"));
649                 }
650                 else
651                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE"));
652         updateTshapeScreenshotLabel();
653         if (myOkPoint1 && myOkPoint2 && myOkPoint3)
654             CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
655                 processPreview();
656         } else if (send == FilletGroupParams->GroupBox1) {
657                 if (send->isChecked()) {
658                         disconnect(ChamferGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, 0);
659                         ChamferGroupParams->GroupBox1->setChecked(!send->isChecked());
660                         connect(ChamferGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, SLOT(ChamferOrFillet(bool)));
661                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET"));
662                 }
663                 else
664                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE"));
665         updateTshapeScreenshotLabel();
666         if (myOkPoint1 && myOkPoint2 && myOkPoint3)
667             CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
668                 processPreview();
669         }
670
671 }
672
673 //=================================================================================
674 // function : DisplayPreview()
675 // purpose  :
676 //=================================================================================
677 void AdvancedGUI_PipeTShapeDlg::DisplayPreview(const bool activate, const bool update, const bool toRemoveFromEngine,
678                 const double lineWidth, const int displayMode, const int color) {
679         isPreview = true;
680         QString msg;
681         if (!isValid(msg)) {
682                 erasePreview(update);
683                 isPreview = false;
684                 return;
685         }
686
687         erasePreview(false);
688
689         try {
690                 SUIT_OverrideCursor wc;
691                 ObjectList objects;
692                 bool hexMeshState = HexMeshCheckBox->isChecked();
693                 HexMeshCheckBox->setChecked(false);
694                 if (!executeNoCheck(objects) || !getOperation()->IsDone()) {
695                         wc.suspend();
696                 } else {
697                         ObjectList::iterator it = objects.begin();
698                         GEOM::GEOM_Object_var obj = *it;
699                         displayPreview(obj, true, activate, false, lineWidth, displayMode, color);
700                         if (toRemoveFromEngine)
701                                 obj->UnRegister();
702                 }
703                 HexMeshCheckBox->setChecked(hexMeshState);
704         } catch (const SALOME::SALOME_Exception& e) {
705                 SalomeApp_Tools::QtCatchCorbaException(e);
706         }
707
708         isPreview = false;
709
710         if (update)
711                 updateViewer();
712 }
713 //=================================================================================
714 // function : createOperation
715 // purpose  :
716 //=================================================================================
717 GEOM::GEOM_IOperations_ptr AdvancedGUI_PipeTShapeDlg::createOperation() {
718         return getGeomEngine()->GetIAdvancedOperations(getStudyId());
719 }
720
721 //=================================================================================
722 // function : isValid
723 // purpose  :
724 //=================================================================================
725 bool AdvancedGUI_PipeTShapeDlg::isValid(QString& msg) {
726         bool ok = true;
727
728         ok = MainTubeGroupParams->SpinBox_DX->isValid(msg, !IsPreview()) && ok;
729         ok = MainTubeGroupParams->SpinBox_DY->isValid(msg, !IsPreview()) && ok;
730         ok = MainTubeGroupParams->SpinBox_DZ->isValid(msg, !IsPreview()) && ok;
731         ok = IncidentTubeGroupParams->SpinBox_DX->isValid(msg, !IsPreview()) && ok;
732         ok = IncidentTubeGroupParams->SpinBox_DY->isValid(msg, !IsPreview()) && ok;
733         ok = IncidentTubeGroupParams->SpinBox_DZ->isValid(msg, !IsPreview()) && ok;
734         ok = ChamferGroupParams->SpinBox_DX->isValid(msg, !IsPreview()) && ok;
735         ok = ChamferGroupParams->SpinBox_DY->isValid(msg, !IsPreview()) && ok;
736         ok = FilletGroupParams->SpinBox_DX->isValid(msg, !IsPreview()) && ok;
737
738         ok = fabs(MainTubeGroupParams->SpinBox_DX->value()) > Precision::Confusion() && ok;
739         ok = fabs(MainTubeGroupParams->SpinBox_DY->value()) > Precision::Confusion() && ok;
740         ok = fabs(MainTubeGroupParams->SpinBox_DZ->value()) > Precision::Confusion() && ok;
741         ok = fabs(IncidentTubeGroupParams->SpinBox_DX->value()) > Precision::Confusion() && ok;
742         ok = fabs(IncidentTubeGroupParams->SpinBox_DY->value()) > Precision::Confusion() && ok;
743         ok = fabs(IncidentTubeGroupParams->SpinBox_DZ->value()) > Precision::Confusion() && ok;
744         ok = fabs(ChamferGroupParams->SpinBox_DX->value()) > Precision::Confusion() && ok;
745         ok = fabs(ChamferGroupParams->SpinBox_DY->value()) > Precision::Confusion() && ok;
746         ok = fabs(FilletGroupParams->SpinBox_DX->value()) > Precision::Confusion() && ok;
747
748         if (JunctionPointsSel->GroupBox1->isChecked())
749                 ok = myOkPoint1 && myOkPoint2 && myOkPoint3 && ok;
750
751         return ok;
752 }
753
754 //=================================================================================
755 // function : CheckCompatiblePosition()
756 // purpose  :
757 //=================================================================================
758 bool AdvancedGUI_PipeTShapeDlg::CheckCompatiblePosition(GEOM::GEOM_Object_var theP1,
759                 GEOM::GEOM_Object_var theP2, GEOM::GEOM_Object_var theP3, double theTolerance) {
760
761     MainTubeGroupParams->SpinBox_DZ->setStyleSheet(CssNormal);
762     IncidentTubeGroupParams->SpinBox_DZ->setStyleSheet(CssNormal);
763     JunctionPointsSel->PushButton4->setStyleSheet(CssNormal);
764     JunctionPointsSel->PushButton5->setStyleSheet(CssNormal);
765
766     CORBA::Double theL1 = MainTubeGroupParams->SpinBox_DZ->value();
767     CORBA::Double theL2 = IncidentTubeGroupParams->SpinBox_DZ->value();
768
769     JunctionPointsSel->LineEdit4->setText("");
770     JunctionPointsSel->LineEdit5->setText("");
771
772     MainTubeGroupParams->SpinBox_DZ->setToolTip("");
773     IncidentTubeGroupParams->SpinBox_DZ->setToolTip("");
774
775         TopoDS_Shape aShape;
776         gp_Pnt P1, P2, P3;
777         if ( GEOMBase::GetShape( theP1, aShape ) && !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
778                 P1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
779         else
780                 return false;
781
782         if ( GEOMBase::GetShape( theP2, aShape ) && !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
783                 P2 = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
784         else
785                 return false;
786
787         if ( GEOMBase::GetShape( theP3, aShape ) && !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
788                 P3 = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
789         else
790                 return false;
791
792     double d12 = P1.Distance(P2);
793     double d13 = P1.Distance(P3);
794     double d23 = P2.Distance(P3);
795
796     if (Abs(d12) <= Precision::Confusion()) {
797 //         SetErrorCode("Junctions points P1 and P2 are identical");
798         return false;
799     }
800     if (Abs(d13) <= Precision::Confusion()) {
801 //         SetErrorCode("Junctions points P1 and P3 are identical");
802         return false;
803     }
804     if (Abs(d23) <= Precision::Confusion()) {
805 //         SetErrorCode("Junctions points P2 and P3 are identical");
806         return false;
807     }
808
809     long double newL1 = 0.5 * d12;
810     long double newL2 = sqrt(pow(d13,2)-pow(newL1,2));
811
812     JunctionPointsSel->LineEdit4->setText(QString::number(newL1,'f',7));
813     JunctionPointsSel->LineEdit5->setText(QString::number(newL2,'f',7));
814
815     if (fabs(newL1 - theL1) > Precision::Approximation()) {
816                 if ((newL1 * (1 - theTolerance) - theL1 <= Precision::Approximation()) &&
817                                 (newL1 * (1 + theTolerance) - theL1 >= Precision::Approximation())) {
818             disconnect(MainTubeGroupParams->SpinBox_DZ, 0, this, 0);
819                         MainTubeGroupParams->SpinBox_DZ->setValue(newL1);
820             connect(MainTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
821                         MainTubeGroupParams->SpinBox_DZ->setToolTip("Value was recomputed to fit with position");
822             MainTubeGroupParams->SpinBox_DZ->setStyleSheet(CssAcceptable);
823             JunctionPointsSel->PushButton4->setStyleSheet(CssAcceptable);
824                 }
825                 else {
826                         MainTubeGroupParams->SpinBox_DZ->setToolTip("Value is incompatible with position");
827             MainTubeGroupParams->SpinBox_DZ->setStyleSheet(CssRefused);
828             JunctionPointsSel->PushButton4->setStyleSheet(CssRefused);
829                 }
830         }
831     else {
832         MainTubeGroupParams->SpinBox_DZ->setStyleSheet(CssNormal);
833         JunctionPointsSel->PushButton4->setStyleSheet(CssNormal);
834     }
835
836         if (fabs(newL2 - theL2) > Precision::Approximation()) {
837                 if ((newL2 * (1 - theTolerance) - theL2 <= Precision::Approximation()) &&
838                                 (newL2 * (1 + theTolerance) - theL2 >= Precision::Approximation())) {
839             disconnect(IncidentTubeGroupParams->SpinBox_DZ, 0, this, 0);
840                         IncidentTubeGroupParams->SpinBox_DZ->setValue(newL2);
841             connect(IncidentTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
842                         IncidentTubeGroupParams->SpinBox_DZ->setToolTip("Value was recomputed to fit with position");
843             IncidentTubeGroupParams->SpinBox_DZ->setStyleSheet(CssAcceptable);
844             JunctionPointsSel->PushButton5->setStyleSheet(CssAcceptable);
845                 }
846                 else {
847                         IncidentTubeGroupParams->SpinBox_DZ->setToolTip("Value is incompatible with position");
848             IncidentTubeGroupParams->SpinBox_DZ->setStyleSheet(CssRefused);
849             JunctionPointsSel->PushButton5->setStyleSheet(CssRefused);
850                 }
851         }
852         else {
853         IncidentTubeGroupParams->SpinBox_DZ->setStyleSheet(CssNormal);
854         JunctionPointsSel->PushButton5->setStyleSheet(CssNormal);
855     }
856
857         return true;
858 }
859
860 bool AdvancedGUI_PipeTShapeDlg::execute(ObjectList& objects) {
861
862     if (JunctionPointsSel->GroupBox1->isChecked() && myOkPoint1 && myOkPoint2 && myOkPoint3)
863         CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
864
865     return executeNoCheck(objects);
866 }
867
868 //=================================================================================
869 // function : execute
870 // purpose  :
871 //=================================================================================
872 bool AdvancedGUI_PipeTShapeDlg::executeNoCheck(ObjectList& objects) {
873         bool res = false;
874
875         //   GEOM::GEOM_Object_var anObj;
876         GEOM::ListOfGO_var anObj;
877
878         GEOM::GEOM_IAdvancedOperations_var anOper = GEOM::GEOM_IAdvancedOperations::_narrow(getOperation());
879
880         //@@ retrieve input values from the widgets here @@//
881         CORBA::Double theR1 = MainTubeGroupParams->SpinBox_DX->value();
882         CORBA::Double theW1 = MainTubeGroupParams->SpinBox_DY->value();
883         CORBA::Double theL1 = MainTubeGroupParams->SpinBox_DZ->value();
884         CORBA::Double theR2 = IncidentTubeGroupParams->SpinBox_DX->value();
885         CORBA::Double theW2 = IncidentTubeGroupParams->SpinBox_DY->value();
886         CORBA::Double theL2 = IncidentTubeGroupParams->SpinBox_DZ->value();
887         CORBA::Double theH = ChamferGroupParams->SpinBox_DX->value();
888         CORBA::Double theW = ChamferGroupParams->SpinBox_DY->value();
889         CORBA::Double theRF = FilletGroupParams->SpinBox_DX->value();
890         CORBA::Boolean theHexMesh = HexMeshCheckBox->isChecked();
891
892 //      if (JunctionPointsSel->GroupBox1->isChecked()) {
893 //              CheckCompatiblePosition(theL1, theL2, myPoint1, myPoint2, myPoint3, 0.01);
894 //              theL1 = MainTubeGroupParams->SpinBox_DZ->value();
895 //              theL2 = IncidentTubeGroupParams->SpinBox_DZ->value();
896 //      }
897
898         // call engine function
899         if (ChamferGroupParams->GroupBox1->isChecked()) {
900                 if (JunctionPointsSel->GroupBox1->isChecked())
901                         anObj = anOper->MakePipeTShapeChamferWithPosition(theR1, theW1, theL1, theR2, theW2, theL2, theH, theW,
902                                         theHexMesh, myPoint1, myPoint2, myPoint3);
903                 else
904                         anObj = anOper->MakePipeTShapeChamfer(theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, theHexMesh);
905         }
906         else if (FilletGroupParams->GroupBox1->isChecked()) {
907                 if (JunctionPointsSel->GroupBox1->isChecked())
908                         anObj = anOper->MakePipeTShapeFilletWithPosition(theR1, theW1, theL1, theR2, theW2, theL2, theRF,
909                                         theHexMesh, myPoint1, myPoint2, myPoint3);
910                 else
911                         anObj = anOper->MakePipeTShapeFillet(theR1, theW1, theL1, theR2, theW2, theL2, theRF, theHexMesh);
912         }
913         else {
914                 if (JunctionPointsSel->GroupBox1->isChecked())
915                 anObj = anOper->MakePipeTShapeWithPosition(theR1, theW1, theL1, theR2, theW2, theL2, theHexMesh, myPoint1,
916                                 myPoint2, myPoint3);
917                 else
918                         anObj = anOper->MakePipeTShape(theR1, theW1, theL1, theR2, theW2, theL2, theHexMesh);
919         }
920
921         res = anObj->length();
922         if (!res)
923                 return false;
924
925         //   res = !anObj->_is_nil();
926         if (res && !IsPreview()) {
927                 QStringList aParameters;
928                 //@@ put stringified input parameters to the string list here to store in the data model for notebook @@//
929                 aParameters << MainTubeGroupParams->SpinBox_DX->text(); // R1 parameter
930                 aParameters << MainTubeGroupParams->SpinBox_DY->text(); // W1 parameter
931                 aParameters << MainTubeGroupParams->SpinBox_DZ->text(); // L1 parameter
932                 aParameters << IncidentTubeGroupParams->SpinBox_DX->text(); // R2 parameter
933                 aParameters << IncidentTubeGroupParams->SpinBox_DY->text(); // W2 parameter
934                 aParameters << IncidentTubeGroupParams->SpinBox_DZ->text(); // L2 parameter
935                 if (ChamferGroupParams->GroupBox1->isChecked()) {// Chamfer parameter
936                         aParameters << ChamferGroupParams->SpinBox_DX->text(); // H parameter
937                         aParameters << ChamferGroupParams->SpinBox_DY->text(); // W parameter
938                 }
939                 if (FilletGroupParams->GroupBox1->isChecked()) // Fillet parameter
940                         aParameters << FilletGroupParams->SpinBox_DX->text(); // RF parameter
941
942                 if (aParameters.count() > 0)
943                         anObj[0]->SetParameters(aParameters.join(":").toLatin1().constData());
944         }
945
946         objects.push_back(anObj[0]._retn());
947         pipeTShapeGroupObjects.clear();
948         for (int i = 1, n = anObj->length(); i < n; i++) {
949                 pipeTShapeGroupObjects.push_back(anObj[i]._retn());
950         }
951
952         return objects.size() > 0;
953 }
954
955 //=================================================================================
956 // function : restoreSubShapes
957 // purpose  :
958 //=================================================================================
959 void AdvancedGUI_PipeTShapeDlg::restoreSubShapes(SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_ptr theSObject) {
960         SALOMEDS::GenericAttribute_var anAttr;
961         if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
962                 return;
963
964         SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
965         CORBA::String_var anIORso = anAttrIOR->Value();
966
967         // get Object from SObject
968         GEOM::GEOM_Object_var theFather = GEOM::GEOM_Object::_narrow(myGeomGUI->getApp()->orb()->string_to_object(anIORso));
969         if (CORBA::is_nil(theFather))
970                 return;
971
972         ObjectList::iterator it = pipeTShapeGroupObjects.begin();
973
974         for (int i = 0; it != pipeTShapeGroupObjects.end(); it++, i++) {
975                 getGeomEngine()->AddInStudy(theStudy, (*it), tr((*it)->GetName()).toStdString().c_str(), theFather);
976         }
977
978 }
979
980 //=================================================================================
981 // function : processPreview()
982 // purpose  : Display preview if CheckBoxPreview is checked
983 //=================================================================================
984 void AdvancedGUI_PipeTShapeDlg::processPreview() {
985   if(mainFrame()->CheckBoxPreview->isChecked())
986     DisplayPreview();
987   else
988     erasePreview(true);
989 }