Salome HOME
Merge from V6_main 01/04/2013
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_StdWidget.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // ---
21 // File    : BLSURFPluginGUI_StdWidget.cxx
22 // Authors : Gilles DAVID (OCC)
23 // ---
24 //
25
26 #include "BLSURFPluginGUI_Dlg.h"
27
28 #include "SMESHGUI_SpinBox.h"
29
30 #include <algorithm>
31 #include <iostream>
32
33 using namespace std;
34
35 //////////////////////////////////////////
36 // BLSURFPluginGUI_StdWidget
37 //////////////////////////////////////////
38
39 BLSURFPluginGUI_StdWidget::BLSURFPluginGUI_StdWidget( QWidget* parent, Qt::WindowFlags f )
40 : QWidget( parent, f )
41 {
42   setupUi( this );
43   myPhySize->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
44   myMinSize->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
45   myMaxSize->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision");
46   myGradation->RangeStepAndValidator(1.1, COORD_MAX, 0.1, "length_precision");
47   myAngleMesh->RangeStepAndValidator(0, 90, 0.5, "angular_precision");
48   myChordalError->RangeStepAndValidator(0, COORD_MAX, 0.1, "length_precision");
49   myAnisotropicRatio->RangeStepAndValidator(0, COORD_MAX, 0.1, "length_precision");
50   myTinyEdgeLength->RangeStepAndValidator(COORD_MIN, COORD_MAX, 0.1, "length_precision");
51   myBadElementAspectRatio->RangeStepAndValidator(0, COORD_MAX, 1000, "length_precision");
52   myMinSize->setText("");
53   myMaxSize->setText("");
54   myAngleMesh->setText("");
55   myChordalError->setText("");
56   myAnisotropicRatio->setText("");
57   myTinyEdgeLength->setText("");
58   myBadElementAspectRatio->setText("");
59 }
60
61 BLSURFPluginGUI_StdWidget::~BLSURFPluginGUI_StdWidget()
62 {
63 }
64
65 void BLSURFPluginGUI_StdWidget::onPhysicalMeshChanged() {
66   bool isPhysicalGlobalSize = (myPhysicalMesh->currentIndex() == PhysicalGlobalSize);
67   bool isPhysicalLocalSize = (myPhysicalMesh->currentIndex() == PhysicalLocalSize);
68   bool isCustom = (isPhysicalGlobalSize || isPhysicalLocalSize) ;
69   bool geomIsCustom = (myGeometricMesh->currentIndex() != DefaultGeom);
70
71   myGradation->setEnabled(!isPhysicalGlobalSize || geomIsCustom);
72   myPhySize->setEnabled(isCustom);
73   myPhySizeRel->setEnabled(isCustom);
74
75   if ( !isCustom ) {
76     if ( myGeometricMesh->currentIndex() == DefaultGeom ) {
77       myGeometricMesh->setCurrentIndex( GeometricalGlobalSize );
78       onGeometricMeshChanged();
79     }
80   }
81 }
82
83 void BLSURFPluginGUI_StdWidget::onGeometricMeshChanged() {
84   bool isCustom = (myGeometricMesh->currentIndex() != DefaultGeom);
85   bool isPhysicalLocalSize = (myPhysicalMesh->currentIndex() == PhysicalLocalSize);
86
87   GeomParamsGroupBox->setEnabled(isCustom);
88   myGradation->setEnabled(isCustom || isPhysicalLocalSize);
89
90   if ( ! isCustom ) {
91     //  hphy_flag = 0 and hgeo_flag = 0 is not allowed (spec)
92     if ( myPhysicalMesh->currentIndex() == DefaultSize ) {
93       myPhysicalMesh->setCurrentIndex( PhysicalGlobalSize );
94       onPhysicalMeshChanged();
95     }
96   }
97 }
98
99 void BLSURFPluginGUI_StdWidget::resizeWidgets() {
100   // Set minimum width of spin boxes
101   // Main parameters
102   QFontMetrics metrics1( myPhySize->font() );
103   QFontMetrics metrics2( myMinSize->font() );
104   QFontMetrics metrics3( myMaxSize->font() );
105   int width1 = metrics1.width(myPhySize->GetString());
106   int width2 = metrics2.width(myMinSize->GetString());
107   int width3 = metrics3.width(myMaxSize->GetString());
108   int max_width = max(width1,width2);
109   max_width = max(max_width, width3);
110   myPhySize->setMinimumWidth( max_width+50 );
111   myMinSize->setMinimumWidth( max_width+50 );
112   myMaxSize->setMinimumWidth( max_width+50 );
113    // Geometrical parameters
114   metrics1 = myAngleMesh->font();
115   metrics2 = myChordalError->font();
116   width1 = metrics1.width(myAngleMesh->GetString());
117   width2 = metrics2.width(myChordalError->GetString());
118   max_width = max(width1,width2); 
119   myAngleMesh->setMinimumWidth( max_width+50 );
120   myChordalError->setMinimumWidth( max_width+50 );
121   // Other parameters
122   metrics1 = myAnisotropicRatio->font();
123   metrics2 = myTinyEdgeLength->font();
124   metrics3 = myBadElementAspectRatio->font();
125   width1 = metrics1.width(myAnisotropicRatio->GetString());
126   width2 = metrics2.width(myTinyEdgeLength->GetString());
127   width3 = metrics3.width(myBadElementAspectRatio->GetString());
128   max_width = max(width1,width2); 
129   max_width = max(max_width, width3);
130   myAnisotropicRatio->setMinimumWidth( max_width+50 );
131   myTinyEdgeLength->setMinimumWidth( max_width+50 );
132   myBadElementAspectRatio->setMinimumWidth( max_width+50 );
133 }
134
135 void BLSURFPluginGUI_StdWidget::onEditingFinished() {
136   SMESHGUI_SpinBox* spinBox = (SMESHGUI_SpinBox*)sender();
137   bool isEmpty = spinBox->editor()->text().isEmpty();
138   if ( isEmpty ) {
139     spinBox->SetValue(-1);
140     spinBox->setText("");
141   }
142 }
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164