def to_wire(self, stroking_interval=5.0): """convert IfcTransitionSegment2D to OCC wire :param stroking_interval: maximum curve length between points to be calculated :type stroking_interval: float :return: OCC wire containing interpolated points """ points = list() L = self.SegmentLength R = self.EndRadius ccw = self.IsStartRadiusCCW trans_type = self.TransitionCurveType.name num_intervals = math.ceil(L / stroking_interval) interval_dist = L / num_intervals lpt = 0.0 # length along the curve at the point to be calculated for _ in range(num_intervals): points.append(self._calc_transition_curve_point(lpt, L, R, ccw, trans_type)) lpt += interval_dist edges = list() for i in range(len(points) - 1): edges.append(BRepBuilderAPI_MakeEdge2d(points[i], points[i + 1])) wire = BRepBuilderAPI_MakeWire() for e in edges: wire.Add(e.Edge()) # return wire return points
def DisplayShape(self, shapes, material=None, texture=None, color=None, transparency=None, update=False): """ display one or a set of displayable objects """ ais_shapes = [] # the list of all displayed shapes if issubclass(shapes.__class__, gp_Pnt): # if a gp_Pnt is passed, first convert to vertex vertex = BRepBuilderAPI_MakeVertex(shapes) shapes = [vertex.Shape()] elif isinstance(shapes, gp_Pnt2d): vertex = BRepBuilderAPI_MakeVertex( gp_Pnt(shapes.X(), shapes.Y(), 0)) shapes = [vertex.Shape()] elif isinstance(shapes, Geom_Surface): bounds = True toldegen = 1e-6 face = BRepBuilderAPI_MakeFace() face.Init(shapes, bounds, toldegen) face.Build() shapes = [face.Shape()] elif isinstance(shapes, Geom_Curve): edge = BRepBuilderAPI_MakeEdge(shapes) shapes = [edge.Shape()] elif isinstance(shapes, Geom2d_Curve): edge2d = BRepBuilderAPI_MakeEdge2d(shapes) shapes = [edge2d.Shape()] # if only one shapes, create a list with a single shape if not isinstance(shapes, list): shapes = [shapes] # build AIS_Shapes list for shape in shapes: if material or texture: if texture: shape_to_display = AIS_TexturedShape(shape) filename, toScaleU, toScaleV, toRepeatU, toRepeatV, originU, originV = texture.GetProperties( ) shape_to_display.SetTextureFileName( TCollection_AsciiString(filename)) shape_to_display.SetTextureMapOn() shape_to_display.SetTextureScale(True, toScaleU, toScaleV) shape_to_display.SetTextureRepeat(True, toRepeatU, toRepeatV) shape_to_display.SetTextureOrigin(True, originU, originV) shape_to_display.SetDisplayMode(3) elif material: shape_to_display = AIS_Shape(shape) shape_to_display.SetMaterial( Graphic3d_MaterialAspect(material)) else: # TODO: can we use .Set to attach all TopoDS_Shapes # to this AIS_Shape instance? shape_to_display = AIS_Shape(shape) ais_shapes.append(shape_to_display) # if not SOLO: # # computing graphic properties is expensive # # if an iterable is found, so cluster all TopoDS_Shape under # # an AIS_MultipleConnectedInteractive # #shape_to_display = AIS_MultipleConnectedInteractive() # for ais_shp in ais_shapes: # # TODO : following line crashes with oce-0.18 # # why ? fix ? # #shape_to_display.Connect(i) # self.Context.Display(ais_shp, False) # set the graphic properties if material is None: #The default material is too shiny to show the object #color well, so I set it to something less reflective for shape_to_display in ais_shapes: shape_to_display.SetMaterial( Graphic3d_MaterialAspect(Graphic3d_NOM_NEON_GNC)) if color: if isinstance(color, str): color = get_color_from_name(color) elif isinstance(color, int): color = Quantity_Color(color) for shp in ais_shapes: self.Context.SetColor(shp, color, False) if transparency: for shape_to_display in ais_shapes: shape_to_display.SetTransparency(transparency) # display the shapes for shape_to_display in ais_shapes: self.Context.Display(shape_to_display, False) if update: # especially this call takes up a lot of time... self.FitAll() self.Repaint() return ais_shapes
def make_edge2d(shape): spline = BRepBuilderAPI_MakeEdge2d(shape) spline.Build() return spline.Shape()
def make_edge2d(*args): edge = BRepBuilderAPI_MakeEdge2d(*args) result = edge.Edge() edge.Delete() return result
def make_edge2d(*args): edge = BRepBuilderAPI_MakeEdge2d(*args) with assert_isdone(edge, 'failed to produce edge'): result = edge.Edge() edge.Delete() return result
def DisplayShape(self, shapes, material=None, texture=None, color=None, transparency=None, update=False): """ display one or a set of displayable objects """ SOLO = False # assume multiple instances by default # if a gp_Pnt is passed, first convert to vertex if issubclass(shapes.__class__, gp_Pnt): vertex = BRepBuilderAPI_MakeVertex(shapes) shapes = [vertex.Shape()] SOLO = True elif isinstance(shapes, gp_Pnt2d): vertex = BRepBuilderAPI_MakeVertex( gp_Pnt(shapes.X(), shapes.Y(), 0)) shapes = [vertex.Shape()] SOLO = True # if a Geom_Curve is passed elif callable(getattr(shapes, "GetHandle", None)): handle = shapes.GetHandle() if issubclass(handle.__class__, Handle_Geom_Curve): edge = BRepBuilderAPI_MakeEdge(handle) shapes = [edge.Shape()] SOLO = True elif issubclass(handle.__class__, Handle_Geom2d_Curve): edge2d = BRepBuilderAPI_MakeEdge2d(handle) shapes = [edge2d.Shape()] SOLO = True elif issubclass(handle.__class__, Handle_Geom_Surface): bounds = True toldegen = 1e-6 face = BRepBuilderAPI_MakeFace() face.Init(handle, bounds, toldegen) face.Build() shapes = [face.Shape()] SOLO = True elif isinstance(shapes, Handle_Geom_Surface): bounds = True toldegen = 1e-6 face = BRepBuilderAPI_MakeFace() face.Init(shapes, bounds, toldegen) face.Build() shapes = [face.Shape()] SOLO = True elif isinstance(shapes, Handle_Geom_Curve): edge = BRepBuilderAPI_MakeEdge(shapes) shapes = [edge.Shape()] SOLO = True elif isinstance(shapes, Handle_Geom2d_Curve): edge2d = BRepBuilderAPI_MakeEdge2d(shapes) shapes = [edge2d.Shape()] SOLO = True elif issubclass(shapes.__class__, TopoDS_Shape): shapes = [shapes] SOLO = True ais_shapes = [] for shape in shapes: if material or texture: if texture: self.View.SetSurfaceDetail(V3d_TEX_ALL) shape_to_display = AIS_TexturedShape(shape) filename, toScaleU, toScaleV, toRepeatU, toRepeatV, originU, originV = texture.GetProperties( ) shape_to_display.SetTextureFileName( TCollection_AsciiString(filename)) shape_to_display.SetTextureMapOn() shape_to_display.SetTextureScale(True, toScaleU, toScaleV) shape_to_display.SetTextureRepeat(True, toRepeatU, toRepeatV) shape_to_display.SetTextureOrigin(True, originU, originV) shape_to_display.SetDisplayMode(3) elif material: shape_to_display = AIS_Shape(shape) shape_to_display.SetMaterial(material) else: # TODO: can we use .Set to attach all TopoDS_Shapes # to this AIS_Shape instance? shape_to_display = AIS_Shape(shape) ais_shapes.append(shape_to_display.GetHandle()) if not SOLO: # computing graphic properties is expensive # if an iterable is found, so cluster all TopoDS_Shape under # an AIS_MultipleConnectedInteractive #shape_to_display = AIS_MultipleConnectedInteractive() for ais_shp in ais_shapes: # TODO : following line crashes with oce-0.18 # why ? fix ? #shape_to_display.Connect(i) self.Context.Display(ais_shp, False) shape_to_display = ais_shapes return shape_to_display # set the graphic properties if material is None: #The default material is too shiny to show the object #color well, so I set it to something less reflective shape_to_display.SetMaterial(Graphic3d_NOM_NEON_GNC) if color: if isinstance(color, str): color = get_color_from_name(color) for shp in ais_shapes: self.Context.SetColor(shp, color, False) if transparency: shape_to_display.SetTransparency(transparency) if update: # only update when explicitely told to do so self.Context.Display(shape_to_display.GetHandle(), False) # especially this call takes up a lot of time... self.FitAll() self.Repaint() else: self.Context.Display(shape_to_display.GetHandle(), False) if SOLO: return ais_shapes[0] else: return shape_to_display
curgp_Array1CurveWeights2d.SetValue(3, 1.0) curgp_Array1CurveWeights2d.SetValue(4, 1.0) curgp_Array1CurveMulti2d = TColStd_Array1OfInteger(1, 3) curgp_Array1CurveMulti2d.SetValue(1, 3) curgp_Array1CurveMulti2d.SetValue(2, 1) curgp_Array1CurveMulti2d.SetValue(3, 3) curgp_Array1CurveKnots2d = TColStd_Array1OfReal(1, 3) curgp_Array1CurveKnots2d.SetValue(1, 0.0) curgp_Array1CurveKnots2d.SetValue(2, 1.0) curgp_Array1CurveKnots2d.SetValue(3, 2.0) myGeom2d_BSplineCurve = Geom2d_BSplineCurve(curgp_Array1CurvePoles2d, curgp_Array1CurveKnots2d, curgp_Array1CurveMulti2d, myDegree) knots:TColStd_Array1OfReal=myGeom2d_BSplineCurve.Knots() mults:TColStd_Array1OfInteger=myGeom2d_BSplineCurve.Multiplicities() for i in range(1,knots.Length()): print(knots.Value(i),end=",") for i in range(1,mults.Length()): print(mults.Value(i),end=",") edge=BRepBuilderAPI_MakeEdge2d(myGeom2d_BSplineCurve) if edge.IsDone(): myGeom2d_BSplineCurve.SetPole(2, gp.Origin2d()) print("edge done") curEdge = edge.Edge() ais_shape=AIS_Shape(curEdge) display.Context.Display(ais_shape,True) start_display()
def make_edge2d(*args): edge = BRepBuilderAPI_MakeEdge2d(*args) assert_isdone(edge, "failed to produce edge") result = edge.Edge() return result