示例#1
0
    def exportBlockTopology(self, name):
        retval= bte.BlockData()
        retval.name= name
        retval.fileName= self.fileName
        retval.logMessage= '# imported from file: '+self.fileName+' on '
        retval.logMessage+= str(datetime.datetime.now())

        counter= 0
        if(self.kPoints):
            for p in self.kPoints:
                key= self.kPointsNames[counter]
                bp= bte.BlockProperties(labels= self.labelDict[key])
                retval.appendPoint(id= counter,x= p[0],y= p[1],z= p[2], pointProperties= bp)
                counter+= 1

            counter= 0
            for key in self.lines:
                line= self.lines[key]
                bp= bte.BlockProperties(labels= self.labelDict[key])
                block= bte.BlockRecord(counter,'line',line, blockProperties= bp)
                retval.appendBlock(block)
                counter+= 1

            for name in self.getNamesToImport():
                fg= self.facesTree[name]
                for key in fg:
                    face= fg[key]
                    bp= bte.BlockProperties(labels= self.labelDict[key])
                    block= bte.BlockRecord(counter,'face',face, blockProperties= bp)
                    retval.appendBlock(block)
                    counter+= 1
        else:
            lmsg.warning('Nothing to export.')
        return retval
示例#2
0
    def importFaces(self):
        ''' Import 3D faces from DXF.'''
        self.facesTree= {}
        for name in self.layersToImport:
            self.facesTree[name]= dict()

        for obj in self.dxfFile.entities:
            dxfType= obj.dxftype()
            layerName= obj.dxf.layer
            if(layerName in self.layersToImport):
                facesDict= self.facesTree[layerName]
                if(dxfType == '3DFACE'):
                    vertices= list()
                    objPoints= [obj.dxf.vtx0, obj.dxf.vtx1, obj.dxf.vtx2, obj.dxf.vtx3]
                    for pt in objPoints:
                        p= self.getRelativeCoo(pt)
                        idx= self.getIndexNearestPoint(p)
                        vertices.append(idx)
                    self.propertyDict[obj.dxf.handle]= bte.BlockProperties(labels= [layerName])
                    facesDict[obj.dxf.handle]= vertices
                elif(dxfType == 'POLYFACE'):
                    count= 0
                    for q in self.polyfaceQuads[obj.dxf.handle]:
                        vertices= list()
                        for pt in q:
                            p= self.getRelativeCoo(pt)
                            idx= self.getIndexNearestPoint(p)
                            if not idx in vertices:
                                vertices.append(idx)
                            else:
                                lmsg.error('Point p: '+str(p)+' idx: '+str(idx)+' repeated in '+str(q)+' vertices: '+str(vertices))
                        count+= 1
                        id= obj.dxf.handle+'_'+str(count)
                        self.propertyDict[id]= bte.BlockProperties(labels= [layerName])
                        facesDict[id]= vertices
                elif((dxfType == 'POLYLINE') or (dxfType == 'LWPOLYLINE')):
                    count= 0
                    if(self.polylinesAsSurfaces): # Import as surfaces
                        for q in self.polylineQuads[obj.dxf.handle]:
                            vertices= list()
                            for pt in q:
                                p= self.getRelativeCoo(pt)
                                idx= self.getIndexNearestPoint(p)
                                if not idx in vertices:
                                    vertices.append(idx)
                                else:
                                    lmsg.error('Point p: '+str(p)+' idx: '+str(idx)+' repeated in '+str(q)+' vertices: '+str(vertices))
                            count+= 1
                            id= obj.dxf.handle+'_'+str(count)
                            self.propertyDict[id]= bte.BlockProperties(labels= [layerName])
                            facesDict[id]= vertices
                elif(dxfType in ['LINE', 'POINT']):
                    count= 0
                    # Nothing to do with those.
                else:
                    lmsg.log('Entity of type: '+dxfType+' ignored.')      
示例#3
0
 def importLines(self):
     ''' Import lines from DXF.'''
     self.lines= {}
     self.polylines= {}
     for obj in self.dxfFile.entities:
         type= obj.dxftype()
         lineName= obj.dxf.handle
         layerName= obj.dxf.layer
         if(layerName in self.layersToImport):
             if(type == 'LINE'):
                 vertices= [-1,-1]
                 p1= self.getRelativeCoo(obj.dxf.start)
                 p2= self.getRelativeCoo(obj.dxf.end)
                 length= cdist([p1],[p2])[0][0]
                 # Try to have all lines with the
                 # same orientation.
                 idx0, idx1= self.getOrientation(p1, p2, length/1e4)
                 # end orientation.
                 vertices[0]= idx0
                 vertices[1]= idx1
                 if(vertices[0]==vertices[1]):
                     lmsg.error('Error in line '+lineName+' vertices are equal: '+str(vertices))
                 if(length>self.threshold):
                     self.lines[lineName]= vertices
                     objProperties= bte.BlockProperties(labels= [layerName])
                     # xdata
                     if(obj.has_xdata('XC')):
                         objProperties.extendLabels(get_extended_data(obj))
                     # groups
                     if(lineName in self.entitiesGroups):
                         objProperties.extendLabels(self.entitiesGroups[lineName])
                     self.propertyDict[lineName]= objProperties
                 else:
                     lmsg.error('line too short: '+str(p1)+','+str(p2)+str(length))
             elif((type == 'POLYLINE') or (type == 'LWPOLYLINE')):
                 if(not self.polylinesAsSurfaces): # Import as lines
                     vertices= list()
                     for p in obj.points:
                         rCoo= self.getRelativeCoo(p)
                         vertices.append(self.getIndexNearestPoint(rCoo))
                     v1= vertices[0]
                     for v2 in vertices[1:]:
                         if(vertices[0]==vertices[1]):
                             lmsg.error('Error in line '+lineName+' vertices are equal: '+str(vertices))
                         else:
                             name= lineName+str(v1)+str(v2)
                             self.lines[name]= [v1,v2]
                             objProperties= bte.BlockProperties(labels= [layerName])
                             # xdata
                             if(obj.has_xdata('XC')):
                                 objProperties.extendLabels(get_extended_data(obj))
                             # groups
                             if(lineName in self.entitiesGroups):
                                 objProperties.extendLabels(self.entitiesGroups[lineName])
                             self.propertyDict[name]= objProperties
                         v1= v2
示例#4
0
    def __init__(self, block):
        ''' Constructor.

        :param block: block topology object (point, line, surface or volume).
        :param attributes: block attributes stored in a dictionary.
        '''
        if (block):
            labels = None
            if (block.hasProp('labels')):
                labels = block.getProp('labels')
            attributes = block.getProp('attributes')
            self.blockProperties = bte.BlockProperties(labels, attributes)
        else:
            self.blockProperties = bte.BlockProperties()
示例#5
0
    def extractPoints(self):
        '''Extract the points from the entities argument.'''
        retval_pos = dict()
        retval_properties = dict()

        def append_point(pt, groupName, pointName, objProperties):
            '''Append the point to the lists.'''
            retval_pos[pointName] = self.getRelativeCoo(pt)
            # group name as label.
            objProperties.extendLabels([groupName])
            retval_properties[pointName] = objProperties

        def append_points(vertexes, objName, groupName, objProperties):
            '''Append the points to the list.'''
            if (len(vertexes) > 1):
                for ptCount, v in enumerate(vertexes):
                    pointName = f'{objName}.{ptCount}'
                    append_point([v.X, v.Y, v.Z], grpName, pointName,
                                 objProperties)
            else:
                v = vertexes[0]
                append_point([v.X, v.Y, v.Z], grpName, objName, objProperties)

        for grpName in self.groupsToImport:
            grp = self.document.getObjectsByLabel(grpName)[0]
            if (hasattr(grp, 'Shape')):  # Object has shape.
                objName = grp.Name
                shape = grp.Shape
                shapeType = shape.ShapeType
                objProperties = bte.BlockProperties(labels=[grp.Label])
                if (shapeType == 'Shell'):
                    for fCount, f in enumerate(shape.SubShapes):
                        thisFaceName = f'{objName}.{fCount}'
                        append_points(f.OuterWire.OrderedVertexes,
                                      thisFaceName, grpName, objProperties)
                else:
                    append_points(grp.Shape.Vertexes, objName, grpName,
                                  objProperties)
            elif (len(grp.OutList) > 0):  # Object is a group
                for obj in grp.OutList:
                    if (hasattr(obj, 'Shape')):  # Object has shape.
                        shapeType = obj.Shape.ShapeType
                        objName = obj.Name
                        objProperties = bte.BlockProperties(labels=[obj.Label])
                        if (shapeType == 'Face'):
                            append_points(obj.Shape.Vertexes, objName, grpName,
                                          objProperties)
        return retval_pos, retval_properties
示例#6
0
 def import_face(faceShape, faceName, labelName):
     ''' Add the face argument to the dictionary.'''
     vertices = list()
     objPoints = list()
     for v in faceShape.OuterWire.OrderedVertexes:
         objPoints.append([float(v.X), float(v.Y), float(v.Z)])
     for pt in objPoints:
         p = self.getRelativeCoo(pt)
         idx = self.getIndexNearestPoint(p)
         vertices.append(idx)
     facesDict[faceName] = vertices
     properties = bte.BlockProperties(
         labels=[labelName], attributes=get_ifc_attributes(obj))
     self.propertyDict[faceName] = properties
示例#7
0
 def importPoints(self):
     ''' Import points from DXF.'''
     self.points= dict()
     for obj in self.dxfFile.entities:
         type= obj.dxftype()
         pointName= obj.dxf.handle
         layerName= obj.dxf.layer
         if(layerName in self.layersToImport):
             if(type == 'POINT'):
                 vertices= [-1]
                 p= self.getRelativeCoo(obj.dxf.location)
                 vertices[0]= self.getIndexNearestPoint(p)
                 self.points[pointName]= vertices
                 self.propertyDict[pointName]= bte.BlockProperties(labels= [layerName])
示例#8
0
 def importLines(self):
     ''' Import lines from FreeCAD file.'''
     self.lines = dict()
     for obj in self.document.Objects:
         if (hasattr(obj, 'Shape')):
             shapeType = obj.Shape.ShapeType
             labelName = obj.Label
             if ((shapeType == 'Wire')
                     and (labelName in self.groupsToImport)):
                 for i, e in enumerate(obj.Shape.Edges):
                     lineName = f"{obj.Name}{i}"
                     vertices = [-1, -1]
                     v0 = e.Vertexes[0]
                     v1 = e.Vertexes[1]
                     p1 = self.getRelativeCoo(
                         [float(v0.X),
                          float(v0.Y),
                          float(v0.Z)])
                     p2 = self.getRelativeCoo(
                         [float(v1.X),
                          float(v1.Y),
                          float(v1.Z)])
                     length = cdist([p1], [p2])[0][0]
                     # Try to have all lines with the
                     # same orientation.
                     idx0, idx1 = self.getOrientation(p1, p2, length / 1e4)
                     # end orientation.
                     vertices[0] = idx0
                     vertices[1] = idx1
                     if (vertices[0] == vertices[1]):
                         lmsg.error(
                             f'Error in line {lineName} vertices are equal: {vertices}'
                         )
                     if (length > self.threshold):
                         self.lines[lineName] = vertices
                         objLabels = [labelName]
                         # # groups
                         # if(lineName in self.entitiesGroups):
                         #     objLabels.extend(self.entitiesGroups[lineName])
                         self.propertyDict[lineName] = bte.BlockProperties(
                             labels=objLabels,
                             attributes=get_ifc_attributes(obj))
                     else:
                         lmsg.error(f'line too short: {p1},{p2}, {length}')
示例#9
0
 def importPoints(self):
     ''' Import points from FreeCAD file.'''
     self.points = dict()
     for obj in self.document.Objects:
         if (hasattr(obj, 'Shape')):
             shape = obj.Shape
             shapeType = shape.ShapeType
             pointName = obj.Name
             labelName = obj.Label
             if ((shapeType == 'Vertex')
                     and (labelName in self.groupsToImport)):
                 vertices = [-1]
                 p = self.getRelativeCoo(
                     [float(shape.X),
                      float(shape.Y),
                      float(shape.Z)])
                 vertices[0] = self.getIndexNearestPoint(p)
                 self.points[pointName] = vertices
                 properties = bte.BlockProperties(
                     labels=[labelName], attributes=get_ifc_attributes(obj))
                 self.propertyDict[pointName] = properties
示例#10
0
文件: dxf_reader.py 项目: smohaorg/xc
    def extractPoints(self):
        '''Extract the points from the entities argument.'''
        retval_pos = dict()
        retval_properties = dict()

        def append_point(count, pt, layerName, objName, objProperties):
            '''Append the point to the lists.'''
            pointName = objName + '_' + str(count)
            retval_pos[pointName] = self.getRelativeCoo(pt)
            properties = bte.BlockProperties.copyFrom(objProperties)
            properties.extendLabels([layerName])  # layer name as label.
            properties.appendAttribute('pointName', pointName)
            retval_properties[pointName] = properties
            return count + 1

        count = 0
        for obj in self.dxfFile.entities:
            type = obj.dxftype()
            layerName = obj.dxf.layer
            objName = obj.dxf.handle
            # xdata
            objProperties = bte.BlockProperties()
            if (obj.has_xdata('XC')):
                objProperties.extendLabels(get_extended_data(obj))
            # groups
            if (objName in self.entitiesGroups):
                objProperties.extendLabels(self.entitiesGroups[objName])
            if (layerName in self.layersToImport):
                if (type == 'POINT'):
                    count = append_point(count, obj.dxf.location, layerName,
                                         objName, objProperties)
                if (self.impSurfaces):
                    if (type == '3DFACE'):
                        objPoints = [
                            obj.dxf.vtx0, obj.dxf.vtx1, obj.dxf.vtx2,
                            obj.dxf.vtx3
                        ]
                        for pt in objPoints:
                            count = append_point(count, pt, layerName, objName,
                                                 objProperties)
                    elif (type == 'POLYLINE' and obj.get_mode()
                          == 'AcDbPolyFaceMesh'):  # POLYFACE
                        self.polyfaceQuads[objName] = decompose_polyface(
                            obj, tol=self.tolerance)
                        for q in self.polyfaceQuads[objName]:
                            for pt in q:
                                count = append_point(count, pt, layerName,
                                                     objName, objProperties)
                if (type == 'LINE'):
                    for pt in [obj.dxf.start, obj.dxf.end]:
                        count = append_point(count, pt, layerName, objName,
                                             objProperties)
                elif ((type == 'POLYLINE') or (type == 'LWPOLYLINE')):
                    if (self.polylinesAsSurfaces):
                        self.polylineQuads[objName] = decompose_polyline(
                            obj, tol=self.tolerance)
                        for q in self.polylineQuads[objName]:
                            for pt in q:
                                count = append_point(count, pt, layerName,
                                                     objName, objProperties)
                    else:
                        pts = obj.points
                        for pt in pts:
                            count = append_point(count, pt, layerName, objName,
                                                 objProperties)
        return retval_pos, retval_properties