From d554939aa65b268649bc9fcb7e2a1feb5d99bcac Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 7 Nov 2014 19:09:17 +0300 Subject: [PATCH] Issues #248, #235 The obtaining of the point from the TopoDS_Vertex shape during saving the operation preselection. Moving the algorithm of a point get from a Vertex shape into a tool method to be called where it is necessary. --- src/ModuleBase/ModuleBase_Operation.cpp | 52 ++++++++++++++----- src/ModuleBase/ModuleBase_Operation.h | 17 +++++- src/PartSet/PartSet_OperationFeatureBase.cpp | 26 +++++----- src/PartSet/PartSet_OperationFeatureBase.h | 10 ++++ .../PartSet_OperationFeatureCreate.cpp | 36 +++++-------- src/PartSet/PartSet_OperationFeatureEdit.cpp | 25 ++------- src/PartSet/PartSet_Tools.cpp | 23 +++++++- src/PartSet/PartSet_Tools.h | 9 ++++ 8 files changed, 127 insertions(+), 71 deletions(-) diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index b3bf0b075..e6a2e3d0a 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -13,6 +13,7 @@ #include "ModuleBase_ViewerPrs.h" #include "ModuleBase_IPropertyPanel.h" #include "ModuleBase_ISelection.h" +#include "ModuleBase_IViewer.h" #include #include @@ -48,6 +49,7 @@ ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* thePar ModuleBase_Operation::~ModuleBase_Operation() { delete myDescription; + clearPreselection(); } QString ModuleBase_Operation::id() const @@ -255,21 +257,15 @@ bool ModuleBase_Operation::activateByPreselection() return false; ModuleBase_ModelWidget* aWgt, *aFilledWgt = 0; - ModuleBase_ViewerPrs aPrs; 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, ++aPIt) { aWgt = (*aWIt); - aPrs = (*aPIt); - ModuleBase_WidgetValueFeature aValue; - aValue.setObject(aPrs.object()); - // Check if the selection has a selected point - // for today it is impossible to do because - // the selected point demands convertation to Sketch plane 2d - if (!aWgt->setValue(&aValue)) { + ModuleBase_WidgetValueFeature* aValue = (*aPIt); + if (!aWgt->setValue(aValue)) { isSet = false; break; } else { @@ -305,14 +301,16 @@ bool ModuleBase_Operation::activateByPreselection() } void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection, - ModuleBase_IViewer* /*theViewer*/) + ModuleBase_IViewer* theViewer) { - myPreSelection.clear(); + clearPreselection(); + QList aPreSelected; // Check that the selected result are not results of operation feature - QList aSelected = theSelection->getSelected(); FeaturePtr aFeature = feature(); if (aFeature) { + QList aSelected = theSelection->getSelected(); + std::list aResults = aFeature->results(); QList aResList; std::list::const_iterator aIt; @@ -321,10 +319,23 @@ void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection, foreach (ModuleBase_ViewerPrs aPrs, aSelected) { if ((!aResList.contains(aPrs.object())) && (aPrs.object() != aFeature)) - myPreSelection.append(aPrs); + aPreSelected.append(aPrs); } } else - myPreSelection = aSelected; + aPreSelected = theSelection->getSelected(); + + // 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(boost::shared_ptr(new GeomAPI_Pnt2d(aX, anY))); + myPreSelection.append(aValue); + } } void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget) @@ -351,6 +362,19 @@ bool ModuleBase_Operation::setWidgetValue(ObjectPtr theFeature, double theX, dou return isApplyed; } +bool ModuleBase_Operation::getViewerPoint(ModuleBase_ViewerPrs thePrs, + ModuleBase_IViewer* theViewer, + double& theX, double& theY) +{ + return false; +} + +void ModuleBase_Operation::clearPreselection() +{ + while (!myPreSelection.isEmpty()) { + delete myPreSelection.takeFirst(); + } +} void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) { diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index 07b413218..cf92faa43 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -23,6 +23,7 @@ class ModuleBase_OperationDescription; class ModuleBase_IPropertyPanel; class ModuleBase_ISelection; class ModuleBase_IViewer; +class ModuleBase_WidgetValueFeature; class QKeyEvent; @@ -217,6 +218,20 @@ signals: /// \return true if the point is set virtual bool setWidgetValue(ObjectPtr theFeature, double theX, double theY); + /// Return a widget value point by the selection and the viewer position + /// The default realization returns false + /// \param thePrs the presentation + /// \param theViewer a viewer to have the viewer the eye position + /// \param theX the horizontal coordinate + /// \param theY the vertical coordinate + /// \return true if the point exits in the selection + virtual bool getViewerPoint(ModuleBase_ViewerPrs thePrs, + ModuleBase_IViewer* theViewer, + double& theX, double& theY); + + // Removes the preselection information and clears the map of preselection + void clearPreselection(); + protected: FeaturePtr myFeature; /// the operation feature to be handled @@ -233,7 +248,7 @@ signals: QStringList myNestedFeatures; /// List of pre-selected object - QList myPreSelection; + QList myPreSelection; /// Access to property panel ModuleBase_IPropertyPanel* myPropertyPanel; diff --git a/src/PartSet/PartSet_OperationFeatureBase.cpp b/src/PartSet/PartSet_OperationFeatureBase.cpp index 6beb71ca4..2d06659a0 100644 --- a/src/PartSet/PartSet_OperationFeatureBase.cpp +++ b/src/PartSet/PartSet_OperationFeatureBase.cpp @@ -73,19 +73,13 @@ void PartSet_OperationFeatureBase::mouseReleased(QMouseEvent* theEvent, ModuleBa PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY); } else { ModuleBase_ViewerPrs aPrs = aSelected.first(); + if (getViewerPoint(aPrs, theViewer, aX, anY)) { + ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); + PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY); + } const TopoDS_Shape& aShape = aPrs.shape(); - if (!aShape.IsNull()) { - if (aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected - const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape); - if (!aVertex.IsNull()) { - aPoint = BRep_Tool::Pnt(aVertex); - PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY); - ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); - PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY); - } - } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected - PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY); - } + if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE) { // a line is selected + PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY); } } ObjectPtr aFeature; @@ -110,6 +104,14 @@ void PartSet_OperationFeatureBase::mouseReleased(QMouseEvent* theEvent, ModuleBa commit(); } +bool PartSet_OperationFeatureBase::getViewerPoint(ModuleBase_ViewerPrs thePrs, + ModuleBase_IViewer* theViewer, + double& theX, double& theY) +{ + return PartSet_Tools::hasVertexShape(thePrs, sketch(), theViewer->activeView(), + theX, theY); +} + /*bool PartSet_OperationFeatureBase::setWidgetValue(ObjectPtr theFeature, double theX, double theY) { ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); diff --git a/src/PartSet/PartSet_OperationFeatureBase.h b/src/PartSet/PartSet_OperationFeatureBase.h index bb74a4431..ee290dd44 100644 --- a/src/PartSet/PartSet_OperationFeatureBase.h +++ b/src/PartSet/PartSet_OperationFeatureBase.h @@ -45,6 +45,16 @@ Q_OBJECT virtual void mouseReleased(QMouseEvent* theEvent, ModuleBase_IViewer* theViewer, ModuleBase_ISelection* theSelection); + protected: + /// Return a widget value point by the selection and the viewer position + /// \param thePrs the presentation + /// \param theViewer a viewer to have the viewer the eye position + /// \param theX the horizontal coordinate + /// \param theY the vertical coordinate + /// \return true if the point exits in the selection + virtual bool getViewerPoint(ModuleBase_ViewerPrs thePrs, + ModuleBase_IViewer* theViewer, + double& theX, double& theY); protected: CompositeFeaturePtr mySketch; ///< the sketch of the feature diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index 49c8b2490..eed4d1ea4 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -33,10 +33,6 @@ #include #include -#include -#include -#include -#include #ifdef _DEBUG #include @@ -119,26 +115,20 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Module PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY); } else { ModuleBase_ViewerPrs aPrs = aSelected.first(); + if (getViewerPoint(aPrs, theViewer, aX, anY)) { + ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); + PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY); + isClosedContour = true; + } const TopoDS_Shape& aShape = aPrs.shape(); - if (!aShape.IsNull()) { - if (aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected - const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape); - if (!aVertex.IsNull()) { - aPoint = BRep_Tool::Pnt(aVertex); - PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY); - ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget(); - PartSet_Tools::setConstraints(sketch(), feature(), aActiveWgt->attributeID(), aX, anY); - isClosedContour = true; - } - } else if (aShape.ShapeType() == TopAbs_EDGE) { // a line is selected - ObjectPtr aObject = aPrs.object(); - if (sketch()->isSub(aObject)) - PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY); - else { - // we have to create the selected edge for the current sketch - ResultPtr aRes = PartSet_Tools::createFixedObjectByEdge(aPrs, sketch()); - aSelected.first().setFeature(aRes); - } + if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE) { // a line is selected + ObjectPtr aObject = aPrs.object(); + if (sketch()->isSub(aObject)) + PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aX, anY); + else { + // we have to create the selected edge for the current sketch + ResultPtr aRes = PartSet_Tools::createFixedObjectByEdge(aPrs, sketch()); + aSelected.first().setFeature(aRes); } } } diff --git a/src/PartSet/PartSet_OperationFeatureEdit.cpp b/src/PartSet/PartSet_OperationFeatureEdit.cpp index 6c6c19682..a49e63dc7 100644 --- a/src/PartSet/PartSet_OperationFeatureEdit.cpp +++ b/src/PartSet/PartSet_OperationFeatureEdit.cpp @@ -28,9 +28,6 @@ #include #include -#include -#include -#include #include #include @@ -89,14 +86,10 @@ void PartSet_OperationFeatureEdit::fillFeature2Attribute( // 1. find all features with skipping features with selected vertex shapes theFeature2Attribute.clear(); // firstly, collect the features without local selection + double aX, anY; foreach (ModuleBase_ViewerPrs aPrs, thePresentations) { - const TopoDS_Shape& aShape = aPrs.shape(); - if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected - const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape); - if (!aVertex.IsNull()) { - continue; - } - } + if (getViewerPoint(aPrs, theViewer, aX, anY)) + continue; else { ObjectPtr aObject = aPrs.object(); if (!aObject) @@ -113,13 +106,8 @@ void PartSet_OperationFeatureEdit::fillFeature2Attribute( // if the list already has this feature, the local selection is skipped // that means that if the selection contains a feature and a feature with local selected point, // the edit is performed for a full feature - Handle(V3d_View) aView = theViewer->activeView(); foreach (ModuleBase_ViewerPrs aPrs, thePresentations) { - const TopoDS_Shape& aShape = aPrs.shape(); - if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) { // a point is selected - const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape); - if (aVertex.IsNull()) - continue; + if (getViewerPoint(aPrs, theViewer, aX, anY)) { ObjectPtr aObject = aPrs.object(); if (!aObject) continue; @@ -128,11 +116,8 @@ void PartSet_OperationFeatureEdit::fillFeature2Attribute( continue; // append the attribute of the vertex if it is found on the current feature - gp_Pnt aPoint = BRep_Tool::Pnt(aVertex); - double aVX, aVY; - PartSet_Tools::convertTo2D(aPoint, sketch(), aView, aVX, aVY); boost::shared_ptr aPoint2D = PartSet_Tools::getFeaturePoint( - aFeature, aVX, aVY); + aFeature, aX, anY); std::string anAttribute = aFeature->data()->id(aPoint2D); std::list aList; if (theFeature2Attribute.find(aFeature) != theFeature2Attribute.end()) diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index b5407f6f7..d13695361 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #ifdef _DEBUG #include @@ -486,4 +487,24 @@ ResultPtr PartSet_Tools::findExternalEdge(CompositeFeaturePtr theSketch, boost:: } } return ResultPtr(); -} \ No newline at end of file +} + +bool PartSet_Tools::hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch, + Handle_V3d_View theView, double& theX, double& theY) +{ + bool aHasVertex = false; + + const TopoDS_Shape& aShape = thePrs.shape(); + if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) + { + const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape); + if (!aVertex.IsNull()) + { + gp_Pnt aPoint = BRep_Tool::Pnt(aVertex); + PartSet_Tools::convertTo2D(aPoint, theSketch, theView, theX, theY); + aHasVertex = true; + } + } + + return aHasVertex; +} diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index a436f7b0b..912db7307 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -151,6 +151,15 @@ class PARTSET_EXPORT PartSet_Tools /// \param theEdge - the edge /// \return result object with external edge if it is found static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, boost::shared_ptr theEdge); + + /// Returns whether the selected presentation has a shape with the vertex type + /// \param thePrs a selected presentation + /// \param theSketch the sketch feature + /// \param theView a 3D view + /// \param theX the output horizontal coordinate of the point + /// \param theY the output vertical coordinate of the point + static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch, + Handle_V3d_View theView, double& theX, double& theY); }; #endif -- 2.39.2