Back to index

salome-geom  6.5.0
MeasureGUI_InertiaDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // GEOM GEOMGUI : GUI for Geometry component
00024 // File   : MeasureGUI_InertiaDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 //
00027 #include "MeasureGUI_InertiaDlg.h"
00028 #include "MeasureGUI_Widgets.h"
00029 
00030 #include <GEOMBase.h>
00031 #include <DlgRef.h>
00032 
00033 #include <gp_XYZ.hxx>
00034 
00035 #include <SUIT_ResourceMgr.h>
00036 #include <SUIT_Session.h>
00037 #include <SalomeApp_Tools.h>
00038 
00039 //=================================================================================
00040 // class    : MeasureGUI_InertiaDlg()
00041 // purpose  : Constructs a MeasureGUI_InertiaDlg which is a child of 'parent', with the
00042 //            name 'name' and widget flags set to 'f'.
00043 //            The dialog will by default be modeless, unless you set 'modal' to
00044 //            true to construct a modal dialog.
00045 //=================================================================================
00046 
00047 MeasureGUI_InertiaDlg::MeasureGUI_InertiaDlg( GeometryGUI* GUI, QWidget* parent )
00048   : MeasureGUI_Skeleton( GUI, parent )
00049 {
00050   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
00051     "GEOM",tr( "ICON_DLG_INERTIA" ) ) );
00052   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
00053     "GEOM",tr( "ICON_SELECT" ) ) );
00054 
00055   setWindowTitle( tr( "GEOM_INERTIA_TITLE" ) );
00056 
00057   /***************************************************************/
00058   
00059   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_INERTIA_CONSTR" ) );
00060   mainFrame()->RadioButton1->setIcon( image0 );
00061 
00062   myGrp = new MeasureGUI_1Sel12LineEdit( centralWidget() );
00063   myGrp->GroupBox1->setTitle( tr( "GEOM_MATRIX" ) );
00064   myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
00065   myGrp->TextLabel2->setText( tr( "GEOM_INERTIA_I" ).arg( "1" ) );
00066   myGrp->TextLabel3->setText( tr( "GEOM_INERTIA_I" ).arg( "2" ) );
00067   myGrp->TextLabel4->setText( tr( "GEOM_INERTIA_I" ).arg( "3" ) );
00068   myGrp->TextLabel5->setText( tr( "GEOM_INERTIA_IXYZ" ) );
00069   myGrp->LineEdit11->setReadOnly( true );
00070   myGrp->LineEdit12->setReadOnly( true );
00071   myGrp->LineEdit13->setReadOnly( true );
00072   myGrp->LineEdit21->setReadOnly( true );
00073   myGrp->LineEdit22->setReadOnly( true );
00074   myGrp->LineEdit23->setReadOnly( true );
00075   myGrp->LineEdit31->setReadOnly( true );
00076   myGrp->LineEdit32->setReadOnly( true );
00077   myGrp->LineEdit33->setReadOnly( true );
00078   myGrp->LineEdit41->setReadOnly( true );
00079   myGrp->LineEdit42->setReadOnly( true );
00080   myGrp->LineEdit43->setReadOnly( true );
00081   myGrp->PushButton1->setIcon( image1 );
00082   myGrp->LineEdit1->setReadOnly( true );
00083 
00084   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00085   layout->setMargin( 0 ); layout->setSpacing( 6 );
00086   layout->addWidget( myGrp );
00087   
00088   /***************************************************************/
00089 
00090   myHelpFileName = "using_measurement_tools_page.html#inertia_anchor";
00091 
00092   /* Initialisation */
00093   Init();
00094 }
00095 
00096 
00097 //=================================================================================
00098 // function : ~MeasureGUI_InertiaDlg()
00099 // purpose  : Destroys the object and frees any allocated resources
00100 //=================================================================================
00101 MeasureGUI_InertiaDlg::~MeasureGUI_InertiaDlg()
00102 {
00103 }
00104 
00105 
00106 //=================================================================================
00107 // function : Init()
00108 // purpose  :
00109 //=================================================================================
00110 void MeasureGUI_InertiaDlg::Init()
00111 {
00112   mySelBtn = myGrp->PushButton1;
00113   mySelEdit = myGrp->LineEdit1;
00114   MeasureGUI_Skeleton::Init();
00115 }
00116 
00117 //=================================================================================
00118 // function : processObject
00119 // purpose  :
00120 //=================================================================================
00121 void MeasureGUI_InertiaDlg::processObject()
00122 {
00123   gp_XYZ anIXYZ;
00124   gp_Mat aMat;
00125 
00126   if ( !getParameters( aMat, anIXYZ ) ) {
00127     mySelEdit->setText( "" );
00128     
00129     myGrp->LineEdit11->setText( "" );
00130     myGrp->LineEdit12->setText( "" );
00131     myGrp->LineEdit13->setText( "" );
00132     
00133     myGrp->LineEdit21->setText( "" );
00134     myGrp->LineEdit22->setText( "" );
00135     myGrp->LineEdit23->setText( "" );
00136     
00137     myGrp->LineEdit31->setText( "" );
00138     myGrp->LineEdit32->setText( "" );
00139     myGrp->LineEdit33->setText( "" );
00140 
00141     myGrp->LineEdit41->setText( "" );
00142     myGrp->LineEdit42->setText( "" );
00143     myGrp->LineEdit43->setText( "" );
00144   }
00145   else {
00146     myGrp->LineEdit11->setText( DlgRef::PrintDoubleValue( aMat( 1, 1 ), -6 ) );
00147     myGrp->LineEdit12->setText( DlgRef::PrintDoubleValue( aMat( 1, 2 ), -6 ) );
00148     myGrp->LineEdit13->setText( DlgRef::PrintDoubleValue( aMat( 1, 3 ), -6 ) );
00149     
00150     myGrp->LineEdit21->setText( DlgRef::PrintDoubleValue( aMat( 2, 1 ), -6 ) );
00151     myGrp->LineEdit22->setText( DlgRef::PrintDoubleValue( aMat( 2, 2 ), -6 ) );
00152     myGrp->LineEdit23->setText( DlgRef::PrintDoubleValue( aMat( 2, 3 ), -6 ) );
00153     
00154     myGrp->LineEdit31->setText( DlgRef::PrintDoubleValue( aMat( 3, 1 ), -6 ) );
00155     myGrp->LineEdit32->setText( DlgRef::PrintDoubleValue( aMat( 3, 2 ), -6 ) );
00156     myGrp->LineEdit33->setText( DlgRef::PrintDoubleValue( aMat( 3, 3 ), -6 ) );
00157     
00158     myGrp->LineEdit41->setText( DlgRef::PrintDoubleValue( anIXYZ.X(), -6 ) );
00159     myGrp->LineEdit42->setText( DlgRef::PrintDoubleValue( anIXYZ.Y(), -6 ) );
00160     myGrp->LineEdit43->setText( DlgRef::PrintDoubleValue( anIXYZ.Z(), -6 ) );
00161   }
00162 }
00163 
00164 //=================================================================================
00165 // function : getParameters
00166 // purpose  :
00167 //=================================================================================
00168 bool MeasureGUI_InertiaDlg::getParameters( gp_Mat& I,
00169                                            gp_XYZ& theIXYZ )
00170 {
00171   if ( myObj->_is_nil() )
00172     return false;
00173   else {
00174     GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
00175     try {
00176       double x, y, z;
00177       anOper->GetInertia( myObj,
00178                           I( 1, 1 ), I( 1, 2 ), I( 1, 3 ),
00179                           I( 2, 1 ), I( 2, 2 ), I( 2, 3 ),
00180                           I( 3, 1 ), I( 3, 2 ), I( 3, 3 ),
00181                           x, y, z );
00182 
00183         theIXYZ.SetCoord( x, y, z );
00184     }
00185     catch ( const SALOME::SALOME_Exception& e ) {
00186       SalomeApp_Tools::QtCatchCorbaException( e );
00187       return false;
00188     }
00189 
00190     return anOper->IsDone();
00191   }
00192 }