From: azv Date: Fri, 2 Sep 2016 08:17:29 +0000 (+0300) Subject: Update Split feature and corresponding unit test X-Git-Tag: V_2.5.0~76 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3b741a32c4706a6a78906aa6b12ef85628277037;p=modules%2Fshaper.git Update Split feature and corresponding unit test --- diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index aaf7de3ae..c0d06f3bf 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -140,6 +140,6 @@ ADD_UNIT_TESTS(TestSketchPointLine.py TestFillet.py TestRectangle.py TestProjection.py - #TestSplit.py + TestSplit.py TestHighload.py TestSnowflake.py) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp index 5681155a2..89996005f 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp @@ -6,7 +6,9 @@ #include "SketchPlugin_ConstraintSplit.h" +#include #include +#include #include #include #include @@ -35,11 +37,15 @@ #include #include +#include + #define DEBUG_SPLIT #ifdef DEBUG_SPLIT #include #endif +static const double PI = 3.141592653589793238463; + SketchPlugin_ConstraintSplit::SketchPlugin_ConstraintSplit() { } @@ -639,7 +645,7 @@ void SketchPlugin_ConstraintSplit::splitLine(FeaturePtr& theSplitFeature, return; } - arrangePoints(aStartPointAttrOfBase, anEndPointAttrOfBase, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); + arrangePointsOnLine(aStartPointAttrOfBase, anEndPointAttrOfBase, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); /// create a split feature theSplitFeature = createLineFeature(aBaseFeature, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); @@ -755,7 +761,8 @@ void SketchPlugin_ConstraintSplit::splitArc(FeaturePtr& theSplitFeature, return; } - arrangePoints(aStartPointAttrOfBase, anEndPointAttrOfBase, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); + arrangePointsOnArc(aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase, + aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); /// split feature theSplitFeature = createArcFeature(aBaseFeature, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); @@ -909,12 +916,13 @@ void SketchPlugin_ConstraintSplit::splitCircle(FeaturePtr& theSplitFeature, theCreatedFeatures.insert(aConstraintFeature); } -void SketchPlugin_ConstraintSplit::arrangePoints(const AttributePoint2DPtr& theStartPointAttr, - const AttributePoint2DPtr& theEndPointAttr, - AttributePoint2DPtr& theFirstPointAttr, - AttributePoint2DPtr& theLastPointAttr) +void SketchPlugin_ConstraintSplit::arrangePointsOnLine( + const AttributePoint2DPtr& theStartPointAttr, + const AttributePoint2DPtr& theEndPointAttr, + AttributePoint2DPtr& theFirstPointAttr, + AttributePoint2DPtr& theLastPointAttr) const { - /// if first point is closer to last point, wrap first and last values + // if first point is closer to last point, swap first and last values if (theStartPointAttr->pnt()->distance(theFirstPointAttr->pnt()) > theStartPointAttr->pnt()->distance(theLastPointAttr->pnt())) { AttributePoint2DPtr aTmpPoint = theFirstPointAttr; @@ -923,6 +931,41 @@ void SketchPlugin_ConstraintSplit::arrangePoints(const AttributePoint2DPtr& theS } } +void SketchPlugin_ConstraintSplit::arrangePointsOnArc( + const FeaturePtr& theArc, + const std::shared_ptr& theStartPointAttr, + const std::shared_ptr& theEndPointAttr, + std::shared_ptr& theFirstPointAttr, + std::shared_ptr& theSecondPointAttr) const +{ + std::shared_ptr aCenter = std::dynamic_pointer_cast( + theArc->attribute(SketchPlugin_Arc::CENTER_ID()))->pnt(); + bool isReversed = theArc->boolean(SketchPlugin_Arc::INVERSED_ID())->value(); + + // collect directions to each point + std::shared_ptr aStartDir( + new GeomAPI_Dir2d(theStartPointAttr->pnt()->xy()->decreased(aCenter->xy()))); + std::shared_ptr aFirstPtDir( + new GeomAPI_Dir2d(theFirstPointAttr->pnt()->xy()->decreased(aCenter->xy()))); + std::shared_ptr aSecondPtDir( + new GeomAPI_Dir2d(theSecondPointAttr->pnt()->xy()->decreased(aCenter->xy()))); + + // sort points by their angular values + double aFirstPtAngle = aStartDir->angle(aFirstPtDir); + double aSecondPtAngle = aStartDir->angle(aSecondPtDir); + double aPeriod = isReversed ? -2.0 * PI : 2.0 * PI; + if (isReversed == (aFirstPtAngle > 0.)) + aFirstPtAngle += aPeriod; + if (isReversed == (aSecondPtAngle > 0.)) + aSecondPtAngle += aPeriod; + + if (fabs(aFirstPtAngle) > fabs(aSecondPtAngle)) { + AttributePoint2DPtr aTmpPoint = theFirstPointAttr; + theFirstPointAttr = theSecondPointAttr; + theSecondPointAttr = aTmpPoint; + } +} + void SketchPlugin_ConstraintSplit::fillAttribute(const AttributePtr& theModifiedAttribute, const AttributePtr& theSourceAttribute) { diff --git a/src/SketchPlugin/SketchPlugin_ConstraintSplit.h b/src/SketchPlugin/SketchPlugin_ConstraintSplit.h index 6555d79c0..f8f90dcb7 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintSplit.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintSplit.h @@ -183,10 +183,24 @@ private: /// \param theEndPointAttr an end point of a segment /// \param theFirstPointAttr a start point of a segment /// \param theSecondPointAttr an end point of a segment - void arrangePoints(const std::shared_ptr& theStartPointAttr, - const std::shared_ptr& theEndPointAttr, - std::shared_ptr& theFirstPointAttr, - std::shared_ptr& theSecondPointAttr); + void arrangePointsOnLine(const std::shared_ptr& theStartPointAttr, + const std::shared_ptr& theEndPointAttr, + std::shared_ptr& theFirstPointAttr, + std::shared_ptr& theSecondPointAttr) const; + + /// Correct the first and the second point to provide condition that the first is closer to + /// the start point and the second point - to the last end of current segment. To rearrange + /// them if this condition is not satisfied. + /// \param theArc an arc to be split + /// \param theStartPointAttr a start point of a segment + /// \param theEndPointAttr an end point of a segment + /// \param theFirstPointAttr a start point of a segment + /// \param theSecondPointAttr an end point of a segment + void arrangePointsOnArc(const FeaturePtr& theArc, + const std::shared_ptr& theStartPointAttr, + const std::shared_ptr& theEndPointAttr, + std::shared_ptr& theFirstPointAttr, + std::shared_ptr& theSecondPointAttr) const; /// Fill attribute by value of another attribute. It processes only Point 2D attributes. /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified diff --git a/src/SketchPlugin/Test/TestSplit.py b/src/SketchPlugin/Test/TestSplit.py index 6cc31d3a0..5215e628e 100644 --- a/src/SketchPlugin/Test/TestSplit.py +++ b/src/SketchPlugin/Test/TestSplit.py @@ -59,8 +59,8 @@ Sketch_3 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) SketchCircle_3_1 = Sketch_3.addCircle(50, 50, 50) SketchPoint_3_1 = Sketch_3.addPoint(50, 0) SketchPoint_3_2 = Sketch_3.addPoint(50, 100) -SketchConstraintCoincidence_3_1 = Sketch_3.setCoincident(SketchPoint_3_1.coordinates(), SketchCircle_3_1.result()[0]) -SketchConstraintCoincidence_3_2 = Sketch_3.setCoincident(SketchPoint_3_2.coordinates(), SketchCircle_3_1.result()[0]) +SketchConstraintCoincidence_3_1 = Sketch_3.setCoincident(SketchPoint_3_1.coordinates(), SketchCircle_3_1.result()[1]) +SketchConstraintCoincidence_3_2 = Sketch_3.setCoincident(SketchPoint_3_2.coordinates(), SketchCircle_3_1.result()[1]) Sketch_3.addSplit(SketchCircle_3_1, SketchPoint_3_1.coordinates(), SketchPoint_3_2.coordinates()) model.do() @@ -77,12 +77,12 @@ assert(idList.count(SketchConstraintTangentId) == 1) # Test split on arc with one point Sketch_4 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) -SketchArc_4_1 = Sketch_4.addArc(50, 50, 0, 50, 100, 50, True) +SketchArc_4_1 = Sketch_4.addArc(50, 50, 50, 0, 0, 50, False) Sketch_4.setFixed(SketchArc_4_1.startPoint()) Sketch_4.setFixed(SketchArc_4_1.endPoint()) Sketch_4.setRadius(SketchArc_4_1, 50) SketchPoint_4_1 = Sketch_4.addPoint(50, 100) -SketchConstraintCoincidence_4_1 = Sketch_4.setCoincident(SketchPoint_4_1.coordinates(), SketchArc_4_1.result()[0]) +SketchConstraintCoincidence_4_1 = Sketch_4.setCoincident(SketchPoint_4_1.coordinates(), SketchArc_4_1.result()[1]) Sketch_4.addSplit(SketchArc_4_1, SketchPoint_4_1.coordinates(), SketchArc_4_1.endPoint()) model.do() @@ -100,15 +100,17 @@ assert(idList.count(SketchConstraintTangentId) == 1) # Test split on arc with two points Sketch_5 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) -SketchArc_5_1 = Sketch_5.addArc(50, 50, 0, 50, 100, 50, True) +#SketchArc_5_1 = Sketch_5.addArc(50, 50, 6.69872981078, 75, 93.30127018922, 75, True) +SketchArc_5_1 = Sketch_5.addArc(50, 50, 0, 50, 93.30127018922, 75, True) Sketch_5.setFixed(SketchArc_5_1.startPoint()) Sketch_5.setFixed(SketchArc_5_1.endPoint()) Sketch_5.setRadius(SketchArc_5_1, 50) -SketchPoint_5_1 = Sketch_5.addPoint(25, 93.301270189222) -SketchPoint_5_2 = Sketch_5.addPoint(75, 93.301270189222) -SketchConstraintCoincidence_5_1 = Sketch_5.setCoincident(SketchPoint_5_1.coordinates(), SketchArc_5_1.result()[0]) -SketchConstraintCoincidence_5_1 = Sketch_5.setCoincident(SketchPoint_5_2.coordinates(), SketchArc_5_1.result()[0]) -Sketch_5.addSplit(SketchArc_5_1, SketchPoint_5_1.coordinates(), SketchPoint_5_2.coordinates()) +SketchLine_5_1 = Sketch_5.addLine(25, 93.301270189222, 75, 93.301270189222) +SketchConstraintCoincidence_5_1 = Sketch_5.setCoincident(SketchLine_5_1.startPoint(), SketchArc_5_1.result()[1]) +SketchConstraintCoincidence_5_2 = Sketch_5.setCoincident(SketchLine_5_1.endPoint(), SketchArc_5_1.result()[1]) +SketchConstraintHorizontal_5_1 = Sketch_5.setHorizontal(SketchLine_5_1.result()[0]) +SketchConstraintLength_5_1 = Sketch_5.setLength(SketchLine_5_1.result()[0], 50) +Sketch_5.addSplit(SketchArc_5_1, SketchLine_5_1.startPoint(), SketchLine_5_1.endPoint()) model.do() Sketch_5_feature = featureToCompositeFeature(Sketch_5.feature()) @@ -117,7 +119,7 @@ for index in range(Sketch_5_feature.numberOfSubs()): idList.append(Sketch_5_feature.subFeature(index).getKind()) assert(idList.count(SketchArcId) == 3) -assert(idList.count(SketchPointId) == 2) +assert(idList.count(SketchPointId) == 0) assert(idList.count(SketchConstraintCoincidenceId) == 4) assert(idList.count(SketchConstraintEqualId) == 2) assert(idList.count(SketchConstraintTangentId) == 2)