#include <StdMeshersGUI_DistrPreview.h>

Public Types | |
| enum | Conversion { EXPONENT, CUT_NEGATIVE } |
Public Member Functions | |
| 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 Member Functions | |
| 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 Member Functions | |
| double | calc (bool &) |
| void | showError () |
| Handle (ExprIntrp_GenExp) myExpr | |
Private Attributes | |
| QString | myFunction |
| int | myPoints |
| int | myNbSeg |
| bool | myIsTable |
| Conversion | myConv |
| SMESH::double_array | myTableFunc |
| QwtPlotCurve * | myDensity |
| QwtPlotCurve * | myDistr |
| QwtPlotMarker * | myMsg |
| Expr_Array1OfNamedUnknown | myVars |
| TColStd_Array1OfReal | myValues |
| bool | myIsDone |
| StdMeshers::StdMeshers_NumberOfSegments_var | myHypo |
Definition at line 48 of file StdMeshersGUI_DistrPreview.h.
Definition at line 53 of file StdMeshersGUI_DistrPreview.h.
{ EXPONENT, CUT_NEGATIVE } Conversion;
| StdMeshersGUI_DistrPreview::StdMeshersGUI_DistrPreview | ( | QWidget * | p, |
| StdMeshers::StdMeshers_NumberOfSegments_ptr | h | ||
| ) |
Definition at line 58 of file StdMeshersGUI_DistrPreview.cxx.
References myDensity, myDistr, myHypo, myMsg, and myVars.
: QwtPlot( p ), myPoints( 50 ), myIsTable( false ), myVars( 1, 1 ), myValues( 1, 1 ), myConv( CUT_NEGATIVE ), myIsDone( true ), myNbSeg( 1 ) { Kernel_Utils::Localizer loc; myHypo = StdMeshers::StdMeshers_NumberOfSegments::_duplicate( h ); myVars.ChangeValue( 1 ) = new Expr_NamedUnknown( "t" ); myDensity = new QwtPlotCurve( QString() ); myDensity->attach( this ); myDistr = new QwtPlotCurve( QString() ); myDistr->attach( this ); myMsg = new QwtPlotMarker(); myMsg->attach( this ); myMsg->setValue( 0.5, 0.5 ); QwtText mt = myMsg->label(); mt.setBackgroundPen( QPen( Qt::red, 1 ) ); QFont f = mt.font(); f.setPointSize( 14 ); //f.setBold( true ); mt.setFont( f ); myMsg->setLabel( mt ); myDensity->setPen( QPen( Qt::red, 1 ) ); QColor dc = Qt::blue; myDistr->setPen( QPen( dc, 1 ) ); myDistr->setSymbol( QwtSymbol( QwtSymbol::XCross, QBrush( dc ), QPen( dc ), QSize( 5, 5 ) ) ); QwtLegend* l = legend(); if ( !l ) { l = new QwtLegend( this ); l->setFrameStyle( QFrame::Box | QFrame::Sunken ); } insertLegend( l, QwtPlot::BottomLegend ); enableAxis(QwtPlot::yLeft, false); enableAxis(QwtPlot::yRight, true); QFont axisFont; axisFont.setPointSize( 8 ); setAxisFont(QwtPlot::yRight, axisFont); setAxisFont(QwtPlot::xBottom, axisFont); myDensity->setYAxis(QwtPlot::yRight); myDistr->setYAxis(QwtPlot::yRight); myMsg->setYAxis(QwtPlot::yRight); myDensity->setTitle( tr( "SMESH_DENSITY_FUNC" ) ); myDistr->setTitle( tr( "SMESH_DISTR" ) ); QwtPlotGrid* aGrid = new QwtPlotGrid(); QPen aMajPen = aGrid->majPen(); aMajPen.setStyle( Qt::DashLine ); aGrid->setPen( aMajPen ); aGrid->enableX( true ); aGrid->enableY( true ); aGrid->attach( this ); }
| StdMeshersGUI_DistrPreview::~StdMeshersGUI_DistrPreview | ( | ) | [virtual] |
Definition at line 122 of file StdMeshersGUI_DistrPreview.cxx.
{
}
| double StdMeshersGUI_DistrPreview::calc | ( | bool & | ok | ) | [private] |
Definition at line 412 of file StdMeshersGUI_DistrPreview.cxx.
References Handle(), myValues, myVars, and SMESH_AdvancedEditor.res.
Referenced by funcValue().
| bool StdMeshersGUI_DistrPreview::convert | ( | double & | v | ) | const [protected, virtual] |
Definition at line 436 of file StdMeshersGUI_DistrPreview.cxx.
References CUT_NEGATIVE, EXPONENT, Handle(), and myConv.
Referenced by update().
{
bool ok = true;
switch( myConv )
{
case EXPONENT:
{
try {
#ifdef NO_CAS_CATCH
OCC_CATCH_SIGNALS;
#endif
// in StdMeshers_NumberOfSegments.cc
// const double PRECISION = 1e-7;
//
if(v < -7) v = -7.0;
v = pow( 10.0, v );
} catch(Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
v = 0.0;
ok = false;
}
}
break;
case CUT_NEGATIVE:
if( v<0 )
v = 0;
break;
}
return ok;
}
| bool StdMeshersGUI_DistrPreview::createTable | ( | SMESH::double_array & | func | ) | [protected, virtual] |
Definition at line 188 of file StdMeshersGUI_DistrPreview.cxx.
References ex13_hole1partial.d, funcValue(), and myPoints.
Referenced by update().
{
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<myPoints; j++ )
{
bool ok;
double t = xmin + d*j, f = funcValue( t, ok );
if( ok )
{
func[2*i] = t;
func[2*i+1] = f;
i++;
}
else
err++;
}
func.length( func.length()-2*err );
return err==0;
}
| QString StdMeshersGUI_DistrPreview::function | ( | ) | const |
Definition at line 136 of file StdMeshersGUI_DistrPreview.cxx.
References myFunction.
{
return myFunction;
}
| double StdMeshersGUI_DistrPreview::funcValue | ( | const double | t, |
| bool & | ok | ||
| ) | [protected, virtual] |
Definition at line 399 of file StdMeshersGUI_DistrPreview.cxx.
References calc(), myValues, and SMESH_AdvancedEditor.res.
Referenced by createTable().
| StdMeshersGUI_DistrPreview.Handle | ( | ExprIntrp_GenExp | ) | [private] |
| bool StdMeshersGUI_DistrPreview::init | ( | const QString & | str | ) | [protected, virtual] |
Definition at line 371 of file StdMeshersGUI_DistrPreview.cxx.
References Handle(), isCorrectArg(), and SMESH_AdvancedEditor.res.
Referenced by setParams().
{
Kernel_Utils::Localizer loc;
bool parsed_ok = true;
try {
#ifdef NO_CAS_CATCH
OCC_CATCH_SIGNALS;
#endif
myExpr = ExprIntrp_GenExp::Create();
myExpr->Process( ( Standard_CString ) str.toLatin1().data() );
} catch(Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
parsed_ok = false;
}
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;
}
| bool StdMeshersGUI_DistrPreview::isDone | ( | ) | const |
Definition at line 431 of file StdMeshersGUI_DistrPreview.cxx.
References myIsDone.
{
return myIsDone;
}
| bool StdMeshersGUI_DistrPreview::isTableFunc | ( | ) | const |
Definition at line 126 of file StdMeshersGUI_DistrPreview.cxx.
References myIsTable.
Referenced by update().
{
return myIsTable;
}
| int StdMeshersGUI_DistrPreview::nbSeg | ( | ) | const |
Definition at line 141 of file StdMeshersGUI_DistrPreview.cxx.
References myNbSeg.
{
return myNbSeg;
}
| int StdMeshersGUI_DistrPreview::pointsCount | ( | ) | const |
Definition at line 146 of file StdMeshersGUI_DistrPreview.cxx.
References myPoints.
{
return myPoints;
}
| void StdMeshersGUI_DistrPreview::setConversion | ( | Conversion | conv, |
| const bool | upd = true |
||
| ) |
Definition at line 151 of file StdMeshersGUI_DistrPreview.cxx.
References myConv, and update().
Referenced by StdMeshersGUI_NbSegmentsCreator.onValueChanged().
| bool StdMeshersGUI_DistrPreview::setParams | ( | const SMESH::double_array & | f, |
| const int | nbSeg, | ||
| const bool | upd = true |
||
| ) |
Definition at line 171 of file StdMeshersGUI_DistrPreview.cxx.
References myFunction, myIsTable, myNbSeg, myPoints, myTableFunc, and update().
{
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::setParams | ( | const QString & | func, |
| const int | nbSeg, | ||
| const int | points = 50, |
||
| const bool | upd = true |
||
| ) |
Definition at line 158 of file StdMeshersGUI_DistrPreview.cxx.
References init(), myFunction, myIsTable, myNbSeg, myPoints, myTableFunc, SMESH_AdvancedEditor.res, and update().
Referenced by StdMeshersGUI_NbSegmentsCreator.onValueChanged().
{
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;
}
| void StdMeshersGUI_DistrPreview::showError | ( | ) | [private] |
| void StdMeshersGUI_DistrPreview::tableFunc | ( | SMESH::double_array & | f | ) | const |
Definition at line 131 of file StdMeshersGUI_DistrPreview.cxx.
References myTableFunc.
{
f = myTableFunc;
}
| void StdMeshersGUI_DistrPreview::update | ( | ) | [protected] |
Definition at line 218 of file StdMeshersGUI_DistrPreview.cxx.
References convert(), createTable(), Handle(), isTableFunc(), myConv, myDensity, myDistr, myFunction, myHypo, myIsDone, myMsg, myNbSeg, myTableFunc, showError(), ex21_lamp.size, ex13_hole1partial.x, and ex13_hole1partial.y.
Referenced by setConversion(), and setParams().
{
Kernel_Utils::Localizer loc;
SMESH::double_array graph, distr;
if( isTableFunc() )
{
myIsDone = true;
graph = myTableFunc;
}
else
myIsDone = createTable( graph );
if( graph.length()>=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.toLatin1().data(), myNbSeg, ( int )myConv );
if( arr )
{
distr = *arr;
delete arr;
}
}
}
bool correct = graph.length()>=2 && distr.length()>=2;
if( !correct )
{
showError();
return;
}
else
{
QwtText mt = myMsg->label();
mt.setText( QString() );
myMsg->setLabel( mt );
}
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; i<size; i++ )
{
x[i] = graph[2*i];
y[i] = graph[2*i+1];
if( !convert( y[i] ) )
{
min_x = 0.0; max_x = 1.0; min_y = 0.0; max_y = 1.0;
delete[] x; delete[] y;
x = y = 0;
showError();
return;
}
#ifdef WIN32
if ( std::fabs(y[i]) >= HUGE_VAL)
y[i] = HUGE_VAL/100.;
#else
if ( isinf(y[i]))
y[i] = std::numeric_limits<double>::max()/100.;
#endif
// if ( y[i] > 1e3 )
// y[i] = 1e3;
if( i==0 || y[i]<min_y )
min_y = y[i];
if( i==0 || y[i]>max_y )
max_y = y[i];
if( i==0 || x[i]<min_x )
min_x = x[i];
if( i==0 || x[i]>max_x )
max_x = x[i];
}
setAxisScale( myDensity->xAxis(), min_x, max_x );
setAxisScale( myDensity->yAxis(),
#ifdef WIN32
min( 0.0, min_y ),
max( 0.0, max_y )
#else
std::min( 0.0, min_y ),
std::max( 0.0, max_y )
#endif
);
myDensity->setData( 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; i<size; i++ )
{
x[i] = distr[i];
y[i] = 0;
}
myDistr->setData( x, y, size );
delete[] x;
delete[] y;
x = y = 0;
try {
#ifdef NO_CAS_CATCH
OCC_CATCH_SIGNALS;
#endif
replot();
} catch(Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
}
}
Conversion StdMeshersGUI_DistrPreview.myConv [private] |
Definition at line 84 of file StdMeshersGUI_DistrPreview.h.
Referenced by convert(), setConversion(), and update().
QwtPlotCurve* StdMeshersGUI_DistrPreview.myDensity [private] |
Definition at line 86 of file StdMeshersGUI_DistrPreview.h.
Referenced by showError(), StdMeshersGUI_DistrPreview(), and update().
QwtPlotCurve* StdMeshersGUI_DistrPreview.myDistr [private] |
Definition at line 87 of file StdMeshersGUI_DistrPreview.h.
Referenced by showError(), StdMeshersGUI_DistrPreview(), and update().
QString StdMeshersGUI_DistrPreview.myFunction [private] |
Definition at line 81 of file StdMeshersGUI_DistrPreview.h.
Referenced by function(), setParams(), and update().
StdMeshers::StdMeshers_NumberOfSegments_var StdMeshersGUI_DistrPreview.myHypo [private] |
Definition at line 93 of file StdMeshersGUI_DistrPreview.h.
Referenced by StdMeshersGUI_DistrPreview(), and update().
bool StdMeshersGUI_DistrPreview.myIsDone [private] |
Definition at line 92 of file StdMeshersGUI_DistrPreview.h.
bool StdMeshersGUI_DistrPreview.myIsTable [private] |
Definition at line 83 of file StdMeshersGUI_DistrPreview.h.
Referenced by isTableFunc(), and setParams().
QwtPlotMarker* StdMeshersGUI_DistrPreview.myMsg [private] |
Definition at line 88 of file StdMeshersGUI_DistrPreview.h.
Referenced by showError(), StdMeshersGUI_DistrPreview(), and update().
int StdMeshersGUI_DistrPreview.myNbSeg [private] |
Definition at line 82 of file StdMeshersGUI_DistrPreview.h.
Referenced by nbSeg(), setParams(), and update().
int StdMeshersGUI_DistrPreview.myPoints [private] |
Definition at line 82 of file StdMeshersGUI_DistrPreview.h.
Referenced by createTable(), pointsCount(), and setParams().
Definition at line 85 of file StdMeshersGUI_DistrPreview.h.
Referenced by setParams(), tableFunc(), and update().
TColStd_Array1OfReal StdMeshersGUI_DistrPreview.myValues [private] |
Definition at line 91 of file StdMeshersGUI_DistrPreview.h.
Referenced by calc(), and funcValue().
Expr_Array1OfNamedUnknown StdMeshersGUI_DistrPreview.myVars [private] |
Definition at line 90 of file StdMeshersGUI_DistrPreview.h.
Referenced by calc(), and StdMeshersGUI_DistrPreview().