Ejemplo n.º 1
0
def OriTransform():
    if cad.GetNumSelected() == 0:
        wx.GetApp().PickObjects('Pick objects to transform')

    if cad.GetNumSelected() == 0:
        return

    config = HeeksConfig()

    selected_items = cad.GetSelectedObjects()

    cad.ClearSelection(False)

    o1 = PickOrigin('Pick From Origin')
    if o1 == None:
        wx.MessageBox("You didn't pick an origin\nTransform Cancelled!")
        return

    o2 = PickOrigin('Pick To Origin')
    if o2 == None:
        wx.MessageBox("You didn't pick an origin\nTransform Cancelled!")
        return

    cad.StartHistory()

    m1 = o1.GetOrigin()
    mat = m1.Inverse()
    m2 = o2.GetOrigin()
    mat.Multiply(m2)
    for object in selected_items:
        cad.TransformUndoably(object, mat)

    cad.EndHistory()
Ejemplo n.º 2
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()
Ejemplo n.º 3
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()
Ejemplo n.º 4
0
    def OnSweep(self, event):
        if cad.GetNumSelected() == 0:
            self.PickObjects('Pick Some Sketches, Faces or Circles')

        if not self.CheckForNumberOrMore(
                1,
            [
                cad.OBJECT_TYPE_SKETCH,
                step.GetFaceType(), cad.OBJECT_TYPE_CIRCLE
            ], 'Pick one or more sketches, faces or circles, to sweep\n( hold down Ctrl key to select more than one solid )',
                'Sweep'):
            return

        sweep_objects = cad.GetSelectedObjects()
        cad.ClearSelection(True)
        self.PickObjects('Pick a Sketch to Sweep Along')

        if not self.CheckForNumberOrMore(1, [cad.OBJECT_TYPE_SKETCH],
                                         'Pick one sketch to sweep along',
                                         'Sweep'):
            return

        sweep_profile = cad.GetSelectedObjects()[0]

        cad.StartHistory()
        step.CreateSweep(sweep_objects, sweep_profile,
                         cad.Color(128, 150, 128))
        cad.EndHistory()
Ejemplo n.º 5
0
    def OnRevolve(self, event):
        if cad.GetNumSelected() == 0:
            self.PickObjects('Pick Some Sketches, Faces or Circles')

        if not self.CheckForNumberOrMore(
                1,
            [
                cad.OBJECT_TYPE_SKETCH,
                step.GetFaceType(), cad.OBJECT_TYPE_CIRCLE
            ], 'Pick one or more sketches, faces or circles, to create an extruded body from\n( hold down Ctrl key to select more than one solid )',
                'Revolve'):
            return

        config = HeeksConfig()
        angle = config.ReadFloat('RevolutionAngle', 360.0)
        extrude_makes_a_solid = config.ReadBool('ExtrudeToSolid')

        success, angle, extrude_makes_a_solid = self.InputRevolutionAngle(
            angle, extrude_makes_a_solid)

        if success:
            config.WriteFloat('RevolutionAngle', angle)
            config.WriteBool('ExtrudeToSolid', extrude_makes_a_solid)
            step.CreateExtrusion(angle, extrude_makes_a_solid, True, 0.0,
                                 cad.Color(128, 128, 150))
Ejemplo n.º 6
0
    def OnExtrude(self, event):
        if cad.GetNumSelected() == 0:
            self.PickObjects('Pick Some Sketches, Faces or Circles')

        if not self.CheckForNumberOrMore(
                1,
            [
                cad.OBJECT_TYPE_SKETCH,
                step.GetFaceType(), cad.OBJECT_TYPE_CIRCLE
            ], 'Pick one or more sketches, faces or circles, to create an extruded body from\n( hold down Ctrl key to select more than one solid )',
                'Extude'):
            return

        config = HeeksConfig()
        height = config.ReadFloat('ExtrusionHeight', 10.0)
        taper_angle = config.ReadFloat('ExtrusionTaperAngle', 0.0)
        extrude_makes_a_solid = config.ReadBool('ExtrudeToSolid')

        success, height, extrude_makes_a_solid, taper_angle = self.InputExtrusionHeight(
            height, extrude_makes_a_solid, taper_angle)

        if success:
            config.WriteFloat('ExtrusionHeight', height)
            config.WriteFloat('ExtrusionTaperAngle', taper_angle)
            config.WriteBool('ExtrudeToSolid', extrude_makes_a_solid)
            step.CreateExtrusion(height, extrude_makes_a_solid, False,
                                 taper_angle, cad.Color(128, 128, 128))
Ejemplo n.º 7
0
    def OnKeyDown(self, e):
        k = e.GetKeyCode()
        if k == wx.WXK_ESCAPE and self.frame.IsFullScreen():
            self.ShowFullScreen(False)
            return True
        else:
            key_code = Key.KeyCodeFromWx(e)
            if wx.GetApp().input_mode_object.OnKeyDown(key_code):
                return True

        if k == wx.WXK_DELETE:
            if cad.GetNumSelected() > 0:
                self.DeleteMarkedList()
        elif k == wx.WXK_RETURN:
            if self.inMainLoop:
                self.ExitMainLoop()
                self.Repaint()
        elif k == ord('Z'):
            if e.ControlDown():
                if e.ShiftDown():
                    self.OnRedo(e)
                else:
                    self.OnUndo(e)
        elif k == ord('X'):
            if e.ControlDown():
                self.OnCut(e)
        elif k == ord('C'):
            if e.ControlDown():
                self.OnCopy(e)
        elif k == ord('V'):
            if e.ControlDown():
                self.OnPaste(e)
        else:
            return False
        return True
Ejemplo n.º 8
0
    def PickSketch(self):
        cad.ClearSelection()
        wx.GetApp().PickObjects('Pick a sketch', cad.OBJECT_TYPE_SKETCH, True)

        self.cmbSketch.Recreate()
        self.Fit()

        id = 0
        if cad.GetNumSelected() > 0: id = cad.GetSelectedObjects()[0].GetID()
        self.cmbSketch.SelectById(id)
Ejemplo n.º 9
0
 def CheckForNumberOrMore(self, min_num, types, msg, caption):
     num_found = 0
     for object in cad.GetSelectedObjects():
         for type in types:
             if object.GetType() == type:
                 num_found += 1
                 break
             
     if num_found < min_num:
         filter = cad.Filter()
         for t in types: filter.AddType(t)
         objects = self.PickObjects(msg, filter, False)
         if cad.GetNumSelected() < min_num:
             wx.MessageBox(msg)
             return False
     return True
Ejemplo n.º 10
0
def Rotate(copy=False):
    #rotation axis - Z axis by default
    axis_Dir = geom.Point3D(0, 0, 1)
    line_Pos = geom.Point3D(0, 0, 0)

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

    if cad.GetNumSelected() == 0:
        return

    config = HeeksConfig()
    ncopies = None
    if copy:
        ncopies = config.ReadInt('RotateNumCopies', 1)
        RemoveUncopyable()
        if cad.GetNumSelected() == 0:
            return

    selected_items = cad.GetSelectedObjects()

    cad.ClearSelection(False)

    angle = config.ReadFloat('RotateAngle', 90.0)

    # enter angle, plane and position

    axis = geom.Point3D(0, 0, 1)
    pos = geom.Point3D(0, 0, 0)
    axis.x = config.ReadFloat("RotateAxisX", 0.0)
    axis.y = config.ReadFloat("RotateAxisY", 0.0)
    axis.z = config.ReadFloat("RotateAxisZ", 1.0)
    pos.x = config.ReadFloat("RotatePosX", 0.0)
    pos.y = config.ReadFloat("RotatePosY", 0.0)
    pos.z = config.ReadFloat("RotatePosZ", 0.0)

    axial_shift = config.ReadFloat('RotateAxialShift', 0.0)

    result, angle, axis, pos, ncopies, axial_shift = InputAngleWithPlane(
        angle, axis, pos, ncopies, axial_shift, 'Rotate')
    if not result:
        return

    if copy:
        if ncopies < 1:
            return
        config.WriteInt("RotateNumCopies", ncopies)

    config.WriteFloat("RotateAngle", angle)
    config.WriteFloat("RotateAxialShift", axial_shift)
    config.WriteFloat("RotateAxisX", axis.x)
    config.WriteFloat("RotateAxisY", axis.y)
    config.WriteFloat("RotateAxisZ", axis.z)
    config.WriteFloat("RotatePosX", pos.x)
    config.WriteFloat("RotatePosY", pos.y)
    config.WriteFloat("RotatePosZ", pos.z)

    cad.StartHistory()

    if copy:
        for i in range(0, ncopies):
            mat = geom.Matrix()
            mat.Translate(-pos)
            mat.RotateAxis(angle * 0.0174532925199433 * (i + 1), axis)
            mat.Translate(pos)
            for object in selected_items:
                new_object = object.MakeACopy()
                object.GetOwner().Add(new_object)
                cad.TransformUndoably(new_object, mat)
    else:
        mat = geom.Matrix()
        mat.Translate(-pos)
        mat.RotateAxis(angle * 0.0174532925199433, axis)
        mat.Translate(pos)
        for object in selected_items:
            cad.TransformUndoably(object, mat)

    cad.EndHistory()
Ejemplo n.º 11
0
def Translate(copy=False):
    if cad.GetNumSelected() == 0:
        wx.GetApp().PickObjects('Pick objects to move')

    if cad.GetNumSelected() == 0:
        return

    config = HeeksConfig()
    ncopies = None
    if copy:
        ncopies = config.ReadInt('TranslateNumCopies', 1)
        RemoveUncopyable()
        if cad.GetNumSelected() == 0:
            return

    selected_items = cad.GetSelectedObjects()

    cad.ClearSelection(False)

    fromp = geom.Point3D()
    to = geom.Point3D()

    fromp.x = config.ReadFloat("TranslateFromX", 0.0)
    fromp.y = config.ReadFloat("TranslateFromY", 0.0)
    fromp.z = config.ReadFloat("TranslateFromZ", 0.0)
    to.x = config.ReadFloat("TranslateToX", 0.0)
    to.y = config.ReadFloat("TranslateToY", 0.0)
    to.z = config.ReadFloat("TranslateToZ", 0.0)

    result, fromp, to, ncopies = InputFromAndTo(fromp, to, ncopies,
                                                'Move Translate')
    if not result:
        return

    if copy:
        if ncopies < 1:
            return
        config.WriteInt("TranslateNumCopies", ncopies)

    config.WriteFloat("TranslateFromX", fromp.x)
    config.WriteFloat("TranslateFromY", fromp.y)
    config.WriteFloat("TranslateFromZ", fromp.z)
    config.WriteFloat("TranslateToX", to.x)
    config.WriteFloat("TranslateToY", to.y)
    config.WriteFloat("TranslateToZ", to.z)

    cad.StartHistory()

    if copy:
        for i in range(0, ncopies):
            mat = geom.Matrix()
            mat.Translate((to - fromp) * (i + 1))
            for object in selected_items:
                new_object = object.MakeACopy()
                object.GetOwner().Add(new_object)
                cad.TransformUndoably(new_object, mat)
    else:
        mat = geom.Matrix()
        mat.Translate(to - fromp)
        for object in selected_items:
            cad.TransformUndoably(object, mat)

    cad.EndHistory()
Ejemplo n.º 12
0
 def OnUpdateCopy(self, e):
     e.Enable(cad.GetNumSelected() > 0)    
Ejemplo n.º 13
0
 def OnUpdateDelete(self, e):
     e.Enable(cad.GetNumSelected() > 0)