#include "VISU_IsoSurfaces_i.hh"
#include "VISU_DeformedShape_i.hh"
#include "VISU_CutPlanes_i.hh"
+#include "VISU_Plot3D_i.hh"
#include "VISU_CutLines_i.hh"
#include "VISU_Vectors_i.hh"
#include "VISU_StreamLines_i.hh"
if (!CORBA::is_nil(theView3D)) {
VISU::View3D_i* pView = dynamic_cast<VISU::View3D_i*>(GetServant(theView3D).in());
- //QAD_StudyFrame* aStudyFrame = pView->GetStudyFrame();
- //myView = VISU::GetViewFrame(aStudyFrame);
- SUIT_ViewWindow* aVW = pView->myViewWindow;
+ SUIT_ViewWindow* aVW = pView->GetViewWindow();
myView = VISU::GetViewWindow(aVW);
}
myTimeMax = 0;
myLastError = "";
myCycling = false;
+
+ myAnimEntry = "";
}
//************************************************************************
-//void VISU_TimeAnimation::addField (SALOMEDS::SObject_ptr theField)
void VISU_TimeAnimation::addField (_PTR(SObject) theField)
{
FieldData aNewData;
- //aNewData.myField = SALOMEDS::SObject::_duplicate(theField);
aNewData.myField = theField;
aNewData.myNbFrames = 0;
aNewData.myPrsType = VISU::TSCALARMAP;
+ aNewData.myOffset[0] = aNewData.myOffset[1] = aNewData.myOffset[2] = 0;
VISU::Storable::TRestoringMap aMap = getMapOfValue(aNewData.myField);
aNewData.myNbTimes = VISU::Storable::FindValue(aMap,"myNbTimeStamps").toLong();
myFieldsLst.append(aNewData);
//************************************************************************
void VISU_TimeAnimation::addField (SALOMEDS::SObject_ptr theField)
{
- FieldData aNewData;
- //aNewData.myField = SALOMEDS::SObject::_duplicate(theField);
- _PTR(SObject) aField = VISU::GetClientSObject(theField, myStudy);
- aNewData.myField = aField;
- aNewData.myNbFrames = 0;
- aNewData.myPrsType = VISU::TSCALARMAP;
- VISU::Storable::TRestoringMap aMap = getMapOfValue(aNewData.myField);
- aNewData.myNbTimes = VISU::Storable::FindValue(aMap,"myNbTimeStamps").toLong();
- myFieldsLst.append(aNewData);
-
- //find Min/Max timestamps
- if ((myTimeMin == 0) && (myTimeMax == 0)) {
- _PTR(ChildIterator) anIter = myStudy->NewChildIterator(aField);
- anIter->Next(); // First is reference on support
- myTimeMin = getTimeValue(anIter->Value());
- for(; anIter->More(); anIter->Next()) {
- myTimeMax = getTimeValue(anIter->Value());
- }
- }
+ SALOMEDS::SObject_var theFieldDup = SALOMEDS::SObject::_duplicate(theField);
+ _PTR(SObject) aField = VISU::GetClientSObject(theFieldDup, myStudy);
+ addField(aField);
}
}
break;
+ case VISU::TPLOT3D: // Plot3d
+ {
+ VISU::Plot3D_i* aPresent = new VISU::Plot3D_i (pResult, false);
+ aPresent->Create(aMeshName.latin1(), anEntity,
+ aFieldName.latin1(), aTimeStampId);
+ aData.myPrs[i] = aPresent;
+ }
+ break;
+
case VISU::TDEFORMEDSHAPE: // Deformed Shape
{
VISU::DeformedShape_i* aPresent = new VISU::DeformedShape_i(pResult, false);
aData.myPrs[i] = aPresent;
}
break;
+ default:
+ MESSAGE("Not implemented for this presentation type: " << aData.myPrsType);
+ return;
}
if (aData.myPrs[i]->GetMin() < aMin) aMin = aData.myPrs[i]->GetMin();
if (aData.myPrs[i]->GetMax() > aMax) aMax = aData.myPrs[i]->GetMax();
i++;
}
aData.myNbFrames = i;
- QString aFixRange = VISU::GetResourceMgr()->stringValue("Visu:SBImposeRange");
- if (aFixRange.compare("true") != 0) {
- for (i = 0; i < aData.myNbFrames; i++)
+
+ int rangeType = VISU::GetResourceMgr()->integerValue("VISU" , "scalar_range_type", 0);
+ if ( rangeType != 1 ) {
+ for (i = 0; i < aData.myNbFrames; i++) {
aData.myPrs[i]->SetRange(aMin, aMax);
- if(aData.myPrsType == VISU::TISOSURFACE)
+ aData.myPrs[i]->SetOffset(aData.myOffset);
+ }
+ if (aData.myPrsType == VISU::TISOSURFACE)
for (i = 0; i < aData.myNbFrames; i++)
- if(VISU::IsoSurfaces_i* aPrs = dynamic_cast<VISU::IsoSurfaces_i*>(aData.myPrs[i]))
+ if (VISU::IsoSurfaces_i* aPrs = dynamic_cast<VISU::IsoSurfaces_i*>(aData.myPrs[i]))
aPrs->SetSubRange(aMin, aMax);
}
}
//************************************************************************
CORBA::Boolean VISU_TimeAnimation::generateFrames() {
if (!myView) {
- MESSAGE("Viewer is nod defined for animation");
+ MESSAGE("Viewer is not defined for animation");
return false;
}
for (long j = 0; j < aData.myNbFrames; j++) {
VISU_Actor* aActor = NULL;
try{
+ aData.myPrs[j]->SetOffset(aData.myOffset);
aActor = aData.myPrs[j]->CreateActor();
myView->AddActor(aActor);
if(j == 0)
//************************************************************************
void VISU_TimeAnimation::clearView() {
if (!myView) {
- MESSAGE("Viewer is nod defined for animation");
+ MESSAGE("Viewer is not defined for animation");
return;
}
vtkRenderer* aRen = myView->getRenderer();
//************************************************************************
-void VISU_TimeAnimation::run() {
+void VISU_TimeAnimation::run()
+{
if (!myView) {
- MESSAGE("Viewer is nod defined for animation");
+ MESSAGE("Viewer is not defined for animation");
return;
}
- double k=1;
- double aOneVal;
- bool isDumping = !myDumpPath.isEmpty();
- aOneVal = (myFieldsLst[0].myNbFrames > 2) ?
- myFieldsLst[0].myTiming[1] - myFieldsLst[0].myTiming[0] : 1;
+ double k = 1;
+ bool isDumping = !myDumpPath.isEmpty();
+ double aOneVal = 1;
+ if (myFieldsLst[0].myNbFrames > 2)
+ aOneVal = myFieldsLst[0].myTiming[1] - myFieldsLst[0].myTiming[0];
qApp->lock();
while (myIsActive) {
emit frameChanged(myFrame, myFieldsLst[0].myTiming[myFrame]);
}
}
myView->Repaint(false);
+
if (isDumping) {
+ // We must unlock mutex for some time before grabbing to allow view updating
+ qApp->unlock();
+ msleep(100);
+ qApp->lock();
+
QPixmap px = QPixmap::grabWindow(myView->winId());
QString aFile(myDumpPath);
QString aName = QString("%1").arg(myFieldsLst[0].myTiming[myFrame]);
aFile += aName;
aFile += ".jpeg";
px.save(aFile, "JPEG");
- }
- if (!isDumping) {
+ } else {
+ k = 1;
if (myProportional) {
switch (myFrame) {
case 0:
- k=1;
break;
case 1:
if (myFieldsLst[0].myNbFrames > 2)
- k = (myFieldsLst[0].myTiming[myFrame+1] - myFieldsLst[0].myTiming[myFrame])/aOneVal;
- else
- k = 1;
+ k = (myFieldsLst[0].myTiming[myFrame+1] -
+ myFieldsLst[0].myTiming[myFrame]) / aOneVal;
break;
default:
- k = (myFrame < (myFieldsLst[0].myNbFrames-1))?
- (myFieldsLst[0].myTiming[myFrame+1] - myFieldsLst[0].myTiming[myFrame])/aOneVal : 1;
+ if (myFrame < (myFieldsLst[0].myNbFrames - 1))
+ k = (myFieldsLst[0].myTiming[myFrame+1] -
+ myFieldsLst[0].myTiming[myFrame]) / aOneVal;
}
- } else
- k = 1;
- qApp->unlock();
- msleep((int)(1000.*k/mySpeed));
- qApp->lock();
- } else {
+ }
+ int delay = (int)(1000. * k / mySpeed);
qApp->unlock();
- msleep(100);
+ msleep(delay);
qApp->lock();
}
+
if (!myIsActive) break;
myFrame++;
}
//************************************************************************
-//VISU::Result_i* VISU_TimeAnimation::createPresent (SALOMEDS::SObject_var theField)
VISU::Result_i* VISU_TimeAnimation::createPresent (_PTR(SObject) theField)
{
- //SALOMEDS::SObject_var aSObj = theField->GetFather();
_PTR(SObject) aSObj = theField->GetFather();
aSObj = aSObj->GetFather();
aSObj = aSObj->GetFather();
}
//************************************************************************
-//VISU::Storable::TRestoringMap VISU_TimeAnimation::getMapOfValue (SALOMEDS::SObject_var theSObject)
VISU::Storable::TRestoringMap VISU_TimeAnimation::getMapOfValue (_PTR(SObject) theSObject)
{
VISU::Storable::TRestoringMap aMap;
- //if (!theSObject->_is_nil()) {
if (theSObject) {
- //SALOMEDS::GenericAttribute_var anAttr;
_PTR(GenericAttribute) anAttr;
if (theSObject->FindAttribute(anAttr, "AttributeComment")) {
- //SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
_PTR(AttributeComment) aComment (anAttr);
- //CORBA::String_var aString = aComment->Value();
std::string aString = aComment->Value();
- //QString strIn (aString.in());
QString strIn (aString.c_str());
VISU::Storable::StrToMap(strIn, aMap);
}
}
//************************************************************************
-//double VISU_TimeAnimation::getTimeValue (SALOMEDS::SObject_var theTimeStamp)
double VISU_TimeAnimation::getTimeValue (_PTR(SObject) theTimeStamp)
{
- //SALOMEDS::GenericAttribute_var anAttr;
_PTR(GenericAttribute) anAttr;
if (theTimeStamp->FindAttribute(anAttr, "AttributeName")) {
- //SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
_PTR(AttributeName) aName (anAttr);
- //QString aNameString (aName->Value());
QString aNameString (aName->Value().c_str());
- return aNameString.toDouble();
+ int time_len = aNameString.find(',');
+ if (time_len > -1)
+ return aNameString.left(time_len).toDouble();
+ else
+ return aNameString.toDouble();
}
return -1.0;
}
mySpeed = (theSpeed<1)? 1 : theSpeed;
}
+//************************************************************************
+int VISU_TimeAnimation::myNBAnimations = 0;
+QString VISU_TimeAnimation::GenerateName()
+{
+ return VISU::GenerateName("Animation", myNBAnimations++);
+}
-//========================================================================
-VISU_TimeAnimation_i::VISU_TimeAnimation_i (SALOMEDS::Study_ptr theStudy,
- VISU::View3D_ptr theView3D)
+//************************************************************************
+std::string GetPresentationComment (VISU::VISUType thePrsType)
{
- //myAnim = new VISU_TimeAnimation (theStudy,theView3D);
+ std::string aPrsCmt;
+ switch (thePrsType) {
+ case VISU::TSCALARMAP:
+ aPrsCmt = VISU::ScalarMap_i::myComment;
+ break;
+ case VISU::TISOSURFACE:
+ aPrsCmt = VISU::IsoSurfaces_i::myComment;
+ break;
+ case VISU::TCUTPLANES:
+ aPrsCmt = VISU::CutPlanes_i::myComment;
+ break;
+ case VISU::TPLOT3D:
+ aPrsCmt = VISU::Plot3D_i::myComment;
+ break;
+ case VISU::TDEFORMEDSHAPE:
+ aPrsCmt = VISU::DeformedShape_i::myComment;
+ break;
+ case VISU::TVECTORS:
+ aPrsCmt = VISU::Vectors_i::myComment;
+ break;
+ case VISU::TSTREAMLINES:
+ aPrsCmt = VISU::StreamLines_i::myComment;
+ break;
+ default:
+ aPrsCmt = "Unknown presentation";
+ break;
+ }
+ return aPrsCmt;
+}
- std::string aStudyName = theStudy->Name();
- SUIT_Session* aSession = SUIT_Session::session();
- QPtrList<SUIT_Application> anApplications = aSession->applications();
- QPtrListIterator<SUIT_Application> anIter (anApplications);
- while (SUIT_Application* anApp = anIter.current()) {
- ++anIter;
- if (SUIT_Study* aSStudy = anApp->activeStudy()) {
- if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
- if (_PTR(Study) aCStudy = aStudy->studyDS()) {
- if (aStudyName == aCStudy->Name()) {
- myAnim = new VISU_TimeAnimation (aCStudy, theView3D);
- break;
+//************************************************************************
+SALOMEDS::SObject_ptr VISU_TimeAnimation::publishInStudy()
+{
+ if (myStudy->GetProperties()->IsLocked())
+ 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;myType=%d;myMinVal=%g;myMaxVal=%g",
+ VISU::TANIMATION,myMinVal,myMaxVal);
+
+ string anEntry = VISU::CreateAttributes(myStudy,aSComponentEntry.c_str(),"","",
+ GenerateName(),"",aComment,true);
+ myAnimEntry = anEntry.c_str();
+ _PTR(SObject) aAnimSObject = myStudy->FindObjectID(anEntry.c_str());
+
+ for (int i = 0; i < getNbFields(); i++) {
+ FieldData& aData = myFieldsLst[i];
+
+ _PTR(SObject) newObj = aStudyBuilder->NewObject(aAnimSObject);
+ aStudyBuilder->Addreference(newObj, aData.myField);
+
+ if (aData.myPrs.empty()) {
+ generatePresentations(i);
+ }
+ ostringstream strOut;
+ aData.myPrs[0]->ToStream(strOut);
+ string aPrsComment = strOut.str();
+ VISU::CreateAttributes(myStudy, newObj->GetID().c_str(),"","",
+ aData.myPrs[0]->GetComment(),"",aPrsComment.c_str(),true);
+ }
+ aStudyBuilder->CommitCommand();
+
+ return VISU::GetSObject(aAnimSObject);
+}
+
+//************************************************************************
+void VISU_TimeAnimation::saveAnimation()
+{
+ if (myStudy->GetProperties()->IsLocked()) return;
+ if (myAnimEntry.isEmpty()) return;
+
+ _PTR(SObject) aAnimSObject = myStudy->FindObjectID(myAnimEntry.latin1());
+ 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;myType=%d;myMinVal=%g;myMaxVal=%g",
+ VISU::TANIMATION,myMinVal,myMaxVal);
+
+ _PTR(GenericAttribute) anAttr;
+ anAttr = aStudyBuilder->FindOrCreateAttribute(aAnimSObject, "AttributeComment");
+ _PTR(AttributeComment) aCmnt (anAttr);
+ aCmnt->SetValue(aComment.latin1());
+
+ _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();
+
+ // 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, "AttributeComment");
+ aCmnt = _PTR(AttributeComment)(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(),"","",
+ aPrsNameTxt.c_str(),"",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;
+ _PTR(GenericAttribute) anAttr;
+ if (!aAnimSObject->FindAttribute(anAttr, "AttributeComment")) return;
+
+ _PTR(AttributeComment) aComment (anAttr);
+ string aComm = aComment->Value();
+ QString strIn (aComm.c_str());
+ VISU::Storable::StrToMap(strIn,aMap);
+ bool isExist;
+
+ myMinVal = VISU::Storable::FindValue(aMap,"myMinVal",&isExist).toDouble();
+ myMaxVal = VISU::Storable::FindValue(aMap,"myMaxVal",&isExist).toDouble();
+
+ _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;
+ addField(aFieldObj);
+ 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();
+ 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::TISOSURFACE;
+ else if (strName == VISU::CutPlanes_i::myComment.c_str())
+ aData.myPrsType = VISU::TCUTPLANES;
+ 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
+ continue;
+ generatePresentations(getNbFields()-1);
+
+ if (!aPrsObj->FindAttribute(anAttr, "AttributeComment")) continue;
+ _PTR(AttributeComment) aPrsComment (anAttr);
+ string aPrsComm = aPrsComment->Value();
+ if (aPrsComm.length() > 0) {
+ QString strPrsIn (aPrsComm.c_str());
+ VISU::Storable::TRestoringMap aPrsMap;
+ VISU::Storable::StrToMap(strPrsIn,aPrsMap);
+
+ aData.myPrs[0]->Restore(aPrsMap);
+ }
+ aData.myPrs[0]->GetOffset(aData.myOffset);
+ for (int i = 1; i < aData.myNbFrames; i++) {
+ //jfa 03.08.2005:aData.myPrs[i]->SameAs(aData.myPrs[0]);
+ aData.myPrs[i]->SameAsParams(aData.myPrs[0]);//jfa 03.08.2005
+ }
+ }
+ string aStr = aAnimSObject->GetID();
+ myAnimEntry = aStr.c_str();
+}
+
+
+//========================================================================
+//========================================================================
+//========================================================================
+struct TNewAnimationEvent: public SALOME_Event
+{
+ std::string myStudyName;
+ VISU::View3D_ptr myView3D;
+
+ typedef VISU_TimeAnimation* TResult;
+ TResult myResult;
+
+ TNewAnimationEvent (std::string theStudyName, VISU::View3D_ptr theView3D):
+ myStudyName(theStudyName),
+ myView3D(VISU::View3D::_duplicate(theView3D)),
+ myResult(NULL)
+ {}
+
+ virtual
+ void
+ Execute()
+ {
+ SUIT_Session* aSession = SUIT_Session::session();
+ QPtrList<SUIT_Application> anApplications = aSession->applications();
+ QPtrListIterator<SUIT_Application> anIter (anApplications);
+ while (SUIT_Application* anApp = anIter.current()) {
+ ++anIter;
+ if (SUIT_Study* aSStudy = anApp->activeStudy()) {
+ if (SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy)) {
+ if (_PTR(Study) aCStudy = aStudy->studyDS()) {
+ if (myStudyName == aCStudy->Name()) {
+ myResult = new VISU_TimeAnimation (aCStudy, myView3D);
+ break;
+ }
}
}
}
}
}
+};
+
+VISU_TimeAnimation_i::VISU_TimeAnimation_i (SALOMEDS::Study_ptr theStudy,
+ VISU::View3D_ptr theView3D)
+{
+ std::string aStudyName = theStudy->Name();
+ myAnim = ProcessEvent(new TNewAnimationEvent (aStudyName, theView3D));
}
VISU_TimeAnimation_i::~VISU_TimeAnimation_i()
{
myAnim->setCycling(theCycle);
}
+
+SALOMEDS::SObject_ptr VISU_TimeAnimation_i::publishInStudy()
+{
+ return myAnim->publishInStudy();
+}
+
+void VISU_TimeAnimation_i::restoreFromStudy(SALOMEDS::SObject_ptr theObj)
+{
+ myAnim->restoreFromStudy(theObj);
+}
+
+CORBA::Boolean VISU_TimeAnimation_i::isSavedInStudy()
+{
+ return myAnim->isSavedInStudy();
+}
+
+void VISU_TimeAnimation_i::saveAnimation()
+{
+ myAnim->saveAnimation();
+}