- 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)
-{
- 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
-
- 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;
-
- 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);
-
- aFeature->string(SketchPlugin_Arc::ARC_TYPE())->setValue(
- SketchPlugin_Arc::ARC_TYPE_CENTER_START_END());
-
- 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::INVERSED_ID())->value();
- aFeature->boolean(SketchPlugin_Arc::INVERSED_ID())->setValue(aReversed);
- }
- aFeature->execute(); // to obtain result
- aFeature->data()->blockSendAttributeUpdated(aWasBlocked);
-
- 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::createConstraint(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;
-}
-
-//********************************************************************
-bool SketchPlugin_Trim::useGraphicIntersection() const
-{
- return true;
-}
-
-//********************************************************************
-void SketchPlugin_Trim::fillObjectShapes(const ObjectPtr& theObject)
-{
- 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
- ModelAPI_Tools::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 = aSketch->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);
-
- // intersection points
- if (useGraphicIntersection()) {
- std::list<FeaturePtr> aFeatures;
- for (int i = 0; i < aSketch->numberOfSubs(); i++) {
- FeaturePtr aFeature = aSketch->subFeature(i);
- if (aFeature.get())
- aFeatures.push_back(aFeature);
- }
- ModelGeomAlgo_Point2D::getPointsIntersectedShape(aFeature, aFeatures, aPointsInfo);
- }
- GeomAlgoAPI_ShapeTools::splitShape(aFeatureShape, aPointsInfo, aShapes);
- }
- myObjectToPoints[theObject] = aPointsInfo;
- myCashedShapes[theObject] = aShapes;
-}
-
-//********************************************************************
-void SketchPlugin_Trim::attributeChanged(const std::string& theID)
-{
- //data()->addAttribute(SketchPlugin_Trim::BASE_OBJECT(), ModelAPI_AttributeReference::typeId());
- if (theID == SketchPlugin_Trim::BASE_OBJECT()) {
- bool isValidAttribute = false;
- // feature for trim
- AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- data()->attribute(SketchPlugin_Trim::BASE_OBJECT()));
- ObjectPtr aBaseObject = aBaseObjectAttr->value();
- if (aBaseObject.get()) {
- FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
- // point on feature
- AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- data()->attribute(ENTITY_POINT()));
- std::shared_ptr<GeomAPI_Pnt2d> anAttributePnt2d = aPoint->pnt();
- std::shared_ptr<GeomAPI_Pnt> anAttributePnt = sketch()->to3D(anAttributePnt2d->x(), anAttributePnt2d->y());
-
- if (myCashedShapes.find(aBaseObject) == myCashedShapes.end())
- fillObjectShapes(aBaseObject);
-
- const std::set<GeomShapePtr>& aShapes = myCashedShapes[aBaseObject];
- isValidAttribute = !aShapes.empty();
-
- if (!isValidAttribute) {
- bool aWasBlocked = data()->blockSendAttributeUpdated(true);
- aBaseObjectAttr->setValue(ObjectPtr());
- data()->blockSendAttributeUpdated(aWasBlocked);
- }
- }
- }