Salome HOME
Bug IPAL19097 NPAL16768 is not implemented for "Normal to a face"
[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 // File   : MeasureGUI_PointDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
24 //
25
26 #include "MeasureGUI_PointDlg.h"
27 #include "MeasureGUI_Widgets.h"
28
29 #include <GEOMBase.h>
30 #include <DlgRef.h>
31
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36
37 #include <TopoDS_Shape.hxx>
38 #include <TopoDS.hxx>
39 #include <TopoDS_Vertex.hxx>
40 #include <BRep_Tool.hxx>
41 #include <TopExp.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <TColStd_IndexedMapOfInteger.hxx>
44 #include <gp_Pnt.hxx>
45
46 //=================================================================================
47 // class    : MeasureGUI_PointDlg()
48 // purpose  : Constructs a MeasureGUI_PointDlg which is a child of 'parent'
49 //            
50 //=================================================================================
51 MeasureGUI_PointDlg::MeasureGUI_PointDlg( GeometryGUI* GUI, QWidget* parent )
52   : MeasureGUI_Skeleton( GUI, parent )
53 {
54   QPixmap iconPnt( SUIT_Session::session()->resourceMgr()->loadPixmap(
55     "GEOM", tr( "ICON_DLG_POINT" ) ) );
56   
57   QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap(
58     "GEOM", tr( "ICON_SELECT" ) ) );
59
60   setWindowTitle( tr( "CAPTION" ) );
61
62   mainFrame()->GroupConstructors->setTitle( tr( "CAPTION" ) );
63   mainFrame()->RadioButton1->setIcon( iconPnt );
64
65   myGrp = new MeasureGUI_1Sel3LineEdit( centralWidget() );
66   myGrp->TextLabel1->setText( tr( "POINT" ) );
67   myGrp->PushButton1->setIcon( iconSelect );
68   myGrp->LineEdit1->setReadOnly( true );
69   myGrp->TextLabel2->setText( tr( "X" ) );
70   myGrp->TextLabel3->setText( tr( "Y" ) );
71   myGrp->TextLabel4->setText( tr( "Z" ) );
72   myGrp->LineEdit2->setReadOnly( true );
73   myGrp->LineEdit3->setReadOnly( true );
74   myGrp->LineEdit4->setReadOnly( true );
75
76   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
77   layout->setMargin( 0 ); layout->setSpacing( 6 );
78   layout->addWidget( myGrp );
79
80   myHelpFileName = "using_measurement_tools_page.html#point_coord_anchor";
81
82   Init();
83 }
84
85
86 //=================================================================================
87 // function : ~MeasureGUI_PointDlg()
88 // purpose  : Destroys the object and frees any allocated resources
89 //======================myGrp->LineEdit2->setReadOnly( true );===========================================================
90 MeasureGUI_PointDlg::~MeasureGUI_PointDlg()
91 {
92 }
93
94
95 //=================================================================================
96 // function : Init()
97 // purpose  :
98 //=================================================================================
99 void MeasureGUI_PointDlg::Init()
100 {
101   QSize aSize( size() );
102   resize( (int)(aSize.width() *0.75 ), aSize.height() );
103   MeasureGUI_Skeleton::Init();
104 }
105
106 //=================================================================================
107 // function : activateSelection
108 // purpose  :
109 //=================================================================================
110 void MeasureGUI_PointDlg::activateSelection()
111 {
112   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
113 }
114
115 //=================================================================================
116 // function : SelectionIntoArgument
117 // purpose  :
118 //=================================================================================
119 void MeasureGUI_PointDlg::SelectionIntoArgument()
120 {
121   try {
122     myObj = GEOM::GEOM_Object::_nil();
123     myGrp->LineEdit1->setText( "" );
124     myGrp->LineEdit2->setText( "" );
125     myGrp->LineEdit3->setText( "" );
126     myGrp->LineEdit4->setText( "" );
127
128     Standard_Boolean testResult = Standard_False;
129     GEOM::GEOM_Object_var aSelectedObject =
130       GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
131
132     if ( !testResult || aSelectedObject->_is_nil() )
133       return;
134
135     myObj = aSelectedObject;
136
137     TColStd_IndexedMapOfInteger anIndexes;
138     ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->
139       selectionMgr()->GetIndexes( firstIObject(), anIndexes );
140
141     TopoDS_Shape aShape;
142     if ( anIndexes.Extent() > 1 || !GEOMBase::GetShape( myObj, aShape ) || aShape.IsNull() )
143       return;
144
145     TopoDS_Vertex aPoint;
146     QString aName = GEOMBase::GetName( myObj );
147     if ( anIndexes.Extent() == 0 ) {
148       if ( aShape.ShapeType() == TopAbs_VERTEX )
149         aPoint = TopoDS::Vertex( aShape );
150     }
151     else {
152       int i = anIndexes( 1 );
153
154       TopTools_IndexedMapOfShape aShapes;
155       TopExp::MapShapes( aShape, aShapes );
156       
157       if ( aShape != aShapes( i ) )
158         aName += QString( ":%1" ).arg( i );
159
160       aPoint = TopoDS::Vertex( aShapes( i ) );
161     }
162
163     if ( !aPoint.IsNull() ) {
164       gp_Pnt aPnt = BRep_Tool::Pnt( aPoint );
165       myGrp->LineEdit1->setText( aName );
166       myGrp->LineEdit2->setText( DlgRef::PrintDoubleValue( aPnt.X() ) );
167       myGrp->LineEdit3->setText( DlgRef::PrintDoubleValue( aPnt.Y() ) );
168       myGrp->LineEdit4->setText( DlgRef::PrintDoubleValue( aPnt.Z() ) );
169     }
170   }
171   catch( ... )
172   {
173     myObj = GEOM::GEOM_Object::_nil();
174     myGrp->LineEdit1->setText( "" );
175     myGrp->LineEdit2->setText( "" );
176     myGrp->LineEdit3->setText( "" );
177     myGrp->LineEdit4->setText( "" );
178   }
179 }