From: nds Date: Thu, 8 Sep 2016 07:14:34 +0000 (+0300) Subject: Split preview correction: it is provided by AISObject of presentable interface X-Git-Tag: V_2.5.0~14 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=454529f85169f883a6bf9ac18e2e85e34f081d8b;p=modules%2Fshaper.git Split preview correction: it is provided by AISObject of presentable interface --- diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp index 7c0f462e0..bc64bf02e 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp @@ -672,8 +672,8 @@ bool GeomAlgoAPI_ShapeTools::isParallel(const std::shared_ptr theE //================================================================================================== void GeomAlgoAPI_ShapeTools::splitShape(const std::shared_ptr& theBaseShape, - const std::set >& thePoints, - std::set >& theShapes) + const std::list >& thePoints, + std::set >& theShapes) { // General Fuse to split edge by vertices BOPAlgo_Builder aBOP; @@ -685,7 +685,7 @@ void GeomAlgoAPI_ShapeTools::splitShape(const std::shared_ptr& th Standard_Real aFirst, aLast; Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aBaseEdge, aFirst, aLast); - std::set >::const_iterator aPIt = thePoints.begin(); + std::list >::const_iterator aPIt = thePoints.begin(); gp_Pnt aPoint((*aPIt)->x(), (*aPIt)->y(), (*aPIt)->z()); TopAbs_Orientation anOrientation = aBaseEdge.Orientation(); @@ -694,7 +694,7 @@ void GeomAlgoAPI_ShapeTools::splitShape(const std::shared_ptr& th } aBOP.AddArgument(aBaseEdge); - std::set >::const_iterator aPtIt = thePoints.begin(); + std::list >::const_iterator aPtIt = thePoints.begin(); for (; aPtIt != thePoints.end(); ++aPtIt) { std::shared_ptr aPnt = *aPtIt; TopoDS_Vertex aV = BRepBuilderAPI_MakeVertex(gp_Pnt(aPnt->x(), aPnt->y(), aPnt->z())); @@ -714,3 +714,34 @@ void GeomAlgoAPI_ShapeTools::splitShape(const std::shared_ptr& th theShapes.insert(anEdge); } } + +//================================================================================================== +std::shared_ptr GeomAlgoAPI_ShapeTools::findShape( + const std::list >& thePoints, + const std::set >& theShapes) +{ + std::shared_ptr aResultShape; + + if (thePoints.size() == 2) { + std::list >::const_iterator aPntIt = thePoints.begin(); + std::shared_ptr aFirstPoint = *aPntIt; + aPntIt++; + std::shared_ptr aLastPoint = *aPntIt; + + std::set >::const_iterator anIt = theShapes.begin(), + aLast = theShapes.end(); + for (; anIt != aLast; anIt++) { + GeomShapePtr aShape = *anIt; + std::shared_ptr anEdge(new GeomAPI_Edge(aShape)); + if (anEdge.get()) { + std::shared_ptr anEdgeFirstPoint = anEdge->firstPoint(); + std::shared_ptr anEdgeLastPoint = anEdge->lastPoint(); + if (anEdgeFirstPoint->isEqual(aFirstPoint) && + anEdgeLastPoint->isEqual(aLastPoint)) + aResultShape = aShape; + } + } + } + + return aResultShape; +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h index f69ad5cd5..cadedc031 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h @@ -104,13 +104,20 @@ public: /// \return true if edge is parallel to face. GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr theEdge, const std::shared_ptr theFace); + /// \brief Performs the split of the shape by points. /// \param[in] theBaseShape shape that should be splitted. /// \param[in] thePoints container of points to split /// \param[out] theShapes container of shapes after split GEOMALGOAPI_EXPORT static void splitShape(const std::shared_ptr& theBaseShape, - const std::set >& thePoints, + const std::list >& thePoints, std::set >& theShapes); + + + GEOMALGOAPI_EXPORT static std::shared_ptr findShape( + const std::list >& thePoints, + const std::set >& theShapes); + }; #endif diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index a156d4002..f4e189731 100755 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -105,6 +105,14 @@ bool Model_Update::addModified(FeaturePtr theFeature, FeaturePtr theReason) { static ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators(); aFactory->validate(theFeature); // need to be validated to update the "Apply" state if not previewed + // to redisplay split's arguments presentation, even result is not computed + if (!theFeature->isPreviewNeeded()) { + static Events_Loop* aLoop = Events_Loop::loop(); + static const Events_ID kRedisplayEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + ModelAPI_EventCreator::get()->sendUpdated(theFeature, kRedisplayEvent); + aLoop->flush(kRedisplayEvent); + } + if (!myIsPreviewBlocked) return true; } diff --git a/src/ModelGeomAlgo/ModelGeomAlgo_Point2D.cpp b/src/ModelGeomAlgo/ModelGeomAlgo_Point2D.cpp index 2e81b4f34..976988cde 100755 --- a/src/ModelGeomAlgo/ModelGeomAlgo_Point2D.cpp +++ b/src/ModelGeomAlgo/ModelGeomAlgo_Point2D.cpp @@ -120,7 +120,7 @@ namespace ModelGeomAlgo_Point2D { const std::shared_ptr& theOrigin, const std::shared_ptr& theDirX, const std::shared_ptr& theDirY, - std::set >& thePoints, + std::list >& thePoints, std::map, std::shared_ptr >& theAttributeToPoint) { @@ -132,7 +132,7 @@ namespace ModelGeomAlgo_Point2D { std::shared_ptr aPoint = aPnt2d->to3D(theOrigin, theDirX, theDirY); std::shared_ptr aProjectedPoint; if (isPointOnEdge(theBaseShape, aPoint, aProjectedPoint)) { - thePoints.insert(aProjectedPoint); + thePoints.push_back(aProjectedPoint); theAttributeToPoint[anAttribute] = aProjectedPoint; } } diff --git a/src/ModelGeomAlgo/ModelGeomAlgo_Point2D.h b/src/ModelGeomAlgo/ModelGeomAlgo_Point2D.h index 940a869c8..7f1e89bdf 100755 --- a/src/ModelGeomAlgo/ModelGeomAlgo_Point2D.h +++ b/src/ModelGeomAlgo/ModelGeomAlgo_Point2D.h @@ -69,7 +69,7 @@ namespace ModelGeomAlgo_Point2D { const std::shared_ptr& theOrigin, const std::shared_ptr& theDirX, const std::shared_ptr& theDirY, - std::set >& thePoints, + std::list >& thePoints, std::map, std::shared_ptr >& theAttributeToPoint); diff --git a/src/PartSet/PartSet_WidgetSubShapeSelector.cpp b/src/PartSet/PartSet_WidgetSubShapeSelector.cpp index 35480469d..50f81218d 100755 --- a/src/PartSet/PartSet_WidgetSubShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetSubShapeSelector.cpp @@ -246,7 +246,7 @@ void PartSet_WidgetSubShapeSelector::fillObjectShapes(const ObjectPtr& theObject 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::set > aPoints; + std::list > aPoints; ModelGeomAlgo_Point2D::getPointsInsideShape(aFeatureShape, aRefAttributes, aC->pnt(), aX->dir(), aY, aPoints, aPointToAttributes); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp index 395ae3171..a7b725c9d 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp @@ -10,6 +10,8 @@ #include #include #include +#include + #include #include #include @@ -313,6 +315,54 @@ bool SketchPlugin_ConstraintSplit::isMacro() const return true; } +AISObjectPtr SketchPlugin_ConstraintSplit::getAISObject(AISObjectPtr thePrevious) +{ + AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Constraint::VALUE())); + FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value()); + + AttributePoint2DPtr aFirstPointAttrOfSplit = getPointOfRefAttr( + data()->attribute(SketchPlugin_Constraint::ENTITY_A())); + AttributePoint2DPtr aSecondPointAttrOfSplit = getPointOfRefAttr( + data()->attribute(SketchPlugin_Constraint::ENTITY_B())); + + if (aBaseObjectAttr->isInitialized() && aBaseFeature.get() && + aFirstPointAttrOfSplit->isInitialized() && + aSecondPointAttrOfSplit->isInitialized()) { + + ResultPtr aResult = getFeatureResult(aBaseFeature); + GeomShapePtr aBaseShape = aResult->shape(); + std::list > aPoints; + + std::shared_ptr aStartPnt2d = aFirstPointAttrOfSplit->pnt(); + std::shared_ptr aStartPoint = sketch()->to3D(aStartPnt2d->x(), aStartPnt2d->y()); + aPoints.push_back(aStartPoint); + + std::shared_ptr aSecondPnt2d = aSecondPointAttrOfSplit->pnt(); + std::shared_ptr aSecondPoint = sketch()->to3D(aSecondPnt2d->x(), aSecondPnt2d->y()); + aPoints.push_back(aSecondPoint); + + std::set > aSplitShapes; + + GeomAlgoAPI_ShapeTools::splitShape(aBaseShape, aPoints, aSplitShapes); + std::shared_ptr aShape = GeomAlgoAPI_ShapeTools::findShape(aPoints, aSplitShapes); + + AISObjectPtr anAIS = thePrevious; + if (aShape) { + if (!anAIS) + anAIS = AISObjectPtr(new GeomAPI_AISObject); + anAIS->createShape(aShape); + anAIS->setWidth(5); + std::vector aColor; + aColor = Config_PropManager::color("Visualization", "sketch_entity_color", + SKETCH_ENTITY_COLOR); + anAIS->setColor(aColor[0], aColor[1], aColor[2]); + } + return anAIS; + } + return AISObjectPtr(); +} + std::shared_ptr SketchPlugin_ConstraintSplit::getPointOfRefAttr( const AttributePtr& theAttribute) { diff --git a/src/SketchPlugin/SketchPlugin_ConstraintSplit.h b/src/SketchPlugin/SketchPlugin_ConstraintSplit.h index eab2ae86f..dee2b9e04 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintSplit.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintSplit.h @@ -85,6 +85,9 @@ class SketchPlugin_ConstraintSplit : public SketchPlugin_ConstraintBase // return myPointFeaturesMap; //}; + /// Returns the AIS preview + SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); + private: /// Returns geom point attribute of the feature bounds. It processes line or arc. /// For circle feature, the result attributes are null diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 9db33a5ed..4f88df34c 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -863,7 +863,7 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute, aData->attribute(SketchPlugin_Sketch::NORM_ID())); std::shared_ptr aDirY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir()))); - std::set > aPoints; + std::list > aPoints; std::map, std::shared_ptr > aPointToAttributes; ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(), aX->dir(), aDirY, aPoints, aPointToAttributes);