Exemple #1
0
def processKeysValues(keys, values):
    if len(keys) != len(values):
        raise Exception(
            "DictionaryByKeysValues - Keys and Values do not have the same length"
        )
    stl_keys = []
    stl_values = []
    for i in range(len(keys)):
        if isinstance(keys[i], str):
            stl_keys.append(keys[i])
        else:
            stl_keys.append(str(keys[i]))
        if isinstance(values[i], list) and len(values[i]) == 1:
            value = values[i][0]
        else:
            value = values[i]
        if isinstance(value, bool):
            if value == False:
                stl_values.append(topologic.IntAttribute(0))
            else:
                stl_values.append(topologic.IntAttribute(1))
        elif isinstance(value, int):
            stl_values.append(topologic.IntAttribute(value))
        elif isinstance(value, float):
            stl_values.append(topologic.DoubleAttribute(value))
        elif isinstance(value, str):
            stl_values.append(topologic.StringAttribute(value))
        elif isinstance(value, sp.CartesianPoint):
            value = list(value)
            l = []
            for v in value:
                if isinstance(v, bool):
                    l.append(topologic.IntAttribute(v))
                elif isinstance(v, int):
                    l.append(topologic.IntAttribute(v))
                elif isinstance(v, float):
                    l.append(topologic.DoubleAttribute(v))
                elif isinstance(v, str):
                    l.append(topologic.StringAttribute(v))
            stl_values.append(topologic.ListAttribute(l))
        elif isinstance(value, list):
            l = []
            for v in value:
                if isinstance(v, bool):
                    l.append(topologic.IntAttribute(v))
                elif isinstance(v, int):
                    l.append(topologic.IntAttribute(v))
                elif isinstance(v, float):
                    l.append(topologic.DoubleAttribute(v))
                elif isinstance(v, str):
                    l.append(topologic.StringAttribute(v))
            stl_values.append(topologic.ListAttribute(l))
        else:
            raise Exception(
                "Error: Value type is not supported. Supported types are: Boolean, Integer, Double, String, or List."
            )
    myDict = topologic.Dictionary.ByKeysValues(stl_keys, stl_values)
    return myDict
def transferDictionaries(sources, sinks, tol):
    for sink in sinks:
        sinkKeys = []
        sinkValues = []
        iv = relevantSelector(sink)
        j = 1
        for source in sources:
            if topologyContains(source, iv, tol):
                d = source.GetDictionary()
                stl_keys = d.Keys()
                if len(stl_keys) > 0:
                    sourceKeys = d.Keys()
                    for aSourceKey in sourceKeys:
                        if aSourceKey not in sinkKeys:
                            sinkKeys.append(aSourceKey)
                            sinkValues.append("")
                    for i in range(len(sourceKeys)):
                        index = sinkKeys.index(sourceKeys[i])
                        sourceValue = getDictionary(source, sourceKeys[i])
                        if sourceValue != None:
                            if sinkValues[index] != "":
                                sinkValues[index] = sinkValues[
                                    index] + "," + sourceValue
                            else:
                                sinkValues[index] = sourceValue
        if len(sinkKeys) > 0 and len(sinkValues) > 0:
            stl_keys = []
            for key in sinkKeys:
                stl_keys.append(key)
            stlValues = []
            for value in sinkValues:
                stlValues.append(topologic.StringAttribute(value))
            newDict = topologic.Dictionary.ByKeysValues(stl_keys, stlValues)
            _ = sink.SetDictionary(newDict)
Exemple #3
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return
        if not any(socket.is_linked for socket in self.inputs):
            return

        keyList = self.inputs['Keys'].sv_get(deepcopy=False)
        valueList = self.inputs['Values'].sv_get(deepcopy=False)
        if (len(keyList) > len(valueList)):
            keyList = keyList[:len(valueList)]
        elif (len(valueList) > len(keyList)):
            valueList = valueList[:len(keyList)]
        print(keyList)
        print(valueList)
        keys = cppyy.gbl.std.list[cppyy.gbl.std.string]()
        values = cppyy.gbl.std.list[topologic.Attribute.Ptr]()
        dictionaries = []
        for i in range(len(keyList)):
            if isinstance(keyList[i], list) == False:
                keyList[i] = [keyList[i]]
            keys.push_back(cppyy.gbl.std.string(keyList[i][0]))
            if isinstance(valueList[i], list) == False:
                valueList[i] = [valueList[i]]
            value = topologic.StringAttribute(valueList[i][0])
            values.push_back(value)
        dictionary = topologic.Dictionary.ByKeysValues(keys, values)
        self.outputs['Dictionary'].sv_set([[dictionary]])
def setDictionary(elem, key, value):
  dictionary = elem.GetDictionary()
  dictionary.TryAdd(key, topologic.StringAttribute(value))
  elem.SetDictionary(dictionary)
def processItem(item):
    spaces = item.getSpaces()
    vertexIndex = 0
    cells = []
    apertures = []
    shadingFaces = []
    shadingSurfaces = item.getShadingSurfaces()
    for aShadingSurface in shadingSurfaces:
        shadingFaces.append(surfaceToFace(aShadingSurface))
    for count, aSpace in enumerate(spaces):
        osTransformation = aSpace.transformation()
        osTranslation = osTransformation.translation()
        osMatrix = osTransformation.rotationMatrix()
        rotation11 = osMatrix[0, 0]
        rotation12 = osMatrix[0, 1]
        rotation13 = osMatrix[0, 2]
        rotation21 = osMatrix[1, 0]
        rotation22 = osMatrix[1, 1]
        rotation23 = osMatrix[1, 2]
        rotation31 = osMatrix[2, 0]
        rotation32 = osMatrix[2, 1]
        rotation33 = osMatrix[2, 2]
        spaceFaces = []
        surfaces = aSpace.surfaces()
        for aSurface in surfaces:
            aFace = surfaceToFace(aSurface)
            aFace = topologic.TopologyUtility.Transform(
                aFace, osTranslation.x(), osTranslation.y(), osTranslation.z(),
                rotation11, rotation12, rotation13, rotation21, rotation22,
                rotation23, rotation31, rotation32, rotation33)
            #aFace.__class__ = topologic.Face
            subSurfaces = aSurface.subSurfaces()
            for aSubSurface in subSurfaces:
                aperture = surfaceToFace(aSubSurface)
                aperture = topologic.TopologyUtility.Transform(
                    aperture, osTranslation.x(), osTranslation.y(),
                    osTranslation.z(), rotation11, rotation12, rotation13,
                    rotation21, rotation22, rotation23, rotation31, rotation32,
                    rotation33)
                # aperture.__class__ = topologic.Face
                apertures.append(aperture)
            addApertures(aFace, apertures)
            spaceFaces.append(aFace)
        spaceCell = topologic.Cell.ByFaces(spaceFaces)
        print(count, spaceCell)
        if not spaceCell:
            spaceCell = topologic.Shell.ByFaces(spaceFaces)
        if not spaceCell:
            spaceCell = topologic.Cluster.ByTopologies(spaceFaces)
        if spaceCell:
            # Set Dictionary for Cell
            stl_keys = []
            stl_keys.append("TOPOLOGIC_id")
            stl_keys.append("TOPOLOGIC_name")
            stl_keys.append("TOPOLOGIC_type")
            stl_keys.append("TOPOLOGIC_color")
            stl_values = []
            spaceID = str(aSpace.handle()).replace('{', '').replace('}', '')
            stl_values.append(topologic.StringAttribute(spaceID))
            stl_values.append(topologic.StringAttribute(aSpace.name().get()))
            spaceTypeName = "Unknown"
            red = 255
            green = 255
            blue = 255
            if (aSpace.spaceType().is_initialized()):
                if (aSpace.spaceType().get().name().is_initialized()):
                    spaceTypeName = aSpace.spaceType().get().name().get()
                if (aSpace.spaceType().get().renderingColor()):
                    red = aSpace.spaceType().get().renderingColor().get(
                    ).renderingRedValue()
                    green = aSpace.spaceType().get().renderingColor().get(
                    ).renderingGreenValue()
                    blue = aSpace.spaceType().get().renderingColor().get(
                    ).renderingBlueValue()
            stl_values.append(topologic.StringAttribute(spaceTypeName))
            l = []
            l.append(topologic.IntAttribute(red))
            l.append(topologic.IntAttribute(green))
            l.append(topologic.IntAttribute(blue))
            stl_values.append(topologic.ListAttribute(l))
            dict = topologic.Dictionary.ByKeysValues(stl_keys, stl_values)
            _ = spaceCell.SetDictionary(dict)
            cells.append(spaceCell)
    return [cells, apertures, shadingFaces]