Example #1
0
def planwingoutlinesketch(sketchname, xvals, yplusedges, yminusedges, additionaldrawingedges=None):
	Psketch = getemptyobject(doc, "Sketcher::SketchObject", sketchname)

	plusEdges = [ Psketch.addGeometry(Part.LineSegment(Vector(xvals[i], yplusedges[i]), Vector(xvals[i+1], yplusedges[i+1])), True)  for i in range(len(xvals)-1) ]
	minusEdges = [ Psketch.addGeometry(Part.LineSegment(Vector(xvals[i], yminusedges[i]), Vector(xvals[i+1], yminusedges[i+1])), True)  for i in range(len(xvals)-1) ]
	leftedge = Psketch.addGeometry(Part.LineSegment(Vector(xvals[0], yplusedges[0]), Vector(xvals[0], yminusedges[0])), True)
	rightedge = Psketch.addGeometry(Part.LineSegment(Vector(xvals[-1], yplusedges[-1]), Vector(xvals[-1], yminusedges[-1])), True)
	if additionaldrawingedges:
		[ Psketch.addGeometry(Part.LineSegment(Vector(xvals[i], additionaldrawingedges[i]), Vector(xvals[i+1], additionaldrawingedges[i+1])), False)  for i in range(len(xvals)-1) ]

	# nail down the endpoints of all these edges
	for i in range(len(Psketch.Geometry)):
		l = Psketch.Geometry[i]
		Psketch.addConstraint(Sketcher.Constraint('DistanceX', i, 1, l.StartPoint.x)) 
		Psketch.addConstraint(Sketcher.Constraint('DistanceY', i, 1, l.StartPoint.y)) 
		Psketch.addConstraint(Sketcher.Constraint('DistanceX', i, 2, l.EndPoint.x)) 
		Psketch.addConstraint(Sketcher.Constraint('DistanceY', i, 2, l.EndPoint.y)) 

	for i in range(len(Psketch.Constraints)):
		Psketch.setVirtualSpace(i, True)
Example #2
0
import math, os, csv, sys
import numpy
from FreeCAD import Vector, Rotation
import ezdxf

sys.path.append(os.path.split(__file__)[0])
from p7modules.barmesh.basicgeo import P2

from p7modules.p7wingflatten_barmeshfuncs import MeshBoundary
from p7modules.p7wingeval import getemptyobject, createobjectingroup, removeObjectRecurse

doc = App.ActiveDocument

sflattened = doc.SFlattened.OutList
spencil = doc.SPencil.OutList
thinnedlines = getemptyobject(doc, "App::DocumentObjectGroup", "ThinnedLines")

import ezdxf, ezdxf.math, os

ezdxfvec3 = ezdxf.math.Vec3 if hasattr(ezdxf.math,
                                       "Vec3") else ezdxf.math.Vector

AAMA_CUT = "1"
AAMA_DRAW = "8"
AAMA_INTCUT = "11"

dxfversion = "R2013"

outputfilename = os.path.join(os.path.split(__file__)[0], "../p7test.dxf")
print("Saving", outputfilename)
from p7modules.p7wingflatten_barmeshfuncs import sliceupatnones
from p7modules.p7wingflatten_barmeshfuncs import MeshBoundary

uvtriangulations = doc.UVTriangulations.OutList
striangulations = doc.STriangulations.OutList
sflattened = doc.SFlattened.OutList
uvfoldlines = doc.UVPolygonsFoldlines.OutList if doc.getObject(
    "UVPolygonsFoldlines") else []
postpenupper = doc.getObject("postpenupper")
postpenlower = doc.getObject("postpenlower")
uvpolygonsdict = dict(
    (uvpolygon.Name[1:], uvpolygon) for uvpolygon in doc.UVPolygons.OutList)

assert len(uvtriangulations) == len(striangulations), len(sflattened)
pencilg = getemptyobject(doc, "App::DocumentObjectGroup", "SPencil")
pencilT = getemptyobject(doc, "App::DocumentObjectGroup", "TPencil")

uvtriangulationboundaries = [
    MeshBoundary(uvtriangulation) for uvtriangulation in uvtriangulations
]

# get the batten detail file and set the duplicated positions for the pen cuts
battendetailfile = None if R13type else os.path.join(
    os.path.split(__file__)[0], "batten detail TSR.dxf")
#battendetailfile = "/home/julian/repositories/HGnotebooks/wingflattening/freecad_macro_work/batten detail TSR.dxf"

if battendetailfile:
    import ezdxf
    docbattendetail = ezdxf.readfile(battendetailfile)
    dxflines = [
import math, os, csv
from FreeCAD import Vector, Rotation

# Run this on testriotwires
# Very much the same as p7wingshape


doc = App.ActiveDocument
from p7modules.p7wingeval import getemptyobject, createobjectingroup, removeObjectRecurse

groupwires = doc.Group.OutList
sections = [ [ (-v.Point.y, v.Point.z)  for v in groupwire.Shape.OrderedVertexes ]  for groupwire in groupwires ]
zvals = [ groupwire.Shape.OrderedVertexes[0].Point.x  for groupwire in groupwires ]
 
if True:
	wingloft = getemptyobject(doc, "Part::Feature", "wingloft")
	wingloft.Shape = Part.makeLoft([l.Shape  for l in doc.Group.OutList], False, True)
	if doc.findObjects(Name="SectionGroup"):
		removeObjectRecurse(doc, "SectionGroup")

else:
	# 
	# This is the old bspline fitting, which generated nasty folds in the curves
	# There's code to demo this at the bottom
	#

	assert False
	
	def deriveparametizationforallsections(chosensection):
		points = [App.Vector(0, -p[0], p[1])  for p in chosensection]
		chordlengths = [ 0 ]
Example #5
0
import FreeCAD as App
import Draft, Part, Mesh
import DraftGeomUtils
import math, os, csv, sys
import numpy
from FreeCAD import Vector, Rotation

sys.path.append(os.path.split(__file__)[0])
from p7modules.p7wingeval import getemptyobject, createobjectingroup, removeObjectRecurse

doc = App.ActiveDocument
R13type = doc.getObject("Group")
print("R13 type offsets" if R13type else "P7 wing offsets")

uvpolygons = doc.UVPolygons.OutList
uvpolygonsoffsets = getemptyobject(doc, "App::DocumentObjectGroup", "UVPolygonsOffsets")
uvpolygonsfoldlines = getemptyobject(doc, "App::DocumentObjectGroup", "UVPolygonsFoldlines")

from p7modules.p7wingeval import WingEval
R13type = doc.getObject("Group")
wingeval = WingEval(doc.getObject("Group" if R13type else "SectionGroup").OutList, R13type)
urange, vrange, seval = wingeval.urange, wingeval.vrange, wingeval.seval


from p7modules.barmesh.basicgeo import P2, P3, Partition1, Along, I1
from p7modules.p7wingflatten_barmeshfuncs import polyloopvedgeseqpolyline, polylinewithinsurfaceoffset

surfacemeshdict = dict((uvpoly.Name[1:], [ P2(v.Point.x, v.Point.y)  for v in uvpoly.Shape.OrderedVertexes ])  for uvpoly in uvpolygons)

#####scratch work
#uvpoly = doc.UVPolygons.OutList[0]
import DraftGeomUtils
import math, os, csv, sys
import numpy
from FreeCAD import Vector, Rotation
import flatmesh

# Do this if running by pasting into Python window
#sys.path.append("/home/julian/repositories/HGnotebooks/wingflattening/freecad_macro_work")
sys.path.append(os.path.split(__file__)[0])
from p7modules.p7wingeval import WingEval
from p7modules.p7wingeval import getemptyobject, createobjectingroup, removeObjectRecurse

doc = App.ActiveDocument

uvtriangulations = doc.UVTriangulations.OutList
stg = getemptyobject(doc, "App::DocumentObjectGroup", "STriangulations")
flg = getemptyobject(doc, "App::DocumentObjectGroup", "SFlattened")

R13type = doc.getObject("Group")
wingeval = WingEval(
    doc.getObject("Group" if R13type else "SectionGroup").OutList, R13type)

urange, vrange, seval = wingeval.urange, wingeval.vrange, wingeval.seval


def transformalignfpts(uvpts, fpts, patchname):
    uvpts = [p.Vector for p in t.Mesh.Points]
    uvcentre = sum(uvpts, Vector()) * (1 / len(uvpts))
    flatcentre = sum(fpts, Vector()) * (1 / len(fpts))

    itopright = max(range(len(uvpts)), key=lambda X: uvpts[X].x + uvpts[X].y)
Example #7
0
from p7modules.p7wingeval import getemptyobject, createobjectingroup, getemptyobject, uvrectangle

doc = App.ActiveDocument

R13type = True

cutlinesketch = doc.cutlinesketch
nnonconstructionlines = sum(
    int(not g.Construction) for g in doc.cutlinesketch.GeometryFacadeList)
if nnonconstructionlines != 0:
    print("cutlinesketch contains %d non-construction lines" %
          nnonconstructionlines)
    print("Creating new cutlinesketch")
    old = doc.copyObject(cutlinesketch, 'cutlinesketch_old')
    old.Visibility = False
    cutlinesketch = getemptyobject(doc, "Sketcher::SketchObject",
                                   "cutlinesketch")
    wingeval = WingEval(doc.getObject("Group").OutList, R13type)
    urange, vrange = wingeval.urange, wingeval.vrange
    cutlinesketch = uvrectangle(urange, vrange, "cutlinesketch", doc)

R13type = doc.getObject("Group")
wingeval = WingEval(
    doc.getObject("Group" if R13type else "SectionGroup").OutList, R13type)

legsampleleng = 3.0


def projectprecut(cutlinesketch, precutsketch, bupperface):
    for g in precutsketch.GeometryFacadeList:
        if not g.Construction:
            gg = g.Geometry
Example #8
0
        'TSF2': (3.907, -0.294),
        'TSM1': (0.415, -0.913),
        'TSM2': (1.266, -0.913),
        'TSM3': (3.394, -0.827),
        'TSR': (4.082, -1.073)
    }


def getnameofpolygon(points):
    avgpt = sum(points, Vector()) * (1.0 / len(points))
    closestname = min(((avgpt - Vector(p[0] * 1000, p[1] * 1000)).Length, name)
                      for name, p in patchnamelookups.items())[1]
    return closestname


clw = getemptyobject(doc, "App::DocumentObjectGroup", "UVPolygons")

# find the sets of nodes from the coincident constraints
gcptsets, gcptnmap = extractcoincidentnodes(cutlinesketch)
gcptorders = [
    coincidentnodetanges(cutlinesketch, gcptset) for gcptset in gcptsets
]

# derive the sequences of (edge, startend) for each contour
seqs = extractsequences(gcptorders, gcptnmap)

for n, seq in enumerate(seqs):
    points = sequencetopoints(cutlinesketch, seq, legsampleleng=3.0)
    if not orientationclockwise(points):
        closestname = getnameofpolygon(points)
        ws = createobjectingroup(doc, clw, "Part::Feature",