Salome HOME
0016756: EDF 545 GEOM : Extrusion, give the coordinates of the vector as input
[modules/geom.git] / src / BuildGUI / BuildGUI_EdgeDlg.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   : BuildGUI_EdgeDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
24 //
25
26 #include "BuildGUI_EdgeDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <GEOMImpl_Types.hxx>
33
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Session.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38
39 //=================================================================================
40 // class    : BuildGUI_EdgeDlg()
41 // purpose  : Constructs a BuildGUI_EdgeDlg 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 BuildGUI_EdgeDlg::BuildGUI_EdgeDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
47   : GEOMBase_Skeleton( theGeometryGUI, parent )
48 {
49   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_EDGE" ) ) );
50   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
51
52   setWindowTitle( tr( "GEOM_EDGE_TITLE" ) );
53
54   /***************************************************************/
55   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_EDGE" ) );
56   mainFrame()->RadioButton1->setIcon( image0 );
57   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
58   mainFrame()->RadioButton2->close();
59   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
60   mainFrame()->RadioButton3->close();
61
62   GroupPoints = new DlgRef_2Sel( centralWidget() );
63
64   GroupPoints->GroupBox1->setTitle( tr( "GEOM_POINTS" ) );
65   GroupPoints->TextLabel1->setText( tr( "GEOM_POINT_I" ).arg( 1 ) );
66   GroupPoints->TextLabel2->setText( tr( "GEOM_POINT_I" ).arg( 2 ) );
67   GroupPoints->PushButton1->setIcon( image1 );
68   GroupPoints->PushButton2->setIcon( image1 );
69   
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("create_edge_page.html");
79
80   /* Initialisations */
81   Init();
82 }
83
84
85 //=================================================================================
86 // function : ~BuildGUI_EdgeDlg()
87 // purpose  : Destroys the object and frees any allocated resources
88 //=================================================================================
89 BuildGUI_EdgeDlg::~BuildGUI_EdgeDlg()
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 BuildGUI_EdgeDlg::Init()
100 {
101   /* init variables */
102   myEditCurrentArgument = GroupPoints->LineEdit1;
103   GroupPoints->LineEdit1->setReadOnly( true );
104   GroupPoints->LineEdit2->setReadOnly( true );
105
106   myOkPoint1 = myOkPoint2 = false;
107
108   globalSelection( GEOM_POINT );
109
110   /* signals and slots connections */
111   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
112   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
113
114   connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
115   connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
116
117   connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
118   connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
119   
120   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
121            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
122
123   initName( tr( "GEOM_EDGE" ) );
124 }
125
126
127 //=================================================================================
128 // function : ClickOnOk()
129 // purpose  :
130 //=================================================================================
131 void BuildGUI_EdgeDlg::ClickOnOk()
132 {
133   if ( ClickOnApply() )
134     ClickOnCancel();
135 }
136
137
138 //=================================================================================
139 // function : ClickOnApply()
140 // purpose  :
141 //=================================================================================
142 bool BuildGUI_EdgeDlg::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 as changed or other case
155 //=================================================================================
156 void BuildGUI_EdgeDlg::SelectionIntoArgument()
157 {
158   erasePreview();
159   myEditCurrentArgument->setText( "" );
160   
161   if ( IObjectCount() != 1 ) {
162     if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
163       myOkPoint1 = false;
164     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
165       myOkPoint2 = false;
166     return;
167   }
168   
169   // nbSel == 1
170   Standard_Boolean testResult = Standard_False;
171   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
172   
173   if ( !testResult )
174     return;
175
176   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
177     myPoint1 = aSelectedObject;
178     myOkPoint1 = true;
179   }
180   else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
181     myPoint2 = aSelectedObject;
182     myOkPoint2 = true;
183   }
184   
185   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
186   
187   displayPreview();
188 }
189
190
191 //=================================================================================
192 // function : LineEditReturnPressed()
193 // purpose  :
194 //=================================================================================
195 void BuildGUI_EdgeDlg::LineEditReturnPressed()
196 {
197   QLineEdit* send = (QLineEdit*)sender();
198   if ( send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2 ) {
199     myEditCurrentArgument = send;
200     GEOMBase_Skeleton::LineEditReturnPressed();
201   }
202 }
203
204
205 //=================================================================================
206 // function : SetEditCurrentArgument()
207 // purpose  :
208 //=================================================================================
209 void BuildGUI_EdgeDlg::SetEditCurrentArgument()
210 {
211   
212   QPushButton* send = (QPushButton*)sender();
213   globalSelection();
214
215   if ( send == GroupPoints->PushButton1 ) {
216     myEditCurrentArgument = GroupPoints->LineEdit1;
217     globalSelection( GEOM_POINT );
218   }
219   else if ( send == GroupPoints->PushButton2 ) {
220     myEditCurrentArgument = GroupPoints->LineEdit2;
221     globalSelection( GEOM_POINT );
222   }
223   
224   myEditCurrentArgument->setFocus();
225   SelectionIntoArgument();
226 }
227
228
229 //=================================================================================
230 // function : ActivateThisDialog()
231 // purpose  :
232 //=================================================================================
233 void BuildGUI_EdgeDlg::ActivateThisDialog()
234 {
235   GEOMBase_Skeleton::ActivateThisDialog();
236   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
237            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
238   globalSelection( GEOM_POINT );
239   displayPreview();
240 }
241
242
243 //=================================================================================
244 // function : enterEvent()
245 // purpose  :
246 //=================================================================================
247 void BuildGUI_EdgeDlg::enterEvent( QEvent* )
248 {
249   if ( !mainFrame()->GroupConstructors->isEnabled() )
250     ActivateThisDialog();
251 }
252
253 //=================================================================================
254 // function : createOperation
255 // purpose  :
256 //=================================================================================
257 GEOM::GEOM_IOperations_ptr BuildGUI_EdgeDlg::createOperation()
258 {
259   return getGeomEngine()->GetIShapesOperations( getStudyId() );
260 }
261
262 //=================================================================================
263 // function : isValid
264 // purpose  :
265 //=================================================================================
266 bool BuildGUI_EdgeDlg::isValid( QString& )
267 {
268   return myOkPoint1 && myOkPoint2;
269 }
270
271 //=================================================================================
272 // function : execute
273 // purpose  :
274 //=================================================================================
275 bool BuildGUI_EdgeDlg::execute( ObjectList& objects )
276 {
277   GEOM::GEOM_Object_var anObj;
278
279   anObj = GEOM::GEOM_IShapesOperations::_narrow( getOperation() )->MakeEdge( myPoint1, myPoint2 );
280
281   if ( !anObj->_is_nil() )
282     objects.push_back( anObj._retn() );
283
284   return true;
285 }