<commit_before>#***************************************************************************
#*                                                                         *
#*   Copyright (c) 2011                                                    *  
#*   <NAME> <<EMAIL>>                                 *  
#*                                                                         *
#*   This program is free software; you can redistribute it and/or modify  *
#*   it under the terms of the GNU Lesser General Public License (LGPL)    *
#*   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.                                 *
#*                                                                         *
#*   This program 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 this program; if not, write to the Free Software   *
#*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
#*   USA                                                                   *
#*                                                                         *
#***************************************************************************

import FreeCAD, Mesh, os, numpy
if FreeCAD.GuiUp:
    from DraftTools import translate
else:
    def translate(context,text):
        return text

__title__="FreeCAD Collada importer"
__author__ = "<NAME>"
__url__ = "http://www.freecadweb.org"

DEBUG = True

def checkCollada():
    "checks if collada if available"
    global collada
    COLLADA = None
    try:
        import collada
    except:
        FreeCAD.Console.PrintError(translate("Arch","pycollada not found, collada support is disabled.\n"))
        return False
    else:
        return True
    
def open(filename):
    "called when freecad wants to open a file"
    if not checkCollada(): 
        return
    docname = os.path.splitext(os.path.basename(filename))[0]
    doc = FreeCAD.newDocument(docname)
    doc.Label = decode(docname)
    FreeCAD.ActiveDocument = doc
    read(filename)
    return doc

def insert(filename,docname):
    "called when freecad wants to import a file"
    if not checkCollada(): 
        return
    try:
        doc = FreeCAD.getDocument(docname)
    except:
        doc = FreeCAD.newDocument(docname)
    FreeCAD.ActiveDocument = doc
    read(filename)
    return doc

def decode(name):
    "decodes encoded strings"
    try:
        decodedName = (name.decode("utf8"))
    except UnicodeDecodeError:
        try:
            decodedName = (name.decode("latin1"))
        except UnicodeDecodeError:
            FreeCAD.Console.PrintError(translate("Arch","Error: Couldn't determine character encoding"))
            decodedName = name
    return decodedName

def read(filename):
    global col
    col = collada.Collada(filename, ignore=[collada.DaeUnsupportedError])
    for geom in col.scene.objects('geometry'):
    #for geom in col.geometries:
        for prim in geom.primitives():
        #for prim in geom.primitives:
            print prim, dir(prim)
            meshdata = []
            if hasattr(prim,"triangles"):
                tset = prim.triangles()
            elif hasattr(prim,"triangleset"):
                tset = prim.triangleset()
            for tri in tset:
                face = []
                for v in tri.vertices:
                    face.append([v[0],v[1],v[2]])
                meshdata.append(face)
            print meshdata
            newmesh = Mesh.Mesh(meshdata)
            print newmesh
            obj = FreeCAD.ActiveDocument.addObject("Mesh::Feature","Mesh")
            obj.Mesh = newmesh

def export(exportList,filename):
    "called when freecad exports a file"
    if not checkCollada(): return
    colmesh = collada.Collada()
    colmesh.assetInfo.upaxis = collada.asset.UP_AXIS.Z_UP
    effect = collada.material.Effect("effect0", [], "phong", diffuse=(.7,.7,.7), specular=(1,1,1))
    mat = collada.material.Material("material0", "mymaterial", effect)
    colmesh.effects.append(effect)
    colmesh.materials.append(mat)
    objind = 0
    scenenodes = []
    for obj in exportList:
        if obj.isDerivedFrom("Part::Feature"):
            print "exporting object ",obj.Name, obj.Shape<commit_msg>Arch: removed degug messages in collada importer<commit_after>#***************************************************************************
#*                                                                         *
#*   Copyright (c) 2011                                                    *  
#*   <NAME> <<EMAIL>>                                 *  
#*                                                                         *
#*   This program is free software; you can redistribute it and/or modify  *
#*   it under the terms of the GNU Lesser General Public License (LGPL)    *
#*   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.                                 *
#*                                                                         *
#*   This program 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 this program; if not, write to the Free Software   *
#*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
#*   USA                                                                   *
#*                                                                         *
#***************************************************************************

import FreeCAD, Mesh, os, numpy
if FreeCAD.GuiUp:
    from DraftTools import translate
else:
    def translate(context,text):
        return text

__title__="FreeCAD Collada importer"
__author__ = "<NAME>"
__url__ = "http://www.freecadweb.org"

DEBUG = True

def checkCollada():
    "checks if collada if available"
    global collada
    COLLADA = None
    try:
        import collada
    except:
        FreeCAD.Console.PrintError(translate("Arch","pycollada not found, collada support is disabled.\n"))
        return False
    else:
        return True
    
def open(filename):
    "called when freecad wants to open a file"
    if not checkCollada(): 
        return
    docname = os.path.splitext(os.path.basename(filename))[0]
    doc = FreeCAD.newDocument(docname)
    doc.Label = decode(docname)
    FreeCAD.ActiveDocument = doc
    read(filename)
    return doc

def insert(filename,docname):
    "called when freecad wants to import a file"
    if not checkCollada(): 
        return
    try:
        doc = FreeCAD.getDocument(docname)
    except:
        doc = FreeCAD.newDocument(docname)
    FreeCAD.ActiveDocument = doc
    read(filename)
    return doc

def decode(name):
    "decodes encoded strings"
    try:
        decodedName = (name.decode("utf8"))
    except UnicodeDecodeError:
        try:
            decodedName = (name.decode("latin1"))
        except UnicodeDecodeError:
            FreeCAD.Console.PrintError(translate("Arch","Error: Couldn't determine character encoding"))
            decodedName = name
    return decodedName

def read(filename):
    global col
    col = collada.Collada(filename, ignore=[collada.DaeUnsupportedError])
    for geom in col.scene.objects('geometry'):
    #for geom in col.geometries:
        for prim in geom.primitives():
        #for prim in geom.primitives:
            #print prim, dir(prim)
            meshdata = []
            if hasattr(prim,"triangles"):
                tset = prim.triangles()
            elif hasattr(prim,"triangleset"):
                tset = prim.triangleset()
            for tri in tset:
                face = []
                for v in tri.vertices:
                    face.append([v[0],v[1],v[2]])
                meshdata.append(face)
            #print meshdata
            newmesh = Mesh.Mesh(meshdata)
            #print newmesh
            obj = FreeCAD.ActiveDocument.addObject("Mesh::Feature","Mesh")
            obj.Mesh = newmesh

def export(exportList,filename):
    "called when freecad exports a file"
    if not checkCollada(): return
    colmesh = collada.Collada()
    colmesh.assetInfo.upaxis = collada.asset.UP_AXIS.Z_UP
    effect = collada.material.Effect("effect0", [], "phong", diffuse=(.7,.7,.7), specular=(1,1,1))
    mat = collada.material.Material("material0", "mymaterial", effect)
    colmesh.effects.append(effect)
    colmesh.materials.append(mat)
    objind = 0
    scenenodes = []
    for obj in exportList:
        if obj.isDerivedFrom("Part::Feature"):
            print "exporting object ",obj.Name, obj.Shape
{'fraction_non_alphanumeric': 0.1197818334382211, 'fraction_numerical': 0.0071323683658485425, 'mean_word_length': 1.7823168952436534, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 42, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4408363', 'n_tokens_mistral': 2510, 'n_tokens_neox': 2389, 'n_words': 711}