]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_PipeDlg.cxx
Salome HOME
*** empty log message ***
[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 // File   : GenerationGUI_PipeDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
24 //
25
26 #include "GenerationGUI_PipeDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36
37 #include <GEOMImpl_Types.hxx>
38
39 //=================================================================================
40 // class    : GenerationGUI_PipeDlg()
41 // purpose  : Constructs a GenerationGUI_PipeDlg which is a child of 'parent', with the 
42 //            name 'name' and widget flags set to 'f'.
43 //            The dialog will by default be modeless, unless you set 'modal' to
44 //            TRUE to construct a modal dialog.
45 //=================================================================================
46 GenerationGUI_PipeDlg::GenerationGUI_PipeDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
47                                               bool modal, Qt::WindowFlags fl )
48   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
49 {
50   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PIPE" ) ) );
51   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
52
53   setWindowTitle( tr( "GEOM_PIPE_TITLE" ) );
54
55   /***************************************************************/
56   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PIPE" ) );
57   mainFrame()->RadioButton1->setIcon(image0);
58   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
59   mainFrame()->RadioButton2->close();
60   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61   mainFrame()->RadioButton3->close();
62
63   GroupPoints = new DlgRef_2Sel( centralWidget() );
64
65   GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
66   GroupPoints->TextLabel1->setText( tr( "GEOM_BASE_OBJECT" ) );
67   GroupPoints->TextLabel2->setText( tr( "GEOM_PATH_OBJECT" ) );
68   GroupPoints->PushButton1->setIcon( image1 );
69   GroupPoints->PushButton2->setIcon( image1 );
70   GroupPoints->LineEdit1->setReadOnly( true );
71   GroupPoints->LineEdit2->setReadOnly( true );
72
73   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
74   layout->setMargin( 0 ); layout->setSpacing( 6 );
75   layout->addWidget( GroupPoints );
76   /***************************************************************/
77
78   setHelpFileName( "pipe_creation.htm" );
79
80   /* Initialisations */
81   Init();
82 }
83
84
85 //=================================================================================
86 // function : ~GenerationGUI_PipeDlg()
87 // purpose  : Destroys the object and frees any allocated resources
88 //=================================================================================
89 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
90 {
91   /* no need to delete child widgets, Qt does it all for us */
92 }
93
94
95 //=================================================================================
96 // function : Init()
97 // purpose  :
98 //=================================================================================
99 void GenerationGUI_PipeDlg::Init()
100 {
101   /* init variables */
102   myEditCurrentArgument = GroupPoints->LineEdit1;
103   GroupPoints->LineEdit1->setReadOnly( true );
104   GroupPoints->LineEdit2->setReadOnly( true );
105
106   myOkBase = myOkPath = false;
107
108   /* signals and slots connections */
109   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
110   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
111
112   connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
113   connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
114
115   connect( GroupPoints->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
116   connect( GroupPoints->LineEdit2,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
117   
118   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
119            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
120
121   initName( tr( "GEOM_PIPE" ) );
122
123   globalSelection( GEOM_ALLSHAPES );
124 }
125
126
127 //=================================================================================
128 // function : ClickOnOk()
129 // purpose  :
130 //=================================================================================
131 void GenerationGUI_PipeDlg::ClickOnOk()
132 {
133   if ( ClickOnApply() )
134     ClickOnCancel();
135 }
136
137
138 //=================================================================================
139 // function : ClickOnAply()
140 // purpose  :
141 //=================================================================================
142 bool GenerationGUI_PipeDlg::ClickOnApply()
143 {
144   if ( !onAccept() )
145     return false;
146
147   initName();
148   return true;
149 }
150
151
152 //=================================================================================
153 // function : SelectionIntoArgument()
154 // purpose  : Called when selection has changed
155 //=================================================================================
156 void GenerationGUI_PipeDlg::SelectionIntoArgument()
157 {
158   erasePreview();
159   myEditCurrentArgument->setText( "" );
160   
161   if ( IObjectCount() != 1 ) {
162     if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
163       myOkBase = false;
164     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
165       myOkPath = false;
166     return;
167   }
168   
169   // nbSel == 1
170   Standard_Boolean testResult = Standard_False;
171   GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
172     
173   if ( !testResult )
174     return;
175   
176   TopoDS_Shape S;
177   
178   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
179     myOkBase = false;
180     
181     if ( !GEOMBase::GetShape( aSelectedObject, S ) ||
182          S.ShapeType() == TopAbs_COMPSOLID || 
183          S.ShapeType() == TopAbs_COMPOUND || 
184          S.ShapeType() == TopAbs_SOLID || 
185          S.ShapeType() == TopAbs_SHAPE ) 
186       return;
187     
188     myBase = aSelectedObject;
189     myOkBase = true;
190   }
191   else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
192     myOkPath = false;
193     
194     if ( !GEOMBase::GetShape( aSelectedObject, S ) ||
195          !( S.ShapeType() == TopAbs_WIRE || S.ShapeType() == TopAbs_EDGE ) )
196       return;
197     
198     myPath = aSelectedObject;
199     myOkPath = true;
200   }
201   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
202   
203   displayPreview();
204 }
205
206
207 //=================================================================================
208 // function : SetEditCurrentArgument()
209 // purpose  :
210 //=================================================================================
211 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
212 {
213   QPushButton* send = (QPushButton*)sender();
214
215   if ( send == GroupPoints->PushButton1 ) {
216     GroupPoints->LineEdit1->setFocus();
217     myEditCurrentArgument = GroupPoints->LineEdit1;
218   }
219   else if ( send == GroupPoints->PushButton2 ) {
220     GroupPoints->LineEdit2->setFocus();
221     myEditCurrentArgument = GroupPoints->LineEdit2;
222   }
223   SelectionIntoArgument();
224 }
225
226
227 //=================================================================================
228 // function : LineEditReturnPressed()
229 // purpose  :
230 //=================================================================================
231 void GenerationGUI_PipeDlg::LineEditReturnPressed()
232 {
233   QLineEdit* send = (QLineEdit*)sender();
234   if ( send == GroupPoints->LineEdit1 ||
235        send == GroupPoints->LineEdit2 ) {
236     myEditCurrentArgument = send;
237     GEOMBase_Skeleton::LineEditReturnPressed();
238   }
239 }
240
241
242 //=================================================================================
243 // function : enterEvent()
244 // purpose  : when mouse enter onto the QWidget
245 //=================================================================================
246 void GenerationGUI_PipeDlg::enterEvent( QEvent* )
247 {
248   if ( !mainFrame()->GroupConstructors->isEnabled() )
249     ActivateThisDialog();
250 }
251
252
253 //=================================================================================
254 // function : ActivateThisDialog()
255 // purpose  :
256 //=================================================================================
257 void GenerationGUI_PipeDlg::ActivateThisDialog()
258 {
259   GEOMBase_Skeleton::ActivateThisDialog();
260   globalSelection( GEOM_ALLSHAPES );
261   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
262            SIGNAL( currentSelectionChanged() ), this, SLOT(SelectionIntoArgument() ) );
263   displayPreview();
264 }
265
266
267 //=================================================================================
268 // function : createOperation
269 // purpose  :
270 //=================================================================================
271 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
272 {
273   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
274 }
275
276 //=================================================================================
277 // function : isValid
278 // purpose  :
279 //=================================================================================
280 bool GenerationGUI_PipeDlg::isValid( QString& )
281 {
282   return myOkBase && myOkPath;
283 }
284
285 //=================================================================================
286 // function : execute
287 // purpose  :
288 //=================================================================================
289 bool GenerationGUI_PipeDlg::execute( ObjectList& objects )
290 {
291   GEOM::GEOM_Object_var anObj;
292
293   anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
294     getOperation() )->MakePipe( myBase, myPath );
295
296   if ( !anObj->_is_nil() )
297     objects.push_back( anObj._retn() );
298
299   return true;
300 }
301
302
303