Salome HOME
Merge remote branch 'origin/eap/23307'
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_StdWidget.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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.0, COORD_MAX, 0.1, "length_precision");
47   myVolumeGradation->RangeStepAndValidator(1.0, COORD_MAX, 0.1, "length_precision");
48   myAngleMesh->RangeStepAndValidator(0, 90, 0.5, "angular_precision");
49   myChordalError->RangeStepAndValidator(0, COORD_MAX, 0.1, "length_precision");
50   myAnisotropicRatio->RangeStepAndValidator(0, COORD_MAX, 0.1, "length_precision");
51   myTinyEdgeLength->RangeStepAndValidator(0, COORD_MAX, 0.1, "length_precision");
52   myTinyEdgeOptimisLength->RangeStepAndValidator(0, COORD_MAX, 0.1, "length_precision");
53   myCorrectSurfaceIntersectionMaxCost->RangeStepAndValidator(0, COORD_MAX, 1);
54   myBadElementAspectRatio->RangeStepAndValidator(0, COORD_MAX, 1000, "length_precision");
55   myMinSize->setText("");
56   myMaxSize->setText("");
57   myAngleMesh->setText("");
58   myChordalError->setText("");
59   myAnisotropicRatio->setText("");
60   myTinyEdgeLength->setText("");
61   myTinyEdgeOptimisLength->setText("");
62   myCorrectSurfaceIntersectionMaxCost->setText("");
63   myBadElementAspectRatio->setText("");
64 }
65
66 BLSURFPluginGUI_StdWidget::~BLSURFPluginGUI_StdWidget()
67 {
68 }
69
70 void BLSURFPluginGUI_StdWidget::onPhysicalMeshChanged() {
71   bool isPhysicalGlobalSize = (myPhysicalMesh->currentIndex() == PhysicalGlobalSize);
72   bool isPhysicalLocalSize  = (myPhysicalMesh->currentIndex() == PhysicalLocalSize);
73   bool isCustom             = (isPhysicalGlobalSize || isPhysicalLocalSize) ;
74
75   myPhySize->setEnabled(isCustom);
76   myPhySizeRel->setEnabled(isCustom);
77 }
78
79 void BLSURFPluginGUI_StdWidget::onGeometricMeshChanged() {
80   bool isCustom            = (myGeometricMesh->currentIndex() != DefaultGeom);
81
82   myAngleMesh->setEnabled( isCustom );
83   myChordalError->setEnabled( isCustom );
84
85 }
86
87 void BLSURFPluginGUI_StdWidget::resizeWidgets() {
88   // Set minimum width of spin boxes
89   // Main parameters
90   QFontMetrics metrics1( myPhySize->font() );
91   QFontMetrics metrics2( myMinSize->font() );
92   QFontMetrics metrics3( myMaxSize->font() );
93   int width1 = metrics1.width(myPhySize->GetString());
94   int width2 = metrics2.width(myMinSize->GetString());
95   int width3 = metrics3.width(myMaxSize->GetString());
96   int max_width = max(width1,width2);
97   max_width = max(max_width, width3);
98   myPhySize->setMinimumWidth( max_width+50 );
99   myMinSize->setMinimumWidth( max_width+50 );
100   myMaxSize->setMinimumWidth( max_width+50 );
101    // Geometrical parameters
102   metrics1 = QFontMetrics(myAngleMesh->font());
103   metrics2 = QFontMetrics(myChordalError->font());
104   width1 = metrics1.width(myAngleMesh->GetString());
105   width2 = metrics2.width(myChordalError->GetString());
106   max_width = max(width1,width2); 
107   myAngleMesh->setMinimumWidth( max_width+50 );
108   myChordalError->setMinimumWidth( max_width+50 );
109   // Other parameters
110   metrics1 = QFontMetrics(myAnisotropicRatio->font());
111   metrics2 = QFontMetrics(myTinyEdgeLength->font());
112   metrics3 = QFontMetrics(myBadElementAspectRatio->font());
113   width1 = metrics1.width(myAnisotropicRatio->GetString());
114   width2 = metrics2.width(myTinyEdgeLength->GetString());
115   width3 = metrics3.width(myBadElementAspectRatio->GetString());
116   max_width = max(width1,width2); 
117   max_width = max(max_width, width3);
118   myAnisotropicRatio->setMinimumWidth( max_width+50 );
119   myTinyEdgeLength->setMinimumWidth( max_width+50 );
120   myBadElementAspectRatio->setMinimumWidth( max_width+50 );
121 }
122
123 void BLSURFPluginGUI_StdWidget::onEditingFinished() {
124   SMESHGUI_SpinBox* spinBox = (SMESHGUI_SpinBox*)sender();
125   bool isEmpty = spinBox->editor()->text().isEmpty();
126   if ( isEmpty ) {
127     spinBox->SetValue(-1);
128     spinBox->setText("");
129   }
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152