A list for the developers of CellML tools

Text archives Help


[cellml-dev] r2367 - in pce/trunk/chrome: content/controls content/domain_layouts skin


Chronological Thread 
  • From: ak.miller at auckland.ac.nz (Andrew Miller)
  • Subject: [cellml-dev] r2367 - in pce/trunk/chrome: content/controls content/domain_layouts skin
  • Date: Mon, 23 Jun 2008 15:44:22 +1200

CellML Automated Notifications wrote:
> Author: jmar150
> Date: 2008-06-23 15:29:52 +1200 (Mon, 23 Jun 2008)
> New Revision: 2367
>
> Added:
> pce/trunk/chrome/content/controls/rendered_view.xml
> Removed:
> pce/trunk/chrome/content/controls/units_view.xml
>
Hi,

I have a minor suggestion regarding the use of Subversion: would it be
possible for people to use the svn move command instead of renaming the
file on the filesystem, removing it from the old filename, and re-adding
it as the new filename? Using svn move is the same as doing a svn copy
and a svn delete, which has several advantages:

1) History of the file is preserved across the copy to the new name so
svn log and svn diff is easier to use on the new file name.
2) It should result in on-commit mails which are easier to review
without re-reviewing the entire renamed file, which is not always feasible.

Best regards,
Andrew

> Modified:
> pce/trunk/chrome/content/controls/modeltreeview.xml
> pce/trunk/chrome/content/domain_layouts/electrophysiology.xml
> pce/trunk/chrome/skin/pcenv-bindings.css
> Log:
> Added rendered connections view for Tracker Item 415. Generalised units
> view for all rendered views thus far.
>
>
> Modified: pce/trunk/chrome/content/controls/modeltreeview.xml
> ===================================================================
> --- pce/trunk/chrome/content/controls/modeltreeview.xml 2008-06-23
> 00:22:19 UTC (rev 2366)
> +++ pce/trunk/chrome/content/controls/modeltreeview.xml 2008-06-23
> 03:29:52 UTC (rev 2367)
> @@ -445,7 +445,8 @@
> component: { active_typefield: "textfield", rightclick:
> "component_menu",
> changeeditbox1: this.changeComponentName },
> group: { rightclick: "group_menu" },
> - connection: { rightclick: "connection_menu"},
> + connection: { rightclick: "connection_menu", editPane: 2,
> onselect: this.renderedConnection,
> + onunselect: this.setIntegratorDisplayed },
> import: { active_typefield: "textfield", rightclick:
> "standard_deletemenu",
> deleteHandler: this.deleteImport,
> changeeditbox1: this.getChangeImportURL(t) },
> @@ -1316,7 +1317,7 @@
> <body><![CDATA[
> this.self.activeDataEdit.QueryInterface
> (Components.interfaces.cellml_apiICellMLVariable).unitsName =
> value;
> - window.unitsView.refresh();
> + window.renderedView.refresh();
> return true;
> ]]></body>
> </method>
> @@ -1333,7 +1334,7 @@
> <body><![CDATA[
> this.self.activeDataEdit.QueryInterface
> (Components.interfaces.cellml_apiINamedCellMLElement).name =
> value;
> - window.unitsView.refresh();
> + window.renderedView.refresh();
> return true;
> ]]></body>
> </method>
> @@ -1342,7 +1343,7 @@
> <body><![CDATA[
> this.self.activeDataEdit.QueryInterface
> (Components.interfaces.cellml_apiICellMLVariable).initialValue =
> value;
> - window.unitsView.refresh();
> + window.renderedView.refresh();
> return true;
> ]]></body>
> </method>
> @@ -1696,9 +1697,16 @@
> <body><![CDATA[
> var ad = this.self.activeDataEdit.
> QueryInterface(Components.interfaces.cellml_apiIUnits);
> - window.unitsView.populateFromElement(ad);
> + window.renderedView.populateFromElement(ad);
> ]]></body>
> </method>
> + <method name="renderedConnection">
> + <body><![CDATA[
> + var ad = this.self.activeDataEdit.
> + QueryInterface(Components.interfaces.cellml_apiIConnection);
> + window.renderedView.populateFromConnection(ad);
> + ]]></body>
> + </method>
> <method name="populateDropdownUnits">
> <parameter name="dropdown" />
> <parameter name="element" />
> @@ -1736,7 +1744,7 @@
> try
> {
> element =
> element.QueryInterface(Components.interfaces.cellml_apiICellMLVariable);
> - window.unitsView.populateFromVariable(element);
> + window.renderedView.populateFromVariable(element);
> }
> catch (e)
> {
> @@ -1746,11 +1754,11 @@
> // units will be null if it is an instance of a predefined
> unit; decompose with CUSES
> if (units == null)
> {
> - window.unitsView.populateFromBaseUnit(element);
> + window.renderedView.populateFromBaseUnit(element);
> }
> else
> {
> - window.unitsView.populateFromElement(units);
> + window.renderedView.populateFromElement(units);
> }
> }
> </body>
>
> Added: pce/trunk/chrome/content/controls/rendered_view.xml
> ===================================================================
> --- pce/trunk/chrome/content/controls/rendered_view.xml
> (rev 0)
> +++ pce/trunk/chrome/content/controls/rendered_view.xml 2008-06-23
> 03:29:52 UTC (rev 2367)
> @@ -0,0 +1,513 @@
> +<?xml version="1.0"?>
> +<bindings id="renderedview-bindings"
> + xmlns="http://www.mozilla.org/xbl";
> + xmlns:html="http://www.w3.org/1999/xhtml";
> +
> xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
> + xmlns:xbl="http://www.mozilla.org/xbl";
> + xmlns:mml="http://www.w3.org/1998/Math/MathML";>
> + <binding id="rendered-binding">
> + <!-- This component is a div which is filled with MathML; there are four
> entry points to ... -->
> + <implementation>
> + <constructor>
> + window.renderedView = this;
> + this.mathml = document.getAnonymousElementByAttribute(this,
> "anonid",
> + "mathml");
> + </constructor>
> + <method name="removeMathML">
> + <body><![CDATA[
> + var cn = this.mathml.childNodes;
> + var i = 0, l = cn.length;
> + for (; i < l; i++)
> + this.mathml.removeChild(this.mathml.lastChild);
> + ]]></body>
> + </method>
> + <method name="refresh">
> + <body>
> + this.populateFromVariable(this.element);
> + </body>
> + </method>
> + <method name="populateFromBaseUnit">
> + <parameter name="unit"/>
> + <body><![CDATA[
> + unit =
> unit.QueryInterface(Components.interfaces.cellml_apiIUnit);
> + var rendstr = '<math
> xmlns="http://www.w3.org/1998/Math/MathML";><mrow><mn>';
> + rendstr += unit.units;
> + rendstr += '</mn> <mo>=</mo>';
> + rendstr += this.decomposeUnit(unit.units, unit);
> + rendstr += "</mrow></math>";
> + var n = window.domParser.parseFromString(rendstr, "text/xml");
> +
> + this.removeMathML();
> + this.mathml.appendChild(n.firstChild);
> + this.mathml.style.display = "block";
> +
> + ]]></body>
> + </method>
> + <method name="populateFromConnection">
> + <parameter name="connection"/>
> + <body><![CDATA[
> + var ci = Components.interfaces;
> + var cc = Components.classes;
> + connection = connection.QueryInterface(ci.cellml_apiIConnection);
> + var rendstr = '<math
> xmlns="http://www.w3.org/1998/Math/MathML";><mtable>';
> + var componentMapping =
> connection.componentMapping.QueryInterface(ci.cellml_apiIMapComponents);
> + rendstr += '<mtr><mtd>' + componentMapping.firstComponent.name +
> '</mtd><mtd/>';
> + rendstr += '<mtd>' + componentMapping.secondComponent.name +
> '</mtd></mtr>';
> + var varMapIterator =
> connection.variableMappings.iterateMapVariables();
> + var varMap;
> + // Determine whether any encapsulation holds between the
> components
> + var a = 'publicInterface', b = 'publicInterface';
> + var q = componentMapping.firstComponent, v =
> componentMapping.secondComponent;
> + while (q != null)
> + {
> + if (q.name == v.name)
> + {
> + b = 'privateInterface';
> + break;
> + }
> + q = q.encapsulationParent;
> + }
> + if (b != 'privateInterface')
> + {
> + q = componentMapping.firstComponent;
> + while (v != null)
> + {
> + if (q.name == v.name)
> + {
> + a = 'privateInterface';
> + break;
> + }
> + v = v.encapsulationParent;
> + }
> + }
> +
> + var mapSymbol = [ [ '?' , '?', '?' ] , [ '?', '??', '?' ] , [
> '?', '?', '?' ] ];
> + while(true)
> + {
> + varMap = varMapIterator.nextMapVariable();
> + if (varMap == null)
> + break;
> + varMap = varMap.QueryInterface(ci.cellml_apiIMapVariables);
> + rendstr += '<mtr><mtd>' + varMap.firstVariable.name + ' (';
> + rendstr += varMap.firstVariable.unitsName +') </mtd>';
> + // Determine direction of connection
> + rendstr += '<mtd><msymbol>' +
> mapSymbol[varMap.firstVariable[a]][varMap.secondVariable[b]] +
> '</msymbol></mtd>';
> + rendstr += '<mtd>' + varMap.secondVariable.name + ' (';
> + rendstr += varMap.secondVariable.unitsName +') </mtd></mtr>';
> + }
> +
> + rendstr += "</mtable></math>";
> + var n = window.domParser.parseFromString(rendstr, "text/xml");
> +
> + this.removeMathML();
> + this.mathml.appendChild(n.firstChild);
> + this.mathml.style.display = "block";
> +
> + ]]></body>
> + </method>
> + <method name="decomposeUnit">
> + <parameter name="unitName"/>
> + <parameter name="element"/>
> + <body><![CDATA[
> + var rendstr2 = '';
> + // Get a CUSES object for the model...
> + var cuses =
> + Components.classes["@cellml.org/cuses-bootstrap;1"].
> +
> getService(Components.interfaces.cellml_servicesICUSESBootstrap).createCUSESForModel(element.modelElement,
> true);
> + var unitsElement = null;
> + try
> + {
> + unitsElement = cuses.getUnitsByName(element,
> unitName).QueryInterface(Components.interfaces.cellml_servicesICanonicalUnitRepresentation);
> + }
> + catch (e)
> + {
> + rendstr2 = "<mrow><mstring>Unknown Unit</mstring></mrow>";
> + return rendstr2;
> + }
> + var numUnits = unitsElement.length, idx = 0;
> + var unitcomp = [];
> + if (numUnits == 0)
> + {
> + unitcomp = [ { prefix: "", name: "Unitless", exponent: "1" }
> ];
> + }
> + var offset = [];
> + var multiplier = 1;
> + var unit = null;
> + for(; idx < numUnits; idx++)
> + {
> + unit = unitsElement.fetchBaseUnit(idx);
> + unit =
> unit.QueryInterface(Components.interfaces.cellml_servicesIBaseUnitInstance);
> + if (unit == null)
> + break;
> + var comp = [];
> + comp.name = this.getCanonName(unit.unit.name);
> + if (unit.prefix != 1)
> + {
> + var premult = this.getShortPrefixSymbol2(unit.prefix,
> unit.exponent);
> + comp.prefix = premult.str;
> + multiplier *= Math.pow(Math.pow(10, premult.mult),
> unit.exponent);
> + }
> + else
> + {
> + comp.prefix = '';
> + }
> + comp.exponent = unit.exponent;
> + unitcomp.push(comp);
> + }
> + rendstr2 += "<mrow>";
> + if (multiplier != 1)
> + {
> + rendstr2 += "<mn>" + multiplier + "</mn>";
> + rendstr2 += "<mo> &#x00D7; </mo>";
> + }
> + var notfirst = false;
> + for (i in unitcomp)
> + {
> + if (notfirst)
> + {
> + rendstr2 += "<mo> &#x00D7; </mo>";
> + }
> + else
> + {
> + notfirst = true;
> + }
> + if (unitcomp[i].exponent != 1)
> + {
> + rendstr2 += '<msup>';
> + }
> + rendstr2 += "<mi>" + unitcomp[i].prefix + unitcomp[i].name +
> '</mi>';
> + if (unitcomp[i].exponent != 1)
> + {
> + rendstr2 += "<mn>" + unitcomp[i].exponent + "</mn></msup>";
> + }
> + }
> + rendstr2 += '</mrow>';
> + return rendstr2;
> + ]]></body>
> + </method>
> + <method name="populateFromVariable">
> + <parameter name="element"/>
> + <body><![CDATA[
> + this.element = element;
> + element =
> element.QueryInterface(Components.interfaces.cellml_apiICellMLVariable);
> + var rendstr = '<math
> xmlns="http://www.w3.org/1998/Math/MathML";><mrow><mn>';
> + rendstr += element.name;
> + rendstr += '</mn> <mo>:</mo>';
> + rendstr += ' <mfenced stretchy="true" largeop="true" open="{"
> close=""> <mtable>';
> + try
> + {
> + if (element.unitsElement)
> + {
> + var rendstr2 =
> '<mtr><mtd><mstring>Units</mstring></mtd><mtd><mo>:</mo></mtd>';
> + rendstr2 += '<mtd>';
> + var unitsElement =
> element.unitsElement.QueryInterface(Components.interfaces.cellml_apiIUnits);
> + var unitset =
> unitsElement.unitCollection.QueryInterface(Components.interfaces.cellml_apiIUnitSet).
> +
> iterateUnits().QueryInterface(Components.interfaces.cellml_apiIUnitIterator);
> + var unit = unitset.nextUnit();
> + unit =
> unit.QueryInterface(Components.interfaces.cellml_apiIUnit);
> + rendstr2 += "<mn>" + element.unitsName + "</mn></mtd></mtr>";
> +// rendstr2 += '<mtr><mtd><mstring>Decomposed
> Units</mstring></mtd><mtd><mo>:</mo></mtd><mtd>';
> +// rendstr2 += this.decomposeUnit(element.unitsName, element);
> +// rendstr2 += '</mtd></mtr>';
> + rendstr += rendstr2;
> + }
> + else
> + {
> + rendstr +=
> '<mtr><mtd><mstring>Units</mstring></mtd><mtd><mo>:</mo></mtd>';
> + rendstr += '<mtd><mi>' + this.getCanonName(element.unitsName)
> + '</mi></mtd></mtr>';
> + }
> + }
> + catch (e)
> + {
> + rendstr +=
> '<mtr><mtd><mstring>Units</mstring></mtd><mtd><mo>:</mo></mtd>';
> + rendstr += '<mtd><mi>' + this.getCanonName(element.unitsName) +
> '</mi></mtd></mtr>';
> + }
> + if (element.initialValue)
> + {
> + rendstr += '<mtr><mtd><mstring>Initial
> Value</mstring></mtd><mtd><mo>:</mo></mtd>';
> + rendstr += '<mtd><mn>' + element.initialValue +
> '</mn></mtd></mtr>';
> + }
> + var inttype = ['In', 'Out', 'None'];
> + if (element.privateInterface != null)
> + {
> + rendstr += '<mtr><mtd><mstring>Private
> Interface</mstring></mtd><mtd><mo>:</mo></mtd>';
> + rendstr += '<mtd><mn>' + inttype[element.privateInterface] +
> '</mn></mtd></mtr>';
> + }
> + if (element.publicInterface != null)
> + {
> + rendstr += '<mtr><mtd><mstring>Public
> Interface</mstring></mtd><mtd><mo>:</mo></mtd>';
> + rendstr += '<mtd><mn>' + inttype[element.publicInterface] +
> '</mn></mtd></mtr>';
> + }
> + rendstr += '</mtable></mfenced></mrow></math>';
> + var n = window.domParser.parseFromString(rendstr, "text/xml");
> +
> + var cn = this.mathml.childNodes;
> + var i = 0, l = cn.length;
> + for (; i < l; i++)
> + this.mathml.removeChild(this.mathml.lastChild);
> +
> + this.mathml.appendChild(n.firstChild);
> + this.mathml.style.display = "block";
> + ]]></body>
> + </method>
> + <method name="populateFromElement">
> + <parameter name="equation" />
> + <body>
> + this.modelDoc = equation.ownerDocument;
> + this.originalEquation = equation;
> + this.compEl = equation.parentNode;
> + this.isDirty = false;
> + this.populateFromElementInternal(equation);
> + </body>
> + </method>
> + <method name="populateFromElementInternal">
> + <parameter name="element" />
> + <body><![CDATA[
> + function openTag(tag)
> + {
> + rendstr += '<' + tag + '>';
> + }
> +
> + function closeTag(tag)
> + {
> + rendstr += '</' + tag + '>';
> + }
> +
> + function staticTag(tag)
> + {
> + rendstr += '<' + tag + '/>';
> + }
> +
> + function staticPair(tag, innerText)
> + {
> + rendstr += '<' + tag + '> ' + innerText + ' </' + tag + '>';
> + }
> +
> + function unmatchedStaticPair(tag1, tag2, innerText)
> + {
> + rendstr += '<' + tag1 + '> ' + innerText + ' </' + tag2 + '>';
> + }
> +
> + var tagstruct = { stack: [], level: 0 };
> +
> + function pushTag(tag)
> + {
> + rendstr += '<' + tag + '>';
> + tagstruct.level+=1;
> + tagstruct.stack.push(tag);
> + }
> + function popTag()
> + {
> + rendstr += '</' + tagstruct.stack.pop() + '>';
> + tagstruct.level-=1;
> + }
> +
> +
> + element =
> element.QueryInterface(Components.interfaces.cellml_apiIUnits);
> + var unitset =
> element.unitCollection.QueryInterface(Components.interfaces.cellml_apiIUnitSet).
> +
> iterateUnits().QueryInterface(Components.interfaces.cellml_apiIUnitIterator);
> + var multiplier = 1, offset = 0;
> + var unitcomp = [];
> + while (true)
> + {
> + var unit = unitset.nextUnit();
> + if (unit == null)
> + break;
> + unit =
> unit.QueryInterface(Components.interfaces.cellml_apiIUnit);
> + multiplier = multiplier * unit.multiplier;
> + offset = offset + unit.offset;
> + var comp = [];
> + comp.name = this.getShortSIName(unit.units);
> + if (comp.name == null)
> + comp.name = unit.units;
> +
> + comp.prefix = this.getShortPrefixSymbol(unit.prefix).str;
> + multiplier *= Math.pow(Math.pow(10,
> this.getShortPrefixSymbol(unit.prefix).mult), unit.exponent);
> +
> + comp.exponent = unit.exponent;
> + unitcomp.push(comp);
> + }
> + var rendstr = '<math
> xmlns="http://www.w3.org/1998/Math/MathML";>';
> + pushTag("mrow");
> + pushTag("apply");
> + staticTag("eq");
> + staticPair("ci", element.name);
> + if (multiplier != 1 || unitcomp.length > 1)
> + {
> + pushTag("apply");
> + staticTag("times");
> + if (multiplier != 1)
> + staticPair("cn", multiplier);
> + }
> + var lvl = tagstruct.level;
> + for (i in unitcomp)
> + {
> + if (unitcomp[i].exponent != 1)
> + {
> + pushTag("apply");
> + staticTag("power");
> + }
> + staticPair("ci", unitcomp[i].prefix + unitcomp[i].name);
> + if (unitcomp[i].exponent != 1)
> + {
> + staticPair("cn", unitcomp[i].exponent);
> + popTag();
> + }
> + }
> + while (tagstruct.level > 0)
> + popTag();
> + rendstr += "</math>";
> + if (window.mathContentToPresentation == null)
> + {
> + window.mathContentToPresentation = new XSLTProcessor();
> + var req =
> Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
> + req.open('GET', 'chrome://pcenv/skin/xsl/mathmlc2p.xsl',
> false);
> + req.send(null);
> +
> window.mathContentToPresentation.importStylesheet(req.responseXML);
> + }
> +
> + //this.removeMathML();
> + //var dtxt = window.bootstrap.serialiseNode(equation);
> + var n = window.domParser.parseFromString(rendstr, "text/xml");
> + var frag = window.mathContentToPresentation.
> + transformToFragment(n, document);
> + var cn = this.mathml.childNodes;
> + var i = 0, l = cn.length;
> + for (; i < l; i++)
> + this.mathml.removeChild(this.mathml.lastChild);
> +
> + this.mathml.appendChild(frag);
> + this.mathml.style.display = "block";
> + ]]></body>
> + </method>
> + <method name="processChange">
> + <parameter name="equation" />
> + <body><![CDATA[
> + if (!window.modelSelector.changeRequested())
> + return;
> + this.isDirty = true;
> + var eq = window.mis.inputFormatToMathML(this.modelDoc,
> this.textrep.value);
> + if (eq.namespaceURI ==
> "http://www.cellml.org/tools/mathml-input/error#";)
> + {
> + var prob = eq.getAttribute("problem");
> + var column = eq.getAttribute("column");
> + Status("Note: " + prob);
> + this.removeMathML();
> + var v = this.textrep.value;
> + var left = v.substr(0, column);
> + var idx =
> left.search(/[^a-z|A-Z|0-9|\.|\_][a-z|A-Z|0-9|\.|\_]*$/);
> + if (idx == -1)
> + idx = 0;
> + else
> + idx++;
> + if (idx == left.length)
> + idx--;
> + if (idx != 0)
> + this.mathml.appendChild(document.createTextNode(
> + left.substr(0, idx)));
> + var div =
> document.createElementNS("http://www.w3.org/1999/xhtml";,
> + "div");
> + div.style.background = "red";
> + div.style.color = "white";
> + div.style.display = "inline";
> + div.appendChild(document.createTextNode(left.substr(idx)));
> + this.mathml.appendChild(div);
> +
> this.mathml.appendChild(document.createTextNode(v.substr(column)));
> + }
> + else
> + {
> + this.populateFromElementInternal(eq);
> + }
> + ]]></body>
> + </method>
> + <method name="getShortSIName">
> + <parameter name="SILong" />
> + <body>
> + var shortByLong = {meter: "m", metre: "m", kilogram: "kg", gram:
> "g",
> + second: "s", litre: "L", liter: "L",
> ampere: "A",
> + kelvin: "K", mole: "mol", candela: "cd",
> radian: "rad",
> + hertz: "Hz", newton: "N", pascal: "Pa",
> joule: "J",
> + watt: "W", coulomb: "C", volt: "V", farad:
> "F", ohm: "?",
> + siemens: "S", weber: "Wb", tesla: "T",
> henry: "H",
> + Celcius: "?C", lumen: "lm", lux: "lux",
> becquerel: "Bq",
> + gray: "Gy", sievert: "Sv", katal: "kat" };
> + if (shortByLong[SILong] != null)
> + return shortByLong[SILong];
> + else
> + return null;
> + </body>
> + </method>
> + <method name="getCanonName">
> + <parameter name="SILong" />
> + <body>
> + if (this.getShortSIName(SILong) != null)
> + return this.getShortSIName(SILong);
> + return SILong;
> + </body>
> + </method>
> + <method name="getShortPrefixSymbol">
> + <parameter name="prefix" />
> + <body><![CDATA[
> + var prefixesByNumber = {"24": "Y", "21": "Z", "18": "E", "15":
> "P",
> + "12": "T", "9": "G", "6": "M", "3": "k",
> "2": "h",
> + "1": "da", "0": "", "-1": "d", "-2": "c",
> + "-3": "m", "-6": "?", "-9": "n", "-12":
> "p",
> + "-15": "f", "-18": "a", "-21": "z",
> "-24": "y" };
> + if (prefixesByNumber[prefix]!=null)
> + return {mult: 0, str: prefixesByNumber[prefix]};
> + if (prefix > 24)
> + {
> + prefix -= 24;
> + return {mult: prefix, str: prefixesByNumber["24"]};
> + }
> + if (prefix < -24)
> + {
> + prefix += 24;
> + return {mult: prefix, str: prefixesByNumber["-24"]};
> + }
> + var mul0 = (prefix % 3) * (Math.abs(prefix) / prefix);
> + var st0 = prefixesByNumber[prefix - mul0];
> + return {mult: mul0, str: st0};
> + ]]></body>
> + </method>
> + <method name="getShortPrefixSymbol2">
> + <parameter name="prefix" />
> + <parameter name="expcorr"/>
> + <body><![CDATA[
> + // This works around CUSES giving back prefixes as raw numbers
> rather than magnitudes
> + // For (10 ^ number) x (unit ^ exp), take number - exp, and then
> take the closest unit.
> + // For the remainder, multiply by 10 ^ exp, and treat that as
> the new multiplier.
> + prefix = -(Math.ceil(Math.log(prefix) / window.log10) / expcorr);
> + var prefixesByNumber = {"24": "Y", "21": "Z", "18": "E", "15":
> "P",
> + "12": "T", "9": "G", "6": "M", "3": "k",
> "2": "h",
> + "1": "da", "0": "", "-1": "d", "-2": "c",
> + "-3": "m", "-6": "?", "-9": "n", "-12":
> "p",
> + "-15": "f", "-18": "a", "-21": "z",
> "-24": "y" };
> + if (prefixesByNumber[prefix]!=null)
> + return {mult: 0, str: prefixesByNumber[prefix]};
> + if (prefix > 24)
> + {
> + prefix -= 24;
> + return {mult: prefix + expcorr, str: prefixesByNumber["24"]};
> + }
> + if (prefix < -24)
> + {
> + prefix += 24;
> + return {mult: prefix + expcorr, str: prefixesByNumber["-24"]};
> + }
> + var mul0 = (prefix % 3) * (Math.abs(prefix) / prefix);
> + var st0 = prefixesByNumber[prefix - mul0];
> + return {mult: mul0 + expcorr, str: st0};
> + ]]></body>
> + </method>
> + </implementation>
> + <content>
> + <xul:vbox flex="1">
> + <xul:box pack="center" align="center" flex="1"
> + style="overflow: auto; width: 0px; height: 0px;">
> + <html:div anonid="mathml"/>
> + </xul:box>
> + </xul:vbox>
> + </content>
> + </binding>
> +</bindings>
>
> Deleted: pce/trunk/chrome/content/controls/units_view.xml
> ===================================================================
> --- pce/trunk/chrome/content/controls/units_view.xml 2008-06-23 00:22:19
> UTC (rev 2366)
> +++ pce/trunk/chrome/content/controls/units_view.xml 2008-06-23 03:29:52
> UTC (rev 2367)
> @@ -1,450 +0,0 @@
> -<?xml version="1.0"?>
> -<bindings id="unitsview-bindings"
> - xmlns="http://www.mozilla.org/xbl";
> - xmlns:html="http://www.w3.org/1999/xhtml";
> -
> xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
> - xmlns:xbl="http://www.mozilla.org/xbl";
> - xmlns:mml="http://www.w3.org/1998/Math/MathML";>
> - <binding id="unit-binding">
> - <implementation>
> - <constructor>
> - window.unitsView = this;
> - this.mathml = document.getAnonymousElementByAttribute(this,
> "anonid",
> - "mathml");
> - </constructor>
> - <method name="removeMathML">
> - <body><![CDATA[
> - var cn = this.mathml.childNodes;
> - var i = 0, l = cn.length;
> - for (; i < l; i++)
> - this.mathml.removeChild(this.mathml.lastChild);
> - ]]></body>
> - </method>
> - <method name="refresh">
> - <body>
> - this.populateFromVariable(this.element);
> - </body>
> - </method>
> - <method name="populateFromBaseUnit">
> - <parameter name="unit"/>
> - <body><![CDATA[
> - unit =
> unit.QueryInterface(Components.interfaces.cellml_apiIUnit);
> - var rendstr = '<math
> xmlns="http://www.w3.org/1998/Math/MathML";><mrow><mn>';
> - rendstr += unit.units;
> - rendstr += '</mn> <mo>=</mo>';
> - rendstr += this.decomposeUnit(unit.units, unit);
> - rendstr += "</mrow></math>";
> - var n = window.domParser.parseFromString(rendstr, "text/xml");
> -
> - this.removeMathML();
> - this.mathml.appendChild(n.firstChild);
> - this.mathml.style.display = "block";
> -
> - ]]></body>
> - </method>
> - <method name="decomposeUnit">
> - <parameter name="unitName"/>
> - <parameter name="element"/>
> - <body><![CDATA[
> - var rendstr2 = '';
> - // Get a CUSES object for the model...
> - var cuses =
> - Components.classes["@cellml.org/cuses-bootstrap;1"].
> -
> getService(Components.interfaces.cellml_servicesICUSESBootstrap).createCUSESForModel(element.modelElement,
> true);
> - var unitsElement = null;
> - try
> - {
> - unitsElement = cuses.getUnitsByName(element,
> unitName).QueryInterface(Components.interfaces.cellml_servicesICanonicalUnitRepresentation);
> - }
> - catch (e)
> - {
> - rendstr2 = "<mrow><mstring>Unknown Unit</mstring></mrow>";
> - return rendstr2;
> - }
> - var numUnits = unitsElement.length, idx = 0;
> - var unitcomp = [];
> - if (numUnits == 0)
> - {
> - unitcomp = [ { prefix: "", name: "Unitless", exponent: "1" }
> ];
> - }
> - var offset = [];
> - var multiplier = 1;
> - var unit = null;
> - for(; idx < numUnits; idx++)
> - {
> - unit = unitsElement.fetchBaseUnit(idx);
> - unit =
> unit.QueryInterface(Components.interfaces.cellml_servicesIBaseUnitInstance);
> - if (unit == null)
> - break;
> - var comp = [];
> - comp.name = this.getCanonName(unit.unit.name);
> - if (unit.prefix != 1)
> - {
> - var premult = this.getShortPrefixSymbol2(unit.prefix,
> unit.exponent);
> - comp.prefix = premult.str;
> - multiplier *= Math.pow(Math.pow(10, premult.mult),
> unit.exponent);
> - }
> - else
> - {
> - comp.prefix = '';
> - }
> - comp.exponent = unit.exponent;
> - unitcomp.push(comp);
> - }
> - rendstr2 += "<mrow>";
> - if (multiplier != 1)
> - {
> - rendstr2 += "<mn>" + multiplier + "</mn>";
> - rendstr2 += "<mo> &#x00D7; </mo>";
> - }
> - var notfirst = false;
> - for (i in unitcomp)
> - {
> - if (notfirst)
> - {
> - rendstr2 += "<mo> &#x00D7; </mo>";
> - }
> - else
> - {
> - notfirst = true;
> - }
> - if (unitcomp[i].exponent != 1)
> - {
> - rendstr2 += '<msup>';
> - }
> - rendstr2 += "<mi>" + unitcomp[i].prefix + unitcomp[i].name +
> '</mi>';
> - if (unitcomp[i].exponent != 1)
> - {
> - rendstr2 += "<mn>" + unitcomp[i].exponent + "</mn></msup>";
> - }
> - }
> - rendstr2 += '</mrow>';
> - return rendstr2;
> - ]]></body>
> - </method>
> - <method name="populateFromVariable">
> - <parameter name="element"/>
> - <body><![CDATA[
> - this.element = element;
> - element =
> element.QueryInterface(Components.interfaces.cellml_apiICellMLVariable);
> - var rendstr = '<math
> xmlns="http://www.w3.org/1998/Math/MathML";><mrow><mn>';
> - rendstr += element.name;
> - rendstr += '</mn> <mo>:</mo>';
> - rendstr += ' <mfenced stretchy="true" largeop="true" open="{"
> close=""> <mtable>';
> - try
> - {
> - if (element.unitsElement)
> - {
> - var rendstr2 =
> '<mtr><mtd><mstring>Units</mstring></mtd><mtd><mo>:</mo></mtd>';
> - rendstr2 += '<mtd>';
> - var unitsElement =
> element.unitsElement.QueryInterface(Components.interfaces.cellml_apiIUnits);
> - var unitset =
> unitsElement.unitCollection.QueryInterface(Components.interfaces.cellml_apiIUnitSet).
> -
> iterateUnits().QueryInterface(Components.interfaces.cellml_apiIUnitIterator);
> - var unit = unitset.nextUnit();
> - unit =
> unit.QueryInterface(Components.interfaces.cellml_apiIUnit);
> - rendstr2 += "<mn>" + element.unitsName + "</mn></mtd></mtr>";
> -// rendstr2 += '<mtr><mtd><mstring>Decomposed
> Units</mstring></mtd><mtd><mo>:</mo></mtd><mtd>';
> -// rendstr2 += this.decomposeUnit(element.unitsName, element);
> -// rendstr2 += '</mtd></mtr>';
> - rendstr += rendstr2;
> - }
> - else
> - {
> - rendstr +=
> '<mtr><mtd><mstring>Units</mstring></mtd><mtd><mo>:</mo></mtd>';
> - rendstr += '<mtd><mi>' + this.getCanonName(element.unitsName)
> + '</mi></mtd></mtr>';
> - }
> - }
> - catch (e)
> - {
> - rendstr +=
> '<mtr><mtd><mstring>Units</mstring></mtd><mtd><mo>:</mo></mtd>';
> - rendstr += '<mtd><mi>' + this.getCanonName(element.unitsName) +
> '</mi></mtd></mtr>';
> - }
> - if (element.initialValue)
> - {
> - rendstr += '<mtr><mtd><mstring>Initial
> Value</mstring></mtd><mtd><mo>:</mo></mtd>';
> - rendstr += '<mtd><mn>' + element.initialValue +
> '</mn></mtd></mtr>';
> - }
> - var inttype = ['In', 'Out', 'None'];
> - if (element.privateInterface != null)
> - {
> - rendstr += '<mtr><mtd><mstring>Private
> Interface</mstring></mtd><mtd><mo>:</mo></mtd>';
> - rendstr += '<mtd><mn>' + inttype[element.privateInterface] +
> '</mn></mtd></mtr>';
> - }
> - if (element.publicInterface != null)
> - {
> - rendstr += '<mtr><mtd><mstring>Public
> Interface</mstring></mtd><mtd><mo>:</mo></mtd>';
> - rendstr += '<mtd><mn>' + inttype[element.publicInterface] +
> '</mn></mtd></mtr>';
> - }
> - rendstr += '</mtable></mfenced></mrow></math>';
> - var n = window.domParser.parseFromString(rendstr, "text/xml");
> -
> - var cn = this.mathml.childNodes;
> - var i = 0, l = cn.length;
> - for (; i < l; i++)
> - this.mathml.removeChild(this.mathml.lastChild);
> -
> - this.mathml.appendChild(n.firstChild);
> - this.mathml.style.display = "block";
> - ]]></body>
> - </method>
> - <method name="populateFromElement">
> - <parameter name="equation" />
> - <body>
> - this.modelDoc = equation.ownerDocument;
> - this.originalEquation = equation;
> - this.compEl = equation.parentNode;
> - this.isDirty = false;
> - this.populateFromElementInternal(equation);
> - </body>
> - </method>
> - <method name="populateFromElementInternal">
> - <parameter name="element" />
> - <body><![CDATA[
> - function openTag(tag)
> - {
> - rendstr += '<' + tag + '>';
> - }
> -
> - function closeTag(tag)
> - {
> - rendstr += '</' + tag + '>';
> - }
> -
> - function staticTag(tag)
> - {
> - rendstr += '<' + tag + '/>';
> - }
> -
> - function staticPair(tag, innerText)
> - {
> - rendstr += '<' + tag + '> ' + innerText + ' </' + tag + '>';
> - }
> -
> - function unmatchedStaticPair(tag1, tag2, innerText)
> - {
> - rendstr += '<' + tag1 + '> ' + innerText + ' </' + tag2 + '>';
> - }
> -
> - var tagstruct = { stack: [], level: 0 };
> -
> - function pushTag(tag)
> - {
> - rendstr += '<' + tag + '>';
> - tagstruct.level+=1;
> - tagstruct.stack.push(tag);
> - }
> - function popTag()
> - {
> - rendstr += '</' + tagstruct.stack.pop() + '>';
> - tagstruct.level-=1;
> - }
> -
> -
> - element =
> element.QueryInterface(Components.interfaces.cellml_apiIUnits);
> - var unitset =
> element.unitCollection.QueryInterface(Components.interfaces.cellml_apiIUnitSet).
> -
> iterateUnits().QueryInterface(Components.interfaces.cellml_apiIUnitIterator);
> - var multiplier = 1, offset = 0;
> - var unitcomp = [];
> - while (true)
> - {
> - var unit = unitset.nextUnit();
> - if (unit == null)
> - break;
> - unit =
> unit.QueryInterface(Components.interfaces.cellml_apiIUnit);
> - multiplier = multiplier * unit.multiplier;
> - offset = offset + unit.offset;
> - var comp = [];
> - comp.name = this.getShortSIName(unit.units);
> - if (comp.name == null)
> - comp.name = unit.units;
> -
> - comp.prefix = this.getShortPrefixSymbol(unit.prefix).str;
> - multiplier *= Math.pow(Math.pow(10,
> this.getShortPrefixSymbol(unit.prefix).mult), unit.exponent);
> -
> - comp.exponent = unit.exponent;
> - unitcomp.push(comp);
> - }
> - var rendstr = '<math
> xmlns="http://www.w3.org/1998/Math/MathML";>';
> - pushTag("mrow");
> - pushTag("apply");
> - staticTag("eq");
> - staticPair("ci", element.name);
> - if (multiplier != 1 || unitcomp.length > 1)
> - {
> - pushTag("apply");
> - staticTag("times");
> - if (multiplier != 1)
> - staticPair("cn", multiplier);
> - }
> - var lvl = tagstruct.level;
> - for (i in unitcomp)
> - {
> - if (unitcomp[i].exponent != 1)
> - {
> - pushTag("apply");
> - staticTag("power");
> - }
> - staticPair("ci", unitcomp[i].prefix + unitcomp[i].name);
> - if (unitcomp[i].exponent != 1)
> - {
> - staticPair("cn", unitcomp[i].exponent);
> - popTag();
> - }
> - }
> - while (tagstruct.level > 0)
> - popTag();
> - rendstr += "</math>";
> - if (window.mathContentToPresentation == null)
> - {
> - window.mathContentToPresentation = new XSLTProcessor();
> - var req =
> Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
> - req.open('GET', 'chrome://pcenv/skin/xsl/mathmlc2p.xsl',
> false);
> - req.send(null);
> -
> window.mathContentToPresentation.importStylesheet(req.responseXML);
> - }
> -
> - //this.removeMathML();
> - //var dtxt = window.bootstrap.serialiseNode(equation);
> - var n = window.domParser.parseFromString(rendstr, "text/xml");
> - var frag = window.mathContentToPresentation.
> - transformToFragment(n, document);
> - var cn = this.mathml.childNodes;
> - var i = 0, l = cn.length;
> - for (; i < l; i++)
> - this.mathml.removeChild(this.mathml.lastChild);
> -
> - this.mathml.appendChild(frag);
> - this.mathml.style.display = "block";
> - ]]></body>
> - </method>
> - <method name="processChange">
> - <parameter name="equation" />
> - <body><![CDATA[
> - if (!window.modelSelector.changeRequested())
> - return;
> - this.isDirty = true;
> - var eq = window.mis.inputFormatToMathML(this.modelDoc,
> this.textrep.value);
> - if (eq.namespaceURI ==
> "http://www.cellml.org/tools/mathml-input/error#";)
> - {
> - var prob = eq.getAttribute("problem");
> - var column = eq.getAttribute("column");
> - Status("Note: " + prob);
> - this.removeMathML();
> - var v = this.textrep.value;
> - var left = v.substr(0, column);
> - var idx =
> left.search(/[^a-z|A-Z|0-9|\.|\_][a-z|A-Z|0-9|\.|\_]*$/);
> - if (idx == -1)
> - idx = 0;
> - else
> - idx++;
> - if (idx == left.length)
> - idx--;
> - if (idx != 0)
> - this.mathml.appendChild(document.createTextNode(
> - left.substr(0, idx)));
> - var div =
> document.createElementNS("http://www.w3.org/1999/xhtml";,
> - "div");
> - div.style.background = "red";
> - div.style.color = "white";
> - div.style.display = "inline";
> - div.appendChild(document.createTextNode(left.substr(idx)));
> - this.mathml.appendChild(div);
> -
> this.mathml.appendChild(document.createTextNode(v.substr(column)));
> - }
> - else
> - {
> - this.populateFromElementInternal(eq);
> - }
> - ]]></body>
> - </method>
> - <method name="getShortSIName">
> - <parameter name="SILong" />
> - <body>
> - var shortByLong = {meter: "m", metre: "m", kilogram: "kg", gram:
> "g",
> - second: "s", litre: "L", liter: "L",
> ampere: "A",
> - kelvin: "K", mole: "mol", candela: "cd",
> radian: "rad",
> - hertz: "Hz", newton: "N", pascal: "Pa",
> joule: "J",
> - watt: "W", coulomb: "C", volt: "V", farad:
> "F", ohm: "?",
> - siemens: "S", weber: "Wb", tesla: "T",
> henry: "H",
> - Celcius: "?C", lumen: "lm", lux: "lux",
> becquerel: "Bq",
> - gray: "Gy", sievert: "Sv", katal: "kat" };
> - if (shortByLong[SILong] != null)
> - return shortByLong[SILong];
> - else
> - return null;
> - </body>
> - </method>
> - <method name="getCanonName">
> - <parameter name="SILong" />
> - <body>
> - if (this.getShortSIName(SILong) != null)
> - return this.getShortSIName(SILong);
> - return SILong;
> - </body>
> - </method>
> - <method name="getShortPrefixSymbol">
> - <parameter name="prefix" />
> - <body><![CDATA[
> - var prefixesByNumber = {"24": "Y", "21": "Z", "18": "E", "15":
> "P",
> - "12": "T", "9": "G", "6": "M", "3": "k",
> "2": "h",
> - "1": "da", "0": "", "-1": "d", "-2": "c",
> - "-3": "m", "-6": "?", "-9": "n", "-12":
> "p",
> - "-15": "f", "-18": "a", "-21": "z",
> "-24": "y" };
> - if (prefixesByNumber[prefix]!=null)
> - return {mult: 0, str: prefixesByNumber[prefix]};
> - if (prefix > 24)
> - {
> - prefix -= 24;
> - return {mult: prefix, str: prefixesByNumber["24"]};
> - }
> - if (prefix < -24)
> - {
> - prefix += 24;
> - return {mult: prefix, str: prefixesByNumber["-24"]};
> - }
> - var mul0 = (prefix % 3) * (Math.abs(prefix) / prefix);
> - var st0 = prefixesByNumber[prefix - mul0];
> - return {mult: mul0, str: st0};
> - ]]></body>
> - </method>
> - <method name="getShortPrefixSymbol2">
> - <parameter name="prefix" />
> - <parameter name="expcorr"/>
> - <body><![CDATA[
> - // This works around CUSES giving back prefixes as raw numbers
> rather than magnitudes
> - // For (10 ^ number) x (unit ^ exp), take number - exp, and then
> take the closest unit.
> - // For the remainder, multiply by 10 ^ exp, and treat that as
> the new multiplier.
> - prefix = -(Math.ceil(Math.log(prefix) / window.log10) / expcorr);
> - var prefixesByNumber = {"24": "Y", "21": "Z", "18": "E", "15":
> "P",
> - "12": "T", "9": "G", "6": "M", "3": "k",
> "2": "h",
> - "1": "da", "0": "", "-1": "d", "-2": "c",
> - "-3": "m", "-6": "?", "-9": "n", "-12":
> "p",
> - "-15": "f", "-18": "a", "-21": "z",
> "-24": "y" };
> - if (prefixesByNumber[prefix]!=null)
> - return {mult: 0, str: prefixesByNumber[prefix]};
> - if (prefix > 24)
> - {
> - prefix -= 24;
> - return {mult: prefix + expcorr, str: prefixesByNumber["24"]};
> - }
> - if (prefix < -24)
> - {
> - prefix += 24;
> - return {mult: prefix + expcorr, str: prefixesByNumber["-24"]};
> - }
> - var mul0 = (prefix % 3) * (Math.abs(prefix) / prefix);
> - var st0 = prefixesByNumber[prefix - mul0];
> - return {mult: mul0 + expcorr, str: st0};
> - ]]></body>
> - </method>
> - </implementation>
> - <content>
> - <xul:vbox flex="1">
> - <xul:box pack="center" align="center" flex="1"
> - style="overflow: auto; width: 0px; height: 0px;">
> - <html:div anonid="mathml"/>
> - </xul:box>
> - </xul:vbox>
> - </content>
> - </binding>
> -</bindings>
>
> Modified: pce/trunk/chrome/content/domain_layouts/electrophysiology.xml
> ===================================================================
> --- pce/trunk/chrome/content/domain_layouts/electrophysiology.xml
> 2008-06-23 00:22:19 UTC (rev 2366)
> +++ pce/trunk/chrome/content/domain_layouts/electrophysiology.xml
> 2008-06-23 03:29:52 UTC (rev 2367)
> @@ -93,7 +93,7 @@
> <xul:deck anonid="editDeck">
> <xul:integrationsettings flex="1" />
> <xul:equationeditor flex="1" />
> - <xul:units_view flex="1" />
> + <xul:rendered_view flex="1" />
> </xul:deck>
> </xul:vbox>
> <xul:splitter anonid="graph_edit_split" collapse="both"/>
>
> Modified: pce/trunk/chrome/skin/pcenv-bindings.css
> ===================================================================
> --- pce/trunk/chrome/skin/pcenv-bindings.css 2008-06-23 00:22:19 UTC (rev
> 2366)
> +++ pce/trunk/chrome/skin/pcenv-bindings.css 2008-06-23 03:29:52 UTC (rev
> 2367)
> @@ -173,8 +173,8 @@
> -moz-binding:
> url(chrome://pcenv/content/controls/equation_editor.xml#editor-binding);
> }
>
> -units_view {
> - -moz-binding:
> url(chrome://pcenv/content/controls/units_view.xml#unit-binding);
> +rendered_view {
> + -moz-binding:
> url(chrome://pcenv/content/controls/rendered_view.xml#rendered-binding);
> }
>
> xmleditor {
>
> _______________________________________________
> automated-notifications mailing list
> automated-notifications at cellml.org
> http://www.cellml.org/mailman/listinfo/automated-notifications
>




  • [cellml-dev] r2367 - in pce/trunk/chrome: content/controls content/domain_layouts skin, Andrew Miller, 06/23/2008

Archive powered by MHonArc 2.6.18.

Top of page