begintemplate ModelViewAllCell
public mkdisplay, mechs, sall, dall, kschans
objref disp, dall, sall, this, nil, tobj
objref dmech, dparm, dpelm, disp1, disp2, ms, mview
strdef tstr, name

proc init() {
	mview = $o1
	sall = new SectionList()
	sprint(tstr, "forall %s.sall.append()", this)
	execute(tstr)
}

proc mkdisplay() {local i
	dall = new ModelViewSeclistAnalysis(mview, sall)
	dall.analyse()
	if (dall.all.count == 0) { return }

	disp = new TreeViewItem(nil, "Density Mechanisms", dall, -2)
	$o1.display.top.append(disp)

	disp1 = new TreeViewItem(disp, "Mechanisms in use", dall, -2)
	miu(disp1)

	disp1 = new TreeViewItem(disp, "Homogeneous Parameters", dall, -2)
	disp2 = new TreeViewItem(disp, "Heterogeneous Parameters", dall, -2)
	homo(disp1, disp2)

	disp1 = new TreeViewItem(disp, "Global parameters for density mechanisms", dall, -2)
	glob($o1, disp1)

	disp1 = new TreeViewItem(disp, "KSChan definitions for density mechanisms", dall, -2)
	kschan($o1, disp1)
}

iterator mechs() {local i
	for i=0, dall.dmlist.count-1 {
		$o1 = dall.dmlist.object(i)
		if (object_id($o1.location)) {
			iterator_statement
		}
	}
}

iterator kschans() {local i, j
	tobj = new List("KSChan")
	for j=0, dall.dmlist.count-1 {
		dmech = dall.dmlist.object(j)
		if (object_id(dmech.location)) {
			for i=0, tobj.count-1 {
				if (strcmp(tobj.object(i).name, dmech.name) == 0) {
					$o1 = tobj.object(i)
					iterator_statement
				}
			}
		}
	}
	tobj = nil
}

proc miu() {
	for mechs(dmech) {
		$o1.append(dmech.name, dmech.location, 0)
	}
}

proc homo() {local i, n
	for mechs(dmech) {
		for dmech.parmiter(dparm) {
			for dparm.parmiter(dpelm) {
				n = 0
				for i = 0, dpelm.parms.count-1 {
					tobj = dpelm.parms.object(i)
					if (tobj.type() == 1) {
						n += 1
					}else if (tobj.type() == 2) {
						n += tobj.vec.size
					}
				}
				if (n == 1) {
					dparm.display($o1, tstr, n, dmech.location)
				}else if (n > 1) {
					dparm.display($o2, tstr, n, dmech.location)
				}
			}
		}
	}
}

proc glob() {local i, j, size
	for mechs(dmech) {
		if (strcmp(dmech.name, "Ra") == 0) { continue }
		$o1.glob($o2, dmech.name)
	}
}

proc kschan() {local i, j, size
	tobj = new List("KSChan")
	for mechs(dmech) {
		for i=0, tobj.count-1 {
			if (strcmp(tobj.object(i).name, dmech.name) == 0) {
				dmech.kschan = tobj.object(i)
				$o1.kschan($o2, tobj.object(i))
			}
		}
	}
	tobj = nil
}

endtemplate ModelViewAllCell
