Beispiel #1
0
    def OnKeyDown(self, e):
        k = e.GetKeyCode()
        if k == wx.WXK_UP:
            sel = cad.GetSelectedObjects()
            index = -1
            if len(sel) > 0:
                index = self.ObjectRenderedIndex(sel[-1])
                if index > 0:
                    index -= 1
            if (index == -1) and (len(self.rendered_objects) > 0):
                index = len(self.rendered_objects) - 1

            cad.ClearSelection(True)

            if len(self.rendered_objects):
                cad.Select(self.rendered_objects[index])
        elif k == wx.WXK_DOWN:
            sel = cad.GetSelectedObjects()
            index = -1
            if len(sel) > 0:
                index = self.ObjectRenderedIndex(sel[-1])
                if index < len(self.rendered_objects) - 1:
                    index += 1
            if (index == -1) and (len(self.rendered_objects) > 0):
                index = 0

            cad.ClearSelection(True)

            if len(self.rendered_objects):
                cad.Select(self.rendered_objects[index])
        else:
            wx.GetApp().OnKeyDown(e)
Beispiel #2
0
 def OnLeftClick(self, event):
     if not event.controlDown:
         # check for nc code block clicked
         if self.select_mode.filter.IsTypeInFilter(cam.GetNcCodeBlockType()):
             mask = cad.Filter()
             mask.AddType(cam.GetNcCodeBlockType())
             objects = cad.ObjectsUnderWindow(cad.IRect(self.select_mode.button_down_point.x, self.select_mode.button_down_point.y), False, True, mask, False)
             if len(objects):
                 block = objects[0]
                 cad.ClearSelection()
                 cad.Select(block)
                 block.__class__ = cam.NcCodeBlock
                 self.output_window.viewport.SelectLine(block.line_number, True)
                 wx.GetApp().frame.graphics_canvas.Refresh()
                 self.output_window.Refresh()
                 return            
             
             program = wx.GetApp().program
             if program != None:
                 nccode = program.nccode
                 if nccode != None:
                     nccode.nc_code.SetHighlightedBlock(None)
     
     # do the default click behaviour
     SolidApp.OnLeftClick(self, event)
Beispiel #3
0
 def OnLeftClick(self, event):
     # select one object
     objects = cad.ObjectsUnderWindow(cad.IRect(self.select_mode.button_down_point.x, self.select_mode.button_down_point.y), False, True, self.select_mode.filter, True)
     if len(objects) > 0:
         object = objects[0]
         
         if event.controlDown:
             if cad.ObjectMarked(object):
                 cad.Unselect(object, True)
             else:
                 cad.Select(object)
         else:
             cad.ClearSelection(True)
             cad.Select(object)
     else:
         cad.ClearSelection(True)
Beispiel #4
0
    def MakeGCode(self):
        wx.GetApp().attached_to_surface = None
        self.number_for_stl_file = 1
        wx.GetApp().tool_number = 0

        # import the relevant machine
        machine_module = __import__('nc.' + self.machine.post,
                                    fromlist=['dummy'])
        import importlib
        importlib.reload(machine_module)
        output(self.GetOutputFileName())
        program_begin(self.GetID(), self.GetTitle())

        absolute()

        if self.units > 25.0:
            imperial()
        else:
            metric()

        set_plane(0)

        if self.path_control_mode != PATH_CONTROL_UNDEFINED:
            set_path_control_mode(self.path_control_mode,
                                  self.motion_blending_tolerance,
                                  self.naive_cam_tolerance)

        for tool in self.tools.GetChildren():
            tool.DoGCodeCalls()

        surfaces_written = {}
        patterns_written = {}

        for op in self.operations.GetChildren():
            if op.active:
                surface = cad.GetObjectFromId(Surface.type, op.surface)
                if surface != None: import attach
                surface_apply_before_pattern = (
                    surface !=
                    None) and not surface.same_for_each_pattern_position
                surface_apply_after_pattern = (
                    surface != None) and surface.same_for_each_pattern_position
                if surface_apply_before_pattern:
                    self.ApplySurfaceToText(surface, surfaces_written)
                tranform_begun = self.ApplyPatternToText(
                    op.pattern, patterns_written)
                if surface_apply_after_pattern:
                    self.ApplySurfaceToText(surface, surfaces_written)
                failure = op.DoGCodeCalls()
                if surface_apply_after_pattern: attach.attach_end()
                if tranform_begun: transform.transform_end()
                if surface_apply_before_pattern: attach.attach_end()
                wx.GetApp().attached_to_surface = None
                if failure:
                    wx.MessageBox(failure)
                    cad.Select(op)
                    return

        program_end()
Beispiel #5
0
 def AddObjectFromButton(self, new_object):
     cad.StartHistory()
     cad.AddUndoably(new_object, None, None)
     cad.ClearSelection(True)
     cad.Select(new_object)
     self.SetInputMode(self.select_mode)
     cad.EndHistory()
     cad.Repaint()
Beispiel #6
0
 def OnLabelLeftDown(self, object, event):
     if event.ShiftDown():
         self.waiting_until_left_up = cad.ShiftSelect(
             object, event.ControlDown())
     else:
         # shift not down
         if event.ControlDown():
             if cad.ObjectMarked(object):
                 cad.Unselect(object, True)
             else:
                 cad.Select(object, True)
         else:
             if cad.ObjectMarked(object):
                 self.waiting_until_left_up = True
                 cad.Select(object, True)
             else:
                 cad.ClearSelection(False)
                 cad.Select(object, True)
Beispiel #7
0
 def OnLeftDown(self, event):
     # select the block clicked on
     line_number = self.viewport.GetCurrentLine(
     ) + event.y / self.viewport.GetPixelsPerLine()
     block = self.viewport.GetBlockAtLine(int(line_number))
     cad.ClearSelection()
     cad.Select(block)
     self.viewport.SelectLine(line_number, False)
     wx.GetApp().frame.graphics_canvas.Refresh()
     self.Refresh()
Beispiel #8
0
 def OffsetSketch(self, object):
     config = HeeksConfig()
     value = config.ReadFloat('SketchOffsetValue', 1.0)
     value = self.InputLength('Offset Sketch', 'Offset Value +ve for Outwards -ve for Inwards', value)
     if value == None: return
     sketch = object
     sketch.__class__ = cad.Sketch
     area = sketch.GetArea()
     area.Reorder()
     area.Offset(-value)
     new_object = cad.NewSketchFromArea(area)
     cad.AddUndoably(new_object)
     cad.ClearSelection()
     cad.Select(new_object)
Beispiel #9
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 #10
0
 def FaceToSketch(self, object):
     sketch = step.NewSketchFromFace(object)
     cad.AddUndoably(sketch)
     cad.Select(sketch)
Beispiel #11
0
 def ChamferEdge(self, object):
     cad.ClearSelection()
     cad.Select(object)
     self.OnChamfer(None)
Beispiel #12
0
 def BlendEdge(self, object):
     cad.ClearSelection()
     cad.Select(object)
     self.OnFillet(None)
Beispiel #13
0
 def FaceRadiusChange(self, object):
     sketch = step.NewSketchFromFace(object)
     cad.AddUndoably(sketch)
     cad.Select(sketch)
Beispiel #14
0
 def Run(self, event):
     if not self.control_pressed:
         cad.ClearSelection(False)
     cad.Select(self.object)
Beispiel #15
0
 def OnLabelRightDown(self, object, event):
     if not cad.ObjectMarked(object):
         cad.ClearSelection(False)
         cad.Select(object, True)
Beispiel #16
0
    def OnMouse(self, event):
        # to do? if(wxGetApp().m_property_grid_validation)return;
        if event.Entering():
            self.SetFocus()  # so middle wheel works

        if event.LeftDown():
            button = self.HitTest(event.GetPosition())

            if button:
                if button.type == ButtonTypePlus or button.type == ButtonTypeMinus:
                    self.SetExpanded(button.obj, button.type == ButtonTypePlus)
                    self.SetVirtualSize(self.GetRenderSize())
                    self.Refresh()
                else:
                    self.OnLabelLeftDown(button.obj, event)
                    self.clicked_object = button.obj
            else:
                cad.ClearSelection(True)

            self.button_down_point = event.GetPosition()

        if event.LeftUp():
            if self.dragging:
                self.dragging = False

                # find the object to drop on to
                button = self.HitTest(event.GetPosition())

                if (button == None) or not cad.ObjectMarked(
                        button.obj
                ):  # can only drop on to an item other than one of the items being dragged
                    # test drop possible
                    drag_possible = True

                    add_to = cad.GetApp()
                    if button and button.paste_into: add_to = button.paste_into
                    for object in self.dragged_list:
                        if not add_to.CanAdd(object) or not object.CanAddTo(
                                add_to):
                            drag_possible = False
                            break

                    if drag_possible:
                        cad.StartHistory()

                        # cut the objects
                        cad.DeleteObjectsUndoably(self.dragged_list)

                        # paste the objects
                        for object in self.dragged_list:
                            if object.OneOfAKind():
                                one_found = False
                                child = add_to.GetFirstChild()
                                while child:
                                    if child.GetType() == object.GetType():
                                        child.CopyFrom(object)
                                        one_found = True
                                        break

                                    child = add_to.GetNextChild()

                                if not one_found:
                                    cad.AddUndoably(
                                        object, add_to, button.paste_before if
                                        (button != None) else None)
                            else:
                                cad.AddUndoably(
                                    object, add_to, button.paste_before if
                                    (button != None) else None)

                        cad.EndHistory()
                    else:
                        self.Refresh()
                else:
                    self.Refresh()
            else:
                if self.waiting_until_left_up:
                    cad.ClearSelection(False)
                    cad.Select(self.clicked_object, True)
            self.waiting_until_left_up = False

        if event.RightDown():
            button = self.HitTest(event.GetPosition())
            self.clicked_object = None
            if (button != None) and (button.type == ButtonTypeLabelBefore
                                     or button.type == ButtonTypeLabel):
                self.clicked_object = button.obj
                self.OnLabelRightDown(button.obj, event)

        if event.RightUp():
            if self.dragging:
                self.dragging = False
            else:
                tools = self.GetDropDownTools(event.ControlDown())
                menu = wx.Menu()
                for tool in tools:
                    wx.GetApp().AddToolToListAndMenu(tool, menu)
                self.PopupMenu(menu, event.GetPosition())

        if event.Dragging():
            if event.LeftIsDown() or event.RightIsDown():
                if (not self.dragging) and (
                        math.fabs(self.button_down_point.x - event.GetX()) > 2
                        or math.fabs(self.button_down_point.y - event.GetY()) >
                        2):
                    self.dragging = True
                    self.dragged_list = cad.GetSelectedObjects()

            if self.dragging:
                self.drag_position = self.CalcUnscrolledPosition(
                    event.GetPosition())
                button = self.HitTest(event.GetPosition())
                self.drag_paste_rect = wx.Rect(0, 0, 0, 0)
                if (button != None) and (button.type == ButtonTypeLabelBefore):
                    self.drag_paste_rect = button.rect
                self.Refresh()

        if event.LeftDClick():
            if self.clicked_object:
                wx.GetApp().EditUndoably(self.clicked_object)

        event.Skip()