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