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 setIsApplyAndClose( true );
212 if ( ClickOnApply() )
216 //=================================================================================
217 // function : ClickOnApply()
219 //=================================================================================
220 bool BasicGUI_CurveDlg::ClickOnApply()
226 globalSelection(); // close local contexts, if any
227 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
231 static void synchronize( QList<GEOM::GeomObjPtr>& left, QList<GEOM::GeomObjPtr>& right )
233 // 1. remove items from the "left" list that are not in the "right" list
234 QMutableListIterator<GEOM::GeomObjPtr> it1( left );
235 while ( it1.hasNext() ) {
236 GEOM::GeomObjPtr o1 = it1.next();
238 QMutableListIterator<GEOM::GeomObjPtr> it2( right );
239 while ( it2.hasNext() && !found )
240 found = o1 == it2.next();
244 // 2. add items from the "right" list that are not in the "left" list (to keep selection order)
246 while ( it1.hasNext() ) {
247 GEOM::GeomObjPtr o1 = it1.next();
249 QMutableListIterator<GEOM::GeomObjPtr> it2( left );
250 while ( it2.hasNext() && !found )
251 found = o1 == it2.next();
257 //=================================================================================
258 // function : SelectionIntoArgument()
259 // purpose : Called when selection as changed or other case
260 //=================================================================================
261 void BasicGUI_CurveDlg::SelectionIntoArgument()
263 QList<GEOM::GeomObjPtr> points = getSelected( TopAbs_VERTEX, -1 );
264 synchronize( myPoints, points );
265 if ( !myPoints.isEmpty() )
266 GroupPoints->LineEdit1->setText( QString::number( myPoints.count() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
268 GroupPoints->LineEdit1->setText( "" );
273 //=================================================================================
274 // function : ActivateThisDialog()
276 //=================================================================================
277 void BasicGUI_CurveDlg::ActivateThisDialog()
279 GEOMBase_Skeleton::ActivateThisDialog();
280 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
281 this, SLOT( SelectionIntoArgument() ) );
283 globalSelection(); // close local contexts, if any
284 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
286 ConstructorsClicked( getConstructorId() );
289 //=================================================================================
290 // function : DeactivateActiveDialog()
291 // purpose : public slot to deactivate if active
292 //=================================================================================
293 void BasicGUI_CurveDlg::DeactivateActiveDialog()
295 // myGeomGUI->SetState( -1 );
296 GEOMBase_Skeleton::DeactivateActiveDialog();
299 //=================================================================================
300 // function : enterEvent()
302 //=================================================================================
303 void BasicGUI_CurveDlg::enterEvent( QEvent* )
305 if ( !mainFrame()->GroupConstructors->isEnabled() )
306 ActivateThisDialog();
309 //=================================================================================
310 // function : createOperation
312 //=================================================================================
313 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
315 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
318 //=================================================================================
319 // function : isValid
321 //=================================================================================
322 bool BasicGUI_CurveDlg::isValid( QString& msg )
324 return myPoints.count() > 1;
327 //=================================================================================
328 // function : execute
330 //=================================================================================
331 bool BasicGUI_CurveDlg::execute( ObjectList& objects )
335 GEOM::GEOM_Object_var anObj;
337 GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() );
339 GEOM::ListOfGO_var points = new GEOM::ListOfGO();
340 points->length( myPoints.count() );
341 for ( int i = 0; i < myPoints.count(); i++ )
342 points[i] = myPoints[i].copy();
344 switch ( getConstructorId() ) {
346 anObj = anOper->MakePolyline( points.in(), GroupPoints->CheckButton1->isChecked() );
350 anObj = anOper->MakeSplineBezier( points.in(), GroupPoints->CheckButton1->isChecked() );
354 anObj = anOper->MakeSplineInterpolation( points.in(), GroupPoints->CheckButton1->isChecked(),
355 GroupPoints->CheckButton2->isChecked() );
360 if ( !anObj->_is_nil() )
361 objects.push_back( anObj._retn() );
366 //=================================================================================
367 // function : addSubshapeToStudy
368 // purpose : virtual method to add new SubObjects if local selection
369 //=================================================================================
370 void BasicGUI_CurveDlg::addSubshapesToStudy()
372 for ( int i = 0; i < myPoints.count(); i++ )
373 GEOMBase::PublishSubObject( myPoints[i].get() );