from includes import * from ui_compositionView import Ui_compositionView #from tree import Tree from cvitems import CVCluster, CVConnection from parameters import Settings import random import geosolver.graph import numpy class DecompositionView(QtGui.QDialog): """ A view where the decomposition of the system of constraints is visualised as a directed acyclic graph""" def __init__(self, viewport, viewportMngr, vpType, prototypeMngr, parent=None): """ Initialization of the CompositionView class Parameters: viewportMngr - the manager of the viewports where the composition view can reside in prototypeMngr - the manager of the prototypes is used to obtain the results of the solver """ QtGui.QDialog.__init__(self, parent) self.prototypeManager = prototypeMngr self.viewport = viewport self.viewportManager = viewportMngr self.settings = Settings() self.setWindowFlags(QtCore.Qt.Window) self.timer = QtCore.QObject() """map GeometricDecomposition to CVCluster""" self.map = {} self.ui = Ui_compositionView() self.ui.setupUi(self) self.ui.graphicsView.setupViewport(QtOpenGL.QGLWidget(QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers|QtOpenGL.QGL.DoubleBuffer))) self.ui.graphicsView.setRenderHints(QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform) self.currentTool = None self.viewportType = vpType self.orientation = TreeOrientation.BOTTOM self.overConstrainedColor = QtGui.QColor(0,0,255) self.underConstrainedColor = QtGui.QColor(255,0,0) self.wellConstrainedColor = QtGui.QColor(0,255,0) self.unsolvedColor = QtGui.QColor(125,124,255) self.createScene() self.createTriggers() def createTriggers(self): """ Create the triggers for the components in the graphical window """ QtCore.QObject.connect(self.ui.zoomInButton,QtCore.SIGNAL("clicked()"),self.zoomIn) QtCore.QObject.connect(self.ui.zoomOutButton,QtCore.SIGNAL("clicked()"),self.zoomOut) QtCore.QObject.connect(self.ui.fitButton, QtCore.SIGNAL("clicked()"), self.fit) #QtCore.QObject.connect(self.ui.collapseButton, QtCore.SIGNAL("clicked()"), self.collapse) QtCore.QObject.connect(self.ui.graphicsScene, QtCore.SIGNAL("changed(const QList & )"), self.updateSceneRect) QtCore.QObject.connect(self.ui.verticalSlider,QtCore.SIGNAL("valueChanged(int)"),self.setupMatrix) #QtCore.QObject.connect(self.settings.dvData,QtCore.SIGNAL("treeOrientationChanged()"), self.updateTreeOrientation) def getViewportType(self): return self.viewportType def updateGL(self): self.update() def createDecomposition(self): """ Create a new decomposition. If an older one exists it will be removed. """ self.clearScene() self.createScene() def clearScene(self): self.map = {} if self.ui.graphicsScene != None: for item in self.ui.graphicsView.items(): item.hide() if item.parentItem() == None: self.ui.graphicsScene.removeItem(item) def createScene(self): """ Updating the view with new data and nodes for the visualisation of the tree """ if self.prototypeManager.result != None: # get all clusters from result new = [self.prototypeManager.result] clusters = set() while len(new) > 0: c = new.pop() clusters.add(c) for child in c.subs: if child not in clusters: new.append(child) # create N layers for clusters with 1-N variables N = len(self.prototypeManager.result.variables) layers = [] for n in range(0,N+1): layers.append([]) # add clusters to layers for c in clusters: n = len(c.variables) layers[n].append(c) # sort clusters in layers # start from layer N (largest clusters) # clusters are initially ordered according to the order in which sub-clusters appear in the previous (n+1) layer for n in reversed(range(1,N)): print "ordering layers",n # find subiable pseudo-ordering in previous layers subordervalue = {} clusterindex = 0 for cluster in layers[n+1]: clusterindex = clusterindex+1 for sub in cluster.subs: # order by first appearence in cluster from left to right if sub not in subordervalue: subordervalue[sub] = clusterindex # determine pseudo-order clusters in this layers: sum subordervalues per cluster clusterordervalue = {} for cluster in layers[n]: clusterordervalue[cluster] = 0 for sub in cluster.subs: if sub in subordervalue: clusterordervalue[cluster] += subordervalue[sub] # sort clusters in layers layers[n].sort(lambda x,y:clusterordervalue[x]