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
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 "LightApp_SelectionMgr.h"
37 #include "utilities.h"
39 #include "SALOME_ListIteratorOfListIO.hxx"
40 #include "SALOME_ListIO.hxx"
42 #include "GEOMImpl_Types.hxx"
47 //=================================================================================
48 // class : BasicGUI_CurveDlg()
49 // purpose : Constructs a BasicGUI_CurveDlg which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 BasicGUI_CurveDlg::BasicGUI_CurveDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
55 const char* name, bool modal, WFlags fl)
56 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
57 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
59 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POLYLINE")));
60 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SPLINE")));
61 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BEZIER")));
63 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
65 setCaption(tr("GEOM_CURVE_TITLE"));
67 /***************************************************************/
68 RadioButton1->setPixmap( image0 );
69 RadioButton2->setPixmap( image3 );
70 RadioButton3->setPixmap( image2 );
72 GroupPoints = new DlgRef_1Sel_QTD( this, "GroupPoints" );
73 GroupPoints->GroupBox1->setTitle( tr( "GEOM_NODES" ) );
74 GroupPoints->TextLabel1->setText( tr("GEOM_POINTS") );
75 GroupPoints->PushButton1->setPixmap(image1);
77 GroupPoints->LineEdit1->setReadOnly( true );
79 Layout1->addWidget(GroupPoints, 2, 0);
80 /***************************************************************/
82 setHelpFileName("curve.htm");
88 //=================================================================================
89 // function : ~BasicGUI_CurveDlg()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 BasicGUI_CurveDlg::~BasicGUI_CurveDlg()
97 //=================================================================================
100 //=================================================================================
101 void BasicGUI_CurveDlg::Init()
104 myEditCurrentArgument = GroupPoints->LineEdit1;
106 myPoints = new GEOM::ListOfGO();
107 myPoints->length( 0 );
109 globalSelection( GEOM_POINT );
111 /* signals and slots connections */
112 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
113 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
114 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
116 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
117 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
118 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
120 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
121 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
123 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
124 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
126 initName( tr( "GEOM_CURVE" ) );
127 ConstructorsClicked( 0 );
130 //=================================================================================
131 // function : ConstructorsClicked()
133 //=================================================================================
134 void BasicGUI_CurveDlg::ConstructorsClicked( int id )
136 QString aTitle = tr( id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL" );
137 GroupConstructors->setTitle( aTitle );
139 myPoints = new GEOM::ListOfGO();
140 myPoints->length( 0 );
142 myEditCurrentArgument->setText("");
146 //=================================================================================
147 // function : SetEditCurrentArgument()
149 //=================================================================================
150 void BasicGUI_CurveDlg::SetEditCurrentArgument()
152 if ( sender() == GroupPoints->PushButton1 )
153 myEditCurrentArgument = GroupPoints->LineEdit1;
154 myEditCurrentArgument->setFocus();
155 SelectionIntoArgument();
159 //=================================================================================
160 // function : LineEditReturnPressed()
162 //=================================================================================
163 void BasicGUI_CurveDlg::LineEditReturnPressed()
165 if ( sender() == GroupPoints->LineEdit1 )
167 myEditCurrentArgument = GroupPoints->LineEdit1;
168 GEOMBase_Skeleton::LineEditReturnPressed();
172 //=================================================================================
173 // function : ClickOnOk()
175 //=================================================================================
176 void BasicGUI_CurveDlg::ClickOnOk()
178 if ( ClickOnApply() )
182 //=================================================================================
183 // function : ClickOnApply()
185 //=================================================================================
186 bool BasicGUI_CurveDlg::ClickOnApply()
192 ConstructorsClicked( getConstructorId() );
196 //=======================================================================
197 // function : ClickOnCancel()
199 //=======================================================================
200 void BasicGUI_CurveDlg::ClickOnCancel()
202 GEOMBase_Skeleton::ClickOnCancel();
205 //=================================================================================
206 /*! function : isPointInList()
207 * purpose : Check is point (theObject) in the list \a thePoints.
209 * \retval -1, if point not in list, else 1 in list
211 //=================================================================================
212 static int isPointInList(list<GEOM::GEOM_Object_var>& thePoints,
213 GEOM::GEOM_Object_var& theObject)
215 int len = thePoints.size();
221 for(list<GEOM::GEOM_Object_var>::iterator i=thePoints.begin();i!=thePoints.end();i++)
222 if (string((*i)->GetEntry()) == string(theObject->GetEntry())){
228 //=================================================================================
229 /*! function : removeUnnecessaryPnt()
230 * purpose : Remove unnecessary points from list \a theOldPoints
232 * \li \a theOldPoints - ordered sequence with unnecessary point
233 * \li \a theNewPoints - not ordered sequence with necessary points
235 //=================================================================================
236 static void removeUnnecessaryPnt(list<GEOM::GEOM_Object_var>& theOldPoints,
237 GEOM::ListOfGO_var& theNewPoints)
239 list<GEOM::GEOM_Object_var> objs_to_remove;
240 for(list<GEOM::GEOM_Object_var>::iterator i=theOldPoints.begin();i!=theOldPoints.end();i++){
242 for (int j=0;j<theNewPoints->length() && !found ; j++){
243 if(string((*i)->GetEntry()) == string(theNewPoints[j]->GetEntry())){
248 objs_to_remove.push_back(*i);
249 //cout << "removed: " << (*i)->GetEntry() << endl;
252 for(list<GEOM::GEOM_Object_var>::iterator i=objs_to_remove.begin();i!=objs_to_remove.end();i++){
253 theOldPoints.remove(*i);
257 //=================================================================================
258 // function : SelectionIntoArgument()
259 // purpose : Called when selection as changed or other case
260 //=================================================================================
261 void BasicGUI_CurveDlg::SelectionIntoArgument()
263 myEditCurrentArgument->setText("");
265 Standard_Boolean aRes = Standard_False;
267 int IOC = IObjectCount();
268 bool is_append = myPoints->length() < IOC; // if true - add point, else remove
269 myPoints->length( IOC ); // this length may be greater than number of objects,
270 // that will actually be put into myPoints
271 for ( SALOME_ListIteratorOfListIO anIt( selectedIO() ); anIt.More(); anIt.Next() )
273 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value(), aRes );
274 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
276 //TopoDS_Shape aPointShape;
277 //if ( myGeomBase->GetShape( aSelectedObject, aPointShape, TopAbs_VERTEX ) )
278 int pos = isPointInList(myOrderedSel,aSelectedObject);
279 if(is_append && pos==-1)
280 myOrderedSel.push_back(aSelectedObject);
281 myPoints[i++] = aSelectedObject;
285 myPoints->length( i ); // this is the right length, smaller of equal to the previously set
287 myOrderedSel.clear();
289 removeUnnecessaryPnt(myOrderedSel,myPoints);
291 if(myOrderedSel.size() == myPoints->length()){
293 for (list<GEOM::GEOM_Object_var>::iterator j=myOrderedSel.begin();j!=myOrderedSel.end();j++)
296 //cout << "ERROR: Ordered sequence size != selection sequence size! ("<<myOrderedSel.size()<<"!="<<myPoints->length()<<")"<<endl;
299 GroupPoints->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
305 //=================================================================================
306 // function : ActivateThisDialog()
308 //=================================================================================
309 void BasicGUI_CurveDlg::ActivateThisDialog()
311 GEOMBase_Skeleton::ActivateThisDialog();
312 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
313 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
315 // myGeomGUI->SetState( 0 );
317 globalSelection( GEOM_POINT );
318 ConstructorsClicked( getConstructorId() );
321 //=================================================================================
322 // function : DeactivateActiveDialog()
323 // purpose : public slot to deactivate if active
324 //=================================================================================
325 void BasicGUI_CurveDlg::DeactivateActiveDialog()
327 // myGeomGUI->SetState( -1 );
328 GEOMBase_Skeleton::DeactivateActiveDialog();
331 //=================================================================================
332 // function : enterEvent()
334 //=================================================================================
335 void BasicGUI_CurveDlg::enterEvent(QEvent* e)
337 if ( !GroupConstructors->isEnabled() )
338 ActivateThisDialog();
341 //=================================================================================
342 // function : createOperation
344 //=================================================================================
345 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
347 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
350 //=================================================================================
351 // function : isValid
353 //=================================================================================
354 bool BasicGUI_CurveDlg::isValid( QString& msg )
356 return myPoints->length() > 1;
359 //=================================================================================
360 // function : execute
362 //=================================================================================
363 bool BasicGUI_CurveDlg::execute( ObjectList& objects )
367 GEOM::GEOM_Object_var anObj;
369 switch ( getConstructorId() )
372 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakePolyline( myPoints );
376 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineBezier( myPoints );
380 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineInterpolation( myPoints );
385 if ( !anObj->_is_nil() )
386 objects.push_back( anObj._retn() );
391 //=================================================================================
392 // function : closeEvent
394 //=================================================================================
395 void BasicGUI_CurveDlg::closeEvent( QCloseEvent* e )
397 GEOMBase_Skeleton::closeEvent( e );