-void addPlane(double theX, double theY, double theZ,
- std::list<boost::shared_ptr<GeomAPI_Shape> >& theShapes)
-{
- boost::shared_ptr<GeomAPI_Pnt> anOrigin(new GeomAPI_Pnt(0, 0, 0));
- boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(theX, theY, theZ));
- double aSize = Config_PropManager::integer("Sketch planes", "Size of planes", PLANE_SIZE);
- boost::shared_ptr<GeomAPI_Shape> aFace = GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal,
- aSize);
- theShapes.push_back(aFace);
+void SketchPlugin_Sketch::attributeChanged(const std::string& theID) {
+ if (theID == SketchPlugin_SketchEntity::EXTERNAL_ID()) {
+ std::shared_ptr<GeomAPI_Shape> aSelection =
+ data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->value();
+ if (aSelection) { // update arguments due to the selection value
+ // update the sketch plane
+ std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aSelection);
+ if (aPlane) {
+ 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
+ static const double tol = 0.1; // here can not be very small value to avoid very close to X normal axis (issue 595)
+ 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)));
+
+ // 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);
+ std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
+ }
+ }
+ } else if (theID == SketchPlugin_Sketch::NORM_ID() || theID == SketchPlugin_Sketch::DIRX_ID()) {
+ // 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())
+ ModelAPI_EventCreator::get()->sendUpdated(*aSub, anUpdateEvent);
+ }
+ }