1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
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 "SalomeApp_Study.h"
34 #include "LightApp_SelectionMgr.h"
38 #include "utilities.h"
40 #include "SALOME_ListIteratorOfListIO.hxx"
41 #include "SALOME_ListIO.hxx"
43 #include <TopoDS_Shape.hxx>
46 #include <TColStd_IndexedMapOfInteger.hxx>
47 #include <TopTools_IndexedMapOfShape.hxx>
49 #include "GEOMImpl_Types.hxx"
54 //=================================================================================
55 // class : BasicGUI_CurveDlg()
56 // purpose : Constructs a BasicGUI_CurveDlg which is a child of 'parent', with the
57 // name 'name' and widget flags set to 'f'.
58 // The dialog will by default be modeless, unless you set 'modal' to
59 // TRUE to construct a modal dialog.
60 //=================================================================================
61 BasicGUI_CurveDlg::BasicGUI_CurveDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
62 const char* name, bool modal, WFlags fl)
63 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
64 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
66 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POLYLINE")));
67 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SPLINE")));
68 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BEZIER")));
70 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
72 setCaption(tr("GEOM_CURVE_TITLE"));
74 /***************************************************************/
75 RadioButton1->setPixmap( image0 );
76 RadioButton2->setPixmap( image3 );
77 RadioButton3->setPixmap( image2 );
79 GroupPoints = new DlgRef_1Sel_QTD( this, "GroupPoints" );
80 GroupPoints->GroupBox1->setTitle( tr( "GEOM_NODES" ) );
81 GroupPoints->TextLabel1->setText( tr("GEOM_POINTS") );
82 GroupPoints->PushButton1->setPixmap(image1);
84 GroupPoints->LineEdit1->setReadOnly( true );
86 Layout1->addWidget(GroupPoints, 2, 0);
87 /***************************************************************/
89 setHelpFileName("create_curve_page.html");
95 //=================================================================================
96 // function : ~BasicGUI_CurveDlg()
97 // purpose : Destroys the object and frees any allocated resources
98 //=================================================================================
99 BasicGUI_CurveDlg::~BasicGUI_CurveDlg()
104 //=================================================================================
107 //=================================================================================
108 void BasicGUI_CurveDlg::Init()
111 myEditCurrentArgument = GroupPoints->LineEdit1;
113 myPoints = new GEOM::ListOfGO();
114 myPoints->length( 0 );
116 globalSelection(); // close local contexts, if any
117 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
119 /* signals and slots connections */
120 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
121 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
122 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
124 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
125 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
126 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
128 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
131 connect(myGeomGUI->getApp()->selectionMgr(),
132 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
134 initName( tr( "GEOM_CURVE" ) );
135 ConstructorsClicked( 0 );
138 //=================================================================================
139 // function : ConstructorsClicked()
141 //=================================================================================
142 void BasicGUI_CurveDlg::ConstructorsClicked( int id )
144 QString aTitle = tr( id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL" );
145 GroupConstructors->setTitle( aTitle );
147 myPoints = new GEOM::ListOfGO();
148 myPoints->length( 0 );
150 myEditCurrentArgument->setText("");
154 //=================================================================================
155 // function : SetEditCurrentArgument()
157 //=================================================================================
158 void BasicGUI_CurveDlg::SetEditCurrentArgument()
160 if ( sender() == GroupPoints->PushButton1 )
161 myEditCurrentArgument = GroupPoints->LineEdit1;
162 myEditCurrentArgument->setFocus();
163 SelectionIntoArgument();
167 //=================================================================================
168 // function : LineEditReturnPressed()
170 //=================================================================================
171 void BasicGUI_CurveDlg::LineEditReturnPressed()
173 if ( sender() == GroupPoints->LineEdit1 )
175 myEditCurrentArgument = GroupPoints->LineEdit1;
176 GEOMBase_Skeleton::LineEditReturnPressed();
180 //=================================================================================
181 // function : ClickOnOk()
183 //=================================================================================
184 void BasicGUI_CurveDlg::ClickOnOk()
186 if ( ClickOnApply() )
190 //=================================================================================
191 // function : ClickOnApply()
193 //=================================================================================
194 bool BasicGUI_CurveDlg::ClickOnApply()
200 ConstructorsClicked( getConstructorId() );
201 globalSelection(); // close local contexts, if any
202 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
206 //=======================================================================
207 // function : ClickOnCancel()
209 //=======================================================================
210 void BasicGUI_CurveDlg::ClickOnCancel()
212 GEOMBase_Skeleton::ClickOnCancel();
215 //=================================================================================
216 /*! function : isPointInList()
217 * purpose : Check is point (theObject) in the list \a thePoints.
219 * \retval -1, if point not in list, else 1 in list
221 //=================================================================================
222 static int isPointInList(list<GEOM::GEOM_Object_var>& thePoints,
223 GEOM::GEOM_Object_var& theObject)
225 int len = thePoints.size();
231 for(list<GEOM::GEOM_Object_var>::iterator i=thePoints.begin();i!=thePoints.end();i++)
232 if (string((*i)->GetEntry()) == string(theObject->GetEntry())){
239 //=================================================================================
240 /*! function : removeUnnecessaryPnt()
241 * purpose : Remove unnecessary points from list \a theOldPoints
243 * \li \a theOldPoints - ordered sequence with unnecessary point
244 * \li \a theNewPoints - not ordered sequence with necessary points
246 //=================================================================================
247 static void removeUnnecessaryPnt(list<GEOM::GEOM_Object_var>& theOldPoints,
248 GEOM::ListOfGO_var& theNewPoints)
250 list<GEOM::GEOM_Object_var> objs_to_remove;
251 for(list<GEOM::GEOM_Object_var>::iterator i=theOldPoints.begin();i!=theOldPoints.end();i++){
253 for (int j=0;j<theNewPoints->length() && !found ; j++){
254 if(string((*i)->GetEntry()) == string(theNewPoints[j]->GetEntry())){
259 objs_to_remove.push_back(*i);
260 //cout << "removed: " << (*i)->GetEntry() << endl;
263 for(list<GEOM::GEOM_Object_var>::iterator i=objs_to_remove.begin();i!=objs_to_remove.end();i++){
264 theOldPoints.remove(*i);
268 //=================================================================================
269 // function : SelectionIntoArgument()
270 // purpose : Called when selection as changed or other case
271 //=================================================================================
272 void BasicGUI_CurveDlg::SelectionIntoArgument()
274 myEditCurrentArgument->setText("");
276 Standard_Boolean aRes = Standard_False;
277 int IOC = IObjectCount();
278 // bool is_append = myPoints->length() < IOC; // if true - add point, else remove
279 // myPoints->length( IOC ); // this length may be greater than number of objects,
280 // that will actually be put into myPoints
282 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
283 SalomeApp_Application* app =
284 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
285 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
286 _PTR(Study) aDStudy = appStudy->studyDS();
287 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
291 TColStd_IndexedMapOfInteger aMapIndexes;
292 GEOM::GEOM_Object_var anObject;
293 std::list<GEOM::GEOM_Object_var> aList;
294 SALOME_ListIO selected;
295 aSelMgr->selectedObjects( selected, QString::null, false );
297 for (SALOME_ListIteratorOfListIO anIt (selected); anIt.More(); anIt.Next())
299 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value(), aRes );
301 if (!CORBA::is_nil(aSelectedObject) && aRes)
303 if (GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull())
305 aSelMgr->GetIndexes( anIt.Value(), aMapIndexes );
307 if (aMapIndexes.Extent() > 0)
309 for (int ii=1; ii <= aMapIndexes.Extent(); ii++) {
310 anIndex = aMapIndexes(ii);
311 QString aName = GEOMBase::GetName( aSelectedObject );
312 aName = aName + ":vertex_" + QString::number( anIndex );
313 anObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
314 //Find Object in study
315 _PTR(SObject) obj ( aDStudy->FindObjectID( anIt.Value()->getEntry() ) );
316 bool inStudy = false;
317 _PTR(ChildIterator) iit (aDStudy->NewChildIterator(obj));
318 for (; iit->More() && !inStudy; iit->Next()) {
319 _PTR(SObject) child (iit->Value());
320 QString aChildName = child->GetName();
321 if (aChildName == aName) {
323 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
324 anObject = GEOM::GEOM_Object::_narrow( corbaObj );
329 GeometryGUI::GetGeomGen()->AddInStudy(GeometryGUI::ClientStudyToStudy(aDStudy),
330 anObject, aName, aSelectedObject);
332 int pos = isPointInList(myOrderedSel, anObject);
334 myOrderedSel.push_back(anObject);
337 aList.push_back(anObject);
339 } else { // aMap.Extent() == 0
340 int pos = isPointInList(myOrderedSel,aSelectedObject);
342 myOrderedSel.push_back(aSelectedObject);
343 aList.push_back(aSelectedObject);
349 myPoints->length( aList.size() );
352 for (list<GEOM::GEOM_Object_var>::iterator j=aList.begin();j!=aList.end();j++)
356 myOrderedSel.clear();
358 removeUnnecessaryPnt(myOrderedSel, myPoints);
360 // if ( myOrderedSel.size() == myPoints->length() ) {
361 myPoints->length( myOrderedSel.size() );
363 for (list<GEOM::GEOM_Object_var>::iterator j=myOrderedSel.begin();j!=myOrderedSel.end();j++)
367 if ( myPoints->length() > 0 )
368 GroupPoints->LineEdit1->setText( QString::number( myPoints->length() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
374 //=================================================================================
375 // function : ActivateThisDialog()
377 //=================================================================================
378 void BasicGUI_CurveDlg::ActivateThisDialog()
380 GEOMBase_Skeleton::ActivateThisDialog();
381 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
382 this, SLOT(SelectionIntoArgument()));
384 globalSelection(); // close local contexts, if any
385 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
386 ConstructorsClicked( getConstructorId() );
389 //=================================================================================
390 // function : DeactivateActiveDialog()
391 // purpose : public slot to deactivate if active
392 //=================================================================================
393 void BasicGUI_CurveDlg::DeactivateActiveDialog()
395 // myGeomGUI->SetState( -1 );
396 GEOMBase_Skeleton::DeactivateActiveDialog();
399 //=================================================================================
400 // function : enterEvent()
402 //=================================================================================
403 void BasicGUI_CurveDlg::enterEvent(QEvent* e)
405 if ( !GroupConstructors->isEnabled() )
406 ActivateThisDialog();
409 //=================================================================================
410 // function : createOperation
412 //=================================================================================
413 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
415 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
418 //=================================================================================
419 // function : isValid
421 //=================================================================================
422 bool BasicGUI_CurveDlg::isValid( QString& msg )
424 return myPoints->length() > 1;
427 //=================================================================================
428 // function : execute
430 //=================================================================================
431 bool BasicGUI_CurveDlg::execute( ObjectList& objects )
435 GEOM::GEOM_Object_var anObj;
437 switch ( getConstructorId() )
440 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakePolyline( myPoints );
444 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineBezier( myPoints );
448 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineInterpolation( myPoints );
453 if ( !anObj->_is_nil() )
454 objects.push_back( anObj._retn() );
459 //=================================================================================
460 // function : closeEvent
462 //=================================================================================
463 void BasicGUI_CurveDlg::closeEvent( QCloseEvent* e )
465 GEOMBase_Skeleton::closeEvent( e );