Salome HOME
Update from BR_V5_DEV 13Feb2009
[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, Open CASCADE S.A.S.
25 //
26 #include "MeasureGUI_PointDlg.h"
27 #include "MeasureGUI_Widgets.h"
28
29 #include <GEOMBase.h>
30 #include <DlgRef.h>
31
32 #include <GeometryGUI.h>
33
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38
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 <TopTools_IndexedMapOfShape.hxx>
45 #include <TColStd_IndexedMapOfInteger.hxx>
46 #include <gp_Pnt.hxx>
47
48 //=================================================================================
49 // class    : MeasureGUI_PointDlg()
50 // purpose  : Constructs a MeasureGUI_PointDlg which is a child of 'parent'
51 //            
52 //=================================================================================
53 MeasureGUI_PointDlg::MeasureGUI_PointDlg( GeometryGUI* GUI, QWidget* parent )
54   : MeasureGUI_Skeleton( GUI, parent )
55 {
56   QPixmap iconPnt( SUIT_Session::session()->resourceMgr()->loadPixmap(
57     "GEOM", tr( "ICON_DLG_POINT" ) ) );
58   
59   QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap(
60     "GEOM", tr( "ICON_SELECT" ) ) );
61
62   setWindowTitle( tr( "CAPTION" ) );
63
64   mainFrame()->GroupConstructors->setTitle( tr( "CAPTION" ) );
65   mainFrame()->RadioButton1->setIcon( iconPnt );
66
67   myGrp = new MeasureGUI_1Sel3LineEdit( centralWidget() );
68   myGrp->TextLabel1->setText( tr( "POINT" ) );
69   myGrp->PushButton1->setIcon( iconSelect );
70   myGrp->LineEdit1->setReadOnly( true );
71   myGrp->TextLabel2->setText( tr( "X" ) );
72   myGrp->TextLabel3->setText( tr( "Y" ) );
73   myGrp->TextLabel4->setText( tr( "Z" ) );
74   myGrp->LineEdit2->setReadOnly( true );
75   myGrp->LineEdit3->setReadOnly( true );
76   myGrp->LineEdit4->setReadOnly( true );
77
78   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
79   layout->setMargin( 0 ); layout->setSpacing( 6 );
80   layout->addWidget( myGrp );
81
82   myHelpFileName = "using_measurement_tools_page.html#point_coord_anchor";
83
84   Init();
85 }
86
87
88 //=================================================================================
89 // function : ~MeasureGUI_PointDlg()
90 // purpose  : Destroys the object and frees any allocated resources
91 //======================myGrp->LineEdit2->setReadOnly( true );===========================================================
92 MeasureGUI_PointDlg::~MeasureGUI_PointDlg()
93 {
94 }
95
96
97 //=================================================================================
98 // function : Init()
99 // purpose  :
100 //=================================================================================
101 void MeasureGUI_PointDlg::Init()
102 {
103   QSize aSize( size() );
104   resize( (int)(aSize.width() *0.75 ), aSize.height() );
105   MeasureGUI_Skeleton::Init();
106 }
107
108 //=================================================================================
109 // function : activateSelection
110 // purpose  :
111 //=================================================================================
112 void MeasureGUI_PointDlg::activateSelection()
113 {
114   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
115 }
116
117 //=================================================================================
118 // function : SelectionIntoArgument
119 // purpose  :
120 //=================================================================================
121 void MeasureGUI_PointDlg::SelectionIntoArgument()
122 {
123   try {
124     myObj = GEOM::GEOM_Object::_nil();
125     myGrp->LineEdit1->setText( "" );
126     myGrp->LineEdit2->setText( "" );
127     myGrp->LineEdit3->setText( "" );
128     myGrp->LineEdit4->setText( "" );
129
130     LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
131     SALOME_ListIO aSelList;
132     aSelMgr->selectedObjects(aSelList);
133
134     if (aSelList.Extent() < 1)
135       return;
136
137     Standard_Boolean testResult = Standard_False;
138     GEOM::GEOM_Object_var aSelectedObject =
139       GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
140
141     if (!testResult || 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       myGrp->LineEdit2->setText( DlgRef::PrintDoubleValue( aPnt.X() ) );
175       myGrp->LineEdit3->setText( DlgRef::PrintDoubleValue( aPnt.Y() ) );
176       myGrp->LineEdit4->setText( DlgRef::PrintDoubleValue( aPnt.Z() ) );
177     }
178   }
179   catch( ... )
180   {
181     myObj = GEOM::GEOM_Object::_nil();
182     myGrp->LineEdit1->setText( "" );
183     myGrp->LineEdit2->setText( "" );
184     myGrp->LineEdit3->setText( "" );
185     myGrp->LineEdit4->setText( "" );
186   }
187 }