# This file is part of the Coral project.
# Please read the copyright notice in the LICENSE file.

import coral
from renderer import *
from coral.modeler.diagram.presentation import *
DI = coral.lang.XMIDI20
L = coral.lang.FSM10

import qt

## Layout classes borrowed directly from UML14

class CompartmentLAY( layout.VBoxLayouter ):
    def __init__( self, graphElement ):
        layout.VBoxLayouter.__init__(self, graphElement)

    def minSize( self ):
        return 0, 12

class NameCompartmentLAY( CompartmentLAY ):

    def moveContained(self, sizeHinter):
        x,y=0,0
        for c in self.contained():
            if c.graphElement.isVisible:
                x=(self.getSize()[0] - sizeHinter.getSizeHint(c)[0])/2
                c.move(x,y)
                y+=c.getSize()[1]

    def minSize(self):
        return 20, 0

    def minSizeHint(self):
        hc = 0
        w = [30] #Sentinel value
        for c in self.contained():
            if c.graphElement.isVisible:
                hc += c.minSizeHint()[1]
                w.append(c.minSizeHint()[0])
        wc = max(w)

        return (wc, max(hc,12))
    

#
# Edge layouters
#

class DependencyLAY( layout.GraphEdgeLayouter ):
    def layout(self, sizeHinter, toMinimal=False, w_parent = -1, h_parent = -1 ):
        self.moveContained(sizeHinter)

    def moveLabels(self, sizeHinter, startDiff, endDiff):
        edge=self.graphElement
        assert len(edge.contained)==1
        if len(edge.contained)==1:
            middleDiff=((startDiff[0]+endDiff[0])/2,(startDiff[1]+endDiff[1])/2)
            edge.contained[0].position.x += middleDiff[0]
            edge.contained[0].position.y += middleDiff[1]
        
    def move( self, x, y ):
        pass
        
    def resize( self, w, h ):
        pass
    
    def getSize( self ):
        return 0.0,0.0
