1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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
24 // File : MeasureGUI_CenterMassDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "MeasureGUI_CenterMassDlg.h"
30 #include "MeasureGUI_1Sel3LineEdit_QTD.h"
32 #include "utilities.h"
33 #include "SUIT_Session.h"
34 #include "SalomeApp_Application.h"
35 #include "LightApp_SelectionMgr.h"
36 #include "SalomeApp_Tools.h"
38 #include <BRep_Tool.hxx>
39 #include <TopoDS_Vertex.hxx>
45 //=================================================================================
46 // class : MeasureGUI_CenterMassDlg()
47 // purpose : Constructs a MeasureGUI_CenterMassDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 MeasureGUI_CenterMassDlg::MeasureGUI_CenterMassDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
53 : GEOMBase_Skeleton(theGeometryGUI, parent, "MeasureGUI_CenterMassDlg", false,
54 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
56 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CENTERMASS")));
57 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
59 setCaption( tr( "GEOM_CMASS_TITLE" ) );
61 /***************************************************************/
62 GroupConstructors->setTitle( tr( "GEOM_CMASS" ) );
63 RadioButton1->setPixmap( image0 );
64 RadioButton2->close( TRUE );
65 RadioButton3->close( TRUE );
67 myGrp = new MeasureGUI_1Sel3LineEdit_QTD( this, "myGrp" );
68 myGrp->GroupBox1->setTitle( tr( "GEOM_CENTER" ) );
69 myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
70 myGrp->TextLabel2->setText( tr( "GEOM_X" ) );
71 myGrp->TextLabel3->setText( tr( "GEOM_Y" ) );
72 myGrp->TextLabel4->setText( tr( "GEOM_Z" ) );
73 myGrp->LineEdit2->setReadOnly( TRUE );
74 myGrp->LineEdit3->setReadOnly( TRUE );
75 myGrp->LineEdit4->setReadOnly( TRUE );
76 myGrp->PushButton1->setPixmap( image1 );
77 myGrp->LineEdit1->setReadOnly( true );
79 Layout1->addWidget( myGrp, 2, 0 );
80 /***************************************************************/
82 myHelpFileName = "files/salome2_sp3_measuregui_functions.htm#Center_gravity";
89 //=================================================================================
90 // function : ~MeasureGUI_CenterMassDlg()
91 // purpose : Destroys the object and frees any allocated resources
92 //=================================================================================
93 MeasureGUI_CenterMassDlg::~MeasureGUI_CenterMassDlg()
98 //=================================================================================
101 //=================================================================================
102 void MeasureGUI_CenterMassDlg::Init()
105 myEditCurrentArgument = myGrp->LineEdit1;
107 /* signals and slots connections */
108 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
109 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
111 connect( myGrp->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
112 connect( myGrp->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
114 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
115 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
117 initName( tr( "GEOM_POINT") );
119 SelectionIntoArgument();
121 /* displays Dialog */
127 //=================================================================================
128 // function : ClickOnOk()
130 //=================================================================================
131 void MeasureGUI_CenterMassDlg::ClickOnOk()
133 if ( ClickOnApply() )
138 //=================================================================================
139 // function : ClickOnApply()
141 //=================================================================================
142 bool MeasureGUI_CenterMassDlg::ClickOnApply()
150 // myMeasureGUI->MakeCDGAndDisplay( myGeomShape );
154 //=================================================================================
155 // function : SelectionIntoArgument()
156 // purpose : Called when selection as changed or other case
157 //=================================================================================
158 void MeasureGUI_CenterMassDlg::SelectionIntoArgument()
161 myObj = GEOM::GEOM_Object::_nil();
163 if ( IObjectCount() != 1 )
169 Standard_Boolean testResult = Standard_False;
170 GEOM::GEOM_Object_var aSelectedObject =
171 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
173 if ( !testResult || aSelectedObject->_is_nil() )
179 myObj = aSelectedObject;
185 //=================================================================================
186 // function : SetEditCurrentArgument()
188 //=================================================================================
189 void MeasureGUI_CenterMassDlg::SetEditCurrentArgument()
191 myGrp->LineEdit1->setFocus();
192 myEditCurrentArgument = myGrp->LineEdit1;
193 SelectionIntoArgument();
197 //=================================================================================
198 // function : LineEditReturnPressed()
200 //=================================================================================
201 void MeasureGUI_CenterMassDlg::LineEditReturnPressed()
203 QLineEdit* send = ( QLineEdit* )sender();
204 if ( send == myGrp->LineEdit1 )
206 myEditCurrentArgument = myGrp->LineEdit1;
207 GEOMBase_Skeleton::LineEditReturnPressed();
212 //=================================================================================
213 // function : ActivateThisDialog()
215 //=================================================================================
216 void MeasureGUI_CenterMassDlg::ActivateThisDialog()
218 GEOMBase_Skeleton::ActivateThisDialog();
220 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
221 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
227 //=================================================================================
228 // function : processObject()
229 // purpose : Fill dialog fields in accordance with myObj
230 //=================================================================================
231 void MeasureGUI_CenterMassDlg::processObject()
233 if ( myObj->_is_nil() )
235 myGrp->LineEdit1->setText( "" );
236 myGrp->LineEdit2->setText( "" );
237 myGrp->LineEdit3->setText( "" );
238 myGrp->LineEdit4->setText( "" );
243 double x = 0, y = 0, z = 0;
245 getParameters( x, y, z );
247 myGrp->LineEdit1->setText( GEOMBase::GetName( myObj ) );
248 myGrp->LineEdit2->setText( QString( "%1" ).arg( x ) );
249 myGrp->LineEdit3->setText( QString( "%1" ).arg( y ) );
250 myGrp->LineEdit4->setText( QString( "%1" ).arg( z ) );
257 //=================================================================================
258 // function : enterEvent()
260 //=================================================================================
261 void MeasureGUI_CenterMassDlg::enterEvent( QEvent* e )
263 if ( !GroupConstructors->isEnabled() )
264 ActivateThisDialog();
267 //=================================================================================
268 // function : createOperation
270 //=================================================================================
271 GEOM::GEOM_IOperations_ptr MeasureGUI_CenterMassDlg::createOperation()
273 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
276 //=================================================================================
277 // function : isValid
279 //=================================================================================
280 bool MeasureGUI_CenterMassDlg::isValid( QString& )
282 return !myObj->_is_nil();
285 //=================================================================================
286 // function : execute
288 //=================================================================================
289 bool MeasureGUI_CenterMassDlg::getParameters( double& theX, double& theY, double& theZ )
291 if ( myObj->_is_nil() )
297 GEOM::GEOM_Object_var anObj;
298 anObj = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetCentreOfMass( myObj );
299 if ( !getOperation()->IsDone() )
303 if ( !GEOMBase::GetShape( anObj, aShape ) ||
305 aShape.ShapeType() != TopAbs_VERTEX )
308 TopoDS_Vertex aVertex = TopoDS::Vertex( aShape );
310 gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
318 catch( const SALOME::SALOME_Exception& e )
320 SalomeApp_Tools::QtCatchCorbaException( e );
326 //=================================================================================
327 // function : execute
329 //=================================================================================
330 bool MeasureGUI_CenterMassDlg::execute( ObjectList& objects )
332 GEOM::GEOM_Object_var anObj;
334 anObj = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetCentreOfMass( myObj );
336 if ( !anObj->_is_nil() )
337 objects.push_back( anObj._retn() );