From 6b471bcc54cbeb90f0d977323db8c76d3d2cce09 Mon Sep 17 00:00:00 2001 From: jfa Date: Wed, 28 Dec 2005 09:17:39 +0000 Subject: [PATCH] Join modifications from branch BR_3_1_0deb --- INSTALL | 10 +- bin/VERSION | 2 +- build_configure | 2 +- doc/salome/tui/SMESH/doxyfile | 2 +- doc/salome/tui/SMESH/doxyfile_py | 2 +- doc/salome/tui/SMESH/sources/static/tree.js | 2 +- idl/SMESH_BasicHypothesis.idl | 17 +- resources/SMESHCatalog.xml | 2 +- src/Controls/SMESH_Controls.cxx | 75 +- src/SMESHGUI/Makefile.in | 18 +- src/SMESHGUI/SMESHGUI.cxx | 4 +- src/SMESHGUI/SMESHGUI_CreateHypothesesDlg.cxx | 9 +- src/SMESHGUI/SMESHGUI_FunctionPreview.cxx | 271 ---- src/SMESHGUI/SMESHGUI_FunctionPreview.h | 73 -- src/SMESHGUI/SMESHGUI_Hypotheses.cxx | 336 +++++ src/SMESHGUI/SMESHGUI_Hypotheses.h | 86 +- src/SMESHGUI/SMESHGUI_HypothesesUtils.cxx | 4 +- src/SMESHGUI/SMESHGUI_MeshOp.cxx | 13 +- src/SMESHGUI/SMESHGUI_aParameter.cxx | 1108 ----------------- src/SMESHGUI/SMESHGUI_aParameterDlg.cxx | 305 ----- src/SMESHGUI/SMESHGUI_aParameterDlg.h | 87 -- src/SMESH_SWIG/SMESH_reg.py | 4 +- src/StdMeshers/Makefile.in | 3 +- src/StdMeshers/StdMeshers_Distribution.cxx | 342 +++++ src/StdMeshers/StdMeshers_Distribution.hxx | 113 ++ .../StdMeshers_NumberOfSegments.cxx | 118 +- .../StdMeshers_NumberOfSegments.hxx | 23 +- src/StdMeshers/StdMeshers_Regular_1D.cxx | 322 +---- src/StdMeshers/StdMeshers_Regular_1D.hxx | 2 +- src/StdMeshersGUI/Makefile.in | 28 +- src/StdMeshersGUI/StdMeshersGUI.cxx | 157 +-- .../StdMeshersGUI_CreateHypothesisDlg.cxx | 471 ------- .../StdMeshersGUI_CreateHypothesisDlg.h | 123 -- .../StdMeshersGUI_CreateStdHypothesisDlg.h | 59 - .../StdMeshersGUI_DistrPreview.cxx | 358 ++++++ .../StdMeshersGUI_DistrPreview.h | 59 + .../StdMeshersGUI_DistrTable.cxx | 348 ++++++ src/StdMeshersGUI/StdMeshersGUI_DistrTable.h | 127 ++ .../StdMeshersGUI_NbSegmentsCreator.cxx | 307 +++++ .../StdMeshersGUI_NbSegmentsCreator.h | 64 + .../StdMeshersGUI_StdHypothesisCreator.cxx | 277 +++++ .../StdMeshersGUI_StdHypothesisCreator.h | 60 + src/StdMeshersGUI/StdMeshers_msg_en.po | 24 +- .../StdMeshers_NumberOfSegments_i.cxx | 71 +- .../StdMeshers_NumberOfSegments_i.hxx | 10 +- 45 files changed, 2794 insertions(+), 3104 deletions(-) delete mode 100644 src/SMESHGUI/SMESHGUI_FunctionPreview.cxx delete mode 100644 src/SMESHGUI/SMESHGUI_FunctionPreview.h create mode 100644 src/SMESHGUI/SMESHGUI_Hypotheses.cxx delete mode 100644 src/SMESHGUI/SMESHGUI_aParameter.cxx delete mode 100644 src/SMESHGUI/SMESHGUI_aParameterDlg.cxx delete mode 100644 src/SMESHGUI/SMESHGUI_aParameterDlg.h create mode 100644 src/StdMeshers/StdMeshers_Distribution.cxx create mode 100644 src/StdMeshers/StdMeshers_Distribution.hxx delete mode 100644 src/StdMeshersGUI/StdMeshersGUI_CreateHypothesisDlg.cxx delete mode 100644 src/StdMeshersGUI/StdMeshersGUI_CreateHypothesisDlg.h delete mode 100644 src/StdMeshersGUI/StdMeshersGUI_CreateStdHypothesisDlg.h create mode 100644 src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx create mode 100644 src/StdMeshersGUI/StdMeshersGUI_DistrPreview.h create mode 100644 src/StdMeshersGUI/StdMeshersGUI_DistrTable.cxx create mode 100644 src/StdMeshersGUI/StdMeshersGUI_DistrTable.h create mode 100644 src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx create mode 100644 src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h create mode 100644 src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx create mode 100644 src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h diff --git a/INSTALL b/INSTALL index 39222c083..78255907a 100644 --- a/INSTALL +++ b/INSTALL @@ -1,6 +1,6 @@ -This is the version 3.1.0b1 of SMESH +This is the version 3.1.0 of SMESH Compatible with : - - KERNEL 3.1.0b1 - - SALOMEGUI 3.1.0b1 - - GEOM 3.1.0b1 - - MED 3.1.0b1 + - KERNEL 3.1.0 + - SALOMEGUI 3.1.0 + - GEOM 3.1.0 + - MED 3.1.0 diff --git a/bin/VERSION b/bin/VERSION index e951f746e..9c664a112 100755 --- a/bin/VERSION +++ b/bin/VERSION @@ -1 +1 @@ -THIS IS SALOME - SMESH VERSION: 3.1.0b1 +THIS IS SALOME - SMESH VERSION: 3.1.0 diff --git a/build_configure b/build_configure index 9df6be15c..b884b1757 100755 --- a/build_configure +++ b/build_configure @@ -110,7 +110,7 @@ fi # make a link allowing AC_OUTPUT to find the salome_adm/.../*.in files echo "" >> configure.in_tmp1 -echo 'ln -fs ${KERNEL_ROOT_DIR}/salome_adm ${ROOT_SRCDIR}/salome_adm' >> configure.in_tmp1 +echo 'ln -fs ${KERNEL_ROOT_DIR}/salome_adm ${ROOT_SRCDIR}/.' >> configure.in_tmp1 echo "" >> configure.in_tmp1 echo "AC_OUTPUT([ \\" >> configure.in_tmp1 diff --git a/doc/salome/tui/SMESH/doxyfile b/doc/salome/tui/SMESH/doxyfile index 883136c2f..7bff2f27e 100755 --- a/doc/salome/tui/SMESH/doxyfile +++ b/doc/salome/tui/SMESH/doxyfile @@ -3,7 +3,7 @@ #--------------------------------------------------------------------------- # General configuration options #--------------------------------------------------------------------------- -PROJECT_NAME = "SALOME - SMESH - v.2.1.0" +PROJECT_NAME = "SALOME - SMESH - v.3.1.0" PROJECT_NUMBER = id#1.1 OUTPUT_DIRECTORY = ../ OUTPUT_LANGUAGE = English diff --git a/doc/salome/tui/SMESH/doxyfile_py b/doc/salome/tui/SMESH/doxyfile_py index 8569636d5..e1516c8ba 100755 --- a/doc/salome/tui/SMESH/doxyfile_py +++ b/doc/salome/tui/SMESH/doxyfile_py @@ -3,7 +3,7 @@ #--------------------------------------------------------------------------- # General configuration options #--------------------------------------------------------------------------- -PROJECT_NAME = "SALOME - SMESH - v.2.1.0" +PROJECT_NAME = "SALOME - SMESH - v.3.1.0" PROJECT_NUMBER = id#1.1 OUTPUT_DIRECTORY = ../ OUTPUT_LANGUAGE = English diff --git a/doc/salome/tui/SMESH/sources/static/tree.js b/doc/salome/tui/SMESH/sources/static/tree.js index b2a9953b2..f50023878 100755 --- a/doc/salome/tui/SMESH/sources/static/tree.js +++ b/doc/salome/tui/SMESH/sources/static/tree.js @@ -1,4 +1,4 @@ -foldersTree = gFld("SALOME v.2.1.0 ", "", "") +foldersTree = gFld("SALOME v.3.1.0 ", "", "") insDoc(foldersTree, gLnk("Main Page", "", "main.html")) aux1 = insFld(foldersTree, gFld("TUI Reference Guide", "")) diff --git a/idl/SMESH_BasicHypothesis.idl b/idl/SMESH_BasicHypothesis.idl index 3d5c227ce..b6367b75d 100644 --- a/idl/SMESH_BasicHypothesis.idl +++ b/idl/SMESH_BasicHypothesis.idl @@ -21,7 +21,6 @@ // // File : SMESH_BasicHypothesis.idl // Author : Paul RASCLE, EDF -// $Header$ #ifndef _SMESH_BASICHYPOTHESIS_IDL_ #define _SMESH_BASICHYPOTHESIS_IDL_ @@ -75,6 +74,14 @@ module StdMeshers */ interface StdMeshers_NumberOfSegments : SMESH::SMESH_Hypothesis { + /*! + * Builds and returns point distribution according to passed density function + */ + SMESH::double_array BuildDistributionExpr( in string func, in long nbSeg, in long conv ) + raises (SALOME::SALOME_Exception); + SMESH::double_array BuildDistributionTab( in SMESH::double_array func, in long nbSeg, in long conv ) + raises (SALOME::SALOME_Exception); + /*! * Sets parameter value */ @@ -134,15 +141,15 @@ module StdMeshers raises (SALOME::SALOME_Exception); /*! - * Sets parameter value for functional distributions + * Sets parameter value for functional distributions */ - void SetExponentMode(in boolean isExponent) + void SetConversionMode(in long conv ) raises (SALOME::SALOME_Exception); /*! - * Returns parameter value for functional distributions + * Returns parameter value for functional distributions */ - boolean IsExponentMode() + long ConversionMode() raises (SALOME::SALOME_Exception); }; diff --git a/resources/SMESHCatalog.xml b/resources/SMESHCatalog.xml index 4c1188637..e77ee98df 100644 --- a/resources/SMESHCatalog.xml +++ b/resources/SMESHCatalog.xml @@ -16,7 +16,7 @@ Mesh MESH NRI - 3.1.0b1 + 3.1.0 Mesh component 1 ModuleMesh.png diff --git a/src/Controls/SMESH_Controls.cxx b/src/Controls/SMESH_Controls.cxx index 3ebd18b90..717f8e66a 100644 --- a/src/Controls/SMESH_Controls.cxx +++ b/src/Controls/SMESH_Controls.cxx @@ -282,6 +282,10 @@ SMDSAbs_ElementType MinimumAngle::GetType() const */ double AspectRatio::GetValue( const TSequenceOfXYZ& P ) { + // According to "Mesh quality control" by Nadir Bouhamau referring to + // Pascal Jean Frey and Paul-Louis George. Maillages, applications aux elements finis. + // Hermes Science publications, Paris 1999 ISBN 2-7462-0024-4 + int nbNodes = P.size(); if ( nbNodes < 3 ) @@ -289,12 +293,7 @@ double AspectRatio::GetValue( const TSequenceOfXYZ& P ) // Compute lengths of the sides - //double aLen[ nbNodes ]; -#ifndef WNT - double aLen [nbNodes]; -#else - double* aLen = (double *)new double[nbNodes]; -#endif + vector< double > aLen (nbNodes); for ( int i = 0; i < nbNodes - 1; i++ ) aLen[ i ] = getDistance( P( i + 1 ), P( i + 2 ) ); @@ -304,30 +303,43 @@ double AspectRatio::GetValue( const TSequenceOfXYZ& P ) if ( nbNodes == 3 ) { + // Q = alfa * h * p / S, where + // + // alfa = sqrt( 3 ) / 6 + // h - length of the longest edge + // p - half perimeter + // S - triangle surface + + const double alfa = sqrt( 3. ) / 6.; + double maxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) ); + double half_perimeter = ( aLen[0] + aLen[1] + aLen[2] ) / 2.; double anArea = getArea( P( 1 ), P( 2 ), P( 3 ) ); if ( anArea <= Precision::Confusion() ) return 0.; - double aMaxLen = Max( aLen[ 0 ], Max( aLen[ 1 ], aLen[ 2 ] ) ); - static double aCoef = sqrt( 3. ) / 4; - return aCoef * aMaxLen * aMaxLen / anArea; + return alfa * maxLen * half_perimeter / anArea; } else { - double aMinLen = aLen[ 0 ]; - double aMaxLen = aLen[ 0 ]; - - for(int i = 1; i < nbNodes ; i++ ){ - aMinLen = Min( aMinLen, aLen[ i ] ); - aMaxLen = Max( aMaxLen, aLen[ i ] ); - } -#ifdef WNT - delete [] aLen; -#endif - if ( aMinLen <= Precision::Confusion() ) - return 0.; - - return aMaxLen / aMinLen; + // return aspect ratio of the worst triange which can be built + // taking three nodes of the quadrangle + TSequenceOfXYZ triaPnts(3); + // triangle on nodes 1 3 2 + triaPnts(1) = P(1); + triaPnts(2) = P(3); + triaPnts(3) = P(2); + double ar = GetValue( triaPnts ); + // triangle on nodes 1 3 4 + triaPnts(3) = P(4); + ar = Max ( ar, GetValue( triaPnts )); + // triangle on nodes 1 2 4 + triaPnts(2) = P(2); + ar = Max ( ar, GetValue( triaPnts )); + // triangle on nodes 3 2 4 + triaPnts(1) = P(3); + ar = Max ( ar, GetValue( triaPnts )); + + return ar; } } @@ -447,7 +459,7 @@ double AspectRatio3D::GetValue( const TSequenceOfXYZ& P ) double aVolume = getVolume(P); //double aVolume = getVolume(aLen); double aHeight = getMaxHeight(aLen); - static double aCoeff = sqrt(6.0)/36.0; + static double aCoeff = sqrt(2.0)/12.0; aQuality = aCoeff*aHeight*aSumArea/aVolume; break; } @@ -633,6 +645,21 @@ double AspectRatio3D::GetValue( const TSequenceOfXYZ& P ) break; } } + if ( nbNodes > 4 ) { + // avaluate aspect ratio of quadranle faces + AspectRatio aspect2D; + SMDS_VolumeTool::VolumeType type = SMDS_VolumeTool::GetType( nbNodes ); + int nbFaces = SMDS_VolumeTool::NbFaces( type ); + TSequenceOfXYZ points(4); + for ( int i = 0; i < nbFaces; ++i ) { // loop on faces of a volume + if ( SMDS_VolumeTool::NbFaceNodes( type, i ) != 4 ) + continue; + const int* pInd = SMDS_VolumeTool::GetFaceNodesIndices( type, i, true ); + for ( int p = 0; p < 4; ++p ) // loop on nodes of a quadranle face + points( p + 1 ) = P( pInd[ p ] + 1 ); + aQuality = max( aQuality, aspect2D.GetValue( points )); + } + } return aQuality; } diff --git a/src/SMESHGUI/Makefile.in b/src/SMESHGUI/Makefile.in index a4b466aa5..a1d7e8ac6 100644 --- a/src/SMESHGUI/Makefile.in +++ b/src/SMESHGUI/Makefile.in @@ -42,10 +42,7 @@ EXPORT_HEADERS= SMESHGUI_Swig.hxx \ SMESHGUI_Hypotheses.h \ SMESHGUI_HypothesesUtils.h \ SMESHGUI_SpinBox.h \ - SMESHGUI_aParameter.h \ - SMESHGUI_aParameterDlg.h \ - SMESHGUI_Selection.h \ - SMESHGUI_FunctionPreview.h + SMESHGUI_Selection.h # .po files to transform in .qm PO_FILES = \ @@ -70,7 +67,6 @@ LIB_SRC = SMESHGUI.cxx \ SMESHGUI_Preferences_ColorDlg.cxx \ SMESHGUI_Preferences_ScalarBarDlg.cxx \ SMESHGUI_Preferences_SelectionDlg.cxx \ - SMESHGUI_aParameterDlg.cxx \ SMESHGUI_Swig.cxx \ SMESHGUI_MoveNodesDlg.cxx \ SMESHGUI_AddMeshElementDlg.cxx \ @@ -82,7 +78,6 @@ LIB_SRC = SMESHGUI.cxx \ SMESHGUI_FilterLibraryDlg.cxx \ SMESHGUI_SingleEditDlg.cxx \ SMESHGUI_MultiEditDlg.cxx \ - SMESHGUI_aParameter.cxx \ SMESHGUI_DeleteGroupDlg.cxx \ SMESHGUI_GroupOpDlg.cxx \ SMESHGUI_SmoothingDlg.cxx \ @@ -113,7 +108,7 @@ LIB_SRC = SMESHGUI.cxx \ SMESHGUI_MeshDlg.cxx \ SMESHGUI_MeshOp.cxx \ SMESHGUI_Displayer.cxx \ - SMESHGUI_FunctionPreview.cxx + SMESHGUI_Hypotheses.cxx LIB_MOC = \ SMESHGUI.h \ @@ -132,7 +127,6 @@ LIB_MOC = \ SMESHGUI_Preferences_ColorDlg.h \ SMESHGUI_Preferences_ScalarBarDlg.h \ SMESHGUI_Preferences_SelectionDlg.h \ - SMESHGUI_aParameterDlg.h \ SMESHGUI_MoveNodesDlg.h \ SMESHGUI_AddMeshElementDlg.h \ SMESHGUI_EditHypothesesDlg.h \ @@ -154,7 +148,6 @@ LIB_MOC = \ SMESHGUI_SewingDlg.h \ SMESHGUI_PrecisionDlg.h \ SMESHGUI_MergeNodesDlg.h \ - SMESHGUI_aParameter.h \ SMESHGUI_EditMeshDlg.h \ SMESHGUI_CreatePolyhedralVolumeDlg.h \ SMESHGUI_Operation.h \ @@ -162,7 +155,7 @@ LIB_MOC = \ SMESHGUI_Dialog.h \ SMESHGUI_MeshDlg.h \ SMESHGUI_MeshOp.h \ - SMESHGUI_FunctionPreview.h + SMESHGUI_Hypotheses.h LIB_CLIENT_IDL = SALOME_Exception.idl \ @@ -189,17 +182,16 @@ LIB_SERVER_IDL = CPPFLAGS += $(QT_INCLUDES) $(VTK_INCLUDES) $(OGL_INCLUDES) $(OCC_INCLUDES) $(PYTHON_INCLUDES) \ -I${KERNEL_ROOT_DIR}/include/salome -I${GUI_ROOT_DIR}/include/salome \ - -I${GEOM_ROOT_DIR}/include/salome $(BOOST_CPPFLAGS) $(QWT_INCLUDES) + -I${GEOM_ROOT_DIR}/include/salome $(BOOST_CPPFLAGS) CXXFLAGS += -I${KERNEL_ROOT_DIR}/include/salome -I${GUI_ROOT_DIR}/include/salome \ -I${GEOM_ROOT_DIR}/include/salome - LDFLAGS += -lSMESHObject -lSMESHFiltersSelection -lSMDS -lSMESHControls -lDlgRef \ $(OCC_KERNEL_LIBS) -lTKBO -lTKAdvTools -L${KERNEL_ROOT_DIR}/lib/salome -L${GUI_ROOT_DIR}/lib/salome \ -lVTKViewer -lSalomeApp -lSalomePrs -lSalomeNS -lSalomeLifeCycleCORBA -lOpUtil -lSalomeObject \ -lEvent -lSALOMELocalTrace -lSVTK -lOCCViewer -L${GEOM_ROOT_DIR}/lib/salome -lGEOM -lGEOMClient \ - -lGEOMBase -lGEOMObject -lGEOMFiltersSelection $(QWT_LIBS) + -lGEOMBase -lGEOMObject -lGEOMFiltersSelection LDFLAGSFORBIN += $(LDFLAGS) diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index ae96d893d..fae703982 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -1725,9 +1725,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID ) char* sName = Hyp->GetName(); SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(sName); if (aCreator) - { - aCreator->EditHypothesis(Hyp); - } + aCreator->edit( Hyp.in(), desktop() ); else { // report error diff --git a/src/SMESHGUI/SMESHGUI_CreateHypothesesDlg.cxx b/src/SMESHGUI/SMESHGUI_CreateHypothesesDlg.cxx index 68d2f10c8..32e4860ac 100644 --- a/src/SMESHGUI/SMESHGUI_CreateHypothesesDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_CreateHypothesesDlg.cxx @@ -205,8 +205,13 @@ void SMESHGUI_CreateHypothesesDlg::ClickOnApply() SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(sHypType); - // Create hypothesis/algorithm - aCreator->CreateHypothesis(myIsAlgo, this); + if( aCreator ) + // Create hypothesis/algorithm + aCreator->create( myIsAlgo, this ); + else + { + // report about error + } } // buttonApply->setEnabled(FALSE); diff --git a/src/SMESHGUI/SMESHGUI_FunctionPreview.cxx b/src/SMESHGUI/SMESHGUI_FunctionPreview.cxx deleted file mode 100644 index b0d2ed5a9..000000000 --- a/src/SMESHGUI/SMESHGUI_FunctionPreview.cxx +++ /dev/null @@ -1,271 +0,0 @@ -// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ -// - -#include "SMESHGUI_FunctionPreview.h" -#include -#include -#include -#include -#include -#include - -SMESHGUI_FunctionPreview::SMESHGUI_FunctionPreview( QWidget* p ) -: QwtPlot( p ), - myXmin( 0.0 ), - myXmax( 1.0 ), - myPoints( 50 ), - myIsTable( false ), - myVars( 1, 1 ), - myValues( 1, 1 ), - myIsExp( false ), - myIsDone( true ) -{ - myVars.ChangeValue( 1 ) = new Expr_NamedUnknown( "t" ); - myCurve = insertCurve( QString() ); - setCurvePen( myCurve, QPen( Qt::red, 1 ) ); -} - -SMESHGUI_FunctionPreview::~SMESHGUI_FunctionPreview() -{ -} - -bool SMESHGUI_FunctionPreview::isTableFunc() const -{ - return myIsTable; -} - -void SMESHGUI_FunctionPreview::tableFunc( SMESH::double_array& f ) const -{ - f = myTableFunc; -} - -QString SMESHGUI_FunctionPreview::function() const -{ - return myFunction; -} - -void SMESHGUI_FunctionPreview::interval( double& xmin, double& xmax ) const -{ - xmin = myXmin; - xmax = myXmax; -} - -int SMESHGUI_FunctionPreview::pointsCount() const -{ - return myPoints; -} - -void SMESHGUI_FunctionPreview::setIsExp( const bool exp, const bool update ) -{ - myIsExp = exp; - if( update ) - repaint(); -} - -bool SMESHGUI_FunctionPreview::setParams( const QString& func, - const double xmin, const double xmax, - const int points, const bool update ) -{ - myIsTable = false; - myTableFunc = SMESH::double_array(); - myFunction = func.isEmpty() ? "0" : func; - myXmin = xmin; - myXmax = xmax0 ? points : 2; - bool res = init( func ); - if( update ) - repaint(); - return res; -} - -bool SMESHGUI_FunctionPreview::setParams( const SMESH::double_array& f, const double xmin, const double xmax, - const bool update ) -{ - myIsTable = true; - myTableFunc = f; - if( myTableFunc.length()%2==1 ) - myTableFunc.length( myTableFunc.length()-1 ); - - myFunction = "0"; - myXmin = xmin; - myXmax = xmax0; -} - -bool SMESHGUI_FunctionPreview::createTable( SMESH::double_array& func ) -{ - if( myExpr.IsNull() ) - { - func.length( 0 ); - return false; - } - - double d = (myXmax-myXmin)/double(myPoints-1); - func.length( 2*myPoints ); - int err = 0; - for( int i=0, j=0; imax_y ) - max_y = y[i]; - if( i==0 || x[i]max_x ) - max_x = x[i]; - } - - setAxisScale( curveXAxis( myCurve ), min_x, max_x ); - setAxisScale( curveYAxis( myCurve ), min_y, max_y ); - setCurveData( myCurve, x, y, size ); - delete[] x; - delete[] y; - - replot(); - QwtPlot::drawContents( p ); -} - -bool isCorrectArg( const Handle( Expr_GeneralExpression )& expr ) -{ - Handle( Expr_NamedUnknown ) sub = Handle( Expr_NamedUnknown )::DownCast( expr ); - if( !sub.IsNull() ) - return sub->GetName()=="t"; - - bool res = true; - for( int i=1, n=expr->NbSubExpressions(); i<=n && res; i++ ) - { - Handle( Expr_GeneralExpression ) sub = expr->SubExpression( i ); - Handle( Expr_NamedUnknown ) name = Handle( Expr_NamedUnknown )::DownCast( sub ); - if( !name.IsNull() ) - { - if( name->GetName()!="t" ) - res = false; - } - else - res = isCorrectArg( sub ); - } - return res; -} - -bool SMESHGUI_FunctionPreview::init( const QString& str ) -{ - myExpr = ExprIntrp_GenExp::Create(); - myExpr->Process( ( Standard_CString ) str.latin1() ); - - bool syntax = false, args = false; - if( myExpr->IsDone() ) - { - syntax = true; - args = isCorrectArg( myExpr->Expression() ); - } - - bool res = syntax && args; - if( !res ) - myExpr.Nullify(); - return res; -} - -double SMESHGUI_FunctionPreview::funcValue( const double t, bool& ok ) -{ - if( myExpr.IsNull() ) - return 0; - - myValues.ChangeValue( 1 ) = t; - - ok = true; - double res = calc( ok ); - - return res; -} - -double SMESHGUI_FunctionPreview::calc( bool& ok ) -{ - OSD::SetSignal( true ); - double res = 0.0; - - CASCatch_CatchSignals aCatchSignals; - aCatchSignals.Activate(); - - ok = true; - CASCatch_TRY { - res = myExpr->Expression()->Evaluate( myVars, myValues ); - } - CASCatch_CATCH(CASCatch_Failure) { - aCatchSignals.Deactivate(); - Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught(); - ok = false; - res = 0.0; - } - aCatchSignals.Deactivate(); - return res; -} - -bool SMESHGUI_FunctionPreview::isDone() const -{ - return myIsDone; -} diff --git a/src/SMESHGUI/SMESHGUI_FunctionPreview.h b/src/SMESHGUI/SMESHGUI_FunctionPreview.h deleted file mode 100644 index 9df9581f4..000000000 --- a/src/SMESHGUI/SMESHGUI_FunctionPreview.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ -// - -#ifndef SMESHGUI_FUNCTION_PREVIEW_HEADER -#define SMESHGUI_FUNCTION_PREVIEW_HEADER - -#include "qwt_plot.h" -#include -#include CORBA_SERVER_HEADER(SMESH_Mesh) -#include -#include -#include - -class SMESHGUI_FunctionPreview : public QwtPlot -{ - Q_OBJECT - -public: - SMESHGUI_FunctionPreview( QWidget* ); - virtual ~SMESHGUI_FunctionPreview(); - - QString function() const; - bool isTableFunc() const; - void tableFunc( SMESH::double_array& ) const; - void interval( double&, double& ) const; - int pointsCount() const; - bool isDone() const; - - bool setParams( const QString&, const double = 0.0, const double = 1.0, const int = 50, const bool = true ); - bool setParams( const SMESH::double_array&, const double = 0.0, const double = 1.0, const bool = true ); - void setIsExp( const bool, const bool = true ); - -protected: - virtual bool init( const QString& ); - virtual double funcValue( const double, bool& ); - virtual bool createTable( SMESH::double_array& ); - virtual void drawContents( QPainter* ); - -private: - double calc( bool& ); - -private: - QString myFunction; - double myXmin, myXmax; - int myPoints; - bool myIsTable; - bool myIsExp; - SMESH::double_array myTableFunc; - long myCurve; - Handle(ExprIntrp_GenExp) myExpr; - Expr_Array1OfNamedUnknown myVars; - TColStd_Array1OfReal myValues; - bool myIsDone; -}; - -#endif diff --git a/src/SMESHGUI/SMESHGUI_Hypotheses.cxx b/src/SMESHGUI/SMESHGUI_Hypotheses.cxx new file mode 100644 index 000000000..676c37cc4 --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_Hypotheses.cxx @@ -0,0 +1,336 @@ + +#include "SMESHGUI_Hypotheses.h" +#include "SMESHGUI.h" +#include "SMESHGUI_HypothesesUtils.h" +#include "SMESHGUI_Utils.h" +#include "SMESHGUI_SpinBox.h" + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +SMESHGUI_GenericHypothesisCreator::SMESHGUI_GenericHypothesisCreator( const QString& aHypType ) +: myHypType( aHypType ), + myIsCreate( false ) +{ +} + +SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator() +{ +} + +void SMESHGUI_GenericHypothesisCreator::create( const bool isAlgo, QWidget* parent ) +{ + MESSAGE( "Creation of hypothesis" ); + + // Get default name for hypothesis/algorithm creation + HypothesisData* aHypData = SMESH::GetHypothesisData( hypType().latin1() ); + QString aHypName = aHypData ? aHypData->Label : hypType(); + + myIsCreate = true; + + // Create hypothesis/algorithm + if (isAlgo) + SMESH::CreateHypothesis( hypType(), aHypName, isAlgo ); + + else + { + SMESH::SMESH_Hypothesis_var newHypo = SMESH::SMESH_Hypothesis::_narrow + ( SMESH::CreateHypothesis( hypType(), aHypName, false ) ); + + if( !editHypothesis( newHypo.in(), parent ) ) + { //remove just created hypothesis + _PTR(SObject) SHyp = SMESH::FindSObject( newHypo.in() ); + _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); + if( aStudy && !aStudy->GetProperties()->IsLocked() ) + { + _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder(); + aBuilder->RemoveObjectWithChildren( SHyp ); + } + } + } + SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 ); +} + +void SMESHGUI_GenericHypothesisCreator::edit( SMESH::SMESH_Hypothesis_ptr h, QWidget* parent ) +{ + if( CORBA::is_nil( h ) ) + return; + + MESSAGE("Edition of hypothesis"); + + myIsCreate = false; + + if( !editHypothesis( h, parent ) ) + return; + + SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis( h ); + if( listSOmesh.size() > 0 ) + for( int i=0; i( submSO ); + SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface( submSO ); + if( !aSubMesh->_is_nil() ) + aMesh = aSubMesh->GetFather(); + _PTR(SObject) meshSO = SMESH::FindSObject( aMesh ); + SMESH::ModifiedMesh( meshSO, false); + } + SMESHGUI::GetSMESHGUI()->updateObjBrowser( true, 0 ); +} + +bool SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ptr h, QWidget* parent ) +{ + if( CORBA::is_nil( h ) ) + return false; + + bool res = true; + myHypo = SMESH::SMESH_Hypothesis::_duplicate( h ); + QFrame* fr = buildFrame(); + if( fr ) + { + SMESHGUI_HypothesisDlg* dlg = + new SMESHGUI_HypothesisDlg( const_cast( this ), parent ); + dlg->setCustomFrame( fr ); + dlg->setCaption( caption() ); + dlg->setHIcon( icon() ); + dlg->setType( type() ); + retrieveParams(); + res = dlg->exec()==QDialog::Accepted; + if( res ) + storeParams(); + delete dlg; + } + changeWidgets().clear(); + myHypo = SMESH::SMESH_Hypothesis::_nil(); + return res; +} + +QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame() +{ + if( CORBA::is_nil( hypothesis() ) ) + return 0; + + ListOfStdParams params; + if( !stdParams( params ) || params.isEmpty() ) + return 0; + + QFrame* fr = new QFrame( 0, "myframe" ); + QVBoxLayout* lay = new QVBoxLayout( fr, 5, 0 ); + + QGroupBox* GroupC1 = new QGroupBox( fr, "GroupC1" ); + lay->addWidget( GroupC1 ); + + GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) ); + GroupC1->setColumnLayout(0, Qt::Vertical ); + GroupC1->layout()->setSpacing( 0 ); + GroupC1->layout()->setMargin( 0 ); + QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() ); + GroupC1Layout->setAlignment( Qt::AlignTop ); + GroupC1Layout->setSpacing( 6 ); + GroupC1Layout->setMargin( 11 ); + + ListOfStdParams::const_iterator anIt = params.begin(), aLast = params.end(); + for( int i=0; anIt!=aLast; anIt++, i++ ) + { + QLabel* lab = new QLabel( (*anIt).myName, GroupC1 ); + GroupC1Layout->addWidget( lab, i, 0 ); + + QWidget* w = 0; + switch( (*anIt).myValue.type() ) + { + case QVariant::Int: + { + QtxIntSpinBox* sb = new QtxIntSpinBox( GroupC1, (*anIt).myName.latin1() ); + attuneStdWidget( sb, i ); + sb->setValue( (*anIt).myValue.toInt() ); + connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) ); + w = sb; + } + break; + case QVariant::Double: + { + QtxDblSpinBox* sb = new SMESHGUI_SpinBox( GroupC1, (*anIt).myName.latin1() ); + attuneStdWidget( sb, i ); + sb->setValue( (*anIt).myValue.toDouble() ); + connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) ); + w = sb; + } + break; + case QVariant::String: + { + QLineEdit* le = new QLineEdit( GroupC1, (*anIt).myName.latin1() ); + attuneStdWidget( le, i ); + le->setText( (*anIt).myValue.toString() ); + connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) ); + w = le; + } + break; + } + + if( w ) + { + GroupC1Layout->addWidget( w, i, 1 ); + changeWidgets().append( w ); + } + } + + return fr; +} + +void SMESHGUI_GenericHypothesisCreator::onValueChanged() +{ +} + +bool SMESHGUI_GenericHypothesisCreator::stdParams( ListOfStdParams& ) const +{ + return false; +} + +bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& params ) const +{ + bool res = true; + StdParam item; + ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end(); + for( ; anIt!=aLast; anIt++ ) + { + item.myName = (*anIt)->name(); + if( (*anIt)->inherits( "QtxIntSpinBox" ) ) + { + QtxIntSpinBox* sb = ( QtxIntSpinBox* )( *anIt ); + item.myValue = sb->value(); + params.append( item ); + } + + else if( (*anIt)->inherits( "QtxDblSpinBox" ) ) + { + QtxDblSpinBox* sb = ( QtxDblSpinBox* )( *anIt ); + item.myValue = sb->value(); + params.append( item ); + } + + else if( (*anIt)->inherits( "QLineEdit" ) ) + { + QLineEdit* line = ( QLineEdit* )( *anIt ); + item.myValue = line->text(); + params.append( item ); + } + + else + res = false; + } + return res; +} + +SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const +{ + return myHypo; +} + +QString SMESHGUI_GenericHypothesisCreator::hypType() const +{ + return myHypType; +} + +const SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::widgets() const +{ + return myParamWidgets; +} + +SMESHGUI_GenericHypothesisCreator::ListOfWidgets& SMESHGUI_GenericHypothesisCreator::changeWidgets() +{ + return myParamWidgets; +} + +bool SMESHGUI_GenericHypothesisCreator::isCreation() const +{ + return myIsCreate; +} + +void SMESHGUI_GenericHypothesisCreator::attuneStdWidget( QWidget*, const int ) const +{ +} + +QString SMESHGUI_GenericHypothesisCreator::caption() const +{ + return QString(); +} + +QPixmap SMESHGUI_GenericHypothesisCreator::icon() const +{ + return QPixmap(); +} + +QString SMESHGUI_GenericHypothesisCreator::type() const +{ + return QString(); +} + + + + + + + + +SMESHGUI_HypothesisDlg::SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator* creator, QWidget* parent ) +: QtxDialog( parent, "", true, true, QtxDialog::OKCancel ), + myCreator( creator ) +{ + setMinimumSize( 300, height() ); +// setFixedSize( 300, height() ); + myLayout = new QVBoxLayout( mainFrame(), 0, 0 ); + + QFrame* titFrame = new QFrame( mainFrame() ); + QHBoxLayout* titLay = new QHBoxLayout( titFrame, 0, 5 ); + + myIconLabel = new QLabel( titFrame ); + myIconLabel->setScaledContents( false ); + myIconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + myTypeLabel = new QLabel( titFrame ); + if( creator ) + myTypeLabel->setText( creator->hypType() ); + + titLay->addWidget( myIconLabel, 0 ); + titLay->addWidget( myTypeLabel, 0 ); + titLay->addStretch( 1 ); + + myLayout->addWidget( titFrame, 0 ); +} + +SMESHGUI_HypothesisDlg::~SMESHGUI_HypothesisDlg() +{ +} + +void SMESHGUI_HypothesisDlg::setCustomFrame( QFrame* f ) +{ + if( f ) + { + f->reparent( mainFrame(), QPoint( 0, 0 ) ); + myLayout->insertWidget( 1, f, 1 ); + } +} + +void SMESHGUI_HypothesisDlg::accept() +{ + if( !myCreator || myCreator->checkParams() ) + QtxDialog::accept(); +} + +void SMESHGUI_HypothesisDlg::setHIcon( const QPixmap& p ) +{ + myIconLabel->setPixmap( p ); +} + +void SMESHGUI_HypothesisDlg::setType( const QString& t ) +{ + myTypeLabel->setText( t ); +} diff --git a/src/SMESHGUI/SMESHGUI_Hypotheses.h b/src/SMESHGUI/SMESHGUI_Hypotheses.h index 431ca2294..a4558df89 100644 --- a/src/SMESHGUI/SMESHGUI_Hypotheses.h +++ b/src/SMESHGUI/SMESHGUI_Hypotheses.h @@ -31,20 +31,88 @@ #include #include CORBA_SERVER_HEADER(SMESH_Hypothesis) -// QT Includes -#include -#include -#include -#include +#include +#include + +class QVBoxLayout; +class QPixmap; /*! * \brief Auxiliary class for creation of hypotheses */ -class SMESHGUI_GenericHypothesisCreator +class SMESHGUI_GenericHypothesisCreator : public QObject { - public: - virtual void CreateHypothesis (const bool isAlgo, QWidget* parent) = 0; - virtual void EditHypothesis (SMESH::SMESH_Hypothesis_ptr theHyp) = 0; + Q_OBJECT + +public: + SMESHGUI_GenericHypothesisCreator( const QString& ); + virtual ~SMESHGUI_GenericHypothesisCreator(); + + void create( const bool isAlgo, QWidget* ); + void edit( SMESH::SMESH_Hypothesis_ptr, QWidget* ); + virtual bool checkParams() const = 0; + + QString hypType() const; + bool isCreation() const; + +protected: + typedef struct + { + QString myName; + QVariant myValue; + + } StdParam; + + typedef QValueList ListOfStdParams; + typedef QPtrList ListOfWidgets; + + SMESH::SMESH_Hypothesis_var hypothesis() const; + const ListOfWidgets& widgets() const; + ListOfWidgets& changeWidgets(); + + virtual QFrame* buildFrame () = 0; + QFrame* buildStdFrame (); + virtual void retrieveParams() const = 0; + virtual void storeParams () const = 0; + virtual bool stdParams ( ListOfStdParams& ) const; + bool getStdParamFromDlg( ListOfStdParams& ) const; + virtual void attuneStdWidget( QWidget*, const int ) const; + virtual QString caption() const; + virtual QPixmap icon() const; + virtual QString type() const; + +protected slots: + virtual void onValueChanged(); + +private: + bool editHypothesis( SMESH::SMESH_Hypothesis_ptr, QWidget* ); + +private: + SMESH::SMESH_Hypothesis_var myHypo; + QString myHypType; + ListOfWidgets myParamWidgets; + bool myIsCreate; +}; + +class SMESHGUI_HypothesisDlg : public QtxDialog +{ + Q_OBJECT + +public: + SMESHGUI_HypothesisDlg( SMESHGUI_GenericHypothesisCreator*, QWidget* ); + virtual ~SMESHGUI_HypothesisDlg(); + + void setHIcon( const QPixmap& ); + void setCustomFrame( QFrame* ); + void setType( const QString& ); + +protected slots: + virtual void accept(); + +private: + SMESHGUI_GenericHypothesisCreator* myCreator; + QVBoxLayout* myLayout; + QLabel *myIconLabel, *myTypeLabel; }; /*! diff --git a/src/SMESHGUI/SMESHGUI_HypothesesUtils.cxx b/src/SMESHGUI/SMESHGUI_HypothesesUtils.cxx index 3e48afa89..98d84f8a9 100644 --- a/src/SMESHGUI/SMESHGUI_HypothesesUtils.cxx +++ b/src/SMESHGUI/SMESHGUI_HypothesesUtils.cxx @@ -297,7 +297,7 @@ namespace SMESH{ // get method, returning hypothesis creator if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ..."); typedef SMESHGUI_GenericHypothesisCreator* (*GetHypothesisCreator) \ - (QString aHypType, QString aServerLibName, SMESHGUI* aSMESHGUI); + ( const QString& ); GetHypothesisCreator procHandle = (GetHypothesisCreator)dlsym(libHandle, "GetHypothesisCreator"); if (!procHandle) { @@ -307,7 +307,7 @@ namespace SMESH{ else { // get hypothesis creator if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << aHypType); - aCreator = procHandle(aHypType, aServerLibName, SMESHGUI::GetSMESHGUI()); + aCreator = procHandle( aHypType ); if (!aCreator) { if(MYDEBUG) MESSAGE("no such a hypothesis in this plugin"); } diff --git a/src/SMESHGUI/SMESHGUI_MeshOp.cxx b/src/SMESHGUI/SMESHGUI_MeshOp.cxx index 716d21e61..7904ea372 100644 --- a/src/SMESHGUI/SMESHGUI_MeshOp.cxx +++ b/src/SMESHGUI/SMESHGUI_MeshOp.cxx @@ -560,7 +560,8 @@ void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex ) SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHypTypeName ); // Create hypothesis - aCreator->CreateHypothesis( false, myDlg ); + if( aCreator ) + aCreator->create( false, myDlg ); } QStringList aNewHyps; @@ -602,7 +603,7 @@ void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex ) char* aTypeName = aHyp->GetName(); SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aTypeName ); if ( aCreator ) - aCreator->EditHypothesis( aHyp ); + aCreator->edit( aHyp.in(), dlg() ); } //================================================================================ @@ -632,7 +633,9 @@ void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName ) { const QString& aHypoTypeName = (*aHypoList)[ i ]; HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName ); - if ( !aHypData ) continue; + if ( !aHypData ) + continue; + int aDim = aHypData->Dim[0]; // create or/and set int index = -1; @@ -673,7 +676,7 @@ void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName ) // Get hypotheses creator client (GUI) SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHypoTypeName ); - aCreator->CreateHypothesis( false, myDlg ); + aCreator->create( false, myDlg ); } QStringList aNewHyps; _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" ); @@ -915,7 +918,7 @@ SMESH::SMESH_Hypothesis_var SMESHGUI_MeshOp::getAlgo( const int theDim ) SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHypName ); if ( aCreator ) - aCreator->CreateHypothesis( true, myDlg ); + aCreator->create( true, myDlg ); } QStringList tmpList; _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" ); diff --git a/src/SMESHGUI/SMESHGUI_aParameter.cxx b/src/SMESHGUI/SMESHGUI_aParameter.cxx deleted file mode 100644 index 65b07e75b..000000000 --- a/src/SMESHGUI/SMESHGUI_aParameter.cxx +++ /dev/null @@ -1,1108 +0,0 @@ -// SMESH SMESHGUI : GUI for SMESH component -// -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : SMESHGUI_aParameter.cxx -// Module : SMESH -// $Header$ - -#include "SMESHGUI_aParameter.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -SMESHGUI_aParameter::SMESHGUI_aParameter( const QString& label, const bool preview ) -: _needPreview( preview ), - _label(label) -{ -} - -SMESHGUI_aParameter::~SMESHGUI_aParameter() -{ -} - -bool SMESHGUI_aParameter::needPreview() const -{ - return _needPreview; -} - -QString& SMESHGUI_aParameter::Label() -{ - return _label; -} - -QString SMESHGUI_aParameter::sigValueChanged() const -{ - return QString::null; -} - -//================================================================================= -// class : SMESHGUI_intParameter -// purpose : -//================================================================================= -SMESHGUI_intParameter::SMESHGUI_intParameter (const int theInitValue, - const QString& theLabel, - const int theBottom, - const int theTop, - const bool preview ) - :SMESHGUI_aParameter(theLabel, preview), - _top(theTop), _bottom(theBottom), _initValue(theInitValue), - _newValue( theInitValue ) -{ -} -SMESHGUI_aParameter::Type SMESHGUI_intParameter::GetType() const -{ - return SMESHGUI_aParameter::INT; -} -bool SMESHGUI_intParameter::GetNewInt (int & theValue) const -{ - theValue = _newValue; - return _newValue != _initValue; -} -bool SMESHGUI_intParameter::GetNewDouble (double & Value) const -{ - return false; -} -bool SMESHGUI_intParameter::GetNewText (QString & Value) const -{ - return false; -} - -QWidget* SMESHGUI_intParameter::CreateWidget( QWidget* parent ) const -{ - return new QSpinBox( parent ); -} - -void SMESHGUI_intParameter::InitializeWidget (QWidget* theQWidget) const -{ - QSpinBox * aSpin = dynamic_cast< QSpinBox *>(theQWidget); - if (aSpin) { - aSpin->setMinValue(_bottom); - aSpin->setMaxValue(_top); - aSpin->setValue(_initValue); - } -} -void SMESHGUI_intParameter::TakeValue (QWidget* theQWidget) -{ - QSpinBox * aSpin = dynamic_cast< QSpinBox *>(theQWidget); - if (aSpin) - _newValue = aSpin->value(); -} - -QString SMESHGUI_intParameter::sigValueChanged() const -{ - return SIGNAL( valueChanged( int ) ); -} - -//================================================================================= -// class : SMESHGUI_doubleParameter -// purpose : -//================================================================================= -SMESHGUI_doubleParameter::SMESHGUI_doubleParameter (const double theInitValue, - const QString& theLabel, - const double theBottom, - const double theTop, - const double theStep, - const int theDecimals, - const bool preview ) - :SMESHGUI_aParameter(theLabel, preview), - _top(theTop), _bottom(theBottom), _step(theStep), - _initValue(theInitValue), _decimals(theDecimals) -{ -} -SMESHGUI_aParameter::Type SMESHGUI_doubleParameter::GetType() const -{ - return SMESHGUI_aParameter::DOUBLE; -} -bool SMESHGUI_doubleParameter::GetNewInt (int & theValue) const -{ - return false; -} -bool SMESHGUI_doubleParameter::GetNewDouble (double & Value) const -{ - Value = _newValue; - return _newValue != _initValue; -} -bool SMESHGUI_doubleParameter::GetNewText (QString & Value) const -{ - return false; -} - -QWidget* SMESHGUI_doubleParameter::CreateWidget( QWidget* parent ) const -{ - return new QtxDblSpinBox( parent ); -} - -void SMESHGUI_doubleParameter::InitializeWidget (QWidget* theQWidget) const -{ - QtxDblSpinBox* aSpin = dynamic_cast(theQWidget); - if (aSpin) { - aSpin->setPrecision(_decimals); -#ifdef NEW_GUI - aSpin->setDblPrecision(_bottom); -#endif - aSpin->setRange(_bottom, _top); - aSpin->setValue(_initValue); - aSpin->setLineStep(_step); - } -} -void SMESHGUI_doubleParameter::TakeValue (QWidget* theQWidget) -{ - QtxDblSpinBox* aSpin = dynamic_cast(theQWidget); - if (aSpin) - _newValue = aSpin->value(); -} - -QString SMESHGUI_doubleParameter::sigValueChanged() const -{ - return SIGNAL( valueChanged( double ) ); -} - -//================================================================================= -// class : SMESHGUI_strParameter -// purpose : -//================================================================================= -SMESHGUI_strParameter::SMESHGUI_strParameter (const QString& theInitValue, - const QString& theLabel, - const bool preview ) - :SMESHGUI_aParameter(theLabel, preview), - _initValue(theInitValue) -{ -} -SMESHGUI_aParameter::Type SMESHGUI_strParameter::GetType() const -{ - return SMESHGUI_aParameter::STRING; -} - -bool SMESHGUI_strParameter::GetNewInt (int & theValue) const -{ - return false; -} -bool SMESHGUI_strParameter::GetNewDouble (double & Value) const -{ - return false; -} -bool SMESHGUI_strParameter::GetNewText (QString & theValue) const -{ - theValue = _newValue; - return _newValue != _initValue; -} - -QWidget* SMESHGUI_strParameter::CreateWidget( QWidget* parent ) const -{ - return new QLineEdit( parent ); -} - -void SMESHGUI_strParameter::InitializeWidget (QWidget* theQWidget) const -{ - QLineEdit* anEdit = dynamic_cast< QLineEdit* >(theQWidget); - if (anEdit) { - anEdit->setText(_initValue); - } -} -void SMESHGUI_strParameter::TakeValue (QWidget* theQWidget) -{ - QLineEdit* anEdit = dynamic_cast< QLineEdit* >(theQWidget); - if (anEdit) - _newValue = anEdit->text(); -} - -QString SMESHGUI_strParameter::sigValueChanged() const -{ - return SIGNAL( textChanged( const QString& ) ); -} - - - -//================================================================================= -// class : SMESHGUI_dependParameter -// purpose : -//================================================================================= -SMESHGUI_dependParameter::SMESHGUI_dependParameter( const QString& label, const bool preview ) -: SMESHGUI_aParameter( label, preview ) -{ -} - -const SMESHGUI_dependParameter::ShownMap& SMESHGUI_dependParameter::shownMap() const -{ - return myShownMap; -} - -SMESHGUI_dependParameter::ShownMap& SMESHGUI_dependParameter::shownMap() -{ - return myShownMap; -} - - - - - -//================================================================================= -// class : SMESHGUI_enumParameter -// purpose : -//================================================================================= -SMESHGUI_enumParameter::SMESHGUI_enumParameter( const QStringList& values, - const int initValue, - const QString& label, - const bool preview ) -: SMESHGUI_dependParameter( label, preview ), - myInitValue( initValue ), - myValue( initValue ), - myValues( values ) -{ -} - -SMESHGUI_enumParameter::~SMESHGUI_enumParameter() -{ -} - -SMESHGUI_aParameter::Type SMESHGUI_enumParameter::GetType() const -{ - return SMESHGUI_aParameter::ENUM; -} - -bool SMESHGUI_enumParameter::GetNewInt( int& v ) const -{ - v = myValue; - return myValue!=myInitValue; -} - -bool SMESHGUI_enumParameter::GetNewDouble( double& ) const -{ - return false; -} - -bool SMESHGUI_enumParameter::GetNewText( QString& v ) const -{ - bool res = myValue>=0 && myValueinherits( "QComboBox" ) ) - { - QComboBox* c = ( QComboBox* ) w; - c->clear(); - c->insertStringList( myValues ); - c->setCurrentItem( myInitValue ); - } -} - -void SMESHGUI_enumParameter::TakeValue( QWidget* w ) -{ - if( w && w->inherits( "QComboBox" ) ) - { - QComboBox* c = ( QComboBox* ) w; - myValue = c->currentItem(); - } -} - -int SMESHGUI_enumParameter::Count() const -{ - return myValues.count(); -} - -QString SMESHGUI_enumParameter::sigValueChanged() const -{ - return SIGNAL( activated( int ) ); -} - - -//================================================================================= -// class : SMESHGUI_boolParameter -// purpose : -//================================================================================= -SMESHGUI_boolParameter::SMESHGUI_boolParameter( const bool initValue, - const QString& label, - const bool preview ) -: SMESHGUI_dependParameter( label, preview ), - myInitValue( initValue ), - myValue( myInitValue ) -{ -} - -SMESHGUI_boolParameter::~SMESHGUI_boolParameter() -{ -} - -SMESHGUI_aParameter::Type SMESHGUI_boolParameter::GetType() const -{ - return BOOL; -} - -bool SMESHGUI_boolParameter::GetNewInt( int& v ) const -{ - if( myValue ) - v = 1; - else - v = 0; - return v!=myInitValue; -} - -bool SMESHGUI_boolParameter::GetNewDouble( double& ) const -{ - return false; -} - -bool SMESHGUI_boolParameter::GetNewText( QString& ) const -{ - return false; -} - -QWidget* SMESHGUI_boolParameter::CreateWidget( QWidget* parent ) const -{ - return new QCheckBox( parent ); -} - -void SMESHGUI_boolParameter::InitializeWidget( QWidget* w ) const -{ - if( w && w->inherits( "QCheckBox" ) ) - { - QCheckBox* box = ( QCheckBox* )w; - box->setChecked( myInitValue ); - } -} - -void SMESHGUI_boolParameter::TakeValue( QWidget* w ) -{ - if( w && w->inherits( "QCheckBox" ) ) - { - QCheckBox* box = ( QCheckBox* )w; - myValue = box->isChecked(); - } -} - -QString SMESHGUI_boolParameter::sigValueChanged() const -{ - return SIGNAL( stateChanged( int ) ); -} - - - - -//================================================================================= -// class : SMESHGUI_doubleItem -// purpose : Custom table item which contains double and has double validator -//================================================================================= -class SMESHGUI_doubleItem: public QTableItem -{ -public: - SMESHGUI_doubleItem( QTable*, EditType, const double ); - virtual ~SMESHGUI_doubleItem(); - - void setValidator( const double, const double, const int ); - void validator( double&, double&, int& ); - virtual QWidget* createEditor() const; - -private: - QDoubleValidator* myValidator; -}; - -SMESHGUI_doubleItem::SMESHGUI_doubleItem( QTable* t, EditType e, const double num ) -: QTableItem( t, e, QString( "%1" ).arg( num ) ), - myValidator( new QDoubleValidator( 0.0, 1.0, 3, t ) ) -{ -} - -SMESHGUI_doubleItem::~SMESHGUI_doubleItem() -{ -} - -void SMESHGUI_doubleItem::setValidator( const double bot, const double top, const int dec ) -{ - myValidator->setBottom( bot ); - myValidator->setTop( top ); - myValidator->setDecimals( dec ); -} - -void SMESHGUI_doubleItem::validator( double& bot, double& top, int& dec ) -{ - bot = myValidator->bottom(); - top = myValidator->top(); - dec = myValidator->decimals(); -} - -QWidget* SMESHGUI_doubleItem::createEditor() const -{ - QWidget* res = QTableItem::createEditor(); - if( res && res->inherits( "QLineEdit" ) ) - { - QLineEdit* l = ( QLineEdit* )res; - l->setValidator( myValidator ); - } - return res; -} - - -//================================================================================= -// class : SMESHGUI_Table -// purpose : -//================================================================================= -SMESHGUI_Table::SMESHGUI_Table( const SMESHGUI_tableParameter* tab, int numRows, int numCols, - QWidget* parent, const char* name ) -: QTable( numRows, numCols, parent, name ), - myParam( ( SMESHGUI_tableParameter* )tab ) -{ -} - -SMESHGUI_Table::~SMESHGUI_Table() -{ -} - -QSize SMESHGUI_Table::sizeHint() const -{ - if( cachedSizeHint().isValid() ) - return cachedSizeHint(); - - constPolish(); - - QSize sh = QScrollView::sizeHint(); - if( sh.width()<400 ) - sh.setWidth( 400 ); - if( sh.height()<200 ) - sh.setHeight( 200 ); - - setCachedSizeHint( sh ); - return sh; -} - -void SMESHGUI_Table::stopEditing() -{ - endEdit( currEditRow(), currEditCol(), false, false ); -} - -void SMESHGUI_Table::validator( const int row, const int col, double& minV, double& maxV, int& dec ) -{ - SMESHGUI_doubleItem* it = dynamic_cast( item( row, col ) ); - if( it ) - it->validator( minV, maxV, dec ); -} - -void SMESHGUI_Table::setValidator( const double minV, const double maxV, const int dec, - const int rmin, const int rmax, - const int cmin, const int cmax ) -{ - int r1 = rmin>=0 ? rmin : 0, - r2 = rmax>=0 ? rmax : numRows(), - c1 = cmin>=0 ? cmin : 0, - c2 = cmax>=0 ? cmax : numCols(); - - for( int i=r1; i<=r2; i++ ) - for( int j=c1; j<=c2; j++ ) - { - SMESHGUI_doubleItem* it = dynamic_cast( item( i, j ) ); - if( it ) - it->setValidator( minV, maxV, dec ); - } -} - -bool SMESHGUI_Table::eventFilter( QObject* o, QEvent* e ) -{ - if( o && e && e->type()==QEvent::KeyPress ) - { - QKeyEvent* ke = ( QKeyEvent* )e; - if( ke->key()==Qt::Key_Tab || ke->key()==Qt::Key_Backtab || ke->key()==Qt::Key_Return ) - { - keyPressEvent( ke ); - return true; - } - } - - return QTable::eventFilter( o, e ); -} - -void SMESHGUI_Table::keyPressEvent( QKeyEvent* e ) -{ - if( e ) - { - bool shift = ( e->state() & Qt::ShiftButton ); - int col = currentColumn(), row = currentRow(); - if( e->key()==Qt::Key_Tab || e->key()==Qt::Key_Backtab ) - { - if( e->key()==Qt::Key_Tab ) - col++; - else - col--; - if( col<0 ) - { - col = numCols()-1; - row--; - if( row<0 ) - { - col = 0; - row = 0; - } - } - if( col>=numCols() ) - { - col = 0; - row++; - if( row>=numRows() ) - row = numRows()-1; - } - e->accept(); - } - else if( e->key()==Qt::Key_Return ) - { - col = 0; - if( shift ) - row--; - else - row++; - if( row<0 ) - row = 0; - else if( row>=numRows() ) - { - //add row - myParam->onEdit( this, SMESHGUI_TableFrame::ADD_ROW, 1 ); - } - e->accept(); - } - if( e->isAccepted() ) - { - clearSelection(); - setCurrentCell( row, col ); - } - else - QTable::keyPressEvent( e ); - } -} - -QWidget* SMESHGUI_Table::createEditor( int r, int c, bool init ) const -{ - QWidget* w = QTable::createEditor( r, c, init ); - if( w ) - w->installEventFilter( this ); - return w; -} - - - -//================================================================================= -// class : SMESHGUI_TableFrame -// purpose : -//================================================================================= -SMESHGUI_TableFrame::SMESHGUI_TableFrame( const SMESHGUI_tableParameter* param, QWidget* parent ) -: QFrame( parent ) -{ - QVBoxLayout* main = new QVBoxLayout( this, 0, 0 ); - - myTable = new SMESHGUI_Table( param, 1, 1, this ); - connect( myTable, SIGNAL( valueChanged( int, int ) ), this, SIGNAL( valueChanged( int, int ) ) ); - - QFrame* aButFrame = new QFrame( this ); - QHBoxLayout* butLay = new QHBoxLayout( aButFrame, 5, 5 ); - - myAddColumn = new QPushButton( "Add column", aButFrame ); - - myRemoveColumn = new QPushButton( "Remove column", aButFrame ); - - myAddRow = new QPushButton( "Add row", aButFrame ); - - myRemoveRow = new QPushButton( "Remove row", aButFrame ); - - butLay->addWidget( myAddColumn, 0 ); - butLay->addWidget( myRemoveColumn, 0 ); - butLay->addWidget( myAddRow, 0 ); - butLay->addWidget( myRemoveRow, 0 ); - butLay->addStretch( 1 ); - - main->addWidget( myTable, 1 ); - main->addWidget( aButFrame, 0 ); - - connect( myAddColumn, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); - connect( myRemoveColumn, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); - connect( myAddRow, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); - connect( myRemoveRow, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); -} - -SMESHGUI_TableFrame::~SMESHGUI_TableFrame() -{ -} - -SMESHGUI_Table* SMESHGUI_TableFrame::table() const -{ - return myTable; -} - -void SMESHGUI_TableFrame::setShown( const Button b, const bool sh ) -{ - if( button( b ) ) - button( b )->setShown( sh ); -} - -bool SMESHGUI_TableFrame::isShown( const Button b ) const -{ - bool res = false; - if( button( b ) ) - res = button( b )->isShown(); - return res; -} - -QButton* SMESHGUI_TableFrame::button( const Button b ) const -{ - QButton* res = 0; - switch( b ) - { - case ADD_COLUMN: - res = myAddColumn; - break; - - case REMOVE_COLUMN: - res = myRemoveColumn; - break; - - case ADD_ROW: - res = myAddRow; - break; - - case REMOVE_ROW: - res = myRemoveRow; - break; - } - return res; -} - -void SMESHGUI_TableFrame::onButtonClicked() -{ - if( sender()==button( ADD_COLUMN ) ) - emit toEdit( ADD_COLUMN, table()->currentColumn() ); - - else if( sender()==button( REMOVE_COLUMN ) ) - emit toEdit( REMOVE_COLUMN, table()->currentColumn() ); - - else if( sender()==button( ADD_ROW ) ) - emit toEdit( ADD_ROW, table()->currentRow() ); - - else if( sender()==button( REMOVE_ROW ) ) - emit toEdit( REMOVE_ROW, table()->currentRow() ); -} - - -//================================================================================= -// class : SMESHGUI_tableParameter -// purpose : -//================================================================================= -SMESHGUI_tableParameter::SMESHGUI_tableParameter( const double init, - const QString& label, - const bool preview ) -: SMESHGUI_aParameter( label, preview ), - myInitValue( init ), - myColsInt( 1 ), - myRowsInt( 1 ), - myEditCols( false ), - myEditRows( false ) -{ -} - -SMESHGUI_tableParameter::~SMESHGUI_tableParameter() -{ -} - -bool operator<( const QPair& p1, const QPair& p2 ) -{ - return p1.first < p2.first; -} - -void SMESHGUI_tableParameter::sortData( SMESH::double_array& arr ) -{ - QValueList< QPair > aData; - if( arr.length()%2==1 ) - arr.length( arr.length()-1 ); - - int aLen = arr.length(); - for( int i=0; i( arr[2*i], arr[2*i+1] ) ); - - qHeapSort( aData ); - - QValueList< QPair >::const_iterator anIt = aData.begin(), aLast = aData.end(); - QValueList unique_values; - double prev; int i=0; - if( (*anIt).first>0.0 ) - { - unique_values.append( 0.0 ); - unique_values.append( 0.0 ); - i++; prev = 0.0; - } - for( ; anIt!=aLast; anIt++ ) - { - if( i==0 || (*anIt).first>prev ) - { - unique_values.append( (*anIt).first ); - unique_values.append( (*anIt).second ); - i++; - } - prev = (*anIt).first; - } - if( prev<1.0 ) - { - unique_values.append( 1.0 ); - unique_values.append( 0.0 ); - } - - arr.length( unique_values.count() ); - QValueList::const_iterator anIt1 = unique_values.begin(), aLast1 = unique_values.end(); - for( int j=0; anIt1!=aLast1; anIt1++, j++ ) - arr[j] = *anIt1; -} - -SMESHGUI_aParameter::Type SMESHGUI_tableParameter::GetType() const -{ - return TABLE; -} - -bool SMESHGUI_tableParameter::GetNewInt( int& ) const -{ - return false; -} - -bool SMESHGUI_tableParameter::GetNewDouble( double& ) const -{ - return false; -} - -bool SMESHGUI_tableParameter::GetNewText( QString& ) const -{ - return false; -} - -QWidget* SMESHGUI_tableParameter::CreateWidget( QWidget* par ) const -{ - SMESHGUI_TableFrame* t = new SMESHGUI_TableFrame( this, par ); - connect( t, SIGNAL( toEdit( SMESHGUI_TableFrame::Button, int ) ), - this, SLOT ( onEdit( SMESHGUI_TableFrame::Button, int ) ) ); - - update( t ); - return t; -} - -void SMESHGUI_tableParameter::setItems( QWidget* w, - int old_row, int new_row, - int old_col, int new_col ) const -{ - if( w && w->inherits( "SMESHGUI_TableFrame" ) ) - { - QTable* tab = ( ( SMESHGUI_TableFrame* )w )->table(); - - if( old_row<0 ) - old_row = 0; - if( new_row<0 ) - new_row = tab->numRows(); - if( old_col<0 ) - old_col = 0; - if( new_col<0 ) - new_col = tab->numCols(); - - for( int i=old_row, m=new_row; isetItem( i, j, new SMESHGUI_doubleItem( tab, QTableItem::WhenCurrent, myInitValue ) ); - - for( int i=0, m=new_row; isetItem( i, j, new SMESHGUI_doubleItem( tab, QTableItem::WhenCurrent, myInitValue ) ); - - for( int j=old_col; jsetColumnWidth( j, 50 ); - } -} - -void SMESHGUI_tableParameter::InitializeWidget( QWidget* w ) const -{ - setItems( w ); - - if( w && w->inherits( "SMESHGUI_TableFrame" ) ) - { - SMESHGUI_Table* tab = ( ( SMESHGUI_TableFrame* )w )->table(); - tab->stopEditing(); - - int col = tab->numCols(), - row = tab->numRows(); - - for( int i=0, m=row; iitem( i, j )->setText( QString( "%1" ).arg( myData[col*i+j] ) ); - } -} - -void SMESHGUI_tableParameter::TakeValue( QWidget* w ) -{ - if( w && w->inherits( "SMESHGUI_TableFrame" ) ) - { - QTable* tab = ( ( SMESHGUI_TableFrame* )w )->table(); - - int col = tab->numCols(), - row = tab->numRows(); - - myData.length( col*row ); - for( int i=0; itext( i, j ).toDouble(); - } -} - -void SMESHGUI_tableParameter::data( SMESH::double_array& v ) const -{ - v = myData; - sortData( v ); -} - -void SMESHGUI_tableParameter::setData( const SMESH::double_array& d ) -{ - myData = d; - sortData( myData ); -} - -void SMESHGUI_tableParameter::update( QWidget* w ) const -{ - if( w && w->inherits( "SMESHGUI_TableFrame" ) ) - { - SMESHGUI_TableFrame* tabfr = ( SMESHGUI_TableFrame* ) w; - SMESHGUI_Table* tab = tabfr->table(); - - int old_col = tab->numCols(), - old_row = tab->numRows(); - - int col = myColsInt, row = myRowsInt; - if( myCols.get() ) - myCols->GetNewInt( col ); - - if( myRows.get() ) - myRows->GetNewInt( row ); - - if( col<=0 ) - col = 1; - if( row<=0 ) - row = 1; - - if( col!=tab->numCols() ) - tab->setNumCols( col ); - - if( row!=tab->numRows() ) - tab->setNumRows( row ); - - tabfr->setShown( SMESHGUI_TableFrame::ADD_COLUMN, myEditCols ); - tabfr->setShown( SMESHGUI_TableFrame::REMOVE_COLUMN, myEditCols ); - tabfr->setShown( SMESHGUI_TableFrame::ADD_ROW, myEditRows ); - tabfr->setShown( SMESHGUI_TableFrame::REMOVE_ROW, myEditRows ); - - setItems( w, old_row, row, old_col, col ); - - QMap< int, QString >::const_iterator aNIt = myColNames.begin(), - aNLast = myColNames.end(); - for( ; aNIt!=aNLast; aNIt++ ) - tab->horizontalHeader()->setLabel( aNIt.key(), aNIt.data() ); - - ValidatorsMap::const_iterator anIt = myValidators.begin(), - aLast = myValidators.end(); - for( ; anIt!=aLast; anIt++ ) - { - int row = anIt.key(), dec; - double minV, maxV; - validator( row, minV, maxV, dec ); - tab->setValidator( minV, maxV, dec, -1, -1, col, col ); - } - - QSize s = tab->sizeHint(); - tab->resize( s.width(), s.height() ); - } -} - -void SMESHGUI_tableParameter::setColCount( const int c, QWidget* w ) -{ - myColsInt = c; - update( w ); -} - -void SMESHGUI_tableParameter::setRowCount( const int c, QWidget* w ) -{ - myRowsInt = c; - update( w ); -} - -void SMESHGUI_tableParameter::setColCount( const SMESHGUI_aParameterPtr p, QWidget* w ) -{ - if( p.get() ) - { - myCols = p; - update( w ); - } -} - -void SMESHGUI_tableParameter::setRowCount( const SMESHGUI_aParameterPtr p, QWidget* w ) -{ - if( p.get() ) - { - myRows = p; - update( w ); - } -} - -QString SMESHGUI_tableParameter::sigValueChanged() const -{ - return SIGNAL( valueChanged( int, int ) ); -} - -void SMESHGUI_tableParameter::setValidator( const int ind, const double minV, const double maxV, const int dec ) -{ - ValidatorInfo inf; - inf.myMin = minV; - inf.myMax = maxV; - inf.myDecimals = dec; - myValidators[ ind ] = inf; -} - -void SMESHGUI_tableParameter::validator( const int ind, double& minV, double& maxV, int& dec ) const -{ - if( myValidators.contains( ind ) ) - { - const ValidatorInfo& inf = myValidators[ ind ]; - minV = inf.myMin; - maxV = inf.myMax; - dec = inf.myDecimals; - } -} - -void SMESHGUI_tableParameter::setEditCols( const bool ed ) -{ - myEditCols = ed; -} - -void SMESHGUI_tableParameter::setEditRows( const bool ed ) -{ - myEditRows = ed; -} - -void SMESHGUI_tableParameter::setColName( const int ind, const QString& name ) -{ - myColNames.insert( ind, name ); -} - -QString SMESHGUI_tableParameter::colName( const int ind ) const -{ - if( myColNames.contains( ind ) ) - return myColNames[ ind ]; - else - return QString::null; -} - -void SMESHGUI_tableParameter::onEdit( SMESHGUI_TableFrame::Button b, int n ) -{ - if( sender() && sender()->inherits( "SMESHGUI_TableFrame" ) ) - { - SMESHGUI_TableFrame* fr = ( SMESHGUI_TableFrame* )sender(); - SMESHGUI_Table* tab = fr->table(); - onEdit( tab, b, n ); - } -} - -void SMESHGUI_tableParameter::onEdit( SMESHGUI_Table* tab, SMESHGUI_TableFrame::Button b, int n ) -{ - if( !tab ) - return; - - SMESHGUI_TableFrame* fr = dynamic_cast( tab->parent() ); - - switch( b ) - { - case SMESHGUI_TableFrame::ADD_COLUMN: - { - if( !myEditCols || myCols.get() ) - return; - - myColsInt++; update( fr ); - if( n>=0 ) - for( int i=0; i=n; j-- ) - if( j==n ) - tab->setText( i, j, QString( "%1" ).arg( myInitValue ) ); - else - tab->setText( i, j, tab->text( i, j-1 ) ); - break; - } - - case SMESHGUI_TableFrame::REMOVE_COLUMN: - { - if( !myEditCols || myCols.get() || myColsInt<=1 ) - return; - - if( n>=0 ) - for( int i=0; isetText( i, j, tab->text( i, j+1 ) ); - myColsInt--; update( fr ); - - break; - } - - case SMESHGUI_TableFrame::ADD_ROW: - { - if( !myEditRows || myRows.get() ) - return; - - myRowsInt++; update( fr ); - if( n>=0 ) - for( int i=myRowsInt-1; i>=n; i-- ) - for( int j=0; jsetText( i, j, QString( "%1" ).arg( myInitValue ) ); - else - tab->setText( i, j, tab->text( i-1, j ) ); - break; - } - - case SMESHGUI_TableFrame::REMOVE_ROW: - { - if( !myEditRows || myRows.get() || myRowsInt<=1 ) - return; - - if( n>=0 ) - for( int i=n; isetText( i, j, tab->text( i+1, j ) ); - myRowsInt--; update( fr ); - - break; - } - } -} diff --git a/src/SMESHGUI/SMESHGUI_aParameterDlg.cxx b/src/SMESHGUI/SMESHGUI_aParameterDlg.cxx deleted file mode 100644 index 211b4f0ec..000000000 --- a/src/SMESHGUI/SMESHGUI_aParameterDlg.cxx +++ /dev/null @@ -1,305 +0,0 @@ -// SMESH SMESHGUI : GUI for SMESH component -// -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : SMESHGUI_aParameterDlg.cxx -// Author : Nicolas REJNERI -// Module : SMESH -// $Header$ - -#include "SMESHGUI_aParameterDlg.h" -#include "SMESHGUI_aParameter.h" -#include "SMESHGUI.h" -#include "SMESHGUI_SpinBox.h" -#include "SMESHGUI_Utils.h" -#include "SMESHGUI_FunctionPreview.h" - -#include "SUIT_Tools.h" -#include "SUIT_Desktop.h" - -// QT Includes -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -//====================================================================================== -// function : SMESHGUI_aParameterDlg() -// -// The dialog will by default be modal, unless you set 'modal' to -// false when constructing dialog -// -//====================================================================================== -SMESHGUI_aParameterDlg::SMESHGUI_aParameterDlg - ( SMESHGUI* theModule, - std::list params, - QString title, - bool modal) -: QDialog( SMESH::GetDesktop( theModule ), "MyParameterDialog", modal, WStyle_Customize | - WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), - myParamList(params), - mySMESHGUI(theModule) -{ - /* creating widgets */ - init(); - /* title */ - setCaption(title); - - /* Move widget on the botton right corner of main widget */ - SUIT_Tools::centerWidget(this, SMESH::GetDesktop( theModule ) ); -} - -//====================================================================================== -// function : SMESHGUI_aParameterDlg::init() -// purpose : creates dialog's layout -//====================================================================================== -void SMESHGUI_aParameterDlg::init() -{ - setSizeGripEnabled(TRUE); - - QVBoxLayout* topLayout = new QVBoxLayout(this); - topLayout->setMargin(11); topLayout->setSpacing(6); - - /***************************************************************/ - QGroupBox* GroupC1 = new QGroupBox(this, "GroupC1"); - GroupC1->setColumnLayout(0, Qt::Vertical); - GroupC1->layout()->setSpacing(0); - GroupC1->layout()->setMargin(0); - QGridLayout* GroupC1Layout = new QGridLayout(GroupC1->layout()); - GroupC1Layout->setAlignment(Qt::AlignTop); - GroupC1Layout->setSpacing(6); - GroupC1Layout->setMargin(11); - /* Spin boxes with labels */ - list::iterator paramIt = myParamList.begin(); - int row; - for( row = 0; paramIt != myParamList.end(); paramIt++ , row++) - { - SMESHGUI_aParameterPtr param = (*paramIt); - QLabel * label = new QLabel(GroupC1, "TextLabel"); - GroupC1Layout->addWidget(label, row, 0); - label->setText(param->Label()); - QWidget* aSpinWidget = param->CreateWidget( GroupC1 ); - if (aSpinWidget) { - GroupC1Layout->addWidget(aSpinWidget, row, 1); - aSpinWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum)); - aSpinWidget->setMinimumSize(150, 0); - - QString sig = param->sigValueChanged(); - if( !sig.isEmpty() /*&& param->GetType()!=SMESHGUI_aParameter::TABLE*/ ) - connect( aSpinWidget, sig.latin1(), this, SLOT( onValueChanged() ) ); - - param->InitializeWidget(aSpinWidget); - mySpinList.push_back(aSpinWidget); - myLabelList.push_back(label); - } - } - - myPreview = new SMESHGUI_FunctionPreview( GroupC1 ); - myPreview->hide(); - GroupC1Layout->addWidget( myPreview, row, 1 ); - - paramIt = myParamList.begin(); - std::list::const_iterator anIt = mySpinList.begin(); - for( ; paramIt!=myParamList.end(); paramIt++, anIt++ ) - { - (*paramIt)->TakeValue( *anIt ); - UpdateShown( *paramIt, *anIt ); - FunctionPreview( *paramIt, *anIt ); - } - - /***************************************************************/ - QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons"); - GroupButtons->setColumnLayout(0, Qt::Vertical); - GroupButtons->layout()->setSpacing(0); - GroupButtons->layout()->setMargin(0); - QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout()); - GroupButtonsLayout->setAlignment(Qt::AlignTop); - GroupButtonsLayout->setSpacing(6); - GroupButtonsLayout->setMargin(11); - /* Ok button */ - myButtonOk = new QPushButton(GroupButtons, "buttonOk"); - myButtonOk->setText(tr("SMESH_BUT_OK")); - myButtonOk->setAutoDefault(TRUE); - myButtonOk->setDefault(TRUE); - GroupButtonsLayout->addWidget(myButtonOk, 0, 0); - /* add spacer between buttons */ - GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1); - /* Cancel button */ - myButtonCancel = new QPushButton(GroupButtons, "buttonCancel"); - myButtonCancel->setText(tr("SMESH_BUT_CANCEL")); - myButtonCancel->setAutoDefault(TRUE); - GroupButtonsLayout->addWidget(myButtonCancel, 0, 2); - - /***************************************************************/ - topLayout->addWidget(GroupC1, 1 ); - topLayout->addWidget(GroupButtons, 0 ); - - /* signals and slots connections */ - connect(myButtonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk())); - connect(myButtonCancel, SIGNAL(clicked()), this, SLOT(reject())); -} - -//====================================================================================== -// function : ~SMESHGUI_aParameterDlg() -// purpose : Destructor -//====================================================================================== -SMESHGUI_aParameterDlg::~SMESHGUI_aParameterDlg() -{ -} - -//======================================================================= -//function : ClickOnOk -//purpose : -//======================================================================= -void SMESHGUI_aParameterDlg::ClickOnOk() -{ - if (!mySMESHGUI->isActiveStudyLocked()) { - list::iterator paramIt = myParamList.begin(); - list::iterator widgetIt = mySpinList.begin(); - for (; - paramIt != myParamList.end() && widgetIt != mySpinList.end(); - paramIt++ , widgetIt++) - (*paramIt)->TakeValue(*widgetIt); - - accept(); - } -} - -//======================================================================= -// function : Parameters() -// purpose : return a list of parameters from a dialog box -//======================================================================= -bool SMESHGUI_aParameterDlg::Parameters( SMESHGUI* theModule, - list params, - const char *aTitle) -{ - if (!params.empty()) { - SMESHGUI_aParameterDlg *Dialog = - new SMESHGUI_aParameterDlg( theModule, params, aTitle, TRUE); - return (Dialog->exec() == QDialog::Accepted); - } - return false; -} - -//======================================================================= -// function : FunctionPreview -// purpose : -//======================================================================= -void SMESHGUI_aParameterDlg::FunctionPreview( const SMESHGUI_aParameterPtr p, QWidget* w ) -{ - if( !w || !w->isShown() ) - return; - - SMESHGUI_strParameter* str_param = dynamic_cast( p.operator->() ); - SMESHGUI_tableParameter* tab_param = dynamic_cast( p.operator->() ); - SMESHGUI_boolParameter* bool_param = dynamic_cast( p.operator->() ); - if( str_param && str_param->needPreview() ) - { - QString val; str_param->GetNewText( val ); - if( !val.isNull() ) - myPreview->setParams( val ); - } - else if( tab_param && tab_param->needPreview() ) - { - SMESH::double_array d; - tab_param->data( d ); - myPreview->setParams( d ); - } - else if( bool_param && bool_param->needPreview() ) - { - int exp=0; - bool_param->GetNewInt( exp ); - myPreview->setIsExp( exp ); - } -} - -//======================================================================= -// function : onValueChanged -// purpose : -//======================================================================= -void SMESHGUI_aParameterDlg::onValueChanged() -{ - if( sender()->inherits( "QWidget" ) ) - { - QWidget* w = ( QWidget* )sender(); - - - std::list::const_iterator anIt = mySpinList.begin(), - aLast = mySpinList.end(); - std::list::const_iterator aPIt = myParamList.begin(); - for( ; anIt!=aLast; anIt++, aPIt++ ) - if( *anIt == w ) - { - (*aPIt)->TakeValue( w ); - UpdateShown( *aPIt, w ); - FunctionPreview( *aPIt, w ); - break; - } - } -} - -//======================================================================= -// function : onValueChanged -// purpose : -//======================================================================= -void SMESHGUI_aParameterDlg::UpdateShown( const SMESHGUI_aParameterPtr param, QWidget* w ) -{ - SMESHGUI_dependParameter* depPar = dynamic_cast( param.get() ); - if( !depPar ) - depPar = dynamic_cast( param.get() ); - - if( !depPar ) - return; - - SMESHGUI_dependParameter::ShownMap& map = depPar->shownMap(); - if( map.isEmpty() ) - return; - - int val; - depPar->TakeValue( w ); - depPar->GetNewInt( val ); - bool hasValue = map.contains( val ); - - std::list::const_iterator anIt = mySpinList.begin(), - aLast = mySpinList.end(), - aLIt = myLabelList.begin(); - std::list::iterator aPIt = myParamList.begin(); - bool preview = false; - for( int i=0; anIt!=aLast; anIt++, aLIt++, i++, aPIt++ ) - { - bool shown = hasValue && map[ val ].contains( i ); - (*anIt)->setShown( shown ); - (*aLIt)->setShown( shown ); - if( shown ) - { - SMESHGUI_strParameter* str_param = dynamic_cast( (*aPIt).operator->() ); - SMESHGUI_tableParameter* tab_param = dynamic_cast( (*aPIt).operator->() ); - preview = preview || ( str_param && str_param->needPreview() ) || ( tab_param && tab_param->needPreview() ); - } - } - myPreview->setShown( preview ); -} diff --git a/src/SMESHGUI/SMESHGUI_aParameterDlg.h b/src/SMESHGUI/SMESHGUI_aParameterDlg.h deleted file mode 100644 index f749aeedd..000000000 --- a/src/SMESHGUI/SMESHGUI_aParameterDlg.h +++ /dev/null @@ -1,87 +0,0 @@ -// SMESH SMESHGUI : GUI for SMESH component -// -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : SMESHGUI_aParameterDlg.h -// Author : Nicolas REJNERI -// Module : SMESH -// $Header$ - -#ifndef SMESHGUI_aParameterDlg_H -#define SMESHGUI_aParameterDlg_H - -// QT Includes -#include - -#include -#include "SMESHGUI_aParameter.h" - -class QLabel; -class QPushButton; -class SMESHGUI; -class QWidget; -class SMESHGUI_FunctionPreview; - -//================================================================================= -// class : SMESHGUI_aParameterDlg -// purpose : -//================================================================================= -class SMESHGUI_aParameterDlg : public QDialog -{ - Q_OBJECT - -public: - SMESHGUI_aParameterDlg( SMESHGUI*, - std::list params, - QString title = QString::null, - bool modal = TRUE); - - ~SMESHGUI_aParameterDlg(); - - /* Parameter function */ - static bool Parameters( SMESHGUI*, std::list params, const char *aTitle); - -protected: - void init(); - -protected slots: - virtual void onValueChanged(); - -private slots: - void ClickOnOk(); - void UpdateShown( const SMESHGUI_aParameterPtr, QWidget* ); - -private: - void FunctionPreview( const SMESHGUI_aParameterPtr, QWidget* ); - -private: - SMESHGUI* mySMESHGUI; - - QPushButton* myButtonOk; - QPushButton* myButtonCancel; - - std::list mySpinList, myLabelList; - std::list myParamList; - SMESHGUI_FunctionPreview* myPreview; -}; - -#endif // SMESHGUI_aParameterDlg.h diff --git a/src/SMESH_SWIG/SMESH_reg.py b/src/SMESH_SWIG/SMESH_reg.py index cbe9e1d2d..3a2f74ae8 100644 --- a/src/SMESH_SWIG/SMESH_reg.py +++ b/src/SMESH_SWIG/SMESH_reg.py @@ -98,7 +98,8 @@ hypNbSeg.append(hypNbSeg2) hypNbSeg3 = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so") hypNbSeg3.SetDistrType(2) hypNbSeg3.SetNumberOfSegments(7) -hypNbSeg3.SetTableFunction( [0.25, 0.5, 0.5, 0.25] ) +hypNbSeg3.SetTableFunction( [0, 0.1, 0.5, 1.0, 1.0, 0.1] ) +hypNbSeg3.SetConversionMode(0) print hypNbSeg3.GetName() print hypNbSeg3.GetId() print hypNbSeg3.GetNumberOfSegments() @@ -110,6 +111,7 @@ hypNbSeg4 = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so") hypNbSeg4.SetDistrType(3) hypNbSeg4.SetNumberOfSegments(10) hypNbSeg4.SetExpressionFunction("sin(3*t)") +hypNbSeg4.SetConversionMode(1) print hypNbSeg4.GetName() print hypNbSeg4.GetId() print hypNbSeg4.GetNumberOfSegments() diff --git a/src/StdMeshers/Makefile.in b/src/StdMeshers/Makefile.in index d44d4cc68..592ff2b2b 100644 --- a/src/StdMeshers/Makefile.in +++ b/src/StdMeshers/Makefile.in @@ -23,7 +23,6 @@ # File : Makefile.in # Author : Julia DOROVSKIKH # Module : SMESH -# $Header$ top_srcdir=@top_srcdir@ top_builddir=../.. @@ -50,6 +49,7 @@ EXPORT_HEADERS = \ StdMeshers_MEFISTO_2D.hxx \ StdMeshers_Hexa_3D.hxx \ StdMeshers_AutomaticLength.hxx \ + StdMeshers_Distribution.hxx \ StdMeshers_QuadranglePreference.hxx EXPORT_PYSCRIPTS = @@ -75,6 +75,7 @@ LIB_SRC = \ StdMeshers_Penta_3D.cxx \ StdMeshers_Hexa_3D.cxx \ StdMeshers_AutomaticLength.cxx \ + StdMeshers_Distribution.cxx \ StdMeshers_QuadranglePreference.cxx LIB_SERVER_IDL = diff --git a/src/StdMeshers/StdMeshers_Distribution.cxx b/src/StdMeshers/StdMeshers_Distribution.cxx new file mode 100644 index 000000000..93858296b --- /dev/null +++ b/src/StdMeshers/StdMeshers_Distribution.cxx @@ -0,0 +1,342 @@ +// SMESH StdMeshers : implementaion of point distribution algorithm +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : StdMeshers_Distribution.cxx +// Author : Alexandre SOLOVYOV +// Module : SMESH +// $Header$ + +#include "StdMeshers_Distribution.hxx" +#include +#include +#include +#include +#include +#include + +Function::Function( const int conv ) +: myConv( conv ) +{ +} + +Function::~Function() +{ +} + +bool Function::value( const double, double& f ) const +{ + CASCatch_CatchSignals aCatchSignals; + aCatchSignals.Activate(); + + bool ok = true; + if( myConv==0 ) + { + CASCatch_TRY + { + f = pow( 10, f ); + } + CASCatch_CATCH(CASCatch_Failure) + { + aCatchSignals.Deactivate(); + Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught(); + f = 0.0; + ok = false; + } + } + else if( myConv==1 && f<0.0 ) + f = 0.0; + + return ok; +} + +FunctionIntegral::FunctionIntegral( const Function* f, const double st ) +: Function( -1 ), + myFunc( const_cast( f ) ), + myStart( st ) +{ +} + +FunctionIntegral::~FunctionIntegral() +{ +} + +bool FunctionIntegral::value( const double t, double& f ) const +{ + f = myFunc ? myFunc->integral( myStart, t ) : 0; + return myFunc!=0 && Function::value( t, f ); +} + +double FunctionIntegral::integral( const double, const double ) const +{ + return 0; +} + +FunctionTable::FunctionTable( const std::vector& data, const int conv ) +: Function( conv ) +{ + myData = data; +} + +FunctionTable::~FunctionTable() +{ +} + +bool FunctionTable::value( const double t, double& f ) const +{ + int i1, i2; + if( !findBounds( t, i1, i2 ) ) + return false; + + double + x1 = myData[2*i1], y1 = myData[2*i1+1], + x2 = myData[2*i2], y2 = myData[2*i2+1]; + + Function::value( x1, y1 ); + Function::value( x2, y2 ); + + f = y1 + ( y2-y1 ) * ( t-x1 ) / ( x2-x1 ); + return true; +} + +double FunctionTable::integral( const int i ) const +{ + if( i>=0 && iProcess( ( Standard_CString )str ); + } + CASCatch_CATCH(CASCatch_Failure) + { + aCatchSignals.Deactivate(); + Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught(); + ok = false; + } + aCatchSignals.Deactivate(); + + if( !ok || !myExpr->IsDone() ) + myExpr.Nullify(); + + myVars.ChangeValue( 1 ) = new Expr_NamedUnknown( "t" ); +} + +FunctionExpr::~FunctionExpr() +{ +} + +Standard_Boolean FunctionExpr::Value( Standard_Real T, Standard_Real& F ) +{ + double f; + Standard_Boolean res = value( T, f ); + F = f; + return res; +} + +bool FunctionExpr::value( const double t, double& f ) const +{ + if( myExpr.IsNull() ) + return false; + + OSD::SetSignal( true ); + CASCatch_CatchSignals aCatchSignals; + aCatchSignals.Activate(); + + ( ( TColStd_Array1OfReal& )myValues ).ChangeValue( 1 ) = t; + bool ok = true; + CASCatch_TRY { + f = myExpr->Expression()->Evaluate( myVars, myValues ); + } + CASCatch_CATCH(CASCatch_Failure) { + aCatchSignals.Deactivate(); + Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught(); + f = 0.0; + ok = false; + } + + aCatchSignals.Deactivate(); + ok = Function::value( t, f ) && ok; + return ok; +} + +double FunctionExpr::integral( const double a, const double b ) const +{ + double res = 0.0; + CASCatch_TRY + { + math_GaussSingleIntegration _int( ( math_Function& )*this, a, b, 20 ); + if( _int.IsDone() ) + res = _int.Value(); + } + CASCatch_CATCH(CASCatch_Failure) + { + res = 0.0; + MESSAGE( "Exception in integral calculating" ); + } + return res; +} + +double dihotomySolve( Function& f, const double val, const double _start, const double _fin, const double eps, bool& ok ) +{ + double start = _start, fin = _fin, start_val, fin_val; bool ok1, ok2; + ok1 = f.value( start, start_val ); + ok2 = f.value( fin, fin_val ); + + if( !ok1 || !ok2 ) + { + ok = false; + return 0.0; + } + + bool start_pos = start_val>=val, fin_pos = fin_val>=val; + ok = true; + + while( fin-start>eps ) + { + double mid = ( start+fin )/2.0, mid_val; + ok = f.value( mid, mid_val ); + if( !ok ) + return 0.0; + + //char buf[1024]; + //sprintf( buf, "start=%f\nfin=%f\nmid_val=%f\n", float( start ), float( fin ), float( mid_val ) ); + //MESSAGE( buf ); + + bool mid_pos = mid_val>=val; + if( start_pos!=mid_pos ) + { + fin_pos = mid_pos; + fin = mid; + } + else if( fin_pos!=mid_pos ) + { + start_pos = mid_pos; + start = mid; + } + else + { + ok = false; + break; + } + } + return (start+fin)/2.0; +} + +bool buildDistribution( const TCollection_AsciiString& f, const int conv, const double start, const double end, + const int nbSeg, vector& data, const double eps ) +{ + FunctionExpr F( f.ToCString(), conv ); + return buildDistribution( F, start, end, nbSeg, data, eps ); +} + +bool buildDistribution( const std::vector& f, const int conv, const double start, const double end, + const int nbSeg, vector& data, const double eps ) +{ + FunctionTable F( f, conv ); + return buildDistribution( F, start, end, nbSeg, data, eps ); +} + +bool buildDistribution( const Function& func, const double start, const double end, const int nbSeg, + vector& data, const double eps ) +{ + if( nbSeg<=0 ) + return false; + + data.resize( nbSeg+1 ); + data[0] = start; + double J = func.integral( start, end ) / nbSeg; + if( J<1E-10 ) + return false; + + bool ok; + //MESSAGE( "distribution:" ); + //char buf[1024]; + for( int i=1; i +#include +#include +#include +#include + + +class Function +{ +public: + Function( const int ); + virtual ~Function(); + virtual bool value( const double, double& ) const; + virtual double integral( const double, const double ) const = 0; + +private: + int myConv; +}; + +class FunctionIntegral : public Function +{ +public: + FunctionIntegral( const Function*, const double ); + virtual ~FunctionIntegral(); + virtual bool value( const double, double& ) const; + virtual double integral( const double, const double ) const; + +private: + Function* myFunc; + double myStart; +}; + +class FunctionTable : public Function +{ +public: + FunctionTable( const std::vector&, const int ); + virtual ~FunctionTable(); + virtual bool value( const double, double& ) const; + virtual double integral( const double, const double ) const; + +private: + bool findBounds( const double, int&, int& ) const; + + //integral from x[i] to x[i+1] + double integral( const int i ) const; + + //integral from x[i] to x[i]+d + //warning: function is presented as linear on interaval from x[i] to x[i]+d, + // for correct result d must be >=0 and <=x[i+1]-x[i] + double integral( const int i, const double d ) const; + +private: + std::vector myData; +}; + +class FunctionExpr : public Function, public math_Function +{ +public: + FunctionExpr( const char*, const int ); + virtual ~FunctionExpr(); + virtual Standard_Boolean Value( Standard_Real, Standard_Real& ); + virtual bool value( const double, double& ) const; + virtual double integral( const double, const double ) const; + +private: + Handle(ExprIntrp_GenExp) myExpr; + Expr_Array1OfNamedUnknown myVars; + TColStd_Array1OfReal myValues; +}; + +bool buildDistribution( const Function& f, + const double start, const double end, + const int nbSeg, + vector& data, + const double eps ); + +bool buildDistribution( const TCollection_AsciiString& f, const int conv, const double start, const double end, + const int nbSeg, vector& data, const double eps ); +bool buildDistribution( const std::vector& f, const int conv, const double start, const double end, + const int nbSeg, vector& data, const double eps ); + +#endif diff --git a/src/StdMeshers/StdMeshers_NumberOfSegments.cxx b/src/StdMeshers/StdMeshers_NumberOfSegments.cxx index a768b6c16..0b9d33355 100644 --- a/src/StdMeshers/StdMeshers_NumberOfSegments.cxx +++ b/src/StdMeshers/StdMeshers_NumberOfSegments.cxx @@ -29,6 +29,7 @@ using namespace std; #include "StdMeshers_NumberOfSegments.hxx" +#include "StdMeshers_Distribution.hxx" #include #include #include @@ -55,7 +56,7 @@ StdMeshers_NumberOfSegments::StdMeshers_NumberOfSegments(int hypId, int studyId, _numberOfSegments(1), _distrType(DT_Regular), _scaleFactor(1.), - _expMode(false) + _convMode(1) //cut negative by default { _name = "NumberOfSegments"; _param_algo_dim = 1; @@ -71,6 +72,28 @@ StdMeshers_NumberOfSegments::~StdMeshers_NumberOfSegments() { } +//============================================================================= +/*! + * + */ +//============================================================================= +const std::vector& StdMeshers_NumberOfSegments::BuildDistributionExpr( const char* expr, int nbSeg, int conv ) +throw ( SALOME_Exception ) +{ + if( !buildDistribution( TCollection_AsciiString( ( Standard_CString )expr ), conv, 0.0, 1.0, nbSeg, _distr, 1E-4 ) ) + _distr.resize( 0 ); + return _distr; +} + +const std::vector& StdMeshers_NumberOfSegments::BuildDistributionTab( const std::vector& tab, + int nbSeg, int conv ) +throw ( SALOME_Exception ) +{ + if( !buildDistribution( tab, conv, 0.0, 1.0, nbSeg, _distr, 1E-4 ) ) + _distr.resize( 0 ); + return _distr; +} + //============================================================================= /*! * @@ -186,10 +209,31 @@ void StdMeshers_NumberOfSegments::SetTableFunction(const std::vector& ta double prev = -PRECISION; bool isSame = table.size() == _table.size(); + OSD::SetSignal( true ); + CASCatch_CatchSignals aCatchSignals; + aCatchSignals.Activate(); + bool pos = false; for (i=0; i < table.size()/2; i++) { double par = table[i*2]; double val = table[i*2+1]; + if( _convMode==0 ) + { + CASCatch_TRY + { + val = pow( 10.0, val ); + } + CASCatch_CATCH(CASCatch_Failure) + { + aCatchSignals.Deactivate(); + Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught(); + throw SALOME_Exception( LOCALIZED( "invalid value")); + return; + } + } + else if( _convMode==1 && val<0.0 ) + val = 0.0; + if ( par<0 || par > 1) throw SALOME_Exception(LOCALIZED("parameter of table function is out of range [0,1]")); if ( fabs(par-prev)& ta } prev = par; } + aCatchSignals.Deactivate(); if( !pos ) throw SALOME_Exception(LOCALIZED("value of table function is not positive")); @@ -263,21 +308,39 @@ bool isCorrectArg( const Handle( Expr_GeneralExpression )& expr ) * ( result in 'syntax' ) and if only 't' is unknown variable in expression ( result in 'args' ) */ //================================================================================ -bool process( const TCollection_AsciiString& str, +bool process( const TCollection_AsciiString& str, int convMode, bool& syntax, bool& args, bool& non_neg, bool& non_zero, bool& singulars, double& sing_point ) { - Handle( ExprIntrp_GenExp ) myExpr = ExprIntrp_GenExp::Create(); - myExpr->Process( str.ToCString() ); + OSD::SetSignal( true ); + CASCatch_CatchSignals aCatchSignals; + aCatchSignals.Activate(); + + bool parsed_ok = true; + Handle( ExprIntrp_GenExp ) myExpr; + CASCatch_TRY + { + myExpr = ExprIntrp_GenExp::Create(); + myExpr->Process( str.ToCString() ); + } + CASCatch_CATCH(CASCatch_Failure) + { + aCatchSignals.Deactivate(); + Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught(); + parsed_ok = false; + } + aCatchSignals.Deactivate(); - if( myExpr->IsDone() ) + syntax = false; + args = false; + if( parsed_ok && myExpr->IsDone() ) { syntax = true; args = isCorrectArg( myExpr->Expression() ); } - bool res = syntax && args; + bool res = parsed_ok && syntax && args; if( !res ) myExpr.Nullify(); @@ -287,42 +350,27 @@ bool process( const TCollection_AsciiString& str, if( res ) { - OSD::SetSignal( true ); - CASCatch_CatchSignals aCatchSignals; - aCatchSignals.Activate(); - double res; - Expr_Array1OfNamedUnknown myVars( 1, 1 ); - TColStd_Array1OfReal myValues( 1, 1 ); - myVars.ChangeValue( 1 ) = new Expr_NamedUnknown( "t" ); - + FunctionExpr f( str.ToCString(), convMode ); const int max = 500; for( int i=0; i<=max; i++ ) { - double t = double(i)/double(max); - myValues.ChangeValue( 1 ) = t; - CASCatch_TRY - { - res = myExpr->Expression()->Evaluate( myVars, myValues ); - } - CASCatch_CATCH(CASCatch_Failure) + double t = double(i)/double(max), val; + if( !f.value( t, val ) ) { - aCatchSignals.Deactivate(); - Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught(); sing_point = t; singulars = true; break; } - if( res<0 ) + if( val<0 ) { non_neg = false; break; } - if( res>PRECISION ) + if( val>PRECISION ) non_zero = true; } - aCatchSignals.Deactivate(); } - return res && non_neg && ( !singulars ); + return res && non_neg && non_zero && ( !singulars ); } //================================================================================ @@ -346,7 +394,7 @@ void StdMeshers_NumberOfSegments::SetExpressionFunction(const char* expr) bool syntax, args, non_neg, singulars, non_zero; double sing_point; - bool res = true;//process( str, syntax, args, non_neg, non_zero, singulars, sing_point ); + bool res = process( str, _convMode, syntax, args, non_neg, non_zero, singulars, sing_point ); if( !res ) { if( !syntax ) @@ -395,15 +443,15 @@ const char* StdMeshers_NumberOfSegments::GetExpressionFunction() const */ //================================================================================ -void StdMeshers_NumberOfSegments::SetExponentMode(bool isExp) +void StdMeshers_NumberOfSegments::SetConversionMode( int conv ) throw(SALOME_Exception) { if (_distrType != DT_TabFunc && _distrType != DT_ExprFunc) throw SALOME_Exception(LOCALIZED("not a functional distribution")); - if (isExp != _expMode) + if( conv != _convMode ) { - _expMode = isExp; + _convMode = conv; NotifySubMeshesHypothesisModification(); } } @@ -414,12 +462,12 @@ void StdMeshers_NumberOfSegments::SetExponentMode(bool isExp) */ //================================================================================ -bool StdMeshers_NumberOfSegments::IsExponentMode() const +int StdMeshers_NumberOfSegments::ConversionMode() const throw(SALOME_Exception) { if (_distrType != DT_TabFunc && _distrType != DT_ExprFunc) throw SALOME_Exception(LOCALIZED("not a functional distribution")); - return _expMode; + return _convMode; } //============================================================================= @@ -451,7 +499,7 @@ ostream & StdMeshers_NumberOfSegments::SaveTo(ostream & save) } if (_distrType == DT_TabFunc || _distrType == DT_ExprFunc) - save << " " << (int)_expMode; + save << " " << _convMode; return save; } @@ -563,7 +611,7 @@ istream & StdMeshers_NumberOfSegments::LoadFrom(istream & load) { isOK = (load >> a); if (isOK) - _expMode = (bool) a; + _convMode = a; else load.clear(ios::badbit | load.rdstate()); } diff --git a/src/StdMeshers/StdMeshers_NumberOfSegments.hxx b/src/StdMeshers/StdMeshers_NumberOfSegments.hxx index a384752ba..28d829b75 100644 --- a/src/StdMeshers/StdMeshers_NumberOfSegments.hxx +++ b/src/StdMeshers/StdMeshers_NumberOfSegments.hxx @@ -47,6 +47,10 @@ public: StdMeshers_NumberOfSegments(int hypId, int studyId, SMESH_Gen* gen); virtual ~StdMeshers_NumberOfSegments(); + // Builds point distribution according to passed function + const std::vector& BuildDistributionExpr( const char*, int, int ) throw ( SALOME_Exception ); + const std::vector& BuildDistributionTab( const std::vector&, int, int ) throw ( SALOME_Exception ); + /*! * \brief Set the number of segments * \param segmentsNumber - must be greater than zero @@ -138,22 +142,23 @@ public: throw (SALOME_Exception); /*! - * \brief When exponent mode is set, the function of distribution of density - * is used as an exponent of 10, i,e, 10^f(t). This mode is sensible only when - * function distribution is used (DT_TabFunc or DT_ExprFunc) - * \param isExp - boolean switching on/off the mode + * \brief Set conversion mode. When it is 0, it means "exponent mode": + * the function of distribution of density is used as an exponent of 10, i,e, 10^f(t). + * When it is 1, it means "cut negative mode". The function of distribution is used as + * F(t), where F(t0)=f(t0), if f(t0)>=0, otherwise F(t0) = 0. + * This mode is sensible only when function distribution is used (DT_TabFunc or DT_ExprFunc) * * Throws SALOME_Exception if distribution type is not functional */ - void SetExponentMode(bool isExp) + void SetConversionMode( int conv ) throw (SALOME_Exception); /*! - * \brief Returns true if the exponent mode is set + * \brief Returns conversion mode * * Throws SALOME_Exception if distribution type is not functional */ - bool IsExponentMode() const + int ConversionMode() const throw (SALOME_Exception); virtual ostream & SaveTo(ostream & save); @@ -165,9 +170,9 @@ protected: int _numberOfSegments; //!< an edge will be split on to this number of segments DistrType _distrType; //!< the type of distribution of density function double _scaleFactor; //!< the scale parameter for DT_Scale - std::vector _table; //!< the table for DT_TabFunc, a sequence of pairs of numbers + std::vector _table, _distr; //!< the table for DT_TabFunc, a sequence of pairs of numbers std::string _func; //!< the expression of the function for DT_ExprFunc - bool _expMode; //!< flag of exponent mode + int _convMode; //!< flag of conversion mode: 0=exponent, 1=cut negative }; #endif diff --git a/src/StdMeshers/StdMeshers_Regular_1D.cxx b/src/StdMeshers/StdMeshers_Regular_1D.cxx index 51df8669d..6bc2ca700 100644 --- a/src/StdMeshers/StdMeshers_Regular_1D.cxx +++ b/src/StdMeshers/StdMeshers_Regular_1D.cxx @@ -30,9 +30,12 @@ using namespace std; #include "StdMeshers_Regular_1D.hxx" +#include "StdMeshers_Distribution.hxx" #include "SMESH_Gen.hxx" #include "SMESH_Mesh.hxx" +#include + #include "StdMeshers_LocalLength.hxx" #include "StdMeshers_NumberOfSegments.hxx" #include "StdMeshers_Arithmetic1D.hxx" @@ -64,12 +67,6 @@ using namespace std; #include #include -#include -#include -#include -#include -#include - #include #include @@ -167,7 +164,7 @@ bool StdMeshers_Regular_1D::CheckHypothesis } if (_ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_TabFunc || _ivalue[ DISTR_TYPE_IND ] == StdMeshers_NumberOfSegments::DT_ExprFunc) - _ivalue[ EXP_MODE_IND ] = (int) hyp->IsExponentMode(); + _ivalue[ CONV_MODE_IND ] = hyp->ConversionMode(); _hypType = NB_SEGMENTS; aStatus = SMESH_Hypothesis::HYP_OK; } @@ -266,304 +263,13 @@ static void compensateError(double a1, double an, } } -class Function -{ -public: - Function( const bool exp ) - : myExp( exp ) - { - } - - virtual ~Function() - { - } - - virtual bool value( const double, double& f ) - { - if( myExp ) - f = pow( 10, f ); - return true; - } - virtual double integral( const double, const double ) = 0; - -private: - bool myExp; -}; - -class FunctionIntegral : public Function -{ -public: - FunctionIntegral( Function*, const double ); - virtual ~FunctionIntegral(); - virtual bool value( const double, double& ); - virtual double integral( const double, const double ); - -private: - Function* myFunc; - double myStart; -}; - -FunctionIntegral::FunctionIntegral( Function* f, const double st ) -: Function( false ) -{ - myFunc = f; - myStart = st; -} - -FunctionIntegral::~FunctionIntegral() -{ -} - -bool FunctionIntegral::value( const double t, double& f ) -{ - f = myFunc ? myFunc->integral( myStart, t ) : 0; - return myFunc!=0 && Function::value( t, f ); -} - -double FunctionIntegral::integral( const double, const double ) -{ - return 0; -} - -class FunctionTable : public Function -{ -public: - FunctionTable( const std::vector&, const bool ); - virtual ~FunctionTable(); - virtual bool value( const double, double& ); - virtual double integral( const double, const double ); - -private: - bool findBounds( const double, int&, int& ) const; - - //integral from x[i] to x[i+1] - double integral( const int i ); - - //integral from x[i] to x[i]+d - //warning: function is presented as linear on interaval from x[i] to x[i]+d, - // for correct result d must be >=0 and <=x[i+1]-x[i] - double integral( const int i, const double d ); - -private: - std::vector myData; -}; - -FunctionTable::FunctionTable( const std::vector& data, const bool exp ) -: Function( exp ) -{ - myData = data; -} - -FunctionTable::~FunctionTable() -{ -} - -bool FunctionTable::value( const double t, double& f ) -{ - int i1, i2; - if( !findBounds( t, i1, i2 ) ) - return false; - - double - x1 = myData[2*i1], y1 = myData[2*i1+1], - x2 = myData[2*i2], y2 = myData[2*i2+1]; - - Function::value( x1, y1 ); - Function::value( x2, y2 ); - - f = y1 + ( y2-y1 ) * ( t-x1 ) / ( x2-x1 ); - return true; -} - -double FunctionTable::integral( const int i ) -{ - if( i>=0 && iProcess( ( Standard_CString )str ); - if( !myExpr->IsDone() ) - myExpr.Nullify(); - - myVars.ChangeValue( 1 ) = new Expr_NamedUnknown( "t" ); -} - -FunctionExpr::~FunctionExpr() -{ -} - -Standard_Boolean FunctionExpr::Value( Standard_Real T, Standard_Real& F ) -{ - double f; - Standard_Boolean res = value( T, f ); - F = f; - return res; -} - -bool FunctionExpr::value( const double t, double& f ) -{ - if( myExpr.IsNull() ) - return false; - - CASCatch_CatchSignals aCatchSignals; - aCatchSignals.Activate(); - - myValues.ChangeValue( 1 ) = t; - bool ok = true; - CASCatch_TRY { - f = myExpr->Expression()->Evaluate( myVars, myValues ); - } - CASCatch_CATCH(CASCatch_Failure) { - aCatchSignals.Deactivate(); - Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught(); - f = 0.0; - } - - aCatchSignals.Deactivate(); - ok = Function::value( t, f ) && ok; - return ok; -} - -double FunctionExpr::integral( const double a, const double b ) -{ - double res = 0.0; - CASCatch_TRY - { - math_GaussSingleIntegration _int( *this, a, b, 20 ); - if( _int.IsDone() ) - res = _int.Value(); - } - CASCatch_CATCH(CASCatch_Failure) - { - res = 0.0; - MESSAGE( "Exception in integral calculating" ); - } - return res; -} - - - - - - - -double dihotomySolve( Function& f, const double val, const double _start, const double _fin, const double eps, bool& ok ) -{ - double start = _start, fin = _fin, start_val, fin_val; bool ok1, ok2; - ok1 = f.value( start, start_val ); - ok2 = f.value( fin, fin_val ); - - if( !ok1 || !ok2 ) - { - ok = false; - return 0.0; - } - - bool start_pos = start_val>=val, fin_pos = fin_val>=val; - ok = true; - - while( fin-start>eps ) - { - double mid = ( start+fin )/2.0, mid_val; - ok = f.value( mid, mid_val ); - if( !ok ) - return 0.0; - -// char buf[1024]; -// sprintf( buf, "start=%f\nfin=%f\nmid_val=%f\n", float( start ), float( fin ), float( mid_val ) ); -// MESSAGE( buf ); - - bool mid_pos = mid_val>=val; - if( start_pos!=mid_pos ) - { - fin_pos = mid_pos; - fin = mid; - } - else if( fin_pos!=mid_pos ) - { - start_pos = mid_pos; - start = mid; - } - else - break; - } - return (start+fin)/2.0; -} - static bool computeParamByFunc(Adaptor3d_Curve& C3d, double first, double last, double length, bool theReverse, int nbSeg, Function& func, list& theParams) { OSD::SetSignal( true ); + if( nbSeg<=0 ) return false; @@ -572,18 +278,9 @@ static bool computeParamByFunc(Adaptor3d_Curve& C3d, double first, double last, int nbPnt = 1 + nbSeg; vector x(nbPnt, 0.); - x[0] = 0.0; - double J = func.integral( 0.0, 1.0 ) / nbSeg; - bool ok; - for( int i=1; i - -#include - -#include "utilities.h" - -using namespace std; - -//============================================================================= -/*! class HypothesisCreator - * - */ //============================================================================= -class StdMeshersGUI_HypothesisCreator : public SMESHGUI_GenericHypothesisCreator -{ - public: - StdMeshersGUI_HypothesisCreator (const QString& aHypType, - const QString& aServerLibName, - SMESHGUI* aSMESHGUI) - : myHypType(aHypType), - myServerLibName(aServerLibName), - mySMESHGUI(aSMESHGUI) {} - - virtual void CreateHypothesis (const bool isAlgo, QWidget* parent = 0); - virtual void EditHypothesis (SMESH::SMESH_Hypothesis_ptr theHyp); - - private: - QString myHypType; - QString myServerLibName; - SMESHGUI* mySMESHGUI; -}; - -//============================================================================= -/*! HypothesisCreator::CreateHypothesis +/*! GetHypothesisCreator * */ //============================================================================= -void StdMeshersGUI_HypothesisCreator::CreateHypothesis - (bool isAlgo, QWidget* parent) +extern "C" { - MESSAGE("StdMeshersGUI_HypothesisCreator::CreateHypothesis"); - - // Get default name for hypothesis/algorithm creation - char* sHypType = (char*)myHypType.latin1(); - HypothesisData* aHypData = SMESH::GetHypothesisData(sHypType); - QString aHypName; - if (aHypData) - aHypName = aHypData->Label; - else - aHypName = myHypType; - - // Create hypothesis/algorithm - if (isAlgo) - { - SMESH::CreateHypothesis(myHypType, aHypName, isAlgo); - } - else + SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator( const QString& aHypType ) { - if ( StdMeshersGUI_Parameters::HasParameters( myHypType )) - { - // Show Dialog for hypothesis creation - StdMeshersGUI_CreateStdHypothesisDlg *aDlg = - new StdMeshersGUI_CreateStdHypothesisDlg(myHypType, parent, ""); - /* Move widget on the botton right corner of main widget */ -// int x, y ; -// mySMESHGUI->DefineDlgPosition( aDlg, x, y ) ; -// aDlg->move( x, y ) ; - aDlg->exec() ; /* displays Dialog */ - } + if( aHypType=="NumberOfSegments" ) + return new StdMeshersGUI_NbSegmentsCreator(); else - SMESH::CreateHypothesis(myHypType, aHypName, isAlgo); // without GUI + return new StdMeshersGUI_StdHypothesisCreator( aHypType ); } } - -//============================================================================= -/*! HypothesisCreator::EditHypothesis - * - */ -//============================================================================= -void StdMeshersGUI_HypothesisCreator::EditHypothesis - (SMESH::SMESH_Hypothesis_ptr theHyp) -{ - MESSAGE("StdMeshersGUI_HypothesisCreator::EditHypothesis"); - - SMESH::SObjectList listSOmesh = SMESH::GetMeshesUsingAlgoOrHypothesis(theHyp); - - list paramList; - StdMeshersGUI_Parameters::GetParameters( theHyp, paramList ); - - bool modified = false; - if ( SMESHGUI_aParameterDlg::Parameters( SMESHGUI::GetSMESHGUI(), paramList, QObject::tr("SMESH_VALUE")) ) - { - try - { - modified = StdMeshersGUI_Parameters::SetParameters( theHyp, paramList ); - } - catch (const SALOME::SALOME_Exception& S_ex) - { - SalomeApp_Tools::QtCatchCorbaException(S_ex); - return; - } - } - - if ( modified ) { - //set new Attribute Comment for hypothesis which parameters were modified - QString aParams = ""; - StdMeshersGUI_Parameters::GetParameters( theHyp, paramList, aParams ); - _PTR(SObject) SHyp = SMESH::FindSObject(theHyp); - if (SHyp) - if (!aParams.isEmpty()) { - SMESH::SetValue(SHyp, aParams); - //mySMESHGUI->GetActiveStudy()->updateObjBrowser(true); - } - - if ( listSOmesh.size() > 0 ) { - _PTR(SObject) submSO = listSOmesh[0]; - SMESH::SMESH_Mesh_var aMesh = - SMESH::SObjectToInterface(submSO); - SMESH::SMESH_subMesh_var aSubMesh = - SMESH::SObjectToInterface(submSO); - if ( !aSubMesh->_is_nil() ) - aMesh = aSubMesh->GetFather(); - _PTR(SObject) meshSO = SMESH::FindSObject( aMesh ); - SMESH::ModifiedMesh( meshSO, false); - } - } -} - -//============================================================================= -/*! GetHypothesisCreator - * - */ -//============================================================================= -extern "C" -{ - SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator - (QString aHypType, QString aServerLibName, SMESHGUI* aSMESHGUI) - { - return new StdMeshersGUI_HypothesisCreator - (aHypType, aServerLibName, aSMESHGUI); - } -} diff --git a/src/StdMeshersGUI/StdMeshersGUI_CreateHypothesisDlg.cxx b/src/StdMeshersGUI/StdMeshersGUI_CreateHypothesisDlg.cxx deleted file mode 100644 index d93e8c2fe..000000000 --- a/src/StdMeshersGUI/StdMeshersGUI_CreateHypothesisDlg.cxx +++ /dev/null @@ -1,471 +0,0 @@ -// SMESH StdMeshersGUI : GUI for StdMeshers plugin -// -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : StdMeshersGUI_CreateHypothesisDlg.cxx -// Moved here from SMESHGUI_CreateHypothesisDlg.cxx -// Author : Nicolas REJNERI -// Module : SMESH -// $Header$ - -#include "StdMeshersGUI_CreateHypothesisDlg.h" -#include "StdMeshersGUI_Parameters.h" -#include "SMESHGUI.h" -#include "SMESHGUI_SpinBox.h" -#include "SMESHGUI_Hypotheses.h" -#include "SMESHGUI_HypothesesUtils.h" -#include "SMESHGUI_Utils.h" -#include "SMESHGUI_FunctionPreview.h" - -#include "SUIT_Application.h" -#include "SUIT_Desktop.h" -#include "SUIT_MessageBox.h" -#include "SUIT_OverrideCursor.h" -#include "utilities.h" - -#include "SalomeApp_Tools.h" -#include "SalomeApp_Application.h" - -#include "OB_Browser.h" - -// QT Includes -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -//================================================================================= -// class : StdMeshersGUI_CreateHypothesisDlg() -// purpose : Constructs a StdMeshersGUI_CreateHypothesisDlg which is a child of 'parent', with the -// name 'name' and widget flags set to 'f'. -// The dialog will by default be modeless, unless you set 'modal' to -// TRUE to construct a modal dialog. -//================================================================================= -StdMeshersGUI_CreateHypothesisDlg::StdMeshersGUI_CreateHypothesisDlg (const QString& hypType, - QWidget* parent, - const char* name, - bool modal, - WFlags /*fl*/) - : QDialog (parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose), myHypType( hypType ) -{ -} - -//======================================================================= -//function : CreateDlgLayout -//purpose : -//======================================================================= - -void StdMeshersGUI_CreateHypothesisDlg::CreateDlgLayout(const QString & theCaption, - const QPixmap & theHypIcon, - const QString & theHypTypeName) -{ - setCaption( theCaption ); - - setSizeGripEnabled( TRUE ); - QVBoxLayout* StdMeshersGUI_CreateHypothesisDlgLayout = new QVBoxLayout( this ); - StdMeshersGUI_CreateHypothesisDlgLayout->setSpacing( 6 ); - StdMeshersGUI_CreateHypothesisDlgLayout->setMargin( 11 ); - - /***************************************************************/ - QFrame* titFrame = new QFrame( this ); - QHBoxLayout* titLay = new QHBoxLayout( titFrame, 0, 0 ); - - iconLabel = new QLabel( titFrame ); - iconLabel->setPixmap( theHypIcon ); - iconLabel->setScaledContents( false ); - iconLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); - typeLabel = new QLabel( titFrame ); - typeLabel->setText( theHypTypeName ); - titLay->addWidget( iconLabel, 0 ); - titLay->addWidget( typeLabel, 0 ); - titLay->addStretch( 1 ); - - StdMeshersGUI_CreateHypothesisDlgLayout->addWidget( titFrame, 0); - - /***************************************************************/ - GroupC1 = new QGroupBox( this, "GroupC1" ); - GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) ); - GroupC1->setColumnLayout(0, Qt::Vertical ); - GroupC1->layout()->setSpacing( 0 ); - GroupC1->layout()->setMargin( 0 ); - QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() ); - GroupC1Layout->setAlignment( Qt::AlignTop ); - GroupC1Layout->setSpacing( 6 ); - GroupC1Layout->setMargin( 11 ); - - TextLabel_NameHypothesis = new QLabel( GroupC1, "TextLabel_NameHypothesis" ); - TextLabel_NameHypothesis->setText( tr( "SMESH_NAME" ) ); - GroupC1Layout->addWidget( TextLabel_NameHypothesis, 0, 0 ); - - LineEdit_NameHypothesis = new QLineEdit( GroupC1, "LineEdit_NameHypothesis" ); - GroupC1Layout->addWidget( LineEdit_NameHypothesis, 0, 1 ); - - myParamMap.clear(); - std::list aParamList; - GetParameters( myHypType, aParamList ); - ASSERT( !aParamList.empty() ); - - /* Spin boxes with labels */ - list::iterator paramIt = aParamList.begin(); - int row; - for ( row = 1; paramIt != aParamList.end(); paramIt++ , row++ ) - { - SMESHGUI_aParameterPtr param = (*paramIt); - QLabel * label = new QLabel( GroupC1, "TextLabel" ); - GroupC1Layout->addWidget( label, row, 0 ); - label->setText( param->Label() ); - QWidget* aWidget = param->CreateWidget( GroupC1 ); - - if ( aWidget ) { - GroupC1Layout->addWidget( aWidget, row, 1 ); - aWidget->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); - aWidget->setMinimumSize( 150, 0 ); - - QString sig = param->sigValueChanged(); - if( !sig.isEmpty() /* && param->GetType()!=SMESHGUI_aParameter::TABLE*/ ) - connect( aWidget, sig.latin1(), this, SLOT( onValueChanged() ) ); - - param->InitializeWidget( aWidget ); - - ParamInfo info; - info.editor = aWidget; - info.label = label; - info.order = row-1; - - myParamMap.insert( param, info ); - } - } - myPreview = new SMESHGUI_FunctionPreview( GroupC1 ); - myPreview->hide(); - GroupC1Layout->addWidget( myPreview, row, 1 ); - - StdMeshersGUI_CreateHypothesisDlgLayout->addWidget( GroupC1, 1 ); - - /***************************************************************/ - GroupButtons = new QGroupBox( this, "GroupButtons" ); - GroupButtons->setColumnLayout(0, Qt::Vertical ); - GroupButtons->layout()->setSpacing( 0 ); - GroupButtons->layout()->setMargin( 0 ); - QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() ); - GroupButtonsLayout->setAlignment( Qt::AlignTop ); - GroupButtonsLayout->setSpacing( 6 ); - GroupButtonsLayout->setMargin( 11 ); - buttonOk = new QPushButton( GroupButtons, "buttonOk" ); - buttonOk->setText( tr( "SMESH_BUT_OK" ) ); - buttonOk->setAutoDefault( TRUE ); - buttonOk->setDefault( TRUE ); - GroupButtonsLayout->addWidget( buttonOk, 0, 0 ); - buttonApply = new QPushButton( GroupButtons, "buttonApply" ); - buttonApply->setText( tr( "SMESH_BUT_APPLY" ) ); - buttonApply->setAutoDefault( TRUE ); - GroupButtonsLayout->addWidget( buttonApply, 0, 1 ); - QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); - GroupButtonsLayout->addItem( spacer, 0, 2 ); - buttonCancel = new QPushButton( GroupButtons, "buttonCancel" ); - buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) ); - buttonCancel->setAutoDefault( TRUE ); - GroupButtonsLayout->addWidget( buttonCancel, 0, 3 ); - StdMeshersGUI_CreateHypothesisDlgLayout->addWidget( GroupButtons, 0 ); - - /***************************************************************/ - Init() ; -} - - -//================================================================================= -// function : ~StdMeshersGUI_CreateHypothesisDlg() -// purpose : Destroys the object and frees any allocated resources -//================================================================================= -StdMeshersGUI_CreateHypothesisDlg::~StdMeshersGUI_CreateHypothesisDlg() -{ - // no need to delete child widgets, Qt does it all for us -} - - -//================================================================================= -// function : Init() -// purpose : -//================================================================================= -void StdMeshersGUI_CreateHypothesisDlg::Init() -{ - ParameterMap::const_iterator anIt = myParamMap.begin(), - aLast = myParamMap.end(); - for( ; anIt!=aLast; anIt++ ) - UpdateShown( anIt.key() ); - - mySMESHGUI = SMESHGUI::GetSMESHGUI() ; - - char* sHypType = const_cast(myHypType.latin1()); - HypothesisData* aHypData = SMESH::GetHypothesisData(sHypType); - LineEdit_NameHypothesis->setText( aHypData ? aHypData->Label : QString("") ); - - mySMESHGUI->SetActiveDialogBox( (QDialog*)this ); - - /* signals and slots connections */ - connect( buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()) ); - connect( buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()) ) ; - connect( buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()) ); - - connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ; - connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ; - - /* Move widget on the botton right corner of main widget */ - int x, y ; - mySMESHGUI->DefineDlgPosition( this, x, y ) ; - this->move( x, y ) ; - this->show() ; /* displays Dialog */ -} - - -//================================================================================= -// function : ClickOnOk() -// purpose : -//================================================================================= -void StdMeshersGUI_CreateHypothesisDlg::ClickOnOk() -{ - if ( ClickOnApply() ) - ClickOnCancel() ; -} - -//================================================================================= -// function : ClickOnApply() -// purpose : -//================================================================================= -bool StdMeshersGUI_CreateHypothesisDlg::ClickOnApply() -{ - if ( !mySMESHGUI || mySMESHGUI->isActiveStudyLocked() ) - return false; - - QString myHypName = LineEdit_NameHypothesis->text().stripWhiteSpace(); - if ( myHypName.isEmpty() ) { - SUIT_MessageBox::warn1 (this, tr( "SMESH_WRN_WARNING" ), - tr( "SMESH_WRN_EMPTY_NAME" ), tr( "SMESH_BUT_OK" ) ); - return false; - } - - SUIT_OverrideCursor wc; - - SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow - ( SMESH::CreateHypothesis( myHypType, myHypName, false ) ); // isAlgorithm - - try { - - list aParamList; - ParameterMap::const_iterator anIt = myParamMap.begin(), - aLast = myParamMap.end(); - for( int i=0; iTakeValue( anIt.data().editor ); - aParamList.push_back( anIt.key() ); - break; - } - - if( !SetParameters( Hyp, aParamList ) ) - return false; - - //set new Attribute Comment for hypothesis which parameters were set - QString aParams = ""; - StdMeshersGUI_Parameters::GetParameters( Hyp.in(), aParamList, aParams ); - _PTR(SObject) SHyp = SMESH::FindSObject(Hyp.in()); - if (SHyp) - if (!aParams.isEmpty()) - { - SMESH::SetValue(SHyp, aParams); - mySMESHGUI->getApp()->objectBrowser()->updateTree(); - } - } - catch (const SALOME::SALOME_Exception& S_ex) - { - wc.suspend(); - - _PTR(SObject) SHyp = SMESH::FindSObject(Hyp.in()); - _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); - if( aStudy && !aStudy->GetProperties()->IsLocked() ) - { - _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder(); - aBuilder->RemoveObjectWithChildren( SHyp ); - mySMESHGUI->updateObjBrowser( true, 0 ); - } - - SalomeApp_Tools::QtCatchCorbaException(S_ex); - return false; - } - return true; -} - -//================================================================================= -// function : ClickOnCancel() -// purpose : -//================================================================================= -void StdMeshersGUI_CreateHypothesisDlg::ClickOnCancel() -{ - close(); -} - -//================================================================================= -// function : DeactivateActiveDialog() -// purpose : -//================================================================================= -void StdMeshersGUI_CreateHypothesisDlg::DeactivateActiveDialog() -{ -// iconLabel->setEnabled(false) ; -// typeLabel->setEnabled(false) ; -// GroupC1->setEnabled(false) ; -// GroupButtons->setEnabled(false) ; - setEnabled(false); -} - - -//================================================================================= -// function : ActivateThisDialog() -// purpose : -//================================================================================= -void StdMeshersGUI_CreateHypothesisDlg::ActivateThisDialog() -{ - if (! isEnabled() ) { - mySMESHGUI->EmitSignalDeactivateDialog() ; -// iconLabel->setEnabled(true) ; -// typeLabel->setEnabled(true) ; -// GroupC1->setEnabled(true) ; -// GroupButtons->setEnabled(true) ; - setEnabled(true) ; - } -} - - -//================================================================================= -// function : enterEvent() -// purpose : -//================================================================================= -void StdMeshersGUI_CreateHypothesisDlg::enterEvent(QEvent* e) -{ - ActivateThisDialog() ; -} - - -//================================================================================= -// function : closeEvent() -// purpose : -//================================================================================= -void StdMeshersGUI_CreateHypothesisDlg::closeEvent( QCloseEvent* e ) -{ - mySMESHGUI->ResetState(); - QDialog::closeEvent( e ); -} - -//================================================================================= -// function : onValueChanged() -// purpose : -//================================================================================= -void StdMeshersGUI_CreateHypothesisDlg::onValueChanged() -{ - if( sender()->inherits( "QWidget" ) ) - { - QWidget* w = ( QWidget* )sender(); - - SMESHGUI_aParameterPtr param; - - ParameterMap::const_iterator anIt = myParamMap.begin(), - aLast = myParamMap.end(); - for( ; anIt!=aLast; anIt++ ) - if( anIt.data().editor == w ) - { - param = anIt.key(); - param->TakeValue( w ); - - SMESHGUI_strParameter* str_param = dynamic_cast( param.operator->() ); - SMESHGUI_tableParameter* tab_param = dynamic_cast( param.operator->() ); - SMESHGUI_boolParameter* bool_param = dynamic_cast( param.operator->() ); - - if( str_param && str_param->needPreview() ) - { - QString val; str_param->GetNewText( val ); - myPreview->setParams( val ); - } - else if( tab_param && tab_param->needPreview() ) - { - SMESH::double_array d; - tab_param->data( d ); - myPreview->setParams( d ); - } - else if( bool_param && bool_param->needPreview() ) - { - int exp=0; - bool_param->GetNewInt( exp ); - myPreview->setIsExp( exp ); - } - UpdateShown( param ); - break; - } - } -} - -//================================================================================= -// function : UpdateShown() -// purpose : -//================================================================================= -void StdMeshersGUI_CreateHypothesisDlg::UpdateShown( const SMESHGUI_aParameterPtr param ) -{ - SMESHGUI_dependParameter* depPar = dynamic_cast( param.get() ); - if( !depPar ) - depPar = dynamic_cast( param.get() ); - - if( !depPar ) - return; - - SMESHGUI_dependParameter::ShownMap& map = depPar->shownMap(); - if( map.isEmpty() ) - return; - - int val; - depPar->TakeValue( myParamMap[ param ].editor ); - depPar->GetNewInt( val ); - - bool hasValue = map.contains( val ); - - ParameterMap::const_iterator anIt = myParamMap.begin(), - aLast = myParamMap.end(); - bool preview = false; - for( ; anIt!=aLast; anIt++ ) - { - bool shown = hasValue && map[ val ].contains( (*anIt).order ); - (*anIt).editor->setShown( shown ); - (*anIt).label->setShown( shown ); - if( shown ) - { - SMESHGUI_strParameter* str_param = dynamic_cast( anIt.key().operator->() ); - SMESHGUI_tableParameter* tab_param = dynamic_cast( anIt.key().operator->() ); - preview = preview || ( str_param && str_param->needPreview() ) || ( tab_param && tab_param->needPreview() ); - } - } - myPreview->setShown( preview ); -} diff --git a/src/StdMeshersGUI/StdMeshersGUI_CreateHypothesisDlg.h b/src/StdMeshersGUI/StdMeshersGUI_CreateHypothesisDlg.h deleted file mode 100644 index 852fd468d..000000000 --- a/src/StdMeshersGUI/StdMeshersGUI_CreateHypothesisDlg.h +++ /dev/null @@ -1,123 +0,0 @@ -// SMESH SMESHGUI : GUI for SMESH component -// -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : StdMeshersGUI_CreateHypothesisDlg.h -// Module : SMESH -// $Header$ - -#ifndef DIALOGBOX_CreateHypothesisDlg_H -#define DIALOGBOX_CreateHypothesisDlg_H - -// QT Includes -#include -#include -#include - -#include -#include CORBA_SERVER_HEADER(SMESH_BasicHypothesis) - -#include "SMESHGUI_aParameter.h" - -#include - -class QGroupBox; -class QLabel; -class QLineEdit; -class QPushButton; -class SMESHGUI; -class SMESHGUI_SpinBox; -class SMESHGUI_FunctionPreview; - -//================================================================================= -// class : StdMeshersGUI_CreateHypothesisDlg -// purpose : -//================================================================================= -class StdMeshersGUI_CreateHypothesisDlg : public QDialog -{ - Q_OBJECT - -public: - StdMeshersGUI_CreateHypothesisDlg (const QString& hypType, - QWidget* parent = 0, - const char* name = 0, - bool modal = FALSE, - WFlags fl = 0); - ~StdMeshersGUI_CreateHypothesisDlg (); - -protected: - - void CreateDlgLayout(const QString & caption, - const QPixmap & hypIcon, - const QString & hypTypeName); - - virtual void GetParameters( const QString& hypType, - std::list& ) = 0; - - virtual bool SetParameters( SMESH::SMESH_Hypothesis_ptr theHyp, - const std::list & params ) = 0; - -protected slots: - virtual void onValueChanged(); - -private: - void UpdateShown( const SMESHGUI_aParameterPtr ); - void Init() ; - void closeEvent( QCloseEvent* e ) ; - void enterEvent ( QEvent * ) ; - - SMESHGUI* mySMESHGUI; - QString myHypType; - - typedef struct - { - QWidget* editor; - QLabel* label; - int order; - - } ParamInfo; - - typedef QMap< SMESHGUI_aParameterPtr, ParamInfo > ParameterMap; - ParameterMap myParamMap; - - QLabel* iconLabel; - QLabel* typeLabel; - QGroupBox* GroupC1; - QLabel* TextLabel_NameHypothesis ; - QLineEdit* LineEdit_NameHypothesis ; - QLabel* TextLabel_Length ; - QGroupBox* GroupButtons; - QPushButton* buttonOk; - QPushButton* buttonApply; - QPushButton* buttonCancel; - SMESHGUI_FunctionPreview* myPreview; - -private slots: - - void ClickOnOk(); - void ClickOnCancel(); - bool ClickOnApply(); - void DeactivateActiveDialog() ; - void ActivateThisDialog() ; -}; - -#endif // DIALOGBOX_LOCAL_LENGTH_H diff --git a/src/StdMeshersGUI/StdMeshersGUI_CreateStdHypothesisDlg.h b/src/StdMeshersGUI/StdMeshersGUI_CreateStdHypothesisDlg.h deleted file mode 100644 index 027c88acb..000000000 --- a/src/StdMeshersGUI/StdMeshersGUI_CreateStdHypothesisDlg.h +++ /dev/null @@ -1,59 +0,0 @@ -// SMESH SMESHGUI : GUI for SMESH component -// -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : StdMeshersGUI_CreateStdHypothesisDlg.h -// Moved here from SMESHGUI_CreateStdHypothesisDlg.h -// Author : Nicolas REJNERI -// Module : SMESH -// $Header$ - -#ifndef DIALOGBOX_CreateStdHypothesisDlg_H -#define DIALOGBOX_CreateStdHypothesisDlg_H - -#include "StdMeshersGUI_CreateHypothesisDlg.h" - -//================================================================================= -// class : StdMeshersGUI_CreateStdHypothesisDlg -// purpose : -//================================================================================= -class StdMeshersGUI_CreateStdHypothesisDlg : public StdMeshersGUI_CreateHypothesisDlg -{ - Q_OBJECT - - public: - StdMeshersGUI_CreateStdHypothesisDlg (const QString& hypType, - QWidget* parent = 0, - const char* name = 0, - bool modal = FALSE, - WFlags fl = 0); - ~StdMeshersGUI_CreateStdHypothesisDlg (); - - private: - virtual void GetParameters(const QString & hypType, - std::list & params); - - virtual bool SetParameters(SMESH::SMESH_Hypothesis_ptr theHyp, - const std::list & params); -}; - -#endif diff --git a/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx new file mode 100644 index 000000000..f763fbd9c --- /dev/null +++ b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx @@ -0,0 +1,358 @@ + +#include "StdMeshersGUI_DistrPreview.h" +#include +#include +#include +#include +#include +#include + +StdMeshersGUI_DistrPreview::StdMeshersGUI_DistrPreview( QWidget* p, StdMeshers::StdMeshers_NumberOfSegments_ptr h ) +: QwtPlot( p ), + myPoints( 50 ), + myIsTable( false ), + myVars( 1, 1 ), + myValues( 1, 1 ), + myConv( CUT_NEGATIVE ), + myIsDone( true ), + myNbSeg( 1 ) +{ + myHypo = StdMeshers::StdMeshers_NumberOfSegments::_duplicate( h ); + myVars.ChangeValue( 1 ) = new Expr_NamedUnknown( "t" ); + myCurve1 = insertCurve( QString() ); + myCurve2 = insertCurve( QString() ); + myMsg = insertMarker( new QwtPlotMarker( this ) ); + setMarkerPos( myMsg, 0.5, 0.5 ); + setMarkerLabelPen( myMsg, QPen( Qt::red, 1 ) ); + QFont f = markerFont( myMsg ); + f.setPointSize( 14 ); + f.setBold( true ); + setMarkerFont( myMsg, f ); + setCurvePen( myCurve1, QPen( Qt::red, 1 ) ); + + QColor dc = Qt::blue; + setCurvePen( myCurve2, QPen( dc, 1 ) ); + setCurveSymbol( myCurve2, QwtSymbol( QwtSymbol::XCross, QBrush( dc ), QPen( dc ), QSize( 5, 5 ) ) ); +} + +StdMeshersGUI_DistrPreview::~StdMeshersGUI_DistrPreview() +{ +} + +bool StdMeshersGUI_DistrPreview::isTableFunc() const +{ + return myIsTable; +} + +void StdMeshersGUI_DistrPreview::tableFunc( SMESH::double_array& f ) const +{ + f = myTableFunc; +} + +QString StdMeshersGUI_DistrPreview::function() const +{ + return myFunction; +} + +int StdMeshersGUI_DistrPreview::nbSeg() const +{ + return myNbSeg; +} + +int StdMeshersGUI_DistrPreview::pointsCount() const +{ + return myPoints; +} + +void StdMeshersGUI_DistrPreview::setConversion( Conversion conv, const bool upd ) +{ + myConv = conv; + if( upd ) + update(); +} + +bool StdMeshersGUI_DistrPreview::setParams( const QString& func, const int nbSeg, const int points, const bool upd ) +{ + myIsTable = false; + myTableFunc = SMESH::double_array(); + myFunction = func.isEmpty() ? "0" : func; + myPoints = points>0 ? points : 2; + myNbSeg = nbSeg>0 ? nbSeg : 1; + bool res = init( func ); + if( upd ) + update(); + return res; +} + +bool StdMeshersGUI_DistrPreview::setParams( const SMESH::double_array& f, const int nbSeg, const bool upd ) +{ + myIsTable = true; + myTableFunc = f; + if( myTableFunc.length()%2==1 ) + myTableFunc.length( myTableFunc.length()-1 ); + + myFunction = "0"; + myPoints = myTableFunc.length()/2; + myNbSeg = nbSeg>0 ? nbSeg : 1; + + if( upd ) + update(); + + return myTableFunc.length()>0; +} + +bool StdMeshersGUI_DistrPreview::createTable( SMESH::double_array& func ) +{ + if( myExpr.IsNull() ) + { + func.length( 0 ); + return false; + } + + const double xmin = 0.0, xmax = 1.0; + + double d = (xmax-xmin)/double(myPoints-1); + func.length( 2*myPoints ); + int err = 0; + for( int i=0, j=0; i=2 ) + { + StdMeshers::StdMeshers_NumberOfSegments_var h = + StdMeshers::StdMeshers_NumberOfSegments::_narrow( myHypo ); + + if( !CORBA::is_nil( h.in() ) ) + { + SMESH::double_array* arr = 0; + if( isTableFunc() ) + arr = h->BuildDistributionTab( myTableFunc, myNbSeg, ( int )myConv ); + else + arr = h->BuildDistributionExpr( myFunction.latin1(), myNbSeg, ( int )myConv ); + if( arr ) + { + distr = *arr; + delete arr; + } + } + } + + bool correct = graph.length()>=2 && distr.length()>=2; + if( !correct ) + { + showError(); + return; + } + else + setMarkerLabel( myMsg, QString() ); + + int size = graph.length()/2; + double* x = new double[size], *y = new double[size]; + double min_x, max_x, min_y, max_y; + for( int i=0; imax_y ) + max_y = y[i]; + if( i==0 || x[i]max_x ) + max_x = x[i]; + } + + setAxisScale( curveXAxis( myCurve1 ), min_x, max_x ); + setAxisScale( curveYAxis( myCurve1 ), min( 0.0, min_y ), max( 0.0, max_y ) ); + setCurveData( myCurve1, x, y, size ); + if( x ) + delete[] x; + if( y ) + delete[] y; + x = y = 0; + + size = distr.length(); + x = new double[size]; + y = new double[size]; + for( int i=0; iGetName()=="t"; + + bool res = true; + for( int i=1, n=expr->NbSubExpressions(); i<=n && res; i++ ) + { + Handle( Expr_GeneralExpression ) sub = expr->SubExpression( i ); + Handle( Expr_NamedUnknown ) name = Handle( Expr_NamedUnknown )::DownCast( sub ); + if( !name.IsNull() ) + { + if( name->GetName()!="t" ) + res = false; + } + else + res = isCorrectArg( sub ); + } + return res; +} + +bool StdMeshersGUI_DistrPreview::init( const QString& str ) +{ + CASCatch_CatchSignals aCatchSignals; + aCatchSignals.Activate(); + + bool parsed_ok = true; + CASCatch_TRY + { + myExpr = ExprIntrp_GenExp::Create(); + myExpr->Process( ( Standard_CString ) str.latin1() ); + } + CASCatch_CATCH(CASCatch_Failure) + { + aCatchSignals.Deactivate(); + Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught(); + parsed_ok = false; + } + aCatchSignals.Deactivate(); + + bool syntax = false, args = false; + if( parsed_ok && myExpr->IsDone() ) + { + syntax = true; + args = isCorrectArg( myExpr->Expression() ); + } + + bool res = parsed_ok && syntax && args; + if( !res ) + myExpr.Nullify(); + return res; +} + +double StdMeshersGUI_DistrPreview::funcValue( const double t, bool& ok ) +{ + if( myExpr.IsNull() ) + return 0; + + myValues.ChangeValue( 1 ) = t; + + ok = true; + double res = calc( ok ); + + return res; +} + +double StdMeshersGUI_DistrPreview::calc( bool& ok ) +{ + OSD::SetSignal( true ); + double res = 0.0; + + CASCatch_CatchSignals aCatchSignals; + aCatchSignals.Activate(); + + ok = true; + CASCatch_TRY { + res = myExpr->Expression()->Evaluate( myVars, myValues ); + } + CASCatch_CATCH(CASCatch_Failure) { + aCatchSignals.Deactivate(); + Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught(); + ok = false; + res = 0.0; + } + aCatchSignals.Deactivate(); + return res; +} + +bool StdMeshersGUI_DistrPreview::isDone() const +{ + return myIsDone; +} + +bool StdMeshersGUI_DistrPreview::convert( double& v ) const +{ + CASCatch_CatchSignals aCatchSignals; + aCatchSignals.Activate(); + + bool ok = true; + switch( myConv ) + { + case EXPONENT: + { + CASCatch_TRY + { + v = pow( 10.0, v ); + } + CASCatch_CATCH(CASCatch_Failure) + { + aCatchSignals.Deactivate(); + Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught(); + v = 0.0; + ok = false; + } + } + break; + + case CUT_NEGATIVE: + if( v<0 ) + v = 0; + break; + } + aCatchSignals.Deactivate(); + return ok; +} diff --git a/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.h b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.h new file mode 100644 index 000000000..5a3551dae --- /dev/null +++ b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.h @@ -0,0 +1,59 @@ + +#ifndef STD_MESHERS_GUI_DISTR_PREVIEW_HEADER +#define STD_MESHERS_GUI_DISTR_PREVIEW_HEADER + +#include +#include +#include CORBA_SERVER_HEADER(SMESH_Mesh) +#include CORBA_SERVER_HEADER(SMESH_BasicHypothesis) +#include +#include +#include + +class StdMeshersGUI_DistrPreview : public QwtPlot +{ + Q_OBJECT + +public: + typedef enum { EXPONENT, CUT_NEGATIVE } Conversion; + + StdMeshersGUI_DistrPreview( QWidget*, StdMeshers::StdMeshers_NumberOfSegments_ptr ); + virtual ~StdMeshersGUI_DistrPreview(); + + QString function() const; + bool isTableFunc() const; + void tableFunc( SMESH::double_array& ) const; + int pointsCount() const; + int nbSeg() const; + bool isDone() const; + + bool setParams( const QString&, const int, const int = 50, const bool = true ); + bool setParams( const SMESH::double_array&, const int, const bool = true ); + void setConversion( Conversion, const bool = true ); + +protected: + virtual bool init( const QString& ); + virtual double funcValue( const double, bool& ); + virtual bool createTable( SMESH::double_array& ); + virtual bool convert( double& ) const; + void update(); + +private: + double calc( bool& ); + void showError(); + +private: + QString myFunction; + int myPoints, myNbSeg; + bool myIsTable; + Conversion myConv; + SMESH::double_array myTableFunc; + long myCurve1, myCurve2, myMsg; + Handle(ExprIntrp_GenExp) myExpr; + Expr_Array1OfNamedUnknown myVars; + TColStd_Array1OfReal myValues; + bool myIsDone; + StdMeshers::StdMeshers_NumberOfSegments_var myHypo; +}; + +#endif diff --git a/src/StdMeshersGUI/StdMeshersGUI_DistrTable.cxx b/src/StdMeshersGUI/StdMeshersGUI_DistrTable.cxx new file mode 100644 index 000000000..db0b7f3ff --- /dev/null +++ b/src/StdMeshersGUI/StdMeshersGUI_DistrTable.cxx @@ -0,0 +1,348 @@ +// SMESH StdMeshersGUI +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : StdMeshersGUI_DistrTable.cxx +// Module : SMESH +// $Header$ + +#include "StdMeshersGUI_DistrTable.h" +#include +#include +#include +#include + +//================================================================================= +// class : StdMeshersGUI_DistrTable +// purpose : +//================================================================================= +StdMeshersGUI_DistrTable::StdMeshersGUI_DistrTable( const int rows, QWidget* parent, const char* name ) +: QTable( rows, 2, parent, name ) +{ + horizontalHeader()->setLabel( 0, "t" ); + horizontalHeader()->setLabel( 1, "f(t)" ); + myArgV = new QDoubleValidator( 0.0, 1.0, 3, this ); + myFuncV = new QDoubleValidator( 0.0, 1E10, 3, this ); +} + +StdMeshersGUI_DistrTable::~StdMeshersGUI_DistrTable() +{ +} + +QSize StdMeshersGUI_DistrTable::sizeHint() const +{ + if( cachedSizeHint().isValid() ) + return cachedSizeHint(); + + constPolish(); + + QSize sh = QScrollView::sizeHint(); + if( sh.width()<400 ) + sh.setWidth( 400 ); + if( sh.height()<200 ) + sh.setHeight( 200 ); + + setCachedSizeHint( sh ); + return sh; +} + +void StdMeshersGUI_DistrTable::stopEditing( const bool accept ) +{ + endEdit( currEditRow(), currEditCol(), accept, false ); +} + +void StdMeshersGUI_DistrTable::edit( const int r, const int c ) +{ + if( isEditing() ) + endEdit( currEditRow(), currEditCol(), true, false ); + clearSelection(); + setCurrentCell( r, c ); + if( beginEdit( r, c, false ) ) + setEditMode( Editing, r, c ); + QTableSelection sel; + sel.init( r, c ); + sel.expandTo( r, c ); + addSelection( sel ); +} + +bool StdMeshersGUI_DistrTable::eventFilter( QObject* o, QEvent* e ) +{ + if( e && e->type()==QEvent::KeyPress ) + { + QKeyEvent* ke = ( QKeyEvent* )e; + int k = ke->key(); + if( k==Qt::Key_Tab || k==Qt::Key_BackTab || k==Qt::Key_Return || k==Qt::Key_Up || k==Qt::Key_Down ) + { + keyPressEvent( ke ); + return true; + } + } + return QTable::eventFilter( o, e ); +} + +void StdMeshersGUI_DistrTable::keyPressEvent( QKeyEvent* e ) +{ + if( e ) + { + int r = currentRow(), c = currentColumn(), nr, nc; + bool shift = e->state() & Qt::ShiftButton, cr = false; + switch( e->key() ) + { + case Qt::Key_Tab: + nc = c+1; + nr = r; + break; + + case Qt::Key_BackTab: + nc = c-1; + nr = r; + break; + + case Qt::Key_Return: + nc = 0; + nr = shift ? r-1 : r+1; + cr = true; + break; + + case Qt::Key_Up: + nc = c; + nr = r-1; + break; + + case Qt::Key_Down: + nc = c; + nr = r+1; + break; + + default: + QTable::keyPressEvent( e ); + return; + } + + if( nc<0 ) + { + nc=1; nr--; + } + if( nc>1 ) + { + nc=0; nr++; + } + + if( nr>=numRows() && cr ) + { + if( isEditing() ) + endEdit( currEditRow(), currEditCol(), true, false ); + onEdit( INSERT_ROW, nr ); + } + + else if( nr<0 || nr>=numRows() ) + { + nr = r; nc = c; + } + edit( nr, nc ); + e->accept(); + } +} + +QWidget* StdMeshersGUI_DistrTable::createEditor( int r, int c, bool init ) const +{ + QWidget* w = QTable::createEditor( r, c, init ); + if( w ) + { + //w->installEventFilter( this ); + if( w->inherits( "QLineEdit" ) ) + { + QLineEdit* le = ( QLineEdit* )w; + le->setValidator( c==0 ? myArgV : myFuncV ); + } + } + + return w; +} + +void StdMeshersGUI_DistrTable::onEdit( TableButton b, int cur ) +{ + switch( b ) + { + case INSERT_ROW: + setNumRows( numRows()+1 ); + for( int i=numRows()-1; i>=cur; i-- ) + for( int j=0; jcur ) + setText( i, j, text( i-1, j ) ); + else + setText( i, j, "0" ); + emit( valueChanged( cur, 0 ) ); + break; + + case REMOVE_ROW: + if( numRows()>1 ) + { + for( int i=cur; i > aData; + if( arr.length()%2==1 ) + arr.length( arr.length()-1 ); + + int aLen = arr.length(); + for( int i=0; i( arr[2*i], arr[2*i+1] ) ); + + qHeapSort( aData ); + + QValueList< QPair >::const_iterator anIt = aData.begin(), aLast = aData.end(); + QValueList unique_values; + double prev; int i=0; + if( (*anIt).first>0.0 ) + { + unique_values.append( 0.0 ); + unique_values.append( (*anIt).second ); + i++; prev = 0.0; + } + for( ; anIt!=aLast; anIt++ ) + { + if( i==0 || (*anIt).first>prev ) + { + unique_values.append( (*anIt).first ); + unique_values.append( (*anIt).second ); + i++; + } + prev = (*anIt).first; + } + if( prev<1.0 ) + { + unique_values.append( 1.0 ); + anIt--; + unique_values.append( (*anIt).second ); + } + + arr.length( unique_values.count() ); + QValueList::const_iterator anIt1 = unique_values.begin(), aLast1 = unique_values.end(); + for( int j=0; anIt1!=aLast1; anIt1++, j++ ) + arr[j] = *anIt1; +} + +void StdMeshersGUI_DistrTable::data( SMESH::double_array& v ) +{ + stopEditing( true ); + v.length( 2*numRows() ); + for( int i=0; iaddWidget( myInsertRow, 0 ); + butLay->addWidget( myRemoveRow, 0 ); + butLay->addStretch( 1 ); + + main->addWidget( myTable, 1 ); + main->addWidget( aButFrame, 0 ); + + connect( myInsertRow, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); + connect( myRemoveRow, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) ); +} + +StdMeshersGUI_DistrTableFrame::~StdMeshersGUI_DistrTableFrame() +{ +} + +StdMeshersGUI_DistrTable* StdMeshersGUI_DistrTableFrame::table() const +{ + return myTable; +} + +void StdMeshersGUI_DistrTableFrame::setShown( const TableButton b, const bool sh ) +{ + if( button( b ) ) + button( b )->setShown( sh ); +} + +bool StdMeshersGUI_DistrTableFrame::isShown( const TableButton b ) const +{ + bool res = false; + if( button( b ) ) + res = button( b )->isShown(); + return res; +} + +QButton* StdMeshersGUI_DistrTableFrame::button( const TableButton b ) const +{ + QButton* res = 0; + switch( b ) + { + case INSERT_ROW: + res = myInsertRow; + break; + + case REMOVE_ROW: + res = myRemoveRow; + break; + } + return res; +} + +void StdMeshersGUI_DistrTableFrame::onButtonClicked() +{ + if( sender()==button( INSERT_ROW ) ) + emit toEdit( INSERT_ROW, table()->currentRow() ); + + else if( sender()==button( REMOVE_ROW ) ) + emit toEdit( REMOVE_ROW, table()->currentRow() ); +} diff --git a/src/StdMeshersGUI/StdMeshersGUI_DistrTable.h b/src/StdMeshersGUI/StdMeshersGUI_DistrTable.h new file mode 100644 index 000000000..6f6ca829a --- /dev/null +++ b/src/StdMeshersGUI/StdMeshersGUI_DistrTable.h @@ -0,0 +1,127 @@ +// SMESH StdMeshersGUI +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : StdMeshersGUI_DistrTable.h +// Module : SMESH +// $Header$ + +#ifndef StdMesherGUI_DistrTable_Header +#define StdMesherGUI_DistrTable_Header + +#include + +#include +#include CORBA_SERVER_HEADER(SMESH_Mesh) + +class QButton; +class QDoubleValidator; + +/*! + * \brief Values corresponding to buttons for table resize + */ +typedef enum { INSERT_ROW, REMOVE_ROW } TableButton; + +/*! + * \brief This class represents custom table. It has only double values and + editor for every cell has validator + */ +class StdMeshersGUI_DistrTable : public QTable +{ + Q_OBJECT + +public: + StdMeshersGUI_DistrTable( const int rows, QWidget* = 0, const char* = 0 ); + virtual ~StdMeshersGUI_DistrTable(); + +/*! + * \brief Hides current editor of cell + */ + void stopEditing( const bool accept ); + + virtual QSize sizeHint() const; + + static void sortData( SMESH::double_array& ); + + void data( SMESH::double_array& ); + void setData( const SMESH::double_array& ); + +protected: + virtual QWidget* createEditor( int, int, bool ) const; + virtual bool eventFilter( QObject*, QEvent* ); + virtual void keyPressEvent( QKeyEvent* ); + virtual void edit( const int, const int ); + +private slots: + void onEdit( TableButton, int ); + +private: + QDoubleValidator *myArgV, *myFuncV; +}; + + +/*! + * \brief This class represents frame for table and buttons + */ +class StdMeshersGUI_DistrTableFrame : public QFrame +{ + Q_OBJECT + +public: + StdMeshersGUI_DistrTableFrame( QWidget* ); + ~StdMeshersGUI_DistrTableFrame(); + + StdMeshersGUI_DistrTable* table() const; + +/*! + * \brief Changes shown state of some button for table resize + */ + void setShown( const TableButton, const bool ); + +/*! + * \brief Returns shown state of some button for table resize + */ + bool isShown( const TableButton ) const; + +private: + QButton* button( const TableButton ) const; + +private slots: + void onButtonClicked(); + +signals: +/*! + * \brief This signal is emitted if some of button for table resize is clicked + * Second parameter is current row. Take into account that + * this object resize table ( returned by table() ) automatically + */ + void toEdit( TableButton, int ); + void valueChanged( int, int ); + +private: + QButton *myInsertRow, *myRemoveRow; + StdMeshersGUI_DistrTable *myTable; +}; + + +#endif + diff --git a/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx new file mode 100644 index 000000000..a071169ae --- /dev/null +++ b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx @@ -0,0 +1,307 @@ + +#include "StdMeshersGUI_NbSegmentsCreator.h" +#include "StdMeshersGUI_DistrTable.h" +#include "StdMeshersGUI_DistrPreview.h" + +#include +#include + +#include CORBA_SERVER_HEADER(SMESH_BasicHypothesis) + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +StdMeshersGUI_NbSegmentsCreator::StdMeshersGUI_NbSegmentsCreator() +: StdMeshersGUI_StdHypothesisCreator( "NumberOfSegments" ), + myNbSeg( 0 ), + myDistr( 0 ), + myScale( 0 ), + myTable( 0 ), + myPreview( 0 ), + myExpr( 0 ), + myConv( 0 ), + myLScale( 0 ), + myLTable( 0 ), + myLExpr( 0 ), + myLConv( 0 ), + myInfo( 0 ), + myGroupLayout( 0 ), + myTableRow( 0 ), + myPreviewRow( 0 ) +{ +} + +StdMeshersGUI_NbSegmentsCreator::~StdMeshersGUI_NbSegmentsCreator() +{ +} + +bool StdMeshersGUI_NbSegmentsCreator::checkParams() const +{ + NbSegmentsHypothesisData data_old, data_new; + readParamsFromHypo( data_old ); + readParamsFromWidgets( data_new ); + bool res = storeParamsToHypo( data_new ); + storeParamsToHypo( data_old ); + return res; +} + +QFrame* StdMeshersGUI_NbSegmentsCreator::buildFrame() +{ + QFrame* fr = new QFrame( 0, "myframe" ); + QVBoxLayout* lay = new QVBoxLayout( fr, 5, 0 ); + + QGroupBox* GroupC1 = new QGroupBox( fr, "GroupC1" ); + lay->addWidget( GroupC1 ); + + StdMeshers::StdMeshers_NumberOfSegments_var h = + StdMeshers::StdMeshers_NumberOfSegments::_narrow( hypothesis() ); + myPreview = new StdMeshersGUI_DistrPreview( GroupC1, h.in() ); + + GroupC1->setTitle( tr( "SMESH_ARGUMENTS" ) ); + GroupC1->setColumnLayout(0, Qt::Vertical ); + GroupC1->layout()->setSpacing( 0 ); + GroupC1->layout()->setMargin( 0 ); + myGroupLayout = new QGridLayout( GroupC1->layout() ); + myGroupLayout->setAlignment( Qt::AlignTop ); + myGroupLayout->setSpacing( 6 ); + myGroupLayout->setMargin( 11 ); + myGroupLayout->setColStretch( 0, 0 ); + myGroupLayout->setColStretch( 1, 1 ); + + int row = 0; + // 0) name + myName = 0; + if( isCreation() ) + { + myName = new QLineEdit( GroupC1 ); + myGroupLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), GroupC1 ), row, 0 ); + myGroupLayout->addWidget( myName, row, 1 ); + row++; + } + + // 1) number of segments + myGroupLayout->addWidget( new QLabel( tr( "SMESH_NB_SEGMENTS_PARAM" ), GroupC1 ), row, 0 ); + myNbSeg = new QtxIntSpinBox( GroupC1 ); + myNbSeg->setMinValue( 1 ); + myNbSeg->setMaxValue( 9999 ); + myGroupLayout->addWidget( myNbSeg, row, 1 ); + row++; + + // 2) type of distribution + myGroupLayout->addWidget( new QLabel( tr( "SMESH_DISTR_TYPE" ), GroupC1 ), row, 0 ); + myDistr = new QtxComboBox( GroupC1 ); + QStringList types; + types.append( QObject::tr( "SMESH_DISTR_REGULAR" ) ); + types.append( QObject::tr( "SMESH_DISTR_SCALE" ) ); + types.append( QObject::tr( "SMESH_DISTR_TAB" ) ); + types.append( QObject::tr( "SMESH_DISTR_EXPR" ) ); + myDistr->insertStringList( types ); + myGroupLayout->addWidget( myDistr, row, 1 ); + row++; + + // 3) scale + myGroupLayout->addWidget( myLScale = new QLabel( tr( "SMESH_NB_SEGMENTS_SCALE_PARAM" ), GroupC1 ), row, 0 ); + myScale = new SMESHGUI_SpinBox( GroupC1 ); + myScale->RangeStepAndValidator( 1E-5, 1E+5, 0.1, 6 ); + myGroupLayout->addWidget( myScale, row, 1 ); + row++; + + myInfo = new QLabel( tr( "SMESH_FUNC_DOMAIN" ), GroupC1 ); + myGroupLayout->addMultiCellWidget( myInfo, row, row, 0, 1 ); + row++; + + // 4) table + myGroupLayout->addWidget( myLTable = new QLabel( tr( "SMESH_TAB_FUNC" ), GroupC1 ), row, 0 ); + myTable = new StdMeshersGUI_DistrTableFrame( GroupC1 ); + myGroupLayout->addWidget( myTable, row, 1 ); + myGroupLayout->setRowStretch( row, 1 ); + myTableRow = row; + row++; + + // 5) expression + myGroupLayout->addWidget( myLExpr = new QLabel( tr( "SMESH_EXPR_FUNC" ), GroupC1 ), row, 0 ); + myExpr = new QLineEdit( GroupC1 ); + myGroupLayout->addWidget( myExpr, row, 1 ); + row++; + + // 6) conversion (radiogroup) + myGroupLayout->addWidget( myLConv = new QLabel( tr( "SMESH_CONV_MODE" ), GroupC1 ), row, 0 ); + myConv = new QButtonGroup( GroupC1 ); + myConv->setExclusive( true ); + myConv->setColumnLayout( 0, Qt::Vertical ); + QGridLayout* convLay = new QGridLayout( myConv->layout() ); + convLay->addWidget( new QRadioButton( tr( "SMESH_EXP_MODE" ), myConv ), 0, 0 ); + convLay->addWidget( new QRadioButton( tr( "SMESH_CUT_NEG_MODE" ), myConv ), 1, 0 ); + myGroupLayout->addWidget( myConv, row, 1 ); + row++; + + // 7) distribution preview + myGroupLayout->addMultiCellWidget( myPreview, row, row, 0, 1 ); + myGroupLayout->setRowStretch( row, 1 ); + myPreviewRow = row; + row++; + + connect( myNbSeg, SIGNAL( valueChanged( const QString& ) ), this, SLOT( onValueChanged() ) ); + connect( myDistr, SIGNAL( activated( int ) ), this, SLOT( onValueChanged() ) ); + connect( myTable, SIGNAL( valueChanged( int, int ) ), this, SLOT( onValueChanged() ) ); + connect( myExpr, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) ); + connect( myConv, SIGNAL( clicked( int ) ), this, SLOT( onValueChanged() ) ); + + return fr; +} + +void StdMeshersGUI_NbSegmentsCreator::retrieveParams() const +{ + NbSegmentsHypothesisData data; + readParamsFromHypo( data ); + + if( myName ) + myName->setText( data.myName ); + myNbSeg->setValue( data.myNbSeg ); + myDistr->setCurrentItem( data.myDistrType ); + myScale->setValue( data.myScale ); + myConv->setButton( data.myConv ); + myTable->table()->setData( data.myTable ); + myExpr->setText( data.myExpr ); +} + +void StdMeshersGUI_NbSegmentsCreator::storeParams() const +{ + NbSegmentsHypothesisData data; + readParamsFromWidgets( data ); + storeParamsToHypo( data ); +} + +bool StdMeshersGUI_NbSegmentsCreator::readParamsFromHypo( NbSegmentsHypothesisData& h_data ) const +{ + StdMeshers::StdMeshers_NumberOfSegments_var h = + StdMeshers::StdMeshers_NumberOfSegments::_narrow( hypothesis() ); + + HypothesisData* data = SMESH::GetHypothesisData( hypType() ); + h_data.myName = isCreation() && data ? data->Label : ""; + + h_data.myNbSeg = (int) h->GetNumberOfSegments(); + int distr = (int) h->GetDistrType(); + h_data.myDistrType = distr; + h_data.myScale = distr==1 ? h->GetScaleFactor() : 1.0; + if( distr==2 ) + { + SMESH::double_array* a = h->GetTableFunction(); + h_data.myTable = *a; + delete a; + } + else + { + SMESH::double_array& a = h_data.myTable; + // by default, constant table function f(t)=1 + a.length( 4 ); + a[0] = 0.0; a[1] = 1.0; + a[2] = 1.0; a[3] = 1.0; + } + + h_data.myExpr = distr==3 ? h->GetExpressionFunction() : "1"; + h_data.myConv = distr==2 || distr==3 ? h->ConversionMode() : 1; /*cut negative by default*/ + + return true; +} + +bool StdMeshersGUI_NbSegmentsCreator::storeParamsToHypo( const NbSegmentsHypothesisData& h_data ) const +{ + StdMeshers::StdMeshers_NumberOfSegments_var h = + StdMeshers::StdMeshers_NumberOfSegments::_narrow( hypothesis() ); + + bool ok = true; + try + { + if( isCreation() ) + SMESH::SetName( SMESH::FindSObject( h ), h_data.myName.latin1() ); + + h->SetNumberOfSegments( h_data.myNbSeg ); + int distr = h_data.myDistrType; + h->SetDistrType( distr ); + + if( distr==1 ) + h->SetScaleFactor( h_data.myScale ); + + if( distr==2 || distr==3 ) + h->SetConversionMode( h_data.myConv ); + + if( distr==2 ) + h->SetTableFunction( h_data.myTable ); + + if( distr==3 ) + h->SetExpressionFunction( h_data.myExpr.latin1() ); + //setting of function must follow after setConversionMode, because otherwise + //the function will be checked with old conversion mode, so that it may occurs + //unexpected errors for user + } + catch(const SALOME::SALOME_Exception& ex) + { + SalomeApp_Tools::QtCatchCorbaException(ex); + ok = false; + } + return ok; +} + +bool StdMeshersGUI_NbSegmentsCreator::readParamsFromWidgets( NbSegmentsHypothesisData& h_data ) const +{ + h_data.myName = myName ? myName->text() : ""; + h_data.myNbSeg = myNbSeg->value(); + h_data.myDistrType = myDistr->currentItem(); + h_data.myConv = myConv->id( myConv->selected() ); + h_data.myScale = myScale->value(); + myTable->table()->data( h_data.myTable ); + h_data.myExpr = myExpr->text(); + return true; +} + +void StdMeshersGUI_NbSegmentsCreator::onValueChanged() +{ + int distr = myDistr->currentItem(); + + myScale->setShown( distr==1 ); + myLScale->setShown( distr==1 ); + + bool isFunc = distr==2 || distr==3; + myPreview->setShown( isFunc ); + myGroupLayout->setRowStretch( myPreviewRow, isFunc ? 1 : 0 ); + + myConv->setShown( isFunc ); + myLConv->setShown( isFunc ); + + if( distr==2 ) + myTable->show(); + else + myTable->hide(); + myLTable->setShown( distr==2 ); + myGroupLayout->setRowStretch( myTableRow, distr==2 ? 1 : 0 ); + + myExpr->setShown( distr==3 ); + myLExpr->setShown( distr==3 ); + myInfo->setShown( isFunc ); + + //change of preview + int nbSeg = myNbSeg->value(); + if( distr==2 ) //preview for table-described function + { + SMESH::double_array a; + myTable->table()->data( a ); + myPreview->setParams( a, nbSeg, false ); + } + else if( distr==3 ) //preview for analytic-described function + myPreview->setParams( myExpr->text(), nbSeg, 100, false ); + + if( isFunc ) + myPreview->setConversion( StdMeshersGUI_DistrPreview::Conversion( myConv->id( myConv->selected() ) ) ); +} diff --git a/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h new file mode 100644 index 000000000..26ca09918 --- /dev/null +++ b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h @@ -0,0 +1,64 @@ + +#ifndef NB_SEGMENTS_CREATOR_HEADER +#define NB_SEGMENTS_CREATOR_HEADER + +#include "StdMeshersGUI_StdHypothesisCreator.h" + +#include +#include CORBA_SERVER_HEADER(SMESH_Mesh) + +class QtxIntSpinBox; +class QtxComboBox; +class SMESHGUI_SpinBox; +class StdMeshersGUI_DistrTableFrame; +class StdMeshersGUI_DistrPreview; +class QLineEdit; +class QButtonGroup; +class QGridLayout; + +typedef struct +{ + int myNbSeg, myDistrType, myConv; + double myScale; + SMESH::double_array myTable; + QString myName, myExpr; + +} NbSegmentsHypothesisData; + +class StdMeshersGUI_NbSegmentsCreator : public StdMeshersGUI_StdHypothesisCreator +{ + Q_OBJECT + +public: + StdMeshersGUI_NbSegmentsCreator(); + virtual ~StdMeshersGUI_NbSegmentsCreator(); + + virtual bool checkParams() const; + +protected: + virtual QFrame* buildFrame(); + virtual void retrieveParams() const; + virtual void storeParams() const; + +protected slots: + virtual void onValueChanged(); + +private: + bool readParamsFromHypo( NbSegmentsHypothesisData& ) const; + bool readParamsFromWidgets( NbSegmentsHypothesisData& ) const; + bool storeParamsToHypo( const NbSegmentsHypothesisData& ) const; + +private: + QtxIntSpinBox* myNbSeg; + QtxComboBox* myDistr; + SMESHGUI_SpinBox* myScale; + StdMeshersGUI_DistrTableFrame* myTable; + StdMeshersGUI_DistrPreview* myPreview; + QLineEdit *myName, *myExpr; + QButtonGroup* myConv; + QLabel *myLScale, *myLTable, *myLExpr, *myLConv, *myInfo; + QGridLayout* myGroupLayout; + int myTableRow, myPreviewRow; +}; + +#endif diff --git a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx new file mode 100644 index 000000000..d39c223c1 --- /dev/null +++ b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx @@ -0,0 +1,277 @@ +// SMESH StdMeshersGUI : GUI for plugged-in meshers +// +// Copyright (C) 2003 CEA +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org or email : webmaster.salome@opencascade.org +// +// +// +// File : StdMeshersGUI_StdHypothesisCreator.cxx +// Author : Alexander SOLOVYOV +// Module : SMESH +// $Header: /home/server/cvs/SMESH/SMESH_SRC/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx + +#include "StdMeshersGUI_StdHypothesisCreator.h" + +#include +#include +#include +#include + +#include + +#include +#include CORBA_SERVER_HEADER(SMESH_BasicHypothesis) +#include CORBA_SERVER_HEADER(SMESH_Mesh) + +#include + + +const double VALUE_MAX = 1.0e+15, // COORD_MAX + VALUE_MAX_2 = VALUE_MAX * VALUE_MAX, + VALUE_MAX_3 = VALUE_MAX_2 * VALUE_MAX, + VALUE_SMALL = 1.0e-15, + VALUE_SMALL_2 = VALUE_SMALL * VALUE_SMALL, + VALUE_SMALL_3 = VALUE_SMALL_2 * VALUE_SMALL; + +StdMeshersGUI_StdHypothesisCreator::StdMeshersGUI_StdHypothesisCreator( const QString& type ) +: SMESHGUI_GenericHypothesisCreator( type ) +{ +} + +StdMeshersGUI_StdHypothesisCreator::~StdMeshersGUI_StdHypothesisCreator() +{ +} + +QFrame* StdMeshersGUI_StdHypothesisCreator::buildFrame() +{ + return buildStdFrame(); +} + +bool StdMeshersGUI_StdHypothesisCreator::checkParams() const +{ + return true; +} + +void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const +{ + //here this method must be empty because buildStdParam sets values itself +} + +void StdMeshersGUI_StdHypothesisCreator::storeParams() const +{ + ListOfStdParams params; + bool res = getStdParamFromDlg( params ); + if( isCreation() ) + { + SMESH::SetName( SMESH::FindSObject( hypothesis() ), params[0].myValue.toString().latin1() ); + params.remove( params.begin() ); + } + + if( res && !params.isEmpty() ) + { + if( hypType()=="LocalLength" ) + { + StdMeshers::StdMeshers_LocalLength_var h = + StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() ); + + h->SetLength( params[0].myValue.toDouble() ); + } + else if( hypType()=="Arithmetic1D" ) + { + StdMeshers::StdMeshers_Arithmetic1D_var h = + StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() ); + + h->SetLength( params[0].myValue.toDouble(), true ); + h->SetLength( params[1].myValue.toDouble(), false ); + } + else if( hypType()=="MaxElementArea" ) + { + StdMeshers::StdMeshers_MaxElementArea_var h = + StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() ); + + h->SetMaxElementArea( params[0].myValue.toDouble() ); + } + else if( hypType()=="MaxElementVolume" ) + { + StdMeshers::StdMeshers_MaxElementVolume_var h = + StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() ); + + h->SetMaxElementVolume( params[0].myValue.toDouble() ); + } + else if( hypType()=="StartEndLength" ) + { + StdMeshers::StdMeshers_StartEndLength_var h = + StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() ); + + h->SetLength( params[0].myValue.toDouble(), true ); + h->SetLength( params[1].myValue.toDouble(), false ); + } + else if( hypType()=="Deflection1D" ) + { + StdMeshers::StdMeshers_Deflection1D_var h = + StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() ); + + h->SetDeflection( params[0].myValue.toDouble() ); + } + } +} + +bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const +{ + bool res = true; + SMESHGUI_GenericHypothesisCreator::StdParam item; + + p.clear(); + if( isCreation() ) + { + HypothesisData* data = SMESH::GetHypothesisData( hypType() ); + item.myName = tr( "SMESH_NAME" ); + item.myValue = data ? data->Label : QString(); + p.append( item ); + } + + if( hypType()=="LocalLength" ) + { + StdMeshers::StdMeshers_LocalLength_var h = + StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() ); + + item.myName = tr("SMESH_LOCAL_LENGTH_PARAM"); + item.myValue = isCreation() ? 1.0 : h->GetLength(); + p.append( item ); + } + else if( hypType()=="Arithmetic1D" ) + { + StdMeshers::StdMeshers_Arithmetic1D_var h = + StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() ); + + item.myName = tr( "SMESH_START_LENGTH_PARAM" ); + item.myValue = isCreation() ? 1.0 : h->GetLength( true ); + p.append( item ); + item.myName = tr( "SMESH_END_LENGTH_PARAM" ); + item.myValue = isCreation() ? 10.0 : h->GetLength( false ); + p.append( item ); + } + else if( hypType()=="MaxElementArea" ) + { + StdMeshers::StdMeshers_MaxElementArea_var h = + StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() ); + + item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" ); + item.myValue = isCreation() ? 1.0 : h->GetMaxElementArea(); + p.append( item ); + } + else if( hypType()=="MaxElementVolume" ) + { + StdMeshers::StdMeshers_MaxElementVolume_var h = + StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() ); + + item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" ); + item.myValue = isCreation() ? 1.0 : h->GetMaxElementVolume(); + p.append( item ); + } + else if( hypType()=="StartEndLength" ) + { + StdMeshers::StdMeshers_StartEndLength_var h = + StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() ); + + item.myName = tr( "SMESH_START_LENGTH_PARAM" ); + item.myValue = isCreation() ? 1.0 : h->GetLength( true ); + p.append( item ); + item.myName = tr( "SMESH_END_LENGTH_PARAM" ); + item.myValue = isCreation() ? 10.0 : h->GetLength( false ); + p.append( item ); + } + else if( hypType()=="Deflection1D" ) + { + StdMeshers::StdMeshers_Deflection1D_var h = + StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() ); + + item.myName = tr( "SMESH_DEFLECTION1D_PARAM" ); + item.myValue = isCreation() ? 1.0 : h->GetDeflection(); + p.append( item ); + } + else + res = false; + return res; +} + +void StdMeshersGUI_StdHypothesisCreator::attuneStdWidget( QWidget* w, const int ) const +{ + SMESHGUI_SpinBox* sb = w->inherits( "SMESHGUI_SpinBox" ) ? ( SMESHGUI_SpinBox* )w : 0; + if( hypType()=="LocalLength" && sb ) + { + sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 ); + } + else if( hypType()=="Arithmetic1D" && sb ) + { + sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 ); + } + else if( hypType()=="MaxElementArea" && sb ) + { + sb->RangeStepAndValidator( VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6 ); + } + else if( hypType()=="MaxElementVolume" && sb ) + { + sb->RangeStepAndValidator( VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6 ); + } + else if( hypType()=="StartEndLength" && sb ) + { + sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 ); + } + else if( hypType()=="Deflection1D" && sb ) + { + sb->RangeStepAndValidator( VALUE_SMALL, VALUE_MAX, 1.0, 6 ); + } +} + +QString StdMeshersGUI_StdHypothesisCreator::caption() const +{ + return tr( QString( "SMESH_%1_TITLE" ).arg( hypTypeName( hypType() ) ) ); +} + +QPixmap StdMeshersGUI_StdHypothesisCreator::icon() const +{ + QString hypIconName = tr( QString( "ICON_DLG_%1" ).arg( hypTypeName( hypType() ) ) ); + return SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName ); +} + +QString StdMeshersGUI_StdHypothesisCreator::type() const +{ + return tr( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeName( hypType() ) ) ); +} + +QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) const +{ + static QMap types; + if( types.isEmpty() ) + { + types.insert( "LocalLength", "LOCAL_LENGTH" ); + types.insert( "NumberOfSegments", "NB_SEGMENTS" ); + types.insert( "MaxElementArea", "MAX_ELEMENT_AREA" ); + types.insert( "MaxElementVolume", "MAX_ELEMENT_VOLUME" ); + types.insert( "StartEndLength", "START_END_LENGTH" ); + types.insert( "Deflection1D", "DEFLECTION1D" ); + types.insert( "Arithmetic1D", "ARITHMETIC_1D" ); + } + + QString res; + if( types.contains( t ) ) + res = types[ t ]; + + return res; +} diff --git a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h new file mode 100644 index 000000000..d818ec5fe --- /dev/null +++ b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h @@ -0,0 +1,60 @@ +// SMESH StdMeshersGUI : GUI for plugged-in meshers +// +// Copyright (C) 2003 CEA +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org or email : webmaster.salome@opencascade.org +// +// +// +// File : StdMeshersGUI_StdHypothesisCreator.h +// Author : Alexander SOLOVYOV +// Module : SMESH +// $Header: /home/server/cvs/SMESH/SMESH_SRC/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h + +#ifndef STDMESHERSGUI_StdHypothesisCreator_HeaderFile +#define STDMESHERSGUI_StdHypothesisCreator_HeaderFile + +#include + +/*! + * \brief Class for creation of simple hypotheses (only set of parameters without dependencies) +*/ +class StdMeshersGUI_StdHypothesisCreator : public SMESHGUI_GenericHypothesisCreator +{ + Q_OBJECT + +public: + StdMeshersGUI_StdHypothesisCreator( const QString& ); + virtual ~StdMeshersGUI_StdHypothesisCreator(); + + virtual bool checkParams() const; + +protected: + virtual QFrame* buildFrame (); + virtual void retrieveParams() const; + virtual void storeParams () const; + virtual bool stdParams ( ListOfStdParams& ) const; + virtual void attuneStdWidget( QWidget*, const int ) const; + virtual QString caption() const; + virtual QPixmap icon() const; + virtual QString type() const; + +private: + QString hypTypeName( const QString& ) const; +}; + +#endif diff --git a/src/StdMeshersGUI/StdMeshers_msg_en.po b/src/StdMeshersGUI/StdMeshers_msg_en.po index 2c598ba89..19cd9295e 100644 --- a/src/StdMeshersGUI/StdMeshers_msg_en.po +++ b/src/StdMeshersGUI/StdMeshers_msg_en.po @@ -53,12 +53,30 @@ msgstr "Table function" msgid "SMESH_EXPR_FUNC" msgstr "Density function f(t) = " -msgid "SMESH_EXP_MODE" -msgstr "Exponent mode " +msgid "SMESH_CONV_MODE" +msgstr "Conversion mode " msgid "SMESH_NB_SEGMENTS_TITLE" msgstr "Hypothesis Construction" +msgid "SMESH_EXP_MODE" +msgstr "Exponent" + +msgid "SMESH_CUT_NEG_MODE" +msgstr "Cut negative" + +msgid "SMESH_INSERT_ROW" +msgstr "Insert row" + +msgid "SMESH_REMOVE_ROW" +msgstr "Remove row" + +msgid "SMESH_FUNC_DOMAIN" +msgstr "Warning: function must be defined on segment [0..1]" + +msgid "SMESH_INVALID_FUNCTION" +msgstr "Function is invalid" + # ----------- Max. Element Area ------------ msgid "SMESH_MAX_ELEMENT_AREA_PARAM" @@ -91,7 +109,7 @@ msgid "SMESH_END_LENGTH_PARAM" msgstr "End Length" msgid "SMESH_START_END_LENGTH_HYPOTHESIS" -msgstr "Start and EndLocal Length" +msgstr "Start and End local Length" msgid "SMESH_START_END_LENGTH_TITLE" msgstr "Hypothesis Construction" diff --git a/src/StdMeshers_I/StdMeshers_NumberOfSegments_i.cxx b/src/StdMeshers_I/StdMeshers_NumberOfSegments_i.cxx index 88149b400..edc817e3b 100644 --- a/src/StdMeshers_I/StdMeshers_NumberOfSegments_i.cxx +++ b/src/StdMeshers_I/StdMeshers_NumberOfSegments_i.cxx @@ -71,6 +71,59 @@ StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i() MESSAGE( "StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i" ); } +//============================================================================= +/*! + * StdMeshers_NumberOfSegments_i::BuildDistribution + * + * Builds point distribution according to passed function + */ +//============================================================================= +SMESH::double_array* StdMeshers_NumberOfSegments_i::BuildDistributionExpr( const char* func, long nbSeg, long conv ) +throw ( SALOME::SALOME_Exception ) +{ + MESSAGE( "StdMeshers_NumberOfSegments_i::BuildDistribution" ); + ASSERT( myBaseImpl ); + try + { + SMESH::double_array_var aRes = new SMESH::double_array(); + const std::vector& res = this->GetImpl()->BuildDistributionExpr( func, nbSeg, conv ); + aRes->length( res.size() ); + for (int i = 0; i < res.size(); i++) + aRes[i] = res[i]; + return aRes._retn(); + } + catch( SALOME_Exception& S_ex ) + { + THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM ); + } +} + +SMESH::double_array* StdMeshers_NumberOfSegments_i::BuildDistributionTab( const SMESH::double_array& func, + long nbSeg, long conv ) +throw ( SALOME::SALOME_Exception ) +{ + MESSAGE( "StdMeshers_NumberOfSegments_i::BuildDistribution" ); + ASSERT( myBaseImpl ); + + std::vector tbl( func.length() ); + for (int i = 0; i < func.length(); i++) + tbl[i] = func[i]; + + try + { + SMESH::double_array_var aRes = new SMESH::double_array(); + const std::vector& res = this->GetImpl()->BuildDistributionTab( tbl, nbSeg, conv ); + aRes->length( res.size() ); + for (int i = 0; i < res.size(); i++) + aRes[i] = res[i]; + return aRes._retn(); + } + catch( SALOME_Exception& S_ex ) + { + THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM ); + } +} + //============================================================================= /*! * StdMeshers_NumberOfSegments_i::SetNumberOfSegments @@ -289,15 +342,15 @@ char* StdMeshers_NumberOfSegments_i::GetExpressionFunction() */ //============================================================================= -void StdMeshers_NumberOfSegments_i::SetExponentMode(CORBA::Boolean isExp) +void StdMeshers_NumberOfSegments_i::SetConversionMode(CORBA::Long conv ) throw ( SALOME::SALOME_Exception ) { - MESSAGE( "StdMeshers_NumberOfSegments_i::SetExponentMode" ); + MESSAGE( "StdMeshers_NumberOfSegments_i::SetConversionMode" ); ASSERT( myBaseImpl ); try { - this->GetImpl()->SetExponentMode( isExp ); + this->GetImpl()->SetConversionMode( conv ); // Update Python script - SMESH::TPythonDump() << _this() << ".SetExponentMode( " << isExp << " )"; + SMESH::TPythonDump() << _this() << ".SetConversionMode( " << conv << " )"; } catch ( SALOME_Exception& S_ex ) { THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), @@ -310,20 +363,20 @@ void StdMeshers_NumberOfSegments_i::SetExponentMode(CORBA::Boolean isExp) */ //============================================================================= -CORBA::Boolean StdMeshers_NumberOfSegments_i::IsExponentMode() +CORBA::Long StdMeshers_NumberOfSegments_i::ConversionMode() throw ( SALOME::SALOME_Exception ) { - MESSAGE( "StdMeshers_NumberOfSegments_i::IsExponentMode" ); + MESSAGE( "StdMeshers_NumberOfSegments_i::ConversionMode" ); ASSERT( myBaseImpl ); - bool isExp; + int conv; try { - isExp = this->GetImpl()->IsExponentMode(); + conv = this->GetImpl()->ConversionMode(); } catch ( SALOME_Exception& S_ex ) { THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM ); } - return isExp; + return conv; } //============================================================================= diff --git a/src/StdMeshers_I/StdMeshers_NumberOfSegments_i.hxx b/src/StdMeshers_I/StdMeshers_NumberOfSegments_i.hxx index 270980f13..1bc5450a3 100644 --- a/src/StdMeshers_I/StdMeshers_NumberOfSegments_i.hxx +++ b/src/StdMeshers_I/StdMeshers_NumberOfSegments_i.hxx @@ -52,6 +52,12 @@ public: // Destructor virtual ~StdMeshers_NumberOfSegments_i(); + // Builds point distribution according to passed function + SMESH::double_array* BuildDistributionExpr( const char*, CORBA::Long, CORBA::Long ) + throw ( SALOME::SALOME_Exception ); + SMESH::double_array* BuildDistributionTab( const SMESH::double_array&, CORBA::Long, CORBA::Long ) + throw ( SALOME::SALOME_Exception ); + // Set number of segments void SetNumberOfSegments( CORBA::Long theSegmentsNumber ) throw ( SALOME::SALOME_Exception ); @@ -86,10 +92,10 @@ public: throw ( SALOME::SALOME_Exception ); // Set the exponent mode on/off - void SetExponentMode(CORBA::Boolean isExp) + void SetConversionMode( CORBA::Long conv ) throw ( SALOME::SALOME_Exception ); // Returns true if the exponent mode is set - CORBA::Boolean IsExponentMode() + CORBA::Long ConversionMode() throw ( SALOME::SALOME_Exception ); // Get implementation -- 2.39.2