From: vsv Date: Fri, 13 May 2005 07:25:03 +0000 (+0000) Subject: Lay out of actors within viewer X-Git-Tag: V2_2_0_VISU_improvement_2005-05-27~30 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c348a39c96c7c748bba2c73512d3039849cefed0;p=modules%2Fvisu.git Lay out of actors within viewer --- diff --git a/src/VISUGUI/VisuGUI.cxx b/src/VISUGUI/VisuGUI.cxx index cbf0b3fc..f1077b27 100644 --- a/src/VISUGUI/VisuGUI.cxx +++ b/src/VISUGUI/VisuGUI.cxx @@ -2883,8 +2883,10 @@ bool VisuGUI::CustomPopup (QAD_Desktop* parent, QPopupMenu* thePopup, const QStr thePopup->clear(); if ( nbSel == 0 ) { - if ( theParent == "Viewer" && isVTKViewer && !aIsLocked) + if ( theParent == "Viewer" && isVTKViewer && !aIsLocked) { + thePopup->insertItem( "Arrange actors...", visuGUI, SLOT( ArrangeActors() ) ); thePopup->insertItem( "Save view parameters", visuGUI, SLOT( SaveViewParams() ) ); + } return false; } if ( nbSel > 1 ) { @@ -4486,14 +4488,15 @@ void VisuGUI::TranslatePrs() aDlg.setOffset(aOffset); if (aDlg.exec() == QDialog::Accepted) { aDlg.getOffset(aOffset); - aPrsObject->SetOffset(aOffset); + if (aDlg.isToSave()) + aPrsObject->SetOffset(aOffset); // RecreateActor(aPrsObject); for(int i = 0, nbFrames = GetActiveStudy()->getStudyFramesCount(); i < nbFrames; i++){ if(QAD_StudyFrame* aFrame = GetActiveStudy()->getStudyFrame(i)){ QAD_ViewFrame* aVFrame = aFrame->getRightFrame()->getViewFrame(); if(VTKViewer_ViewFrame* aViewFrame = dynamic_cast(aVFrame)) if(VISU_Actor* anActor = GetActor(aPrsObject,aViewFrame)) - anActor->SetPosition(aOffset);; + anActor->SetPosition(aOffset); } } if (VTKViewer_ViewFrame* vf = GetVtkViewFrame()) { @@ -4510,3 +4513,13 @@ void VisuGUI::TranslatePrs() } } } + + +void VisuGUI::ArrangeActors() +{ + VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(); + if (aViewFrame) { + ArrangeDlg aDlg(GetDesktop(), aViewFrame); + aDlg.exec(); + } +} diff --git a/src/VISUGUI/VisuGUI.h b/src/VISUGUI/VisuGUI.h index 381fd4bf..dad1addd 100644 --- a/src/VISUGUI/VisuGUI.h +++ b/src/VISUGUI/VisuGUI.h @@ -283,6 +283,7 @@ public slots: void SelectionInfo(); void TranslatePrs(); + void ArrangeActors(); private : QDialog* myActiveDialogBox; diff --git a/src/VISUGUI/VisuGUI_OffsetDlg.cxx b/src/VISUGUI/VisuGUI_OffsetDlg.cxx index 1da6938e..92f1ce01 100644 --- a/src/VISUGUI/VisuGUI_OffsetDlg.cxx +++ b/src/VISUGUI/VisuGUI_OffsetDlg.cxx @@ -9,6 +9,7 @@ #include #include #include +#include #define MAXVAL 1e10 @@ -45,6 +46,10 @@ VisuGUI_OffsetDlg::VisuGUI_OffsetDlg() TopLayout->addWidget(aOffsetsPane); + mySaveChk = new QCheckBox("Save to presentation", this); + mySaveChk->setChecked(true); + TopLayout->addWidget(mySaveChk); + // Common buttons =========================================================== QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" ); GroupButtons->setColumnLayout(0, Qt::Vertical ); @@ -95,3 +100,9 @@ void VisuGUI_OffsetDlg::onReset() myDyEdt->setValue(0); myDzEdt->setValue(0); } + + +bool VisuGUI_OffsetDlg::isToSave() const +{ + return mySaveChk->isChecked(); +} diff --git a/src/VISUGUI/VisuGUI_OffsetDlg.h b/src/VISUGUI/VisuGUI_OffsetDlg.h index ee056867..48703f10 100644 --- a/src/VISUGUI/VisuGUI_OffsetDlg.h +++ b/src/VISUGUI/VisuGUI_OffsetDlg.h @@ -8,6 +8,7 @@ #include class QAD_SpinBoxDbl; +class QCheckBox; class VisuGUI_OffsetDlg: public QDialog { @@ -18,6 +19,7 @@ class VisuGUI_OffsetDlg: public QDialog void setOffset(const float* theOffset); void getOffset(float* theOffset) const; + bool isToSave() const; public slots: void onReset(); @@ -26,6 +28,8 @@ class VisuGUI_OffsetDlg: public QDialog QAD_SpinBoxDbl* myDxEdt; QAD_SpinBoxDbl* myDyEdt; QAD_SpinBoxDbl* myDzEdt; + + QCheckBox* mySaveChk; }; #endif // DIALOGBOX_OFFSET_H diff --git a/src/VISUGUI/VisuGUI_TimeAnimation.cxx b/src/VISUGUI/VisuGUI_TimeAnimation.cxx index 62273ad2..3c5b9ebf 100644 --- a/src/VISUGUI/VisuGUI_TimeAnimation.cxx +++ b/src/VISUGUI/VisuGUI_TimeAnimation.cxx @@ -45,6 +45,9 @@ #include "VISU_StreamLines_i.hh" #include "VISU_Actor.h" +#include + + static double MAXVALUE = 1.0E+300; #define MAXVAL 1e10 @@ -54,7 +57,7 @@ static double MAXVALUE = 1.0E+300; ArrangeDlg::ArrangeDlg(QWidget* theParent, VISU_TimeAnimation* theAnimator) : QDialog(theParent, "ArrangeDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), - myAnimator(theAnimator) + myAnimator(theAnimator), myViewFrame(0) { myCurrent = 0; init(); @@ -73,6 +76,43 @@ ArrangeDlg::ArrangeDlg(QWidget* theParent, VISU_TimeAnimation* theAnimator) } +ArrangeDlg::ArrangeDlg(QWidget* theParent, VTKViewer_ViewFrame* theViewFrame) + : QDialog(theParent, "ArrangeDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), + myAnimator(0), myViewFrame(theViewFrame) +{ + myCurrent = 0; + init(); + QStringList aPrsNames; + vtkActor* anActor; + vtkActorCollection *anActColl = myViewFrame->getRenderer()->GetActors(); + for (anActColl->InitTraversal(); (anActor = anActColl->GetNextActor()) != NULL;) { + if (VISU_Actor* anVISUActor = dynamic_cast(anActor)) + if (anVISUActor->GetVisibility() != 0) + if (VISU::Prs3d_i* aPrs = anVISUActor->GetParent()->GetPrs3d()) { + if (!myPrsMap.contains(aPrs)) { + SALOMEDS::SObject_var aSObject = aPrs->GetSObject(); + if(!aSObject->_is_nil()){ + SALOMEDS::GenericAttribute_var anAttr; + if (aSObject->FindAttribute(anAttr, "AttributeName")) { + SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); + string aNam = aName->Value(); + QString strIn(aNam.c_str()); + aPrsNames.append(strIn); + myPrsMap[aPrs] = myOffsets.count(); + Offset aOffs; + anVISUActor->GetPosition(aOffs.myOffset); + myOffsets.append(aOffs); + } + } + } + } + } + myFieldLst->insertStringList(aPrsNames); + myFieldLst->setSelected(0, true); +} + + + void ArrangeDlg::init() { setCaption("Arrange Presentations"); @@ -115,9 +155,9 @@ void ArrangeDlg::init() //Distance Input QHBox* aDistPane = new QHBox(aAutoPane); aDistPane->setSpacing(5); - new QLabel("Distance", aDistPane); - myDistVal = new QAD_SpinBoxDbl(aDistPane, -5, 5, 0.5 ); - myDistVal->setValue(0.5); + new QLabel("Relative Distance", aDistPane); + myDistVal = new QAD_SpinBoxDbl(aDistPane, -10,10, 0.5 ); + myDistVal->setValue(1); myStackWgt->addWidget(aAutoPane, AutoMode); @@ -150,6 +190,12 @@ void ArrangeDlg::init() connect(aBtnGrp, SIGNAL(clicked(int)), myStackWgt, SLOT(raiseWidget(int)) ); + if (!myAnimator) { + mySaveChk = new QCheckBox("Save to presentation", this); + mySaveChk->setChecked(false); + aMainLayout->addWidget(mySaveChk); + } + // Common buttons =========================================================== QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" ); GroupButtons->setColumnLayout(0, Qt::Vertical ); @@ -178,6 +224,31 @@ void ArrangeDlg::init() void ArrangeDlg::accept() +{ + if (myAnimator) { + acceptAnimation(); + } else { + acceptViewWindow(); + } + QDialog::accept(); +} + +void ArrangeDlg::onFieldChange(int theCurrent) +{ + if (myCurrent != theCurrent) { + Offset& aOffs = myOffsets[myCurrent]; + aOffs.myOffset[0] = myCoord[0]->value(); + aOffs.myOffset[1] = myCoord[1]->value(); + aOffs.myOffset[2] = myCoord[2]->value(); + } + myCurrent = theCurrent; + const Offset& aNewOffs = myOffsets[myCurrent]; + myCoord[0]->setValue(aNewOffs.myOffset[0]); + myCoord[1]->setValue(aNewOffs.myOffset[1]); + myCoord[2]->setValue(aNewOffs.myOffset[2]); +} + +void ArrangeDlg::acceptAnimation() { if (getMode() == ManualMode) { // Save from GUI @@ -205,45 +276,81 @@ void ArrangeDlg::accept() int aAxis = getAxis(); switch (aAxis) { case XAxis: - aDist = fabs(aBounds[3] - aBounds[0]); + aDist = fabs(aBounds[1] - aBounds[0]); break; case YAxis: - aDist = fabs(aBounds[4] - aBounds[1]); + aDist = fabs(aBounds[3] - aBounds[2]); break; case ZAxis: - aDist = fabs(aBounds[5] - aBounds[2]); + aDist = fabs(aBounds[5] - aBounds[4]); } - aDist += aDist*getDistance(); + aDist = aDist*getDistance(); for (int i = 0; i < myAnimator->getNbFields(); i++) { myAnimator->getFieldData(i).myOffset[0] = 0; myAnimator->getFieldData(i).myOffset[1] = 0; myAnimator->getFieldData(i).myOffset[2] = 0; myAnimator->getFieldData(i).myOffset[aAxis] = aDist * i; } - + QApplication::restoreOverrideCursor(); } - QDialog::accept(); } -void ArrangeDlg::onFieldChange(int theCurrent) +void ArrangeDlg::acceptViewWindow() { - if (myCurrent != theCurrent) { + if (getMode() == ManualMode) { + // Save from GUI Offset& aOffs = myOffsets[myCurrent]; aOffs.myOffset[0] = myCoord[0]->value(); aOffs.myOffset[1] = myCoord[1]->value(); aOffs.myOffset[2] = myCoord[2]->value(); + + QMap::Iterator it; + for (it = myPrsMap.begin(); it != myPrsMap.end(); ++it) { + VISU::Prs3d_i* aPrs = it.key(); + Offset& aOffs = myOffsets[it.data()]; + if (VISU_Actor* anActor = VisuGUI::GetActor(aPrs, myViewFrame)) anActor->SetPosition(aOffs.myOffset); + if (mySaveChk->isChecked())aPrs->SetOffset(aOffs.myOffset); + } + } else { + float aDist = 0; + bool aInit = true; + int i; + QMap::Iterator it; + for (it = myPrsMap.begin(), i = 0; it != myPrsMap.end(); ++it, i++) { + VISU::Prs3d_i* aPrs = it.key(); + if (VISU_Actor* aActor = VisuGUI::GetActor(aPrs, myViewFrame)){ + int aAxis = getAxis(); + if (aInit) { + float 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]); + } + aDist = aDist*getDistance(); + aInit = false; + } + float aOffset[3]; + aOffset[0] = aOffset[1] = aOffset[2] = 0; + aOffset[aAxis] = aDist * i; + aActor->SetPosition(aOffset); + + if (mySaveChk->isChecked())aPrs->SetOffset(aOffset); + } + } } - myCurrent = theCurrent; - const Offset& aNewOffs = myOffsets[myCurrent]; - myCoord[0]->setValue(aNewOffs.myOffset[0]); - myCoord[1]->setValue(aNewOffs.myOffset[1]); - myCoord[2]->setValue(aNewOffs.myOffset[2]); + myViewFrame->getRenderer()->ResetCameraClippingRange(); + myViewFrame->Repaint(); } - - //***************************************************************************************************** //***************************************************************************************************** //***************************************************************************************************** diff --git a/src/VISUGUI/VisuGUI_TimeAnimation.h b/src/VISUGUI/VisuGUI_TimeAnimation.h index dbba957f..6d5a9c5a 100644 --- a/src/VISUGUI/VisuGUI_TimeAnimation.h +++ b/src/VISUGUI/VisuGUI_TimeAnimation.h @@ -26,7 +26,7 @@ #include CORBA_CLIENT_HEADER(VISU_Gen) class VISU_TimeAnimation; - +class VTKViewer_ViewFrame; /** * Auxilliary class for presentations definition @@ -39,6 +39,7 @@ class ArrangeDlg: public QDialog enum { XAxis, YAxis, ZAxis }; ArrangeDlg(QWidget* theParent, VISU_TimeAnimation* theAnimator); + ArrangeDlg(QWidget* theParent, VTKViewer_ViewFrame* theViewFrame); ~ArrangeDlg() {}; int getMode() const { return myStackWgt->id(myStackWgt->visibleWidget()); } @@ -56,16 +57,23 @@ protected slots: void init(); + void acceptAnimation(); + void acceptViewWindow(); VISU_TimeAnimation* myAnimator; + VTKViewer_ViewFrame* myViewFrame; + QWidgetStack* myStackWgt; QButtonGroup* myAxisGrp; QAD_SpinBoxDbl* myDistVal; QListBox* myFieldLst; QAD_SpinBoxDbl* myCoord[3]; - QValueList myOffsets; + QValueList myOffsets; + + QCheckBox* mySaveChk; int myCurrent; + QMap myPrsMap; };