Пример #1
0
def get_lowest_curve_info(brep, h_tol):
    #right now hardcoded to not deal with multiple breps at the final step. to revise if needed.
    bdims = wge.get_bounding_dims(brep)
    brep_faces = wge.get_extreme_srf(brep, h_tol, False)

    crvs_by_brep = []

    for f in brep_faces:
        crvs = []
        inds = f.AdjacentEdges()
        for i in inds:
            k = brep.Edges
            crvs.append(brep.Edges[i])
        crvs = Rhino.Geometry.Curve.JoinCurves(crvs, D_TOL)
    crvs_by_brep.append(crvs)

    crvs_by_brep = crvs_by_brep[
        0]  #to fix this later. only deals w one brep for now
    list_curves = []
    for pc in crvs_by_brep:
        if pc.GetType() != Rhino.Geometry.PolyCurve:
            pc = wru.polylinecurve_to_polycurve(pc)

        wge.make_pcurve_ccw(pc)
        list_curves.append(pc)

    return [list_curves, bdims]
Пример #2
0
def get_section_curve_info_multi_no_ortho(brep, plane):
    """returns the curve outline, the bounding dims, and the plane where the curve was cut"""
    #set height
    bdims = wge.get_bounding_dims(brep)
    g_polycurves = wge.get_brep_plan_cut_use_plane(brep, plane, D_TOL)
    #g_polycurve = g_polycurves[0]

    list_curves = []
    for pc in g_polycurves:
        if pc.GetType() != Rhino.Geometry.PolyCurve:
            pc = wru.polylinecurve_to_polycurve(pc)

        wge.make_pcurve_ccw(pc)
        list_curves.append(pc)

    #plane1 is where the section curve gets built. will be at the midheight.
    return [list_curves, bdims]
Пример #3
0
def get_brep_sides_info(brep, material_thickness):
    #Dimensions as a namedtuple type.
    Dimensions = namedtuple('Dimensions', 'x y')

    height = wge.get_brep_height(brep)
    g_polycurves = wge.get_brep_plan_cut(brep, height / 2,
                                         D_TOL)  #get plan cut at mid-height
    g_polycurve = g_polycurves[
        0]  #extract the first curve, we assume there will only be one curve.
    top_label_pt = get_brep_labelpt(brep, 0.15)

    if g_polycurve.GetType() == Rhino.Geometry.PolyCurve:
        wge.make_pcurve_ccw(g_polycurve)
    else:
        g_polycurve = wru.polylinecurve_to_polycurve(g_polycurve)
        wge.make_pcurve_ccw(g_polycurve)

    startpts, endpts, divpts = wge.get_polycurve_segment_points(g_polycurve)
    g_polyline = wru.polycurve_to_polyline(g_polycurve,
                                           doc.ModelAbsoluteTolerance,
                                           doc.ModelAngleToleranceDegrees)
    seg_count = g_polycurve.SegmentCount

    angles = wge.get_internal_angles(startpts)

    for i, point in enumerate(divpts):
        k = rs.AddTextDot(i, point)
        rs.ObjectLayer(k, "XXX_LCUT_00-GUIDES")

    #get output info
    piece_dims = []
    for i in xrange(seg_count):

        corner_angles = (angles[i], angles[(i + 1) % seg_count])
        #print corner_angles

        seg = g_polycurve.SegmentCurve(i)
        seg_len = seg.GetLength()
        if i % 2 == 0:
            #print "dir 1"
            for angle in corner_angles:
                if abs((angle - 90)) < 0.1:
                    seg_len -= material_thickness
        if i % 2 == 1:
            #print "dir 2"
            #print corner_angles
            for angle in corner_angles:
                if abs((angle - 270)) < 0.1:
                    seg_len += material_thickness
        this_piece_dims = Dimensions(seg_len, height)
        piece_dims.append(this_piece_dims)

    xdim = 0
    ydim = height

    for i, dim in enumerate(piece_dims):
        if (i != len(piece_dims) - 1):
            xdim += GAP_SIZE + dim[0]

    label_numbers = list(range(len(piece_dims)))

    bounding_dims = Dimensions(xdim, ydim)

    SidesInfo = namedtuple('SidesInfo',
                           'dims labelNums boundingDims topLabelPt')
    out_sides_info = SidesInfo(piece_dims, label_numbers, bounding_dims,
                               top_label_pt)

    return out_sides_info
Пример #4
0
def get_brep_lid_info(brep, start_index, material_thickness):
    #get bounding box
    bb = rs.BoundingBox(brep)
    if bb:
        for i, point in enumerate(bb):
            pass
            #rs.AddTextDot(i,point)

    #set height
    height = wge.get_brep_height(brep)
    top_crv = rs.AddPolyline([bb[4], bb[5], bb[6], bb[7], bb[4]])
    bottom_crv = rs.AddPolyline([bb[0], bb[1], bb[2], bb[3], bb[0]])
    top_label_pt, _ = rs.CurveAreaCentroid(top_crv)
    bottom_label_pt, _ = rs.CurveAreaCentroid(bottom_crv)
    rs.DeleteObjects([top_crv, bottom_crv])

    #add text dots
    d1 = rs.AddTextDot(str(start_index), top_label_pt)
    d2 = rs.AddTextDot(str(start_index + 1), bottom_label_pt)
    rs.ObjectLayer([d1, d2], "XXX_LCUT_00-GUIDES")

    #get middle section and get polycurve

    g_polycurves = wge.get_brep_plan_cut(brep, height / 2,
                                         D_TOL)  #get plan cut at mid-height
    g_polycurve = g_polycurves[
        0]  #extract the first curve, we assume there will only be one curve.

    seg_count = 0

    if g_polycurve.GetType() == Rhino.Geometry.PolyCurve:
        wge.make_pcurve_ccw(g_polycurve)
    else:
        g_polycurve = wru.polylinecurve_to_polycurve(g_polycurve)
        wge.make_pcurve_ccw(g_polycurve)

    startpts, endpts, divpts = wge.get_polycurve_segment_points(g_polycurve)
    g_polyline = wru.polycurve_to_polyline(g_polycurve,
                                           doc.ModelAbsoluteTolerance,
                                           doc.ModelAngleToleranceDegrees)
    seg_count = g_polycurve.SegmentCount

    g_polycurve_lid = offset_pcurve(g_polycurve, material_thickness)

    #convert to polyline if needed.
    if g_polycurve.GetType() == Rhino.Geometry.PolylineCurve:
        g_polyline = wru.polycurve_to_polyline(g_polycurve_lid,
                                               doc.ModelAbsoluteTolerance,
                                               doc.ModelAngleToleranceDegrees)
    else:
        g_polyline = g_polycurve_lid

    crv_bbox = g_polyline.GetBoundingBox(False)
    if not crv_bbox.IsValid:
        return Rhino.Commands.Result.Failure

    #Print the min and max box coordinates in world coordinates
    Rhino.RhinoApp.WriteLine("World min: {0}", crv_bbox.Min)
    Rhino.RhinoApp.WriteLine("World max: {0}", crv_bbox.Max)

    pt_origin = crv_bbox.Corner(True, True, True)
    pt_x_axis = crv_bbox.Corner(False, True, True)
    pt_y_axis = crv_bbox.Corner(True, False, True)
    plane1 = rs.PlaneFromPoints(pt_origin, pt_x_axis, pt_y_axis)
    plane2 = rs.PlaneFromPoints([0, 0, 0], [1, 0, 0], [0, 1, 0])

    transformation = Rhino.Geometry.Transform.ChangeBasis(
        rs.coerceplane(plane2), rs.coerceplane(plane1))

    g_polyline.Transform(transformation)

    dims = [
        rs.Distance(pt_origin, pt_x_axis),
        rs.Distance(pt_origin, pt_y_axis)
    ]
    #print g_polyline.PointCount
    Dimensions = namedtuple('Dimensions', 'x y')
    dims = Dimensions(rs.Distance(pt_origin, pt_x_axis),
                      rs.Distance(pt_origin, pt_y_axis))

    SidesInfo = namedtuple(
        'SidesInfo', 'outline dims')  #dims are bounding dims for the curve
    out_sides_info = SidesInfo(g_polyline, dims)

    return out_sides_info
Пример #5
0
def rc_get_tags(curves):

    global LCUT_INDICES
    LCUT_INDICES = wla.get_lcut_layers()

    text_buffer = 0
    if PREFIX != None:
        text_buffer = 0.2 * len(PREFIX) * TEXTSIZE

    fi = sc.doc.Fonts.FindOrCreate("MecSoft_Font-1", True, False)
    [wge.make_pcurve_ccw(c) for c in curves]
    offset_curves = [
        offset_pcurve(c, 1.4 * TEXTSIZE + text_buffer) for c in curves
    ]
    centroids = [
        c.GetBoundingBox(rs.WorldXYPlane()).Center for c in offset_curves
    ]

    curve_collection = zip(centroids, offset_curves)
    curve_collection = sorted(curve_collection, sortcompare)
    _, offset_curves = zip(*curve_collection)

    tt_locations = []
    td_locations = []
    for c in offset_curves:
        #j = add_curve_to_layer(c,LCUT_INDICES[1]) #uncomment for preview
        bb = c.GetBoundingBox(rs.WorldXYPlane())
        ll_corner = bb.Corner(True, True, True)
        v = rs.VectorCreate([0, 0, 0], [1, 1, 0])
        extremes = c.ExtremeParameters(v)

        thept = None
        for i, pt in enumerate(extremes):
            pointat = c.PointAt(extremes[i])
            if thept is not None:
                if pointat.Y < thept.Y: thept = pointat
            else:
                thept = pointat
        tt_locations.append(thept)

        td_locations.append(bb.Center)

    text_guids = []
    dot_guids = []

    tt_text = []
    for i in xrange(len(tt_locations)):
        text = PREFIX + str(i) if PREFIX != None else str(i)
        tt_text.append(text)

    if MODE != "TextDots":
        text_guids = wfa.add_fab_tags(
            tt_locations, tt_text, TEXTSIZE,
            Rhino.Geometry.TextJustification.MiddleLeft)
    if MODE != "Curves":
        dot_guids = [
            rs.AddTextDot(tt_text[i], td_locations[i])
            for i in xrange(len(tt_text))
        ]

    for id in text_guids:
        rs.ObjectLayer(id, "XXX_LCUT_03-LSCORE")
    for id in dot_guids:
        rs.ObjectLayer(id, "XXX_LCUT_00-GUIDES")

    if len(text_guids) > 0: [rs.SelectObjects(x) for x in text_guids]
    if len(dot_guids) > 0: [rs.SelectObjects(x) for x in dot_guids]
    sc.doc.Views.Redraw()