diff --git a/smtk/bridge/polygon/plugin/qtPolygonEdgeOperationView.cxx b/smtk/bridge/polygon/plugin/qtPolygonEdgeOperationView.cxx index 53b772ad42a9311bc365a0dd785910f913c35dd8..cbf0bc5f65f44cfc198eff9f866392d3b972c810 100644 --- a/smtk/bridge/polygon/plugin/qtPolygonEdgeOperationView.cxx +++ b/smtk/bridge/polygon/plugin/qtPolygonEdgeOperationView.cxx @@ -17,7 +17,6 @@ #include "smtk/extension/qt/qtModelOperationWidget.h" #include "smtk/extension/qt/qtModelView.h" #include "smtk/extension/qt/qtUIManager.h" -#include "smtk/extension/paraview/widgets/pqArcWidget.h" #include "smtk/bridge/polygon/qt/pqArcWidgetManager.h" #include "smtk/bridge/polygon/qt/pqPolygonArc.h" #include "smtk/bridge/polygon/qt/pqSplitEdgeWidget.h" @@ -344,8 +343,6 @@ void qtPolygonEdgeOperationView::operationSelected(const smtk::model::OperatorPt // This handles ui panel update when we need an arc-edit widget QWidget* prevUiWidget = this->Internals->ArcManager->getActiveWidget(); - pq3DWidget* prev3dWidget = qobject_cast(prevUiWidget); - if(op->name() == "create edge") { this->Internals->ArcManager->create(); @@ -361,18 +358,10 @@ void qtPolygonEdgeOperationView::operationSelected(const smtk::model::OperatorPt { return; } - pq3DWidget* sel3dWidget = qobject_cast(selUiWidget); QString widgetName = selUiWidget->objectName(); - // we need to make invisible all 3d widget UI panels - QList< pq3DWidget* > user3dWidgets = pWidget->findChildren(); - QList< QWidget* > userUiWidgets; - // if this is not a 3d widget - if(!sel3dWidget) - { - userUiWidgets = pWidget->findChildren(widgetName); - } - userUiWidgets.append(reinterpret_cast< QList& >(user3dWidgets)); + QList userUiWidgets = + pWidget->findChildren(widgetName); bool found = false; for(int i=0; ideselect(); - prev3dWidget->setVisible(false); - prev3dWidget->setEnabled(false); - } - else if(prevUiWidget && prevUiWidget != selUiWidget) - { - prevUiWidget->setVisible(false); - prevUiWidget->setEnabled(false); - prevUiWidget->hide(); + if (prevUiWidget && prevUiWidget != selUiWidget) { + prevUiWidget->setVisible(false); + prevUiWidget->setEnabled(false); + prevUiWidget->hide(); } - if(sel3dWidget && sel3dWidget->widgetVisible()) - { - sel3dWidget->select(); - sel3dWidget->setVisible(true); - sel3dWidget->setEnabled(true); - } - else if(!sel3dWidget) - { - selUiWidget->setVisible(true); - selUiWidget->setEnabled(true); - selUiWidget->show(); + if (!selUiWidget) { + selUiWidget->setVisible(true); + selUiWidget->setEnabled(true); + selUiWidget->show(); } } else @@ -425,17 +400,8 @@ void qtPolygonEdgeOperationView::operationSelected(const smtk::model::OperatorPt if(this->Internals->ArcManager) { QWidget* prevUiWidget = this->Internals->ArcManager->getActiveWidget(); - pq3DWidget* prev3dWidget = qobject_cast(prevUiWidget); - // turn off previous active widgets if they are not the active one anymore - if(prev3dWidget) - { - prev3dWidget->deselect(); - prev3dWidget->setVisible(false); - prev3dWidget->setEnabled(false); - } - else if(prevUiWidget) - { + if (prevUiWidget) { prevUiWidget->setVisible(false); prevUiWidget->setEnabled(false); prevUiWidget->hide(); diff --git a/smtk/bridge/polygon/plugin/smconfig.xml b/smtk/bridge/polygon/plugin/smconfig.xml index b719f33303678bb2bebdcb4ee46ccfadd1841042..6bc43faae4e9dd1033ef52234ffb33da1eabb486 100644 --- a/smtk/bridge/polygon/plugin/smconfig.xml +++ b/smtk/bridge/polygon/plugin/smconfig.xml @@ -1,4 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + - - - + + + + + diff --git a/smtk/bridge/polygon/qt/CMakeLists.txt b/smtk/bridge/polygon/qt/CMakeLists.txt index 05ba95d473b1898fbb55ff069bbbeb1597b4315a..0cdc4f4ef35a3db95487303857f989c17dffd031 100644 --- a/smtk/bridge/polygon/qt/CMakeLists.txt +++ b/smtk/bridge/polygon/qt/CMakeLists.txt @@ -94,5 +94,6 @@ if (SMTK_ENABLE_TESTING) endif() endforeach() - target_link_libraries(TestBuild_smtk_bridge_polygon_qt PUBLIC ${SMTK_VTK_TARGET_LIST}) + target_link_libraries(TestBuild_smtk_bridge_polygon_qt PUBLIC ${SMTK_VTK_TARGET_LIST} + smtkQtExt) endif() diff --git a/smtk/bridge/polygon/qt/pqArcWidgetManager.cxx b/smtk/bridge/polygon/qt/pqArcWidgetManager.cxx index f8fbdb2352783c2d6a0ed4a33f94a1d692914220..d30a747599506ed4b33a8e78116133a49773fb1d 100644 --- a/smtk/bridge/polygon/qt/pqArcWidgetManager.cxx +++ b/smtk/bridge/polygon/qt/pqArcWidgetManager.cxx @@ -16,29 +16,22 @@ #include "smtk/bridge/polygon/qt/pqArcWidgetPanel.h" #include "smtk/bridge/polygon/qt/pqPolygonArc.h" -#include "smtk/extension/paraview/widgets/pqArcWidget.h" +#include "smtk/extension/paraview/widgets/qtArcWidget.h" -#include "pqApplicationCore.h" -#include "pqObjectBuilder.h" -#include "pqDataRepresentation.h" -#include "pqPipelineSource.h" #include "pqRenderView.h" -#include "pqSMAdaptor.h" #include "pqServer.h" - +#include "vtkAbstractWidget.h" +#include "vtkCamera.h" #include "vtkCommand.h" #include "vtkDoubleArray.h" #include "vtkIdTypeArray.h" +#include "vtkNew.h" #include "vtkProcessModule.h" #include "vtkSMNewWidgetRepresentationProxy.h" -#include "vtkSMInputProperty.h" -#include "vtkSMIntVectorProperty.h" #include "vtkSMPropertyHelper.h" #include "vtkSMProxyManager.h" #include "vtkSMRenderViewProxy.h" -#include "vtkSMSourceProxy.h" -#include "vtkAbstractWidget.h" -#include "vtkNew.h" + #include //----------------------------------------------------------------------------- @@ -128,33 +121,24 @@ int pqArcWidgetManager::create() if ( !created ) { - this->ArcWidget->setView(this->View); this->getDefaultArcPlane(normal, planepos); this->resetArcPlane(normal, planepos); this->ArcWidget->setView(this->View); - this->ArcWidget->setWidgetVisible(true); - - vtkSMPropertyHelper(this->ArcWidget->getWidgetProxy(), "Enabled").Set(1); - this->ArcWidget->getWidgetProxy()->UpdateVTKObjects(); - this->ArcWidget->showWidget(); + this->ArcWidget->setEnableInteractivity(true); } - this->ArcWidget->select(); - this->Arc->setPlaneProjectionNormal(normal); - this->Arc->setPlaneProjectionPosition(planepos); - this->ArcWidget->enableApplyButton(this->EnableWidgetApplyButton); - this->ActiveWidget = this->ArcWidget; - return 1; + // this->ArcWidget->select(); + this->Arc->setPlaneProjectionNormal(normal); + this->Arc->setPlaneProjectionPosition(planepos); + this->ArcWidget->enableApplyButton(this->EnableWidgetApplyButton); + this->ActiveWidget = this->ArcWidget; + return 1; } //----------------------------------------------------------------------------- int pqArcWidgetManager::edit() { - if(this->ArcWidget && this->ArcWidget->isVisible()) - { - this->disableArcWidget(); - this->ActiveWidget = NULL; - } + delete this->ArcWidget; emit this->Busy(); if ( !this->Arc ) @@ -165,9 +149,10 @@ int pqArcWidgetManager::edit() if(!this->EditWidget) { this->EditWidget = new pqArcWidgetPanel(); - QObject::connect(this->EditWidget,SIGNAL( - arcModified(pqArcWidget*, const smtk::common::UUID&)), - this,SLOT(updateEdge(pqArcWidget*, const smtk::common::UUID&))); + QObject::connect( + this->EditWidget, + SIGNAL(arcModified(qtArcWidget *, const smtk::common::UUID &)), this, + SLOT(updateEdge(qtArcWidget *, const smtk::common::UUID &))); QObject::connect(this->EditWidget,SIGNAL(arcModificationfinished()), this,SLOT(editingFinished())); QObject::connect(this->EditWidget,SIGNAL(startArcEditing()), @@ -178,13 +163,11 @@ int pqArcWidgetManager::edit() pqPolygonArc* arcObj = this->Arc; this->EditWidget->setView(this->View); - this->EditWidget->setArc(arcObj); this->EditWidget->setArcManager(this); this->EditWidget->resetWidget(); this->EditWidget->show(); this->ActiveWidget = this->EditWidget; - return 1; } @@ -200,13 +183,9 @@ void pqArcWidgetManager::cancelOperation(const smtk::model::OperatorPtr& op) this->EditWidget->hide(); } - if(this->ArcWidget && this->ArcWidget->isVisible()) - { - this->disableArcWidget(); - } - - this->ActiveWidget = NULL; - emit this->operationCancelled(); + delete this->ArcWidget; + this->ActiveWidget = NULL; + emit this->operationCancelled(); } //----------------------------------------------------------------------------- @@ -226,16 +205,17 @@ void pqArcWidgetManager::createEdge() return; } - //push the polydata from the widget representation to the poly source + Q_ASSERT(this->ArcWidget); - pqPolygonArc* obj = this->Arc; - if ( obj ) - { - vtkSMNewWidgetRepresentationProxy *widget = this->ArcWidget->getWidgetProxy(); - if(!obj->createEdge(widget)) - { - qDebug() << "Can't create an edge with given widget!" << widget; - return; + // push the polydata from the widget representation to the poly source + + pqPolygonArc *obj = this->Arc; + if (obj) { + vtkSMNewWidgetRepresentationProxy *widget = + this->ArcWidget->widgetProxy(); + if (!obj->createEdge(widget)) { + qDebug() << "Can't create an edge with given widget!" << widget; + return; } } @@ -256,9 +236,8 @@ void pqArcWidgetManager::editingFinished() } //----------------------------------------------------------------------------- -void pqArcWidgetManager::updateEdge( - pqArcWidget* subArcWidget, const smtk::common::UUID& edgeId) -{ +void pqArcWidgetManager::updateEdge(qtArcWidget *subArcWidget, + const smtk::common::UUID &edgeId) { if ( (!this->Arc) || this->ActiveWidget != this->EditWidget) { return; @@ -268,7 +247,7 @@ void pqArcWidgetManager::updateEdge( pqPolygonArc* obj = this->Arc; if ( obj ) { - vtkSMNewWidgetRepresentationProxy *widget = subArcWidget->getWidgetProxy(); + vtkSMNewWidgetRepresentationProxy *widget = subArcWidget->widgetProxy(); obj->editEdge(widget, edgeId); /* //if the object hasn't been created yet update will call createArc @@ -319,44 +298,31 @@ void pqArcWidgetManager::updateEdge( } //----------------------------------------------------------------------------- -pqArcWidget* pqArcWidgetManager::createDefaultContourWidget( - int& normal, double& planePos) -{ +qtArcWidget *pqArcWidgetManager::createDefaultContourWidget(int &normal, + double &planePos) { this->getDefaultArcPlane(normal, planePos); return this->createContourWidget(normal, planePos); } //----------------------------------------------------------------------------- -pqArcWidget* pqArcWidgetManager::createContourWidget( - int normal, double position) -{ - vtkSMProxy* pointplacer = vtkSMProxyManager::GetProxyManager()->NewProxy( - "point_placers", "BoundedPlanePointPlacer"); - - pqArcWidget *widget= new pqArcWidget( - pointplacer, pointplacer, NULL); - +qtArcWidget *pqArcWidgetManager::createContourWidget(int normal, + double position) { + qtArcWidget *widget = new qtArcWidget(nullptr); widget->setObjectName("smtkArcWidget"); + vtkSMProxy *pointplacer = widget->pointPlacer(); vtkSMPropertyHelper(pointplacer, "ProjectionNormal").Set(normal); vtkSMPropertyHelper(pointplacer, "ProjectionPosition").Set(position); - widget->setLineInterpolator(0); - widget->setPointPlacer(pointplacer); pointplacer->UpdateVTKObjects(); - pointplacer->Delete(); - //this block is needed to create the widget in the right order //we need to set on the proxy enabled, not the widget //than we need to call Initialize - widget->setView( this->View ); - widget->setWidgetVisible( this->View != NULL ); - - vtkSMPropertyHelper(widget->getWidgetProxy(), "AlwaysOnTop").Set(1); - vtkSMPropertyHelper(widget->getWidgetProxy(), "Enabled").Set(1); - widget->getWidgetProxy()->UpdateVTKObjects(); - widget->showWidget(); - + widget->setView(this->View); + vtkSMPropertyHelper(widget->widgetProxy(), "AlwaysOnTop").Set(1); + widget->widgetProxy()->UpdateVTKObjects(); + widget->setEnableInteractivity(true); + widget->emphasize(); return widget; } @@ -365,37 +331,28 @@ pqPolygonArc* pqArcWidgetManager::createLegacyV1Contour( const int &normal,const double &position,const int &closedLoop, vtkDoubleArray* nodePositions, vtkIdTypeArray* SelIndices) { - - pqArcWidget* contourWidget = - this->createContourWidget(normal,position); - - vtkSMNewWidgetRepresentationProxy *widgetProxy = - contourWidget->getWidgetProxy(); - - if(nodePositions && nodePositions->GetNumberOfTuples() > 0) - { - QList values; - double pointPos[3]; + qtArcWidget *contourWidget = this->createContourWidget(normal, position); + vtkSMNewWidgetRepresentationProxy *widgetProxy = contourWidget->widgetProxy(); + if (nodePositions && nodePositions->GetNumberOfTuples() > 0) { + std::vector points; for(vtkIdType i=0; iGetNumberOfTuples(); i++) { + double pointPos[3]; nodePositions->GetTuple(i,pointPos); - values << pointPos[0] << pointPos[1] << pointPos[2]; - } - pqSMAdaptor::setMultipleElementProperty( - widgetProxy->GetRepresentationProxy()->GetProperty("NodePositions"), - values); - } - - if ( SelIndices && SelIndices->GetNumberOfTuples() > 0 ) - { - QList values; - for(vtkIdType i=0; iGetNumberOfTuples(); i++) - { - values << SelIndices->GetValue(i); + points.push_back(pointPos[0]); + points.push_back(pointPos[1]); + points.push_back(pointPos[2]); } - pqSMAdaptor::setMultipleElementProperty( - widgetProxy->GetRepresentationProxy()->GetProperty("SelectNodes"), - values); + vtkSMPropertyHelper(widgetProxy, "NodePositions") + .Set(&points[0], static_cast(points.size())); + } else { + vtkSMPropertyHelper(widgetProxy, "NodePositions").SetNumberOfElements(0); + } + if (SelIndices && SelIndices->GetNumberOfTuples() > 0) { + vtkSMPropertyHelper(widgetProxy, "SelectNodes") + .Set(SelIndices->GetPointer(0), SelIndices->GetNumberOfTuples()); + } else { + vtkSMPropertyHelper(widgetProxy, "SelectNodes").SetNumberOfElements(0); } //push all the node positions down to the server before @@ -430,26 +387,30 @@ void pqArcWidgetManager::getDefaultArcPlane( (void)position; (void)cameraDistance; (void)focalPt; -/* - pqCMBCommonMainWindowCore::getViewCameraInfo( - this->View, focalPt, position, viewDirection, cameraDistance, - viewUp, parallelScale); -*/ - projpos = 0; - QList values = - pqSMAdaptor::getMultipleElementProperty( - this->View->getProxy()->GetProperty("CameraFocalPointInfo")); - projpos = values[2].toDouble(); + + vtkCamera *camera = this->View->getRenderViewProxy()->GetActiveCamera(); + Q_ASSERT(camera); + camera->GetFocalPoint(focalPt); + camera->GetDirectionOfProjection(viewDirection); + + /* + pqCMBCommonMainWindowCore::getViewCameraInfo( + this->View, focalPt, position, viewDirection, cameraDistance, + viewUp, parallelScale); + */ + /// FIXME: why does this code assume we'll never get an non-axis aligned + /// viewing direction? + projpos = focalPt[2]; orthoPlane = 2; // z axis if (viewDirection[0] < -.99 || viewDirection[0] > .99) { - projpos = values[0].toDouble(); + projpos = focalPt[0]; orthoPlane = 0; // x axis } else if (viewDirection[1] < -.99 || viewDirection[1] > .99) { orthoPlane = 1; // y axis; - projpos = values[1].toDouble(); + projpos = focalPt[1]; } } @@ -457,15 +418,10 @@ void pqArcWidgetManager::getDefaultArcPlane( void pqArcWidgetManager::resetArcPlane( int normal, double planePos) { - vtkSMProxyProperty* proxyProp = - vtkSMProxyProperty::SafeDownCast( - this->ArcWidget->getWidgetProxy()->GetProperty("PointPlacer")); - if (proxyProp && proxyProp->GetNumberOfProxies()) - { - vtkSMProxy* pointplacer = proxyProp->GetProxy(0); + if (vtkSMProxy *pointplacer = this->ArcWidget->pointPlacer()) { vtkSMPropertyHelper(pointplacer, "ProjectionNormal").Set(normal); vtkSMPropertyHelper(pointplacer, "ProjectionPosition").Set(planePos); - pointplacer->MarkModified(pointplacer); + // pointplacer->MarkModified(pointplacer); why was this needed? pointplacer->UpdateVTKObjects(); } } @@ -473,13 +429,14 @@ void pqArcWidgetManager::resetArcPlane( //----------------------------------------------------------------------------- void pqArcWidgetManager::disableArcWidget() { - if(this->ArcWidget) - { - this->ArcWidget->setVisible(false); - this->ArcWidget->reset(); - this->ArcWidget->removeAllNodes(); - this->ArcWidget->setWidgetVisible(false); - this->ArcWidget->getWidgetProxy()->UpdatePropertyInformation(); - this->ArcWidget->setView(NULL); - } + delete this->ArcWidget; + // if(this->ArcWidget) + // { + // this->ArcWidget->setVisible(false); + // this->ArcWidget->reset(); + // this->ArcWidget->removeAllNodes(); + // this->ArcWidget->setWidgetVisible(false); + // this->ArcWidget->getWidgetProxy()->UpdatePropertyInformation(); + // this->ArcWidget->setView(NULL); + // } } diff --git a/smtk/bridge/polygon/qt/pqArcWidgetManager.h b/smtk/bridge/polygon/qt/pqArcWidgetManager.h index 386ea9b30b1cfbae56c6b439f5fb62d5de263805..e5f636e32fa9ef36d4493e85a8be65a442d4669d 100644 --- a/smtk/bridge/polygon/qt/pqArcWidgetManager.h +++ b/smtk/bridge/polygon/qt/pqArcWidgetManager.h @@ -26,7 +26,7 @@ #include #include "vtkType.h" -class pqArcWidget; +class qtArcWidget; class pqArcWidgetPanel; class pqPolygonArc; class pqRenderView; @@ -46,7 +46,7 @@ public: int edit(); void reset(); - pqArcWidget* createDefaultContourWidget(int& normal, double& pos); + qtArcWidget *createDefaultContourWidget(int &normal, double &pos); QWidget* getActiveWidget() { return ActiveWidget; } pqPolygonArc* activeArc(); @@ -73,20 +73,20 @@ protected slots: // called when a whole arc is done creating or modifying. void createEdge(); // called when a sub arc modification is done - void updateEdge(pqArcWidget*, const smtk::common::UUID& edgeid); + void updateEdge(qtArcWidget *, const smtk::common::UUID &edgeid); // called when the edit widget is closed void editingFinished(); protected: void getDefaultArcPlane(int& normal, double& pos); void resetArcPlane(int normal, double pos); - pqArcWidget* createContourWidget( int normal, double position ); + qtArcWidget *createContourWidget(int normal, double position); pqPolygonArc* createLegacyV1Contour( const int &normal,const double &position,const int &closedLoop, vtkDoubleArray* nodePositions, vtkIdTypeArray* SelIndices); void disableArcWidget(); - QPointer ArcWidget; + QPointer ArcWidget; QPointer EditWidget; QPointer Arc; diff --git a/smtk/bridge/polygon/qt/pqArcWidgetPanel.cxx b/smtk/bridge/polygon/qt/pqArcWidgetPanel.cxx index a34ff641313563b9583a5b3f16fb5751552f23dc..5cf50e3c205d3d6bd502da9c22e2a55f8e6d0304 100644 --- a/smtk/bridge/polygon/qt/pqArcWidgetPanel.cxx +++ b/smtk/bridge/polygon/qt/pqArcWidgetPanel.cxx @@ -35,11 +35,11 @@ #include "vtkSMVectorProperty.h" #include "vtkUnsignedIntArray.h" -#include "smtk/extension/vtk/widgets/vtkSMTKArcRepresentation.h" -#include "smtk/bridge/polygon/qt/pqPolygonArc.h" #include "smtk/bridge/polygon/qt/pqArcWidgetManager.h" +#include "smtk/bridge/polygon/qt/pqPolygonArc.h" #include "smtk/bridge/polygon/qt/vtkPolygonArcInfo.h" -#include "smtk/extension/paraview/widgets/pqArcWidget.h" +#include "smtk/extension/paraview/widgets/qtArcWidget.h" +#include "smtk/extension/vtk/widgets/vtkSMTKArcRepresentation.h" #include "smtk/model/Edge.h" #include "smtk/model/Manager.h" #include "smtk/model/Operator.h" @@ -247,16 +247,7 @@ pqArcWidgetPanel::pqArcWidgetPanel(QWidget *parent) : pqArcWidgetPanel::~pqArcWidgetPanel() { - if ( this->ArcWidget ) - { - //if a widget is deleted without having an active view it throws errors - if ( this->View && !this->ArcWidget->view() ) - { - this->ArcWidget->setView(this->View); - } - delete this->ArcWidget; - } - this->ArcWidget = NULL; + delete this->ArcWidget; delete Internals; } @@ -358,11 +349,8 @@ void pqArcWidgetPanel::hideArcWidget() { if(this->ArcWidget) { - this->ArcWidget->setWidgetVisible(false); + this->ArcWidget->setEnableInteractivity(false); this->ArcWidget->setVisible(false); - this->ArcWidget->deselect(); - this->ArcWidget->hideWidget(); - this->ArcWidget->getWidgetProxy()->UpdatePropertyInformation(); this->ArcWidget->setView(NULL); this->ArcWidget->hide(); } @@ -399,51 +387,40 @@ void pqArcWidgetPanel::modifyArc() this->ArcWidget->setView(this->View); if(arcObj) { - vtkSMProxyProperty* proxyProp = - vtkSMProxyProperty::SafeDownCast( - this->ArcWidget->getWidgetProxy()->GetProperty("PointPlacer")); - if (proxyProp && proxyProp->GetNumberOfProxies()) - { - vtkSMProxy* pointplacer = proxyProp->GetProxy(0); + if (vtkSMProxy *pointplacer = this->ArcWidget->pointPlacer()) { vtkSMPropertyHelper(pointplacer, "ProjectionNormal").Set( arcObj->getPlaneProjectionNormal()); vtkSMPropertyHelper(pointplacer, "ProjectionPosition").Set( arcObj->getPlaneProjectionPosition()); - pointplacer->MarkModified(pointplacer); + // pointplacer->MarkModified(pointplacer); pointplacer->UpdateVTKObjects(); } } - vtkSMPropertyHelper(this->ArcWidget->getWidgetProxy(), "Enabled").Set(1); - this->ArcWidget->getWidgetProxy()->UpdateVTKObjects(); } this->ArcWidget->useArcEditingUI(true); + this->ArcWidget->setEnableInteractivity(true); this->ArcWidget->show(); - this->ArcWidget->setEnabled(true); - this->ArcWidget->setWidgetVisible(true); - if ( arcObj ) { if (!created) { - this->ArcWidget->reset(); + this->ArcWidget->reset(); // FIXME:why even bother reusing? Simply create + // a new widget everytime. } //pass the info from the arc into the widget proxy this->updateWidgetRepresentation(); - vtkSMProxy* repProxy = this->ArcWidget->getWidgetProxy()->GetRepresentationProxy(); - vtkSMPropertyHelper(repProxy, "CanEdit").Set(0); - repProxy->UpdateVTKObjects(); + vtkSMPropertyHelper(this->ArcWidget->widgetProxy(), "CanEdit").Set(0); + this->ArcWidget->widgetProxy()->UpdateVTKObjects(); this->ArcWidget->checkContourLoopClosed(); this->ArcWidget->ModifyMode(); this->ArcWidget->checkCanBeEdited(); - this->ArcWidget->setModified(); } this->View->forceRender(); - this->ArcWidget->select(); } //----------------------------------------------------------------------------- @@ -476,7 +453,8 @@ void pqArcWidgetPanel::updateWidgetRepresentation() sourceProxy->UpdateVTKObjects(); sourceProxy->UpdatePipeline(); - vtkSMNewWidgetRepresentationProxy* widgetProxy = this->ArcWidget->getWidgetProxy(); + vtkSMNewWidgetRepresentationProxy *widgetProxy = + this->ArcWidget->widgetProxy(); vtkSMProxy* repProxy = widgetProxy->GetRepresentationProxy(); vtkClientServerStream stream; stream << vtkClientServerStream::Invoke diff --git a/smtk/bridge/polygon/qt/pqArcWidgetPanel.h b/smtk/bridge/polygon/qt/pqArcWidgetPanel.h index fdcd34a46111b32a5e5dcbcf574d36be78bd6cc0..8f7df8f1fb90365ffcee17d24928cd11887f1f76 100644 --- a/smtk/bridge/polygon/qt/pqArcWidgetPanel.h +++ b/smtk/bridge/polygon/qt/pqArcWidgetPanel.h @@ -13,15 +13,16 @@ #include "smtk/bridge/polygon/qt/Exports.h" #include "smtk/common/UUID.h" -#include -#include //needed for ArcPicker #include "vtkType.h" +#include //needed for ArcPicker +#include +#include class pqOutputPort; class pqRenderView; class pqRenderViewSelectionReaction; class pqPolygonArc; -class pqArcWidget; +class qtArcWidget; class pqArcWidgetManager; class pqPipelineSource; class vtkSelectionNode; @@ -88,7 +89,7 @@ explicit pqArcWidgetPanel(QWidget *parent = 0); {this->ArcManager = arcManager;} signals: - void arcModified(pqArcWidget*, const smtk::common::UUID& edgeid); + void arcModified(qtArcWidget *, const smtk::common::UUID &edgeid); void arcModificationfinished(); void arcModificationCacelled(); void startArcEditing(); @@ -137,7 +138,7 @@ private: Ui::ArcPicker Picker; pqRenderView *View; pqPolygonArc *Arc; - pqArcWidget* ArcWidget; + QPointer ArcWidget; pqArcWidgetManager* ArcManager; }; diff --git a/smtk/extension/paraview/widgets/CMakeLists.txt b/smtk/extension/paraview/widgets/CMakeLists.txt index 8e7602e4e9dbd893fbaecaba528115d7a25731f1..5eeb369641aef20040f190a77155801312889663 100644 --- a/smtk/extension/paraview/widgets/CMakeLists.txt +++ b/smtk/extension/paraview/widgets/CMakeLists.txt @@ -2,11 +2,10 @@ include(${QT_USE_FILE}) # set up sources to build set(PQWidgetsSrcs - pq3DWidget.cxx - pq3DWidgetInterface.cxx - pqArcWidget.cxx - pqLineWidget.cxx pqGenerateContoursDialog.cxx + qtArcWidget.cxx + qtInteractionWidget.cxx + qtLineWidget.cxx ) set(PQWidgetsUIs @@ -16,15 +15,14 @@ set(PQWidgetsUIs ) set(PQWidgetsMocHeaders - pq3DWidget.h - pqArcWidget.h - pqLineWidget.h pqGenerateContoursDialog.h + qtArcWidget.h + qtInteractionWidget.h + qtLineWidget.h ) set(PQWidgetsHeaders ${PQWidgetsMocHeaders} - pq3DWidgetInterface.h ) #install the headers diff --git a/smtk/extension/paraview/widgets/pq3DWidget.cxx b/smtk/extension/paraview/widgets/pq3DWidget.cxx deleted file mode 100644 index bb4797b6e7f8f99a0c997904418a99d6b6357ead..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/widgets/pq3DWidget.cxx +++ /dev/null @@ -1,790 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/extension/paraview/widgets/pq3DWidget.h" - -// ParaView Server Manager includes. -#include "vtkBoundingBox.h" -#include "vtkEventQtSlotConnect.h" -#include "vtkMemberFunctionCommand.h" -#include "vtkPVDataInformation.h" -#include "vtkPVXMLElement.h" -#include "vtkRenderWindowInteractor.h" -#include "vtkSmartPointer.h" -#include "vtkSMInputProperty.h" -#include "vtkSMIntVectorProperty.h" -#include "vtkSMNewWidgetRepresentationProxy.h" -#include "vtkSMPropertyHelper.h" -#include "vtkSMProxyManager.h" -#include "vtkSMProxyProperty.h" -#include "vtkSMProxySelectionModel.h" -#include "vtkSMRenderViewProxy.h" -#include "vtkSMSession.h" -#include "vtkSMSessionProxyManager.h" -#include "vtkSMSourceProxy.h" -#include "vtkSMTrace.h" - -// Qt includes. -#include -#include -#include - -// ParaView GUI includes. -#include "pq3DWidgetFactory.h" -#include "pq3DWidgetInterface.h" -#include "pqActiveObjects.h" -#include "pqApplicationCore.h" -//#include "pqBoxWidget.h" -#include "pqCoreUtilities.h" -//#include "pqDistanceWidget.h" -//#include "pqImplicitCylinderWidget.h" -//#include "pqImplicitPlaneWidget.h" -#include "pqInterfaceTracker.h" -//#include "pqLineSourceWidget.h" -#include "pqLineWidget.h" -#include "pqPipelineFilter.h" -#include "pqPipelineSource.h" -//#include "pqPointSourceWidget.h" -//#include "pqPolyLineWidget.h" -#include "pqRenderView.h" -#include "pqServer.h" -#include "pqSMAdaptor.h" -//#include "pqSphereWidget.h" -//#include "pqSplineWidget.h" - -namespace -{ - vtkSMProxySelectionModel* getSelectionModel(vtkSMProxy* proxy) - { - vtkSMSessionProxyManager* pxm = - proxy->GetSession()->GetSessionProxyManager(); - return pxm->GetSelectionModel("ActiveSources"); - } -} - -//----------------------------------------------------------------------------- -class pq3DWidget::pqStandardWidgets : public pq3DWidgetInterface -{ -public: - pq3DWidget* newWidget(const QString& name, - vtkSMProxy* referenceProxy, - vtkSMProxy* controlledProxy) - { - pq3DWidget *widget = 0; -/* if (name == "Plane") - { - widget = new pqImplicitPlaneWidget(referenceProxy, controlledProxy, 0); - } - else if (name == "Box") - { - widget = new pqBoxWidget(referenceProxy, controlledProxy, 0); - } - else if (name == "Handle") - { - widget = new pqHandleWidget(referenceProxy, controlledProxy, 0); - } - else if (name == "PointSource") - { - widget = new pqPointSourceWidget(referenceProxy, controlledProxy, 0); - } - else if (name == "LineSource") - { - widget = new pqLineSourceWidget(referenceProxy, controlledProxy, 0); - } -*/ if (name == "Line") - { - widget = new pqLineWidget(referenceProxy, controlledProxy, 0); - } -/* - else if (name == "PolyLineSource") - { - widget = new pqPolyLineWidget(referenceProxy, controlledProxy, 0); - } - else if (name == "Distance") - { - widget = new pqDistanceWidget(referenceProxy, controlledProxy, 0); - } - else if (name == "Sphere") - { - widget = new pqSphereWidget(referenceProxy, controlledProxy, 0); - } - else if (name == "Spline") - { - widget = new pqSplineWidget(referenceProxy, controlledProxy, 0); - } - else if (name == "Cylinder") - { - widget = new pqImplicitCylinderWidget(referenceProxy, controlledProxy, 0); - } -*/ - return widget; - } -}; - -//----------------------------------------------------------------------------- -class pq3DWidgetInternal -{ -public: - pq3DWidgetInternal() : - IgnorePropertyChange(false), - WidgetVisible(true), - Selected(false), - LastWidgetVisibilityGoal(true), - InDeleteCall(false), - PickOnMeshPoint(false) - { - this->VTKConnect = vtkSmartPointer::New(); - this->IsMaster = pqApplicationCore::instance()->getActiveServer()->isMaster(); - } - - vtkSmartPointer ReferenceProxy; - vtkSmartPointer WidgetProxy; - vtkSmartPointer ControlledPropertiesObserver; - vtkSmartPointer Hints; - vtkSmartPointer VTKConnect; - - QMap, vtkSmartPointer > PropertyMap; - - /// Used to avoid recursion when updating the controlled properties - bool IgnorePropertyChange; - /// Stores the visible/hidden state of the 3D widget (controlled by the user) - bool WidgetVisible; - /// Stores the selected/not selected state of the 3D widget (controlled by the owning panel) - bool Selected; - - QKeySequence PickSequence; - QPointer PickShortcut; - bool IsMaster; - bool LastWidgetVisibilityGoal; - bool InDeleteCall; - bool PickOnMeshPoint; -}; - -//----------------------------------------------------------------------------- -pq3DWidget::pq3DWidget(vtkSMProxy* refProxy, vtkSMProxy* pxy, QWidget* _p) : - pqProxyPanel(pxy, _p), - Internal(new pq3DWidgetInternal()) -{ - this->UseSelectionDataBounds = false; - this->Internal->ReferenceProxy = refProxy; - - this->Internal->ControlledPropertiesObserver.TakeReference( - vtkMakeMemberFunctionCommand(*this, - &pq3DWidget::onControlledPropertyChanged)); - this->Internal->IgnorePropertyChange = false; - - this->setControlledProxy(pxy); - - QObject::connect( pqApplicationCore::instance(), - SIGNAL(updateMasterEnableState(bool)), - this, SLOT(updateMasterEnableState(bool))); - if (refProxy) - { - // Listen to UserEvent to allow Python to toggle widget visibility. - // Leaving the current "core" design intact for this. When we refactor - // 3DWidgets, we should revisit this design. - pqCoreUtilities::connect(refProxy, vtkCommand::UserEvent, - this, SLOT(handleReferenceProxyUserEvent(vtkObject*, unsigned long, void*))); - } -} - -//----------------------------------------------------------------------------- -pq3DWidget::~pq3DWidget() -{ - this->Internal->InDeleteCall = true; - vtkSMNewWidgetRepresentationProxy* widget = this->getWidgetProxy(); - if(widget) - { - pqApplicationCore::instance()->get3DWidgetFactory()->free3DWidget(widget); - } - this->setWidgetProxy(0); - this->setView(0); - this->setControlledProxy(0); - delete this->Internal; -} - -//----------------------------------------------------------------------------- -QList pq3DWidget::createWidgets(vtkSMProxy* refProxy, vtkSMProxy* pxy) -{ - QList widgets; - - QList interfaces = - pqApplicationCore::instance()->interfaceTracker()->interfaces(); - - vtkPVXMLElement* hints = pxy->GetHints(); - unsigned int max = hints->GetNumberOfNestedElements(); - for (unsigned int cc=0; cc < max; cc++) - { - vtkPVXMLElement* element = hints->GetNestedElement(cc); - if (QString("PropertyGroup") == element->GetName()) - { - QString widgetType = element->GetAttribute("type"); - pq3DWidget *widget = 0; - - // Create the widget from plugins. - foreach (pq3DWidgetInterface* iface, interfaces) - { - widget = iface->newWidget(widgetType, refProxy, pxy); - if (widget) - { - break; - } - } - if (!widget) - { - // try to create the standard widget if the plugins fail. - pqStandardWidgets standardWidgets; - widget = standardWidgets.newWidget(widgetType, refProxy, pxy); - } - if (widget) - { - widget->setHints(element); - widgets.push_back(widget); - } - } - } - return widgets; -} - -//----------------------------------------------------------------------------- -pqRenderViewBase* pq3DWidget::renderView() const -{ - return qobject_cast(this->view()); -} - -//----------------------------------------------------------------------------- -void pq3DWidget::pickingSupported(const QKeySequence& key) -{ - this->Internal->PickSequence = key; -} - -//----------------------------------------------------------------------------- -void pq3DWidget::setView(pqView* pqview) -{ - pqRenderViewBase* rview = this->renderView(); - if (pqview == rview) - { - this->Superclass::setView(pqview); - return; - } - - // This test has been added to support proxy that have been created on - // different servers. We return if we switch from a view from a server - // to another view from another server. - vtkSMProxy* widget = this->getWidgetProxy(); - if ((widget && pqview && - pqview->getProxy()->GetSession() != widget->GetSession()) - || - (rview && pqview && - rview->getProxy()->GetSession() != pqview->getProxy()->GetSession())) - { - return; - } - - // get rid of old shortcut. - delete this->Internal->PickShortcut; - - bool cur_visbility = this->widgetVisible(); - this->hideWidget(); - - if (rview && widget) - { - // To add/remove the 3D widget display from the view module. - // we don't use the property. This is so since the 3D widget add/remove - // should not get saved in state or undo-redo. - vtkSMPropertyHelper( - rview->getProxy(), "HiddenRepresentations").Remove(widget); - rview->getProxy()->UpdateVTKObjects(); - } - - this->Superclass::setView(pqview); - - rview = this->renderView(); - if (rview && !this->Internal->PickSequence.isEmpty()) - { - this->Internal->PickShortcut = new QShortcut( - this->Internal->PickSequence, pqview->widget()); - QObject::connect(this->Internal->PickShortcut, SIGNAL(activated()), - this, SLOT(pickPoint())); - } - - if (rview && widget) - { - // To add/remove the 3D widget display from the view module. - // we don't use the property. This is so since the 3D widget add/remove - // should not get saved in state or undo-redo. - this->updateWidgetVisibility(); - vtkSMPropertyHelper( - rview->getProxy(), "HiddenRepresentations").Add(widget); - rview->getProxy()->UpdateVTKObjects(); - } - - if (cur_visbility) - { - this->showWidget(); - } - this->updatePickShortcut(); -} - -//----------------------------------------------------------------------------- -void pq3DWidget::render() -{ - if (pqRenderViewBase* rview = this->renderView()) - { - rview->render(); - } -} - -//----------------------------------------------------------------------------- -void pq3DWidget::setPickOnMeshPoint(bool enable) -{ - this->Internal->PickOnMeshPoint = enable; -} - -//----------------------------------------------------------------------------- -void pq3DWidget::pickPoint() -{ - pqRenderView* rview = qobject_cast(this->renderView()); - if (rview && rview->getRenderViewProxy()) - { - vtkRenderWindowInteractor* rwi = rview->getRenderViewProxy()->GetInteractor(); - if (!rwi) - { - return; - } - - // Get region - const int* eventpos = rwi->GetEventPosition(); - double position[3]; - if (rview->getRenderViewProxy()->ConvertDisplayToPointOnSurface(eventpos, - position, this->Internal->PickOnMeshPoint)) - { - this->pick(position[0], position[1], position[2]); - } - } -} - -//----------------------------------------------------------------------------- -void pq3DWidget::onControlledPropertyChanged() -{ - if (this->Internal->IgnorePropertyChange) - { - return; - } - - // Synchronize the 3D and Qt widgets with the controlled properties - this->reset(); -} - -//----------------------------------------------------------------------------- -void pq3DWidget::setWidgetProxy(vtkSMNewWidgetRepresentationProxy* pxy) -{ - this->Internal->VTKConnect->Disconnect(); - - vtkSMNewWidgetRepresentationProxy* widget = this->getWidgetProxy(); - pqRenderViewBase* rview = this->renderView(); - vtkSMProxy* viewProxy = rview? rview->getProxy() : NULL; - if (rview && widget) - { - // To add/remove the 3D widget display from the view module. - // we don't use the property. This is so since the 3D widget add/remove - // should not get saved in state or undo-redo. - vtkSMPropertyHelper(viewProxy,"HiddenRepresentations").Remove(widget); - viewProxy->UpdateVTKObjects(); - rview->render(); - } - - this->Internal->WidgetProxy = pxy; - - if (pxy) - { - this->Internal->VTKConnect->Connect(pxy, vtkCommand::StartInteractionEvent, - this, SIGNAL(widgetStartInteraction())); - this->Internal->VTKConnect->Connect(pxy, vtkCommand::InteractionEvent, - this, SLOT(setModified())); - this->Internal->VTKConnect->Connect(pxy, vtkCommand::InteractionEvent, - this, SIGNAL(widgetInteraction())); - this->Internal->VTKConnect->Connect(pxy, vtkCommand::EndInteractionEvent, - this, SIGNAL(widgetEndInteraction())); - } - - if (rview && pxy) - { - // To add/remove the 3D widget display from the view module. - // we don't use the property. This is so since the 3D widget add/remove - // should not get saved in state or undo-redo. - vtkSMPropertyHelper(viewProxy,"HiddenRepresentations").Add(widget); - viewProxy->UpdateVTKObjects(); - rview->render(); - } -} - -//----------------------------------------------------------------------------- -vtkSMNewWidgetRepresentationProxy* pq3DWidget::getWidgetProxy() const -{ - return this->Internal->WidgetProxy; -} - -//----------------------------------------------------------------------------- -vtkSMProxy* pq3DWidget::getControlledProxy() const -{ - return this->proxy(); -} - -//----------------------------------------------------------------------------- -vtkSMProxy* pq3DWidget::getReferenceProxy() const -{ - return this->Internal->ReferenceProxy; -} - -//----------------------------------------------------------------------------- -void pq3DWidget::setControlledProxy(vtkSMProxy* /*pxy*/) -{ - foreach(vtkSMProperty* controlledProperty, this->Internal->PropertyMap) - { - controlledProperty->RemoveObserver( - this->Internal->ControlledPropertiesObserver); - } - this->Internal->PropertyMap.clear(); -} - -//----------------------------------------------------------------------------- -vtkPVXMLElement* pq3DWidget::getHints() const -{ - return this->Internal->Hints; -} - -//----------------------------------------------------------------------------- -void pq3DWidget::setHints(vtkPVXMLElement* hints) -{ - this->Internal->Hints = hints; - if (!hints) - { - return; - } - - if (!this->proxy()) - { - qDebug() << "pq3DWidget::setHints must be called only after the controlled " - << "proxy has been set."; - return; - } - if (QString("PropertyGroup") != hints->GetName()) - { - qDebug() << "Argument to setHints must be a element."; - return; - } - - vtkSMProxy* pxy = this->proxy(); - unsigned int max_props = hints->GetNumberOfNestedElements(); - for (unsigned int i=0; i < max_props; i++) - { - vtkPVXMLElement* propElem = hints->GetNestedElement(i); - this->setControlledProperty(propElem->GetAttribute("function"), - pxy->GetProperty(propElem->GetAttribute("name"))); - } -} - -//----------------------------------------------------------------------------- -bool pq3DWidget::pickOnMeshPoint() const -{ - return this->Internal->PickOnMeshPoint; -} - -//----------------------------------------------------------------------------- -void pq3DWidget::setControlledProperty(const char* function, - vtkSMProperty* controlled_property) -{ - this->Internal->PropertyMap.insert( - this->Internal->WidgetProxy->GetProperty(function), - controlled_property); - - controlled_property->AddObserver(vtkCommand::ModifiedEvent, - this->Internal->ControlledPropertiesObserver); -} - -//----------------------------------------------------------------------------- -void pq3DWidget::setControlledProperty(vtkSMProperty* widget_property, - vtkSMProperty* controlled_property) -{ - this->Internal->PropertyMap.insert( - widget_property, - controlled_property); - - controlled_property->AddObserver(vtkCommand::ModifiedEvent, - this->Internal->ControlledPropertiesObserver); -} - -//----------------------------------------------------------------------------- -void pq3DWidget::accept() -{ - this->Internal->IgnorePropertyChange = true; - QMap, - vtkSmartPointer >::const_iterator iter; - for (iter = this->Internal->PropertyMap.constBegin() ; - iter != this->Internal->PropertyMap.constEnd(); - ++iter) - { - iter.value()->Copy(iter.key()); - } - if (this->proxy()) - { - this->proxy()->UpdateVTKObjects(); - } - this->Internal->IgnorePropertyChange = false; -} - -//----------------------------------------------------------------------------- -void pq3DWidget::reset() -{ - // We don't want to fire any widget modified events while resetting the - // 3D widget, hence we block all signals. Otherwise, on reset, we fire a - // widget modified event, which makes the accept button enabled again. - this->blockSignals(true); - QMap, - vtkSmartPointer >::const_iterator iter; - for (iter = this->Internal->PropertyMap.constBegin() ; - iter != this->Internal->PropertyMap.constEnd(); - ++iter) - { - iter.key()->Copy(iter.value()); - } - - if (this->Internal->WidgetProxy) - { - this->Internal->WidgetProxy->UpdateVTKObjects(); - this->Internal->WidgetProxy->UpdatePropertyInformation(); - this->render(); - } - this->blockSignals(false); -} - -//----------------------------------------------------------------------------- -bool pq3DWidget::widgetVisible() const -{ - return this->Internal->WidgetVisible; -} - -//----------------------------------------------------------------------------- -bool pq3DWidget::widgetSelected() const -{ - return this->Internal->Selected; -} - -//----------------------------------------------------------------------------- -void pq3DWidget::select() -{ - if(true != this->Internal->Selected) - { - this->Internal->Selected = true; - this->updateWidgetVisibility(); - } -} - -//----------------------------------------------------------------------------- -void pq3DWidget::deselect() -{ - if(false != this->Internal->Selected) - { - this->Internal->Selected = false; - this->updateWidgetVisibility(); - } -} - -//----------------------------------------------------------------------------- -void pq3DWidget::setWidgetVisible(bool visible) -{ - if(this->Internal->IsMaster) - { - this->Internal->LastWidgetVisibilityGoal = visible; - } - - if( visible != this->Internal->WidgetVisible && - ((!this->Internal->IsMaster && !visible) || this->Internal->IsMaster)) - { - this->Internal->WidgetVisible = visible; - this->updateWidgetVisibility(); - - if (vtkSMProxy* refProxy = this->getReferenceProxy()) - { - SM_SCOPED_TRACE(CallFunction) - .arg(visible? "Show3DWidgets" : "Hide3DWidgets") - .arg("proxy", refProxy) - .arg("comment", "toggle 3D widget visibility (only when running from the GUI)"); - } - emit this->widgetVisibilityChanged(visible); - } -} - -//----------------------------------------------------------------------------- -void pq3DWidget::showWidget() -{ - this->setWidgetVisible(true); -} - -//----------------------------------------------------------------------------- -void pq3DWidget::hideWidget() -{ - this->setWidgetVisible(false); -} - -//----------------------------------------------------------------------------- -int pq3DWidget::getReferenceInputBounds(double bounds[6]) const -{ - vtkSMProxy* refProxy = this->getReferenceProxy(); - if (!refProxy) - { - return 0; - } - - vtkSMSourceProxy* input = NULL; - vtkSMInputProperty* ivp = vtkSMInputProperty::SafeDownCast( - refProxy->GetProperty("Input")); - int output_port = 0; - if (ivp && ivp->GetNumberOfProxies()) - { - vtkSMProxy* pxy = ivp->GetProxy(0); - input = vtkSMSourceProxy::SafeDownCast(pxy); - output_port =ivp->GetOutputPortForConnection(0); - } - else - { - // reference proxy has no input. This generally happens when the widget is - // controlling properties of a source. In that case, if the source has been - // "created", simply use the source's bounds. - input = vtkSMSourceProxy::SafeDownCast(refProxy); - } - - if(input) - { - input->GetDataInformation(output_port)->GetBounds(bounds); - return (bounds[1] >= bounds[0] && bounds[3] >= bounds[2] && bounds[5] >= - bounds[4]) ? 1 : 0; - } - return 0; -} - -//----------------------------------------------------------------------------- -void pq3DWidget::updateWidgetVisibility() -{ - const bool widget_visible = this->Internal->Selected - && this->Internal->WidgetVisible; - - const bool widget_enabled = widget_visible; - - this->updateWidgetState(widget_visible, widget_enabled); -} - -//----------------------------------------------------------------------------- -void pq3DWidget::updateWidgetState(bool widget_visible, bool widget_enabled) -{ - if (this->Internal->WidgetProxy && this->renderView()) - { - if(vtkSMIntVectorProperty* const visibility = - vtkSMIntVectorProperty::SafeDownCast( - this->Internal->WidgetProxy->GetProperty("Visibility"))) - { - visibility->SetElement(0, widget_visible); - } - - if(vtkSMIntVectorProperty* const enabled = - vtkSMIntVectorProperty::SafeDownCast( - this->Internal->WidgetProxy->GetProperty("Enabled"))) - { - enabled->SetElement(0, widget_enabled); - } - - this->Internal->WidgetProxy->UpdateVTKObjects(); - - // need to render since the widget visibility state changed. - this->render(); - } - this->updatePickShortcut(); -} - -//----------------------------------------------------------------------------- -void pq3DWidget::updatePickShortcut() -{ - bool pickable = (this->Internal->Selected - && this->Internal->WidgetVisible && - this->Internal->WidgetProxy && this->renderView()); - - this->updatePickShortcut(pickable); -} - -//----------------------------------------------------------------------------- -void pq3DWidget::updatePickShortcut(bool pickable) -{ - if (this->Internal->PickShortcut) - { - this->Internal->PickShortcut->setEnabled(pickable); - } -} - -//----------------------------------------------------------------------------- -void pq3DWidget::resetBounds() -{ - vtkSMNewWidgetRepresentationProxy* widget = this->getWidgetProxy(); - if (!widget) - { - return; - } - - double input_bounds[6]; - if (this->UseSelectionDataBounds) - { - vtkSMProxySelectionModel* selModel = getSelectionModel(widget); - - if (!selModel->GetSelectionDataBounds(input_bounds)) - { - return; - } - } - else if (!this->getReferenceInputBounds(input_bounds)) - { - return; - } - this->resetBounds(input_bounds); - this->setModified(); - this->render(); -} -//----------------------------------------------------------------------------- -void pq3DWidget::updateMasterEnableState(bool I_am_the_Master) -{ - this->Internal->IsMaster = I_am_the_Master; - if(I_am_the_Master) - { - this->setWidgetVisible(this->Internal->LastWidgetVisibilityGoal); - } - else - { - this->hideWidget(); - } -} - -//----------------------------------------------------------------------------- -void pq3DWidget::handleReferenceProxyUserEvent( - vtkObject* caller, unsigned long eventid, void* calldata) -{ - (void)caller; - (void)eventid; - - Q_ASSERT(caller == this->getReferenceProxy()); - Q_ASSERT(eventid == vtkCommand::UserEvent); - - const char* message = reinterpret_cast(calldata); - if (message != NULL && strcmp("HideWidget", message) == 0) - { - this->hideWidget(); - } - else if (message != NULL && strcmp("ShowWidget", message) == 0) - { - this->showWidget(); - } -} diff --git a/smtk/extension/paraview/widgets/pq3DWidget.h b/smtk/extension/paraview/widgets/pq3DWidget.h deleted file mode 100644 index 8c5891ea3b55bcc120930b8351e2239d084ced0f..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/widgets/pq3DWidget.h +++ /dev/null @@ -1,212 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef __smtk_pq_3DWidget_h -#define __smtk_pq_3DWidget_h - -#include "smtk/extension/paraview/widgets/Exports.h" -#include "pqProxyPanel.h" - -class pq3DWidgetInternal; -class pqPipelineSource; -class pqProxy; -class pqRenderViewBase; -class QKeySequence; -class vtkObject; -class vtkPVXMLElement; -class vtkSMNewWidgetRepresentationProxy; -class vtkSMProperty; - -/// pq3DWidget is the abstract superclass for all 3D widgets. -/// This class represents a 3D Widget proxy as well as the GUI for the -/// widget. -class SMTKPQWIDGETSEXT_EXPORT pq3DWidget : public pqProxyPanel -{ - Q_OBJECT - typedef pqProxyPanel Superclass; -public: - pq3DWidget(vtkSMProxy* referenceProxy, vtkSMProxy* proxy, QWidget* parent=0); - virtual ~pq3DWidget(); - - // This method creates widgets using the hints provided by - // the proxy. If a proxy needs more that one - // 3D widget, this method will create all the 3D widgets and - // return them. There is no parent associated with the newly - // created 3D widgets, it's the responsibility of the caller - // to do the memory management for the 3D widgets. - static QList createWidgets(vtkSMProxy* refProxy, vtkSMProxy* proxy); - - /// Controlled proxy is a proxy which is controlled by the 3D widget. - /// A controlled proxy must provide "Hints" describing how - /// the properties of the controlled proxy are controlled by the - /// 3D widget. - vtkSMProxy* getControlledProxy() const; - - vtkSMProxy* getReferenceProxy() const; - - /// Set the hints XML to be using to map the 3D widget to the controlled - /// proxy. This method must be called only after the controlled - /// proxy has been set. The argument is the element - /// which will be controlled by this widget. - void setHints(vtkPVXMLElement* element); - vtkPVXMLElement* getHints() const; - - /// Return the 3D Widget proxy. - vtkSMNewWidgetRepresentationProxy* getWidgetProxy() const; - - /// Returns true if 3D widget visibility is enabled. - /// Note: this *does not* indicate that the 3D widget is currently visible - /// in the display, since this widget's panel might not be visible. - bool widgetVisible() const; - - /// Returns true if 3D widget is selected. - bool widgetSelected() const; - - /// Returns the current render view. - pqRenderViewBase* renderView() const; - - /// Reset the bounds to the specified bounds. - /// This typically calls PlaceWidget on the underlying 3D Widget - /// with reference proxy bounds. - virtual void resetBounds(double bounds[6])=0; - -signals: - /// Notifies observers that widget visibility has changed - void widgetVisibilityChanged(bool); - - /// Notifies observers that the user is dragging the 3D widget - void widgetStartInteraction(); - - /// Notifies observers that the user is done dragging the 3D widget - void widgetEndInteraction(); - - /// Notifies observers that the user is dragging the 3D widget - void widgetInteraction(); - -public slots: - /// Sets 3D widget visibility - void setWidgetVisible(bool); - /// Makes the 3D widget visible. - void showWidget(); - /// Hides the 3D widget. - void hideWidget(); - - /// Activates the widget. Respects the visibility flag. - virtual void select(); - - /// Deactivates the widget. - virtual void deselect(); - - /// Accepts pending changes. Default implementation - /// pushes the 3D widget information property values to - /// the corresponding properties on the controlled widget. - /// The correspondence is determined from the - /// associated with the controlled proxy. - virtual void accept(); - - /// Resets pending changes. Default implementation - /// pushes the property values of the controlled widget to the - /// 3D widget properties. - /// The correspondence is determined from the - /// associated with the controlled proxy. - virtual void reset(); - - /// Set the view that this panel works with - virtual void setView(pqView*); - - /// Resets the bounds of the 3D widget to the reference proxy bounds. - /// This typically calls PlaceWidget on the underlying 3D Widget - /// with reference proxy bounds. - /// This should be explicitly called after the panel is created - /// and the widget is initialized i.e. the reference proxy, controlled proxy - /// and hints have been set. - /// Default implementation uses the getReferenceInputBounds() to get the - /// bounds and then calls resetBounds(double bounds[]). Subclasses generally - /// need to override this resetBounds(double*) method. - virtual void resetBounds(); - - /// When set to true, instead of using the referenceProxy to obtain the - /// default bounds to reset to, it will use the bounds for the selected sources - /// as indicated by - /// pqApplicationCore::getSelectionModel()->getSelectionDataBounds(). - /// Default is false. - virtual void setUseSelectionDataBounds(bool use) - { this->UseSelectionDataBounds = use; } - bool useSelectionDataBounds() - {return this->UseSelectionDataBounds; } - -protected slots: - /// Called to request a render. - void render(); - - // When set to true, instead of intersecting with the mesh surface for picking, it will only get a close point from the mesh - void setPickOnMeshPoint(bool); - - /// triggers a pick action using the current location of the mouse. - void pickPoint(); - - /// Called on each pick, default implementation does nothing. - virtual void pick(double, double, double) {}; - - /// Called when master/slave change - virtual void updateMasterEnableState(bool); - - /// Handle custom user notification to show/hide corresponding widget - void handleReferenceProxyUserEvent(vtkObject*, unsigned long, void*); - -protected: - - // Return true if picking is on mesh point only - bool pickOnMeshPoint() const; - - /// Subclasses can override this method to map properties to - /// GUI. Default implementation updates the internal datastructures - /// so that default implementations can be provided for - /// accept/reset. - virtual void setControlledProperty(const char* function, - vtkSMProperty * controlled_property); - - /// Subclasses should call this method if they support picking. - /// When the user picks a position, - /// the virtual method pick(double, double, double) will be called. - void pickingSupported(const QKeySequence& key); - - void setControlledProperty(vtkSMProperty* widget_property, vtkSMProperty* controlled_property); - - // Subclasses must set the widget proxy. - void setWidgetProxy(vtkSMNewWidgetRepresentationProxy*); - - /// Called when one of the controlled properties change (e.g: by undo/redo) - virtual void onControlledPropertyChanged(); - - /// Used to get the input bounds on for the reference proxy, if any. - /// returns 1 on success, 0 otherwise. - int getReferenceInputBounds(double bounds[6]) const; - - /// Update the widget visibility according to the WidgetVisible and Selected flags - virtual void updateWidgetVisibility(); - - /// Update the widget visibility and enable state - virtual void updateWidgetState(bool visible, bool enable); - - /// updates the enable state of the picking shortcut. - virtual void updatePickShortcut(); - virtual void updatePickShortcut(bool pickable); - -private: - void setControlledProxy(vtkSMProxy*); - - pq3DWidgetInternal* const Internal; - - bool UseSelectionDataBounds; - - class pqStandardWidgets; -}; - -#endif diff --git a/smtk/extension/paraview/widgets/pq3DWidgetInterface.cxx b/smtk/extension/paraview/widgets/pq3DWidgetInterface.cxx deleted file mode 100644 index 12028d98c2129a432063944a13bb10f7761aa464..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/widgets/pq3DWidgetInterface.cxx +++ /dev/null @@ -1,16 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/extension/paraview/widgets/pq3DWidgetInterface.h" - -//----------------------------------------------------------------------------- -pq3DWidgetInterface::~pq3DWidgetInterface() -{ -} diff --git a/smtk/extension/paraview/widgets/pq3DWidgetInterface.h b/smtk/extension/paraview/widgets/pq3DWidgetInterface.h deleted file mode 100644 index 1aa32e67a698bbc9d1f745b8e3c1a6848d74f18f..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/widgets/pq3DWidgetInterface.h +++ /dev/null @@ -1,41 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef __smtk_pq_3DWidgetInterface_h -#define __smtk_pq_3DWidgetInterface_h - -#include -#include "smtk/extension/paraview/widgets/Exports.h" - -class pq3DWidget; -class vtkSMProxy; - -/// Interface for plugins that provide pq3DWidget subclasses. -class SMTKPQWIDGETSEXT_EXPORT pq3DWidgetInterface -{ -public: - virtual ~pq3DWidgetInterface(); - - /// Creates the 3D widget of the requested type is possible otherwise simply - /// returns NULL. - /// \c referenceProxy -- source proxy providing initialization data bounds - /// etc. - /// \c controlledProxy -- proxy whose properties are controlled by the 3D - /// widget. - virtual pq3DWidget* newWidget(const QString& name, - vtkSMProxy* referenceProxy, - vtkSMProxy* controlledProxy)=0; -}; - -Q_DECLARE_INTERFACE(pq3DWidgetInterface, "com.kitware/paraview/3dwidget") - -#endif - - diff --git a/smtk/extension/paraview/widgets/pqArcWidget.cxx b/smtk/extension/paraview/widgets/pqArcWidget.cxx deleted file mode 100644 index 3d53b9f4ba22080c2064a3de4bd9aae6c8231513..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/widgets/pqArcWidget.cxx +++ /dev/null @@ -1,348 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#include "smtk/extension/paraview/widgets/pqArcWidget.h" -#include "ui_qtArcWidget.h" - -#include "pq3DWidgetFactory.h" -#include "pqApplicationCore.h" -#include "pqPropertyLinks.h" -#include "pqServerManagerModel.h" -#include "pqSignalAdaptorTreeWidget.h" -#include "pqSMAdaptor.h" -#include "pqView.h" - -#include -#include -#include -#include - -#include "vtkEventQtSlotConnect.h" -#include "vtkSmartPointer.h" -#include "vtkSMDoubleVectorProperty.h" -#include "vtkSMIntVectorProperty.h" -#include "vtkSMNewWidgetRepresentationProxy.h" -#include "vtkSMPropertyHelper.h" -#include "vtkSMProxyManager.h" -#include "vtkSMProxyProperty.h" - -#include "vtkAbstractWidget.h" -#include "vtkCommand.h" - -#include "vtkClientServerStream.h" - -class pqArcWidget::pqInternals : public Ui::qtArcWidget -{ -public: - vtkSmartPointer ClosedLoopConnect; -}; - -//----------------------------------------------------------------------------- -pqArcWidget::pqArcWidget( - vtkSMProxy* _smproxy, vtkSMProxy* pxy, QWidget* p) : - Superclass(_smproxy, pxy, p) -{ - this->Internals = new pqInternals(); - this->Internals->ClosedLoopConnect = - vtkSmartPointer::New(); - - this->Internals->setupUi(this); - - this->Internals->Visibility->setChecked(this->widgetVisible()); - QObject::connect(this, SIGNAL(widgetVisibilityChanged(bool)), - this->Internals->Visibility, SLOT(setChecked(bool))); - - QObject::connect(this->Internals->Visibility, - SIGNAL(toggled(bool)), this, SLOT(setWidgetVisible(bool))); - - QObject::connect(this->Internals->Closed, - SIGNAL(toggled(bool)), this, SLOT(closeLoop(bool))); - - QObject::connect(this->Internals->Delete, SIGNAL(clicked()), - this, SLOT(deleteAllNodes())); - - QObject::connect(this->Internals->EditMode, SIGNAL(toggled(bool)), - this, SLOT(updateMode())); - QObject::connect(this->Internals->ModifyMode, SIGNAL(toggled(bool)), - this, SLOT(updateMode())); - QObject::connect(this->Internals->Finished, SIGNAL(clicked()), - this, SLOT(finishContour())); - QPushButton* finishButton = this->Internals->Finished; - QPalette applyPalette = finishButton->palette(); - applyPalette.setColor(QPalette::Active, QPalette::Button, QColor(161, 213, 135)); - applyPalette.setColor(QPalette::Inactive, QPalette::Button, QColor(161, 213, 135)); - finishButton->setPalette(applyPalette); - finishButton->setDefault(true); - - pqServerManagerModel* smmodel = - pqApplicationCore::instance()->getServerManagerModel(); - this->createWidget(smmodel->findServer(_smproxy->GetSession())); -} - -//----------------------------------------------------------------------------- -pqArcWidget::~pqArcWidget() -{ - this->freeWidget(); - delete this->Internals; -} - -//----------------------------------------------------------------------------- -void pqArcWidget::enableApplyButton(bool state) -{ - this->Internals->Finished->setEnabled(state); -} -//----------------------------------------------------------------------------- -void pqArcWidget::createWidget(pqServer* server) -{ - vtkSMNewWidgetRepresentationProxy* widget = NULL; - widget = pqApplicationCore::instance()->get3DWidgetFactory()-> - get3DWidget("smtkArcWidgetRepresentation", server); - - this->setWidgetProxy(widget); - - widget->UpdateVTKObjects(); - widget->UpdatePropertyInformation(); - - this->Internals->ClosedLoopConnect->Connect( - widget, vtkCommand::EndInteractionEvent, - this, SLOT(checkContourLoopClosed())); -} - -//----------------------------------------------------------------------------- -void pqArcWidget::freeWidget() -{ - vtkSMNewWidgetRepresentationProxy* widget = this->getWidgetProxy(); - - if (widget) - { -/* - vtkSMPropertyHelper(widget, "Enabled").Set(1); - widget->UpdateVTKObjects(); - widget->InvokeCommand("Initialize"); -*/ - pqApplicationCore::instance()->get3DWidgetFactory()-> - free3DWidget(widget); - } - this->setWidgetProxy(0); -} - -//----------------------------------------------------------------------------- -void pqArcWidget::select() -{ - this->setWidgetVisible(true); - this->setLineColor(QColor::fromRgbF(1.0,0.0,1.0)); - this->Superclass::select(); - this->Superclass::updatePickShortcut(true); - vtkSMPropertyHelper(this->getWidgetProxy(), "Enabled").Set(1); - this->getWidgetProxy()->UpdateVTKObjects(); -} - -//----------------------------------------------------------------------------- -void pqArcWidget::deselect() -{ - this->setLineColor(QColor::fromRgbF(1.0,1.0,1.0)); - this->Superclass::updatePickShortcut(false); - this->setEnabled(0); -} - -//----------------------------------------------------------------------------- -void pqArcWidget::updateWidgetVisibility() -{ - const bool widget_visible = this->widgetVisible(); - const bool widget_enabled = this->widgetSelected(); - this->updateWidgetState(widget_visible, widget_enabled); -} - -//----------------------------------------------------------------------------- -void pqArcWidget::deleteAllNodes() -{ - QMessageBox msgBox; - msgBox.setText("Delete all contour nodes."); - msgBox.setInformativeText("Do you want to delete everything you have drawn?"); - msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); - int ret = msgBox.exec(); - if (ret == QMessageBox::Ok) - { - this->removeAllNodes(); - } -} -//----------------------------------------------------------------------------- -void pqArcWidget::removeAllNodes() -{ - vtkSMNewWidgetRepresentationProxy* widget = this->getWidgetProxy(); - if (widget) - { - widget->InvokeCommand("ClearAllNodes"); -// widget->InvokeCommand("Initialize"); - this->setModified(); - this->render(); - } - -} - -//----------------------------------------------------------------------------- -void pqArcWidget::checkContourLoopClosed() -{ - vtkSMProxy* repProxy = this->getWidgetProxy()->GetRepresentationProxy(); - - //request from the info the state of the loop not on the property it self - vtkSMPropertyHelper loopHelper(repProxy,"ClosedLoopInfo"); - loopHelper.UpdateValueFromServer(); - - int loopClosed = loopHelper.GetAsInt(); - this->Internals->Closed->setChecked(loopClosed); - if(loopClosed) - { - this->ModifyMode(); - emit this->contourLoopClosed(); - } - -} - -//----------------------------------------------------------------------------- -void pqArcWidget::closeLoop(bool val) -{ - vtkSMNewWidgetRepresentationProxy* widget = this->getWidgetProxy(); - if (widget) - { - vtkSMProxy* repProxy = widget->GetRepresentationProxy(); - vtkSMPropertyHelper loopHelper(repProxy,"ClosedLoop"); - if(val) - { - widget->InvokeCommand("CloseLoop"); - } - this->Internals->ModifyMode->setChecked(val); - loopHelper.Set(val); - repProxy->UpdateVTKObjects(); - - this->setModified(); - this->render(); - } -} - -//----------------------------------------------------------------------------- -void pqArcWidget::ModifyMode() -{ - this->Internals->ModifyMode->setChecked(true); -} - -//----------------------------------------------------------------------------- -void pqArcWidget::checkCanBeEdited() -{ - vtkSMNewWidgetRepresentationProxy* widget = this->getWidgetProxy(); - if (widget) - { - vtkSMProxy* repProxy = widget->GetRepresentationProxy(); - vtkSMPropertyHelper canEditHelper(repProxy,"CanEditInfo"); - canEditHelper.UpdateValueFromServer(); - int canEdit = canEditHelper.GetAsInt(); - if (!canEdit) - { - this->Internals->ModifyMode->setChecked(true); - } - this->Internals->EditMode->setVisible(canEdit); - this->Internals->Closed->setVisible(canEdit); - } -} - -//----------------------------------------------------------------------------- -void pqArcWidget::updateMode() -{ - //the text should always be updated to this. - vtkSMNewWidgetRepresentationProxy* widget = this->getWidgetProxy(); - if (widget) - { - if (this->Internals->EditMode->isChecked() ) - { - pqSMAdaptor::setElementProperty( - widget->GetProperty("WidgetState"), 1); - } - else if (this->Internals->ModifyMode->isChecked() ) - { - pqSMAdaptor::setElementProperty( - widget->GetProperty("WidgetState"), 2); - } - widget->UpdateVTKObjects(); - } -} - -//----------------------------------------------------------------------------- -void pqArcWidget::finishContour( ) -{ - vtkSMNewWidgetRepresentationProxy* widget = this->getWidgetProxy(); - widget->GetWidget()->InvokeEvent(vtkCommand::EndInteractionEvent,NULL); - emit this->contourDone(); -} - -//---------------------------------------------------------------------------- -void pqArcWidget::setPointPlacer(vtkSMProxy* placerProxy) -{ - this->updateRepProperty(placerProxy, "PointPlacer"); -} - -//----------------------------------------------------------------------------- -void pqArcWidget::setLineInterpolator(vtkSMProxy* interpProxy) -{ - this->updateRepProperty(interpProxy, "LineInterpolator"); -} - -//----------------------------------------------------------------------------- -void pqArcWidget::reset() -{ - this->Superclass::reset(); - - //update our mode - this->Internals->EditMode->setDisabled(false); - this->Internals->EditMode->setChecked(true); - this->Internals->Closed->blockSignals(true); - this->Internals->Closed->setEnabled(true); - this->Internals->Closed->setChecked(false); - // consistent with Closed checkbox - this->closeLoop(false); - this->Internals->Closed->blockSignals(false); -} - -//----------------------------------------------------------------------------- -void pqArcWidget::setLineColor(const QColor& color) -{ - vtkSMProxy* widget = this->getWidgetProxy(); - vtkSMPropertyHelper(widget, - "LineColor").Set(0, color.redF()); - vtkSMPropertyHelper(widget, - "LineColor").Set(1,color.greenF()); - vtkSMPropertyHelper(widget, - "LineColor").Set(2 , color.blueF()); - widget->UpdateVTKObjects(); -} - -//----------------------------------------------------------------------------- -void pqArcWidget::updateRepProperty( - vtkSMProxy* smProxy, const char* propertyName) -{ - vtkSMNewWidgetRepresentationProxy* widget = this->getWidgetProxy(); - if (widget && propertyName && *propertyName) - { - vtkSMProxyProperty* proxyProp = - vtkSMProxyProperty::SafeDownCast( - widget->GetProperty(propertyName)); - if (proxyProp) - { - proxyProp->RemoveAllProxies(); - proxyProp->AddProxy(smProxy); - widget->UpdateProperty(propertyName); - } - } -} - -//----------------------------------------------------------------------------- -void pqArcWidget::useArcEditingUI(bool isWholeArc) -{ - this->Internals->Delete->setVisible(false); - this->Internals->Closed->setEnabled(isWholeArc); -} diff --git a/smtk/extension/paraview/widgets/pqArcWidget.h b/smtk/extension/paraview/widgets/pqArcWidget.h deleted file mode 100644 index 9f0872c65d7455567e0ed7ccf83367edea20a511..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/widgets/pqArcWidget.h +++ /dev/null @@ -1,115 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= -#ifndef __smtk_pq_ArcWidget_h -#define __smtk_pq_ArcWidget_h - -#include "smtk/extension/paraview/widgets/Exports.h" -#include "pq3DWidget.h" -#include - -class pqServer; -class vtkSMProxy; - -/// GUI for ArcWidgetRepresentation. This is a 3D widget that edits an Arc. -class SMTKPQWIDGETSEXT_EXPORT pqArcWidget : public pq3DWidget -{ - Q_OBJECT - typedef pq3DWidget Superclass; -public: - pqArcWidget(vtkSMProxy* refProxy, vtkSMProxy* proxy, QWidget* parent); - virtual ~pqArcWidget(); - - /// Resets the bounds of the 3D widget to the reference proxy bounds. - /// This typically calls PlaceWidget on the underlying 3D Widget - /// with reference proxy bounds. - /// This should be explicitly called after the panel is created - /// and the widget is initialized i.e. the reference proxy, controlled proxy - /// and hints have been set. - virtual void resetBounds(double /*bounds*/[6]) {} - virtual void resetBounds() - { return this->Superclass::resetBounds(); } - - // Some convenient methods - // Set the point placer/line interpolator - virtual void setPointPlacer(vtkSMProxy*); - virtual void setLineInterpolator(vtkSMProxy*); - - /// Activates the widget. Respects the visibility flag. - virtual void select(); - /// Deactivates the widget. - virtual void deselect(); - - /// Set the line color - virtual void setLineColor(const QColor& color); - - /// Update the UI to be in the Arc Editing mode. - /// In this mode, for whole arc, the Visibility, Closed, Delete, buttonRectArc - /// are all invisible; and for sub-arc, we only allow Modify for now. - virtual void useArcEditingUI(bool isWholeArc); - -signals: - /// Signal emitted when the representation proxy's "ClosedLoop" property - /// is modified. - void contourLoopClosed(); - void contourDone(); - -public slots: - void removeAllNodes(); - void checkContourLoopClosed(); - - /// Close the contour loop - void closeLoop(bool); - - /// Move to modify mode - void ModifyMode( ); - - /// Check if the loop can even go to edit mode - void checkCanBeEdited(); - - /// Move to the next mode ( Drawing, Editing, Done ) - void updateMode( ); - - /// Finish editing the contour - void finishContour( ); - - /// Resets pending changes. Default implementation - /// pushes the property values of the controlled widget to the - /// 3D widget properties. - /// The correspondence is determined from the - /// associated with the controlled proxy. - virtual void reset(); - // enable/disable the apply button of the widget - void enableApplyButton(bool); - -protected: - /// Internal method to create the widget. - virtual void createWidget(pqServer*); - - /// Update the widget visibility according to the WidgetVisible and Selected flags - virtual void updateWidgetVisibility(); - - /// Internal method to free widget. - void freeWidget(); - -protected slots: - void deleteAllNodes(); - -private: - pqArcWidget(const pqArcWidget&); // Not implemented. - void operator=(const pqArcWidget&); // Not implemented. - - void updateRepProperty(vtkSMProxy* smProxy, - const char* propertyName); - - class pqInternals; - pqInternals* Internals; -}; - -#endif diff --git a/smtk/extension/paraview/widgets/pqLineWidget.cxx b/smtk/extension/paraview/widgets/pqLineWidget.cxx deleted file mode 100644 index 2b310a14fa9f46b9585cecdb2f6e9fe882f2210c..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/widgets/pqLineWidget.cxx +++ /dev/null @@ -1,410 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#include "smtk/extension/paraview/widgets/pqLineWidget.h" - -#include "pq3DWidgetFactory.h" -#include "pqApplicationCore.h" -#include "pqServerManagerModel.h" -#include "pqPropertyLinks.h" -#include "pqProxy.h" -#include "pqSMAdaptor.h" -#include "vtkEventQtSlotConnect.h" - -#include "ui_qtLineWidget.h" - -#include - -#include -#include -#include -#include -#include -#include -#include - -///////////////////////////////////////////////////////////////////////// -// pqLineWidget::pqImplementation - -class pqLineWidget::pqImplementation -{ -public: - pqImplementation() : - WidgetPoint1(0), - WidgetPoint2(0) - { - this->Links.setUseUncheckedProperties(false); - this->Links.setAutoUpdateVTKObjects(true); - this->PickPoint1 = true; - } - - ~pqImplementation() - { - } - - /// Stores the Qt widgets - Ui::qtLineWidget UI; - - /// Stores the 3D widget properties - vtkSMDoubleVectorProperty* WidgetPoint1; - vtkSMDoubleVectorProperty* WidgetPoint2; - - /// Maps Qt widgets to the 3D widget - pqPropertyLinks Links; - - bool PickPoint1; -}; - -///////////////////////////////////////////////////////////////////////// -// pqLineWidget - -pqLineWidget::pqLineWidget(vtkSMProxy* o, vtkSMProxy* pxy, QWidget* p, - const char* xmlname/*="LineWidgetRepresentation"*/) : - Superclass(o, pxy, p), - Implementation(new pqImplementation()) -{ - // enable picking. - this->pickingSupported(QKeySequence(tr("P"))); - - this->Implementation->UI.setupUi(this); - this->Implementation->UI.visible->setChecked(this->widgetVisible()); - this->Implementation->UI.pickMeshPoint->setChecked(this->pickOnMeshPoint()); - - // Setup validators for all line widgets. - QDoubleValidator* validator = new QDoubleValidator(this); - this->Implementation->UI.point1X->setValidator(validator); - this->Implementation->UI.point1Y->setValidator(validator); - this->Implementation->UI.point1Z->setValidator(validator); - this->Implementation->UI.point2X->setValidator(validator); - this->Implementation->UI.point2Y->setValidator(validator); - this->Implementation->UI.point2Z->setValidator(validator); - - QObject::connect(this->Implementation->UI.visible, - SIGNAL(toggled(bool)), this, SLOT(setWidgetVisible(bool))); - - QObject::connect(this->Implementation->UI.pickMeshPoint, - SIGNAL(toggled(bool)), this, SLOT(setPickOnMeshPoint(bool))); - - QObject::connect(this, SIGNAL(widgetVisibilityChanged(bool)), - this, SLOT(onWidgetVisibilityChanged(bool))); - - QObject::connect(this->Implementation->UI.xAxis, - SIGNAL(clicked()), this, SLOT(onXAxis())); - QObject::connect(this->Implementation->UI.yAxis, - SIGNAL(clicked()), this, SLOT(onYAxis())); - QObject::connect(this->Implementation->UI.zAxis, - SIGNAL(clicked()), this, SLOT(onZAxis())); - - // Trigger a render when use explicitly edits the positions. - QObject::connect(this->Implementation->UI.point1X, - SIGNAL(editingFinished()), - this, SLOT(render()), Qt::QueuedConnection); - QObject::connect(this->Implementation->UI.point1Y, - SIGNAL(editingFinished()), - this, SLOT(render()), Qt::QueuedConnection); - QObject::connect(this->Implementation->UI.point1Z, - SIGNAL(editingFinished()), - this, SLOT(render()), Qt::QueuedConnection); - QObject::connect(this->Implementation->UI.point2X, - SIGNAL(editingFinished()), - this, SLOT(render()), Qt::QueuedConnection); - QObject::connect(this->Implementation->UI.point2Y, - SIGNAL(editingFinished()), - this, SLOT(render()), Qt::QueuedConnection); - QObject::connect(this->Implementation->UI.point2Z, - SIGNAL(editingFinished()), - this, SLOT(render()), Qt::QueuedConnection); - - pqServerManagerModel* smmodel = - pqApplicationCore::instance()->getServerManagerModel(); - - this->createWidget(smmodel->findServer(o->GetSession()), xmlname); - QObject::connect(&this->Implementation->Links, SIGNAL(qtWidgetChanged()), - this, SLOT(setModified())); -} - -//----------------------------------------------------------------------------- -pqLineWidget::~pqLineWidget() -{ - this->Implementation->Links.removeAllPropertyLinks(); - - if(vtkSMNewWidgetRepresentationProxy* widget = this->getWidgetProxy()) - { - pqApplicationCore::instance()->get3DWidgetFactory()-> - free3DWidget(widget); - - this->setWidgetProxy(0); - } - - delete this->Implementation; -} - -//----------------------------------------------------------------------------- -void pqLineWidget::setControlledProperties(vtkSMProperty* point1, vtkSMProperty* point2) -{ - this->Implementation->WidgetPoint1->Copy(point1); - this->Implementation->WidgetPoint2->Copy(point2); - - // Map widget properties to controlled properties ... - this->setControlledProperty("Point1WorldPosition", point1); - this->setControlledProperty("Point2WorldPosition", point2); -} - -//----------------------------------------------------------------------------- -void pqLineWidget::setControlledProperty(const char* function, - vtkSMProperty* prop) -{ - this->Superclass::setControlledProperty(function, prop); - if (QString("Point1WorldPosition") == function) - { - if (prop->GetXMLLabel()) - { - this->Implementation->UI.labelPoint1->setText( - prop->GetXMLLabel()); - } - } - else if (QString("Point2WorldPosition") == function) - { - if (prop->GetXMLLabel()) - { - this->Implementation->UI.labelPoint2->setText( - prop->GetXMLLabel()); - } - } -} - -//----------------------------------------------------------------------------- -void pqLineWidget::pick(double dx, double dy, double dz) -{ - vtkSMProxy* widget = this->getWidgetProxy(); - QList value; - value << dx << dy << dz; - - bool point1; - int pickPointIndex = this->Implementation->UI.pickPoint->currentIndex(); - if (pickPointIndex == 1) - { - point1 = true; - } - else if (pickPointIndex == 2) - { - point1 = false; - } - else - { - point1 = this->Implementation->PickPoint1; - this->Implementation->PickPoint1 = - !this->Implementation->PickPoint1; - } - - if (point1) - { - pqSMAdaptor::setMultipleElementProperty( - widget->GetProperty("Point1WorldPosition"), value); - } - else - { - pqSMAdaptor::setMultipleElementProperty( - widget->GetProperty("Point2WorldPosition"), value); - } - widget->UpdateVTKObjects(); - - this->setModified(); - this->render(); -} - -//----------------------------------------------------------------------------- -void pqLineWidget::onXAxis() -{ - double object_center[3]; - double object_size[3]; - this->getReferenceBoundingBox(object_center, object_size); - - if(this->Implementation->WidgetPoint1 && this->Implementation->WidgetPoint2) - { - this->Implementation->WidgetPoint1->SetElement(0, object_center[0] - object_size[0] * 0.5); - this->Implementation->WidgetPoint1->SetElement(1, object_center[1]); - this->Implementation->WidgetPoint1->SetElement(2, object_center[2]); - - this->Implementation->WidgetPoint2->SetElement(0, object_center[0] + object_size[0] * 0.5); - this->Implementation->WidgetPoint2->SetElement(1, object_center[1]); - this->Implementation->WidgetPoint2->SetElement(2, object_center[2]); - - this->getWidgetProxy()->UpdateVTKObjects(); - pqApplicationCore::instance()->render(); - this->setModified(); - } -} - -//----------------------------------------------------------------------------- -void pqLineWidget::onYAxis() -{ - double object_center[3]; - double object_size[3]; - this->getReferenceBoundingBox(object_center, object_size); - - if(this->Implementation->WidgetPoint1 && this->Implementation->WidgetPoint2) - { - this->Implementation->WidgetPoint1->SetElement(0, object_center[0]); - this->Implementation->WidgetPoint1->SetElement(1, object_center[1] - object_size[1] * 0.5); - this->Implementation->WidgetPoint1->SetElement(2, object_center[2]); - - this->Implementation->WidgetPoint2->SetElement(0, object_center[0]); - this->Implementation->WidgetPoint2->SetElement(1, object_center[1] + object_size[1] * 0.5); - this->Implementation->WidgetPoint2->SetElement(2, object_center[2]); - - this->getWidgetProxy()->UpdateVTKObjects(); - pqApplicationCore::instance()->render(); - this->setModified(); - } -} - -//----------------------------------------------------------------------------- -void pqLineWidget::onZAxis() -{ - double object_center[3]; - double object_size[3]; - this->getReferenceBoundingBox(object_center, object_size); - - if(this->Implementation->WidgetPoint1 && this->Implementation->WidgetPoint2) - { - this->Implementation->WidgetPoint1->SetElement(0, object_center[0]); - this->Implementation->WidgetPoint1->SetElement(1, object_center[1]); - this->Implementation->WidgetPoint1->SetElement(2, object_center[2] - object_size[2] * 0.5); - - this->Implementation->WidgetPoint2->SetElement(0, object_center[0]); - this->Implementation->WidgetPoint2->SetElement(1, object_center[1]); - this->Implementation->WidgetPoint2->SetElement(2, object_center[2] + object_size[2] * 0.5); - - this->getWidgetProxy()->UpdateVTKObjects(); - pqApplicationCore::instance()->render(); - this->setModified(); - } -} - -//----------------------------------------------------------------------------- -void pqLineWidget::createWidget(pqServer* server, const QString& xmlname) -{ - vtkSMNewWidgetRepresentationProxy* const widget = - pqApplicationCore::instance()->get3DWidgetFactory()->get3DWidget( - xmlname, server, this->getReferenceProxy()); - this->setWidgetProxy(widget); - - widget->UpdateVTKObjects(); - widget->UpdatePropertyInformation(); - - this->Implementation->WidgetPoint1 = vtkSMDoubleVectorProperty::SafeDownCast( - widget->GetProperty("Point1WorldPosition")); - this->Implementation->WidgetPoint2 = vtkSMDoubleVectorProperty::SafeDownCast( - widget->GetProperty("Point2WorldPosition")); - - this->Implementation->Links.addPropertyLink( - this->Implementation->UI.point1X, "text2", - SIGNAL(textChanged(const QString&)), - widget, this->Implementation->WidgetPoint1, 0); - - this->Implementation->Links.addPropertyLink( - this->Implementation->UI.point1Y, "text2", - SIGNAL(textChanged(const QString&)), - widget, this->Implementation->WidgetPoint1, 1); - - this->Implementation->Links.addPropertyLink( - this->Implementation->UI.point1Z, "text2", - SIGNAL(textChanged(const QString&)), - widget, this->Implementation->WidgetPoint1, 2); - - this->Implementation->Links.addPropertyLink( - this->Implementation->UI.point2X, "text2", - SIGNAL(textChanged(const QString&)), - widget, this->Implementation->WidgetPoint2, 0); - - this->Implementation->Links.addPropertyLink( - this->Implementation->UI.point2Y, "text2", - SIGNAL(textChanged(const QString&)), - widget, this->Implementation->WidgetPoint2, 1); - - this->Implementation->Links.addPropertyLink( - this->Implementation->UI.point2Z, "text2", - SIGNAL(textChanged(const QString&)), - widget, this->Implementation->WidgetPoint2, 2); - -} - -//----------------------------------------------------------------------------- -void pqLineWidget::resetBounds(double bounds[6]) -{ - vtkSMNewWidgetRepresentationProxy* widget = this->getWidgetProxy(); - if(vtkSMDoubleVectorProperty* const place_widget = - vtkSMDoubleVectorProperty::SafeDownCast( - widget->GetProperty("PlaceWidget"))) - { - place_widget->SetElements(bounds); - widget->UpdateProperty("PlaceWidget", 1); - } - widget->UpdatePropertyInformation(); -} - -//----------------------------------------------------------------------------- -void pqLineWidget::getReferenceBoundingBox(double center[3], double sz[3]) -{ - double input_bounds[6]; - vtkMath::UninitializeBounds(input_bounds); - this->getReferenceInputBounds(input_bounds); - - if(vtkMath::AreBoundsInitialized(input_bounds)) - { - center[0] = (input_bounds[0] + input_bounds[1]) / 2.0; - center[1] = (input_bounds[2] + input_bounds[3]) / 2.0; - center[2] = (input_bounds[4] + input_bounds[5]) / 2.0; - - // extended a bit - sz[0] = fabs(input_bounds[1] - input_bounds[0]); - sz[1] = fabs(input_bounds[3] - input_bounds[2]); - sz[2] = fabs(input_bounds[5] - input_bounds[4]); - } - else if(this->Implementation->WidgetPoint1 && - this->Implementation->WidgetPoint2) - { - // get spherical bounds from what we had before - double* tmp1 = this->Implementation->WidgetPoint1->GetElements(); - double* tmp2 = this->Implementation->WidgetPoint2->GetElements(); - center[0] = (tmp1[0] + tmp2[0])/2.0; - center[1] = (tmp1[1] + tmp2[1])/2.0; - center[2] = (tmp1[2] + tmp2[2])/2.0; - sz[0] = fabs(tmp1[0] - tmp2[0]); - sz[1] = fabs(tmp1[1] - tmp2[1]); - sz[2] = fabs(tmp1[2] - tmp2[2]); - double s = qMax(qMax(sz[0], sz[1]), sz[2]); - sz[0] = s; - sz[1] = s; - sz[2] = s; - } -} - -//----------------------------------------------------------------------------- -void pqLineWidget::onWidgetVisibilityChanged(bool visible) -{ - this->Implementation->UI.visible->blockSignals(true); - this->Implementation->UI.visible->setChecked(visible); - this->Implementation->UI.visible->blockSignals(false); -} - -//----------------------------------------------------------------------------- -void pqLineWidget::setLineColor(const QColor& color) -{ - vtkSMProxy* widget = this->getWidgetProxy(); - vtkSMPropertyHelper(widget, - "LineColor").Set(0, color.redF()); - vtkSMPropertyHelper(widget, - "LineColor").Set(1,color.greenF()); - vtkSMPropertyHelper(widget, - "LineColor").Set(2 , color.blueF()); - widget->UpdateVTKObjects(); -} diff --git a/smtk/extension/paraview/widgets/pqLineWidget.h b/smtk/extension/paraview/widgets/pqLineWidget.h deleted file mode 100644 index 60ec80730091c14f792c8a2eaeb1ba725d02a5ba..0000000000000000000000000000000000000000 --- a/smtk/extension/paraview/widgets/pqLineWidget.h +++ /dev/null @@ -1,68 +0,0 @@ -//========================================================================= -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -//========================================================================= - -#ifndef __smtk_pq_LineWidget_h -#define __smtk_pq_LineWidget_h - -#include "smtk/extension/paraview/widgets/Exports.h" -#include "pq3DWidget.h" -#include - -class pqServer; - -/// Provides a complete Qt UI for working with a 3D line widget -class SMTKPQWIDGETSEXT_EXPORT pqLineWidget : public pq3DWidget -{ - typedef pq3DWidget Superclass; - - Q_OBJECT - -public: - pqLineWidget(vtkSMProxy* o, vtkSMProxy* pxy, QWidget* p = 0, - const char* xmlname="LineWidgetRepresentation"); - ~pqLineWidget(); - - /// Resets the bounds of the 3D widget to the reference proxy bounds. - /// This typically calls PlaceWidget on the underlying 3D Widget - /// with reference proxy bounds. - /// This should be explicitly called after the panel is created - /// and the widget is initialized i.e. the reference proxy, controlled proxy - /// and hints have been set. - virtual void resetBounds() - { this->Superclass::resetBounds(); } - virtual void resetBounds(double bounds[6]); - - void setControlledProperties(vtkSMProperty* point1, vtkSMProperty* point2); - void setLineColor(const QColor& color); - -public slots: - void onXAxis(); - void onYAxis(); - void onZAxis(); - -protected: - virtual void setControlledProperty(const char* function, - vtkSMProperty * controlled_property); - - /// Called on pick. - virtual void pick(double, double, double); - -private slots: - void onWidgetVisibilityChanged(bool visible); - -private: - void createWidget(pqServer* server, const QString& xmlname); - void getReferenceBoundingBox(double center[3], double size[3]); - - class pqImplementation; - pqImplementation* const Implementation; -}; - -#endif diff --git a/smtk/extension/paraview/widgets/qtArcWidget.cxx b/smtk/extension/paraview/widgets/qtArcWidget.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d56ce854934f1142ab7245be634187bdc674040e --- /dev/null +++ b/smtk/extension/paraview/widgets/qtArcWidget.cxx @@ -0,0 +1,203 @@ +//========================================================================= +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +//========================================================================= +#include "smtk/extension/paraview/widgets/qtArcWidget.h" +#include "ui_qtArcWidget.h" + +#include +#include +#include +#include + +#include "vtkAbstractWidget.h" +#include "vtkCommand.h" +#include "vtkEventQtSlotConnect.h" +#include "vtkNew.h" +#include "vtkSMNewWidgetRepresentationProxy.h" +#include "vtkSMPropertyHelper.h" + +class qtArcWidget::qtInternals : public Ui::qtArcWidget { +public: + vtkNew ClosedLoopConnect; +}; + +//----------------------------------------------------------------------------- +qtArcWidget::qtArcWidget(QWidget *parentWdg) + : Superclass(qtInteractionWidget::createWidget( + "representations", "smtkArcWidgetRepresentation"), + parentWdg), + Internals(new qtArcWidget::qtInternals()) { + this->Internals->setupUi(this); + + this->Internals->Visibility->setChecked(this->isInteractivityEnabled()); + this->connect(this->Internals->Visibility, SIGNAL(toggled(bool)), + SLOT(setEnableInteractivity(bool))); + this->Internals->Visibility->connect( + this, SIGNAL(enableInteractivityChanged(bool)), SLOT(setChecked(bool))); + + QObject::connect(this->Internals->Closed, SIGNAL(toggled(bool)), this, + SLOT(closeLoop(bool))); + + QObject::connect(this->Internals->Delete, SIGNAL(clicked()), this, + SLOT(deleteAllNodes())); + + QObject::connect(this->Internals->EditMode, SIGNAL(toggled(bool)), this, + SLOT(updateMode())); + QObject::connect(this->Internals->ModifyMode, SIGNAL(toggled(bool)), this, + SLOT(updateMode())); + QObject::connect(this->Internals->Finished, SIGNAL(clicked()), this, + SLOT(finishContour())); + QPushButton *finishButton = this->Internals->Finished; + QPalette applyPalette = finishButton->palette(); + applyPalette.setColor(QPalette::Active, QPalette::Button, + QColor(161, 213, 135)); + applyPalette.setColor(QPalette::Inactive, QPalette::Button, + QColor(161, 213, 135)); + finishButton->setPalette(applyPalette); + finishButton->setDefault(true); + + this->Internals->ClosedLoopConnect->Connect( + this->widgetProxy(), vtkCommand::EndInteractionEvent, this, + SLOT(checkContourLoopClosed())); +} + +//----------------------------------------------------------------------------- +qtArcWidget::~qtArcWidget() {} + +//----------------------------------------------------------------------------- +void qtArcWidget::enableApplyButton(bool state) { + this->Internals->Finished->setEnabled(state); +} + +//----------------------------------------------------------------------------- +void qtArcWidget::deleteAllNodes() { + QMessageBox msgBox; + msgBox.setText("Delete all contour nodes."); + msgBox.setInformativeText("Do you want to delete everything you have drawn?"); + msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + int ret = msgBox.exec(); + if (ret == QMessageBox::Ok) { + this->removeAllNodes(); + } +} +//----------------------------------------------------------------------------- +void qtArcWidget::removeAllNodes() { + vtkSMNewWidgetRepresentationProxy *widget = this->widgetProxy(); + if (widget) { + widget->InvokeCommand("ClearAllNodes"); + this->render(); + } +} + +//----------------------------------------------------------------------------- +void qtArcWidget::checkContourLoopClosed() { + vtkSMProxy *repProxy = this->widgetProxy()->GetRepresentationProxy(); + + // request from the info the state of the loop not on the property it self + vtkSMPropertyHelper loopHelper(repProxy, "ClosedLoopInfo"); + loopHelper.UpdateValueFromServer(); + + int loopClosed = loopHelper.GetAsInt(); + this->Internals->Closed->setChecked(loopClosed); + if (loopClosed) { + this->ModifyMode(); + emit this->contourLoopClosed(); + } +} + +//----------------------------------------------------------------------------- +void qtArcWidget::closeLoop(bool val) { + vtkSMNewWidgetRepresentationProxy *widget = this->widgetProxy(); + if (widget) { + vtkSMProxy *repProxy = widget->GetRepresentationProxy(); + vtkSMPropertyHelper loopHelper(repProxy, "ClosedLoop"); + if (val) { + widget->InvokeCommand("CloseLoop"); + } + this->Internals->ModifyMode->setChecked(val); + loopHelper.Set(val); + repProxy->UpdateVTKObjects(); + this->render(); + } +} + +//----------------------------------------------------------------------------- +void qtArcWidget::ModifyMode() { + this->Internals->ModifyMode->setChecked(true); +} + +//----------------------------------------------------------------------------- +void qtArcWidget::checkCanBeEdited() { + vtkSMNewWidgetRepresentationProxy *widget = this->widgetProxy(); + if (widget) { + vtkSMProxy *repProxy = widget->GetRepresentationProxy(); + vtkSMPropertyHelper canEditHelper(repProxy, "CanEditInfo"); + canEditHelper.UpdateValueFromServer(); + int canEdit = canEditHelper.GetAsInt(); + if (!canEdit) { + this->Internals->ModifyMode->setChecked(true); + } + this->Internals->EditMode->setVisible(canEdit); + this->Internals->Closed->setVisible(canEdit); + } +} + +//----------------------------------------------------------------------------- +void qtArcWidget::updateMode() { + // the text should always be updated to this. + vtkSMNewWidgetRepresentationProxy *widget = this->widgetProxy(); + if (widget) { + if (this->Internals->EditMode->isChecked()) { + vtkSMPropertyHelper(widget, "WidgetState").Set(1); + } else if (this->Internals->ModifyMode->isChecked()) { + vtkSMPropertyHelper(widget, "WidgetState").Set(2); + } + widget->UpdateVTKObjects(); + } +} + +//----------------------------------------------------------------------------- +void qtArcWidget::finishContour() { + vtkSMNewWidgetRepresentationProxy *widget = this->widgetProxy(); + widget->GetWidget()->InvokeEvent(vtkCommand::EndInteractionEvent, NULL); + emit this->contourDone(); +} + +//----------------------------------------------------------------------------- +vtkSMProxy *qtArcWidget::pointPlacer() const { + return vtkSMPropertyHelper(this->widgetProxy(), "PointPlacer").GetAsProxy(); +} + +//----------------------------------------------------------------------------- +void qtArcWidget::reset() { + // update our mode + this->Internals->EditMode->setDisabled(false); + this->Internals->EditMode->setChecked(true); + this->Internals->Closed->blockSignals(true); + this->Internals->Closed->setEnabled(true); + this->Internals->Closed->setChecked(false); + // consistent with Closed checkbox + this->closeLoop(false); + this->Internals->Closed->blockSignals(false); +} + +//----------------------------------------------------------------------------- +void qtArcWidget::setLineColor(const QColor &color) { + vtkSMProxy *widget = this->widgetProxy(); + vtkSMPropertyHelper(widget, "LineColor").Set(0, color.redF()); + vtkSMPropertyHelper(widget, "LineColor").Set(1, color.greenF()); + vtkSMPropertyHelper(widget, "LineColor").Set(2, color.blueF()); + widget->UpdateVTKObjects(); +} + +//----------------------------------------------------------------------------- +void qtArcWidget::useArcEditingUI(bool isWholeArc) { + this->Internals->Delete->setVisible(false); + this->Internals->Closed->setEnabled(isWholeArc); +} diff --git a/smtk/extension/paraview/widgets/qtArcWidget.h b/smtk/extension/paraview/widgets/qtArcWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..cddf8023f4f2dce74881a3b4e77c212dd0fcb500 --- /dev/null +++ b/smtk/extension/paraview/widgets/qtArcWidget.h @@ -0,0 +1,88 @@ +//========================================================================= +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +//========================================================================= +#ifndef __smtk_qt_ArcWidget_h +#define __smtk_qt_ArcWidget_h + +/// qtArcWidget is a qtInteractionWidget subclass that uses a +/// **smtkArcWidgetRepresentation** for enabling users to interactively add +/// points in an arc. +/// +/// Developer notes: most this class is simply a modified version of +/// pqArcWidget. SMTK developers should look into cleaning up the API as needed. + +#include "smtk/extension/paraview/widgets/qtInteractionWidget.h" +#include + +class vtkSMProxy; + +class SMTKPQWIDGETSEXT_EXPORT qtArcWidget : public qtInteractionWidget { + Q_OBJECT; + typedef qtInteractionWidget Superclass; + +public: + qtArcWidget(QWidget *parent = nullptr); + virtual ~qtArcWidget(); + + /// Changes the line color to magenta. + void emphasize() { this->setLineColor(QColor::fromRgbF(1.0, 0.0, 1.0)); } + void deemphasize() { this->setLineColor(QColor::fromRgbF(1.0, 1.0, 1.0)); } + + /// Set the line color + virtual void setLineColor(const QColor &color); + + /// Update the UI to be in the Arc Editing mode. + /// In this mode, for whole arc, the Visibility, Closed, Delete, buttonRectArc + /// are all invisible; and for sub-arc, we only allow Modify for now. + virtual void useArcEditingUI(bool isWholeArc); + + /// Returns the point placer proxy. + vtkSMProxy *pointPlacer() const; +signals: + /// Signal emitted when the representation proxy's "ClosedLoop" property + /// is modified. + void contourLoopClosed(); + void contourDone(); + +public slots: + void removeAllNodes(); + void checkContourLoopClosed(); + + /// Close the contour loop + void closeLoop(bool); + + /// Move to modify mode + void ModifyMode(); + + /// Check if the loop can even go to edit mode + void checkCanBeEdited(); + + /// Move to the next mode ( Drawing, Editing, Done ) + void updateMode(); + + /// Finish editing the contour + void finishContour(); + + /// resets the widget. + void reset(); + + // enable/disable the apply button of the widget + void enableApplyButton(bool); + +protected slots: + void deleteAllNodes(); + +private: + Q_DISABLE_COPY(qtArcWidget); + + class qtInternals; + QScopedPointer Internals; +}; + +#endif diff --git a/smtk/extension/paraview/widgets/qtInteractionWidget.cxx b/smtk/extension/paraview/widgets/qtInteractionWidget.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c11ab052097149d0c79b4c6cdad2d0ce2cfb3155 --- /dev/null +++ b/smtk/extension/paraview/widgets/qtInteractionWidget.cxx @@ -0,0 +1,113 @@ +//========================================================================= +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +//========================================================================= +#include "qtInteractionWidget.h" + +#include "pqActiveObjects.h" +#include "pqServer.h" +#include "pqView.h" +#include "vtkEventQtSlotConnect.h" +#include "vtkNew.h" +#include "vtkSMNewWidgetRepresentationProxy.h" +#include "vtkSMParaViewPipelineController.h" +#include "vtkSMPropertyHelper.h" +#include "vtkSMSessionProxyManager.h" + +//----------------------------------------------------------------------------- +qtInteractionWidget::qtInteractionWidget( + const vtkSmartPointer &smproxy, + QWidget *parentWdg) + : Superclass(parentWdg), WidgetProxy(smproxy.Get()), Interactivity(false) { + Q_ASSERT(smproxy != NULL); + + this->VTKConnect->Connect(smproxy, vtkCommand::StartInteractionEvent, this, + SIGNAL(widgetStartInteraction())); + this->VTKConnect->Connect(smproxy, vtkCommand::InteractionEvent, this, + SIGNAL(widgetInteraction())); + this->VTKConnect->Connect(smproxy, vtkCommand::EndInteractionEvent, this, + SIGNAL(widgetEndInteraction())); +} + +//----------------------------------------------------------------------------- +qtInteractionWidget::~qtInteractionWidget() { this->setView(nullptr); } + +//----------------------------------------------------------------------------- +vtkSmartPointer +qtInteractionWidget::createWidget(const char *smgroup, const char *smname) { + pqServer *server = pqActiveObjects::instance().activeServer(); + Q_ASSERT(server); + + vtkSMSessionProxyManager *pxm = server->proxyManager(); + Q_ASSERT(pxm); + vtkSmartPointer proxy; + proxy.TakeReference(pxm->NewProxy(smgroup, smname)); + vtkSmartPointer reprProxy; + reprProxy = vtkSMNewWidgetRepresentationProxy::SafeDownCast(proxy.Get()); + + if (reprProxy) { + vtkNew controller; + controller->InitializeProxy(reprProxy); + } + return reprProxy; +} + +//----------------------------------------------------------------------------- +vtkSMNewWidgetRepresentationProxy *qtInteractionWidget::widgetProxy() const { + return this->WidgetProxy; +} + +//----------------------------------------------------------------------------- +void qtInteractionWidget::setView(pqView *aview) { + if (this->View != aview) { + if (vtkSMProxy *viewProxy = this->View ? this->View->getProxy() : nullptr) { + vtkSMPropertyHelper(viewProxy, "HiddenRepresentations") + .Remove(this->widgetProxy()); + viewProxy->UpdateVTKObjects(); + this->render(); + } + this->View = aview; + if (vtkSMProxy *viewProxy = this->View ? this->View->getProxy() : nullptr) { + vtkSMPropertyHelper(viewProxy, "HiddenRepresentations") + .Add(this->widgetProxy()); + viewProxy->UpdateVTKObjects(); + this->render(); + } + + // this will update the 3d widget's enabled state & visibility as needed. + this->setEnableInteractivity(this->isInteractivityEnabled()); + } +} + +//----------------------------------------------------------------------------- +pqView *qtInteractionWidget::view() const { return this->View; } + +//----------------------------------------------------------------------------- +void qtInteractionWidget::setEnableInteractivity(bool val) { + bool trueInteractivity = (val && this->view()); + + vtkSMProxy *wdgProxy = this->widgetProxy(); + Q_ASSERT(wdgProxy != nullptr); + + vtkSMPropertyHelper(wdgProxy, "Visibility", true).Set(trueInteractivity); + vtkSMPropertyHelper(wdgProxy, "Enabled", true).Set(trueInteractivity); + wdgProxy->UpdateVTKObjects(); + this->render(); + + if (this->Interactivity != val) { + this->Interactivity = val; + emit this->enableInteractivityChanged(this->Interactivity); + } +} + +//----------------------------------------------------------------------------- +void qtInteractionWidget::render() { + if (this->View) { + this->View->render(); + } +} diff --git a/smtk/extension/paraview/widgets/qtInteractionWidget.h b/smtk/extension/paraview/widgets/qtInteractionWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..9c7526ab36dc1d3ca4d701e8c70c8c18186f37c4 --- /dev/null +++ b/smtk/extension/paraview/widgets/qtInteractionWidget.h @@ -0,0 +1,96 @@ +//========================================================================= +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +//========================================================================= +#ifndef __smtk_qt_InteractionWidget_h +#define __smtk_qt_InteractionWidget_h + +#include "smtk/extension/paraview/widgets/Exports.h" + +#include +#include +#include +#include + +class pqView; +class vtkSMNewWidgetRepresentationProxy; +class vtkEventQtSlotConnect; + +/// qtInteractionWidget is a base class for QWidgets that use a +/// vtkAbstractWidget/vtkWidgetRepresentation subclasses (via Proxy's of course) +/// to let user interactive setup parameters. +class SMTKPQWIDGETSEXT_EXPORT qtInteractionWidget : public QWidget { + Q_OBJECT; + typedef QWidget Superclass; + Q_PROPERTY(bool enableInteractivity READ isInteractivityEnabled WRITE + setEnableInteractivity); + +public: + virtual ~qtInteractionWidget(); + + //@{ + /// Set the pqView (typically pqRenderView) which in which to show the widget + /// for interaction. There can only be one view in which the widget can be + /// shown at a time. If the view is changed, the widget will be remove/hidden + /// from the previous view. Set to nullptr to hide the widget. + void setView(pqView *); + pqView *view() const; + //@} + + bool isInteractivityEnabled() const { return this->Interactivity; } + + /// Provides access to vtkSMNewWidgetRepresentationProxy used. + vtkSMNewWidgetRepresentationProxy *widgetProxy() const; + +public slots: + //@{ + /// Controls the visibility and interactivity of the vtkWidgetRepresentation + /// in the view set using `setView`. Note, if no active view is set (or is of + /// an incompatible type), the enabling interactivity will have no effect till + /// a compatible view is provided. + void setEnableInteractivity(bool val); + void enableInteractivity() { this->setEnableInteractivity(true); } + void disableInteractivity() { this->setEnableInteractivity(false); } + //@} + +signals: + /// fired when interactivity state is changed. + void enableInteractivityChanged(bool enabled); + + /// Notifies observers that the user is dragging the 3D widget + void widgetStartInteraction(); + + /// Notifies observers that the user is done dragging the 3D widget + void widgetEndInteraction(); + + /// Notifies observers that the user is dragging the 3D widget + void widgetInteraction(); + +protected slots: + /// call to trigger a render. + void render(); + +protected: + qtInteractionWidget( + const vtkSmartPointer &proxy, + QWidget *parent = nullptr); + + + /// Convenience method to create a new proxy for the given type. + static vtkSmartPointer + createWidget(const char *smgroup, const char *smname); + +private: + Q_DISABLE_COPY(qtInteractionWidget); + QPointer View; + vtkSmartPointer WidgetProxy; + bool Interactivity; + vtkNew VTKConnect; +}; + +#endif diff --git a/smtk/extension/paraview/widgets/qtLineWidget.cxx b/smtk/extension/paraview/widgets/qtLineWidget.cxx new file mode 100644 index 0000000000000000000000000000000000000000..4fabc1b7c96da64beab2e9f1f85ea07a543ac521 --- /dev/null +++ b/smtk/extension/paraview/widgets/qtLineWidget.cxx @@ -0,0 +1,135 @@ +//========================================================================= +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +//========================================================================= +#include "smtk/extension/paraview/widgets/qtLineWidget.h" +#include "ui_qtLineWidget.h" + +#include "pqPropertyLinks.h" +#include "vtkSMNewWidgetRepresentationProxy.h" +#include "vtkSMPropertyHelper.h" + +class qtLineWidget::qtInternals { +public: + Ui::qtLineWidget UI; + pqPropertyLinks Links; +}; + +//----------------------------------------------------------------------------- +qtLineWidget::qtLineWidget(QWidget *parentWdg) + : Superclass(qtInteractionWidget::createWidget("representations", + "LineWidgetRepresentation"), + parentWdg), + Internals(new qtLineWidget::qtInternals()) { + Ui::qtLineWidget &ui(this->Internals->UI); + + ui.setupUi(this); + ui.visible->setChecked(this->isInteractivityEnabled()); + QObject::connect(ui.visible, SIGNAL(toggled(bool)), this, + SLOT(setEnableInteractivity(bool))); + ui.visible->connect(this, SIGNAL(enableInteractivityChanged(bool)), + SLOT(setChecked(bool))); + + // Setup validators for all line widgets. + QDoubleValidator *validator = new QDoubleValidator(this); + ui.point1X->setValidator(validator); + ui.point1Y->setValidator(validator); + ui.point1Z->setValidator(validator); + ui.point2X->setValidator(validator); + ui.point2Y->setValidator(validator); + ui.point2Z->setValidator(validator); + + vtkSMProxy *wdgProxy = this->widgetProxy(); + pqPropertyLinks &links = this->Internals->Links; + if (vtkSMProperty *p1 = wdgProxy->GetProperty("Point1WorldPosition")) { + ui.labelPoint1->setText(tr(p1->GetXMLLabel())); + links.addPropertyLink(ui.point1X, "text2", + SIGNAL(textChangedAndEditingFinished()), wdgProxy, p1, + 0); + links.addPropertyLink(ui.point1Y, "text2", + SIGNAL(textChangedAndEditingFinished()), wdgProxy, p1, + 1); + links.addPropertyLink(ui.point1Z, "text2", + SIGNAL(textChangedAndEditingFinished()), wdgProxy, p1, + 2); + } else { + qCritical("Missing required property for function 'Point1WorldPosition'."); + } + + if (vtkSMProperty *p2 = wdgProxy->GetProperty("Point2WorldPosition")) { + ui.labelPoint2->setText(tr(p2->GetXMLLabel())); + links.addPropertyLink(ui.point2X, "text2", + SIGNAL(textChangedAndEditingFinished()), wdgProxy, p2, + 0); + links.addPropertyLink(ui.point2Y, "text2", + SIGNAL(textChangedAndEditingFinished()), wdgProxy, p2, + 1); + links.addPropertyLink(ui.point2Z, "text2", + SIGNAL(textChangedAndEditingFinished()), wdgProxy, p2, + 2); + } else { + qCritical("Missing required property for function 'Point2WorldPosition'."); + } + + QObject::connect(ui.xAxis, SIGNAL(clicked()), this, SLOT(xAxis())); + QObject::connect(ui.yAxis, SIGNAL(clicked()), this, SLOT(yAxis())); + QObject::connect(ui.zAxis, SIGNAL(clicked()), this, SLOT(zAxis())); + this->connect(&links, SIGNAL(qtWidgetChanged()), SLOT(render())); +} + +//----------------------------------------------------------------------------- +qtLineWidget::~qtLineWidget() {} + +//----------------------------------------------------------------------------- +void qtLineWidget::setLineColor(const QColor &acolor) { + double dcolor[3] = {acolor.redF(), acolor.greenF(), acolor.blueF()}; + if (vtkSMProxy *proxy = this->widgetProxy()) { + vtkSMPropertyHelper(proxy, "LineColor").Set(dcolor, 3); + proxy->UpdateVTKObjects(); + this->render(); + } +} + +//----------------------------------------------------------------------------- +QColor qtLineWidget::color() const { + if (vtkSMProxy *proxy = this->widgetProxy()) { + double dcolor[3]; + vtkSMPropertyHelper(proxy, "LineColor").Get(dcolor, 3); + return QColor::fromRgbF(dcolor[0], dcolor[1], dcolor[2]); + } + + return QColor(); +} + +//----------------------------------------------------------------------------- +void qtLineWidget::setPoints(const double p1[3], const double p2[3]) { + vtkSMProxy *wdg = this->widgetProxy(); + Q_ASSERT(wdg); + + vtkSMPropertyHelper(wdg, "Point1WorldPosition").Set(p1, 3); + vtkSMPropertyHelper(wdg, "Point2WorldPosition").Set(p2, 3); + wdg->UpdateVTKObjects(); + this->render(); +} + +//----------------------------------------------------------------------------- +void qtLineWidget::points(double p1[3], double p2[3]) const { + vtkSMProxy *wdg = this->widgetProxy(); + Q_ASSERT(wdg); + vtkSMPropertyHelper(wdg, "Point1WorldPosition").Get(p1, 3); + vtkSMPropertyHelper(wdg, "Point2WorldPosition").Get(p2, 3); +} + +//----------------------------------------------------------------------------- +void qtLineWidget::xAxis() {} + +//----------------------------------------------------------------------------- +void qtLineWidget::yAxis() {} + +//----------------------------------------------------------------------------- +void qtLineWidget::zAxis() {} diff --git a/smtk/extension/paraview/widgets/qtLineWidget.h b/smtk/extension/paraview/widgets/qtLineWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..b07b0cccc833cafc0410d55b22c45b7b0e1558a3 --- /dev/null +++ b/smtk/extension/paraview/widgets/qtLineWidget.h @@ -0,0 +1,61 @@ +//========================================================================= +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +//========================================================================= +#ifndef __smtk_qtLineWidget_h +#define __smtk_qtLineWidget_h + +#include "smtk/extension/paraview/widgets/qtInteractionWidget.h" +#include + +/// qtLineWidget is a qtInteractionWidget subclass that uses +/// **LineWidgetRepresentation** for enabling suers to interactively set the end +/// points for a line. +class SMTKPQWIDGETSEXT_EXPORT qtLineWidget : public qtInteractionWidget { + Q_OBJECT; + typedef qtInteractionWidget Superclass; + +public: + qtLineWidget(QWidget *parent = nullptr); + virtual ~qtLineWidget(); + + /// Changes the line color to magenta. + void emphasize() { this->setLineColor(QColor::fromRgbF(1.0, 0.0, 1.0)); } + void deemphasize() { this->setLineColor(QColor::fromRgbF(1.0, 1.0, 1.0)); } + + /// Set the line color + void setLineColor(const QColor &color); + void setLineColor(const double rgb[3]) { + this->setLineColor(QColor::fromRgbF(rgb[0], rgb[1], rgb[2])); + } + QColor color() const; + + /// set the point locations. + void setPoints(const double p1[3], const double p2[3]); + + /// get the point locations. + void points(double p1[3], double p2[3]) const; + +public slots: + /// Make the line aligned with x-axis. + void xAxis(); + + /// Make the line aligned with y-axis. + void yAxis(); + + /// Make the line aligned with z-axis. + void zAxis(); + +private: + Q_DISABLE_COPY(qtLineWidget); + + class qtInternals; + QScopedPointer Internals; +}; + +#endif diff --git a/smtk/extension/qt/CMakeLists.txt b/smtk/extension/qt/CMakeLists.txt index c6d7f96345e32d1ac0c2795f073afd09c7aee6b2..73710b3c7363b2c9004bc108066e7e17a9dbb4cc 100644 --- a/smtk/extension/qt/CMakeLists.txt +++ b/smtk/extension/qt/CMakeLists.txt @@ -141,6 +141,11 @@ smtk_export_header(smtkQtExt Exports.h) #install the library and exports the library when used from a build tree smtk_install_library(smtkQtExt) +if (SMTK_ENABLE_TESTING) + target_link_libraries(TestBuild_smtk_extension_qt LINK_PRIVATE smtkQtExt) +endif() + + if (SMTK_ENABLE_EXAMPLES) add_subdirectory(examples) endif() diff --git a/smtk/extension/vtk/widgets/vtkSMTKArcRepresentation.cxx b/smtk/extension/vtk/widgets/vtkSMTKArcRepresentation.cxx index 96e8b378f23214e4661054fd7be76b962dd2004e..0b691ab71ce1c5f529380a7155dd7e03a805cb49 100644 --- a/smtk/extension/vtk/widgets/vtkSMTKArcRepresentation.cxx +++ b/smtk/extension/vtk/widgets/vtkSMTKArcRepresentation.cxx @@ -39,6 +39,8 @@ #include "vtkNew.h" #include "vtkBoundingBox.h" #include "vtkCellArray.h" +#include "vtkUnsignedIntArray.h" +#include "vtkCommand.h" #include @@ -62,14 +64,27 @@ class vtkSMTKArcRepresentation::vtkInternalMap : public vtkInternalMapBase {}; //---------------------------------------------------------------------- vtkSMTKArcRepresentation::vtkSMTKArcRepresentation() { + this->LinesMapper->SetScalarModeToUseCellData(); + this->Property->SetLineWidth(2.0); + this->Property->SetPointSize(6.0); + this->LinesProperty->SetLineWidth(2.0); + this->ActiveProperty->SetLineWidth(2.0); this->LoggingEnabled = false; this->ModifiedPointMap = new vtkSMTKArcRepresentation::vtkInternalMap(); this->CanEdit = 1; + this->PointSelectMode = 0; + this->pointId = 0; + this->PointSelectCallBack = nullptr; } //---------------------------------------------------------------------- vtkSMTKArcRepresentation::~vtkSMTKArcRepresentation() { + if (PointSelectCallBack) + { + PointSelectCallBack->Delete(); + } + PointSelectCallBack = nullptr; if ( this->ModifiedPointMap ) { delete this->ModifiedPointMap; @@ -150,6 +165,10 @@ int vtkSMTKArcRepresentation::ActivateNode( double displayPos[2] ) //---------------------------------------------------------------------- int vtkSMTKArcRepresentation::DeleteNthNode(int n) { + if(PointSelectMode) + { + return 0; + } if (n <= 0) { //you can't delete this first node ever! @@ -182,6 +201,7 @@ void vtkSMTKArcRepresentation::UpdateLines(int index) { this->Superclass::UpdateLines(index); } + //----------------------------------------------------------------------------- void vtkSMTKArcRepresentation::BuildRepresentation() { @@ -234,9 +254,29 @@ int vtkSMTKArcRepresentation::SetActiveNodeToWorldPosition(double worldPos[3]) return ret; } +void vtkSMTKArcRepresentation::StartWidgetInteraction(double startEventPos[2]) +{ + if(PointSelectMode) + { + if( this->GetCurrentOperation() == vtkContourRepresentation::Translate ) + { + this->SetCurrentOperationToInactive(); + } + PointSelectCallBack->Execute(NULL, this->ActiveNode, NULL); + } + else + { + this->Superclass::StartWidgetInteraction(startEventPos); + } +} + //---------------------------------------------------------------------- int vtkSMTKArcRepresentation::AddNodeOnContour(int X, int Y) { + if(PointSelectMode) + { + return 0; + } int idx; double worldPos[3]; @@ -286,6 +326,8 @@ int vtkSMTKArcRepresentation::AddNodeOnContour(int X, int Y) node->WorldPosition[1] = worldPos[1]; node->WorldPosition[2] = worldPos[2]; node->Selected = 0; + node->PointId = this->pointId; + pointId++; this->GetRendererComputedDisplayPositionFromWorldPosition( worldPos, worldOrient, node->NormalizedDisplayPosition ); @@ -313,6 +355,19 @@ int vtkSMTKArcRepresentation::AddNodeOnContour(int X, int Y) return 1; } +int vtkSMTKArcRepresentation::AddNodeAtDisplayPosition(int X, int Y) +{ + int addNode = GetNumberOfNodes(); + int r = vtkOrientedGlyphContourRepresentation::AddNodeAtDisplayPosition(X,Y); + if(r) + { + vtkContourRepresentationNode * node = GetNthNode( addNode ); + node->PointId = this->pointId; + pointId++; + } + return r; +} + //---------------------------------------------------------------------- void vtkSMTKArcRepresentation::UpdatePropertyMap(int index, int flags) { @@ -343,15 +398,33 @@ void vtkSMTKArcRepresentation::UpdatePropertyMap(int index, int flags) } //------------------------------------------------------------------------- -int vtkSMTKArcRepresentation::ComputeInteractionState( - int X, int Y, int modified) +int vtkSMTKArcRepresentation::ComputeInteractionState(int X, int Y, int modified) { if(this->FocalPoint->GetNumberOfPoints() == 0) + { + int numPoints = this->GetNumberOfNodes(); + //Some times the focal point has no data with it. This results in a + //segfault in Superclass::ComputeInteractionState, since when there is + //no data, part of FocalPoint is NULL. there is no check on FocalPoint + //in the superclass. + for ( int i = 0; i < numPoints; i++ ) { - return this->InteractionState; + if ( i != this->ActiveNode ) + { + double worldPos[3]; + double worldOrient[9]; + this->GetNthNodeWorldPosition( i, worldPos ); + this->GetNthNodeWorldOrientation( i, worldOrient ); + this->FocalPoint->InsertNextPoint(worldPos ); + this->FocalData->GetPointData()->GetNormals()->InsertNextTuple(worldOrient+6); + } } - return this->vtkOrientedGlyphContourRepresentation:: - ComputeInteractionState(X, Y, modified); + } + if(this->FocalPoint->GetNumberOfPoints() == 0) + { + return this->InteractionState; // not pretty sure. + } + return Superclass::ComputeInteractionState(X,Y,modified); } //----------------------------------------------------------------------------- @@ -361,6 +434,21 @@ vtkPolyData* vtkSMTKArcRepresentation::GetContourRepresentationAsPolyData() this->UpdateContour(); this->BuildLines(); + vtkSmartPointer ids = + vtkSmartPointer::New(); + ids->SetNumberOfComponents(1); + ids->SetName ("PointIDs"); + //std::set checker; + + for(int i = 0; i < GetNumberOfNodes(); ++i) + { + //assert( checker.find(GetNthNode( i )->PointId) == checker.end()); + //checker.insert(GetNthNode( i )->PointId); + ids->InsertNextTuple1(GetNthNode( i )->PointId); + } + + this->Lines->GetPointData()->SetScalars(ids); + return Lines; } @@ -377,6 +465,16 @@ int vtkSMTKArcRepresentation::GetNodeModifiedFlags(int n) return flag; } +//----------------------------------------------------------------------------- +void vtkSMTKArcRepresentation::SetPointSelectCallBack(vtkCommand * cp) +{ + if(this->PointSelectCallBack) + { + this->PointSelectCallBack->Delete(); + } + this->PointSelectCallBack = cp; +} + //---------------------------------------------------------------------- void vtkSMTKArcRepresentation::Initialize( vtkPolyData * pd ) { @@ -401,6 +499,7 @@ void vtkSMTKArcRepresentation::Initialize( vtkPolyData * pd ) delete this->Internal->Nodes[i]; } this->Internal->Nodes.clear(); + pointId = 0; vtkPolyData *tmpPoints = vtkPolyData::New(); tmpPoints->DeepCopy(pd); @@ -412,6 +511,7 @@ void vtkSMTKArcRepresentation::Initialize( vtkPolyData * pd ) //account for the offset if the input has vert cells vtkIdList *pointIds = pd->GetCell(pd->GetNumberOfVerts())->GetPointIds(); + vtkDataArray * vda = pd->GetPointData()->GetScalars(); vtkIdType numPointsInLineCells = pointIds->GetNumberOfIds(); // Get the worldOrient from the point placer @@ -450,6 +550,8 @@ void vtkSMTKArcRepresentation::Initialize( vtkPolyData * pd ) node->WorldPosition[1] = pos[1]; node->WorldPosition[2] = pos[2]; node->Selected = 0; + node->PointId = vda->GetTuple1(i); + pointId = std::max(pointId, static_cast(node->PointId+1)); node->NormalizedDisplayPosition[0] = displayPos[0]; node->NormalizedDisplayPosition[1] = displayPos[1]; diff --git a/smtk/extension/vtk/widgets/vtkSMTKArcRepresentation.h b/smtk/extension/vtk/widgets/vtkSMTKArcRepresentation.h index 4d7e7cf57b393a5d4017a1ef7354aeaa2b49741a..b0040c7f8b3e182c5fb5a79976bacecb28425ecd 100644 --- a/smtk/extension/vtk/widgets/vtkSMTKArcRepresentation.h +++ b/smtk/extension/vtk/widgets/vtkSMTKArcRepresentation.h @@ -41,7 +41,7 @@ public: // Description: // Standard methods for instances of this class. vtkTypeMacro(vtkSMTKArcRepresentation,vtkOrientedGlyphContourRepresentation); - void PrintSelf(ostream& os, vtkIndent indent); + void PrintSelf(ostream& os, vtkIndent indent) override; // Description: // Controls whether the contour widget should @@ -54,8 +54,8 @@ public: vtkBooleanMacro( LoggingEnabled, int ); //needed to make sure selected nodes are highlighted properly - virtual int SetNthNodeSelected(int); - int ToggleActiveNodeSelected(); + virtual int SetNthNodeSelected(int) override; + int ToggleActiveNodeSelected() override; // Get the number of selected nodes virtual int GetNumberOfSelectedNodes(); @@ -70,20 +70,22 @@ public: virtual int ActivateNode( double displayPos[2] ); //overloaded for logging purposes - virtual int DeleteNthNode(int n); - virtual int SetActiveNodeToWorldPosition( double worldPos[3],double worldOrient[9] ); - virtual int SetActiveNodeToWorldPosition(double worldPos[3]); - virtual int AddNodeOnContour(int X, int Y); + virtual int DeleteNthNode(int n) override; + virtual int SetActiveNodeToWorldPosition( double worldPos[3],double worldOrient[9] ) override; + virtual int SetActiveNodeToWorldPosition(double worldPos[3]) override; + virtual int AddNodeOnContour(int X, int Y) override; + int AddNodeAtDisplayPosition(int X, int Y) override; + void StartWidgetInteraction(double startEventPos[2]) override; // Description: // A method that the widget and its representation use to // communicate with each other. // Re-implement to add initial 0-point checking - virtual int ComputeInteractionState(int X, int Y, int modified=0); + virtual int ComputeInteractionState(int X, int Y, int modified=0) override; // Description: // Get the points in this contour as a vtkPolyData. - virtual vtkPolyData * GetContourRepresentationAsPolyData(); + virtual vtkPolyData * GetContourRepresentationAsPolyData() override; //Description: // Get the flags for a given point @@ -98,6 +100,11 @@ public: vtkGetMacro( CanEdit, int ); vtkBooleanMacro( CanEdit, int ); + vtkSetMacro( PointSelectMode, int ); + vtkGetMacro( PointSelectMode, int ); + vtkBooleanMacro( PointSelectMode, int ); + + void SetPointSelectCallBack(vtkCommand * cp); // takes ownership //Description: // Expose method in superClass void InitializeContour( vtkPolyData * poly, vtkIdList *) @@ -109,8 +116,8 @@ protected: vtkSMTKArcRepresentation(); ~vtkSMTKArcRepresentation(); - virtual void UpdateLines(int index); - virtual void BuildRepresentation(); + virtual void UpdateLines(int index) override; + virtual void BuildRepresentation() override; // Description: // Build a contour representation from externally supplied PolyData. This @@ -131,6 +138,9 @@ protected: //suppor the ability to disable editing of the arc int CanEdit; + int PointSelectMode; + vtkCommand * PointSelectCallBack; + class vtkInternalMap; vtkInternalMap *ModifiedPointMap; @@ -141,6 +151,8 @@ protected: private: vtkSMTKArcRepresentation(const vtkSMTKArcRepresentation&); //Not implemented void operator=(const vtkSMTKArcRepresentation&); //Not implemented + + unsigned pointId; }; #endif