<?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">
	<define name="KMRESPATH" value="':mmlab.chemcommon.resources.graphics:/molconst/'"/>

	<include src="consts.xml"/>
	<include src="window.xml"/>
	<include src="buttons.xml"/>
	<include src="frames.xml"/>
	<include src="molconst/mcbase.xml"/>
	<include src="imhint.xml"/>

	<composition name="CMolViewerIcon" class="CSkinedButton">
		<image name="imSkin"  src="rmgr:molViewer/icon.png"/>
		<script>
			this.init(3);
		</script>
	</composition>


	<composition name="CMoleculeViewerWindow" class="CBaseWindow">
		<script>
			this.useOnlyClientArea = true;
		</script>
		<styles _name="stlCap" fontSize="16"  fontFamily="Arial"  textAlign="center" color="#25527C"/>
		<styles _name="stlTitle" fontSize="15"  fontFamily="Arial"  textAlign="center" color="#25527C"/>
		<image name="hint" src=":rmgr:molViewer/annotation.png" depth="-2"/>
		<composition name="imTop">
			<script>
				this.init("rmgr:molViewer/window/top.png", 3,3,22,2);
			</script>
		</composition>
		<composition name="imFrame" _y="21">
			<script>
				this.init("rmgr:molViewer/window/frame.png", 2,2,2,2);
			</script>
		</composition>
		<composition _name="btClose"  _y="3" _depth="-1">
				<script>
					this.imCount = 3;
					this.checkButton = false;
					updateButtonImage();
				</script>
			<image name="img" src="rmgr:molViewer/window/btClose.png"/>
		</composition>
		<image name="img" src="eval(KMRESPATH+'_back3d.png')"  class="CBaseMCImage" depth="-1"/>
		<viewport _name="vport" depth="-1" enabled="false"/>

		<composition name="frame">
			<composition name="imFrame" class="CResizablePaper">
				<script>
					this.init("rmgr:molViewer/bckgr_mol.png", 2, 2, 2, 2);
				</script>
			</composition>
		</composition>

		<script>
			function setCaptionStyle(stl)
			{
				this.txtTitle.style = stl;
			}
		</script>
		<script>
			function resize(w, h)
			{
				this.imFrame.resize(w, h);
				this.imTop.resize(w, 23);
				this.hsA01.hitArea = "[0,0," + w + ",23]";
				this.btClose._x = w - 19;

				this.hint.y = h-33+23-2;
				this.hint.x = (this.getWidth() - this.hint.width)/2+5;
			}
		</script>
		<script>
			function setScenePos(x,y,w,h)
			{
				this.frame.x = x;
				this.frame.y = y;
				this.frame.imFrame.resize(w, h);
				this.vport.x = x+1;
				this.vport.y = y+1;
				this.vport.width = w-2;
				this.vport.height = h-2;
				this.img.x = x;
				this.img.y = y;
				this.img.width = w;
				this.img.height = h;
			}
		</script>
		<script>
			function createAtomScene(id)
			{
				var scn = new Scene3D();
				scn._class = "CAtomScene";
				scn.parent = scene;
				if (id == null || id == undefined)
					scn.name = "atom_scene";
				else
					scn.name = "atom_scene" + id;

				this.img.myPlugin = scn.molconst.dll;
				this.img.enabled=true;
				this.vport.camera = scn.main_camera;
			}
			this.close();
		</script>
	</composition>

	<composition name="CMoleculeViewerSkelWindow" class="CMoleculeViewerWindow">
		<viewport _name="vport" depth="-3"/>
		<image  name="myimg" src="eval(KMRESPATH+'back3d.png')"  depth="-2" x="2" y="22">
			<script>
				this.drag = false;
				this.dragPoint = new Position3D();
				this.pickedObject = null;
			</script>
			<script event="onPress">
				this.drag = true;
				this.dragPoint.x = scene.xMouse;
				this.dragPoint.y = scene.yMouse;
			</script>

			<script event="onRelease">
				this.drag = false;
			</script>

			<script event="onMouseMove"><![CDATA[
				if( this.pickedObject != null && this.drag == true )
				{
					dx = scene.xMouse - this.dragPoint.x;
					dy = scene.yMouse - this.dragPoint.y;
					var rtnX = new Rotation3D(0,0,1,-dx);
					var rtnY = new Rotation3D(1,0,0,-dy);
					this.pickedObject.rotation.mult(rtnX);
					this.pickedObject.rotation.mult(rtnY);

					this.dragPoint.x = scene.xMouse;
					this.dragPoint.y = scene.yMouse;
				}
			]]></script>

		</image>

		<script>
			function resize(w, h)
			{
				this.myimg.width = w-4;
				this.myimg.height = h-4;
				CMoleculeViewerWindow_resize(w, h);
			}

			function createAtomScene(id)
			{
				CMoleculeViewerWindow_createAtomScene(id);

				var scn;
				if (id == null || id == undefined)
					scn = eval("scene.atom_scene");
				else
					scn = eval("scene.atom_scene" + id);

				var obj = new Object3D;
				obj.parent = scn;
				obj.src = this.parent.srcname;

				obj.scale.x = 0.5;
				obj.scale.y = 0.5;
				obj.scale.z = 0.5;

				this.myimg.pickedObject = obj;
			}
		</script>

	</composition>

	<composition name="CMoleculeViewer" depth="-500">
		<script><![CDATA[
				this.id = null;
				// Отложенная загрузка
				this.delayedInitialization = true;//*/false;
				this.isInitialized = false;
				this.ipSrc = null;
				this.ipW = null;
				this.ipH = null;
				this.ipID = null;
				this.myWindow = null;
				this.windowClassName = "CMoleculeViewerWindow";

				function showDialog()
				{
					this.initializeIfNeeded();
					this.myWindow.showDialog();
				}

				function setTarget(item)
				{
					item.onPress=function()
					{
						showDialog();
					}
				}

				function initializeIfNeeded()
				{
					if( this.isInitialized == true)	return;
					this.isInitialized = true;
					this.myWindow = new Composition();
					this.myWindow._class = this.windowClassName;
					this.myWindow.parent = this;

					this.myWindow.setTitle(this.ipTitle);
					this.myWindow.setCaptionStyle(this.myWindow.stlCap);

					createAtomScene(this.ipID);
					this.setScenePos(2, 21, this.ipW-4, this.ipH-2);
					this.rendllmes("freeze", "", this.ipID);
					this.rendllmes("loadxml", this.ipSrc, this.ipID);
					this.rendllmes("fitnow", "", this.ipID);

					this.myWindow.resize(this.ipW,this.ipH);

					this.myWindow.x=(1024-this.myWindow.getWidth())/2;
					this.myWindow.y=(600-this.myWindow.getHeight())/2;
				}

				function initialize(src, w ,h, id, icon, title)
				{
					this.id=id;

					this.ipSrc = src;
					this.ipW = w;
					this.ipH = h;
					this.ipID = id;
					this.ipTitle = title;
					if( !this.delayedInitialization)
					{
						this.initializeIfNeeded();
					}

					if (icon !=undefined && icon !=null)
					{
						setTarget(icon);
					}
				}

				function setScenePos(x,y,w,h)
				{
					if( this.myWindow != null)
						this.myWindow.setScenePos(x,y,w,h);
				}

				function rendllmes(message, params, id)
				{
					this.initializeIfNeeded();
					var scn;
					if (id == null || id == undefined)
						scn = scene.atom_scene
					else
						scn = eval("scene.atom_scene" +id);
					scn.molconst.dll.call("", ""+message, ""+params);
				}

				function createAtomScene(id)
				{
					if( this.myWindow != null)
						this.myWindow.createAtomScene(id);
				}
		]]></script>
		</composition>
</rmml>