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 <TopoDS_Shape.hxx>
45 #include <TColStd_IndexedMapOfInteger.hxx>
46 #include <TopTools_IndexedMapOfShape.hxx>
48 #include "GEOMImpl_Types.hxx"
53 //=================================================================================
54 // class : BasicGUI_CurveDlg()
55 // purpose : Constructs a BasicGUI_CurveDlg which is a child of 'parent', with the
56 // name 'name' and widget flags set to 'f'.
57 // The dialog will by default be modeless, unless you set 'modal' to
58 // TRUE to construct a modal dialog.
59 //=================================================================================
60 BasicGUI_CurveDlg::BasicGUI_CurveDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
61 const char* name, bool modal, WFlags fl)
62 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
63 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
65 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POLYLINE")));
66 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SPLINE")));
67 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BEZIER")));
69 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
71 setCaption(tr("GEOM_CURVE_TITLE"));
73 /***************************************************************/
74 RadioButton1->setPixmap( image0 );
75 RadioButton2->setPixmap( image3 );
76 RadioButton3->setPixmap( image2 );
78 GroupPoints = new DlgRef_1Sel_QTD( this, "GroupPoints" );
79 GroupPoints->GroupBox1->setTitle( tr( "GEOM_NODES" ) );
80 GroupPoints->TextLabel1->setText( tr("GEOM_POINTS") );
81 GroupPoints->PushButton1->setPixmap(image1);
83 GroupPoints->LineEdit1->setReadOnly( true );
85 Layout1->addWidget(GroupPoints, 2, 0);
86 /***************************************************************/
88 setHelpFileName("curve.htm");
94 //=================================================================================
95 // function : ~BasicGUI_CurveDlg()
96 // purpose : Destroys the object and frees any allocated resources
97 //=================================================================================
98 BasicGUI_CurveDlg::~BasicGUI_CurveDlg()
103 //=================================================================================
106 //=================================================================================
107 void BasicGUI_CurveDlg::Init()
110 myEditCurrentArgument = GroupPoints->LineEdit1;
112 myPoints = new GEOM::ListOfGO();
113 myPoints->length( 0 );
115 // globalSelection( GEOM_POINT );
116 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
118 /* signals and slots connections */
119 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
120 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
121 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
123 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
124 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
127 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
130 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
131 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
133 initName( tr( "GEOM_CURVE" ) );
134 ConstructorsClicked( 0 );
137 //=================================================================================
138 // function : ConstructorsClicked()
140 //=================================================================================
141 void BasicGUI_CurveDlg::ConstructorsClicked( int id )
143 QString aTitle = tr( id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL" );
144 GroupConstructors->setTitle( aTitle );
146 myPoints = new GEOM::ListOfGO();
147 myPoints->length( 0 );
149 myEditCurrentArgument->setText("");
153 //=================================================================================
154 // function : SetEditCurrentArgument()
156 //=================================================================================
157 void BasicGUI_CurveDlg::SetEditCurrentArgument()
159 if ( sender() == GroupPoints->PushButton1 )
160 myEditCurrentArgument = GroupPoints->LineEdit1;
161 myEditCurrentArgument->setFocus();
162 SelectionIntoArgument();
166 //=================================================================================
167 // function : LineEditReturnPressed()
169 //=================================================================================
170 void BasicGUI_CurveDlg::LineEditReturnPressed()
172 if ( sender() == GroupPoints->LineEdit1 )
174 myEditCurrentArgument = GroupPoints->LineEdit1;
175 GEOMBase_Skeleton::LineEditReturnPressed();
179 //=================================================================================
180 // function : ClickOnOk()
182 //=================================================================================
183 void BasicGUI_CurveDlg::ClickOnOk()
185 if ( ClickOnApply() )
189 //=================================================================================
190 // function : ClickOnApply()
192 //=================================================================================
193 bool BasicGUI_CurveDlg::ClickOnApply()
199 ConstructorsClicked( getConstructorId() );
203 //=======================================================================
204 // function : ClickOnCancel()
206 //=======================================================================
207 void BasicGUI_CurveDlg::ClickOnCancel()
209 GEOMBase_Skeleton::ClickOnCancel();
212 //=================================================================================
213 /*! function : isPointInList()
214 * purpose : Check is point (theObject) in the list \a thePoints.
216 * \retval -1, if point not in list, else 1 in list
218 //=================================================================================
219 static int isPointInList(list<GEOM::GEOM_Object_var>& thePoints,
220 GEOM::GEOM_Object_var& theObject)
222 int len = thePoints.size();
228 for(list<GEOM::GEOM_Object_var>::iterator i=thePoints.begin();i!=thePoints.end();i++)
229 if (string((*i)->GetEntry()) == string(theObject->GetEntry())){
235 //=================================================================================
236 /*! function : removeUnnecessaryPnt()
237 * purpose : Remove unnecessary points from list \a theOldPoints
239 * \li \a theOldPoints - ordered sequence with unnecessary point
240 * \li \a theNewPoints - not ordered sequence with necessary points
242 //=================================================================================
243 static void removeUnnecessaryPnt(list<GEOM::GEOM_Object_var>& theOldPoints,
244 GEOM::ListOfGO_var& theNewPoints)
246 list<GEOM::GEOM_Object_var> objs_to_remove;
247 for(list<GEOM::GEOM_Object_var>::iterator i=theOldPoints.begin();i!=theOldPoints.end();i++){
249 for (int j=0;j<theNewPoints->length() && !found ; j++){
250 if(string((*i)->GetEntry()) == string(theNewPoints[j]->GetEntry())){
255 objs_to_remove.push_back(*i);
256 //cout << "removed: " << (*i)->GetEntry() << endl;
259 for(list<GEOM::GEOM_Object_var>::iterator i=objs_to_remove.begin();i!=objs_to_remove.end();i++){
260 theOldPoints.remove(*i);
264 //=================================================================================
265 // function : SelectionIntoArgument()
266 // purpose : Called when selection as changed or other case
267 //=================================================================================
268 void BasicGUI_CurveDlg::SelectionIntoArgument()
270 myEditCurrentArgument->setText("");
272 Standard_Boolean aRes = Standard_False;
274 int IOC = IObjectCount();
275 bool is_append = myPoints->length() < IOC; // if true - add point, else remove
276 myPoints->length( IOC ); // this length may be greater than number of objects,
277 // that will actually be put into myPoints
278 for ( SALOME_ListIteratorOfListIO anIt( selectedIO() ); anIt.More(); anIt.Next() )
280 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value(), aRes );
281 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
283 //TopoDS_Shape aPointShape;
284 //if ( myGeomBase->GetShape( aSelectedObject, aPointShape, TopAbs_VERTEX ) )
287 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
289 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
290 TColStd_IndexedMapOfInteger aMap;
291 aSelMgr->GetIndexes( anIt.Value(), aMap );
292 if ( aMap.Extent() == 1 )
294 GEOM::GEOM_IShapesOperations_var aShapesOp =
295 getGeomEngine()->GetIShapesOperations( getStudyId() );
296 int anIndex = aMap( 1 );
297 TopTools_IndexedMapOfShape aShapes;
298 TopExp::MapShapes( aShape, aShapes );
299 aShape = aShapes.FindKey( anIndex );
300 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
301 aSelMgr->clearSelected();
305 int pos = isPointInList(myOrderedSel,aSelectedObject);
306 if(is_append && pos==-1)
307 myOrderedSel.push_back(aSelectedObject);
309 myPoints[i++] = aSelectedObject;
313 myPoints->length( i ); // this is the right length, smaller of equal to the previously set
315 myOrderedSel.clear();
317 removeUnnecessaryPnt(myOrderedSel,myPoints);
319 if(myOrderedSel.size() == myPoints->length()){
321 for (list<GEOM::GEOM_Object_var>::iterator j=myOrderedSel.begin();j!=myOrderedSel.end();j++)
324 //cout << "ERROR: Ordered sequence size != selection sequence size! ("<<myOrderedSel.size()<<"!="<<myPoints->length()<<")"<<endl;
327 GroupPoints->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
333 //=================================================================================
334 // function : ActivateThisDialog()
336 //=================================================================================
337 void BasicGUI_CurveDlg::ActivateThisDialog()
339 GEOMBase_Skeleton::ActivateThisDialog();
340 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
341 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
343 // myGeomGUI->SetState( 0 );
345 // globalSelection( GEOM_POINT );
346 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
347 ConstructorsClicked( getConstructorId() );
350 //=================================================================================
351 // function : DeactivateActiveDialog()
352 // purpose : public slot to deactivate if active
353 //=================================================================================
354 void BasicGUI_CurveDlg::DeactivateActiveDialog()
356 // myGeomGUI->SetState( -1 );
357 GEOMBase_Skeleton::DeactivateActiveDialog();
360 //=================================================================================
361 // function : enterEvent()
363 //=================================================================================
364 void BasicGUI_CurveDlg::enterEvent(QEvent* e)
366 if ( !GroupConstructors->isEnabled() )
367 ActivateThisDialog();
370 //=================================================================================
371 // function : createOperation
373 //=================================================================================
374 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
376 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
379 //=================================================================================
380 // function : isValid
382 //=================================================================================
383 bool BasicGUI_CurveDlg::isValid( QString& msg )
385 return myPoints->length() > 1;
388 //=================================================================================
389 // function : execute
391 //=================================================================================
392 bool BasicGUI_CurveDlg::execute( ObjectList& objects )
396 GEOM::GEOM_Object_var anObj;
398 switch ( getConstructorId() )
401 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakePolyline( myPoints );
405 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineBezier( myPoints );
409 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineInterpolation( myPoints );
414 if ( !anObj->_is_nil() )
415 objects.push_back( anObj._retn() );
420 //=================================================================================
421 // function : closeEvent
423 //=================================================================================
424 void BasicGUI_CurveDlg::closeEvent( QCloseEvent* e )
426 GEOMBase_Skeleton::closeEvent( e );