コード例 #1
0
ファイル: lsysparameters.py プロジェクト: jvail/lpy
    def retrieve_from_json_dict(self, obj):
        import openalea.plantgl.algo.jsonrep as jrep
        from openalea.lpy.parameters.scalar import scalar_from_json_rep
        if not LsystemParameters.is_valid_schema(obj):
            return False
        version = obj.get('version',default_lpyjson_version)
        self.credits.update(obj.get('credits',{}))
        options = obj.get('options',{}).copy()
        if 'animation_timestep' in options:
            self.animation_timestep = options['animation_timestep']
            del options['animation_timestep']
        if 'default_category' in options:
            self.animation_timestep = options['default_category']
            del options['default_category']
        self.execOptions = options

        materials = {}
        for jmat in obj.get('materials',[]):
            idx = jmat['index']
            del jmat['index']
            materials[idx] = jrep.from_json_rep(jmat)
        self.color_list = materials
        parameters = obj.get('parameters',[])
        scalars = []
        gparameters = []
        managers = self.get_graphicalparameter_managers()
        for pset in parameters:
            pinfo = {}
            for propname in pset.keys():
                if not propname in ['items','scalars']:
                    pinfo[propname] = pset[propname]
            pscalars = list(map(scalar_from_json_rep,pset['scalars']))
            for sc in pscalars:
                sc.category = pinfo['name']

            pitems = []
            for v in pset['items']:
                managername = None
                if 'is_function' in v:
                    if v['is_function']:
                        managername = 'Function'
                    del v['is_function']
                obj = jrep.from_json_rep(v)
                if managername is None:
                    managername = graphictypemap[type(obj)]
                manager = managers[managername]
                pitems.append((manager,obj))
            category = Category(pinfo, pitems, pscalars)
            self.categories[category.info['name']] = category
        return True
コード例 #2
0
def jsonconversion(sceneobj, verbose=False):
    assert sceneobj.isValid()
    if verbose:
        print(sceneobj)
    res = jr.to_json_rep(sceneobj)
    if verbose:
        print(res)
    assert type(res) == dict
    sceneobj2 = jr.from_json_rep(res)
    assert type(sceneobj2) == type(sceneobj)
コード例 #3
0
ファイル: json.py プロジェクト: jvail/plantgl
 def read(self, fname):
     """ read a json file """
     with open(fname, 'r') as json_file:
         json_schema = json.load(json_file)
         return jr.from_json_rep(json_schema)