def action(self, arg): """Handle the 3D scene events. This is installed as an EventCallback in the Inventor view. Parameters ---------- arg: dict Dictionary with strings that indicates the type of event received from the 3D view. """ if arg["Type"] == "SoKeyboardEvent" and arg["Key"] == "ESCAPE": self.finish() elif arg["Type"] == "SoLocation2Event": self.point, ctrlPoint, info = gui_tool_utils.getPoint(self, arg) gui_tool_utils.redraw3DView() elif (arg["Type"] == "SoMouseButtonEvent" and arg["State"] == "DOWN" and arg["Button"] == "BUTTON1"): if arg["Position"] == self.pos: return self.finish(False, cont=True) if (not self.node) and (not self.support): gui_tool_utils.getSupport(arg) (self.point, ctrlPoint, info) = gui_tool_utils.getPoint(self, arg) if self.point: self.ui.redraw() self.pos = arg["Position"] self.node.append(self.point) self.drawSegment(self.point) if not self.isWire and len(self.node) == 2: self.finish(False, cont=True) if len(self.node) > 2: if (self.point - self.node[0]).Length < utils.tolerance(): self.undolast() self.finish(True, cont=True)
def action(self, arg): """Handle the 3D scene events. This is installed as an EventCallback in the Inventor view by the `Activated` method of the parent class. Parameters ---------- arg: dict Dictionary with strings that indicates the type of event received from the 3D view. """ if arg["Type"] == "SoKeyboardEvent": if arg["Key"] == "ESCAPE": self.finish() elif arg["Type"] == "SoLocation2Event": # mouse movement detection (self.point, ctrlPoint, info) = gui_tool_utils.getPoint(self, arg, noTracker=True) # existing points + this pointer position self.bezcurvetrack.update(self.node + [self.point], degree=self.degree) gui_tool_utils.redraw3DView() elif (arg["Type"] == "SoMouseButtonEvent" and arg["State"] == "DOWN" and arg["Button"] == "BUTTON1"): # left click if arg["Position"] == self.pos: self.finish(False, cont=True) if (not self.node) and (not self.support): # first point gui_tool_utils.getSupport(arg) (self.point, ctrlPoint, info) = gui_tool_utils.getPoint(self, arg, noTracker=True) if self.point: self.ui.redraw() self.pos = arg["Position"] self.node.append(self.point) # add point to "clicked list" # sb add a control point, # if mod(len(cpoints), 2) == 0 # then create 2 handle points? self.drawUpdate(self.point) if not self.isWire and len(self.node) == 2: self.finish(False, cont=True) if len(self.node) > 2: # does this make sense for a BCurve? # DNC: allows to close the curve # by placing ends close to each other # with tol = Draft tolerance # old code has been to insensitive if (self.point-self.node[0]).Length < utils.tolerance(): self.undolast() self.finish(True, cont=True) _msg(translate("draft", "Bezier curve has been closed"))
def action(self, arg): """Handle the 3D scene events. This is installed as an EventCallback in the Inventor view by the `Activated` method of the parent class. Parameters ---------- arg: dict Dictionary with strings that indicates the type of event received from the 3D view. """ if arg["Type"] == "SoKeyboardEvent": if arg["Key"] == "ESCAPE": self.finish() elif arg["Type"] == "SoLocation2Event": # mouse movement detection (self.point, ctrlPoint, info) = gui_tool_utils.getPoint(self, arg, noTracker=True) self.bsplinetrack.update(self.node + [self.point]) gui_tool_utils.redraw3DView() elif (arg["Type"] == "SoMouseButtonEvent" and arg["State"] == "DOWN" and arg["Button"] == "BUTTON1"): if arg["Position"] == self.pos: self.finish(False, cont=True) if (not self.node) and (not self.support): gui_tool_utils.getSupport(arg) (self.point, ctrlPoint, info) = gui_tool_utils.getPoint(self, arg, noTracker=True) if self.point: self.ui.redraw() self.pos = arg["Position"] self.node.append(self.point) self.drawUpdate(self.point) if not self.isWire and len(self.node) == 2: self.finish(False, cont=True) if len(self.node) > 2: # DNC: allows to close the curve # by placing ends close to each other # with tol = Draft tolerance # old code has been to insensitive if (self.point - self.node[0]).Length < utils.tolerance(): self.undolast() self.finish(True, cont=True) _msg(translate("draft", "Spline has been closed"))
def drawUpdate(self, point): """Draw and update to the spline.""" import Part if self.planetrack and self.node: self.planetrack.set(self.node[-1]) # if len(self.node) == 1: # # self.linetrack.on() # _msg(translate("draft", "Pick next point")) # else: if len(self.node) > 0: if (point - self.node[0]).Length < utils.tolerance(): return wire = Part.makePolygon(self.node + [point]) shape = punch_funcs.get_left_right_offset_wire_and_shape( wire, self.bf_left_width, self.bf_right_width)[0] self.obj.Shape = Part.makeCompound([shape, wire])
def action(self, arg): """Handle the 3D scene events. This is installed as an EventCallback in the Inventor view by the `Activated` method of the parent class. Parameters ---------- arg: dict Dictionary with strings that indicates the type of event received from the 3D view. """ if arg["Type"] == "SoKeyboardEvent": if arg["Key"] == "ESCAPE": self.finish() elif arg["Type"] == "SoLocation2Event": # mouse movement detection (self.point, ctrlPoint, info) = gui_tool_utils.getPoint(self, arg, noTracker=True) if (len(self.node) - 1) % self.degree == 0 and len(self.node) > 2: prevctrl = 2 * self.node[-1] - self.point # Existing points + this pointer position self.bezcurvetrack.update(self.node[0:-2] + [prevctrl] + [self.node[-1]] + [self.point], degree=self.degree) else: # Existing points + this pointer position self.bezcurvetrack.update(self.node + [self.point], degree=self.degree) gui_tool_utils.redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": # Press and hold the button if arg["State"] == "DOWN" and arg["Button"] == "BUTTON1": if arg["Position"] == self.pos: if len(self.node) > 2: self.node = self.node[0:-2] else: self.node = [] return else: if (not self.node) and (not self.support): # first point gui_tool_utils.getSupport(arg) (self.point, ctrlPoint, info) = gui_tool_utils.getPoint(self, arg, noTracker=True) if self.point: self.ui.redraw() self.pos = arg["Position"] # add point to "clicked list" self.node.append(self.point) # sb add a control point, # if mod(len(cpoints), 2) == 0 # then create 2 handle points? self.drawUpdate(self.point) if not self.isWire and len(self.node) == 2: self.finish(False, cont=True) # does this make sense for a BCurve? if len(self.node) > 2: # add point to "clicked list" self.node.append(self.point) self.drawUpdate(self.point) # DNC: allows to close the curve # by placing ends close to each other # with tol = Draft tolerance # old code has been to insensitive _diff = (self.point - self.node[0]).Length if (_diff < utils.tolerance() and len(self.node) >= 4): # self.undolast() self.node = self.node[0:-2] # close the curve with a smooth symmetric knot _sym = 2 * self.node[0] - self.node[1] self.node.append(_sym) self.finish(True, cont=True) _msg(translate("draft", "Bezier curve has been closed")) # Release the held button if arg["State"] == "UP" and arg["Button"] == "BUTTON1": if arg["Position"] == self.pos: self.node = self.node[0:-2] return else: if (not self.node) and (not self.support): # first point return if self.point: self.ui.redraw() self.pos = arg["Position"] # add point to "clicked list" self.node.append(self.point) # sb add a control point, # if mod(len(cpoints),2) == 0 # then create 2 handle points? self.drawUpdate(self.point) if not self.isWire and len(self.node) == 2: self.finish(False, cont=True) # Does this make sense for a BCurve? if len(self.node) > 2: self.node[-3] = 2 * self.node[-2] - self.node[-1] self.drawUpdate(self.point)