Esempio n. 1
0
 def findNearestPosition(aListPosition=None, aListGroupToIgnore=[]):
     "find nearest position between some known or specific position"
     "aListPosition is a mixed type list: eg: [ 'Sitting', 'Standing', {'TorsoX': 0.005236, 'TorsoY': 0.001745 } ]"
     "aListGroupToIgnore is a mixed type list of joint or group to ignore for comparison"
     "return an array [position, distance to this position, name of position (if this position has a name)]"
     if (aListPosition == None):
         aListPosition = PoseLibrary.getListPosition()
     rDistMin = 1000.0
     strNameMin = ""
     posMin = dict()
     for pos in aListPosition:
         strName = ""
         if (typetools.isString(pos)):
             strName = pos
             pos = PoseLibrary.getPosition(strName)
         rDist = PoseLibrary.comparePosition(pos, aListGroupToIgnore)
         # here it's not optimal, at every call we will compute the current position
         #      print( "rDist: %f" % rDist );
         if (rDist < rDistMin):
             rDistMin = rDist
             strNameMin = strName
             posMin = pos
     debug.debug("findNearestPosition between %s:" % aListPosition)
     debug.debug("posMin: %s\ndistMin: %f\nName: '%s'" %
                 (str(posMin), rDistMin, strNameMin))
     return [posMin, rDistMin, strNameMin]
Esempio n. 2
0
def removeFromCache( strName, typeType ):
    "remove an object from the cache, return False if the object isn't present in the cache"
    if( typetools.isString( typeType ) ):
        strGeneratedName = strName + str( type( typeType ) );
    else:
        strGeneratedName = strName + str( typeType ); # => return the type    
#    print( "altools.removeFromCache: strGeneratedName: '%s'" % strGeneratedName );        
    global global_dictCacheObj;
    try:
        del global_dictCacheObj[strGeneratedName];
        return True;
    except:
        pass
    return False;
Esempio n. 3
0
def getInCache( strName, typeType ):
  "get an objet from a list of cached object, return None if object not in cache"
#  debug( "altools.getInCache( %s )" % strName );
  if( typetools.isString( typeType ) ):
    strGeneratedName = strName + str( type( typeType ) );
  else:
    strGeneratedName = strName + str( typeType ); # => return the type
#  print( "altools.getInCache: strGeneratedName: '%s'" % strGeneratedName );
  global global_dictCacheObj;
  if( strGeneratedName in global_dictCacheObj ):
#    debug( "altools.getInCache: obj %s as %s caching success" % ( strName , strGeneratedName ) );
    return global_dictCacheObj[strGeneratedName];
#  debug( "altools.getInCache: obj %s as %s not in cache" % ( strName , strGeneratedName ) );
  return None;
Esempio n. 4
0
def removeFromCache(strName, typeType):
    "remove an object from the cache, return False if the object isn't present in the cache"
    if (typetools.isString(typeType)):
        strGeneratedName = strName + str(type(typeType))
    else:
        strGeneratedName = strName + str(typeType)
        # => return the type
#    print( "altools.removeFromCache: strGeneratedName: '%s'" % strGeneratedName );
    global global_dictCacheObj
    try:
        del global_dictCacheObj[strGeneratedName]
        return True
    except:
        pass
    return False
Esempio n. 5
0
def getInCache(strName, typeType):
    "get an objet from a list of cached object, return None if object not in cache"
    #  debug( "altools.getInCache( %s )" % strName );
    if (typetools.isString(typeType)):
        strGeneratedName = strName + str(type(typeType))
    else:
        strGeneratedName = strName + str(typeType)
        # => return the type
#  print( "altools.getInCache: strGeneratedName: '%s'" % strGeneratedName );
    global global_dictCacheObj
    if (strGeneratedName in global_dictCacheObj):
        #    debug( "altools.getInCache: obj %s as %s caching success" % ( strName , strGeneratedName ) );
        return global_dictCacheObj[strGeneratedName]
#  debug( "altools.getInCache: obj %s as %s not in cache" % ( strName , strGeneratedName ) );
    return None
Esempio n. 6
0
  def findNearestPosition( aListPosition = None, aListGroupToIgnore = [] ):
    "find nearest position between some known or specific position"
    "aListPosition is a mixed type list: eg: [ 'Sitting', 'Standing', {'TorsoX': 0.005236, 'TorsoY': 0.001745 } ]"
    "aListGroupToIgnore is a mixed type list of joint or group to ignore for comparison"
    "return an array [position, distance to this position, name of position (if this position has a name)]"
    if( aListPosition == None ):
      aListPosition = PoseLibrary.getListPosition();
    rDistMin = 1000.0;
    strNameMin = "";
    posMin = dict();
    for pos in aListPosition:
      strName = "";
      if( typetools.isString( pos ) ):
        strName = pos;
        pos = PoseLibrary.getPosition( strName );
      rDist = PoseLibrary.comparePosition( pos, aListGroupToIgnore ); # here it's not optimal, at every call we will compute the current position
#      print( "rDist: %f" % rDist );
      if( rDist < rDistMin ):
        rDistMin = rDist;
        strNameMin = strName;
        posMin = pos;
    debug.debug( "findNearestPosition between %s:"  % aListPosition );
    debug.debug( "posMin: %s\ndistMin: %f\nName: '%s'" % ( str( posMin), rDistMin, strNameMin ) );
    return [ posMin, rDistMin, strNameMin ];
def generateDocumentation( objectToDocument, bShowPrivate = False, nBaseLevel = 0 ):
    "return a documentation of all methods and objects contains in an object"
    class Dummy:
        """ a small class just to deduce class type further"""
        def __init__(self):
            pass
    # class Dummy - end
    
    strDoc = "";
    nLenHashLine = 60;
    strDoc += "#" + " " * nBaseLevel + "-" * nLenHashLine + "\n";
    try:
        strName = objectToDocument.__name__;
    except:
        strName = "(noname)";
    try:
        strTypeName = type( objectToDocument ).__name__;
    except:
        strTypeName = "(noname)";        
    strDoc += "#" + " " * nBaseLevel + " %s '%s': %s\n" % ( strTypeName, strName, str( objectToDocument.__doc__ ) );
    strDoc += "#" + " " * nBaseLevel + "-" * nLenHashLine + "\n";
#    strDoc += "# summary:\n";
    stdDocClass = "";
    stdDocMethod = "";
    stdDocData = "";
    
    for attrName in dir( objectToDocument ):
        if( not bShowPrivate and ( attrName[0:2] == '__' or attrName[0:4] == "dict" ) ):
            continue;
        some_object = getattr( objectToDocument, attrName );
        try:
            if( isinstance( some_object, type(constants) ) ): # quand on importe un module, il apparait dans le scope de l'objet qui l'a importé
                continue;
        except BaseException, err:
            print( "ERROR: generateDocumentation: pb on object '%s' (err:%s)" % ( attrName, err ) );
#            continue;
        strDesc = "";
        if( typetools.isDict( some_object ) ):
            strDesc = "a dictionnary.";
        elif( isinstance( some_object, type( bool ) ) ):
            strDesc = "a bool.";
        elif( typetools.isInt( some_object ) ):
            strDesc = "an integer.";
        elif( isinstance( some_object, float ) ):
            strDesc = "a float.";            
        elif( isinstance( some_object, list ) ):
            strDesc = "a list.";            
        elif( typetools.isString( some_object ) ):
            strDesc = "a string.";            
        elif( isinstance( some_object, type( Dummy ) ) ):
            attrName = "class " + attrName;
            strDesc = some_object.__doc__;
        else:
            if( some_object.__doc__ == None ):
                strDesc = "TODO: DOCUMENT ME";
            else:
                strDesc = some_object.__doc__;
        if( isinstance( some_object, type( generateDocumentation ) ) ):
            attrName = attrName + "(" + ")";
        strToAdd = "#" + " " * nBaseLevel + " - %s: %s\n" % ( attrName, strDesc );
        if( isinstance( some_object, type( generateDocumentation ) ) ):
            stdDocMethod += strToAdd;
        elif( isinstance( some_object, type( Dummy ) ) ):
            stdDocClass += strToAdd;
            stdDocClass += generateDocumentation( some_object, nBaseLevel = nBaseLevel + 6 );            
        else:
            stdDocData += strToAdd;
Esempio n. 8
0
def generateDocumentation(objectToDocument, bShowPrivate=False, nBaseLevel=0):
    "return a documentation of all methods and objects contains in an object"

    class Dummy:
        """ a small class just to deduce class type further"""
        def __init__(self):
            pass

    # class Dummy - end

    strDoc = ""
    nLenHashLine = 60
    strDoc += "#" + " " * nBaseLevel + "-" * nLenHashLine + "\n"
    try:
        strName = objectToDocument.__name__
    except:
        strName = "(noname)"
    try:
        strTypeName = type(objectToDocument).__name__
    except:
        strTypeName = "(noname)"
    strDoc += "#" + " " * nBaseLevel + " %s '%s': %s\n" % (
        strTypeName, strName, str(objectToDocument.__doc__))
    strDoc += "#" + " " * nBaseLevel + "-" * nLenHashLine + "\n"
    #    strDoc += "# summary:\n";
    stdDocClass = ""
    stdDocMethod = ""
    stdDocData = ""

    for attrName in dir(objectToDocument):
        if (not bShowPrivate
                and (attrName[0:2] == '__' or attrName[0:4] == "dict")):
            continue
        some_object = getattr(objectToDocument, attrName)
        try:
            if (
                    isinstance(some_object, type(constants))
            ):  # quand on importe un module, il apparait dans le scope de l'objet qui l'a importé
                continue
        except BaseException, err:
            print("ERROR: generateDocumentation: pb on object '%s' (err:%s)" %
                  (attrName, err))
#            continue;
        strDesc = ""
        if (typetools.isDict(some_object)):
            strDesc = "a dictionnary."
        elif (isinstance(some_object, type(bool))):
            strDesc = "a bool."
        elif (typetools.isInt(some_object)):
            strDesc = "an integer."
        elif (isinstance(some_object, float)):
            strDesc = "a float."
        elif (isinstance(some_object, list)):
            strDesc = "a list."
        elif (typetools.isString(some_object)):
            strDesc = "a string."
        elif (isinstance(some_object, type(Dummy))):
            attrName = "class " + attrName
            strDesc = some_object.__doc__
        else:
            if (some_object.__doc__ == None):
                strDesc = "TODO: DOCUMENT ME"
            else:
                strDesc = some_object.__doc__
        if (isinstance(some_object, type(generateDocumentation))):
            attrName = attrName + "(" + ")"
        strToAdd = "#" + " " * nBaseLevel + " - %s: %s\n" % (attrName, strDesc)
        if (isinstance(some_object, type(generateDocumentation))):
            stdDocMethod += strToAdd
        elif (isinstance(some_object, type(Dummy))):
            stdDocClass += strToAdd
            stdDocClass += generateDocumentation(some_object,
                                                 nBaseLevel=nBaseLevel + 6)
        else:
            stdDocData += strToAdd