From 6a53ce713888d738058d3652d716aa14d4227a3b Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 9 Feb 2015 16:29:33 +0300 Subject: [PATCH] Issue #399: Create a rigid vertex on selection of external one --- src/PartSet/PartSet_Tools.cpp | 2 +- src/PartSet/PartSet_Tools.h | 6 +- src/PartSet/PartSet_WidgetPoint2d.cpp | 71 ++++++++++++--------- src/PartSet/PartSet_WidgetShapeSelector.cpp | 8 +-- src/SketchPlugin/SketchPlugin_Feature.h | 4 +- 5 files changed, 52 insertions(+), 39 deletions(-) diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 0b07da7e7..4bab36441 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -433,7 +433,7 @@ bool PartSet_Tools::isConstraintFeature(const std::string& theKind) || theKind == SketchPlugin_ConstraintRigid::ID(); } -ResultPtr PartSet_Tools::createFixedObjectByEdge(const TopoDS_Shape& theShape, +ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape, const ObjectPtr& theObject, CompositeFeaturePtr theSketch) { diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 31508cb9a..4ff7da471 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -155,9 +155,9 @@ class PARTSET_EXPORT PartSet_Tools /// \param theObject a selected result object /// \param theSketch a sketch feature /// \return result of created feature - static ResultPtr createFixedObjectByEdge(const TopoDS_Shape& theShape, - const ObjectPtr& theObject, - CompositeFeaturePtr theSketch); + static ResultPtr createFixedObjectByExternal(const TopoDS_Shape& theShape, + const ObjectPtr& theObject, + CompositeFeaturePtr theSketch); /// Checks whether the list of selected presentations contains the given one /// \param theSelected a list of presentations diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index e8796669b..d61d8d748 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -30,6 +30,8 @@ #include #include +#include + #include #include #include @@ -234,45 +236,56 @@ bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView, void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { XGUI_Selection* aSelection = myWorkshop->selector()->selection(); + Handle(V3d_View) aView = theWnd->v3dView(); // TODO: This fragment doesn't work because bug in OCC Viewer. It can be used after fixing. - //NCollection_List aShapes; - //std::list aObjects; - //aSelection->selectedShapes(aShapes, aObjects); - //if (aShapes.Extent() > 0) { - // TopoDS_Shape aShape = aShapes.First(); - // 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); - // emit focusOutWidget(this); - // return; - // } - //} + NCollection_List aShapes; + std::list aObjects; + aSelection->selectedShapes(aShapes, aObjects); + // if we have selection + if (aShapes.Extent() > 0) { + TopoDS_Shape aShape = aShapes.First(); + ObjectPtr aObject = aObjects.front(); + FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aObject); + if (aSelectedFeature.get() != NULL) { + std::shared_ptr aSPFeature = + std::dynamic_pointer_cast(aSelectedFeature); + if ((!aSPFeature) && (!aShape.IsNull())) + PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch); + } + double aX, aY; + if (getPoint2d(aView, aShape, aX, aY)) { + setPoint(aX, aY); + + PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY); + emit vertexSelected(); + emit focusOutWidget(this); + return; + } + } // End of Bug dependent fragment // A case when point is taken from mouse event gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView()); double aX, anY; - Handle(V3d_View) aView = theWnd->v3dView(); PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, anY); if (!setPoint(aX, anY)) return; - std::shared_ptr aFeaturePoint = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID())); - QList aIgnore; - aIgnore.append(feature()); - - double aTolerance = aView->Convert(7); - std::shared_ptr aAttrPnt = - PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore); - if (aAttrPnt.get() != NULL) { - aFeaturePoint->setValue(aAttrPnt->pnt()); - PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint); - emit vertexSelected(); - } + /// Start alternative code + //std::shared_ptr aFeaturePoint = std::dynamic_pointer_cast< + // GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID())); + //QList aIgnore; + //aIgnore.append(feature()); + + //double aTolerance = aView->Convert(7); + //std::shared_ptr aAttrPnt = + // PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore); + //if (aAttrPnt.get() != NULL) { + // aFeaturePoint->setValue(aAttrPnt->pnt()); + // PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint); + // emit vertexSelected(); + //} + /// End alternative code emit focusOutWidget(this); } diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index cd69a1998..2f9bb3e95 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -28,8 +28,8 @@ bool PartSet_WidgetShapeSelector::storeValue() const std::dynamic_pointer_cast(aSelectedFeature); if ((!aSPFeature) && (!myShape->isNull())) { // Processing of external (non-sketch) object - ObjectPtr aObj = PartSet_Tools::createFixedObjectByEdge(myShape->impl(), - mySelectedObject, mySketch); + ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(myShape->impl(), + mySelectedObject, mySketch); if (aObj) { PartSet_WidgetShapeSelector* that = (PartSet_WidgetShapeSelector*) this; that->mySelectedObject = aObj; @@ -133,8 +133,8 @@ bool PartSet_WidgetConstraintShapeSelector::storeValue() const std::shared_ptr aSPFeature = std::dynamic_pointer_cast(aFeature); if ((!aSPFeature) && (!myShape->isNull())) { - ObjectPtr aObj = PartSet_Tools::createFixedObjectByEdge(myShape->impl(), - mySelectedObject, mySketch); + ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(myShape->impl(), + mySelectedObject, mySketch); if (aObj) { PartSet_WidgetConstraintShapeSelector* that = (PartSet_WidgetConstraintShapeSelector*) this; that->mySelectedObject = aObj; diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index 66d59467b..5174eff40 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -67,8 +67,8 @@ class SketchPlugin_Feature : public ModelAPI_Feature, public GeomAPI_ICustomPrs /// Customize presentation of the feature virtual void customisePresentation(AISObjectPtr thePrs) { - // if this is an edge - if (thePrs->getShapeType() == 6) { + // if this is an edge or vertex + if ((thePrs->getShapeType() == 6) || (thePrs->getShapeType() == 7)) { thePrs->setWidth(3); if (isExternal()) thePrs->setColor(0,255,0); -- 2.39.2