# Path: fuzzy/doc/structure/dot/dot.py
# def register_handler(class_, handler):
#     _registered_handler[class_] = handler
# 
# def print_dot(obj,out,system,parentname):
#     """Print object obj into output stream out"""
#     for class_ in type(obj).mro():
#         if class_ in _registered_handler.keys():
#             handler = _registered_handler[class_]
#             return handler(obj,out,system,parentname)
#     return ""


from fuzzy.doc.structure.dot.dot import register_handler,print_dot
import fuzzy.operator.Compound
import fuzzy.operator.Const
import fuzzy.operator.Input
import fuzzy.operator.Not
import fuzzy.norm.Norm
import fuzzy.norm.ParametricNorm
import fuzzy.Adjective
import fuzzy.AdjectiveProxy
import fuzzy.Rule
import fuzzy.OutputVariable
import fuzzy.Variable
register_handler(fuzzy.Adjective.Adjective,Doc_Adjective())
register_handler(fuzzy.AdjectiveProxy.AdjectiveProxy,Doc_Adjective())

#########################
class Doc_Rule(DocBase):
    def __init__(self):
        super(Doc_Rule,self).__init__()
        self.connection_style.update({
            "label":"%(label)s",
#            "decorate":"true",
            "weight":"2"
        })

    def __call__(self,obj,out,system,parent_name):
        node_name = "RULE_" + ID(obj)
        name = obj.getName(system)
        out.write(
"""#  subgraph "%(node_name)s" {
#    label="%(name)s";
    """ % locals())
        operator_node_name = print_dot(obj.operator,out,system,node_name)

        if isinstance(obj.adjective,fuzzy.Adjective.Adjective):
            #out.write("{rank=max;\n")
            adj_node_name = print_dot(obj.adjective,out,system,node_name)
            #out.write("}\n")
            self.make_connection(out,operator_node_name,adj_node_name,{"label": name + ("" if obj.certainty == 1.0 else ": %g" % obj.certainty) })
        elif isinstance(obj.adjective,list):
            for adj in obj.adjective:
                #out.write("{rank=max;\n")

# Path: fuzzy/doc/structure/dot/dot.py
# def register_handler(class_, handler):
#     _registered_handler[class_] = handler
# 
# def print_dot(obj,out,system,parentname):
#     """Print object obj into output stream out"""
#     for class_ in type(obj).mro():
#         if class_ in _registered_handler.keys():
#             handler = _registered_handler[class_]
#             return handler(obj,out,system,parentname)
#     return ""


# Path: fuzzy/doc/structure/dot/handlers.py
from fuzzy.doc.structure.dot.dot import register_handler,print_dot
import fuzzy.operator.Compound
import fuzzy.operator.Const
import fuzzy.operator.Input
import fuzzy.operator.Not
import fuzzy.norm.Norm
import fuzzy.norm.ParametricNorm
import fuzzy.Adjective
import fuzzy.AdjectiveProxy
import fuzzy.Rule
import fuzzy.OutputVariable
import fuzzy.Variable

register_handler(fuzzy.Adjective.Adjective,Doc_Adjective())
register_handler(fuzzy.AdjectiveProxy.AdjectiveProxy,Doc_Adjective())

#########################
class Doc_Rule(DocBase):
    def __init__(self):
        super(Doc_Rule,self).__init__()
        self.connection_style.update({
            "label":"%(label)s",
#            "decorate":"true",
            "weight":"2"
        })

    def __call__(self,obj,out,system,parent_name):
        node_name = "RULE_" + ID(obj)
        name = obj.getName(system)
        out.write(
"""#  subgraph "%(node_name)s" {
#    label="%(name)s";
    """ % locals())
        operator_node_name = print_dot(obj.operator,out,system,node_name)

        if isinstance(obj.adjective,fuzzy.Adjective.Adjective):
            #out.write("{rank=max;\n")
            adj_node_name = print_dot(obj.adjective,out,system,node_name)
            #out.write("}\n")
            self.make_connection(out,operator_node_name,adj_node_name,{"label": name + ("" if obj.certainty == 1.0 else ": %g" % obj.certainty) })
        elif isinstance(obj.adjective,list):
            for adj in obj.adjective:
                #out.write("{rank=max;\n")

                adj_node_name = print_dot(adj,out,system,node_name)