]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Update Split feature and corresponding unit test
authorazv <azv@opencascade.com>
Fri, 2 Sep 2016 08:17:29 +0000 (11:17 +0300)
committerazv <azv@opencascade.com>
Fri, 2 Sep 2016 08:18:35 +0000 (11:18 +0300)
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp
src/SketchPlugin/SketchPlugin_ConstraintSplit.h
src/SketchPlugin/Test/TestSplit.py

index aaf7de3ae999a64a94579464153954a61979d82c..c0d06f3bfea910ff9dd9c922bf27c5ebae959d9d 100644 (file)
@@ -140,6 +140,6 @@ ADD_UNIT_TESTS(TestSketchPointLine.py
                TestFillet.py
                TestRectangle.py
                TestProjection.py
-               #TestSplit.py
+               TestSplit.py
                TestHighload.py
                TestSnowflake.py)
index 5681155a21c47db42b3cc66923719c0e5a5e3d9e..89996005f42f72742a732918f27b57f55fa283e0 100755 (executable)
@@ -6,7 +6,9 @@
 
 #include "SketchPlugin_ConstraintSplit.h"
 
+#include <GeomAPI_Dir2d.h>
 #include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_XY.h>
 #include <GeomDataAPI_Point2D.h>
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelGeomAlgo_Point2D.h>
 #include <Events_Loop.h>
 
+#include <cmath>
+
 #define DEBUG_SPLIT
 #ifdef DEBUG_SPLIT
 #include <iostream>
 #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<GeomDataAPI_Point2D>& theStartPointAttr,
+    const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
+    std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
+    std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr) const
+{
+  std::shared_ptr<GeomAPI_Pnt2d> aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      theArc->attribute(SketchPlugin_Arc::CENTER_ID()))->pnt();
+  bool isReversed = theArc->boolean(SketchPlugin_Arc::INVERSED_ID())->value();
+
+  // collect directions to each point
+  std::shared_ptr<GeomAPI_Dir2d> aStartDir(
+      new GeomAPI_Dir2d(theStartPointAttr->pnt()->xy()->decreased(aCenter->xy())));
+  std::shared_ptr<GeomAPI_Dir2d> aFirstPtDir(
+      new GeomAPI_Dir2d(theFirstPointAttr->pnt()->xy()->decreased(aCenter->xy())));
+  std::shared_ptr<GeomAPI_Dir2d> 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)
 {
index 6555d79c0384c3c0a23b2936b5ce4d6a928fda55..f8f90dcb7e3eb962ef16d44b15bcb3cbd586622d 100755 (executable)
@@ -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<GeomDataAPI_Point2D>& theStartPointAttr,
-                     const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
-                     std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
-                     std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr);
+  void arrangePointsOnLine(const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
+                           const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
+                           std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
+                           std::shared_ptr<GeomDataAPI_Point2D>& 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<GeomDataAPI_Point2D>& theStartPointAttr,
+                          const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
+                          std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
+                          std::shared_ptr<GeomDataAPI_Point2D>& 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
index 6cc31d3a0583a1d0d4b4f7d19b3477ded90918b4..5215e628e85eece36985a85d57255880807423a1 100644 (file)
@@ -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)