Salome HOME
Merge branch occ/shape_reparation_2
[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 = "basic_prop_page.html";
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   std::list<int> needTypes;
127   needTypes.push_back( TopAbs_EDGE ), needTypes.push_back( TopAbs_WIRE ), needTypes.push_back( TopAbs_FACE ), needTypes.push_back( TopAbs_SHELL ), needTypes.push_back( TopAbs_SOLID ), needTypes.push_back( TopAbs_COMPOUND );
128   localSelection(GEOM::GEOM_Object::_nil(), needTypes );
129 }
130
131 void MeasureGUI_PropertiesDlg::SelectionIntoArgument()
132 {
133   myObj.nullify();
134   QList<TopAbs_ShapeEnum> aTypes;
135   aTypes << TopAbs_EDGE << TopAbs_WIRE << TopAbs_FACE << TopAbs_SHELL << TopAbs_SOLID << TopAbs_COMPOUND;
136   myObj = getSelected( aTypes );
137  
138   if (!myObj) {
139     mySelEdit->setText("");
140     processObject();
141     erasePreview();
142     return;
143   }
144
145   mySelEdit->setText(GEOMBase::GetName(myObj.get()));
146   processObject();
147   redisplayPreview();
148 }
149 //=================================================================================
150 // function : processObject
151 // purpose  :
152 //=================================================================================
153 void MeasureGUI_PropertiesDlg::processObject()
154 {
155   double aLength, anArea, aVolume;
156   
157   if ( !getParameters( aLength, anArea, aVolume ) ) {
158     mySelEdit->setText( "" );
159     myGrp->LineEdit2->setText( "" );
160     myGrp->LineEdit3->setText( "" );
161     myGrp->LineEdit4->setText( "" );
162   }
163   else {
164     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
165     int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
166     myGrp->LineEdit2->setText( DlgRef::PrintDoubleValue( aLength, aPrecision ) );
167     myGrp->LineEdit3->setText( DlgRef::PrintDoubleValue( anArea,  aPrecision ) );
168     myGrp->LineEdit4->setText( DlgRef::PrintDoubleValue( aVolume, aPrecision ) );
169   }
170 }
171
172 //=================================================================================
173 // function : getParameters
174 // purpose  :
175 //=================================================================================
176 bool MeasureGUI_PropertiesDlg::getParameters( double& theLength,
177                                               double& theArea,
178                                               double& theVolume )
179 {
180   if ( !myObj )
181     return false;
182   else {
183     GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
184     try {
185       anOper->GetBasicProperties( myObj.get(), theLength, theArea, theVolume );
186     }
187     catch( const SALOME::SALOME_Exception& e ) {
188       SalomeApp_Tools::QtCatchCorbaException( e );
189       return false;
190     }
191
192     return anOper->IsDone();
193   }
194 }
195
196 //=================================================================================
197 // function : createOperation
198 // purpose  :
199 //=================================================================================
200 SALOME_Prs* MeasureGUI_PropertiesDlg::buildPrs()
201 {
202   SALOME_Prs* prs = 0;
203   TopoDS_Shape shape;
204
205   if ( GEOMBase::GetShape( myObj.get(), shape, TopAbs_EDGE ) &&
206        getDisplayer()->IsDisplayed( GEOMBase::GetEntry(myObj.get()) ) ) {
207     shape = GEOMBase::CreateArrowForLinearEdge( shape );
208     if ( !shape.IsNull() )
209       prs = getDisplayer()->BuildPrs( shape );
210   }
211   return prs;
212 }