Assembly: InsertLink : Kill behavior of parts following mouse.

This commit is contained in:
PaddleStroke
2024-03-14 10:18:44 +01:00
committed by Yorik van Havre
parent c8128f19ee
commit 1941fda891

View File

@@ -55,7 +55,7 @@ class CommandInsertLink:
"ToolTip": "<p>"
+ QT_TRANSLATE_NOOP(
"Assembly_InsertLink",
"Insert a component into the current active assembly. This will create dynamic links to parts, bodies, primitives, and assemblies. To insert external components, make sure that the file is <b>open in the current session</b>",
"Insert a component into the active assembly. This will create dynamic links to parts, bodies, primitives, and assemblies. To insert external components, make sure that the file is <b>open in the current session</b>",
)
+ "</p><p><ul><li>"
+ QT_TRANSLATE_NOOP("Assembly_InsertLink", "Insert by left clicking items in the list.")
@@ -109,7 +109,7 @@ class TaskAssemblyInsertLink(QtCore.QObject):
self.form.partList.header().hide()
self.translation = 0
self.partMoving = False
# self.partMoving = False
self.totalTranslation = App.Vector()
self.groundedObj = None
@@ -122,8 +122,8 @@ class TaskAssemblyInsertLink(QtCore.QObject):
def accept(self):
self.deactivated()
if self.partMoving:
self.endMove()
# if self.partMoving:
# self.endMove()
App.closeActiveTransaction()
return True
@@ -131,8 +131,8 @@ class TaskAssemblyInsertLink(QtCore.QObject):
def reject(self):
self.deactivated()
if self.partMoving:
self.dismissPart()
# if self.partMoving:
# self.dismissPart()
App.closeActiveTransaction(True)
return True
@@ -257,8 +257,8 @@ class TaskAssemblyInsertLink(QtCore.QObject):
item.setExpanded(not item.isExpanded())
return
if self.partMoving:
self.endMove()
# if self.partMoving:
# self.endMove()
# check that the current document had been saved or that it's the same document as that of the selected part
if not self.doc == selectedPart.Document:
@@ -325,7 +325,7 @@ class TaskAssemblyInsertLink(QtCore.QObject):
Gui.Selection.addSelection(self.doc.Name, addedObject.Name, "")
# Start moving the part if user brings mouse on view
self.initMove()
# self.initMove()
item.setSelected(False)
# self.form.partList.setItemSelected(item, False)
@@ -371,7 +371,7 @@ class TaskAssemblyInsertLink(QtCore.QObject):
self.groundedObj = self.insertionStack[0]["addedObject"]
self.groundedJoint = CommandCreateJoint.createGroundedJoint(self.groundedObj)
self.endMove()
# self.endMove()
def increment_counter(self, item):
text = item.text(0)
@@ -404,29 +404,25 @@ class TaskAssemblyInsertLink(QtCore.QObject):
item.setText(0, new_text)
def initMove(self):
self.callbackMove = self.view.addEventCallback("SoLocation2Event", self.moveMouse)
self.callbackClick = self.view.addEventCallback("SoMouseButtonEvent", self.clickMouse)
self.callbackKey = self.view.addEventCallback("SoKeyboardEvent", self.KeyboardEvent)
self.partMoving = True
# def initMove(self):
# self.callbackMove = self.view.addEventCallback("SoLocation2Event", self.moveMouse)
# self.callbackClick = self.view.addEventCallback("SoMouseButtonEvent", self.clickMouse)
# self.callbackKey = self.view.addEventCallback("SoKeyboardEvent", self.KeyboardEvent)
# self.partMoving = True
# Selection filter to avoid selecting the part while it's moving
# filter = Gui.Selection.Filter('SELECT ???')
# Gui.Selection.addSelectionGate(filter)
# def endMove(self):
# self.view.removeEventCallback("SoLocation2Event", self.callbackMove)
# self.view.removeEventCallback("SoMouseButtonEvent", self.callbackClick)
# self.view.removeEventCallback("SoKeyboardEvent", self.callbackKey)
# self.partMoving = False
# self.doc.recompute()
# # Gui.Selection.removeSelectionGate()
def endMove(self):
self.view.removeEventCallback("SoLocation2Event", self.callbackMove)
self.view.removeEventCallback("SoMouseButtonEvent", self.callbackClick)
self.view.removeEventCallback("SoKeyboardEvent", self.callbackKey)
self.partMoving = False
self.doc.recompute()
# Gui.Selection.removeSelectionGate()
# def moveMouse(self, info):
# newPos = self.view.getPoint(*info["Position"])
# self.insertionStack[-1]["addedObject"].Placement.Base = newPos
def moveMouse(self, info):
newPos = self.view.getPoint(*info["Position"])
self.insertionStack[-1]["addedObject"].Placement.Base = newPos
def clickMouse(self, info):
"""def clickMouse(self, info):
if info["Button"] == "BUTTON1" and info["State"] == "DOWN":
Gui.Selection.clearSelection()
if info["ShiftDown"]:
@@ -451,26 +447,26 @@ class TaskAssemblyInsertLink(QtCore.QObject):
self.endMove()
elif info["Button"] == "BUTTON2" and info["State"] == "DOWN":
self.dismissPart()
self.dismissPart()"""
# 3D view keyboard handler
def KeyboardEvent(self, info):
if info["State"] == "UP" and info["Key"] == "ESCAPE":
self.dismissPart()
# def KeyboardEvent(self, info):
# if info["State"] == "UP" and info["Key"] == "ESCAPE":
# self.dismissPart()
def dismissPart(self):
self.endMove()
stack_item = self.insertionStack.pop()
self.totalTranslation -= stack_item["translation"]
UtilsAssembly.removeObjAndChilds(stack_item["addedObject"])
self.decrement_counter(stack_item["item"])
# def dismissPart(self):
# self.endMove()
# stack_item = self.insertionStack.pop()
# self.totalTranslation -= stack_item["translation"]
# UtilsAssembly.removeObjAndChilds(stack_item["addedObject"])
# self.decrement_counter(stack_item["item"])
# Taskbox keyboard event handler
def eventFilter(self, watched, event):
if watched == self.form and event.type() == QtCore.QEvent.KeyPress:
if event.key() == QtCore.Qt.Key_Escape and self.partMoving:
self.dismissPart()
return True # Consume the event
# if watched == self.form and event.type() == QtCore.QEvent.KeyPress:
# if event.key() == QtCore.Qt.Key_Escape and self.partMoving:
# self.dismissPart()
# return True # Consume the event
if event.type() == QtCore.QEvent.ContextMenu and watched is self.form.partList:
item = watched.itemAt(event.pos())
@@ -481,8 +477,8 @@ class TaskAssemblyInsertLink(QtCore.QObject):
stack_item = self.insertionStack[i]
if stack_item["item"] == item:
if self.partMoving:
self.endMove()
# if self.partMoving:
# self.endMove()
self.totalTranslation -= stack_item["translation"]
obj = stack_item["addedObject"]