From: nds Date: Tue, 26 Jul 2016 08:10:00 +0000 (+0300) Subject: Issue #1664: In the Sketcher, add the function Split a segment. AttrRefAttribute... X-Git-Tag: V_2.5.0~172 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ce3669ca33d7066dd715918b7e8b7e1bfd08e4cb;p=modules%2Fshaper.git Issue #1664: In the Sketcher, add the function Split a segment. AttrRefAttribute instead of Geom2D_Point. --- diff --git a/src/PartSet/PartSet_WidgetSubShapeSelector.cpp b/src/PartSet/PartSet_WidgetSubShapeSelector.cpp index 72e0738bf..9ec849c48 100755 --- a/src/PartSet/PartSet_WidgetSubShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetSubShapeSelector.cpp @@ -15,6 +15,8 @@ #include #include +#include +#include #include #include @@ -110,24 +112,65 @@ void PartSet_WidgetSubShapeSelector::mouseMoved(ModuleBase_IViewWindow* theWindo } //******************************************************************** -bool PartSet_WidgetSubShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs) +bool PartSet_WidgetSubShapeSelector::setSelection( + QList>& theValues, + const bool theToValidate) { - bool aResult = ModuleBase_WidgetSelector::setSelectionCustom(thePrs); - - //if (aResult) - //GeomShapePtr aBaseShape = *anIt; - // myCurrentSubShape->setShape(aBaseShape); - - FeaturePtr aFeature = feature(); - AttributePoint2DPtr anAPointAttr = std::dynamic_pointer_cast( - aFeature->attribute(SketchPlugin_Constraint::ENTITY_A())); - AttributePoint2DPtr aBPointAttr = std::dynamic_pointer_cast( - aFeature->attribute(SketchPlugin_Constraint::ENTITY_B())); - + bool aResult = ModuleBase_WidgetShapeSelector::setSelection(theValues, theToValidate); + + if (aResult && !theToValidate) { + ObjectPtr aBaseObject = myCurrentSubShape->object(); + GeomShapePtr aBaseShape = myCurrentSubShape->shape(); + + if (aBaseShape->shapeType() == GeomAPI_Shape::EDGE) { + std::shared_ptr anEdge(new GeomAPI_Edge(aBaseShape)); + + std::shared_ptr aSketchPlane = PartSet_Tools::sketchPlane(mySketch); + std::shared_ptr aFirstPnt = anEdge->firstPoint(); + std::shared_ptr aLastPnt = anEdge->lastPoint(); + std::shared_ptr aFirstPnt2D = aFirstPnt->to2D(aSketchPlane); + std::shared_ptr aLastPnt2D = aLastPnt->to2D(aSketchPlane); + + /// find the points in feature attributes + FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObject); + std::list a2DPointAttributes = aBaseFeature->data()->attributes( + GeomDataAPI_Point2D::typeId()); + std::list::const_iterator anIt = a2DPointAttributes.begin(), + aLast = a2DPointAttributes.end(); + std::shared_ptr aFirstPointAttr, aLastPointAttr; + for (; anIt != aLast; anIt++) { + std::shared_ptr anAttributePoint = + std::dynamic_pointer_cast(*anIt); + if (aFirstPnt2D->isEqual(anAttributePoint->pnt())) + aFirstPointAttr = anAttributePoint; + else if (aLastPnt2D->isEqual(anAttributePoint->pnt())) + aLastPointAttr = anAttributePoint; + } + /// find the points in coincident features + if (!aFirstPointAttr.get() || !aLastPointAttr.get()) { + std::set > aRefAttributes = myCashedReferences[aBaseObject]; + std::set >::const_iterator aRefIt = aRefAttributes.begin(), + aRefLast = aRefAttributes.end(); + for (; aRefIt != aRefLast; aRefIt++) { + std::shared_ptr anAttributePoint = *aRefIt; + if (!aFirstPointAttr.get() && aFirstPnt2D->isEqual(anAttributePoint->pnt())) + aFirstPointAttr = anAttributePoint; + if (!aLastPointAttr.get() && aLastPnt2D->isEqual(anAttributePoint->pnt())) + aLastPointAttr = anAttributePoint; + if (aFirstPointAttr.get() && aLastPointAttr.get()) + break; + } + } - //GeomDataAPI_Point2D anAPointAttr = aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()) - //data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), GeomDataAPI_Point2D::typeId()); - //data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), GeomDataAPI_Point2D::typeId()); + FeaturePtr aFeature = feature(); + AttributeRefAttrPtr anAPointAttr = std::dynamic_pointer_cast( + aFeature->attribute(SketchPlugin_Constraint::ENTITY_A())); + AttributeRefAttrPtr aBPointAttr = std::dynamic_pointer_cast( + aFeature->attribute(SketchPlugin_Constraint::ENTITY_B())); + anAPointAttr->setAttr(aFirstPointAttr); + aBPointAttr->setAttr(aLastPointAttr); + } + } return aResult; } @@ -144,6 +187,7 @@ void PartSet_WidgetSubShapeSelector::getHighlighted( void PartSet_WidgetSubShapeSelector::fillObjectShapes(const ObjectPtr& theObject) { std::set > aShapes; + std::set > aRefAttributes; // current feature FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); @@ -154,7 +198,6 @@ void PartSet_WidgetSubShapeSelector::fillObjectShapes(const ObjectPtr& theObject GeomShapePtr aFeatureShape = *anEdgeShapes.begin(); // coincidences to the feature - std::set > aRefAttributes; ModelGeomAlgo_Point2D::getPointsOfReference(aFeature, SketchPlugin_ConstraintCoincidence::ID(), aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID()); // layed on feature coincidences to divide it on several shapes @@ -174,6 +217,7 @@ void PartSet_WidgetSubShapeSelector::fillObjectShapes(const ObjectPtr& theObject GeomAlgoAPI_ShapeTools::splitShape(aFeatureShape, aPoints, aShapes); } myCashedShapes[theObject] = aShapes; + myCashedReferences[theObject] = aRefAttributes; } //******************************************************************** diff --git a/src/PartSet/PartSet_WidgetSubShapeSelector.h b/src/PartSet/PartSet_WidgetSubShapeSelector.h index 86ac40a9d..5797683bb 100644 --- a/src/PartSet/PartSet_WidgetSubShapeSelector.h +++ b/src/PartSet/PartSet_WidgetSubShapeSelector.h @@ -14,6 +14,7 @@ #include #include +#include #include @@ -67,9 +68,14 @@ Q_OBJECT /// \param theValues a list of presentations virtual void getHighlighted(QList>& theValues); - /// Fills the attribute with the value of the selected owner - /// \param thePrs a selected owner - virtual bool setSelectionCustom(const std::shared_ptr& thePrs); + /// Set the given wrapped value to the current widget + /// This value should be processed in the widget according to the needs + /// The method is called by the current operation to process the operation preselection. + /// It is redefined to fill attributes responsible for the sub selection + /// \param theValues the wrapped selection values + /// \param theToValidate a flag on validation of the values + virtual bool setSelection(QList>& theValues, + const bool theToValidate); protected: /// Checks the widget validity. By default, it returns true. @@ -93,6 +99,7 @@ protected: protected: std::shared_ptr myCurrentSubShape; std::map > myCashedShapes; + std::map > myCashedReferences; /// Pointer to a sketch CompositeFeaturePtr mySketch; diff --git a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp index 09f8dbcb6..af88d14d0 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp @@ -15,7 +15,7 @@ //#include #include //#include -//#include +#include //#include //#include //#include @@ -71,8 +71,8 @@ SketchPlugin_ConstraintSplit::SketchPlugin_ConstraintSplit() void SketchPlugin_ConstraintSplit::initAttributes() { data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeReference::typeId()); - data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId()); //data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId()); //data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttrList::typeId());