Beispiel #1
0
def InputAngleWithPlane(angle, axis, pos, ncopies, axial_shift, title):
    axis_type = 0  # not one of the three
    if axis == geom.Point3D(0, 0, 1): axis_type = 1
    elif axis == geom.Point3D(0, -1, 0): axis_type = 2
    elif axis == geom.Point3D(1, 0, 0): axis_type = 3

    while (True):
        dlg = AngleAndPlaneDlg(angle, axis, axis_type, pos, ncopies,
                               axial_shift, title)
        ret = dlg.ShowModal()
        angle, axis, axis_type, pos, ncopies, axial_shift = dlg.GetAllValues()

        if ret == wx.ID_OK:
            return True, angle, axis, pos, ncopies, axial_shift
        elif ret == dlg.rbXy.GetId():
            continue
        elif ret == dlg.rbXz.GetId():
            continue
        elif ret == dlg.rbYz.GetId():
            continue
        elif ret == dlg.rbOther.GetId():
            continue
        elif ret == dlg.btnPick.GetId():
            p = wx.GetApp().PickPosition("Pick Position To Rotate About")
            if p != None: pos = p
        elif ret == dlg.btnVectorPick.GetId():
            p = wx.GetApp().PickPosition("Pick Position On Rotation Axis")
            if p != None:
                v = p - pos
                if v.Length() < 0.01:
                    wx.MessageBox('Axis Point Too Close to Position')
            else:
                axis = v.Normalized()
        else:
            return False, None, None, None, None, None
Beispiel #2
0
 def GetTwoAxes(self, flattened_onto_screen, plane):
     plane_mode = self.ChooseBestPlane(plane)
     orimat = self.viewport.cad.GetDrawMatrix(False)
     if plane_mode == 0:
         vx = geom.Point3D(1, 0, 0).Transformed(orimat)
         vy = geom.Point3D(0, 1, 0).Transformed(orimat)
     elif plane_mode == 1:
         vx = geom.Point3D(1, 0, 0).Transformed(orimat)
         vy = geom.Point3D(0, 0, 1).Transformed(orimat)
     elif plane_mode == 2:
         vx = geom.Point3D(0, 1, 0).Transformed(orimat)
         vy = geom.Point3D(0, 0, 1).Transformed(orimat)
     # find closest between vx and vy to screen y
     dpx = vx * self.vertical
     dpy = vy * self.vertical
     if math.fabs(dpx) > math.fabs(dpy):
         vtemp = geom.Point3D(vx.x, vx.y, vx.z)
         vx = vy
         vy = vtemp
     # make sure vz is towards us
     if (vx ^ vy ) * self.forwards_vector() > 0:
         vx = -vx
     if flattened_onto_screen:
         f = self.forwards_vector().Normalized()
         vx = geom.Point3D(vx - (f * (f * vx))).Normalized()
         vy = geom.Point3D(vy - (f * (f * vy))).Normalized()
         r = rightwards_vector()
         if math.fabs(vy * r) > math.fabs(vx * r):
             vtemp = geom.Point3D(vx.x, vx.y, vx.z)
             vx = vy
             vy = vtemp
     return vx, vy, plane_mode
Beispiel #3
0
def InputMirrorPlane(axis, pos, copy, title):
    axis_type = 0  # not one of the three
    if axis == geom.Point3D(1, 0, 0): axis_type = 1
    elif axis == geom.Point3D(0, 1, 0): axis_type = 2
    elif axis == geom.Point3D(0, 0, 1): axis_type = 3

    while (True):
        dlg = MirrorDlg(axis, pos, axis_type, copy, title)
        ret = dlg.ShowModal()
        axis, pos, axis_type, copy = dlg.GetAllValues()

        if ret == wx.ID_OK:
            return True, axis, pos, copy
        elif ret == dlg.rbH.GetId():
            continue
        elif ret == dlg.rbV.GetId():
            continue
        elif ret == dlg.rbZ.GetId():
            continue
        elif ret == dlg.rbOther.GetId():
            continue
        elif ret == dlg.btnPick.GetId():
            p = wx.GetApp().PickPosition("Pick Position To Mirror About")
            if p != None: pos = p
        elif (dlg.btnVectorPick != None) and (ret
                                              == dlg.btnVectorPick.GetId()):
            p = wx.GetApp().PickPosition("Pick Position On Mirror Axis")
            if p != None:
                v = p - pos
                if v.Length() < 0.01:
                    wx.MessageBox('Axis Point Too Close to Position')
                else:
                    axis = v.Normalized()
        else:
            return False, None, None, None
Beispiel #4
0
    def OnGlCommands(self, select, marked, no_color):
        if self.texture_number == None:
            image = wx.Image(self.filepath)
            if not image.IsOk():
                self.texture_number = 0
                return

            self.width = image.GetWidth()
            self.height = image.GetHeight()
            if self.bottom_left == None:
                self.bottom_left = geom.Point3D(0, 0, 0)
                self.bottom_right = geom.Point3D(self.width, 0, 0)
                self.top_right = geom.Point3D(self.width, self.height, 0)
                self.top_left = geom.Point3D(0, self.height, 0)
            self.texture_number, self.textureWidth = cad.GenTexture(
                image.GetData(), None, self.width, self.height,
                image.HasAlpha())

        if self.texture_number == 0:
            return

        if self.bottom_left != None:
            cad.DrawImageQuads(self.width, self.height, self.textureWidth,
                               self.texture_number, self.bottom_left,
                               self.bottom_right, self.top_right,
                               self.top_left, self.opacity, no_color, marked)
Beispiel #5
0
    def GetAllValues(self):
        angle = self.angle_ctrl.GetValue()
        if self.rbXy.GetValue():
            axis = geom.Point3D(0, 0, 1)
            axis_type = 1
        elif self.rbXz.GetValue():
            axis = geom.Point3D(0, -1, 0)
            axis_type = 2
        elif self.rbYz.GetValue():
            axis = geom.Point3D(1, 0, 0)
            axis_type = 3
        else:
            if self.vectorx == None:
                axis = self.axis
            else:
                axis = geom.Point3D(self.vectorx.GetValue(),
                                    self.vectory.GetValue(),
                                    self.vectorz.GetValue())
            axis_type = 0
        pos = geom.Point3D(self.posx.GetValue(), self.posy.GetValue(),
                           self.posz.GetValue())

        ncopies = None
        if self.ncopies:
            ncopies = int(self.txt_num_copies.GetValue())

        axial_shift = self.axial_shift_ctrl.GetValue()

        return angle, axis, axis_type, pos, ncopies, axial_shift
Beispiel #6
0
 def AddPoint(self, d):
     if (self.drawing_mode == LineDrawingMode) or (self.drawing_mode
                                                   == ArcDrawingMode):
         # edit the end of the previous item to be the start of the arc
         # this only happens if we are drawing tangents to other objects
         # really need to fill the gap with whatever we are tangent around
         # ellipse,arc,spline or whatever
         if (self.TempObject() != None) and (self.prev_object != None):
             if (self.prev_object != None):
                 spos = self.TempObject().GetStartPoint()
                 epos = self.prev_object.GetEndPoint()
                 tanobject = self.start_pos.GetObject1()
                 if self.start_pos.type == cad.DigitizeType.DIGITIZE_TANGENT_TYPE and (
                         tanobject != None):
                     if tanobject.GetType() == cad.OBJECT_TYPE_SKETCH_LINE:
                         #((HLine*)prev_object)->B = p;
                         pass
                     elif tanobject.GetType() == cad.OBJECT_TYPE_SKETCH_ARC:
                         tanobject.A = geom.Point3D(spos)
                         tanobject.B = geom.Point3D(epos)
                         self.AddToTempObjects(tanobject)
                     elif tanobject.GetType() == cad.OBJECT_TYPE_CIRCLE:
                         arc = cad.NewArc(spos, epos, tanobject.axis,
                                          tanobject.C)
                         arc.A = geom.Point3D(spos)
                         arc.B = geom.Point3D(epos)
                         self.AddToTempObjects(arc)
     Drawing.AddPoint(self, d)
Beispiel #7
0
 def __init__(self, sketch=0):
     SketchOp.__init__(self, sketch)
     self.tool_on_side = PROFILE_LEFT_OR_OUTSIDE
     self.cut_mode = PROFILE_CLIMB
     self.auto_roll_radius = 2.0
     self.auto_roll_on = True
     self.auto_roll_off = True
     self.roll_on_point = geom.Point3D(0, 0, 0)
     self.roll_off_point = geom.Point3D(0, 0, 0)
     self.start_given = False
     self.end_given = False
     self.start = geom.Point3D(0, 0, 0)
     self.end = geom.Point3D(0, 0, 0)
     self.sort_sketches = True
     self.tags = None
     self.offset_extra = 0.0
     self.do_finishing_pass = False
     self.only_finishing_pass = False
     self.finishing_h_feed_rate = 100.0
     self.finishing_cut_mode = PROFILE_CONVENTIONAL
     self.finishing_step_down = 1.0
     self.end_beyond_full_profile = False
     self.extend_at_start = 0.0
     self.extend_at_end = 0.0
     self.lead_in_line_len = 0.0
     self.lead_out_line_len = 0.0
Beispiel #8
0
 def CopyFrom(self, o):
     self.filepath = o.filepath
     self.bottom_left = geom.Point3D(o.bottom_left)
     self.bottom_right = geom.Point3D(o.bottom_right)
     self.top_right = geom.Point3D(o.top_right)
     self.top_left = geom.Point3D(o.top_left)
     self.opacity = o.opacity
     Object.CopyFrom(self, o)
Beispiel #9
0
def AddTriangleToSketch(x0, y0, z0, x1, y1, z1, x2, y2, z2):
    p0 = geom.Point3D(x0, y0, z0)
    p1 = geom.Point3D(x1, y1, z1)
    p2 = geom.Point3D(x2, y2, z2)
    if p0 == p1:
        return
    if p1 == p2:
        return
    if p2 == p0:
        return
    stl_to_add_to.Add(p0, p1, p2)
Beispiel #10
0
def Mirror():
    if cad.GetNumSelected() == 0:
        wx.GetApp().PickObjects('Pick objects to mirror')

    if cad.GetNumSelected() == 0:
        return

    config = HeeksConfig()

    selected_items = cad.GetSelectedObjects()

    cad.ClearSelection(False)

    copy = config.ReadBool("MirrorCopy", False)
    axis = geom.Point3D(0, 0, 1)
    pos = geom.Point3D(0, 0, 0)
    axis.x = config.ReadFloat("MirrorAxisX", 1.0)
    axis.y = config.ReadFloat("MirrorAxisY", 0.0)
    axis.z = config.ReadFloat("MirrorAxisZ", 0.0)
    pos.x = config.ReadFloat("MirrorPosX", 0.0)
    pos.y = config.ReadFloat("MirrorPosY", 0.0)
    pos.z = config.ReadFloat("MirrorPosZ", 0.0)

    result, axis, pos, copy = InputMirrorPlane(axis, pos, copy, 'Mirror')
    if not result:
        return

    config.WriteBool("MirrorCopy", copy)
    config.WriteFloat("MirrorAxisX", axis.x)
    config.WriteFloat("MirrorAxisY", axis.y)
    config.WriteFloat("MirrorAxisZ", axis.z)
    config.WriteFloat("MirrorPosX", pos.x)
    config.WriteFloat("MirrorPosY", pos.y)
    config.WriteFloat("MirrorPosZ", pos.z)

    cad.StartHistory()

    mat = geom.Matrix()
    x, y = axis.ArbitraryAxes()
    axis_mat = geom.Matrix(pos, x, y)
    inv_mat = axis_mat.Inverse()
    mat.Multiply(inv_mat)  # transform so axis goes to z axis
    mat.Scale3(1.0, 1.0, -1.0)  # mirror in z axis
    mat.Multiply(axis_mat)  # transform back to where it was
    for object in selected_items:
        if copy:
            if object.CanBeCopied():
                object = object.MakeACopy()
                object.Transform(mat)
                cad.AddUndoably(object)
        else:
            cad.TransformUndoably(object, mat)

    cad.EndHistory()
Beispiel #11
0
    def OnGlCommands(self, select, marked, no_color):
        if marked and not select:
            tool = Tool.FindTool(self.tool_number)
            if tool == None:
                return
            radius = tool.CuttingRadius(True)
            global circle_sketch
            global arc1
            global arc2

            # get 3d position from the point objects, sorted by distance from camera
            forwards = wx.GetApp(
            ).frame.graphics_canvas.viewport.view_point.Forwards()
            lens_point = wx.GetApp(
            ).frame.graphics_canvas.viewport.view_point.lens_point
            posns = []
            for point in self.points:
                object = cad.GetObjectFromId(cad.OBJECT_TYPE_POINT, point)
                if object == None:
                    continue
                pos = object.GetStartPoint()
                dotp = (lens_point - pos) * forwards
                posns.append(DotpAndPos(dotp, pos))

            posns = sorted(posns)

            for dotp_and_pos in posns:
                pos = dotp_and_pos.pos
                p0 = pos + geom.Point3D(-radius, 0, 0)
                p1 = pos + geom.Point3D(radius, 0, 0)

                if circle_sketch == None:
                    circle_sketch = cad.NewSketch()
                    arc1 = cad.NewArc(p0, p1, geom.Point3D(0, 0, 1), pos)
                    arc2 = cad.NewArc(p1, p0, geom.Point3D(0, 0, 1), pos)
                    circle_sketch.Add(arc1)
                    circle_sketch.Add(arc2)
                else:
                    arc1.SetStartPoint(p0)
                    arc1.SetEndPoint(p1)
                    arc1.SetCentrePoint(pos)
                    arc2.SetStartPoint(p1)
                    arc2.SetEndPoint(p0)
                    arc2.SetCentrePoint(pos)

                cad.Material(cad.Color(255, 255, 0)).glMaterial(1.0)
                cad.DrawEnableLighting()
                cad.DrawDisableDepthTesting()
                cad.DrawEnableCullFace()
                cad.Sketch.RenderAsExtrusion(circle_sketch, self.start_depth,
                                             self.final_depth)
                cad.DrawDisableCullFace()
                cad.DrawEnableDepthTesting()
                cad.DrawDisableLighting()
Beispiel #12
0
 def add_arc(self, x, y, z, i, j, k, r = None, d = None):
     arc = cam.NewPathArc()
     arc.c = geom.Point3D(self.oldp)
     if i != None: arc.c.x = float(i) - self.oldp.x
     if j != None: arc.c.y = float(j) - self.oldp.y
     if k != None: arc.c.z = float(k) - self.oldp.z
     if x != None: self.oldp.x = float(x)
     if y != None: self.oldp.y = float(y)
     if z != None: self.oldp.z = float(z)
     arc.point = geom.Point3D(self.oldp)
     if r != None: arc.radius = float(r)
     if d != None: arc.dir = int(d)
     self.current_path.AddPathObject(arc)
Beispiel #13
0
    def GetMatrices(self, matrices):
        m2 = geom.Matrix()
        shift_m2 = geom.Matrix()
        shift_m2.Translate(geom.Point3D(self.x_shift2, self.y_shift2, 0.0))
        shift_m1 = geom.Matrix()
        shift_m1.Translate(geom.Point3D(self.x_shift1, self.y_shift1, 0.0))

        for j in range(0, self.copies2):
            m = geom.Matrix(m2)
            for i in range(0, self.copies1):
                matrices.append(m)
                m = m * shift_m1
            m2 = m2 * shift_m2
Beispiel #14
0
def GetTmFromCurve(curve):
    if curve == None:
        return
    ps = GetMinXPoint(curve)
    pe = GetMaxXPoint(curve)
    vx = pe - ps
    vx.Normalize()
    vy = ~vx
    o = geom.Point3D(ps.x, ps.y, 0.0)
    vvx = geom.Point3D(vx.x, vx.y, 0.0)
    vvy = geom.Point3D(vy.x, vy.y, 0.0)
    tm = geom.Matrix(o, vvx, vvy)
    return tm.Inverse()
Beispiel #15
0
    def CalculatePolygon(self, p0, p1, zdir):
        if p0 == p1:
            return
        
        if self.TempObject() == None:
            return

        if self.TempObject().GetNumChildren() != self.number_of_side_for_polygon:
            self.ClearSketch()
            
        lines = []

        if self.TempObject().GetNumChildren() > 0:
            object = self.TempObject().GetFirstChild()
            for i in range(0, self.number_of_side_for_polygon):
                lines.append(object)
                object = self.TempObject().GetNextChild()
        else:
            for i in range(0, self.number_of_side_for_polygon):
                line = cad.NewLine(geom.Point3D(0, 0, 0), geom.Point3D(0, 0, 0))
                lines.append(line)
                self.TempObject().Add(line)

        radius = p0.Dist(p1)
        sideAngle=0
        
        if self.polygon_inscribed:
            # inscribed circle
            sideAngle = 2.0 * math.pi / self.number_of_side_for_polygon
            radius = radius/math.cos(sideAngle/2)
            for i in range(0, self.number_of_side_for_polygon):
                xdir = p1 - p0
                xdir.Normalize()
                ydir = zdir ^ xdir
                angle0 = (sideAngle * i)+(sideAngle/2)
                angle1 = (sideAngle * (i+1))+(sideAngle/2)
                lines[i].A = p0 + xdir * ( math.cos(angle0) * radius ) + ydir * ( math.sin(angle0) * radius )
                if i == self.number_of_side_for_polygon - 1: lines[i].B = lines[0].A
                lines[i].B = p0 + xdir * ( math.cos(angle1) * radius ) + ydir * ( math.sin(angle1) * radius )

        else:
            # excribed circle
            for i in range(0, self.number_of_side_for_polygon):
                xdir = p1 - p0
                xdir.Normalize()
                ydir = zdir ^ xdir
                angle0 = 2.0 * math.pi / self.number_of_side_for_polygon * i
                angle1 = 2.0 * math.pi / self.number_of_side_for_polygon * (i+1)
                lines[i].A = p0 + xdir * ( math.cos(angle0) * radius ) + ydir * ( math.sin(angle0) * radius )
                if i == self.number_of_side_for_polygon - 1: lines[i].B = lines[0].A
                lines[i].B = p0 + xdir * ( math.cos(angle1) * radius ) + ydir * ( math.sin(angle1) * radius )
Beispiel #16
0
def RenderGrid(cad, view_point, plane=0):
    if cad.grid_mode == 1:
        cc = cad.background_color[0].best_black_or_white()
        v_bg = geom.Point3D(bg.red, bg.green, bg.blue)
        v_cc = geom.Point3D(cc.red, cc.green, cc.blue)
        v_contrast = v_cc - v_bg
        unit_contrast = v_contrast.Normalized()
        l1, l2, l3 = 100, 0, 10
        if v_cc * geom.Point3D(1, 1, 1) > 0: l1, l2, l3 = 200, 130, 80

        if l1 > v_contrast.Magnitude(): l1 = v_contrast.Magnitude()
        if l2 > v_contrast.Magnitude(): l2 = v_contrast.Magnitude()
        if l3 > v_contrast.Magnitude(): l3 = v_contrast.Magnitude()
        uf = (view_point.forwards_vector()).Normalized()
        vx, vy = view_point.GetTwoAxes(false, plane)
        datum = geom.Point3D(0, 0, 0)
        orimat = cad.GetDrawMatrix(False)
        datum = datum.Transformed(orimat)
        orimat = make_matrix(datum, vx, vy)
        v_up = geom.Point3D(0, 0, 1).Transformed(orimat)
        fufz = math.fabs(uf * v_up)
        if fufz < 0.7:
            there = (fufz - 0.3) / 0.4
            l1 *= there
            l2 *= there

        v_gc1 = v_bg + unit_contrast * l1
        v_gc2 = v_bg + unit_contrast * l2
        v_gc3 = v_bg + unit_contrast * l3

        glColor3ub(v_gc3.x, v_gc3.y, v_gc3.z)
        RenderGrid2(cad, view_point, 200, False, True, None, None, 0, plane)
        glColor3ub(v_gc2.x, v_gc2.y, v_gc2.z)
        RenderGrid2(cad, view_point, 20, True, False, None, None, 0, plane)
        glColor3ub(v_gc1.x, v_gc1.y, v_gc1.z)
        RenderGrid2(cad, view_point, 20, False, False, None, None, 0, plane)

    elif cad.grid_mode == 2 or cad.grid_mode == 3:
        bg = cad.background_color[0]
        cc = bg.best_black_or_white()
        light_color = ((cc.red + cc.green + cc.blue) > 384)
        cad.EnableBlend()
        RenderGrid2(cad, view_point, 200, False, True, bg, cc,
                    40 if light_color else 10, plane)
        RenderGrid2(cad, view_point, 20, True, False, bg, cc,
                    80 if light_color else 20, plane)
        RenderGrid2(cad, view_point, 20, False, False, bg, cc,
                    120 if light_color else 30, plane)
        cad.DisableBlend()
Beispiel #17
0
def Scale():
    centre_Pos = geom.Point3D(0, 0, 0)

    if cad.GetNumSelected() == 0:
        wx.GetApp().PickObjects('Pick objects to scale')

    if cad.GetNumSelected() == 0:
        return

    config = HeeksConfig()

    selected_items = cad.GetSelectedObjects()

    cad.ClearSelection(False)

    scale_factor = config.ReadFloat('ScaleFactor', 1.0)
    copy = config.ReadBool("ScaleCopy", False)
    pos = geom.Point3D(0, 0, 0)
    pos.x = config.ReadFloat("ScaleAboutPosX", 0.0)
    pos.y = config.ReadFloat("ScaleAboutPosY", 0.0)
    pos.z = config.ReadFloat("ScaleAboutPosZ", 0.0)

    result, pos, scale_factor, copy = InputScale(pos, scale_factor, copy,
                                                 'Scale')
    if not result:
        return

    config.WriteFloat("ScaleFactor", scale_factor)
    config.WriteBool("ScaleCopy", copy)
    config.WriteFloat("ScaleAboutPosX", pos.x)
    config.WriteFloat("ScaleAboutPosY", pos.y)
    config.WriteFloat("ScaleAboutPosZ", pos.z)

    cad.StartHistory()

    mat = geom.Matrix()
    mat.Translate(-pos)
    mat.Scale(scale_factor)
    mat.Translate(pos)
    for object in selected_items:
        if copy:
            if object.CanBeCopied():
                object = object.MakeACopy()
                object.Transform(mat)
                cad.AddUndoably(object)
        else:
            cad.TransformUndoably(object, mat)

    cad.EndHistory()
Beispiel #18
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
Beispiel #19
0
    def construct_from_3_points(self, origin, x_axis, y_axis):
        unit_x = x_axis
        unit_x.Normalize()

        t = unit_x.x * y_axis.x + unit_x.y * y_axis.y + unit_x.z * y_axis.z
        y_orthogonal = geom.Point3D(y_axis.x - unit_x.x * t,
                                    y_axis.y - unit_x.y * t,
                                    y_axis.z - unit_x.z * t)

        unit_y = copy.deepcopy(y_orthogonal)
        unit_y.Normalize()
        unit_z = unit_x ^ y_orthogonal
        unit_z.Normalize()

        self.m = []
        self.m.append(unit_x.x)
        self.m.append(unit_y.x)
        self.m.append(unit_z.x)
        self.m.append(origin.x)
        self.m.append(unit_x.y)
        self.m.append(unit_y.y)
        self.m.append(unit_z.y)
        self.m.append(origin.y)
        self.m.append(unit_x.z)
        self.m.append(unit_y.z)
        self.m.append(unit_z.z)
        self.m.append(origin.z)
        self.m.append(0)
        self.m.append(0)
        self.m.append(0)
        self.m.append(1)
Beispiel #20
0
    def OnSetOriginPoints(self, three_points):
        mat = cad.GetDrawMatrix(False)
        o = geom.Point3D(0,0,0).Transformed(mat)
        x = geom.Point3D(1,0,0).Transformed(mat) - o
        y = geom.Point3D(0,1,0).Transformed(mat) - o
        new_object = cad.NewCoordinateSystem("Coordinate System", o, x, y)
        cad.ClearSelection()
        self.SetInputMode(self.select_mode)

        # and pick from three points
        result = self.MakeOriginFromPickPoints(new_object, three_points)
        if result:
            cad.AddUndoably(new_object)
            cad.Select(new_object)
        else:
            cad.DeleteInternalObject(new_object)
Beispiel #21
0
 def add_line(self, x, y, z, a = None, b = None, c = None):
     line = cam.NewPathLine()
     if x != None: self.oldp.x = float(x)
     if y != None: self.oldp.y = float(y)
     if z != None: self.oldp.z = float(z)
     line.point = geom.Point3D(self.oldp)
     self.current_path.AddPathObject(line)
Beispiel #22
0
 def __init__(self, nccode):
     self.nccode = nccode
     self.t = None
     self.oldp = geom.Point3D(0,0,50)
     self.current_block = None
     self.current_path = None
     self.next_line_number = 0
Beispiel #23
0
 def GetXYZScale(self):
     sx = math.sqrt(self.m[0] * self.m[0] + self.m[1] * self.m[1] +
                    self.m[2] * self.m[2])
     sy = math.sqrt(self.m[4] * self.m[4] + self.m[5] * self.m[5] +
                    self.m[6] * self.m[6])
     sz = math.sqrt(self.m[8] * self.m[8] + self.m[9] * self.m[9] +
                    self.m[10] * self.m[10])
     return geom.Point3D(sx, sy, sz)
Beispiel #24
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)
Beispiel #25
0
    def GetRotationABC(self):
        if self.IsUnit():
            return geom.Point3D(0.0, 0.0, 0.0)

        scale_xyz = self.GetXYZScale()
        if self.IsMirrored():
            scale_xyz.x = -scale_xyz.x

        # solve for d and decide case and solve for a, b, c, e and f
        d = -self.m[8] / sz
        c = (1 - d) * (1 + d)
        if c > 0.001:
            # case 1
            c = sqrt(c)
            a = self.m[10] / sz / c
            b = self.m[9] / sz / c
            ee = self.m[0] / sx / c
            f = self.m[4] / sy / c
        else:
            # case 2
            d = -1 if (d < 0) else 1
            c = 0
            p = d * self.m[5] / sy - self.m[2] / sx
            q = d * self.m[6] / sy + self.m[1] / sx
            coef = math.sqrt(p * p + q * q)
            if coef > 0.001:
                a = q / coef
                b = p / coef
                ee = b
                f = -d * b
            else:
                # dependent pairs
                a = self.m[5] / sy
                b = -self.m[6] / sy
                ee = 1
                f = 0

        # solve and return ax, ay and az
        ax = math.atan2(b, a)
        ay = math.atan2(d, c)
        az = math.atan2(f, ee)

        return geom.Point3D(ax, ay, az)
Beispiel #26
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()
Beispiel #27
0
 def GetDrawMatrix(self, get_the_appropriate_orthogonal):
     if get_the_appropriate_orthogonal:
         # choose from the three orthoganal possibilities, the one where it's z-axis closest to the camera direction
         vx, vy = self.current_viewport.view_point.GetTwoAxes(False, 0)
         o = geom.Point3D(0, 0, 0)
         if self.current_coordinate_system: o.Transform(self.current_coordinate_system.GetMatrix())
         return geom.Matrix(o, vx, vy)
     mat = geom.Matrix()
     if self.current_coordinate_system: mat = self.current_coordinate_system.GetMatrix()
     return mat
Beispiel #28
0
 def ReadXml(self):
     self.filepath = cad.GetXmlValue('filepath')
     if self.bottom_left == None:
         self.bottom_left = geom.Point3D(0, 0, 0)
         self.bottom_right = geom.Point3D(0, 0, 0)
         self.top_right = geom.Point3D(0, 0, 0)
         self.top_left = geom.Point3D(0, 0, 0)
     self.bottom_left.x = float(cad.GetXmlValue('x00'))
     self.bottom_left.y = float(cad.GetXmlValue('x01'))
     self.bottom_left.z = float(cad.GetXmlValue('x02'))
     self.bottom_right.x = float(cad.GetXmlValue('x10'))
     self.bottom_right.y = float(cad.GetXmlValue('x11'))
     self.bottom_right.z = float(cad.GetXmlValue('x12'))
     self.top_right.x = float(cad.GetXmlValue('x20'))
     self.top_right.y = float(cad.GetXmlValue('x21'))
     self.top_right.z = float(cad.GetXmlValue('x22'))
     self.top_left.x = float(cad.GetXmlValue('x30'))
     self.top_left.y = float(cad.GetXmlValue('x31'))
     self.top_left.z = float(cad.GetXmlValue('x32'))
     self.opacity = float(cad.GetXmlValue('opacity'))
     Object.ReadXml(self)
Beispiel #29
0
 def __init__(self, p0, p1, p2=None):
     """ construct Plane from three points, from distance and normal ( Point3D ), or a point ( Point3D ) and a normal vector ( Point3D ) """
     if p2 == None:
         if isinstance(p0, geom.Point3D):
             self.normal = p1
             self.normal.Normalize()
             self.d = -(self.normal * p0)
         elif isinstance(p0, int) or isinatance(p0, float):
             self.normal = p1
             mag = self.normal.Normalize()
             self.ok = self.normal != geom.Point3D(0.0, 0.0, 0.0)
             if self.ok: self.d = float(p0) / mag
         else:
             raise ValueError(
                 "Point3D or float for first argument expected")
     else:
         # construct plane from 3 points
         self.normal = geom.Point3D(p0, p1) ^ geom.Point3D(p0, p2)
         self.normal.Normalize()
         self.ok = self.normal != geom.Point3D(0.0, 0.0, 0.0)
         self.d = -(self.normal * p0)
Beispiel #30
0
 def ChooseBestPlane(self, plane):
     f = self.forwards_vector()
     orimat = self.viewport.cad.GetDrawMatrix(False)
     dp = [geom.Point3D(0, 0, 1).Transformed(orimat) * f, geom.Point3D(0, 1, 0).Transformed(orimat) * f, geom.Point3D(1, 0, 0).Transformed(orimat) * f]
     best_dp = 0.0
     best_mode = -1
     second_best_dp = 0.0
     second_best_mode = -1
     third_best_dp = 0.0
     third_best_mode = -1
     for i in range(0, 3):
         if best_mode == -1:
             best_mode = i
             best_dp = math.fabs(dp[i])
         else:
             if math.fabs(dp[i])>best_dp:
                 third_best_dp = second_best_dp
                 third_best_mode = second_best_mode
                 second_best_dp = best_dp
                 second_best_mode = best_mode
                 best_mode = i
                 best_dp = math.fabs(dp[i])
             else:
                 if second_best_mode == -1:
                     second_best_mode = i
                     second_best_dp = math.fabs(dp[i])
                 else:
                     if math.fabs(dp[i])>second_best_dp:
                         third_best_dp = second_best_dp
                         third_best_mode = second_best_mode
                         second_best_dp = math.fabs(dp[i])
                         second_best_mode = i
                     else:
                         third_best_dp = math.fabs(dp[i])
                         third_best_mode = i;
     if plane == 0:
         return best_mode
     elif plane == 1:
         return second_best_mode
     return third_best_mode