From: nds Date: Wed, 27 Jul 2016 04:50:02 +0000 (+0300) Subject: Issue #1664: In the Sketcher, add the function Split a segment. Split feature impleme... X-Git-Tag: V_2.5.0~170 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6150d0ba5b4a72ac10f033bbe88ca737bec419bc;p=modules%2Fshaper.git Issue #1664: In the Sketcher, add the function Split a segment. Split feature implementation to process attributes --- diff --git a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp index af88d14d0..779ceca46 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp @@ -9,13 +9,18 @@ //#include //#include //#include -//#include +#include //#include #include //#include #include +#include //#include #include + +#include +#include + //#include //#include //#include @@ -80,16 +85,46 @@ void SketchPlugin_ConstraintSplit::initAttributes() void SketchPlugin_ConstraintSplit::execute() { -/* std::shared_ptr aData = data(); + std::shared_ptr aData = data(); // Check the base objects are initialized. - AttributeRefAttrListPtr aPointsRefList = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Constraint::ENTITY_A())); - if(!aPointsRefList->isInitialized()) { - setError("Error: List of points is not initialized."); + AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast( + aData->attribute(SketchPlugin_Constraint::ENTITY_A())); + if(!aBaseObjectAttr->isInitialized()) { + setError("Error: Base object is not initialized."); + return; + } + AttributePoint2DPtr aFirstPointAttr = getPointOfRefAttr(aData->attribute(SketchPlugin_Constraint::ENTITY_A())); + AttributePoint2DPtr aLastPointAttr = getPointOfRefAttr(aData->attribute(SketchPlugin_Constraint::ENTITY_B())); + if (!aFirstPointAttr.get() || !aFirstPointAttr->isInitialized() || + !aLastPointAttr.get() || !aLastPointAttr->isInitialized()) { + setError("Error: Sub-shape is not initialized."); return; } + AttributePoint2DPtr aStartPointAttr = getFeaturePoint(true); + AttributePoint2DPtr anEndPointAttr = getFeaturePoint(false); + if (!aStartPointAttr.get() && !anEndPointAttr.get()) { + setError("Error: Circle is not processed."); /// TODO + return; + } + + /// if first point is closer to last point, wrap first and last values + if (aStartPointAttr->pnt()->distance(aFirstPointAttr->pnt()) > + anEndPointAttr->pnt()->distance(aLastPointAttr->pnt())) { + AttributePoint2DPtr aTmpPoint = aFirstPointAttr; + aFirstPointAttr = aLastPointAttr; + aLastPointAttr = aTmpPoint; + } + FeaturePtr aSplitFeature = createFeature(aFirstPointAttr, aLastPointAttr); + + std::set aLeftFeatures; + if (!aStartPointAttr->pnt()->isEqual(aFirstPointAttr->pnt())) + aLeftFeatures.insert(createFeature(aStartPointAttr, aFirstPointAttr)); + if (!aLastPointAttr->pnt()->isEqual(anEndPointAttr->pnt())) + aLeftFeatures.insert(createFeature(aLastPointAttr, anEndPointAttr)); + + /* // Get fillet radius. double aFilletRadius = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_Constraint::VALUE()))->value(); @@ -1087,3 +1122,79 @@ std::set getCoincides(const FeaturePtr& theConstraintCoincidence) return aCoincides; } */ + +std::shared_ptr SketchPlugin_ConstraintSplit::getPointOfRefAttr( + const AttributePtr& theAttribute) +{ + AttributePoint2DPtr aPointAttribute; + + if (theAttribute->id() == ModelAPI_AttributeRefAttr::typeId()) { + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(theAttribute); + if (aRefAttr.get() && aRefAttr->isInitialized()) { + AttributePtr anAttribute = aRefAttr->attr(); + if (anAttribute.get() && anAttribute->id() == GeomDataAPI_Point2D::typeId()) + aPointAttribute = std::dynamic_pointer_cast(anAttribute); + } + } + return aPointAttribute; +} + +AttributePoint2DPtr SketchPlugin_ConstraintSplit::getFeaturePoint(const bool& theStartPoint) +{ + AttributePoint2DPtr aPointAttribute; + + AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Constraint::ENTITY_A())); + FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value()); + + std::string aFeatureKind = aBaseFeature->getKind(); + std::string anAttributeName; + if (aFeatureKind == SketchPlugin_Line::ID()) + anAttributeName = theStartPoint ? SketchPlugin_Line::START_ID() + : SketchPlugin_Line::END_ID(); + else if (aFeatureKind == SketchPlugin_Arc::ID()) { + anAttributeName = theStartPoint ? SketchPlugin_Arc::START_ID() + : SketchPlugin_Arc::END_ID(); + } + if (!anAttributeName.empty()) + aPointAttribute = std::dynamic_pointer_cast( + aBaseFeature->attribute(anAttributeName)); + return aPointAttribute; +} + +FeaturePtr SketchPlugin_ConstraintSplit::createFeature(const AttributePoint2DPtr& theStartPointAttr, + const AttributePoint2DPtr& theEndPointAttr) +{ + FeaturePtr aFeature; + + AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Constraint::ENTITY_A())); + FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value()); + + std::string aFeatureKind = aBaseFeature->getKind(); + aFeature = sketch()->addFeature(aFeatureKind); + + if (aFeatureKind == SketchPlugin_Line::ID()) { + AttributePoint2DPtr aStartAttribute = std::dynamic_pointer_cast( + aFeature->attribute(SketchPlugin_Line::START_ID())); + aStartAttribute->setValue(theStartPointAttr->pnt()); + + AttributePoint2DPtr anEndAttribute = std::dynamic_pointer_cast( + aFeature->attribute(SketchPlugin_Line::END_ID())); + anEndAttribute->setValue(theEndPointAttr->pnt()); + } + else if (aFeatureKind == SketchPlugin_Arc::ID()) { + AttributeStringPtr anArcType = std::dynamic_pointer_cast( + data()->addAttribute(SketchPlugin_Arc::ARC_TYPE(), ModelAPI_AttributeString::typeId())); + + AttributePoint2DPtr aPointAttribute = std::dynamic_pointer_cast( + aFeature->attribute(SketchPlugin_Arc::START_ID())); + aPointAttribute->setValue(theStartPointAttr->pnt()); + + AttributePoint2DPtr anEndAttribute = std::dynamic_pointer_cast( + aFeature->attribute(SketchPlugin_Arc::END_ID())); + anEndAttribute->setValue(theEndPointAttr->pnt()); + } + + return aFeature; +} diff --git a/src/SketchPlugin/SketchPlugin_ConstraintSplit.h b/src/SketchPlugin/SketchPlugin_ConstraintSplit.h index e08880990..02c7df346 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintSplit.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintSplit.h @@ -11,6 +11,8 @@ #include #include "SketchPlugin_ConstraintBase.h" +class GeomDataAPI_Point2D; + /** \class SketchPlugin_ConstraintSplit * \ingroup Plugins * \brief Feature for creation of a new constraint filleting two objects which have coincident point @@ -70,8 +72,22 @@ class SketchPlugin_ConstraintSplit : public SketchPlugin_ConstraintBase //}; private: - /// \ Removes all produced features and restore base edges. - //void clearResults(); + /// Returns geom point attribute of the feature + /// \param theStartPoint + /// \return geometical point + std::shared_ptr getFeaturePoint(const bool& theStartPoint); + + /// Returns cast of attribute to geometrical point if the attribute is a ref attr attribute + /// \param theAttribute an attribute + /// \param geom point 2D or NULL + std::shared_ptr getPointOfRefAttr(const AttributePtr& theAttribute); + + /// Creates a new feature in the base shape type with bounding points given in parameters + /// \param theStartPointAttr an attribute of the start point + /// \param theEndPointAttr an attribute of the end point + FeaturePtr SketchPlugin_ConstraintSplit::createFeature( + const std::shared_ptr& theStartPointAttr, + const std::shared_ptr& theEndPointAttr); private: //std::set myNewPoints; ///< set of new points