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