#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_Vertex.h>
#include <GeomAPI_XY.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomDataAPI_Point2D.h>
#include <GeomDataAPI_Dir.h>
thePoint->setValue(aProjection);
}
+static void intersectShapeAndCircle(const GeomShapePtr& theShape,
+ const GeomAPI_Circ2d& theCircle,
+ const SketchPlugin_Sketch* theSketch,
+ AttributePoint2DPtr& theIntersection)
+{
+ if (!theShape->isEdge())
+ return projectPointOnCircle(theIntersection, theCircle);
+
+ // convert shape to unbounded
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
+ if (anEdge->isLine()) {
+ static const double HALF_SIZE = 1.e6;
+ std::shared_ptr<GeomAPI_XYZ> aLoc = anEdge->line()->location()->xyz();
+ std::shared_ptr<GeomAPI_XYZ> aDir = anEdge->line()->direction()->xyz();
+
+ std::shared_ptr<GeomAPI_Pnt> aStart(
+ new GeomAPI_Pnt(aLoc->added(aDir->multiplied(-HALF_SIZE))));
+ std::shared_ptr<GeomAPI_Pnt> aEnd(
+ new GeomAPI_Pnt(aLoc->added(aDir->multiplied(HALF_SIZE))));
+ anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, aEnd);
+ } else if (anEdge->isArc()) {
+ std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
+ anEdge = GeomAlgoAPI_EdgeBuilder::lineCircle(
+ aCircle->center(), aCircle->normal(), aCircle->radius());
+ }
+
+ // convert 2D circle to 3D object
+ std::shared_ptr<GeomAPI_Pnt2d> aCenter2d = theCircle.center();
+ std::shared_ptr<GeomAPI_Pnt> aCenter(theSketch->to3D(aCenter2d->x(), aCenter2d->y()));
+ std::shared_ptr<GeomDataAPI_Dir> aNDir = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ const_cast<SketchPlugin_Sketch*>(theSketch)->attribute(SketchPlugin_Sketch::NORM_ID()));
+ std::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
+
+ GeomShapePtr aCircleShape =
+ GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, theCircle.radius());
+
+ GeomShapePtr anInter = anEdge->intersect(aCircleShape);
+ std::shared_ptr<GeomAPI_Pnt2d> anInterPnt;
+ if (!anInter)
+ return projectPointOnCircle(theIntersection, theCircle);
+ if (anInter->isVertex()) {
+ std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(anInter));
+ anInterPnt = theSketch->to2D(aVertex->point());
+ } else if (anInter->isCompound()) {
+ double aMinDist = 1.e300;
+
+ GeomAPI_ShapeIterator anIt(anInter);
+ for (; anIt.more(); anIt.next()) {
+ GeomShapePtr aCurrent = anIt.current();
+ if (!aCurrent->isVertex())
+ continue;
+ std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aCurrent));
+ std::shared_ptr<GeomAPI_Pnt2d> aPnt = theSketch->to2D(aVertex->point());
+ double aDist = aPnt->distance(theIntersection->pnt());
+ if (aDist < aMinDist) {
+ aMinDist = aDist;
+ anInterPnt = aPnt;
+ }
+ }
+ }
+ if(anInterPnt.get()) {
+ theIntersection->setValue(anInterPnt);
+ }
+}
+
SketchPlugin_MacroArc::SketchPlugin_MacroArc()
: SketchPlugin_SketchEntity(),
}
bool aWasBlocked = data()->blockSendAttributeUpdated(true);
+ if(myCenter.get()) {
+ // center attribute is used in processEvent() to set reference to reentrant arc
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_POINT_ID()))
+ ->setValue(myCenter);
+ }
real(RADIUS_ID())->setValue(aRadius);
real(ANGLE_ID())->setValue(anAngle);
data()->blockSendAttributeUpdated(aWasBlocked, false);
}
-GeomShapePtr SketchPlugin_MacroArc::getArcShape()
+GeomShapePtr SketchPlugin_MacroArc::getArcShape(bool isBound)
{
if(!myStart.get() || !myEnd.get() || !myCenter.get()) {
return GeomShapePtr();
std::dynamic_pointer_cast<GeomDataAPI_Dir>(aSketch->attribute(SketchPlugin_Sketch::NORM_ID()));
std::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
- GeomShapePtr anArcShape = boolean(REVERSED_ID())->value() ?
- GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, anEnd, aStart, aNormal)
- : GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStart, anEnd, aNormal);
+ GeomShapePtr anArcShape;
+ if (isBound) {
+ anArcShape = boolean(REVERSED_ID())->value() ?
+ GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, anEnd, aStart, aNormal)
+ : GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStart, anEnd, aNormal);
+ } else {
+ double aRadius = aCenter->distance(aStart);
+ anArcShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, aRadius);
+ }
return anArcShape;
}
// message to init reentrant operation
static Events_ID anId = SketchPlugin_MacroArcReentrantMessage::eventId();
std::shared_ptr<SketchPlugin_MacroArcReentrantMessage> aMessage = std::shared_ptr
- <SketchPlugin_MacroArcReentrantMessage>(new SketchPlugin_MacroArcReentrantMessage(anId, 0));
+ <SketchPlugin_MacroArcReentrantMessage>(new SketchPlugin_MacroArcReentrantMessage(anId, this));
std::string anEditArcType = string(EDIT_ARC_TYPE_ID())->value();
aMessage->setTypeOfCreation(!anEditArcType.empty() ? anEditArcType : anArcType);
aPointAttr->setValue(aClickedPoint);
// fill reference attribute
AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- attribute(aReferenceAttributeName));
+ attribute(aReferenceAttributeName));
if (aRefAttr.get()) {
- if (anAttribute.get())
+ if (anAttribute.get()) {
+ if (!anAttribute->owner().get() || !anAttribute->owner()->data()->isValid()) {
+ FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature();
+ if (aCreatedFeature.get()) {
+ std::string anID = anAttribute->id();
+ std::string anArcID;
+ if (anID == END_POINT_1_ID() || anID == END_POINT_2_ID() ||
+ anID == END_POINT_3_ID())
+ anArcID = SketchPlugin_Arc::END_ID();
+ else if (anID == START_POINT_1_ID() || anID ==START_POINT_2_ID())
+ anArcID = SketchPlugin_Arc::START_ID();
+ else if (anID == CENTER_POINT_ID())
+ anArcID = SketchPlugin_Arc::CENTER_ID();
+ anAttribute = aCreatedFeature->attribute(anArcID);
+ }
+ }
aRefAttr->setAttr(anAttribute);
+ }
else if (anObject.get()) {
// if presentation of previous reentrant macro arc is used, the object is invalid,
// we should use result of previous feature of the message(Arc)
if (!anObject->data()->isValid()) {
FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature();
- anObject = aCreatedFeature->lastResult();
+ if (aCreatedFeature.get())
+ anObject = aCreatedFeature->lastResult();
}
aRefAttr->setObject(anObject);
}
GeomAPI_Circ2d aCircleForArc(myCenter, myStart);
- // End point should be a projection on circle.
bool aWasBlocked = data()->blockSendAttributeUpdated(true);
- projectPointOnCircle(anEndPointAttr, aCircleForArc);
+ // check the end point is referred to another feature
+ GeomShapePtr aRefShape;
+ AttributeRefAttrPtr aEndPointRefAttr = refattr(END_POINT_REF_ID());
+ if (aEndPointRefAttr && aEndPointRefAttr->isInitialized()) {
+ if (aEndPointRefAttr->isObject()) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aEndPointRefAttr->object());
+ if (aFeature)
+ aRefShape = aFeature->lastResult()->shape();
+ }
+ }
+ if (aRefShape) {
+ // Calculate end point as an intersection between circle and another shape
+ intersectShapeAndCircle(aRefShape, aCircleForArc, sketch(), anEndPointAttr);
+ } else {
+ // End point should be a projection on circle.
+ projectPointOnCircle(anEndPointAttr, aCircleForArc);
+ }
data()->blockSendAttributeUpdated(aWasBlocked, false);
myEnd = anEndPointAttr->pnt();