From cec7a28b09627b034ee86c6b1ce1de883bb25984 Mon Sep 17 00:00:00 2001 From: spo Date: Mon, 26 Oct 2015 15:36:34 +0300 Subject: [PATCH] sketch.selectFace() returns Selection --- src/PythonAPI/Test/TestFeaturesExtrusion.py | 34 ++++++++++----------- src/PythonAPI/model/roots.py | 4 +-- src/PythonAPI/model/sketcher/sketch.py | 3 ++ src/PythonAPI/model/tools.py | 11 ++----- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/PythonAPI/Test/TestFeaturesExtrusion.py b/src/PythonAPI/Test/TestFeaturesExtrusion.py index 2cfec0b04..46e6b31fe 100644 --- a/src/PythonAPI/Test/TestFeaturesExtrusion.py +++ b/src/PythonAPI/Test/TestFeaturesExtrusion.py @@ -28,10 +28,10 @@ class FeaturesExtrusionFixture(FeaturesAddExtrusionFixture): # Create extrusion sketch = model.addSketch(self.part, model.defaultPlane("XOY")) circle = sketch.addCircle(0, 0, 10) + model.do() base = [sketch.selectFace(circle.result())] - self.extrusion = model.addExtrusion(self.part, base, - 10, 0) + self.extrusion = model.addExtrusion(self.part, base, 10, 0) model.do() def tearDown(self): @@ -52,10 +52,11 @@ class FeaturesAddExtrusionTestCase(FeaturesAddExtrusionFixture): def test_add_extrusion_by_face_and_size(self): sketch = model.addSketch(self.part, model.defaultPlane("XOY")) circle = sketch.addCircle(0, 0, 10) + model.do() base = [sketch.selectFace(circle.result())] - extrusion = model.addExtrusion(self.part, base, - 10, 0) + extrusion = model.addExtrusion(self.part, base, 10, 0) + model.do() self.assertEqual(extrusion.getCreationMethod().value(), "BySizes") self.assertEqual(extrusion.getToSize().value(), 10) @@ -69,24 +70,25 @@ class FeaturesAddExtrusionTestCase(FeaturesAddExtrusionFixture): # base base_sketch = model.addSketch(self.part, model.defaultPlane("XOY")) base_circle = base_sketch.addCircle(0, 0, 10) - base_sketch.selectFace(base_circle.result()) # to to_plane = model.defaultPlane("XOY") to_plane.location().setZ(10) to_sketch = model.addSketch(self.part, to_plane) to_circle = to_sketch.addCircle(0, 0, 10) - to_sketch.selectFace(to_circle.result()) # from from_plane = model.defaultPlane("XOY") from_plane.location().setZ(-10) from_sketch = model.addSketch(self.part, from_plane) from_circle = from_sketch.addCircle(0, 0, 10) - from_sketch.selectFace(from_circle.result()) - base = [base_sketch] + model.do() + + base = [base_sketch.selectFace(base_circle.result())] + to_object = to_sketch.selectFace(to_circle.result()) + from_object = from_sketch.selectFace(from_circle.result()) extrusion = model.addExtrusion(self.part, base, - to_sketch, 15, - from_sketch, 20) + to_object, 15, + from_object, 20) self.assertEqual(extrusion.getCreationMethod().value(), "ByPlanesAndOffsets") self.assertEqual(extrusion.getToSize().value(), 0) @@ -135,24 +137,22 @@ class FeaturesExtrusionTestCase(FeaturesExtrusionFixture): self.assertEqual(self.extrusion.getFromOffset().value(), 0) def test_extrusion_set_planes_and_offsets(self): - # base - base_sketch = model.addSketch(self.part, model.defaultPlane("XOY")) - base_circle = base_sketch.addCircle(0, 0, 10) - base_sketch.selectFace(base_circle.result()) # to to_plane = model.defaultPlane("XOY") to_plane.location().setZ(10) to_sketch = model.addSketch(self.part, to_plane) to_circle = to_sketch.addCircle(0, 0, 10) - to_sketch.selectFace(to_circle.result()) # from from_plane = model.defaultPlane("XOY") from_plane.location().setZ(-10) from_sketch = model.addSketch(self.part, from_plane) from_circle = from_sketch.addCircle(0, 0, 10) - from_sketch.selectFace(from_circle.result()) - self.extrusion.setPlanesAndOffsets(to_sketch, 15, from_sketch, 20) + model.do() + + to_object = to_sketch.selectFace(to_circle.result()) + from_object = from_sketch.selectFace(from_circle.result()) + self.extrusion.setPlanesAndOffsets(to_object, 15, from_object, 20) if __name__ == "__main__": diff --git a/src/PythonAPI/model/roots.py b/src/PythonAPI/model/roots.py index 798f4dac3..a5ac3c201 100644 --- a/src/PythonAPI/model/roots.py +++ b/src/PythonAPI/model/roots.py @@ -63,9 +63,9 @@ class Interface(): """Return ModelAPI_Feature.""" return self._feature - def _fill_attribute(self, attribute, value, *args): + def _fill_attribute(self, attribute, value): """Fill ModelAPI_Attribute* with value.""" - tools.fill_attribute(attribute, value, *args) + tools.fill_attribute(attribute, value) def setRealInput(self, inputid, value): self._feature.data().real(inputid).setValue(value) diff --git a/src/PythonAPI/model/sketcher/sketch.py b/src/PythonAPI/model/sketcher/sketch.py index 8123ab979..c865651c2 100644 --- a/src/PythonAPI/model/sketcher/sketch.py +++ b/src/PythonAPI/model/sketcher/sketch.py @@ -12,6 +12,8 @@ from model.sketcher.line import Line from model.sketcher.circle import Circle from model.sketcher.arc import Arc from model.roots import Interface +from model.tools import Selection + def addSketch(doc, plane): """Add a Sketch feature to the Part or PartSet and return an interface @@ -283,6 +285,7 @@ class Sketch(Interface): self._feature.firstResult()).shape() elif len(args) == 1: self._selection = args[0].shape() + return Selection(self.result(), self.buildShape()) else: raise Exception("not yet implemented") return self diff --git a/src/PythonAPI/model/tools.py b/src/PythonAPI/model/tools.py index 71c2df660..8626b823b 100644 --- a/src/PythonAPI/model/tools.py +++ b/src/PythonAPI/model/tools.py @@ -55,15 +55,16 @@ class Selection: # , # "args[1] should be str (%s given)." % # type(args[1])) - elif isinstance(args[0], ModelAPI.ModelAPI_Result): + elif isinstance(args[0], ModelAPI.ModelAPI_Result) or args[0] is None: assert(isinstance(args[1], GeomAPI.GeomAPI_Shape)) + # , # "args[1] should be GeomAPI_Shape (%s given)." % # type(args[1])) self.args = args -def fill_attribute(attribute, value, *args): +def fill_attribute(attribute, value): """Set value to attribure. This function processes complex cases. @@ -78,9 +79,6 @@ def fill_attribute(attribute, value, *args): assert(isinstance(value, collections.Iterable)) for item in value: - attribute.append(item.result(), item.buildShape()) - continue - assert(isinstance(item, Selection)) attribute.append(*item.args) @@ -89,9 +87,6 @@ def fill_attribute(attribute, value, *args): attribute.setValue(None, None) return - attribute.setValue(value.result(), value.buildShape()) - return - assert(isinstance(value, Selection)) attribute.setValue(*value.args) -- 2.39.2