From 89775a64fb63ba0d7c875c1f7aba41f9b6f89c13 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 18 Feb 2016 18:36:24 +0300 Subject: [PATCH] OperationPrs should not be shown if it is empty. Correction for fillet, rectangle sketch features. --- .../ModuleBase_WidgetShapeSelector.cpp | 5 +- src/PartSet/PartSet_OperationPrs.cpp | 25 ++++-- src/PartSet/PartSet_OperationPrs.h | 3 +- src/PartSet/PartSet_Tools.cpp | 78 ++++++++----------- src/SketcherPrs/SketcherPrs_Equal.cpp | 3 +- src/SketcherPrs/SketcherPrs_HVDirection.cpp | 3 +- src/SketcherPrs/SketcherPrs_Tangent.cpp | 3 + 7 files changed, 65 insertions(+), 55 deletions(-) diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 27487c72a..13f071c21 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -212,7 +212,10 @@ GeomShapePtr ModuleBase_WidgetShapeSelector::getShape() const if (aType == ModelAPI_AttributeReference::typeId()) { } else if (aType == ModelAPI_AttributeRefAttr::typeId()) { AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); - aShape = myWorkshop->module()->findShape(aRefAttr); + if (aRefAttr.get() && !aRefAttr->isObject()) { + AttributePtr anAttribute = aRefAttr->attr(); + aShape = myWorkshop->module()->findShape(anAttribute); + } } else if (aType == ModelAPI_AttributeSelection::typeId()) { AttributeSelectionPtr aSelectAttr = aData->selection(attributeID()); aShape = aSelectAttr->value(); diff --git a/src/PartSet/PartSet_OperationPrs.cpp b/src/PartSet/PartSet_OperationPrs.cpp index 99e5e1624..e6a52bdd8 100755 --- a/src/PartSet/PartSet_OperationPrs.cpp +++ b/src/PartSet/PartSet_OperationPrs.cpp @@ -257,8 +257,20 @@ void PartSet_OperationPrs::getFeatureShapes(const FeaturePtr& theFeature, std::shared_ptr aCurSelList = std::dynamic_pointer_cast(anAttribute); for (int i = 0; i < aCurSelList->size(); i++) { - GeomShapePtr aShape; - addValue(aCurSelList->object(i), aShape, theFeature, theObjectShapes); + ObjectPtr anObject = aCurSelList->object(i); + FeaturePtr aFeature = std::dynamic_pointer_cast(anObject); + // feature rectangle uses as parameters feature lines, so we should obtain line results + if (aFeature.get()) { + getResultShapes(aFeature, theWorkshop, theObjectShapes, false); + } + else { + ResultPtr aResult = std::dynamic_pointer_cast(anObject); + if (aResult.get()) { + GeomShapePtr aShape = aResult->shape(); + if (aShape.get()) + addValue(aResult, aShape, theFeature, theObjectShapes); + } + } } } else { @@ -270,7 +282,8 @@ void PartSet_OperationPrs::getFeatureShapes(const FeaturePtr& theFeature, anObject = anAttr->object(); } else { - aShape = PartSet_Tools::findShapeBy2DPoint(anAttr, theWorkshop); + AttributePtr anAttribute = anAttr->attr(); + aShape = PartSet_Tools::findShapeBy2DPoint(anAttribute, theWorkshop); // the distance point is not found if the point is selected in the 2nd time // TODO: after debug, this check can be removed if (!aShape.get()) @@ -294,9 +307,11 @@ void PartSet_OperationPrs::getFeatureShapes(const FeaturePtr& theFeature, void PartSet_OperationPrs::getResultShapes(const FeaturePtr& theFeature, ModuleBase_IWorkshop* theWorkshop, - QMap >& theObjectShapes) + QMap >& theObjectShapes, + const bool theListShouldBeCleared) { - theObjectShapes.clear(); + if (theListShouldBeCleared) + theObjectShapes.clear(); if (!theFeature.get()) return; diff --git a/src/PartSet/PartSet_OperationPrs.h b/src/PartSet/PartSet_OperationPrs.h index bf1e5a2bc..51922f5d6 100755 --- a/src/PartSet/PartSet_OperationPrs.h +++ b/src/PartSet/PartSet_OperationPrs.h @@ -100,7 +100,8 @@ private: /// \param theObjectShape an output map of objects static void getResultShapes(const FeaturePtr& theFeature, ModuleBase_IWorkshop* theWorkshop, - QMap >& theObjectShapes); + QMap >& theObjectShapes, + const bool theListShouldBeCleared = true); /// Fills the map by the feature object and shapes, which should be visuaziled /// Gets the active widget, obtain the highlighted presentations if it has such and diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 002f148e5..a41dc94fd 100755 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -644,52 +644,42 @@ bool PartSet_Tools::hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePt } GeomShapePtr PartSet_Tools::findShapeBy2DPoint(const AttributePtr& theAttribute, - ModuleBase_IWorkshop* theWorkshop) + ModuleBase_IWorkshop* theWorkshop) { - // 1. find an attribute value in attribute reference attribute value GeomShapePtr aShape; - AttributeRefAttrPtr aRefAttr = - std::dynamic_pointer_cast(theAttribute); - if (aRefAttr) { - if (!aRefAttr->isObject()) { - AttributePtr theAttribute = aRefAttr->attr(); - if (theAttribute.get()) { - XGUI_ModuleConnector* aConnector = dynamic_cast(theWorkshop); - XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); - - // 2. find visualized vertices of the attribute and if the attribute of the vertex is - // the same, return it - FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(theAttribute->owner()); - // 2.1 get visualized results of the feature - const std::list& aResList = anAttributeFeature->results(); - std::list::const_iterator anIt = aResList.begin(), aLast = aResList.end(); - for (; anIt != aLast; anIt++) { - AISObjectPtr aAISObj = aDisplayer->getAISObject(*anIt); - if (aAISObj.get() != NULL) { - Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl(); - // 2.2 find selected owners of a visualizedd object - SelectMgr_IndexedMapOfOwner aSelectedOwners; - aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners); - for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) { - Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i); - if (!anOwner.IsNull()) { - Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(anOwner); - if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) { - const TopoDS_Shape& aBRepShape = aBRepOwner->Shape(); - if (aBRepShape.ShapeType() == TopAbs_VERTEX) { - // 2.3 if the owner is vertex and an attribute of the vertex is equal to the initial - // attribute, returns the shape - PartSet_Module* aModule = dynamic_cast(theWorkshop->module()); - PartSet_SketcherMgr* aSketchMgr = aModule->sketchMgr(); - AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(anAttributeFeature, - aBRepShape, aSketchMgr->activeSketch()); - if (aPntAttr.get() != NULL && aPntAttr == theAttribute) { - aShape = std::shared_ptr(new GeomAPI_Shape); - aShape->setImpl(new TopoDS_Shape(aBRepShape)); - break; - } - } - } + XGUI_ModuleConnector* aConnector = dynamic_cast(theWorkshop); + XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); + + // 2. find visualized vertices of the attribute and if the attribute of the vertex is + // the same, return it + FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(theAttribute->owner()); + // 2.1 get visualized results of the feature + const std::list& aResList = anAttributeFeature->results(); + std::list::const_iterator anIt = aResList.begin(), aLast = aResList.end(); + for (; anIt != aLast; anIt++) { + AISObjectPtr aAISObj = aDisplayer->getAISObject(*anIt); + if (aAISObj.get() != NULL) { + Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl(); + // 2.2 find selected owners of a visualizedd object + SelectMgr_IndexedMapOfOwner aSelectedOwners; + aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners); + for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) { + Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i); + if (!anOwner.IsNull()) { + Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(anOwner); + if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) { + const TopoDS_Shape& aBRepShape = aBRepOwner->Shape(); + if (aBRepShape.ShapeType() == TopAbs_VERTEX) { + // 2.3 if the owner is vertex and an attribute of the vertex is equal to the initial + // attribute, returns the shape + PartSet_Module* aModule = dynamic_cast(theWorkshop->module()); + PartSet_SketcherMgr* aSketchMgr = aModule->sketchMgr(); + AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(anAttributeFeature, + aBRepShape, aSketchMgr->activeSketch()); + if (aPntAttr.get() != NULL && aPntAttr == theAttribute) { + aShape = std::shared_ptr(new GeomAPI_Shape); + aShape->setImpl(new TopoDS_Shape(aBRepShape)); + break; } } } diff --git a/src/SketcherPrs/SketcherPrs_Equal.cpp b/src/SketcherPrs/SketcherPrs_Equal.cpp index ff5e21f10..1a808f935 100644 --- a/src/SketcherPrs/SketcherPrs_Equal.cpp +++ b/src/SketcherPrs/SketcherPrs_Equal.cpp @@ -46,9 +46,8 @@ bool SketcherPrs_Equal::IsReadyToDisplay(ModelAPI_Feature* theConstraint, bool SketcherPrs_Equal::updatePoints(double theStep) const { - if (!IsReadyToDisplay(myConstraint, myPlane)) { + if (!IsReadyToDisplay(myConstraint, myPlane)) return false; - } ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); diff --git a/src/SketcherPrs/SketcherPrs_HVDirection.cpp b/src/SketcherPrs/SketcherPrs_HVDirection.cpp index c317a71b6..bc9371240 100644 --- a/src/SketcherPrs/SketcherPrs_HVDirection.cpp +++ b/src/SketcherPrs/SketcherPrs_HVDirection.cpp @@ -42,9 +42,8 @@ bool SketcherPrs_HVDirection::IsReadyToDisplay(ModelAPI_Feature* theConstraint, bool SketcherPrs_HVDirection::updatePoints(double theStep) const { - if (!SketcherPrs_HVDirection::IsReadyToDisplay(myConstraint, myPlane)) { + if (!IsReadyToDisplay(myConstraint, myPlane)) return false; - } // Set point of the symbol ObjectPtr aObj = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); diff --git a/src/SketcherPrs/SketcherPrs_Tangent.cpp b/src/SketcherPrs/SketcherPrs_Tangent.cpp index 57fd51779..cb86910fc 100644 --- a/src/SketcherPrs/SketcherPrs_Tangent.cpp +++ b/src/SketcherPrs/SketcherPrs_Tangent.cpp @@ -49,6 +49,9 @@ bool SketcherPrs_Tangent::IsReadyToDisplay(ModelAPI_Feature* theConstraint, bool SketcherPrs_Tangent::updatePoints(double theStep) const { + if (!IsReadyToDisplay(myConstraint, myPlane)) + return false; + ObjectPtr aObj1 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_A()); ObjectPtr aObj2 = SketcherPrs_Tools::getResult(myConstraint, SketchPlugin_Constraint::ENTITY_B()); -- 2.39.2