Exemplo n.º 1
0
 def __init__(self, labels, color=None, **kwargs):
     super(LabelsConduit, self).__init__(**kwargs)
     self._default_color = FromArgb(0, 0, 0)
     self._default_textcolor = FromArgb(255, 255, 255)
     self._color = None
     self.labels = labels or []
     self.color = color
Exemplo n.º 2
0
 def __init__(self, mesh, tol=0.1, dotcolor=None, textcolor=None, **kwargs):
     super(MeshVertexInspector, self).__init__(**kwargs)
     self.mesh = mesh
     self.tol = tol
     dotcolor = dotcolor or (255, 0, 0)
     textcolor = textcolor or (0, 0, 0)
     self.dotcolor = FromArgb(*dotcolor)
     self.textcolor = FromArgb(*textcolor)
     self.mouse = Mouse(self)
Exemplo n.º 3
0
 def color(self, color):
     if color:
         color[:] = [(FromArgb(* color_to_rgb(bgc)), FromArgb(* color_to_rgb(tc))) for bgc, tc in color]
         l = len(self.labels)
         c = len(color)
         if c < l:
             colors += [(self._default_color, self._default_textcolor) for i in range(l - c)]
         elif c > l:
             color[:] = color[:l]
         self._color = color
Exemplo n.º 4
0
 def color(self, color):
     if not color:
         return
     if not is_sequence_of_iterable(color[0]):
         # the first item in the list should be a tuple of colors
         # if not, wrap the tuple
         color = [color]
     color = [(FromArgb(*bg), FromArgb(*text))
              for bg, text in iterable_like(self.labels, color, (
                  self.default_color, self.default_textcolor))]
     self._color = color
Exemplo n.º 5
0
    def __init__(self, volmesh, tol=0.1, **kwargs):
        super(VolmeshVertexInspector, self).__init__(**kwargs)

        dotcolor = (255, 0, 0)
        textcolor = (255, 255, 255)

        self.volmesh = volmesh
        self.tol = tol
        self.mouse = Mouse()
        self.dotcolor = FromArgb(*dotcolor)
        self.textcolor = FromArgb(*textcolor)
Exemplo n.º 6
0
 def __init__(self, lines, thickness=1.0, color=None, **kwargs):
     super(LinesConduit, self).__init__(**kwargs)
     self.lines = lines
     self.n = len(lines)
     self.thickness = thickness
     color = color or (255, 255, 255)
     self.color = FromArgb(*color)
Exemplo n.º 7
0
def xdraw_points(points, **kwargs):
    """Draw points and optionally set individual name, layer, and color properties.
    """
    guids = []
    for p in iter(points):
        pos = p['pos']
        name = p.get('name', '')
        color = p.get('color')
        layer = p.get('layer')
        guid = add_point(Point3d(*pos))
        if not guid:
            continue
        obj = find_object(guid)
        if not obj:
            continue
        attr = obj.Attributes
        if color:
            attr.ObjectColor = FromArgb(*color)
            attr.ColorSource = ColorFromObject
        else:
            attr.ColorSource = ColorFromLayer
        if layer and find_layer_by_fullpath:
            index = find_layer_by_fullpath(layer, True)
            if index >= 0:
                attr.LayerIndex = index
        attr.Name = name
        obj.CommitChanges()
        guids.append(guid)
    return guids
Exemplo n.º 8
0
 def __init__(self, points, radius=3, color=None, **kwargs):
     super(PointsConduit, self).__init__(**kwargs)
     self.points = points
     self.n = len(points)
     self.radius = radius
     color = color or (255, 0, 0)
     self.color = FromArgb(*color)
Exemplo n.º 9
0
def xdraw_spheres(spheres, **kwargs):
    guids = []
    for s in iter(spheres):
        pos = s['pos']
        radius = s['radius']
        name = s.get('name', '')
        color = s.get('color')
        layer = s.get('layer')
        sphere = Sphere(Point3d(*pos), radius)
        guid = add_sphere(sphere)
        if not guid:
            continue
        obj = find_object(guid)
        if not obj:
            continue
        attr = obj.Attributes
        if color:
            attr.ObjectColor = FromArgb(*color)
            attr.ColorSource = ColorFromObject
        else:
            attr.ColorSource = ColorFromLayer
        if layer and find_layer_by_fullpath:
            index = find_layer_by_fullpath(layer, True)
            if index >= 0:
                attr.LayerIndex = index
        attr.Name = name
        attr.WireDensity = -1
        obj.CommitChanges()
        guids.append(guid)
    return guids
Exemplo n.º 10
0
    def __init__(self, volmesh, color_dict=None, tol=1, **kwargs):
        super(VolmeshCellInspector, self).__init__(**kwargs)

        dotcolor = (0, 0, 0)
        textcolor = (255, 255, 255)
        edgecolor = (0, 0, 0)
        facecolor = (255, 0, 0)

        self.volmesh = volmesh
        self.color_dict = color_dict
        self.tol = tol
        self.mouse = Mouse()
        self.dotcolor = FromArgb(*dotcolor)
        self.textcolor = FromArgb(*textcolor)
        self.edgecolor = FromArgb(*edgecolor)
        self.facecolor = FromArgb(*facecolor)
Exemplo n.º 11
0
    def __init__(self, volmesh, network, tol=2, **kwargs):
        super(BiCellInspector, self).__init__(**kwargs)

        dotcolor = (0, 0, 0)
        textcolor = (255, 255, 255)
        edgecolor = (0, 0, 0)
        facecolor = (255, 0, 0)

        self.volmesh = volmesh
        self.network = network
        self.tol = tol
        self.mouse = Mouse()
        self.dotcolor = FromArgb(*dotcolor)
        self.textcolor = FromArgb(*textcolor)
        self.edgecolor = FromArgb(*edgecolor)
        self.facecolor = FromArgb(*facecolor)
Exemplo n.º 12
0
 def __init__(self, vertices, faces, color=None, **kwargs):
     super(FacesConduit, self).__init__(**kwargs)
     self._default_color = FromArgb(255, 255, 255)
     self._color = None
     self.vertices = vertices or []
     self.faces = faces or []
     self.color = color
Exemplo n.º 13
0
def draw_circles(circles, **kwargs):
    guids = []
    for data in iter(circles):
        point, normal = data['plane']
        radius = data['radius']
        name = data.get('name', '')
        color = data.get('color')
        layer = data.get('layer')
        circle = Circle(Plane(Point3d(*point), Vector3d(*normal)), radius)
        guid = add_circle(circle)
        if not guid:
            continue
        obj = find_object(guid)
        if not obj:
            continue
        attr = obj.Attributes
        if color:
            attr.ObjectColor = FromArgb(*color)
            attr.ColorSource = ColorFromObject
        else:
            attr.ColorSource = ColorFromLayer
        if layer and find_layer_by_fullpath:
            index = find_layer_by_fullpath(layer, True)
            if index >= 0:
                attr.LayerIndex = index
        attr.Name = name
        attr.WireDensity = -1
        obj.CommitChanges()
        guids.append(guid)
    return guids
Exemplo n.º 14
0
def draw_mesh(vertices, faces, name=None, color=None, disjoint=False, **kwargs):
    points = []
    mesh = RhinoMesh()
    if disjoint:
        for keys in faces:
            i = len(points)
            facet = [j + i for j in range(len(keys))]
            for key in keys:
                point = vertices[key]
                points.append(point)
                x, y, z = point
                mesh.Vertices.Add(x, y, z)
            mesh.Faces.AddFace(*facet)
    else:
        for x, y, z in vertices:
            mesh.Vertices.Add(x, y, z)
        for face in faces:
            mesh.Faces.AddFace(*face)
    mesh.Normals.ComputeNormals()
    mesh.Compact()
    guid = add_mesh(mesh)
    if guid:
        obj = find_object(guid)
        attr = obj.Attributes
        if color:
            attr.ObjectColor = FromArgb(*color)
            attr.ColorSource = ColorFromObject
        else:
            attr.ColorSource = ColorFromLayer
        if name:
            attr.Name = name
        obj.CommitChanges()
    return guid
Exemplo n.º 15
0
    def DrawForeground(self, e):
        p1 = self.mouse.p1
        p2 = self.mouse.p2
        v12 = subtract_vectors(p2, p1)
        l12 = length_vector(v12)

        # force diagram
        for ckey in self.volmesh.cell:
            p0 = self.volmesh.cell_center(ckey)
            v01 = subtract_vectors(p1, p0)
            v02 = subtract_vectors(p2, p0)
            l = length_vector(cross_vectors(v01, v02))
            color = self.edgecolor
            if self.color_dict:
                color = FromArgb(*self.color_dict[ckey])
            if l12 == 0.0 or (l / l12) < self.tol:
                for hfkey in self.volmesh.cell_halffaces(ckey):
                    vkeys = self.volmesh.halfface_vertices(hfkey)
                    face_coordinates = [
                        self.volmesh.vertex_coordinates(vkey) for vkey in vkeys
                    ]
                    face_coordinates.append(face_coordinates[0])
                    polygon_xyz = [Point3d(*xyz) for xyz in face_coordinates]
                    e.Display.DrawPolyline(polygon_xyz, color, 3)
                break
Exemplo n.º 16
0
    def __init__(self, volmesh, hfkeys=None, dependents=False, tol=1, **kwargs):
        super(VolmeshHalffaceInspector, self).__init__(**kwargs)

        dotcolor = (0, 0, 0)
        textcolor = (255, 255, 255)
        edgecolor = (255, 255, 0)
        facecolor = (255, 0, 0)

        self.volmesh = volmesh
        self.hfkeys = hfkeys
        self.dependents = dependents
        self.tol = tol
        self.mouse = Mouse()
        self.dotcolor = FromArgb(*dotcolor)
        self.textcolor = FromArgb(*textcolor)
        self.edgecolor = FromArgb(*edgecolor)
        self.facecolor = FromArgb(*facecolor)
Exemplo n.º 17
0
 def color(self, color):
     color = color or self.default_color
     if not is_sequence_of_iterable(color):
         color = [color]
     self._color = [
         FromArgb(*c)
         for c in iterable_like(self.lines, color, self.default_color)
     ]
Exemplo n.º 18
0
 def __init__(self, points, pairs, thickness=1, color=None, **kwargs):
     super(PointPairsConduit, self).__init__(**kwargs)
     self.points = points
     self.pairs = pairs
     self.n = len(pairs)
     self.thickness = thickness
     color = color or (255, 255, 255)
     self.color = FromArgb(*color)
Exemplo n.º 19
0
def xdraw_breps(faces,
                srf=None,
                u=10,
                v=10,
                trim=True,
                tangency=True,
                spacing=0.1,
                flex=1.0,
                pull=1.0,
                **kwargs):
    """Draw polygonal faces as Breps, and optionally set individual name, color,
    and layer properties.
    """
    guids = []
    for f in iter(faces):
        points = f['points']
        name = f.get('name', '')
        color = f.get('color')
        layer = f.get('layer')
        corners = [Point3d(*point) for point in points]
        pcurve = PolylineCurve(corners)
        geo = List[GeometryBase](1)
        geo.Add(pcurve)
        p = len(points)
        if p == 4:
            brep = Brep.CreateFromCornerPoints(Point3d(*points[0]),
                                               Point3d(*points[1]),
                                               Point3d(*points[2]), TOL)
        elif p == 5:
            brep = Brep.CreateFromCornerPoints(Point3d(*points[0]),
                                               Point3d(*points[1]),
                                               Point3d(*points[2]),
                                               Point3d(*points[3]), TOL)
        else:
            brep = Brep.CreatePatch(geo, u, v, TOL)
        if not brep:
            continue
        guid = add_brep(brep)
        if not guid:
            continue
        obj = find_object(guid)
        if not obj:
            continue
        attr = obj.Attributes
        if color:
            attr.ObjectColor = FromArgb(*color)
            attr.ColorSource = ColorFromObject
        else:
            attr.ColorSource = ColorFromLayer
        if layer and find_layer_by_fullpath:
            index = find_layer_by_fullpath(layer, True)
            if index >= 0:
                attr.LayerIndex = index
        attr.Name = name
        attr.WireDensity = -1
        obj.CommitChanges()
        guids.append(guid)
    return guids
Exemplo n.º 20
0
def draw_circles(circles, **kwargs):
    """Draw circles and optionally set individual name, color, and layer properties.

    Parameters
    ----------
    circles : list[dict]
        A list of circle dictionaries.
        See Notes, for more information about the structure of the dict.

    Returns
    -------
    list[System.Guid]

    Notes
    -----
    A circle dict has the following schema:

    .. code-block:: python

        Schema({
            'plane': lambda x: len(x[0]) == 3 and len(x[1]) == 3,
            'radius': And(Or(int, float), lambda x: x > 0),
            Optional('name', default=''): str,
            Optional('color', default=None): And(lambda x: len(x) == 3, all(0 <= y <= 255 for y in x)),
            Optional('layer', default=None): str
        })

    """
    guids = []
    for data in iter(circles):
        point, normal = data['plane']
        radius = data['radius']
        name = data.get('name', '')
        color = data.get('color')
        layer = data.get('layer')
        circle = Circle(Plane(Point3d(*point), Vector3d(*normal)), radius)
        guid = add_circle(circle)
        if not guid:
            continue
        obj = find_object(guid)
        if not obj:
            continue
        attr = obj.Attributes
        if color:
            attr.ObjectColor = FromArgb(*color)
            attr.ColorSource = ColorFromObject
        else:
            attr.ColorSource = ColorFromLayer
        if layer and find_layer_by_fullpath:
            index = find_layer_by_fullpath(layer, True)
            if index >= 0:
                attr.LayerIndex = index
        attr.Name = name
        attr.WireDensity = -1
        obj.CommitChanges()
        guids.append(guid)
    return guids
Exemplo n.º 21
0
 def __init__(self, lines, thickness=None, color=None, **kwargs):
     super(LinesConduit, self).__init__(**kwargs)
     self._default_thickness = 1.0
     self._default_color = FromArgb(255, 255, 255)
     self._thickness = None
     self._color = None
     self.lines = lines or []
     self.thickness = thickness
     self.color = color
Exemplo n.º 22
0
 def color(self, color):
     color = color or self.default_color
     if not is_sequence_of_iterable(color):
         color = [color]
     color = [
         FromArgb(*color_to_rgb(c))
         for c in iterable_like(self.points, color, self.default_color)
     ]
     self._color = color
Exemplo n.º 23
0
def draw_mesh(vertices,
              faces,
              name=None,
              color=None,
              disjoint=False,
              **kwargs):
    """Draw a mesh and optionally set individual name, color, and layer properties.

    Parameters
    ----------
    vertices : :obj:`list` of point
        A list of point locations.
    faces : :obj:`list` of :obj:`list` of :obj:`int`
        A list of faces as lists of indices into ``vertices``.
    name : :obj:`str`, optional
    color : RGB :obj:`tuple`, optional
    disjoint : :obj:`bool`, optional
        Draw the mesh with disjoint faces.
        Default is ``False``.

    Returns
    -------
    str or GUID

    """
    points = []
    mesh = RhinoMesh()
    if disjoint:
        for keys in faces:
            i = len(points)
            facet = [j + i for j in range(len(keys))]
            for key in keys:
                point = vertices[key]
                points.append(point)
                x, y, z = point
                mesh.Vertices.Add(x, y, z)
            mesh.Faces.AddFace(*facet)
    else:
        for x, y, z in vertices:
            mesh.Vertices.Add(x, y, z)
        for face in faces:
            mesh.Faces.AddFace(*face)
    mesh.Normals.ComputeNormals()
    mesh.Compact()
    guid = add_mesh(mesh)
    if guid:
        obj = find_object(guid)
        attr = obj.Attributes
        if color:
            attr.ObjectColor = FromArgb(*color)
            attr.ColorSource = ColorFromObject
        else:
            attr.ColorSource = ColorFromLayer
        if name:
            attr.Name = name
        obj.CommitChanges()
    return guid
Exemplo n.º 24
0
 def __init__(self, mesh, thickness=None, color=None, **kwargs):
     super(MeshConduit, self).__init__(**kwargs)
     self._default_thickness = 1.0
     self._default_color = FromArgb(255, 255, 255)
     self._thickness = None
     self._color = None
     self.mesh = mesh
     self.thickness = thickness
     self.color = color
Exemplo n.º 25
0
 def __init__(self, points, size=None, color=None, **kwargs):
     super(PointsConduit, self).__init__(**kwargs)
     self._default_size = 3
     self._default_color = FromArgb(255, 0, 0)
     self._size = None
     self._color = None
     self.points = points or []
     self.size = size
     self.color = color
Exemplo n.º 26
0
def draw_spheres(spheres, **kwargs):
    """Draw spheres and optionally set individual name, color, and layer properties.

    Parameters
    ----------
    spheres : list of dict
        A list of sphere dictionaries.

    Returns
    -------
    list of GUID

    Notes
    -----
    A sphere dict has the following schema:

    .. code-block:: python

        Schema({
            'pos': And(list, lambda x: len(x) == 3),
            'radius': And(Or(int, float), lambda x: x > 0.0),
            Optional('name', default=''): str,
            Optional('color', default=None): And(lambda x: len(x) == 3, all(0 <= y <= 255 for y in x)),
            Optional('layer', default=None): str,
        })

    """
    guids = []
    for s in iter(spheres):
        pos = s['pos']
        radius = s['radius']
        name = s.get('name', '')
        color = s.get('color')
        layer = s.get('layer')
        sphere = Sphere(Point3d(*pos), radius)
        guid = add_sphere(sphere)
        if not guid:
            continue
        obj = find_object(guid)
        if not obj:
            continue
        attr = obj.Attributes
        if color:
            attr.ObjectColor = FromArgb(*color)
            attr.ColorSource = ColorFromObject
        else:
            attr.ColorSource = ColorFromLayer
        if layer and find_layer_by_fullpath:
            index = find_layer_by_fullpath(layer, True)
            if index >= 0:
                attr.LayerIndex = index
        attr.Name = name
        attr.WireDensity = -1
        obj.CommitChanges()
        guids.append(guid)
    return guids
Exemplo n.º 27
0
 def color(self, color):
     if not color:
         return
     if not is_sequence_of_iterable(color):
         color = [color]
     color = [
         FromArgb(*c)
         for c in iterable_like(self.faces, color, self.default_color)
     ]
     self._color = color
Exemplo n.º 28
0
 def color(self, color):
     if color:
         color[:] = [FromArgb(*color_to_rgb(c)) for c in color]
         e = self.mesh.number_of_edges()
         c = len(color)
         if c < e:
             color += [self._default_color for i in range(e - c)]
         elif c > e:
             color[:] = color[:e]
         self._color = color
Exemplo n.º 29
0
    def DrawForeground(self, e):
        _conduit_mesh_edges(self.mesh, e)

        if self.face_colordict:
            for fkey in self.face_colordict:
                color = FromArgb(*self.face_colordict[fkey])
                points = self.mesh.face_coordinates(fkey)
                points.append(points[0])
                points = [Point3d(*pt) for pt in points]
                e.Display.DrawPolygon(points, color, filled=True)
Exemplo n.º 30
0
def draw_labels(labels, **kwargs):
    """Draw labels as text dots and optionally set individual font, fontsize, name and color.

    Parameters
    ----------
    labels : list of dict
        A list of labels dictionaries.

    Returns
    -------
    list of GUID

    Notes
    -----
    A label dict has the following schema:

    .. code-block:: python

        Schema({
            'pos': And(list, lambda x: len(x) == 3),
            'text': And(str, len),
            Optional('name', default=''): str,
            Optional('color', default=None): (lambda x: len(x) == 3 and all(0 <= y <= 255 for y in x)),
            Optional('fontsize', default=10): Or(int, float),
            Optional('font', default="Arial Regular"): str
        })

    """
    guids = []
    for label in iter(labels):
        pos = label['pos']
        text = label['text']
        name = label.get('name', '')
        color = label.get('color', None)
        size = label.get('fontsize', 10)
        font = label.get('font', 'Arial Regular')
        dot = TextDot(str(text), Point3d(*pos))
        dot.FontHeight = size
        dot.FontFace = font
        guid = add_dot(dot)
        if not guid:
            continue
        obj = find_object(guid)
        if not obj:
            continue
        attr = obj.Attributes
        if color:
            attr.ObjectColor = FromArgb(*color)
            attr.ColorSource = ColorFromObject
        else:
            attr.ColorSource = ColorFromLayer
        attr.Name = name
        obj.CommitChanges()
        guids.append(guid)
    return guids