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()
def SketchOperation(self, mode): objects_to_delete = [] area = None for object in cad.GetSelectedObjects(): t = object.GetType() if t == cad.OBJECT_TYPE_SKETCH: objects_to_delete.append(object) sketch = object sketch.__class__ = cad.Sketch a = sketch.GetArea() if area == None: area = a else: if mode == SKETCH_OP_UNION: area.Union(a) elif mode == SKETCH_OP_SUBTRACT: area.Subtract(a) elif mode == SKETCH_OP_INTERSECT: area.Intersect(a) if area != None: cad.StartHistory() sketch = cad.NewSketchFromArea(area) cad.AddUndoably(sketch) cad.DeleteObjectsUndoably(objects_to_delete) cad.EndHistory()
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()
def AddPoint(self, d): if d.type == cad.DigitizeType.DIGITIZE_NO_ITEM_TYPE: return calculated = False cad.StartHistory() if self.is_an_add_level(self.draw_step): calculated = self.calculate_item(d) if calculated: self.before_add_item() self.prev_object = self.TempObject() self.AddObjectsMade() self.set_previous_direction() self.ClearObjectsMade() self.SetStartPosUndoable(d) #cad.UseDigitiedPointAsReference() next_step = self.draw_step + 1 if next_step >= self.number_of_steps(): next_step = self.step_to_go_to_after_last_step() self.SetDrawStepUndoable(next_step) cad.EndHistory() self.getting_position = False self.inhibit_coordinate_change = False cad.Repaint()
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()
def OnFuse(self, event): if not self.CheckForNumberOrMore( 2, [step.GetSolidType()], 'Pick two or more solids to be fused together', 'Fuse Solids'): return cad.StartHistory() step.FuseShapes() cad.EndHistory()
def SplitSketch(self, object): sketch = object sketch.__class__ = cad.Sketch new_sketches = sketch.Split() cad.StartHistory() cad.DeleteUndoably(object) for sketch in new_sketches: cad.AddUndoably(sketch, object.GetOwner(), None) cad.EndHistory()
def OnSubtract(self, event): if not self.CheckForNumberOrMore( 2, [ step.GetFaceType(), step.GetSolidType() ], 'Pick two or more faces or solids, the first one will be cut by the others', 'Subtract Solids'): return cad.StartHistory() step.CutShapes() cad.EndHistory()
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()
def OnCommon(self, event): if not self.CheckForNumberOrMore( 2, [ step.GetSolidType() ], 'Pick two or more solids, only the shape that is contained by all of them will remain', 'Intersection of Solids'): return cad.StartHistory() step.CommonShapes() cad.EndHistory()
def FitArcs(self, object): value = self.InputLength('Set tolerance for Fit Arcs', 'tolerance', geom.get_accuracy()) if value != None: geom.set_accuracy(value) sketch = object sketch.__class__ = cad.Sketch curve = sketch.GetCurve() curve.FitArcs() cad.StartHistory() cad.DeleteUndoably(object) cad.AddUndoably(cad.NewSketchFromCurve(curve)) cad.EndHistory()
def OnSpline(self, e): if not self.CheckForNumberOrMore( 2, [cad.OBJECT_TYPE_POINT], 'Pick one or more points to make a spline through', 'Spline Through Points'): return cad.StartHistory() points = [] for object in cad.GetSelectedObjects(): points.append(object.GetStartPoint()) new_object = step.NewSplineFromPoints(points) cad.AddUndoably(new_object) cad.EndHistory()
def OnFillet(self, event): if not self.CheckForNumberOrMore( 1, [step.GetEdgeType()], 'Pick one or more edges to add a fillet to', 'Edge Fillet'): return config = HeeksConfig() rad = config.ReadFloat('EdgeBlendRadius', 2.0) rad = self.InputLength('Enter Blend Radius', 'Radius', rad) if rad: cad.StartHistory() step.FilletOrChamferEdges(rad, False) config.WriteFloat('EdgeBlendRadius', rad) cad.ClearSelection(True) cad.EndHistory()
def OnChamfer(self, event): if not self.CheckForNumberOrMore( 1, [step.GetEdgeType()], 'Pick one or more edges to add a chamfer to', 'Edge Chamfer'): return config = HeeksConfig() rad = config.ReadFloat('EdgeChamferDist', 2.0) rad = self.InputLength('Enter Chamfer Distance', 'Distance', rad) if rad: cad.StartHistory() step.FilletOrChamferEdges(rad, True) config.WriteFloat('EdgeChamferDist', rad) cad.ClearSelection(True) cad.EndHistory()
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()
def EditAndAddSketchOp(self, new_object, sketches): if new_object.Edit(): cad.StartHistory('Add ' + new_object.GetTitle()) cad.AddUndoably(new_object, self.program.operations, None) first = True for sketch in sketches: if first: first = False else: copy = new_object.MakeACopy() copy.sketch = sketch cad.AddUndoably(copy, self.program.operations, None) self.EndHistory()
def MakeToSketch(self): objects_to_delete = [] sketch = cad.NewSketch() for object in cad.GetSelectedObjects(): t = object.GetType() if object.CanAddTo(sketch): new_object = object.MakeACopy() objects_to_delete.append(object) sketch.Add(new_object) cad.StartHistory() cad.AddUndoably(sketch) cad.DeleteObjectsUndoably(objects_to_delete) cad.EndHistory()
def RotateToFace(self, object): n = self.context_face_plane.normal p = n * (-self.context_face_plane.d) x, y = n.ArbitraryAxes() face_matrix = geom.Matrix(p, x, y) inv_matrix = face_matrix.Inverse() cad.StartHistory() selected = cad.GetSelectedObjects() # if any objects are selected, move them if len(selected) > 0: for object in selected: cad.TransformUndoably(object, inv_matrix) else: # move the solid parent_body = object.GetParentBody() cad.TransformUndoably(parent_body, inv_matrix) cad.EndHistory()
def OnShadow(self, event): if not self.CheckForNumberOrMore( 1, [step.GetSolidType(), cad.OBJECT_TYPE_STL_SOLID], 'Pick one or more solids to make a shadow sketch from', 'Shadow Sketch of Solids'): return accuracy = self.InputLength('Enter Shadow Accuracy', 'Accuracy', geom.get_accuracy()) if accuracy: cad.StartHistory() geom.set_accuracy(accuracy) for object in cad.GetSelectedObjects(): stl = object.GetTris(accuracy) mat = geom.Matrix() shadow = stl.Shadow(mat, False) #shadow.Reorder() sketch = cad.NewSketchFromArea(shadow) cad.AddUndoably(sketch) cad.EndHistory()
def OnPropGridChange(self, event): self.in_OnPropGridChange = True p = event.GetProperty() properties = self.GetProperties(p) if properties == None: return cad.StartHistory() for property in properties: if property.GetType( ) == cad.PROPERTY_TYPE_STRING or property.GetType( ) == cad.PROPERTY_TYPE_LONG_STRING: cad.ChangePropertyString(p.GetValue(), property) elif property.GetType() == cad.PROPERTY_TYPE_DOUBLE: cad.ChangePropertyDouble(p.GetValue(), property) elif property.GetType() == cad.PROPERTY_TYPE_LENGTH: cad.ChangePropertyLength(p.GetValue() * cad.GetUnits(), property) elif property.GetType() == cad.PROPERTY_TYPE_INT: cad.ChangePropertyInt(p.GetValue(), property) elif property.GetType() == cad.PROPERTY_TYPE_CHOICE: cad.ChangePropertyChoice(p.GetValue(), property) elif property.GetType() == cad.PROPERTY_TYPE_COLOR: c = p.GetValue() cad.ChangePropertyColor(cad.Color(c.red, c.green, c.blue), property) elif property.GetType() == cad.PROPERTY_TYPE_CHECK: cad.ChangePropertyCheck(p.GetValue(), property) elif property.GetType() == cad.PROPERTY_TYPE_LIST: pass elif property.GetType() == cad.PROPERTY_TYPE_FILE: cad.ChangePropertyString(p.GetValue(), property) #for changer in changers: #cad.DoUndoable(changer) cad.EndHistory() self.in_OnPropGridChange = False
def EditAndAddOp(self, op): if op.Edit(): cad.StartHistory('Add ' + op.GetTitle()) cad.AddUndoably(op, op.PreferredPasteTarget(), None) self.EndHistory()
def EditAndAddTool(self, tool): if tool.Edit(): cad.StartHistory('Add Tool') cad.AddUndoably(tool, self.program.tools, None) self.EndHistory()
def ClearToolpath(self): cad.StartHistory('Clear Toolpath') blank_nc = NcCode.NcCode() cad.PyIncref(blank_nc) wx.GetApp().CopyUndoablyWithChildren(wx.GetApp().program.nccode, blank_nc) self.EndHistory()
def OnDelete(self, e): cad.StartHistory() for object in cad.GetSelectedObjects(): cad.DeleteUndoably(object) cad.EndHistory()
def OnCut(self, e): self.CopySelectedItems() cad.StartHistory() for object in cad.GetSelectedObjects(): cad.DeleteUndoably(object) cad.EndHistory()
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()
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()
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()
def OnStart(self): self.draw_step = 0 self.ReadDefaultValues() cad.StartHistory(False)