Back to index

salome-geom  6.5.0
MeasureGUI_PropertiesDlg.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_PropertiesDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 //
00027 #include "MeasureGUI_PropertiesDlg.h"
00028 #include "MeasureGUI_Widgets.h"
00029 
00030 #include <GEOMImpl_Types.hxx>
00031 #include <GEOMBase.h>
00032 #include <DlgRef.h>
00033 
00034 #include <SalomeApp_Tools.h>
00035 #include <SUIT_Session.h>
00036 #include <SUIT_ResourceMgr.h>
00037 
00038 #include <TColStd_MapOfInteger.hxx>
00039 
00040 //=================================================================================
00041 // class    : MeasureGUI_PropertiesDlg()
00042 // purpose  : Constructs a MeasureGUI_PropertiesDlg which is a child of 'parent', with the 
00043 //            name 'name' and widget flags set to 'f'.
00044 //            The dialog will by default be modeless, unless you set 'modal' to
00045 //            true to construct a modal dialog.
00046 //=================================================================================
00047 MeasureGUI_PropertiesDlg::MeasureGUI_PropertiesDlg( GeometryGUI* GUI, QWidget* parent )
00048   : MeasureGUI_Skeleton( GUI, parent )
00049 {
00050   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
00051     "GEOM", tr( "ICON_DLG_BASICPROPERTIES" ) ) );
00052   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
00053     "GEOM", tr( "ICON_SELECT" ) ) );
00054 
00055   setWindowTitle( tr( "GEOM_PROPERTIES_TITLE" ) );
00056 
00057   /***************************************************************/
00058   
00059   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PROPERTIES" ) );
00060   mainFrame()->RadioButton1->setIcon( image0 );
00061 
00062   myGrp = new MeasureGUI_1Sel3LineEdit( centralWidget()  );
00063   myGrp->GroupBox1->setTitle( tr( "GEOM_PROPERTIES_CONSTR" ) );
00064   myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
00065   myGrp->TextLabel2->setText( tr( "GEOM_LENGTH" ) );
00066   myGrp->TextLabel3->setText( tr( "GEOM_PROPERTIES_SURFACE" ) );
00067   myGrp->TextLabel4->setText( tr( "GEOM_PROPERTIES_VOLUME" ) );
00068   myGrp->LineEdit1->setReadOnly( true );
00069   myGrp->PushButton1->setIcon( image1 );
00070   myGrp->LineEdit2->setReadOnly( true );
00071   myGrp->LineEdit3->setReadOnly( true );
00072   myGrp->LineEdit4->setReadOnly( true );
00073 
00074   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00075   layout->setMargin( 0 ); layout->setSpacing( 6 );
00076   layout->addWidget( myGrp );
00077   
00078   /***************************************************************/
00079 
00080   myHelpFileName = "using_measurement_tools_page.html#basic_prop_anchor";
00081 
00082   /* Initialisation */
00083   Init();
00084 }
00085 
00086 
00087 //=================================================================================
00088 // function : ~MeasureGUI_PropertiesDlg()
00089 // purpose  : Destroys the object and frees any allocated resources
00090 //=================================================================================
00091 MeasureGUI_PropertiesDlg::~MeasureGUI_PropertiesDlg()
00092 {
00093 }
00094 
00095 
00096 //=================================================================================
00097 // function : Init()
00098 // purpose  :
00099 //=================================================================================
00100 void MeasureGUI_PropertiesDlg::Init()
00101 {
00102   mySelBtn = myGrp->PushButton1;
00103   mySelEdit = myGrp->LineEdit1;
00104   MeasureGUI_Skeleton::Init();
00105 }
00106 
00107 //=================================================================================
00108 // function : activateSelection
00109 // purpose  :
00110 //=================================================================================
00111 void MeasureGUI_PropertiesDlg::activateSelection()
00112 {
00113   static TColStd_MapOfInteger aTypes;
00114   if ( aTypes.IsEmpty() ) {
00115     aTypes.Add( GEOM_COMPOUND );
00116     //    aTypes.Add( TopAbs_COMPSOLID );
00117     aTypes.Add( GEOM_SOLID );
00118     aTypes.Add( GEOM_SHELL );
00119     aTypes.Add( GEOM_FACE );
00120     aTypes.Add( GEOM_WIRE );
00121     aTypes.Add( GEOM_EDGE );
00122   }
00123 
00124   globalSelection( aTypes );
00125 }
00126 
00127 //=================================================================================
00128 // function : processObject
00129 // purpose  :
00130 //=================================================================================
00131 void MeasureGUI_PropertiesDlg::processObject()
00132 {
00133   double aLength, anArea, aVolume;
00134   
00135   if ( !getParameters( aLength, anArea, aVolume ) ) {
00136     mySelEdit->setText( "" );
00137     myGrp->LineEdit2->setText( "" );
00138     myGrp->LineEdit3->setText( "" );
00139     myGrp->LineEdit4->setText( "" );
00140   }
00141   else {
00142     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00143     int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
00144     myGrp->LineEdit2->setText( DlgRef::PrintDoubleValue( aLength, aPrecision ) );
00145     myGrp->LineEdit3->setText( DlgRef::PrintDoubleValue( anArea,  aPrecision ) );
00146     myGrp->LineEdit4->setText( DlgRef::PrintDoubleValue( aVolume, aPrecision ) );
00147   }
00148 }
00149 
00150 //=================================================================================
00151 // function : getParameters
00152 // purpose  :
00153 //=================================================================================
00154 bool MeasureGUI_PropertiesDlg::getParameters( double& theLength,
00155                                               double& theArea,
00156                                               double& theVolume )
00157 {
00158   if ( myObj->_is_nil() )
00159     return false;
00160   else {
00161     GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
00162     try {
00163       anOper->GetBasicProperties( myObj, theLength, theArea, theVolume );
00164     }
00165     catch( const SALOME::SALOME_Exception& e ) {
00166       SalomeApp_Tools::QtCatchCorbaException( e );
00167       return false;
00168     }
00169 
00170     return anOper->IsDone();
00171   }
00172 }
00173 
00174 //=================================================================================
00175 // function : createOperation
00176 // purpose  :
00177 //=================================================================================
00178 SALOME_Prs* MeasureGUI_PropertiesDlg::buildPrs()
00179 {
00180   SALOME_Prs* prs = 0;
00181   TopoDS_Shape shape;
00182   
00183   if ( GEOMBase::GetShape( myObj, shape, TopAbs_EDGE ) ) {
00184     shape = GEOMBase::CreateArrowForLinearEdge( shape );
00185     if ( !shape.IsNull() )
00186       prs = getDisplayer()->BuildPrs( shape );
00187   }
00188   return prs;
00189 }