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 "GeometryGUI.h"
33 #include "SUIT_ResourceMgr.h"
34 #include "SUIT_Session.h"
35 #include "SalomeApp_Application.h"
36 #include "LightApp_SelectionMgr.h"
38 #include "SALOME_ListIteratorOfListIO.hxx"
39 #include "SALOME_ListIO.hxx"
41 #include "GEOMImpl_Types.hxx"
46 //=================================================================================
47 // class : BasicGUI_CurveDlg()
48 // purpose : Constructs a BasicGUI_CurveDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 BasicGUI_CurveDlg::BasicGUI_CurveDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
54 const char* name, bool modal, Qt::WindowFlags fl)
55 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
57 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_POLYLINE")));
58 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SPLINE")));
59 QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_BEZIER")));
61 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
63 setWindowTitle(tr("GEOM_CURVE_TITLE"));
65 /***************************************************************/
66 RadioButton1->setIcon( image0 );
67 RadioButton2->setIcon( image3 );
68 RadioButton3->setIcon( image2 );
70 GroupPoints = new Ui::DlgRef_1Sel_QTD();
71 QWidget* aGroupPointsWidget = new QWidget(this);
72 GroupPoints->setupUi(aGroupPointsWidget);
73 aGroupPointsWidget->setObjectName("GroupPoints");
75 GroupPoints->GroupBox1->setTitle( tr( "GEOM_NODES" ) );
76 GroupPoints->TextLabel1->setText( tr("GEOM_POINTS") );
77 GroupPoints->PushButton1->setIcon(image1);
79 GroupPoints->LineEdit1->setReadOnly( true );
81 gridLayout1->addWidget(aGroupPointsWidget, 2, 0);
82 /***************************************************************/
84 setHelpFileName("curve.htm");
90 //=================================================================================
91 // function : ~BasicGUI_CurveDlg()
92 // purpose : Destroys the object and frees any allocated resources
93 //=================================================================================
94 BasicGUI_CurveDlg::~BasicGUI_CurveDlg()
99 //=================================================================================
102 //=================================================================================
103 void BasicGUI_CurveDlg::Init()
106 myEditCurrentArgument = GroupPoints->LineEdit1;
108 myPoints = new GEOM::ListOfGO();
109 myPoints->length( 0 );
111 globalSelection( GEOM_POINT );
113 /* signals and slots connections */
114 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
115 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
116 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
118 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
119 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
120 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
122 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
125 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
126 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
128 initName( tr( "GEOM_CURVE" ).toStdString().c_str() );
129 ConstructorsClicked( 0 );
132 //=================================================================================
133 // function : ConstructorsClicked()
135 //=================================================================================
136 void BasicGUI_CurveDlg::ConstructorsClicked( int id )
138 QString aTitle = tr( id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL" );
139 GroupConstructors->setTitle( aTitle );
141 myPoints = new GEOM::ListOfGO();
142 myPoints->length( 0 );
144 myEditCurrentArgument->setText("");
148 //=================================================================================
149 // function : SetEditCurrentArgument()
151 //=================================================================================
152 void BasicGUI_CurveDlg::SetEditCurrentArgument()
154 if ( sender() == GroupPoints->PushButton1 )
155 myEditCurrentArgument = GroupPoints->LineEdit1;
156 myEditCurrentArgument->setFocus();
157 SelectionIntoArgument();
161 //=================================================================================
162 // function : LineEditReturnPressed()
164 //=================================================================================
165 void BasicGUI_CurveDlg::LineEditReturnPressed()
167 if ( sender() == GroupPoints->LineEdit1 )
169 myEditCurrentArgument = GroupPoints->LineEdit1;
170 GEOMBase_Skeleton::LineEditReturnPressed();
174 //=================================================================================
175 // function : ClickOnOk()
177 //=================================================================================
178 void BasicGUI_CurveDlg::ClickOnOk()
180 if ( ClickOnApply() )
184 //=================================================================================
185 // function : ClickOnApply()
187 //=================================================================================
188 bool BasicGUI_CurveDlg::ClickOnApply()
194 ConstructorsClicked( getConstructorId() );
198 //=======================================================================
199 // function : ClickOnCancel()
201 //=======================================================================
202 void BasicGUI_CurveDlg::ClickOnCancel()
204 GEOMBase_Skeleton::ClickOnCancel();
207 //=================================================================================
208 /*! function : isPointInList()
209 * purpose : Check is point (theObject) in the list \a thePoints.
211 * \retval -1, if point not in list, else 1 in list
213 //=================================================================================
214 static int isPointInList(list<GEOM::GEOM_Object_var>& thePoints,
215 GEOM::GEOM_Object_var& theObject)
217 int len = thePoints.size();
223 for(list<GEOM::GEOM_Object_var>::iterator i=thePoints.begin();i!=thePoints.end();i++)
224 if (string((*i)->GetEntry()) == string(theObject->GetEntry())){
230 //=================================================================================
231 /*! function : removeUnnecessaryPnt()
232 * purpose : Remove unnecessary points from list \a theOldPoints
234 * \li \a theOldPoints - ordered sequence with unnecessary point
235 * \li \a theNewPoints - not ordered sequence with necessary points
237 //=================================================================================
238 static void removeUnnecessaryPnt(list<GEOM::GEOM_Object_var>& theOldPoints,
239 GEOM::ListOfGO_var& theNewPoints)
241 list<GEOM::GEOM_Object_var> objs_to_remove;
242 for(list<GEOM::GEOM_Object_var>::iterator i=theOldPoints.begin();i!=theOldPoints.end();i++){
244 for (int j=0;j<theNewPoints->length() && !found ; j++){
245 if(string((*i)->GetEntry()) == string(theNewPoints[j]->GetEntry())){
250 objs_to_remove.push_back(*i);
251 //cout << "removed: " << (*i)->GetEntry() << endl;
254 for(list<GEOM::GEOM_Object_var>::iterator i=objs_to_remove.begin();i!=objs_to_remove.end();i++){
255 theOldPoints.remove(*i);
259 //=================================================================================
260 // function : SelectionIntoArgument()
261 // purpose : Called when selection as changed or other case
262 //=================================================================================
263 void BasicGUI_CurveDlg::SelectionIntoArgument()
265 myEditCurrentArgument->setText("");
267 Standard_Boolean aRes = Standard_False;
269 int IOC = IObjectCount();
270 bool is_append = myPoints->length() < IOC; // if true - add point, else remove
271 myPoints->length( IOC ); // this length may be greater than number of objects,
272 // that will actually be put into myPoints
273 for ( SALOME_ListIteratorOfListIO anIt( selectedIO() ); anIt.More(); anIt.Next() )
275 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value(), aRes );
276 if ( !CORBA::is_nil( aSelectedObject ) && aRes )
278 //TopoDS_Shape aPointShape;
279 //if ( myGeomBase->GetShape( aSelectedObject, aPointShape, TopAbs_VERTEX ) )
280 int pos = isPointInList(myOrderedSel,aSelectedObject);
281 if(is_append && pos==-1)
282 myOrderedSel.push_back(aSelectedObject);
283 myPoints[i++] = aSelectedObject;
287 myPoints->length( i ); // this is the right length, smaller of equal to the previously set
289 myOrderedSel.clear();
291 removeUnnecessaryPnt(myOrderedSel,myPoints);
293 if(myOrderedSel.size() == myPoints->length()){
295 for (list<GEOM::GEOM_Object_var>::iterator j=myOrderedSel.begin();j!=myOrderedSel.end();j++)
298 //cout << "ERROR: Ordered sequence size != selection sequence size! ("<<myOrderedSel.size()<<"!="<<myPoints->length()<<")"<<endl;
301 GroupPoints->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
307 //=================================================================================
308 // function : ActivateThisDialog()
310 //=================================================================================
311 void BasicGUI_CurveDlg::ActivateThisDialog()
313 GEOMBase_Skeleton::ActivateThisDialog();
314 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
315 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
317 // myGeomGUI->SetState( 0 );
319 globalSelection( GEOM_POINT );
320 ConstructorsClicked( getConstructorId() );
323 //=================================================================================
324 // function : DeactivateActiveDialog()
325 // purpose : public slot to deactivate if active
326 //=================================================================================
327 void BasicGUI_CurveDlg::DeactivateActiveDialog()
329 // myGeomGUI->SetState( -1 );
330 GEOMBase_Skeleton::DeactivateActiveDialog();
333 //=================================================================================
334 // function : enterEvent()
336 //=================================================================================
337 void BasicGUI_CurveDlg::enterEvent(QEvent* e)
339 if ( !GroupConstructors->isEnabled() )
340 ActivateThisDialog();
343 //=================================================================================
344 // function : createOperation
346 //=================================================================================
347 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
349 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
352 //=================================================================================
353 // function : isValid
355 //=================================================================================
356 bool BasicGUI_CurveDlg::isValid( QString& msg )
358 return myPoints->length() > 1;
361 //=================================================================================
362 // function : execute
364 //=================================================================================
365 bool BasicGUI_CurveDlg::execute( ObjectList& objects )
369 GEOM::GEOM_Object_var anObj;
371 switch ( getConstructorId() )
374 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakePolyline( myPoints );
378 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineBezier( myPoints );
382 anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeSplineInterpolation( myPoints );
387 if ( !anObj->_is_nil() )
388 objects.push_back( anObj._retn() );
393 //=================================================================================
394 // function : closeEvent
396 //=================================================================================
397 void BasicGUI_CurveDlg::closeEvent( QCloseEvent* e )
399 GEOMBase_Skeleton::closeEvent( e );