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