Ejemplo n.º 1
0
class Connection(FromToData, FromToJson, FromToPickle, Datastructure):
    """Wasp Connection

    """

    __module__ = 'compas_wasp'

    def __init__(self, _frame=None, _type=None, _part=None, _id=None):
        super(Connection, self).__init__()

        self.frame = _frame

        self.flip_pln = None
        if self.frame is not None:
            flip_pln_Y = self.frame.yaxis.copy()
            flip_pln_Y.scale(-1)
            self.flip_pln = Frame(self.frame.point, self.frame.xaxis,
                                  flip_pln_Y)

        self.type = _type
        self.part = _part
        self.id = _id

        self.rules_table = []
        self.active_rules = []

        ## override Rhino .ToString() method (display name of the class in Gh)
    def ToString(self):
        return "WaspConnection [id: %s, type: %s]" % (self.id, self.type)

    @property
    def data(self):
        """dict : A data dict representing the part data structure for serialisation.

        The dict has the following structure:

        * 'aaa'   => dict

        Note
        ----
        All dictionary keys are converted to their representation value (``repr(key)``)
        to ensure compatibility of all allowed key types with the JSON serialisation
        format, which only allows for dict keys that are strings.

        """
        data = {
            'f_origin':
            [self.frame.point.x, self.frame.point.y, self.frame.point.z],
            'f_xaxis':
            [self.frame.xaxis.x, self.frame.xaxis.y, self.frame.xaxis.z],
            'f_yaxis':
            [self.frame.yaxis.x, self.frame.yaxis.y, self.frame.yaxis.z],
            'type':
            self.type,
            'part':
            self.part,
            'id':
            str(self.id)
        }

        return data

    @data.setter
    def data(self, data):
        f_origin = data.get('f_origin') or []
        f_xaxis = data.get('f_xaxis') or []
        f_yaxis = data.get('f_yaxis') or []
        c_type = data.get('type') or None
        c_part = data.get('part') or None
        c_id = data.get('id') or None

        self.frame = Frame(f_origin, f_xaxis, f_yaxis)

        flip_pln_Y = self.frame.yaxis.copy()
        flip_pln_Y.scale(-1)
        self.flip_pln = Frame(self.frame.point, self.frame.xaxis, flip_pln_Y)

        self.type = c_type
        self.part = c_part
        self.id = int(c_id)

        self.rules_table = []
        self.active_rules = []

    ## return a transformed copy of the connection
    def transform(self, trans):
        pln_trans = self.frame.transformed(trans)
        conn_trans = Connection(pln_trans, self.type, self.part, self.id)
        return conn_trans

    ## return a copy of the connection
    def copy(self):
        pln_copy = self.frame.copy()
        conn_copy = Connection(pln_copy, self.type, self.part, self.id)
        return conn_copy

    ## generate the rules-table for the connection
    def generate_rules_table(self, rules):
        count = 0
        self.rules_table = []
        self.active_rules = []
        for rule in rules:
            if rule.part1 == self.part and rule.conn1 == self.id:
                self.rules_table.append(rule)
                self.active_rules.append(count)
                count += 1
Ejemplo n.º 2
0
from compas.geometry import Point, Box, Frame, Vector, Plane, scale_vector, normalize_vector, Polygon, Rotation, intersection_line_line
from compas.geometry import Transformation

frame1 = Frame(Point(0, 0), Vector(-1, 0), Vector(0, 1))
frame2 = Frame(Point(10, 0), Vector(-1, 0), Vector(0, 1))

frame3 = Frame(Point(0, 0), Vector(0, 1), Vector(1, 0))

F1 = Transformation.from_change_of_basis(frame1, frame2)

frame4 = frame3.transformed(F1)

print(frame4)
# initialize an empty assembly class
assembly = Assembly()

cf = Frame(Point(0.4, 0.4, 0.), Vector(1., 0., 0.), Vector(0., 1., 0.))

for i in range(25):  # loop through the number of layers i

    axis = cf.zaxis
    angle = math.radians(i * 3)

    # Calculates a ``Rotation`` from a rotation axis and an angle and an optional point of rotation.
    R = Rotation.from_axis_and_angle(axis, angle, point=cf.point)
    T = Translation.from_vector([0, 0, 0.005 * i])

    cft = cf.transformed(R * T)  # transforms the origin plane

    if i % 2 == 0:
        R = Rotation.from_axis_and_angle(cft.zaxis,
                                         math.radians(90),
                                         point=cft.point)
        cft = cft.transformed(R)

    add = math.sin(i / 5) * 0.015
    # print(add)

    o1 = cft.point + cft.yaxis * (0.075 + add)
    o2 = cft.point - cft.yaxis * (0.075 + add)

    f1 = Frame(o1, cft.xaxis, cft.yaxis)
    f2 = Frame(o2, cft.xaxis, cft.yaxis)