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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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( QWidget* parent )
53 : GEOMBase_Skeleton( 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 /***************************************************************/
63 GroupConstructors->setTitle( tr( "GEOM_CMASS" ) );
64 RadioButton1->setPixmap( image0 );
65 RadioButton2->close( TRUE );
66 RadioButton3->close( TRUE );
68 myGrp = new MeasureGUI_1Sel3LineEdit_QTD( this, "myGrp" );
69 myGrp->GroupBox1->setTitle( tr( "GEOM_CENTER" ) );
70 myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
71 myGrp->TextLabel2->setText( tr( "GEOM_X" ) );
72 myGrp->TextLabel3->setText( tr( "GEOM_Y" ) );
73 myGrp->TextLabel4->setText( tr( "GEOM_Z" ) );
74 myGrp->LineEdit2->setReadOnly( TRUE );
75 myGrp->LineEdit3->setReadOnly( TRUE );
76 myGrp->LineEdit4->setReadOnly( TRUE );
77 myGrp->PushButton1->setPixmap( image1 );
78 myGrp->LineEdit1->setReadOnly( true );
80 Layout1->addWidget( myGrp, 2, 0 );
81 /***************************************************************/
88 //=================================================================================
89 // function : ~MeasureGUI_CenterMassDlg()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 MeasureGUI_CenterMassDlg::~MeasureGUI_CenterMassDlg()
97 //=================================================================================
100 //=================================================================================
101 void MeasureGUI_CenterMassDlg::Init()
104 myEditCurrentArgument = myGrp->LineEdit1;
106 /* signals and slots connections */
107 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
108 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
110 connect( myGrp->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
111 connect( myGrp->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
113 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
114 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
116 initName( tr( "GEOM_POINT") );
118 SelectionIntoArgument();
120 /* displays Dialog */
126 //=================================================================================
127 // function : ClickOnOk()
129 //=================================================================================
130 void MeasureGUI_CenterMassDlg::ClickOnOk()
132 if ( ClickOnApply() )
137 //=================================================================================
138 // function : ClickOnApply()
140 //=================================================================================
141 bool MeasureGUI_CenterMassDlg::ClickOnApply()
149 // myMeasureGUI->MakeCDGAndDisplay( myGeomShape );
153 //=================================================================================
154 // function : SelectionIntoArgument()
155 // purpose : Called when selection as changed or other case
156 //=================================================================================
157 void MeasureGUI_CenterMassDlg::SelectionIntoArgument()
160 myObj = GEOM::GEOM_Object::_nil();
162 if ( IObjectCount() != 1 )
168 Standard_Boolean testResult = Standard_False;
169 GEOM::GEOM_Object_var aSelectedObject =
170 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
172 if ( !testResult || aSelectedObject->_is_nil() )
178 myObj = aSelectedObject;
184 //=================================================================================
185 // function : SetEditCurrentArgument()
187 //=================================================================================
188 void MeasureGUI_CenterMassDlg::SetEditCurrentArgument()
190 myGrp->LineEdit1->setFocus();
191 myEditCurrentArgument = myGrp->LineEdit1;
192 SelectionIntoArgument();
196 //=================================================================================
197 // function : LineEditReturnPressed()
199 //=================================================================================
200 void MeasureGUI_CenterMassDlg::LineEditReturnPressed()
202 QLineEdit* send = ( QLineEdit* )sender();
203 if ( send == myGrp->LineEdit1 )
205 myEditCurrentArgument = myGrp->LineEdit1;
206 GEOMBase_Skeleton::LineEditReturnPressed();
211 //=================================================================================
212 // function : ActivateThisDialog()
214 //=================================================================================
215 void MeasureGUI_CenterMassDlg::ActivateThisDialog()
217 GEOMBase_Skeleton::ActivateThisDialog();
219 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
220 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
226 //=================================================================================
227 // function : processObject()
228 // purpose : Fill dialog fields in accordance with myObj
229 //=================================================================================
230 void MeasureGUI_CenterMassDlg::processObject()
232 if ( myObj->_is_nil() )
234 myGrp->LineEdit1->setText( "" );
235 myGrp->LineEdit2->setText( "" );
236 myGrp->LineEdit3->setText( "" );
237 myGrp->LineEdit4->setText( "" );
242 double x = 0, y = 0, z = 0;
244 getParameters( x, y, z );
246 myGrp->LineEdit1->setText( GEOMBase::GetName( myObj ) );
247 myGrp->LineEdit2->setText( QString( "%1" ).arg( x ) );
248 myGrp->LineEdit3->setText( QString( "%1" ).arg( y ) );
249 myGrp->LineEdit4->setText( QString( "%1" ).arg( z ) );
256 //=================================================================================
257 // function : enterEvent()
259 //=================================================================================
260 void MeasureGUI_CenterMassDlg::enterEvent( QEvent* e )
262 if ( !GroupConstructors->isEnabled() )
263 ActivateThisDialog();
266 //=================================================================================
267 // function : createOperation
269 //=================================================================================
270 GEOM::GEOM_IOperations_ptr MeasureGUI_CenterMassDlg::createOperation()
272 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
275 //=================================================================================
276 // function : isValid
278 //=================================================================================
279 bool MeasureGUI_CenterMassDlg::isValid( QString& )
281 return !myObj->_is_nil();
284 //=================================================================================
285 // function : execute
287 //=================================================================================
288 bool MeasureGUI_CenterMassDlg::getParameters( double& theX, double& theY, double& theZ )
290 if ( myObj->_is_nil() )
296 GEOM::GEOM_Object_var anObj;
297 anObj = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetCentreOfMass( myObj );
298 if ( !getOperation()->IsDone() )
302 if ( !GEOMBase::GetShape( anObj, aShape ) ||
304 aShape.ShapeType() != TopAbs_VERTEX )
307 TopoDS_Vertex aVertex = TopoDS::Vertex( aShape );
309 gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
317 catch( const SALOME::SALOME_Exception& e )
319 SalomeApp_Tools::QtCatchCorbaException( e );
325 //=================================================================================
326 // function : execute
328 //=================================================================================
329 bool MeasureGUI_CenterMassDlg::execute( ObjectList& objects )
331 GEOM::GEOM_Object_var anObj;
333 anObj = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetCentreOfMass( myObj );
335 if ( !anObj->_is_nil() )
336 objects.push_back( anObj._retn() );