From: nds Date: Tue, 26 Jul 2016 06:28:00 +0000 (+0300) Subject: Issue #1664: In the Sketcher, add the function Split a segment. Correction of circle... X-Git-Tag: V_2.5.0~174 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=656b2b25f58ce91c661437af3b35cb7e8da09f6a;p=modules%2Fshaper.git Issue #1664: In the Sketcher, add the function Split a segment. Correction of circle::project to obtain a point with zero distance. Correct Attribute reference to do not check if attribute is initialized in ::value() as it might be called during validation(when attribute initialization is blocked). --- diff --git a/src/GeomAPI/GeomAPI_Circ.cpp b/src/GeomAPI/GeomAPI_Circ.cpp index c7c4573f0..4346391bd 100644 --- a/src/GeomAPI/GeomAPI_Circ.cpp +++ b/src/GeomAPI/GeomAPI_Circ.cpp @@ -70,11 +70,11 @@ const std::shared_ptr GeomAPI_Circ::project( GeomAPI_ProjectPointOnCurve aProj(aPoint, aCircle); Standard_Integer aNbPoint = aProj.NbPoints(); if (aNbPoint > 0) { - double aMinDistance = 0, aDistance; + double aMinDistance = Precision::Infinite(), aDistance; for (Standard_Integer j = 1; j <= aNbPoint; j++) { gp_Pnt aNewPoint = aProj.Point(j); aDistance = aNewPoint.Distance(aPoint); - if (!aMinDistance || aDistance < aMinDistance) { + if (aDistance < aMinDistance) { aMinDistance = aDistance; aResult = std::shared_ptr( new GeomAPI_Pnt(aNewPoint.X(), aNewPoint.Y(), aNewPoint.Z())); diff --git a/src/Model/Model_AttributeReference.cpp b/src/Model/Model_AttributeReference.cpp index b1707c006..dc1a3994d 100644 --- a/src/Model/Model_AttributeReference.cpp +++ b/src/Model/Model_AttributeReference.cpp @@ -25,7 +25,6 @@ void Model_AttributeReference::setValue(ObjectPtr theObject) // return; ObjectPtr aValue = value(); if (!myIsInitialized || aValue != theObject) { - myIsInitialized = true; REMOVE_BACK_REF(aValue); TDF_Label anObjLab; @@ -64,34 +63,31 @@ void Model_AttributeReference::setValue(ObjectPtr theObject) ObjectPtr Model_AttributeReference::value() { - if (isInitialized()) { - Handle(TDataStd_Comment) aDocID; - if (myRef->Label().FindAttribute(TDataStd_Comment::GetID(), aDocID)) { // external ref - int anID = atoi(TCollection_AsciiString(aDocID->Get()).ToCString()); - DocumentPtr aRefDoc = Model_Application::getApplication()->document(anID); - if (aRefDoc.get()) { - Handle(TDataStd_AsciiString) anEntry; - if (myRef->Label().FindAttribute(TDataStd_AsciiString::GetID(), anEntry)) { - std::shared_ptr aDR = std::dynamic_pointer_cast(aRefDoc); - TDF_Label aRefLab; - TDF_Tool::Label(aDR->objects()->featuresLabel().Data(), anEntry->Get().ToCString(), aRefLab); - if (!aRefLab.IsNull()) { - return aDR->objects()->object(aRefLab); - } + Handle(TDataStd_Comment) aDocID; + if (myRef->Label().FindAttribute(TDataStd_Comment::GetID(), aDocID)) { // external ref + int anID = atoi(TCollection_AsciiString(aDocID->Get()).ToCString()); + DocumentPtr aRefDoc = Model_Application::getApplication()->document(anID); + if (aRefDoc.get()) { + Handle(TDataStd_AsciiString) anEntry; + if (myRef->Label().FindAttribute(TDataStd_AsciiString::GetID(), anEntry)) { + std::shared_ptr aDR = std::dynamic_pointer_cast(aRefDoc); + TDF_Label aRefLab; + TDF_Tool::Label(aDR->objects()->featuresLabel().Data(), anEntry->Get().ToCString(), aRefLab); + if (!aRefLab.IsNull()) { + return aDR->objects()->object(aRefLab); } } - } else { // internal ref - std::shared_ptr aDoc = std::dynamic_pointer_cast( - owner()->document()); - if (aDoc) { - TDF_Label aRefLab = myRef->Get(); - if (!aRefLab.IsNull()) { // it may happen with old document, issue #285 - return aDoc->objects()->object(aRefLab); - } + } + } else { // internal ref + std::shared_ptr aDoc = std::dynamic_pointer_cast( + owner()->document()); + if (aDoc) { + TDF_Label aRefLab = myRef->Get(); + if (!aRefLab.IsNull()) { // it may happen with old document, issue #285 + return aDoc->objects()->object(aRefLab); } } } - // not initialized return FeaturePtr(); } diff --git a/src/PartSet/PartSet_WidgetSubShapeSelector.cpp b/src/PartSet/PartSet_WidgetSubShapeSelector.cpp index bdb039aad..72e0738bf 100755 --- a/src/PartSet/PartSet_WidgetSubShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetSubShapeSelector.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -108,6 +109,29 @@ void PartSet_WidgetSubShapeSelector::mouseMoved(ModuleBase_IViewWindow* theWindo } } +//******************************************************************** +bool PartSet_WidgetSubShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs) +{ + bool aResult = ModuleBase_WidgetSelector::setSelectionCustom(thePrs); + + //if (aResult) + //GeomShapePtr aBaseShape = *anIt; + // myCurrentSubShape->setShape(aBaseShape); + + FeaturePtr aFeature = feature(); + AttributePoint2DPtr anAPointAttr = std::dynamic_pointer_cast( + aFeature->attribute(SketchPlugin_Constraint::ENTITY_A())); + AttributePoint2DPtr aBPointAttr = std::dynamic_pointer_cast( + aFeature->attribute(SketchPlugin_Constraint::ENTITY_B())); + + + //GeomDataAPI_Point2D anAPointAttr = aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()) + //data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), GeomDataAPI_Point2D::typeId()); + //data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), GeomDataAPI_Point2D::typeId()); + + return aResult; +} + //******************************************************************** void PartSet_WidgetSubShapeSelector::getHighlighted( QList>& theValues) diff --git a/src/PartSet/PartSet_WidgetSubShapeSelector.h b/src/PartSet/PartSet_WidgetSubShapeSelector.h index feee61b01..86ac40a9d 100644 --- a/src/PartSet/PartSet_WidgetSubShapeSelector.h +++ b/src/PartSet/PartSet_WidgetSubShapeSelector.h @@ -67,6 +67,10 @@ Q_OBJECT /// \param theValues a list of presentations virtual void getHighlighted(QList>& theValues); + /// Fills the attribute with the value of the selected owner + /// \param thePrs a selected owner + virtual bool setSelectionCustom(const std::shared_ptr& thePrs); + protected: /// Checks the widget validity. By default, it returns true. /// \param thePrs a selected presentation in the view diff --git a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp index 472cf8725..09f8dbcb6 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp @@ -11,7 +11,7 @@ //#include //#include //#include -//#include +#include //#include #include //#include @@ -70,7 +70,9 @@ SketchPlugin_ConstraintSplit::SketchPlugin_ConstraintSplit() void SketchPlugin_ConstraintSplit::initAttributes() { - data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeReference::typeId()); + data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeReference::typeId()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), GeomDataAPI_Point2D::typeId()); //data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId()); //data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttrList::typeId()); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintSplit.h b/src/SketchPlugin/SketchPlugin_ConstraintSplit.h index d084b8083..e08880990 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintSplit.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintSplit.h @@ -16,8 +16,8 @@ * \brief Feature for creation of a new constraint filleting two objects which have coincident point * * This constraint has three attributes: - * SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() for the filleting objects; - * SketchPlugin_Constraint::VALUE() contains radius of filleting circular arc + * SketchPlugin_Constraint::VALUE() contains reference object to be splitted + * SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() for the points of split; * * Also the constraint has attribute SketchPlugin_Constraint::ENTITY_C() * which contains created list objects forming the fillet diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index ec8be9d1f..b8a79e198 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -133,7 +133,7 @@