<?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="parser.xml"/>
	<include src="../molconst/toolbar.xml"/>
	<include src="../dragcomp.xml"/>
	<include src="../resimage.xml"/>
	<include src="../imhint.xml"/>
	<include src="../select.xml"/>
	<include src="board.xml"/>
	<include src="tableelem.xml"/>
	<include src="cycleelem.xml"/>
	<include src="linkelem.xml"/>
	<include src="trash.xml"/>

	<composition name="CMolViewerBack" class="CResizablePaper">
		<image _name="lt" src="rmgr:molconst2d/bckgr_mol.png">
			<script>this.crop(0,0,2,2);</script>
		</image>
		<image _name="ct" src="rmgr:molconst2d/bckgr_mol.png">
			<script>this.crop(2,0,1,2);</script>
		</image>
		<image _name="rt" src="rmgr:molconst2d/bckgr_mol.png">
			<script>this.crop(3,0,2,2);</script>
		</image>
		<image _name="lc" src="rmgr:molconst2d/bckgr_mol.png">
			<script>this.crop(0,2,2,1);</script>
		</image>
		<image _name="cc" src="rmgr:molconst2d/bckgr_mol.png">
			<script>this.crop(2,2,1,1);</script>
		</image>
		<image _name="rc" src="rmgr:molconst2d/bckgr_mol.png">
			<script>this.crop(3,2,2,1);</script>
		</image>
		<image _name="lb" src="rmgr:molconst2d/bckgr_mol.png">
			<script>this.crop(0,3,2,2);</script>
		</image>
		<image _name="cb" src="rmgr:molconst2d/bckgr_mol.png">
			<script>this.crop(2,3,1,2);</script>
		</image>
		<image _name="rb" src="rmgr:molconst2d/bckgr_mol.png">
			<script>this.crop(3,3,2,2);</script>
		</image>
	</composition>

	<composition name="CMCSelection" class="cVSelection">
		<text _name="pathStub" value="rmgr:molconst2d/"/>
		<image _name="imBCK" src="rmgr:molconst2d/select/imBCK.png"/>
		<image _name="imSelBck" src="rmgr:molconst2d/select/imSelBck.png"/>

		<image _name="imLUC" src="_rmgr:molconst2d/select/imLUC.png"/>
		<image _name="imRUC" src="_rmgr:molconst2d/select/imRUC.png"/>
		<image _name="imLDC" src="_rmgr:molconst2d/select/imLDC.png"/>
		<image _name="imRDC" src="_rmgr:molconst2d/select/imRDC.png"/>
		<image _name="imRDC" src="_rmgr:molconst2d/select/imRDC.png"/>

		<image _name="imTop" src="rmgr:molconst2d/select/point.png" _depth="-101"/>
		<image _name="imBot" src="rmgr:molconst2d/select/point.png" _depth="-101"/>
		<image _name="imLeft" src="rmgr:molconst2d/select/point.png" _depth="-101"/>
		<image _name="imRight" src="rmgr:molconst2d/select/point.png" _depth="-101"/>

		<script><![CDATA[
			this.szSMrgsW = 1;
			this.szSMrgsH = 2;
			this.szIMrgsW=1;
			this.szIMrgsH=1;
			this.iLThck=0;
			this.szSBLMrgsH=0;
			function AddItems()
			{
				cSelection_AddItems();
				if( imBot.width!=0 && imBot.height!=0)
				{
					imLUC.hide();imRUC.hide();imLDC.hide();imRDC.hide();imRDC.hide();
					imTop.width = imBCK.width;
					imBot.width = imBCK.width;	imBot.y = imBCK.height - imBot.height;
					imLeft.height = imBCK.height;
					imRight.height = imBCK.height;	imRight.x = imBCK.width - imRight.width;
				}
			}
		]]></script>
	</composition>

	<!-- Шаблон текста названий атомов -->
	<text name="CMC2Text" style="parent.stlNormal">
		<script>
			this.atom=null;
		</script>
		<script event="onRollOver">
			this.atom.handleOnTextRollOver();
		</script>
		<script event="onRollOut">
			this.atom.handleOnTextRollOut();
		</script>
		<script event="onPress">
			this.atom.handleOnPress();
		</script>
		<script event="onRelease">
			this.atom.handleOnRelease();
		</script>
		<script event="onReleaseOutside">
			this.atom.handleOnRelease();
		</script>
		<script event="onRMouseDown">
			if( Mouse.target == this)
			{
				this.atom.handleOnRButtonDown();
			}
		</script>
	</text>

	<image name="CMC2Image">
		<script>
			this.isHighlighted=false;
			this.cropWidth=this.getMediaSize().width/2;
			this.cropHeight=this.getMediaSize().height;

			function cropMe()
			{
				var sw = this.getMediaSize().width/2;
				var h = this.getMediaSize().height;
				if( this.isHighlighted)
					this.crop(sw, 0, sw, h);
				else
					this.crop(0, 0, sw, h);

				this.width = this.cropWidth;
				this.height = this.cropHeight;
			}

			function setCropWidth(val)
			{
				this.cropWidth = val;
			}

			function setCropHeight(val)
			{
//trace("YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY");
//trace("setCropHeight="+val);
				this.cropHeight = val;
			}

			function setSrc(val)
			{
				if( this.src != val)
					this.src = val;
				this.setCropWidth(this.getMediaSize().width/2);
				this.setCropHeight(this.getMediaSize().height);
			}
		</script>
		<script event="onLoad">
			this.cropWidth=this.getMediaSize().width/2;
			this.cropHeight=this.getMediaSize().height;
			this.cropMe();
		</script>
		<script event="onRollOver">
			this.isHighlighted=true;
			this.cropMe();
			this.atom.handleOnLinkRollOver();
		</script>
		<script event="onRollOut">
			this.isHighlighted=false;
			this.cropMe();
			this.atom.handleOnLinkRollOut();
		</script>
		<script event="onRMouseDown">
			if( this.isHighlighted)
			{
				this.atom.handleOnLinkRButtonDown();
			}
		</script>
		<script event="onPress">
			this.atom.handleLinkPress();
		</script>
		<script event="onRelease">
			this.atom.handleLinkRelease();
		</script>
		<script event="onReleaseOutside">
			this.atom.handleLinkRelease();
		</script>
	</image>

	<!-- Рабочая область 2Dконструктора -->
	<composition name="CMCWorkspace2D">
		<script>
			// Массив ссылок на конструируемые молекулы
			this.molecules = new Array();
			// Массив ссылок на доступные для добавления элементы
			this.elements = new Array();
			// Массив ссылок на доступные для добавления связи
			this.links = new Array();
			// Режим работы
			this.mode="add";	// "select", "delete"
			// Атом для которого показывается selection
			this.selectionAtom=null;
			//
			// "moveMolecule" - перетаскивание молекулы по рабочему полю
			// "sliceMolecule" - перетаскивание части молекулы
			// "pressedOnAtom" - нажали на атом, но еще не потащили
			this.mouseOperation="";
			this.mouseTarget=null;
			// Атом под курсором
			this.highlightedAtom=null;
			// Тип активного элемента
			this.activeElement = "C";
		</script>
		<script src="config.mjs"/>
		<script src="atom.mjs"/>
		<script src="cycle.mjs"/>
		<script src="speccycles.mjs"/>
		<script src="board.mjs"/>
		<script src="relatives.mjs"/>
		<script src="groups.mjs"/>
		<script src="visual.mjs"/>
		<script src="marker.mjs"/>
		<script src="optimization.mjs"/>
		<script src="linkEvents.mjs"/>

		<composition name="selAtoms" class="CMCSelection" y="300" x="0" visible="false">
			<image	name="item0"	src="rmgr:molconst2d/btnH.png" enabled="false"/>
			<image	name="item1"	src="rmgr:molconst2d/btnC.png" enabled="false"/>
			<image	name="item2"	src="rmgr:molconst2d/btnN.png" enabled="false"/>
			<image	name="item3"	src="rmgr:molconst2d/btnO.png" enabled="false"/>
			<image	name="item4"	src="rmgr:molconst2d/btnRotate.png" enabled="false"/>
			<script><![CDATA[
				this.autoHide = true;
				this.item0.value = "H";
				this.item1.value = "C";
				this.item2.value = "N";
				this.item3.value = "O";
				this.Add( new Array( this.item0,this.item1,this.item2,this.item3,this.item4));
				function onSelected(id, item)
				{
					if( this.parent.selectionAtom == null)	return;
					if( id < 4)
					{
						// тип элемента
						this.parent.selectionAtom.setType( item.value);
					}
					else	if( item.name == "item4")
					{
						// поворот
						this.parent.selectionAtom.flip();
					}
					this.parent.onAtomSelectionDone();
				}
			]]></script>
		</composition>

		<composition name="selLinks" class="CMCSelection" y="300" x="300" visible="false">
			<image	name="item1"	src="rmgr:molconst2d/link1.png" enabled="false"/>
			<image	name="item2"	src="rmgr:molconst2d/link2.png" enabled="false"/>
			<image	name="item3"	src="rmgr:molconst2d/link3.png" enabled="false"/>
			<script><![CDATA[
				this.autoHide = true;
				this.Add( new Array( this.item1, this.item2, this.item3));
				function onSelected(id, item)
				{
					if( this.parent.selectionAtom == null)	return;
					if( id < 3)	// это ссылки
					{
						this.parent.selectionAtom.setLink( id+1);
					}
					this.parent.onLinkSelectionDone();
				}
			]]></script>
		</composition>

		<composition name="selCycles" class="CMCSelection" y="140" x="110" visible="false">
			<image	name="item1"	src="rmgr:molconst2d/btnC3.png" enabled="false"/>
			<image	name="item2"	src="rmgr:molconst2d/btnC4.png" enabled="false"/>
			<image	name="item3"	src="rmgr:molconst2d/btnC5.png" enabled="false"/>
			<image	name="item4"	src="rmgr:molconst2d/btnC6.png" enabled="false"/>
			<script><![CDATA[
				this.autoHide = true;
				this.item1.value = "C:3";
				this.item2.value = "C:4";
				this.item3.value = "C:5";
				this.item4.value = "C:6";
				this.Add( new Array( this.item1,this.item2,this.item3,this.item4));
				function onSelected(id, item)
				{
					this.parent.elementsToolbar.elemCycles.setType( id + 3);
					this.parent.setActiveElement( item.value);
					this.hide();
				}
			]]></script>
		</composition>

		<composition name="selGroups" class="CMCSelection" y="170" x="110" visible="false">
			<image	name="item1"	src="rmgr:molconst2d/btnGroups1.png" enabled="false"/>
			<image	name="item2"	src="rmgr:molconst2d/btnGroups2.png" enabled="false"/>
			<image	name="item3"	src="rmgr:molconst2d/btnGroups3.png" enabled="false"/>
			<image	name="item4"	src="rmgr:molconst2d/btnGroups4.png" enabled="false"/>
			<image	name="item5"	src="rmgr:molconst2d/btnGroups5.png" enabled="false"/>
			<image	name="item6"	src="rmgr:molconst2d/btnGroups6.png" enabled="false"/>
			<image	name="item7"	src="rmgr:molconst2d/btnGroups7.png" enabled="false"/>
			<script><![CDATA[
				this.autoHide = true;
				this.item1.value = gpGroup1;
				this.item2.value = gpGroup2;
				this.item3.value = gpGroup3;
				this.item4.value = gpGroup4;
				this.item5.value = gpGroup5;
				this.item6.value = gpGroup6;
				this.item7.value = gpGroup7;
				this.Add( new Array( this.item1,this.item2,this.item3,this.item4,this.item5,this.item6,this.item7));
				function onSelected(id, item)
				{
trace("ID="+id);
					//this.parent.elementsToolbar.elemGroups.setType( eval("gpGroup"+(id+1)));
					this.parent.elementsToolbar.elemGroups.setType( id+1);
					this.parent.setActiveElement( item.value);
					this.hide();
				}
			]]></script>
		</composition>

		<!--Класс чтения молекул из файла-->
		<composition class="CMCParser" name="parser"/>
		<composition class="CMCTrash" name="trash" x="65" y="494">
			<script event="onRollOver">
				if( this.parent.mouseOperation=="sliceMolecule" || this.parent.mouseOperation=="moveMolecule")
				{
					this.activate( true);
				}
			</script>
			<script event="onRollOut">
				this.activate( false);
			</script>
		</composition>
		<script>
			this.sceneBounds = new Object;
				sceneBounds.left = 125;
				sceneBounds.top = 47;
				sceneBounds.right = 1010;
				sceneBounds.bottom = 553;

			this.listBounds = new Object;
				listBounds.left = 805;
				listBounds.top = 65;
				listBounds.right = 1007;
				listBounds.bottom = 595;

			this.showH = false;
		</script>

		<image name="whiteBack" src="rmgr:molconst2d/whiteBg.png">
			<script event="onPress">
				this.parent.createNewMolecule(scene.xMouse+22, scene.yMouse+scene.y+2);
			</script>
		</image>


		<script><![CDATA[
			this.whiteBack.x = sceneBounds.left - 4;
			this.whiteBack.y = 1;
			this.whiteBack.width = 675;
			this.whiteBack.height = 508;

			function loadMoleculeFromString(asMolecule)
			{
				var fileName = scene.molList.imgTitle.tempDir + "chemTemp.xml";
				scene.molList.imgTitle.dll.call( '', 'saveText', fileName + '|' + asMolecule);
				this.parser.xmlEngine.src=fileName;
				var molecule = this.parser.load();
				return molecule;
			}

			function loadMolecule(asrc)
			{
				this.parser.xmlEngine.src=asrc;
				var molecule = this.parser.load();
				if( molecule != null)
				{
					this.addMolecule(molecule);
				}
				return molecule;
			}

			function addMolecule(molecule)
			{
				if( molecule==null)
				{
					trace("mc2d addMolecule error: molecule is null");
					return null;
				}
				var virtBoard = new Composition();
				virtBoard._class="CMCBoard";
				virtBoard.depth=-2;
				virtBoard.parent = this;

				virtBoard.x = 0;
				virtBoard.y = 0;
				virtBoard.setMolecule( molecule);
				virtBoard.showH(this.showH);
				molecule.create();
				this.molecules.push(virtBoard);
				return virtBoard;
			}

			function setActiveElement(type)
			{
trace("setActiveElement="+type);
				this.activeElement=type;
			}

			// Перетаскивание объектов
			this.draggedElement = null;
			this.underMouseMolecule = null;
			function handleDragElementPress( obj)
			{
				if( obj==null)	return;
				this.draggedElement = obj;
			}
			function handleDragElementRelease( obj)
			{
				if( obj==null)	return;
				if( !isMouseOn() || (scene.xMouse > this.listBounds.left))	return;
				trace("handleDragElementRelease");
				trace("obj.xy="+obj.x+","+obj.y);
				this.draggedElement = null;
				// 1. Находимся на атоме -> добавим к нему
				// 2. Находимся на свободном месте -> создадим новую молекулу

trace( "this.highlightedAtom="+this.highlightedAtom);
				if( this.highlightedAtom != null)
				{
					this.highlightedAtom.molecule.addElement( this.highlightedAtom, this.activeElement);
				}
				else
				{
					var objXY = obj.dragElement.localToGlobal(0, 0);
					createNewMolecule(objXY.x, objXY.y);
				}
			}
			// Создает новую молекулу
			function createNewMolecule(ax, ay)
			{
trace("#FF0080 this.activeElement="+this.activeElement);
				var molecule = new CMolecule();
				this.addMolecule(molecule);
				molecule.addElement( null, this.activeElement);
				trace("Root is=" + molecule.root + ":" + molecule.root.oText);
				if( molecule.root!=null && molecule.root.oText!=null)
				{
					var textXY = molecule.root.oText.localToGlobal(0, 0);

trace("textXY="+molecule.root.oText.x+","+molecule.root.oText.y);
trace("textXY="+textXY.x+","+textXY.y);

					molecule.board.x += (ax - textXY.x - 24);
					molecule.board.y += (ay - textXY.y - 22);
				}
trace("textXY="+molecule.board.x+","+molecule.board.y);
			}
			// Обработка переноса связей
			function handleDragLinkPress( obj)
			{
			}

			function handleDragLinkRelease( obj)
			{
				var i=0;
				var elem = null;
				for( ; i<this.molecules.length; i++)
				{
					if( this.molecules[i].isMouseOn())
					{
						elem = this.molecules[i].molecule.getAtomUnderMouse();
						if( elem != null)
						{
							break;
						}
					}
				}
				trace("elem="+elem);
				if( elem != null)
				{
					elem.setLink( obj.linkType);
				}
			}

			function isMouseOn()
			{
				var mx = scene.xMouse;
				var my = scene.yMouse;
				var border=3;
				if( (mx>this.sceneBounds.left+border) && (mx<this.sceneBounds.right-border) &&
					(my>this.sceneBounds.top+border) && (my<this.sceneBounds.bottom-border))
					return true;
				return false;
			}

			function isBoardOnWorkspace( board)
			{
				var screenBounds = board.molecule.getScreenBounds();
				var lt = board.localToGlobal(screenBounds.left, screenBounds.top);
				var rb = board.localToGlobal(screenBounds.right, screenBounds.bottom);
				lt.x -= scene.x;	lt.y -= scene.y;
				rb.x -= scene.x;	rb.y -= scene.y;
				// Проверим на пересечение зоны молекулы и зоны списка
				if( (lt.x>=this.sceneBounds.left &&
						rb.x<=this.listBounds.left &&
						lt.y>=this.sceneBounds.top &&
						rb.y<=this.sceneBounds.bottom))
				{
//trace(lt.x+","+lt.y+","+rb.x+","+rb.y);
//trace(this.sceneBounds.left+","+this.sceneBounds.top+","+this.sceneBounds.right+","+this.sceneBounds.bottom);
//trace("||||||||||| true");
					return true;
				}
//trace("||||||||||| false");
				return false;
			}

			function isBoardOnMolList( board)
			{
				var screenBounds = board.molecule.getScreenBounds();
				var lt = board.localToGlobal(screenBounds.left, screenBounds.top);
				var rb = board.localToGlobal(screenBounds.right, screenBounds.bottom);
				lt.x -= scene.x;	lt.y -= scene.y;
				rb.x -= scene.x;	rb.y -= scene.y;
				// Проверим на пересечение зоны молекулы и зоны списка
				if( !(lt.x>this.listBounds.right ||
						rb.x<this.listBounds.left ||
						lt.y>this.listBounds.bottom ||
						rb.y<this.listBounds.top))
				{
					return true;
				}
				return false;
			}

			function onBoardEndDrag( board)
			{
				if( typeof( scene.molList) == "undefined")
				{
					trace("mc2d onBoardEndDrag error: molList is undefined");
					return;
				}
				scene.molList.highlight( false);
				if( this.isBoardOnMolList(board))
				{
					this.exportBoard( board);
				}
				else
				{
					//trace("---------- 3");
				}
				//trace("---------- 4");
			}

			function exportBoard(board)
			{
				trace("---------- 1");
				var fileName = saveMolecule(board);
				trace("---------- 3");
				var base_path = scene.molList.imgTitle.tempDir + Player.module.identifier.replace( /:/g, '_');
				if( scene.molList.addIsomer( base_path + "\\", fileName))
				{
					trace("---------- 2");
					this.removeBoard( board);
				}
				else
				{
					//??
				}
			}

			function saveMolecule(board)
			{
				if( typeof(scene.molList)=="undefined")
				{
					trace("mc2d saveMolecule error: scene.molList is undefined");
					return "";
				}

				var molecule = board.molecule;
				board.prepareToSnapshot();
				var base_path = scene.molList.imgTitle.tempDir + Player.module.identifier.replace( /:/g, '_');
				var tmp_xml_path = base_path+ '\\isomer' + (scene.molList.list.nextId+1) + ".xml";
				scene.molList.imgTitle.dll.call( '', 'saveText', tmp_xml_path + '|' + molecule.getIsomerXML());

				if( typeof(scene.photocamera)!="undefined")
				{
					var tmp_image_path = base_path+ '\\isomer' + (scene.molList.list.nextId+1) + ".png";
					scene.photocamera.cameye.imFilm.makeSnapshot(board);
					scene.photocamera.cameye.imFilm.setAutoUpdatePhotolist( false);
					scene.photocamera.cameye.imFilm.saveAs(tmp_image_path, "Введите название", true);
					//
					scene.set3DMode(2);
					if( typeof(scene.wnd3D.wndView) != "undefined")
					{
						scene.show3DView( molecule.getXML(), molecule.toString());
						var snapArray = new Array();
						snapArray.push( scene.wnd3D.wndView);
						snapArray.push( scene.wnd3D.wndFrame);

						var tmp_preview_path = base_path+ '\\isomer' + (scene.molList.list.nextId+1) + "_p.png";
						scene.photocamera.cameye.imFilm.makeSnapshot(snapArray);
						scene.photocamera.cameye.imFilm.saveAs(tmp_preview_path, "Введите название", false);
					}
					scene.photocamera.cameye.imFilm.setAutoUpdatePhotolist( true);
				}

				return (scene.molList.list.nextId+1);
			}

			function removeBoard( board)
			{
				var i=0;
				for( ; i<this.molecules.length; i++)
				{
					if( this.molecules[i] == board)
					{
						this.molecules[i].destroy();
						this.molecules[i].parent = null;
						this.molecules.splice(i, 1);
					}
				}
			}

			function showSelection4Atom( atom)
			{
				this.selectionAtom = atom;
				this.selAtoms.x = this.xMouse;
				this.selAtoms.y = this.yMouse;
				this.selAtoms.show_sel();
				this.selLinks.hide();
			}

			function showSelection4Link( atom, extended)
			{
				// Порядок команд
				// 1. Одинарная связь
				// 2. Двойная связь
				// 3. Тройная связь
				// 4. Поворот на 180
				this.selectionAtom = atom;
				//var xy = atom.molecule.board.getCellXY( atom.getAbsX(), atom.getAbsY());
				//this.selLinks.x = xy.x + atom.molecule.board.x;
				//this.selLinks.y = xy.y + atom.molecule.board.y;
				if( atom.linkType > 0)
					this.selLinks.select(atom.linkType);
				this.selLinks.x = this.xMouse;
				this.selLinks.y = this.yMouse;
				this.selLinks.show_sel();
				this.selAtoms.hide();
			}

			function onAtomSelectionDone()
			{
				this.selectionAtom = null;
				this.selAtoms.hide();
			}
			function onLinkSelectionDone()
			{
				this.selectionAtom = null;
				this.selLinks.hide();
			}

			function placeOnFreePlace( board)
			{
				/*if ( !tryToPlace( board, 0, 0))
				{
					board.x = 0;
					board.y = 0;
				}*/
				var bounds = board.molecule.getScreenBounds();
				bounds.left += board.x;	bounds.right += board.x;
				bounds.top += board.y + 1;	bounds.bottom += board.y + 1;
				var boardWidth = bounds.right - bounds.left;
				var boardHeight = bounds.bottom - bounds.top;

				board.setMoleculePosition( this.sceneBounds.left, 0);

				var sy = board.y;
				var stx = board.x;
				var sty = board.y;
				for( ;sy+boardHeight < 509 + sty; sy+=boardHeight)
				{
					var sx = stx;
					for( ;sx+boardWidth < 676 + stx; sx+=boardWidth)
					{
//trace("sx="+sx+", boardWidth ="+boardWidth +":"+(sx+boardWidth) + ":" + (this.listBounds.left + stx));
						board.x = sx;
						board.y = sy;

						bounds = board.molecule.getScreenBounds();
						bounds.left += board.x;	bounds.right += board.x;
						bounds.top += board.y;	bounds.bottom += board.y;

						var i=0;
						for( ; i<this.molecules.length; i++)
						{
							if( this.molecules[i] == board)	continue;
							var bounds2 = this.molecules[i].molecule.getScreenBounds();
							bounds2.left += this.molecules[i].x;	bounds2.right += this.molecules[i].x;
							bounds2.top += this.molecules[i].y;		bounds2.bottom += this.molecules[i].y;
							if( boundsIntersect(bounds, bounds2))
							{
								break;
							}
						}
						if( i==this.molecules.length)
						{
							return;
						}
					}
				}
				board.setMoleculePosition( this.sceneBounds.left, 0);
			}

			function boundsIntersect(bounds1, bounds2)
			{
				if( bounds1.left > bounds2.right || bounds1.right < bounds2.left ||
					bounds1.top > bounds2.bottom || bounds1.bottom < bounds2.top)	return false;
				return true;
			}
		]]></script>

		<composition name="selViewCH" class="CMCSelection" x="142" y="-14" visible="false">
			<image	name="item1"	src="rmgr:molconst2d/selHItem1.png" enabled="false"/>
			<image	name="item2"	src="rmgr:molconst2d/selHItem2.png" enabled="false"/>
			<script><![CDATA[
				this.autoHide = true;
				this.Add( new Array( this.item1, this.item2));
				function onSelected(id, item)
				{
					if( id == 0)	// показывать
					{
						this.parent.showH = true;
						this.parent.btnMenuCH_item01.show();
						this.parent.btnMenuCH_item02.hide();
					}
					else			// не показывать
					{
						this.parent.showH = false;
						this.parent.btnMenuCH_item02.show();
						this.parent.btnMenuCH_item01.hide();
					}
					for( var i=0; i<this.parent.molecules.length; i++)
					{
						var board = this.parent.molecules[i];
						board.showH(this.parent.showH);
					}
					this.hide();
				}
			]]></script>
		</composition>

		<composition name="selView3D" class="CMCSelection" x="190" y="-14" visible="false">
			<image	name="item1"	src="rmgr:molconst2d/selViewItem1.png" enabled="false"/>
			<image	name="item2"	src="rmgr:molconst2d/selViewItem2.png" enabled="false"/>
			<image	name="item3"	src="rmgr:molconst2d/selViewItem3.png" enabled="false"/>
			<script><![CDATA[
				this.autoHide = true;
				this.Add( new Array( this.item1, this.item2, this.item3));
				function onSelected(id, item)
				{
					scene.set3DMode( id + 1);
					this.hide();
				}
			]]></script>
		</composition>

		<script>
			function onSet3DMode(id)
			{
				this.btnView3D_item01.hide();
				this.btnView3D_item02.hide();
				this.btnView3D_item03.hide();
				eval("this.btnView3D_item0"+id).show();
			}
		</script>

		<image name="btnMenuCH_item01" src="rmgr:molconst2d/selHItem1stub.png" visible="false" enabled="false" x="120" y="-25" depth="-5"/>
		<image name="btnMenuCH_item02" src="rmgr:molconst2d/selHItem2stub.png" visible="true" enabled="false" x="120" y="-25" depth="-5"/>

		<image name="btnView3D_item01" src="rmgr:molconst2d/selViewItem1stub.png" visible="false" enabled="false" x="166" y="-32" depth="-5"/>
		<image name="btnView3D_item02" src="rmgr:molconst2d/selViewItem2stub.png" visible="true" enabled="false" x="171" y="-29" depth="-5"/>
		<image name="btnView3D_item03" src="rmgr:molconst2d/selViewItem3stub.png" visible="false" enabled="false" x="166" y="-32" depth="-5"/>
		<composition name="editorToolbar" class="CKMToolbar" x="119" y="-35">
			<script>
				this.radioGroup = "rg1";
				this.basePath = KM2DRESPATH;
				this.createButton("btnViewCH", "btnMenuCH.png", "Показывать атомы водорода").checkButton = false;
				this.createButton("btnView3D", "btnMenu3D.png", "Тип 3D просмотра").checkButton = false;
			</script>
			<script event="btnViewCH.onClick">
				this.parent.selView3D.hide();
				if( this.parent.showH)
				{
					this.parent.selViewCH.select(1);
				}
				else
				{
					this.parent.selViewCH.select(2);
				}
				this.parent.selViewCH.show_sel();
			</script>
			<script event="btnView3D.onClick">
				this.parent.selViewCH.hide();
				this.parent.selView3D.show_sel();
			</script>
		</composition>

		<!-- Кнопки редактирования-->
		<composition name="elementsToolbar" class="CKMToolbar" x="82" y="0" depth="-10">
			<composition name="elemH" class="CTableElement"/>
			<composition name="elemC" class="CTableElement"/>
			<composition name="elemN" class="CTableElement"/>
			<composition name="elemO" class="CTableElement"/>
			<composition name="elemCycles" class="CMultiElement"/>
			<composition name="elemGroups" class="CMultiElement">
				<script>
					this.btnPrefix = "btnGroups";
					this.typePrefix = "";
				</script>
			</composition>
			<!-- Специальные циклы -->
			<!-- Пятиугольный цикл -->
			<composition name="elemSC5" class="CCycleElement" visible="false">
				<script>
					this.btnPrefix = "btnSC";
					this.typePrefix = "C_";
				</script>
			</composition>
			<!-- Шестиугольный цикл -->
			<composition name="elemSC6" class="CCycleElement" visible="false">
				<script>
					this.btnPrefix = "btnSC";
					this.typePrefix = "C_";
				</script>
			</composition>
			<!-- H -->
			<composition name="elemSpecH" class="CCycleElement" visible="false">
				<script>
					this.btnPrefix = "btnSpec";
					this.typePrefix = "";
				</script>
			</composition>
			<!-- OH -->
			<composition name="elemSpecOH" class="CCycleElement" visible="false">
				<script>
					this.btnPrefix = "btn";
					this.typePrefix = "";
				</script>
			</composition>
			<!-- CH2OH -->
			<composition name="elemSpecCH2OH" class="CCycleElement" visible="false">
				<script>
					this.btnPrefix = "btn";
					this.typePrefix = "";
				</script>
			</composition>
			<script>
				this.radioGroup = "rg1";
				this.isVertical=true;
				this.margins=0;

				// Set workspace
				this.elemH.workspace = this.parent;
				this.elemC.workspace = this.parent;
				this.elemN.workspace = this.parent;
				this.elemO.workspace = this.parent;
				this.elemCycles.workspace = this.parent;
				this.elemGroups.workspace = this.parent;
				this.elemSC5.workspace = this.parent;
				this.elemSC6.workspace = this.parent;
				this.elemSpecH.workspace = this.parent;
				this.elemSpecOH.workspace = this.parent;
				this.elemSpecCH2OH.workspace = this.parent;

				// Selections
				this.elemCycles.externalSelection = this.parent.selCycles;
				this.elemGroups.externalSelection = this.parent.selGroups;

				// Set type and add buttons
				this.elemH.setType("H");		this.addButton( this.elemH);
				this.elemC.setType("C");		this.addButton( this.elemC);
				this.elemN.setType("N");		this.addButton( this.elemN);
				this.elemO.setType("O");		this.addButton( this.elemO);
				this.elemCycles.setType("6");	this.addButton( this.elemCycles);
				this.elemGroups.setType("1");	this.addButton( this.elemGroups);
				this.elemSC5.setType("5");		this.addButton( this.elemSC5);
				this.elemSC6.setType("6");		this.addButton( this.elemSC6);
				this.elemSpecH.setType("H");		this.addButton( this.elemSpecH);
				this.elemSpecOH.setType("OH");		this.addButton( this.elemSpecOH);
				this.elemSpecCH2OH.setType("CH2OH");	this.addButton( this.elemSpecCH2OH);

				this.elemC.setPressed( true);	this.elemC.setEnabled( false);
			</script>
			<script event="elemH.onPressedChanged">
				if( this.elemH.isPressed())
				{
					this.parent.setActiveElement( "H");
				}
			</script>
			<script event="elemC.onPressedChanged">
				if( this.elemC.isPressed())
				{
					this.parent.setActiveElement( "C");
				}
			</script>
			<script event="elemN.onPressedChanged">
				if( this.elemN.isPressed())
				{
					this.parent.setActiveElement( "N");
				}
			</script>
			<script event="elemO.onPressedChanged">
				if( this.elemO.isPressed())
				{
					this.parent.setActiveElement( "O");
				}
			</script>
			<script event="elemCycles.onPressedChanged">
				if( this.elemCycles.isPressed())
				{
					this.parent.setActiveElement( this.elemCycles.type);
				}
			</script>
			<script event="elemGroups.onPressedChanged">
				if( this.elemGroups.isPressed())
				{
					this.parent.setActiveElement( eval("gpGroup" + this.elemGroups.type));
				}
			</script>
			<script event="elemSC5.onPressedChanged">
				if( this.elemSC5.isPressed())
				{
					this.parent.setActiveElement( this.elemSC5.type);
				}
			</script>
			<script event="elemSC6.onPressedChanged">
				if( this.elemSC6.isPressed())
				{
					this.parent.setActiveElement( this.elemSC6.type);
				}
			</script>
			<script event="elemSpecH.onPressedChanged">
				if( this.elemSpecH.isPressed())
				{
					this.parent.setActiveElement( this.elemSpecH.type);
				}
			</script>
			<script event="elemSpecOH.onPressedChanged">
				if( this.elemSpecOH.isPressed())
				{
					this.parent.setActiveElement( this.elemSpecOH.type);
				}
			</script>
			<script event="elemSpecCH2OH.onPressedChanged">
				if( this.elemSpecCH2OH.isPressed())
				{
					this.parent.setActiveElement( this.elemSpecCH2OH.type);
				}
			</script>
		</composition>

		<script>
			//this.addElement("C");
			//this.addElement("N");
			//this.addElement("O");

			//this.addLink(1);
			//this.addLink(2);
			//this.addLink(3);

			function SetExpertTaskMode( )
			{
				this.elementsToolbar.removeButton("elemH");
				this.elementsToolbar.removeButton("elemC");
				this.elementsToolbar.removeButton("elemN");
				this.elementsToolbar.removeButton("elemO");
				this.elementsToolbar.removeButton("elemCycles");
				this.elementsToolbar.removeButton("elemGroups");

				this.elementsToolbar.elemSC5.visible = true;
				this.elementsToolbar.elemSC6.visible = true;
				this.elementsToolbar.elemSpecH.visible = true;
				this.elementsToolbar.elemSpecOH.visible = true;
				this.elementsToolbar.elemSpecCH2OH.visible = true;

				this.elementsToolbar.elemSC5.setPressed( true);
				this.elementsToolbar.elemSC5.setEnabled( false);
				this.setActiveElement("C_5");
			}
		</script>
	</composition>
</rmml>