//==================================================================================================
void GeomAlgoAPI_ShapeTools::splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
- const std::set<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
- std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes)
+ const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
+ std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes)
{
// General Fuse to split edge by vertices
BOPAlgo_Builder aBOP;
Standard_Real aFirst, aLast;
Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aBaseEdge, aFirst, aLast);
- std::set<std::shared_ptr<GeomAPI_Pnt> >::const_iterator aPIt = thePoints.begin();
+ std::list<std::shared_ptr<GeomAPI_Pnt> >::const_iterator aPIt = thePoints.begin();
gp_Pnt aPoint((*aPIt)->x(), (*aPIt)->y(), (*aPIt)->z());
TopAbs_Orientation anOrientation = aBaseEdge.Orientation();
}
aBOP.AddArgument(aBaseEdge);
- std::set<std::shared_ptr<GeomAPI_Pnt> >::const_iterator aPtIt = thePoints.begin();
+ std::list<std::shared_ptr<GeomAPI_Pnt> >::const_iterator aPtIt = thePoints.begin();
for (; aPtIt != thePoints.end(); ++aPtIt) {
std::shared_ptr<GeomAPI_Pnt> aPnt = *aPtIt;
TopoDS_Vertex aV = BRepBuilderAPI_MakeVertex(gp_Pnt(aPnt->x(), aPnt->y(), aPnt->z()));
theShapes.insert(anEdge);
}
}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::findShape(
+ const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
+ const std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes)
+{
+ std::shared_ptr<GeomAPI_Shape> aResultShape;
+
+ if (thePoints.size() == 2) {
+ std::list<std::shared_ptr<GeomAPI_Pnt> >::const_iterator aPntIt = thePoints.begin();
+ std::shared_ptr<GeomAPI_Pnt> aFirstPoint = *aPntIt;
+ aPntIt++;
+ std::shared_ptr<GeomAPI_Pnt> aLastPoint = *aPntIt;
+
+ std::set<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = theShapes.begin(),
+ aLast = theShapes.end();
+ for (; anIt != aLast; anIt++) {
+ GeomShapePtr aShape = *anIt;
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
+ if (anEdge.get()) {
+ std::shared_ptr<GeomAPI_Pnt> anEdgeFirstPoint = anEdge->firstPoint();
+ std::shared_ptr<GeomAPI_Pnt> anEdgeLastPoint = anEdge->lastPoint();
+ if (anEdgeFirstPoint->isEqual(aFirstPoint) &&
+ anEdgeLastPoint->isEqual(aLastPoint))
+ aResultShape = aShape;
+ }
+ }
+ }
+
+ return aResultShape;
+}
/// \return true if edge is parallel to face.
GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
const std::shared_ptr<GeomAPI_Face> 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<GeomAPI_Shape>& theBaseShape,
- const std::set<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
+ const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
+
+
+ GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> findShape(
+ const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
+ const std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
+
};
#endif
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;
}
const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
const std::shared_ptr<GeomAPI_Dir>& theDirX,
const std::shared_ptr<GeomAPI_Dir>& theDirY,
- std::set<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
+ std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
std::map<std::shared_ptr<GeomDataAPI_Point2D>,
std::shared_ptr<GeomAPI_Pnt> >& theAttributeToPoint)
{
std::shared_ptr<GeomAPI_Pnt> aPoint = aPnt2d->to3D(theOrigin, theDirX, theDirY);
std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
if (isPointOnEdge(theBaseShape, aPoint, aProjectedPoint)) {
- thePoints.insert(aProjectedPoint);
+ thePoints.push_back(aProjectedPoint);
theAttributeToPoint[anAttribute] = aProjectedPoint;
}
}
const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
const std::shared_ptr<GeomAPI_Dir>& theDirX,
const std::shared_ptr<GeomAPI_Dir>& theDirY,
- std::set<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
+ std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
std::map<std::shared_ptr<GeomDataAPI_Point2D>,
std::shared_ptr<GeomAPI_Pnt> >& theAttributeToPoint);
std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
aData->attribute(SketchPlugin_Sketch::NORM_ID()));
std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
- std::set<std::shared_ptr<GeomAPI_Pnt> > aPoints;
+ std::list<std::shared_ptr<GeomAPI_Pnt> > aPoints;
ModelGeomAlgo_Point2D::getPointsInsideShape(aFeatureShape, aRefAttributes, aC->pnt(),
aX->dir(), aY, aPoints, aPointToAttributes);
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_XY.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomAlgoAPI_ShapeTools.h>
+
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_AttributeRefAttr.h>
return true;
}
+AISObjectPtr SketchPlugin_ConstraintSplit::getAISObject(AISObjectPtr thePrevious)
+{
+ AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
+ 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<std::shared_ptr<GeomAPI_Pnt> > aPoints;
+
+ std::shared_ptr<GeomAPI_Pnt2d> aStartPnt2d = aFirstPointAttrOfSplit->pnt();
+ std::shared_ptr<GeomAPI_Pnt> aStartPoint = sketch()->to3D(aStartPnt2d->x(), aStartPnt2d->y());
+ aPoints.push_back(aStartPoint);
+
+ std::shared_ptr<GeomAPI_Pnt2d> aSecondPnt2d = aSecondPointAttrOfSplit->pnt();
+ std::shared_ptr<GeomAPI_Pnt> aSecondPoint = sketch()->to3D(aSecondPnt2d->x(), aSecondPnt2d->y());
+ aPoints.push_back(aSecondPoint);
+
+ std::set<std::shared_ptr<GeomAPI_Shape> > aSplitShapes;
+
+ GeomAlgoAPI_ShapeTools::splitShape(aBaseShape, aPoints, aSplitShapes);
+ std::shared_ptr<GeomAPI_Shape> 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<int> 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<GeomDataAPI_Point2D> SketchPlugin_ConstraintSplit::getPointOfRefAttr(
const AttributePtr& theAttribute)
{
// 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
aData->attribute(SketchPlugin_Sketch::NORM_ID()));
std::shared_ptr<GeomAPI_Dir> aDirY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
- std::set<std::shared_ptr<GeomAPI_Pnt> > aPoints;
+ std::list<std::shared_ptr<GeomAPI_Pnt> > aPoints;
std::map<std::shared_ptr<GeomDataAPI_Point2D>, std::shared_ptr<GeomAPI_Pnt> > aPointToAttributes;
ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(),
aX->dir(), aDirY, aPoints, aPointToAttributes);