1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : MeasureGUI_PointDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "MeasureGUI_PointDlg.h"
31 #include "DlgRef_SpinBox.h"
33 #include "utilities.h"
35 #include "SUIT_Session.h"
36 #include "SalomeApp_Application.h"
37 #include "LightApp_SelectionMgr.h"
39 #include <TColStd_MapOfInteger.hxx>
40 #include <TopAbs_ShapeEnum.hxx>
41 #include <TopoDS_Shape.hxx>
43 #include <TopoDS_Vertex.hxx>
44 #include <BRep_Tool.hxx>
46 #include <TopAbs_ShapeEnum.hxx>
47 #include <TopTools_IndexedMapOfShape.hxx>
48 #include <TColStd_IndexedMapOfInteger.hxx>
51 #include <qlineedit.h>
54 #include <qpushbutton.h>
55 #include <qgroupbox.h>
56 #include <qbuttongroup.h>
57 #include <qradiobutton.h>
58 #include <qapplication.h>
60 //=================================================================================
61 // class : MeasureGUI_PointDlg()
62 // purpose : Constructs a MeasureGUI_PointDlg which is a child of 'parent'
63 //=================================================================================
64 MeasureGUI_PointDlg::MeasureGUI_PointDlg( GeometryGUI* GUI, QWidget* parent )
65 : MeasureGUI_Skeleton( GUI, parent, "MeasureGUI_PointDlg" )
67 QPixmap iconPnt( SUIT_Session::session()->resourceMgr()->loadPixmap(
68 "GEOM",tr( "ICON_DLG_POINT" ) ) );
70 QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap(
71 "GEOM",tr( "ICON_SELECT" ) ) );
73 setCaption( tr( "CAPTION" ) );
75 GroupConstructors->setTitle( tr( "CAPTION" ) );
76 RadioButton1->setPixmap( iconPnt );
78 QGroupBox* aGrp = new QGroupBox( 2, Qt::Horizontal, tr( "COORDINATES" ), this );
80 new QLabel( tr( "POINT" ), aGrp );
81 QFrame* aFrame = new QFrame( aGrp );
82 mySelBtn = new QPushButton( aFrame );
83 mySelBtn->setPixmap( iconSelect );
84 mySelEdit = new QLineEdit( aFrame );
85 QHBoxLayout* aLay = new QHBoxLayout( aFrame, 0, 10 );
86 aLay->addWidget( mySelBtn );
87 aLay->addWidget( mySelEdit );
89 new QLabel( tr( "X" ), aGrp );
90 myX = new QLineEdit( aGrp );
91 new QLabel( tr( "Y" ), aGrp );
92 myY = new QLineEdit( aGrp );
93 new QLabel( tr( "Z" ), aGrp );
94 myZ = new QLineEdit( aGrp );
96 mySelEdit->setReadOnly( true );
97 myX->setReadOnly( true );
98 myY->setReadOnly( true );
99 myZ->setReadOnly( true );
101 Layout1->addWidget( aGrp, 1, 0 );
103 myHelpFileName = "using_measurement_tools_page.html#point_coord_anchor";
109 //=================================================================================
110 // function : ~MeasureGUI_PointDlg()
111 // purpose : Destroys the object and frees any allocated resources
112 //=================================================================================
113 MeasureGUI_PointDlg::~MeasureGUI_PointDlg()
118 //=================================================================================
121 //=================================================================================
122 void MeasureGUI_PointDlg::Init()
124 QSize aSize( size() );
125 resize( (int)(aSize.width() *0.75 ), aSize.height() );
126 MeasureGUI_Skeleton::Init();
129 //=================================================================================
130 // function : activateSelection
132 //=================================================================================
133 void MeasureGUI_PointDlg::activateSelection()
135 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
138 //=================================================================================
139 // function : SelectionIntoArgument
141 //=================================================================================
142 void MeasureGUI_PointDlg::SelectionIntoArgument()
146 myObj = GEOM::GEOM_Object::_nil();
147 mySelEdit->setText( "" );
152 Standard_Boolean testResult = Standard_False;
153 GEOM::GEOM_Object_var aSelectedObject =
154 GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
156 if( !testResult || aSelectedObject->_is_nil() )
159 myObj = aSelectedObject;
161 TColStd_IndexedMapOfInteger anIndexes;
162 ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->
163 selectionMgr()->GetIndexes( firstIObject(), anIndexes );
166 if ( anIndexes.Extent() > 1 || !GEOMBase::GetShape( myObj, aShape ) || aShape.IsNull() )
169 TopoDS_Vertex aPoint;
170 QString aName = GEOMBase::GetName( myObj );
171 if ( anIndexes.Extent() == 0 )
173 if ( aShape.ShapeType() == TopAbs_VERTEX )
174 aPoint = TopoDS::Vertex( aShape );
178 int i = anIndexes( 1 );
180 TopTools_IndexedMapOfShape aShapes;
181 TopExp::MapShapes( aShape, aShapes );
183 if ( aShape != aShapes( i ) )
184 aName += QString( ":%1" ).arg( i );
186 aPoint = TopoDS::Vertex( aShapes( i ) );
189 if ( !aPoint.IsNull() )
191 gp_Pnt aPnt = BRep_Tool::Pnt( aPoint );
192 mySelEdit->setText( aName );
193 myX->setText(DlgRef_SpinBox::PrintDoubleValue(aPnt.X()));
194 myY->setText(DlgRef_SpinBox::PrintDoubleValue(aPnt.Y()));
195 myZ->setText(DlgRef_SpinBox::PrintDoubleValue(aPnt.Z()));
200 myObj = GEOM::GEOM_Object::_nil();
201 mySelEdit->setText( "" );