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
22 // File : MeasureGUI_CenterMassDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "MeasureGUI_CenterMassDlg.h"
27 #include "MeasureGUI_Widgets.h"
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.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>
43 //=================================================================================
44 // class : MeasureGUI_CenterMassDlg()
45 // purpose : Constructs a MeasureGUI_CenterMassDlg which is a child of 'parent', with the
46 // name 'name' and widget flags set to 'f'.
47 // The dialog will by default be modeless, unless you set 'modal' to
48 // true to construct a modal dialog.
49 //=================================================================================
50 MeasureGUI_CenterMassDlg::MeasureGUI_CenterMassDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
51 : GEOMBase_Skeleton( theGeometryGUI, parent, false )
53 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CENTERMASS" ) ) );
54 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
56 setWindowTitle( tr( "GEOM_CMASS_TITLE" ) );
58 /***************************************************************/
59 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CMASS" ) );
60 mainFrame()->RadioButton1->setIcon( image0 );
61 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->RadioButton2->close();
63 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
64 mainFrame()->RadioButton3->close();
66 myGrp = new MeasureGUI_1Sel3LineEdit( centralWidget() );
67 myGrp->GroupBox1->setTitle( tr( "GEOM_CENTER" ) );
68 myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
69 myGrp->TextLabel2->setText( tr( "GEOM_X" ) );
70 myGrp->TextLabel3->setText( tr( "GEOM_Y" ) );
71 myGrp->TextLabel4->setText( tr( "GEOM_Z" ) );
72 myGrp->LineEdit2->setReadOnly( true );
73 myGrp->LineEdit3->setReadOnly( true );
74 myGrp->LineEdit4->setReadOnly( true );
75 myGrp->PushButton1->setIcon( image1 );
76 myGrp->LineEdit1->setReadOnly( true );
78 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
79 layout->setMargin( 0 ); layout->setSpacing( 6 );
80 layout->addWidget( myGrp );
82 /***************************************************************/
84 myHelpFileName = "files/salome2_sp3_measuregui_functions.htm#Center_gravity";
91 //=================================================================================
92 // function : ~MeasureGUI_CenterMassDlg()
93 // purpose : Destroys the object and frees any allocated resources
94 //=================================================================================
95 MeasureGUI_CenterMassDlg::~MeasureGUI_CenterMassDlg()
100 //=================================================================================
103 //=================================================================================
104 void MeasureGUI_CenterMassDlg::Init()
107 myEditCurrentArgument = myGrp->LineEdit1;
109 /* signals and slots connections */
110 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
111 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
113 connect( myGrp->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
114 connect( myGrp->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
116 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
117 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
119 initName( tr( "GEOM_POINT") );
121 SelectionIntoArgument();
125 //=================================================================================
126 // function : ClickOnOk()
128 //=================================================================================
129 void MeasureGUI_CenterMassDlg::ClickOnOk()
131 if ( ClickOnApply() )
136 //=================================================================================
137 // function : ClickOnApply()
139 //=================================================================================
140 bool MeasureGUI_CenterMassDlg::ClickOnApply()
148 // myMeasureGUI->MakeCDGAndDisplay( myGeomShape );
152 //=================================================================================
153 // function : SelectionIntoArgument()
154 // purpose : Called when selection as changed or other case
155 //=================================================================================
156 void MeasureGUI_CenterMassDlg::SelectionIntoArgument()
159 myObj = GEOM::GEOM_Object::_nil();
161 if ( IObjectCount() != 1 ) {
166 Standard_Boolean testResult = Standard_False;
167 GEOM::GEOM_Object_var aSelectedObject =
168 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
170 if ( !testResult || aSelectedObject->_is_nil() ) {
175 myObj = aSelectedObject;
181 //=================================================================================
182 // function : SetEditCurrentArgument()
184 //=================================================================================
185 void MeasureGUI_CenterMassDlg::SetEditCurrentArgument()
187 myGrp->LineEdit1->setFocus();
188 myEditCurrentArgument = myGrp->LineEdit1;
189 SelectionIntoArgument();
193 //=================================================================================
194 // function : LineEditReturnPressed()
196 //=================================================================================
197 void MeasureGUI_CenterMassDlg::LineEditReturnPressed()
199 QLineEdit* send = ( QLineEdit* )sender();
200 if ( send == myGrp->LineEdit1 ) {
201 myEditCurrentArgument = myGrp->LineEdit1;
202 GEOMBase_Skeleton::LineEditReturnPressed();
207 //=================================================================================
208 // function : ActivateThisDialog()
210 //=================================================================================
211 void MeasureGUI_CenterMassDlg::ActivateThisDialog()
213 GEOMBase_Skeleton::ActivateThisDialog();
215 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
216 SIGNAL(currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
222 //=================================================================================
223 // function : processObject()
224 // purpose : Fill dialog fields in accordance with myObj
225 //=================================================================================
226 void MeasureGUI_CenterMassDlg::processObject()
228 if ( myObj->_is_nil() ) {
229 myGrp->LineEdit1->setText( "" );
230 myGrp->LineEdit2->setText( "" );
231 myGrp->LineEdit3->setText( "" );
232 myGrp->LineEdit4->setText( "" );
236 double x = 0, y = 0, z = 0;
238 getParameters( x, y, z );
240 myGrp->LineEdit1->setText( GEOMBase::GetName( myObj ) );
241 myGrp->LineEdit2->setText( QString( "%1" ).arg( x ) );
242 myGrp->LineEdit3->setText( QString( "%1" ).arg( y ) );
243 myGrp->LineEdit4->setText( QString( "%1" ).arg( z ) );
250 //=================================================================================
251 // function : enterEvent()
253 //=================================================================================
254 void MeasureGUI_CenterMassDlg::enterEvent( QEvent* )
256 if ( !mainFrame()->GroupConstructors->isEnabled() )
257 ActivateThisDialog();
260 //=================================================================================
261 // function : createOperation
263 //=================================================================================
264 GEOM::GEOM_IOperations_ptr MeasureGUI_CenterMassDlg::createOperation()
266 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
269 //=================================================================================
270 // function : isValid
272 //=================================================================================
273 bool MeasureGUI_CenterMassDlg::isValid( QString& )
275 return !myObj->_is_nil();
278 //=================================================================================
279 // function : execute
281 //=================================================================================
282 bool MeasureGUI_CenterMassDlg::getParameters( double& theX, double& theY, double& theZ )
284 if ( myObj->_is_nil() )
288 GEOM::GEOM_Object_var anObj;
289 anObj = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetCentreOfMass( myObj );
290 if ( !getOperation()->IsDone() )
294 if ( !GEOMBase::GetShape( anObj, aShape ) ||
296 aShape.ShapeType() != TopAbs_VERTEX )
299 TopoDS_Vertex aVertex = TopoDS::Vertex( aShape );
301 gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
309 catch( const SALOME::SALOME_Exception& e ) {
310 SalomeApp_Tools::QtCatchCorbaException( e );
316 //=================================================================================
317 // function : execute
319 //=================================================================================
320 bool MeasureGUI_CenterMassDlg::execute( ObjectList& objects )
322 GEOM::GEOM_Object_var anObj;
324 anObj = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetCentreOfMass( myObj );
326 if ( !anObj->_is_nil() )
327 objects.push_back( anObj._retn() );