]> SALOME platform Git repositories - modules/geom.git/blob - src/MeasureGUI/MeasureGUI_PointDlg.cxx
Salome HOME
SMH: Merged GEOM (NEWGUI, HEAD, POLYWORK)
[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 "GEOMBase.h"
31
32 #include "utilities.h"
33 #include "SUIT_Session.h"
34 #include "SalomeApp_Application.h"
35 #include "SalomeApp_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   Init();
103 }
104
105
106 //=================================================================================
107 // function : ~MeasureGUI_PointDlg()
108 // purpose  : Destroys the object and frees any allocated resources
109 //======================myX->setReadOnly( true );===========================================================
110 MeasureGUI_PointDlg::~MeasureGUI_PointDlg()
111 {
112 }
113
114
115 //=================================================================================
116 // function : Init()
117 // purpose  :
118 //=================================================================================
119 void MeasureGUI_PointDlg::Init()
120 {
121   QSize aSize( size() );
122   resize( (int)(aSize.width() *0.75 ), aSize.height() );
123   MeasureGUI_Skeleton::Init();
124 }
125
126 //=================================================================================
127 // function : activateSelection
128 // purpose  :
129 //=================================================================================
130 void MeasureGUI_PointDlg::activateSelection()
131 {
132   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
133 }
134
135 //=================================================================================
136 // function : SelectionIntoArgument
137 // purpose  :
138 //=================================================================================
139 void MeasureGUI_PointDlg::SelectionIntoArgument()
140 {
141   try
142   {
143     myObj = GEOM::GEOM_Object::_nil();
144     mySelEdit->setText( "" );
145     myX->setText( "" );
146     myY->setText( "" );
147     myZ->setText( "" );
148
149     Standard_Boolean testResult = Standard_False;
150     GEOM::GEOM_Object_var aSelectedObject =
151       GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
152
153     if( !testResult || aSelectedObject->_is_nil() )
154       return;
155
156     myObj = aSelectedObject;
157
158     TColStd_IndexedMapOfInteger anIndexes;
159     ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->
160       selectionMgr()->GetIndexes( firstIObject(), anIndexes );
161
162     TopoDS_Shape aShape;
163     if ( anIndexes.Extent() > 1 || !GEOMBase::GetShape( myObj, aShape ) || aShape.IsNull() )
164       return;
165
166     TopoDS_Vertex aPoint;
167     QString aName = GEOMBase::GetName( myObj );
168     if ( anIndexes.Extent() == 0 )
169     {
170       if ( aShape.ShapeType() == TopAbs_VERTEX )
171         aPoint = TopoDS::Vertex( aShape );
172     }
173     else
174     {
175       int i = anIndexes( 1 );
176
177       TopTools_IndexedMapOfShape aShapes;
178       TopExp::MapShapes( aShape, aShapes );
179       
180       if ( aShape != aShapes( i ) )
181         aName += QString( ":%1" ).arg( i );
182
183       aPoint = TopoDS::Vertex( aShapes( i ) );
184     }
185
186     if ( !aPoint.IsNull() )
187     {
188       gp_Pnt aPnt = BRep_Tool::Pnt( aPoint );
189       mySelEdit->setText( aName );
190       myX->setText( QString( "%1" ).arg( aPnt.X() ) );
191       myY->setText( QString( "%1" ).arg( aPnt.Y() ) );
192       myZ->setText( QString( "%1" ).arg( aPnt.Z() ) );
193     }
194   }
195   catch( ... )
196   {
197     myObj = GEOM::GEOM_Object::_nil();
198     mySelEdit->setText( "" );
199     myX->setText( "" );
200     myY->setText( "" );
201     myZ->setText( "" );
202   }
203 }
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223