<?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">
	<include src="../resimage.xml"/>
	<include src="../list.xml"/>
	<include src="../buttons.xml"/>
	<include src="../kmbutton.xml"/>
	<include src="../inputValue.xml"/>
	<include src="parser.xml"/>

	<composition name="CMC2DList"  x="800" y="0" depth="0">
		<composition name="imFrame"  class="CResizablePaper">
			<script>
				init("rmeq:environment\\photo\\frame_back.png", 2, 2, 2, 2);
			</script>
		</composition>
		<animation name="animLamp" src="rmgr:molconst2d\mollamp.fln" x="3" y="3" depth="-11" visible="false" loop="true"/>
		<image name="imgTitle" src="rmeq:environment\photo\mollistTitle.png" depth="-10" visible="true">
			<plugin name="dll" src="rmeq:dlls\chem3drnd.dll" uid="mmlabSnapshotPlugin"/>
		</image>
		<image name="imgBottom" src="rmeq:environment\photo\photolist2.png" depth="-10" visible="true" y="590"/>
		<styles _name="stlFotoTxt" fontSize="14" fontFamily="Microsoft Sans Serif" textAlign="justify" color="#000000"/>
		<composition class="CMCParser" name="parser"/>
		<composition name="list" class="CScrolledList" userProperties="lines=false" y="46">
			<script>
				this.nextId = 0;
			</script>

			<script event="evItemAdd">
				this.nextId += 1;
			</script>

			<image name="img1" src="eval(ENVRPATH+'viewporthint.png')" visible="false">
			<script>
					this.width = 150;
					this.height = 150;
				</script>
			</image>
			<image name="maskIm" src="rmeq:environment\photo\frame_back.png" visible="false">
				<script>
					this.width = 210;
					this.height = 544;
				</script>
				<script event="onPress">
					trace("event=onPress");
				</script>
			</image>
			<script>
				this.showTree();
				this.createScroller(maskIm);
				this.setTab(0);
				this.setSpace(-10);
				setStringInterval(25);
				this.maskIm.enabled=false;
			</script>
		</composition>

		<composition name="item" visible="false">
			<script><![CDATA[
				this.w = 177;
				this.h = 133;
				this.molecule = null;
				this.molSrc = "";
				this.fileName = "";
				this.textPhotoItems = new Array();
				this.previewPhotoItem = null;

				function addTextPhotoItem(aPhotoItem)
				{
					this.textPhotoItems.push( aPhotoItem);
				}

				function add3DPhotoItem( aPhotoItem)
				{
					this.previewPhotoItem = aPhotoItem;
				}

				function getSecondaryTop()
				{
					return this.im3D.height + this.imMolecule.getMediaSize().height + 2;
				}

				function loadMolecule( aparser, asrc)
				{
					if( this.molecule != null)
					{
						this.molecule.destroy();
						this.molecule = null;
					}
					this.fileName = asrc;
					aparser.xmlEngine.src=asrc + ".xml";
					this.molecule = aparser.load();
					if( molecule != null)
					{
						this.imMolecule.src = asrc + ".png";
						this.im3D.src = asrc + "_p.png";
						this.im3D.width = 200;
						this.im3D.height = 150;
						if( this.molecule.name == "")
							this.molecule.name = "Введите название";
						this.txName.value = this.molecule.name;
						//trace("#FF0000 this.molecule.name="+this.molecule.name);
					}
				}

				function checkLayout(aInitialization)
				{
					var top = this.getSecondaryTop();
					this.imMolecule.y = this.im3D.height;
					this.btnImport.x = -3;
					this.btnImport.y = top;
					this.btnView3D.x = this.btnImport.x + this.btnImport.width;
					this.btnView3D.y = top;
					this.animPhoto.x = 4;
					this.animPhoto.y = top - this.animPhoto.getMediaSize().height - 4 - this.imMolecule.getMediaSize().height;
					showInput();
					if( aInitialization)
						onInputEnd();
				}

				function showInput()
				{
					this.txName.hide();
					var top = this.getSecondaryTop();
					this.cmInput.show( '', this.btnView3D.x + this.btnView3D.width + 5, top, 127, 17);
					this.cmInput.iptValue.value = this.txName.value;
					//trace("this.txName.value="+this.txName.value);
				}

				function onOkInput(bUpdateFile)
				{
					if( this.molecule != null)
					{
						this.molecule.name = this.cmInput.iptValue.value;
					}
					if( this.textPhotoItems.length != 0)
					{
						for( var i=0; i<this.textPhotoItems.length; i++)
							if( this.textPhotoItems[i] != null)
								this.textPhotoItems[i].item.setPhotoCaption(this.cmInput.iptValue.value);
					}
					updateFile();
					onInputEnd();
				}

				function onCancelInput()
				{
					if( this.molecule != null)
					{
						this.txName.value = this.molecule.name;
					}
					onInputEnd();
				}

				function onInputEnd()
				{
					this.txName.x = this.cmInput.x;
					this.txName.y = this.cmInput.y;
					if( this.molecule != null)
					{
						this.txName.value = this.molecule.name;
					}
					this.txName.show();
					this.cmInput.hide();
				}

				function onImport()
				{
					var molecule = scene.mcEditor.loadMolecule( this.fileName + ".xml");
					scene.mcEditor.placeOnFreePlace(molecule.board);
				}

				function onView3D()
				{
					if( typeof(scene.show3DView) == "function" && this.molecule!=null)
					{
						this.molecule.isShowH = scene.mcEditor.showH;
						scene.show3DView( this.molecule.getXML(), this.molecule.toString());
					}
				}

				function updateFile()
				{
					if( this.molecule != null)
						scene.molList.imgTitle.dll.call( '', 'saveText', this.fileName+".xml" + '|' + this.molecule.getIsomerXML());
				}
			]]></script>
			<animation name="animPhoto" src="rmgr:molconst2d/cam.fln" depth="-1" loop="true">
				<script event="onPress">
trace("1");
					this.rewindAndPlay();
trace("2");
					this.parent.seqPhoto.rewindAndPlay();
trace("3");
					this.parent.onView3D();
trace("4");
					var snapArray = new Array();
						snapArray.push( scene.wnd3D.wndView);
						snapArray.push( scene.wnd3D.wndFrame);
trace("5");
					var tmp_preview_path = this.parent.fileName + "_p.png";
					scene.photocamera.cameye.imFilm.makeSnapshot(snapArray);
trace("6");
					scene.photocamera.cameye.imFilm.setAutoUpdatePhotolist(false);
trace("7");
					scene.photocamera.cameye.imFilm.saveAs(tmp_preview_path);
trace("tmp_preview_path="+tmp_preview_path);
					scene.photocamera.cameye.imFilm.setAutoUpdatePhotolist(true);
					if( this.parent.previewPhotoItem != null)
					{
						this.parent.previewPhotoItem.item.photo.src = ":" + tmp_preview_path;
					}
					this.parent.im3D.src = tmp_preview_path;
				</script>
			</animation>
			<image name="im3D" />
			<image name="imMolecule" />
			<composition name="btnImport" class="CKMButton" x="0" y="0" depth="-2">
				<script>
					this.checkButton=false;
				</script>
				<image _name="img" src="rmgr:molconst2d/btnImport.png"/>
				<script event="onClick">
					this.parent.onImport();
				</script>
			</composition>
			<composition name="btnView3D" class="CKMButton" x="0" y="0" depth="-2">
				<script>
					this.checkButton=false;
				</script>
				<image _name="img" src="rmgr:molconst2d/btnView3D.png"/>
				<script event="onClick">
					this.parent.onView3D();
				</script>
				<script>
/*					trace("1"+this.enabled);
					trace("2"+this.parent.enabled);
					trace("3"+this.parent.parent.enabled);
					trace("4"+this.parent.parent.parent.enabled);
					trace("5"+this.parent.parent.parent.parent.enabled);
					trace("6"+this.parent.parent.parent.parent.parent.enabled+":"+this.parent.parent.parent.parent.parent.name);
					trace("7"+this.parent.parent.parent.parent.parent.parent.enabled);*/
				</script>
			</composition>
			<composition name="cmInput" class="CInputValue" x="0" y="0" visible="false" depth="-2">
				<composition name="cmFrame">
					<script>
						this.resBase = "rmgr:molconst2d/";
						this.init("Select.png", 14, 7);
					</script>
				</composition>
				<script event="onOK">
					this.parent.onOkInput();
					this.parent.txName.value = this.iptValue.value;
				</script>
				<script event="onCancel">
					this.parent.onCancelInput();
				</script>
			</composition>
			<styles name="stlID" fontSize="14"  fontFamily="Arial"  textAlign="center" color="#000000" fontWeight="bold"/>
			<text name="txName" style="parent.stlID" value="_">
				<script>
					this.prevValue = "";
				</script>
				<script event="onPress">
					this.prevValue = this.value;
					this.parent.showInput();
				</script>
			</text>
			<sequencer name="seqPhoto">
				<script>
					500;
				</script>
				<script>
					this.animPhoto.stop();
					this.animPhoto.rewind();
				</script>
			</sequencer>
		</composition>

		<script><![CDATA[
			this.initialization=false;
			function loadMolecules(src, id)
			{
				this.initialization=true;
				var i=id;
				source = src + "isomer" + i + ".xml";
				while (resourceExists(source))
				{
					addIsomer(src, i);
					//
					i++;
					source = src + "isomer" + i + ".xml";
				}
				this.initialization=false;
			}

			function addIsomer(path, num)
			{
				var fileName = path + "isomer" + num;
				if (list.nextId < 100)
				{
					this.list.root.enabled = true;
					list.addItem(this.list.root,"r" + this.list.nextId, item);
					var content = list.root.children[this.list.nextId-1].content;
					content.onPress = null;
					content.item.loadMolecule( this.parser, fileName);
					content.item.checkLayout(this.initialization);
					list.resetScrollers();
					list.showTree();

					list.scrollerV.setClientPos(list.scrollerV.scrollMax);
					list.scrollerV.setSliderPos(1);

					var content = list.root.children[this.list.nextId-1].content;
					if( content != null && content.item.molecule!=null)
					{
						scene.photoList.addPhoto(path + "isomer" + num + "_p.png", content.item.molecule.name, false);
						var	photoContent = scene.photoList.list.root.children[scene.photoList.list.nextId-1].content;
						content.item.addTextPhotoItem( photoContent);
						content.item.add3DPhotoItem( photoContent);
						scene.photoList.addPhoto(path + "isomer" + num + ".png", content.item.molecule.name, true);
						photoContent = scene.photoList.list.root.children[scene.photoList.list.nextId-1].content;
						content.item.addTextPhotoItem( photoContent);
					}
					else
					{
						scene.photoList.addPhoto(path + "isomer" + num + "_p.png", "", false);
						scene.photoList.addPhoto(path + "isomer" + num + ".png", "", true);
					}

					return true;
				}
				return false;
			}

			function highlight(val)
			{
				if( val == this.animLamp.playing)	return;
				if( val)
				{
					animLamp.rewindAndPlay();
					animLamp.visible=true;
				}
				else
				{
					animLamp.stop();
					animLamp.rewind();
					animLamp.visible=false;
				}
			}

			function isMouseOn()
			{
				return false;
			}
		]]></script>
		<script>
			this.imFrame.resize(224, 600);


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