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
21 // File : BasicGUI_EllipseDlg.cxx
22 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
25 #include "BasicGUI_EllipseDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <TColStd_IndexedMapOfInteger.hxx>
38 #include <TopTools_IndexedMapOfShape.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Edge.hxx>
44 #include <GEOMImpl_Types.hxx>
46 //=================================================================================
47 // class : BasicGUI_EllipseDlg()
48 // purpose : Constructs a BasicGUI_EllipseDlg 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_EllipseDlg::BasicGUI_EllipseDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
54 bool modal, Qt::WindowFlags fl )
55 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
57 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_ELLIPSE_PV" ) ) );
58 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
60 setWindowTitle( tr( "GEOM_ELLIPSE_TITLE" ) );
62 /***************************************************************/
63 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_ELLIPSE" ) );
64 mainFrame()->RadioButton1->setIcon( image0 );
65 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
66 mainFrame()->RadioButton2->close();
67 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
68 mainFrame()->RadioButton3->close();
70 GroupPoints = new DlgRef_2Sel2Spin( centralWidget() );
71 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
72 GroupPoints->TextLabel1->setText( tr( "GEOM_CENTER" ) + " (Origin by default)" );
73 GroupPoints->TextLabel2->setText( tr( "GEOM_VECTOR" ) + " (Z axis by default)" );
74 GroupPoints->TextLabel3->setText( tr( "GEOM_RADIUS_MAJOR" ) );
75 GroupPoints->TextLabel4->setText( tr( "GEOM_RADIUS_MINOR" ) );
76 GroupPoints->PushButton1->setIcon( image1 );
77 GroupPoints->PushButton2->setIcon( image1 );
79 GroupPoints->LineEdit1->setReadOnly( true );
80 GroupPoints->LineEdit2->setReadOnly( true );
82 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
83 layout->setMargin( 0 ); layout->setSpacing( 6 );
84 layout->addWidget( GroupPoints );
85 /***************************************************************/
87 setHelpFileName( "create_ellipse_page.html" );
93 //=================================================================================
94 // function : ~BasicGUI_EllipseDlg()
95 // purpose : Destroys the object and frees any allocated resources
96 //=================================================================================
97 BasicGUI_EllipseDlg::~BasicGUI_EllipseDlg()
102 //=================================================================================
105 //=================================================================================
106 void BasicGUI_EllipseDlg::Init()
109 myEditCurrentArgument = GroupPoints->LineEdit1;
110 globalSelection(); // close local contexts, if any
111 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
113 myPoint = myDir = GEOM::GEOM_Object::_nil();
115 /* Get setting of step value from file configuration */
116 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
117 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
119 double aMajorR( 200. ), aMinorR( 100. );
121 /* min, max, step and decimals for spin boxes & initial values */
122 initSpinBox( GroupPoints->SpinBox_DX, 0.001, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
123 initSpinBox( GroupPoints->SpinBox_DY, 0.001, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
124 GroupPoints->SpinBox_DX->setValue( aMajorR );
125 GroupPoints->SpinBox_DY->setValue( aMinorR );
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( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
135 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
137 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
138 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
140 connect( GroupPoints->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
141 connect( GroupPoints->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
143 connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
145 connect( myGeomGUI->getApp()->selectionMgr(),
146 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
148 initName( tr( "GEOM_ELLIPSE" ) );
153 //=================================================================================
154 // function : SetDoubleSpinBoxStep()
155 // purpose : Double spin box management
156 //=================================================================================
157 void BasicGUI_EllipseDlg::SetDoubleSpinBoxStep( double step )
159 GroupPoints->SpinBox_DX->setSingleStep(step);
160 GroupPoints->SpinBox_DY->setSingleStep(step);
164 //=================================================================================
165 // function : ClickOnOk()
167 //=================================================================================
168 void BasicGUI_EllipseDlg::ClickOnOk()
170 if ( ClickOnApply() )
175 //=================================================================================
176 // function : ClickOnApply()
178 //=================================================================================
179 bool BasicGUI_EllipseDlg::ClickOnApply()
187 myPoint = myDir = GEOM::GEOM_Object::_nil();
188 GroupPoints->LineEdit1->setText( "" );
189 GroupPoints->LineEdit2->setText( "" );
190 myEditCurrentArgument = GroupPoints->LineEdit1;
191 //globalSelection(GEOM_POINT);
192 globalSelection(); // close local contexts, if any
193 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
199 //=================================================================================
200 // function : SelectionIntoArgument()
201 // purpose : Called when selection as changed or other case
202 //=================================================================================
203 void BasicGUI_EllipseDlg::SelectionIntoArgument()
205 myEditCurrentArgument->setText( "" );
207 if ( IObjectCount() != 1 ) {
208 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = GEOM::GEOM_Object::_nil();
209 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir = GEOM::GEOM_Object::_nil();
213 Standard_Boolean aRes = Standard_False;
214 Handle(SALOME_InteractiveObject) anIO = firstIObject();
215 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
216 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
217 QString aName = GEOMBase::GetName( aSelectedObject );
219 // Get Selected object if selected subshape
222 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
223 TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
224 if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
225 aNeedType = TopAbs_EDGE;
227 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
228 TColStd_IndexedMapOfInteger aMap;
229 aSelMgr->GetIndexes( anIO, aMap );
230 if ( aMap.Extent() == 1 ) {
231 int anIndex = aMap(1);
232 if ( aNeedType == TopAbs_EDGE )
233 aName += QString( ":edge_%1" ).arg( anIndex );
235 aName += QString( ":vertex_%1" ).arg( anIndex );
237 //Find SubShape Object in Father
238 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
240 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
241 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
242 aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
245 aSelectedObject = aFindedObject; // get Object from study
248 else { // Global Selection
249 if ( aShape.ShapeType() != aNeedType ) {
250 aSelectedObject = GEOM::GEOM_Object::_nil();
256 myEditCurrentArgument->setText( aName );
258 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint = aSelectedObject;
259 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myDir = aSelectedObject;
266 //=================================================================================
267 // function : SetEditCurrentArgument()
269 //=================================================================================
270 void BasicGUI_EllipseDlg::SetEditCurrentArgument()
272 QPushButton* send = (QPushButton*)sender();
273 globalSelection( GEOM_POINT );
275 if ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
276 else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
278 myEditCurrentArgument->setFocus();
279 globalSelection(); // close local contexts, if any
280 if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
281 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
283 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
284 SelectionIntoArgument();
287 //=================================================================================
288 // function : LineEditReturnPressed()
290 //=================================================================================
291 void BasicGUI_EllipseDlg::LineEditReturnPressed()
293 QLineEdit* send = (QLineEdit*)sender();
294 if ( send == GroupPoints->LineEdit1 ||
295 send == GroupPoints->LineEdit2 ) {
296 myEditCurrentArgument = send;
297 GEOMBase_Skeleton::LineEditReturnPressed();
302 //=================================================================================
303 // function : ActivateThisDialog()
305 //=================================================================================
306 void BasicGUI_EllipseDlg::ActivateThisDialog()
308 GEOMBase_Skeleton::ActivateThisDialog();
309 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
310 this, SLOT( SelectionIntoArgument() ) );
312 GroupPoints->LineEdit1->setFocus();
313 myEditCurrentArgument = GroupPoints->LineEdit1;
315 GroupPoints->LineEdit1->setText( "" );
316 GroupPoints->LineEdit2->setText( "" );
318 myPoint = myDir = GEOM::GEOM_Object::_nil();
319 //globalSelection( GEOM_POINT );
320 globalSelection(); // close local contexts, if any
321 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
324 //=================================================================================
325 // function : DeactivateActiveDialog()
326 // purpose : public slot to deactivate if active
327 //=================================================================================
328 void BasicGUI_EllipseDlg::DeactivateActiveDialog()
330 // myGeomGUI->SetState( -1 );
331 GEOMBase_Skeleton::DeactivateActiveDialog();
334 //=================================================================================
335 // function : enterEvent()
337 //=================================================================================
338 void BasicGUI_EllipseDlg::enterEvent( QEvent* )
340 if ( !mainFrame()->GroupConstructors->isEnabled() )
341 ActivateThisDialog();
344 //=================================================================================
345 // function : ValueChangedInSpinBox()
347 //=================================================================================
348 void BasicGUI_EllipseDlg::ValueChangedInSpinBox( double newValue )
353 //=================================================================================
354 // function : createOperation
356 //=================================================================================
357 GEOM::GEOM_IOperations_ptr BasicGUI_EllipseDlg::createOperation()
359 return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
362 //=================================================================================
363 // function : isValid
365 //=================================================================================
366 bool BasicGUI_EllipseDlg::isValid( QString& msg )
368 double aMajorR = GroupPoints->SpinBox_DX->value();
369 double aMinorR = GroupPoints->SpinBox_DY->value();
370 if ( aMajorR < aMinorR ) {
371 msg = tr( "GEOM_ELLIPSE_ERROR_1" );
374 //return !myPoint->_is_nil() && !myDir->_is_nil();
375 //nil point means origin of global CS
376 //nil vector means Z axis
380 //=================================================================================
381 // function : execute
383 //=================================================================================
384 bool BasicGUI_EllipseDlg::execute( ObjectList& objects )
386 double aMajorR = GroupPoints->SpinBox_DX->value();
387 double aMinorR = GroupPoints->SpinBox_DY->value();
388 GEOM::GEOM_Object_var anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeEllipse( myPoint, myDir, aMajorR, aMinorR );
390 if ( !anObj->_is_nil() )
391 objects.push_back( anObj._retn() );
396 //=================================================================================
397 // function : addSubshapeToStudy
398 // purpose : virtual method to add new SubObjects if local selection
399 //=================================================================================
400 void BasicGUI_EllipseDlg::addSubshapesToStudy()
402 QMap<QString, GEOM::GEOM_Object_var> objMap;
404 if (!CORBA::is_nil(myPoint))
405 objMap[GroupPoints->LineEdit1->text()] = myPoint;
406 if (!CORBA::is_nil(myDir))
407 objMap[GroupPoints->LineEdit2->text()] = myDir;
409 addSubshapesToFather( objMap );