Salome HOME
Merge with version on tag OCC-V2_1_0d
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
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 "utilities.h"
31 #include "QAD_Desktop.h"
32 #include "GEOMBase.h"
33
34 #include <TColStd_MapOfInteger.hxx>
35 #include <TopAbs_ShapeEnum.hxx>
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS.hxx>
38 #include <TopoDS_Vertex.hxx>
39 #include <BRep_Tool.hxx>
40 #include <TopExp.hxx>
41 #include <TopAbs_ShapeEnum.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <TColStd_IndexedMapOfInteger.hxx>
44 #include <gp_Pnt.hxx>
45
46 #include <qlineedit.h>
47 #include <qlabel.h>
48 #include <qlayout.h>
49 #include <qpushbutton.h>
50 #include <qgroupbox.h>
51 #include <qbuttongroup.h>
52 #include <qradiobutton.h>
53 #include <qapplication.h>
54
55 //=================================================================================
56 // class    : MeasureGUI_PointDlg()
57 // purpose  : Constructs a MeasureGUI_PointDlg which is a child of 'parent'
58 //            
59 //=================================================================================
60 MeasureGUI_PointDlg::MeasureGUI_PointDlg( QWidget* parent, SALOME_Selection* Sel )
61 : MeasureGUI_Skeleton( parent, "MeasureGUI_PointDlg", Sel )
62 {
63   QPixmap iconPnt( QAD_Desktop::getResourceManager()->loadPixmap(
64     "GEOM",tr( "ICON_DLG_POINT" ) ) );
65   
66   QPixmap iconSelect( QAD_Desktop::getResourceManager()->loadPixmap(
67     "GEOM",tr( "ICON_SELECT" ) ) );
68
69   setCaption( tr( "CAPTION" ) );
70
71   GroupConstructors->setTitle( tr( "CAPTION" ) );
72   RadioButton1->setPixmap( iconPnt );
73
74   QGroupBox* aGrp = new QGroupBox( 2, Qt::Horizontal, tr( "COORDINATES" ), this );
75   
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 );
84
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 );
91
92   mySelEdit->setReadOnly( true );
93   myX->setReadOnly( true );
94   myY->setReadOnly( true );
95   myZ->setReadOnly( true );
96
97   Layout1->addWidget( aGrp, 1, 0 );
98
99   Init( Sel );
100 }
101
102
103 //=================================================================================
104 // function : ~MeasureGUI_PointDlg()
105 // purpose  : Destroys the object and frees any allocated resources
106 //======================myX->setReadOnly( true );===========================================================
107 MeasureGUI_PointDlg::~MeasureGUI_PointDlg()
108 {
109 }
110
111
112 //=================================================================================
113 // function : Init()
114 // purpose  :
115 //=================================================================================
116 void MeasureGUI_PointDlg::Init( SALOME_Selection* Sel )
117 {
118   QSize aSize( size() );
119   resize( (int)(aSize.width() *0.75 ), aSize.height() );
120   MeasureGUI_Skeleton::Init( Sel );
121 }
122
123 //=================================================================================
124 // function : activateSelection
125 // purpose  :
126 //=================================================================================
127 void MeasureGUI_PointDlg::activateSelection()
128 {
129   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
130 }
131
132 //=================================================================================
133 // function : SelectionIntoArgument
134 // purpose  :
135 //=================================================================================
136 void MeasureGUI_PointDlg::SelectionIntoArgument()
137 {
138   try
139   {
140     myObj = GEOM::GEOM_Object::_nil();
141     mySelEdit->setText( "" );
142     myX->setText( "" );
143     myY->setText( "" );
144     myZ->setText( "" );
145
146     Standard_Boolean testResult = Standard_False;
147     GEOM::GEOM_Object_var aSelectedObject =
148       GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), testResult );
149
150     if( !testResult || aSelectedObject->_is_nil() )
151       return;
152
153     myObj = aSelectedObject;
154
155     TColStd_IndexedMapOfInteger anIndexes;
156     mySelection->GetIndex( mySelection->firstIObject(), anIndexes );
157
158     TopoDS_Shape aShape;
159     if ( anIndexes.Extent() > 1 || !GEOMBase::GetShape( myObj, aShape ) || aShape.IsNull() )
160       return;
161
162     TopoDS_Vertex aPoint;
163     QString aName = GEOMBase::GetName( myObj );
164     if ( anIndexes.Extent() == 0 )
165     {
166       if ( aShape.ShapeType() == TopAbs_VERTEX )
167         aPoint = TopoDS::Vertex( aShape );
168     }
169     else
170     {
171       int i = anIndexes( 1 );
172
173       TopTools_IndexedMapOfShape aShapes;
174       TopExp::MapShapes( aShape, aShapes );
175       
176       if ( aShape != aShapes( i ) )
177         aName += QString( ":%1" ).arg( i );
178
179       aPoint = TopoDS::Vertex( aShapes( i ) );
180     }
181
182     if ( !aPoint.IsNull() )
183     {
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() ) );
189     }
190   }
191   catch( ... )
192   {
193     myObj = GEOM::GEOM_Object::_nil();
194     mySelEdit->setText( "" );
195     myX->setText( "" );
196     myY->setText( "" );
197     myZ->setText( "" );
198   }
199 }
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219