From: nds Date: Mon, 27 Mar 2017 14:48:18 +0000 (+0300) Subject: Issue #2027: Sketcher Trim Feature unit tests for Circle/Arc X-Git-Tag: V_2.7.0~174 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3a1a1bd9b311b0a2945942519554fefaa8ccbc9b;p=modules%2Fshaper.git Issue #2027: Sketcher Trim Feature unit tests for Circle/Arc --- diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index 77adc1a81..8058fa585 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -760,6 +760,22 @@ std::shared_ptr SketchAPI_Sketch::setVertical( //-------------------------------------------------------------------------------------- +std::shared_ptr SketchAPI_Sketch::to2D(const std::shared_ptr& thePoint) +{ + FeaturePtr aBase = feature(); + std::shared_ptr aC = std::dynamic_pointer_cast( + aBase->attribute(SketchPlugin_Sketch::ORIGIN_ID())); + std::shared_ptr aNorm = std::dynamic_pointer_cast( + aBase->attribute(SketchPlugin_Sketch::NORM_ID())); + std::shared_ptr aX = std::dynamic_pointer_cast( + aBase->attribute(SketchPlugin_Sketch::DIRX_ID())); + std::shared_ptr aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir()))); + + return thePoint->to2D(aC->pnt(), aX->dir(), aY); +} + +//-------------------------------------------------------------------------------------- + void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const { FeaturePtr aBase = feature(); diff --git a/src/SketchAPI/SketchAPI_Sketch.h b/src/SketchAPI/SketchAPI_Sketch.h index 843630f5b..15450976f 100644 --- a/src/SketchAPI/SketchAPI_Sketch.h +++ b/src/SketchAPI/SketchAPI_Sketch.h @@ -395,6 +395,9 @@ public: const std::shared_ptr & theConstraint, const ModelHighAPI_Double & theValue); + SKETCHAPI_EXPORT + std::shared_ptr to2D(const std::shared_ptr& thePoint); + // TODO(spo): rename to selectFaces() or faces() (or add faces() -> list to SWIG) /// Select face SKETCHAPI_EXPORT diff --git a/src/SketchPlugin/Test/TestTrimArc01.py b/src/SketchPlugin/Test/TestTrimArc01.py new file mode 100644 index 000000000..c7a2e29ca --- /dev/null +++ b/src/SketchPlugin/Test/TestTrimArc01.py @@ -0,0 +1,96 @@ +from salome.shaper import model + +from ModelAPI import * +from GeomDataAPI import * +from ModelGeomAlgo import ModelGeomAlgo_Point2D +from salome.shaper import geom +import math + +TOLERANCE = 1.e-7 + +SketchLineId = 'SketchLine' +SketchArcId = 'SketchArc' +SketchConstraintCoincidenceId = 'SketchConstraintCoincidence' +SketchConstraintEqualId = 'SketchConstraintEqual' + +aSession = ModelAPI_Session.get() +model.begin() +partSet = model.moduleDocument() +Part = model.addPart(partSet) +Part_doc = Part.document() + +# Test1:begin split on arc with coincident point and intersection line : smaller part +Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY")) +SketchArc = Sketch.addArc(50, 50, 30, 50, 50, 70, False) +SketchLine = Sketch.addLine(32, 20, 82, 70) +SketchLine_intersecting = Sketch.addLine(10, 40, 90, 40) +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 3) + +Arc_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc.feature(), FeatureList([SketchLine_intersecting.feature()])) +assert(len(Arc_Points) == 2) + +ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()])) + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 2) + +assert (len(Arc_Points) == 2) +if Arc_Points[0].x() < Arc_Points[1].x(): + GeomPoint = Arc_Points[0] +else: + GeomPoint = Arc_Points[1] + +#check number of features before trim +Sketch_feature = featureToCompositeFeature(Sketch.feature()) +idList_before = [] +for index in range(Sketch_feature.numberOfSubs()): + idList_before.append(Sketch_feature.subFeature(index).getKind()) + +assert(idList_before.count(SketchArcId) == 1) +assert(idList_before.count(SketchLineId) == 1) +assert(idList_before.count(SketchConstraintCoincidenceId) == 0) + +#perform trim +SketchTrim = Sketch.addTrim(SketchArc, Sketch.to2D(GeomPoint)) +SketchTrim.execute() +model.do() + +#check number of features after trim +SketchFeatures = featureToCompositeFeature(Sketch.feature()) +idList_after = [] +for SubIndex in range(SketchFeatures.numberOfSubs()): + SubFeature = SketchFeatures.subFeature(SubIndex) + idList_after.append(SubFeature.getKind()) + if SubFeature.getKind() == SketchArcId: + SketchArc = SubFeature + +assert(idList_after.count(SketchArcId) == 1) +assert(idList_after.count(SketchLineId) == 1) +assert(idList_after.count(SketchConstraintCoincidenceId) == 1) + + +#check arc position intersections of created arc to an additional line +SketchLine_intersecting_1 = Sketch.addLine(50, 50, 25, 25) +SketchLine_intersecting_2 = Sketch.addLine(50, 50, 75, 25) +SketchLine_intersecting_3 = Sketch.addLine(50, 50, 75, 75) +SketchLine_intersecting_4 = Sketch.addLine(50, 50, 25, 75) + +Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_1.feature()])) +Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_2.feature()])) +Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_3.feature()])) +Intersection_Points_4 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_4.feature()])) + +assert(len(Intersection_Points_1) == 0) +assert(len(Intersection_Points_2) == 1) +assert(len(Intersection_Points_3) == 1) +assert(len(Intersection_Points_4) == 0) + +#add point for check +SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y()) +Intersection_Points_5 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchPoint.feature()])) +assert(len(Intersection_Points_5) == 0) + +model.end() + +#assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestTrimArc02.py b/src/SketchPlugin/Test/TestTrimArc02.py new file mode 100644 index 000000000..4b1cbf4b6 --- /dev/null +++ b/src/SketchPlugin/Test/TestTrimArc02.py @@ -0,0 +1,101 @@ +from salome.shaper import model + +from ModelAPI import * +from GeomDataAPI import * +from ModelGeomAlgo import ModelGeomAlgo_Point2D +from salome.shaper import geom +import math + +TOLERANCE = 1.e-7 + +SketchLineId = 'SketchLine' +SketchArcId = 'SketchArc' +SketchConstraintCoincidenceId = 'SketchConstraintCoincidence' +SketchConstraintEqualId = 'SketchConstraintEqual' + +aSession = ModelAPI_Session.get() +model.begin() +partSet = model.moduleDocument() +Part = model.addPart(partSet) +Part_doc = Part.document() + +# Test1:begin split on arc with coincident point and intersection line : smaller part +Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY")) +SketchArc = Sketch.addArc(50, 50, 30, 50, 50, 70, False) +SketchLine = Sketch.addLine(32, 20, 82, 70) +SketchLine_intersecting = Sketch.addLine(10, 40, 90, 40) +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 3) + +Arc_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc.feature(), FeatureList([SketchLine_intersecting.feature()])) +assert(len(Arc_Points) == 2) + +ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()])) + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 2) + +assert (len(Arc_Points) == 2) +if Arc_Points[0].x() < Arc_Points[1].x(): + GeomPoint = Arc_Points[1] +else: + GeomPoint = Arc_Points[0] + +#check number of features before trim +Sketch_feature = featureToCompositeFeature(Sketch.feature()) +idList_before = [] +for index in range(Sketch_feature.numberOfSubs()): + idList_before.append(Sketch_feature.subFeature(index).getKind()) + +assert(idList_before.count(SketchArcId) == 1) +assert(idList_before.count(SketchLineId) == 1) +assert(idList_before.count(SketchConstraintCoincidenceId) == 0) + +#perform trim +SketchTrim = Sketch.addTrim(SketchArc, Sketch.to2D(GeomPoint)) +SketchTrim.execute() +model.do() + +#check number of features after trim +SketchFeatures = featureToCompositeFeature(Sketch.feature()) +idList_after = [] +anArcList = FeatureList() +for SubIndex in range(SketchFeatures.numberOfSubs()): + SubFeature = SketchFeatures.subFeature(SubIndex) + idList_after.append(SubFeature.getKind()) + if SubFeature.getKind() == SketchArcId: + SketchArc = SubFeature + anArcList.append(SubFeature) + +assert(len(anArcList) == 2) +assert(idList_after.count(SketchArcId) == 2) +assert(idList_after.count(SketchLineId) == 1) +assert(idList_after.count(SketchConstraintCoincidenceId) == 3) +assert(idList_after.count(SketchConstraintEqualId) == 1) + + +#check arc position intersections of created arc to an additional line +SketchLine_intersecting_1 = Sketch.addLine(50, 50, 25, 25) +SketchLine_intersecting_2 = Sketch.addLine(50, 50, 75, 25) +SketchLine_intersecting_3 = Sketch.addLine(50, 50, 75, 75) +SketchLine_intersecting_4 = Sketch.addLine(50, 50, 25, 75) + +Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_1.feature(), anArcList) +Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_2.feature(), anArcList) +Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_3.feature(), anArcList) +Intersection_Points_4 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_4.feature(), anArcList) + +assert(len(Intersection_Points_1) == 1) +assert(len(Intersection_Points_2) == 0) +assert(len(Intersection_Points_3) == 1) +assert(len(Intersection_Points_4) == 0) + +#add point for check +SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y()) +SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y()) +Intersection_Points_5 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchPoint.feature(), anArcList) +assert(len(Intersection_Points_5) == 0) + +model.end() + +#assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestTrimArc03.py b/src/SketchPlugin/Test/TestTrimArc03.py new file mode 100644 index 000000000..55c17601b --- /dev/null +++ b/src/SketchPlugin/Test/TestTrimArc03.py @@ -0,0 +1,105 @@ +from salome.shaper import model + +from ModelAPI import * +from GeomDataAPI import * +from ModelGeomAlgo import ModelGeomAlgo_Point2D +from salome.shaper import geom +import math + +TOLERANCE = 1.e-7 + +SketchLineId = 'SketchLine' +SketchArcId = 'SketchArc' +SketchConstraintCoincidenceId = 'SketchConstraintCoincidence' +SketchConstraintEqualId = 'SketchConstraintEqual' + +aSession = ModelAPI_Session.get() +model.begin() +partSet = model.moduleDocument() +Part = model.addPart(partSet) +Part_doc = Part.document() + +# Test1:begin split on arc with coincident point and intersection line : smaller part +Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY")) +SketchArc = Sketch.addArc(50, 50, 30, 50, 50, 70, False) +SketchLine_1 = Sketch.addLine(50, 20, 100, 20) +SketchLine_2 = Sketch.addLine(100, 20, 70, 50) +SketchLine_intersecting = Sketch.addLine(10, 40, 90, 40) + +SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_1.startPoint(), SketchArc.results()[1]) +SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchLine_2.endPoint(), SketchArc.results()[1]) +SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 7) + +Arc_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc.feature(), FeatureList([SketchLine_intersecting.feature()])) +assert(len(Arc_Points) == 2) + +ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()])) + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 6) + +assert (len(Arc_Points) == 2) +if Arc_Points[0].x() < Arc_Points[1].x(): + GeomPoint = Arc_Points[0] +else: + GeomPoint = Arc_Points[1] + +#check number of features before trim +Sketch_feature = featureToCompositeFeature(Sketch.feature()) +idList_before = [] +for index in range(Sketch_feature.numberOfSubs()): + idList_before.append(Sketch_feature.subFeature(index).getKind()) + +assert(idList_before.count(SketchArcId) == 1) +assert(idList_before.count(SketchLineId) == 2) +assert(idList_before.count(SketchConstraintCoincidenceId) == 3) + +#perform trim +SketchTrim = Sketch.addTrim(SketchArc, Sketch.to2D(GeomPoint)) +SketchTrim.execute() +model.do() + +#check number of features after trim +SketchFeatures = featureToCompositeFeature(Sketch.feature()) +idList_after = [] +anArcList = FeatureList() +for SubIndex in range(SketchFeatures.numberOfSubs()): + SubFeature = SketchFeatures.subFeature(SubIndex) + idList_after.append(SubFeature.getKind()) + if SubFeature.getKind() == SketchArcId: + SketchArc = SubFeature + anArcList.append(SubFeature) + +assert(len(anArcList) == 1) +assert(idList_after.count(SketchArcId) == 1) +assert(idList_after.count(SketchLineId) == 2) +assert(idList_after.count(SketchConstraintCoincidenceId) == 3) + +#check arc position intersections of created arc to an additional line +SketchLine_intersecting_1 = Sketch.addLine(50, 50, 25, 25) +SketchLine_intersecting_2 = Sketch.addLine(50, 50, 75, 25) +SketchLine_intersecting_3 = Sketch.addLine(50, 50, 75, 75) +SketchLine_intersecting_4 = Sketch.addLine(50, 50, 25, 75) + +Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_1.feature(), anArcList) +Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_2.feature(), anArcList) +Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_3.feature(), anArcList) +Intersection_Points_4 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_4.feature(), anArcList) + +assert(len(Intersection_Points_1) == 0) +assert(len(Intersection_Points_2) == 1) +assert(len(Intersection_Points_3) == 1) +assert(len(Intersection_Points_4) == 0) + +#add point for check +SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y()) +SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y()) +Intersection_Points_5 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchPoint.feature(), anArcList) +assert(len(Intersection_Points_5) == 0) + +model.end() + +#assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestTrimArc04.py b/src/SketchPlugin/Test/TestTrimArc04.py new file mode 100644 index 000000000..c694ef490 --- /dev/null +++ b/src/SketchPlugin/Test/TestTrimArc04.py @@ -0,0 +1,105 @@ +from salome.shaper import model + +from ModelAPI import * +from GeomDataAPI import * +from ModelGeomAlgo import ModelGeomAlgo_Point2D +from salome.shaper import geom +import math + +TOLERANCE = 1.e-7 + +SketchLineId = 'SketchLine' +SketchArcId = 'SketchArc' +SketchConstraintCoincidenceId = 'SketchConstraintCoincidence' +SketchConstraintEqualId = 'SketchConstraintEqual' + +aSession = ModelAPI_Session.get() +model.begin() +partSet = model.moduleDocument() +Part = model.addPart(partSet) +Part_doc = Part.document() + +# Test1:begin split on arc with coincident point and intersection line : smaller part +Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY")) +SketchArc = Sketch.addArc(50, 50, 30, 50, 50, 70, False) +SketchLine_1 = Sketch.addLine(50, 20, 100, 20) +SketchLine_2 = Sketch.addLine(100, 20, 70, 50) +SketchLine_intersecting = Sketch.addLine(10, 40, 90, 40) + +SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_1.startPoint(), SketchArc.results()[1]) +SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchLine_2.endPoint(), SketchArc.results()[1]) +SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 7) + +Arc_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc.feature(), FeatureList([SketchLine_intersecting.feature()])) +assert(len(Arc_Points) == 2) + +ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()])) + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 6) + +assert (len(Arc_Points) == 2) +if Arc_Points[0].x() < Arc_Points[1].x(): + GeomPoint = Arc_Points[1] +else: + GeomPoint = Arc_Points[0] + +#check number of features before trim +Sketch_feature = featureToCompositeFeature(Sketch.feature()) +idList_before = [] +for index in range(Sketch_feature.numberOfSubs()): + idList_before.append(Sketch_feature.subFeature(index).getKind()) + +assert(idList_before.count(SketchArcId) == 1) +assert(idList_before.count(SketchLineId) == 2) +assert(idList_before.count(SketchConstraintCoincidenceId) == 3) + +#perform trim +SketchTrim = Sketch.addTrim(SketchArc, Sketch.to2D(GeomPoint)) +SketchTrim.execute() +model.do() + +#check number of features after trim +SketchFeatures = featureToCompositeFeature(Sketch.feature()) +idList_after = [] +anArcList = FeatureList() +for SubIndex in range(SketchFeatures.numberOfSubs()): + SubFeature = SketchFeatures.subFeature(SubIndex) + idList_after.append(SubFeature.getKind()) + if SubFeature.getKind() == SketchArcId: + SketchArc = SubFeature + anArcList.append(SubFeature) + +assert(len(anArcList) == 2) +assert(idList_after.count(SketchArcId) == 2) +assert(idList_after.count(SketchLineId) == 2) +assert(idList_after.count(SketchConstraintCoincidenceId) == 4) + +#check arc position intersections of created arc to an additional line +SketchLine_intersecting_1 = Sketch.addLine(50, 50, 25, 25) +SketchLine_intersecting_2 = Sketch.addLine(50, 50, 75, 25) +SketchLine_intersecting_3 = Sketch.addLine(50, 50, 75, 75) +SketchLine_intersecting_4 = Sketch.addLine(50, 50, 25, 75) + +Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_1.feature(), anArcList) +Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_2.feature(), anArcList) +Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_3.feature(), anArcList) +Intersection_Points_4 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_4.feature(), anArcList) + +assert(len(Intersection_Points_1) == 1) +assert(len(Intersection_Points_2) == 0) +assert(len(Intersection_Points_3) == 1) +assert(len(Intersection_Points_4) == 0) + +#add point for check +SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y()) +SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y()) +Intersection_Points_5 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchPoint.feature(), anArcList) +assert(len(Intersection_Points_5) == 0) + +model.end() + +#assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestTrimArc05.py b/src/SketchPlugin/Test/TestTrimArc05.py new file mode 100644 index 000000000..1bf8ae699 --- /dev/null +++ b/src/SketchPlugin/Test/TestTrimArc05.py @@ -0,0 +1,106 @@ +from salome.shaper import model + +from ModelAPI import * +from GeomDataAPI import * +from ModelGeomAlgo import ModelGeomAlgo_Point2D +from salome.shaper import geom +import math + +TOLERANCE = 1.e-7 + +SketchLineId = 'SketchLine' +SketchArcId = 'SketchArc' +SketchConstraintCoincidenceId = 'SketchConstraintCoincidence' +SketchConstraintEqualId = 'SketchConstraintEqual' + +aSession = ModelAPI_Session.get() +model.begin() +partSet = model.moduleDocument() +Part = model.addPart(partSet) +Part_doc = Part.document() + +# Test1:begin split on arc with coincident point and intersection line : smaller part +Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY")) +# Test of inverted Arc +SketchArc = Sketch.addArc(50, 50, 50, 70, 30, 50, True) +SketchLine_1 = Sketch.addLine(50, 20, 100, 20) +SketchLine_2 = Sketch.addLine(100, 20, 70, 50) +SketchLine_intersecting = Sketch.addLine(10, 40, 90, 40) + +SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_1.startPoint(), SketchArc.results()[1]) +SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchLine_2.endPoint(), SketchArc.results()[1]) +SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 7) + +Arc_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc.feature(), FeatureList([SketchLine_intersecting.feature()])) +assert(len(Arc_Points) == 2) + +ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()])) + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 6) + +assert (len(Arc_Points) == 2) +if Arc_Points[0].x() < Arc_Points[1].x(): + GeomPoint = Arc_Points[0] +else: + GeomPoint = Arc_Points[1] + +#check number of features before trim +Sketch_feature = featureToCompositeFeature(Sketch.feature()) +idList_before = [] +for index in range(Sketch_feature.numberOfSubs()): + idList_before.append(Sketch_feature.subFeature(index).getKind()) + +assert(idList_before.count(SketchArcId) == 1) +assert(idList_before.count(SketchLineId) == 2) +assert(idList_before.count(SketchConstraintCoincidenceId) == 3) + +#perform trim +SketchTrim = Sketch.addTrim(SketchArc, Sketch.to2D(GeomPoint)) +SketchTrim.execute() +model.do() + +#check number of features after trim +SketchFeatures = featureToCompositeFeature(Sketch.feature()) +idList_after = [] +anArcList = FeatureList() +for SubIndex in range(SketchFeatures.numberOfSubs()): + SubFeature = SketchFeatures.subFeature(SubIndex) + idList_after.append(SubFeature.getKind()) + if SubFeature.getKind() == SketchArcId: + SketchArc = SubFeature + anArcList.append(SubFeature) + +assert(len(anArcList) == 1) +assert(idList_after.count(SketchArcId) == 1) +assert(idList_after.count(SketchLineId) == 2) +assert(idList_after.count(SketchConstraintCoincidenceId) == 3) + +#check arc position intersections of created arc to an additional line +SketchLine_intersecting_1 = Sketch.addLine(50, 50, 25, 25) +SketchLine_intersecting_2 = Sketch.addLine(50, 50, 75, 25) +SketchLine_intersecting_3 = Sketch.addLine(50, 50, 75, 75) +SketchLine_intersecting_4 = Sketch.addLine(50, 50, 25, 75) + +Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_1.feature(), anArcList) +Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_2.feature(), anArcList) +Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_3.feature(), anArcList) +Intersection_Points_4 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_4.feature(), anArcList) + +assert(len(Intersection_Points_1) == 0) +assert(len(Intersection_Points_2) == 1) +assert(len(Intersection_Points_3) == 1) +assert(len(Intersection_Points_4) == 0) + +#add point for check +SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y()) +SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y()) +Intersection_Points_5 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchPoint.feature(), anArcList) +assert(len(Intersection_Points_5) == 0) + +model.end() + +#assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestTrimArc06.py b/src/SketchPlugin/Test/TestTrimArc06.py new file mode 100644 index 000000000..610946cb3 --- /dev/null +++ b/src/SketchPlugin/Test/TestTrimArc06.py @@ -0,0 +1,105 @@ +from salome.shaper import model + +from ModelAPI import * +from GeomDataAPI import * +from ModelGeomAlgo import ModelGeomAlgo_Point2D +from salome.shaper import geom +import math + +TOLERANCE = 1.e-7 + +SketchLineId = 'SketchLine' +SketchArcId = 'SketchArc' +SketchConstraintCoincidenceId = 'SketchConstraintCoincidence' +SketchConstraintEqualId = 'SketchConstraintEqual' + +aSession = ModelAPI_Session.get() +model.begin() +partSet = model.moduleDocument() +Part = model.addPart(partSet) +Part_doc = Part.document() + +# Test1:begin split on arc with coincident point and intersection line : smaller part +Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY")) +# Test of inverted Arc +SketchArc = Sketch.addArc(50, 50, 50, 70, 30, 50, True) +SketchLine_1 = Sketch.addLine(50, 20, 100, 20) +SketchLine_2 = Sketch.addLine(100, 20, 70, 50) +SketchLine_intersecting = Sketch.addLine(10, 40, 90, 40) + +SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_1.startPoint(), SketchArc.results()[1]) +SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchLine_2.endPoint(), SketchArc.results()[1]) +SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 7) + +Arc_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc.feature(), FeatureList([SketchLine_intersecting.feature()])) +assert(len(Arc_Points) == 2) + +ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()])) + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 6) + +assert (len(Arc_Points) == 2) +if Arc_Points[0].x() < Arc_Points[1].x(): + GeomPoint = Arc_Points[1] +else: + GeomPoint = Arc_Points[0] + +#check number of features before trim +Sketch_feature = featureToCompositeFeature(Sketch.feature()) +idList_before = [] +for index in range(Sketch_feature.numberOfSubs()): + idList_before.append(Sketch_feature.subFeature(index).getKind()) + +assert(idList_before.count(SketchArcId) == 1) +assert(idList_before.count(SketchLineId) == 2) +assert(idList_before.count(SketchConstraintCoincidenceId) == 3) + +#perform trim +SketchTrim = Sketch.addTrim(SketchArc, Sketch.to2D(GeomPoint)) +SketchTrim.execute() +model.do() + +#check number of features after trim +SketchFeatures = featureToCompositeFeature(Sketch.feature()) +idList_after = [] +anArcList = FeatureList() +for SubIndex in range(SketchFeatures.numberOfSubs()): + SubFeature = SketchFeatures.subFeature(SubIndex) + idList_after.append(SubFeature.getKind()) + if SubFeature.getKind() == SketchArcId: + anArcList.append(SubFeature) + +assert(len(anArcList) == 2) +assert(idList_after.count(SketchArcId) == 2) +assert(idList_after.count(SketchLineId) == 2) +assert(idList_after.count(SketchConstraintCoincidenceId) == 4) + +#check arc position intersections of created arc to an additional line +SketchLine_intersecting_1 = Sketch.addLine(50, 50, 25, 25) +SketchLine_intersecting_2 = Sketch.addLine(50, 50, 75, 25) +SketchLine_intersecting_3 = Sketch.addLine(50, 50, 75, 75) +SketchLine_intersecting_4 = Sketch.addLine(50, 50, 25, 75) + +Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_1.feature(), anArcList) +Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_2.feature(), anArcList) +Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_3.feature(), anArcList) +Intersection_Points_4 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_4.feature(), anArcList) + +assert(len(Intersection_Points_1) == 1) +assert(len(Intersection_Points_2) == 0) +assert(len(Intersection_Points_3) == 1) +assert(len(Intersection_Points_4) == 0) + +#add point for check +SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y()) +SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y()) +Intersection_Points_5 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchPoint.feature(), anArcList) +assert(len(Intersection_Points_5) == 0) + +model.end() + +#assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestTrimCircle01.py b/src/SketchPlugin/Test/TestTrimCircle01.py new file mode 100644 index 000000000..f9e270d05 --- /dev/null +++ b/src/SketchPlugin/Test/TestTrimCircle01.py @@ -0,0 +1,93 @@ +from salome.shaper import model + +from ModelAPI import * +from GeomDataAPI import * +from ModelGeomAlgo import ModelGeomAlgo_Point2D +from salome.shaper import geom +import math + +TOLERANCE = 1.e-7 + +SketchLineId = 'SketchLine' +SketchArcId = 'SketchArc' +SketchCircleId = 'SketchCircle' +SketchConstraintCoincidenceId = 'SketchConstraintCoincidence' + +aSession = ModelAPI_Session.get() +model.begin() +partSet = model.moduleDocument() +Part = model.addPart(partSet) +Part_doc = Part.document() + +# Test1:begin split on circle with coincident point and intersection line : smaller part +Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY")) +SketchCircle = Sketch.addCircle(50, 50, 20) +SketchLine = Sketch.addLine(30, 75, 75, 30) +SketchLine_intersecting = Sketch.addLine(10, 55, 90, 55) +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 3) + +Circle_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchCircle.feature(), FeatureList([SketchLine_intersecting.feature()])) +assert(len(Circle_Points) == 2) + +ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()])) + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 2) + +assert (len(Circle_Points) == 2) +if Circle_Points[0].x() < Circle_Points[1].x(): + GeomPoint = Circle_Points[0] +else: + GeomPoint = Circle_Points[1] + + +#check number of features before trim +Sketch_feature = featureToCompositeFeature(Sketch.feature()) +idList_before = [] +for index in range(Sketch_feature.numberOfSubs()): + idList_before.append(Sketch_feature.subFeature(index).getKind()) + +assert(idList_before.count(SketchCircleId) == 1) +assert(idList_before.count(SketchArcId) == 0) +assert(idList_before.count(SketchLineId) == 1) +assert(idList_before.count(SketchConstraintCoincidenceId) == 0) + +#perform trim +SketchTrim = Sketch.addTrim(SketchCircle, Sketch.to2D(GeomPoint)) +SketchTrim.execute() +model.do() + +#check number of features after trim +SketchFeatures = featureToCompositeFeature(Sketch.feature()) +idList_after = [] +for SubIndex in range(SketchFeatures.numberOfSubs()): + SubFeature = SketchFeatures.subFeature(SubIndex) + idList_after.append(SubFeature.getKind()) + if SubFeature.getKind() == SketchArcId: + SketchArc = SubFeature + +assert(idList_after.count(SketchCircleId) == 0) +assert(idList_after.count(SketchArcId) == 1) +assert(idList_after.count(SketchLineId) == 1) +assert(idList_after.count(SketchConstraintCoincidenceId) == 2) + + +#check arc position intersections of created arc to an additional line +SketchLine_intersecting_1 = Sketch.addLine(0, 0, 50, 50) +SketchLine_intersecting_2 = Sketch.addLine(50, 50, 100, 100) + +Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_1.feature()])) +Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_2.feature()])) + +assert(len(Intersection_Points_1) == 0) +assert(len(Intersection_Points_2) == 1) + +#add point for check +SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y()) +Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchPoint.feature()])) +assert(len(Intersection_Points_3) == 0) + +model.end() + +#assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestTrimCircle02.py b/src/SketchPlugin/Test/TestTrimCircle02.py new file mode 100644 index 000000000..e843c55da --- /dev/null +++ b/src/SketchPlugin/Test/TestTrimCircle02.py @@ -0,0 +1,92 @@ +from salome.shaper import model + +from ModelAPI import * +from GeomDataAPI import * +from ModelGeomAlgo import ModelGeomAlgo_Point2D +from salome.shaper import geom +import math + +TOLERANCE = 1.e-7 + +SketchLineId = 'SketchLine' +SketchArcId = 'SketchArc' +SketchCircleId = 'SketchCircle' +SketchConstraintCoincidenceId = 'SketchConstraintCoincidence' + +aSession = ModelAPI_Session.get() +model.begin() +partSet = model.moduleDocument() +Part = model.addPart(partSet) +Part_doc = Part.document() + +# Test1:begin split on circle with coincident point and intersection line : smaller part +Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY")) +SketchCircle = Sketch.addCircle(50, 50, 20) +SketchLine = Sketch.addLine(30, 75, 75, 30) +SketchLine_intersecting = Sketch.addLine(10, 55, 90, 55) +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 3) + +Circle_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchCircle.feature(), FeatureList([SketchLine_intersecting.feature()])) +assert(len(Circle_Points) == 2) + +ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()])) + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 2) + +assert (len(Circle_Points) == 2) +if Circle_Points[0].x() < Circle_Points[1].x(): + GeomPoint = Circle_Points[1] +else: + GeomPoint = Circle_Points[0] + +#check number of features before trim +Sketch_feature = featureToCompositeFeature(Sketch.feature()) +idList_before = [] +for index in range(Sketch_feature.numberOfSubs()): + idList_before.append(Sketch_feature.subFeature(index).getKind()) + +assert(idList_before.count(SketchCircleId) == 1) +assert(idList_before.count(SketchArcId) == 0) +assert(idList_before.count(SketchLineId) == 1) +assert(idList_before.count(SketchConstraintCoincidenceId) == 0) + +#perform trim +SketchTrim = Sketch.addTrim(SketchCircle, Sketch.to2D(GeomPoint)) +SketchTrim.execute() +model.do() + +#check number of features after trim +SketchFeatures = featureToCompositeFeature(Sketch.feature()) +idList_after = [] +for SubIndex in range(SketchFeatures.numberOfSubs()): + SubFeature = SketchFeatures.subFeature(SubIndex) + idList_after.append(SubFeature.getKind()) + if SubFeature.getKind() == SketchArcId: + SketchArc = SubFeature + +assert(idList_after.count(SketchCircleId) == 0) +assert(idList_after.count(SketchArcId) == 1) +assert(idList_after.count(SketchLineId) == 1) +assert(idList_after.count(SketchConstraintCoincidenceId) == 2) + + +#check arc position intersections of created arc to an additional line +SketchLine_intersecting_1 = Sketch.addLine(0, 0, 50, 50) +SketchLine_intersecting_2 = Sketch.addLine(50, 50, 100, 100) + +Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_1.feature()])) +Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_2.feature()])) + +assert(len(Intersection_Points_1) == 1) +assert(len(Intersection_Points_2) == 0) + +#add point for check +SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y()) +Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchPoint.feature()])) +assert(len(Intersection_Points_3) == 0) + +model.end() + +#assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestTrimCircle03.py b/src/SketchPlugin/Test/TestTrimCircle03.py new file mode 100644 index 000000000..e95823b03 --- /dev/null +++ b/src/SketchPlugin/Test/TestTrimCircle03.py @@ -0,0 +1,97 @@ +from salome.shaper import model + +from ModelAPI import * +from GeomDataAPI import * +from ModelGeomAlgo import ModelGeomAlgo_Point2D +from salome.shaper import geom +import math + +TOLERANCE = 1.e-7 + +SketchLineId = 'SketchLine' +SketchArcId = 'SketchArc' +SketchCircleId = 'SketchCircle' +SketchConstraintCoincidenceId = 'SketchConstraintCoincidence' + +aSession = ModelAPI_Session.get() +model.begin() +partSet = model.moduleDocument() +Part = model.addPart(partSet) +Part_doc = Part.document() + +# Test1:begin split on circle with coincident point and intersection line : smaller part +Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY")) +SketchCircle = Sketch.addCircle(50, 50, 20) +SketchLine_1 = Sketch.addLine(70, 50, 80, 80) +SketchLine_2 = Sketch.addLine(80, 80, 50, 70) + +SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_1.startPoint(), SketchCircle.results()[1]) +SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchLine_2.endPoint(), SketchCircle.results()[1]) + + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 6) +#intersection points on circle to prepare a trim selection point +SketchLine_intersecting = Sketch.addLine(10, 60, 90, 60) +Circle_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchCircle.feature(), FeatureList([SketchLine_intersecting.feature()])) +assert(len(Circle_Points) == 2) +ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()])) +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 6) + +assert (len(Circle_Points) == 2) +if Circle_Points[0].x() < Circle_Points[1].x(): + GeomPoint = Circle_Points[0] +else: + GeomPoint = Circle_Points[1] + +#check number of features before trim +Sketch_feature = featureToCompositeFeature(Sketch.feature()) +idList_before = [] +for index in range(Sketch_feature.numberOfSubs()): + idList_before.append(Sketch_feature.subFeature(index).getKind()) + +assert(idList_before.count(SketchCircleId) == 1) +assert(idList_before.count(SketchArcId) == 0) +assert(idList_before.count(SketchLineId) == 2) +assert(idList_before.count(SketchConstraintCoincidenceId) == 3) + +#perform trim +SketchTrim = Sketch.addTrim(SketchCircle, Sketch.to2D(GeomPoint)) +SketchTrim.execute() +model.do() + +#check number of features after trim +SketchFeatures = featureToCompositeFeature(Sketch.feature()) +idList_after = [] +for SubIndex in range(SketchFeatures.numberOfSubs()): + SubFeature = SketchFeatures.subFeature(SubIndex) + idList_after.append(SubFeature.getKind()) + if SubFeature.getKind() == SketchArcId: + SketchArc = SubFeature + +assert(idList_after.count(SketchCircleId) == 0) +assert(idList_after.count(SketchArcId) == 1) +assert(idList_after.count(SketchLineId) == 2) +assert(idList_after.count(SketchConstraintCoincidenceId) == 3) + + +#check arc position intersections of created arc to an additional line +SketchLine_intersecting_1 = Sketch.addLine(0, 0, 50, 50) +SketchLine_intersecting_2 = Sketch.addLine(50, 50, 100, 100) + +Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_1.feature()])) +Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_2.feature()])) + +assert(len(Intersection_Points_1) == 0) +assert(len(Intersection_Points_2) == 1) + +#add point for check +SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y()) +Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchPoint.feature()])) +assert(len(Intersection_Points_3) == 0) + +model.end() + +#assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestTrimCircle04.py b/src/SketchPlugin/Test/TestTrimCircle04.py new file mode 100644 index 000000000..57db65228 --- /dev/null +++ b/src/SketchPlugin/Test/TestTrimCircle04.py @@ -0,0 +1,98 @@ +from salome.shaper import model + +from ModelAPI import * +from GeomDataAPI import * +from ModelGeomAlgo import ModelGeomAlgo_Point2D +from salome.shaper import geom +import math + +TOLERANCE = 1.e-7 + +SketchLineId = 'SketchLine' +SketchArcId = 'SketchArc' +SketchCircleId = 'SketchCircle' +SketchConstraintCoincidenceId = 'SketchConstraintCoincidence' + +aSession = ModelAPI_Session.get() +model.begin() +partSet = model.moduleDocument() +Part = model.addPart(partSet) +Part_doc = Part.document() + +# Test1:begin split on circle with coincident point and intersection line : smaller part +Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY")) +SketchCircle = Sketch.addCircle(50, 50, 20) +SketchLine_1 = Sketch.addLine(70, 50, 80, 80) +SketchLine_2 = Sketch.addLine(80, 80, 50, 70) + +SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_1.startPoint(), SketchCircle.results()[1]) +SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchLine_2.endPoint(), SketchCircle.results()[1]) + + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 6) +#intersection points on circle to prepare a trim selection point +SketchLine_intersecting = Sketch.addLine(10, 60, 90, 60) +Circle_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchCircle.feature(), FeatureList([SketchLine_intersecting.feature()])) +assert(len(Circle_Points) == 2) +ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()])) +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 6) + +assert (len(Circle_Points) == 2) +GeomPoint = Circle_Points[1] +if Circle_Points[0].x() < Circle_Points[1].x(): + GeomPoint = Circle_Points[1] +else: + GeomPoint = Circle_Points[0] + +#check number of features before trim +Sketch_feature = featureToCompositeFeature(Sketch.feature()) +idList_before = [] +for index in range(Sketch_feature.numberOfSubs()): + idList_before.append(Sketch_feature.subFeature(index).getKind()) + +assert(idList_before.count(SketchCircleId) == 1) +assert(idList_before.count(SketchArcId) == 0) +assert(idList_before.count(SketchLineId) == 2) +assert(idList_before.count(SketchConstraintCoincidenceId) == 3) + +#perform trim +SketchTrim = Sketch.addTrim(SketchCircle, Sketch.to2D(GeomPoint)) +SketchTrim.execute() +model.do() + +#check number of features after trim +SketchFeatures = featureToCompositeFeature(Sketch.feature()) +idList_after = [] +for SubIndex in range(SketchFeatures.numberOfSubs()): + SubFeature = SketchFeatures.subFeature(SubIndex) + idList_after.append(SubFeature.getKind()) + if SubFeature.getKind() == SketchArcId: + SketchArc = SubFeature + +assert(idList_after.count(SketchCircleId) == 0) +assert(idList_after.count(SketchArcId) == 1) +assert(idList_after.count(SketchLineId) == 2) +assert(idList_after.count(SketchConstraintCoincidenceId) == 3) + + +#check arc position intersections of created arc to an additional line +SketchLine_intersecting_1 = Sketch.addLine(0, 0, 50, 50) +SketchLine_intersecting_2 = Sketch.addLine(50, 50, 100, 100) + +Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_1.feature()])) +Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_2.feature()])) + +assert(len(Intersection_Points_1) == 1) +assert(len(Intersection_Points_2) == 0) + +#add point for check +SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y()) +Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchPoint.feature()])) +assert(len(Intersection_Points_3) == 0) + +model.end() + +#assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestTrimCircle05.py b/src/SketchPlugin/Test/TestTrimCircle05.py new file mode 100644 index 000000000..d53d89b93 --- /dev/null +++ b/src/SketchPlugin/Test/TestTrimCircle05.py @@ -0,0 +1,102 @@ +from salome.shaper import model + +from ModelAPI import * +from GeomDataAPI import * +from ModelGeomAlgo import ModelGeomAlgo_Point2D +from salome.shaper import geom +import math + +TOLERANCE = 1.e-7 + +SketchPointId = 'SketchPoint' +SketchArcId = 'SketchArc' +SketchCircleId = 'SketchCircle' +SketchConstraintCoincidenceId = 'SketchConstraintCoincidence' + +aSession = ModelAPI_Session.get() +model.begin() +partSet = model.moduleDocument() +Part = model.addPart(partSet) +Part_doc = Part.document() + +# Test1:begin split on circle with coincident point and intersection line : smaller part +Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY")) +SketchCircle = Sketch.addCircle(50, 50, 20) +SketchPoint_1 = Sketch.addPoint(70, 50) +SketchPoint_2 = Sketch.addPoint(30, 50) +SketchPoint_3 = Sketch.addPoint(50, 70) +SketchPoint_4 = Sketch.addPoint(50, 30) + +#coincidence point to circle +SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchPoint_1.results()[0], SketchCircle.results()[1]) +SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchPoint_2.results()[0], SketchCircle.results()[1]) + +#coincidence circle to point +SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchCircle.results()[1], SketchPoint_3.results()[0]) +SketchConstraintCoincidence_1_4 = Sketch.setCoincident(SketchCircle.results()[1], SketchPoint_4.results()[0]) + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 9) +#intersection points on circle to prepare a trim selection point +SketchLine_intersecting = Sketch.addLine(10, 60, 90, 60) +Circle_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchCircle.feature(), FeatureList([SketchLine_intersecting.feature()])) +assert(len(Circle_Points) == 2) +ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()])) +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 9) + +assert (len(Circle_Points) == 2) +if Circle_Points[0].x() < Circle_Points[1].x(): + GeomPoint = Circle_Points[0] +else: + GeomPoint = Circle_Points[1] + +#check number of features before trim +Sketch_feature = featureToCompositeFeature(Sketch.feature()) +idList_before = [] +for index in range(Sketch_feature.numberOfSubs()): + idList_before.append(Sketch_feature.subFeature(index).getKind()) + +assert(idList_before.count(SketchCircleId) == 1) +assert(idList_before.count(SketchArcId) == 0) +assert(idList_before.count(SketchPointId) == 4) +assert(idList_before.count(SketchConstraintCoincidenceId) == 4) + +#perform trim +SketchTrim = Sketch.addTrim(SketchCircle, Sketch.to2D(GeomPoint)) +SketchTrim.execute() +model.do() + +#check number of features after trim +SketchFeatures = featureToCompositeFeature(Sketch.feature()) +idList_after = [] +for SubIndex in range(SketchFeatures.numberOfSubs()): + SubFeature = SketchFeatures.subFeature(SubIndex) + idList_after.append(SubFeature.getKind()) + if SubFeature.getKind() == SketchArcId: + SketchArc = SubFeature + +assert(idList_after.count(SketchCircleId) == 0) +assert(idList_after.count(SketchArcId) == 1) +assert(idList_after.count(SketchPointId) == 4) +assert(idList_after.count(SketchConstraintCoincidenceId) == 4) + + +#check arc position intersections of created arc to an additional line +SketchLine_intersecting_1 = Sketch.addLine(0, 0, 100, 100) +SketchLine_intersecting_2 = Sketch.addLine(0, 100, 100, 0) + +Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_1.feature()])) +Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_2.feature()])) + +assert(len(Intersection_Points_1) == 2) +assert(len(Intersection_Points_2) == 1) + +#add point for check +SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y()) +Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchPoint.feature()])) +assert(len(Intersection_Points_3) == 0) + +model.end() + +#assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestTrimCircleAndArc01.py b/src/SketchPlugin/Test/TestTrimCircleAndArc01.py new file mode 100644 index 000000000..1bb501b1e --- /dev/null +++ b/src/SketchPlugin/Test/TestTrimCircleAndArc01.py @@ -0,0 +1,157 @@ +from salome.shaper import model + +from ModelAPI import * +from GeomDataAPI import * +from ModelGeomAlgo import ModelGeomAlgo_Point2D +from salome.shaper import geom +import math + +TOLERANCE = 1.e-7 + +SketchLineId = 'SketchLine' +SketchArcId = 'SketchArc' +SketchCircleId = 'SketchCircle' +SketchConstraintCoincidenceId = 'SketchConstraintCoincidence' + +aSession = ModelAPI_Session.get() +model.begin() +partSet = model.moduleDocument() +Part = model.addPart(partSet) +Part_doc = Part.document() + +# Test1:begin split on circle with coincident point and intersection line : smaller part +Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY")) +SketchCircle = Sketch.addCircle(50, 50, 20) +SketchLine_1 = Sketch.addLine(45, 68, 45, 73) +SketchLine_2 = Sketch.addLine(45, 73, 55, 73) +SketchLine_3 = Sketch.addLine(55, 73, 55, 68) + +SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchLine_1.startPoint(), SketchCircle.results()[1]) +SketchConstraintCoincidence_1_4 = Sketch.setCoincident(SketchLine_3.endPoint(), SketchCircle.results()[1]) + +SketchLine_4 = Sketch.addLine(68, 45, 73, 45) +SketchLine_5 = Sketch.addLine(73, 45, 73, 55) +SketchLine_6 = Sketch.addLine(73, 55, 68, 55) + +SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchLine_4.startPoint(), SketchCircle.results()[1]) +SketchConstraintCoincidence_1_4 = Sketch.setCoincident(SketchLine_6.endPoint(), SketchCircle.results()[1]) + + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 15) +#intersection points on circle to prepare a trim selection point +#first intersection point - vertical +SketchLine_intersecting = Sketch.addLine(48, 10, 48, 90) +Circle_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchCircle.feature(), FeatureList([SketchLine_intersecting.feature()])) +assert(len(Circle_Points) == 2) +ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()])) +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 15) + +assert (len(Circle_Points) == 2) +GeomPoint = Circle_Points[1] +if Circle_Points[0].y() < Circle_Points[1].y(): + GeomPoint = Circle_Points[1] +else: + GeomPoint = Circle_Points[0] + +#check number of features before trim +Sketch_feature = featureToCompositeFeature(Sketch.feature()) +idList_before = [] +for index in range(Sketch_feature.numberOfSubs()): + idList_before.append(Sketch_feature.subFeature(index).getKind()) + +assert(idList_before.count(SketchCircleId) == 1) +assert(idList_before.count(SketchArcId) == 0) +assert(idList_before.count(SketchLineId) == 6) +assert(idList_before.count(SketchConstraintCoincidenceId) == 8) + +#perform trim: vertical +SketchTrim = Sketch.addTrim(SketchCircle, Sketch.to2D(GeomPoint)) +SketchTrim.execute() +model.do() + +#check number of features after trim +SketchFeatures = featureToCompositeFeature(Sketch.feature()) +idList_after = [] +for SubIndex in range(SketchFeatures.numberOfSubs()): + SubFeature = SketchFeatures.subFeature(SubIndex) + idList_after.append(SubFeature.getKind()) + if SubFeature.getKind() == SketchArcId: + SketchArc = SubFeature + +assert(idList_after.count(SketchCircleId) == 0) +assert(idList_after.count(SketchArcId) == 1) +assert(idList_after.count(SketchLineId) == 6) +assert(idList_after.count(SketchConstraintCoincidenceId) == 8) + + +#check arc position intersections of created arc to an additional line +#SketchLine_intersecting_1 = Sketch.addLine(0, 0, 50, 50) +#SketchLine_intersecting_2 = Sketch.addLine(50, 50, 100, 100) + +#Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_1.feature()])) +#Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_2.feature()])) + +#assert(len(Intersection_Points_1) == 1) +#assert(len(Intersection_Points_2) == 0) + +#add point for check +SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y()) +Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchPoint.feature()])) +assert(len(Intersection_Points_3) == 0) + + + +#perform trim: horizontal +#second intersection point - horizontal +SketchLine_intersecting_h = Sketch.addLine(10, 48, 72, 48) +Circle_Points_h = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_h.feature()])) +assert(len(Circle_Points_h) == 2) +ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting_h.feature()])) +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 16) + +assert (len(Circle_Points_h) == 2) +GeomPoint = Circle_Points_h[1] +if Circle_Points_h[0].x() < Circle_Points_h[1].x(): + GeomPoint_h = Circle_Points_h[1] +else: + GeomPoint_h = Circle_Points_h[0] + + +SketchTrim = Sketch.addTrim(SketchArc, Sketch.to2D(GeomPoint_h)) +SketchTrim.execute() +model.do() + +#check number of features after trim +SketchFeatures = featureToCompositeFeature(Sketch.feature()) +idList_after = [] +anArcList = FeatureList() +for SubIndex in range(SketchFeatures.numberOfSubs()): + SubFeature = SketchFeatures.subFeature(SubIndex) + idList_after.append(SubFeature.getKind()) + if SubFeature.getKind() == SketchArcId: + anArcList.append(SubFeature) + +assert(len(anArcList) == 2) + +assert(idList_after.count(SketchCircleId) == 0) +assert(idList_after.count(SketchArcId) == 2) +assert(idList_after.count(SketchLineId) == 6) +assert(idList_after.count(SketchConstraintCoincidenceId) == 9) + + +#add point for check +SketchPoint = Sketch.addPoint(GeomPoint_h.x(), GeomPoint_h.y()) +Intersection_Points_5 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchPoint.feature(), anArcList) +assert(len(Intersection_Points_5) == 0) + + +model.end() + +#assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestTrimLine01.py b/src/SketchPlugin/Test/TestTrimLine01.py new file mode 100644 index 000000000..cc2f909a3 --- /dev/null +++ b/src/SketchPlugin/Test/TestTrimLine01.py @@ -0,0 +1,82 @@ +from salome.shaper import model + +from ModelAPI import * +from GeomDataAPI import * +from ModelGeomAlgo import ModelGeomAlgo_Point2D +from salome.shaper import geom +import math + +TOLERANCE = 1.e-7 + +SketchLineId = 'SketchLine' +SketchConstraintCoincidenceId = 'SketchConstraintCoincidence' + +aSession = ModelAPI_Session.get() +model.begin() +partSet = model.moduleDocument() +Part = model.addPart(partSet) +Part_doc = Part.document() + +# Test1:begin split on arc with coincident point and intersection line : smaller part +Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY")) +# Test of inverted Arc +SketchLine_1 = Sketch.addLine(200, 20, 20, 70) +SketchLine_2 = Sketch.addLine(20, 70, 90, 150) +SketchLine_3 = Sketch.addLine(-10, 190, 90, 50) + +SketchLine_intersecting = Sketch.addLine(-30, 85, 50, 85) + +SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_1.results()[0], SketchLine_3.endPoint()) + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 6) + +Intersection_Point = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_2.feature(), FeatureList([SketchLine_intersecting.feature()])) +assert(len(Intersection_Point) == 1) + +ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()])) + +Sketch_features = featureToCompositeFeature(Sketch.feature()) +assert (Sketch_features.numberOfSubs() == 5) + +GeomPoint = Intersection_Point[0] + +#check number of features before trim +Sketch_feature = featureToCompositeFeature(Sketch.feature()) +idList_before = [] +for index in range(Sketch_feature.numberOfSubs()): + idList_before.append(Sketch_feature.subFeature(index).getKind()) + +assert(idList_before.count(SketchLineId) == 3) +assert(idList_before.count(SketchConstraintCoincidenceId) == 2) + +#perform trim +SketchTrim = Sketch.addTrim(SketchLine_2, Sketch.to2D(GeomPoint)) +SketchTrim.execute() +model.do() + +#check number of features after trim +SketchFeatures = featureToCompositeFeature(Sketch.feature()) +idList_after = [] +for SubIndex in range(SketchFeatures.numberOfSubs()): + SubFeature = SketchFeatures.subFeature(SubIndex) + idList_after.append(SubFeature.getKind()) + +assert(idList_after.count(SketchLineId) == 3) +assert(idList_after.count(SketchConstraintCoincidenceId) == 2) + +#check if line points are the same +assert(SketchLine_1.startPoint().x() == 200) +assert(SketchLine_1.startPoint().y() == 20) +assert(SketchLine_1.endPoint().x() == 20) +assert(SketchLine_1.endPoint().y() == 70) + +assert(SketchLine_3.startPoint().x() == -10) +assert(SketchLine_3.startPoint().y() == 190) +assert(SketchLine_3.endPoint().x() == 90) +assert(SketchLine_3.endPoint().y() == 50) + +model.end() + +#assert(model.checkPythonDump())