Ejemplo n.º 1
0
 def __init__(self, section=None, material=None, orientation=None, **kargs):
     """Create a new element section property. Empty by default."""
     if _matDB is None:
         setMaterialDB({})
     if _secDB is None:
         setSectionDB({})
     CDict.__init__(self, kargs)
     self.addMaterial(material)
     self.addSection(section)
     if orientation is not None:
         self.orientation = orientation
Ejemplo n.º 2
0
    def __init__(self,section=None,material=None,orientation=None,behavior=None,**kargs):
        ### sectiontype is now an attribute of section ###
        """Create a new element section property. Empty by default."""
        self._class_init()
        CDict.__init__(self,kargs)
        self.addMaterial(material)
        self.addSection(section)
##         if sectiontype is not None:
##             self.sectiontype = sectiontype
        if orientation is not None:
            self.orientation = orientation
Ejemplo n.º 3
0
 def __init__(self,section=None,material=None,orientation=None,**kargs):
     """Create a new element section property. Empty by default."""
     if _matDB is None:
         setMaterialDB({})
     if _secDB is None:
         setSectionDB({})
     CDict.__init__(self,kargs)
     self.addMaterial(material)
     self.addSection(section)
     if orientation is not None:
         self.orientation = orientation
Ejemplo n.º 4
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
Ejemplo n.º 5
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 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
Ejemplo n.º 6
0
    def addMaterial(self, material):
        """Create or replace the material properties of the element.

        If the argument is a dict, it will be added to the global MaterialDB.
        If the argument is a string, this string will be used as a key to
        search in the global MaterialDB.
        """
        if isinstance(material, str):
            if material in _matDB:
                self.material = _matDB[material]
            else:
                pf.warning("Material '%s'  is not in the database" % material)
        elif isinstance(material, dict):
            _matDB[material['name']] = CDict(material)
            self.material = _matDB[material['name']]
        elif material == None:
            self.material = material
        else:
            raise ValueError, "Expected a string or a dict"
Ejemplo n.º 7
0
    def addSection(self, section):
        """Create or replace the section properties of the element.

        If 'section' is a dict, it will be added to the global SectionDB.
        If 'section' is a string, this string will be used as a key to
        search in the global SectionDB.
        """
        if isinstance(section, str):
            if section in _secDB:
                self.section = _secDB[section]
            else:
                pf.warning("Section '%s' is not in the database" % section)
        elif isinstance(section, dict):
            # WE COULD ADD AUTOMATIC CALCULATION OF SECTION PROPERTIES
            #self.computeSection(section)
            #print(section)
            _secDB[section['name']] = CDict(section)
            self.section = _secDB[section['name']]
        elif section == None:
            self.section = section
        else:
            raise ValueError, "Expected a string or a dict"
Ejemplo n.º 8
0
    print(os.getcwd())

    P = PropertyDB()

    Stick = P.Prop(
        color='green',
        name='Stick',
        weight=25,
        comment='This could be anything: a gum, a frog, a usb-stick,...')
    print(Stick)

    author = P.Prop(tag='author',
                    alias='Alfred E Neuman',
                    address=CDict({
                        'street': 'Krijgslaan',
                        'city': 'Gent',
                        'country': 'Belgium'
                    }))

    print(P.getProp(tag='author')[0])

    Stick.weight = 30
    Stick.length = 10
    print(Stick)

    print(author.street)
    author.street = 'Voskenslaan'
    print(author.street)
    print(author.address.street)
    author.address.street = 'Wiemersdreef'
    print(author.address.street)