[Solved using variable] QTCursor postion set based on COIN3D Drawing location after a click?

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

[Solved using variable] QTCursor postion set based on COIN3D Drawing location after a click?

Post by mariwan »

You might know that I uses arrows to drag objects.
I have a problem where the first click user do on the drawing is far from being the position of the arrow. This causes a jump in the mouse movement.
The solution is to move the mouse cursor after first click to the position of the arrow. But the arrow is drawn at 3D world and the mouse QTCursor-set position is 2D.
I know I can make a variable and always count the diff .. But that is not so good.
Is there a way to convert the COIN3D drawing position to QT 2D position so I an set the mouse cursor at the origin position of the COIN3D drawing?
Or what do you suggest.
Thank you for your help.
Last edited by mariwan on Tue Dec 07, 2021 8:58 pm, edited 1 time in total.
openBrain
Veteran
Posts: 9031
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: QTCursor postion set based on COIN3D Drawing location after a click?

Post by openBrain »

Would you have a minimal Python snippet just to fully understand the issue?
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: QTCursor postion set based on COIN3D Drawing location after a click?

Post by mariwan »

Pleaes you need to have my Workbench installed and loaded in your freecad.
Now run the code and try to click/drag the arrow. You will see the the location is different compared to the mouse click. I must have them the same otherwise the arrow will jump first time you use which can cause a big (extrude, chamfer ..etc ) tool.

Code: Select all

import ThreeDWidgets.fr_arrow_widget as wd
import ThreeDWidgets.fr_coinwindow as wnn
from ThreeDWidgets.constant import FR_COLOR

def callback_move(userData : wd.userDataObject =None):
     ArrowObject = userData.ArrowObj  # Arrow object
     click=App.Vector(ArrowObject.w_parent.link_to_root_handle.w_lastEventXYZ.Coin_x,
                                            ArrowObject.w_parent.link_to_root_handle.w_lastEventXYZ.Coin_y,
                                            ArrowObject.w_parent.link_to_root_handle.w_lastEventXYZ.Coin_z)

     print("clicked at", str(click))
     print("Widget located at", ArrowObject.w_vector)
     ArrowObject.w_vector=click
     ArrowObject.redraw()

mywin = wnn.Fr_CoinWindow()

vectors=App.Vector(0,0,0) 
rot=[0,0,0,0]

root=(wd.Fr_Arrow_Widget(vectors, "X-Axis", 1, FR_COLOR.FR_OLIVEDRAB, rot))

root.w_move_callback_=callback_move
mywin.addWidget(root)

mywin.show()

Attachments
1.JPG
1.JPG (35.7 KiB) Viewed 767 times
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: QTCursor postion set based on COIN3D Drawing location after a click?

Post by mariwan »

I belive I will use this solution.

Code: Select all

import ThreeDWidgets.fr_one_arrow_widget as wd
import ThreeDWidgets.fr_coinwindow as wnn
from ThreeDWidgets.constant import FR_COLOR

class test:
	global runOunce
	def __init__(self):
		self.runOunce = None

	def callback_move(self,userData : wd.userDataObject = None):
     
	     PadObj = userData.PadObj  # Arrow object
	     click=App.Vector(PadObj.w_parent.link_to_root_handle.w_lastEventXYZ.Coin_x,
                                            PadObj.w_parent.link_to_root_handle.w_lastEventXYZ.Coin_y,
                                            PadObj.w_parent.link_to_root_handle.w_lastEventXYZ.Coin_z)
	     if self.runOunce == None:
	           self.runOunce = click.sub(PadObj.w_vector[0])

	     PadObj.w_vector[0]=click.sub(self.runOunce)
	     PadObj.redraw()
	     print(self.runOunce,"self.runOunce")

	def runme(self):
		mywin = wnn.Fr_CoinWindow()
		vectors=[App.Vector(0,0,0), App.Vector(0,0,0)] 
		rot=[0,0,0,0]
		rot1=[1,0,0,0.31]
		root=wd.Fr_OneArrow_Widget(vectors, "X-Axis")
		root.w_move_callback_=self.callback_move
		mywin.addWidget(root)
		mywin.show()

a=test()
a.runme()
Still I don't know how to set the cursor at that position .. might not be good either. So, this solution works.
Post Reply