Salome HOME
9375f929b94a3e717c508bbc79a0ac84c211837e
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_StdWidget.cxx
1 // Copyright (C) 2007-2023  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   mySurfaceProximityRatio->RangeStepAndValidator(1, COORD_MAX, 1, "length_precision");
56   myVolumeProximityRatio->RangeStepAndValidator(1, COORD_MAX, 1, "length_precision");
57   myMinSize->setText("");
58   myMaxSize->setText("");
59   myAngleMesh->setText("");
60   myChordalError->setText("");
61   myAnisotropicRatio->setText("");
62   myTinyEdgeLength->setText("");
63   myTinyEdgeOptimisLength->setText("");
64   myCorrectSurfaceIntersectionMaxCost->setText("");
65   myBadElementAspectRatio->setText("");
66   myButtonGroupElementType->setId(myRadioButtonTriangles, Triangles);
67   myButtonGroupElementType->setId(myRadioButtonQuadrangleDominant, QuadrangleDominant);
68   myButtonGroupElementType->setId(myRadioButtonQuadrangles, Quadrangles);
69 }
70
71 BLSURFPluginGUI_StdWidget::~BLSURFPluginGUI_StdWidget()
72 {
73 }
74
75 void BLSURFPluginGUI_StdWidget::onPhysicalMeshChanged() {
76   bool isPhysicalGlobalSize = (myPhysicalMesh->currentIndex() == PhysicalGlobalSize);
77   bool isPhysicalLocalSize  = (myPhysicalMesh->currentIndex() == PhysicalLocalSize);
78   bool isCustom             = (isPhysicalGlobalSize || isPhysicalLocalSize) ;
79
80   myPhySize->setEnabled(isCustom);
81   myPhySizeRel->setEnabled(isCustom);
82 }
83
84 void BLSURFPluginGUI_StdWidget::onGeometricMeshChanged() {
85   bool isCustom            = (myGeometricMesh->currentIndex() != DefaultGeom);
86
87   myAngleMesh->setEnabled( isCustom );
88   myChordalError->setEnabled( isCustom );
89
90 }
91
92 void BLSURFPluginGUI_StdWidget::resizeWidgets() {
93   // Set minimum width of spin boxes
94   // Main parameters
95   QFontMetrics metrics1( myPhySize->font() );
96   QFontMetrics metrics2( myMinSize->font() );
97   QFontMetrics metrics3( myMaxSize->font() );
98   int width1 = metrics1.width(myPhySize->GetString());
99   int width2 = metrics2.width(myMinSize->GetString());
100   int width3 = metrics3.width(myMaxSize->GetString());
101   int max_width = max(width1,width2);
102   max_width = max(max_width, width3);
103   myPhySize->setMinimumWidth( max_width+50 );
104   myMinSize->setMinimumWidth( max_width+50 );
105   myMaxSize->setMinimumWidth( max_width+50 );
106    // Geometrical parameters
107   metrics1 = QFontMetrics(myAngleMesh->font());
108   metrics2 = QFontMetrics(myChordalError->font());
109   width1 = metrics1.width(myAngleMesh->GetString());
110   width2 = metrics2.width(myChordalError->GetString());
111   max_width = max(width1,width2); 
112   myAngleMesh->setMinimumWidth( max_width+50 );
113   myChordalError->setMinimumWidth( max_width+50 );
114   // Other parameters
115   metrics1 = QFontMetrics(myAnisotropicRatio->font());
116   metrics2 = QFontMetrics(myTinyEdgeLength->font());
117   metrics3 = QFontMetrics(myBadElementAspectRatio->font());
118   width1 = metrics1.width(myAnisotropicRatio->GetString());
119   width2 = metrics2.width(myTinyEdgeLength->GetString());
120   width3 = metrics3.width(myBadElementAspectRatio->GetString());
121   max_width = max(width1,width2); 
122   max_width = max(max_width, width3);
123   myAnisotropicRatio->setMinimumWidth( max_width+50 );
124   myTinyEdgeLength->setMinimumWidth( max_width+50 );
125   myBadElementAspectRatio->setMinimumWidth( max_width+50 );
126 }
127
128 void BLSURFPluginGUI_StdWidget::onEditingFinished() {
129   SMESHGUI_SpinBox* spinBox = (SMESHGUI_SpinBox*)sender();
130   bool isEmpty = spinBox->editor()->text().isEmpty();
131   if ( isEmpty ) {
132     spinBox->SetValue(-1);
133     spinBox->setText("");
134   }
135 }