Salome HOME
Update mail address
[modules/geom.git] / src / MeasureGUI / MeasureGUI_PointDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : MeasureGUI_PointDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "MeasureGUI_PointDlg.h"
30 #include "GEOMBase.h"
31
32 #include "utilities.h"
33 #include "SUIT_Session.h"
34 #include "SalomeApp_Application.h"
35 #include "LightApp_SelectionMgr.h"
36
37 #include <TColStd_MapOfInteger.hxx>
38 #include <TopAbs_ShapeEnum.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS.hxx>
41 #include <TopoDS_Vertex.hxx>
42 #include <BRep_Tool.hxx>
43 #include <TopExp.hxx>
44 #include <TopAbs_ShapeEnum.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <TColStd_IndexedMapOfInteger.hxx>
47 #include <gp_Pnt.hxx>
48
49 #include <qlineedit.h>
50 #include <qlabel.h>
51 #include <qlayout.h>
52 #include <qpushbutton.h>
53 #include <qgroupbox.h>
54 #include <qbuttongroup.h>
55 #include <qradiobutton.h>
56 #include <qapplication.h>
57
58 //=================================================================================
59 // class    : MeasureGUI_PointDlg()
60 // purpose  : Constructs a MeasureGUI_PointDlg which is a child of 'parent'
61 //            
62 //=================================================================================
63 MeasureGUI_PointDlg::MeasureGUI_PointDlg( GeometryGUI* GUI, QWidget* parent )
64 : MeasureGUI_Skeleton( GUI, parent, "MeasureGUI_PointDlg" )
65 {
66   QPixmap iconPnt( SUIT_Session::session()->resourceMgr()->loadPixmap(
67     "GEOM",tr( "ICON_DLG_POINT" ) ) );
68   
69   QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap(
70     "GEOM",tr( "ICON_SELECT" ) ) );
71
72   setCaption( tr( "CAPTION" ) );
73
74   GroupConstructors->setTitle( tr( "CAPTION" ) );
75   RadioButton1->setPixmap( iconPnt );
76
77   QGroupBox* aGrp = new QGroupBox( 2, Qt::Horizontal, tr( "COORDINATES" ), this );
78   
79   new QLabel( tr( "POINT" ), aGrp );
80   QFrame* aFrame = new QFrame( aGrp );
81   mySelBtn = new QPushButton( aFrame );
82   mySelBtn->setPixmap( iconSelect );
83   mySelEdit = new QLineEdit( aFrame );
84   QHBoxLayout* aLay = new QHBoxLayout( aFrame, 0, 10 );
85   aLay->addWidget( mySelBtn );
86   aLay->addWidget( mySelEdit );
87
88   new QLabel( tr( "X" ), aGrp );
89   myX = new QLineEdit( aGrp );
90   new QLabel( tr( "Y" ), aGrp );
91   myY = new QLineEdit( aGrp );
92   new QLabel( tr( "Z" ), aGrp );
93   myZ = new QLineEdit( aGrp );
94
95   mySelEdit->setReadOnly( true );
96   myX->setReadOnly( true );
97   myY->setReadOnly( true );
98   myZ->setReadOnly( true );
99
100   Layout1->addWidget( aGrp, 1, 0 );
101
102   myHelpFileName = "files/salome2_sp3_measuregui_functions.htm#PointCoord";
103
104   Init();
105 }
106
107
108 //=================================================================================
109 // function : ~MeasureGUI_PointDlg()
110 // purpose  : Destroys the object and frees any allocated resources
111 //======================myX->setReadOnly( true );===========================================================
112 MeasureGUI_PointDlg::~MeasureGUI_PointDlg()
113 {
114 }
115
116
117 //=================================================================================
118 // function : Init()
119 // purpose  :
120 //=================================================================================
121 void MeasureGUI_PointDlg::Init()
122 {
123   QSize aSize( size() );
124   resize( (int)(aSize.width() *0.75 ), aSize.height() );
125   MeasureGUI_Skeleton::Init();
126 }
127
128 //=================================================================================
129 // function : activateSelection
130 // purpose  :
131 //=================================================================================
132 void MeasureGUI_PointDlg::activateSelection()
133 {
134   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
135 }
136
137 //=================================================================================
138 // function : SelectionIntoArgument
139 // purpose  :
140 //=================================================================================
141 void MeasureGUI_PointDlg::SelectionIntoArgument()
142 {
143   try
144   {
145     myObj = GEOM::GEOM_Object::_nil();
146     mySelEdit->setText( "" );
147     myX->setText( "" );
148     myY->setText( "" );
149     myZ->setText( "" );
150
151     Standard_Boolean testResult = Standard_False;
152     GEOM::GEOM_Object_var aSelectedObject =
153       GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
154
155     if( !testResult || aSelectedObject->_is_nil() )
156       return;
157
158     myObj = aSelectedObject;
159
160     TColStd_IndexedMapOfInteger anIndexes;
161     ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->
162       selectionMgr()->GetIndexes( firstIObject(), anIndexes );
163
164     TopoDS_Shape aShape;
165     if ( anIndexes.Extent() > 1 || !GEOMBase::GetShape( myObj, aShape ) || aShape.IsNull() )
166       return;
167
168     TopoDS_Vertex aPoint;
169     QString aName = GEOMBase::GetName( myObj );
170     if ( anIndexes.Extent() == 0 )
171     {
172       if ( aShape.ShapeType() == TopAbs_VERTEX )
173         aPoint = TopoDS::Vertex( aShape );
174     }
175     else
176     {
177       int i = anIndexes( 1 );
178
179       TopTools_IndexedMapOfShape aShapes;
180       TopExp::MapShapes( aShape, aShapes );
181       
182       if ( aShape != aShapes( i ) )
183         aName += QString( ":%1" ).arg( i );
184
185       aPoint = TopoDS::Vertex( aShapes( i ) );
186     }
187
188     if ( !aPoint.IsNull() )
189     {
190       gp_Pnt aPnt = BRep_Tool::Pnt( aPoint );
191       mySelEdit->setText( aName );
192       myX->setText( QString( "%1" ).arg( aPnt.X() ) );
193       myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
194       myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
195     }
196   }
197   catch( ... )
198   {
199     myObj = GEOM::GEOM_Object::_nil();
200     mySelEdit->setText( "" );
201     myX->setText( "" );
202     myY->setText( "" );
203     myZ->setText( "" );
204   }
205 }
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225