View difference between Paste ID: yc5penNq and LKXX2f6x
SHOW: | | - or go back to the newest paste.
1-
#***************************************************************************
1+
#!/usr/bin/env python
2-
#*                                                                         *
2+
3-
#*   Copyright (c) 2013                                                    *  
3+
import sys
4-
#*   Yorik van Havre <yorik@uncreated.net>                                 *  
4+
5-
#*                                                                         *
5+
FREECADPATH = '/home/danfalck/cadcam/freecad/freecad1/lib'
6-
#*   This program is free software; you can redistribute it and/or modify  *
6+
sys.path.append(FREECADPATH)
7-
#*   it under the terms of the GNU Lesser General Public License (LGPL)    *
7+
import FreeCAD, Part, Drawing, importWebGL
8-
#*   as published by the Free Software Foundation; either version 2 of     *
8+
9-
#*   the License, or (at your option) any later version.                   *
9+
box = Part.makeBox(100,100,100)
10-
#*   for detail see the LICENCE text file.                                 *
10+
box.translate(box.CenterOfMass.multiply(-1))
11-
#*                                                                         *
11+
12-
#*   This program is distributed in the hope that it will be useful,       *
12+
cylx = Part.makeCylinder(25, 100, FreeCAD.Base.Vector(0,1,0), FreeCAD.Base.Vector(0,90,0))
13-
#*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13+
cylx.translate(cylx.CenterOfMass.multiply(-1))
14-
#*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14+
15-
#*   GNU Library General Public License for more details.                  *
15+
cyly = Part.makeCylinder(25, 100, FreeCAD.Base.Vector(0,1,0), FreeCAD.Base.Vector(90,0,0))
16-
#*                                                                         *
16+
cyly.translate(cyly.CenterOfMass.multiply(-1))
17-
#*   You should have received a copy of the GNU Library General Public     *
17+
18-
#*   License along with this program; if not, write to the Free Software   *
18+
cylz = Part.makeCylinder(25, 100)
19-
#*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
19+
cylz.translate(cylz.CenterOfMass.multiply(-1))
20-
#*   USA                                                                   *
20+
21-
#*                                                                         *
21+
hole = cylx.fuse(cyly).fuse(cylz)
22-
#***************************************************************************
22+
23
test = box.cut(hole).common(Part.makeSphere(50))
24-
"FreeCAD webgl exporter"
24+
25
Part.show(test)
26-
import FreeCAD,Draft,Part,DraftGeomUtils
26+
27-
if FreeCAD.GuiUp:
27+
Shape = FreeCAD.ActiveDocument.Shape.Shape
28-
    from DraftTools import translate
28+
29
visibleG0,visibleG1,hiddenG0,hiddenG1 = Drawing.project(Shape,FreeCAD.Base.Vector(1,1,1))
30-
if FreeCAD.GuiUp:
30+
resultSVG = Drawing.projectToSVG(Shape,FreeCAD.Base.Vector(1,0.2,1))
31-
    import FreeCADGui
31+
# if 0 is used instead of dv, the image is rendered incorrectly
32-
else:
32+
#resultSVG = Drawing.projectToSVG(Shape,FreeCAD.Base.Vector(0,dv,1))
33-
    FreeCADGui = None
33+
34
35-
tab = "                "
35+
36-
addWireframe = False
36+
37
#with open('test.html', 'w') as f:
38-
if open.__module__ == '__builtin__':
38+
#  f.write('<html>')
39-
    pythonopen = open
39+
#  f.write('<body>')
40
#  f.write('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-100 -100 200 200">')
41-
def export(exportList,filename):
41+
#  f.write(resultSVG)
42-
    "exports the given objects to a .html file"
42+
#  f.write('</svg>')
43
#  f.write('</html>')
44-
    html = getHTML(exportList)
44+
#  f.write('</body>')
45-
    outfile = pythonopen(filename,"wb")
45+
46-
    outfile.write(html)
46+
def drawIt():
47-
    outfile.close()
47+
    result = ''
48-
    FreeCAD.Console.PrintMessage(str(translate("Arch","successfully written "))+filename)
48+
    result+='<html>'
49
    result+='<body>'
50-
def getHTML(objectsList):
50+
    result+='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-100 -100 200 200">'
51-
    "returns the complete HTML code of a viewer for the given objects"
51+
    result+= resultSVG
52
    result+= '</svg>'
53-
    # get objects data
53+
    result+='</html>'
54-
    objectsData = ''
54+
    result+='</body>'
55-
    for obj in objectsList:
55+
56-
        objectsData += getObjectData(obj)
56+
57-
    template = getTemplate()
57+
58-
    template = template.replace("$CameraData",getCameraData())
58+
def drwsolid():
59-
    template = template.replace("$ObjectsData",objectsData)
59+
    solidlist = [test]
60-
    return template
60+
    result = ''
61
    result+= importWebGL.getHTML(solidlist)
62-
def getCameraData():
62+