Back to index

salome-geom  6.5.0
MeasureGUI_PointDlg.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_PointDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 //
00027 #include "MeasureGUI_PointDlg.h"
00028 #include "MeasureGUI_Widgets.h"
00029 
00030 #include <GEOMBase.h>
00031 #include <DlgRef.h>
00032 
00033 #include <GeometryGUI.h>
00034 
00035 #include <SUIT_Session.h>
00036 #include <SUIT_ResourceMgr.h>
00037 #include <SalomeApp_Application.h>
00038 #include <LightApp_SelectionMgr.h>
00039 
00040 #include <TopoDS_Shape.hxx>
00041 #include <TopoDS.hxx>
00042 #include <TopoDS_Vertex.hxx>
00043 #include <BRep_Tool.hxx>
00044 #include <TopExp.hxx>
00045 #include <TopTools_IndexedMapOfShape.hxx>
00046 #include <TColStd_IndexedMapOfInteger.hxx>
00047 #include <gp_Pnt.hxx>
00048 
00049 //=================================================================================
00050 // class    : MeasureGUI_PointDlg()
00051 // purpose  : Constructs a MeasureGUI_PointDlg which is a child of 'parent'
00052 //            
00053 //=================================================================================
00054 MeasureGUI_PointDlg::MeasureGUI_PointDlg( GeometryGUI* GUI, QWidget* parent )
00055   : MeasureGUI_Skeleton( GUI, parent )
00056 {
00057   QPixmap iconPnt( SUIT_Session::session()->resourceMgr()->loadPixmap(
00058     "GEOM", tr( "ICON_DLG_POINT" ) ) );
00059   
00060   QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap(
00061     "GEOM", tr( "ICON_SELECT" ) ) );
00062 
00063   setWindowTitle( tr( "CAPTION" ) );
00064 
00065   mainFrame()->GroupConstructors->setTitle( tr( "CAPTION" ) );
00066   mainFrame()->RadioButton1->setIcon( iconPnt );
00067 
00068   myGrp = new MeasureGUI_1Sel3LineEdit( centralWidget() );
00069   myGrp->TextLabel1->setText( tr( "POINT" ) );
00070   myGrp->PushButton1->setIcon( iconSelect );
00071   myGrp->LineEdit1->setReadOnly( true );
00072   myGrp->TextLabel2->setText( tr( "X" ) );
00073   myGrp->TextLabel3->setText( tr( "Y" ) );
00074   myGrp->TextLabel4->setText( tr( "Z" ) );
00075   myGrp->LineEdit2->setReadOnly( true );
00076   myGrp->LineEdit3->setReadOnly( true );
00077   myGrp->LineEdit4->setReadOnly( true );
00078 
00079   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00080   layout->setMargin( 0 ); layout->setSpacing( 6 );
00081   layout->addWidget( myGrp );
00082 
00083   myHelpFileName = "using_measurement_tools_page.html#point_coord_anchor";
00084 
00085   Init();
00086 }
00087 
00088 
00089 //=================================================================================
00090 // function : ~MeasureGUI_PointDlg()
00091 // purpose  : Destroys the object and frees any allocated resources
00092 //======================myGrp->LineEdit2->setReadOnly( true );===========================================================
00093 MeasureGUI_PointDlg::~MeasureGUI_PointDlg()
00094 {
00095 }
00096 
00097 
00098 //=================================================================================
00099 // function : Init()
00100 // purpose  :
00101 //=================================================================================
00102 void MeasureGUI_PointDlg::Init()
00103 {
00104   QSize aSize( size() );
00105   resize( (int)(aSize.width() *0.75 ), aSize.height() );
00106   MeasureGUI_Skeleton::Init();
00107 }
00108 
00109 //=================================================================================
00110 // function : activateSelection
00111 // purpose  :
00112 //=================================================================================
00113 void MeasureGUI_PointDlg::activateSelection()
00114 {
00115   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
00116 }
00117 
00118 //=================================================================================
00119 // function : SelectionIntoArgument
00120 // purpose  :
00121 //=================================================================================
00122 void MeasureGUI_PointDlg::SelectionIntoArgument()
00123 {
00124   try {
00125     myObj = GEOM::GEOM_Object::_nil();
00126     myGrp->LineEdit1->setText( "" );
00127     myGrp->LineEdit2->setText( "" );
00128     myGrp->LineEdit3->setText( "" );
00129     myGrp->LineEdit4->setText( "" );
00130 
00131     LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00132     SALOME_ListIO aSelList;
00133     aSelMgr->selectedObjects(aSelList);
00134 
00135     if (aSelList.Extent() < 1)
00136       return;
00137 
00138     GEOM::GEOM_Object_var aSelectedObject =
00139       GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
00140 
00141     if ( aSelectedObject->_is_nil() )
00142       return;
00143 
00144     myObj = aSelectedObject;
00145 
00146     TColStd_IndexedMapOfInteger anIndexes;
00147     aSelMgr->GetIndexes(aSelList.First(), anIndexes);
00148 
00149     TopoDS_Shape aShape;
00150     if ( anIndexes.Extent() > 1 || !GEOMBase::GetShape( myObj, aShape ) || aShape.IsNull() )
00151       return;
00152 
00153     TopoDS_Vertex aPoint;
00154     QString aName = GEOMBase::GetName( myObj );
00155     if ( anIndexes.Extent() == 0 ) {
00156       if ( aShape.ShapeType() == TopAbs_VERTEX )
00157         aPoint = TopoDS::Vertex( aShape );
00158     }
00159     else {
00160       int i = anIndexes( 1 );
00161 
00162       TopTools_IndexedMapOfShape aShapes;
00163       TopExp::MapShapes( aShape, aShapes );
00164       
00165       if ( aShape != aShapes( i ) )
00166         aName += QString( ":%1" ).arg( i );
00167 
00168       aPoint = TopoDS::Vertex( aShapes( i ) );
00169     }
00170 
00171     if ( !aPoint.IsNull() ) {
00172       gp_Pnt aPnt = BRep_Tool::Pnt( aPoint );
00173       myGrp->LineEdit1->setText( aName );
00174       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00175       int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
00176       myGrp->LineEdit2->setText( DlgRef::PrintDoubleValue( aPnt.X(), aPrecision ) );
00177       myGrp->LineEdit3->setText( DlgRef::PrintDoubleValue( aPnt.Y(), aPrecision ) );
00178       myGrp->LineEdit4->setText( DlgRef::PrintDoubleValue( aPnt.Z(), aPrecision ) );
00179     }
00180   }
00181   catch( ... )
00182   {
00183     myObj = GEOM::GEOM_Object::_nil();
00184     myGrp->LineEdit1->setText( "" );
00185     myGrp->LineEdit2->setText( "" );
00186     myGrp->LineEdit3->setText( "" );
00187     myGrp->LineEdit4->setText( "" );
00188   }
00189 }