From: vsv Date: Fri, 21 Aug 2015 14:30:40 +0000 (+0300) Subject: Icon for angle constraint is added, execute method is reviewed for working with pre... X-Git-Tag: V_1.4.0_beta4~290 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0e158cb76c7797d04c2090d9283c3fb907d8b4bb;p=modules%2Fshaper.git Icon for angle constraint is added, execute method is reviewed for working with pre-selection --- diff --git a/src/PartSet/PartSet_icons.qrc b/src/PartSet/PartSet_icons.qrc index 2e7928ace..c8e47dcd1 100644 --- a/src/PartSet/PartSet_icons.qrc +++ b/src/PartSet/PartSet_icons.qrc @@ -60,5 +60,6 @@ icons/movement.png icons/extrusion_cut.png icons/extrusion_fuse.png + icons/angle_constr.png diff --git a/src/PartSet/icons/angle_constr.png b/src/PartSet/icons/angle_constr.png new file mode 100644 index 000000000..1c403b813 Binary files /dev/null and b/src/PartSet/icons/angle_constr.png differ diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp index fc2df7237..c0ed69812 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp @@ -38,14 +38,26 @@ void SketchPlugin_ConstraintAngle::initAttributes() void SketchPlugin_ConstraintAngle::execute() { std::shared_ptr aData = data(); - AttributeDoublePtr anAttrValue = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Constraint::VALUE())); - if(anAttrValue->isInitialized()) + std::shared_ptr anAttrA = aData->refattr(SketchPlugin_Constraint::ENTITY_A()); + std::shared_ptr anAttrB = aData->refattr(SketchPlugin_Constraint::ENTITY_B()); + if (!anAttrA->isInitialized() || !anAttrB->isInitialized()) return; - double anAngle = calculateAngle(); - anAttrValue->setValue(anAngle); + AttributeDoublePtr anAttrValue = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Constraint::VALUE())); + + if (!anAttrValue->isInitialized()) { + double anAngle = calculateAngle(); + anAttrValue->setValue(anAngle); + } + // the value should to be computed here, not in the getAISObject in order to change the model value + // inside the object transaction. This is important for creating a constraint by preselection. + // The display of the presentation in this case happens after the transaction commit + std::shared_ptr aFlyOutAttr = std::dynamic_pointer_cast< + GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); + if(!aFlyOutAttr->isInitialized()) + compute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()); } AISObjectPtr SketchPlugin_ConstraintAngle::getAISObject(AISObjectPtr thePrevious) @@ -67,16 +79,16 @@ AISObjectPtr SketchPlugin_ConstraintAngle::getAISObject(AISObjectPtr thePrevious void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID) { - if (theID == SketchPlugin_Constraint::ENTITY_A() || - theID == SketchPlugin_Constraint::ENTITY_B()) { - std::shared_ptr aData = data(); - if (!aData) - return; + std::shared_ptr aData = data(); + if (!aData) + return; FeaturePtr aLineA = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A()); FeaturePtr aLineB = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B()); - if (!aLineA || !aLineB) - return; + if (!aLineA || !aLineB) + return; + if (theID == SketchPlugin_Constraint::ENTITY_A() || + theID == SketchPlugin_Constraint::ENTITY_B()) { std::shared_ptr aValueAttr = std::dynamic_pointer_cast< ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE())); if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value @@ -85,6 +97,7 @@ void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID) } } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) { // Recalculate flyout point in local coordinates + // coordinates are calculated according to the center of shapes intersection std::shared_ptr aFlyoutAttr = std::dynamic_pointer_cast(attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); } @@ -148,3 +161,45 @@ void SketchPlugin_ConstraintAngle::move(double theDeltaX, double theDeltaY) aFlyoutAttr->setValue(aFlyoutAttr->x() + theDeltaX, aFlyoutAttr->y() + theDeltaY); myFlyoutUpdate = false; } + + +bool SketchPlugin_ConstraintAngle::compute(const std::string& theAttributeId) +{ + if (theAttributeId != SketchPlugin_Constraint::FLYOUT_VALUE_PNT()) + return false; + if (!sketch()) + return false; + + std::shared_ptr aFlyOutAttr = std::dynamic_pointer_cast< + GeomDataAPI_Point2D>(attribute(theAttributeId)); + if (fabs(aFlyOutAttr->x()) >= tolerance || fabs(aFlyOutAttr->y()) >= tolerance) + return false; + + DataPtr aData = data(); + std::shared_ptr aPlane = SketchPlugin_Sketch::plane(sketch()); + FeaturePtr aLineA = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A()); + FeaturePtr aLineB = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B()); + + if ((aLineA.get() == NULL) || (aLineB.get() == NULL)) + return false; + + // Start and end points of lines + std::shared_ptr aPointA1 = std::dynamic_pointer_cast( + aLineA->attribute(SketchPlugin_Line::START_ID())); + std::shared_ptr aPointA2 = std::dynamic_pointer_cast( + aLineA->attribute(SketchPlugin_Line::END_ID())); + + std::shared_ptr aStartA = aPointA1->pnt(); + std::shared_ptr aEndA = aPointA2->pnt(); + if (aStartA->distance(aEndA) < tolerance) + return false; + + myFlyoutUpdate = true; + double aX = (aStartA->x() + aEndA->x()) / 2.; + double aY = (aStartA->y() + aEndA->y()) / 2.; + + aFlyOutAttr->setValue(aX, aY); + myFlyoutUpdate = false; + + return true; +} \ No newline at end of file diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.h b/src/SketchPlugin/SketchPlugin_ConstraintAngle.h index 29f37f82f..ef3c478be 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.h @@ -37,6 +37,11 @@ class SketchPlugin_ConstraintAngle : public SketchPlugin_ConstraintBase /// \brief Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); + /// Computes the attribute value on the base of other attributes if the value can be computed + /// \param theAttributeId an attribute index to be computed + /// \return a boolean value about it is computed + SKETCHPLUGIN_EXPORT virtual bool compute(const std::string& theAttributeId); + /// \brief Request for initialization of data model of the feature: adding all attributes SKETCHPLUGIN_EXPORT virtual void initAttributes(); diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 8418520a8..8468ea0eb 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -101,8 +101,25 @@ - - + + + + + + + + + + + + + + + + + + + @@ -219,25 +236,6 @@ - - - - - - - - - - - - - - - - - - -