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 "QAD_Desktop.h"
31 #include "QAD_Config.h"
32 #include "utilities.h"
34 #include "SALOME_ListIteratorOfListIO.hxx"
35 #include "SALOME_ListIO.hxx"
37 #include "GEOMImpl_Types.hxx"
41 //=================================================================================
42 // class : BasicGUI_CurveDlg()
43 // purpose : Constructs a BasicGUI_CurveDlg 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 BasicGUI_CurveDlg::BasicGUI_CurveDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
49 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
51 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_POLYLINE")));
52 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SPLINE")));
53 QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_BEZIER")));
55 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
57 setCaption(tr("GEOM_CURVE_TITLE"));
59 /***************************************************************/
60 RadioButton1->setPixmap( image0 );
61 RadioButton2->setPixmap( image3 );
62 RadioButton3->setPixmap( image2 );
64 GroupPoints = new DlgRef_1Sel_QTD( this, "GroupPoints" );
65 GroupPoints->GroupBox1->setTitle( tr( "GEOM_NODES" ) );
66 GroupPoints->TextLabel1->setText( tr("GEOM_POINTS") );
67 GroupPoints->PushButton1->setPixmap(image1);
69 GroupPoints->LineEdit1->setReadOnly( true );
71 Layout1->addWidget(GroupPoints, 2, 0);
72 /***************************************************************/
78 //=================================================================================
79 // function : ~BasicGUI_CurveDlg()
80 // purpose : Destroys the object and frees any allocated resources
81 //=================================================================================
82 BasicGUI_CurveDlg::~BasicGUI_CurveDlg()
87 //=================================================================================
90 //=================================================================================
91 void BasicGUI_CurveDlg::Init()
94 myEditCurrentArgument = GroupPoints->LineEdit1;
96 myPoints = new GEOM::ListOfGO();
97 myPoints->length( 0 );
99 globalSelection( GEOM_POINT );
101 /* signals and slots connections */
102 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
103 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
104 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
106 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
107 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
108 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
110 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
111 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
113 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
115 initName( tr( "GEOM_CURVE" ) );
116 ConstructorsClicked( 0 );
119 //=================================================================================
120 // function : ConstructorsClicked()
122 //=================================================================================
123 void BasicGUI_CurveDlg::ConstructorsClicked( int id )
125 QString aTitle = tr( id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL" );
126 GroupConstructors->setTitle( aTitle );
128 myPoints = new GEOM::ListOfGO();
129 myPoints->length( 0 );
131 myEditCurrentArgument->setText("");
135 //=================================================================================
136 // function : SetEditCurrentArgument()
138 //=================================================================================
139 void BasicGUI_CurveDlg::SetEditCurrentArgument()
141 if ( sender() == GroupPoints->PushButton1 )
142 myEditCurrentArgument = GroupPoints->LineEdit1;
143 myEditCurrentArgument->setFocus();
144 SelectionIntoArgument();
148 //=================================================================================
149 // function : LineEditReturnPressed()
151 //=================================================================================
152 void BasicGUI_CurveDlg::LineEditReturnPressed()
154 if ( sender() == GroupPoints->LineEdit1 )
156 myEditCurrentArgument = GroupPoints->LineEdit1;
157 GEOMBase_Skeleton::LineEditReturnPressed();
161 //=================================================================================
162 // function : ClickOnOk()
164 //=================================================================================
165 void BasicGUI_CurveDlg::ClickOnOk()
167 if ( ClickOnApply() )
171 //=================================================================================
172 // function : ClickOnApply()
174 //=================================================================================
175 bool BasicGUI_CurveDlg::ClickOnApply()
181 ConstructorsClicked( getConstructorId() );
185 //=======================================================================
186 // function : ClickOnCancel()
188 //=======================================================================
189 void BasicGUI_CurveDlg::ClickOnCancel()
191 GEOMBase_Skeleton::ClickOnCancel();
194 //=================================================================================
195 // function : SelectionIntoArgument()
196 // purpose : Called when selection as changed or other case
197 //=================================================================================
198 void BasicGUI_CurveDlg::SelectionIntoArgument()
200 myEditCurrentArgument->setText("");
202 Standard_Boolean aRes = Standard_False;
204 myPoints->length( mySelection->IObjectCount() ); // this length may be greater than number of objects,
205 // that will actually be put into myPoints
206 for ( SALOME_ListIteratorOfListIO anIt( mySelection->StoredIObjects() ); anIt.More(); anIt.Next() )
208 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value(), aRes );
209 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
211 //TopoDS_Shape aPointShape;
212 //if ( myGeomBase->GetShape( aSelectedObject, aPointShape, TopAbs_VERTEX ) )
213 myPoints[i++] = aSelectedObject;
216 myPoints->length( i ); // this is the right length, smaller of equal to the previously set
218 GroupPoints->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
224 //=================================================================================
225 // function : ActivateThisDialog()
227 //=================================================================================
228 void BasicGUI_CurveDlg::ActivateThisDialog()
230 GEOMBase_Skeleton::ActivateThisDialog();
231 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
233 myGeomGUI->SetState( 0 );
235 globalSelection( GEOM_POINT );
236 ConstructorsClicked( getConstructorId() );
239 //=================================================================================
240 // function : DeactivateActiveDialog()
241 // purpose : public slot to deactivate if active
242 //=================================================================================
243 void BasicGUI_CurveDlg::DeactivateActiveDialog()
245 myGeomGUI->SetState( -1 );
246 GEOMBase_Skeleton::DeactivateActiveDialog();
249 //=================================================================================
250 // function : enterEvent()
252 //=================================================================================
253 void BasicGUI_CurveDlg::enterEvent(QEvent* e)
255 if ( !GroupConstructors->isEnabled() )
256 ActivateThisDialog();
259 //=================================================================================
260 // function : createOperation
262 //=================================================================================
263 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
265 return getGeomEngine()->GetICurvesOperations( getStudyId() );
268 //=================================================================================
269 // function : isValid
271 //=================================================================================
272 bool BasicGUI_CurveDlg::isValid( QString& msg )
274 return myPoints->length() > 1;
277 //=================================================================================
278 // function : execute
280 //=================================================================================
281 bool BasicGUI_CurveDlg::execute( ObjectList& objects )
285 GEOM::GEOM_Object_var anObj;
287 switch ( getConstructorId() )
290 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakePolyline( myPoints );
294 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineBezier( myPoints );
298 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineInterpolation( myPoints );
303 if ( !anObj->_is_nil() )
304 objects.push_back( anObj._retn() );
309 //=================================================================================
310 // function : closeEvent
312 //=================================================================================
313 void BasicGUI_CurveDlg::closeEvent( QCloseEvent* e )
315 myGeomGUI->SetState( -1 );
316 GEOMBase_Skeleton::closeEvent( e );