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 "DlgRef_SpinBox.h"
34 #include "utilities.h"
35 #include "SUIT_Session.h"
36 #include "SalomeApp_Application.h"
37 #include "LightApp_SelectionMgr.h"
38 #include "SalomeApp_Tools.h"
40 #include <BRep_Tool.hxx>
41 #include <TopoDS_Vertex.hxx>
47 //=================================================================================
48 // class : MeasureGUI_CenterMassDlg()
49 // purpose : Constructs a MeasureGUI_CenterMassDlg which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 MeasureGUI_CenterMassDlg::MeasureGUI_CenterMassDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
55 : GEOMBase_Skeleton(theGeometryGUI, parent, "MeasureGUI_CenterMassDlg", false,
56 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
58 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CENTERMASS")));
59 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
61 setCaption( tr( "GEOM_CMASS_TITLE" ) );
63 /***************************************************************/
64 GroupConstructors->setTitle( tr( "GEOM_CMASS" ) );
65 RadioButton1->setPixmap( image0 );
66 RadioButton2->close( TRUE );
67 RadioButton3->close( TRUE );
69 myGrp = new MeasureGUI_1Sel3LineEdit_QTD( this, "myGrp" );
70 myGrp->GroupBox1->setTitle( tr( "GEOM_CENTER" ) );
71 myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
72 myGrp->TextLabel2->setText( tr( "GEOM_X" ) );
73 myGrp->TextLabel3->setText( tr( "GEOM_Y" ) );
74 myGrp->TextLabel4->setText( tr( "GEOM_Z" ) );
75 myGrp->LineEdit2->setReadOnly( TRUE );
76 myGrp->LineEdit3->setReadOnly( TRUE );
77 myGrp->LineEdit4->setReadOnly( TRUE );
78 myGrp->PushButton1->setPixmap( image1 );
79 myGrp->LineEdit1->setReadOnly( true );
81 Layout1->addWidget( myGrp, 2, 0 );
82 /***************************************************************/
84 myHelpFileName = "using_measurement_tools_page.html#center_mass_anchor";
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();
123 /* displays Dialog */
129 //=================================================================================
130 // function : ClickOnOk()
132 //=================================================================================
133 void MeasureGUI_CenterMassDlg::ClickOnOk()
135 if ( ClickOnApply() )
140 //=================================================================================
141 // function : ClickOnApply()
143 //=================================================================================
144 bool MeasureGUI_CenterMassDlg::ClickOnApply()
152 // myMeasureGUI->MakeCDGAndDisplay( myGeomShape );
156 //=================================================================================
157 // function : SelectionIntoArgument()
158 // purpose : Called when selection as changed or other case
159 //=================================================================================
160 void MeasureGUI_CenterMassDlg::SelectionIntoArgument()
163 myObj = GEOM::GEOM_Object::_nil();
165 if ( IObjectCount() != 1 )
171 Standard_Boolean testResult = Standard_False;
172 GEOM::GEOM_Object_var aSelectedObject =
173 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
175 if ( !testResult || aSelectedObject->_is_nil() )
181 myObj = aSelectedObject;
187 //=================================================================================
188 // function : SetEditCurrentArgument()
190 //=================================================================================
191 void MeasureGUI_CenterMassDlg::SetEditCurrentArgument()
193 myGrp->LineEdit1->setFocus();
194 myEditCurrentArgument = myGrp->LineEdit1;
195 SelectionIntoArgument();
199 //=================================================================================
200 // function : LineEditReturnPressed()
202 //=================================================================================
203 void MeasureGUI_CenterMassDlg::LineEditReturnPressed()
205 QLineEdit* send = ( QLineEdit* )sender();
206 if ( send == myGrp->LineEdit1 )
208 myEditCurrentArgument = myGrp->LineEdit1;
209 GEOMBase_Skeleton::LineEditReturnPressed();
214 //=================================================================================
215 // function : ActivateThisDialog()
217 //=================================================================================
218 void MeasureGUI_CenterMassDlg::ActivateThisDialog()
220 GEOMBase_Skeleton::ActivateThisDialog();
222 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
223 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
229 //=================================================================================
230 // function : processObject()
231 // purpose : Fill dialog fields in accordance with myObj
232 //=================================================================================
233 void MeasureGUI_CenterMassDlg::processObject()
235 if ( myObj->_is_nil() )
237 myGrp->LineEdit1->setText( "" );
238 myGrp->LineEdit2->setText( "" );
239 myGrp->LineEdit3->setText( "" );
240 myGrp->LineEdit4->setText( "" );
245 double x = 0, y = 0, z = 0;
247 getParameters( x, y, z );
249 myGrp->LineEdit1->setText( GEOMBase::GetName( myObj ) );
250 myGrp->LineEdit2->setText( DlgRef_SpinBox::PrintDoubleValue( x ) );
251 myGrp->LineEdit3->setText( DlgRef_SpinBox::PrintDoubleValue( y ) );
252 myGrp->LineEdit4->setText( DlgRef_SpinBox::PrintDoubleValue( z ) );
259 //=================================================================================
260 // function : enterEvent()
262 //=================================================================================
263 void MeasureGUI_CenterMassDlg::enterEvent( QEvent* e )
265 if ( !GroupConstructors->isEnabled() )
266 ActivateThisDialog();
269 //=================================================================================
270 // function : createOperation
272 //=================================================================================
273 GEOM::GEOM_IOperations_ptr MeasureGUI_CenterMassDlg::createOperation()
275 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
278 //=================================================================================
279 // function : isValid
281 //=================================================================================
282 bool MeasureGUI_CenterMassDlg::isValid( QString& )
284 return !myObj->_is_nil();
287 //=================================================================================
288 // function : execute
290 //=================================================================================
291 bool MeasureGUI_CenterMassDlg::getParameters( double& theX, double& theY, double& theZ )
293 if ( myObj->_is_nil() )
299 GEOM::GEOM_Object_var anObj;
300 anObj = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetCentreOfMass( myObj );
301 if ( !getOperation()->IsDone() )
305 if ( !GEOMBase::GetShape( anObj, aShape ) ||
307 aShape.ShapeType() != TopAbs_VERTEX )
310 TopoDS_Vertex aVertex = TopoDS::Vertex( aShape );
312 gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
320 catch( const SALOME::SALOME_Exception& e )
322 SalomeApp_Tools::QtCatchCorbaException( e );
328 //=================================================================================
329 // function : execute
331 //=================================================================================
332 bool MeasureGUI_CenterMassDlg::execute( ObjectList& objects )
334 GEOM::GEOM_Object_var anObj;
336 anObj = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetCentreOfMass( myObj );
338 if ( !anObj->_is_nil() )
339 objects.push_back( anObj._retn() );