From 15a4288aeac8dc3a8d3346e7994a562e1ec6aab3 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 29 May 2008 11:35:37 +0000 Subject: [PATCH] *** empty log message *** --- src/OBJECT/VISU_Actor.cxx | 19 + src/OBJECT/VISU_Actor.h | 10 + src/OBJECT/VISU_DataSetActor.cxx | 64 ++- src/OBJECT/VISU_DataSetActor.h | 16 + src/OBJECT/VISU_ScalarMapAct.cxx | 14 +- src/VISUGUI/VISU_msg_en.ts | 24 + src/VISUGUI/VisuGUI_ClippingDlg.cxx | 305 ++++++++++++- src/VISUGUI/VisuGUI_ClippingDlg.h | 23 +- src/VISUGUI/VisuGUI_ClippingPlaneMgr.cxx | 539 ++++++++++++++++------- src/VISUGUI/VisuGUI_ClippingPlaneMgr.h | 85 +++- src/VISUGUI/VisuGUI_SegmentationMgr.cxx | 41 +- src/VISUGUI/VisuGUI_SegmentationMgr.h | 18 +- src/VISUGUI/VisuGUI_ViewExtender.cxx | 28 +- src/VISUGUI/VisuGUI_ViewExtender.h | 7 + 14 files changed, 974 insertions(+), 219 deletions(-) diff --git a/src/OBJECT/VISU_Actor.cxx b/src/OBJECT/VISU_Actor.cxx index 79a3a7ae..ac5501ab 100644 --- a/src/OBJECT/VISU_Actor.cxx +++ b/src/OBJECT/VISU_Actor.cxx @@ -698,6 +698,25 @@ VISU_Actor return aRet; } +void VISU_Actor::RemoveAllClippingPlanes() +{ +} + +vtkIdType VISU_Actor::GetNumberOfClippingPlanes() +{ + return 0; +} + +bool VISU_Actor::AddClippingPlane(vtkPlane* thePlane) +{ + return false; +} + +vtkPlane* VISU_Actor::GetClippingPlane(vtkIdType theID) +{ + return NULL; +} + //---------------------------------------------------------------------------- template std::string getScalar(TData* theData, int theId) { diff --git a/src/OBJECT/VISU_Actor.h b/src/OBJECT/VISU_Actor.h index 8377ec94..688c3d85 100644 --- a/src/OBJECT/VISU_Actor.h +++ b/src/OBJECT/VISU_Actor.h @@ -46,6 +46,7 @@ class vtkInteractorStyle; class vtkCallbackCommand; class VTKViewer_ShrinkFilter; class VISU_PipeLine; +class vtkPlane; class VISU_FramedTextActor; @@ -255,6 +256,15 @@ class VTKOCC_EXPORT VISU_Actor : vtkCell* GetElemCell(vtkIdType theObjID); + //---------------------------------------------------------------------------- + virtual void RemoveAllClippingPlanes(); + + virtual vtkIdType GetNumberOfClippingPlanes(); + + virtual bool AddClippingPlane(vtkPlane* thePlane); + + virtual vtkPlane* GetClippingPlane(vtkIdType theID); + //---------------------------------------------------------------------------- //! Apply the picking settings on the actor. void diff --git a/src/OBJECT/VISU_DataSetActor.cxx b/src/OBJECT/VISU_DataSetActor.cxx index 1b282c01..c19e829f 100644 --- a/src/OBJECT/VISU_DataSetActor.cxx +++ b/src/OBJECT/VISU_DataSetActor.cxx @@ -31,6 +31,10 @@ #include #include +#include +#include +#include +#include #include @@ -48,11 +52,19 @@ vtkStandardNewMacro(VISU_DataSetActor); //---------------------------------------------------------------------------- VISU_DataSetActor ::VISU_DataSetActor(): - myMapper(vtkDataSetMapper::New()) + myMapper(vtkDataSetMapper::New()), + myExtractor(SALOME_ExtractGeometry::New()), + myFunction(vtkImplicitBoolean::New()) { if(MYDEBUG) MESSAGE("VISU_DataSetActor::VISU_DataSetActor - this = "<SetImplicitFunction(myFunction); + //myExtractor->ExtractBoundaryCellsOn(); + myFunction->SetOperationTypeToIntersection(); + myMapper->Delete(); + myExtractor->Delete(); + myFunction->Delete(); } //---------------------------------------------------------------------------- @@ -71,9 +83,8 @@ VISU_DataSetActor if(VISU_UnstructuredGridPL* aPipeLine = dynamic_cast(thePipeLine)){ vtkDataSetMapper* aTarget = GetDataSetMapper(); - vtkDataSetMapper* aSource = aPipeLine->GetDataSetMapper(); + vtkDataSetMapper* aSource = aPipeLine->GetDataSetMapper(); VISU::CopyDataSetMapper(aTarget, aSource, true); - aTarget->SetLookupTable(aSource->GetLookupTable()); } } @@ -82,14 +93,53 @@ void VISU_DataSetActor ::SetMapperInput(vtkDataSet* theDataSet) { - myMapper->SetInput(theDataSet); + myExtractor->SetInput(theDataSet); + myMapper->SetInput(myExtractor->GetOutput()); SetMapper(myMapper.GetPointer()); } //---------------------------------------------------------------------------- -vtkDataSetMapper* -VISU_DataSetActor -::GetDataSetMapper() +vtkDataSetMapper* VISU_DataSetActor::GetDataSetMapper() { return myMapper.GetPointer(); } + +//---------------------------------------------------------------------------- +void VISU_DataSetActor::RemoveAllClippingPlanes() +{ + myFunction->GetFunction()->RemoveAllItems(); + myFunction->Modified(); +} + +//---------------------------------------------------------------------------- +vtkIdType VISU_DataSetActor::GetNumberOfClippingPlanes() +{ + return myFunction->GetFunction()->GetNumberOfItems(); +} + +//---------------------------------------------------------------------------- +bool VISU_DataSetActor::AddClippingPlane(vtkPlane* thePlane) +{ + myFunction->AddFunction(thePlane); +} + +//---------------------------------------------------------------------------- +vtkPlane* VISU_DataSetActor::GetClippingPlane(vtkIdType theID) +{ + vtkPlane* aPlane = NULL; + if ((theID >= 0) && (theID < GetNumberOfClippingPlanes())) { + vtkImplicitFunctionCollection* aFunction = myFunction->GetFunction(); + vtkImplicitFunction* aFun = NULL; + aFunction->InitTraversal(); + for (vtkIdType i = 0; i <= theID; i++) + aFun = aFunction->GetNextItem(); + aPlane = dynamic_cast(aFun); + } + return aPlane; +} + +//---------------------------------------------------------------------------- +vtkImplicitFunctionCollection* VISU_DataSetActor::GetClippingPlanes() +{ + return myFunction->GetFunction(); +} diff --git a/src/OBJECT/VISU_DataSetActor.h b/src/OBJECT/VISU_DataSetActor.h index 9e7ef457..18ef7958 100644 --- a/src/OBJECT/VISU_DataSetActor.h +++ b/src/OBJECT/VISU_DataSetActor.h @@ -31,6 +31,9 @@ #include "VISU_Actor.h" class vtkDataSetMapper; +class SALOME_ExtractGeometry; +class vtkImplicitBoolean; +class vtkImplicitFunctionCollection; #ifdef _WIN_32 #define VTKOCC_EXPORT __declspec (dllexport) @@ -56,6 +59,17 @@ class VTKOCC_EXPORT VISU_DataSetActor : public VISU_Actor vtkDataSetMapper* GetDataSetMapper(); + //---------------------------------------------------------------------------- + virtual void RemoveAllClippingPlanes(); + + virtual vtkIdType GetNumberOfClippingPlanes(); + + virtual bool AddClippingPlane(vtkPlane* thePlane); + + virtual vtkPlane* GetClippingPlane(vtkIdType theID); + + virtual vtkImplicitFunctionCollection* GetClippingPlanes(); + //---------------------------------------------------------------------------- protected: VISU_DataSetActor(); @@ -69,6 +83,8 @@ class VTKOCC_EXPORT VISU_DataSetActor : public VISU_Actor //---------------------------------------------------------------------------- vtkSmartPointer myMapper; + vtkSmartPointer myExtractor; + vtkSmartPointer myFunction; }; #endif //VISU_DATASETACTOR_H diff --git a/src/OBJECT/VISU_ScalarMapAct.cxx b/src/OBJECT/VISU_ScalarMapAct.cxx index 90816504..5f1774be 100644 --- a/src/OBJECT/VISU_ScalarMapAct.cxx +++ b/src/OBJECT/VISU_ScalarMapAct.cxx @@ -36,6 +36,8 @@ #include "VISU_DeformedShapePL.hxx" #include "VISU_PipeLineUtils.hxx" +#include + #include #include #include @@ -258,7 +260,7 @@ void VISU_ScalarMapAct ::ShallowCopyPL(VISU_PipeLine* thePipeLine) { - VISU_Actor::ShallowCopyPL( thePipeLine ); + VISU_DataSetActor::ShallowCopyPL( thePipeLine ); myEdgeActor->GetMapper()->ScalarVisibilityOff(); @@ -274,10 +276,12 @@ VISU_ScalarMapAct { Superclass::SetMapperInput( theDataSet ); - myPointsActor->SetInput( theDataSet ); - - mySurfaceActor->SetInput( theDataSet ); - myEdgeActor->SetInput( theDataSet ); +// myPointsActor->SetInput( theDataSet ); +// mySurfaceActor->SetInput( theDataSet ); +// myEdgeActor->SetInput( theDataSet ); + myPointsActor->SetInput( myExtractor->GetOutput() ); + mySurfaceActor->SetInput( myExtractor->GetOutput() ); + myEdgeActor->SetInput( myExtractor->GetOutput() ); } //---------------------------------------------------------------------------- diff --git a/src/VISUGUI/VISU_msg_en.ts b/src/VISUGUI/VISU_msg_en.ts index 23684e8d..358d756f 100644 --- a/src/VISUGUI/VISU_msg_en.ts +++ b/src/VISUGUI/VISU_msg_en.ts @@ -1474,6 +1474,22 @@ Please, refer to the documentation. Impossible to use given clipping planes because of VTK restrictions. Please, provide non-empty resulting presentation. + + GRP_TYPE + Type of plane + + + GLOBAL_BTN + Global planes + + + LOCAL_BTN + Local planes + + + GRP_VIEWER_PLANES + Planes defined in viewer + VisuGUI_CubeAxesDlg @@ -3394,6 +3410,10 @@ Please, refer to the documentation. BTN_DELETE Delete + + BTN_IMPORT + Import... + VisuGUI_ViewExtender @@ -3409,5 +3429,9 @@ Please, refer to the documentation. VISU_VIEW_TOOLBAR VISU tools + + VISU_SETPLANES_MNU + Set clipping plane... + diff --git a/src/VISUGUI/VisuGUI_ClippingDlg.cxx b/src/VISUGUI/VisuGUI_ClippingDlg.cxx index a5aca09a..dc5b5938 100644 --- a/src/VISUGUI/VisuGUI_ClippingDlg.cxx +++ b/src/VISUGUI/VisuGUI_ClippingDlg.cxx @@ -23,16 +23,21 @@ #include "VisuGUI.h" #include "VisuGUI_Tools.h" #include "VisuGUI_ViewTools.h" +#include "VisuGUI_SegmentationMgr.h" +#include "VisuGUI_ViewExtender.h" +#include "VisuGUI_ClippingPlaneMgr.h" #include "VISU_Prs3d_i.hh" #include "VISU_Result_i.hh" #include "VISU_PipeLine.hxx" +#include "VISU_DataSetActor.h" #include "LightApp_SelectionMgr.h" #include "LightApp_Application.h" #include "SVTK_ViewWindow.h" +#include #include "SUIT_Session.h" #include "SUIT_Desktop.h" @@ -41,6 +46,7 @@ #include "SUIT_OverrideCursor.h" #include "SALOME_Actor.h" +#include "VISU_ViewManager_i.hh" // QT Includes #include @@ -55,6 +61,10 @@ #include #include #include +#include +#include +#include +#include // VTK Includes #include @@ -67,6 +77,7 @@ #include #include #include +#include // OCCT Includes #include @@ -244,25 +255,69 @@ VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (VisuGUI* theModule, mySelectionMgr(VISU::GetSelectionMgr(theModule)), myVisuGUI(theModule), myPrs3d(0), - myIsSelectPlane(false) + myIsSelectPlane(false), + myDSActor(0) { setWindowTitle(tr("TITLE")); setSizeGripEnabled(TRUE); setAttribute( Qt::WA_DeleteOnClose, true ); - QGridLayout* VisuGUI_ClippingDlgLayout = new QGridLayout(this); + QVBoxLayout* VisuGUI_ClippingDlgLayout = new QVBoxLayout(this); VisuGUI_ClippingDlgLayout->setSpacing(6); VisuGUI_ClippingDlgLayout->setMargin(11); + myHasGlobalPl = hasGlobalPlanes(); + + if (myHasGlobalPl) { + QGroupBox* aTypeFrm = new QGroupBox (tr("GRP_TYPE"), this); + QHBoxLayout* aTypeLayout = new QHBoxLayout(aTypeFrm); + aTypeFrm->setLayout(aTypeLayout); + VisuGUI_ClippingDlgLayout->addWidget(aTypeFrm); + + myPlaneTypeGrp = new QButtonGroup (aTypeFrm); + myPlaneTypeGrp->setExclusive(true); + + QRadioButton* aGlobalBtn = new QRadioButton(tr("GLOBAL_BTN"), aTypeFrm); + aGlobalBtn->setChecked(true); + aTypeLayout->addWidget(aGlobalBtn); + myPlaneTypeGrp->addButton(aGlobalBtn, 0); + + aTypeLayout->addStretch(); + + QRadioButton* aLocalBtn = new QRadioButton(tr("LOCAL_BTN"), aTypeFrm); + aTypeLayout->addWidget(aLocalBtn); + myPlaneTypeGrp->addButton(aLocalBtn, 1); + } + + QStackedWidget* aStackWidget = new QStackedWidget(this); + VisuGUI_ClippingDlgLayout->addWidget(aStackWidget); + if (myHasGlobalPl) { + connect(myPlaneTypeGrp, SIGNAL(buttonClicked(int)), aStackWidget, SLOT(setCurrentIndex(int)) ); + connect(myPlaneTypeGrp, SIGNAL(buttonClicked(int)), this, SLOT(onPlaneType(int)) ); + + // Global planes + QGroupBox* aViewerPlanes = new QGroupBox (tr("GRP_VIEWER_PLANES"), aStackWidget); + QVBoxLayout* aGPlanesLayout = new QVBoxLayout(aStackWidget); + aViewerPlanes->setLayout(aGPlanesLayout); + aStackWidget->addWidget(aViewerPlanes); + + myGlobalPlanes = new QListWidget(aViewerPlanes); + connect(myGlobalPlanes, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(onPlaneCheck())); + + aGPlanesLayout->addWidget(myGlobalPlanes); + } + // Local planes + QWidget* aLocalPlanes = new QWidget(aStackWidget); + QVBoxLayout* aLocalLayout = new QVBoxLayout(aLocalPlanes); + aStackWidget->addWidget(aLocalPlanes); + // Controls for selecting, creating, deleting planes - QGroupBox* GroupPlanes = new QGroupBox (tr("GRP_PLANES"), this); - //GroupPlanes->setColumnLayout(0, Qt::Vertical); - //GroupPlanes->layout()->setSpacing(0); - //GroupPlanes->layout()->setMargin(0); + QGroupBox* GroupPlanes = new QGroupBox (tr("GRP_PLANES"), aLocalPlanes); QGridLayout* GroupPlanesLayout = new QGridLayout (GroupPlanes); GroupPlanesLayout->setAlignment(Qt::AlignTop); GroupPlanesLayout->setSpacing(6); GroupPlanesLayout->setMargin(11); + aLocalLayout->addWidget(GroupPlanes); ComboBoxPlanes = new QComboBox (GroupPlanes); GroupPlanesLayout->addWidget(ComboBoxPlanes, 0, 0); @@ -281,30 +336,38 @@ VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (VisuGUI* theModule, // Controls for defining plane parameters // Tab pane - QGroupBox* GroupParameters = new QGroupBox(tr("GRP_PARAMETERS"), this); - //GroupParameters->setColumnLayout(0, Qt::Vertical); - //GroupParameters->layout()->setSpacing(0); - //GroupParameters->layout()->setMargin(0); + QGroupBox* GroupParameters = new QGroupBox(tr("GRP_PARAMETERS"), aLocalPlanes); QGridLayout* GroupParametersLayout = new QGridLayout (GroupParameters); GroupParametersLayout->setAlignment(Qt::AlignTop); GroupParametersLayout->setSpacing(6); GroupParametersLayout->setMargin(11); + aLocalLayout->addWidget(GroupParameters); TabPane = new QTabWidget (GroupParameters); TabPane->addTab(createParamsTab() , tr("TAB_NON_STRUCTURED")); TabPane->addTab(createIJKParamsTab(), tr("TAB_IJK_STRUCTURED")); GroupParametersLayout->addWidget(TabPane, 0, 0); + + + + // "Show preview" and "Auto Apply" check boxes + QHBoxLayout* aCheckBoxLayout = new QHBoxLayout(this); + VisuGUI_ClippingDlgLayout->addLayout(aCheckBoxLayout); PreviewCheckBox = new QCheckBox (tr("SHOW_PREVIEW_CHK"), this); PreviewCheckBox->setChecked(true); + aCheckBoxLayout->addWidget(PreviewCheckBox); + aCheckBoxLayout->addStretch(); AutoApplyCheckBox = new QCheckBox (tr("AUTO_APPLY_CHK"), this); AutoApplyCheckBox->setChecked(false); + aCheckBoxLayout->addWidget(AutoApplyCheckBox); // Controls for "Ok", "Apply" and "Close" button QGroupBox* GroupButtons = new QGroupBox (this); + VisuGUI_ClippingDlgLayout->addWidget(GroupButtons); QSizePolicy aSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed ); aSizePolicy.setHeightForWidth( GroupButtons->sizePolicy().hasHeightForWidth() ); @@ -312,9 +375,6 @@ VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (VisuGUI* theModule, aSizePolicy.setVerticalStretch( 0 ); GroupButtons->setSizePolicy( aSizePolicy ); GroupButtons->setGeometry(QRect(10, 10, 281, 48)); - //GroupButtons->setColumnLayout(0, Qt::Vertical); - //GroupButtons->layout()->setSpacing(0); - //GroupButtons->layout()->setMargin(0); QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons); GroupButtons->setLayout(GroupButtonsLayout); GroupButtonsLayout->setAlignment(Qt::AlignTop); @@ -340,12 +400,6 @@ VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (VisuGUI* theModule, buttonOk->setDefault(TRUE); GroupButtonsLayout->addWidget(buttonOk, 0, 0); - VisuGUI_ClippingDlgLayout->addWidget(GroupPlanes, 0, 0, 1, 2); - VisuGUI_ClippingDlgLayout->addWidget(GroupParameters, 1, 0, 1, 2); - VisuGUI_ClippingDlgLayout->addWidget(PreviewCheckBox, 2, 0); - VisuGUI_ClippingDlgLayout->addWidget(AutoApplyCheckBox, 2, 1); - VisuGUI_ClippingDlgLayout->addWidget(GroupButtons, 3, 0, 3, 2); - // Initial state VISU::RangeStepAndValidator(SpinBoxDistance, 0.0, 1.0, 0.01, 3); VISU::RangeStepAndValidator(SpinBoxRot1, -180.0, 180.0, 1, 3); @@ -357,6 +411,8 @@ VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (VisuGUI* theModule, SpinBoxDistance->setValue(0.5); + initGlobalPlanes(); + onSelectionChanged(); // signals and slots connections : @@ -391,6 +447,9 @@ VisuGUI_ClippingDlg::VisuGUI_ClippingDlg (VisuGUI* theModule, //================================================================================= VisuGUI_ClippingDlg::~VisuGUI_ClippingDlg() { + if (myHasGlobalPl) + deleteGlobalPlanesPreview(); + // no need to delete child widgets, Qt does it all for us SetPrs3d(NULL); std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false)); @@ -488,6 +547,27 @@ QWidget* VisuGUI_ClippingDlg::createIJKParamsTab() // purpose : //================================================================================= void VisuGUI_ClippingDlg::ClickOnApply() +{ + if (myHasGlobalPl) { + switch (myPlaneTypeGrp->checkedId()) { + case 0: // Global plane + applyGlobalPlanes(); + break; + case 1: // Local plane + applyLocalPlanes(); + break; + } + } else { + applyLocalPlanes(); + } +} + + +//================================================================================= +// function : applyLocalPlanes() +// purpose : +//================================================================================= +void VisuGUI_ClippingDlg::applyLocalPlanes() { if (!myPrs3d) return; @@ -555,6 +635,33 @@ void VisuGUI_ClippingDlg::ClickOnApply() } } + +//================================================================================= +// function : applyGlobalPlanes() +// purpose : +//================================================================================= +void VisuGUI_ClippingDlg::applyGlobalPlanes() +{ + if (!myDSActor) return; + + VisuGUI_ViewExtender* aVisuExtender = dynamic_cast(myVisuGUI->getViewExtender()); + SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow(myVisuGUI); + VisuGUI_SegmentationMgr* aSegmentationMgr = aVisuExtender->getSegmentationMgr(); + + myDSActor->RemoveAllClippingPlanes(); + const QListOfPlanes& aPlanes = aSegmentationMgr->getPlanes(aViewWindow); + PlaneDef aPlane; + for (int i = 0; i < myGlobalPlanes->count(); i++) { + if (myGlobalPlanes->item(i)->checkState() == Qt::Checked) { + aPlane = aPlanes.at(i); + myDSActor->AddClippingPlane(aPlane.plane); + } + } + VISU::RenderViewWindow(aViewWindow); +} + + + //================================================================================= // function : ClickOnOk() // purpose : @@ -804,9 +911,9 @@ void VisuGUI_ClippingDlg::Sinchronize() } buttonDelete ->setEnabled(anIsControlsEnable); - buttonApply ->setEnabled(anIsControlsEnable); - PreviewCheckBox ->setEnabled(anIsControlsEnable); - AutoApplyCheckBox ->setEnabled(anIsControlsEnable); + //buttonApply ->setEnabled(anIsControlsEnable); + // PreviewCheckBox ->setEnabled(anIsControlsEnable); + // AutoApplyCheckBox ->setEnabled(anIsControlsEnable); ComboBoxOrientation ->setEnabled(anIsControlsEnable); SpinBoxDistance ->setEnabled(anIsControlsEnable); @@ -1190,7 +1297,20 @@ void VisuGUI_ClippingDlg::onIJKAxisChanged(int axisId) //================================================================================= void VisuGUI_ClippingDlg::OnPreviewToggle (bool theIsToggled) { - std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(theIsToggled)); + if (myHasGlobalPl) { + switch (myPlaneTypeGrp->checkedId()) { + case 0: // Global plane + previewGlobalPlanes(theIsToggled); + std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(false)); + break; + case 1: // Local plane + previewGlobalPlanes(false); + std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(theIsToggled)); + break; + } + } else { + std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(theIsToggled)); + } if (SVTK_ViewWindow* vw = VISU::GetActiveViewWindow(myVisuGUI)) VISU::RenderViewWindow(vw); } @@ -1224,3 +1344,142 @@ void VisuGUI_ClippingDlg::SetPrs3d(VISU::Prs3d_i* thePrs) } else return; } + +//================================================================================= +// function : hasGlobalPlanes() +// purpose : +//================================================================================= +bool VisuGUI_ClippingDlg::hasGlobalPlanes() +{ + VisuGUI_ViewExtender* aVisuExtender = dynamic_cast(myVisuGUI->getViewExtender()); + if (!aVisuExtender) return false; + + SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow(myVisuGUI); + if (!aViewWindow) return false; + + VisuGUI_SegmentationMgr* aSegmentationMgr = aVisuExtender->getSegmentationMgr(); + return aSegmentationMgr->getPlanes(aViewWindow).size() > 0; +} + +//================================================================================= +// function : initGlobalPlanes() +// purpose : +//================================================================================= +void VisuGUI_ClippingDlg::initGlobalPlanes() +{ + if (!myHasGlobalPl) return; + VisuGUI_ViewExtender* aVisuExtender = dynamic_cast(myVisuGUI->getViewExtender()); + SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow(myVisuGUI); + VisuGUI_SegmentationMgr* aSegmentationMgr = aVisuExtender->getSegmentationMgr(); + + double aBounds[6]; + ComputeVisiblePropBounds(aViewWindow->getRenderer(), aBounds); + + // Add planes names to list + const QListOfPlanes& aPlanes = aSegmentationMgr->getPlanes(aViewWindow); + PlaneDef aPlane; + for (int i = 0; i < aPlanes.size(); i++) { + aPlane = aPlanes.at(i); + QListWidgetItem* aItem = new QListWidgetItem(aPlane.name, myGlobalPlanes); + if (aPlane.isAuto) + aItem->setFlags(0); + else + aItem->setCheckState(Qt::Unchecked); + myGlobalPlanes->addItem(aItem); + + //Create preview + PreviewPlane* aPreview = new PreviewPlane(aViewWindow, aPlane, aBounds); + aPreview->setVisible(PreviewCheckBox->checkState() == Qt::Checked); + myPreviewList.append(aPreview); + } + + // Check items according to already added planes + myDSActor = getSelectedActor(); + if (!myDSActor) return; + + vtkImplicitFunctionCollection* aFunctions = myDSActor->GetClippingPlanes(); + aFunctions->InitTraversal(); + vtkImplicitFunction* aItem; + while (aItem = aFunctions->GetNextItem()) { + for (int i = 0; i < aPlanes.size(); i++) { + aPlane = aPlanes.at(i); + if (aPlane.plane.GetPointer() == aItem) { + myGlobalPlanes->item(i)->setCheckState(Qt::Checked); + break; + } + } + } +} + + +//================================================================================= +// function : initGlobalPlanes() +// purpose : +//================================================================================= +VISU_DataSetActor* VisuGUI_ClippingDlg::getSelectedActor() +{ + SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow(myVisuGUI); + + VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(myVisuGUI); + if(aSelectionInfo.empty()) return 0; + + VISU::TSelectionItem aSelectionItem = aSelectionInfo.front(); + VISU::Base_i* aBase = aSelectionItem.myObjectInfo.myBase; + if(!aBase) return 0; + + VISU::Prs3d_i* aPrs = dynamic_cast(aBase); + if (!aPrs) return 0; + + VISU_Actor* aActor = VISU::FindActor(aViewWindow, aPrs); + if (!aActor) return 0; + + VISU_DataSetActor* aDSActor = dynamic_cast(aActor); + return aDSActor; +} + +//================================================================================= +// function : onPlaneCheck() +// purpose : +//================================================================================= +void VisuGUI_ClippingDlg::onPlaneCheck() +{ + if (AutoApplyCheckBox->checkState() == Qt::Checked) { + applyGlobalPlanes(); + } +} + +//================================================================================= +// function : previewGlobalPlanes() +// purpose : +//================================================================================= +void VisuGUI_ClippingDlg::previewGlobalPlanes(bool theShow) +{ + for (int i = 0; i < myPreviewList.size(); i++) { + myPreviewList.at(i)->setVisible(theShow); + } +} + +//================================================================================= +// function : deleteGlobalPlanesPreview() +// purpose : +//================================================================================= +void VisuGUI_ClippingDlg::deleteGlobalPlanesPreview() +{ + PreviewPlane* aPreview = 0; + while (myPreviewList.size() > 0) { + aPreview = myPreviewList.last(); + myPreviewList.removeLast(); + delete aPreview; + } +} + +//================================================================================= +// function : deleteGlobalPlanesPreview() +// purpose : +//================================================================================= +void VisuGUI_ClippingDlg::onPlaneType(int theType) +{ + previewGlobalPlanes(theType == 0); + std::for_each(myPlanes.begin(),myPlanes.end(),TSetVisiblity(theType == 1)); + VISU::RenderViewWindow(VISU::GetActiveViewWindow(myVisuGUI)); +} diff --git a/src/VISUGUI/VisuGUI_ClippingDlg.h b/src/VISUGUI/VisuGUI_ClippingDlg.h index f14ac095..f53bc1ec 100644 --- a/src/VISUGUI/VisuGUI_ClippingDlg.h +++ b/src/VISUGUI/VisuGUI_ClippingDlg.h @@ -44,6 +44,7 @@ class QComboBox; class QButtonGroup; class QSpinBox; class QTabWidget; +class QListWidget; class SALOME_Actor; @@ -54,11 +55,11 @@ class SVTK_ViewWindow; class LightApp_SelectionMgr; class VisuGUI; - class vtkPlaneSource; class vtkDataSetMapper; - class OrientedPlane; +class VISU_DataSetActor; +class PreviewPlane; namespace VISU { class Prs3d_i; @@ -135,7 +136,17 @@ private: void keyPressEvent( QKeyEvent* e ); void SetPrs3d(VISU::Prs3d_i* thePrs); + + void initGlobalPlanes(); + bool hasGlobalPlanes(); + VISU_DataSetActor* getSelectedActor(); + + void applyLocalPlanes(); + void applyGlobalPlanes(); + + void deleteGlobalPlanesPreview(); + void previewGlobalPlanes(bool theShow); private: @@ -179,6 +190,12 @@ private: bool myIsSelectPlane; + QButtonGroup* myPlaneTypeGrp; + QListWidget* myGlobalPlanes; + bool myHasGlobalPl; + VISU_DataSetActor* myDSActor; + QList myPreviewList; + protected: QWidget* createParamsTab(); QWidget* createIJKParamsTab(); @@ -201,6 +218,8 @@ public slots: void ClickOnCancel(); void ClickOnApply(); void ClickOnHelp(); + void onPlaneCheck(); + void onPlaneType(int); }; #endif // DIALOGBOX_TRANSPARENCYDLG_H diff --git a/src/VISUGUI/VisuGUI_ClippingPlaneMgr.cxx b/src/VISUGUI/VisuGUI_ClippingPlaneMgr.cxx index 5643b5a8..8fce9c4a 100644 --- a/src/VISUGUI/VisuGUI_ClippingPlaneMgr.cxx +++ b/src/VISUGUI/VisuGUI_ClippingPlaneMgr.cxx @@ -23,12 +23,17 @@ #include "VisuGUI.h" #include "VisuGUI_Tools.h" +#include "VISU_DataSetActor.h" + #include #include #include #include #include #include +#include + +#include #include #include @@ -43,13 +48,124 @@ #include #include - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include using namespace std; +#define SIZEFACTOR 1.5 + + + + +#define PRINT3(MARK, VAL) printf("#### %s x=%f, y=%f, z=%f\n", MARK, VAL[0], VAL[1], VAL[2]); + + +void AdjustBounds(const double bounds[6], double newBounds[6], double center[3]) +{ + center[0] = (bounds[0] + bounds[1])/2.0; + center[1] = (bounds[2] + bounds[3])/2.0; + center[2] = (bounds[4] + bounds[5])/2.0; + + newBounds[0] = center[0] + SIZEFACTOR*(bounds[0]-center[0]); + newBounds[1] = center[0] + SIZEFACTOR*(bounds[1]-center[0]); + newBounds[2] = center[1] + SIZEFACTOR*(bounds[2]-center[1]); + newBounds[3] = center[1] + SIZEFACTOR*(bounds[3]-center[1]); + newBounds[4] = center[2] + SIZEFACTOR*(bounds[4]-center[2]); + newBounds[5] = center[2] + SIZEFACTOR*(bounds[5]-center[2]); +} + + + +//**************************************************************** +PreviewPlane::PreviewPlane(SVTK_ViewWindow* theWindow, const PlaneDef& thePlane, const double* theBounds): + myWindow(theWindow), + myBounds(theBounds) +{ + double aCenter[3]; + double aBound[6]; + + AdjustBounds(myBounds, aBound, aCenter); + + myPlane = thePlane.plane; + + myBox = vtkImageData::New(); + myBox->SetDimensions(2, 2, 2); + myBox->SetOrigin(aBound[0],aBound[2],aBound[4]); + myBox->SetSpacing((aBound[1]-aBound[0]), + (aBound[3]-aBound[2]), + (aBound[5]-aBound[4])); + + myCutter = vtkCutter::New(); + myCutter->SetInput(myBox); + myCutter->SetCutFunction(myPlane); + + myMapper = vtkPolyDataMapper::New(); + myMapper->SetInput(myCutter->GetOutput()); + + myActor = vtkActor::New(); + myActor->VisibilityOff(); + myActor->PickableOff(); + myActor->SetMapper(myMapper); + vtkProperty* aProp = vtkProperty::New(); + float anRGB[3]; + + SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr(); + + QColor aFillColor = aResourceMgr->colorValue("SMESH", "fill_color", QColor(0, 170, 255)); + anRGB[0] = aFillColor.red()/255.; + anRGB[1] = aFillColor.green()/255.; + anRGB[2] = aFillColor.blue()/255.; + aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]); + aProp->SetOpacity(0.75); + myActor->SetBackfaceProperty(aProp); + aProp->Delete(); + + vtkProperty* aBackProp = vtkProperty::New(); + QColor aBackFaceColor = aResourceMgr->colorValue("SMESH", "backface_color", QColor(0, 0, 255)); + anRGB[0] = aBackFaceColor.red()/255.; + anRGB[1] = aBackFaceColor.green()/255.; + anRGB[2] = aBackFaceColor.blue()/255.; + aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]); + aBackProp->SetOpacity(0.75); + myActor->SetProperty(aBackProp); + aBackProp->Delete(); + + myWindow->getRenderer()->AddActor(myActor); +} + +//**************************************************************** +PreviewPlane::~PreviewPlane() +{ + myWindow->getRenderer()->RemoveActor(myActor); + myActor->Delete(); + + myMapper->RemoveAllInputs(); + myMapper->Delete(); + myCutter->Delete(); + myBox->Delete(); +} + + + +//**************************************************************** +//**************************************************************** //**************************************************************** VisuGUI_ClippingPlaneMgr::VisuGUI_ClippingPlaneMgr(VisuGUI* theModule, SVTK_ViewWindow* theViewWindow, @@ -58,24 +174,34 @@ VisuGUI_ClippingPlaneMgr::VisuGUI_ClippingPlaneMgr(VisuGUI* theModule, myModule(theModule), myPlanes(thePlanes), myViewWindow(theViewWindow), - myCurrentPlane(-1) + myCurrentPlane(-1), + myPreviewWidget(0), + myCallback( vtkCallbackCommand::New() ), + myIsRestored(false) { + ComputeVisiblePropBounds(myViewWindow->getRenderer(), myBounds); + setWindowTitle(tr("TITLE")); setSizeGripEnabled(true); setAttribute( Qt::WA_DeleteOnClose, true ); setModal(false); + myCallback->SetClientData(this); + myCallback->SetCallback(VisuGUI_ClippingPlaneMgr::ProcessEvents); + QVBoxLayout* aMainLayout = new QVBoxLayout(this); aMainLayout->setSpacing(6); aMainLayout->setMargin(11); - QHBoxLayout* aPlanesBox = new QHBoxLayout(this); + QWidget* aPlBox = new QWidget(this); + QHBoxLayout* aPlanesBox = new QHBoxLayout(aPlBox); aPlanesBox->setMargin(6); aPlanesBox->setSizeConstraint(QLayout::SetMinimumSize); - aMainLayout->addLayout(aPlanesBox); + aMainLayout->addWidget(aPlBox); myPlanesList = new QListWidget(this); - for (int i = 0; i < myPlanes.size(); i++) + int i; + for (i = 0; i < myPlanes.size(); i++) myPlanesList->addItem(myPlanes.at(i).name); myPlanesList->setMaximumSize(160, 500); @@ -100,13 +226,9 @@ VisuGUI_ClippingPlaneMgr::VisuGUI_ClippingPlaneMgr(VisuGUI* theModule, myNameEdt = new QLineEdit(aPlanesFrame); aNameBox->addWidget(myNameEdt); - //myMethodTab = new QTabWidget(aPlanesFrame); myMethodTab = createVectorTab(aPlanesFrame); aFrameLayout->addWidget(myMethodTab); - // myMethodTab->addTab(createVectorTab(), tr("BYVECTOR_TITLE")); - // myMethodTab->addTab(createPlanesTab(), tr("BYPLANE_TITLE")); - myAutoApply = new QCheckBox(tr("CHK_AUTOAPPLY"), aPlanesFrame); aFrameLayout->addWidget(myAutoApply); @@ -122,10 +244,15 @@ VisuGUI_ClippingPlaneMgr::VisuGUI_ClippingPlaneMgr(VisuGUI* theModule, QPushButton* aDeleteBtn = new QPushButton(tr("BTN_DELETE"), this); connect(aDeleteBtn, SIGNAL(clicked()), this, SLOT(onDeletePlane())); aManageBox->addWidget(aDeleteBtn); + + QPushButton* aImportBtn = new QPushButton(tr("BTN_IMPORT"), this); + connect(aImportBtn, SIGNAL(clicked()), this, SLOT(onImportPlane())); + aManageBox->addWidget(aImportBtn); aManageBox->addStretch(); myShowPreview = new QCheckBox(tr("CHK_SHOW_PREVIEW"), this); + myShowPreview->setCheckState(Qt::Checked); aManageBox->addWidget(myShowPreview); // Dialog buttons @@ -140,27 +267,35 @@ VisuGUI_ClippingPlaneMgr::VisuGUI_ClippingPlaneMgr(VisuGUI* theModule, QPushButton* aBtnOk = new QPushButton(tr("BUT_OK"), aGroupButtons); aButtonsLayout->addWidget(aBtnOk); - QPushButton* aBtnApply = new QPushButton(tr("BUT_APPLY"), aGroupButtons); - aButtonsLayout->addWidget(aBtnApply); - aButtonsLayout->addStretch(); - QPushButton* aBtnClose = new QPushButton(tr("BUT_CLOSE"), aGroupButtons); + QPushButton* aBtnClose = new QPushButton(tr("BUT_CANCEL"), aGroupButtons); aButtonsLayout->addWidget(aBtnClose); QPushButton* aBtnHelp = new QPushButton(tr("BUT_HELP"), aGroupButtons); aButtonsLayout->addWidget(aBtnHelp); connect(aBtnOk , SIGNAL(clicked()), this, SLOT(onOk())); - connect(aBtnApply, SIGNAL(clicked()), this, SLOT(onApply())); connect(aBtnClose, SIGNAL(clicked()), this, SLOT(onClose())); connect(aBtnHelp , SIGNAL(clicked()), this, SLOT(onHelp())); + // compute preview + for (i = 0; i < myPlanes.size(); i++) { + PreviewPlane* aPreview = new PreviewPlane(myViewWindow, myPlanes.at(i), myBounds); + aPreview->setVisible(myShowPreview->checkState() == Qt::Checked); + myPreviewList.append(aPreview); + } + myViewWindow->getRenderer()->ResetCameraClippingRange(); + myViewWindow->Repaint(); + if (myPlanes.size() == 0) myMethodTab->setEnabled(false); else { myPlanesList->setCurrentRow(0); } + + // Save state of planes in actors + saveState(); } @@ -177,16 +312,19 @@ QWidget* VisuGUI_ClippingPlaneMgr::createVectorTab(QWidget* theParent) aOriginLayout->addWidget( new QLabel("X", aOriginGroup) ); myXOrigin = new QtxDoubleSpinBox( -1000.0, 1000.0, 0.1, aOriginGroup ); myXOrigin->setValue( 0.0 ); + connect(myXOrigin, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged())); aOriginLayout->addWidget( myXOrigin ); aOriginLayout->addWidget( new QLabel("Y", aOriginGroup) ); myYOrigin = new QtxDoubleSpinBox( -1000.0, 1000, 0.1, aOriginGroup ); myYOrigin->setValue( 0.0 ); + connect(myYOrigin, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged())); aOriginLayout->addWidget( myYOrigin ); aOriginLayout->addWidget( new QLabel("Z", aOriginGroup) ); myZOrigin = new QtxDoubleSpinBox( -1000.0, 1000.0, 0.1, aOriginGroup ); myZOrigin->setValue( 0.0 ); + connect(myZOrigin, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged())); aOriginLayout->addWidget( myZOrigin ); QGroupBox* aDirGroup = new QGroupBox( tr( "DIRECTION_TITLE" ), aVectorTab ); @@ -196,96 +334,142 @@ QWidget* VisuGUI_ClippingPlaneMgr::createVectorTab(QWidget* theParent) aDirLayout->addWidget( new QLabel("dX", aDirGroup) ); myXDir = new QtxDoubleSpinBox( -1000.0, 1000.0, 0.1, aDirGroup ); myXDir->setValue( 0.0 ); + connect(myXDir, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged())); aDirLayout->addWidget( myXDir ); aDirLayout->addWidget( new QLabel("dY", aDirGroup) ); myYDir = new QtxDoubleSpinBox( -1000.0, 1000.0, 0.1, aDirGroup ); myYDir->setValue( 0.0 ); + connect(myYDir, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged())); aDirLayout->addWidget( myYDir ); aDirLayout->addWidget( new QLabel("dZ", aDirGroup) ); myZDir = new QtxDoubleSpinBox( -1000.0, 1000.0, 0.1, aDirGroup ); myZDir->setValue( 0.0 ); + connect(myZDir, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged())); aDirLayout->addWidget( myZDir ); - connect(myXDir, SIGNAL(valueChanged(double)), this, SLOT(setPlaneFromVector())); - connect(myYDir, SIGNAL(valueChanged(double)), this, SLOT(setPlaneFromVector())); - connect(myZDir, SIGNAL(valueChanged(double)), this, SLOT(setPlaneFromVector())); - - return aVectorTab; } + //**************************************************************** -// QWidget* VisuGUI_ClippingPlaneMgr::createPlanesTab() -// { -// QWidget* aPlanesTab = new QWidget(myMethodTab); -// QGridLayout* aVectorTabLayout = new QGridLayout(aPlanesTab); - -// aVectorTabLayout->addWidget(new QLabel(tr("LBL_ORIENTATION"), aPlanesTab), 0, 0); -// aVectorTabLayout->addWidget(new QLabel(tr("LBL_DISTANCE"), aPlanesTab), 1, 0); - -// myPlaneCombo = new QComboBox(aPlanesTab); -// myPlaneCombo->addItem("|| X-Y"); -// myPlaneCombo->addItem("|| Y-Z"); -// myPlaneCombo->addItem("|| Z-X"); -// connect(myPlaneCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onMainPlaneSelect(int))); -// aVectorTabLayout->addWidget(myPlaneCombo, 0, 1); - -// myDistance = new QtxDoubleSpinBox( -1000, 1000, 1, aPlanesTab ); -// myDistance->setValue( 0.0 ); -// aVectorTabLayout->addWidget( myDistance, 1, 1 ); - -// myRotationXLbl = new QLabel(tr("LBL_ROTATION").arg("X"), aPlanesTab); -// aVectorTabLayout->addWidget(myRotationXLbl, 0, 2); - -// myRotX = new QtxDoubleSpinBox( -180.0, 180.0, 1, aPlanesTab ); -// myRotX->setValue( 0.0 ); -// aVectorTabLayout->addWidget( myRotX, 0, 3 ); - -// myRotationYLbl = new QLabel(tr("LBL_ROTATION").arg("Y"), aPlanesTab); -// aVectorTabLayout->addWidget(myRotationYLbl, 1, 2); - -// myRotY = new QtxDoubleSpinBox( -180.0, 180.0, 1, aPlanesTab ); -// myRotY->setValue( 0.0 ); -// aVectorTabLayout->addWidget( myRotY, 1, 3 ); - +VisuGUI_ClippingPlaneMgr::~VisuGUI_ClippingPlaneMgr() +{ + PreviewPlane* aPreview = 0; + while (myPreviewList.size() > 0) { + aPreview = myPreviewList.last(); + myPreviewList.removeLast(); + delete aPreview; + } + if (myPreviewWidget) { + myPreviewWidget->Off(); + myPreviewWidget->Delete(); + } + myPreviewWidget = 0; -// return aPlanesTab; -// } + myCallback->Delete(); +} +//**************************************************************** +void VisuGUI_ClippingPlaneMgr::saveState() +{ + myActorsMap.clear(); + vtkActorCollection* anActors = myViewWindow->getRenderer()->GetActors(); + anActors->InitTraversal(); + PlaneDef aPlane; + vtkActor* aActor; + while ( (aActor = anActors->GetNextActor()) ) { + VISU_Actor* vActor = VISU_Actor::SafeDownCast( aActor ); + if (vActor) { + VISU_DataSetActor* aDSActor = dynamic_cast(vActor); + if (aDSActor) { + ListOfvtkPlanes aList; + vtkImplicitFunctionCollection* aFunctions = aDSActor->GetClippingPlanes(); + aFunctions->InitTraversal(); + vtkImplicitFunction* aItem; + while ((aItem = aFunctions->GetNextItem())) { + for (int i = 0; i < myPlanes.size(); i++) { + aPlane = myPlanes.at(i); + if (aPlane.plane.GetPointer() == aItem) + aList.append(aPlane.plane); + } + } + myActorsMap[aDSActor] = aList; + aDSActor->RemoveAllClippingPlanes(); + } + } + } + myCopyActorsMap = myActorsMap; + myIsRestored = false; +} //**************************************************************** -VisuGUI_ClippingPlaneMgr::~VisuGUI_ClippingPlaneMgr() +void VisuGUI_ClippingPlaneMgr::deletePlaneFromActors(int thePlaneId) { + vtkPlane* aPl = myPlanes.at(thePlaneId).plane; + QList aActors = myActorsMap.keys(); + VISU_DataSetActor* aActor; + vtkPlane* aPlane; + for (int i = 0; i < aActors.size(); i++) { + aActor = aActors.at(i); + ListOfvtkPlanes& aPlanes = myActorsMap[aActor]; + for (int j = 0; j < aPlanes.size(); j++) { + aPlane = aPlanes.at(j); + if (aPlane == aPl) { + aPlanes.removeAt(j); + break; + } + } + } } + //**************************************************************** -void VisuGUI_ClippingPlaneMgr::onOk() +void VisuGUI_ClippingPlaneMgr::restoreState(const QMap& theState) { - onApply(); - onClose(); + if (myIsRestored) return; + QList aActors = theState.keys(); + VISU_DataSetActor* aActor; + vtkPlane* aPlane; + QMapIterator aIt(theState); + while (aIt.hasNext()) { + aIt.next(); + aActor = aIt.key(); + const ListOfvtkPlanes& aPlanes = aIt.value(); + for (int i = 0; i < aPlanes.size(); i++) { + aPlane = aPlanes.at(i); + aActor->AddClippingPlane(aPlane); + } + } + myIsRestored = true; } + //**************************************************************** -void VisuGUI_ClippingPlaneMgr::onApply() +void VisuGUI_ClippingPlaneMgr::onOk() { savePlane(myCurrentPlane); + restoreState(myActorsMap); emit applyPlanes(); + onClose(); } //**************************************************************** void VisuGUI_ClippingPlaneMgr::onClose() { + restoreState(myCopyActorsMap); + myViewWindow->Repaint(); close(); } //**************************************************************** void VisuGUI_ClippingPlaneMgr::onPlaneSelection(int theRow) { - if (myCurrentPlane != -1) + if (myCurrentPlane != -1) { savePlane(myCurrentPlane); + } showPlane(theRow); myCurrentPlane = theRow; } @@ -297,9 +481,55 @@ void VisuGUI_ClippingPlaneMgr::onNewPlane() setEmptyPlane(aPlane); myPlanes.append(aPlane); + PreviewPlane* aPreview = new PreviewPlane(myViewWindow, aPlane, myBounds); + aPreview->setVisible(false); + myPreviewList.append(aPreview); + myPlanesList->addItem(aPlane.name); myPlanesList->setCurrentRow(myPlanes.size() - 1); myMethodTab->setEnabled(true); + + myViewWindow->getRenderer()->ResetCameraClippingRange(); + myViewWindow->Repaint(); +} + +//**************************************************************** +vtkImplicitPlaneWidget* VisuGUI_ClippingPlaneMgr::createPreviewWidget(PlaneDef& thePlane) +{ + vtkImplicitPlaneWidget* aPlaneWgt = vtkImplicitPlaneWidget::New(); + aPlaneWgt->SetInteractor(myViewWindow->getInteractor()); + aPlaneWgt->SetPlaceFactor(SIZEFACTOR); + aPlaneWgt->ScaleEnabledOff(); + aPlaneWgt->PlaceWidget(myBounds[0],myBounds[1],myBounds[2],myBounds[3],myBounds[4],myBounds[5]); + aPlaneWgt->SetOrigin(thePlane.plane->GetOrigin()); + aPlaneWgt->SetNormal(thePlane.plane->GetNormal()); + aPlaneWgt->On(); + + //aPlaneWgt->OutlineTranslationOff(); + //aPlaneWgt->ScaleEnabledOn(); + aPlaneWgt->AddObserver(vtkCommand::InteractionEvent, + myCallback.GetPointer(), + 0.); + return aPlaneWgt; +} + +//**************************************************************** +void VisuGUI_ClippingPlaneMgr::onValueChanged() +{ + if (!myPreviewWidget) return; + double aOrigin[3]; + double aDir[3]; + aOrigin[0] = myXOrigin->value(); + aOrigin[1] = myYOrigin->value(); + aOrigin[2] = myZOrigin->value(); + + aDir[0] = myXDir->value(); + aDir[1] = myYDir->value(); + aDir[2] = myZDir->value(); + + myPreviewWidget->SetOrigin(aOrigin); + myPreviewWidget->SetNormal(aDir); + myViewWindow->Repaint(); } //**************************************************************** @@ -307,7 +537,20 @@ void VisuGUI_ClippingPlaneMgr::onDeletePlane() { if (myCurrentPlane == -1) return; disconnect(myPlanesList, SIGNAL(currentRowChanged(int)), this, SLOT(onPlaneSelection(int))); + deletePlaneFromActors(myCurrentPlane); + PlaneDef aPlane = myPlanes.at(myCurrentPlane); myPlanes.removeAt(myCurrentPlane); + //aPlane.plane->Delete(); + + PreviewPlane* aPreview = myPreviewList.at(myCurrentPlane); + myPreviewList.removeAt(myCurrentPlane); + delete aPreview; + if (myPreviewWidget) { + myPreviewWidget->Off(); + myPreviewWidget->Delete(); + myPreviewWidget = 0; + } + myPlanesList->takeItem(myCurrentPlane); if (myPlanes.size() == 0) myCurrentPlane = -1; @@ -319,6 +562,8 @@ void VisuGUI_ClippingPlaneMgr::onDeletePlane() myPlanesList->setCurrentRow(myCurrentPlane); connect(myPlanesList, SIGNAL(currentRowChanged(int)), this, SLOT(onPlaneSelection(int))); myMethodTab->setEnabled(myPlanes.size() > 0); + myViewWindow->getRenderer()->ResetCameraClippingRange(); + myViewWindow->Repaint(); } //**************************************************************** @@ -326,133 +571,121 @@ void VisuGUI_ClippingPlaneMgr::savePlane(int thePlaneNb) { if (thePlaneNb < 0) return; if (myPlanes.size() <= thePlaneNb) return; - PlaneDef aPlane; + PlaneDef aPlane = myPlanes.at(thePlaneNb); aPlane.name = myNameEdt->text(); - aPlane.origin[0] = myXOrigin->value(); - aPlane.origin[1] = myYOrigin->value(); - aPlane.origin[2] = myZOrigin->value(); + aPlane.plane->SetOrigin(myXOrigin->value(), + myYOrigin->value(), + myZOrigin->value()); - aPlane.direction[0] = myXDir->value(); - aPlane.direction[1] = myYDir->value(); - aPlane.direction[2] = myZDir->value(); + aPlane.plane->SetNormal(myXDir->value(), + myYDir->value(), + myZDir->value()); aPlane.isAuto = (myAutoApply->checkState() == Qt::Checked); myPlanesList->item(thePlaneNb)->setText(aPlane.name); myPlanes.replace(thePlaneNb, aPlane); + + myPreviewList.at(myCurrentPlane)->setVisible(myShowPreview->checkState() == Qt::Checked); + myViewWindow->getRenderer()->ResetCameraClippingRange(); + myViewWindow->Repaint(); } //**************************************************************** -void VisuGUI_ClippingPlaneMgr::showPlane(int thePlaneNb) const +void VisuGUI_ClippingPlaneMgr::showPlane(int thePlaneNb) { if (myPlanes.size() <= thePlaneNb) return; PlaneDef aNullPlane; setEmptyPlane(aNullPlane); - const PlaneDef& aPlane = (thePlaneNb < 0)? aNullPlane : myPlanes.at(thePlaneNb); + PlaneDef aPlane = (thePlaneNb < 0)? aNullPlane : myPlanes.at(thePlaneNb); myNameEdt->setText(aPlane.name); - myXOrigin->setValue(aPlane.origin[0]); - myYOrigin->setValue(aPlane.origin[1]); - myZOrigin->setValue(aPlane.origin[2]); - - myXDir->setValue(aPlane.direction[0]); - myYDir->setValue(aPlane.direction[1]); - myZDir->setValue(aPlane.direction[2]); + double aOrigin[3]; + aPlane.plane->GetOrigin(aOrigin); + myXOrigin->setValue(aOrigin[0]); + myYOrigin->setValue(aOrigin[1]); + myZOrigin->setValue(aOrigin[2]); + + double aDir[3]; + aPlane.plane->GetNormal(aDir); + myXDir->setValue(aDir[0]); + myYDir->setValue(aDir[1]); + myZDir->setValue(aDir[2]); myAutoApply->setCheckState(aPlane.isAuto? Qt::Checked : Qt::Unchecked); + + if (myPreviewWidget) { + myPreviewWidget->Off(); + myPreviewWidget->Delete(); + myPreviewWidget = 0; + } + if (thePlaneNb > -1) { + myPreviewList.at(thePlaneNb)->setVisible(false); + myPreviewWidget = createPreviewWidget(aPlane); + } } //**************************************************************** void VisuGUI_ClippingPlaneMgr::setEmptyPlane(PlaneDef& thePlane) const { thePlane.name = QString("Plane %1").arg(myPlanes.size()); - thePlane.origin[0] = 0.; - thePlane.origin[1] = 0.; - thePlane.origin[2] = 0.; - thePlane.direction[0] = 0.; - thePlane.direction[1] = 0.; - thePlane.direction[2] = 1.; + thePlane.plane = vtkPlane::New(); + thePlane.plane->Delete(); + thePlane.plane->SetOrigin(0.,0.,0.); + thePlane.plane->SetNormal(0.,0.,1.); thePlane.isAuto = false; + thePlane.isOn = false; } //**************************************************************** -//! returns number of main plane in the list myPlaneCombo. -//! If values are not correct returns -1 -// int VisuGUI_ClippingPlaneMgr::getMainPlane() -// { -// double aDir[3] = { myXDir->value(), myYDir->value(), myZDir->value() }; -// int aMainPlane = -1; -// if (vtkMath::Normalize(aDir) == 0) -// return aMainPlane; - -// //printf("#### Res x=%f, y=%f, z=%f\n", aDir[0], aDir[1], aDir[2]); -// double aLimit = cos(vtkMath::DegreesToRadians()*45.); -// //printf("#### Limit = %f\n", aLimit); -// if (fabs(aDir[0]) > aLimit) // Plane is Y-Z -// aMainPlane = 1; -// else if (fabs(aDir[1]) > aLimit) // Plane is X-Z -// aMainPlane = 2; -// else if (fabs(aDir[2]) > aLimit) // Plane is X-Z -// aMainPlane = 0; - -// //printf("#### Plane = %i\n", aMainPlane); -// return aMainPlane; -// } +void VisuGUI_ClippingPlaneMgr::ProcessEvents(vtkObject* theObject, + unsigned long theEvent, + void* theClientData, + void* vtkNotUsed(theCallData)) +{ + vtkImplicitPlaneWidget* aWidget = vtkImplicitPlaneWidget::SafeDownCast(theObject); + if (aWidget == NULL) return; + if (theClientData == NULL) return; + + VisuGUI_ClippingPlaneMgr* aDlg = (VisuGUI_ClippingPlaneMgr*) theClientData; + + double aOrigin[3]; + double aDir[3]; + + switch(theEvent){ + case vtkCommand::InteractionEvent: + aWidget->GetOrigin(aOrigin); + aWidget->GetNormal(aDir); + + aDlg->setOrigin(aOrigin); + aDlg->setDirection(aDir); + + break; + } +} //**************************************************************** -//! Compute parameters of main planes pane from vector pane -// void VisuGUI_ClippingPlaneMgr::setPlaneFromVector() -// { -// int aPlaneIndex = getMainPlane(); -// if (aPlaneIndex == -1) return; -// myPlaneCombo->setCurrentIndex(aPlaneIndex); - -// double aDir[3] = { myXDir->value(), myYDir->value(), myZDir->value() }; -// vtkMath::Normalize(aDir); -// printf("#### Res x=%f, y=%f, z=%f\n", aDir[0], aDir[1], aDir[2]); - -// double aCoef = vtkMath::RadiansToDegrees(); -// switch (aPlaneIndex) { -// case 0: // || X-Y -// myRotX->setValue(asin(myYDir->value()) * aCoef); -// myRotY->setValue(asin(myXDir->value()) * aCoef); -// break; -// case 1: // || Y-Z -// myRotX->setValue(asin(myZDir->value()) * aCoef); -// myRotY->setValue(asin(myYDir->value()) * aCoef); -// break; -// case 2: // || Z-X -// myRotX->setValue(asin(myXDir->value()) * aCoef); -// myRotY->setValue(asin(myZDir->value()) * aCoef); -// break; -// } -// double aOrigin[3] = { myXOrigin->value(), myYOrigin->value(), myZOrigin->value() }; -// } +void VisuGUI_ClippingPlaneMgr::setOrigin(double theVal[3]) +{ + myXOrigin->setValue(theVal[0]); + myYOrigin->setValue(theVal[1]); + myZOrigin->setValue(theVal[2]); +} //**************************************************************** -//! Compute parameters of vector pane from main planes pane -// void VisuGUI_ClippingPlaneMgr::setPlaneFromMPlane() -// { -// } +void VisuGUI_ClippingPlaneMgr::setDirection(double theVal[3]) +{ + myXDir->setValue(theVal[0]); + myYDir->setValue(theVal[1]); + myZDir->setValue(theVal[2]); +} + //**************************************************************** -// void VisuGUI_ClippingPlaneMgr::onMainPlaneSelect(int theIndex) -// { -// switch (theIndex) { -// case 0: // || X-Y -// myRotationXLbl->setText( tr("LBL_ROTATION").arg("X") ); -// myRotationXLbl->setText( tr("LBL_ROTATION").arg("Y") ); -// break; -// case 1: // || Y-Z -// myRotationXLbl->setText( tr("LBL_ROTATION").arg("Y") ); -// myRotationXLbl->setText( tr("LBL_ROTATION").arg("Z") ); -// break; -// case 2: // || Z-X -// myRotationXLbl->setText( tr("LBL_ROTATION").arg("Z") ); -// myRotationXLbl->setText( tr("LBL_ROTATION").arg("X") ); -// break; -// } -// } +void VisuGUI_ClippingPlaneMgr::onImportPlane() +{ +} + //**************************************************************** void VisuGUI_ClippingPlaneMgr::onHelp() diff --git a/src/VISUGUI/VisuGUI_ClippingPlaneMgr.h b/src/VISUGUI/VisuGUI_ClippingPlaneMgr.h index 319863cd..0163b370 100644 --- a/src/VISUGUI/VisuGUI_ClippingPlaneMgr.h +++ b/src/VISUGUI/VisuGUI_ClippingPlaneMgr.h @@ -31,10 +31,45 @@ class QTabWidget; class QLabel; class QComboBox; class QCheckBox; +class PreviewPlane; +class vtkImplicitPlaneWidget; +class vtkCallbackCommand; +class vtkPolyDataMapper; +class vtkImageData; +class vtkCutter; + +class VISU_DataSetActor; #include #include +#include +#include + +class PreviewPlane +{ +public: + PreviewPlane(SVTK_ViewWindow* theWindow, const PlaneDef& thePlane, const double* theBounds); + ~PreviewPlane(); + + void setVisible(bool theVisible) + { myActor->SetVisibility(theVisible); } + + //void setPlane(const PlaneDef& thePlane); + +private: + SVTK_ViewWindow* myWindow; + + //SALOME_Actor* myActor; + vtkActor* myActor; + vtkPolyDataMapper* myMapper; + const double* myBounds; + vtkPlane* myPlane; + vtkImageData* myBox; + vtkCutter* myCutter; +}; + + class VisuGUI_ClippingPlaneMgr : public QDialog { @@ -49,41 +84,44 @@ public: const QListOfPlanes& getPlanes() const { return myPlanes; } SVTK_ViewWindow* getViewWindow() const { return myViewWindow; } + + void setOrigin(double theVal[3]); + void setDirection(double theVal[3]); + + signals: void applyPlanes(); private slots: void onOk(); - void onApply(); void onClose(); void onHelp(); void onPlaneSelection(int theRow); void onNewPlane(); void onDeletePlane(); - //! Compute parameters of main planes pane from vector pane - //void setPlaneFromVector(); - //! Compute parameters of vector pane from main planes pane - //void setPlaneFromMPlane(); - - //void onMainPlaneSelect(int); + void onValueChanged(); + void onImportPlane(); private: QWidget* createVectorTab(QWidget* theParent); - //QWidget* createPlanesTab(); void savePlane(int thePlaneNb); - void showPlane(int thePlaneNb) const; + void showPlane(int thePlaneNb); void setEmptyPlane(PlaneDef& thePlane) const; - //! returns number of main plane in the list myPlaneCombo. - //! If values are not correct returns -1 - //int getMainPlane(); + vtkImplicitPlaneWidget* createPreviewWidget(PlaneDef& thePlane); + + static void ProcessEvents(vtkObject* theObject, unsigned long theEvent, + void* theClientData, void* theCallData); + + void saveState(); + void deletePlaneFromActors(int thePlaneId); + void restoreState(const QMap& theState); QListWidget* myPlanesList; QLineEdit* myNameEdt; VisuGUI* myModule; - //QTabWidget* myMethodTab; QWidget* myMethodTab; QtxDoubleSpinBox* myXOrigin; @@ -94,20 +132,25 @@ private slots: QtxDoubleSpinBox* myYDir; QtxDoubleSpinBox* myZDir; - //QLabel* myRotationXLbl; - //QLabel* myRotationYLbl; - - //QComboBox* myPlaneCombo; - //QtxDoubleSpinBox* myDistance; - //QtxDoubleSpinBox* myRotX; - //QtxDoubleSpinBox* myRotY; - QCheckBox* myAutoApply; QCheckBox* myShowPreview; QListOfPlanes myPlanes; SVTK_ViewWindow* myViewWindow; int myCurrentPlane; + + QList myPreviewList; + vtkImplicitPlaneWidget* myPreviewWidget; + + vtkSmartPointer myCallback; + + //Stores Actors and Ids of applied planes (position in myPlanes) + QMap myActorsMap; + QMap myCopyActorsMap; + + bool myIsRestored; + + double myBounds[6]; }; #endif diff --git a/src/VISUGUI/VisuGUI_SegmentationMgr.cxx b/src/VISUGUI/VisuGUI_SegmentationMgr.cxx index aeb4db90..5c1981cc 100644 --- a/src/VISUGUI/VisuGUI_SegmentationMgr.cxx +++ b/src/VISUGUI/VisuGUI_SegmentationMgr.cxx @@ -30,14 +30,21 @@ #include +#include +#include +#include + +//**************************************************************** VisuGUI_SegmentationMgr::VisuGUI_SegmentationMgr(VisuGUI* theModule) { } +//**************************************************************** VisuGUI_SegmentationMgr::~VisuGUI_SegmentationMgr() { } +//**************************************************************** const QListOfPlanes& VisuGUI_SegmentationMgr::getPlanes(SVTK_ViewWindow* theWindow) { if (!myViewPlanesMap.contains(theWindow)) { @@ -47,20 +54,48 @@ const QListOfPlanes& VisuGUI_SegmentationMgr::getPlanes(SVTK_ViewWindow* theWind return myViewPlanesMap[theWindow]; } +//**************************************************************** void VisuGUI_SegmentationMgr::setPlanes(SVTK_ViewWindow* theWindow, const QListOfPlanes& theNewPlanes) { + myViewPlanesMap.remove(theWindow); myViewPlanesMap[theWindow] = theNewPlanes; + + vtkActorCollection* anActors = theWindow->getRenderer()->GetActors(); + anActors->InitTraversal(); + vtkActor* aActor = 0; + VISU_Actor* aVisuActor = 0; + while ( (aActor = anActors->GetNextActor()) ) { + aVisuActor = VISU_Actor::SafeDownCast(aActor); + if (aVisuActor) { + applyPlanes(theWindow, aVisuActor, true); + } + } } -void VisuGUI_SegmentationMgr::onAddActor(SVTK_ViewWindow*, VTKViewer_Actor*) +//**************************************************************** +void VisuGUI_SegmentationMgr::onAddActor(SVTK_ViewWindow* theWindow, VTKViewer_Actor* theActor) { - printf("#### onAddActor\n"); + VISU_Actor* aActor = VISU_Actor::SafeDownCast(theActor); + if (!aActor) return; + applyPlanes(theWindow, aActor, true); } +//**************************************************************** +void VisuGUI_SegmentationMgr::applyPlanes(SVTK_ViewWindow* theWindow, VISU_Actor* theActor, bool theAuto) +{ + const QListOfPlanes& aPlanes = getPlanes(theWindow); + for (int i = 0; i < aPlanes.size(); i++) { + PlaneDef aPlane = aPlanes.at(i); + if ((theAuto)? aPlane.isAuto : aPlane.isOn) { + theActor->AddClippingPlane(aPlane.plane); + } + } + theWindow->Repaint(); +} +//**************************************************************** void VisuGUI_SegmentationMgr::onViewDeleted(SUIT_ViewWindow* theWindow) { - printf("#### onViewDeleted\n"); SVTK_ViewWindow* aWindow = dynamic_cast(theWindow); if (aWindow) { if (myViewPlanesMap.contains(aWindow)) diff --git a/src/VISUGUI/VisuGUI_SegmentationMgr.h b/src/VISUGUI/VisuGUI_SegmentationMgr.h index 2e34b516..7cc51f40 100644 --- a/src/VISUGUI/VisuGUI_SegmentationMgr.h +++ b/src/VISUGUI/VisuGUI_SegmentationMgr.h @@ -27,6 +27,7 @@ #ifndef VisuGUI_SegmentationMgr_HeaderFile #define VisuGUI_SegmentationMgr_HeaderFile + #include "VisuGUI_ClippingDlg.h" #include @@ -35,18 +36,25 @@ #include #include +class VISU_Actor; +class vtkPlane; + -struct PlaneDef +struct PlaneDef { - double origin[3]; - double direction[3]; + // PlaneDef() { + // plane = 0; + //} + //~PlaneDef() { if (plane) plane->DebugOn();} + vtkSmartPointer plane; bool isAuto; QString name; + bool isOn; }; typedef QList QListOfPlanes; - +typedef QList ListOfvtkPlanes; class VisuGUI_SegmentationMgr: public QObject { @@ -64,6 +72,8 @@ private slots: void onViewDeleted(SUIT_ViewWindow*); private: + void applyPlanes(SVTK_ViewWindow* theWindow, VISU_Actor* theActor, bool theAuto); + QMap myViewPlanesMap; }; diff --git a/src/VISUGUI/VisuGUI_ViewExtender.cxx b/src/VISUGUI/VisuGUI_ViewExtender.cxx index 67eb0d24..37bcce55 100644 --- a/src/VISUGUI/VisuGUI_ViewExtender.cxx +++ b/src/VISUGUI/VisuGUI_ViewExtender.cxx @@ -33,15 +33,21 @@ #include "VisuGUI.h" #include "VisuGUI_SegmentationMgr.h" #include "VisuGUI_ViewTools.h" +#include "VisuGUI_Tools.h" +#include #include #include #include #include +#include +#include #include #include #include +#include + //using namespace std; @@ -64,11 +70,13 @@ VisuGUI_ViewExtender::VisuGUI_ViewExtender(VisuGUI* theModule): myActionsMap[ClippingPlaneMgrId] = aAction; } +//**************************************************************** VisuGUI_ViewExtender::~VisuGUI_ViewExtender() { delete mySegmentationMgr; } +//**************************************************************** int VisuGUI_ViewExtender::createToolbar(QtxActionToolMgr* theMgr) { int aToolBar = theMgr->createToolBar( tr("VISU_VIEW_TOOLBAR")); @@ -76,11 +84,23 @@ int VisuGUI_ViewExtender::createToolbar(QtxActionToolMgr* theMgr) return aToolBar; } +//**************************************************************** void VisuGUI_ViewExtender::contextMenuPopup(QMenu* theMenu) { - printf("#### contextMenuPopup\n"); +// SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow(myModule); +// if (!aViewWindow) return; + +// SalomeApp_Application* anApp = myModule->getApp(); +// LightApp_SelectionMgr* aSelectionMgr = VISU::GetSelectionMgr(myModule); +// myListIO.Clear(); +// aSelectionMgr->selectedObjects(myListIO); +// if (myListIO.IsEmpty()) return; + +// theMenu->addSeparator(); +// theMenu->addAction(tr("VISU_SETPLANES_MNU"), this, SLOT(onSetPlanes())); } +//**************************************************************** void VisuGUI_ViewExtender::onPlanesMgr() { if (myNonModalDlg) return; @@ -97,6 +117,7 @@ void VisuGUI_ViewExtender::onPlanesMgr() myNonModalDlg->show(); } +//**************************************************************** void VisuGUI_ViewExtender::activate(SUIT_ViewModel* theViewer) { // Connect to signal on destroy ViewWindow @@ -113,6 +134,7 @@ void VisuGUI_ViewExtender::activate(SUIT_ViewModel* theViewer) } } +//**************************************************************** void VisuGUI_ViewExtender::deactivate(SUIT_ViewModel*) { if (myNonModalDlg) { @@ -121,14 +143,18 @@ void VisuGUI_ViewExtender::deactivate(SUIT_ViewModel*) } } +//**************************************************************** void VisuGUI_ViewExtender::onDialogDestroy() { disconnect(myNonModalDlg, SIGNAL( destroyed(QObject*) ), this, SLOT( onDialogDestroy() )); myNonModalDlg = 0; + } +//**************************************************************** void VisuGUI_ViewExtender::onApplyPlanes() { VisuGUI_ClippingPlaneMgr* aDlg = (VisuGUI_ClippingPlaneMgr*) myNonModalDlg; mySegmentationMgr->setPlanes(aDlg->getViewWindow(), aDlg->getPlanes()); } + diff --git a/src/VISUGUI/VisuGUI_ViewExtender.h b/src/VISUGUI/VisuGUI_ViewExtender.h index 909c0f31..39b68be1 100644 --- a/src/VISUGUI/VisuGUI_ViewExtender.h +++ b/src/VISUGUI/VisuGUI_ViewExtender.h @@ -30,6 +30,7 @@ #define VisuGUI_ViewExtender_HeaderFile #include +#include #include #include @@ -55,6 +56,9 @@ class VisuGUI_ViewExtender: public QObject, public CAM_ViewExtender virtual void activate(SUIT_ViewModel*); virtual void deactivate(SUIT_ViewModel*); + VisuGUI_SegmentationMgr* getSegmentationMgr() const { return mySegmentationMgr; } + + private slots: void onPlanesMgr(); void onDialogDestroy(); @@ -71,6 +75,9 @@ private slots: VisuGUI_SegmentationMgr* mySegmentationMgr; QList myViewers; + + SALOME_ListIO myListIO; + }; -- 2.39.2