<?xml version="1.0" encoding="UTF-8"?>
<rmml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="L:\collaborative-nir\program\Cscl3DWS\rmml\RMML.xsd">
	<!-- Композиция показывает при перетаскивании формулу молекулы -->
	<composition name="CSplicedView" depth="0" _class="CDraggableComposition">
		<text name="txFormula" enabled="false"/>
		<script src="config.mjs"/>
		<script src="atom.mjs"/>
		<script src="cycle.mjs"/>
		<script src="speccycles.mjs"/>
		<script src="board.mjs"/>
		<script src="visual.mjs"/>
		<script src="relatives.mjs"/>
		<script src="groups.mjs"/>
		<script src="marker.mjs"/>
		<script src="optimization.mjs"/>
		<script src="linkEvents.mjs"/>
		<script>
			this.molecule = null;
			this.countC = 0;
			this.countN = 0;
			this.countO = 0;
			this.countH = 0;

			// Инициализация композиции на основе помеченных атомов молекулы
			function init(amolecule)
			{
				if( this.molecule!=null)
				{
					this.molecule.destroy();
				}
				this.molecule = new CMolecule();
				this.molecule.copyFrom( amolecule);
				this.molecule.markedRoot = amolecule.markedRoot.createdCopy;
				var biggestRoot = this.molecule.getBiggestSubtreeRoot( this.molecule.markedRoot);
				if( biggestRoot == null)
				{
					// ??
				}
				else
				{
trace("biggestRoot="+biggestRoot.type);
					if( biggestRoot == this.molecule.markedRoot.parent)
					{
						var linkType = this.molecule.markedRoot.linkType;
						this.molecule.markedRoot.parent.removeChild( this.molecule.markedRoot);
						this.molecule.calcBottomUp( this.molecule.fwDeleteSubtree);
						this.molecule.markedRoot.linkType = linkType;
					}
					else
					{
						var linkType = biggestRoot.linkType;
						this.molecule.markedRoot.removeChild( biggestRoot);
						this.molecule.calcBottomUp( this.molecule.fwDeleteSubtree, biggestRoot);
						this.molecule.droopTree(this.molecule.markedRoot);
						this.molecule.markedRoot.linkType = linkType;
					}
					this.molecule.root = this.molecule.markedRoot;
				}
				trace("----------------Created molecule IS:----------------");
				this.molecule.calculateDistances();
				this.molecule.print();
				this.calculateCNOH();

			}

			function calculateCNOH()
			{
				this.countC = 0;
				this.countN = 0;
				this.countO = 0;
				this.countH = 0;
				if( this.molecule != null)
				{
					this.molecule.calcTopDown( this.wfCalculateCNOH);
				}
				//this.countH += this.molecule.markedRoot.linkType;

				this.txFormula.value = CMolecule.prototype.getText("C", this.countC);
				this.txFormula.value += CMolecule.prototype.getText("N", this.countN);
				this.txFormula.value += CMolecule.prototype.getText("O", this.countO);
				this.txFormula.value += CMolecule.prototype.getText("H", this.countH);
				this.visible = true;
			}

			function wfCalculateCNOH(atom)
			{
				countC += atom.getElementCount("C");
				countN += atom.getElementCount("N");
				countO += atom.getElementCount("O");
				countH += atom.getElementCount("H");
			}

		</script>
	</composition>
</rmml>