]> SALOME platform Git repositories - modules/geom.git/blob - src/BasicGUI/BasicGUI_CurveDlg.cxx
Salome HOME
SMH: Merged GEOM (NEWGUI, HEAD, POLYWORK)
[modules/geom.git] / src / BasicGUI / BasicGUI_CurveDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE 
4 // 
5 //  This library is free software; you can redistribute it and/or 
6 //  modify it under the terms of the GNU Lesser General Public 
7 //  License as published by the Free Software Foundation; either 
8 //  version 2.1 of the License. 
9 // 
10 //  This library is distributed in the hope that it will be useful, 
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 //  Lesser General Public License for more details. 
14 // 
15 //  You should have received a copy of the GNU Lesser General Public 
16 //  License along with this library; if not, write to the Free Software 
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
18 // 
19 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
20 //
21 //
22 //
23 //  File   : BasicGUI_CurveDlg.cxx
24 //  Author : Nicolas REJNERI
25 //  Module : GEOM
26 //  $Header$
27
28 #include "BasicGUI_CurveDlg.h"
29
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "SalomeApp_SelectionMgr.h"
34
35 #include <qlabel.h>
36
37 #include "utilities.h"
38
39 #include "SALOME_ListIteratorOfListIO.hxx"
40 #include "SALOME_ListIO.hxx"
41
42 #include "GEOMImpl_Types.hxx"
43
44 using namespace std;
45
46 //=================================================================================
47 // class    : BasicGUI_CurveDlg()
48 // purpose  : Constructs a BasicGUI_CurveDlg which is a child of 'parent', with the 
49 //            name 'name' and widget flags set to 'f'.
50 //            The dialog will by default be modeless, unless you set 'modal' to
51 //            TRUE to construct a modal dialog.
52 //=================================================================================
53 BasicGUI_CurveDlg::BasicGUI_CurveDlg(GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
54   :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), 
55    myGeometryGUI(theGeometryGUI)
56 {
57   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POLYLINE")));
58   QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SPLINE")));
59   QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BEZIER")));
60   
61   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
62
63   setCaption(tr("GEOM_CURVE_TITLE"));
64   
65   /***************************************************************/
66   RadioButton1->setPixmap( image0 );
67   RadioButton2->setPixmap( image3 );
68   RadioButton3->setPixmap( image2 );
69
70   GroupPoints = new DlgRef_1Sel_QTD( this, "GroupPoints" );
71   GroupPoints->GroupBox1->setTitle( tr( "GEOM_NODES" ) );
72   GroupPoints->TextLabel1->setText( tr("GEOM_POINTS") );
73   GroupPoints->PushButton1->setPixmap(image1);
74   
75   GroupPoints->LineEdit1->setReadOnly( true );
76
77   Layout1->addWidget(GroupPoints, 2, 0);
78   /***************************************************************/
79
80   Init();
81 }
82
83
84 //=================================================================================
85 // function : ~BasicGUI_CurveDlg()
86 // purpose  : Destroys the object and frees any allocated resources
87 //=================================================================================
88 BasicGUI_CurveDlg::~BasicGUI_CurveDlg()
89 {
90 }
91
92
93 //=================================================================================
94 // function : Init()
95 // purpose  :
96 //=================================================================================
97 void BasicGUI_CurveDlg::Init()
98 {
99   /* init variables */
100   myEditCurrentArgument = GroupPoints->LineEdit1;
101
102   myPoints = new GEOM::ListOfGO();
103   myPoints->length( 0 );
104
105   globalSelection( GEOM_POINT );
106
107   /* signals and slots connections */
108   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
109   connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
110   connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
111   
112   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
113   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
114   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
115
116   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
117   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
118
119   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
120           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
121
122   initName( tr( "GEOM_CURVE" ) );
123   ConstructorsClicked( 0 );
124 }
125
126 //=================================================================================
127 // function : ConstructorsClicked()
128 // purpose  :
129 //=================================================================================
130 void BasicGUI_CurveDlg::ConstructorsClicked( int id )
131 {
132   QString aTitle = tr( id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL" );
133   GroupConstructors->setTitle( aTitle );
134         
135         myPoints = new GEOM::ListOfGO();
136   myPoints->length( 0 );  
137
138   myEditCurrentArgument->setText("");
139 }
140
141
142 //=================================================================================
143 // function : SetEditCurrentArgument()
144 // purpose  :
145 //=================================================================================
146 void BasicGUI_CurveDlg::SetEditCurrentArgument()
147 {
148   if ( sender() == GroupPoints->PushButton1 ) 
149     myEditCurrentArgument = GroupPoints->LineEdit1;
150   myEditCurrentArgument->setFocus();
151   SelectionIntoArgument();
152 }
153
154
155 //=================================================================================
156 // function : LineEditReturnPressed()
157 // purpose  :
158 //=================================================================================
159 void BasicGUI_CurveDlg::LineEditReturnPressed()
160 {
161   if ( sender() == GroupPoints->LineEdit1 ) 
162   {
163     myEditCurrentArgument = GroupPoints->LineEdit1;
164     GEOMBase_Skeleton::LineEditReturnPressed();
165   }
166 }
167
168 //=================================================================================
169 // function : ClickOnOk()
170 // purpose  :
171 //=================================================================================
172 void BasicGUI_CurveDlg::ClickOnOk()
173 {
174   if ( ClickOnApply() )
175     ClickOnCancel();
176 }
177
178 //=================================================================================
179 // function : ClickOnApply()
180 // purpose  :
181 //=================================================================================
182 bool BasicGUI_CurveDlg::ClickOnApply()
183 {
184   if ( !onAccept() )
185     return false;
186
187   initName();
188   ConstructorsClicked( getConstructorId() );
189   return true;
190 }
191
192 //=======================================================================
193 // function : ClickOnCancel()
194 // purpose  :
195 //=======================================================================
196 void BasicGUI_CurveDlg::ClickOnCancel()
197 {
198   GEOMBase_Skeleton::ClickOnCancel();
199 }
200
201 //=================================================================================
202 // function : SelectionIntoArgument()
203 // purpose  : Called when selection as changed or other case
204 //=================================================================================
205 void BasicGUI_CurveDlg::SelectionIntoArgument()
206 {
207   myEditCurrentArgument->setText("");
208
209   Standard_Boolean aRes = Standard_False;
210   int i = 0;
211   myPoints->length( IObjectCount() ); // this length may be greater than number of objects,
212                                                    // that will actually be put into myPoints
213   for ( SALOME_ListIteratorOfListIO anIt( selectedIO() ); anIt.More(); anIt.Next() )
214   {
215     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value(), aRes );
216     if ( !CORBA::is_nil( aSelectedObject ) && aRes )
217     {
218       //TopoDS_Shape aPointShape;
219       //if ( myGeomBase->GetShape( aSelectedObject, aPointShape, TopAbs_VERTEX ) )
220       myPoints[i++] = aSelectedObject;
221     }
222   }
223   myPoints->length( i ); // this is the right length, smaller of equal to the previously set
224   if ( i )
225     GroupPoints->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
226   
227   displayPreview(); 
228 }
229
230
231 //=================================================================================
232 // function : ActivateThisDialog()
233 // purpose  :
234 //=================================================================================
235 void BasicGUI_CurveDlg::ActivateThisDialog()
236 {
237   GEOMBase_Skeleton::ActivateThisDialog();
238   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
239           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
240
241   // myGeometryGUI->SetState( 0 );
242
243   globalSelection( GEOM_POINT );
244   ConstructorsClicked( getConstructorId() );
245 }
246
247 //=================================================================================
248 // function : DeactivateActiveDialog()
249 // purpose  : public slot to deactivate if active
250 //=================================================================================
251 void BasicGUI_CurveDlg::DeactivateActiveDialog()
252 {
253   // myGeometryGUI->SetState( -1 );
254   GEOMBase_Skeleton::DeactivateActiveDialog();
255 }
256
257 //=================================================================================
258 // function : enterEvent()
259 // purpose  :
260 //=================================================================================
261 void BasicGUI_CurveDlg::enterEvent(QEvent* e)
262 {
263   if ( !GroupConstructors->isEnabled() )
264     ActivateThisDialog();
265 }
266
267 //=================================================================================
268 // function : createOperation
269 // purpose  :
270 //=================================================================================
271 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
272 {
273   return myGeometryGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
274 }
275
276 //=================================================================================
277 // function : isValid
278 // purpose  :
279 //=================================================================================
280 bool BasicGUI_CurveDlg::isValid( QString& msg )
281 {
282   return myPoints->length() > 1;
283 }
284
285 //=================================================================================
286 // function : execute
287 // purpose  :
288 //=================================================================================
289 bool BasicGUI_CurveDlg::execute( ObjectList& objects )
290 {
291   bool res = false;
292
293   GEOM::GEOM_Object_var anObj;
294
295   switch ( getConstructorId() )
296   {
297   case 0 :
298     anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakePolyline( myPoints );
299     res = true;
300     break;
301   case 1 :
302     anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineBezier( myPoints );
303     res = true;
304     break;
305   case 2 :
306     anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineInterpolation( myPoints );
307     res = true;
308     break;
309   }
310
311   if ( !anObj->_is_nil() )
312     objects.push_back( anObj._retn() );
313
314   return res;
315 }
316
317 //=================================================================================
318 // function : closeEvent
319 // purpose  :
320 //=================================================================================
321 void BasicGUI_CurveDlg::closeEvent( QCloseEvent* e )
322 {
323   // myGeometryGUI->SetState( -1 );
324   GEOMBase_Skeleton::closeEvent( e );
325 }
326