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<class TData> std::string getScalar(TData* theData, int theId)
{
class vtkCallbackCommand;
class VTKViewer_ShrinkFilter;
class VISU_PipeLine;
+class vtkPlane;
class VISU_FramedTextActor;
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
#include <vtkDataSetMapper.h>
#include <vtkObjectFactory.h>
+#include <vtkImplicitBoolean.h>
+#include <SALOME_ExtractGeometry.h>
+#include <vtkImplicitFunctionCollection.h>
+#include <vtkPlane.h>
#include <boost/bind.hpp>
//----------------------------------------------------------------------------
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 = "<<this);
+ myExtractor->SetImplicitFunction(myFunction);
+ //myExtractor->ExtractBoundaryCellsOn();
+ myFunction->SetOperationTypeToIntersection();
+
myMapper->Delete();
+ myExtractor->Delete();
+ myFunction->Delete();
}
//----------------------------------------------------------------------------
if(VISU_UnstructuredGridPL* aPipeLine = dynamic_cast<VISU_UnstructuredGridPL*>(thePipeLine)){
vtkDataSetMapper* aTarget = GetDataSetMapper();
- vtkDataSetMapper* aSource = aPipeLine->GetDataSetMapper();
+ vtkDataSetMapper* aSource = aPipeLine->GetDataSetMapper();
VISU::CopyDataSetMapper(aTarget, aSource, true);
- aTarget->SetLookupTable(aSource->GetLookupTable());
}
}
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<vtkPlane*>(aFun);
+ }
+ return aPlane;
+}
+
+//----------------------------------------------------------------------------
+vtkImplicitFunctionCollection* VISU_DataSetActor::GetClippingPlanes()
+{
+ return myFunction->GetFunction();
+}
#include "VISU_Actor.h"
class vtkDataSetMapper;
+class SALOME_ExtractGeometry;
+class vtkImplicitBoolean;
+class vtkImplicitFunctionCollection;
#ifdef _WIN_32
#define VTKOCC_EXPORT __declspec (dllexport)
vtkDataSetMapper*
GetDataSetMapper();
+ //----------------------------------------------------------------------------
+ virtual void RemoveAllClippingPlanes();
+
+ virtual vtkIdType GetNumberOfClippingPlanes();
+
+ virtual bool AddClippingPlane(vtkPlane* thePlane);
+
+ virtual vtkPlane* GetClippingPlane(vtkIdType theID);
+
+ virtual vtkImplicitFunctionCollection* GetClippingPlanes();
+
//----------------------------------------------------------------------------
protected:
VISU_DataSetActor();
//----------------------------------------------------------------------------
vtkSmartPointer<vtkDataSetMapper> myMapper;
+ vtkSmartPointer<SALOME_ExtractGeometry> myExtractor;
+ vtkSmartPointer<vtkImplicitBoolean> myFunction;
};
#endif //VISU_DATASETACTOR_H
#include "VISU_DeformedShapePL.hxx"
#include "VISU_PipeLineUtils.hxx"
+#include <SALOME_ExtractGeometry.h>
+
#include <vtkObjectFactory.h>
#include <vtkRenderer.h>
#include <vtkProperty.h>
VISU_ScalarMapAct
::ShallowCopyPL(VISU_PipeLine* thePipeLine)
{
- VISU_Actor::ShallowCopyPL( thePipeLine );
+ VISU_DataSetActor::ShallowCopyPL( thePipeLine );
myEdgeActor->GetMapper()->ScalarVisibilityOff();
{
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() );
}
//----------------------------------------------------------------------------
<translation>Impossible to use given clipping planes because of VTK restrictions.
Please, provide non-empty resulting presentation.</translation>
</message>
+ <message>
+ <source>GRP_TYPE</source>
+ <translation>Type of plane</translation>
+ </message>
+ <message>
+ <source>GLOBAL_BTN</source>
+ <translation>Global planes</translation>
+ </message>
+ <message>
+ <source>LOCAL_BTN</source>
+ <translation>Local planes</translation>
+ </message>
+ <message>
+ <source>GRP_VIEWER_PLANES</source>
+ <translation>Planes defined in viewer</translation>
+ </message>
</context>
<context>
<name>VisuGUI_CubeAxesDlg</name>
<source>BTN_DELETE</source>
<translation>Delete</translation>
</message>
+ <message>
+ <source>BTN_IMPORT</source>
+ <translation>Import...</translation>
+ </message>
</context>
<context>
<name>VisuGUI_ViewExtender</name>
<source>VISU_VIEW_TOOLBAR</source>
<translation>VISU tools</translation>
</message>
+ <message>
+ <source>VISU_SETPLANES_MNU</source>
+ <translation>Set clipping plane...</translation>
+ </message>
</context>
</TS>
#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 <VTKViewer_Utilities.h>
#include "SUIT_Session.h"
#include "SUIT_Desktop.h"
#include "SUIT_OverrideCursor.h"
#include "SALOME_Actor.h"
+#include "VISU_ViewManager_i.hh"
// QT Includes
#include <QLabel>
#include <QSpinBox>
#include <QKeyEvent>
#include <QPushButton>
+#include <QListWidget>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QStackedWidget>
// VTK Includes
#include <vtkMath.h>
#include <vtkPolyData.h>
#include <vtkUnstructuredGrid.h>
#include <vtkProperty.h>
+#include <vtkImplicitFunctionCollection.h>
// OCCT Includes
#include <gp_Dir.hxx>
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);
// 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() );
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);
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);
SpinBoxDistance->setValue(0.5);
+ initGlobalPlanes();
+
onSelectionChanged();
// signals and slots connections :
//=================================================================================
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));
// 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;
}
}
+
+//=================================================================================
+// function : applyGlobalPlanes()
+// purpose :
+//=================================================================================
+void VisuGUI_ClippingDlg::applyGlobalPlanes()
+{
+ if (!myDSActor) return;
+
+ VisuGUI_ViewExtender* aVisuExtender = dynamic_cast<VisuGUI_ViewExtender*>(myVisuGUI->getViewExtender());
+ SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(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 :
}
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);
//=================================================================================
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<SVTK_ViewWindow>(myVisuGUI))
VISU::RenderViewWindow(vw);
}
} else
return;
}
+
+//=================================================================================
+// function : hasGlobalPlanes()
+// purpose :
+//=================================================================================
+bool VisuGUI_ClippingDlg::hasGlobalPlanes()
+{
+ VisuGUI_ViewExtender* aVisuExtender = dynamic_cast<VisuGUI_ViewExtender*>(myVisuGUI->getViewExtender());
+ if (!aVisuExtender) return false;
+
+ SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(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<VisuGUI_ViewExtender*>(myVisuGUI->getViewExtender());
+ SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(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<SVTK_ViewWindow>(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<VISU::Prs3d_i*>(aBase);
+ if (!aPrs) return 0;
+
+ VISU_Actor* aActor = VISU::FindActor(aViewWindow, aPrs);
+ if (!aActor) return 0;
+
+ VISU_DataSetActor* aDSActor = dynamic_cast<VISU_DataSetActor*>(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<SVTK_ViewWindow>(myVisuGUI));
+}
class QButtonGroup;
class QSpinBox;
class QTabWidget;
+class QListWidget;
class SALOME_Actor;
class LightApp_SelectionMgr;
class VisuGUI;
-
class vtkPlaneSource;
class vtkDataSetMapper;
-
class OrientedPlane;
+class VISU_DataSetActor;
+class PreviewPlane;
namespace VISU {
class Prs3d_i;
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:
bool myIsSelectPlane;
+ QButtonGroup* myPlaneTypeGrp;
+ QListWidget* myGlobalPlanes;
+ bool myHasGlobalPl;
+ VISU_DataSetActor* myDSActor;
+ QList<PreviewPlane*> myPreviewList;
+
protected:
QWidget* createParamsTab();
QWidget* createIJKParamsTab();
void ClickOnCancel();
void ClickOnApply();
void ClickOnHelp();
+ void onPlaneCheck();
+ void onPlaneType(int);
};
#endif // DIALOGBOX_TRANSPARENCYDLG_H
#include "VisuGUI.h"
#include "VisuGUI_Tools.h"
+#include "VISU_DataSetActor.h"
+
#include <LightApp_Application.h>
#include <SUIT_Desktop.h>
#include <SUIT_Session.h>
#include <SUIT_MessageBox.h>
#include <SUIT_ResourceMgr.h>
#include <QtxDoubleSpinBox.h>
+#include <SALOME_Actor.h>
+
+#include <VTKViewer_Utilities.h>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <vtkMath.h>
-
+#include <vtkPlaneSource.h>
+#include <vtkDataSetMapper.h>
+#include <vtkProperty.h>
+#include <vtkRenderer.h>
+#include <vtkImplicitPlaneWidget.h>
+#include <vtkGlyph3D.h>
+#include <vtkCallbackCommand.h>
+#include <vtkImageData.h>
+#include <vtkCutter.h>
+#include <vtkPolyDataMapper.h>
+#include <vtkActorCollection.h>
+#include <vtkActor.h>
+#include <vtkPlane.h>
+#include <vtkImplicitFunction.h>
+#include <vtkImplicitFunctionCollection.h>
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,
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);
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);
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
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();
}
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 );
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<VISU_DataSetActor*>(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<VISU_DataSetActor*> 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<VISU_DataSetActor*, ListOfvtkPlanes>& theState)
{
- onApply();
- onClose();
+ if (myIsRestored) return;
+ QList<VISU_DataSetActor*> aActors = theState.keys();
+ VISU_DataSetActor* aActor;
+ vtkPlane* aPlane;
+ QMapIterator<VISU_DataSetActor*, ListOfvtkPlanes> 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;
}
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();
}
//****************************************************************
{
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;
myPlanesList->setCurrentRow(myCurrentPlane);
connect(myPlanesList, SIGNAL(currentRowChanged(int)), this, SLOT(onPlaneSelection(int)));
myMethodTab->setEnabled(myPlanes.size() > 0);
+ myViewWindow->getRenderer()->ResetCameraClippingRange();
+ myViewWindow->Repaint();
}
//****************************************************************
{
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()
class QLabel;
class QComboBox;
class QCheckBox;
+class PreviewPlane;
+class vtkImplicitPlaneWidget;
+class vtkCallbackCommand;
+class vtkPolyDataMapper;
+class vtkImageData;
+class vtkCutter;
+
+class VISU_DataSetActor;
#include <QDialog>
#include <VisuGUI_SegmentationMgr.h>
+#include <vtkSmartPointer.h>
+#include <vtkActor.h>
+
+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
{
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<VISU_DataSetActor*, ListOfvtkPlanes>& theState);
QListWidget* myPlanesList;
QLineEdit* myNameEdt;
VisuGUI* myModule;
- //QTabWidget* myMethodTab;
QWidget* myMethodTab;
QtxDoubleSpinBox* myXOrigin;
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<PreviewPlane*> myPreviewList;
+ vtkImplicitPlaneWidget* myPreviewWidget;
+
+ vtkSmartPointer<vtkCallbackCommand> myCallback;
+
+ //Stores Actors and Ids of applied planes (position in myPlanes)
+ QMap<VISU_DataSetActor*, ListOfvtkPlanes> myActorsMap;
+ QMap<VISU_DataSetActor*, ListOfvtkPlanes> myCopyActorsMap;
+
+ bool myIsRestored;
+
+ double myBounds[6];
};
#endif
#include <SVTK_ViewModel.h>
+#include <VISU_PipeLine.hxx>
+#include <VISU_Actor.h>
+#include <vtkRenderer.h>
+
+//****************************************************************
VisuGUI_SegmentationMgr::VisuGUI_SegmentationMgr(VisuGUI* theModule)
{
}
+//****************************************************************
VisuGUI_SegmentationMgr::~VisuGUI_SegmentationMgr()
{
}
+//****************************************************************
const QListOfPlanes& VisuGUI_SegmentationMgr::getPlanes(SVTK_ViewWindow* theWindow)
{
if (!myViewPlanesMap.contains(theWindow)) {
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<SVTK_ViewWindow*>(theWindow);
if (aWindow) {
if (myViewPlanesMap.contains(aWindow))
#ifndef VisuGUI_SegmentationMgr_HeaderFile
#define VisuGUI_SegmentationMgr_HeaderFile
+
#include "VisuGUI_ClippingDlg.h"
#include <SVTK_ViewWindow.h>
#include <QMap>
#include <QList>
+class VISU_Actor;
+class vtkPlane;
+
-struct PlaneDef
+struct PlaneDef
{
- double origin[3];
- double direction[3];
+ // PlaneDef() {
+ // plane = 0;
+ //}
+ //~PlaneDef() { if (plane) plane->DebugOn();}
+ vtkSmartPointer<vtkPlane> plane;
bool isAuto;
QString name;
+ bool isOn;
};
typedef QList<PlaneDef> QListOfPlanes;
-
+typedef QList<vtkPlane*> ListOfvtkPlanes;
class VisuGUI_SegmentationMgr: public QObject
{
void onViewDeleted(SUIT_ViewWindow*);
private:
+ void applyPlanes(SVTK_ViewWindow* theWindow, VISU_Actor* theActor, bool theAuto);
+
QMap<SVTK_ViewWindow*, QListOfPlanes> myViewPlanesMap;
};
#include "VisuGUI.h"
#include "VisuGUI_SegmentationMgr.h"
#include "VisuGUI_ViewTools.h"
+#include "VisuGUI_Tools.h"
+#include <VISU_PipeLine.hxx>
#include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
#include <SUIT_ViewManager.h>
#include <SVTK_ViewModel.h>
+#include <LightApp_SelectionMgr.h>
+#include <SalomeApp_Application.h>
#include <QtxAction.h>
#include <QtxActionToolMgr.h>
#include <QDialog>
+#include <QMenu>
+
//using namespace std;
myActionsMap[ClippingPlaneMgrId] = aAction;
}
+//****************************************************************
VisuGUI_ViewExtender::~VisuGUI_ViewExtender()
{
delete mySegmentationMgr;
}
+//****************************************************************
int VisuGUI_ViewExtender::createToolbar(QtxActionToolMgr* theMgr)
{
int aToolBar = theMgr->createToolBar( tr("VISU_VIEW_TOOLBAR"));
return aToolBar;
}
+//****************************************************************
void VisuGUI_ViewExtender::contextMenuPopup(QMenu* theMenu)
{
- printf("#### contextMenuPopup\n");
+// SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(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;
myNonModalDlg->show();
}
+//****************************************************************
void VisuGUI_ViewExtender::activate(SUIT_ViewModel* theViewer)
{
// Connect to signal on destroy ViewWindow
}
}
+//****************************************************************
void VisuGUI_ViewExtender::deactivate(SUIT_ViewModel*)
{
if (myNonModalDlg) {
}
}
+//****************************************************************
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());
}
+
#define VisuGUI_ViewExtender_HeaderFile
#include <CAM_ViewExtender.h>
+#include <SALOME_ListIO.hxx>
#include <QObject>
#include <QMap>
virtual void activate(SUIT_ViewModel*);
virtual void deactivate(SUIT_ViewModel*);
+ VisuGUI_SegmentationMgr* getSegmentationMgr() const { return mySegmentationMgr; }
+
+
private slots:
void onPlanesMgr();
void onDialogDestroy();
VisuGUI_SegmentationMgr* mySegmentationMgr;
QList<SVTK_Viewer*> myViewers;
+
+ SALOME_ListIO myListIO;
+
};