+ // feature not found, create new
+ if (!theFeature)
+ theFeature = theSketch->addFeature(theFeatureKind);
+ }
+}
+
+void SketchPlugin_Offset::updateExistentOrCreateNew(const GeomShapePtr& theShape,
+ FeaturePtr& theFeature,
+ std::list<ObjectPtr>& thePoolOfFeatures)
+{
+ if (theShape->shapeType() != GeomAPI_Shape::EDGE)
+ return;
+
+ std::shared_ptr<GeomAPI_Edge> aResEdge(new GeomAPI_Edge(theShape));
+
+ std::shared_ptr<GeomAPI_Pnt2d> aFP, aLP;
+ std::shared_ptr<GeomAPI_Pnt> aFP3d = aResEdge->firstPoint();
+ std::shared_ptr<GeomAPI_Pnt> aLP3d = aResEdge->lastPoint();
+ if (aFP3d && aLP3d) {
+ aFP = sketch()->to2D(aFP3d);
+ aLP = sketch()->to2D(aLP3d);
+ }
+
+ if (aResEdge->isLine()) {
+ findOrCreateFeatureByKind(sketch(), SketchPlugin_Line::ID(), theFeature, thePoolOfFeatures);
+
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (theFeature->attribute(SketchPlugin_Line::START_ID()))->setValue(aFP);
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (theFeature->attribute(SketchPlugin_Line::END_ID()))->setValue(aLP);
+ }
+ else if (aResEdge->isArc()) {
+ std::shared_ptr<GeomAPI_Circ> aCircEdge = aResEdge->circle();
+ std::shared_ptr<GeomAPI_Pnt> aCP3d = aCircEdge->center();
+ std::shared_ptr<GeomAPI_Pnt2d> aCP = sketch()->to2D(aCP3d);
+
+ findOrCreateFeatureByKind(sketch(), SketchPlugin_Arc::ID(), theFeature, thePoolOfFeatures);
+
+ bool aWasBlocked = theFeature->data()->blockSendAttributeUpdated(true);
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (theFeature->attribute(SketchPlugin_Arc::CENTER_ID()))->setValue(aCP);
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (theFeature->attribute(SketchPlugin_Arc::START_ID()))->setValue(aFP);
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (theFeature->attribute(SketchPlugin_Arc::END_ID()))->setValue(aLP);
+ theFeature->data()->blockSendAttributeUpdated(aWasBlocked);
+ }
+ else if (aResEdge->isCircle()) {
+ std::shared_ptr<GeomAPI_Circ> aCircEdge = aResEdge->circle();
+ std::shared_ptr<GeomAPI_Pnt> aCP3d = aCircEdge->center();
+ std::shared_ptr<GeomAPI_Pnt2d> aCP = sketch()->to2D(aCP3d);
+
+ findOrCreateFeatureByKind(sketch(), SketchPlugin_Circle::ID(), theFeature, thePoolOfFeatures);
+
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (theFeature->attribute(SketchPlugin_Circle::CENTER_ID()))->setValue(aCP);
+ theFeature->real(SketchPlugin_Circle::RADIUS_ID())->setValue(aCircEdge->radius());
+ }
+ else if (aResEdge->isEllipse()) {
+ std::shared_ptr<GeomAPI_Ellipse> anEllipseEdge = aResEdge->ellipse();
+
+ GeomPointPtr aCP3d = anEllipseEdge->center();
+ GeomPnt2dPtr aCP = sketch()->to2D(aCP3d);
+
+ GeomPointPtr aFocus3d = anEllipseEdge->firstFocus();
+ GeomPnt2dPtr aFocus = sketch()->to2D(aFocus3d);
+
+ if (aFP3d && aLP3d) {
+ // Elliptic arc
+ findOrCreateFeatureByKind(sketch(), SketchPlugin_EllipticArc::ID(),
+ theFeature, thePoolOfFeatures);
+
+ bool aWasBlocked = theFeature->data()->blockSendAttributeUpdated(true);
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (theFeature->attribute(SketchPlugin_EllipticArc::CENTER_ID()))->setValue(aCP);
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (theFeature->attribute(SketchPlugin_EllipticArc::FIRST_FOCUS_ID()))->setValue(aFocus);
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (theFeature->attribute(SketchPlugin_EllipticArc::START_POINT_ID()))->setValue(aFP);
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (theFeature->attribute(SketchPlugin_EllipticArc::END_POINT_ID()))->setValue(aLP);
+ theFeature->data()->blockSendAttributeUpdated(aWasBlocked);
+ }
+ else {
+ // Ellipse
+ findOrCreateFeatureByKind(sketch(), SketchPlugin_Ellipse::ID(),
+ theFeature, thePoolOfFeatures);
+
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (theFeature->attribute(SketchPlugin_Ellipse::CENTER_ID()))->setValue(aCP);
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>
+ (theFeature->attribute(SketchPlugin_Ellipse::FIRST_FOCUS_ID()))->setValue(aFocus);
+ theFeature->real(SketchPlugin_Ellipse::MINOR_RADIUS_ID())->setValue(anEllipseEdge->minorRadius());
+ }
+ }
+ else {
+ // convert to b-spline
+ mkBSpline(theFeature, aResEdge, thePoolOfFeatures);
+ }
+
+ if (theFeature.get()) {
+ theFeature->boolean(SketchPlugin_SketchEntity::COPY_ID())->setValue(true);
+ theFeature->execute();
+
+ static Events_ID aRedisplayEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ ModelAPI_EventCreator::get()->sendUpdated(theFeature, aRedisplayEvent);
+ const std::list<ResultPtr>& aResults = theFeature->results();
+ for (std::list<ResultPtr>::const_iterator anIt = aResults.begin();
+ anIt != aResults.end(); ++anIt)
+ ModelAPI_EventCreator::get()->sendUpdated(*anIt, aRedisplayEvent);