Merge pull request #5088 from Roy-043/Draft-improvements-for-Draft_Hatch
Draft: improvements for Draft_Hatch
This commit is contained in:
@@ -422,9 +422,9 @@ if App.GuiUp:
|
||||
from draftviewproviders.view_text import (ViewProviderText,
|
||||
ViewProviderDraftText)
|
||||
|
||||
from draftobjects.hatch import (Draft_Hatch_Object)
|
||||
from draftmake.make_hatch import (make_hatch, makeHatch)
|
||||
from draftobjects.hatch import (Hatch)
|
||||
from draftmake.make_hatch import (make_hatch)
|
||||
if App.GuiUp:
|
||||
from draftviewproviders.view_hatch import (Draft_Hatch_ViewProvider)
|
||||
from draftviewproviders.view_hatch import (ViewProviderDraftHatch)
|
||||
|
||||
## @}
|
||||
|
||||
@@ -25,10 +25,11 @@
|
||||
|
||||
import os
|
||||
import FreeCAD
|
||||
import draftguitools.gui_base as gui_base
|
||||
|
||||
from draftutils.translate import translate, QT_TRANSLATE_NOOP
|
||||
|
||||
|
||||
class Draft_Hatch:
|
||||
class Draft_Hatch(gui_base.GuiCommandSimplest):
|
||||
|
||||
|
||||
def GetResources(self):
|
||||
@@ -36,7 +37,7 @@ class Draft_Hatch:
|
||||
return {'Pixmap' : "Draft_Hatch",
|
||||
'MenuText': QT_TRANSLATE_NOOP("Draft_Hatch", "Hatch"),
|
||||
'Accel': "H, A",
|
||||
'ToolTip' : QT_TRANSLATE_NOOP("Draft_Hatch", "Create hatches on selected faces")}
|
||||
'ToolTip' : QT_TRANSLATE_NOOP("Draft_Hatch", "Creates hatches on the faces of a selected object")}
|
||||
|
||||
def Activated(self):
|
||||
|
||||
@@ -89,7 +90,7 @@ class Draft_Hatch_TaskPanel:
|
||||
# create new hatch object
|
||||
FreeCAD.ActiveDocument.openTransaction("Create Hatch")
|
||||
FreeCADGui.addModule("Draft")
|
||||
cmd = "Draft.makeHatch("
|
||||
cmd = "Draft.make_hatch("
|
||||
cmd += "baseobject=FreeCAD.ActiveDocument.getObject(\""+self.baseobj.Name
|
||||
cmd += "\"),filename=\""+self.form.File.property("fileName")
|
||||
cmd += "\",pattern=\""+self.form.Pattern.currentText()
|
||||
|
||||
@@ -23,12 +23,12 @@
|
||||
"""This module contains FreeCAD commands for the Draft workbench"""
|
||||
|
||||
import FreeCAD
|
||||
from draftobjects.hatch import Draft_Hatch_Object
|
||||
from draftviewproviders.view_hatch import Draft_Hatch_ViewProvider
|
||||
from draftobjects.hatch import Hatch
|
||||
from draftviewproviders.view_hatch import ViewProviderDraftHatch
|
||||
|
||||
def makeHatch(baseobject, filename, pattern, scale, rotation):
|
||||
def make_hatch(baseobject, filename, pattern, scale, rotation):
|
||||
|
||||
"""makeHatch(baseobject, filename, pattern, scale, rotation): Creates and returns a
|
||||
"""make_hatch(baseobject, filename, pattern, scale, rotation): Creates and returns a
|
||||
hatch object made by applying the given pattern of the given PAT file to the faces of
|
||||
the given base object. Given scale and rotation factors are applied to the hatch object.
|
||||
The result is a Part-based object created in the active document."""
|
||||
@@ -36,13 +36,11 @@ def makeHatch(baseobject, filename, pattern, scale, rotation):
|
||||
if not FreeCAD.ActiveDocument:
|
||||
return
|
||||
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", "Hatch")
|
||||
Draft_Hatch_Object(obj)
|
||||
Hatch(obj)
|
||||
obj.Base = baseobject
|
||||
obj.File = filename
|
||||
obj.Pattern = pattern
|
||||
obj.Scale = scale
|
||||
obj.Rotation = rotation
|
||||
if FreeCAD.GuiUp:
|
||||
Draft_Hatch_ViewProvider(obj.ViewObject)
|
||||
|
||||
make_hatch = makeHatch
|
||||
ViewProviderDraftHatch(obj.ViewObject)
|
||||
|
||||
@@ -30,7 +30,7 @@ from draftutils.translate import translate, QT_TRANSLATE_NOOP
|
||||
|
||||
|
||||
|
||||
class Draft_Hatch_Object:
|
||||
class Hatch:
|
||||
|
||||
|
||||
def __init__(self,obj):
|
||||
@@ -41,12 +41,6 @@ class Draft_Hatch_Object:
|
||||
def setProperties(self,obj):
|
||||
|
||||
pl = obj.PropertiesList
|
||||
if not "Placement" in pl:
|
||||
obj.addProperty("App::PropertyPlacement","Placement","Hatch",
|
||||
QT_TRANSLATE_NOOP("App::Property","The placement of this object"))
|
||||
if not "Shape" in pl:
|
||||
obj.addProperty("Part::PropertyPartShape","Shape","Hatch",
|
||||
QT_TRANSLATE_NOOP("App::Property","The shape of this object"))
|
||||
if not "Base" in pl:
|
||||
obj.addProperty("App::PropertyLink","Base","Hatch",
|
||||
QT_TRANSLATE_NOOP("App::Property","The base object used by this object"))
|
||||
@@ -103,23 +97,30 @@ class Draft_Hatch_Object:
|
||||
pla = obj.Placement
|
||||
shapes = []
|
||||
for face in obj.Base.Shape.Faces:
|
||||
face = face.copy()
|
||||
if obj.Translate:
|
||||
bpoint = face.CenterOfMass
|
||||
norm = face.normalAt(0,0)
|
||||
fpla = FreeCAD.Placement(bpoint,FreeCAD.Rotation(FreeCAD.Vector(0,0,1),norm))
|
||||
face.Placement = face.Placement.multiply(fpla.inverse())
|
||||
if obj.Rotation:
|
||||
face.rotate(FreeCAD.Vector(),FreeCAD.Vector(0,0,1),obj.Rotation)
|
||||
shape = TechDraw.makeGeomHatch(face,obj.Scale,obj.Pattern,obj.File)
|
||||
if obj.Rotation:
|
||||
shape.rotate(FreeCAD.Vector(),FreeCAD.Vector(0,0,1),-obj.Rotation)
|
||||
if obj.Translate:
|
||||
shape.Placement = shape.Placement.multiply(fpla)
|
||||
shapes.append(shape)
|
||||
if face.findPlane(): # Only planar faces.
|
||||
face = face.copy()
|
||||
if obj.Translate:
|
||||
e = face.Edges[0] # Todo: check for almost zero-length edge.
|
||||
sta = e.firstVertex().Point
|
||||
end = e.lastVertex().Point
|
||||
u = end.sub(sta).normalize()
|
||||
w = face.normalAt(0, 0)
|
||||
v = w.cross(u)
|
||||
m = FreeCAD.Matrix(u.x, v.x, w.x, sta.x,
|
||||
u.y, v.y, w.y, sta.y,
|
||||
u.z, v.z, w.z, sta.z,
|
||||
0.0, 0.0, 0.0, 1.0)
|
||||
face = face.transformGeometry(m.inverse()).Faces[0]
|
||||
if obj.Rotation.Value:
|
||||
face.rotate(FreeCAD.Vector(), FreeCAD.Vector(0,0,1), -obj.Rotation)
|
||||
shape = TechDraw.makeGeomHatch(face, obj.Scale, obj.Pattern, obj.File)
|
||||
if obj.Rotation.Value:
|
||||
shape.rotate(FreeCAD.Vector(), FreeCAD.Vector(0,0,1), obj.Rotation)
|
||||
if obj.Translate:
|
||||
shape = shape.transformGeometry(m)
|
||||
shapes.append(shape)
|
||||
if shapes:
|
||||
obj.Shape = Part.makeCompound(shapes)
|
||||
obj.Placement = pla
|
||||
|
||||
def getPatterns(self,filename):
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import os
|
||||
import FreeCAD
|
||||
from draftguitools.gui_hatch import Draft_Hatch_TaskPanel
|
||||
|
||||
class Draft_Hatch_ViewProvider:
|
||||
class ViewProviderDraftHatch:
|
||||
|
||||
|
||||
def __init__(self,vobj):
|
||||
|
||||
Reference in New Issue
Block a user