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