From d835c119735365336d202dc7ffa08b638d00a5c5 Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Sat, 6 May 2017 22:34:02 +0300 Subject: [PATCH] Draft: use viewer.redraw() in interactive operations improves responsiveness of Draft on Windows dramatically --- src/Mod/Draft/DraftTools.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py index fcc2f63bb1..c1679670d3 100644 --- a/src/Mod/Draft/DraftTools.py +++ b/src/Mod/Draft/DraftTools.py @@ -447,6 +447,13 @@ class SelectPlane(DraftTool): # Geometry constructors #--------------------------------------------------------------------------- +def redraw3DView(): + """redraw3DView(): forces a redraw of 3d view.""" + try: + FreeCADGui.ActiveDocument.ActiveView.redraw() + except AttributeError as err: + pass + class Creator(DraftTool): "A generic Draft Creator Tool used by creation tools such as line or arc" @@ -527,6 +534,7 @@ class Line(Creator): elif arg["Type"] == "SoLocation2Event": # mouse movement detection self.point,ctrlPoint,info = getPoint(self,arg) + redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": # mouse button detection if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): @@ -670,6 +678,7 @@ class BSpline(Line): elif arg["Type"] == "SoLocation2Event": #mouse movement detection self.point,ctrlPoint,info = getPoint(self,arg,noTracker=True) self.bsplinetrack.update(self.node + [self.point]) + redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): if (arg["Position"] == self.pos): @@ -768,6 +777,7 @@ class BezCurve(Line): elif arg["Type"] == "SoLocation2Event": #mouse movement detection self.point,ctrlPoint,info = getPoint(self,arg,noTracker=True) self.bezcurvetrack.update(self.node + [self.point]) #existing points + this pointer position + redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): #left click if (arg["Position"] == self.pos): #double click? @@ -989,6 +999,7 @@ class Rectangle(Creator): elif arg["Type"] == "SoLocation2Event": #mouse movement detection self.point,ctrlPoint,info = getPoint(self,arg,mobile=True,noTracker=True) self.rect.update(self.point) + redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): if (arg["Position"] == self.pos): @@ -1157,6 +1168,8 @@ class Arc(Creator): self.ui.setRadiusValue(math.degrees(self.angle),unit="Angle") self.arctrack.setApertureAngle(self.angle) + redraw3DView() + elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): if self.point: @@ -1439,6 +1452,8 @@ class Polygon(Creator): self.ui.setRadiusValue(self.rad,'Length') self.arctrack.setRadius(self.rad) + redraw3DView() + elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): if self.point: @@ -1615,6 +1630,7 @@ class Ellipse(Creator): elif arg["Type"] == "SoLocation2Event": #mouse movement detection self.point,ctrlPoint,info = getPoint(self,arg,mobile=True,noTracker=True) self.rect.update(self.point) + redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): if (arg["Position"] == self.pos): @@ -1701,6 +1717,7 @@ class Text(Creator): elif arg["Type"] == "SoLocation2Event": #mouse movement detection if self.active: self.point,ctrlPoint,info = getPoint(self,arg) + redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): if self.point: @@ -1965,6 +1982,7 @@ class Dimension(Creator): # update the dimline if self.node and (not self.arcmode): self.dimtrack.update(self.node+[self.point]+[self.cont]) + redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): import DraftGeomUtils @@ -2128,6 +2146,7 @@ class ShapeString(Creator): elif arg["Type"] == "SoLocation2Event": #mouse movement detection if self.active: self.point,ctrlPoint,info = getPoint(self,arg,noTracker=True) + redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): if not self.ssBase: @@ -2269,6 +2288,7 @@ class Move(Modifier): self.ghost.on() if self.extendedCopy: if not hasMod(arg,MODALT): self.finish() + redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): if self.point: @@ -2457,6 +2477,7 @@ class Rotate(Modifier): self.ui.setRadiusValue(math.degrees(sweep), 'Angle') self.ui.radiusValue.setFocus() self.ui.radiusValue.selectAll() + redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): @@ -2656,6 +2677,7 @@ class Offset(Modifier): self.ui.radiusValue.selectAll() if self.extendedCopy: if not hasMod(arg,MODALT): self.finish() + redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): @@ -2764,6 +2786,7 @@ class Stretch(Modifier): point,ctrlPoint,info = getPoint(self,arg) #,mobile=True) #,noTracker=(self.step < 3)) if self.step == 2: self.rectracker.update(point) + redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): if (arg["Position"] == self.pos): @@ -3163,6 +3186,7 @@ class Trimex(Modifier): self.ui.setRadiusValue(dist,unit="Length") self.ui.radiusValue.setFocus() self.ui.radiusValue.selectAll() + redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): @@ -3547,6 +3571,7 @@ class Scale(Modifier): self.ui.zValue.setText("1") if self.extendedCopy: if not hasMod(arg,MODALT): self.finish() + redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): if self.point: @@ -3937,6 +3962,7 @@ class Edit(Modifier): # commented out the following line to disable updating # the object during edit, otherwise it confuses the snapper #self.update(self.trackers[self.editing].get()) + redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): self.ui.redraw() @@ -4106,6 +4132,10 @@ class Edit(Modifier): self.obj.TagPosition = self.invpl.multVec(v) else: self.obj.Group[self.editing-1].Placement.Base = self.invpl.multVec(v) + try: + FreeCADGui.ActiveDocument.ActiveView.redraw() + except AttributeError as err: + pass def numericInput(self,v,numy=None,numz=None): '''this function gets called by the toolbar @@ -4968,6 +4998,7 @@ class Mirror(Modifier): self.ghost.setMatrix(m) if self.extendedCopy: if not hasMod(arg,MODALT): self.finish() + redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): if self.point: