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 "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, const char* name, bool modal, WFlags fl)
55 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
56 myGeometryGUI(theGeometryGUI)
58 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POLYLINE")));
59 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SPLINE")));
60 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BEZIER")));
62 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
64 setCaption(tr("GEOM_CURVE_TITLE"));
66 /***************************************************************/
67 RadioButton1->setPixmap( image0 );
68 RadioButton2->setPixmap( image3 );
69 RadioButton3->setPixmap( image2 );
71 GroupPoints = new DlgRef_1Sel_QTD( this, "GroupPoints" );
72 GroupPoints->GroupBox1->setTitle( tr( "GEOM_NODES" ) );
73 GroupPoints->TextLabel1->setText( tr("GEOM_POINTS") );
74 GroupPoints->PushButton1->setPixmap(image1);
76 GroupPoints->LineEdit1->setReadOnly( true );
78 Layout1->addWidget(GroupPoints, 2, 0);
79 /***************************************************************/
85 //=================================================================================
86 // function : ~BasicGUI_CurveDlg()
87 // purpose : Destroys the object and frees any allocated resources
88 //=================================================================================
89 BasicGUI_CurveDlg::~BasicGUI_CurveDlg()
94 //=================================================================================
97 //=================================================================================
98 void BasicGUI_CurveDlg::Init()
101 myEditCurrentArgument = GroupPoints->LineEdit1;
103 myPoints = new GEOM::ListOfGO();
104 myPoints->length( 0 );
106 globalSelection( GEOM_POINT );
108 /* signals and slots connections */
109 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
110 connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
111 connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
113 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
114 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
115 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
117 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
118 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
120 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
121 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
123 initName( tr( "GEOM_CURVE" ) );
124 ConstructorsClicked( 0 );
127 //=================================================================================
128 // function : ConstructorsClicked()
130 //=================================================================================
131 void BasicGUI_CurveDlg::ConstructorsClicked( int id )
133 QString aTitle = tr( id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL" );
134 GroupConstructors->setTitle( aTitle );
136 myPoints = new GEOM::ListOfGO();
137 myPoints->length( 0 );
139 myEditCurrentArgument->setText("");
143 //=================================================================================
144 // function : SetEditCurrentArgument()
146 //=================================================================================
147 void BasicGUI_CurveDlg::SetEditCurrentArgument()
149 if ( sender() == GroupPoints->PushButton1 )
150 myEditCurrentArgument = GroupPoints->LineEdit1;
151 myEditCurrentArgument->setFocus();
152 SelectionIntoArgument();
156 //=================================================================================
157 // function : LineEditReturnPressed()
159 //=================================================================================
160 void BasicGUI_CurveDlg::LineEditReturnPressed()
162 if ( sender() == GroupPoints->LineEdit1 )
164 myEditCurrentArgument = GroupPoints->LineEdit1;
165 GEOMBase_Skeleton::LineEditReturnPressed();
169 //=================================================================================
170 // function : ClickOnOk()
172 //=================================================================================
173 void BasicGUI_CurveDlg::ClickOnOk()
175 if ( ClickOnApply() )
179 //=================================================================================
180 // function : ClickOnApply()
182 //=================================================================================
183 bool BasicGUI_CurveDlg::ClickOnApply()
189 ConstructorsClicked( getConstructorId() );
193 //=======================================================================
194 // function : ClickOnCancel()
196 //=======================================================================
197 void BasicGUI_CurveDlg::ClickOnCancel()
199 GEOMBase_Skeleton::ClickOnCancel();
202 //=================================================================================
203 /*! function : isPointInList()
204 * purpose : Check is point (theObject) in the list \a thePoints.
206 * \retval -1, if point not in list, else 1 in list
208 //=================================================================================
209 static int isPointInList(list<GEOM::GEOM_Object_var>& thePoints,
210 GEOM::GEOM_Object_var& theObject)
212 int len = thePoints.size();
218 for(list<GEOM::GEOM_Object_var>::iterator i=thePoints.begin();i!=thePoints.end();i++)
219 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() )
270 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value(), aRes );
271 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
273 //TopoDS_Shape aPointShape;
274 //if ( myGeomBase->GetShape( aSelectedObject, aPointShape, TopAbs_VERTEX ) )
275 int pos = isPointInList(myOrderedSel,aSelectedObject);
276 if(is_append && pos==-1)
277 myOrderedSel.push_back(aSelectedObject);
278 myPoints[i++] = aSelectedObject;
282 myPoints->length( i ); // this is the right length, smaller of equal to the previously set
284 myOrderedSel.clear();
286 removeUnnecessaryPnt(myOrderedSel,myPoints);
288 if(myOrderedSel.size() == myPoints->length()){
290 for (list<GEOM::GEOM_Object_var>::iterator j=myOrderedSel.begin();j!=myOrderedSel.end();j++)
293 //cout << "ERROR: Ordered sequence size != selection sequence size! ("<<myOrderedSel.size()<<"!="<<myPoints->length()<<")"<<endl;
296 GroupPoints->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
302 //=================================================================================
303 // function : ActivateThisDialog()
305 //=================================================================================
306 void BasicGUI_CurveDlg::ActivateThisDialog()
308 GEOMBase_Skeleton::ActivateThisDialog();
309 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
310 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
312 // myGeometryGUI->SetState( 0 );
314 globalSelection( GEOM_POINT );
315 ConstructorsClicked( getConstructorId() );
318 //=================================================================================
319 // function : DeactivateActiveDialog()
320 // purpose : public slot to deactivate if active
321 //=================================================================================
322 void BasicGUI_CurveDlg::DeactivateActiveDialog()
324 // myGeometryGUI->SetState( -1 );
325 GEOMBase_Skeleton::DeactivateActiveDialog();
328 //=================================================================================
329 // function : enterEvent()
331 //=================================================================================
332 void BasicGUI_CurveDlg::enterEvent(QEvent* e)
334 if ( !GroupConstructors->isEnabled() )
335 ActivateThisDialog();
338 //=================================================================================
339 // function : createOperation
341 //=================================================================================
342 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
344 return myGeometryGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
347 //=================================================================================
348 // function : isValid
350 //=================================================================================
351 bool BasicGUI_CurveDlg::isValid( QString& msg )
353 return myPoints->length() > 1;
356 //=================================================================================
357 // function : execute
359 //=================================================================================
360 bool BasicGUI_CurveDlg::execute( ObjectList& objects )
364 GEOM::GEOM_Object_var anObj;
366 switch ( getConstructorId() )
369 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakePolyline( myPoints );
373 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineBezier( myPoints );
377 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineInterpolation( myPoints );
382 if ( !anObj->_is_nil() )
383 objects.push_back( anObj._retn() );
388 //=================================================================================
389 // function : closeEvent
391 //=================================================================================
392 void BasicGUI_CurveDlg::closeEvent( QCloseEvent* e )
394 // myGeometryGUI->SetState( -1 );
395 GEOMBase_Skeleton::closeEvent( e );