Back to index

salome-geom  6.5.0
MeasureGUI_BndBoxDlg.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_BndBoxDlg.cxx
00025 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
00026 //
00027 #include "MeasureGUI_BndBoxDlg.h"
00028 #include "MeasureGUI_Widgets.h"
00029 
00030 #include "GeometryGUI.h"
00031 
00032 #include <GEOMBase.h>
00033 #include <DlgRef.h>
00034 
00035 #include <GEOM_Function.hxx>
00036 #include <GEOM_Object.hxx>
00037 
00038 #include <BRepPrimAPI_MakeBox.hxx>
00039 #include <BRepAdaptor_Surface.hxx>
00040 #include <BRep_Tool.hxx>
00041 #include <BRep_TFace.hxx>
00042 #include <TopoDS.hxx>
00043 #include <TopoDS_Face.hxx>
00044 #include <TopExp_Explorer.hxx>
00045 
00046 #include <SUIT_Session.h>
00047 #include <SUIT_ResourceMgr.h>
00048 #include <SalomeApp_Tools.h>
00049 
00050 // #include <qlineedit.h>
00051 // #include <qlabel.h>
00052 // #include <qlayout.h>
00053 // #include <qpushbutton.h>
00054 // #include <qradiobutton.h>
00055 // #include <qbuttongroup.h>
00056 
00057 //=================================================================================
00058 // class    : MeasureGUI_BndBoxDlg()
00059 // purpose  : Constructs a MeasureGUI_BndBoxDlg which is a child of 'parent', with the 
00060 //            name 'name' and widget flags set to 'f'.
00061 //            The dialog will by default be modeless, unless you set 'modal' to
00062 //            true to construct a modal dialog.
00063 //=================================================================================
00064 MeasureGUI_BndBoxDlg::MeasureGUI_BndBoxDlg( GeometryGUI* GUI, QWidget* parent )
00065   : MeasureGUI_Skeleton( GUI, parent )
00066 {
00067   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
00068     "GEOM", tr( "ICON_DLG_BOUNDING_BOX" ) ) );
00069   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
00070     "GEOM", tr( "ICON_SELECT" ) ) );
00071 
00072   setWindowTitle( tr( "GEOM_BNDBOX_TITLE" ) );
00073 
00074   /***************************************************************/
00075   
00076   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_BNDBOX" ) );
00077   mainFrame()->RadioButton1->setIcon( image0 );
00078 
00079   myGrp = new MeasureGUI_1Sel6LineEdit( centralWidget() );
00080   myGrp->GroupBox1->setTitle( tr( "GEOM_BNDBOX_OBJDIM" ) );
00081   myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
00082   myGrp->TextLabel2->setText( tr( "GEOM_MIN" ) );
00083   myGrp->TextLabel3->setText( tr( "GEOM_MAX" ) );
00084   myGrp->TextLabel4->setText( tr( "GEOM_X" ) );
00085   myGrp->TextLabel5->setText( tr( "GEOM_Y" ) );
00086   myGrp->TextLabel6->setText( tr( "GEOM_Z" ) );
00087   myGrp->LineEdit11->setReadOnly( true );
00088   myGrp->LineEdit12->setReadOnly( true );
00089   myGrp->LineEdit21->setReadOnly( true );
00090   myGrp->LineEdit22->setReadOnly( true );
00091   myGrp->LineEdit31->setReadOnly( true );
00092   myGrp->LineEdit32->setReadOnly( true );
00093   myGrp->LineEdit11->setMinimumWidth(120);
00094   myGrp->LineEdit12->setMinimumWidth(120);
00095   myGrp->LineEdit21->setMinimumWidth(120);
00096   myGrp->LineEdit22->setMinimumWidth(120);
00097   myGrp->LineEdit31->setMinimumWidth(120);
00098   myGrp->LineEdit32->setMinimumWidth(120);
00099   myGrp->PushButton1->setIcon( image1 );
00100   myGrp->LineEdit1->setReadOnly( true );
00101 
00102   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00103   layout->setMargin( 0 ); layout->setSpacing( 6 );
00104   layout->addWidget( myGrp );
00105   
00106   /***************************************************************/
00107 
00108   myHelpFileName = "using_measurement_tools_page.html#bounding_box_anchor";
00109 
00110   /* Initialisation */
00111   Init();
00112 }
00113 
00114 
00115 //=================================================================================
00116 // function : ~MeasureGUI_BndBoxDlg()
00117 // purpose  : Destroys the object and frees any allocated resources
00118 //=================================================================================
00119 MeasureGUI_BndBoxDlg::~MeasureGUI_BndBoxDlg()
00120 {
00121 }
00122 
00123 
00124 //=================================================================================
00125 // function : Init()
00126 // purpose  :
00127 //=================================================================================
00128 void MeasureGUI_BndBoxDlg::Init()
00129 {
00130   mySelBtn = myGrp->PushButton1;
00131   mySelEdit = myGrp->LineEdit1;
00132   MeasureGUI_Skeleton::Init();
00133 }
00134 
00135 //=================================================================================
00136 // function : processObject
00137 // purpose  :
00138 //=================================================================================
00139 void MeasureGUI_BndBoxDlg::processObject()
00140 {
00141   double aXMin, aXMax, aYMin, aYMax, aZMin, aZMax;
00142 
00143   if ( !getParameters( aXMin, aXMax, aYMin, aYMax, aZMin, aZMax ) ) {
00144     mySelEdit->setText( "" );
00145     myGrp->LineEdit11->setText( "" );
00146     myGrp->LineEdit12->setText( "" );
00147     myGrp->LineEdit21->setText( "" );
00148     myGrp->LineEdit22->setText( "" );
00149     myGrp->LineEdit31->setText( "" );
00150     myGrp->LineEdit32->setText( "" );
00151   }
00152   else {
00153     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00154     int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
00155 
00156     myGrp->LineEdit11->setText( DlgRef::PrintDoubleValue( aXMin, aPrecision ) );
00157     myGrp->LineEdit12->setText( DlgRef::PrintDoubleValue( aXMax, aPrecision ) );
00158 
00159     myGrp->LineEdit21->setText( DlgRef::PrintDoubleValue( aYMin, aPrecision ) );
00160     myGrp->LineEdit22->setText( DlgRef::PrintDoubleValue( aYMax, aPrecision ) );
00161 
00162     myGrp->LineEdit31->setText( DlgRef::PrintDoubleValue( aZMin, aPrecision ) );
00163     myGrp->LineEdit32->setText( DlgRef::PrintDoubleValue( aZMax, aPrecision ) );
00164   }
00165 }
00166 
00167 //=================================================================================
00168 // function : getParameters
00169 // purpose  :
00170 //=================================================================================
00171 bool MeasureGUI_BndBoxDlg::getParameters( double& theXmin, double& theXmax,
00172                                           double& theYmin, double& theYmax,
00173                                           double& theZmin, double& theZmax )
00174 {
00175   if ( myObj->_is_nil() )
00176     return false;
00177   else {
00178     GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
00179     try {
00180       Handle(Poly_Triangulation) Trtn = 0; 
00181 
00182       GEOM::GEOM_Gen_var aGeomGen = GeometryGUI::GetGeomGen();
00183       if ( CORBA::is_nil(aGeomGen) )
00184         return false;
00185 
00186       QString IOR = GEOMBase::GetIORFromObject( myObj );
00187       GEOM::GEOM_Object_var anObject = aGeomGen->GetIORFromString( IOR.toLatin1().constData() );
00188       if ( CORBA::is_nil(anObject) )
00189         return false;
00190 
00191       TopoDS_Shape aShape;
00192       GEOMBase::GetShape(anObject, aShape, TopAbs_SHAPE);
00193       if ( aShape.IsNull() )
00194         return false;
00195       
00196       TopLoc_Location l;
00197       Handle(Poly_Triangulation) T;
00198       TopExp_Explorer ex;
00199       for (ex.Init(aShape,TopAbs_FACE); ex.More(); ex.Next()) {
00200         const TopoDS_Face& F = TopoDS::Face(ex.Current());
00201         BRepAdaptor_Surface surf(F);
00202         if (surf.GetType() == GeomAbs_Sphere) {
00203           T = BRep_Tool::Triangulation(F, l);
00204           if (!T.IsNull()) {
00205             Handle(Poly_Triangulation) NullTrtn = 0;
00206             (*((Handle(BRep_TFace)*)&F.TShape()))->Triangulation(NullTrtn);
00207             Trtn = T;
00208             break;
00209           }
00210         }
00211         else
00212           break;
00213       }
00214       
00215       anOper->GetBoundingBox( myObj, theXmin, theXmax, theYmin, theYmax, theZmin, theZmax );
00216       
00217       if (!Trtn.IsNull()) {
00218         TopLoc_Location l;
00219         Handle(Poly_Triangulation) T;
00220         TopExp_Explorer ex;
00221         for (ex.Init(aShape,TopAbs_FACE); ex.More(); ex.Next()) {
00222           const TopoDS_Face& F = TopoDS::Face(ex.Current());
00223           (*((Handle(BRep_TFace)*)&F.TShape()))->Triangulation(Trtn);
00224           break;
00225         }
00226       }
00227       
00228     }
00229     catch( const SALOME::SALOME_Exception& e ) {
00230       SalomeApp_Tools::QtCatchCorbaException( e );
00231       return false;
00232     }
00233 
00234     return anOper->IsDone();
00235   }
00236 }
00237 
00238 //=================================================================================
00239 // function : buildPrs
00240 // purpose  :
00241 //=================================================================================
00242 SALOME_Prs* MeasureGUI_BndBoxDlg::buildPrs()
00243 {
00244   double aXMin, aYMin, aZMin, aXMax, aYMax, aZMax;
00245 
00246   if ( myObj->_is_nil() || !getParameters( aXMin, aXMax, aYMin, aYMax, aZMin, aZMax ) )
00247     return 0;
00248 
00249   TopoDS_Shape aShape = BRepPrimAPI_MakeBox( gp_Pnt( aXMin, aYMin, aZMin ),
00250                                              gp_Pnt( aXMax, aYMax, aZMax ) ).Shape();
00251        
00252   return !aShape.IsNull() ? getDisplayer()->BuildPrs( aShape ) : 0;
00253 
00254 }