Esempio n. 1
0
def propagatePartToBoard(part, brd):
    """
    Copy :code:`part` to ``brd`` by creating a new :class:`Element` and populating it accordingly.
    If the part already exists, it will be replaced.  Attributes are not displayed by default, but the display layer is set to "Document".
    
    If the library for the part is missing in the board, it will be create.  If the package is missing, it will be copied.  If it exists and the package for the part and the package in the board are not the same, raise an exception.

    .. Note::
       This function doesn't update the board's signals.  You can run :meth:`rebuildBoardConnections` to do that.

    :param part: :class:`Part` object that to propagate.
    :param brd: Destination :class`BoardFile`.
    :rtype: :code:`None`

    """
    if part.find_device().get_package() is None:
        return

    if part.find_package() is None:
        raise Swoop.SwoopError(
            "Can't find package for '{}' ({}.{}.{}.{}).".format(
                part.get_name(), part.get_library(), part.get_deviceset(),
                part.get_device(), part.get_technology()))

    dst_lib = brd.get_library(part.get_library())

    if dst_lib is None:
        dst_lib = Swoop.Library().set_name(part.get_library())
        brd.add_library(dst_lib)

    #src_lib = part.find_library()
    #assert src_lib is not None, "Missing library '{}' for part '{}'".format(part.get_library(), part.get_name())

    dst_package = dst_lib.get_package(part.find_package().get_name())
    if dst_package is None:
        dst_package = part.find_package().clone()
        dst_lib.add_package(dst_package)
    else:
        assert dst_package.is_equal(part.find_package(
        )), "Package from schematic is not the same as package in board"

    # Reverse-engineered logic about setting values in board files.
    if part.find_deviceset().get_uservalue():
        fallback_value = ""
    else:
        fallback_value = part.get_deviceset() + part.get_device()

    n = (Swoop.Element().set_name(part.get_name()).set_library(
        part.get_library()).set_package(
            part.find_package().get_name()).set_value(part.get_value(
            ) if part.get_value() is not None else fallback_value).set_x(
                0).set_y(0))

    for a in part.find_technology().get_attributes():
        n.add_attribute(a.clone().set_display("off").set_layer("Document"))

    for a in part.get_attributes():
        n.add_attribute(a.clone().set_display("off").set_layer("Document"))

    brd.add_element(n)
Esempio n. 2
0
def consolidate_parts_in_schematic(schematic,
                                   lib_name,
                                   part_names=None,
                                   ignore_conflicts=False):
    """
    Create a new library called :code:`lib_name` in :code:`schematic` that the
    information for the parts listed in :code:`part_names`.  Check for
    conflicting names.

    Update the parts to refer to the new libray. 

    Warning:  This will make the schematic inconsistent with the board (if one exists).

    :param schematic: A :class:`SchematicFile` object to operate on.
    :param lib_name: The name of the new library.
    :param part_names: An array of part names (i.e., reference designators).  If :code:`None` then do all the parts.  Defaults to :code:`None`.
    :returns:  Nothing.
    """

    if schematic.get_library(lib_name) is None:
        lib = Swoop.Library().set_name(lib_name)
        schematic.add_library(lib)
    else:
        lib = schematic.get_library(lib_name)

    src_lib = {}

    def check_for_conflicts(name, lib):
        if name in src_lib:
            assert src_lib[name] == lib, "Name '{}' in both {} and {}".format(
                name, lib, src_lib[name])
        else:
            src_lib[name] = lib

    for p in Swoop.From(schematic).get_parts().filtered_by(
            lambda x: part_names is None or x.get_name() in part_names):
        package = p.find_device().find_package()
        if package is not None:
            if not ignore_conflicts:
                check_for_conflicts(package.get_name(), p.get_library())

        for s in Swoop.From(p).find_deviceset().get_gates().find_symbol():
            if not ignore_conflicts:
                check_for_conflicts(s.get_name(), p.get_library())

        if not ignore_conflicts:
            check_for_conflicts(p.find_deviceset().get_name(), p.get_library())

        copy_deviceset(p.find_deviceset(), lib)

        p.set_library(lib_name)

    return lib