+void SketchPlugin_Sketch::attributeChanged(const std::string& theID) {
+ if (theID == SketchPlugin_SketchEntity::EXTERNAL_ID()) {
+ AttributeSelectionPtr aSelAttr = selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
+ if (aSelAttr->context().get()) { // update arguments due to the selection value
+ std::shared_ptr<GeomAPI_Shape> aSelection = aSelAttr->value();
+ if (!aSelection.get()) aSelection = aSelAttr->context()->shape();
+ // update the sketch plane
+ std::shared_ptr<GeomAPI_Face> aFace;
+ if (aSelection->isFace()) {
+ aFace = aSelection->face();
+ } else if (aSelection->isCompound()) {
+ GeomAPI_ShapeIterator anIt(aSelection);
+ aFace = anIt.current()->face();
+ }
+ if (aFace.get()) {
+ std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
+ if (aPlane.get()) {
+ double anA, aB, aC, aD;
+ aPlane->coefficients(anA, aB, aC, aD);
+
+ // calculate attributes of the sketch
+ std::shared_ptr<GeomAPI_Dir> aNormDir(new GeomAPI_Dir(anA, aB, aC));
+ std::shared_ptr<GeomAPI_XYZ> aCoords = aNormDir->xyz();
+ std::shared_ptr<GeomAPI_XYZ> aZero(new GeomAPI_XYZ(0, 0, 0));
+ aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
+ std::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
+ // X axis is preferable to be dirX on the sketch
+ // here can not be very small value to avoid very close to X normal axis (issue 595)
+ static const double tol = 0.1;
+ bool isX = fabs(anA) - 1.0 < tol && fabs(aB) < tol && fabs(aC) < tol;
+ std::shared_ptr<GeomAPI_Dir> aTempDir(
+ isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0));
+ std::shared_ptr<GeomAPI_Dir> aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir)));
+ std::shared_ptr<GeomAPI_Dir> aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir)));
+
+ bool aWasBlocked = data()->blockSendAttributeUpdated(true);
+ // update position of the sketch
+ std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast
+ <GeomDataAPI_Point>(data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ anOrigin->setValue(anOrigPnt);
+ std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(SketchPlugin_Sketch::NORM_ID()));
+ aNormal->setValue(aNormDir);
+ std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
+ aDirX->setValue(aXDir);
+ data()->blockSendAttributeUpdated(aWasBlocked, true);
+ }
+ }
+ }
+ } else if (theID == NORM_ID() || theID == DIRX_ID() || theID == ORIGIN_ID()) {
+ // check if current and previous sketch planes are coordinate planes and they are different
+ GeomAx3Ptr aCurPlane;
+ bool areCoordPlanes = false;
+ if (isPlaneSet()) {
+ aCurPlane = coordinatePlane();
+ areCoordPlanes = isCoordinatePlane(aCurPlane) && isCoordinatePlane(myPlane);
+ }
+
+ // send all sub-elements are also updated: all entities become created on different plane
+ static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+ std::list<ObjectPtr> aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
+ std::list<ObjectPtr>::iterator aSub = aSubs.begin();
+ for(; aSub != aSubs.end(); aSub++) {
+ if (aSub->get()) {
+ if (areCoordPlanes)
+ updateCoordinateAxis(*aSub, aCurPlane);
+
+ ModelAPI_EventCreator::get()->sendUpdated(*aSub, anUpdateEvent);
+ }
+ }
+ if (aCurPlane)
+ myPlane = aCurPlane;
+ }