1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE
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.
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.
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
19 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File : BasicGUI_CurveDlg.cxx
24 // Author : Nicolas REJNERI
28 #include "BasicGUI_CurveDlg.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "SalomeApp_SelectionMgr.h"
37 #include "utilities.h"
39 #include "SALOME_ListIteratorOfListIO.hxx"
40 #include "SALOME_ListIO.hxx"
42 #include "GEOMImpl_Types.hxx"
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)
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")));
61 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
63 setCaption(tr("GEOM_CURVE_TITLE"));
65 /***************************************************************/
66 RadioButton1->setPixmap( image0 );
67 RadioButton2->setPixmap( image3 );
68 RadioButton3->setPixmap( image2 );
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);
75 GroupPoints->LineEdit1->setReadOnly( true );
77 Layout1->addWidget(GroupPoints, 2, 0);
78 /***************************************************************/
84 //=================================================================================
85 // function : ~BasicGUI_CurveDlg()
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 BasicGUI_CurveDlg::~BasicGUI_CurveDlg()
93 //=================================================================================
96 //=================================================================================
97 void BasicGUI_CurveDlg::Init()
100 myEditCurrentArgument = GroupPoints->LineEdit1;
102 myPoints = new GEOM::ListOfGO();
103 myPoints->length( 0 );
105 globalSelection( GEOM_POINT );
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()));
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)));
116 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
117 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
119 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
120 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
122 initName( tr( "GEOM_CURVE" ) );
123 ConstructorsClicked( 0 );
126 //=================================================================================
127 // function : ConstructorsClicked()
129 //=================================================================================
130 void BasicGUI_CurveDlg::ConstructorsClicked( int id )
132 QString aTitle = tr( id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL" );
133 GroupConstructors->setTitle( aTitle );
135 myPoints = new GEOM::ListOfGO();
136 myPoints->length( 0 );
138 myEditCurrentArgument->setText("");
142 //=================================================================================
143 // function : SetEditCurrentArgument()
145 //=================================================================================
146 void BasicGUI_CurveDlg::SetEditCurrentArgument()
148 if ( sender() == GroupPoints->PushButton1 )
149 myEditCurrentArgument = GroupPoints->LineEdit1;
150 myEditCurrentArgument->setFocus();
151 SelectionIntoArgument();
155 //=================================================================================
156 // function : LineEditReturnPressed()
158 //=================================================================================
159 void BasicGUI_CurveDlg::LineEditReturnPressed()
161 if ( sender() == GroupPoints->LineEdit1 )
163 myEditCurrentArgument = GroupPoints->LineEdit1;
164 GEOMBase_Skeleton::LineEditReturnPressed();
168 //=================================================================================
169 // function : ClickOnOk()
171 //=================================================================================
172 void BasicGUI_CurveDlg::ClickOnOk()
174 if ( ClickOnApply() )
178 //=================================================================================
179 // function : ClickOnApply()
181 //=================================================================================
182 bool BasicGUI_CurveDlg::ClickOnApply()
188 ConstructorsClicked( getConstructorId() );
192 //=======================================================================
193 // function : ClickOnCancel()
195 //=======================================================================
196 void BasicGUI_CurveDlg::ClickOnCancel()
198 GEOMBase_Skeleton::ClickOnCancel();
201 //=================================================================================
202 // function : SelectionIntoArgument()
203 // purpose : Called when selection as changed or other case
204 //=================================================================================
205 void BasicGUI_CurveDlg::SelectionIntoArgument()
207 myEditCurrentArgument->setText("");
209 Standard_Boolean aRes = Standard_False;
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() )
215 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value(), aRes );
216 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
218 //TopoDS_Shape aPointShape;
219 //if ( myGeomBase->GetShape( aSelectedObject, aPointShape, TopAbs_VERTEX ) )
220 myPoints[i++] = aSelectedObject;
223 myPoints->length( i ); // this is the right length, smaller of equal to the previously set
225 GroupPoints->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
231 //=================================================================================
232 // function : ActivateThisDialog()
234 //=================================================================================
235 void BasicGUI_CurveDlg::ActivateThisDialog()
237 GEOMBase_Skeleton::ActivateThisDialog();
238 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
239 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
241 // myGeometryGUI->SetState( 0 );
243 globalSelection( GEOM_POINT );
244 ConstructorsClicked( getConstructorId() );
247 //=================================================================================
248 // function : DeactivateActiveDialog()
249 // purpose : public slot to deactivate if active
250 //=================================================================================
251 void BasicGUI_CurveDlg::DeactivateActiveDialog()
253 // myGeometryGUI->SetState( -1 );
254 GEOMBase_Skeleton::DeactivateActiveDialog();
257 //=================================================================================
258 // function : enterEvent()
260 //=================================================================================
261 void BasicGUI_CurveDlg::enterEvent(QEvent* e)
263 if ( !GroupConstructors->isEnabled() )
264 ActivateThisDialog();
267 //=================================================================================
268 // function : createOperation
270 //=================================================================================
271 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
273 return myGeometryGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
276 //=================================================================================
277 // function : isValid
279 //=================================================================================
280 bool BasicGUI_CurveDlg::isValid( QString& msg )
282 return myPoints->length() > 1;
285 //=================================================================================
286 // function : execute
288 //=================================================================================
289 bool BasicGUI_CurveDlg::execute( ObjectList& objects )
293 GEOM::GEOM_Object_var anObj;
295 switch ( getConstructorId() )
298 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakePolyline( myPoints );
302 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineBezier( myPoints );
306 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineInterpolation( myPoints );
311 if ( !anObj->_is_nil() )
312 objects.push_back( anObj._retn() );
317 //=================================================================================
318 // function : closeEvent
320 //=================================================================================
321 void BasicGUI_CurveDlg::closeEvent( QCloseEvent* e )
323 // myGeometryGUI->SetState( -1 );
324 GEOMBase_Skeleton::closeEvent( e );