Advertisement
danfalck

parseGroups.py

May 5th, 2013
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.74 KB | None | 0 0
  1. from DraftGeomUtils import sortEdges, findMidpoint,findWires, isReallyClosed, isClockwise
  2. from FreeCAD import Vector,Base,Part
  3. import FreeCADGui
  4. import FreeCAD
  5. import FreeCAD as App
  6. import FreeCADGui as Gui
  7. from PyQt4 import QtGui,QtCore
  8.  
  9. def getGeom(g):
  10.  
  11.     geom = g.Group
  12.     name = g.Label
  13.    
  14.     objs = []
  15.     item = "# ***** "+name+" *****\n"
  16.     edges=[]
  17.     points = []
  18.     for s in geom:
  19.         if s.Type =='Part::Vertex':
  20.             points.append(s)
  21.         else:
  22.         #objs.append(s.Object)
  23.             edges.append(s.Shape)
  24.        
  25.     sorted_edges = []
  26.     sorted_edges = sortEdges(edges)
  27.     wire1 = findWires(sorted_edges)
  28.  
  29.  
  30.     start=sorted_edges[0]
  31.     end=sorted_edges[-1]
  32.     startingZ = start.Vertexes[0].Z
  33.     #set starting depth to same Z as starting curve element
  34.     #self.form.lineEditStartDepth.setText(str(start.Vertexes[0].Z))
  35.     item += name+" = area.Curve()\n"
  36.    
  37.     if isReallyClosed(wire1[0]):
  38.         item += '#closed path\n'
  39.         path = 'closedpath'
  40.     else:
  41.         item += '#open path\n'
  42.         path = 'openpath'
  43.    
  44. #    if isSameVertex(start.Vertexes[0],end.Vertexes[1]) :
  45. #        item += '#closed path\n'
  46. #        path = 'closedpath'
  47. #    else:
  48. #        item += '#open path\n'
  49. #        path = 'openpath'
  50.  
  51.     #if path ==  'openpath' :
  52.     item += name+".append(area.Point(" + str(start.Vertexes[0].X) + "," + str(start.Vertexes[0].Y)+ "))\n"
  53.  
  54.     for s in sorted_edges:
  55.         #edges.append(s)
  56.         if (isinstance(s.Curve,Part.Circle)):
  57.             mp = findMidpoint(s)
  58.             ce = s.Curve.Center
  59. #            tang1 = s.Curve.tangent(s.ParameterRange[0]) ; tang2 = s.Curve.tangent(s.ParameterRange[1])
  60. #            cross1 = Vector.cross(Base.Vector(tang1[0][0],tang1[0][1],tang1[0][2]),Base.Vector(tang2[0][0],tang2[0][1],tang2[0][2]))
  61.             #look at isClockwise in DraftGeomUtils.py
  62. #            if cross1[2] > 0:
  63.             if isClockwise(s):
  64.                 direct = '1 ' #we seem to be working in a rh system in FreeCAD
  65.             else:
  66.                 direct = '-1 '
  67.             item += name+".append(area.Vertex("+str(direct)+ ", area.Point( "+ str(s.Vertexes[-1].Point[0])+", "+str(s.Vertexes[-1].Point[1])+ "), area.Point("+str(s.Curve.Center [0])+ ", " + str(s.Curve.Center[1])+ ")))\n"
  68.  
  69.         elif (isinstance(s.Curve,Part.Line)):
  70.             item += name+".append(area.Point( "+str(s.Vertexes[-1].Point[0])+", " +str(s.Vertexes[-1].Point[1])+ "))\n"
  71.         else:
  72.             pass
  73.  
  74. #    if path ==  'closedpath':
  75. #        item += name+".append(area.Point(" + str(start.Vertexes[1].X) + "," + str(start.Vertexes[1].Y)+ "))\n"
  76.  
  77.     #item+= name+".Reverse()\n"
  78.     #return item
  79.  
  80.     if points:
  81.         item+= name+"_startparams = {'key':'value'}\n"
  82.         item+= name+"_startparams['startpt'] = True\n"
  83.         item+= name+"_startparams['startptX'] = "+str(points[0].X)+"\n"
  84.         item+= name+"_startparams['startptY'] = "+str(points[0].Y)+"\n"
  85.         #item+= "kurve_funcs.make_smaller( "+ name+ ", start = area.Point(" + str(points[0].X)+","+str(points[0].Y)+"))\n"
  86.     else:
  87.         item+= name+"_startparams = {'key':'value'}\n"
  88.         item+= name+"_startparams['startpt'] = False\n"
  89.        
  90.  
  91. #    item+="profileparams['side'] = 'left'\n"
  92. #    item+="profile("+name+", profileparams,"+ name+"_startparams)\n"
  93.  
  94.     return item
  95. #    clipboard = QtGui.QApplication.clipboard()
  96. #    clipboard.setText(item)
  97.  
  98.  
  99. def getcustom(d):
  100.     item = ""
  101.     for p in d.PropertiesList:
  102.         if p=='Proxy':
  103.             pass
  104.         elif p=='Label':
  105.             pass
  106.         elif p=='CustomProps':
  107.             for i in d.getPropertyByName(p):
  108.                 item += i
  109.                
  110.         else:
  111.             if p == 'Side':
  112.                 item += (p +"="+ repr(d.getPropertyByName(p)))
  113.             else:
  114.                 item += (p +"="+ str(d.getPropertyByName(p)))
  115.             item +="\n"
  116.     return item
  117.  
  118.  
  119. def parseit():
  120.     sel=Gui.Selection.getSelection()
  121.     topgroup = sel[0]
  122.     items = ""
  123.     geomlist =[]
  124.     for g in topgroup.Group:
  125.         #geomlist.append(g.Label)
  126.         if g.Type ==  'App::FeaturePython':
  127.             #print 'FeaturePython\n'
  128.             items+= getcustom(g)
  129.             items+="\n"
  130.         elif g.Type ==  'App::DocumentObjectGroup' :
  131.             #print 'DocumentObjectGroup'
  132.             #items+=  '#'+ g.Label
  133.             geomlist.append(str(g.Label))
  134.             items+=  getGeom(g)
  135.             items+="\n"
  136.         else:
  137.             items+=  '# something else'
  138.     #items+= str(geomlist)
  139.     return items,geomlist
  140.  
  141. curves,geolist = parseit()
  142. heeksitems =""
  143. heeksitems+= curves
  144. #heeksitems+= "geolist=" + str(geolist)
  145. clipboard = QtGui.QApplication.clipboard()
  146. clipboard.setText(heeksitems)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement