def add_shape(self, a_shape): r"""Add shape Parameters ---------- a_shape : TopoDS_Shape or subclass """ check_shape(a_shape) # raises an exception if the shape is not valid self._shapes.append(a_shape)
def set_shape(self, a_shape): """ only a single shape can be exported... Parameters ---------- a_shape """ check_shape(a_shape) # raises an exception if the shape is not valid self._shape = a_shape
def add_shape(self, shape, color=None, layer=None): r"""add a shape to export a layer and color can be specified. note that the set colors / layers will be used for further objects added too! Parameters ---------- shape : TopoDS_Shape the TopoDS_Shape to export color : can be a tuple: (r,g,b) or a Quantity_Color instance layer : str layer name """ check_shape(shape) # raises an exception if the shape is not valid shp_label = self.shape_tool.AddShape(shape) if color is None: self.colors.SetColor(shp_label, self.current_color, XCAFDoc.XCAFDoc_ColorGen) else: if isinstance(color, Quantity.Quantity_Color): self.current_color = color else: assert len( color) == 3, 'expected a tuple with three values < 1.' r, g, b = color self.set_color(r, g, b) self.colors.SetColor(shp_label, self.current_color, XCAFDoc.XCAFDoc_ColorGen) if layer is None: self.layers.SetLayer(shp_label, self.current_layer) else: self.set_layer(layer) self.layers.SetLayer(shp_label, self.current_layer)
def add_shape(self, shape, color=None, layer=None): r"""add a shape to export a layer and color can be specified. note that the set colors / layers will be used for further objects added too! Parameters ---------- shape : TopoDS_Shape the TopoDS_Shape to export color : can be a tuple: (r,g,b) or a Quantity_Color instance layer : str layer name """ check_shape(shape) # raises an exception if the shape is not valid shp_label = self.shape_tool.AddShape(shape) if color is None: self.colors.SetColor(shp_label, self.current_color, XCAFDoc.XCAFDoc_ColorGen) else: if isinstance(color, Quantity.Quantity_Color): self.current_color = color else: assert len(color) == 3, 'expected a tuple with three values < 1.' r, g, b = color self.set_color(r, g, b) self.colors.SetColor(shp_label, self.current_color, XCAFDoc.XCAFDoc_ColorGen) if layer is None: self.layers.SetLayer(shp_label, self.current_layer) else: self.set_layer(layer) self.layers.SetLayer(shp_label, self.current_layer)
def test_check_shape(): r"""check_shape() tests""" # Null shapes should raise a ValueError with pytest.raises(ValueError): check_shape(TopoDS.TopoDS_Shape()) with pytest.raises(ValueError): check_shape(TopoDS.TopoDS_Shell()) builderapi_makeedge = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(gp.gp_Pnt(), gp.gp_Pnt(10, 10, 10)) shape = builderapi_makeedge.Shape() # a ValueError should be raised is check_shape() is not give a TopoDS_Shape or subclass with pytest.raises(ValueError): check_shape(gp.gp_Pnt()) with pytest.raises(ValueError): check_shape(builderapi_makeedge) # a TopoDS_Shape should pass the check without raising any exception check_shape(shape) # a subclass of shape should not raise any exception check_shape(Topo(shape).edges().next())
def test_check_shape(): r"""check_shape() tests""" # Null shapes should raise a ValueError with pytest.raises(ValueError): check_shape(TopoDS.TopoDS_Shape()) with pytest.raises(ValueError): check_shape(TopoDS.TopoDS_Shell()) builderapi_makeedge = BRepBuilderAPI.BRepBuilderAPI_MakeEdge( gp.gp_Pnt(), gp.gp_Pnt(10, 10, 10)) shape = builderapi_makeedge.Shape() # a ValueError should be raised is check_shape() is not give a TopoDS_Shape or subclass with pytest.raises(ValueError): check_shape(gp.gp_Pnt()) with pytest.raises(ValueError): check_shape(builderapi_makeedge) # a TopoDS_Shape should pass the check without raising any exception check_shape(shape) # a subclass of shape should not raise any exception check_shape(next(Topo(shape).edges()))