X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_Sketch.cpp;h=2b45cb65a45458a6bbb61f182e10b2fee5c92a31;hb=93152527420704cf35e22b11d1de198e1710bd90;hp=5429b2b605668573097dbc9bd76ff09713971433;hpb=f94597c12ce50d16f067cbe1bdc89066dcf5e199;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 5429b2b60..2b45cb65a 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -21,11 +22,15 @@ #include #include #include +#include +#include #include +#include #include +#include #include using namespace std; @@ -41,6 +46,10 @@ void SketchPlugin_Sketch::initAttributes() data()->addAttribute(SketchPlugin_Sketch::DIRY_ID(), GeomDataAPI_Dir::type()); data()->addAttribute(SketchPlugin_Sketch::NORM_ID(), GeomDataAPI_Dir::type()); data()->addAttribute(SketchPlugin_Sketch::FEATURES_ID(), ModelAPI_AttributeRefList::type()); + // the selected face, base for the sketcher plane, not obligatory + data()->addAttribute(SketchPlugin_Feature::EXTERNAL_ID(), ModelAPI_AttributeSelection::type()); + ModelAPI_Session::get()->validators()->registerNotObligatory( + getKind(), SketchPlugin_Feature::EXTERNAL_ID()); } void SketchPlugin_Sketch::execute() @@ -69,6 +78,11 @@ void SketchPlugin_Sketch::execute() for (; anIt != aLast; anIt++) { aFeature = boost::dynamic_pointer_cast(*anIt); if (aFeature) { + // do not include the external edges into the result + if (aFeature->data()->attribute(SketchPlugin_Feature::EXTERNAL_ID())) { + if (aFeature->data()->selection(SketchPlugin_Feature::EXTERNAL_ID())->value()) + continue; + } const std::list >& aRes = aFeature->results(); std::list >::const_iterator aResIter = aRes.cbegin(); @@ -165,6 +179,19 @@ boost::shared_ptr SketchPlugin_Sketch::to3D(const double theX, cons return boost::shared_ptr(new GeomAPI_Pnt(aSum)); } +boost::shared_ptr SketchPlugin_Sketch::to2D( + const boost::shared_ptr& thePnt) +{ + boost::shared_ptr aC = boost::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); + boost::shared_ptr aX = boost::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Sketch::DIRX_ID())); + boost::shared_ptr aY = boost::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Sketch::DIRY_ID())); + return thePnt->to2D(aC->pnt(), aX->dir(), aY->dir()); +} + + bool SketchPlugin_Sketch::isPlaneSet() { boost::shared_ptr aNormal = boost::dynamic_pointer_cast( @@ -241,3 +268,65 @@ void SketchPlugin_Sketch::erase() } ModelAPI_CompositeFeature::erase(); } + +void SketchPlugin_Sketch::attributeChanged() { + static bool kIsUpdated = false; // to avoid infinitive cycle on attrubtes change + static bool kIsAttrChanged = false; + boost::shared_ptr aSelection = + data()->selection(SketchPlugin_Feature::EXTERNAL_ID())->value(); + if (aSelection && !kIsUpdated) { // update arguments due to the selection value + kIsUpdated = true; + // update the sketch plane + boost::shared_ptr aPlane = GeomAlgoAPI_FaceBuilder::plane(aSelection); + if (aPlane) { + double anA, aB, aC, aD; + aPlane->coefficients(anA, aB, aC, aD); + + // calculate attributes of the sketch + boost::shared_ptr aNormDir(new GeomAPI_Dir(anA, aB, aC)); + boost::shared_ptr aCoords = aNormDir->xyz(); + boost::shared_ptr aZero(new GeomAPI_XYZ(0, 0, 0)); + aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero)); + boost::shared_ptr anOrigPnt(new GeomAPI_Pnt(aCoords)); + // X axis is preferable to be dirX on the sketch + static const double tol = 1.e-7; + bool isX = fabs(anA - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol; + boost::shared_ptr aTempDir( + isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0)); + boost::shared_ptr aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir))); + boost::shared_ptr aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir))); + + kIsAttrChanged = false; // track the attributes were really changed during the plane update + boost::shared_ptr anOrigin = boost::dynamic_pointer_cast + (data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); + anOrigin->setValue(anOrigPnt); + boost::shared_ptr aNormal = boost::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Sketch::NORM_ID())); + aNormal->setValue(aNormDir); + boost::shared_ptr aDirX = boost::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Sketch::DIRX_ID())); + aDirX->setValue(aXDir); + boost::shared_ptr aDirY = boost::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Sketch::DIRY_ID())); + aDirY->setValue(aYDir); + boost::shared_ptr aDir = aPlane->direction(); + + if (kIsAttrChanged) { + // the plane was changed, so reexecute sub-elements to update shapes (located in new plane) + ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators(); + list aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list(); + for(list::iterator aSubIt = aSubs.begin(); aSubIt != aSubs.end(); aSubIt++) { + boost::shared_ptr aFeature = + boost::dynamic_pointer_cast(*aSubIt); + if (aFeature && aFactory->validate(aFeature)) { + aFeature->execute(); + } + } + kIsAttrChanged = false; + } + } + kIsUpdated = false; + } else if (kIsUpdated) { // other attributes are updated during the selection comupation + kIsAttrChanged = true; + } +}