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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : MeasureGUI_PointDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "MeasureGUI_PointDlg.h"
30 #include "utilities.h"
31 #include "QAD_Desktop.h"
34 #include <TColStd_MapOfInteger.hxx>
35 #include <TopAbs_ShapeEnum.hxx>
36 #include <TopoDS_Shape.hxx>
38 #include <TopoDS_Vertex.hxx>
39 #include <BRep_Tool.hxx>
41 #include <TopAbs_ShapeEnum.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <TColStd_IndexedMapOfInteger.hxx>
46 #include <qlineedit.h>
49 #include <qpushbutton.h>
50 #include <qgroupbox.h>
51 #include <qbuttongroup.h>
52 #include <qradiobutton.h>
53 #include <qapplication.h>
55 //=================================================================================
56 // class : MeasureGUI_PointDlg()
57 // purpose : Constructs a MeasureGUI_PointDlg which is a child of 'parent'
59 //=================================================================================
60 MeasureGUI_PointDlg::MeasureGUI_PointDlg( QWidget* parent, SALOME_Selection* Sel )
61 : MeasureGUI_Skeleton( parent, "MeasureGUI_PointDlg", Sel )
63 QPixmap iconPnt( QAD_Desktop::getResourceManager()->loadPixmap(
64 "GEOM",tr( "ICON_DLG_POINT" ) ) );
66 QPixmap iconSelect( QAD_Desktop::getResourceManager()->loadPixmap(
67 "GEOM",tr( "ICON_SELECT" ) ) );
69 setCaption( tr( "CAPTION" ) );
71 GroupConstructors->setTitle( tr( "CAPTION" ) );
72 RadioButton1->setPixmap( iconPnt );
74 QGroupBox* aGrp = new QGroupBox( 2, Qt::Horizontal, tr( "COORDINATES" ), this );
76 new QLabel( tr( "POINT" ), aGrp );
77 QFrame* aFrame = new QFrame( aGrp );
78 mySelBtn = new QPushButton( aFrame );
79 mySelBtn->setPixmap( iconSelect );
80 mySelEdit = new QLineEdit( aFrame );
81 QHBoxLayout* aLay = new QHBoxLayout( aFrame, 0, 10 );
82 aLay->addWidget( mySelBtn );
83 aLay->addWidget( mySelEdit );
85 new QLabel( tr( "X" ), aGrp );
86 myX = new QLineEdit( aGrp );
87 new QLabel( tr( "Y" ), aGrp );
88 myY = new QLineEdit( aGrp );
89 new QLabel( tr( "Z" ), aGrp );
90 myZ = new QLineEdit( aGrp );
92 mySelEdit->setReadOnly( true );
93 myX->setReadOnly( true );
94 myY->setReadOnly( true );
95 myZ->setReadOnly( true );
97 Layout1->addWidget( aGrp, 1, 0 );
103 //=================================================================================
104 // function : ~MeasureGUI_PointDlg()
105 // purpose : Destroys the object and frees any allocated resources
106 //======================myX->setReadOnly( true );===========================================================
107 MeasureGUI_PointDlg::~MeasureGUI_PointDlg()
112 //=================================================================================
115 //=================================================================================
116 void MeasureGUI_PointDlg::Init( SALOME_Selection* Sel )
118 QSize aSize( size() );
119 resize( (int)(aSize.width() *0.75 ), aSize.height() );
120 MeasureGUI_Skeleton::Init( Sel );
123 //=================================================================================
124 // function : activateSelection
126 //=================================================================================
127 void MeasureGUI_PointDlg::activateSelection()
129 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
132 //=================================================================================
133 // function : SelectionIntoArgument
135 //=================================================================================
136 void MeasureGUI_PointDlg::SelectionIntoArgument()
140 myObj = GEOM::GEOM_Object::_nil();
141 mySelEdit->setText( "" );
146 Standard_Boolean testResult = Standard_False;
147 GEOM::GEOM_Object_var aSelectedObject =
148 GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), testResult );
150 if( !testResult || aSelectedObject->_is_nil() )
153 myObj = aSelectedObject;
155 TColStd_IndexedMapOfInteger anIndexes;
156 mySelection->GetIndex( mySelection->firstIObject(), anIndexes );
159 if ( anIndexes.Extent() > 1 || !GEOMBase::GetShape( myObj, aShape ) || aShape.IsNull() )
162 TopoDS_Vertex aPoint;
163 QString aName = GEOMBase::GetName( myObj );
164 if ( anIndexes.Extent() == 0 )
166 if ( aShape.ShapeType() == TopAbs_VERTEX )
167 aPoint = TopoDS::Vertex( aShape );
171 int i = anIndexes( 1 );
173 TopTools_IndexedMapOfShape aShapes;
174 TopExp::MapShapes( aShape, aShapes );
176 if ( aShape != aShapes( i ) )
177 aName += QString( ":%1" ).arg( i );
179 aPoint = TopoDS::Vertex( aShapes( i ) );
182 if ( !aPoint.IsNull() )
184 gp_Pnt aPnt = BRep_Tool::Pnt( aPoint );
185 mySelEdit->setText( aName );
186 myX->setText( QString( "%1" ).arg( aPnt.X() ) );
187 myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
188 myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
193 myObj = GEOM::GEOM_Object::_nil();
194 mySelEdit->setText( "" );