From fa273b1f8576e370fb73c6224023ac5117c6c018 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 26 Jul 2016 14:18:53 +0300 Subject: [PATCH] Issue #1664: In the Sketcher, add the function Split a segment. Fill Split attributes by parameters of selected sub-shape. --- src/PartSet/PartSet_Tools.cpp | 33 +++--------- .../PartSet_WidgetSubShapeSelector.cpp | 51 ++++++++++++++----- src/PartSet/PartSet_WidgetSubShapeSelector.h | 8 +++ src/SketchPlugin/SketchPlugin_Validators.cpp | 7 ++- 4 files changed, 60 insertions(+), 39 deletions(-) diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index a4e44a736..5e22fd68a 100755 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -395,32 +395,15 @@ void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr the std::shared_ptr PartSet_Tools::sketchPlane(CompositeFeaturePtr theSketch) { - std::shared_ptr aPlane; + std::shared_ptr anOrigin = std::dynamic_pointer_cast( + theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); + std::shared_ptr aNorm = std::dynamic_pointer_cast( + theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); - std::shared_ptr aData = theSketch->data(); - if (aData) { - std::shared_ptr anOrigin = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Sketch::ORIGIN_ID())); - std::shared_ptr aNormal = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Sketch::NORM_ID())); - if (aNormal.get() && aNormal->isInitialized() && - anOrigin.get() && anOrigin->isInitialized()) { - double adX = aNormal->x(); - double adY = aNormal->y(); - double adZ = aNormal->z(); - - if ( (adX != 0) || (adY != 0) || (adZ != 0) ) { // Plane is valid - double aX = anOrigin->x(); - double aY = anOrigin->y(); - double aZ = anOrigin->z(); - gp_Pln aPln(gp_Pnt(aX, aY, aZ), gp_Dir(adX, adY, adZ)); - double aA, aB, aC, aD; - aPln.Coefficients(aA, aB, aC, aD); - aPlane = std::shared_ptr(new GeomAPI_Pln(aA, aB, aC, aD)); - } - } - } - return aPlane; + if (!anOrigin || !aNorm) + return std::shared_ptr(); + + return std::shared_ptr(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir())); } std::shared_ptr PartSet_Tools::point3D(std::shared_ptr thePoint2D, diff --git a/src/PartSet/PartSet_WidgetSubShapeSelector.cpp b/src/PartSet/PartSet_WidgetSubShapeSelector.cpp index 9ec849c48..2057b467c 100755 --- a/src/PartSet/PartSet_WidgetSubShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetSubShapeSelector.cpp @@ -111,25 +111,46 @@ void PartSet_WidgetSubShapeSelector::mouseMoved(ModuleBase_IViewWindow* theWindo } } +//******************************************************************** +void PartSet_WidgetSubShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs, + ObjectPtr& theObject, + GeomShapePtr& theShape) +{ + ModuleBase_ISelection* aSelection = myWorkshop->selection(); + theObject = aSelection->getResult(thePrs); + if (!theObject.get() && myCurrentSubShape->object()) + theObject = myCurrentSubShape->object(); +} + //******************************************************************** bool PartSet_WidgetSubShapeSelector::setSelection( QList>& theValues, const bool theToValidate) { - bool aResult = ModuleBase_WidgetShapeSelector::setSelection(theValues, theToValidate); - - if (aResult && !theToValidate) { - ObjectPtr aBaseObject = myCurrentSubShape->object(); - GeomShapePtr aBaseShape = myCurrentSubShape->shape(); - + //if (theToValidate) + // bool aResult = ModuleBase_WidgetShapeSelector::setSelection(theValues, theToValidate); + //else { + // the sub-shape is selected, initial shape is not highlighted/selected, we need to use + // the sub-shape to fill attribute; + ObjectPtr aBaseObject = myCurrentSubShape->object(); + GeomShapePtr aBaseShape = myCurrentSubShape->shape(); + bool aResult = aBaseObject.get() && aBaseShape.get(); + // firstly set the selection to the attribute + if (aResult) { + QList aValues; + aValues.append(myCurrentSubShape); + aResult = ModuleBase_WidgetShapeSelector::setSelection(aValues, theToValidate); + } + // secondly fill additional attributes + if (aResult) { 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); + std::shared_ptr aFirstPnt2D = PartSet_Tools::convertTo2D(mySketch, aFirstPnt); + std::shared_ptr aLastPnt2D = PartSet_Tools::convertTo2D(mySketch, aLastPnt); + /// find the points in feature attributes FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObject); @@ -153,6 +174,8 @@ bool PartSet_WidgetSubShapeSelector::setSelection( aRefLast = aRefAttributes.end(); for (; aRefIt != aRefLast; aRefIt++) { std::shared_ptr anAttributePoint = *aRefIt; + double anX = anAttributePoint->x(); + double anY = anAttributePoint->y(); if (!aFirstPointAttr.get() && aFirstPnt2D->isEqual(anAttributePoint->pnt())) aFirstPointAttr = anAttributePoint; if (!aLastPointAttr.get() && aLastPnt2D->isEqual(anAttributePoint->pnt())) @@ -162,15 +185,19 @@ bool PartSet_WidgetSubShapeSelector::setSelection( } } + if (!aFirstPointAttr.get() || !aLastPointAttr) + return false; + FeaturePtr aFeature = feature(); AttributeRefAttrPtr anAPointAttr = std::dynamic_pointer_cast( - aFeature->attribute(SketchPlugin_Constraint::ENTITY_A())); + aFeature->attribute(SketchPlugin_Constraint::ENTITY_A())); AttributeRefAttrPtr aBPointAttr = std::dynamic_pointer_cast( - aFeature->attribute(SketchPlugin_Constraint::ENTITY_B())); + aFeature->attribute(SketchPlugin_Constraint::ENTITY_B())); anAPointAttr->setAttr(aFirstPointAttr); aBPointAttr->setAttr(aLastPointAttr); } } + //} return aResult; } @@ -201,7 +228,7 @@ void PartSet_WidgetSubShapeSelector::fillObjectShapes(const ObjectPtr& theObject 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 - FeaturePtr aSketch = sketch(); + CompositeFeaturePtr aSketch = sketch(); std::shared_ptr aData = aSketch->data(); std::shared_ptr aC = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_Sketch::ORIGIN_ID())); diff --git a/src/PartSet/PartSet_WidgetSubShapeSelector.h b/src/PartSet/PartSet_WidgetSubShapeSelector.h index 5797683bb..2831dfdb6 100644 --- a/src/PartSet/PartSet_WidgetSubShapeSelector.h +++ b/src/PartSet/PartSet_WidgetSubShapeSelector.h @@ -92,6 +92,14 @@ protected: // GeomShapePtr& theShape); void fillObjectShapes(const ObjectPtr& theObject); + /// Return an object and geom shape by the viewer presentation + /// \param thePrs a selection + /// \param theObject an output object + /// \param theShape a shape of the selection + virtual void getGeomSelection(const std::shared_ptr& thePrs, + ObjectPtr& theObject, + GeomShapePtr& theShape); + protected: /// The methiod called when widget is activated virtual void activateCustom(); diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index bbb3bdc50..d309ce8cb 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -888,6 +888,7 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute, std::shared_ptr aSFeature = std::dynamic_pointer_cast(anAttrFeature); SketchPlugin_Sketch* aSketch = aSFeature->sketch(); + std::shared_ptr aData = aSketch->data(); std::shared_ptr aC = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_Sketch::ORIGIN_ID())); @@ -895,10 +896,12 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute, aData->attribute(SketchPlugin_Sketch::DIRX_ID())); std::shared_ptr aNorm = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_Sketch::NORM_ID())); - std::shared_ptr aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir()))); + std::shared_ptr aDirY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir()))); + std::set > aPoints; + ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(), - aX->dir(), aY, aPoints); + aX->dir(), aDirY, aPoints); int aCoincidentToFeature = aPoints.size(); if (aKind == SketchPlugin_Circle::ID()) -- 2.39.2