From 6f1da290c7a4db4432c28887ad9d4073c8d443cb Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 8 Dec 2014 16:58:12 +0300 Subject: [PATCH] Provide preselection of Line and Point for Distance --- src/ModuleBase/CMakeLists.txt | 4 - src/ModuleBase/ModuleBase_ModelWidget.h | 4 +- src/ModuleBase/ModuleBase_Operation.cpp | 32 ++--- src/ModuleBase/ModuleBase_Operation.h | 3 +- .../ModuleBase_WidgetShapeSelector.cpp | 131 +++++++++--------- .../ModuleBase_WidgetShapeSelector.h | 2 +- src/ModuleBase/ModuleBase_WidgetValue.cpp | 13 -- src/ModuleBase/ModuleBase_WidgetValue.h | 23 --- .../ModuleBase_WidgetValueFeature.cpp | 35 ----- .../ModuleBase_WidgetValueFeature.h | 50 ------- src/PartSet/PartSet_WidgetPoint2d.cpp | 63 +++++---- src/PartSet/PartSet_WidgetPoint2d.h | 7 +- src/PartSet/PartSet_WidgetPoint2dDistance.cpp | 1 - src/PartSet/PartSet_WidgetPoint2dDistance.h | 1 - 14 files changed, 123 insertions(+), 246 deletions(-) delete mode 100644 src/ModuleBase/ModuleBase_WidgetValue.cpp delete mode 100644 src/ModuleBase/ModuleBase_WidgetValue.h delete mode 100644 src/ModuleBase/ModuleBase_WidgetValueFeature.cpp delete mode 100644 src/ModuleBase/ModuleBase_WidgetValueFeature.h diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 394f67673..e80812b3c 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -15,8 +15,6 @@ SET(PROJECT_HEADERS ModuleBase_WidgetSwitch.h ModuleBase_WidgetShapeSelector.h ModuleBase_IWorkshop.h - ModuleBase_WidgetValue.h - ModuleBase_WidgetValueFeature.h ModuleBase_Definitions.h ModuleBase_SelectionValidator.h ModuleBase_ISelection.h @@ -46,8 +44,6 @@ SET(PROJECT_SOURCES ModuleBase_WidgetFactory.cpp ModuleBase_WidgetSwitch.cpp ModuleBase_WidgetShapeSelector.cpp - ModuleBase_WidgetValue.cpp - ModuleBase_WidgetValueFeature.cpp ModuleBase_WidgetChoice.cpp ModuleBase_WidgetFileSelector.cpp ModuleBase_DoubleSpinBox.cpp diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index c8a91fb93..af9e6a8cd 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -6,6 +6,7 @@ #define MODULEBASE_MODELWIDGET_H #include +#include #include @@ -14,7 +15,6 @@ #include class Config_WidgetAPI; -class ModuleBase_WidgetValue; class QKeyEvent; /**\class ModuleBase_ModelWidget @@ -58,7 +58,7 @@ Q_OBJECT /// Set the given wrapped value to the current widget /// This value should be processed in the widget according to the needs /// \param theValue the wrapped widget value - virtual bool setValue(ModuleBase_WidgetValue* theValue) + virtual bool setSelection(ModuleBase_ViewerPrs theValue) { return false; } diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index eca9c1c2a..89b1957d3 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -9,7 +9,6 @@ #include "ModuleBase_OperationDescription.h" #include "ModuleBase_ModelWidget.h" -#include "ModuleBase_WidgetValueFeature.h" #include "ModuleBase_ViewerPrs.h" #include "ModuleBase_IPropertyPanel.h" #include "ModuleBase_ISelection.h" @@ -243,18 +242,18 @@ bool ModuleBase_Operation::activateByPreselection() ModuleBase_ModelWidget* aWgt, *aFilledWgt = 0; QList::const_iterator aWIt; - QList::const_iterator aPIt; + QList::const_iterator aPIt; bool isSet = false; for (aWIt = aWidgets.constBegin(), aPIt = myPreSelection.constBegin(); (aWIt != aWidgets.constEnd()) && (aPIt != myPreSelection.constEnd()); ++aWIt) { aWgt = (*aWIt); - ModuleBase_WidgetValueFeature* aValue = (*aPIt); + ModuleBase_ViewerPrs aValue = (*aPIt); if (!aWgt->canSetValue()) continue; ++aPIt; - if (!aWgt->setValue(aValue)) { + if (!aWgt->setSelection(aValue)) { isSet = false; break; } else { @@ -304,16 +303,17 @@ void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection, // convert the selection values to the values, which are set to the operation widgets - Handle(V3d_View) aView = theViewer->activeView(); - foreach (ModuleBase_ViewerPrs aPrs, aPreSelected) { - ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature(); - aValue->setObject(aPrs.object()); - - double aX, anY; - if (getViewerPoint(aPrs, theViewer, aX, anY)) - aValue->setPoint(std::shared_ptr(new GeomAPI_Pnt2d(aX, anY))); - myPreSelection.append(aValue); - } + //Handle(V3d_View) aView = theViewer->activeView(); + //foreach (ModuleBase_ViewerPrs aPrs, aPreSelected) { + // ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature(); + // aValue->setObject(aPrs.object()); + + // double aX, anY; + // if (getViewerPoint(aPrs, theViewer, aX, anY)) + // aValue->setPoint(std::shared_ptr(new GeomAPI_Pnt2d(aX, anY))); + // myPreSelection.append(aValue); + //} + myPreSelection = aPreSelected; } //void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget) @@ -349,9 +349,7 @@ bool ModuleBase_Operation::getViewerPoint(ModuleBase_ViewerPrs thePrs, void ModuleBase_Operation::clearPreselection() { - while (!myPreSelection.isEmpty()) { - delete myPreSelection.takeFirst(); - } + myPreSelection.clear(); } void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index 4a155ebe2..acefc9ee8 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -23,7 +23,6 @@ class ModuleBase_OperationDescription; class ModuleBase_IPropertyPanel; class ModuleBase_ISelection; class ModuleBase_IViewer; -class ModuleBase_WidgetValueFeature; class QKeyEvent; @@ -264,7 +263,7 @@ signals: QStringList myNestedFeatures; /// List of pre-selected object - QList myPreSelection; + QList myPreSelection; /// Access to property panel ModuleBase_IPropertyPanel* myPropertyPanel; diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 0f3c87e48..0a15d04b6 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include @@ -244,65 +243,69 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged() // In order to make reselection possible // TODO: check with MPV clearAttribute(); - QObjectPtrList aObjects = myWorkshop->selection()->selectedPresentations(); - if (aObjects.size() > 0) { - ObjectPtr aObject = aObjects.first(); - if ((!mySelectedObject) && (!aObject)) - return; + //QObjectPtrList aObjects = myWorkshop->selection()->selectedPresentations(); + QList aSelected = myWorkshop->selection()->getSelected(); + if (aSelected.size() > 0) + setSelection(aSelected.first()); +} - // Check that the selected object is result (others can not be accepted) - ResultPtr aRes = std::dynamic_pointer_cast(aObject); - if (!aRes) - return; +//******************************************************************** +bool ModuleBase_WidgetShapeSelector::setSelection(ModuleBase_ViewerPrs theValue) +{ + ObjectPtr aObject = theValue.object(); + if ((!mySelectedObject) && (!aObject)) + return false; - if (myFeature) { - // We can not select a result of our feature - const std::list>& aResList = myFeature->results(); - std::list >::const_iterator aIt; - for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) { - if ((*aIt) == aRes) - return; - } + // Check that the selected object is result (others can not be accepted) + ResultPtr aRes = std::dynamic_pointer_cast(aObject); + if (!aRes) + return false; + + if (myFeature) { + // We can not select a result of our feature + const std::list>& aResList = myFeature->results(); + std::list >::const_iterator aIt; + for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) { + if ((*aIt) == aRes) + return false; } - // Check that object belongs to active document or PartSet - DocumentPtr aDoc = aRes->document(); - SessionPtr aMgr = ModelAPI_Session::get(); - if (!(aDoc == aMgr->activeDocument()) && !(aDoc == aMgr->moduleDocument())) - return; + } + // Check that object belongs to active document or PartSet + DocumentPtr aDoc = aRes->document(); + SessionPtr aMgr = ModelAPI_Session::get(); + if (!(aDoc == aMgr->activeDocument()) && !(aDoc == aMgr->moduleDocument())) + return false; - // Check that the result has a shape - GeomShapePtr aShape = ModelAPI_Tools::shape(aRes); - if (!aShape) - return; + // Check that the result has a shape + GeomShapePtr aShape = ModelAPI_Tools::shape(aRes); + if (!aShape) + return false; - /// Check that object has acceptable type - if (!acceptObjectType(aObject)) - return; + /// Check that object has acceptable type + if (!acceptObjectType(aObject)) + return false; - // Get sub-shapes from local selection - if (myUseSubShapes) { - NCollection_List aShapeList; - std::list aOwners; - myWorkshop->selection()->selectedShapes(aShapeList, aOwners); - if (aShapeList.Extent() > 0) { - aShape = std::shared_ptr(new GeomAPI_Shape()); - aShape->setImpl(new TopoDS_Shape(aShapeList.First())); - } + // Get sub-shapes from local selection + if (myUseSubShapes) { + if (!theValue.shape().IsNull()) { + aShape = std::shared_ptr(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(theValue.shape())); } + } - // Check that the selection corresponds to selection type - if (myUseSubShapes) { - if (!acceptSubShape(aShape)) - return; - } else { - if (!acceptObjectShape(aObject)) - return; - } - if (isValid(aObject, aShape)) { - setObject(aObject, aShape); - emit focusOutWidget(this); - } + // Check that the selection corresponds to selection type + if (myUseSubShapes) { + if (!acceptSubShape(aShape)) + return false; + } else { + if (!acceptObjectShape(aObject)) + return false; } + if (isValid(aObject, aShape)) { + setObject(aObject, aShape); + emit focusOutWidget(this); + } + return true; } //******************************************************************** @@ -443,21 +446,17 @@ void ModuleBase_WidgetShapeSelector::raisePanel() const } //******************************************************************** -bool ModuleBase_WidgetShapeSelector::setValue(ModuleBase_WidgetValue* theValue) -{ - if (theValue) { - ModuleBase_WidgetValueFeature* aFeatureValue = - dynamic_cast(theValue); - if (aFeatureValue && aFeatureValue->object()) { - ObjectPtr aObject = aFeatureValue->object(); - if (acceptObjectShape(aObject)) { - setObject(aObject); - return true; - } - } - } - return false; -} +//bool ModuleBase_WidgetShapeSelector::setSelection(ModuleBase_ViewerPrs theValue) +//{ +// if (theValue.object()) { +// ObjectPtr aObject = theValue.object(); +// if (acceptObjectShape(aObject)) { +// setObject(aObject); +// return true; +// } +// } +// return false; +//} //******************************************************************** void ModuleBase_WidgetShapeSelector::activate() diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index 0e479e178..d2b27af6b 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -58,7 +58,7 @@ Q_OBJECT /// Set the given wrapped value to the current widget /// This value should be processed in the widget according to the needs /// \param theValue the wrapped widget value - virtual bool setValue(ModuleBase_WidgetValue* theValue); + virtual bool setSelection(ModuleBase_ViewerPrs theValue); /// The methiod called when widget is activated diff --git a/src/ModuleBase/ModuleBase_WidgetValue.cpp b/src/ModuleBase/ModuleBase_WidgetValue.cpp deleted file mode 100644 index 83a9d27a7..000000000 --- a/src/ModuleBase/ModuleBase_WidgetValue.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// File: ModuleBase_WidgetValue.cpp -// Created: 25 Apr 2014 -// Author: Natalia ERMOLAEVA - -#include - -ModuleBase_WidgetValue::ModuleBase_WidgetValue() -{ -} - -ModuleBase_WidgetValue::~ModuleBase_WidgetValue() -{ -} diff --git a/src/ModuleBase/ModuleBase_WidgetValue.h b/src/ModuleBase/ModuleBase_WidgetValue.h deleted file mode 100644 index 38b8e51b3..000000000 --- a/src/ModuleBase/ModuleBase_WidgetValue.h +++ /dev/null @@ -1,23 +0,0 @@ -// File: ModuleBase_WidgetValue.h -// Created: 25 Apr 2014 -// Author: Natalia ERMOLAEVA - -#ifndef ModuleBase_WidgetValue_H -#define ModuleBase_WidgetValue_H - -#include - -/**\class ModuleBase_WidgetValue - * \ingroup GUI - * \brief Custom widget value. An abstract class to be redefined and to be set in the model widget - */ -class MODULEBASE_EXPORT ModuleBase_WidgetValue -{ - public: - /// Constructor - ModuleBase_WidgetValue(); - /// Destructor - virtual ~ModuleBase_WidgetValue(); -}; - -#endif diff --git a/src/ModuleBase/ModuleBase_WidgetValueFeature.cpp b/src/ModuleBase/ModuleBase_WidgetValueFeature.cpp deleted file mode 100644 index 43d3a7cfe..000000000 --- a/src/ModuleBase/ModuleBase_WidgetValueFeature.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// File: ModuleBase_WidgetValueFeature.cpp -// Created: 25 Apr 2014 -// Author: Natalia ERMOLAEVA - -#include - -#include - -ModuleBase_WidgetValueFeature::ModuleBase_WidgetValueFeature() -{ -} - -ModuleBase_WidgetValueFeature::~ModuleBase_WidgetValueFeature() -{ -} - -void ModuleBase_WidgetValueFeature::setObject(const ObjectPtr& theFeature) -{ - myResult = theFeature; -} - -const ObjectPtr& ModuleBase_WidgetValueFeature::object() const -{ - return myResult; -} - -void ModuleBase_WidgetValueFeature::setPoint(const std::shared_ptr& thePoint) -{ - myPoint = thePoint; -} - -const std::shared_ptr& ModuleBase_WidgetValueFeature::point() const -{ - return myPoint; -} diff --git a/src/ModuleBase/ModuleBase_WidgetValueFeature.h b/src/ModuleBase/ModuleBase_WidgetValueFeature.h deleted file mode 100644 index d11a6bfd9..000000000 --- a/src/ModuleBase/ModuleBase_WidgetValueFeature.h +++ /dev/null @@ -1,50 +0,0 @@ -// File: ModuleBase_WidgetValueFeature.h -// Created: 25 Apr 2014 -// Author: Natalia ERMOLAEVA - -#ifndef ModuleBase_WidgetValueFeature_H -#define ModuleBase_WidgetValueFeature_H - -#include -#include - -#include - -#include - -class GeomAPI_Pnt2d; - -/**\class ModuleBase_WidgetValueFeature - * \ingroup GUI - * \brief Custom widget value. The widget contains a feature and 2D point. - */ -class ModuleBase_WidgetValueFeature : public ModuleBase_WidgetValue -{ - public: - /// Constructor - MODULEBASE_EXPORT ModuleBase_WidgetValueFeature(); - /// Destructor - MODULEBASE_EXPORT virtual ~ModuleBase_WidgetValueFeature(); - - /// Fill the widget values by given point - /// \param thePoint the point - MODULEBASE_EXPORT void setObject(const ObjectPtr& theFeature); - - /// Returns the widget values by given point - /// \return theFeature the current feature - MODULEBASE_EXPORT const ObjectPtr& object() const; - - /// Fill the widget values by given point - /// \param thePoint the point - MODULEBASE_EXPORT void setPoint(const std::shared_ptr& thePoint); - - /// Returns the widget point - /// \return the current point - MODULEBASE_EXPORT const std::shared_ptr& point() const; - - private: - ObjectPtr myResult; - std::shared_ptr myPoint; -}; - -#endif diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 8c7ce43fc..d21d25f0a 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include #include @@ -89,19 +88,15 @@ PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D() { } -bool PartSet_WidgetPoint2D::setValue(ModuleBase_WidgetValue* theValue) +bool PartSet_WidgetPoint2D::setSelection(ModuleBase_ViewerPrs theValue) { + Handle(V3d_View) aView = myWorkshop->viewer()->activeView(); bool isDone = false; - if (theValue) { - ModuleBase_WidgetValueFeature* aFeatureValue = - dynamic_cast(theValue); - if (aFeatureValue) { - std::shared_ptr aPoint = aFeatureValue->point(); - if (aPoint) { - setPoint(aPoint->x(), aPoint->y()); - isDone = true; - } - } + TopoDS_Shape aShape = theValue.shape(); + double aX, aY; + if (getPoint2d(aView, aShape, aX, aY)) { + setPoint(aX, aY); + isDone = true; } return isDone; } @@ -213,6 +208,24 @@ void PartSet_WidgetPoint2D::deactivate() myWorkshop->moduleConnector()->deactivateSubShapesSelection(); } +bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView, + const TopoDS_Shape& theShape, + double& theX, double& theY) const +{ + if (!theShape.IsNull()) { + if (theShape.ShapeType() == TopAbs_VERTEX) { + const TopoDS_Vertex& aVertex = TopoDS::Vertex(theShape); + if (!aVertex.IsNull()) { + // A case when point is taken from existing vertex + gp_Pnt aPoint = BRep_Tool::Pnt(aVertex); + PartSet_Tools::convertTo2D(aPoint, mySketch, theView, theX, theY); + return true; + } + } + } + return false; +} + void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { @@ -222,23 +235,15 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous aSelection->selectedShapes(aShapes, aObjects); if (aShapes.Extent() > 0) { TopoDS_Shape aShape = aShapes.First(); - if (!aShape.IsNull()) { - if (aShape.ShapeType() == TopAbs_VERTEX) { - const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape); - if (!aVertex.IsNull()) { - // A case when point is taken from existing vertex - gp_Pnt aPoint = BRep_Tool::Pnt(aVertex); - double aX, aY; - PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY); - setPoint(aX, aY); - - PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY); - emit vertexSelected(aObjects.front(), aShape); - QApplication::processEvents(); - emit focusOutWidget(this); - return; - } - } + double aX, aY; + if (getPoint2d(theWnd->v3dView(), aShape, aX, aY)) { + setPoint(aX, aY); + + PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY); + emit vertexSelected(aObjects.front(), aShape); + QApplication::processEvents(); + emit focusOutWidget(this); + return; } } // A case when point is taken from mouse event diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index 0e8ae42b1..4971997a8 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -12,9 +12,9 @@ #include #include +#include class ModelAPI_Feature; -class ModuleBase_WidgetValue; class ModuleBase_IWorkshop; class ModuleBase_DoubleSpinBox; class ModuleBase_IViewWindow; @@ -44,7 +44,7 @@ Q_OBJECT /// Set the given wrapped value to the current widget /// This value should be processed in the widget according to the needs /// \param theValue the wrapped widget value - virtual bool setValue(ModuleBase_WidgetValue* theValue); + virtual bool setSelection(ModuleBase_ViewerPrs theValue); /// Saves the internal parameters to the given feature /// \param theObject a model feature to be changed @@ -97,6 +97,9 @@ protected slots: void onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); private: + bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape, + double& theX, double& theY) const; + XGUI_Workshop* myWorkshop; QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index 29c0ad56b..9fdbc3f27 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -5,7 +5,6 @@ #include "PartSet_WidgetPoint2dDistance.h" #include "PartSet_Tools.h" -#include #include #include diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.h b/src/PartSet/PartSet_WidgetPoint2dDistance.h index 7c2364780..84d962a06 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.h +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.h @@ -10,7 +10,6 @@ #include -//class ModuleBase_WidgetValue; class GeomAPI_Pnt2d; class XGUI_Workshop; class ModuleBase_IViewWindow; -- 2.39.2