On 19/05/2013 at 07:57, xxxxxxxx wrote:
Is something unclear about my question ? It seems to be rather common problem for me. At
least in python I am not sure if ToolDescriptionData behaves differently in cpp. What I do
really not understand is why there is no update at all while I am dragging, instead of a
sluggish GUI/update behaviour because I do run everything from one thread.
If some code helps for giving me an answer, I will try to show the update cycle on the
example of an editor view mouse drag. The tool is working with a cache of the objects
point and polygon data, so you can drag the sliders back and forth and they will always
relate to the state when the tool has been raised.
# --- Implements value mouse/editor manipulation and cursor change while drag event.
# -----------------------------------------------------------------------------------------------
def MouseInput(self, doc, data, bd, win, msg) :
startbc, currentbc, ox, dv = c4d.BaseContainer(), c4d.BaseContainer(), None, None
# starting mouse state
isok = gui.GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_MOUSELEFT, startbc)
# start drag
if isok and startbc[c4d.BFM_INPUT_VALUE]:
sx = startbc.GetLong(c4d.BFM_INPUT_X)
# loop while mouse drag
while gui.GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_MOUSELEFT, currentbc) :
if currentbc.GetLong(c4d.BFM_INPUT_VALUE) == 0: break
gui.SetMousePointer(c4d.MOUSE_ARROW_H)
x = currentbc.GetLong(c4d.BFM_INPUT_X)
# change dialog values when x != ox
if self.Dialog and x != ox:
# reset sx if drag vector changed
if dv != None and (dv>0) != (x-ox > 0) : sx = x
# check for shift qualifier and adjust dragscale
if currentbc[c4d.BFM_INPUT_QUALIFIER] == c4d.QSHIFT:
scale = fhPolyTools.ID_MOUSE_DRAGSMALL
else : scale = fhPolyTools.ID_MOUSE_DRAGBIG
# edit the dialog value with the mouse data
dialogvalue = self.Dialog.GetReal(fhPolyTools.IDC_STRAIGHTEN_STRENGHT_EDT)
value = round(c4d.utils.Clamp(0.001, 1, dialogvalue + ((x - sx) * 0.01) * scale), 4)
self.Dialog.SetPercent(id = fhPolyTools.IDC_STRAIGHTEN_STRENGHT_EDT, value = value,
min = 0.0, max = 100.0, step = 0.01, tristate = False)
self.Dialog.Update()
# set dragvector and last pos
if ox: dv = x - ox
ox = x
# set cursor back
gui.SetMousePointer(c4d.MOUSE_NORMAL)
return isok
the orange line calls GeDialog.Update() in my tools dialog, which then simply calls back to the
tool itself:
def Update(self) :
return self.Host.Update(strenght = self.GetReal(fhPolyTools.IDC_STRAIGHTEN_STRENGHT_EDT),
relax = self.GetReal(fhPolyTools.IDC_STRAIGHTEN_RELAX_EDT),
distribution = self.GetReal(fhPolyTools.IDC_STRAIGHTEN_UNIFORM_CHK))
the ToolData.Update() method loops through some earlier processed ordered point data to
apply the transform method ToolData.straightenEdge() which then updates the point array
of the object which is then written into the object. undos are currently implemented in
other methods.
# --- Update method called by the dialog and mouse input
# --> Bool
# -----------------------------------------------------------------------------------------------
def Update(self, strenght, relax, distribution) :
doc = documents.GetActiveDocument()
if self.GetData(doc) :
# copy cache
data = self.PointCache[:]
for pointgroup in self.PointGroups.PointGroups:
data = self.straightenEdge(data, pointgroup, strenght, True)
if not data: return False
# update object
self.Object.SetAllPoints(data)
self.Object.Message(c4d.MSG_CHANGE)
c4d.EventAdd()
return True
return False
so which part do i have to put into a thread ?