-
-FeaturePtr SketchPlugin_Trim::createLineFeature(const FeaturePtr& theBaseFeature,
- const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
- const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint)
-{
-#ifdef DEBUG_TRIM
- std::cout << "---- createLineFeature ---" << std::endl;
-#endif
-
- FeaturePtr aFeature;
- SketchPlugin_Sketch* aSketch = sketch();
- if (!aSketch || !theBaseFeature.get())
- return aFeature;
-
- aFeature = aSketch->addFeature(SketchPlugin_Line::ID());
-
- fillPointAttribute(aFeature->attribute(SketchPlugin_Line::START_ID()), theFirstPoint);
- fillPointAttribute(aFeature->attribute(SketchPlugin_Line::END_ID()), theSecondPoint);
-
- fillAttribute(aFeature->attribute(SketchPlugin_SketchEntity::AUXILIARY_ID()),
- theBaseFeature->attribute(SketchPlugin_SketchEntity::AUXILIARY_ID()));
-
- aFeature->execute(); // to obtain result
-
-#ifdef DEBUG_TRIM
- std::cout << "---- createLineFeature:end ---" << std::endl;
-#endif
-
- return aFeature;
-}
-
-FeaturePtr SketchPlugin_Trim::createArcFeature(const FeaturePtr& theBaseFeature,
- const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
- const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint)
-{
- FeaturePtr aFeature;
- SketchPlugin_Sketch* aSketch = sketch();
- if (!aSketch || !theBaseFeature.get())
- return aFeature;
-
- std::string aCenterAttributeId;
- if (theBaseFeature->getKind() == SketchPlugin_Arc::ID())
- aCenterAttributeId = SketchPlugin_Arc::CENTER_ID();
- else if (theBaseFeature->getKind() == SketchPlugin_Circle::ID())
- aCenterAttributeId = SketchPlugin_Circle::CENTER_ID();
-
- if (aCenterAttributeId.empty())
- return aFeature;
-
-#ifdef DEBUG_TRIM
- std::cout << "---- createArcFeature ---" << std::endl;
-#endif
-
- aFeature = aSketch->addFeature(SketchPlugin_Arc::ID());
- // update fillet arc: make the arc correct for sure, so, it is not needed to process
- // the "attribute updated"
- // by arc; moreover, it may cause cyclicity in hte mechanism of updater
- bool aWasBlocked = aFeature->data()->blockSendAttributeUpdated(true);
-
- fillAttribute(aFeature->attribute(SketchPlugin_Arc::CENTER_ID()),
- theBaseFeature->attribute(aCenterAttributeId));
- fillPointAttribute(aFeature->attribute(SketchPlugin_Arc::START_ID()), theFirstPoint);
- fillPointAttribute(aFeature->attribute(SketchPlugin_Arc::END_ID()), theSecondPoint);
-
- fillAttribute(aFeature->attribute(SketchPlugin_SketchEntity::AUXILIARY_ID()),
- theBaseFeature->attribute(SketchPlugin_SketchEntity::AUXILIARY_ID()));
-
- /// fill referersed state of created arc as it is on the base arc
- if (theBaseFeature->getKind() == SketchPlugin_Arc::ID()) {
- bool aReversed = theBaseFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
- aFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue(aReversed);
- }
- aFeature->execute(); // to obtain result (need to calculate arc parameters before sending Update)
- aFeature->data()->blockSendAttributeUpdated(aWasBlocked);
-
- #ifdef DEBUG_TRIM
- std::cout << "---- createArcFeature:end ---" << std::endl;
- #endif
-
- return aFeature;
-}
-
-std::shared_ptr<ModelAPI_Result> SketchPlugin_Trim::getFeatureResult(
- const std::shared_ptr<ModelAPI_Feature>& theFeature)
-{
- std::shared_ptr<ModelAPI_Result> aResult;
-
- std::string aFeatureKind = theFeature->getKind();
- if (aFeatureKind == SketchPlugin_Line::ID())
- aResult = theFeature->firstResult();
- else if (aFeatureKind == SketchPlugin_Arc::ID())
- aResult = theFeature->lastResult();
- else if (aFeatureKind == SketchPlugin_Circle::ID())
- aResult = theFeature->lastResult();
-
- return aResult;
-}
-
-//********************************************************************
-void SketchPlugin_Trim::fillObjectShapes(const ObjectPtr& theObject,
- const ObjectPtr& theSketch,
- std::map<ObjectPtr, std::set<GeomShapePtr> >& theCashedShapes,
- std::map<ObjectPtr, PointToRefsMap>& theObjectToPoints)
-{
- PointToRefsMap aPointsInfo;
-
- std::set<std::shared_ptr<GeomAPI_Shape> > aShapes;
- std::map<std::shared_ptr<GeomAPI_Pnt>,
- std::list< AttributePoint2DPtr > > aPointToAttributes;
- std::map<std::shared_ptr<GeomAPI_Pnt>,
- std::list< ObjectPtr > > aPointToObjects;
-
- std::set<AttributePoint2DPtr > aRefAttributes;
- // current feature
- FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
- std::set<ResultPtr> anEdgeShapes;
- // edges on feature
- ModelGeomAlgo_Shape::shapesOfType(aFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
- if (!anEdgeShapes.empty()) {
- GeomShapePtr aFeatureShape = (*anEdgeShapes.begin())->shape();
-
- // coincidences to the feature
- 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
- std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
- std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
- aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
- 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())));
-
- ModelGeomAlgo_Point2D::getPointsInsideShape(aFeatureShape, aRefAttributes, aC->pnt(),
- aX->dir(), aY, aPointsInfo);
-
- std::list<FeaturePtr> aFeatures;
- CompositeFeaturePtr aSketchComposite =
- std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theSketch);
- for (int i = 0; i < aSketchComposite->numberOfSubs(); i++) {
- FeaturePtr aFeature = aSketchComposite->subFeature(i);
- if (aFeature.get() && aFeature->getKind() != SketchPlugin_Projection::ID())
- aFeatures.push_back(aFeature);
- }
- ModelGeomAlgo_Point2D::getPointsIntersectedShape(aFeature, aFeatures, aPointsInfo);
-
- GeomAlgoAPI_ShapeTools::splitShape(aFeatureShape, aPointsInfo, aShapes);
- }
- theObjectToPoints[theObject] = aPointsInfo;
- theCashedShapes[theObject] = aShapes;
-}