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