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