Salome HOME
Merge from BR_WIN_INDUS_514 04/10/2010
[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         // Signal/slot connections
221         connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
222         connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
223         connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
224         // ValueChangedInSpinBox
225         connect(MainTubeGroupParams->SpinBox_DX, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
226         connect(MainTubeGroupParams->SpinBox_DY, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
227         connect(MainTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
228         connect(IncidentTubeGroupParams->SpinBox_DX, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
229         connect(IncidentTubeGroupParams->SpinBox_DY, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
230         connect(IncidentTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
231         connect(ChamferGroupParams->SpinBox_DX, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
232         connect(ChamferGroupParams->SpinBox_DY, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
233         connect(FilletGroupParams->SpinBox_DX, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
234         // ChamferOrFillet
235         connect(ChamferGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, SLOT(ChamferOrFillet(bool)));
236         connect(FilletGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, SLOT(ChamferOrFillet(bool)));
237         // Preview
238 //      connect(PreviewPushButton, SIGNAL(clicked()), this, SLOT(DisplayPreview()));
239         // Position
240         connect(JunctionPointsSel->GroupBox1, SIGNAL(toggled(bool)), this, SLOT(SetPosition(bool)));
241         connect(JunctionPointsSel->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
242         connect(JunctionPointsSel->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
243         connect(JunctionPointsSel->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
244     // ApplyNewDimensions
245     connect(JunctionPointsSel->PushButton4, SIGNAL(clicked()), this, SLOT(ApplyNewDimensions()));
246     connect(JunctionPointsSel->PushButton5, SIGNAL(clicked()), this, SLOT(ApplyNewDimensions()));
247         connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(UpdatePicture(QWidget*, QWidget*)));
248         //@@ put additional signal/slot connections here @@//
249
250         initName(tr("GEOM_PIPE_TSHAPE"));
251     updateTshapeScreenshotLabel();
252         DisplayPreview();
253 }
254
255 //=================================================================================
256 // function : ApplyNewDimensions()
257 // purpose  :
258 //=================================================================================
259 void AdvancedGUI_PipeTShapeDlg::ApplyNewDimensions() {
260     QPushButton* send = (QPushButton*) sender();
261
262     bool ok = false;
263     double newVal;
264     if (send == JunctionPointsSel->PushButton4) {
265         if (!JunctionPointsSel->LineEdit4->text().isEmpty()) {
266             newVal = JunctionPointsSel->LineEdit4->text().toDouble(&ok);
267             if (ok) {
268                 disconnect(MainTubeGroupParams->SpinBox_DZ, 0, this, 0);
269                 MainTubeGroupParams->SpinBox_DZ->setValue(newVal);
270                 connect(MainTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
271                 MainTubeGroupParams->SpinBox_DZ->setToolTip("");
272                 MainTubeGroupParams->SpinBox_DZ->setStyleSheet("background-color: rgb(255, 255, 255);");
273                 CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
274                 DisplayPreview();
275             }
276         }
277     }
278     else if (send == JunctionPointsSel->PushButton5) {
279         if (!JunctionPointsSel->LineEdit5->text().isEmpty()) {
280             newVal = JunctionPointsSel->LineEdit5->text().toDouble(&ok);
281             if (ok) {
282                 disconnect(IncidentTubeGroupParams->SpinBox_DZ, 0, this, 0);
283                 IncidentTubeGroupParams->SpinBox_DZ->setValue(newVal);
284                 connect(IncidentTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
285                 IncidentTubeGroupParams->SpinBox_DZ->setToolTip("");
286                 IncidentTubeGroupParams->SpinBox_DZ->setStyleSheet("background-color: rgb(255, 255, 255);");
287                 CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
288                 DisplayPreview();
289             }
290         }
291     }
292 }
293
294 //=================================================================================
295 // function : UpdatePicture()
296 // purpose  :
297 //=================================================================================
298 void AdvancedGUI_PipeTShapeDlg::UpdatePicture(QWidget* old, QWidget* now) {
299
300         if (ChamferGroupParams->GroupBox1->isChecked())
301                 if (now == MainTubeGroupParams->SpinBox_DX)
302                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_R1"));
303                 else if (now == MainTubeGroupParams->SpinBox_DY)
304                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_W1"));
305                 else if (now == MainTubeGroupParams->SpinBox_DZ)
306                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_L1"));
307                 else if (now == IncidentTubeGroupParams->SpinBox_DX)
308                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_R2"));
309                 else if (now == IncidentTubeGroupParams->SpinBox_DY)
310                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_W2"));
311                 else if (now == IncidentTubeGroupParams->SpinBox_DZ)
312                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_L2"));
313                 else if (now == ChamferGroupParams->SpinBox_DX)
314                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_H"));
315                 else if (now == ChamferGroupParams->SpinBox_DY)
316                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_W"));
317                 else
318                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER"));
319         else if (FilletGroupParams->GroupBox1->isChecked())
320                 if (now == MainTubeGroupParams->SpinBox_DX)
321                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_R1"));
322                 else if (now == MainTubeGroupParams->SpinBox_DY)
323                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_W1"));
324                 else if (now == MainTubeGroupParams->SpinBox_DZ)
325                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_L1"));
326                 else if (now == IncidentTubeGroupParams->SpinBox_DX)
327                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_R2"));
328                 else if (now == IncidentTubeGroupParams->SpinBox_DY)
329                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_W2"));
330                 else if (now == IncidentTubeGroupParams->SpinBox_DZ)
331                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_L2"));
332                 else if (now == FilletGroupParams->SpinBox_DX)
333                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_RF"));
334                 else
335                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET"));
336         else
337                 if (now == MainTubeGroupParams->SpinBox_DX)
338                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_R1"));
339                 else if (now == MainTubeGroupParams->SpinBox_DY)
340                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_W1"));
341                 else if (now == MainTubeGroupParams->SpinBox_DZ)
342                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_L1"));
343                 else if (now == IncidentTubeGroupParams->SpinBox_DX)
344                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_R2"));
345                 else if (now == IncidentTubeGroupParams->SpinBox_DY)
346                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_W2"));
347                 else if (now == IncidentTubeGroupParams->SpinBox_DZ)
348                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_L2"));
349                 else
350                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE"));
351
352     updateTshapeScreenshotLabel();
353 }
354
355 //=================================================================================
356 // function : SetPosition()
357 // purpose  :
358 //=================================================================================
359 void AdvancedGUI_PipeTShapeDlg::SetPosition(bool isChecked) {
360         if (isChecked) {
361                 erasePreview();
362         JunctionPointsSel->LineEdit4->setText("");
363         JunctionPointsSel->LineEdit5->setText("");
364 //              connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(
365 //                              SelectionIntoArgument()));
366                 JunctionPointsSel->PushButton1->click();
367                 SelectionIntoArgument();
368         } else {
369                 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
370                 JunctionPointsSel->LineEdit4->setText("");
371                 JunctionPointsSel->LineEdit5->setText("");
372                 DisplayPreview();
373         }
374 }
375
376 //=================================================================================
377 // function : ValueChangedInSpinBox()
378 // purpose  :
379 //=================================================================================
380 void AdvancedGUI_PipeTShapeDlg::ValueChangedInSpinBox(double newValue)
381 {
382     if (JunctionPointsSel->GroupBox1->isChecked() && myOkPoint1 && myOkPoint2 && myOkPoint3)
383         CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
384     DisplayPreview();
385 }
386
387 //=================================================================================
388 // function : SelectionIntoArgument()
389 // purpose  : Called when selection as changed or other case
390 //=================================================================================
391 void AdvancedGUI_PipeTShapeDlg::SelectionIntoArgument() {
392
393         erasePreview();
394 //      myEditCurrentArgument->setText("");
395
396         LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
397         SALOME_ListIO aSelList;
398         aSelMgr->selectedObjects(aSelList);
399
400         if (aSelList.Extent() != 1) {
401                 if (myEditCurrentArgument == JunctionPointsSel->LineEdit1)
402                         myOkPoint1 = false;
403                 else if (myEditCurrentArgument == JunctionPointsSel->LineEdit2)
404                         myOkPoint2 = false;
405                 else if (myEditCurrentArgument == JunctionPointsSel->LineEdit3)
406                         myOkPoint3 = false;
407                 return;
408                 myEditCurrentArgument->setText("");
409         }
410
411         // nbSel == 1
412         if (aSelList.Extent() == 1) {
413                 Standard_Boolean aRes = Standard_False;
414                 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
415                 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(anIO, aRes);
416                 if (!CORBA::is_nil(aSelectedObject) && aRes) {
417                         QString aName = GEOMBase::GetName(aSelectedObject);
418                         TopoDS_Shape aShape;
419                         if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) {
420
421                                 TColStd_IndexedMapOfInteger aMap;
422                                 aSelMgr->GetIndexes(anIO, aMap);
423                                 if (aMap.Extent() == 1) { // Local Selection
424                                         int anIndex = aMap(1);
425                                         aName += QString(":vertex_%1").arg(anIndex);
426
427                                         //Find SubShape Object in Father
428                                         GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
429
430                                         if (aFindedObject->_is_nil()) { // Object not found in study
431                                                 GEOM::GEOM_IShapesOperations_var aShapesOp =
432                                                                 getGeomEngine()->GetIShapesOperations(getStudyId());
433                                                 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
434                                         } else {
435                                                 aSelectedObject = aFindedObject; // get Object from study
436                                         }
437                                         GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE);
438                                 } else { // Global Selection
439                                         if (aShape.ShapeType() != TopAbs_VERTEX) {
440                                                 aSelectedObject = GEOM::GEOM_Object::_nil();
441                                                 aName = "";
442                                         }
443                                 }
444                         }
445
446                         if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX) {
447                                 return;
448                         }
449                         myEditCurrentArgument->setText(aName);
450                         if (myEditCurrentArgument == JunctionPointsSel->LineEdit1) {
451                                 myPoint1 = aSelectedObject;
452                                 myOkPoint1 = true;
453                                 if (!myOkPoint2)
454                                         JunctionPointsSel->PushButton2->click();
455                         } else if (myEditCurrentArgument == JunctionPointsSel->LineEdit2) {
456                                 myPoint2 = aSelectedObject;
457                                 myOkPoint2 = true;
458                                 if (!myOkPoint3)
459                                         JunctionPointsSel->PushButton3->click();
460                         } else if (myEditCurrentArgument == JunctionPointsSel->LineEdit3) {
461                                 myPoint3 = aSelectedObject;
462                                 myOkPoint3 = true;
463                                 if (!myOkPoint1)
464                                         JunctionPointsSel->PushButton1->click();
465                         }
466                 }
467         }
468
469         if (myOkPoint1 && myOkPoint2 && myOkPoint3) {
470         CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
471                 DisplayPreview();
472     }
473
474 //      Standard_Boolean testResult = Standard_False;
475 //      GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
476 //      if (!testResult || 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         if (ClickOnApply())
574                 ClickOnCancel();
575 }
576
577 //=================================================================================
578 // function : ClickOnApply()
579 // purpose  :
580 //=================================================================================
581 bool AdvancedGUI_PipeTShapeDlg::ClickOnApply() {
582         if (!onAccept())
583                 return false;
584
585         initName();
586
587         return true;
588 }
589
590 //=================================================================================
591 // function : ActivateThisDialog()
592 // purpose  :
593 //=================================================================================
594 void AdvancedGUI_PipeTShapeDlg::ActivateThisDialog() {
595         GEOMBase_Skeleton::ActivateThisDialog();
596         //      globalSelection( GEOM_POINT);
597         //      connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(
598         //                      currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
599     if (myOkPoint1 && myOkPoint2 && myOkPoint3)
600         CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
601         DisplayPreview();
602 }
603
604 //=================================================================================
605 // function : enterEvent [REDEFINED]
606 // purpose  :
607 //=================================================================================
608 void AdvancedGUI_PipeTShapeDlg::enterEvent(QEvent*) {
609         if (!mainFrame()->GroupConstructors->isEnabled())
610                 ActivateThisDialog();
611 }
612
613 //=================================================================================
614 // function : resizeEvent [REDEFINED]
615 // purpose  :
616 //=================================================================================
617 void AdvancedGUI_PipeTShapeDlg::resizeEvent(QResizeEvent */*event*/) {
618     QSize scaledSize = imagePipeTShape.size();
619     scaledSize.scale(tshapeScreenShotLabel->size(), Qt::KeepAspectRatio);
620     if (!tshapeScreenShotLabel->pixmap()
621       || scaledSize != tshapeScreenShotLabel->pixmap()->size())
622         updateTshapeScreenshotLabel();
623 }
624
625 //=================================================================================
626 // function : updateTshapeScreenshotLabel
627 // purpose  :
628 //=================================================================================
629 void AdvancedGUI_PipeTShapeDlg::updateTshapeScreenshotLabel() {
630     tshapeScreenShotLabel->setPixmap(imagePipeTShape.scaled(tshapeScreenShotLabel->size(),
631                                                       Qt::KeepAspectRatio,
632                                                       Qt::SmoothTransformation));
633 }
634
635 //=================================================================================
636 // function : ChamferOrFillet()
637 // purpose  :
638 //=================================================================================
639 void AdvancedGUI_PipeTShapeDlg::ChamferOrFillet(bool) {
640         QGroupBox* send = (QGroupBox*) sender();
641
642         if (send == ChamferGroupParams->GroupBox1) {
643                 if (send->isChecked()) {
644                         disconnect(FilletGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, 0);
645                         FilletGroupParams->GroupBox1->setChecked(false);
646                         connect(FilletGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, SLOT(ChamferOrFillet(bool)));
647                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER"));
648                 }
649                 else
650                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE"));
651         updateTshapeScreenshotLabel();
652         if (myOkPoint1 && myOkPoint2 && myOkPoint3)
653             CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
654                 DisplayPreview();
655         } else if (send == FilletGroupParams->GroupBox1) {
656                 if (send->isChecked()) {
657                         disconnect(ChamferGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, 0);
658                         ChamferGroupParams->GroupBox1->setChecked(!send->isChecked());
659                         connect(ChamferGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, SLOT(ChamferOrFillet(bool)));
660                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET"));
661                 }
662                 else
663                         imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE"));
664         updateTshapeScreenshotLabel();
665         if (myOkPoint1 && myOkPoint2 && myOkPoint3)
666             CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
667                 DisplayPreview();
668         }
669
670 }
671
672 //=================================================================================
673 // function : DisplayPreview()
674 // purpose  :
675 //=================================================================================
676 void AdvancedGUI_PipeTShapeDlg::DisplayPreview(const bool activate, const bool update, const bool toRemoveFromEngine,
677                 const double lineWidth, const int displayMode, const int color) {
678         isPreview = true;
679         QString msg;
680         if (!isValid(msg)) {
681                 erasePreview(update);
682                 isPreview = false;
683                 return;
684         }
685
686         erasePreview(false);
687
688         try {
689                 SUIT_OverrideCursor wc;
690                 ObjectList objects;
691                 bool hexMeshState = HexMeshCheckBox->isChecked();
692                 HexMeshCheckBox->setChecked(false);
693                 if (!executeNoCheck(objects) || !getOperation()->IsDone()) {
694                         wc.suspend();
695                 } else {
696                         ObjectList::iterator it = objects.begin();
697                         GEOM::GEOM_Object_var obj = *it;
698                         displayPreview(obj, true, activate, false, lineWidth, displayMode, color);
699                         if (toRemoveFromEngine)
700                                 obj->Destroy();
701                 }
702                 HexMeshCheckBox->setChecked(hexMeshState);
703         } catch (const SALOME::SALOME_Exception& e) {
704                 SalomeApp_Tools::QtCatchCorbaException(e);
705         }
706
707         isPreview = false;
708
709         if (update)
710                 updateViewer();
711 }
712 //=================================================================================
713 // function : createOperation
714 // purpose  :
715 //=================================================================================
716 GEOM::GEOM_IOperations_ptr AdvancedGUI_PipeTShapeDlg::createOperation() {
717         return getGeomEngine()->GetIAdvancedOperations(getStudyId());
718 }
719
720 //=================================================================================
721 // function : isValid
722 // purpose  :
723 //=================================================================================
724 bool AdvancedGUI_PipeTShapeDlg::isValid(QString& msg) {
725         bool ok = true;
726
727         ok = MainTubeGroupParams->SpinBox_DX->isValid(msg, !IsPreview()) && ok;
728         ok = MainTubeGroupParams->SpinBox_DY->isValid(msg, !IsPreview()) && ok;
729         ok = MainTubeGroupParams->SpinBox_DZ->isValid(msg, !IsPreview()) && ok;
730         ok = IncidentTubeGroupParams->SpinBox_DX->isValid(msg, !IsPreview()) && ok;
731         ok = IncidentTubeGroupParams->SpinBox_DY->isValid(msg, !IsPreview()) && ok;
732         ok = IncidentTubeGroupParams->SpinBox_DZ->isValid(msg, !IsPreview()) && ok;
733         ok = ChamferGroupParams->SpinBox_DX->isValid(msg, !IsPreview()) && ok;
734         ok = ChamferGroupParams->SpinBox_DY->isValid(msg, !IsPreview()) && ok;
735         ok = FilletGroupParams->SpinBox_DX->isValid(msg, !IsPreview()) && ok;
736
737         ok = fabs(MainTubeGroupParams->SpinBox_DX->value()) > Precision::Confusion() && ok;
738         ok = fabs(MainTubeGroupParams->SpinBox_DY->value()) > Precision::Confusion() && ok;
739         ok = fabs(MainTubeGroupParams->SpinBox_DZ->value()) > Precision::Confusion() && ok;
740         ok = fabs(IncidentTubeGroupParams->SpinBox_DX->value()) > Precision::Confusion() && ok;
741         ok = fabs(IncidentTubeGroupParams->SpinBox_DY->value()) > Precision::Confusion() && ok;
742         ok = fabs(IncidentTubeGroupParams->SpinBox_DZ->value()) > Precision::Confusion() && ok;
743         ok = fabs(ChamferGroupParams->SpinBox_DX->value()) > Precision::Confusion() && ok;
744         ok = fabs(ChamferGroupParams->SpinBox_DY->value()) > Precision::Confusion() && ok;
745         ok = fabs(FilletGroupParams->SpinBox_DX->value()) > Precision::Confusion() && ok;
746
747         if (JunctionPointsSel->GroupBox1->isChecked())
748                 ok = myOkPoint1 && myOkPoint2 && myOkPoint3 && ok;
749
750         return ok;
751 }
752
753 //=================================================================================
754 // function : CheckCompatiblePosition()
755 // purpose  :
756 //=================================================================================
757 bool AdvancedGUI_PipeTShapeDlg::CheckCompatiblePosition(GEOM::GEOM_Object_var theP1,
758                 GEOM::GEOM_Object_var theP2, GEOM::GEOM_Object_var theP3, double theTolerance) {
759
760     MainTubeGroupParams->SpinBox_DZ->setStyleSheet(CssNormal);
761     IncidentTubeGroupParams->SpinBox_DZ->setStyleSheet(CssNormal);
762     JunctionPointsSel->PushButton4->setStyleSheet(CssNormal);
763     JunctionPointsSel->PushButton5->setStyleSheet(CssNormal);
764
765     CORBA::Double theL1 = MainTubeGroupParams->SpinBox_DZ->value();
766     CORBA::Double theL2 = IncidentTubeGroupParams->SpinBox_DZ->value();
767
768     JunctionPointsSel->LineEdit4->setText("");
769     JunctionPointsSel->LineEdit5->setText("");
770
771     MainTubeGroupParams->SpinBox_DZ->setToolTip("");
772     IncidentTubeGroupParams->SpinBox_DZ->setToolTip("");
773
774         TopoDS_Shape aShape;
775         gp_Pnt P1, P2, P3;
776         if ( GEOMBase::GetShape( theP1, aShape ) && !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
777                 P1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
778         else
779                 return false;
780
781         if ( GEOMBase::GetShape( theP2, aShape ) && !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
782                 P2 = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
783         else
784                 return false;
785
786         if ( GEOMBase::GetShape( theP3, aShape ) && !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
787                 P3 = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
788         else
789                 return false;
790
791     double d12 = P1.Distance(P2);
792     double d13 = P1.Distance(P3);
793     double d23 = P2.Distance(P3);
794
795     if (Abs(d12) <= Precision::Confusion()) {
796 //         SetErrorCode("Junctions points P1 and P2 are identical");
797         return false;
798     }
799     if (Abs(d13) <= Precision::Confusion()) {
800 //         SetErrorCode("Junctions points P1 and P3 are identical");
801         return false;
802     }
803     if (Abs(d23) <= Precision::Confusion()) {
804 //         SetErrorCode("Junctions points P2 and P3 are identical");
805         return false;
806     }
807
808     long double newL1 = 0.5 * d12;
809     long double newL2 = sqrt(pow(d13,2)-pow(newL1,2));
810
811     JunctionPointsSel->LineEdit4->setText(QString::number(newL1,'f',7));
812     JunctionPointsSel->LineEdit5->setText(QString::number(newL2,'f',7));
813
814     if (fabs(newL1 - theL1) > Precision::Approximation()) {
815                 if ((newL1 * (1 - theTolerance) - theL1 <= Precision::Approximation()) &&
816                                 (newL1 * (1 + theTolerance) - theL1 >= Precision::Approximation())) {
817             disconnect(MainTubeGroupParams->SpinBox_DZ, 0, this, 0);
818                         MainTubeGroupParams->SpinBox_DZ->setValue(newL1);
819             connect(MainTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
820                         MainTubeGroupParams->SpinBox_DZ->setToolTip("Value was recomputed to fit with position");
821             MainTubeGroupParams->SpinBox_DZ->setStyleSheet(CssAcceptable);
822             JunctionPointsSel->PushButton4->setStyleSheet(CssAcceptable);
823                 }
824                 else {
825                         MainTubeGroupParams->SpinBox_DZ->setToolTip("Value is incompatible with position");
826             MainTubeGroupParams->SpinBox_DZ->setStyleSheet(CssRefused);
827             JunctionPointsSel->PushButton4->setStyleSheet(CssRefused);
828                 }
829         }
830     else {
831         MainTubeGroupParams->SpinBox_DZ->setStyleSheet(CssNormal);
832         JunctionPointsSel->PushButton4->setStyleSheet(CssNormal);
833     }
834
835         if (fabs(newL2 - theL2) > Precision::Approximation()) {
836                 if ((newL2 * (1 - theTolerance) - theL2 <= Precision::Approximation()) &&
837                                 (newL2 * (1 + theTolerance) - theL2 >= Precision::Approximation())) {
838             disconnect(IncidentTubeGroupParams->SpinBox_DZ, 0, this, 0);
839                         IncidentTubeGroupParams->SpinBox_DZ->setValue(newL2);
840             connect(IncidentTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
841                         IncidentTubeGroupParams->SpinBox_DZ->setToolTip("Value was recomputed to fit with position");
842             IncidentTubeGroupParams->SpinBox_DZ->setStyleSheet(CssAcceptable);
843             JunctionPointsSel->PushButton5->setStyleSheet(CssAcceptable);
844                 }
845                 else {
846                         IncidentTubeGroupParams->SpinBox_DZ->setToolTip("Value is incompatible with position");
847             IncidentTubeGroupParams->SpinBox_DZ->setStyleSheet(CssRefused);
848             JunctionPointsSel->PushButton5->setStyleSheet(CssRefused);
849                 }
850         }
851         else {
852         IncidentTubeGroupParams->SpinBox_DZ->setStyleSheet(CssNormal);
853         JunctionPointsSel->PushButton5->setStyleSheet(CssNormal);
854     }
855
856         return true;
857 }
858
859 bool AdvancedGUI_PipeTShapeDlg::execute(ObjectList& objects) {
860
861     if (JunctionPointsSel->GroupBox1->isChecked() && myOkPoint1 && myOkPoint2 && myOkPoint3)
862         CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
863
864     return executeNoCheck(objects);
865 }
866
867 //=================================================================================
868 // function : execute
869 // purpose  :
870 //=================================================================================
871 bool AdvancedGUI_PipeTShapeDlg::executeNoCheck(ObjectList& objects) {
872         bool res = false;
873
874         //   GEOM::GEOM_Object_var anObj;
875         GEOM::ListOfGO_var anObj;
876
877         GEOM::GEOM_IAdvancedOperations_var anOper = GEOM::GEOM_IAdvancedOperations::_narrow(getOperation());
878
879         //@@ retrieve input values from the widgets here @@//
880         CORBA::Double theR1 = MainTubeGroupParams->SpinBox_DX->value();
881         CORBA::Double theW1 = MainTubeGroupParams->SpinBox_DY->value();
882         CORBA::Double theL1 = MainTubeGroupParams->SpinBox_DZ->value();
883         CORBA::Double theR2 = IncidentTubeGroupParams->SpinBox_DX->value();
884         CORBA::Double theW2 = IncidentTubeGroupParams->SpinBox_DY->value();
885         CORBA::Double theL2 = IncidentTubeGroupParams->SpinBox_DZ->value();
886         CORBA::Double theH = ChamferGroupParams->SpinBox_DX->value();
887         CORBA::Double theW = ChamferGroupParams->SpinBox_DY->value();
888         CORBA::Double theRF = FilletGroupParams->SpinBox_DX->value();
889         CORBA::Boolean theHexMesh = HexMeshCheckBox->isChecked();
890
891 //      if (JunctionPointsSel->GroupBox1->isChecked()) {
892 //              CheckCompatiblePosition(theL1, theL2, myPoint1, myPoint2, myPoint3, 0.01);
893 //              theL1 = MainTubeGroupParams->SpinBox_DZ->value();
894 //              theL2 = IncidentTubeGroupParams->SpinBox_DZ->value();
895 //      }
896
897         // call engine function
898         if (ChamferGroupParams->GroupBox1->isChecked()) {
899                 if (JunctionPointsSel->GroupBox1->isChecked())
900                         anObj = anOper->MakePipeTShapeChamferWithPosition(theR1, theW1, theL1, theR2, theW2, theL2, theH, theW,
901                                         theHexMesh, myPoint1, myPoint2, myPoint3);
902                 else
903                         anObj = anOper->MakePipeTShapeChamfer(theR1, theW1, theL1, theR2, theW2, theL2, theH, theW, theHexMesh);
904         }
905         else if (FilletGroupParams->GroupBox1->isChecked()) {
906                 if (JunctionPointsSel->GroupBox1->isChecked())
907                         anObj = anOper->MakePipeTShapeFilletWithPosition(theR1, theW1, theL1, theR2, theW2, theL2, theRF,
908                                         theHexMesh, myPoint1, myPoint2, myPoint3);
909                 else
910                         anObj = anOper->MakePipeTShapeFillet(theR1, theW1, theL1, theR2, theW2, theL2, theRF, theHexMesh);
911         }
912         else {
913                 if (JunctionPointsSel->GroupBox1->isChecked())
914                 anObj = anOper->MakePipeTShapeWithPosition(theR1, theW1, theL1, theR2, theW2, theL2, theHexMesh, myPoint1,
915                                 myPoint2, myPoint3);
916                 else
917                         anObj = anOper->MakePipeTShape(theR1, theW1, theL1, theR2, theW2, theL2, theHexMesh);
918         }
919
920         res = anObj->length();
921         if (!res)
922                 return false;
923
924         //   res = !anObj->_is_nil();
925         if (res && !IsPreview()) {
926                 QStringList aParameters;
927                 //@@ put stringified input parameters to the string list here to store in the data model for notebook @@//
928                 aParameters << MainTubeGroupParams->SpinBox_DX->text(); // R1 parameter
929                 aParameters << MainTubeGroupParams->SpinBox_DY->text(); // W1 parameter
930                 aParameters << MainTubeGroupParams->SpinBox_DZ->text(); // L1 parameter
931                 aParameters << IncidentTubeGroupParams->SpinBox_DX->text(); // R2 parameter
932                 aParameters << IncidentTubeGroupParams->SpinBox_DY->text(); // W2 parameter
933                 aParameters << IncidentTubeGroupParams->SpinBox_DZ->text(); // L2 parameter
934                 if (ChamferGroupParams->GroupBox1->isChecked()) {// Chamfer parameter
935                         aParameters << ChamferGroupParams->SpinBox_DX->text(); // H parameter
936                         aParameters << ChamferGroupParams->SpinBox_DY->text(); // W parameter
937                 }
938                 if (FilletGroupParams->GroupBox1->isChecked()) // Fillet parameter
939                         aParameters << FilletGroupParams->SpinBox_DX->text(); // RF parameter
940
941                 if (aParameters.count() > 0)
942                         anObj[0]->SetParameters(aParameters.join(":").toLatin1().constData());
943         }
944
945         objects.push_back(anObj[0]._retn());
946         pipeTShapeGroupObjects.clear();
947         for (int i = 1, n = anObj->length(); i < n; i++) {
948                 pipeTShapeGroupObjects.push_back(anObj[i]._retn());
949         }
950
951         return objects.size() > 0;
952 }
953
954 //=================================================================================
955 // function : restoreSubShapes
956 // purpose  :
957 //=================================================================================
958 void AdvancedGUI_PipeTShapeDlg::restoreSubShapes(SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_ptr theSObject) {
959         SALOMEDS::GenericAttribute_var anAttr;
960         if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
961                 return;
962
963         SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
964         CORBA::String_var anIORso = anAttrIOR->Value();
965
966         // get Object from SObject
967         GEOM::GEOM_Object_var theFather = GEOM::GEOM_Object::_narrow(myGeomGUI->getApp()->orb()->string_to_object(anIORso));
968         if (CORBA::is_nil(theFather))
969                 return;
970
971         ObjectList::iterator it = pipeTShapeGroupObjects.begin();
972
973         for (int i = 0; it != pipeTShapeGroupObjects.end(); it++, i++) {
974                 getGeomEngine()->AddInStudy(theStudy, (*it), tr((*it)->GetName()).toStdString().c_str(), theFather);
975         }
976
977 }