Ejemplo n.º 1
0
import numpyNode
reload(numpyNode)

t=numpyNode.createNP()
#t.sourceObject= App.ActiveDocument.Plot001
#t.expression2="4* np.arctan2(in2,in3)"



import  mathplotlibNode
from mathplotlibNode import createMPL

t=createMPL()
t.sourceObject= App.ActiveDocument.My_Manager
t.countSources=4
t.sourceData="step"

t.source1Object= App.ActiveDocument.Box001
t.source1Data="Placement.Rotation.Angle"


t.source2Object= App.ActiveDocument.Box001
t.source2Data="Placement.Base.x"

t.source3Object= App.ActiveDocument.Box001
t.source3Data="Placement.Base.y"

# t.expression2="2* np.arctan2(in2,in3)"

t.record=True
Ejemplo n.º 2
0
def import_gpx(filename, orig, hi):
    '''import a gpx trackfile'''

    global sd
    # content=trackstring

    #	fn='/home/microelly2/FCB/b202_gmx_tracks/im_haus.gpx'
    #	filename='/home/microelly2/FCB/b202_gmx_tracks/neufang.gpx'

    f = open(filename, "r")
    c1 = f.read()
    import re
    content = re.sub('^\<\?[^\>]+\?\>', '', c1)
    print(content)

    tm = TransverseMercator()

    # outdoor inn ...
    tm.lat, tm.lon = 50.3736049, 11.191643

    if orig != 'auto':
        yy = orig.split(',')
        origin = (float(yy[0]), float(yy[1]))
        tm.lat = origin[0]
        tm.lon = origin[1]
#	center=tm.fromGeographic(tm.lat,tm.lon)

    sd = parse(content)
    if debug: print(json.dumps(sd, indent=4))

    points = []
    points2 = []
    points0 = []
    px = []
    py = []
    pz = []
    pt = []

    startx = None
    starty = None
    starth = None
    FreeCAD.sd = sd
    seg = sd['gpx']['trk']['trkseg']
    try:
        seg['trkpt']
        ss = seg
        seg = [ss]
    except:
        pass
    lats = []
    lons = []

    for s in seg:
        trkpts = s['trkpt']
        for n in trkpts:
            lats.append(float(n['@lat']))
            lons.append(float(n['@lon']))

    print(min(lats), max(lats))
    print(min(lons), max(lons))
    print((max(lats) + min(lats)) / 2, (max(lons) + min(lons)) / 2)
    print((max(lats) - min(lats)) / 2, (max(lons) - min(lons)) / 2)

    if orig == 'auto':
        tm.lat, tm.lon = (max(lats) + min(lats)) / 2, (max(lons) +
                                                       min(lons)) / 2
        print("origin:")
        print(tm.lat, tm.lon)
        print("----------")

    for s in seg:
        trkpts = s['trkpt']

        n = trkpts[0]

        center = tm.fromGeographic(tm.lat, tm.lon)

        #		print(trkpts)
        #		for p in  trkpts:
        #			print(p)

        # map all points to xy-plane
        for n in trkpts:
            #			print(n['@lat'],n['@lon'])
            lats.append(float(n['@lat']))
            lons.append(float(n['@lon']))
            ll = tm.fromGeographic(float(n['@lat']), float(n['@lon']))
            h = n['ele']
            #			print(h)
            tim = n['time']
            t2 = re.sub('^.*T', '', tim)
            t3 = re.sub('Z', '', t2)
            t4 = t3.split(':')
            timx = int(t4[0]) * 3600 + int(t4[1]) * 60 + int(t4[2])
            pt.append(timx)
            if starth == None:
                starth = float(h)
                starth = 0

            points.append(
                FreeCAD.Vector(ll[0] - center[0], ll[1] - center[1],
                               1000 * (float(h) - starth)))
            points.append(
                FreeCAD.Vector(ll[0] - center[0], ll[1] - center[1], 0))
            points.append(
                FreeCAD.Vector(ll[0] - center[0], ll[1] - center[1],
                               1000 * (float(h) - starth)))
            points2.append(
                FreeCAD.Vector(ll[0] - center[0], ll[1] - center[1],
                               1000 * (float(h) - starth) + 20000))
            points0.append(
                FreeCAD.Vector(ll[0] - center[0], ll[1] - center[1], 0))
            px.append(ll[0] - center[0])
            py.append(ll[1] - center[1])
            pz.append(1000 * (float(h) - starth))


#			print(ll)

    if 1:
        import Draft
        if 0:  #close path
            points.append(points[0])

        Draft.makeWire(points0)

        Draft.makeWire(points)

        po = App.ActiveDocument.ActiveObject
        po.ViewObject.LineColor = (1.0, .0, 0.0)
        po.MakeFace = False

        po.Placement.Base.z = float(hi) * 1000
        po.Label = "My Track"

        Draft.makeWire(points2)

        po2 = App.ActiveDocument.ActiveObject
        po2.ViewObject.LineColor = (.0, .0, 1.0)
        po2.ViewObject.PointSize = 5
        po2.ViewObject.PointColor = (.0, 1.0, 1.0)

        po2.Placement.Base.z = float(hi) * 1000
        po2.Label = "Track + 20m"

        App.activeDocument().recompute()
        Gui.SendMsgToActiveView("ViewFit")
        # break

    #------------------------------------------------
    # data for postprocessing
    return

    try:
        import numpyNode
        import mathplotlibNode

        t = mathplotlibNode.createMPL()
        t.Label = "My Track raw Data"

        # hier werte bereitstellen
        t.countSources = 4
        t.source1Values = px
        t.source2Values = py
        t.source3Values = pz
        t.source4Values = pt

        t.source1Data = "px"
        t.source2Data = "py"
        t.source3Data = "pz"
        t.source4Data = "pt"

        t.useOut1 = True
        t.useOut2 = True
        t.useOut3 = True
        t.useOut4 = True

        # werte umrechnen
        t2 = numpyNode.createNP()
        t2.Label = "My Track data processed"
        t2.sourceObject = t
        t2.expression1 = "in1/np.max(np.abs(in1))"
        t2.label1 = "x relative"

        t2.expression2 = "in2/np.max(np.abs(in2))"
        t2.label2 = "y relative"

        t2.expression3 = "in3/np.max(np.abs(in3))"
        t2.label3 = "z relative"

        t2.expression4 = "-1+2*(in4-np.min(in4))/(np.max(in4)-np.min(in4))"
        t2.label4 = "time relative"

        # werte grafisch darstellen
        t3 = mathplotlibNode.createMPL()
        t3.Label = "My Track Data visualization"
        t3.record = False
        t3.useNumpy = True
        t3.sourceNumpy = t2

        t3.useOut1 = True
        t3.useOut2 = True
        t3.useOut3 = True
        t3.useOut4 = True

        t4 = numpyNode.createNP()
        t4.Label = "My Track Data xy"
        t4.sourceObject = t

        t4.expression2 = "in2"
        t4.label2 = "path xy"

        t4.expressionTime = "in1"

        t5 = mathplotlibNode.createMPL()
        t5.Label = "My Track Data xy Map"
        t5.record = False
        t5.useNumpy = True
        t5.sourceNumpy = t4

        t5.useOut2 = True
        FreeCAD.ActiveDocument.recompute()
    except:
        sayexc()

    return (str(tm.lat) + ',' + str(tm.lon))
    return px, py
Ejemplo n.º 3
0
def import_gpx(filename,orig,hi):
	global sd
	# content=trackstring
	
#	fn='/home/microelly2/FCB/b202_gmx_tracks/im_haus.gpx'
#	filename='/home/microelly2/FCB/b202_gmx_tracks/neufang.gpx'
	
	
	f=open(filename,"r")
	c1=f.read()
	import re
	content = re.sub('^\<\?[^\>]+\?\>', '', c1)
#	print content


	tm=TransverseMercator()

	# outdoor inn ...
	tm.lat,tm.lon = 50.3736049,11.191643
	
	if orig<>'auto':
		yy=orig.split(',')
		origin=(float(yy[0]),float(yy[1]))
		tm.lat=origin[0]
		tm.lon=origin[1]
#	center=tm.fromGeographic(tm.lat,tm.lon)
	
	sd=parse(content)
	if debug: print(json.dumps(sd, indent=4))
	
	points=[]
	points2=[]
	points0=[]
	px=[]
	py=[]
	pz=[]
	pt=[]
	
	startx=None
	starty=None
	starth=None
	FreeCAD.sd=sd
	seg=sd['gpx']['trk']['trkseg']
	try:
		seg['trkpt']
		ss=seg
		seg=[ss]
	except:
		pass
	lats=[]
	lons=[]

	for s in seg:
		trkpts=s['trkpt']
		for n in trkpts:
			lats.append(float(n['@lat']))
			lons.append(float(n['@lon']))

	print (min(lats),max(lats))
	print (min(lons),max(lons))
	print ((max(lats)+min(lats))/2,(max(lons)+min(lons))/2)
	print ((max(lats)-min(lats))/2,(max(lons)-min(lons))/2)

	if orig == 'auto':
		tm.lat, tm.lon = (max(lats)+min(lats))/2,(max(lons)+min(lons))/2
		print "origin:"
		print(tm.lat,tm.lon)
		print ("----------")



	for s in seg:
		trkpts=s['trkpt']


		n=trkpts[0]

		center=tm.fromGeographic(tm.lat,tm.lon)

#		print trkpts
#		for p in  trkpts:
#			print p

		# map all points to xy-plane
		for n in trkpts:
#			print n['@lat'],n['@lon']
			lats.append(float(n['@lat']))
			lons.append(float(n['@lon']))
			ll=tm.fromGeographic(float(n['@lat']),float(n['@lon']))
			h=n['ele']
#			print h
			tim=n['time']
			t2=re.sub('^.*T', '', tim)
			t3=re.sub('Z', '', t2)
			t4=t3.split(':')
			timx=int(t4[0])*3600+int(t4[1])*60+int(t4[2])
			pt.append(timx)
			if starth == None:
				starth=float(h)
				starth=0

			points.append(FreeCAD.Vector(ll[0]-center[0],ll[1]-center[1],1000*(float(h)-starth)))
			points.append(FreeCAD.Vector(ll[0]-center[0],ll[1]-center[1],0))
			points.append(FreeCAD.Vector(ll[0]-center[0],ll[1]-center[1],1000*(float(h)-starth)))
			points2.append(FreeCAD.Vector(ll[0]-center[0],ll[1]-center[1],1000*(float(h)-starth)+20000))
			points0.append(FreeCAD.Vector(ll[0]-center[0],ll[1]-center[1],0))
			px.append(ll[0]-center[0])
			py.append(ll[1]-center[1])
			pz.append(1000*(float(h)-starth))
#			print ll


	if 1:
		import Draft
		if 0: #close path
			points.append(points[0])
		
		
		
		Draft.makeWire(points0)
		
		Draft.makeWire(points)

		po=App.ActiveDocument.ActiveObject
		po.ViewObject.LineColor=(1.0,.0,0.0)
		po.MakeFace = False

		po.Placement.Base.z= float(hi) *1000
		po.Label="My Track" 

		Draft.makeWire(points2)

		po2=App.ActiveDocument.ActiveObject
		po2.ViewObject.LineColor=(.0,.0,1.0)
		po2.ViewObject.PointSize=5
		po2.ViewObject.PointColor=(.0,1.0,1.0)
		
		po2.Placement.Base.z= float(hi)*1000
		po2.Label="Track + 20m"


		App.activeDocument().recompute()
		Gui.SendMsgToActiveView("ViewFit")
		# break

	#------------------------------------------------
	# data for postprocessing

	try:
		import numpyNode
		import mathplotlibNode

		t=mathplotlibNode.createMPL()
		t.Label="My Track raw Data"

		# hier werte bereitstellen
		t.countSources=4
		t.source1Values=px
		t.source2Values=py
		t.source3Values=pz
		t.source4Values=pt

		t.source1Data="px"
		t.source2Data="py"
		t.source3Data="pz"
		t.source4Data="pt"
		
		t.useOut1=True
		t.useOut2=True
		t.useOut3=True
		t.useOut4=True

		# werte umrechnen
		t2=numpyNode.createNP()
		t2.Label="My Track data processed"
		t2.sourceObject=t
		t2.expression1="in1/np.max(np.abs(in1))"
		t2.label1 = "x relative"

		t2.expression2="in2/np.max(np.abs(in2))"
		t2.label2 = "y relative"

		t2.expression3="in3/np.max(np.abs(in3))"
		t2.label3 = "z relative"

		t2.expression4="-1+2*(in4-np.min(in4))/(np.max(in4)-np.min(in4))"
		t2.label4 = "time relative"

		# werte grafisch darstellen
		t3=mathplotlibNode.createMPL()
		t3.Label="My Track Data visualization"
		t3.record=False
		t3.useNumpy=True
		t3.sourceNumpy=t2

		t3.useOut1=True
		t3.useOut2=True
		t3.useOut3=True
		t3.useOut4=True

		t4=numpyNode.createNP()
		t4.Label="My Track Data xy"
		t4.sourceObject=t

		t4.expression2="in2"
		t4.label2 = "path xy"
		
		t4.expressionTime="in1"

		t5=mathplotlibNode.createMPL()
		t5.Label="My Track Data xy Map"
		t5.record=False
		t5.useNumpy=True
		t5.sourceNumpy=t4

		t5.useOut2=True
		FreeCAD.ActiveDocument.recompute()
	except:
		sayexc()

	print "!",orig,"!"
	return (str(tm.lat)+','+str(tm.lon))
	return px,py