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"
31 #include "SALOMEGUI_QtCatchCorbaException.hxx"
32 #include "utilities.h"
33 #include "QAD_Desktop.h"
35 #include <BRep_Tool.hxx>
36 #include <TopoDS_Vertex.hxx>
40 //=================================================================================
41 // class : MeasureGUI_CenterMassDlg()
42 // purpose : Constructs a MeasureGUI_CenterMassDlg which is a child of 'parent', with the
43 // name 'name' and widget flags set to 'f'.
44 // The dialog will by default be modeless, unless you set 'modal' to
45 // TRUE to construct a modal dialog.
46 //=================================================================================
47 MeasureGUI_CenterMassDlg::MeasureGUI_CenterMassDlg( QWidget* parent, SALOME_Selection* Sel )
48 : GEOMBase_Skeleton( parent, "MeasureGUI_CenterMassDlg", Sel, false,
49 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
51 QPixmap image0( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr( "ICON_DLG_CENTERMASS" ) ) );
52 QPixmap image1( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr( "ICON_SELECT" ) ) );
54 setCaption( tr( "GEOM_CMASS_TITLE" ) );
56 /***************************************************************/
58 GroupConstructors->setTitle( tr( "GEOM_CMASS" ) );
59 RadioButton1->setPixmap( image0 );
60 RadioButton2->close( TRUE );
61 RadioButton3->close( TRUE );
63 myGrp = new MeasureGUI_1Sel3LineEdit_QTD( this, "myGrp" );
64 myGrp->GroupBox1->setTitle( tr( "GEOM_CENTER" ) );
65 myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
66 myGrp->TextLabel2->setText( tr( "GEOM_X" ) );
67 myGrp->TextLabel3->setText( tr( "GEOM_Y" ) );
68 myGrp->TextLabel4->setText( tr( "GEOM_Z" ) );
69 myGrp->LineEdit2->setReadOnly( TRUE );
70 myGrp->LineEdit3->setReadOnly( TRUE );
71 myGrp->LineEdit4->setReadOnly( TRUE );
72 myGrp->PushButton1->setPixmap( image1 );
73 myGrp->LineEdit1->setReadOnly( true );
75 Layout1->addWidget( myGrp, 2, 0 );
76 /***************************************************************/
83 //=================================================================================
84 // function : ~MeasureGUI_CenterMassDlg()
85 // purpose : Destroys the object and frees any allocated resources
86 //=================================================================================
87 MeasureGUI_CenterMassDlg::~MeasureGUI_CenterMassDlg()
92 //=================================================================================
95 //=================================================================================
96 void MeasureGUI_CenterMassDlg::Init( SALOME_Selection* Sel )
100 myEditCurrentArgument = myGrp->LineEdit1;
102 /* signals and slots connections */
103 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
104 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
106 connect( myGrp->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
107 connect( myGrp->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
109 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
111 initName( tr( "GEOM_POINT") );
113 SelectionIntoArgument();
115 /* displays Dialog */
121 //=================================================================================
122 // function : ClickOnOk()
124 //=================================================================================
125 void MeasureGUI_CenterMassDlg::ClickOnOk()
127 if ( ClickOnApply() )
132 //=================================================================================
133 // function : ClickOnApply()
135 //=================================================================================
136 bool MeasureGUI_CenterMassDlg::ClickOnApply()
144 // myMeasureGUI->MakeCDGAndDisplay( myGeomShape );
148 //=================================================================================
149 // function : SelectionIntoArgument()
150 // purpose : Called when selection as changed or other case
151 //=================================================================================
152 void MeasureGUI_CenterMassDlg::SelectionIntoArgument()
155 myObj = GEOM::GEOM_Object::_nil();
157 if ( mySelection->IObjectCount() != 1 )
163 Standard_Boolean testResult = Standard_False;
164 GEOM::GEOM_Object_var aSelectedObject =
165 GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), testResult );
167 if ( !testResult || aSelectedObject->_is_nil() )
173 myObj = aSelectedObject;
179 //=================================================================================
180 // function : SetEditCurrentArgument()
182 //=================================================================================
183 void MeasureGUI_CenterMassDlg::SetEditCurrentArgument()
185 myGrp->LineEdit1->setFocus();
186 myEditCurrentArgument = myGrp->LineEdit1;
187 SelectionIntoArgument();
191 //=================================================================================
192 // function : LineEditReturnPressed()
194 //=================================================================================
195 void MeasureGUI_CenterMassDlg::LineEditReturnPressed()
197 QLineEdit* send = ( QLineEdit* )sender();
198 if ( send == myGrp->LineEdit1 )
200 myEditCurrentArgument = myGrp->LineEdit1;
201 GEOMBase_Skeleton::LineEditReturnPressed();
206 //=================================================================================
207 // function : ActivateThisDialog()
209 //=================================================================================
210 void MeasureGUI_CenterMassDlg::ActivateThisDialog()
212 GEOMBase_Skeleton::ActivateThisDialog();
214 connect( mySelection, SIGNAL( currentSelectionChanged() ),
215 this, SLOT ( SelectionIntoArgument() ) );
221 //=================================================================================
222 // function : processObject()
223 // purpose : Fill dialog fields in accordance with myObj
224 //=================================================================================
225 void MeasureGUI_CenterMassDlg::processObject()
227 if ( myObj->_is_nil() )
229 myGrp->LineEdit1->setText( "" );
230 myGrp->LineEdit2->setText( "" );
231 myGrp->LineEdit3->setText( "" );
232 myGrp->LineEdit4->setText( "" );
237 double x = 0, y = 0, z = 0;
239 getParameters( x, y, z );
241 myGrp->LineEdit1->setText( GEOMBase::GetName( myObj ) );
242 myGrp->LineEdit2->setText( QString( "%1" ).arg( x ) );
243 myGrp->LineEdit3->setText( QString( "%1" ).arg( y ) );
244 myGrp->LineEdit4->setText( QString( "%1" ).arg( z ) );
251 //=================================================================================
252 // function : enterEvent()
254 //=================================================================================
255 void MeasureGUI_CenterMassDlg::enterEvent( QEvent* e )
257 if ( !GroupConstructors->isEnabled() )
258 ActivateThisDialog();
261 //=================================================================================
262 // function : createOperation
264 //=================================================================================
265 GEOM::GEOM_IOperations_ptr MeasureGUI_CenterMassDlg::createOperation()
267 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
270 //=================================================================================
271 // function : isValid
273 //=================================================================================
274 bool MeasureGUI_CenterMassDlg::isValid( QString& )
276 return !myObj->_is_nil();
279 //=================================================================================
280 // function : execute
282 //=================================================================================
283 bool MeasureGUI_CenterMassDlg::getParameters( double& theX, double& theY, double& theZ )
285 if ( myObj->_is_nil() )
291 GEOM::GEOM_Object_var anObj;
292 anObj = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetCentreOfMass( myObj );
293 if ( !getOperation()->IsDone() )
297 if ( !GEOMBase::GetShape( anObj, aShape ) ||
299 aShape.ShapeType() != TopAbs_VERTEX )
302 TopoDS_Vertex aVertex = TopoDS::Vertex( aShape );
304 gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
312 catch( const SALOME::SALOME_Exception& e )
314 QtCatchCorbaException( e );
320 //=================================================================================
321 // function : execute
323 //=================================================================================
324 bool MeasureGUI_CenterMassDlg::execute( ObjectList& objects )
326 GEOM::GEOM_Object_var anObj;
328 anObj = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetCentreOfMass( myObj );
330 if ( !anObj->_is_nil() )
331 objects.push_back( anObj._retn() );