Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/geom.git] / src / MeasureGUI / MeasureGUI_PropertiesDlg.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 //
23 //
24 //  File   : MeasureGUI_PropertiesDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "MeasureGUI_PropertiesDlg.h"
30 #include "MeasureGUI_1Sel3LineEdit_QTD.h"
31 #include "GEOM_Displayer.h"
32 #include "GEOMImpl_Types.hxx"
33 #include "GEOMBase.h"
34
35 #include "SalomeApp_Tools.h"
36 #include "utilities.h"
37 #include "SUIT_Session.h"
38
39 #include <TColStd_MapOfInteger.hxx>
40
41 #include <qlineedit.h>
42 #include <qlabel.h>
43 #include <qlayout.h>
44 #include <qpushbutton.h>
45 #include <qradiobutton.h>
46 #include <qbuttongroup.h>
47
48 //=================================================================================
49 // class    : MeasureGUI_PropertiesDlg()
50 // purpose  : Constructs a MeasureGUI_PropertiesDlg which is a child of 'parent', with the 
51 //            name 'name' and widget flags set to 'f'.
52 //            The dialog will by default be modeless, unless you set 'modal' to
53 //            TRUE to construct a modal dialog.
54 //=================================================================================
55 MeasureGUI_PropertiesDlg::MeasureGUI_PropertiesDlg( GeometryGUI* GUI, QWidget* parent )
56 : MeasureGUI_Skeleton( GUI, parent, "MeasureGUI_PropertiesDlg" )
57 {
58   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
59     "GEOM",tr( "ICON_DLG_BASICPROPERTIES" ) ) );
60   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
61     "GEOM",tr( "ICON_SELECT" ) ) );
62
63   setCaption( tr( "GEOM_PROPERTIES_TITLE" ) );
64
65   /***************************************************************/
66   
67   GroupConstructors->setTitle( tr( "GEOM_PROPERTIES" ) );
68   RadioButton1->setPixmap( image0 );
69
70   myGrp = new MeasureGUI_1Sel3LineEdit_QTD( this, "myGrp"  );
71   myGrp->GroupBox1->setTitle( tr( "GEOM_PROPERTIES_CONSTR" ) );
72   myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
73   myGrp->TextLabel2->setText( tr( "GEOM_LENGTH" ) );
74   myGrp->TextLabel3->setText( tr( "GEOM_PROPERTIES_SURFACE" ) );
75   myGrp->TextLabel4->setText( tr( "GEOM_PROPERTIES_VOLUME" ) );
76   myGrp->LineEdit2->setReadOnly( TRUE );
77   myGrp->LineEdit3->setReadOnly( TRUE );
78   myGrp->LineEdit4->setReadOnly( TRUE );
79   myGrp->PushButton1->setPixmap( image1 );
80   myGrp->LineEdit1->setReadOnly( true );
81
82   Layout1->addWidget( myGrp, 1, 0 );
83   
84   /***************************************************************/
85
86   myHelpFileName = "files/salome2_sp3_measuregui_functions.htm#Basic_properties";
87
88   /* Initialisation */
89   Init();
90 }
91
92
93 //=================================================================================
94 // function : ~MeasureGUI_PropertiesDlg()
95 // purpose  : Destroys the object and frees any allocated resources
96 //=================================================================================
97 MeasureGUI_PropertiesDlg::~MeasureGUI_PropertiesDlg()
98 {
99 }
100
101
102 //=================================================================================
103 // function : Init()
104 // purpose  :
105 //=================================================================================
106 void MeasureGUI_PropertiesDlg::Init()
107 {
108   mySelBtn = myGrp->PushButton1;
109   mySelEdit = myGrp->LineEdit1;
110   MeasureGUI_Skeleton::Init();
111 }
112
113 //=================================================================================
114 // function : activateSelection
115 // purpose  :
116 //=================================================================================
117 void MeasureGUI_PropertiesDlg::activateSelection()
118 {
119   static TColStd_MapOfInteger aTypes;
120   if ( aTypes.IsEmpty() )
121   {
122     aTypes.Add( GEOM_COMPOUND );
123 //    aTypes.Add( TopAbs_COMPSOLID );
124     aTypes.Add( GEOM_SOLID );
125     aTypes.Add( GEOM_SHELL );
126     aTypes.Add( GEOM_FACE );
127     aTypes.Add( GEOM_WIRE );
128     aTypes.Add( GEOM_EDGE );
129   }
130
131   globalSelection( aTypes );
132 }
133
134 //=================================================================================
135 // function : processObject
136 // purpose  :
137 //=================================================================================
138 void MeasureGUI_PropertiesDlg::processObject()
139 {
140   double aLength, anArea, aVolume;
141   
142   if ( !getParameters( aLength, anArea, aVolume ) )
143   {
144     mySelEdit->setText( "" );
145     myGrp->LineEdit2->setText( "" );
146     myGrp->LineEdit3->setText( "" );
147     myGrp->LineEdit4->setText( "" );
148   }
149   else
150   {
151     myGrp->LineEdit2->setText( QString( "%1" ).arg( aLength ) );
152     myGrp->LineEdit3->setText( QString( "%1" ).arg( anArea ) );
153     myGrp->LineEdit4->setText( QString( "%1" ).arg( aVolume ) );
154   }
155 }
156
157 //=================================================================================
158 // function : getParameters
159 // purpose  :
160 //=================================================================================
161 bool MeasureGUI_PropertiesDlg::getParameters( double& theLength,
162                                               double& theArea,
163                                               double& theVolume )
164 {
165   if ( myObj->_is_nil() )
166     return false;
167   else
168   {
169     try
170     {
171       GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetBasicProperties(
172         myObj, theLength, theArea, theVolume );
173     }
174     catch( const SALOME::SALOME_Exception& e )
175     {
176       SalomeApp_Tools::QtCatchCorbaException( e );
177       return false;
178     }
179
180     return getOperation()->IsDone();
181   }
182 }
183
184 //=================================================================================
185 // function : createOperation
186 // purpose  :
187 //=================================================================================
188 SALOME_Prs* MeasureGUI_PropertiesDlg::buildPrs()
189 {
190   TopoDS_Shape aShape, aResult;
191   
192   if ( myObj->_is_nil() ||
193        !GEOMBase::GetShape( myObj, aShape )||
194        aShape.IsNull() ||
195        aShape.ShapeType() != TopAbs_EDGE ||
196        !GEOMBase::CreateArrowForLinearEdge( aShape, aResult ) ||
197        aResult.IsNull() )
198     return 0;
199
200   return getDisplayer()->BuildPrs( aResult );
201   
202 }
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223