Draft: Introduced Hatch command + object
This commit is contained in:
@@ -137,6 +137,7 @@ SET(Draft_make_functions
|
||||
draftmake/make_text.py
|
||||
draftmake/make_wire.py
|
||||
draftmake/make_wpproxy.py
|
||||
draftmake/make_hatch.py
|
||||
draftmake/README.md
|
||||
)
|
||||
|
||||
@@ -169,6 +170,7 @@ SET(Draft_objects
|
||||
draftobjects/text.py
|
||||
draftobjects/wire.py
|
||||
draftobjects/wpproxy.py
|
||||
draftobjects/hatch.py
|
||||
draftobjects/README.md
|
||||
)
|
||||
|
||||
@@ -194,6 +196,7 @@ SET(Draft_view_providers
|
||||
draftviewproviders/view_text.py
|
||||
draftviewproviders/view_wire.py
|
||||
draftviewproviders/view_wpproxy.py
|
||||
draftviewproviders/view_hatch.py
|
||||
draftviewproviders/README.md
|
||||
)
|
||||
|
||||
@@ -213,6 +216,7 @@ SET(Creator_tools
|
||||
draftguitools/gui_points.py
|
||||
draftguitools/gui_facebinders.py
|
||||
draftguitools/gui_labels.py
|
||||
draftguitools/gui_hatch.py
|
||||
)
|
||||
|
||||
SET(Modifier_tools
|
||||
|
||||
@@ -422,4 +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)
|
||||
if App.GuiUp:
|
||||
from draftviewproviders.view_hatch import (Draft_Hatch_ViewProvider)
|
||||
|
||||
## @}
|
||||
|
||||
@@ -168,6 +168,7 @@ from draftguitools.gui_shapestrings import ShapeString
|
||||
from draftguitools.gui_points import Point
|
||||
from draftguitools.gui_facebinders import Draft_Facebinder
|
||||
from draftguitools.gui_labels import Draft_Label
|
||||
from draftguitools.gui_hatch import Draft_Hatch
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Modifier functions
|
||||
|
||||
@@ -107,6 +107,7 @@
|
||||
<file>icons/Snap_Special.svg</file>
|
||||
<file>icons/Snap_WorkingPlane.svg</file>
|
||||
<file>icons/Draft_NewLayer.svg</file>
|
||||
<file>icons/Draft_Hatch.svg</file>
|
||||
<file>patterns/aluminium.svg</file>
|
||||
<file>patterns/brick01.svg</file>
|
||||
<file>patterns/concrete.svg</file>
|
||||
@@ -184,5 +185,6 @@
|
||||
<file>ui/TaskShapeString.ui</file>
|
||||
<file>ui/dialog_AnnotationStyleEditor.ui</file>
|
||||
<file>ui/TaskPanel_SetStyle.ui</file>
|
||||
<file>ui/dialogHatch.ui</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
height="64"
|
||||
width="64"
|
||||
version="1.1"
|
||||
id="svg3542"
|
||||
sodipodi:docname="Draft_Hatch.svg"
|
||||
inkscape:version="1.0.2 (e86c870879, 2021-01-15)">
|
||||
<sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1051"
|
||||
id="namedview30"
|
||||
showgrid="false"
|
||||
inkscape:zoom="3.6902135"
|
||||
inkscape:cx="110.72455"
|
||||
inkscape:cy="69.551041"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg3542"
|
||||
inkscape:document-rotation="0" />
|
||||
<title
|
||||
id="title854">TechDraw_TreeHatch</title>
|
||||
<metadata
|
||||
id="metadata3552">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title>TechDraw_TreeHatch</dc:title>
|
||||
<dc:creator>
|
||||
<cc:Agent>
|
||||
<dc:title>[WandererFan]</dc:title>
|
||||
</cc:Agent>
|
||||
</dc:creator>
|
||||
<dc:title>TechDraw_TreeHatch</dc:title>
|
||||
<dc:date>2016-04-27</dc:date>
|
||||
<dc:relation>http://www.freecadweb.org/wiki/index.php?title=Artwork</dc:relation>
|
||||
<dc:publisher>
|
||||
<cc:Agent>
|
||||
<dc:title>FreeCAD</dc:title>
|
||||
</cc:Agent>
|
||||
</dc:publisher>
|
||||
<dc:identifier>FreeCAD/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_TreeHatch.svg</dc:identifier>
|
||||
<dc:rights>
|
||||
<cc:Agent>
|
||||
<dc:title>FreeCAD LGPL2+</dc:title>
|
||||
</cc:Agent>
|
||||
</dc:rights>
|
||||
<cc:license>https://www.gnu.org/copyleft/lesser.html</cc:license>
|
||||
<dc:contributor>
|
||||
<cc:Agent>
|
||||
<dc:title>[agryson] Alexander Gryson</dc:title>
|
||||
</cc:Agent>
|
||||
</dc:contributor>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<defs
|
||||
id="defs3544">
|
||||
<linearGradient
|
||||
id="linearGradient3807">
|
||||
<stop
|
||||
id="stop3809"
|
||||
offset="0"
|
||||
style="stop-color:#d3d7cf;stop-opacity:1" />
|
||||
<stop
|
||||
id="stop3811"
|
||||
offset="1"
|
||||
style="stop-color:#ffffff;stop-opacity:1" />
|
||||
</linearGradient>
|
||||
<pattern
|
||||
height=".1"
|
||||
width=".1"
|
||||
y="0"
|
||||
x="0"
|
||||
patternUnits="userSpaceOnUse"
|
||||
id="cross">
|
||||
<g
|
||||
id="g3382"
|
||||
style="fill:none; stroke:#000000; stroke-width:.005">
|
||||
<path
|
||||
id="path3384"
|
||||
d="M0,0 l.12,.12" />
|
||||
<path
|
||||
id="path3386"
|
||||
d="M.12,0 l-.12,.12" />
|
||||
</g>
|
||||
</pattern>
|
||||
<linearGradient
|
||||
gradientUnits="userSpaceOnUse"
|
||||
y2="10"
|
||||
x2="37"
|
||||
y1="59"
|
||||
x1="44"
|
||||
id="linearGradient3813"
|
||||
xlink:href="#linearGradient3807" />
|
||||
</defs>
|
||||
<path
|
||||
style="fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;fill-opacity:1"
|
||||
d="m 35.554173,7.186196 h 21.125503 l 0.2648,49.823336 H 7.2893958 L 7.64097,34.189786 34.151151,33.767917 Z"
|
||||
id="path858"
|
||||
sodipodi:nodetypes="ccccccc" />
|
||||
<rect
|
||||
style="color:#000000;overflow:visible;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.6;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;stop-color:#000000;font-variation-settings:normal;opacity:1;vector-effect:none;stroke-dashoffset:0;stop-opacity:1"
|
||||
id="rect866"
|
||||
width="29.70842"
|
||||
height="5.2460818"
|
||||
x="30.890678"
|
||||
y="-21.753223"
|
||||
transform="rotate(45)" />
|
||||
<rect
|
||||
style="color:#000000;overflow:visible;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.6;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;stop-color:#000000;font-variation-settings:normal;opacity:1;vector-effect:none;stroke-dashoffset:0;stop-opacity:1"
|
||||
id="rect866-3"
|
||||
width="29.70842"
|
||||
height="5.2460818"
|
||||
x="40.526852"
|
||||
y="-11.281341"
|
||||
transform="rotate(45)" />
|
||||
<rect
|
||||
style="color:#000000;overflow:visible;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.6;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;stop-color:#000000;font-variation-settings:normal;opacity:1;vector-effect:none;stroke-dashoffset:0;stop-opacity:1"
|
||||
id="rect866-6"
|
||||
width="29.70842"
|
||||
height="5.2460818"
|
||||
x="46.942085"
|
||||
y="3.5527137e-15"
|
||||
transform="rotate(45)" />
|
||||
<rect
|
||||
style="color:#000000;overflow:visible;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.6;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;stop-color:#000000;font-variation-settings:normal;opacity:1;vector-effect:none;stroke-dashoffset:0;stop-opacity:1"
|
||||
id="rect866-7"
|
||||
width="29.70842"
|
||||
height="5.2460818"
|
||||
x="36.091351"
|
||||
y="11.061804"
|
||||
transform="rotate(45)" />
|
||||
<rect
|
||||
style="color:#000000;overflow:visible;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.6;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;stop-color:#000000;font-variation-settings:normal;opacity:1;vector-effect:none;stroke-dashoffset:0;stop-opacity:1"
|
||||
id="rect866-5"
|
||||
width="21.511063"
|
||||
height="5.3138289"
|
||||
x="34.473373"
|
||||
y="22.273962"
|
||||
transform="rotate(45)" />
|
||||
<rect
|
||||
style="color:#000000;overflow:visible;fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.6;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;stop-color:#000000;font-variation-settings:normal;opacity:1;vector-effect:none;stroke-dashoffset:0;stop-opacity:1"
|
||||
id="rect866-5-3"
|
||||
width="12.4612"
|
||||
height="4.907351"
|
||||
x="39.141003"
|
||||
y="-32.287083"
|
||||
transform="rotate(45)" />
|
||||
<g
|
||||
id="rect4151"
|
||||
style="opacity:1;fill:#ffed24;fill-opacity:1;stroke:#433c21;stroke-width:2.11221675;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;font-variation-settings:normal;vector-effect:none;stroke-linecap:round;stroke-linejoin:round;stroke-dashoffset:0;stop-color:#000000;stop-opacity:1"
|
||||
transform="matrix(0.85218527,0,0,0.85218527,4.7300714,4.7300714)">
|
||||
<path
|
||||
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-variant-east-asian:normal;font-feature-settings:normal;font-variation-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;shape-margin:0;inline-size:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#ffed24;fill-opacity:1;fill-rule:nonzero;stroke:#433c21;stroke-width:2.11221675;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate;stop-color:#000000;stop-opacity:1"
|
||||
d="M 35.076172,0.05078125 A 2.950295,2.950295 0 0 0 32.126953,3 V 31.150391 H 3 A 2.950295,2.950295 0 0 0 0.05078125,34.101562 V 61 A 2.950295,2.950295 0 0 0 3,63.949219 H 61 A 2.950295,2.950295 0 0 0 63.949219,61 V 3 A 2.950295,2.950295 0 0 0 61,0.05078125 Z m 2.949219,5.89843755 h 20.02539 V 58.050781 H 5.9492188 v -21 H 35.076172 a 2.950295,2.950295 0 0 0 2.949219,-2.949219 z"
|
||||
id="path859" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 8.5 KiB |
@@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>227</width>
|
||||
<height>142</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="Pattern"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="Gui::FileChooser" name="File">
|
||||
<property name="filter">
|
||||
<string>pattern files (*.pat)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>PAT file:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Scale</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Pattern:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QDoubleSpinBox" name="Scale">
|
||||
<property name="suffix">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>999999.000000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Rotation:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QDoubleSpinBox" name="Rotation">
|
||||
<property name="suffix">
|
||||
<string>°</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>359.990000000000009</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Gui::FileChooser</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>Gui/FileDialog.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,132 @@
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2021 Yorik van Havre <[email protected]> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
|
||||
"""This module contains FreeCAD commands for the Draft workbench"""
|
||||
|
||||
import os
|
||||
import FreeCAD
|
||||
from draftutils.translate import translate, QT_TRANSLATE_NOOP
|
||||
|
||||
|
||||
class Draft_Hatch:
|
||||
|
||||
|
||||
def GetResources(self):
|
||||
|
||||
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")}
|
||||
|
||||
def Activated(self):
|
||||
|
||||
import FreeCADGui
|
||||
|
||||
if FreeCADGui.Selection.getSelection():
|
||||
FreeCADGui.Control.showDialog(Draft_Hatch_TaskPanel(FreeCADGui.Selection.getSelection()[0]))
|
||||
else:
|
||||
FreeCAD.Console.PrintError(translate("Draft","You must choose a base object before using this command")+"\n")
|
||||
|
||||
|
||||
class Draft_Hatch_TaskPanel:
|
||||
|
||||
|
||||
def __init__(self,baseobj):
|
||||
|
||||
import FreeCADGui
|
||||
from PySide import QtCore,QtGui
|
||||
import Draft_rc
|
||||
|
||||
self.baseobj = baseobj
|
||||
self.form = FreeCADGui.PySideUic.loadUi(":/ui/dialogHatch.ui")
|
||||
self.form.setWindowIcon(QtGui.QIcon(":/icons/Draft_Hatch.svg"))
|
||||
self.form.File.fileNameChanged.connect(self.onFileChanged)
|
||||
self.p1 = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/TechDraw/PAT")
|
||||
self.p2 = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
|
||||
self.form.File.setFileName(self.p1.GetString("FilePattern",""))
|
||||
pat = self.p1.GetString("NamePattern","")
|
||||
if pat in [self.form.Pattern.itemText(i) for i in range(self.form.Pattern.count())]:
|
||||
self.form.Pattern.setCurrentText(pat)
|
||||
self.form.Scale.setValue(self.p2.GetFloat("HatchPatternScale",1000.0))
|
||||
self.form.Rotation.setValue(self.p2.GetFloat("HatchPatternRotation",0.0))
|
||||
|
||||
def accept(self):
|
||||
|
||||
import FreeCADGui
|
||||
|
||||
self.p1.SetString("FilePattern",self.form.File.property("fileName"))
|
||||
self.p1.SetString("NamePattern",self.form.Pattern.currentText())
|
||||
self.p2.SetFloat("HatchPatternScale",self.form.Scale.value())
|
||||
self.p2.SetFloat("HatchPatternRotation",self.form.Rotation.value())
|
||||
if hasattr(self.baseobj,"File") and hasattr(self.baseobj,"Pattern"):
|
||||
# modify existing hatch object
|
||||
o = "FreeCAD.ActiveDocument.getObject(\""+self.baseobj.Name+"\")"
|
||||
FreeCADGui.doCommand(o+".File=\""+self.form.File.property("fileName")+"\"")
|
||||
FreeCADGui.doCommand(o+".Pattern=\""+self.form.Pattern.currentText()+"\"")
|
||||
FreeCADGui.doCommand(o+".Scale="+str(self.form.Scale.value()))
|
||||
FreeCADGui.doCommand(o+".Rotation="+str(self.form.Rotation.value()))
|
||||
else:
|
||||
# create new hatch object
|
||||
FreeCAD.ActiveDocument.openTransaction("Create Hatch")
|
||||
FreeCADGui.addModule("Draft")
|
||||
cmd = "Draft.makeHatch("
|
||||
cmd += "baseobject=FreeCAD.ActiveDocument.getObject(\""+self.baseobj.Name
|
||||
cmd += "\"),filename=\""+self.form.File.property("fileName")
|
||||
cmd += "\",pattern=\""+self.form.Pattern.currentText()
|
||||
cmd += "\",scale="+str(self.form.Scale.value())
|
||||
cmd += ",rotation="+str(self.form.Rotation.value())+")"
|
||||
FreeCADGui.doCommand(cmd)
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
FreeCADGui.doCommand("FreeCAD.ActiveDocument.recompute()")
|
||||
self.reject()
|
||||
|
||||
def reject(self):
|
||||
|
||||
import FreeCADGui
|
||||
|
||||
FreeCADGui.Control.closeDialog()
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
def onFileChanged(self,filename):
|
||||
|
||||
pat = self.form.Pattern.currentText()
|
||||
self.form.Pattern.clear()
|
||||
patterns = self.getPatterns(filename)
|
||||
self.form.Pattern.addItems(patterns)
|
||||
if pat in patterns:
|
||||
self.form.Pattern.setCurrentText(pat)
|
||||
|
||||
def getPatterns(self,filename):
|
||||
|
||||
"""returns a list of pattern names found in a PAT file"""
|
||||
patterns = []
|
||||
if os.path.exists(filename):
|
||||
with open(filename) as patfile:
|
||||
for line in patfile:
|
||||
if line.startswith("*"):
|
||||
patterns.append(line.split(",")[0][1:])
|
||||
return patterns
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
import FreeCADGui
|
||||
FreeCADGui.addCommand("Draft_Hatch",Draft_Hatch())
|
||||
@@ -0,0 +1,48 @@
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2021 Yorik van Havre <[email protected]> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
"""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
|
||||
|
||||
def makeHatch(baseobject,filename,pattern,scale,rotation):
|
||||
|
||||
"""makeHatch(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 inthe active document."""
|
||||
|
||||
if not FreeCAD.ActiveDocument:
|
||||
return
|
||||
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Hatch")
|
||||
Draft_Hatch_Object(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
|
||||
@@ -0,0 +1,133 @@
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2021 Yorik van Havre <[email protected]> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
|
||||
"""This module contains FreeCAD commands for the Draft workbench"""
|
||||
|
||||
import os
|
||||
import FreeCAD
|
||||
from draftutils.translate import translate, QT_TRANSLATE_NOOP
|
||||
|
||||
|
||||
|
||||
|
||||
class Draft_Hatch_Object:
|
||||
|
||||
|
||||
def __init__(self,obj):
|
||||
|
||||
obj.Proxy = self
|
||||
self.setProperties(obj)
|
||||
|
||||
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"))
|
||||
if not "File" in pl:
|
||||
obj.addProperty("App::PropertyFile","File","Hatch",
|
||||
QT_TRANSLATE_NOOP("App::Property","The PAT file used by this object"))
|
||||
if not "Pattern" in pl:
|
||||
obj.addProperty("App::PropertyString","Pattern","Hatch",
|
||||
QT_TRANSLATE_NOOP("App::Property","The pattern name used by this object"))
|
||||
if not "Scale" in pl:
|
||||
obj.addProperty("App::PropertyFloat","Scale","Hatch",
|
||||
QT_TRANSLATE_NOOP("App::Property","The pattern scale used by this object"))
|
||||
if not "Rotation" in pl:
|
||||
obj.addProperty("App::PropertyAngle","Rotation","Hatch",
|
||||
QT_TRANSLATE_NOOP("App::Property","The pattern rotation used by this object"))
|
||||
if not "Translate" in pl:
|
||||
obj.addProperty("App::PropertyBool","Translate","Hatch",
|
||||
QT_TRANSLATE_NOOP("App::Property","If set to False, hatch is applied as is to the faces, without translation (this might give wrong results for non-XY faces)"))
|
||||
obj.Translate = True
|
||||
self.Type = "Hatch"
|
||||
|
||||
def onDocumentRestored(self,obj):
|
||||
|
||||
self.setProperties(obj)
|
||||
|
||||
def __getstate__(self):
|
||||
|
||||
return None
|
||||
|
||||
def __setstate__(self,state):
|
||||
|
||||
return None
|
||||
|
||||
def execute(self,obj):
|
||||
|
||||
import Part
|
||||
import TechDraw
|
||||
|
||||
if not obj.Base:
|
||||
return
|
||||
if not obj.File:
|
||||
return
|
||||
if not obj.Pattern:
|
||||
return
|
||||
if not obj.Scale:
|
||||
return
|
||||
if not obj.Pattern in self.getPatterns(obj.File):
|
||||
return
|
||||
if not obj.Base.isDerivedFrom("Part::Feature"):
|
||||
return
|
||||
if not obj.Base.Shape.Faces:
|
||||
return
|
||||
|
||||
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 shapes:
|
||||
obj.Shape = Part.makeCompound(shapes)
|
||||
obj.Placement = pla
|
||||
|
||||
def getPatterns(self,filename):
|
||||
|
||||
"""returns a list of pattern names found in a PAT file"""
|
||||
patterns = []
|
||||
if os.path.exists(filename):
|
||||
with open(filename) as patfile:
|
||||
for line in patfile:
|
||||
if line.startswith("*"):
|
||||
patterns.append(line.split(",")[0][1:])
|
||||
return patterns
|
||||
@@ -45,7 +45,7 @@ def get_draft_drawing_commands():
|
||||
"Draft_Circle", "Draft_Ellipse", "Draft_Rectangle",
|
||||
"Draft_Polygon", "Draft_BSpline", "Draft_BezierTools",
|
||||
"Draft_Point", "Draft_Facebinder",
|
||||
"Draft_ShapeString"]
|
||||
"Draft_ShapeString","Draft_Hatch"]
|
||||
|
||||
|
||||
def get_draft_annotation_commands():
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2021 Yorik van Havre <[email protected]> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
|
||||
"""This module contains FreeCAD commands for the Draft workbench"""
|
||||
|
||||
import os
|
||||
import FreeCAD
|
||||
from draftguitools.gui_hatch import Draft_Hatch_TaskPanel
|
||||
|
||||
class Draft_Hatch_ViewProvider:
|
||||
|
||||
|
||||
def __init__(self,vobj):
|
||||
|
||||
vobj.Proxy = self
|
||||
|
||||
def getIcon(self):
|
||||
|
||||
return ":/icons/Draft_Hatch.svg"
|
||||
|
||||
def __getstate__(self):
|
||||
|
||||
return None
|
||||
|
||||
def __setstate__(self,state):
|
||||
|
||||
return None
|
||||
|
||||
def setEdit(self,vobj,mode):
|
||||
|
||||
import FreeCADGui
|
||||
|
||||
taskd = Draft_Hatch_TaskPanel(vobj.Object)
|
||||
taskd.form.File.setFileName(vobj.Object.File)
|
||||
taskd.form.Pattern.setCurrentText(vobj.Object.Pattern)
|
||||
taskd.form.Scale.setValue(vobj.Object.Scale)
|
||||
taskd.form.Rotation.setValue(vobj.Object.Rotation)
|
||||
FreeCADGui.Control.showDialog(taskd)
|
||||
return True
|
||||
|
||||
def unsetEdit(self,vobj,mode):
|
||||
|
||||
import FreeCADGui
|
||||
|
||||
FreeCADGui.Control.closeDialog()
|
||||
return True
|
||||
|
||||
def doubleClicked(self,vobj):
|
||||
|
||||
self.setEdit(vobj,None)
|
||||
Reference in New Issue
Block a user