X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FVISU_I%2FVISU_ColoredPrs3d_i.cc;h=4eb39df853d81342acc2a73510ee99b4ad4e7ffe;hb=716894d52739e56d77c5085e02b4cdfdbef60136;hp=5501a17ada3f85bd6b671ae9d0b84eaf7a8bc60f;hpb=e208a04edd5d8cebc0185834ecdf3faec4514f99;p=modules%2Fvisu.git diff --git a/src/VISU_I/VISU_ColoredPrs3d_i.cc b/src/VISU_I/VISU_ColoredPrs3d_i.cc index 5501a17a..4eb39df8 100644 --- a/src/VISU_I/VISU_ColoredPrs3d_i.cc +++ b/src/VISU_I/VISU_ColoredPrs3d_i.cc @@ -17,7 +17,7 @@ // 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 +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // // File : VISU_PrsObject_i.cxx @@ -25,18 +25,19 @@ // Module : VISU #include "VISU_ColoredPrs3d_i.hh" +#include "VISU_Prs3dUtils.hh" -#include "VISU_ScalarMapPL.hxx" #include "VISU_Result_i.hh" +#include "VISU_ColoredPL.hxx" +#include "VISU_PipeLineUtils.hxx" #include "VISU_Convertor.hxx" #include "SUIT_ResourceMgr.h" #include "SALOME_Event.hxx" +#include #include - -using namespace VISU; -using namespace std; +#include #ifdef _DEBUG_ static int MYDEBUG = 0; @@ -46,38 +47,165 @@ static int MYDEBUG = 0; #endif -//============================================================================ -VISU::ColoredPrs3d_i:: -ColoredPrs3d_i(Result_i* theResult, - bool theAddToStudy) : - PrsObject_i(theResult->GetStudyDocument()), - Prs3d_i(theResult,theAddToStudy), - myScalarMapPL(NULL), - myIsFixedRange(false) -{} +//--------------------------------------------------------------- +namespace +{ + std::string + FindOrCreate3DPresentationsFolder(SALOMEDS::Study_ptr theStudy) + { + static char aFolderName[] = "3D Presentations"; + CORBA::String_var anEntry; + SALOMEDS::SObject_var aSObject = theStudy->FindObject(aFolderName); + if(!CORBA::is_nil(aSObject) && aSObject->Depth() == 3){ + anEntry = aSObject->GetID(); + return anEntry.in(); + } + SALOMEDS::SComponent_var aSComponent = VISU::FindOrCreateVisuComponent(theStudy); + CORBA::String_var aFatherEntry = aSComponent->GetID(); + anEntry = VISU::CreateAttributes(theStudy, + aFatherEntry.in(), + "", + "", + aFolderName, + "", + "", + true).c_str(); + return anEntry.in(); + } +} + +//--------------------------------------------------------------- +namespace VISU +{ + //--------------------------------------------------------------- + inline + TMinMax + GetMinMax(VISU::Result_i* theResult, + VISU::PField theField, + vtkIdType theCompID) + { + if(!theResult->IsMinMaxDone()) + theResult->GetInput()->BuildMinMax(); + + return theField->GetMinMax(theCompID); + } + + //--------------------------------------------------------------- + void + TMinMaxController + ::UpdateReference(ColoredPrs3d_i* theFromPrs3, ColoredPrs3d_i* theToPrs3d) + {} + + + //--------------------------------------------------------------- + vtkFloatingPointType + TMinMaxController + ::GetComponentMin(vtkIdType theCompID) + { + return VTK_LARGE_FLOAT; + } + + + //--------------------------------------------------------------- + vtkFloatingPointType + TMinMaxController + ::GetComponentMax(vtkIdType theCompID) + { + return -VTK_LARGE_FLOAT; + } + + //--------------------------------------------------------------- + struct TSimpleMinMaxController: virtual TVTKMinMaxController + { + VISU::Result_i* myResult; + VISU::ColoredPrs3d_i* myColoredPrs3d; + + TSimpleMinMaxController(VISU::ColoredPrs3d_i* theColoredPrs3d): + myResult(theColoredPrs3d->GetCResult()), + myColoredPrs3d(theColoredPrs3d) + {} + + ~TSimpleMinMaxController() + {} + + virtual + vtkFloatingPointType + GetComponentMin(vtkIdType theCompID) + { + if ( VISU::PField aField = myColoredPrs3d->GetScalarField() ) { + TMinMax aMinMax = GetMinMax(myResult, aField, theCompID); + return aMinMax.first; + } + return TMinMaxController::GetComponentMin(theCompID); + } + + virtual + vtkFloatingPointType + GetComponentMax(vtkIdType theCompID) + { + if ( VISU::PField aField = myColoredPrs3d->GetScalarField() ) { + TMinMax aMinMax = GetMinMax(myResult, aField, theCompID); + return aMinMax.second; + } + return TMinMaxController::GetComponentMax(theCompID); + } + }; + + + //--------------------------------------------------------------- + PMinMaxController + CreateDefaultMinMaxController(VISU::ColoredPrs3d_i* theColoredPrs3d) + { + return PMinMaxController(new TSimpleMinMaxController(theColoredPrs3d)); + } + + + //--------------------------------------------------------------- +} + + +//--------------------------------------------------------------- VISU::ColoredPrs3d_i:: -ColoredPrs3d_i(Result_i* theResult, - SALOMEDS::SObject_ptr theSObject) : - PrsObject_i(theResult->GetStudyDocument()), - Prs3d_i(theResult,theSObject), - myScalarMapPL(NULL), - myIsFixedRange(false) +ColoredPrs3d_i(EPublishInStudyMode thePublishInStudyMode) : + myPublishInStudyMode(thePublishInStudyMode), + myIsTimeStampFixed(thePublishInStudyMode == EPublishUnderTimeStamp), + myColoredPL(NULL), + myIsFixedRange(false), + myIsRestored(true) {} +//--------------------------------------------------------------- VISU::ColoredPrs3d_i ::~ColoredPrs3d_i() {} +//--------------------------------------------------------------- +void +VISU::ColoredPrs3d_i +::Register() +{ + TSuperClass::Register(); +} + +//--------------------------------------------------------------- +void +VISU::ColoredPrs3d_i +::Destroy() +{ + TSuperClass::Destroy(); +} + //--------------------------------------------------------------- void VISU::ColoredPrs3d_i ::RemoveFromStudy() { - struct TRemoveFromStudy: public SALOME_Event + struct TEvent: public SALOME_Event { VISU::ColoredPrs3d_i* myRemovable; - TRemoveFromStudy(VISU::ColoredPrs3d_i* theRemovable): + + TEvent(VISU::ColoredPrs3d_i* theRemovable): myRemovable(theRemovable) {} @@ -86,13 +214,452 @@ VISU::ColoredPrs3d_i Execute() { SALOMEDS::SObject_var aSObject = myRemovable->GetSObject(); + if(!CORBA::is_nil(aSObject.in())) VISU::RemoveFromStudy(aSObject,false); + myRemovable->TSuperClass::RemoveFromStudy(); } }; - ProcessVoidEvent(new TRemoveFromStudy(this)); + ProcessVoidEvent(new TEvent(this)); +} + + +//---------------------------------------------------------------------------- +void +VISU::ColoredPrs3d_i +::UpdateFromResult(Result_i* theResult) +{ + struct TEvent: public SALOME_Event + { + VISU::ColoredPrs3d_i* myColoredPrs3d; + + TEvent(VISU::ColoredPrs3d_i* theColoredPrs3d): + myColoredPrs3d(theColoredPrs3d) + {} + + virtual + void + Execute() + { + try{ + myColoredPrs3d->DoSetInput(false, false); + myColoredPrs3d->UpdateActors(); + }catch(std::exception& exc){ + INFOS("Follow exception was occured :\n"<Init(); + + // To update scalar range according to the new input + if(!IsRangeFixed() && theReInit) + SetSourceRange(); + + if(GetPublishInStudyMode() != EDoNotPublish) + GetCResult()->ConnectObserver(this, myResultConnection); + + myPreviousEntity = myEntity; + myPreviousFieldName = myFieldName; + myPreviousTimeStampNumber = myTimeStampNumber; + }catch(std::exception& exc){ + INFOS("Follow exception was occured :\n"<length(); + + if( theIndex >= 0 && theIndex < aLength ) + { + VISU::ColoredPrs3dHolder::TimeStampInfo anInfo = aTimeStampsRange[ theIndex ]; + return anInfo.myNumber; + } + + return -1; +} + + +//---------------------------------------------------------------------------- +CORBA::Long +VISU::ColoredPrs3d_i +::GetTimeStampIndexByNumber( CORBA::Long theNumber ) +{ + VISU::ColoredPrs3dHolder::TimeStampsRange_var aTimeStampsRange = GetTimeStampsRange(); + CORBA::Long aLength = aTimeStampsRange->length(); + + for( int index = 0; index < aLength; index++ ) + { + VISU::ColoredPrs3dHolder::TimeStampInfo anInfo = aTimeStampsRange[ index ]; + + if( anInfo.myNumber == theNumber ) + return index; + } + + return -1; +} + + +//---------------------------------------------------------------------------- +VISU::PField +VISU::ColoredPrs3d_i +::GetScalarField() +{ + return myField; +} + + +//---------------------------------------------------------------------------- +VISU::PMinMaxController +VISU::ColoredPrs3d_i +::GetMinMaxController() +{ + return myMinMaxController; +} + + +//---------------------------------------------------------------------------- +void +VISU::ColoredPrs3d_i +::SetMinMaxController( const VISU::PMinMaxController& theController ) +{ + myMinMaxController = theController; + + if(!IsRangeFixed()) + SetSourceRange(); +} + + +//---------------------------------------------------------------------------- +void +VISU::ColoredPrs3d_i +::SetMinMaxController( VISU::ColoredPrs3d_i* theOrigin ) +{ + VISU::PMinMaxController aController = theOrigin->GetMinMaxController(); + + if ( aController ) + aController->UpdateReference( theOrigin, this ); + + SetMinMaxController( aController ); +} + + +//---------------------------------------------------------------------------- +CORBA::Long +VISU::ColoredPrs3d_i +::GetScalarTimeStampNumber() const +{ + return myTimeStampNumber; +} + + +//---------------------------------------------------------------------------- +VISU::ColoredPrs3dHolder::TimeStampsRange* +VISU::ColoredPrs3d_i +::GetTimeStampsRange() +{ + VISU::ColoredPrs3dHolder::TimeStampsRange_var aTimeStampsRange = + new VISU::ColoredPrs3dHolder::TimeStampsRange(); + VISU::TValField& aValField = GetField()->myValField; + if(IsTimeStampFixed()){ + aTimeStampsRange->length(1); + PValForTime& aValForTime = aValField[GetTimeStampNumber()]; + std::string aTime = VISU_Convertor::GenerateName(aValForTime->myTime); + VISU::ColoredPrs3dHolder::TimeStampInfo anInfo; + anInfo.myNumber = GetTimeStampNumber(); + anInfo.myTime = aTime.c_str(); + aTimeStampsRange[0] = anInfo; + return aTimeStampsRange._retn(); + } + + // To exclude timstamps with repeated time + typedef std::map TTimeStampsRange; + TTimeStampsRange aRange; + { + VISU::TValField::const_iterator anIter = aValField.begin(); + for(; anIter != aValField.end(); anIter++){ + vtkIdType aTimeStampNumber = anIter->first; + const PValForTime& aValForTime = anIter->second; + std::string aTime = VISU_Convertor::GenerateName(aValForTime->myTime); + aRange[aTime] = aTimeStampNumber; + } + } + + // To sort timestamps according to their timestamp number + typedef std::map TTimeStampsSortedRange; + TTimeStampsSortedRange aSortedRange; + { + TTimeStampsRange::const_iterator anIter = aRange.begin(); + for(size_t aCounter = 0; anIter != aRange.end(); anIter++, aCounter++){ + vtkIdType aTimeStampNumber = anIter->second; + const std::string& aTime = anIter->first; + aSortedRange[aTimeStampNumber] = aTime; + } + } + + // To map the C++ data structures to the corresponding CORBA ones + { + aTimeStampsRange->length(aRange.size()); + TTimeStampsSortedRange::const_iterator anIter = aSortedRange.begin(); + for(size_t aCounter = 0; anIter != aSortedRange.end(); anIter++, aCounter++){ + vtkIdType aTimeStampNumber = anIter->first; + const std::string& aTime = anIter->second; + VISU::ColoredPrs3dHolder::TimeStampInfo anInfo; + anInfo.myNumber = aTimeStampNumber; + anInfo.myTime = aTime.c_str(); + aTimeStampsRange[aCounter] = anInfo; + } + } + return aTimeStampsRange._retn(); +} + +CORBA::Float +VISU::ColoredPrs3d_i +::GetMemorySize() +{ + return TSuperClass::GetMemorySize(); +} + +VISU::ColoredPrs3dHolder::BasicInput* +VISU::ColoredPrs3d_i +::GetBasicInput() +{ + VISU::ColoredPrs3dHolder::BasicInput* aBasicInput = new VISU::ColoredPrs3dHolder::BasicInput(); + aBasicInput->myResult = GetResultObject(); + aBasicInput->myMeshName = GetMeshName(); + aBasicInput->myEntity = GetEntity(); + aBasicInput->myFieldName = GetFieldName(); + aBasicInput->myTimeStampNumber = GetTimeStampNumber(); + + return aBasicInput; +} + + +//---------------------------------------------------------------------------- +void +VISU::ColoredPrs3d_i +::SetHolderEntry(const std::string& theEntry) +{ + myHolderEntry = theEntry; +} + + +//---------------------------------------------------------------------------- +std::string +VISU::ColoredPrs3d_i +::GetHolderEntry() +{ + return myHolderEntry; +} + + +//---------------------------------------------------------------------------- +std::string +VISU::ColoredPrs3d_i +::GetActorEntry() +{ + if(myHolderEntry != "") + return myHolderEntry; + return TSuperClass::GetActorEntry(); +} + + +//---------------------------------------------------------------------------- +CORBA::Boolean +VISU::ColoredPrs3d_i +::IsTimeStampFixed() +{ + return myIsTimeStampFixed; +} + +//---------------------------------------------------------------------------- +VISU::ColoredPrs3d_i::EPublishInStudyMode +VISU::ColoredPrs3d_i +::GetPublishInStudyMode() +{ + return myPublishInStudyMode; } //--------------------------------------------------------------- @@ -101,34 +668,48 @@ VISU::ColoredPrs3d_i ::SameAs(const Prs3d_i* theOrigin) { if(const ColoredPrs3d_i* aPrs3d = dynamic_cast(theOrigin)){ - DoHook(); - ColoredPrs3d_i* anOrigin = const_cast(aPrs3d); - - myField = anOrigin->GetField(); - myMeshName = myField->myMeshName; - myEntity = VISU::TEntity(anOrigin->GetEntity());//myField->myEntity; - myIteration = anOrigin->GetIteration(); - myFieldName = anOrigin->GetFieldName(); - - Build(-1); + + bool anIsCreatNew = OnSetInput(false); + if(anIsCreatNew) + Build(ESameAs); TSuperClass::SameAs(theOrigin); - SetScalarMode(anOrigin->GetScalarMode()); + CORBA::Long aNbComp = GetScalarField()->myNbComp; + CORBA::Long anOriginNbComp = anOrigin->GetScalarField()->myNbComp; + if(anOriginNbComp < aNbComp) + SetScalarMode(0); + else + SetScalarMode(anOrigin->GetScalarMode()); + SetNbColors(anOrigin->GetNbColors()); + + SetUnitsVisible(anOrigin->IsUnitsVisible()); + SetLabelsFormat(anOrigin->GetLabelsFormat()); + SetBarOrientation(anOrigin->GetBarOrientation()); + SetMinMaxController( anOrigin ); + + if(anOrigin->IsRangeFixed()) + SetRange(anOrigin->GetMin(), anOrigin->GetMax()); + else + SetSourceRange(); + SetPosition(anOrigin->GetPosX(), anOrigin->GetPosY()); SetSize(anOrigin->GetWidth(), anOrigin->GetHeight()); + SetRatios(anOrigin->GetTitleWidth(), anOrigin->GetTitleHeight(), + anOrigin->GetLabelWidth(), anOrigin->GetLabelHeight(), + anOrigin->GetBarWidth(), anOrigin->GetBarHeight()); SetLabels(anOrigin->GetLabels()); - SetTitle(anOrigin->GetTitle()); - + + SetTitle(anOrigin->GetTitle()); SetBoldTitle(anOrigin->IsBoldTitle()); SetItalicTitle(anOrigin->IsItalicTitle()); SetShadowTitle(anOrigin->IsShadowTitle()); SetTitFontType(anOrigin->GetTitFontType()); - float r,g,b; + vtkFloatingPointType r,g,b; anOrigin->GetTitleColor(&r,&g,&b); SetTitleColor(r,g,b); @@ -138,87 +719,253 @@ VISU::ColoredPrs3d_i SetLblFontType(anOrigin->GetLblFontType()); anOrigin->GetLabelColor(&r,&g,&b); SetLabelColor(r,g,b); + + myIsTimeStampFixed = anOrigin->IsTimeStampFixed(); + + SetHolderEntry( anOrigin->GetHolderEntry() ); + + myGroupNames = anOrigin->GetGroupNames(); } } +//---------------------------------------------------------------------------- +CORBA::Long +VISU::ColoredPrs3d_i +::GetScalarMode() +{ + return myColoredPL->GetScalarMode(); +} + + +//---------------------------------------------------------------------------- void VISU::ColoredPrs3d_i -::SameAsParams(const ColoredPrs3d_i* theOrigin) +::SetScalarMode(CORBA::Long theScalarMode) { - int anIteration = GetIteration(); - SameAs(theOrigin); - myIteration = anIteration; + CORBA::Long aNbComp = GetScalarField()->myNbComp; + if(aNbComp == 1) + theScalarMode = 1; + else if(theScalarMode > aNbComp) + theScalarMode = 0; + + VISU::TSetModified aModified(this); - Build(-1); - Update(); + ProcessVoidEvent(new TVoidMemFun1ArgEvent + (GetSpecificPL(), &VISU_ColoredPL::SetScalarMode, theScalarMode)); } +//---------------------------------------------------------------------------- +CORBA::Double +VISU::ColoredPrs3d_i +::GetMin() +{ + return myColoredPL->GetScalarRange()[0]; +} //---------------------------------------------------------------------------- -CORBA::Long +CORBA::Double VISU::ColoredPrs3d_i -::GetScalarMode() +::GetMax() { - return myScalarMapPL->GetScalarMode(); + return myColoredPL->GetScalarRange()[1]; } +//---------------------------------------------------------------------------- void VISU::ColoredPrs3d_i -::SetScalarMode(CORBA::Long theScalarMode) +::SetRange(CORBA::Double theMin, CORBA::Double theMax) +{ + VISU::TSetModified aModified(this); + + vtkFloatingPointType aScalarRange[2] = {theMin, theMax}; + ProcessVoidEvent(new TVoidMemFun1ArgEvent + (GetSpecificPL(), &VISU_ColoredPL::SetScalarRange, aScalarRange)); + + UseFixedRange(true); +} + + +//---------------------------------------------------------------------------- +void +VISU::ColoredPrs3d_i +::SetSourceRange() +{ + VISU::TSetModified aModified(this); + + if(IsTimeStampFixed()){ + GetSpecificPL()->SetSourceRange(); + ProcessVoidEvent(new TVoidMemFunEvent + (GetSpecificPL(), &VISU_ColoredPL::SetSourceRange)); + }else{ + vtkFloatingPointType aScalarRange[2] = {GetSourceMin(), GetSourceMax()}; + ProcessVoidEvent(new TVoidMemFun1ArgEvent + (GetSpecificPL(), &VISU_ColoredPL::SetScalarRange, aScalarRange)); + } + UseFixedRange(false); +} + +//---------------------------------------------------------------------------- +CORBA::Double +VISU::ColoredPrs3d_i +::GetSourceMin() +{ + if(IsTimeStampFixed()){ + vtkFloatingPointType aRange[2]; + GetSpecificPL()->GetSourceRange(aRange); + return aRange[0]; + } + return GetComponentMin(GetScalarMode()); +} + +//---------------------------------------------------------------------------- +CORBA::Double +VISU::ColoredPrs3d_i +::GetSourceMax() +{ + if(IsTimeStampFixed()){ + vtkFloatingPointType aRange[2]; + GetSpecificPL()->GetSourceRange(aRange); + return aRange[1]; + } + return GetComponentMax(GetScalarMode()); +} + + +//---------------------------------------------------------------------------- +struct TGetComponentMin: public SALOME_Event +{ + VISU::ColoredPrs3d_i* myColoredPrs3d; + vtkIdType myCompID; + + typedef CORBA::Double TResult; + TResult myResult; + + TGetComponentMin( VISU::ColoredPrs3d_i* theColoredPrs3d, + vtkIdType theCompID ): + myColoredPrs3d( theColoredPrs3d ), + myCompID( theCompID ) + {} + + virtual + void + Execute() + { + VISU::PMinMaxController aMinMaxController = myColoredPrs3d->GetMinMaxController(); + if ( aMinMaxController ) { + myResult = aMinMaxController->GetComponentMin( myCompID ); + } else { + VISU::TMinMax aTMinMax = myColoredPrs3d->GetScalarField()->GetMinMax( myCompID ); + myResult = aTMinMax.first; + } + } +}; + + +//---------------------------------------------------------------------------- +vtkFloatingPointType +VISU::ColoredPrs3d_i +::GetComponentMin(vtkIdType theCompID) { - myScalarMapPL->SetScalarMode(theScalarMode); + return ProcessEvent( new TGetComponentMin( this, theCompID ) ); } -CORBA::Double -VISU::ColoredPrs3d_i -::GetMin() +//---------------------------------------------------------------------------- +struct TGetComponentMax: public SALOME_Event { - return myScalarMapPL->GetScalarRange()[0]; -} + VISU::ColoredPrs3d_i* myColoredPrs3d; + vtkIdType myCompID; -CORBA::Double + typedef CORBA::Double TResult; + TResult myResult; + + TGetComponentMax( VISU::ColoredPrs3d_i* theColoredPrs3d, + vtkIdType theCompID ): + myColoredPrs3d( theColoredPrs3d ), + myCompID( theCompID ) + {} + + virtual + void + Execute() + { + VISU::PMinMaxController aMinMaxController = myColoredPrs3d->GetMinMaxController(); + if ( aMinMaxController ) { + myResult = aMinMaxController->GetComponentMax( myCompID ); + } else { + VISU::TMinMax aTMinMax = myColoredPrs3d->GetScalarField()->GetMinMax( myCompID ); + myResult = aTMinMax.second; + } + } +}; + + +//---------------------------------------------------------------------------- +vtkFloatingPointType VISU::ColoredPrs3d_i -::GetMax() +::GetComponentMax(vtkIdType theCompID) { - return myScalarMapPL->GetScalarRange()[1]; + return ProcessEvent( new TGetComponentMax( this, theCompID ) ); } +//---------------------------------------------------------------------------- void VISU::ColoredPrs3d_i ::SetNbColors(CORBA::Long theNbColors) { - myScalarMapPL->SetNbColors(theNbColors); + VISU::TSetModified aModified(this); + + ProcessVoidEvent(new TVoidMemFun1ArgEvent + (GetSpecificPL(), &VISU_ColoredPL::SetNbColors, theNbColors)); } +//---------------------------------------------------------------------------- CORBA::Long VISU::ColoredPrs3d_i ::GetNbColors() { - return myScalarMapPL->GetNbColors(); + return GetSpecificPL()->GetNbColors(); } +//---------------------------------------------------------------------------- void VISU::ColoredPrs3d_i -::SetBarOrientation(VISU::ScalarMap::Orientation theOrientation) +::SetBarOrientation(VISU::ColoredPrs3d::Orientation theOrientation) { + if(myOrientation == theOrientation) + return; + + VISU::TSetModified aModified(this); + myOrientation = theOrientation; + myParamsTime.Modified(); } -VISU::ScalarMap::Orientation +//---------------------------------------------------------------------------- +VISU::ColoredPrs3d::Orientation VISU::ColoredPrs3d_i ::GetBarOrientation() { return myOrientation; } +//---------------------------------------------------------------------------- void VISU::ColoredPrs3d_i -::SetPosition(CORBA::Double X, CORBA::Double Y) +::SetPosition(CORBA::Double theX, CORBA::Double theY) { - myPosition[0] = X; - myPosition[1] = Y; + bool anIsSameValue = VISU::CheckIsSameValue(myPosition[0], theX); + anIsSameValue &= VISU::CheckIsSameValue(myPosition[1], theY); + if(anIsSameValue) + return; + + VISU::TSetModified aModified(this); + + myPosition[0] = theX; + myPosition[1] = theY; + myParamsTime.Modified(); } +//---------------------------------------------------------------------------- CORBA::Double VISU::ColoredPrs3d_i ::GetPosX() @@ -226,6 +973,7 @@ VISU::ColoredPrs3d_i return myPosition[0]; } +//---------------------------------------------------------------------------- CORBA::Double VISU::ColoredPrs3d_i ::GetPosY() @@ -233,14 +981,24 @@ VISU::ColoredPrs3d_i return myPosition[1]; } +//---------------------------------------------------------------------------- void VISU::ColoredPrs3d_i ::SetSize(CORBA::Double theWidth, CORBA::Double theHeight) { + bool anIsSameValue = VISU::CheckIsSameValue(myWidth, theWidth); + anIsSameValue &= VISU::CheckIsSameValue(myHeight, theHeight); + if(anIsSameValue) + return; + + VISU::TSetModified aModified(this); + myWidth = theWidth; myHeight = theHeight; + myParamsTime.Modified(); } +//---------------------------------------------------------------------------- CORBA::Double VISU::ColoredPrs3d_i ::GetWidth() @@ -248,6 +1006,7 @@ VISU::ColoredPrs3d_i return myWidth; } +//---------------------------------------------------------------------------- CORBA::Double VISU::ColoredPrs3d_i ::GetHeight() @@ -255,13 +1014,96 @@ VISU::ColoredPrs3d_i return myHeight; } +//---------------------------------------------------------------------------- +void +VISU::ColoredPrs3d_i +::SetRatios(CORBA::Long theTitleWidth, CORBA::Long theTitleHeight, + CORBA::Long theLabelWidth, CORBA::Long theLabelHeight, + 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); + anIsSameValue &= VISU::CheckIsSameValue(myBarWidth, theBarWidth); + anIsSameValue &= VISU::CheckIsSameValue(myBarHeight, theBarHeight); + if(anIsSameValue) + return; + + VISU::TSetModified aModified(this); + + myTitleWidth = theTitleWidth; + myTitleHeight = theTitleHeight; + myLabelWidth = theLabelWidth; + myLabelHeight = theLabelHeight; + myBarWidth = theBarWidth; + myBarHeight = theBarHeight; + myParamsTime.Modified(); +} + +//---------------------------------------------------------------------------- +CORBA::Long +VISU::ColoredPrs3d_i +::GetTitleWidth() +{ + return myTitleWidth; +} + +//---------------------------------------------------------------------------- +CORBA::Long +VISU::ColoredPrs3d_i +::GetTitleHeight() +{ + return myTitleHeight; +} + +//---------------------------------------------------------------------------- +CORBA::Long +VISU::ColoredPrs3d_i +::GetLabelWidth() +{ + return myLabelWidth; +} + +//---------------------------------------------------------------------------- +CORBA::Long +VISU::ColoredPrs3d_i +::GetLabelHeight() +{ + return myLabelHeight; +} + +//---------------------------------------------------------------------------- +CORBA::Long +VISU::ColoredPrs3d_i +::GetBarWidth() +{ + return myBarWidth; +} + +//---------------------------------------------------------------------------- +CORBA::Long +VISU::ColoredPrs3d_i +::GetBarHeight() +{ + return myBarHeight; +} + +//---------------------------------------------------------------------------- void VISU::ColoredPrs3d_i ::SetLabels(CORBA::Long theNbLabels) { + if(myNumberOfLabels == theNbLabels) + return; + + VISU::TSetModified aModified(this); + myNumberOfLabels = theNbLabels; + myParamsTime.Modified(); } +//---------------------------------------------------------------------------- CORBA::Long VISU::ColoredPrs3d_i ::GetLabels() @@ -269,13 +1111,62 @@ VISU::ColoredPrs3d_i return myNumberOfLabels; } +//---------------------------------------------------------------------------- +void +VISU::ColoredPrs3d_i +::SetLabelsFormat(const char* theFormat) +{ + if( myLabelsFormat != theFormat ){ + VISU::TSetModified aModified(this); + myLabelsFormat = theFormat; + myParamsTime.Modified(); + } +} + + +//---------------------------------------------------------------------------- +char* +VISU::ColoredPrs3d_i +::GetLabelsFormat() +{ + return CORBA::string_dup(myLabelsFormat.c_str()); +} + +//---------------------------------------------------------------------------- void VISU::ColoredPrs3d_i -::SetTitle(const char* theName) +::SetTitle(const char* theTitle) { - myTitle = theName; + VISU::PValForTime aValForTime; + VISU::TValField& aValField = GetScalarField()->myValField; + VISU::TValField::iterator anIter = aValField.find(GetScalarTimeStampNumber()); + if (anIter != aValField.end()) + aValForTime = anIter->second; + + if (aValForTime) { + std::strstream aStream; + const VISU::TTime& aTime = aValForTime->myTime; + aStream<integerValue("VISU", "scalar_bar_mode", 0); SetScalarMode(aScalarMode); + // Scalar Range + int aRangeType = aResourceMgr->integerValue("VISU" , "scalar_range_type", 0); + if(aRangeType == 1){ + float aMin = aResourceMgr->doubleValue("VISU", "scalar_range_min", 0); + float aMax = aResourceMgr->doubleValue("VISU", "scalar_range_max", 0); + SetRange(aMin, aMax); + } + UseFixedRange(aRangeType == 1); + int aNumberOfColors = aResourceMgr->integerValue( "VISU", "scalar_bar_num_colors", 64 ); SetNbColors(aNumberOfColors); + bool isUnits = aResourceMgr->booleanValue( "VISU", "scalar_bar_display_units", true ); + SetUnitsVisible(isUnits); + + QString aLabelsFormat = aResourceMgr->stringValue( "VISU", "scalar_bar_label_format", "%-#6.3g" ); + const char *lf=aLabelsFormat.latin1(); + SetLabelsFormat(lf); + // Orientation int anOrientation = aResourceMgr->integerValue("VISU", "scalar_bar_orientation", 0); if(anOrientation == 1) - myOrientation = VISU::ScalarMap::HORIZONTAL; + SetBarOrientation(VISU::ColoredPrs3d::HORIZONTAL); else - myOrientation = VISU::ScalarMap::VERTICAL; + SetBarOrientation(VISU::ColoredPrs3d::VERTICAL); // Scalar Bar origin QString propertyName = QString( "scalar_bar_%1_" ).arg( anOrientation == 0 ? "vertical" : "horizontal" ); - float aXorigin = (myOrientation == VISU::ScalarMap::VERTICAL) ? 0.01 : 0.2; + vtkFloatingPointType aXorigin = (myOrientation == VISU::ColoredPrs3d::VERTICAL) ? 0.01 : 0.2; aXorigin = aResourceMgr->doubleValue("VISU", propertyName + "x", aXorigin); myPosition[0] = aXorigin; - float aYorigin = (myOrientation == VISU::ScalarMap::VERTICAL) ? 0.1 : 0.012; + vtkFloatingPointType aYorigin = (myOrientation == VISU::ColoredPrs3d::VERTICAL) ? 0.1 : 0.012; aYorigin = aResourceMgr->doubleValue("VISU", propertyName + "y", aYorigin); myPosition[1] = aYorigin; // Scalar Bar size - myWidth = (myOrientation == VISU::ScalarMap::VERTICAL)? 0.1 : 0.6; + myWidth = (myOrientation == VISU::ColoredPrs3d::VERTICAL)? 0.1 : 0.6; myWidth = aResourceMgr->doubleValue("VISU", propertyName + "width", myWidth); - myHeight = (myOrientation == VISU::ScalarMap::VERTICAL)? 0.8:0.12; + myHeight = (myOrientation == VISU::ColoredPrs3d::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); + + myLabelHeight = 0; + myLabelHeight = aResourceMgr->integerValue("VISU", propertyName + "label_height", myLabelHeight); + + myBarWidth = 0; + myBarWidth = aResourceMgr->integerValue("VISU", propertyName + "bar_width", myBarWidth); + + myBarHeight = 0; + myBarHeight = aResourceMgr->integerValue("VISU", propertyName + "bar_height", myBarHeight); + // scalar bar default position bool anIsArrangeBar = aResourceMgr->booleanValue("VISU", "scalar_bars_default_position", 0); int aPlace = 1; if (anIsArrangeBar){ aPlace = aResourceMgr->integerValue("VISU", "scalar_bar_position_num",0); } - if(myOrientation == VISU::ScalarMap::HORIZONTAL){ + if(myOrientation == VISU::ColoredPrs3d::HORIZONTAL){ myPosition[1] += myHeight*(aPlace-1); } else { myPosition[0] += myWidth*(aPlace-1); @@ -550,33 +1624,72 @@ VISU::ColoredPrs3d_i return this; } -VISU::Storable* + +//---------------------------------------------------------------------------- +void +VISU::ColoredPrs3d_i +::SaveRestoringState(SALOMEDS::SObject_ptr theSObject, + const Storable::TRestoringMap& theMap) +{ + myRestoringSObject = SALOMEDS::SObject::_duplicate(theSObject); + myRestoringMap = theMap; + myIsRestored = false; +} + + +//---------------------------------------------------------------------------- +void VISU::ColoredPrs3d_i -::Restore(const Storable::TRestoringMap& theMap) +::InitFromRestoringState() { - DoHook(); + if(!myIsRestored){ + Restore(myRestoringSObject, myRestoringMap); + myIsRestored = true; + } +} - myMeshName = VISU::Storable::FindValue(theMap,"myMeshName").latin1(); - myEntity = (VISU::TEntity)VISU::Storable::FindValue(theMap,"myEntity").toInt(); - myFieldName = VISU::Storable::FindValue(theMap,"myFieldName").latin1(); - myIteration = VISU::Storable::FindValue(theMap,"myIteration").toInt(); - myAddToStudy = false; //SRN Added 21/06/2003 SAL2983: to avoid addition of the new ScalarMap to study. +//---------------------------------------------------------------------------- +VISU::Storable* +VISU::ColoredPrs3d_i +::Restore(SALOMEDS::SObject_ptr theSObject, + const Storable::TRestoringMap& theMap) +{ + if(!TSuperClass::Restore(theSObject, theMap)) + return NULL; - Build(true); + SetEntity((VISU::Entity)VISU::Storable::FindValue(theMap,"myEntity").toInt()); + SetFieldName(VISU::Storable::FindValue(theMap,"myFieldName").latin1()); + SetTimeStampNumber(VISU::Storable::FindValue(theMap,"myIteration").toInt()); + myIsTimeStampFixed = VISU::Storable::FindValue(theMap,"myIsTimeStampFixed", "1").toInt(); + OnSetInput(false); - TSuperClass::Restore(theMap); + Build(ERestore); SetScalarMode(VISU::Storable::FindValue(theMap,"myScalarMode").toInt()); + float aMin = VISU::Storable::FindValue(theMap,"myScalarRange[0]").toDouble(); + float aMax = VISU::Storable::FindValue(theMap,"myScalarRange[1]").toDouble(); + SetRange(aMin, aMax); + + UseFixedRange(VISU::Storable::FindValue(theMap,"myIsFixedRange", "0").toInt()); + SetNbColors(VISU::Storable::FindValue(theMap,"myNumberOfColors").toInt()); - SetBarOrientation((VISU::ScalarMap::Orientation)VISU::Storable::FindValue(theMap,"myOrientation").toInt()); + SetUnitsVisible(VISU::Storable::FindValue(theMap,"myUnitsVisible", "1").toInt()); + SetLabelsFormat(VISU::Storable::FindValue(theMap,"myLabelsFormat", "%-#6.3g")); + SetBarOrientation((VISU::ColoredPrs3d::Orientation)VISU::Storable::FindValue(theMap,"myOrientation").toInt()); - myTitle = VISU::Storable::FindValue(theMap,"myTitle").latin1(); + SetTitle(VISU::Storable::FindValue(theMap,"myTitle").latin1()); myNumberOfLabels = VISU::Storable::FindValue(theMap,"myNumberOfLabels").toInt(); myPosition[0] = VISU::Storable::FindValue(theMap,"myPosition[0]").toDouble(); 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(); + myBarWidth = VISU::Storable::FindValue(theMap,"myBarWidth").toInt(); + myBarHeight = VISU::Storable::FindValue(theMap,"myBarHeight").toInt(); myTitFontType = VISU::Storable::FindValue(theMap,"myTitFontType").toInt(); myIsBoldTitle = VISU::Storable::FindValue(theMap,"myIsBoldTitle").toInt(); @@ -594,30 +1707,56 @@ VISU::ColoredPrs3d_i myLabelColor[1] = VISU::Storable::FindValue(theMap,"myLabelColor[1]").toFloat(); myLabelColor[2] = VISU::Storable::FindValue(theMap,"myLabelColor[2]").toFloat(); + bool anIsExists; + QString aGeomNames = VISU::Storable::FindValue(theMap, "myGeomNameList", &anIsExists); + if(anIsExists){ + QStringList aGeomNameList = QStringList::split("|", aGeomNames); + int aNbOfGroups = aGeomNameList.count(); + if(aNbOfGroups > 0){ + RemoveAllGeom(); + for(int aGroupNum = 0; aGroupNum < aNbOfGroups; aGroupNum++){ + QString aGroupName = aGeomNameList[aGroupNum]; + AddMeshOnGroup(aGroupName.latin1()); + } + } + } return this; } +//---------------------------------------------------------------------------- void VISU::ColoredPrs3d_i ::ToStream(std::ostringstream& theStr) { TSuperClass::ToStream(theStr); + Storable::DataToStream( theStr, "myEntity", GetEntity() ); + Storable::DataToStream( theStr, "myFieldName", GetCFieldName() ); + Storable::DataToStream( theStr, "myIteration", int(GetTimeStampNumber()) ); + Storable::DataToStream( theStr, "myIsTimeStampFixed", int(myIsTimeStampFixed) ); + Storable::DataToStream( theStr, "myScalarMode", int(GetScalarMode()) ); + Storable::DataToStream( theStr, "myScalarRange[0]", GetMin() ); + Storable::DataToStream( theStr, "myScalarRange[1]", GetMax() ); + Storable::DataToStream( theStr, "myIsFixedRange", IsRangeFixed() ); + Storable::DataToStream( theStr, "myNumberOfColors", int(GetNbColors()) ); Storable::DataToStream( theStr, "myOrientation", myOrientation ); - Storable::DataToStream( theStr, "myMeshName", myMeshName.c_str() ); - Storable::DataToStream( theStr, "myEntity", myEntity ); - Storable::DataToStream( theStr, "myFieldName", myFieldName.c_str() ); - Storable::DataToStream( theStr, "myIteration", myIteration ); - 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, "myBarWidth", myBarWidth ); + Storable::DataToStream( theStr, "myBarHeight", myBarHeight ); Storable::DataToStream( theStr, "myTitFontType", myTitFontType ); Storable::DataToStream( theStr, "myIsBoldTitle", myIsBoldTitle ); @@ -634,59 +1773,113 @@ VISU::ColoredPrs3d_i Storable::DataToStream( theStr, "myLabelColor[0]", myLabelColor[0] ); Storable::DataToStream( theStr, "myLabelColor[1]", myLabelColor[1] ); Storable::DataToStream( theStr, "myLabelColor[2]", myLabelColor[2] ); + + std::ostringstream aGeomNameList; + std::string aMeshName = GetCMeshName(); + const TGroupNames& aGroupNames = GetGroupNames(); + TGroupNames::const_iterator anIter = aGroupNames.begin(); + for(; anIter != aGroupNames.end(); anIter++){ + const std::string& aGroupName = *anIter; + aGeomNameList<GetMapper()->SetScalarVisibility(1); - } - myScalarMapPL = dynamic_cast(myPipeLine); + if(MYDEBUG) MESSAGE("ColoredPrs3d_i::CreatePipeLine() - "<(thePipeLine); + + SetPipeLine(myColoredPL); } //---------------------------------------------------------------------------- + + VISU::Storable* VISU::ColoredPrs3d_i -::Build(int theRestoring) +::Build(EBuildMode theBuildMode) { if(MYDEBUG) - MESSAGE("ColoredPrs3d_i::Build - "<Init(); - if(!myIsFixedRange) myScalarMapPL->SetSourceRange(); - const VISU::TValField& aValField = myField->myValField; - const VISU::PValForTime aValForTime = aValField.find(myIteration)->second; - aComment.sprintf("%s %s",myFieldName.c_str(),VISU_Convertor::GenerateName(aValForTime->myTime).c_str()); - if (theRestoring == 0) myTitle = aComment.simplifyWhiteSpace().latin1(); + SetName("NoName", false); + if(theBuildMode == ECreateNew || theBuildMode == ESameAs){ + if(!IsRangeFixed()) + SetSourceRange(); + if(theBuildMode == ECreateNew) + SetTitle(GetCFieldName().c_str()); } - if(myAddToStudy){ - myName = GenerateName().latin1(); - aComment.sprintf("myComment=TIMESTAMP;myType=%d;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d", - VISU::TTIMESTAMP,myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp); - string aResultEntry = myResult->GetEntry(); - string aRefFatherEntry = myResult->GetRefFatherEntry(); - string anEntry = myResult->GetEntry(aComment.latin1()); - if(anEntry == "") throw std::runtime_error("There is no Entry for binding the presentation !!!"); + if(myPublishInStudyMode == EPublishUnderTimeStamp){ + SetName(GenerateName().latin1(), false); + VISU::Storable::TRestoringMap aRestoringMap; + aRestoringMap["myComment"] = "TIMESTAMP"; + aRestoringMap["myMeshName"] = GetCMeshName(); + aRestoringMap["myEntityId"] = QString::number(GetEntity()); + aRestoringMap["myFieldName"] = GetCFieldName(); + aRestoringMap["myTimeStampId"] = QString::number(GetTimeStampNumber()); + aRestoringMap["myNumComponent"] = QString::number(GetScalarField()->myNbComp); + std::string anEntry = GetCResult()->GetEntry(aRestoringMap); + if(anEntry == "") + throw std::runtime_error("There is no Entry for binding the presentation !!!"); aComment.sprintf("myComment=%s;myMeshName=%s;myEntityId=%d;myFieldName=%s;myTimeStampId=%d;myNumComponent=%d", - GetComment(),myMeshName.c_str(),myEntity,myFieldName.c_str(),myIteration,myField->myNbComp); + GetComment(), + GetCMeshName().c_str(), + GetEntity(), + GetCFieldName().c_str(), + GetTimeStampNumber(), + GetScalarField()->myNbComp); CORBA::String_var anIOR = GetID(); - CreateAttributes(myStudy,anEntry.c_str(),aRefFatherEntry.c_str(),anIOR,myName.c_str(),"",aComment.latin1(),true); - mySObject = myStudy->FindObjectIOR(anIOR); + CreateAttributes(GetStudyDocument(), + anEntry, + GetIconName(), + anIOR.in(), + GetName(), + "", + aComment.latin1(), + true); + }else if(myPublishInStudyMode == EPublishIndependently){ + SetName(GenerateName().latin1(), false); + CORBA::String_var anIOR = GetID(); + std::string aFatherEntry = ::FindOrCreate3DPresentationsFolder(GetStudyDocument()); + aComment.sprintf("myComment=%s", + GetComment()); + CreateAttributes(GetStudyDocument(), + aFatherEntry, + GetIconName(), + anIOR.in(), + GetName(), + "", + aComment.latin1(), + true); } #ifndef _DEXCEPT_ }catch(std::exception& exc){ @@ -697,51 +1890,8 @@ VISU::ColoredPrs3d_i throw; } #endif - if(myAddToStudy) + + if(anIsPublishInStudy) aStudyBuilder->CommitCommand(); return this; } - - -//---------------------------------------------------------------------------- -const VISU::PField& -VISU::ColoredPrs3d_i -::GetField() const -{ - return myField; -} - -const std::string& -VISU::ColoredPrs3d_i -::GetMeshName() const -{ - return myMeshName; -} - -VISU::Entity -VISU::ColoredPrs3d_i -::GetEntity() const -{ - return VISU::Entity(myEntity); -} - -const std::string& -VISU::ColoredPrs3d_i -::GetFieldName() const -{ - return myFieldName; -} - -int -VISU::ColoredPrs3d_i -::GetIteration() const -{ - return myIteration; -} - -VISU_ScalarMapPL* -VISU::ColoredPrs3d_i -::GetScalarMapPL() -{ - return myScalarMapPL; -}