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 bool modal, Qt::WindowFlags fl )
50 : GEOMBase_Skeleton( theGeometryGUI, parent, "BasicGUI_CurveDlg", 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( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
111 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
113 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
115 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
116 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
118 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
119 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
121 initName( tr( "GEOM_CURVE" ) );
122 ConstructorsClicked( 0 );
125 //=================================================================================
126 // function : ConstructorsClicked()
128 //=================================================================================
129 void BasicGUI_CurveDlg::ConstructorsClicked( int id )
131 QString aTitle = tr( id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL" );
132 mainFrame()->GroupConstructors->setTitle( aTitle );
134 myPoints = new GEOM::ListOfGO();
135 myPoints->length( 0 );
137 myEditCurrentArgument->setText( "" );
141 //=================================================================================
142 // function : SetEditCurrentArgument()
144 //=================================================================================
145 void BasicGUI_CurveDlg::SetEditCurrentArgument()
147 if ( sender() == GroupPoints->PushButton1 )
148 myEditCurrentArgument = GroupPoints->LineEdit1;
149 myEditCurrentArgument->setFocus();
150 SelectionIntoArgument();
154 //=================================================================================
155 // function : LineEditReturnPressed()
157 //=================================================================================
158 void BasicGUI_CurveDlg::LineEditReturnPressed()
160 if ( sender() == GroupPoints->LineEdit1 )
162 myEditCurrentArgument = GroupPoints->LineEdit1;
163 GEOMBase_Skeleton::LineEditReturnPressed();
167 //=================================================================================
168 // function : ClickOnOk()
170 //=================================================================================
171 void BasicGUI_CurveDlg::ClickOnOk()
173 if ( ClickOnApply() )
177 //=================================================================================
178 // function : ClickOnApply()
180 //=================================================================================
181 bool BasicGUI_CurveDlg::ClickOnApply()
187 ConstructorsClicked( getConstructorId() );
191 //=================================================================================
192 /*! function : isPointInList()
193 * purpose : Check is point (theObject) in the list \a thePoints.
195 * \retval -1, if point not in list, else 1 in list
197 //=================================================================================
198 static int isPointInList( list<GEOM::GEOM_Object_var>& thePoints,
199 GEOM::GEOM_Object_var& theObject )
201 int len = thePoints.size();
207 for ( list<GEOM::GEOM_Object_var>::iterator i = thePoints.begin(); i != thePoints.end(); i++ ) {
208 if ( string( (*i)->GetEntry() ) == string( theObject->GetEntry() ) ) {
215 //=================================================================================
216 /*! function : removeUnnecessaryPnt()
217 * purpose : Remove unnecessary points from list \a theOldPoints
219 * \li \a theOldPoints - ordered sequence with unnecessary point
220 * \li \a theNewPoints - not ordered sequence with necessary points
222 //=================================================================================
223 static void removeUnnecessaryPnt( list<GEOM::GEOM_Object_var>& theOldPoints,
224 GEOM::ListOfGO_var& theNewPoints )
226 list<GEOM::GEOM_Object_var> objs_to_remove;
227 for ( list<GEOM::GEOM_Object_var>::iterator i = theOldPoints.begin(); i != theOldPoints.end(); i++ ) {
229 for ( int j = 0; j < theNewPoints->length() && !found ; j++ ) {
230 if ( string( (*i)->GetEntry() ) == string( theNewPoints[j]->GetEntry() ) ) {
235 objs_to_remove.push_back( *i );
236 //cout << "removed: " << (*i)->GetEntry() << endl;
239 for ( list<GEOM::GEOM_Object_var>::iterator i = objs_to_remove.begin(); i != objs_to_remove.end(); i++ ) {
240 theOldPoints.remove( *i );
244 //=================================================================================
245 // function : SelectionIntoArgument()
246 // purpose : Called when selection as changed or other case
247 //=================================================================================
248 void BasicGUI_CurveDlg::SelectionIntoArgument()
250 myEditCurrentArgument->setText( "" );
252 Standard_Boolean aRes = Standard_False;
254 int IOC = IObjectCount();
255 bool is_append = myPoints->length() < IOC; // if true - add point, else remove
256 myPoints->length( IOC ); // this length may be greater than number of objects,
257 // that will actually be put into myPoints
258 for ( SALOME_ListIteratorOfListIO anIt( selectedIO() ); anIt.More(); anIt.Next() ) {
259 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value(), aRes );
260 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
261 //TopoDS_Shape aPointShape;
262 //if ( myGeomBase->GetShape( aSelectedObject, aPointShape, TopAbs_VERTEX ) )
263 int pos = isPointInList(myOrderedSel, aSelectedObject);
264 if ( is_append && pos == -1 )
265 myOrderedSel.push_back( aSelectedObject );
266 myPoints[i++] = aSelectedObject;
270 myPoints->length( i ); // this is the right length, smaller of equal to the previously set
272 myOrderedSel.clear();
274 removeUnnecessaryPnt( myOrderedSel, myPoints );
276 if ( myOrderedSel.size() == myPoints->length() ) {
278 for ( list<GEOM::GEOM_Object_var>::iterator j = myOrderedSel.begin(); j!= myOrderedSel.end(); j++ )
282 //cout << "ERROR: Ordered sequence size != selection sequence size! ("<<myOrderedSel.size()<<"!="<<myPoints->length()<<")"<<endl;
285 GroupPoints->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
291 //=================================================================================
292 // function : ActivateThisDialog()
294 //=================================================================================
295 void BasicGUI_CurveDlg::ActivateThisDialog()
297 GEOMBase_Skeleton::ActivateThisDialog();
298 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
299 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
301 // myGeomGUI->SetState( 0 );
303 globalSelection( GEOM_POINT );
304 ConstructorsClicked( getConstructorId() );
307 //=================================================================================
308 // function : DeactivateActiveDialog()
309 // purpose : public slot to deactivate if active
310 //=================================================================================
311 void BasicGUI_CurveDlg::DeactivateActiveDialog()
313 // myGeomGUI->SetState( -1 );
314 GEOMBase_Skeleton::DeactivateActiveDialog();
317 //=================================================================================
318 // function : enterEvent()
320 //=================================================================================
321 void BasicGUI_CurveDlg::enterEvent( QEvent* )
323 if ( !mainFrame()->GroupConstructors->isEnabled() )
324 ActivateThisDialog();
327 //=================================================================================
328 // function : createOperation
330 //=================================================================================
331 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
333 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
336 //=================================================================================
337 // function : isValid
339 //=================================================================================
340 bool BasicGUI_CurveDlg::isValid( QString& msg )
342 return myPoints->length() > 1;
345 //=================================================================================
346 // function : execute
348 //=================================================================================
349 bool BasicGUI_CurveDlg::execute( ObjectList& objects )
353 GEOM::GEOM_Object_var anObj;
355 switch ( getConstructorId() ) {
357 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakePolyline( myPoints );
361 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineBezier( myPoints );
365 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineInterpolation( myPoints );
370 if ( !anObj->_is_nil() )
371 objects.push_back( anObj._retn() );
376 //=================================================================================
377 // function : closeEvent
379 //=================================================================================
380 void BasicGUI_CurveDlg::closeEvent( QCloseEvent* e )
382 GEOMBase_Skeleton::closeEvent( e );