Пример #1
0
 def CalculateBox(self):
     self.box = geom.Box3D()
     for i in range(0, len(self.sketch_ids)):
         if self.curves[i] != None:
             curve_box = self.curves[i].GetBox()
             self.box.InsertBox(
                 geom.Box3D(curve_box.MinX(), curve_box.MinY(), 0.0,
                            curve_box.MaxX(), curve_box.MaxY(), 0.0))
Пример #2
0
 def MakeFromTwoPoints(self, p0, p1):
     self.p = p
     self.v = geom.Point3D(p0, p1)
     self.length = v.magnitude()
     self.box = geom.Box3D()
     self.GetBox(self.box)
     self.ok = length > geom.tolerance
Пример #3
0
 def __init__(self, type, id_named=False):
     cad.BaseObject.__init__(self, type)
     cad.PyIncref(self)
     self.box = geom.Box3D()
     self.id_named = id_named
     if self.id_named:
         self.title = self.TypeName()
         self.title_made_from_id = True
Пример #4
0
 def GetBoxWithInvisibles(self):
     self.box = geom.Box3D()
     # return the box around all the solids
     for solid in self.solids:
         object = cad.GetObjectFromId(cad.OBJECT_TYPE_STL_SOLID, solid)
         if object:
             self.box.InsertBox(object.GetBox())
     return self.box
Пример #5
0
 def GetBoxWithInvisibles(self):
     import geom
     box = geom.Box3D()
     for stock in self.GetChildren():
         b = stock.GetBoxWithInvisibles()
         if b:
             box.InsertBox(b)
     return box
Пример #6
0
 def __init__(self, viewport):
     self.viewport = viewport
     self.initial_point = wx.Point()
     self.initial_pixel_scale = 0.0
     self.perspective = 0.0
     self.section = False
     self.lens_point = geom.Point3D(0, 0, 200)
     self.target_point = geom.Point3D(0, 0, 0)
     self.vertical = geom.Point3D(0, 1, 0)
     self.pixel_scale = 10.0
     self.view_angle = 30.0
     self.projm = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
     self.modelm = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
     self.window_rect = [0, 0, 0, 0]
     self.matrix_valid = False
     self.near_plane = 0.0
     self.far_plane = 0.0
     self.extra_depth_box = geom.Box3D()
     self.extra_view_box = geom.Box3D()
Пример #7
0
 def MakeFromPointAndVector(p, v, boxed = True):
     #constructor from point & vector
     self.p = p
     self.v = v
     self.length = v.magnitude()
     self.box = None
     if boxed:
         self.box = geom.Box3D()
         self.GetBox(self.box)
     self.ok = length > geom.tolerance
Пример #8
0
 def GetBox(self):
     box = geom.Box3D()
     if self.bottom_left != None:
         box.InsertPoint(self.bottom_left.x, self.bottom_left.y,
                         self.bottom_left.z)
         box.InsertPoint(self.bottom_right.x, self.bottom_right.y,
                         self.bottom_right.z)
         box.InsertPoint(self.top_right.x, self.top_right.y,
                         self.top_right.z)
         box.InsertPoint(self.top_left.x, self.top_left.y, self.top_left.z)
     return box
Пример #9
0
 def GetBox(self):
     box = geom.Box3D()
     pitch_radius = float(self.module) * self.numTeeth * 0.5
     outside_radius = pitch_radius + (
         self.addendumMultiplier * self.module + self.addendumOffset)
     steps = 20
     angle_step = 2.0 * math.pi / steps
     angle = 0.0
     for i in range(0, 20):
         p = geom.Point3D(outside_radius * math.cos(angle),
                          outside_radius * math.sin(angle), 0.0)
         p.Transform(self.tm)
         box.InsertPoint(p.x, p.y, p.z)
         angle += angle_step
     return box
Пример #10
0
    def SetProjection2(self, use_depth_testing):
        rad = 0.0
        box = geom.Box3D()
        if use_depth_testing:
            self.viewport.cad.GetBox(box)
            box.InsertBox(self.extra_depth_box)
            box.InsertBox(self.extra_view_box)

        if use_depth_testing == False:
            self.near_plane = 0.0
            self.far_plane = 100000000.0
            rad = 2000000.0
        elif box.valid == False:
            self.near_plane = 0.2
            self.far_plane = 2000.0
            rad = 1000.0
        else:
            x, y, z = box.Centre()
            box_centre = geom.Point3D(x, y, z)
            rad = box.Radius()
            to_centre_of_box = geom.Point3D(self.lens_point, box_centre)
            f = self.forwards_vector()
            f.Normalize()
            distance = to_centre_of_box * f
            if self.section: rad = rad /100
            self.near_plane = distance - rad
            self.far_plane = distance + rad

        size = self.viewport.GetViewportSize()
        w = size.GetWidth()/self.pixel_scale
        h = size.GetHeight()/self.pixel_scale
        s = math.sqrt(w*w + h*h)
        self.near_plane = self.near_plane - s/2
        self.far_plane = self.far_plane + s/2

        hw = float(size.GetWidth())/2
        hh = float(size.GetHeight())/2
        if self.perspective:
            fovy = self.view_angle
            if h>w and w>0: fovy = 2 * 180/math.pi * math.atan( math.tan(self.view_angle/2 * math.pi/180) * h/w)
            if self.near_plane < self.far_plane / 200: self.near_plane= self.far_plane /200
            gluPerspective(fovy, w/h, self.near_plane, self.far_plane)
        else:
            glOrtho((-0.5 - hw)/self.pixel_scale, (hw+0.5)/self.pixel_scale, (-0.5-hh)/self.pixel_scale, (0.5+hh)/self.pixel_scale, self.near_plane, self.far_plane)
Пример #11
0
 def GetBox(self):
     self.box = geom.Box3D()
     for object in self.GetChildren():
         if object.GetVisible():
             self.box.InsertBox(object.GetBox())
     return self.box
Пример #12
0
def RenderGrid2(cad, view_point, max_number_across, in_between_spaces,
                miss_main_lines, bg, cc, brightness, plane_mode):
    zval = 0.5
    size = view_point.viewport.GetViewportSize()
    sp = []
    sp.append(geom.Point3D(0, 0, zval))
    sp.append(geom.Point3D(size.GetWidth(), 0, zval))
    sp.append(geom.Point3D(size.GetWidth(), size.GetHeight(), zval))
    sp.append(geom.Point3D(0, size.GetHeight(), zval))

    vx, vy, plane_mode2 = view_point.GetTwoAxes(False, plane_mode)
    datum = geom.Point3D(0, 0, 0)
    orimat = cad.GetDrawMatrix(False)
    datum.Transform(orimat)
    orimat = geom.Matrix(datum, vx, vy)
    unit_forward = view_point.forwards_vector().Normalized()
    plane_dp = math.fabs(
        geom.Point3D(0, 0, 1).Transformed(orimat) * unit_forward)
    if plane_dp < 0.3: return
    plane = geom.Plane(
        geom.Point3D(0, 0, 0).Transformed(orimat),
        geom.Point3D(0, 0, 1).Transformed(orimat))

    for i in range(0, 4):
        p1 = view_point.glUnproject(sp[i])
        sp[i].z = 0.0
        p2 = view_point.glUnproject(sp[i])
        if p1.Dist(p2) < 0.00000000001: return

        line = geom.Line(p1, p2)

        pnt = line.IntersectPlane(plane)
        if pnt != None:
            sp[i].x = (pnt * vx) - (datum * vx)
            sp[i].y = (pnt * vy) - (datum * vy)
            sp[i].z = 0.0

    b = geom.Box3D()
    for i in range(0, 4):
        b.InsertPoint(sp[i].x, sp[i].y, sp[i].z)

    width = b.Width()
    height = b.Height()
    biggest_dimension = None
    if height > width: biggest_dimension = height
    else: biggest_dimension = width
    widest_spacing = biggest_dimension / max_number_across
    dimmer = False
    dimness_ratio = 1.0
    spacing = None

    if cad.draw_to_grid:
        spacing = cad.digitizing_grid
        if miss_main_lines == False: spacing = spacing * 10
        if spacing < 0.0000000001: return
        if biggest_dimension / spacing > max_number_across * 1.5: return
        if biggest_dimension / spacing > max_number_across:
            dimmer = True
            dimness_ratio = (max_number_across * 1.5 - biggest_dimension /
                             spacing) / (max_number_across * 0.5)
    else:
        l = math.log10(widest_spacing / cad.view_units)
        intl = int(l)
        if l > 0: intl = intl + 1
        spacing = math.pow(10.0, intl) * cad.view_units

    if cad.grid_mode == 3:
        dimmer = True
        dimness_ratio = dimness_ratio * plane_dp
        dimness_ratio = dimness_ratio * plane_dp

    ext2d = [b.x[0], b.x[1], b.x[3], b.x[4]]

    for i in range(0, 4):
        intval = int(ext2d[i] / spacing)

        if i < 2:
            if ext2d[i] < 0: intval -= 1
            elif ext2d[i] > 0: intval += 1
            ext2d[i] = intval * spacing
    if cc:
        col = HeeksColor(cc.red, cc.green, cc.blue)
        if cad.grid_mode == 3:
            if plane_mode2 == 0:
                col.green = int(0.6 * float(bg.green))
            elif plane_mode2 == 1:
                col.red = int(0.9 * float(bg.red))
            else:
                col.blue = bg.blue

        if dimmer:
            d_brightness = float(brightness) * dimness_ratio
            uc_brightness = int(d_brightness)
            glColor4ub(col.red, col.green, col.blue, uc_brightness)
        else:
            glColor4ub(col.red, col.green, col.blue, brightness)

    glBegin(GL_LINES)
    extra = 0.0
    if in_between_spaces: extra = spacing * 0.5

    x = ext2d[0] - extra
    while x < ext2d[2] + extra:
        if miss_main_lines:
            xr = x / spacing / 5
            temp = xr
            if temp > 0: temp += 0.5
            else: temp -= 0.5
            temp = int(temp)
            temp = float(temp)
            if math.fabs(xr - temp) < 0.1:
                x += spacing
                continue
        temp = datum + (vx * x) + (vy * ext2d[1])
        glVertex3d(temp.x, temp.y, temp.z)
        temp = datum + (vx * x) + (vy * ext2d[3])
        glVertex3d(temp.x, temp.y, temp.z)
        x += spacing

    y = ext2d[1] - extra
    while y < ext2d[3] + extra:
        if miss_main_lines:
            yr = y / spacing / 5
            temp = yr
            if temp > 0: temp += 0.5
            else: temp -= 0.5
            temp = int(temp)
            temp = float(temp)
            if math.fabs(yr - temp) < 0.1:
                y += spacing
                continue
        temp = datum + (vx * ext2d[0]) + (vy * y)
        glVertex3d(temp.x, temp.y, temp.z)
        temp = datum + (vx * ext2d[2]) + (vy * y)
        glVertex3d(temp.x, temp.y, temp.z)
        y += spacing

    glEnd()
Пример #13
0
    def RedrawBitmap2(self, numA, numB, xshiftA, yshiftA, xshiftB, yshiftB):
        # paint a picture with Draw commands
        bitmap = wx.Bitmap(300, 200)
        dc = wx.MemoryDC(bitmap)

        # paint background
        dc.SetBrush(wx.WHITE_BRUSH)
        dc.SetPen(wx.WHITE_PEN)
        dc.DrawRectangle(0, 0, 300, 200)

        #limit numbers for the drawing
        if numA > 20: numA = 20
        if numB > 20: numB = 20

        total_x = math.fabs(xshiftA) * numA + math.fabs(xshiftB) * numB
        total_y = math.fabs(yshiftA) * numA + math.fabs(yshiftB) * numB

        box = geom.Box3D()
        box.InsertPoint(0, 0, 0)
        if numA > 0 and numB > 0:
            box.InsertPoint(xshiftA * (numA - 1), yshiftA * (numA - 1), 0)
            box.InsertPoint(xshiftB * (numB - 1), yshiftB * (numB - 1), 0)
            box.InsertPoint(xshiftA * (numA - 1) + xshiftB * (numB - 1),
                            yshiftA * (numA - 1) + yshiftB * (numB - 1), 0)

        with_margins_x = box.Width() + 2 * PATTERN_MARGIN_X
        with_margins_y = box.Height() + 2 * PATTERN_MARGIN_Y

        scale_x = 1000000000.0
        if box.Width() > 0.000000001:
            scale_x = (300.0 - 2 * PATTERN_MARGIN_X) / box.Width()
        scale_y = 1000000000.0
        if box.Height() > 0.000000001:
            scale_y = (200.0 - 2 * PATTERN_MARGIN_Y) / box.Height()

        # use the smallest scale
        scale = scale_x
        if scale_y < scale: scale = scale_y

        ox = -box.MinX()
        oy = -box.MinY()

        img = wx.Image(wx.GetApp().cam_dir + '/bitmaps/pattern/shape.png')
        img2 = wx.Image(wx.GetApp().cam_dir + '/bitmaps/pattern/shape2.png')

        num = numA
        if numB > num: num = numB
        if num > 5:
            s = (24.0 - num) / 19.0
            neww = 26.0 * s
            newh = 31.0 * s
            img.Rescale(neww, newh)
            img2.Rescale(neww, newh)

        self.shape_bitmap = wx.Bitmap(img)
        self.shape_bitmap2 = wx.Bitmap(img2)

        # draw the pattern
        for j in range(0, numB):
            for i in range(0, numA):
                x = PATTERN_MARGIN_X + (ox + i * xshiftA + j * xshiftB) * scale
                ix = x
                y = PATTERN_MARGIN_Y + (oy + i * yshiftA + j * yshiftB) * scale
                iy = 200 - y
                self.DrawPatternShape(dc, ix, iy, i == 0 and j == 0)

        dc.SelectObject(wx.NullBitmap)

        return bitmap