# Draw a poset of objects with specified level function and comparison function
#  (and optional string rep?)

### NEEDS FURTHER DEBUGGING

# Example usage
#  C:=Combinations([1..4]);
#  GraphicalObjectPoset(C, IsSubset, Size);

# For
#   Collection C, 
#   comparison function issubobj, and 
#   level function level_f. 
GraphicObjectPoset:=function(C, issubobj_f, level_f)
  local P, obj, vertices, v, w, u, l, posetduality;

  # -1 means levels are ordered from high to low.  Set to 1 for reverse.
  posetduality:=-1;

  P:=GraphicPoset("ObjectPoset", 800, 600);
  vertices:=[];
  for obj in C do
    if not posetduality*level_f(obj) in Levels(P) then
      CreateLevel(P, posetduality*level_f(obj), String(level_f(obj)));
    fi;
    v:=Vertex(P, obj, rec(levelparam:=posetduality*level_f(obj), label:="", shape:= "circle"));
    AddSet(vertices, v);
  od;

  for v in vertices do
    for w in vertices do
      if v<> w and issubobj_f(v!.data, w!.data) then
        if IsEmpty(Filtered(Maximals(P,v), x->issubobj_f(x!.data, w!.data))) then
#          Print(v!.data, " ", w!.data, ": ", List(Filtered(Maximals(P,v), x->issubobj_f(w!.data, x!.data)), x->x!.data), "\n");
          Perform(Filtered(Maximals(P,v), x->issubobj_f(w!.data, x!.data)), x->Delete(P, x, v));
          Edge(P, w, v);
        fi;
      fi;
    od;
  od;
  return P;
end;

