Salome HOME
Join modifications from V3_2_0_maintainance (V3_2_6pre4 - T32x_16Aug2007_16h00m)
[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 "DlgRef_SpinBox.h"
33
34 #include "utilities.h"
35
36 #include "SUIT_Session.h"
37 #include "SalomeApp_Application.h"
38 #include "LightApp_SelectionMgr.h"
39
40 #include <TColStd_MapOfInteger.hxx>
41 #include <TopAbs_ShapeEnum.hxx>
42 #include <TopoDS_Shape.hxx>
43 #include <TopoDS.hxx>
44 #include <TopoDS_Vertex.hxx>
45 #include <BRep_Tool.hxx>
46 #include <TopExp.hxx>
47 #include <TopAbs_ShapeEnum.hxx>
48 #include <TopTools_IndexedMapOfShape.hxx>
49 #include <TColStd_IndexedMapOfInteger.hxx>
50 #include <gp_Pnt.hxx>
51
52 #include <qlineedit.h>
53 #include <qlabel.h>
54 #include <qlayout.h>
55 #include <qpushbutton.h>
56 #include <qgroupbox.h>
57 #include <qbuttongroup.h>
58 #include <qradiobutton.h>
59 #include <qapplication.h>
60
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" )
67 {
68   QPixmap iconPnt( SUIT_Session::session()->resourceMgr()->loadPixmap(
69     "GEOM",tr( "ICON_DLG_POINT" ) ) );
70
71   QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap(
72     "GEOM",tr( "ICON_SELECT" ) ) );
73
74   setCaption( tr( "CAPTION" ) );
75
76   GroupConstructors->setTitle( tr( "CAPTION" ) );
77   RadioButton1->setPixmap( iconPnt );
78
79   QGroupBox* aGrp = new QGroupBox( 2, Qt::Horizontal, tr( "COORDINATES" ), this );
80
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 );
89
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 );
96
97   mySelEdit->setReadOnly( true );
98   myX->setReadOnly( true );
99   myY->setReadOnly( true );
100   myZ->setReadOnly( true );
101
102   Layout1->addWidget( aGrp, 1, 0 );
103
104   myHelpFileName = "files/salome2_sp3_measuregui_functions.htm#PointCoord";
105
106   Init();
107 }
108
109
110 //=================================================================================
111 // function : ~MeasureGUI_PointDlg()
112 // purpose  : Destroys the object and frees any allocated resources
113 //=================================================================================
114 MeasureGUI_PointDlg::~MeasureGUI_PointDlg()
115 {
116 }
117
118
119 //=================================================================================
120 // function : Init()
121 // purpose  :
122 //=================================================================================
123 void MeasureGUI_PointDlg::Init()
124 {
125   QSize aSize( size() );
126   resize( (int)(aSize.width() *0.75 ), aSize.height() );
127   MeasureGUI_Skeleton::Init();
128 }
129
130 //=================================================================================
131 // function : activateSelection
132 // purpose  :
133 //=================================================================================
134 void MeasureGUI_PointDlg::activateSelection()
135 {
136   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
137 }
138
139 //=================================================================================
140 // function : SelectionIntoArgument
141 // purpose  :
142 //=================================================================================
143 void MeasureGUI_PointDlg::SelectionIntoArgument()
144 {
145   try
146   {
147     myObj = GEOM::GEOM_Object::_nil();
148     mySelEdit->setText( "" );
149     myX->setText( "" );
150     myY->setText( "" );
151     myZ->setText( "" );
152
153     Standard_Boolean testResult = Standard_False;
154     GEOM::GEOM_Object_var aSelectedObject =
155       GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
156
157     if( !testResult || aSelectedObject->_is_nil() )
158       return;
159
160     myObj = aSelectedObject;
161
162     TColStd_IndexedMapOfInteger anIndexes;
163     ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->
164       selectionMgr()->GetIndexes( firstIObject(), anIndexes );
165
166     TopoDS_Shape aShape;
167     if ( anIndexes.Extent() > 1 || !GEOMBase::GetShape( myObj, aShape ) || aShape.IsNull() )
168       return;
169
170     TopoDS_Vertex aPoint;
171     QString aName = GEOMBase::GetName( myObj );
172     if ( anIndexes.Extent() == 0 )
173     {
174       if ( aShape.ShapeType() == TopAbs_VERTEX )
175         aPoint = TopoDS::Vertex( aShape );
176     }
177     else
178     {
179       int i = anIndexes( 1 );
180
181       TopTools_IndexedMapOfShape aShapes;
182       TopExp::MapShapes( aShape, aShapes );
183
184       if ( aShape != aShapes( i ) )
185         aName += QString( ":%1" ).arg( i );
186
187       aPoint = TopoDS::Vertex( aShapes( i ) );
188     }
189
190     if ( !aPoint.IsNull() )
191     {
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()));
197     }
198   }
199   catch( ... )
200   {
201     myObj = GEOM::GEOM_Object::_nil();
202     mySelEdit->setText( "" );
203     myX->setText( "" );
204     myY->setText( "" );
205     myZ->setText( "" );
206   }
207 }