1 // Copyright (C) 2007-2010 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : BasicGUI_CurveDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #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 <SalomeApp_Study.h>
37 #include <LightApp_SelectionMgr.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>
50 //=================================================================================
51 // class : BasicGUI_CurveDlg()
52 // purpose : Constructs a BasicGUI_CurveDlg which is a child of 'parent', with the
53 // name 'name' and widget flags set to 'f'.
54 // The dialog will by default be modeless, unless you set 'modal' to
55 // TRUE to construct a modal dialog.
56 //=================================================================================
57 BasicGUI_CurveDlg::BasicGUI_CurveDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
58 bool modal, Qt::WindowFlags fl )
59 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
61 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POLYLINE" ) ) );
62 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SPLINE" ) ) );
63 QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BEZIER" ) ) );
64 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
66 setWindowTitle( tr( "GEOM_CURVE_TITLE" ) );
68 /***************************************************************/
69 mainFrame()->RadioButton1->setIcon( image0 );
70 mainFrame()->RadioButton2->setIcon( image3 );
71 mainFrame()->RadioButton3->setIcon( image2 );
73 GroupPoints = new DlgRef_1Sel1Check( centralWidget() );
75 GroupPoints->GroupBox1->setTitle( tr( "GEOM_NODES" ) );
76 GroupPoints->TextLabel1->setText( tr( "GEOM_POINTS" ) );
77 GroupPoints->PushButton1->setIcon( image1 );
78 GroupPoints->PushButton1->setDown( true );
80 GroupPoints->LineEdit1->setReadOnly( true );
82 GroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
83 GroupPoints->CheckButton1->setChecked(false);
84 GroupPoints->CheckButton1->hide();
86 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
87 layout->setMargin( 0 ); layout->setSpacing( 6 );
88 layout->addWidget( GroupPoints );
89 /***************************************************************/
91 setHelpFileName( "create_curve_page.html" );
97 //=================================================================================
98 // function : ~BasicGUI_CurveDlg()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 BasicGUI_CurveDlg::~BasicGUI_CurveDlg()
106 //=================================================================================
109 //=================================================================================
110 void BasicGUI_CurveDlg::Init()
113 myEditCurrentArgument = GroupPoints->LineEdit1;
117 globalSelection(); // close local contexts, if any
118 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
120 /* signals and slots connections */
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() ) );
127 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
129 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
131 connect( GroupPoints->CheckButton1,SIGNAL( toggled(bool) ), this, SLOT( CheckButtonToggled() ) );
133 connect( myGeomGUI->getApp()->selectionMgr(),
134 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
136 initName( tr( "GEOM_CURVE" ) );
138 ConstructorsClicked( 0 );
141 //=================================================================================
142 // function : ConstructorsClicked()
144 //=================================================================================
145 void BasicGUI_CurveDlg::ConstructorsClicked( int id )
147 QString aTitle = tr( id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL" );
148 mainFrame()->GroupConstructors->setTitle( aTitle );
150 if (id == 2) // b-spline
151 GroupPoints->CheckButton1->show();
153 GroupPoints->CheckButton1->hide();
157 myEditCurrentArgument->setText( "" );
158 qApp->processEvents();
160 resize( minimumSizeHint() );
161 SelectionIntoArgument();
165 //=================================================================================
166 // function : SetEditCurrentArgument()
168 //=================================================================================
169 void BasicGUI_CurveDlg::SetEditCurrentArgument()
171 if ( sender() == GroupPoints->PushButton1 )
172 myEditCurrentArgument = GroupPoints->LineEdit1;
173 myEditCurrentArgument->setFocus();
174 SelectionIntoArgument();
177 //=================================================================================
178 // function : CheckButtonToggled()
180 //=================================================================================
181 void BasicGUI_CurveDlg::CheckButtonToggled()
186 //=================================================================================
187 // function : ClickOnOk()
189 //=================================================================================
190 void BasicGUI_CurveDlg::ClickOnOk()
192 if ( ClickOnApply() )
196 //=================================================================================
197 // function : ClickOnApply()
199 //=================================================================================
200 bool BasicGUI_CurveDlg::ClickOnApply()
206 globalSelection(); // close local contexts, if any
207 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
211 static void synchronize( QList<GEOM::GeomObjPtr>& left, QList<GEOM::GeomObjPtr>& right )
213 // 1. remove items from the "left" list that are not in the "right" list
214 QMutableListIterator<GEOM::GeomObjPtr> it1( left );
215 while ( it1.hasNext() ) {
216 GEOM::GeomObjPtr o1 = it1.next();
218 QMutableListIterator<GEOM::GeomObjPtr> it2( right );
219 while ( it2.hasNext() && !found )
220 found = o1 == it2.next();
224 // 2. add items from the "right" list that are not in the "left" list (to keep selection order)
226 while ( it1.hasNext() ) {
227 GEOM::GeomObjPtr o1 = it1.next();
229 QMutableListIterator<GEOM::GeomObjPtr> it2( left );
230 while ( it2.hasNext() && !found )
231 found = o1 == it2.next();
237 //=================================================================================
238 // function : SelectionIntoArgument()
239 // purpose : Called when selection as changed or other case
240 //=================================================================================
241 void BasicGUI_CurveDlg::SelectionIntoArgument()
243 QList<GEOM::GeomObjPtr> points = getSelected( TopAbs_VERTEX, -1 );
244 synchronize( myPoints, points );
245 if ( !myPoints.isEmpty() )
246 GroupPoints->LineEdit1->setText( QString::number( myPoints.count() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
248 GroupPoints->LineEdit1->setText( "" );
253 //=================================================================================
254 // function : ActivateThisDialog()
256 //=================================================================================
257 void BasicGUI_CurveDlg::ActivateThisDialog()
259 GEOMBase_Skeleton::ActivateThisDialog();
260 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
261 this, SLOT( SelectionIntoArgument() ) );
263 globalSelection(); // close local contexts, if any
264 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
266 ConstructorsClicked( getConstructorId() );
269 //=================================================================================
270 // function : DeactivateActiveDialog()
271 // purpose : public slot to deactivate if active
272 //=================================================================================
273 void BasicGUI_CurveDlg::DeactivateActiveDialog()
275 // myGeomGUI->SetState( -1 );
276 GEOMBase_Skeleton::DeactivateActiveDialog();
279 //=================================================================================
280 // function : enterEvent()
282 //=================================================================================
283 void BasicGUI_CurveDlg::enterEvent( QEvent* )
285 if ( !mainFrame()->GroupConstructors->isEnabled() )
286 ActivateThisDialog();
289 //=================================================================================
290 // function : createOperation
292 //=================================================================================
293 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
295 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
298 //=================================================================================
299 // function : isValid
301 //=================================================================================
302 bool BasicGUI_CurveDlg::isValid( QString& msg )
304 return myPoints.count() > 1;
307 //=================================================================================
308 // function : execute
310 //=================================================================================
311 bool BasicGUI_CurveDlg::execute( ObjectList& objects )
315 GEOM::GEOM_Object_var anObj;
317 GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() );
319 GEOM::ListOfGO_var points = new GEOM::ListOfGO();
320 points->length( myPoints.count() );
321 for ( int i = 0; i < myPoints.count(); i++ )
322 points[i] = myPoints[i].copy();
324 switch ( getConstructorId() ) {
326 anObj = anOper->MakePolyline( points.in() );
330 anObj = anOper->MakeSplineBezier( points.in() );
334 anObj = anOper->MakeSplineInterpolation( points.in(), GroupPoints->CheckButton1->isChecked() );
339 if ( !anObj->_is_nil() )
340 objects.push_back( anObj._retn() );
345 //=================================================================================
346 // function : addSubshapeToStudy
347 // purpose : virtual method to add new SubObjects if local selection
348 //=================================================================================
349 void BasicGUI_CurveDlg::addSubshapesToStudy()
351 for ( int i = 0; i < myPoints.count(); i++ )
352 GEOMBase::PublishSubObject( myPoints[i].get() );