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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : BasicGUI_CurveDlg.cxx
22 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
25 #include "BasicGUI_CurveDlg.h"
27 #include <GEOM_DlgRef.h>
28 #include <GeometryGUI.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <SUIT_Session.h>
33 #include <SalomeApp_Application.h>
34 #include <LightApp_SelectionMgr.h>
36 #include <SALOME_ListIteratorOfListIO.hxx>
37 #include <SALOME_ListIO.hxx>
39 #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( GeometryGUI* theGeometryGUI, QWidget* parent,
49 const char* name, bool modal, Qt::WindowFlags fl )
50 : GEOMBase_Skeleton( theGeometryGUI, parent, name, modal, fl )
52 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POLYLINE" ) ) );
53 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SPLINE" ) ) );
54 QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BEZIER" ) ) );
55 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
57 setWindowTitle( tr( "GEOM_CURVE_TITLE" ) );
59 /***************************************************************/
60 mainFrame()->RadioButton1->setIcon( image0 );
61 mainFrame()->RadioButton2->setIcon( image3 );
62 mainFrame()->RadioButton3->setIcon( image2 );
64 GroupPoints = new DlgRef_1Sel( centralWidget() );
66 GroupPoints->GroupBox1->setTitle( tr( "GEOM_NODES" ) );
67 GroupPoints->TextLabel1->setText( tr( "GEOM_POINTS" ) );
68 GroupPoints->PushButton1->setIcon( image1 );
70 GroupPoints->LineEdit1->setReadOnly( true );
72 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
73 layout->setMargin( 0 ); layout->setSpacing( 6 );
74 layout->addWidget( GroupPoints );
75 /***************************************************************/
77 setHelpFileName( "curve.htm" );
83 //=================================================================================
84 // function : ~BasicGUI_CurveDlg()
85 // purpose : Destroys the object and frees any allocated resources
86 //=================================================================================
87 BasicGUI_CurveDlg::~BasicGUI_CurveDlg()
92 //=================================================================================
95 //=================================================================================
96 void BasicGUI_CurveDlg::Init()
99 myEditCurrentArgument = GroupPoints->LineEdit1;
101 myPoints = new GEOM::ListOfGO();
102 myPoints->length( 0 );
104 globalSelection( GEOM_POINT );
106 /* signals and slots connections */
107 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog( ) ) );
108 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
110 connect( buttonCancel(), SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) );
111 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
112 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
114 connect( this, SIGNAL( constructorsClicked( 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 mainFrame()->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 : isPointInList()
203 * purpose : Check is point (theObject) in the list \a thePoints.
205 * \retval -1, if point not in list, else 1 in list
207 //=================================================================================
208 static int isPointInList( list<GEOM::GEOM_Object_var>& thePoints,
209 GEOM::GEOM_Object_var& theObject )
211 int len = thePoints.size();
217 for ( list<GEOM::GEOM_Object_var>::iterator i = thePoints.begin(); i != thePoints.end(); i++ ) {
218 if ( string( (*i)->GetEntry() ) == string( theObject->GetEntry() ) ) {
225 //=================================================================================
226 /*! function : removeUnnecessaryPnt()
227 * purpose : Remove unnecessary points from list \a theOldPoints
229 * \li \a theOldPoints - ordered sequence with unnecessary point
230 * \li \a theNewPoints - not ordered sequence with necessary points
232 //=================================================================================
233 static void removeUnnecessaryPnt( list<GEOM::GEOM_Object_var>& theOldPoints,
234 GEOM::ListOfGO_var& theNewPoints )
236 list<GEOM::GEOM_Object_var> objs_to_remove;
237 for ( list<GEOM::GEOM_Object_var>::iterator i = theOldPoints.begin(); i != theOldPoints.end(); i++ ) {
239 for ( int j = 0; j < theNewPoints->length() && !found ; j++ ) {
240 if ( string( (*i)->GetEntry() ) == string( theNewPoints[j]->GetEntry() ) ) {
245 objs_to_remove.push_back( *i );
246 //cout << "removed: " << (*i)->GetEntry() << endl;
249 for ( list<GEOM::GEOM_Object_var>::iterator i = objs_to_remove.begin(); i != objs_to_remove.end(); i++ ) {
250 theOldPoints.remove( *i );
254 //=================================================================================
255 // function : SelectionIntoArgument()
256 // purpose : Called when selection as changed or other case
257 //=================================================================================
258 void BasicGUI_CurveDlg::SelectionIntoArgument()
260 myEditCurrentArgument->setText( "" );
262 Standard_Boolean aRes = Standard_False;
264 int IOC = IObjectCount();
265 bool is_append = myPoints->length() < IOC; // if true - add point, else remove
266 myPoints->length( IOC ); // this length may be greater than number of objects,
267 // that will actually be put into myPoints
268 for ( SALOME_ListIteratorOfListIO anIt( selectedIO() ); anIt.More(); anIt.Next() ) {
269 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value(), aRes );
270 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
271 //TopoDS_Shape aPointShape;
272 //if ( myGeomBase->GetShape( aSelectedObject, aPointShape, TopAbs_VERTEX ) )
273 int pos = isPointInList(myOrderedSel, aSelectedObject);
274 if ( is_append && pos == -1 )
275 myOrderedSel.push_back( aSelectedObject );
276 myPoints[i++] = aSelectedObject;
280 myPoints->length( i ); // this is the right length, smaller of equal to the previously set
282 myOrderedSel.clear();
284 removeUnnecessaryPnt( myOrderedSel, myPoints );
286 if ( myOrderedSel.size() == myPoints->length() ) {
288 for ( list<GEOM::GEOM_Object_var>::iterator j = myOrderedSel.begin(); j!= myOrderedSel.end(); j++ )
292 //cout << "ERROR: Ordered sequence size != selection sequence size! ("<<myOrderedSel.size()<<"!="<<myPoints->length()<<")"<<endl;
295 GroupPoints->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
301 //=================================================================================
302 // function : ActivateThisDialog()
304 //=================================================================================
305 void BasicGUI_CurveDlg::ActivateThisDialog()
307 GEOMBase_Skeleton::ActivateThisDialog();
308 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
309 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
311 // myGeomGUI->SetState( 0 );
313 globalSelection( GEOM_POINT );
314 ConstructorsClicked( getConstructorId() );
317 //=================================================================================
318 // function : DeactivateActiveDialog()
319 // purpose : public slot to deactivate if active
320 //=================================================================================
321 void BasicGUI_CurveDlg::DeactivateActiveDialog()
323 // myGeomGUI->SetState( -1 );
324 GEOMBase_Skeleton::DeactivateActiveDialog();
327 //=================================================================================
328 // function : enterEvent()
330 //=================================================================================
331 void BasicGUI_CurveDlg::enterEvent( QEvent* )
333 if ( !mainFrame()->GroupConstructors->isEnabled() )
334 ActivateThisDialog();
337 //=================================================================================
338 // function : createOperation
340 //=================================================================================
341 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
343 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
346 //=================================================================================
347 // function : isValid
349 //=================================================================================
350 bool BasicGUI_CurveDlg::isValid( QString& msg )
352 return myPoints->length() > 1;
355 //=================================================================================
356 // function : execute
358 //=================================================================================
359 bool BasicGUI_CurveDlg::execute( ObjectList& objects )
363 GEOM::GEOM_Object_var anObj;
365 switch ( getConstructorId() ) {
367 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakePolyline( myPoints );
371 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineBezier( myPoints );
375 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineInterpolation( myPoints );
380 if ( !anObj->_is_nil() )
381 objects.push_back( anObj._retn() );
386 //=================================================================================
387 // function : closeEvent
389 //=================================================================================
390 void BasicGUI_CurveDlg::closeEvent( QCloseEvent* e )
392 GEOMBase_Skeleton::closeEvent( e );