+ unify DLL export defines to namespace names
git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5000 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
84
src/Mod/PartDesign/Scripts/DistanceBolt.py
Normal file
84
src/Mod/PartDesign/Scripts/DistanceBolt.py
Normal file
@@ -0,0 +1,84 @@
|
||||
"""
|
||||
An example for a high-level cutsom feature object to form a full-parametric distance bolt.
|
||||
|
||||
***************************************************************************
|
||||
* Copyright (c) 2010 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License (GPL) *
|
||||
* 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. *
|
||||
* *
|
||||
* FreeCAD 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 FreeCAD; if not, write to the Free Software *
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* USA *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
|
||||
__author__ = "Werner Mayer <wmayer@users.sourceforge.net>"
|
||||
|
||||
import FreeCAD, Part, math
|
||||
from FreeCAD import Base
|
||||
|
||||
class DistanceBolt:
|
||||
def __init__(self, obj):
|
||||
''' Add the properties: Length, Edges, Radius, Height '''
|
||||
obj.addProperty("App::PropertyInteger","Edges","Bolt","Number of edges of the outline").Edges=6
|
||||
obj.addProperty("App::PropertyLength","Length","Bolt","Length of the edges of the outline").Length=10.0
|
||||
obj.addProperty("App::PropertyLength","Radius","Bolt","Radius of the inner circle").Radius=4.0
|
||||
obj.addProperty("App::PropertyLength","Height","Bolt","Height of the extrusion").Height=20.0
|
||||
obj.Proxy = self
|
||||
|
||||
def onChanged(self, fp, prop):
|
||||
if prop == "Edges" or prop == "Length" or prop == "Radius" or prop == "Height":
|
||||
self.execute(fp)
|
||||
|
||||
def execute(self, fp):
|
||||
edges = fp.Edges
|
||||
if edges < 3:
|
||||
edges = 3
|
||||
length = fp.Length
|
||||
radius = fp.Radius
|
||||
height = fp.Height
|
||||
|
||||
m=Base.Matrix()
|
||||
m.rotateZ(math.radians(360.0/edges))
|
||||
|
||||
# create polygon
|
||||
polygon = []
|
||||
v=Base.Vector(length,0,0)
|
||||
for i in range(edges):
|
||||
polygon.append(v)
|
||||
v = m.multiply(v)
|
||||
polygon.append(v)
|
||||
wire = Part.makePolygon(polygon)
|
||||
|
||||
# create circle
|
||||
circ=Part.makeCircle(radius)
|
||||
|
||||
# Create the face with the polygon as outline and the circle as hole
|
||||
face=Part.Face([wire,Part.Wire(circ)])
|
||||
|
||||
# Extrude in z to create the final solid
|
||||
extrude=face.extrude(Base.Vector(0,0,height))
|
||||
fp.Shape = extrude
|
||||
|
||||
def makeDistanceBolt():
|
||||
doc = FreeCAD.activeDocument()
|
||||
if doc == None:
|
||||
doc = FreeCAD.newDocument()
|
||||
bolt=doc.addObject("Part::FeaturePython","Distance_Bolt")
|
||||
bolt.Label = "Distance bolt"
|
||||
DistanceBolt(bolt)
|
||||
bolt.ViewObject.Proxy=0
|
||||
|
||||
141
src/Mod/PartDesign/Scripts/FilletArc.py
Normal file
141
src/Mod/PartDesign/Scripts/FilletArc.py
Normal file
@@ -0,0 +1,141 @@
|
||||
"""
|
||||
***************************************************************************
|
||||
* Copyright (c) 2010 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License (GPL) *
|
||||
* 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. *
|
||||
* *
|
||||
* FreeCAD 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 FreeCAD; if not, write to the Free Software *
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* USA *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
|
||||
__author__ = "Werner Mayer <wmayer[at]users.sourceforge.net>"
|
||||
|
||||
# Formulas:
|
||||
# M2 = P + b*r2 + t*u
|
||||
# S1 = (r2*M1 + r1*M2)/(r1+r2)
|
||||
# S2 = M2-b*r2
|
||||
|
||||
import math
|
||||
|
||||
# 3d vector class
|
||||
class Vector:
|
||||
def __init__(self,x,y,z):
|
||||
self.x=x
|
||||
self.y=y
|
||||
self.z=z
|
||||
def add(self,vec):
|
||||
return Vector(self.x+vec.x,self.y+vec.y,self.z+vec.z)
|
||||
def sub(self,vec):
|
||||
return Vector(self.x-vec.x,self.y-vec.y,self.z-vec.z)
|
||||
def dot(self,vec):
|
||||
return self.x*vec.x+self.y*vec.y+self.z*vec.z
|
||||
def mult(self,s):
|
||||
return Vector(self.x*s,self.y*s,self.z*s)
|
||||
def cross(self,vec):
|
||||
return Vector(
|
||||
self.y * vec.z - self.z * vec.y,
|
||||
self.z * vec.x - self.x * vec.z,
|
||||
self.x * vec.y - self.y * vec.x)
|
||||
def length(self):
|
||||
return math.sqrt(self.x*self.x+self.y*self.y+self.z*self.z)
|
||||
def norm(self):
|
||||
l = self.length()
|
||||
if l > 0:
|
||||
self.x /= l
|
||||
self.y /= l
|
||||
self.z /= l
|
||||
def __repr__(self):
|
||||
return "(%f,%f,%f)" % (self.x,self.y,self.z)
|
||||
|
||||
# A signum function
|
||||
def sgn(val):
|
||||
if val > 0:
|
||||
return 1
|
||||
elif val < 0:
|
||||
return -1
|
||||
else:
|
||||
return 0
|
||||
|
||||
# M1 ... is the center of the arc
|
||||
# P ... is the end point of the arc and start point of the line
|
||||
# Q .. is a second point on the line
|
||||
# N ... is the normal of the plane where the arc and the line lie on, usually N=(0,0,1)
|
||||
# r2 ... the fillet radius
|
||||
# ccw ... counter-clockwise means which part of the arc is given. ccw must be either True or False
|
||||
def makeFilletArc(M1,P,Q,N,r2,ccw):
|
||||
u = Q.sub(P)
|
||||
v = P.sub(M1)
|
||||
if ccw:
|
||||
b = u.cross(N)
|
||||
else:
|
||||
b = N.cross(u)
|
||||
b.norm()
|
||||
|
||||
uu = u.dot(u)
|
||||
uv = u.dot(v)
|
||||
r1 = v.length()
|
||||
|
||||
# distinguish between internal and external fillets
|
||||
r2 *= sgn(uv);
|
||||
|
||||
cc = 2.0 * r2 * (b.dot(v)-r1)
|
||||
dd = uv * uv - uu * cc
|
||||
if dd < 0:
|
||||
raise Exception("Unable to caluclate intersection points")
|
||||
t1 = (-uv + math.sqrt(dd)) / uu
|
||||
t2 = (-uv - math.sqrt(dd)) / uu
|
||||
|
||||
if (abs(t1) < abs(t2)):
|
||||
t = t1
|
||||
else:
|
||||
t = t2
|
||||
|
||||
br2 = b.mult(r2)
|
||||
print br2
|
||||
ut = u.mult(t)
|
||||
print ut
|
||||
M2 = P.add(ut).add(br2)
|
||||
S1 = M1.mult(r2/(r1+r2)).add(M2.mult(r1/(r1+r2)))
|
||||
S2 = M2.sub(br2)
|
||||
|
||||
return (S1,S2,M2)
|
||||
|
||||
|
||||
|
||||
def test():
|
||||
from FreeCAD import Base
|
||||
import Part
|
||||
|
||||
P1=Base.Vector(1,-5,0)
|
||||
P2=Base.Vector(-5,2,0)
|
||||
P3=Base.Vector(1,5,0)
|
||||
#Q=Base.Vector(5,10,0)
|
||||
#Q=Base.Vector(5,11,0)
|
||||
Q=Base.Vector(5,0,0)
|
||||
r2=3.0
|
||||
axis=Base.Vector(0,0,1)
|
||||
ccw=False
|
||||
|
||||
arc=Part.ArcOfCircle(P1,P2,P3)
|
||||
C=arc.Center
|
||||
Part.show(Part.makeLine(P3,Q))
|
||||
Part.show(arc.toShape())
|
||||
|
||||
(S1,S2,M2) = makeArc(Vector(C.x,C.y,C.z),Vector(P3.x,P3.y,P3.z),Vector(Q.x,Q.y,Q.z),Vector(axis.x,axis.y,axis.z),r2,ccw)
|
||||
circle=Part.Circle(Base.Vector(M2.x,M2.y,M2.z), Base.Vector(0,0,1), math.fabs(r2))
|
||||
Part.show(circle.toShape())
|
||||
289
src/Mod/PartDesign/Scripts/Gear.py
Normal file
289
src/Mod/PartDesign/Scripts/Gear.py
Normal file
@@ -0,0 +1,289 @@
|
||||
#Involute Gears Generation Script
|
||||
#by Marcin Wanczyk (dj_who)
|
||||
#(c) 2011 LGPL
|
||||
|
||||
|
||||
import FreeCAD, FreeCADGui, Part, Draft, math, MeshPart, Mesh
|
||||
from PyQt4 import QtGui,QtCore
|
||||
App=FreeCAD
|
||||
Gui=FreeCADGui
|
||||
|
||||
def proceed():
|
||||
QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)
|
||||
|
||||
if FreeCAD.ActiveDocument==None:
|
||||
FreeCAD.newDocument("Gear")
|
||||
|
||||
oldDocumentObjects=App.ActiveDocument.Objects
|
||||
|
||||
try:
|
||||
N = int(l1.text())
|
||||
p = float(l2.text())
|
||||
alfa = int(l3.text())
|
||||
y = float(l4.text()) #standard value y<1 for gear drives y>1 for Gear pumps
|
||||
m=p/math.pi #standard value 0.06, 0.12, 0.25, 0.5, 1, 2, 4, 8, 16, 32, 60 (polish norm)
|
||||
c = float(l5.text())*m #standard value 0,1*m - 0,3*m
|
||||
j = float(l6.text())*m #standard value 0,015 - 0,04*m
|
||||
width = float(l7.text()) #gear width
|
||||
except:
|
||||
FreeCAD.Console.PrintError("Wrong input! Only numbers allowed...\n")
|
||||
|
||||
|
||||
#tooth hight
|
||||
h=2*y*m+c
|
||||
|
||||
#pitch diameter
|
||||
d=N*m
|
||||
|
||||
#root diameter
|
||||
df=d - 2*y*m - 2*c #df=d-2hf where and hf=y*m+c
|
||||
|
||||
#addendum diameter
|
||||
da=d + 2*y*m #da=d+2ha where ha=y*m
|
||||
|
||||
#base diameter for involute
|
||||
db=d * math.cos(math.radians(alfa))
|
||||
|
||||
|
||||
#Base circle
|
||||
baseCircle=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","BaseCircle")
|
||||
Draft.Circle(baseCircle)
|
||||
Draft.ViewProviderCircle(baseCircle.ViewObject)
|
||||
baseCircle.Radius = db/2
|
||||
baseCircle.FirstAngle=0.0
|
||||
baseCircle.LastAngle=0.0
|
||||
|
||||
#Root circle
|
||||
rootCircle=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","RootCircle")
|
||||
Draft.Circle(rootCircle)
|
||||
Draft.ViewProviderCircle(rootCircle.ViewObject)
|
||||
rootCircle.Radius = df/2
|
||||
rootCircle.FirstAngle=0.0
|
||||
rootCircle.LastAngle=0.0
|
||||
|
||||
#Addendum circle
|
||||
addendumCircle=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","AddendumCircle")
|
||||
Draft.Circle(addendumCircle)
|
||||
Draft.ViewProviderCircle(addendumCircle.ViewObject)
|
||||
addendumCircle.Radius = da/2
|
||||
addendumCircle.FirstAngle=0.0
|
||||
addendumCircle.LastAngle=0.0
|
||||
|
||||
#Pitch circle
|
||||
pitchCircle=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","PitchCircle")
|
||||
Draft.Circle(pitchCircle)
|
||||
Draft.ViewProviderCircle(pitchCircle.ViewObject)
|
||||
pitchCircle.Radius = d/2
|
||||
pitchCircle.FirstAngle=0.0
|
||||
pitchCircle.LastAngle=0.0
|
||||
|
||||
#************ Calculating right sides of teeth
|
||||
#Involute of base circle
|
||||
involute=[]
|
||||
involutee=[]
|
||||
involutesav=[]
|
||||
|
||||
for t in range(0,60,1):
|
||||
x=db/2*(math.cos(math.radians(t))+math.radians(t)*math.sin(math.radians(t)))
|
||||
y=db/2*(math.sin(math.radians(t))-math.radians(t)*math.cos(math.radians(t)))
|
||||
involute.append(Part.Vertex(x,y,0).Point)
|
||||
|
||||
#************ Drawing rigth sides of teeth
|
||||
involutesav.extend(involute)
|
||||
involutee.extend(involute)
|
||||
|
||||
for angle in range(1,N+1,1):
|
||||
involuteobj = FreeCAD.ActiveDocument.addObject("Part::Feature","InvoluteL"+str(angle))
|
||||
involutee.insert(0,(0,0,0))
|
||||
involuteshape = Part.makePolygon(involutee)
|
||||
involuteobj.Shape=involuteshape
|
||||
involutee=[]
|
||||
for num in range(0,60,1):
|
||||
point=involute.pop()
|
||||
pointt=Part.Vertex(point.x*math.cos(math.radians(angle*360/N)) - point.y*math.sin(math.radians(angle*360/N)),point.x*math.sin(math.radians(angle*360/N)) + point.y*math.cos(math.radians(angle*360/N)),0).Point
|
||||
involutee.insert(0,pointt)
|
||||
involute.extend(involutesav)
|
||||
involutee=[]
|
||||
|
||||
#************ Calculating difference between tooth spacing on BaseCircle and PitchCircle
|
||||
|
||||
pc=App.ActiveDocument.getObject("PitchCircle")
|
||||
inv=App.ActiveDocument.getObject("InvoluteL1")
|
||||
cut=inv.Shape.cut(pc.Shape)
|
||||
# FreeCAD.ActiveDocument.addObject("Part::Feature","CutInv").Shape=cut
|
||||
invPoint=cut.Vertexes[0].Point
|
||||
|
||||
|
||||
diff=invPoint.y*2 # instead of making axial symmetry and calculating point distance.
|
||||
anglediff=2*math.asin(diff/d)
|
||||
|
||||
#************ Calculating left sides of teeth
|
||||
|
||||
#************ Inversing Involute
|
||||
for num in range(0,60,1):
|
||||
point=involute.pop()
|
||||
pointt=Part.Vertex(point.x,point.y*-1,0).Point
|
||||
involutee.insert(0,pointt)
|
||||
involute.extend(involutee)
|
||||
involutee=[]
|
||||
|
||||
#Normal tooth size calculated as: 0,5* p - j j=m * 0,1 below are calculations
|
||||
# 0,5* p - m * 0,1
|
||||
# 0,5* p - p /pi * 0,1
|
||||
# 0,5*360/N - ((360/N)/pi)* 0,1
|
||||
# 0,5*360/N - (360/N)*((1/pi)*0,1) j=(p/pi)*0,1
|
||||
# 0,5*360/N - (360/N)*((p/pi)*0,1)/p
|
||||
# 0,5*360/N - (360/N)*( j )/p
|
||||
for num in range(0,60,1):
|
||||
point=involute.pop()
|
||||
pointt=Part.Vertex(point.x*math.cos(math.radians(180/N-(360/N)*(j/p))+anglediff) - point.y*math.sin(math.radians(180/N-(360/N)*(j/p))+anglediff),point.x*math.sin(math.radians(180/N-(360/N)*(j/p))+anglediff) + point.y*math.cos(math.radians(180/N-(360/N)*(j/p))+anglediff),0).Point
|
||||
involutee.insert(0,pointt)
|
||||
involute.extend(involutee)
|
||||
involutesav=[]
|
||||
involutesav.extend(involute)
|
||||
|
||||
#************ Drawing left sides of teeth
|
||||
for angle in range(1,N+1,1):
|
||||
involuteobj = FreeCAD.ActiveDocument.addObject("Part::Feature","InvoluteR"+str(angle))
|
||||
involutee.insert(0,(0,0,0))
|
||||
involuteshape = Part.makePolygon(involutee)
|
||||
involuteobj.Shape=involuteshape
|
||||
involutee=[]
|
||||
for num in range(0,60,1):
|
||||
point=involute.pop()
|
||||
pointt=Part.Vertex(point.x*math.cos(math.radians(angle*360/N)) - point.y*math.sin(math.radians(angle*360/N)),point.x*math.sin(math.radians(angle*360/N)) + point.y*math.cos(math.radians(angle*360/N)),0).Point
|
||||
involutee.insert(0,pointt)
|
||||
involute.extend(involutesav)
|
||||
|
||||
Gui.SendMsgToActiveView("ViewFit")
|
||||
|
||||
#************ Forming teeth
|
||||
|
||||
cutCircle=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","CutCircle")
|
||||
Draft.Circle(cutCircle)
|
||||
Draft.ViewProviderCircle(cutCircle.ViewObject)
|
||||
cutCircle.Radius = da # da because must be bigger than addendumCircle and bigger than whole construction da is right for this but it not has to be.
|
||||
cutCircle.FirstAngle=0.0
|
||||
cutCircle.LastAngle=0.0
|
||||
|
||||
|
||||
cutTool=cutCircle.Shape.cut(addendumCircle.Shape)
|
||||
#cutshape=Part.show(cutTool)
|
||||
|
||||
gearShape=rootCircle.Shape
|
||||
|
||||
for invNum in range(1,N+1,1):
|
||||
invL=App.ActiveDocument.getObject("InvoluteL"+str(invNum))
|
||||
invR=App.ActiveDocument.getObject("InvoluteR"+str(invNum))
|
||||
cutL=invL.Shape.cut(cutTool)
|
||||
cutR=invR.Shape.cut(cutTool)
|
||||
pointL=cutL.Vertexes.pop().Point
|
||||
pointR=cutR.Vertexes.pop().Point
|
||||
faceEdge=Part.makeLine(pointL,pointR)
|
||||
|
||||
toothWhole=cutL.fuse(cutR)
|
||||
toothWhole=toothWhole.fuse(faceEdge)
|
||||
toothWire=Part.Wire(toothWhole.Edges)
|
||||
toothShape=Part.Face(toothWire)
|
||||
# tooth=App.ActiveDocument.addObject("Part::Feature","Tooth"+str(invNum))
|
||||
# tooth.Shape=toothShape
|
||||
gearShape=gearShape.fuse(toothShape)
|
||||
|
||||
|
||||
for o in App.ActiveDocument.Objects:
|
||||
if oldDocumentObjects.count(o)==0:
|
||||
App.ActiveDocument.removeObject(o.Name)
|
||||
|
||||
gearFlat=App.ActiveDocument.addObject("Part::Feature","GearFlat")
|
||||
gearFlat.Shape=gearShape
|
||||
Gui.ActiveDocument.getObject(gearFlat.Name).Visibility=False
|
||||
|
||||
gear=App.ActiveDocument.addObject("Part::Extrusion","Gear3D")
|
||||
gear.Base=gearFlat
|
||||
gear.Dir=(0,0,width)
|
||||
App.ActiveDocument.recompute()
|
||||
|
||||
|
||||
if c1.isChecked()==True:
|
||||
gearMesh=App.ActiveDocument.addObject("Mesh::Feature","Gear3D-mesh")
|
||||
|
||||
faces = []
|
||||
triangles = gear.Shape.tessellate(1) # the number represents the precision of the tessellation)
|
||||
for tri in triangles[1]:
|
||||
face = []
|
||||
for i in range(3):
|
||||
vindex = tri[i]
|
||||
face.append(triangles[0][vindex])
|
||||
faces.append(face)
|
||||
mesh = Mesh.Mesh(faces)
|
||||
|
||||
gearMesh.Mesh=mesh
|
||||
App.ActiveDocument.removeObject(gear.Name)
|
||||
App.ActiveDocument.removeObject(gearFlat.Name)
|
||||
|
||||
|
||||
App.ActiveDocument.recompute()
|
||||
Gui.SendMsgToActiveView("ViewFit")
|
||||
|
||||
QtGui.qApp.restoreOverrideCursor()
|
||||
|
||||
|
||||
hide()
|
||||
|
||||
def hide():
|
||||
dialog.hide()
|
||||
|
||||
dialog = QtGui.QDialog()
|
||||
dialog.resize(200,450)
|
||||
dialog.setWindowTitle("Gear")
|
||||
la = QtGui.QVBoxLayout(dialog)
|
||||
t1 = QtGui.QLabel("Number of teeth (N)")
|
||||
la.addWidget(t1)
|
||||
l1 = QtGui.QLineEdit()
|
||||
l1.setText("16")
|
||||
la.addWidget(l1)
|
||||
t2 = QtGui.QLabel("Circular pitch (p)")
|
||||
la.addWidget(t2)
|
||||
l2 = QtGui.QLineEdit()
|
||||
l2.setText("1.65")
|
||||
la.addWidget(l2)
|
||||
t3 = QtGui.QLabel("Pressure angle (alfa)")
|
||||
la.addWidget(t3)
|
||||
l3 = QtGui.QLineEdit()
|
||||
l3.setText("20")
|
||||
la.addWidget(l3)
|
||||
t4 = QtGui.QLabel("Tooth hight factor (y)")
|
||||
la.addWidget(t4)
|
||||
l4 = QtGui.QLineEdit()
|
||||
l4.setText("1.0")
|
||||
la.addWidget(l4)
|
||||
t5 = QtGui.QLabel("Tooth clearance (c)")
|
||||
la.addWidget(t5)
|
||||
l5 = QtGui.QLineEdit()
|
||||
l5.setText("0.1")
|
||||
la.addWidget(l5)
|
||||
t6 = QtGui.QLabel("Tooth lateral clearance (j)")
|
||||
la.addWidget(t6)
|
||||
l6 = QtGui.QLineEdit()
|
||||
l6.setText("0.04")
|
||||
la.addWidget(l6)
|
||||
t7 = QtGui.QLabel("Gear width")
|
||||
la.addWidget(t7)
|
||||
l7 = QtGui.QLineEdit()
|
||||
l7.setText("6.0")
|
||||
la.addWidget(l7)
|
||||
c1 = QtGui.QCheckBox("Create as a Mesh")
|
||||
la.addWidget(c1)
|
||||
e1 = QtGui.QLabel("(for faster rendering)")
|
||||
commentFont=QtGui.QFont("Times",8,True)
|
||||
e1.setFont(commentFont)
|
||||
la.addWidget(e1)
|
||||
|
||||
okbox = QtGui.QDialogButtonBox(dialog)
|
||||
okbox.setOrientation(QtCore.Qt.Horizontal)
|
||||
okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
|
||||
la.addWidget(okbox)
|
||||
QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), proceed)
|
||||
QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), hide)
|
||||
QtCore.QMetaObject.connectSlotsByName(dialog)
|
||||
dialog.show()
|
||||
12
src/Mod/PartDesign/Scripts/Makefile.am
Normal file
12
src/Mod/PartDesign/Scripts/Makefile.am
Normal file
@@ -0,0 +1,12 @@
|
||||
# Change data dir from default $(datadir) to $(prefix)/Mod/PartDesign/Scripts
|
||||
datadir = $(prefix)/Mod/PartDesign/Scripts
|
||||
data_DATA = \
|
||||
__init__.py \
|
||||
Gear.py \
|
||||
DistanceBolt.py \
|
||||
RadialCopy.py \
|
||||
Parallelepiped.py
|
||||
|
||||
EXTRA_DIST = \
|
||||
$(data_DATA)
|
||||
|
||||
107
src/Mod/PartDesign/Scripts/Parallelepiped.py
Normal file
107
src/Mod/PartDesign/Scripts/Parallelepiped.py
Normal file
@@ -0,0 +1,107 @@
|
||||
"""
|
||||
An example for a high-level cutsom feature object to form a full-parametric parallelepiped.
|
||||
|
||||
***************************************************************************
|
||||
* Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License (GPL) *
|
||||
* 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. *
|
||||
* *
|
||||
* FreeCAD 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 FreeCAD; if not, write to the Free Software *
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
* USA *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
|
||||
__author__ = "Werner Mayer <wmayer@users.sourceforge.net>"
|
||||
|
||||
import FreeCAD, Part, math
|
||||
from FreeCAD import Base
|
||||
|
||||
class Parallelepiped:
|
||||
def __init__(self, obj):
|
||||
''' Add the properties: Length, Edges, Radius, Height '''
|
||||
obj.addProperty("App::PropertyVector","A","Parallelepiped","Vector").A=Base.Vector(1,0,0)
|
||||
obj.addProperty("App::PropertyVector","B","Parallelepiped","Vector").B=Base.Vector(0,1,0)
|
||||
obj.addProperty("App::PropertyVector","C","Parallelepiped","Vector").C=Base.Vector(0,0,1)
|
||||
obj.Proxy = self
|
||||
|
||||
def onChanged(self, fp, prop):
|
||||
if prop == "A" or prop == "B" or prop == "C":
|
||||
self.execute(fp)
|
||||
|
||||
def execute(self, fp):
|
||||
a = fp.A
|
||||
b = fp.B
|
||||
c = fp.C
|
||||
|
||||
m=Base.Matrix()
|
||||
m.A11=a.x
|
||||
m.A12=a.y
|
||||
m.A13=a.z
|
||||
m.A21=b.x
|
||||
m.A22=b.y
|
||||
m.A23=b.z
|
||||
m.A31=c.x
|
||||
m.A32=c.y
|
||||
m.A33=c.z
|
||||
box = Part.makeBox(1,1,1)
|
||||
fp.Shape = box.transformGeometry(m)
|
||||
|
||||
class BoxCylinder:
|
||||
def __init__(self, obj):
|
||||
obj.addProperty("App::PropertyFloat","Length","BoxCylinder","Length").Length=10.0
|
||||
obj.addProperty("App::PropertyFloat","Width","BoxCylinder","Width").Width=10.0
|
||||
obj.addProperty("App::PropertyLink","Source","BoxCylinder","Source").Source=None
|
||||
obj.Proxy = self
|
||||
|
||||
def onChanged(self, fp, prop):
|
||||
if prop == "Length" or prop == "Width":
|
||||
self.execute(fp)
|
||||
|
||||
def execute(self, fp):
|
||||
FreeCAD.Console.PrintMessage(str(fp.Source)+"\n")
|
||||
if fp.Source is None:
|
||||
return
|
||||
r = fp.Source.Radius
|
||||
l = fp.Length
|
||||
w = fp.Width
|
||||
h = 2*r+10
|
||||
fp.Shape = Part.makeBox(l,w,h)
|
||||
|
||||
def makeParallelepiped():
|
||||
doc = FreeCAD.activeDocument()
|
||||
if doc == None:
|
||||
doc = FreeCAD.newDocument()
|
||||
obj=doc.addObject("Part::FeaturePython","Parallelepiped")
|
||||
obj.Label = "Parallelepiped"
|
||||
Parallelepiped(obj)
|
||||
obj.ViewObject.Proxy=0
|
||||
|
||||
|
||||
def makeBoxCylinder():
|
||||
doc = FreeCAD.activeDocument()
|
||||
if doc == None:
|
||||
doc = FreeCAD.newDocument()
|
||||
cyl=doc.addObject("Part::Cylinder","Cylinder")
|
||||
cyl.Radius=16.0
|
||||
cyl.Height=800.0
|
||||
obj=doc.addObject("Part::FeaturePython","Box")
|
||||
BoxCylinder(obj)
|
||||
obj.Source=cyl
|
||||
obj.Length=800.0
|
||||
obj.Width=600.0
|
||||
obj.ViewObject.Proxy=0
|
||||
doc.recompute()
|
||||
60
src/Mod/PartDesign/Scripts/RadialCopy.py
Normal file
60
src/Mod/PartDesign/Scripts/RadialCopy.py
Normal file
@@ -0,0 +1,60 @@
|
||||
#! python
|
||||
# -*- coding: utf-8 -*-
|
||||
# (c) 2010 Werner Mayer LGPL
|
||||
|
||||
"""
|
||||
An example for a high-level cutsom feature object to make a so called "radial copy".
|
||||
"""
|
||||
__author__ = "Werner Mayer <wmayer@users.sourceforge.net>"
|
||||
|
||||
import FreeCAD, FreeCADGui, Part, math
|
||||
from PyQt4 import QtGui
|
||||
from FreeCAD import Base
|
||||
|
||||
def makeCopy(shape, radius, angle):
|
||||
mat = Base.Matrix()
|
||||
mat.rotateZ(math.radians(angle))
|
||||
step = 360.0 / angle
|
||||
shape = shape.copy()
|
||||
shape.translate((radius, 0, 0))
|
||||
comp = shape.copy()
|
||||
for i in range(step):
|
||||
shape.transformShape(mat)
|
||||
comp = comp.fuse(shape)
|
||||
return comp
|
||||
|
||||
|
||||
class RadialCopy:
|
||||
def __init__(self, obj):
|
||||
obj.addProperty("App::PropertyLength","Radius","","Radius").Radius=10.0
|
||||
obj.addProperty("App::PropertyLength","Angle" ,"","Angle").Angle=20.0
|
||||
obj.addProperty("App::PropertyLink","Source" ,"","Source shape").Source=None
|
||||
obj.Proxy = self
|
||||
|
||||
# def onChanged(self, fp, prop):
|
||||
# if prop == "Angle" or prop == "Radius":
|
||||
# self.execute(fp)
|
||||
|
||||
def execute(self, fp):
|
||||
shape = fp.Source.Shape
|
||||
radius = fp.Radius
|
||||
angle = fp.Angle
|
||||
fp.Shape = makeCopy(shape, radius, angle)
|
||||
|
||||
def makeRadialCopy():
|
||||
sel = FreeCADGui.Selection.getSelection()
|
||||
try:
|
||||
sel = sel[0]
|
||||
shape = sel.Shape
|
||||
name = sel.Label
|
||||
except:
|
||||
QtGui.QMessageBox.critical(None,"Wrong selection","Please select a shape object")
|
||||
#raise Exception("Nothing selected")
|
||||
else:
|
||||
doc = sel.Document
|
||||
rc = doc.addObject("Part::FeaturePython","RadialCopy")
|
||||
rc.Label = name+"(Radial Copy)"
|
||||
RadialCopy(rc)
|
||||
rc.Source = sel
|
||||
rc.ViewObject.Proxy=0
|
||||
|
||||
0
src/Mod/PartDesign/Scripts/__init__.py
Normal file
0
src/Mod/PartDesign/Scripts/__init__.py
Normal file
Reference in New Issue
Block a user