Esempio n. 1
0
    def getMaterial(self,key = None):
        """
        Method to get a material from the loaded database.
        parm key name, (usually glass name) if None, then it will be prompted for 
        via tio.getOption()
        """
        if key == None:
            options = self.getList()
            i,key = getOption("Material",options)
        #
        #        Scan through the data looking for the key thsi will crash if the format of the database is wrong.
        try:
            for line in DataBase:
                if not line.startswith("#") or len(line.strip()) == 0:
                    token = line.split()
                    if token[0].strip() == key:                # Got whole key

                        if token[1].strip().lower() == "formula":
                            formula = int(token[2].strip())    # Formula type
                        else:
                            raise IOError("Material.getMaterial: failed to find formula i {0:s}".format(line))

                        if token[3].strip().lower() == "range": 
                            ragn = []
                            rl = float(token[4].strip())       # Lower range
                            ragn.append(rl)
                            rh = float(token[5].strip())       # Upper range
                            ragn.append(rh)
                        else:
                            raise IOError("Material.getMaterail: failed to finf range in {0:s}".format(line))

                        if token[6].strip().lower() == "coef": # Start of coef
                            coef = []
                            for c in token[7:]:                # May be any numner
                                cf = float(c.strip())
                                coef.append(cf)
                                                               # Success, return
                            return Material(key,formula,ragn,coef)
                        else:
                            raise IOError("Material.getMaterail: failed to finf range in {0:s}".format(line))
        except (IOError,ValueError):
            raise SyntaxError("MaterialData.getMaterial: syntax error on line [{0:s}]".format(line))
            
    
        raise ValueError("MaterialData.getMaterial: Material {0:s} not found.".format(key))
Esempio n. 2
0
def main():

   f = tio.openFile("Give file","r","lens")

   for l in f.readlines():
      tio.tprint(l)

   
   z = tio.getComplex("Give complex",complex(1,1))
   tio.tprint("Complex is " + repr(z))

   v = tio.getVector3d("Vector")
   tio.tprint("vector is : " + repr(v))
   
   options = ["start","close","quit","restart"]
   n,nopt = tio.getOption("Option",options)

   tio.tprint("Option {0:d} chosen, name is {1:s}".format(n,nopt))

   x = tio.getFloat("float",3.0,0.0,5.0)
   tio.tprint(x)

   st = tio.getString("and a string")
   tio.tprint(st)
Esempio n. 3
0
def main():
    options = ["stop","go","reset","reformat"]
    i,opt = tio.getOption("Which option",options,1)
    tio.tprint("Option chosen was : ",i," being ",opt)