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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : MeasureGUI_PointDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "MeasureGUI_PointDlg.h"
32 #include "DlgRef_SpinBox.h"
34 #include "utilities.h"
36 #include "SUIT_Session.h"
37 #include "SalomeApp_Application.h"
38 #include "LightApp_SelectionMgr.h"
40 #include <TColStd_MapOfInteger.hxx>
41 #include <TopAbs_ShapeEnum.hxx>
42 #include <TopoDS_Shape.hxx>
44 #include <TopoDS_Vertex.hxx>
45 #include <BRep_Tool.hxx>
47 #include <TopAbs_ShapeEnum.hxx>
48 #include <TopTools_IndexedMapOfShape.hxx>
49 #include <TColStd_IndexedMapOfInteger.hxx>
52 #include <qlineedit.h>
55 #include <qpushbutton.h>
56 #include <qgroupbox.h>
57 #include <qbuttongroup.h>
58 #include <qradiobutton.h>
59 #include <qapplication.h>
61 //=================================================================================
62 // class : MeasureGUI_PointDlg()
63 // purpose : Constructs a MeasureGUI_PointDlg which is a child of 'parent'
64 //=================================================================================
65 MeasureGUI_PointDlg::MeasureGUI_PointDlg( GeometryGUI* GUI, QWidget* parent )
66 : MeasureGUI_Skeleton( GUI, parent, "MeasureGUI_PointDlg" )
68 QPixmap iconPnt( SUIT_Session::session()->resourceMgr()->loadPixmap(
69 "GEOM",tr( "ICON_DLG_POINT" ) ) );
71 QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap(
72 "GEOM",tr( "ICON_SELECT" ) ) );
74 setCaption( tr( "CAPTION" ) );
76 GroupConstructors->setTitle( tr( "CAPTION" ) );
77 RadioButton1->setPixmap( iconPnt );
79 QGroupBox* aGrp = new QGroupBox( 2, Qt::Horizontal, tr( "COORDINATES" ), this );
81 new QLabel( tr( "POINT" ), aGrp );
82 QFrame* aFrame = new QFrame( aGrp );
83 mySelBtn = new QPushButton( aFrame );
84 mySelBtn->setPixmap( iconSelect );
85 mySelEdit = new QLineEdit( aFrame );
86 QHBoxLayout* aLay = new QHBoxLayout( aFrame, 0, 10 );
87 aLay->addWidget( mySelBtn );
88 aLay->addWidget( mySelEdit );
90 new QLabel( tr( "X" ), aGrp );
91 myX = new QLineEdit( aGrp );
92 new QLabel( tr( "Y" ), aGrp );
93 myY = new QLineEdit( aGrp );
94 new QLabel( tr( "Z" ), aGrp );
95 myZ = new QLineEdit( aGrp );
97 mySelEdit->setReadOnly( true );
98 myX->setReadOnly( true );
99 myY->setReadOnly( true );
100 myZ->setReadOnly( true );
102 Layout1->addWidget( aGrp, 1, 0 );
104 myHelpFileName = "using_measurement_tools_page.html#point_coord_anchor";
110 //=================================================================================
111 // function : ~MeasureGUI_PointDlg()
112 // purpose : Destroys the object and frees any allocated resources
113 //=================================================================================
114 MeasureGUI_PointDlg::~MeasureGUI_PointDlg()
119 //=================================================================================
122 //=================================================================================
123 void MeasureGUI_PointDlg::Init()
125 QSize aSize( size() );
126 resize( (int)(aSize.width() *0.75 ), aSize.height() );
127 MeasureGUI_Skeleton::Init();
130 //=================================================================================
131 // function : activateSelection
133 //=================================================================================
134 void MeasureGUI_PointDlg::activateSelection()
136 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
139 //=================================================================================
140 // function : SelectionIntoArgument
142 //=================================================================================
143 void MeasureGUI_PointDlg::SelectionIntoArgument()
147 myObj = GEOM::GEOM_Object::_nil();
148 mySelEdit->setText( "" );
153 Standard_Boolean testResult = Standard_False;
154 GEOM::GEOM_Object_var aSelectedObject =
155 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
157 if( !testResult || aSelectedObject->_is_nil() )
160 myObj = aSelectedObject;
162 TColStd_IndexedMapOfInteger anIndexes;
163 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->
164 selectionMgr()->GetIndexes( firstIObject(), anIndexes );
167 if ( anIndexes.Extent() > 1 || !GEOMBase::GetShape( myObj, aShape ) || aShape.IsNull() )
170 TopoDS_Vertex aPoint;
171 QString aName = GEOMBase::GetName( myObj );
172 if ( anIndexes.Extent() == 0 )
174 if ( aShape.ShapeType() == TopAbs_VERTEX )
175 aPoint = TopoDS::Vertex( aShape );
179 int i = anIndexes( 1 );
181 TopTools_IndexedMapOfShape aShapes;
182 TopExp::MapShapes( aShape, aShapes );
184 if ( aShape != aShapes( i ) )
185 aName += QString( ":%1" ).arg( i );
187 aPoint = TopoDS::Vertex( aShapes( i ) );
190 if ( !aPoint.IsNull() )
192 gp_Pnt aPnt = BRep_Tool::Pnt( aPoint );
193 mySelEdit->setText( aName );
194 myX->setText(DlgRef_SpinBox::PrintDoubleValue(aPnt.X()));
195 myY->setText(DlgRef_SpinBox::PrintDoubleValue(aPnt.Y()));
196 myZ->setText(DlgRef_SpinBox::PrintDoubleValue(aPnt.Z()));
201 myObj = GEOM::GEOM_Object::_nil();
202 mySelEdit->setText( "" );