Salome HOME
Copyrights update
[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 "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   /* Initialisation */
87   Init();
88 }
89
90
91 //=================================================================================
92 // function : ~MeasureGUI_PropertiesDlg()
93 // purpose  : Destroys the object and frees any allocated resources
94 //=================================================================================
95 MeasureGUI_PropertiesDlg::~MeasureGUI_PropertiesDlg()
96 {
97 }
98
99
100 //=================================================================================
101 // function : Init()
102 // purpose  :
103 //=================================================================================
104 void MeasureGUI_PropertiesDlg::Init()
105 {
106   mySelBtn = myGrp->PushButton1;
107   mySelEdit = myGrp->LineEdit1;
108   MeasureGUI_Skeleton::Init();
109 }
110
111 //=================================================================================
112 // function : activateSelection
113 // purpose  :
114 //=================================================================================
115 void MeasureGUI_PropertiesDlg::activateSelection()
116 {
117   static TColStd_MapOfInteger aTypes;
118   if ( aTypes.IsEmpty() )
119   {
120     aTypes.Add( GEOM_COMPOUND );
121 //    aTypes.Add( TopAbs_COMPSOLID );
122     aTypes.Add( GEOM_SOLID );
123     aTypes.Add( GEOM_SHELL );
124     aTypes.Add( GEOM_FACE );
125     aTypes.Add( GEOM_WIRE );
126     aTypes.Add( GEOM_EDGE );
127   }
128
129   globalSelection( aTypes );
130 }
131
132 //=================================================================================
133 // function : processObject
134 // purpose  :
135 //=================================================================================
136 void MeasureGUI_PropertiesDlg::processObject()
137 {
138   double aLength, anArea, aVolume;
139   
140   if ( !getParameters( aLength, anArea, aVolume ) )
141   {
142     mySelEdit->setText( "" );
143     myGrp->LineEdit2->setText( "" );
144     myGrp->LineEdit3->setText( "" );
145     myGrp->LineEdit4->setText( "" );
146   }
147   else
148   {
149     myGrp->LineEdit2->setText( QString( "%1" ).arg( aLength ) );
150     myGrp->LineEdit3->setText( QString( "%1" ).arg( anArea ) );
151     myGrp->LineEdit4->setText( QString( "%1" ).arg( aVolume ) );
152   }
153 }
154
155 //=================================================================================
156 // function : getParameters
157 // purpose  :
158 //=================================================================================
159 bool MeasureGUI_PropertiesDlg::getParameters( double& theLength,
160                                               double& theArea,
161                                               double& theVolume )
162 {
163   if ( myObj->_is_nil() )
164     return false;
165   else
166   {
167     try
168     {
169       GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetBasicProperties(
170         myObj, theLength, theArea, theVolume );
171     }
172     catch( const SALOME::SALOME_Exception& e )
173     {
174       SalomeApp_Tools::QtCatchCorbaException( e );
175       return false;
176     }
177
178     return getOperation()->IsDone();
179   }
180 }
181
182 //=================================================================================
183 // function : createOperation
184 // purpose  :
185 //=================================================================================
186 SALOME_Prs* MeasureGUI_PropertiesDlg::buildPrs()
187 {
188   TopoDS_Shape aShape, aResult;
189   
190   if ( myObj->_is_nil() ||
191        !GEOMBase::GetShape( myObj, aShape )||
192        aShape.IsNull() ||
193        aShape.ShapeType() != TopAbs_EDGE ||
194        !GEOMBase::CreateArrowForLinearEdge( aShape, aResult ) ||
195        aResult.IsNull() )
196     return 0;
197
198   return getDisplayer()->BuildPrs( aResult );
199   
200 }
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221