+void createConstraint(SketchPlugin_Feature* theFeature,
+ const std::string& theId,
+ const AttributePtr theAttr,
+ const ObjectPtr theObject,
+ const bool theIsCanBeTangent)
+{
+ AttributeRefAttrPtr aRefAttr = theFeature->refattr(theId);
+ if(aRefAttr.get() && aRefAttr->isInitialized()) {
+ FeaturePtr aConstraint;
+ if(!theIsCanBeTangent) {
+ aConstraint = theFeature->sketch()
+ ->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+ } else {
+ if(aRefAttr->isObject()) {
+ ObjectPtr anObject = aRefAttr->object();
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ if(aFeature->getKind() == SketchPlugin_Point::ID()) {
+ aConstraint = theFeature->sketch()
+ ->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+ } else {
+ aConstraint = theFeature->sketch()
+ ->addFeature(SketchPlugin_ConstraintTangent::ID());
+ }
+ } else {
+ aConstraint = theFeature->sketch()
+ ->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+ }
+ }
+ AttributeRefAttrPtr aRefAttrA = aConstraint->refattr(SketchPlugin_Constraint::ENTITY_A());
+ aRefAttr->isObject() ? aRefAttrA->setObject(aRefAttr->object())
+ : aRefAttrA->setAttr(aRefAttr->attr());
+ AttributeRefAttrPtr aRefAttrB = aConstraint->refattr(SketchPlugin_Constraint::ENTITY_B());
+ if(theObject.get()) {
+ aRefAttrB->setObject(theObject);
+ } else if(theAttr.get()) {
+ aRefAttrB->setAttr(theAttr);
+ }
+ }
+}
+
+void convertRefAttrToPointOrTangentCurve(const AttributeRefAttrPtr& theRefAttr,
+ const AttributePtr& theDefaultAttr,
+ std::shared_ptr<GeomAPI_Shape>& theTangentCurve,
+ std::shared_ptr<GeomAPI_Pnt2d>& thePassingPoint)
+{
+ AttributePtr anAttr = theDefaultAttr;
+ if (theRefAttr->isObject()) {
+ FeaturePtr aTgFeature = ModelAPI_Feature::feature(theRefAttr->object());
+ if (aTgFeature) {
+ if (aTgFeature->getKind() != SketchPlugin_Point::ID()) {
+ theTangentCurve = aTgFeature->lastResult()->shape();
+ return;
+ }
+ anAttr = aTgFeature->attribute(SketchPlugin_Point::COORD_ID());
+ }
+ } else
+ anAttr = theRefAttr->attr();
+
+ thePassingPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr)->pnt();
+}
+