From: sln Date: Tue, 16 Dec 2008 11:00:22 +0000 (+0000) Subject: 0019819: EDF 643 VISU : Scalar bar ergonomics X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f365af0a29b0786e9f5b7c8a60d50e51f201598a;p=modules%2Fvisu.git 0019819: EDF 643 VISU : Scalar bar ergonomics Scalar bar ergonomics is updated. Two Parameters ?Title width (%)? and ?Title height (%)? are replaced with one parameter ?Title size (%)?. Two Parameters ?Labels width (%)? and ?Labels height (%)? are replaced with one parameter ?Labels size (%)?. Format of labels is stored as integer value specified format precision instead of string value representing format. This integer value is used by Preferences and ?Bar properties? dialog box. All other internal objects (actors and presentations) uses format as string values. Two auxiliary methods VISU_Prs3dUtils::ToFormat() and VISU_Prs3dUtils::ToPrecision() are created for converting precision to format and vice versa. --- diff --git a/src/VISU_I/VISU_ColoredPrs3d_i.cc b/src/VISU_I/VISU_ColoredPrs3d_i.cc index 44605b54..13272497 100644 --- a/src/VISU_I/VISU_ColoredPrs3d_i.cc +++ b/src/VISU_I/VISU_ColoredPrs3d_i.cc @@ -697,8 +697,8 @@ VISU::ColoredPrs3d_i SetUnitsVisible(anOrigin->IsUnitsVisible()); SetIsDistributionVisible(anOrigin->GetIsDistributionVisible()); - SetLabelsFormat(anOrigin->GetLabelsFormat()); - + SetLabelsFormat( anOrigin->GetLabelsFormat() ); + SetBarOrientation(anOrigin->GetBarOrientation()); SetMinMaxController( anOrigin ); @@ -713,8 +713,7 @@ VISU::ColoredPrs3d_i SetPosition(anOrigin->GetPosX(), anOrigin->GetPosY()); SetSize(anOrigin->GetWidth(), anOrigin->GetHeight()); - SetRatios(anOrigin->GetTitleWidth(), anOrigin->GetTitleHeight(), - anOrigin->GetLabelWidth(), anOrigin->GetLabelHeight(), + SetRatios(anOrigin->GetTitleSize(), anOrigin->GetLabelSize(), anOrigin->GetBarWidth(), anOrigin->GetBarHeight()); SetLabels(anOrigin->GetLabels()); @@ -1008,14 +1007,11 @@ VISU::ColoredPrs3d_i //---------------------------------------------------------------------------- void VISU::ColoredPrs3d_i -::SetRatios(CORBA::Long theTitleWidth, CORBA::Long theTitleHeight, - CORBA::Long theLabelWidth, CORBA::Long theLabelHeight, +::SetRatios(CORBA::Long theTitleSize, CORBA::Long theLabelSize, CORBA::Long theBarWidth, CORBA::Long theBarHeight) { - bool anIsSameValue = VISU::CheckIsSameValue(myTitleWidth, theTitleWidth); - anIsSameValue &= VISU::CheckIsSameValue(myTitleHeight, theTitleHeight); - anIsSameValue &= VISU::CheckIsSameValue(myLabelWidth, theLabelWidth); - anIsSameValue &= VISU::CheckIsSameValue(myLabelHeight, theLabelHeight); + bool anIsSameValue = VISU::CheckIsSameValue(myTitleSize, theTitleSize); + anIsSameValue &= VISU::CheckIsSameValue(myLabelSize, theLabelSize); anIsSameValue &= VISU::CheckIsSameValue(myBarWidth, theBarWidth); anIsSameValue &= VISU::CheckIsSameValue(myBarHeight, theBarHeight); if(anIsSameValue) @@ -1023,10 +1019,8 @@ VISU::ColoredPrs3d_i VISU::TSetModified aModified(this); - myTitleWidth = theTitleWidth; - myTitleHeight = theTitleHeight; - myLabelWidth = theLabelWidth; - myLabelHeight = theLabelHeight; + myTitleSize = theTitleSize; + myLabelSize = theLabelSize; myBarWidth = theBarWidth; myBarHeight = theBarHeight; myParamsTime.Modified(); @@ -1035,33 +1029,17 @@ VISU::ColoredPrs3d_i //---------------------------------------------------------------------------- CORBA::Long VISU::ColoredPrs3d_i -::GetTitleWidth() +::GetTitleSize() { - return myTitleWidth; -} - -//---------------------------------------------------------------------------- -CORBA::Long -VISU::ColoredPrs3d_i -::GetTitleHeight() -{ - return myTitleHeight; + return myTitleSize; } //---------------------------------------------------------------------------- CORBA::Long VISU::ColoredPrs3d_i -::GetLabelWidth() +::GetLabelSize() { - return myLabelWidth; -} - -//---------------------------------------------------------------------------- -CORBA::Long -VISU::ColoredPrs3d_i -::GetLabelHeight() -{ - return myLabelHeight; + return myLabelSize; } //---------------------------------------------------------------------------- @@ -1102,6 +1080,8 @@ VISU::ColoredPrs3d_i return myNumberOfLabels; } +//---------------------------------------------------------------------------- + //---------------------------------------------------------------------------- void VISU::ColoredPrs3d_i @@ -1510,8 +1490,8 @@ VISU::ColoredPrs3d_i SetIsDistributionVisible( aResourceMgr->booleanValue("VISU", "scalar_bar_show_distribution", false) ); // RKV - QString aLabelsFormat = aResourceMgr->stringValue( "VISU", "scalar_bar_label_format", "%-#6.3g" ); - SetLabelsFormat(aLabelsFormat.toLatin1().data()); + int lp = aResourceMgr->integerValue( "VISU", "scalar_bar_label_precision", 3 ); + SetLabelsFormat( VISU::ToFormat( lp ).c_str() ); // Orientation int anOrientation = aResourceMgr->integerValue("VISU", "scalar_bar_orientation", 0); @@ -1538,17 +1518,11 @@ VISU::ColoredPrs3d_i myHeight = (myOrientation == VISU::ColoredPrs3dBase::VERTICAL)? 0.8:0.12; myHeight = aResourceMgr->doubleValue("VISU", propertyName + "height", myHeight); - myTitleWidth = 0; - myTitleWidth = aResourceMgr->integerValue("VISU", propertyName + "title_width", myTitleWidth); - - myTitleHeight = 0; - myTitleHeight = aResourceMgr->integerValue("VISU", propertyName + "title_height", myTitleHeight); - - myLabelWidth = 0; - myLabelWidth = aResourceMgr->integerValue("VISU", propertyName + "label_width", myLabelWidth); + myTitleSize = 0; + myTitleSize = aResourceMgr->integerValue("VISU", propertyName + "title_size", myTitleSize); - myLabelHeight = 0; - myLabelHeight = aResourceMgr->integerValue("VISU", propertyName + "label_height", myLabelHeight); + myLabelSize = 0; + myLabelSize = aResourceMgr->integerValue("VISU", propertyName + "label_size", myLabelSize); myBarWidth = 0; myBarWidth = aResourceMgr->integerValue("VISU", propertyName + "bar_width", myBarWidth); @@ -1729,10 +1703,8 @@ VISU::ColoredPrs3d_i myPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble(); myWidth = VISU::Storable::FindValue(theMap,"myWidth").toDouble(); myHeight = VISU::Storable::FindValue(theMap,"myHeight").toDouble(); - myTitleWidth = VISU::Storable::FindValue(theMap,"myTitleWidth").toInt(); - myTitleHeight = VISU::Storable::FindValue(theMap,"myTitleHeight").toInt(); - myLabelWidth = VISU::Storable::FindValue(theMap,"myLabelWidth").toInt(); - myLabelHeight = VISU::Storable::FindValue(theMap,"myLabelHeight").toInt(); + myTitleSize = VISU::Storable::FindValue(theMap,"myTitleSize").toInt(); + myLabelSize = VISU::Storable::FindValue(theMap,"myLabelSize").toInt(); myBarWidth = VISU::Storable::FindValue(theMap,"myBarWidth").toInt(); myBarHeight = VISU::Storable::FindValue(theMap,"myBarHeight").toInt(); @@ -1809,15 +1781,15 @@ VISU::ColoredPrs3d_i Storable::DataToStream( theStr, "myTitle", myTitle.c_str() ); Storable::DataToStream( theStr, "myUnitsVisible", myIsUnits ); Storable::DataToStream( theStr, "myNumberOfLabels", myNumberOfLabels ); + Storable::DataToStream( theStr, "myLabelsFormat", myLabelsFormat.c_str() ); + Storable::DataToStream( theStr, "myPosition[0]", myPosition[0] ); Storable::DataToStream( theStr, "myPosition[1]", myPosition[1] ); Storable::DataToStream( theStr, "myWidth", myWidth ); Storable::DataToStream( theStr, "myHeight", myHeight ); - Storable::DataToStream( theStr, "myTitleWidth", myTitleWidth ); - Storable::DataToStream( theStr, "myTitleHeight", myTitleHeight ); - Storable::DataToStream( theStr, "myLabelWidth", myLabelWidth ); - Storable::DataToStream( theStr, "myLabelHeight", myLabelHeight ); + Storable::DataToStream( theStr, "myTitleSize", myTitleSize ); + Storable::DataToStream( theStr, "myLabelSize", myLabelSize ); Storable::DataToStream( theStr, "myBarWidth", myBarWidth ); Storable::DataToStream( theStr, "myBarHeight", myBarHeight ); diff --git a/src/VISU_I/VISU_ColoredPrs3d_i.hh b/src/VISU_I/VISU_ColoredPrs3d_i.hh index 73cd4807..d150f686 100644 --- a/src/VISU_I/VISU_ColoredPrs3d_i.hh +++ b/src/VISU_I/VISU_ColoredPrs3d_i.hh @@ -284,8 +284,7 @@ namespace VISU virtual void - SetRatios(CORBA::Long theTitleWidth, CORBA::Long theTitleHeight, - CORBA::Long theLabelWidth, CORBA::Long theLabelHeight, + SetRatios(CORBA::Long theTitleSize, CORBA::Long theLabelSize, CORBA::Long theBarWidth, CORBA::Long theBarHeight); virtual @@ -298,19 +297,11 @@ namespace VISU virtual CORBA::Long - GetTitleWidth(); - - virtual - CORBA::Long - GetTitleHeight(); + GetTitleSize(); virtual CORBA::Long - GetLabelWidth(); - - virtual - CORBA::Long - GetLabelHeight(); + GetLabelSize(); virtual CORBA::Long @@ -740,11 +731,11 @@ namespace VISU int myNumberOfLabels; std::string myLabelsFormat; + VISU::ColoredPrs3dBase::Orientation myOrientation; vtkFloatingPointType myPosition[2], myWidth, myHeight, - myTitleWidth, myTitleHeight, - myLabelWidth, myLabelHeight, + myTitleSize, myLabelSize, myBarWidth, myBarHeight; //Font management diff --git a/src/VISU_I/VISU_GaussPoints_i.cc b/src/VISU_I/VISU_GaussPoints_i.cc index ef1f7427..af6412b4 100644 --- a/src/VISU_I/VISU_GaussPoints_i.cc +++ b/src/VISU_I/VISU_GaussPoints_i.cc @@ -883,8 +883,7 @@ VISU::GaussPoints_i theScalarBar->SetTitle(GetScalarBarTitle().c_str()); theScalarBar->SetOrientation(GetBarOrientation()); theScalarBar->SetNumberOfLabels(GetLabels()); - theScalarBar->SetRatios(GetTitleWidth(), GetTitleHeight(), - GetLabelWidth(), GetLabelHeight(), + theScalarBar->SetRatios(GetTitleSize(), GetLabelSize(), GetBarWidth(), GetBarHeight()); theScalarBar->SetLabelFormat(GetLabelsFormat()); diff --git a/src/VISU_I/VISU_PointMap3d_i.cc b/src/VISU_I/VISU_PointMap3d_i.cc index 9c316f47..877bd8eb 100644 --- a/src/VISU_I/VISU_PointMap3d_i.cc +++ b/src/VISU_I/VISU_PointMap3d_i.cc @@ -217,8 +217,8 @@ VISU::Storable* VISU::PointMap3d_i::Create() SetRange(aMin, aMax); } - QString aLabelsFormat = aResourceMgr->stringValue( "VISU", "scalar_bar_label_format", "%-#6.3g" ); - SetLabelsFormat(aLabelsFormat.toLatin1().constData()); + int lp = aResourceMgr->integerValue( "VISU", "scalar_bar_label_precision", 3 ); + SetLabelsFormat( VISU::ToFormat( lp ).c_str() ); // Orientation int anOrientation = aResourceMgr->integerValue("VISU", "scalar_bar_orientation", 0); @@ -245,10 +245,8 @@ VISU::Storable* VISU::PointMap3d_i::Create() myHeight = (myBarOrientation == VISU::ColoredPrs3dBase::VERTICAL)? 0.8:0.12; myHeight = aResourceMgr->doubleValue("VISU", propertyName + "height", myHeight); - myTitleWidth = aResourceMgr->doubleValue("VISU", propertyName + "title_width", 0); - myTitleHeight = aResourceMgr->doubleValue("VISU", propertyName + "title_height", 0); - myLabelWidth = aResourceMgr->doubleValue("VISU", propertyName + "label_width", 0); - myLabelHeight = aResourceMgr->doubleValue("VISU", propertyName + "label_height", 0); + myTitleSize = aResourceMgr->doubleValue("VISU", propertyName + "title_size", 0); + myLabelSize = aResourceMgr->doubleValue("VISU", propertyName + "label_size", 0); myBarWidth = aResourceMgr->doubleValue("VISU", propertyName + "bar_width", 0); myBarHeight = aResourceMgr->doubleValue("VISU", propertyName + "bar_height", 0); @@ -404,8 +402,7 @@ void VISU::PointMap3d_i::UpdateActor(VISU_ActorBase* theActor) aScalarBar->SetWidth(GetWidth()); aScalarBar->SetHeight(GetHeight()); aScalarBar->SetNumberOfLabels(GetLabels()); - aScalarBar->SetRatios(myTitleWidth, myTitleHeight, - myLabelWidth, myLabelHeight, + aScalarBar->SetRatios(myTitleSize, myLabelSize, myBarWidth, myBarHeight); aScalarBar->SetNumberOfLabels(GetLabels()); aScalarBar->SetLabelFormat(GetLabelsFormat()); @@ -583,10 +580,8 @@ VISU::Storable* VISU::PointMap3d_i::Restore( const Storable::TRestoringMap& theM myPosition[1] = VISU::Storable::FindValue(theMap,"myPosition[1]").toDouble(); myWidth = VISU::Storable::FindValue(theMap,"myWidth").toDouble(); myHeight = VISU::Storable::FindValue(theMap,"myHeight").toDouble(); - myTitleWidth = VISU::Storable::FindValue(theMap,"myTitleWidth").toInt(); - myTitleHeight = VISU::Storable::FindValue(theMap,"myTitleHeight").toInt(); - myLabelWidth = VISU::Storable::FindValue(theMap,"myLabelWidth").toInt(); - myLabelHeight = VISU::Storable::FindValue(theMap,"myLabelHeight").toInt(); + myTitleSize = VISU::Storable::FindValue(theMap,"myTitleSize").toInt(); + myLabelSize = VISU::Storable::FindValue(theMap,"myLabelSize").toInt(); myBarWidth = VISU::Storable::FindValue(theMap,"myBarWidth").toInt(); myBarHeight = VISU::Storable::FindValue(theMap,"myBarHeight").toInt(); @@ -633,10 +628,8 @@ void VISU::PointMap3d_i::ToStream( std::ostringstream& theStr ) Storable::DataToStream( theStr, "myPosition[1]", myPosition[1] ); Storable::DataToStream( theStr, "myWidth", myWidth ); Storable::DataToStream( theStr, "myHeight", myHeight ); - Storable::DataToStream( theStr, "myTitleWidth", myTitleWidth ); - Storable::DataToStream( theStr, "myTitleHeight", myTitleHeight ); - Storable::DataToStream( theStr, "myLabelWidth", myLabelWidth ); - Storable::DataToStream( theStr, "myLabelHeight", myLabelHeight ); + Storable::DataToStream( theStr, "myTitleSize", myTitleSize ); + Storable::DataToStream( theStr, "myLabelSize", myLabelSize ); Storable::DataToStream( theStr, "myBarWidth", myBarWidth ); Storable::DataToStream( theStr, "myBarHeight", myBarHeight ); @@ -1188,27 +1181,15 @@ void VISU::PointMap3d_i::SetLabelColor(vtkFloatingPointType theR, } //---------------------------------------------------------------------------- -CORBA::Long VISU::PointMap3d_i::GetTitleWidth() +CORBA::Long VISU::PointMap3d_i::GetTitleSize() { - return myTitleWidth; + return myTitleSize; } //---------------------------------------------------------------------------- -CORBA::Long VISU::PointMap3d_i::GetTitleHeight() -{ - return myTitleHeight; -} - -//---------------------------------------------------------------------------- -CORBA::Long VISU::PointMap3d_i::GetLabelWidth() +CORBA::Long VISU::PointMap3d_i::GetLabelSize() { - return myLabelWidth; -} - -//---------------------------------------------------------------------------- -CORBA::Long VISU::PointMap3d_i::GetLabelHeight() -{ - return myLabelHeight; + return myLabelSize; } //---------------------------------------------------------------------------- @@ -1255,23 +1236,19 @@ CORBA::Boolean VISU::PointMap3d_i::IsUnitsVisible() } //---------------------------------------------------------------------------- -void VISU::PointMap3d_i::SetRatios(CORBA::Long theTitleWidth, CORBA::Long theTitleHeight, - CORBA::Long theLabelWidth, CORBA::Long theLabelHeight, +void VISU::PointMap3d_i::SetRatios(CORBA::Long theTitleSize, + CORBA::Long theLabelSize, CORBA::Long theBarWidth, CORBA::Long theBarHeight) { - bool anIsSameValue = VISU::CheckIsSameValue(myTitleWidth, theTitleWidth); - anIsSameValue &= VISU::CheckIsSameValue(myTitleHeight, theTitleHeight); - anIsSameValue &= VISU::CheckIsSameValue(myLabelWidth, theLabelWidth); - anIsSameValue &= VISU::CheckIsSameValue(myLabelHeight, theLabelHeight); + bool anIsSameValue = VISU::CheckIsSameValue(myTitleSize, theTitleSize); + anIsSameValue &= VISU::CheckIsSameValue(myLabelSize, theLabelSize); anIsSameValue &= VISU::CheckIsSameValue(myBarWidth, theBarWidth); anIsSameValue &= VISU::CheckIsSameValue(myBarHeight, theBarHeight); if(anIsSameValue) return; - myTitleWidth = theTitleWidth; - myTitleHeight = theTitleHeight; - myLabelWidth = theLabelWidth; - myLabelHeight = theLabelHeight; + myTitleSize = theTitleSize; + myLabelSize = theLabelSize; myBarWidth = theBarWidth; myBarHeight = theBarHeight; myParamsTime.Modified(); diff --git a/src/VISU_I/VISU_PointMap3d_i.hh b/src/VISU_I/VISU_PointMap3d_i.hh index 593721ec..6ab36578 100644 --- a/src/VISU_I/VISU_PointMap3d_i.hh +++ b/src/VISU_I/VISU_PointMap3d_i.hh @@ -100,8 +100,7 @@ namespace VISU virtual void SetSize(CORBA::Double theWidth, CORBA::Double theHeight); - virtual void SetRatios(CORBA::Long theTitleWidth, CORBA::Long theTitleHeight, - CORBA::Long theLabelWidth, CORBA::Long theLabelHeight, + virtual void SetRatios(CORBA::Long theTitleSize, CORBA::Long theLabelSize, CORBA::Long theBarWidth, CORBA::Long theBarHeight); virtual CORBA::Double GetWidth(); @@ -115,7 +114,7 @@ namespace VISU virtual void SetLabelsFormat(const char* theFormat); virtual char* GetLabelsFormat(); - + virtual void SetBarOrientation(VISU::ColoredPrs3dBase::Orientation theOrientation); virtual VISU::ColoredPrs3dBase::Orientation GetBarOrientation(); @@ -188,10 +187,8 @@ namespace VISU vtkFloatingPointType theB); //------------------------------------------------------------------- - virtual CORBA::Long GetTitleWidth(); - virtual CORBA::Long GetTitleHeight(); - virtual CORBA::Long GetLabelWidth(); - virtual CORBA::Long GetLabelHeight(); + virtual CORBA::Long GetTitleSize(); + virtual CORBA::Long GetLabelSize(); virtual CORBA::Long GetBarWidth(); virtual CORBA::Long GetBarHeight(); @@ -213,8 +210,8 @@ namespace VISU std::string myLabelsFormat; vtkFloatingPointType myPosition[2], myWidth, myHeight, - myTitleWidth, myTitleHeight, - myLabelWidth, myLabelHeight, + myTitleSize, + myLabelSize, myBarWidth, myBarHeight; bool myIsFixedRange; CORBA::Float myOffset[3]; diff --git a/src/VISU_I/VISU_Prs3dUtils.cc b/src/VISU_I/VISU_Prs3dUtils.cc index 652e781e..fd5bebd1 100644 --- a/src/VISU_I/VISU_Prs3dUtils.cc +++ b/src/VISU_I/VISU_Prs3dUtils.cc @@ -70,6 +70,59 @@ namespace VISU ProcessVoidEvent(new TEvent(this)); } + //---------------------------------------------------------------------------- + + std::string ToFormat( const int thePrec ) + { + // "%-#6.3g" + char str[ 255 ]; + sprintf( str, "%%-#.%dg", thePrec ); + return str; + } //---------------------------------------------------------------------------- + + int ToPrecision( const char* theFormat ) + { + int N = strlen( theFormat ); + int k = -1; + char str[ 255 ]; + bool isOk = false; + for ( int i = 0; i < N; i++ ) + { + if ( theFormat[ i ] == '.' ) + k = 0; + else if ( theFormat[ i ] == 'g' ) + { + str[ k ] = 0; + isOk = true; + break; + } + else if ( k >= 0 ) + str[ k++ ] = theFormat[ i ]; + } + + int res = 0; + if ( isOk ) + res = atoi( str ); + + return res; + } }; + + + + + + + + + + + + + + + + + diff --git a/src/VISU_I/VISU_Prs3dUtils.hh b/src/VISU_I/VISU_Prs3dUtils.hh index 2f4bf8b9..5c300342 100644 --- a/src/VISU_I/VISU_Prs3dUtils.hh +++ b/src/VISU_I/VISU_Prs3dUtils.hh @@ -31,7 +31,6 @@ #include - namespace VISU { //---------------------------------------------------------------------------- @@ -44,6 +43,9 @@ namespace VISU ~TSetModified(); }; + Standard_EXPORT std::string ToFormat( const int thePrec ); + Standard_EXPORT int ToPrecision( const char* theFormat ); + //---------------------------------------------------------------------------- } diff --git a/src/VISU_I/VISU_ScalarMap_i.cc b/src/VISU_I/VISU_ScalarMap_i.cc index 1ef187fe..85e40ce6 100644 --- a/src/VISU_I/VISU_ScalarMap_i.cc +++ b/src/VISU_I/VISU_ScalarMap_i.cc @@ -460,8 +460,7 @@ VISU::ScalarMap_i aScalarBar->GetPositionCoordinate()->SetValue(GetPosX(),GetPosY()); aScalarBar->SetWidth(GetWidth()); aScalarBar->SetHeight(GetHeight()); - aScalarBar->SetRatios(GetTitleWidth(), GetTitleHeight(), - GetLabelWidth(), GetLabelHeight(), + aScalarBar->SetRatios(GetTitleSize(), GetLabelSize(), GetBarWidth(), GetBarHeight()); aScalarBar->SetNumberOfLabels(GetLabels()); aScalarBar->SetLabelFormat(GetLabelsFormat());