From 2d377b25bd785a251e6a57064a4bfd88c60d2468 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 27 Jul 2016 18:51:10 +0300 Subject: [PATCH] Issue #1652 Add a real widget displaying the length of the line in the panel: correction to open already save studies. --- src/PartSet/PartSet_Tools.cpp | 11 +++++++---- src/SketchPlugin/SketchPlugin_Line.cpp | 13 ++++++++----- src/SketchPlugin/SketchPlugin_Line.h | 7 ++++--- src/SketchPlugin/SketchPlugin_Validators.cpp | 2 +- src/SketchPlugin/plugin-Sketch.xml | 13 ++++++------- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 5e22fd68a..6495c3ce9 100755 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -395,15 +395,18 @@ void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr the std::shared_ptr PartSet_Tools::sketchPlane(CompositeFeaturePtr theSketch) { + std::shared_ptr aPlane; + std::shared_ptr anOrigin = std::dynamic_pointer_cast( theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); - std::shared_ptr aNorm = std::dynamic_pointer_cast( + std::shared_ptr aNormal = std::dynamic_pointer_cast( theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); - if (!anOrigin || !aNorm) - return std::shared_ptr(); + if (aNormal.get() && aNormal->isInitialized() && + anOrigin.get() && anOrigin->isInitialized()) + aPlane = std::shared_ptr(new GeomAPI_Pln(anOrigin->pnt(), aNormal->dir())); - return std::shared_ptr(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir())); + return aPlane; } std::shared_ptr PartSet_Tools::point3D(std::shared_ptr thePoint2D, diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index 3c4e19a1a..2d2c6bc4a 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -27,14 +27,19 @@ SketchPlugin_Line::SketchPlugin_Line() : SketchPlugin_SketchEntity() {} +void SketchPlugin_Line::initAttributes() +{ + SketchPlugin_SketchEntity::initAttributes(); + /// new attributes should be added to end of the feature in order to provide + /// correct attribute values in previous saved studies + data()->addAttribute(LENGTH_ID(), ModelAPI_AttributeDouble::typeId()); +} + void SketchPlugin_Line::initDerivedClassAttributes() { data()->addAttribute(START_ID(), GeomDataAPI_Point2D::typeId()); data()->addAttribute(END_ID(), GeomDataAPI_Point2D::typeId()); data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId()); -#ifndef LINE_LENGHT_BLOCKED - data()->addAttribute(LENGTH_ID(), ModelAPI_AttributeDouble::typeId()); -#endif ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID()); } @@ -137,7 +142,6 @@ void SketchPlugin_Line::attributeChanged(const std::string& theID) { void SketchPlugin_Line::updateLenghtValue() { -#ifndef LINE_LENGHT_BLOCKED std::shared_ptr aStartAttr = std::dynamic_pointer_cast< GeomDataAPI_Point2D>(data()->attribute(START_ID())); std::shared_ptr anEndAttr = std::dynamic_pointer_cast< @@ -146,5 +150,4 @@ void SketchPlugin_Line::updateLenghtValue() double aDistance = aStartAttr->pnt()->distance(anEndAttr->pnt()); data()->real(LENGTH_ID())->setValue(aDistance); } -#endif } diff --git a/src/SketchPlugin/SketchPlugin_Line.h b/src/SketchPlugin/SketchPlugin_Line.h index 0ff8e6b71..e24e90e54 100644 --- a/src/SketchPlugin/SketchPlugin_Line.h +++ b/src/SketchPlugin/SketchPlugin_Line.h @@ -12,7 +12,6 @@ #include #include -#define LINE_LENGHT_BLOCKED class GeomAPI_Pnt2d; /**\class SketchPlugin_Line @@ -42,19 +41,21 @@ class SketchPlugin_Line : public SketchPlugin_SketchEntity } /// Line length. -#ifndef LINE_LENGHT_BLOCKED static const std::string& LENGTH_ID() { static const std::string MY_LENGTH("LineLength"); return MY_LENGTH; } -#endif + /// Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind(); /// Returns true is sketch element is under the rigid constraint SKETCHPLUGIN_EXPORT virtual bool isFixed(); + /// Request for initialization of data model of the feature: adding all attributes + virtual void initAttributes(); + /// Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index d309ce8cb..d094a04c7 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -903,7 +903,7 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute, ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(), aX->dir(), aDirY, aPoints); - int aCoincidentToFeature = aPoints.size(); + int aCoincidentToFeature = (int)aPoints.size(); if (aKind == SketchPlugin_Circle::ID()) aValid = aCoincidentToFeature >= 2; else diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index b8a79e198..d6d7d909c 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -31,9 +31,8 @@ enable_value="enable_by_preferences"/> - + tooltip="Line length" obligatory="0" enable_value="false"/> @@ -49,11 +48,6 @@ - - - + + + -- 2.30.2