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