]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_PipeDlg.cxx
Salome HOME
Porting to Qt4.
[modules/geom.git] / src / GenerationGUI / GenerationGUI_PipeDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : GenerationGUI_PipeDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "GenerationGUI_PipeDlg.h"
30
31 #include "GeometryGUI.h"
32 #include "GEOMBase.h"
33
34 #include "SUIT_ResourceMgr.h"
35 #include "SUIT_Session.h"
36 #include "SalomeApp_Application.h"
37 #include "LightApp_SelectionMgr.h"
38
39 #include "GEOMImpl_Types.hxx"
40
41 //=================================================================================
42 // class    : GenerationGUI_PipeDlg()
43 // purpose  : Constructs a GenerationGUI_PipeDlg which is a child of 'parent', with the 
44 //            name 'name' and widget flags set to 'f'.
45 //            The dialog will by default be modeless, unless you set 'modal' to
46 //            TRUE to construct a modal dialog.
47 //=================================================================================
48 GenerationGUI_PipeDlg::GenerationGUI_PipeDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
49                                              const char* name, bool modal, Qt::WindowFlags fl)
50   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
51 {
52   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PIPE")));
53   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
54
55   setWindowTitle(tr("GEOM_PIPE_TITLE"));
56
57   /***************************************************************/
58   GroupConstructors->setTitle(tr("GEOM_PIPE"));
59   RadioButton1->setIcon(image0);
60   RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
61   RadioButton2->close();
62   RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
63   RadioButton3->close();
64
65   GroupPoints = new Ui::DlgRef_2Sel_QTD();
66   QWidget* aGroupPointsWidget = new QWidget(this);
67   GroupPoints->setupUi(aGroupPointsWidget);
68   aGroupPointsWidget->setObjectName("GroupPoints");
69
70   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
71   GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
72   GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
73   GroupPoints->PushButton1->setIcon(image1);
74   GroupPoints->PushButton2->setIcon(image1);
75   GroupPoints->LineEdit1->setReadOnly( true );
76   GroupPoints->LineEdit2->setReadOnly( true );
77
78   gridLayout1->addWidget(aGroupPointsWidget, 2, 0);
79   /***************************************************************/
80
81   setHelpFileName("pipe_creation.htm");
82
83   /* Initialisations */
84   Init();
85 }
86
87
88 //=================================================================================
89 // function : ~GenerationGUI_PipeDlg()
90 // purpose  : Destroys the object and frees any allocated resources
91 //=================================================================================
92 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
93 {
94   /* no need to delete child widgets, Qt does it all for us */
95 }
96
97
98 //=================================================================================
99 // function : Init()
100 // purpose  :
101 //=================================================================================
102 void GenerationGUI_PipeDlg::Init()
103 {
104   /* init variables */
105   myEditCurrentArgument = GroupPoints->LineEdit1;
106   GroupPoints->LineEdit1->setReadOnly( true );
107   GroupPoints->LineEdit2->setReadOnly( true );
108
109   myOkBase = myOkPath = false;
110
111   /* signals and slots connections */
112   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
113   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
114
115   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
116   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
117
118   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
119   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
120   
121   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
122           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
123
124   initName(tr("GEOM_PIPE").toStdString().c_str());
125
126   globalSelection( GEOM_ALLSHAPES );
127 }
128
129
130 //=================================================================================
131 // function : ClickOnOk()
132 // purpose  :
133 //=================================================================================
134 void GenerationGUI_PipeDlg::ClickOnOk()
135 {
136   if ( ClickOnApply() )
137     ClickOnCancel();
138 }
139
140
141 //=================================================================================
142 // function : ClickOnAply()
143 // purpose  :
144 //=================================================================================
145 bool GenerationGUI_PipeDlg::ClickOnApply()
146 {
147   if ( !onAccept() )
148     return false;
149
150   initName();
151   return true;
152 }
153
154
155 //=================================================================================
156 // function : SelectionIntoArgument()
157 // purpose  : Called when selection has changed
158 //=================================================================================
159 void GenerationGUI_PipeDlg::SelectionIntoArgument()
160 {
161   erasePreview();
162   myEditCurrentArgument->setText("");
163   
164   if(IObjectCount() != 1) {
165     if(myEditCurrentArgument == GroupPoints->LineEdit1)
166       myOkBase = false;
167     else if(myEditCurrentArgument == GroupPoints->LineEdit2)
168       myOkPath = false;
169     return;
170   }
171   
172   // nbSel == 1
173   Standard_Boolean testResult = Standard_False;
174   GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
175     
176   if (!testResult)
177     return;
178   
179   TopoDS_Shape S;
180   
181   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
182     myOkBase = false;
183     
184     if(!GEOMBase::GetShape(aSelectedObject, S) ||
185        S.ShapeType() == TopAbs_COMPSOLID || 
186        S.ShapeType() == TopAbs_COMPOUND || 
187        S.ShapeType() == TopAbs_SOLID || 
188        S.ShapeType() == TopAbs_SHAPE) 
189       return;
190     
191     myBase = aSelectedObject;
192     myOkBase = true;
193   }
194   else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
195     myOkPath = false;
196     
197     if(!GEOMBase::GetShape(aSelectedObject, S) ||
198        !(S.ShapeType() == TopAbs_WIRE || S.ShapeType() == TopAbs_EDGE) ) 
199       return;
200     
201     myPath = aSelectedObject;
202     myOkPath = true;
203   }
204   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
205   
206   displayPreview();
207 }
208
209
210 //=================================================================================
211 // function : SetEditCurrentArgument()
212 // purpose  :
213 //=================================================================================
214 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
215 {
216   QPushButton* send = (QPushButton*)sender();
217
218   if(send == GroupPoints->PushButton1) {
219     GroupPoints->LineEdit1->setFocus();
220     myEditCurrentArgument = GroupPoints->LineEdit1;
221   }
222   else if(send == GroupPoints->PushButton2) {
223     GroupPoints->LineEdit2->setFocus();
224     myEditCurrentArgument = GroupPoints->LineEdit2;
225   }
226   SelectionIntoArgument();
227 }
228
229
230 //=================================================================================
231 // function : LineEditReturnPressed()
232 // purpose  :
233 //=================================================================================
234 void GenerationGUI_PipeDlg::LineEditReturnPressed()
235 {
236   QLineEdit* send = (QLineEdit*)sender();
237   if(send == GroupPoints->LineEdit1 ||
238      send == GroupPoints->LineEdit2)
239     {
240       myEditCurrentArgument = send;
241       GEOMBase_Skeleton::LineEditReturnPressed();
242     }
243 }
244
245
246 //=================================================================================
247 // function : enterEvent()
248 // purpose  : when mouse enter onto the QWidget
249 //=================================================================================
250 void GenerationGUI_PipeDlg::enterEvent(QEvent* e)
251 {
252   if ( !GroupConstructors->isEnabled() )
253     ActivateThisDialog();
254 }
255
256
257 //=================================================================================
258 // function : ActivateThisDialog()
259 // purpose  :
260 //=================================================================================
261 void GenerationGUI_PipeDlg::ActivateThisDialog()
262 {
263   GEOMBase_Skeleton::ActivateThisDialog();
264   globalSelection( GEOM_ALLSHAPES );
265   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
266           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
267   displayPreview();
268 }
269
270
271 //=================================================================================
272 // function : createOperation
273 // purpose  :
274 //=================================================================================
275 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
276 {
277   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
278 }
279
280 //=================================================================================
281 // function : isValid
282 // purpose  :
283 //=================================================================================
284 bool GenerationGUI_PipeDlg::isValid( QString& )
285 {
286   return myOkBase && myOkPath;
287 }
288
289 //=================================================================================
290 // function : execute
291 // purpose  :
292 //=================================================================================
293 bool GenerationGUI_PipeDlg::execute( ObjectList& objects )
294 {
295   GEOM::GEOM_Object_var anObj;
296
297   anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
298     getOperation() )->MakePipe( myBase, myPath );
299
300   if ( !anObj->_is_nil() )
301     objects.push_back( anObj._retn() );
302
303   return true;
304 }
305
306
307