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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : BasicGUI_CurveDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "BasicGUI_CurveDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <SalomeApp_Study.h>
36 #include <LightApp_SelectionMgr.h>
38 #include <SALOME_ListIteratorOfListIO.hxx>
39 #include <SALOME_ListIO.hxx>
41 #include <TopoDS_Shape.hxx>
44 #include <TColStd_IndexedMapOfInteger.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
47 #include <GEOMImpl_Types.hxx>
49 //=================================================================================
50 // class : BasicGUI_CurveDlg()
51 // purpose : Constructs a BasicGUI_CurveDlg which is a child of 'parent', with the
52 // name 'name' and widget flags set to 'f'.
53 // The dialog will by default be modeless, unless you set 'modal' to
54 // TRUE to construct a modal dialog.
55 //=================================================================================
56 BasicGUI_CurveDlg::BasicGUI_CurveDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
57 bool modal, Qt::WindowFlags fl )
58 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
60 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POLYLINE" ) ) );
61 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SPLINE" ) ) );
62 QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BEZIER" ) ) );
63 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
65 setWindowTitle( tr( "GEOM_CURVE_TITLE" ) );
67 /***************************************************************/
68 mainFrame()->RadioButton1->setIcon( image0 );
69 mainFrame()->RadioButton2->setIcon( image3 );
70 mainFrame()->RadioButton3->setIcon( image2 );
72 GroupPoints = new DlgRef_1Sel3Check( centralWidget() );
74 GroupPoints->GroupBox1->setTitle( tr( "GEOM_NODES" ) );
75 GroupPoints->TextLabel1->setText( tr( "GEOM_POINTS" ) );
76 GroupPoints->PushButton1->setIcon( image1 );
77 GroupPoints->PushButton1->setDown( true );
79 GroupPoints->LineEdit1->setReadOnly( true );
81 GroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
82 GroupPoints->CheckButton1->setChecked(false);
83 //GroupPoints->CheckButton1->hide();
85 GroupPoints->CheckButton2->setText( tr( "GEOM_IS_REORDER" ) );
86 GroupPoints->CheckButton2->setChecked(false);
87 GroupPoints->CheckButton2->hide();
89 GroupPoints->CheckButton3->hide();
91 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
92 layout->setMargin( 0 ); layout->setSpacing( 6 );
93 layout->addWidget( GroupPoints );
94 /***************************************************************/
96 setHelpFileName( "create_curve_page.html" );
102 //=================================================================================
103 // function : ~BasicGUI_CurveDlg()
104 // purpose : Destroys the object and frees any allocated resources
105 //=================================================================================
106 BasicGUI_CurveDlg::~BasicGUI_CurveDlg()
111 //=================================================================================
114 //=================================================================================
115 void BasicGUI_CurveDlg::Init()
118 myEditCurrentArgument = GroupPoints->LineEdit1;
122 globalSelection(); // close local contexts, if any
123 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
125 showOnlyPreviewControl();
127 /* signals and slots connections */
128 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog( ) ) );
129 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) );
131 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
132 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
134 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
136 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
138 connect( GroupPoints->CheckButton1, SIGNAL( toggled(bool) ), this, SLOT( CheckButtonToggled() ) );
139 connect( GroupPoints->CheckButton2, SIGNAL( toggled(bool) ), this, SLOT( CheckButtonToggled() ) );
141 connect( myGeomGUI->getApp()->selectionMgr(),
142 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
144 initName( tr( "GEOM_CURVE" ) );
146 ConstructorsClicked( 0 );
149 //=================================================================================
150 // function : ConstructorsClicked()
152 //=================================================================================
153 void BasicGUI_CurveDlg::ConstructorsClicked( int id )
155 QString aTitle = tr( id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL" );
156 mainFrame()->GroupConstructors->setTitle( aTitle );
158 if (id == 0) { // polyline (wire)
159 //GroupPoints->CheckButton1->hide();
160 GroupPoints->CheckButton1->setText( tr( "GEOM_BUILD_CLOSED_WIRE" ) );
161 GroupPoints->CheckButton2->hide();
163 else if (id == 1) { // bezier
164 //GroupPoints->CheckButton1->hide();
165 GroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
166 GroupPoints->CheckButton2->hide();
169 //GroupPoints->CheckButton1->show();
170 GroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
171 GroupPoints->CheckButton2->show();
176 myEditCurrentArgument->setText( "" );
177 qApp->processEvents();
179 resize( minimumSizeHint() );
180 SelectionIntoArgument();
184 //=================================================================================
185 // function : SetEditCurrentArgument()
187 //=================================================================================
188 void BasicGUI_CurveDlg::SetEditCurrentArgument()
190 if ( sender() == GroupPoints->PushButton1 )
191 myEditCurrentArgument = GroupPoints->LineEdit1;
192 myEditCurrentArgument->setFocus();
193 SelectionIntoArgument();
196 //=================================================================================
197 // function : CheckButtonToggled()
199 //=================================================================================
200 void BasicGUI_CurveDlg::CheckButtonToggled()
205 //=================================================================================
206 // function : ClickOnOk()
208 //=================================================================================
209 void BasicGUI_CurveDlg::ClickOnOk()
211 if ( ClickOnApply() )
215 //=================================================================================
216 // function : ClickOnApply()
218 //=================================================================================
219 bool BasicGUI_CurveDlg::ClickOnApply()
225 globalSelection(); // close local contexts, if any
226 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
230 static void synchronize( QList<GEOM::GeomObjPtr>& left, QList<GEOM::GeomObjPtr>& right )
232 // 1. remove items from the "left" list that are not in the "right" list
233 QMutableListIterator<GEOM::GeomObjPtr> it1( left );
234 while ( it1.hasNext() ) {
235 GEOM::GeomObjPtr o1 = it1.next();
237 QMutableListIterator<GEOM::GeomObjPtr> it2( right );
238 while ( it2.hasNext() && !found )
239 found = o1 == it2.next();
243 // 2. add items from the "right" list that are not in the "left" list (to keep selection order)
245 while ( it1.hasNext() ) {
246 GEOM::GeomObjPtr o1 = it1.next();
248 QMutableListIterator<GEOM::GeomObjPtr> it2( left );
249 while ( it2.hasNext() && !found )
250 found = o1 == it2.next();
256 //=================================================================================
257 // function : SelectionIntoArgument()
258 // purpose : Called when selection as changed or other case
259 //=================================================================================
260 void BasicGUI_CurveDlg::SelectionIntoArgument()
262 QList<GEOM::GeomObjPtr> points = getSelected( TopAbs_VERTEX, -1 );
263 synchronize( myPoints, points );
264 if ( !myPoints.isEmpty() )
265 GroupPoints->LineEdit1->setText( QString::number( myPoints.count() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
267 GroupPoints->LineEdit1->setText( "" );
272 //=================================================================================
273 // function : ActivateThisDialog()
275 //=================================================================================
276 void BasicGUI_CurveDlg::ActivateThisDialog()
278 GEOMBase_Skeleton::ActivateThisDialog();
279 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
280 this, SLOT( SelectionIntoArgument() ) );
282 globalSelection(); // close local contexts, if any
283 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
285 ConstructorsClicked( getConstructorId() );
288 //=================================================================================
289 // function : DeactivateActiveDialog()
290 // purpose : public slot to deactivate if active
291 //=================================================================================
292 void BasicGUI_CurveDlg::DeactivateActiveDialog()
294 // myGeomGUI->SetState( -1 );
295 GEOMBase_Skeleton::DeactivateActiveDialog();
298 //=================================================================================
299 // function : enterEvent()
301 //=================================================================================
302 void BasicGUI_CurveDlg::enterEvent( QEvent* )
304 if ( !mainFrame()->GroupConstructors->isEnabled() )
305 ActivateThisDialog();
308 //=================================================================================
309 // function : createOperation
311 //=================================================================================
312 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
314 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
317 //=================================================================================
318 // function : isValid
320 //=================================================================================
321 bool BasicGUI_CurveDlg::isValid( QString& msg )
323 return myPoints.count() > 1;
326 //=================================================================================
327 // function : execute
329 //=================================================================================
330 bool BasicGUI_CurveDlg::execute( ObjectList& objects )
334 GEOM::GEOM_Object_var anObj;
336 GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() );
338 GEOM::ListOfGO_var points = new GEOM::ListOfGO();
339 points->length( myPoints.count() );
340 for ( int i = 0; i < myPoints.count(); i++ )
341 points[i] = myPoints[i].copy();
343 switch ( getConstructorId() ) {
345 anObj = anOper->MakePolyline( points.in(), GroupPoints->CheckButton1->isChecked() );
349 anObj = anOper->MakeSplineBezier( points.in(), GroupPoints->CheckButton1->isChecked() );
353 anObj = anOper->MakeSplineInterpolation( points.in(), GroupPoints->CheckButton1->isChecked(),
354 GroupPoints->CheckButton2->isChecked() );
359 if ( !anObj->_is_nil() )
360 objects.push_back( anObj._retn() );
365 //=================================================================================
366 // function : addSubshapeToStudy
367 // purpose : virtual method to add new SubObjects if local selection
368 //=================================================================================
369 void BasicGUI_CurveDlg::addSubshapesToStudy()
371 for ( int i = 0; i < myPoints.count(); i++ )
372 GEOMBase::PublishSubObject( myPoints[i].get() );