From 80bdb874d95e6913a07f1648c290d9ea928f2f93 Mon Sep 17 00:00:00 2001 From: dmv Date: Wed, 23 Jul 2008 10:07:43 +0000 Subject: [PATCH] Bug IPAL20132 Arrange Actors is not working for table presentations --- src/VISUGUI/VisuGUI_TimeAnimation.cxx | 108 ++++++++++++++++++++++++-- src/VISUGUI/VisuGUI_TimeAnimation.h | 2 + 2 files changed, 105 insertions(+), 5 deletions(-) diff --git a/src/VISUGUI/VisuGUI_TimeAnimation.cxx b/src/VISUGUI/VisuGUI_TimeAnimation.cxx index e4811c5f..2ea7c526 100644 --- a/src/VISUGUI/VisuGUI_TimeAnimation.cxx +++ b/src/VISUGUI/VisuGUI_TimeAnimation.cxx @@ -160,7 +160,7 @@ ArrangeDlg::ArrangeDlg(QWidget* theParent, vtkActorCollection *aCollection = myViewWindow->getRenderer()->GetActors(); aCollection->InitTraversal(); while(vtkActor* anActor = aCollection->GetNextActor()){ - if (VISU_Actor* anVISUActor = dynamic_cast(anActor)) + if (VISU_Actor* anVISUActor = dynamic_cast(anActor)) { if(anVISUActor->GetVisibility() != 0){ if (VISU::Prs3d_i* aPrs = anVISUActor->GetPrs3d()){ if(!myPrsMap.contains(aPrs)){ @@ -182,8 +182,33 @@ ArrangeDlg::ArrangeDlg(QWidget* theParent, } } } - } + } } + } else { //if PointMap3d Actor + if (VISU_ActorBase* anActorBase = dynamic_cast(anActor)) + if(anActorBase->GetVisibility() != 0) + if (VISU::PointMap3d_i* aPrs = dynamic_cast(anActorBase->GetFactory())) { + if(!myPointMapPrsMap.contains(aPrs)){ + Handle(SALOME_InteractiveObject) anIO = aPrs->GetIO(); + if(!anIO->hasEntry()) + continue; + SalomeApp_Study* aStudy = VISU::GetAppStudy(theModule); + VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, anIO->getEntry()); + if(_PTR(SObject) aSObject = anObjectInfo.mySObject){ + _PTR(GenericAttribute) anAttr; + if (aSObject->FindAttribute(anAttr, "AttributeName")) { + _PTR(AttributeName) aName(anAttr); + QString strIn(aName->Value().c_str()); + aPrsNames.append(strIn); + myPointMapPrsMap[aPrs] = myOffsets.count(); + Offset aOffs; + anActorBase->GetPosition(aOffs.myOffset); + myOffsets.append(aOffs); + } + } + } + } + } } myFieldLst->insertStringList(aPrsNames); myFieldLst->setSelected(0, true); @@ -411,14 +436,24 @@ void ArrangeDlg::acceptViewWindow() if (mySaveChk->isChecked()) aPrs->SetOffset(aOffs.myOffset[0],aOffs.myOffset[1],aOffs.myOffset[2]); } + QMap::Iterator itt; + for (itt = myPointMapPrsMap.begin(); itt != myPointMapPrsMap.end(); ++itt) { + VISU::PointMap3d_i* aPrs = itt.key(); + Offset& aOffs = myOffsets[itt.data()]; + if (VISU_ActorBase* anActor = VISU::FindActorBase(myViewWindow, aPrs)) + anActor->SetPosition(aOffs.myOffset); + if (mySaveChk) + if (mySaveChk->isChecked()) + aPrs->SetOffset(aOffs.myOffset[0],aOffs.myOffset[1],aOffs.myOffset[2]); + } } else { vtkFloatingPointType aDist = 0; vtkFloatingPointType aShift = 0; vtkFloatingPointType aPrevDist = 0; vtkFloatingPointType aPrevShift = 0; - int i; + int i = 0; QMap::Iterator it; - for (it = myPrsMap.begin(), i = 0; it != myPrsMap.end(); ++it, i++) { + for (it = myPrsMap.begin(); it != myPrsMap.end(); ++it, i++) { VISU::Prs3d_i* aPrs = it.key(); if (VISU_Actor* aActor = VISU::FindActor(myViewWindow, aPrs)) { int aAxis = getAxis(); @@ -491,7 +526,70 @@ void ArrangeDlg::acceptViewWindow() aPrevDist = aDist; aPrevShift = aShift; } - } + } // end of myPrsMap loop + // Loop in PointMap3D the same as previous loop + QMap::Iterator itt; + for (itt = myPointMapPrsMap.begin(); itt != myPointMapPrsMap.end(); ++itt, i++) { + VISU::PointMap3d_i* aPrs = itt.key(); + if (VISU_ActorBase* aActor = VISU::FindActorBase(myViewWindow, aPrs)) { + int aAxis = getAxis(); + + vtkFloatingPointType aZeroOffset[3]; + aZeroOffset[0] = aZeroOffset[1] = aZeroOffset[2] = 0; + aActor->SetPosition(aZeroOffset); + aActor->GetMapper()->Update(); + + vtkFloatingPointType aBounds[6]; + aActor->GetBounds(aBounds); + switch (aAxis) { + case XAxis: + aDist = fabs(aBounds[1] - aBounds[0]); + break; + case YAxis: + aDist = fabs(aBounds[3] - aBounds[2]); + break; + case ZAxis: + aDist = fabs(aBounds[5] - aBounds[4]); + } + vtkFloatingPointType aOffset[3]; + aOffset[0] = aOffset[1] = aOffset[2] = 0; + aOffset[aAxis] = + (aBounds[2*aAxis+1] < aBounds[2*aAxis]) ? -aBounds[2*aAxis+1] : -aBounds[2*aAxis]; + + if (i > 0) { + vtkFloatingPointType aCCDist = (aDist + aPrevDist) / 2.0; + + vtkFloatingPointType dx = fabs(aBounds[1] - aBounds[0]); + vtkFloatingPointType dy = fabs(aBounds[3] - aBounds[2]); + vtkFloatingPointType dz = fabs(aBounds[5] - aBounds[4]); + vtkFloatingPointType max = (dx > dy) ? dx : dy; + max = (dz > max) ? dz : max; + max /= 100.0; + + if (aCCDist < max) { + // set base distance between centers of bounding boxes + // to minimal (but big enough) size of current bounding box + if (dx < max) dx = FLT_MAX; + if (dy < max) dy = FLT_MAX; + if (dz < max) dz = FLT_MAX; + + aCCDist = (dx < dy) ? dx : dy; + aCCDist = (dz < aCCDist) ? dz : aCCDist; + } + aShift = aPrevShift + aPrevDist/2.0 + aCCDist*getDistance() - aDist/2.0; + } + + aOffset[aAxis] += aShift; + aActor->SetPosition(aOffset); + if (mySaveChk) + if (mySaveChk->isChecked()) + aPrs->SetOffset(aOffset[0],aOffset[1],aOffset[2]); + + aPrevDist = aDist; + aPrevShift = aShift; + } + } // end of myPointMapPrsMap loop + } myViewWindow->getRenderer()->ResetCameraClippingRange(); myViewWindow->Repaint(); diff --git a/src/VISUGUI/VisuGUI_TimeAnimation.h b/src/VISUGUI/VisuGUI_TimeAnimation.h index d41e369c..9a97900e 100644 --- a/src/VISUGUI/VisuGUI_TimeAnimation.h +++ b/src/VISUGUI/VisuGUI_TimeAnimation.h @@ -47,6 +47,7 @@ class VISU_TimeAnimation; namespace VISU { class Prs3d_i; + class PointMap3d_i; } class SVTK_ViewWindow; @@ -113,6 +114,7 @@ class ArrangeDlg: public QDialog int myCurrent; QMap myPrsMap; + QMap myPointMapPrsMap; }; -- 2.39.2