Salome HOME
Merge from V6_main 01/04/2013
[modules/geom.git] / src / AdvancedGUI / AdvancedGUI_PipeTShapeDlg.cxx
1 // Copyright (C) 2007-2013  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 <LightApp_SelectionMgr.h>
30 #include <SalomeApp_Application.h>
31 #include <SalomeApp_Tools.h>
32
33 // OCCT Includes
34 #include <BRep_Tool.hxx>
35 #include <TopTools_IndexedMapOfShape.hxx>
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS.hxx>
38 #include <TopExp.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <gp_Pnt.hxx>
41
42 #include <QTabWidget>
43
44 #include <GEOMImpl_Types.hxx>
45
46 //=================================================================================
47 // Constructor
48 //=================================================================================
49 AdvancedGUI_PipeTShapeDlg::AdvancedGUI_PipeTShapeDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
50   : GEOMBase_Skeleton(theGeometryGUI, parent, false)
51 {
52   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
53   //QPixmap imageOp  = aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PIPETSHAPE"));
54   QPixmap imageSel = aResMgr->loadPixmap("GEOM", tr("ICON_SELECT"));
55   QPixmap imageImp = aResMgr->loadPixmap("GEOM", tr("ICO_PIPETSHAPE_IMPORT"));
56   imagePipeTShape  = aResMgr->loadPixmap("GEOM", tr("DLG_PIPETSHAPE"));
57   imageReduction   = aResMgr->loadPixmap("GEOM", tr("IMG_PIPETSHAPE_SECT"));
58
59   setWindowTitle(tr("GEOM_PIPE_TSHAPE_TITLE"));
60
61   /***************************************************************/
62   mainFrame()->GroupConstructors->setAttribute(Qt::WA_DeleteOnClose);
63   mainFrame()->GroupConstructors->close();
64
65   QTabWidget* aTabWidget = new QTabWidget (centralWidget());
66
67   QGridLayout* myMainLayout = new QGridLayout (centralWidget());
68   myMainLayout->setMargin(0);
69   myMainLayout->setSpacing(6);
70
71   // Main parameters
72   QGroupBox* GroupMain = new QGroupBox();
73   QGridLayout* layoutGroupMain = new QGridLayout (GroupMain);
74
75   MainTubeGroupParams = new DlgRef_3Spin();
76   MainTubeGroupParams->GroupBox1->setTitle(tr("GEOM_PIPE_TSHAPE_MPIPE"));
77   MainTubeGroupParams->TextLabel1->setText(tr("GEOM_PIPE_TSHAPE_R"));
78   MainTubeGroupParams->TextLabel2->setText(tr("GEOM_PIPE_TSHAPE_W"));
79   MainTubeGroupParams->TextLabel3->setText(tr("GEOM_PIPE_TSHAPE_L"));
80   MainTubeGroupParams->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); // ??
81
82   IncidentTubeGroupParams = new DlgRef_3Spin();
83   IncidentTubeGroupParams->GroupBox1->setTitle(tr("GEOM_PIPE_TSHAPE_IPIPE"));
84   IncidentTubeGroupParams->TextLabel1->setText(tr("GEOM_PIPE_TSHAPE_R"));
85   IncidentTubeGroupParams->TextLabel2->setText(tr("GEOM_PIPE_TSHAPE_W"));
86   IncidentTubeGroupParams->TextLabel3->setText(tr("GEOM_PIPE_TSHAPE_L"));
87
88   ChamferGroupParams = new DlgRef_2Spin();
89   ChamferGroupParams->GroupBox1->setCheckable(true);
90   ChamferGroupParams->GroupBox1->setChecked(false);
91   ChamferGroupParams->GroupBox1->setTitle(tr("GEOM_PIPE_TSHAPE_CHAMFER"));
92   ChamferGroupParams->TextLabel1->setText(tr("GEOM_PIPE_TSHAPE_CHAMFER_H"));
93   ChamferGroupParams->TextLabel2->setText(tr("GEOM_PIPE_TSHAPE_CHAMFER_W"));
94
95   FilletGroupParams = new DlgRef_1Spin();
96   FilletGroupParams->GroupBox1->setCheckable(true);
97   FilletGroupParams->GroupBox1->setChecked(false);
98   FilletGroupParams->GroupBox1->setTitle(tr("GEOM_PIPE_TSHAPE_FILLET"));
99   FilletGroupParams->TextLabel1->setText(tr("GEOM_PIPE_TSHAPE_R"));
100
101   HexMeshCheckBox = new QCheckBox();
102   HexMeshCheckBox->setText(tr("GEOM_PIPE_TSHAPE_HEX"));
103   HexMeshCheckBox->setChecked(true);
104
105   LabelImgPipeTShape = new QLabel();
106   LabelImgPipeTShape->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
107   LabelImgPipeTShape->setAlignment(Qt::AlignCenter);
108   LabelImgPipeTShape->setMinimumSize(300, 300);
109
110   layoutGroupMain->addWidget(MainTubeGroupParams, 0, 0, 1, 1);
111   layoutGroupMain->addWidget(IncidentTubeGroupParams, 1, 0, 1, 1);
112   layoutGroupMain->addWidget(ChamferGroupParams, 2, 0, 1, 1);
113   layoutGroupMain->addWidget(FilletGroupParams, 3, 0, 1, 1);
114   layoutGroupMain->addWidget(HexMeshCheckBox, 4, 0, 1, 1);
115
116   layoutGroupMain->addWidget(LabelImgPipeTShape, 0, 1, 5, 1);
117   layoutGroupMain->setColumnStretch(1, 1); // stretch of column 0 is supposed 0 by default
118
119   // Thickness reduction parameters
120   QGroupBox* GroupReduct = new QGroupBox();
121   QGridLayout* layoutGroupReduct = new QGridLayout (GroupReduct);
122
123   LReductionGroupParams = new AdvancedGUI_4Spin();
124   LReductionGroupParams->GroupBox1->setCheckable(true);
125   LReductionGroupParams->GroupBox1->setChecked(false);
126   LReductionGroupParams->GroupBox1->setTitle(tr("GEOM_PIPE_TSHAPE_LEFT_TR"));
127   LReductionGroupParams->TextLabel1->setText(tr("GEOM_PIPE_TSHAPE_TR_R").arg("L"));
128   LReductionGroupParams->TextLabel2->setText(tr("GEOM_PIPE_TSHAPE_TR_W").arg("L"));
129   LReductionGroupParams->TextLabel3->setText(tr("GEOM_PIPE_TSHAPE_TR_L_TRANS").arg("L"));
130   LReductionGroupParams->TextLabel4->setText(tr("GEOM_PIPE_TSHAPE_TR_L_THIN").arg("L"));
131
132   RReductionGroupParams = new AdvancedGUI_4Spin();
133   RReductionGroupParams->GroupBox1->setCheckable(true);
134   RReductionGroupParams->GroupBox1->setChecked(false);
135   RReductionGroupParams->GroupBox1->setTitle(tr("GEOM_PIPE_TSHAPE_RIGHT_TR"));
136   RReductionGroupParams->TextLabel1->setText(tr("GEOM_PIPE_TSHAPE_TR_R").arg("R"));
137   RReductionGroupParams->TextLabel2->setText(tr("GEOM_PIPE_TSHAPE_TR_W").arg("R"));
138   RReductionGroupParams->TextLabel3->setText(tr("GEOM_PIPE_TSHAPE_TR_L_TRANS").arg("R"));
139   RReductionGroupParams->TextLabel4->setText(tr("GEOM_PIPE_TSHAPE_TR_L_THIN").arg("R"));
140
141   IReductionGroupParams = new AdvancedGUI_4Spin();
142   IReductionGroupParams->GroupBox1->setCheckable(true);
143   IReductionGroupParams->GroupBox1->setChecked(false);
144   IReductionGroupParams->GroupBox1->setTitle(tr("GEOM_PIPE_TSHAPE_INCI_TR"));
145   IReductionGroupParams->TextLabel1->setText(tr("GEOM_PIPE_TSHAPE_TR_R").arg("I"));
146   IReductionGroupParams->TextLabel2->setText(tr("GEOM_PIPE_TSHAPE_TR_W").arg("I"));
147   IReductionGroupParams->TextLabel3->setText(tr("GEOM_PIPE_TSHAPE_TR_L_TRANS").arg("I"));
148   IReductionGroupParams->TextLabel4->setText(tr("GEOM_PIPE_TSHAPE_TR_L_THIN").arg("I"));
149
150   LabelImgReduction = new QLabel();
151   LabelImgReduction->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
152   LabelImgReduction->setAlignment(Qt::AlignCenter);
153   LabelImgReduction->setMinimumSize(300, 300);
154
155   layoutGroupReduct->addWidget(LReductionGroupParams->GroupBox1, 0, 0, 1, 1);
156   layoutGroupReduct->addWidget(RReductionGroupParams->GroupBox1, 1, 0, 1, 1);
157   layoutGroupReduct->addWidget(IReductionGroupParams->GroupBox1, 2, 0, 1, 1);
158
159   layoutGroupReduct->addWidget(LabelImgReduction, 0, 1, 3, 1);
160   layoutGroupReduct->setColumnStretch(1, 1); // stretch of column 0 is supposed 0 by default
161
162   // Position parameters
163   QGroupBox* GroupPos = new QGroupBox();
164   QVBoxLayout* layoutGroupPos = new QVBoxLayout (GroupPos);
165
166   JunctionPointsSel = new DlgRef_6Sel();
167   JunctionPointsSel->GroupBox1->setTitle(tr("GEOM_PIPE_TSHAPE_POSITION"));
168   JunctionPointsSel->GroupBox1->setCheckable(true);
169   JunctionPointsSel->GroupBox1->setChecked(false);
170   JunctionPointsSel->PushButton1->setIcon(imageSel);
171   JunctionPointsSel->LineEdit1->setReadOnly(true);
172   JunctionPointsSel->LineEdit1->setText("");
173   JunctionPointsSel->TextLabel1->setText(tr("GEOM_PIPE_TSHAPE_POSITION_P1"));
174
175   JunctionPointsSel->PushButton2->setIcon(imageSel);
176   JunctionPointsSel->LineEdit2->setReadOnly(true);
177   JunctionPointsSel->LineEdit2->setText("");
178   JunctionPointsSel->TextLabel2->setText(tr("GEOM_PIPE_TSHAPE_POSITION_P2"));
179
180   JunctionPointsSel->PushButton3->setIcon(imageSel);
181   JunctionPointsSel->LineEdit3->setReadOnly(true);
182   JunctionPointsSel->LineEdit3->setText("");
183   JunctionPointsSel->TextLabel3->setText(tr("GEOM_PIPE_TSHAPE_POSITION_P3"));
184
185   JunctionPointsSel->PushButton4->setIcon(imageImp);
186   JunctionPointsSel->LineEdit4->setReadOnly(true);
187   JunctionPointsSel->LineEdit4->setText("");
188   JunctionPointsSel->TextLabel4->setText(tr("GEOM_PIPE_TSHAPE_POSITION_LBL_L1"));
189
190   JunctionPointsSel->PushButton5->setIcon(imageImp);
191   JunctionPointsSel->LineEdit5->setReadOnly(true);
192   JunctionPointsSel->LineEdit5->setText("");
193   JunctionPointsSel->TextLabel5->setText(tr("GEOM_PIPE_TSHAPE_POSITION_LBL_L2"));
194
195   JunctionPointsSel->PushButton6->setAttribute(Qt::WA_DeleteOnClose);
196   JunctionPointsSel->PushButton6->close();
197   JunctionPointsSel->LineEdit6->setAttribute(Qt::WA_DeleteOnClose);
198   JunctionPointsSel->LineEdit6->close();
199   JunctionPointsSel->TextLabel6->setAttribute(Qt::WA_DeleteOnClose);
200   JunctionPointsSel->TextLabel6->close();
201
202   layoutGroupPos->addWidget(JunctionPointsSel);
203   layoutGroupPos->addStretch();
204
205   //aTabWidget->addTab(GroupMain, imageOp, tr("GEOM_PIPETSHAPE_GROUPMAIN"));
206   aTabWidget->addTab(GroupMain, tr("GEOM_PIPETSHAPE_GROUPMAIN"));
207   aTabWidget->addTab(GroupReduct, tr("GEOM_PIPETSHAPE_GROUPREDUCT"));
208   aTabWidget->addTab(GroupPos, tr("GEOM_PIPETSHAPE_GROUPPOS"));
209
210   myMainLayout->addWidget(aTabWidget, 0, 0, 1, 1);
211   connect(aTabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
212   /***************************************************************/
213
214   setHelpFileName("create_pipetshape_page.html");
215
216   Init();
217 }
218
219 //=================================================================================
220 // Destructor
221 //=================================================================================
222 AdvancedGUI_PipeTShapeDlg::~AdvancedGUI_PipeTShapeDlg() {
223   // no need to delete child widgets, Qt does it all for us
224 }
225
226 //=================================================================================
227 // function : Init()
228 // purpose  :
229 //=================================================================================
230 void AdvancedGUI_PipeTShapeDlg::Init()
231 {
232   // Get setting of step value from file configuration
233   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
234   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
235   double minValue = Precision::Approximation();
236
237   myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
238   myOkPoint1 = myOkPoint2 = myOkPoint3 = false;
239
240   pipeTShapeGroupObjects.clear();
241
242   // min, max, step and decimals for spin boxes
243   initSpinBox(MainTubeGroupParams->SpinBox_DX, minValue, COORD_MAX, step, "length_precision");
244   initSpinBox(MainTubeGroupParams->SpinBox_DY, minValue, COORD_MAX, step, "length_precision");
245   initSpinBox(MainTubeGroupParams->SpinBox_DZ, minValue, COORD_MAX, step, "length_precision");
246   initSpinBox(IncidentTubeGroupParams->SpinBox_DX, minValue, COORD_MAX, step, "length_precision");
247   initSpinBox(IncidentTubeGroupParams->SpinBox_DY, minValue, COORD_MAX, step, "length_precision");
248   initSpinBox(IncidentTubeGroupParams->SpinBox_DZ, minValue, COORD_MAX, step, "length_precision");
249   initSpinBox(ChamferGroupParams->SpinBox_DX, minValue, COORD_MAX, step, "length_precision");
250   initSpinBox(ChamferGroupParams->SpinBox_DY, minValue, COORD_MAX, step, "length_precision");
251   initSpinBox(FilletGroupParams->SpinBox_DX, minValue, COORD_MAX, step, "length_precision");
252
253   initSpinBox(LReductionGroupParams->SpinBox1, minValue, COORD_MAX, step, "length_precision");
254   initSpinBox(LReductionGroupParams->SpinBox2, minValue, COORD_MAX, step, "length_precision");
255   initSpinBox(LReductionGroupParams->SpinBox3, minValue, COORD_MAX, step, "length_precision");
256   initSpinBox(LReductionGroupParams->SpinBox4, 0.,       COORD_MAX, step, "length_precision");
257
258   initSpinBox(RReductionGroupParams->SpinBox1, minValue, COORD_MAX, step, "length_precision");
259   initSpinBox(RReductionGroupParams->SpinBox2, minValue, COORD_MAX, step, "length_precision");
260   initSpinBox(RReductionGroupParams->SpinBox3, minValue, COORD_MAX, step, "length_precision");
261   initSpinBox(RReductionGroupParams->SpinBox4, 0.,       COORD_MAX, step, "length_precision");
262
263   initSpinBox(IReductionGroupParams->SpinBox1, minValue, COORD_MAX, step, "length_precision");
264   initSpinBox(IReductionGroupParams->SpinBox2, minValue, COORD_MAX, step, "length_precision");
265   initSpinBox(IReductionGroupParams->SpinBox3, minValue, COORD_MAX, step, "length_precision");
266   initSpinBox(IReductionGroupParams->SpinBox4, 0.,       COORD_MAX, step, "length_precision");
267
268   // init variables
269   MainTubeGroupParams->SpinBox_DX->setValue(80);
270   MainTubeGroupParams->SpinBox_DY->setValue(20);
271   MainTubeGroupParams->SpinBox_DZ->setValue(200);
272   IncidentTubeGroupParams->SpinBox_DX->setValue(50);
273   IncidentTubeGroupParams->SpinBox_DY->setValue(20);
274   IncidentTubeGroupParams->SpinBox_DZ->setValue(200);
275   ChamferGroupParams->SpinBox_DX->setValue(20);
276   ChamferGroupParams->SpinBox_DY->setValue(10);
277   FilletGroupParams->SpinBox_DX->setValue(20);
278
279   LReductionGroupParams->SpinBox1->setValue(60);
280   LReductionGroupParams->SpinBox2->setValue(30);
281   LReductionGroupParams->SpinBox3->setValue(40);
282   LReductionGroupParams->SpinBox4->setValue(20);
283
284   RReductionGroupParams->SpinBox1->setValue(60);
285   RReductionGroupParams->SpinBox2->setValue(30);
286   RReductionGroupParams->SpinBox3->setValue(40);
287   RReductionGroupParams->SpinBox4->setValue(20);
288
289   IReductionGroupParams->SpinBox1->setValue(40);
290   IReductionGroupParams->SpinBox2->setValue(10);
291   IReductionGroupParams->SpinBox3->setValue(30);
292   IReductionGroupParams->SpinBox4->setValue(15);
293
294   CssNormal = QString("QDoubleSpinBox {");
295   CssNormal.append(MainTubeGroupParams->SpinBox_DZ->styleSheet());
296   CssNormal.append("}");
297   CssNormal.append("\nQPushButton {");
298   CssNormal.append(JunctionPointsSel->PushButton4->styleSheet());
299   CssNormal.append("}");
300   CssAcceptable = "QDoubleSpinBox, QPushButton {background-color: rgb(85, 170, 127)}";
301   CssRefused = "QDoubleSpinBox, QPushButton {background-color: rgb(255, 0, 0)}";
302
303   showOnlyPreviewControl();
304
305   // Signal/slot connections
306   connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
307   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
308   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
309   //connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
310   // ValueChangedInSpinBox
311   connect(MainTubeGroupParams->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
312   connect(MainTubeGroupParams->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
313   connect(MainTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
314   connect(IncidentTubeGroupParams->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
315   connect(IncidentTubeGroupParams->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
316   connect(IncidentTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
317   connect(ChamferGroupParams->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
318   connect(ChamferGroupParams->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
319   connect(FilletGroupParams->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
320   // ChamferOrFillet
321   connect(ChamferGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, SLOT(ChamferOrFillet(bool)));
322   connect(FilletGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, SLOT(ChamferOrFillet(bool)));
323   // Preview
324   //connect(PreviewPushButton, SIGNAL(clicked()), this, SLOT(DisplayPreview()));
325   // Position
326   connect(JunctionPointsSel->GroupBox1, SIGNAL(toggled(bool)), this, SLOT(SetPosition(bool)));
327   connect(JunctionPointsSel->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
328   connect(JunctionPointsSel->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
329   connect(JunctionPointsSel->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
330   // ApplyNewDimensions
331   connect(JunctionPointsSel->PushButton4, SIGNAL(clicked()), this, SLOT(ApplyNewDimensions()));
332   connect(JunctionPointsSel->PushButton5, SIGNAL(clicked()), this, SLOT(ApplyNewDimensions()));
333   connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(UpdatePicture(QWidget*, QWidget*)));
334   //@@ put additional signal/slot connections here @@//
335
336   initName(tr("GEOM_PIPE_TSHAPE"));
337
338   qApp->processEvents();
339   updateGeometry();
340   resize(minimumSizeHint());
341
342   updateLabelImgPipeTShape();
343   LabelImgReduction->setPixmap(imageReduction.scaled(LabelImgReduction->size(),
344                                                      Qt::KeepAspectRatio,
345                                                      Qt::SmoothTransformation));
346   processPreview();
347 }
348
349 //=================================================================================
350 // function : currentChanged()
351 // purpose  : Tab widget management
352 //=================================================================================
353 void AdvancedGUI_PipeTShapeDlg::currentChanged (int tabId)
354 {
355   if (tabId == 0 || tabId == 1)
356     resizeEvent(NULL);
357 }
358
359 //=================================================================================
360 // function : ApplyNewDimensions()
361 // purpose  :
362 //=================================================================================
363 void AdvancedGUI_PipeTShapeDlg::ApplyNewDimensions()
364 {
365   QPushButton* send = (QPushButton*) sender();
366
367   bool ok = false;
368   double newVal;
369   if (send == JunctionPointsSel->PushButton4) {
370     if (!JunctionPointsSel->LineEdit4->text().isEmpty()) {
371       newVal = JunctionPointsSel->LineEdit4->text().toDouble(&ok);
372       if (ok) {
373         disconnect(MainTubeGroupParams->SpinBox_DZ, 0, this, 0);
374         MainTubeGroupParams->SpinBox_DZ->setValue(newVal);
375         connect(MainTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
376         MainTubeGroupParams->SpinBox_DZ->setToolTip("");
377         MainTubeGroupParams->SpinBox_DZ->setStyleSheet("background-color: rgb(255, 255, 255);");
378         CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
379         processPreview();
380       }
381     }
382   }
383   else if (send == JunctionPointsSel->PushButton5) {
384     if (!JunctionPointsSel->LineEdit5->text().isEmpty()) {
385       newVal = JunctionPointsSel->LineEdit5->text().toDouble(&ok);
386       if (ok) {
387         disconnect(IncidentTubeGroupParams->SpinBox_DZ, 0, this, 0);
388         IncidentTubeGroupParams->SpinBox_DZ->setValue(newVal);
389         connect(IncidentTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
390         IncidentTubeGroupParams->SpinBox_DZ->setToolTip("");
391         IncidentTubeGroupParams->SpinBox_DZ->setStyleSheet("background-color: rgb(255, 255, 255);");
392         CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
393         processPreview();
394       }
395     }
396   }
397 }
398
399 //=================================================================================
400 // function : UpdatePicture()
401 // purpose  :
402 //=================================================================================
403 void AdvancedGUI_PipeTShapeDlg::UpdatePicture (QWidget* old, QWidget* now)
404 {
405   if (ChamferGroupParams->GroupBox1->isChecked())
406     if (now == MainTubeGroupParams->SpinBox_DX)
407       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_R1"));
408     else if (now == MainTubeGroupParams->SpinBox_DY)
409       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_W1"));
410     else if (now == MainTubeGroupParams->SpinBox_DZ)
411       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_L1"));
412     else if (now == IncidentTubeGroupParams->SpinBox_DX)
413       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_R2"));
414     else if (now == IncidentTubeGroupParams->SpinBox_DY)
415       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_W2"));
416     else if (now == IncidentTubeGroupParams->SpinBox_DZ)
417       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_L2"));
418     else if (now == ChamferGroupParams->SpinBox_DX)
419       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_H"));
420     else if (now == ChamferGroupParams->SpinBox_DY)
421       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER_W"));
422     else
423       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER"));
424   else if (FilletGroupParams->GroupBox1->isChecked())
425     if (now == MainTubeGroupParams->SpinBox_DX)
426       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_R1"));
427     else if (now == MainTubeGroupParams->SpinBox_DY)
428       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_W1"));
429     else if (now == MainTubeGroupParams->SpinBox_DZ)
430       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_L1"));
431     else if (now == IncidentTubeGroupParams->SpinBox_DX)
432       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_R2"));
433     else if (now == IncidentTubeGroupParams->SpinBox_DY)
434       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_W2"));
435     else if (now == IncidentTubeGroupParams->SpinBox_DZ)
436       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_L2"));
437     else if (now == FilletGroupParams->SpinBox_DX)
438       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET_RF"));
439     else
440       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET"));
441   else
442     if (now == MainTubeGroupParams->SpinBox_DX)
443       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_R1"));
444     else if (now == MainTubeGroupParams->SpinBox_DY)
445       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_W1"));
446     else if (now == MainTubeGroupParams->SpinBox_DZ)
447       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_L1"));
448     else if (now == IncidentTubeGroupParams->SpinBox_DX)
449       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_R2"));
450     else if (now == IncidentTubeGroupParams->SpinBox_DY)
451       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_W2"));
452     else if (now == IncidentTubeGroupParams->SpinBox_DZ)
453       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_L2"));
454     else
455       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE"));
456
457   updateLabelImgPipeTShape();
458 }
459
460 //=================================================================================
461 // function : SetPosition()
462 // purpose  :
463 //=================================================================================
464 void AdvancedGUI_PipeTShapeDlg::SetPosition (bool isChecked)
465 {
466   if (isChecked) {
467     erasePreview();
468     JunctionPointsSel->LineEdit4->setText("");
469     JunctionPointsSel->LineEdit5->setText("");
470     //connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(
471     //SelectionIntoArgument()));
472     JunctionPointsSel->PushButton1->click();
473     SelectionIntoArgument();
474   }
475   else {
476     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
477     JunctionPointsSel->LineEdit4->setText("");
478     JunctionPointsSel->LineEdit5->setText("");
479     processPreview();
480   }
481 }
482
483 //=================================================================================
484 // function : ValueChangedInSpinBox()
485 // purpose  :
486 //=================================================================================
487 void AdvancedGUI_PipeTShapeDlg::ValueChangedInSpinBox (double newValue)
488 {
489   if (JunctionPointsSel->GroupBox1->isChecked() && myOkPoint1 && myOkPoint2 && myOkPoint3)
490     CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
491   processPreview();
492 }
493
494 //=================================================================================
495 // function : SelectionIntoArgument()
496 // purpose  : Called when selection as changed or other case
497 //=================================================================================
498 void AdvancedGUI_PipeTShapeDlg::SelectionIntoArgument()
499 {
500   erasePreview();
501   //myEditCurrentArgument->setText("");
502
503   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
504   SALOME_ListIO aSelList;
505   aSelMgr->selectedObjects(aSelList);
506
507   if (aSelList.Extent() != 1) {
508     if (myEditCurrentArgument == JunctionPointsSel->LineEdit1)
509       myOkPoint1 = false;
510     else if (myEditCurrentArgument == JunctionPointsSel->LineEdit2)
511       myOkPoint2 = false;
512     else if (myEditCurrentArgument == JunctionPointsSel->LineEdit3)
513       myOkPoint3 = false;
514     return;
515     myEditCurrentArgument->setText("");
516   }
517
518   // nbSel == 1
519   if (aSelList.Extent() == 1) {
520     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
521     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(anIO);
522     if (!CORBA::is_nil(aSelectedObject)) {
523       QString aName = GEOMBase::GetName(aSelectedObject);
524       TopoDS_Shape aShape;
525       if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) {
526
527         TColStd_IndexedMapOfInteger aMap;
528         aSelMgr->GetIndexes(anIO, aMap);
529         if (aMap.Extent() == 1) { // Local Selection
530           int anIndex = aMap(1);
531           aName += QString(":vertex_%1").arg(anIndex);
532
533           //Find SubShape Object in Father
534           GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
535
536           if (aFindedObject->_is_nil()) { // Object not found in study
537             GEOM::GEOM_IShapesOperations_var aShapesOp =
538               getGeomEngine()->GetIShapesOperations(getStudyId());
539             aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
540           }
541           else {
542             aSelectedObject = aFindedObject; // get Object from study
543           }
544           GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE);
545         } else { // Global Selection
546           if (aShape.ShapeType() != TopAbs_VERTEX) {
547             aSelectedObject = GEOM::GEOM_Object::_nil();
548             aName = "";
549           }
550         }
551       }
552
553       if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX) {
554         return;
555       }
556       myEditCurrentArgument->setText(aName);
557       if (myEditCurrentArgument == JunctionPointsSel->LineEdit1) {
558         myPoint1 = aSelectedObject;
559         myOkPoint1 = true;
560         if (!myOkPoint2)
561           JunctionPointsSel->PushButton2->click();
562       } else if (myEditCurrentArgument == JunctionPointsSel->LineEdit2) {
563         myPoint2 = aSelectedObject;
564         myOkPoint2 = true;
565         if (!myOkPoint3)
566           JunctionPointsSel->PushButton3->click();
567       } else if (myEditCurrentArgument == JunctionPointsSel->LineEdit3) {
568         myPoint3 = aSelectedObject;
569         myOkPoint3 = true;
570         if (!myOkPoint1)
571           JunctionPointsSel->PushButton1->click();
572       }
573     }
574   }
575
576   if (myOkPoint1 && myOkPoint2 && myOkPoint3) {
577     CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
578     processPreview();
579   }
580 }
581
582 //=================================================================================
583 // function : SetEditCurrentArgument()
584 // purpose  :
585 //=================================================================================
586 void AdvancedGUI_PipeTShapeDlg::SetEditCurrentArgument()
587 {
588   QPushButton* send = (QPushButton*) sender();
589
590   if (send == JunctionPointsSel->PushButton1) {
591     myEditCurrentArgument = JunctionPointsSel->LineEdit1;
592     JunctionPointsSel->PushButton2->setDown(false);
593     JunctionPointsSel->LineEdit2->setEnabled(false);
594     JunctionPointsSel->PushButton3->setDown(false);
595     JunctionPointsSel->LineEdit3->setEnabled(false);
596   }
597   else if (send == JunctionPointsSel->PushButton2) {
598     myEditCurrentArgument = JunctionPointsSel->LineEdit2;
599     JunctionPointsSel->PushButton1->setDown(false);
600     JunctionPointsSel->LineEdit1->setEnabled(false);
601     JunctionPointsSel->PushButton3->setDown(false);
602     JunctionPointsSel->LineEdit3->setEnabled(false);
603   }
604   else if (send == JunctionPointsSel->PushButton3) {
605     myEditCurrentArgument = JunctionPointsSel->LineEdit3;
606     JunctionPointsSel->PushButton1->setDown(false);
607     JunctionPointsSel->LineEdit1->setEnabled(false);
608     JunctionPointsSel->PushButton2->setDown(false);
609     JunctionPointsSel->LineEdit2->setEnabled(false);
610   }
611
612   // enable line edit
613   myEditCurrentArgument->setEnabled(true);
614   myEditCurrentArgument->setFocus();
615   myEditCurrentArgument->setText("");
616   // after setFocus(), because it will be setDown(false) when loses focus
617   send->setDown(true);
618
619   JunctionPointsSel->LineEdit4->setText("");
620   JunctionPointsSel->LineEdit5->setText("");
621
622   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
623   //globalSelection(GEOM_POINT);
624   globalSelection(); // close local contexts, if any
625   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
626   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
627           this, SLOT(SelectionIntoArgument()));
628 }
629
630 //=================================================================================
631 // function : SetDoubleSpinBoxStep()
632 // purpose  : Double spin box management
633 //=================================================================================
634 void AdvancedGUI_PipeTShapeDlg::SetDoubleSpinBoxStep (double step)
635 {
636   MainTubeGroupParams->SpinBox_DX->setSingleStep(step);
637   MainTubeGroupParams->SpinBox_DY->setSingleStep(step);
638   MainTubeGroupParams->SpinBox_DZ->setSingleStep(step);
639   IncidentTubeGroupParams->SpinBox_DX->setSingleStep(step);
640   IncidentTubeGroupParams->SpinBox_DY->setSingleStep(step);
641   IncidentTubeGroupParams->SpinBox_DZ->setSingleStep(step);
642   ChamferGroupParams->SpinBox_DX->setSingleStep(step);
643   ChamferGroupParams->SpinBox_DY->setSingleStep(step);
644   FilletGroupParams->SpinBox_DX->setSingleStep(step);
645
646   LReductionGroupParams->SpinBox1->setSingleStep(step);
647   LReductionGroupParams->SpinBox2->setSingleStep(step);
648   LReductionGroupParams->SpinBox3->setSingleStep(step);
649   LReductionGroupParams->SpinBox4->setSingleStep(step);
650
651   RReductionGroupParams->SpinBox1->setSingleStep(step);
652   RReductionGroupParams->SpinBox2->setSingleStep(step);
653   RReductionGroupParams->SpinBox3->setSingleStep(step);
654   RReductionGroupParams->SpinBox4->setSingleStep(step);
655
656   IReductionGroupParams->SpinBox1->setSingleStep(step);
657   IReductionGroupParams->SpinBox2->setSingleStep(step);
658   IReductionGroupParams->SpinBox3->setSingleStep(step);
659   IReductionGroupParams->SpinBox4->setSingleStep(step);
660 }
661
662 //=================================================================================
663 // function : ClickOnOk()
664 // purpose  :
665 //=================================================================================
666 void AdvancedGUI_PipeTShapeDlg::ClickOnOk()
667 {
668   setIsApplyAndClose( true );
669   if (ClickOnApply())
670     ClickOnCancel();
671 }
672
673 //=================================================================================
674 // function : ClickOnApply()
675 // purpose  :
676 //=================================================================================
677 bool AdvancedGUI_PipeTShapeDlg::ClickOnApply()
678 {
679   if (!onAccept())
680     return false;
681
682   initName();
683
684   return true;
685 }
686
687 //=================================================================================
688 // function : ActivateThisDialog()
689 // purpose  :
690 //=================================================================================
691 void AdvancedGUI_PipeTShapeDlg::ActivateThisDialog()
692 {
693   GEOMBase_Skeleton::ActivateThisDialog();
694   //globalSelection( GEOM_POINT);
695   //connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(
696   //        currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
697   if (myOkPoint1 && myOkPoint2 && myOkPoint3)
698     CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
699   processPreview();
700 }
701
702 //=================================================================================
703 // function : enterEvent [REDEFINED]
704 // purpose  :
705 //=================================================================================
706 void AdvancedGUI_PipeTShapeDlg::enterEvent (QEvent*)
707 {
708   if (!mainFrame()->GroupButtons->isEnabled())
709     ActivateThisDialog();
710 }
711
712 //=================================================================================
713 // function : resizeEvent [REDEFINED]
714 // purpose  :
715 //=================================================================================
716 void AdvancedGUI_PipeTShapeDlg::resizeEvent (QResizeEvent */*event*/)
717 {
718   QSize scaledSize1 = imagePipeTShape.size();
719   scaledSize1.scale(LabelImgPipeTShape->size(), Qt::KeepAspectRatio);
720   if (!LabelImgPipeTShape->pixmap() || scaledSize1 != LabelImgPipeTShape->pixmap()->size())
721     updateLabelImgPipeTShape();
722
723   QSize scaledSize2 = imageReduction.size();
724   scaledSize2.scale(LabelImgReduction->size(), Qt::KeepAspectRatio);
725   if (!LabelImgReduction->pixmap() || scaledSize2 != LabelImgReduction->pixmap()->size())
726     LabelImgReduction->setPixmap(imageReduction.scaled(LabelImgReduction->size(),
727                                                        Qt::KeepAspectRatio,
728                                                        Qt::SmoothTransformation));
729 }
730
731 //=================================================================================
732 // function : updateLabelImgPipeTShape
733 // purpose  :
734 //=================================================================================
735 void AdvancedGUI_PipeTShapeDlg::updateLabelImgPipeTShape()
736 {
737   LabelImgPipeTShape->setPixmap(imagePipeTShape.scaled(LabelImgPipeTShape->size(),
738                                                        Qt::KeepAspectRatio,
739                                                        Qt::SmoothTransformation));
740 }
741
742 //=================================================================================
743 // function : ChamferOrFillet()
744 // purpose  :
745 //=================================================================================
746 void AdvancedGUI_PipeTShapeDlg::ChamferOrFillet (bool)
747 {
748   QGroupBox* send = (QGroupBox*) sender();
749
750   if (send == ChamferGroupParams->GroupBox1) {
751     if (send->isChecked()) {
752       disconnect(FilletGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, 0);
753       FilletGroupParams->GroupBox1->setChecked(false);
754       connect(FilletGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, SLOT(ChamferOrFillet(bool)));
755       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_CHAMFER"));
756     }
757     else
758       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE"));
759
760     updateLabelImgPipeTShape();
761     if (myOkPoint1 && myOkPoint2 && myOkPoint3)
762       CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
763     processPreview();
764   }
765   else if (send == FilletGroupParams->GroupBox1) {
766     if (send->isChecked()) {
767       disconnect(ChamferGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, 0);
768       ChamferGroupParams->GroupBox1->setChecked(!send->isChecked());
769       connect(ChamferGroupParams->GroupBox1, SIGNAL(toggled(bool)), this, SLOT(ChamferOrFillet(bool)));
770       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE_FILLET"));
771     }
772     else
773       imagePipeTShape = SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("DLG_PIPETSHAPE"));
774
775     updateLabelImgPipeTShape();
776     if (myOkPoint1 && myOkPoint2 && myOkPoint3)
777       CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
778     processPreview();
779   }
780 }
781
782 //=================================================================================
783 // function : DisplayPreview()
784 // purpose  :
785 //=================================================================================
786 void AdvancedGUI_PipeTShapeDlg::DisplayPreview (const bool activate, const bool update,
787                                                 const bool toRemoveFromEngine, const double lineWidth,
788                                                 const int displayMode, const int color)
789 {
790   QString msg;
791   if (!isValid(msg)) {
792     erasePreview(update);
793     return;
794   }
795
796   erasePreview(false);
797
798   try {
799     SUIT_OverrideCursor wc;
800     ObjectList objects;
801     bool hexMeshState = HexMeshCheckBox->isChecked();
802     HexMeshCheckBox->setChecked(false);
803     if (!executeNoCheck(objects) || !getOperation()->IsDone()) {
804       wc.suspend();
805     }
806     else {
807       ObjectList::iterator it = objects.begin();
808       GEOM::GEOM_Object_var obj = *it;
809       displayPreview(obj, true, activate, false, lineWidth, displayMode, color);
810       if (toRemoveFromEngine)
811         obj->UnRegister();
812     }
813     HexMeshCheckBox->setChecked(hexMeshState);
814   } catch (const SALOME::SALOME_Exception& e) {
815     SalomeApp_Tools::QtCatchCorbaException(e);
816   }
817
818   if (update)
819     updateViewer();
820 }
821
822 //=================================================================================
823 // function : createOperation
824 // purpose  :
825 //=================================================================================
826 GEOM::GEOM_IOperations_ptr AdvancedGUI_PipeTShapeDlg::createOperation()
827 {
828   return getGeomEngine()->GetIAdvancedOperations(getStudyId());
829 }
830
831 //=================================================================================
832 // function : isValid
833 // purpose  :
834 //=================================================================================
835 bool AdvancedGUI_PipeTShapeDlg::isValid (QString& msg)
836 {
837   bool ok = true;
838
839   ok = MainTubeGroupParams->SpinBox_DX->isValid(msg, !IsPreview()) && ok;
840   ok = MainTubeGroupParams->SpinBox_DY->isValid(msg, !IsPreview()) && ok;
841   ok = MainTubeGroupParams->SpinBox_DZ->isValid(msg, !IsPreview()) && ok;
842   ok = IncidentTubeGroupParams->SpinBox_DX->isValid(msg, !IsPreview()) && ok;
843   ok = IncidentTubeGroupParams->SpinBox_DY->isValid(msg, !IsPreview()) && ok;
844   ok = IncidentTubeGroupParams->SpinBox_DZ->isValid(msg, !IsPreview()) && ok;
845   ok = ChamferGroupParams->SpinBox_DX->isValid(msg, !IsPreview()) && ok;
846   ok = ChamferGroupParams->SpinBox_DY->isValid(msg, !IsPreview()) && ok;
847   ok = FilletGroupParams->SpinBox_DX->isValid(msg, !IsPreview()) && ok;
848
849   if (LReductionGroupParams->GroupBox1->isChecked()) {
850     ok = LReductionGroupParams->SpinBox1->isValid(msg, !IsPreview()) && ok;
851     ok = LReductionGroupParams->SpinBox2->isValid(msg, !IsPreview()) && ok;
852     ok = LReductionGroupParams->SpinBox3->isValid(msg, !IsPreview()) && ok;
853     ok = LReductionGroupParams->SpinBox4->isValid(msg, !IsPreview()) && ok;
854   }
855   if (RReductionGroupParams->GroupBox1->isChecked()) {
856     ok = RReductionGroupParams->SpinBox1->isValid(msg, !IsPreview()) && ok;
857     ok = RReductionGroupParams->SpinBox2->isValid(msg, !IsPreview()) && ok;
858     ok = RReductionGroupParams->SpinBox3->isValid(msg, !IsPreview()) && ok;
859     ok = RReductionGroupParams->SpinBox4->isValid(msg, !IsPreview()) && ok;
860   }
861   if (IReductionGroupParams->GroupBox1->isChecked()) {
862     ok = IReductionGroupParams->SpinBox1->isValid(msg, !IsPreview()) && ok;
863     ok = IReductionGroupParams->SpinBox2->isValid(msg, !IsPreview()) && ok;
864     ok = IReductionGroupParams->SpinBox3->isValid(msg, !IsPreview()) && ok;
865     ok = IReductionGroupParams->SpinBox4->isValid(msg, !IsPreview()) && ok;
866   }
867
868   ok = fabs(MainTubeGroupParams->SpinBox_DX->value()) > Precision::Confusion() && ok;
869   ok = fabs(MainTubeGroupParams->SpinBox_DY->value()) > Precision::Confusion() && ok;
870   ok = fabs(MainTubeGroupParams->SpinBox_DZ->value()) > Precision::Confusion() && ok;
871   ok = fabs(IncidentTubeGroupParams->SpinBox_DX->value()) > Precision::Confusion() && ok;
872   ok = fabs(IncidentTubeGroupParams->SpinBox_DY->value()) > Precision::Confusion() && ok;
873   ok = fabs(IncidentTubeGroupParams->SpinBox_DZ->value()) > Precision::Confusion() && ok;
874   ok = fabs(ChamferGroupParams->SpinBox_DX->value()) > Precision::Confusion() && ok;
875   ok = fabs(ChamferGroupParams->SpinBox_DY->value()) > Precision::Confusion() && ok;
876   ok = fabs(FilletGroupParams->SpinBox_DX->value()) > Precision::Confusion() && ok;
877
878   if (JunctionPointsSel->GroupBox1->isChecked())
879     ok = myOkPoint1 && myOkPoint2 && myOkPoint3 && ok;
880
881   return ok;
882 }
883
884 //=================================================================================
885 // function : CheckCompatiblePosition()
886 // purpose  :
887 //=================================================================================
888 bool AdvancedGUI_PipeTShapeDlg::CheckCompatiblePosition
889      (GEOM::GEOM_Object_var theP1, GEOM::GEOM_Object_var theP2, GEOM::GEOM_Object_var theP3,
890       double theTolerance)
891 {
892   MainTubeGroupParams->SpinBox_DZ->setStyleSheet(CssNormal);
893   IncidentTubeGroupParams->SpinBox_DZ->setStyleSheet(CssNormal);
894   JunctionPointsSel->PushButton4->setStyleSheet(CssNormal);
895   JunctionPointsSel->PushButton5->setStyleSheet(CssNormal);
896
897   CORBA::Double theL1 = MainTubeGroupParams->SpinBox_DZ->value();
898   CORBA::Double theL2 = IncidentTubeGroupParams->SpinBox_DZ->value();
899
900   JunctionPointsSel->LineEdit4->setText("");
901   JunctionPointsSel->LineEdit5->setText("");
902
903   MainTubeGroupParams->SpinBox_DZ->setToolTip("");
904   IncidentTubeGroupParams->SpinBox_DZ->setToolTip("");
905
906   TopoDS_Shape aShape;
907   gp_Pnt P1, P2, P3;
908   if ( GEOMBase::GetShape( theP1, aShape ) && !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
909     P1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
910   else
911     return false;
912
913   if ( GEOMBase::GetShape( theP2, aShape ) && !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
914     P2 = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
915   else
916     return false;
917
918   if ( GEOMBase::GetShape( theP3, aShape ) && !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
919     P3 = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
920   else
921     return false;
922
923   double d12 = P1.Distance(P2);
924   double d13 = P1.Distance(P3);
925   double d23 = P2.Distance(P3);
926
927   if (Abs(d12) <= Precision::Confusion()) {
928     //SetErrorCode("Junctions points P1 and P2 are identical");
929     return false;
930   }
931   if (Abs(d13) <= Precision::Confusion()) {
932     //SetErrorCode("Junctions points P1 and P3 are identical");
933     return false;
934   }
935   if (Abs(d23) <= Precision::Confusion()) {
936     //SetErrorCode("Junctions points P2 and P3 are identical");
937     return false;
938   }
939
940   long double newL1 = 0.5 * d12;
941   long double newL2 = sqrt(pow(d13,2)-pow(newL1,2));
942
943   JunctionPointsSel->LineEdit4->setText(QString::number(newL1,'f',7));
944   JunctionPointsSel->LineEdit5->setText(QString::number(newL2,'f',7));
945
946   if (fabs(newL1 - theL1) > Precision::Approximation()) {
947     if ((newL1 * (1 - theTolerance) - theL1 <= Precision::Approximation()) &&
948         (newL1 * (1 + theTolerance) - theL1 >= Precision::Approximation())) {
949       disconnect(MainTubeGroupParams->SpinBox_DZ, 0, this, 0);
950       MainTubeGroupParams->SpinBox_DZ->setValue(newL1);
951       connect(MainTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged(double)),
952               this, SLOT(ValueChangedInSpinBox(double)));
953       MainTubeGroupParams->SpinBox_DZ->setToolTip("Value was recomputed to fit with position");
954       MainTubeGroupParams->SpinBox_DZ->setStyleSheet(CssAcceptable);
955       JunctionPointsSel->PushButton4->setStyleSheet(CssAcceptable);
956     }
957     else {
958       MainTubeGroupParams->SpinBox_DZ->setToolTip("Value is incompatible with position");
959       MainTubeGroupParams->SpinBox_DZ->setStyleSheet(CssRefused);
960       JunctionPointsSel->PushButton4->setStyleSheet(CssRefused);
961     }
962   }
963   else {
964     MainTubeGroupParams->SpinBox_DZ->setStyleSheet(CssNormal);
965     JunctionPointsSel->PushButton4->setStyleSheet(CssNormal);
966   }
967
968   if (fabs(newL2 - theL2) > Precision::Approximation()) {
969     if ((newL2 * (1 - theTolerance) - theL2 <= Precision::Approximation()) &&
970         (newL2 * (1 + theTolerance) - theL2 >= Precision::Approximation())) {
971       disconnect(IncidentTubeGroupParams->SpinBox_DZ, 0, this, 0);
972       IncidentTubeGroupParams->SpinBox_DZ->setValue(newL2);
973       connect(IncidentTubeGroupParams->SpinBox_DZ, SIGNAL(valueChanged( double )), this, SLOT(ValueChangedInSpinBox(double)));
974       IncidentTubeGroupParams->SpinBox_DZ->setToolTip("Value was recomputed to fit with position");
975       IncidentTubeGroupParams->SpinBox_DZ->setStyleSheet(CssAcceptable);
976       JunctionPointsSel->PushButton5->setStyleSheet(CssAcceptable);
977     }
978     else {
979       IncidentTubeGroupParams->SpinBox_DZ->setToolTip("Value is incompatible with position");
980       IncidentTubeGroupParams->SpinBox_DZ->setStyleSheet(CssRefused);
981       JunctionPointsSel->PushButton5->setStyleSheet(CssRefused);
982     }
983   }
984   else {
985     IncidentTubeGroupParams->SpinBox_DZ->setStyleSheet(CssNormal);
986     JunctionPointsSel->PushButton5->setStyleSheet(CssNormal);
987   }
988
989   return true;
990 }
991
992 //=================================================================================
993 // function : execute
994 // purpose  :
995 //=================================================================================
996 bool AdvancedGUI_PipeTShapeDlg::execute (ObjectList& objects)
997 {
998   if (JunctionPointsSel->GroupBox1->isChecked() && myOkPoint1 && myOkPoint2 && myOkPoint3)
999     CheckCompatiblePosition(myPoint1, myPoint2, myPoint3, 0.01);
1000
1001   return executeNoCheck(objects);
1002 }
1003
1004 //=================================================================================
1005 // function : executeNoCheck
1006 // purpose  :
1007 //=================================================================================
1008 bool AdvancedGUI_PipeTShapeDlg::executeNoCheck (ObjectList& objects)
1009 {
1010   bool res = false;
1011
1012   //   GEOM::GEOM_Object_var anObj;
1013   GEOM::ListOfGO_var anObj;
1014
1015   GEOM::GEOM_IAdvancedOperations_var anOper = GEOM::GEOM_IAdvancedOperations::_narrow(getOperation());
1016
1017   //@@ retrieve input values from the widgets here @@//
1018   CORBA::Double theR1 = MainTubeGroupParams->SpinBox_DX->value();
1019   CORBA::Double theW1 = MainTubeGroupParams->SpinBox_DY->value();
1020   CORBA::Double theL1 = MainTubeGroupParams->SpinBox_DZ->value();
1021   CORBA::Double theR2 = IncidentTubeGroupParams->SpinBox_DX->value();
1022   CORBA::Double theW2 = IncidentTubeGroupParams->SpinBox_DY->value();
1023   CORBA::Double theL2 = IncidentTubeGroupParams->SpinBox_DZ->value();
1024   CORBA::Double theH = ChamferGroupParams->SpinBox_DX->value();
1025   CORBA::Double theW = ChamferGroupParams->SpinBox_DY->value();
1026   CORBA::Double theRF = FilletGroupParams->SpinBox_DX->value();
1027   CORBA::Boolean theHexMesh = HexMeshCheckBox->isChecked();
1028
1029   // Thickness reductions
1030   CORBA::Double theRL = 0., theWL = 0., theLtransL = 0., theLthinL = 0.;
1031   CORBA::Double theRR = 0., theWR = 0., theLtransR = 0., theLthinR = 0.;
1032   CORBA::Double theRI = 0., theWI = 0., theLtransI = 0., theLthinI = 0.;
1033
1034   if (LReductionGroupParams->GroupBox1->isChecked()) {
1035     theRL = LReductionGroupParams->SpinBox1->value();
1036     theWL = LReductionGroupParams->SpinBox2->value();
1037     theLtransL = LReductionGroupParams->SpinBox3->value();
1038     theLthinL = LReductionGroupParams->SpinBox4->value();
1039   }
1040   if (RReductionGroupParams->GroupBox1->isChecked()) {
1041     theRR = RReductionGroupParams->SpinBox1->value();
1042     theWR = RReductionGroupParams->SpinBox2->value();
1043     theLtransR = RReductionGroupParams->SpinBox3->value();
1044     theLthinR = RReductionGroupParams->SpinBox4->value();
1045   }
1046   if (IReductionGroupParams->GroupBox1->isChecked()) {
1047     theRI = IReductionGroupParams->SpinBox1->value();
1048     theWI = IReductionGroupParams->SpinBox2->value();
1049     theLtransI = IReductionGroupParams->SpinBox3->value();
1050     theLthinI = IReductionGroupParams->SpinBox4->value();
1051   }
1052
1053   //if (JunctionPointsSel->GroupBox1->isChecked()) {
1054   //  CheckCompatiblePosition(theL1, theL2, myPoint1, myPoint2, myPoint3, 0.01);
1055   //  theL1 = MainTubeGroupParams->SpinBox_DZ->value();
1056   //  theL2 = IncidentTubeGroupParams->SpinBox_DZ->value();
1057   //}
1058
1059   // call engine function
1060   if (ChamferGroupParams->GroupBox1->isChecked()) {
1061     if (JunctionPointsSel->GroupBox1->isChecked())
1062       anObj = anOper->MakePipeTShapeTRChamferWithPosition(theR1, theW1, theL1, theR2, theW2, theL2,
1063                                                           theRL, theWL, theLtransL, theLthinL,
1064                                                           theRR, theWR, theLtransR, theLthinR,
1065                                                           theRI, theWI, theLtransI, theLthinI,
1066                                                           theH, theW, theHexMesh, myPoint1, myPoint2, myPoint3);
1067     else
1068       anObj = anOper->MakePipeTShapeTRChamfer(theR1, theW1, theL1, theR2, theW2, theL2,
1069                                               theRL, theWL, theLtransL, theLthinL,
1070                                               theRR, theWR, theLtransR, theLthinR,
1071                                               theRI, theWI, theLtransI, theLthinI,
1072                                               theH, theW, theHexMesh);
1073   }
1074   else if (FilletGroupParams->GroupBox1->isChecked()) {
1075     if (JunctionPointsSel->GroupBox1->isChecked())
1076       anObj = anOper->MakePipeTShapeTRFilletWithPosition(theR1, theW1, theL1, theR2, theW2, theL2,
1077                                                          theRL, theWL, theLtransL, theLthinL,
1078                                                          theRR, theWR, theLtransR, theLthinR,
1079                                                          theRI, theWI, theLtransI, theLthinI,
1080                                                          theRF, theHexMesh, myPoint1, myPoint2, myPoint3);
1081     else
1082       anObj = anOper->MakePipeTShapeTRFillet(theR1, theW1, theL1, theR2, theW2, theL2,
1083                                              theRL, theWL, theLtransL, theLthinL,
1084                                              theRR, theWR, theLtransR, theLthinR,
1085                                              theRI, theWI, theLtransI, theLthinI,
1086                                              theRF, theHexMesh);
1087   }
1088   else {
1089     if (JunctionPointsSel->GroupBox1->isChecked())
1090       anObj = anOper->MakePipeTShapeTRWithPosition(theR1, theW1, theL1, theR2, theW2, theL2,
1091                                                    theRL, theWL, theLtransL, theLthinL,
1092                                                    theRR, theWR, theLtransR, theLthinR,
1093                                                    theRI, theWI, theLtransI, theLthinI,
1094                                                    theHexMesh, myPoint1, myPoint2, myPoint3);
1095     else
1096       anObj = anOper->MakePipeTShapeTR(theR1, theW1, theL1, theR2, theW2, theL2,
1097                                        theRL, theWL, theLtransL, theLthinL,
1098                                        theRR, theWR, theLtransR, theLthinR,
1099                                        theRI, theWI, theLtransI, theLthinI,
1100                                        theHexMesh);
1101   }
1102
1103   res = anObj->length();
1104   if (!res)
1105     return false;
1106
1107   //res = !anObj->_is_nil();
1108   if (res && !IsPreview()) {
1109     QStringList aParameters;
1110     //@@ put stringified input parameters to the string list here to store in the data model for notebook @@//
1111     aParameters << MainTubeGroupParams->SpinBox_DX->text(); // R1 parameter
1112     aParameters << MainTubeGroupParams->SpinBox_DY->text(); // W1 parameter
1113     aParameters << MainTubeGroupParams->SpinBox_DZ->text(); // L1 parameter
1114     aParameters << IncidentTubeGroupParams->SpinBox_DX->text(); // R2 parameter
1115     aParameters << IncidentTubeGroupParams->SpinBox_DY->text(); // W2 parameter
1116     aParameters << IncidentTubeGroupParams->SpinBox_DZ->text(); // L2 parameter
1117
1118     if (ChamferGroupParams->GroupBox1->isChecked()) { // Chamfer parameter
1119       aParameters << ChamferGroupParams->SpinBox_DX->text(); // H parameter
1120       aParameters << ChamferGroupParams->SpinBox_DY->text(); // W parameter
1121     }
1122     if (FilletGroupParams->GroupBox1->isChecked()) // Fillet parameter
1123       aParameters << FilletGroupParams->SpinBox_DX->text(); // RF parameter
1124
1125     // Thickness reductions
1126     if (LReductionGroupParams->GroupBox1->isChecked()) {
1127       aParameters << LReductionGroupParams->SpinBox1->text();
1128       aParameters << LReductionGroupParams->SpinBox2->text();
1129       aParameters << LReductionGroupParams->SpinBox3->text();
1130       aParameters << LReductionGroupParams->SpinBox4->text();
1131     }
1132     else {
1133       aParameters << "0" << "0" << "0" << "0";
1134     }
1135     if (RReductionGroupParams->GroupBox1->isChecked()) {
1136       aParameters << RReductionGroupParams->SpinBox1->text();
1137       aParameters << RReductionGroupParams->SpinBox2->text();
1138       aParameters << RReductionGroupParams->SpinBox3->text();
1139       aParameters << RReductionGroupParams->SpinBox4->text();
1140     }
1141     else {
1142       aParameters << "0" << "0" << "0" << "0";
1143     }
1144     if (IReductionGroupParams->GroupBox1->isChecked()) {
1145       aParameters << IReductionGroupParams->SpinBox1->text();
1146       aParameters << IReductionGroupParams->SpinBox2->text();
1147       aParameters << IReductionGroupParams->SpinBox3->text();
1148       aParameters << IReductionGroupParams->SpinBox4->text();
1149     }
1150     else {
1151       aParameters << "0" << "0" << "0" << "0";
1152     }
1153
1154     if (aParameters.count() > 0)
1155       anObj[0]->SetParameters(aParameters.join(":").toLatin1().constData());
1156   }
1157
1158   objects.push_back(anObj[0]._retn());
1159   pipeTShapeGroupObjects.clear();
1160   for (int i = 1, n = anObj->length(); i < n; i++) {
1161     pipeTShapeGroupObjects.push_back(anObj[i]._retn());
1162   }
1163
1164   return objects.size() > 0;
1165 }
1166
1167 //=================================================================================
1168 // function : restoreSubShapes
1169 // purpose  :
1170 //=================================================================================
1171 void AdvancedGUI_PipeTShapeDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
1172                                                   SALOMEDS::SObject_ptr theSObject)
1173 {
1174   SALOMEDS::GenericAttribute_var anAttr;
1175   if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
1176     return;
1177
1178   SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1179   CORBA::String_var anIORso = anAttrIOR->Value();
1180
1181   // get Object from SObject
1182   GEOM::GEOM_Object_var theFather =
1183     GEOM::GEOM_Object::_narrow(myGeomGUI->getApp()->orb()->string_to_object(anIORso));
1184   if (CORBA::is_nil(theFather))
1185     return;
1186
1187   ObjectList::iterator it = pipeTShapeGroupObjects.begin();
1188
1189   for (int i = 0; it != pipeTShapeGroupObjects.end(); it++, i++) {
1190     getGeomEngine()->AddInStudy(theStudy, (*it), tr((*it)->GetName()).toStdString().c_str(), theFather);
1191   }
1192 }
1193
1194 //=================================================================================
1195 // function : processPreview()
1196 // purpose  : Display preview if CheckBoxPreview is checked
1197 //=================================================================================
1198 void AdvancedGUI_PipeTShapeDlg::processPreview()
1199 {
1200   if (mainFrame()->CheckBoxPreview->isChecked())
1201     DisplayPreview();
1202   else
1203     erasePreview(true);
1204 }
1205
1206 //=================================================================================
1207 // function : AdvancedGUI_4Spin
1208 // purpose  :
1209 //=================================================================================
1210 AdvancedGUI_4Spin::AdvancedGUI_4Spin()
1211 {
1212   GroupBox1 = new QGroupBox ();
1213
1214   gridLayout1 = new QGridLayout (GroupBox1);
1215   gridLayout1->setSpacing(6);
1216   gridLayout1->setContentsMargins(11, 11, 11, 11);
1217   gridLayout1->setHorizontalSpacing(6);
1218   gridLayout1->setVerticalSpacing(6);
1219   gridLayout1->setContentsMargins(9, 9, 9, 9);
1220
1221   TextLabel1 = new QLabel (GroupBox1);
1222   TextLabel2 = new QLabel (GroupBox1);
1223   TextLabel3 = new QLabel (GroupBox1);
1224   TextLabel4 = new QLabel (GroupBox1);
1225
1226   SpinBox1 = new SalomeApp_DoubleSpinBox (GroupBox1);
1227   SpinBox2 = new SalomeApp_DoubleSpinBox (GroupBox1);
1228   SpinBox3 = new SalomeApp_DoubleSpinBox (GroupBox1);
1229   SpinBox4 = new SalomeApp_DoubleSpinBox (GroupBox1);
1230
1231   SpinBox1->setMinimumWidth(60);
1232   SpinBox2->setMinimumWidth(60);
1233   SpinBox3->setMinimumWidth(60);
1234   SpinBox4->setMinimumWidth(60);
1235
1236   gridLayout1->addWidget(TextLabel1, 0, 0, 1, 1);
1237   gridLayout1->addWidget(TextLabel2, 1, 0, 1, 1);
1238   gridLayout1->addWidget(TextLabel3, 2, 0, 1, 1);
1239   gridLayout1->addWidget(TextLabel4, 3, 0, 1, 1);
1240
1241   gridLayout1->addWidget(SpinBox1, 0, 1, 1, 1);
1242   gridLayout1->addWidget(SpinBox2, 1, 1, 1, 1);
1243   gridLayout1->addWidget(SpinBox3, 2, 1, 1, 1);
1244   gridLayout1->addWidget(SpinBox4, 3, 1, 1, 1);
1245 }
1246
1247 //=================================================================================
1248 // function : ~AdvancedGUI_4Spin()
1249 // purpose  : Destroys the object and frees any allocated resources
1250 //=================================================================================
1251 AdvancedGUI_4Spin::~AdvancedGUI_4Spin()
1252 {
1253   // no need to delete child widgets, Qt does it all for us
1254 }