- else if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) {
- AttributeRefAttrPtr aRefAttributeToFill = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- theModifiedAttribute);
- AttributeRefAttrPtr aSourceRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- theSourceAttribute);
- if (!aSourceRefAttr.get())
- aRefAttributeToFill->setAttr(theSourceAttribute);
- else {
- if (aSourceRefAttr->isObject())
- aRefAttributeToFill->setObject(aSourceRefAttr->object());
- else
- aRefAttributeToFill->setAttr(aSourceRefAttr->attr());
- }
- }
-}
-
-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
- aFeature->data()->blockSendAttributeUpdated(aWasBlocked);
-
- #ifdef DEBUG_TRIM
- std::cout << "---- createArcFeature:end ---" << std::endl;
- #endif
-
- return aFeature;
-}
-
-FeaturePtr SketchPlugin_Trim::createConstraint(const std::string& theConstraintId,
- const AttributePtr& theFirstAttribute,
- const AttributePtr& theSecondAttribute)
-{
- FeaturePtr aConstraint = sketch()->addFeature(theConstraintId);
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- aRefAttr->setAttr(theFirstAttribute);
-
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
- aRefAttr->setAttr(theSecondAttribute);
-
-#ifdef DEBUG_TRIM
- std::cout << "<createConstraint to attribute> :"
- << "first attribute - " << theFirstAttribute->id()
- << "second attribute - " << theSecondAttribute->id()
- << std::endl;
-#endif
-
- return aConstraint;
-}
-
-FeaturePtr SketchPlugin_Trim::createConstraintToObject(const std::string& theConstraintId,
- const AttributePtr& theFirstAttribute,
- const ObjectPtr& theSecondObject)
-{
- FeaturePtr aConstraint = sketch()->addFeature(theConstraintId);
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- aRefAttr->setAttr(theFirstAttribute);
-
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
- aRefAttr->setObject(theSecondObject);
-
-#ifdef DEBUG_TRIM
- std::cout << "<createConstraint to attribute> :"
- << "first attribute - " << theFirstAttribute->id()
- << "second object - " << ModelAPI_Feature::feature(theSecondObject)->getKind()
- << std::endl;
-#endif
-
- return aConstraint;
-}
-
-FeaturePtr SketchPlugin_Trim::createConstraintForObjects(
- const std::string& theConstraintId,
- const ObjectPtr& theFirstObject,
- const ObjectPtr& theSecondObject)
-{
- FeaturePtr aConstraint = sketch()->addFeature(theConstraintId);
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- aRefAttr->setObject(theFirstObject);
-
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
- aRefAttr->setObject(theSecondObject);
-
- return aConstraint;
-}
-
-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
- //SketchPlugin_Sketch* aSketch = sketch();
- 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())
- aFeatures.push_back(aFeature);
- }
- ModelGeomAlgo_Point2D::getPointsIntersectedShape(aFeature, aFeatures, aPointsInfo);
-
- GeomAlgoAPI_ShapeTools::splitShape(aFeatureShape, aPointsInfo, aShapes);
- }
- theObjectToPoints[theObject] = aPointsInfo;
- theCashedShapes[theObject] = aShapes;