def Prop(self,kind='',tag=None,set=None,name=None,**kargs):
        """Create a new property, empty by default.

        A property can hold almost anything, just like any Dict type.
        It has however four predefined keys that should not be used for
        anything else than explained hereafter:
        
        - nr: a unique id, that never should be set/changed by the user.
        - tag: an identification tag used to group properties
        - name: the name to be used for this set. Default is to use an
          automatically generated name.
        - set: identifies the geometrical elements for which the defined
          properties will hold. This can be either:

          - a single number,
          - a list of numbers,
          - the name of an already defined set,
          - a list of such names.

        Besides these, any other fields may be defined and will be added
        without checking.
        """
        d = CDict()
        # update with kargs first, to make sure tag,set and nr are sane
        d.update(dict(**kargs))

        prop = getattr(self,kind+'prop')
        d.nr = len(prop)
        if tag is not None:
            d.tag = str(tag)
        if name is None and kargs.has_key('setname'):
            # allow for backwards compatibility
            print("!! 'setname' is deprecated, please use 'name'")
            name = setname
        if set is not None:
            if type(set) is str and name is None:
                ### convenience to allow set='name' as alias for name='name'
                ### to reuse already defined set
                set,name = name,set
            else:
                if type(set) is int:
                    set = [ set ]
                d.set = unique(set)
                if name is None:
                    name = self.autoName(kind,d.nr)
        if name is not None:
            if type(name) is not str:
                raise ValueError,"Property name should be a string"
            d.name = name
        
        prop.append(d)
        return d
示例#2
0
    def Prop(self, kind='', tag=None, set=None, name=None, **kargs):
        """Create a new property, empty by default.

        A property can hold almost anything, just like any Dict type.
        It has however four predefined keys that should not be used for
        anything else than explained hereafter:
        
        - nr: a unique id, that never should be set/changed by the user.
        - tag: an identification tag used to group properties
        - name: the name to be used for this set. Default is to use an
          automatically generated name.
        - set: identifies the geometrical elements for which the defined
          properties will hold. This can be either:

          - a single number,
          - a list of numbers,
          - the name of an already defined set,
          - a list of such names.

        Besides these, any other fields may be defined and will be added
        without checking.
        """
        d = CDict()
        # update with kargs first, to make sure tag,set and nr are sane
        d.update(dict(**kargs))

        prop = getattr(self, kind + 'prop')
        d.nr = len(prop)
        if tag is not None:
            d.tag = str(tag)
        if name is None and 'setname' in kargs:
            # allow for backwards compatibility
            pf.utils.warn("!! 'setname' is deprecated, please use 'name'")
            name = setname
        if name is None and type(set) is str:
            ### convenience to allow set='name' as alias for name='name'
            ### to reuse already defined set
            name, set = set, name
        if name is None:
            name = self.autoName(kind, d.nr)
        elif type(name) is not str:
            raise ValueError, "Property name should be a string"
        d.name = name
        if set is not None:
            if type(set) is int or type(set) is str:
                set = [set]
            d.set = unique(set)

        prop.append(d)
        return d