+
+//------------------------------------------------------------------------
+SALOMEDS::SObject_ptr VISU_TimeAnimation::publishInStudy()
+{
+ if (myStudy->GetProperties()->IsLocked()) {
+ SUIT_MessageBox::warning(0,
+ QObject::tr("WRN_VISU_WARNING"),
+ QObject::tr("WRN_STUDY_LOCKED"),
+ QObject::tr("BUT_OK"));
+ return SALOMEDS::SObject::_nil();
+ }
+
+ _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
+ aStudyBuilder->NewCommand(); // There is a transaction
+ _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
+ std::string aSComponentEntry = aSComponent->GetID();
+
+ QString aComment;
+ aComment.sprintf("myComment=ANIMATION;myTimeMinVal=%g;myTimeMaxVal=%g;mySequence=%s;myMode=%d",
+ myTimeMinVal,
+ myTimeMaxVal,
+ mySequence.toLatin1().data(),
+ myAnimationMode);
+
+ string anEntry = VISU::CreateAttributes(myStudy,
+ aSComponentEntry.c_str(),
+ VISU::NO_ICON,
+ VISU::NO_IOR,
+ GenerateName().toLatin1().data(),
+ VISU::NO_PERFSITENT_REF,
+ aComment.toLatin1().data(),
+ true);
+ myAnimEntry = anEntry.c_str();
+ _PTR(SObject) aAnimSObject = myStudy->FindObjectID(anEntry.c_str());
+
+ for (int i = 0; i < getNbFields(); i++) {
+ FieldData& aData = myFieldsLst[i];
+ if (aData.myPrs.empty()) {
+ generatePresentations(i);
+ }
+ if ( !aData.myPrs.empty() ) {
+ _PTR(SObject) newObj = aStudyBuilder->NewObject(aAnimSObject);
+ aStudyBuilder->Addreference(newObj, aData.myField);
+
+ ostringstream strOut;
+ aData.myPrs[0]->ToStream(strOut);
+ string aPrsComment = strOut.str();
+ string aPrsMyComment = aData.myPrs[0]->GetComment();
+ if(aPrsMyComment == "PRSMERGER")
+ aPrsMyComment = "SCALARMAP";
+ VISU::CreateAttributes(myStudy,
+ newObj->GetID().c_str(),
+ VISU::NO_ICON,
+ VISU::NO_IOR,
+ aPrsMyComment.c_str(),
+ VISU::NO_PERFSITENT_REF,
+ aPrsComment.c_str(),
+ true);
+ }
+ }
+ aStudyBuilder->CommitCommand();
+
+ return VISU::GetSObject(aAnimSObject)._retn();
+}
+
+//------------------------------------------------------------------------
+void VISU_TimeAnimation::saveAnimation()
+{
+ if (myStudy->GetProperties()->IsLocked()) return;
+ if (myAnimEntry.isEmpty()) return;
+
+ _PTR(SObject) aAnimSObject = myStudy->FindObjectID(myAnimEntry.toLatin1().data());
+ if (!aAnimSObject) return;
+
+ _PTR(StudyBuilder) aStudyBuilder = myStudy->NewBuilder();
+ aStudyBuilder->NewCommand(); // There is a transaction
+ _PTR(SComponent) aSComponent = VISU::ClientFindOrCreateVisuComponent(myStudy);
+ std::string aSComponentEntry = aSComponent->GetID();
+
+ QString aComment;
+ aComment.sprintf("myComment=ANIMATION;myTimeMinVal=%g;myTimeMaxVal=%g;mySequence=%s;myMode=%d",
+ myTimeMinVal,
+ myTimeMaxVal,
+ mySequence.toLatin1().data(),
+ myAnimationMode);
+
+ _PTR(GenericAttribute) anAttr;
+ anAttr = aStudyBuilder->FindOrCreateAttribute(aAnimSObject, "AttributeString");
+ _PTR(AttributeString) aCmnt (anAttr);
+ aCmnt->SetValue(aComment.toLatin1().data());
+
+ _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
+ int i = 0, nbf = getNbFields();
+ for (anIter->Init(); anIter->More(); anIter->Next(), i++) {
+ if (i >= nbf) break; // it must not be
+ FieldData& aData = myFieldsLst[i];
+
+ // Get presentation name and comment
+ if (aData.myPrs.empty()) {
+ generatePresentations(i);
+ }
+ ostringstream strOut;
+ aData.myPrs[0]->ToStream(strOut);
+ string aPrsComment = strOut.str();
+ string aPrsNameTxt = aData.myPrs[0]->GetComment();
+ if(aPrsNameTxt == "PRSMERGER")
+ aPrsNameTxt = "SCALARMAP";
+ // Save in study
+ _PTR(SObject) aRefObj = anIter->Value();
+ _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
+ anPrsIter->Init();
+
+ if (anPrsIter->More()) {
+ _PTR(SObject) aPrsObj = anPrsIter->Value();
+ anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeString");
+ aCmnt = _PTR(AttributeString)(anAttr);
+ aCmnt->SetValue(aPrsComment.c_str());
+
+ anAttr = aStudyBuilder->FindOrCreateAttribute(aPrsObj, "AttributeName");
+ _PTR(AttributeName) aPrsName (anAttr);
+ aPrsName->SetValue(aPrsNameTxt);
+
+ } else {
+ VISU::CreateAttributes(myStudy,
+ aRefObj->GetID().c_str(),
+ VISU::NO_ICON,
+ VISU::NO_IOR,
+ aPrsNameTxt.c_str(),
+ VISU::NO_PERFSITENT_REF,
+ aPrsComment.c_str(),
+ true);
+ }
+ }
+ aStudyBuilder->CommitCommand();
+}
+
+//------------------------------------------------------------------------
+void VISU_TimeAnimation::restoreFromStudy(SALOMEDS::SObject_ptr theField)
+{
+ _PTR(SObject) aAnimSObject = VISU::GetClientSObject(theField, myStudy);
+ restoreFromStudy(aAnimSObject);
+}
+
+void VISU_TimeAnimation::restoreFromStudy(_PTR(SObject) theField)
+{
+ _PTR(SObject) aAnimSObject = theField;
+
+ VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(aAnimSObject);
+ if (aMap.empty())
+ return;
+
+ bool isExist;
+ myTimeMinVal = VISU::Storable::FindValue(aMap,"myTimeMinVal",&isExist).toDouble();
+ myTimeMaxVal = VISU::Storable::FindValue(aMap,"myTimeMaxVal",&isExist).toDouble();
+ mySequence = VISU::Storable::FindValue(aMap,"mySequence",&isExist);
+ myAnimationMode = VISU::Animation::AnimationMode(VISU::Storable::FindValue(aMap,"myMode",&isExist).toInt());
+
+ _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aAnimSObject);
+ for (anIter->Init(); anIter->More(); anIter->Next()) {
+ _PTR(SObject) aRefObj = anIter->Value();
+ _PTR(SObject) aFieldObj;
+
+ if (!aRefObj->ReferencedObject(aFieldObj) )
+ continue;
+
+ int nbAttr = aFieldObj->GetAllAttributes().size();
+ //std::string name1 = aFieldObj->GetName();
+ if(nbAttr<1)
+ continue;
+
+ addField(aFieldObj);
+ if ( isRangeDefined() || isSequenceDefined() )
+ myFieldsAbsFrames.pop_back();
+
+ FieldData& aData = getFieldData(getNbFields()-1);
+
+ // Get Presentation object
+ _PTR(ChildIterator) anPrsIter = myStudy->NewChildIterator(aRefObj);
+ anPrsIter->Init();
+ if (!anPrsIter->More())
+ continue;
+ _PTR(SObject) aPrsObj = anPrsIter->Value();
+ _PTR(GenericAttribute) anAttr;
+ if (!aPrsObj->FindAttribute(anAttr, "AttributeName"))
+ continue;
+ _PTR(AttributeName) aName (anAttr);
+ string aStr = aName->Value();
+ QString strName (aStr.c_str());
+
+ if (strName == VISU::ScalarMap_i::myComment.c_str())
+ aData.myPrsType = VISU::TSCALARMAP;
+ else if (strName == VISU::IsoSurfaces_i::myComment.c_str())
+ aData.myPrsType = VISU::TISOSURFACES;
+ else if (strName == VISU::CutPlanes_i::myComment.c_str())
+ aData.myPrsType = VISU::TCUTPLANES;
+ else if (strName == VISU::CutLines_i::myComment.c_str())
+ aData.myPrsType = VISU::TCUTLINES;
+ else if (strName == VISU::CutSegment_i::myComment.c_str())
+ aData.myPrsType = VISU::TCUTSEGMENT;
+ else if (strName == VISU::Plot3D_i::myComment.c_str())
+ aData.myPrsType = VISU::TPLOT3D;
+ else if (strName == VISU::DeformedShape_i::myComment.c_str())
+ aData.myPrsType = VISU::TDEFORMEDSHAPE;
+ else if (strName == VISU::Vectors_i::myComment.c_str())
+ aData.myPrsType = VISU::TVECTORS;
+ else if (strName == VISU::StreamLines_i::myComment.c_str())
+ aData.myPrsType = VISU::TSTREAMLINES;
+ else if (strName == VISU::GaussPoints_i::myComment.c_str())
+ aData.myPrsType = VISU::TGAUSSPOINTS;
+ else if (strName == VISU::DeformedShapeAndScalarMap_i::myComment.c_str())
+ aData.myPrsType = VISU::TDEFORMEDSHAPEANDSCALARMAP;
+ else
+ continue;
+ generatePresentations(getNbFields()-1);
+
+ VISU::Storable::TRestoringMap aPrsMap = VISU::Storable::GetStorableMap(aPrsObj);
+ if (aPrsMap.empty())
+ continue;
+ if (aData.myPrs[0]) {
+ aData.myPrs[0]->Restore(VISU::GetSObject(aData.myField), aPrsMap);
+ aData.myPrs[0]->GetOffset(aData.myOffset);
+ }
+ for (int i = 1; i < aData.myNbFrames; i++) {
+ if (!aData.myPrs[0])
+ continue;
+ bool anIsFixedRange = false;
+ if (aData.myPrsType != VISU::TGAUSSPOINTS) {
+ if (VISU::ScalarMap_i* aPrs = dynamic_cast<VISU::ScalarMap_i*>(aData.myPrs[i]))
+ anIsFixedRange = aPrs->IsRangeFixed();
+ }
+ if (aData.myPrsType == VISU::TDEFORMEDSHAPEANDSCALARMAP) {
+ if (VISU::DeformedShapeAndScalarMap_i* aDeformedPrs =
+ dynamic_cast<VISU::DeformedShapeAndScalarMap_i*>(aData.myPrs[i])) {
+ //Set correct time stamp number
+ int aTimeStampNum = aDeformedPrs->GetScalarTimeStampNumber();
+ aDeformedPrs->SameAs(aData.myPrs[0]);
+ aDeformedPrs->SetScalarField(aDeformedPrs->GetScalarEntity(),
+ aDeformedPrs->GetScalarFieldName(),
+ aTimeStampNum);
+ }
+ }
+ else
+ aData.myPrs[i]->SameAs(aData.myPrs[0]);
+ }
+ }
+ string aStr = aAnimSObject->GetID();
+ myAnimEntry = aStr.c_str();
+}
+
+void VISU_TimeAnimation::onViewDeleted()
+{
+ myView = 0;
+ stopAnimation();
+}
+
+void VISU_TimeAnimation::ApplyProperties(CORBA::Long theFieldNum, VISU::ColoredPrs3d_ptr thePrs)
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ VISU::ColoredPrs3d_i* aPrs_i = dynamic_cast<VISU::ColoredPrs3d_i*>(GetServant(thePrs).in());
+
+ if ( !aPrs_i )
+ THROW_SALOME_CORBA_EXCEPTION("Error : invalid dynamic cast of the given presentation to VISU::ColoredPrs3d_i",
+ SALOME::INTERNAL_ERROR);