kekule
Version:
Open source JavaScript toolkit for chemoinformatics
1 lines • 111 kB
JavaScript
"use strict";!function(){if(Kekule.PROP_AUTO_TITLE){var e=ClassEx.getPrototype(ObjectEx).defineProp;ClassEx.getPrototype(ObjectEx).defineProp=function(t,r){if(!r.title&&!r.description){var n=this.getClassName();n.startsWith("Kekule.")&&(n=n.substr(7));var i="TITLE_"+t,o="DES_"+t,a=Kekule.Localization.findValue("OBJDEF_TEXTS."+n+"."+i),s=Kekule.Localization.findValue("OBJDEF_TEXTS."+n+"."+o);r.title=a,r.description=s}return e.apply(this,[t,r])}}Kekule.ExceptionLevel={ERROR:-1,NOT_FATAL_ERROR:-10,WARNING:-2,NOTE:-3,LOG:-4,getAllLevels:function(){var e=Kekule.ExceptionLevel;return[e.ERROR,e.NOT_FATAL_ERROR,e.WARNING,e.NOTE,e.LOG]},levelToString:function(e){var t=Kekule.ExceptionLevel;return e===t.ERROR||e===t.NOT_FATAL_ERROR?"error":e===t.WARNING?"warning":e===t.NOTE?"note":"log"}},Kekule.ErrorLevel=Kekule.ExceptionLevel,Kekule.throwException=function(e,t){if(Kekule.exceptionHandler)return Kekule.exceptionHandler.throwException(e,t);var r=Kekule.ExceptionLevel;if(!t||t===r.ERROR)throw"string"==typeof e&&(e=new Kekule.Exception(e)),e;if("undefined"!=typeof console){"string"!=typeof e&&(e=e.message);var n=t===r.NOT_FATAL_ERROR?console.error:t===r.WARNING?console.warn:t===r.NOTE?console.info:console.log;n?n(e):console.log(e)}},Kekule.getExceptionMsg=function(e){return"string"==typeof e?e:"object"==typeof e?e.message:""},Kekule.raise=Kekule.throwException,Kekule.error=function(e,t){var r=t?Kekule.ExceptionLevel.NOT_FATAL_ERROR:Kekule.ExceptionLevel.ERROR;return Kekule.raise(e,r)},Kekule.chemError=function(e,t){return"string"==typeof e&&(e=new Kekule.ChemError(e)),Kekule.error(e,t)},Kekule.warn=function(e){return Kekule.raise(e,Kekule.ExceptionLevel.WARNING)},Kekule.notify=function(e){return Kekule.raise(e,Kekule.ExceptionLevel.NOTE)},Kekule.log=function(e){return Kekule.raise(e,Kekule.ExceptionLevel.LOG)},Kekule.hasLocalRes=function(){return!!Kekule.LOCAL_RES},Kekule.globalOptions={add:function(e,t){var r=Object.getCascadeFieldValue(e,Kekule.globalOptions);r&&DataType.isObjectValue(r)&&DataType.isObjectValue(t)?Object.extend(r,t):Object.setCascadeFieldValue(e,t,Kekule.globalOptions,!0)},get:function(e,t){var r=Object.getCascadeFieldValue(e,Kekule.globalOptions);return void 0===r&&(r=t),r}},Kekule.HashEx=Class.create({CLASS_NAME:"Kekule.HashEx",PROP_NAME_PREFIX:"__$key$__",initialize:function(){this._map={}},finalize:function(){this._map=null},keyToPropName:function(e){return this.PROP_NAME_PREFIX+e},has:function(e){return this._map.hasOwnProperty(this.keyToPropName(e))},set:function(e,t){return this._map[this.keyToPropName(e)]=t,this},get:function(e,t){var r=this.keyToPropName(e);return this._map.hasOwnProperty(r)?this._map[r]:t},remove:function(e){var t=this.keyToPropName(e);return this._map.hasOwnProperty(t)&&delete this._map[t],this},clear:function(){this._map={}}}),Kekule.MapEx=Class.create({CLASS_NAME:"Kekule.MapEx",initialize:function(e,t){this.isWeak=!e,Kekule.MapEx._inited||Kekule.MapEx._init();var r=e?Kekule.MapEx._implementationNonWeak:Kekule.MapEx._implementationWeak;r?this._implementation=new r:(this._keys=[],this._values=[]),t&&(this._cache={})},finalize:function(){this._implementation||(this._keys=null,this._values=null,this._cache=null)},set:function(e,t){if(this._implementation)this._implementation.set(e,t);else{var r=this._keys.indexOf(e);r>=0?this._values[r]=t:(this._keys.push(e),this._values.push(t))}return this._cache&&this._cache.key===e&&(this._cache.value=t),this},get:function(e,t){if(this._cache&&this._cache.key===e)return this._cache.value;var r,n=!1;if(this._implementation)this._implementation.has(e)&&(r=this._implementation.get(e),n=!0);else{var i=this._keys.indexOf(e);i>=0&&(r=this._values[i],n=!0)}return n&&this._cache&&(this._cache.key=e,this._cache.value=r),n?r:t},has:function(e){return this._implementation?this._implementation.has(e):this._keys.indexOf(e)>=0},remove:function(e){if(this._cache&&this._cache.key===e&&(this._cache={}),this._implementation)return this._implementation[!this._implementation||"delete"](e);var t=this._keys.indexOf(e);return t>=0&&(this._keys.splice(t,1),this._values.splice(t,1)),this},clear:function(){return this._cache&&(this._cache={}),this._implementation&&!this._debug||(this._keys=[],this._values=[]),this._implementation&&(this.isWeak?Kekule.error(Kekule.$L("ErrorMsg.CANNOT_CLEAR_WEAKMAP")):this._implementation.clear()),this},getKeys:function(){if(this._implementation){if(this.isWeak)return Kekule.error(Kekule.$L("ErrorMsg.CANNOT_GET_KEY_LIST_IN_WEAKMAP")),[];var e,t=this._implementation.keys();if(Array.from)e=Array.from(t);else if(t.next){e=[];for(var r=t.next();!r.done;)e.push(r.value),r=t.next()}else for(var n in e=[],t)e.push(n);return e}return[].concat(this._keys)},getValues:function(){if(this._implementation){if(this.isWeak)return Kekule.error(Kekule.$L("ErrorMsg.CANNOT_GET_VALUE_LIST_IN_WEAKMAP")),[];var e,t=this._implementation.values();if(Array.from)e=Array.from(t);else if(t.next){e=[];for(var r=t.next();!r.done;)e.push(r.value),r=t.next()}else for(var n in e=[],t)e.push(n);return e}return this._values},getLength:function(){return this.getKeys().length}}),Kekule.MapEx._init=function(){Kekule.MapEx._implementationWeak=null,Kekule.MapEx._implementationNonWeak=null,Kekule.$jsRoot.WeakMap&&(Kekule.MapEx._implementationWeak=Kekule.$jsRoot.WeakMap),Kekule.$jsRoot.Map&&Kekule.$jsRoot.Map.prototype.keys&&(Kekule.MapEx._implementationNonWeak=Kekule.$jsRoot.Map),Kekule.MapEx._inited=!0},Kekule.MapEx._inited=!1,Kekule.TwoTupleMapEx=Class.create({CLASS_NAME:"Kekule.TwoTupleMapEx",initialize:function(e,t){this.nonWeak=e,this.map=new Kekule.MapEx(e,t),t&&(this._level1Cache={})},finalize:function(){this._level1Cache=null,this.map.finalize()},getSecondLevelMap:function(e,t){if(e&&this._level1Cache&&e===this._level1Cache.key&&this._level1Cache.value)return this._level1Cache.value;var r=this.map.get(e);return!r&&t&&(r=new Kekule.MapEx(this.nonWeak),this.map.set(e,r)),r},set:function(e,t,r){return this.getSecondLevelMap(e,!0).set(t,r),this},get:function(e,t,r){var n=this.getSecondLevelMap(e,!1);return n?n.get(t,r):r},has:function(e,t){var r=this.getSecondLevelMap(e,!1);return!!r&&r.has(t)},remove:function(e,t){var r=this.getSecondLevelMap(e,!1);if(r)return r.remove(t)},clear:function(){this.map.clear(),this._level1Cache&&(this._level1Cache={})}}),Kekule.CoordMode={UNKNOWN:0,COORD2D:2,COORD3D:3},Kekule.ObjAnchorPosition={CORNER:0,CENTER:1,DEFAULT:0},Kekule.ClassDefineUtils={CommonSizeMethods:{getSizeOfMode:function(e,t){return e===Kekule.CoordMode.COORD3D?this.getSize3D(t):this.getSize2D(t)},setSizeOfMode:function(e,t){return t===Kekule.CoordMode.COORD3D?this.setSize3D(e):this.setSize2D(e)},getBoxOfMode:function(e,t){return e===Kekule.CoordMode.COORD3D?this.getBox3D(t):this.getBox2D(t)}},Size2DMethods:{fetchSize2D:function(){var e=this.getPropStoreFieldValue("size2D");return e||(e={},this.setPropStoreFieldValue("size2D",e)),e},notifySize2DChanged:function(e){this.notifyPropSet("size2D",e)},hasSize2D:function(e){var t=this.getPropStoreFieldValue("size2D"),r=t&&(void 0!==t.x||void 0!==t.y);return!r&&e&&(r=!!this.hasSize3D&&this.hasSize3D()),r},getBox2D:function(e){var t=this.getCoord2D(e)||{x:0,y:0},r=this.getSize2D(e);if(r&&(r.x||r.y)){var n={x:r.x,y:-r.y},i=Kekule.CoordUtils.add(t,n);return{x1:t.x,y1:t.y,x2:i.x,y2:i.y}}return{x1:t.x,y1:t.y,x2:t.x,y2:t.y}},get2DSizeX:function(e){var t=this.getSize2D(e);return t&&t.x||0},set2DSizeX:function(e){var t=this.fetchSize2D();t.x!=e&&(t.x=e,this.notifySize2DChanged(t))},get2DSizeY:function(e){var t=this.getSize2D(e);return t&&t.y||0},set2DSizeY:function(e){var t=this.fetchSize2D();t.y!=e&&(t.y=e,this.notifySize2DChanged(t))}},Size3DMethods:{fetchSize3D:function(){var e=this.getPropStoreFieldValue("size3D");return e||(e={},this.setPropStoreFieldValue("size3D",e)),e},notifySize3DChanged:function(e){this.notifyPropSet("size3D",e)},hasSize3D:function(e){var t=this.getPropStoreFieldValue("size3D"),r=t&&(void 0!==t.x||void 0!==t.y||void 0!==t.z);return!r&&e&&(r=!!this.hasSize2D&&this.hasSize2D()),r},getBox3D:function(e){var t=this.getCoord3D(e),r=this.getSize3D(e);if(t&&r){var n=Kekule.CoordUtils.add(t,r);return{x1:t.x,y1:t.y,z1:t.z,x2:n.x,y2:n.y,z2:n.z}}},get3DSizeX:function(e){var t=this.getSize3D(e);return t&&t.x||0},set3DSizeX:function(e){var t=this.fetchSize3D();t.x!=e&&(t.x=e,this.notifySize3DChanged(t))},get3DSizeY:function(e){var t=this.getSize3D(e);return t&&t.y||0},set3DSizeY:function(e){var t=this.fetchSize3D();t.y!=e&&(t.y=e,this.notifySize3DChanged(t))},get3DSizeZ:function(e){var t=this.getSize3D(e);return t&&t.z||0},set3DSizeZ:function(e){var t=this.fetchSize3D();t.z!=e&&(t.z=e,this.notifySize3DChanged(t))}},addStandardSizeSupport:function(e,t){ClassEx.extend(e,Kekule.ClassDefineUtils.CommonSizeMethods),(!t||t.indexOf("size2D")>=0)&&(ClassEx.defineProp(e,"size2D",{dataType:DataType.HASH,getter:function(e,t){var r=this.getPropStoreFieldValue("size2D");!r&&e&&this.hasSize3D()&&(r=this.getSize3D()),!r&&t&&(r={x:0,y:0},this.setPropStoreFieldValue("size2D",r));var n=r?{x:r.x,y:r.y}:void 0;return n&&(n=Kekule.CoordUtils.absValue(n)),n},setter:function(e){var t=this.fetchSize2D();void 0!==e.x&&(t.x=e.x),void 0!==e.y&&(t.y=e.y),this.notifySize2DChanged(t)}}),ClassEx.extend(e,Kekule.ClassDefineUtils.Size2DMethods)),(!t||t.indexOf("size3D")>=0)&&(ClassEx.defineProp(e,"size3D",{dataType:DataType.HASH,getter:function(e,t){var r=this.getPropStoreFieldValue("size3D");return!r&&e&&this.hasSize2D()&&((r=this.getSize2D()).z=0),!r&&t&&(r={x:0,y:0,z:0},this.setPropStoreFieldValue("size3D",r)),r?{x:r.x,y:r.y,z:r.z}:void 0},setter:function(e){var t=this.fetchSize3D();void 0!==e.x&&(t.x=e.x),void 0!==e.y&&(t.y=e.y),void 0!==e.z&&(t.z=e.z),this.notifySize3DChanged(t)}}),ClassEx.extend(e,Kekule.ClassDefineUtils.Size3DMethods))},CommonCoordMethods:{getObjAnchorPosition:function(e){var t=this.doGetObjAnchorPosition&&this.doGetObjAnchorPosition(e);return t=t||Kekule.ObjAnchorPosition.DEFAULT},getCoordParent:function(e){return this.getParent&&this.getParent()||null},getCoordOfMode:function(e,t){return e===Kekule.CoordMode.COORD3D?this.getCoord3D(t):this.getCoord2D(t)},setCoordOfMode:function(e,t){return t===Kekule.CoordMode.COORD3D?this.setCoord3D(e):this.setCoord2D(e)},getAbsCoordOfMode:function(e,t){return e===Kekule.CoordMode.COORD3D?this.getAbsCoord3D(t):this.getAbsCoord2D(t)},setAbsCoordOfMode:function(e,t){return t===Kekule.CoordMode.COORD3D?this.setAbsCoord3D(e):this.setAbsCoord2D(e)},hasCoordOfMode:function(e,t){return e===Kekule.CoordMode.COORD3D?this.hasCoord3D(t):this.hasCoord2D(t)},getIndirectCoordStorageOfMode:function(e){var t=this.getIndirectCoordStorage&&this.getIndirectCoordStorage();return t&&t[e]},setIndirectCoordStorageOfMode:function(e,t){var r=this.getIndirectCoordStorage&&this.getIndirectCoordStorage();return r&&(r[e]=t),this},calcIndirectCoordValue:function(e,t){var r=["x","y"];e===Kekule.CoordMode.COORD3D&&r.push("z");var n=this.getIndirectCoordStorage()[e],i=this.getIndirectCoordRefCoords(e,t);Kekule.ArrayUtils.isArray(i)&&(i=i[0]);var o=this.getIndirectCoordRefLengths(e,t);if(n&&i&&o){for(var a={},s=Kekule.ObjUtils.notUnset,l=0,u=r.length;l<u;++l){var c,h=r[l],d=n[h],f=i[h],p=o[h];if(s(d)&&s(f)&&s(p))c=0===p?f:f+p*d,a[h]=c}return a}return null},calcIndirectCoordStorage:function(e,t,r,n){var i=["x","y"];e===Kekule.CoordMode.COORD3D&&i.push("z");var o=this.getIndirectCoordStorageOfMode(e),a=this.getIndirectCoordRefCoords(e,n);Kekule.ArrayUtils.isArray(a)&&(a=a[0]);var s=this.getIndirectCoordRefLengths(e,n);if(o&&a&&s){for(var l={},u=Kekule.ObjUtils.notUnset,c=0,h=i.length;c<h;++c){var d,f=i[c],p=t[f],g=a[f],m=s[f];if(!(u(p)&&u(g)&&u(m)))return null;d=0!==m?(p-g)/m:1,l[f]=d}return l}return null},saveIndirectCoordValue:function(e,t,r,n){if(t){var i=this.calcIndirectCoordStorage(e,t,r,n);if(i)return this.setIndirectCoordStorageOfMode(e,i),i}return null},getIndirectCoordRefLengths:function(e,t){return null},getIndirectCoordRefCoords:function(e,t){return null}},Coord2DMethods:{fetchCoord2D:function(){var e=this.getPropStoreFieldValue("coord2D");return e||(e={},this.setPropStoreFieldValue("coord2D",e)),e},notifyCoord2DChanged:function(e){this.notifyPropSet("coord2D",e)},hasCoord2D:function(e){var t=this.getPropStoreFieldValue("coord2D"),r=t&&(void 0!==t.x||void 0!==t.y);return!r&&e&&(r=!!this.hasCoord3D&&this.hasCoord3D()),r},get2DX:function(e){var t=this.getCoord2D(e);return t&&t.x||0},set2DX:function(e){var t=this.fetchCoord2D();t.x!=e&&(t.x=e,this.notifyCoord2DChanged(t))},get2DY:function(e){var t=this.getCoord2D(e);return t&&t.y||0},set2DY:function(e){var t=this.fetchCoord2D();t.y!=e&&(t.y=e,this.notifyCoord2DChanged(t))}},Coord3DMethods:{fetchCoord3D:function(){var e=this.getPropStoreFieldValue("coord3D");return e||(e={},this.setPropStoreFieldValue("coord3D",e)),e},notifyCoord3DChanged:function(e){this.notifyPropSet("coord3D",e)},hasCoord3D:function(e){var t=this.getPropStoreFieldValue("coord3D"),r=t&&(void 0!==t.x||void 0!==t.y||void 0!==t.z);return!r&&e&&(r=!!this.hasCoord2D&&this.hasCoord2D()),r},get3DX:function(e){var t=this.getCoord3D(e);return t&&t.x||0},set3DX:function(e){var t=this.fetchCoord3D();t.x!=e&&(t.x=e,this.notifyCoord3DChanged(t))},get3DY:function(e){var t=this.getCoord3D(e);return t&&t.y||0},set3DY:function(e){var t=this.fetchCoord3D();t.y!=e&&(t.y=e,this.notifyCoord3DChanged(t))},get3DZ:function(e){var t=this.getCoord3D(e);return t&&t.z||0},set3DZ:function(e){var t=this.fetchCoord3D();t.z!=e&&(t.z=e,this.notifyCoord3DChanged(t))}},addStandardCoordSupport:function(e,t){ClassEx.extend(e,Kekule.ClassDefineUtils.CommonCoordMethods),(!t||t.indexOf("coord2D")>=0)&&(ClassEx.defineProp(e,"coord2D",{dataType:DataType.HASH,getter:function(e,t){if(this.getEnableIndirectCoord()){var r=this.calcIndirectCoordValue(Kekule.CoordMode.COORD2D,e);if(r)return r}var n=this.getPropStoreFieldValue("coord2D");return!n&&e&&this.hasCoord3D()&&(n=this.getCoord3D()),!n&&t&&(n={x:0,y:0},this.setPropStoreFieldValue("coord2D",n)),n?{x:n.x,y:n.y}:void 0},setter:function(e){var t=this.fetchCoord2D();this.getEnableIndirectCoord()&&this.saveIndirectCoordValue(Kekule.CoordMode.COORD2D,e,t),void 0!==e.x&&(t.x=e.x),void 0!==e.y&&(t.y=e.y),this.notifyCoord2DChanged(t)}}),ClassEx.extend(e,Kekule.ClassDefineUtils.Coord2DMethods)),(!t||t.indexOf("coord3D")>=0)&&(ClassEx.defineProp(e,"coord3D",{dataType:DataType.HASH,getter:function(e,t){if(this.getEnableIndirectCoord()){var r=this.calcIndirectCoordValue(Kekule.CoordMode.COORD2D,e);if(r)return r}var n=this.getPropStoreFieldValue("coord3D");return!n&&e&&this.hasCoord2D()&&((n=this.getCoord2D()).z=0),!n&&t&&(n={x:0,y:0,z:0},this.setPropStoreFieldValue("coord3D",n)),n?{x:n.x,y:n.y,z:n.z}:void 0},setter:function(e){var t=this.fetchCoord3D();this.getEnableIndirectCoord()&&this.saveIndirectCoordValue(Kekule.CoordMode.COORD3D,e,t),void 0!==e.x&&(t.x=e.x),void 0!==e.y&&(t.y=e.y),void 0!==e.z&&(t.z=e.z),this.notifyCoord3DChanged(t)}}),ClassEx.extend(e,Kekule.ClassDefineUtils.Coord3DMethods)),(!t||t.indexOf("absCoord2D")>=0)&&ClassEx.defineProp(e,"absCoord2D",{dataType:DataType.HASH,serializable:!1,getter:function(e){var t=this.getCoord2D(e)||{},r=this.getCoordParent(Kekule.CoordMode.COORD2D);return r&&r.getAbsCoord2D?Kekule.CoordUtils.add(t,r.getAbsCoord2D(e)||{}):{x:t.x,y:t.y}},setter:function(e,t){var r=e,n=this.getCoordParent(Kekule.CoordMode.COORD2D);n&&n.getAbsCoord2D&&(r=Kekule.CoordUtils.substract(e,n.getAbsCoord2D(t))),this.setCoord2D(r)}}),(!t||t.indexOf("absCoord3D")>=0)&&ClassEx.defineProp(e,"absCoord3D",{dataType:DataType.HASH,serializable:!1,getter:function(e){var t=this.getCoord3D(e)||{},r=this.getCoordParent(Kekule.CoordMode.COORD3D);return r&&r.getAbsCoord3D?Kekule.CoordUtils.add(t,r.getAbsCoord3D(e)||{}):{x:t.x,y:t.y,z:t.z}},setter:function(e,t){var r=e,n=this.getCoordParent(Kekule.CoordMode.COORD2D);n&&n.getAbsCoord3D&&(r=Kekule.CoordUtils.substract(e,n.getAbsCoord3D(t))),this.setCoord3D(r)}}),(!t||t.indexOf("enableIndirectCoord")>=0)&&ClassEx.defineProp(e,"enableIndirectCoord",{scope:Class.PropertyScope.PUBLIC,dataType:DataType.BOOL,serializable:!0,setter:function(e){if(this.getPropStoreFieldValue("enableIndirectCoord")!=e){if(e){var t=this.getCoord2D(),r=this.getCoord3D();t&&this.saveIndirectCoordValue(Kekule.CoordMode.COORD2D,t,t,!0),r&&this.saveIndirectCoordValue(Kekule.CoordMode.COORD3D,r,r,!0)}this.setPropStoreFieldValue("enableIndirectCoord",e)}}}),(!t||t.indexOf("indirectCoordStorage")>=0)&&ClassEx.defineProp(e,"indirectCoordStorage",{dataType:DataType.HASH,serializable:function(){return!!this.getEnableIndirectCoord()},setter:null,getter:function(){var e=this.getPropStoreFieldValue("indirectCoordStorage");return e||((e={})[Kekule.CoordMode.COORD2D]={},e[Kekule.CoordMode.COORD3D]={},this.setPropStoreFieldValue("indirectCoordStorage",e)),e}})},ExtraObjMapMethods:{getExtraProp:function(e,t){var r=this.getExtraObjMap().get(e);return r?t?r[t]:r:void 0},setExtraProp:function(e,t,r){var n;(n=this.getExtraProp(e))?n[t]=r:((n={})[t]=r,this.getExtraObjMap().set(e,n))},removeExtraProp:function(e,t){if(t){var r=this.getExtraProp(e);r[t]=void 0,delete r[t]}else this.getExtraObjMap().remove(e)}},addExtraObjMapSupport:function(e){ClassEx.defineProp(e,"extraObjMap",{dataType:"Kekule.MapEx",serializable:!1,getter:function(){var e=this.getPropStoreFieldValue("extraObjMap");return e||(e=new Kekule.MapEx(!0,!0),this.setPropStoreFieldValue("extraObjMap",e)),e}}),ClassEx.extend(e,Kekule.ClassDefineUtils.ExtraObjMapMethods)},ExtraTwoTupleObjMapMethods:{getExtraProp2:function(e,t,r){var n=(this.__$__k__extraTwoTupleObjMap__$__||this.getExtraTwoTupleObjMap()).get(e,t);return n?r?n[r]:n:void 0},setExtraProp2:function(e,t,r,n){var i;(i=this.getExtraProp2(e,t))?i[r]=n:((i={})[r]=n,(this.__$__k__extraTwoTupleObjMap__$__||this.getExtraTwoTupleObjMap()).set(e,t,i))},removeExtraProp2:function(e,t,r){if(r){var n=this.getExtraProp2(e,t);n[r]=void 0,delete n[r]}else this.getExtraTwoTupleObjMap().remove(e,t)}},addExtraTwoTupleObjMapSupport:function(e){var t="extraTwoTupleObjMap";ClassEx.defineProp(e,t,{dataType:"Kekule.TwoTupleMapEx",serializable:!1,getter:function(){var e=this.getPropStoreFieldValue(t);return e||(e=new Kekule.TwoTupleMapEx(!0,!0),this.setPropStoreFieldValue(t,e),this.__$__k__extraTwoTupleObjMap__$__=e),e}}),ClassEx.extend(e,Kekule.ClassDefineUtils.ExtraTwoTupleObjMapMethods)}},Kekule.ObjPropSettingManager={_items:new Kekule.MapEx(!0),register:function(e,t){Kekule.ObjPropSettingManager._items.set(e,t)},unregister:function(e){Kekule.ObjPropSettingManager._items.remove(e)},getSetting:function(e){return Kekule.ObjPropSettingManager._items.get(e)}},ClassEx.defineProp(ObjectEx,"predefinedSetting",{dataType:DataType.STRING,scope:Class.PropertyScope.PUBLIC,setter:function(e){var t=Kekule.StrUtils.splitTokens(e||"",",");if(t.length){for(var r=0,n=t.length;r<n;++r){for(var i=this.getClass(),o=t[r],a=null,s="";i&&!a;){s=ClassEx.getClassName(i)+"."+o;a=Kekule.ObjPropSettingManager.getSetting(s),i=ClassEx.getSuperClass(i)}a||(a=Kekule.ObjPropSettingManager.getSetting(o)),a&&this.setPropValues(a)}this.setPropStoreFieldValue("predefinedSetting",s)}}}),Kekule.ObjectTreeOperation={MODIFY:0,ADD:1,REMOVE:2},Kekule.ChemObjInteractMode={DEFAULT:0,UNMOVABLE:1,UNSELECTABLE:2,HIDDEN:3},Kekule.ComparisonMethod={DEFAULT:0,PROPERTIES:1,CHEM_STRUCTURE:10},Kekule.ObjComparer={equal:function(e,t,r){return 0===Kekule.ObjComparer.compare(e,t,r)},compare:function(e,t,r){return Kekule.ObjComparer._compareValue(e,t,r)},_compareValue:function(e,t,r){var n=DataType;if(e===t)return 0;var i=n.getType(e),o=n.getType(t);if("number"===i&&Kekule.NumUtils.isFloatEqual(e,t))return 0;if(e<t&&!(e>t))return-1;if(e>t&&!(e<t))return 1;var a=null;if(i!==o){var s=[n.UNKNOWN,n.VARIANT,n.UNDEFINED,n.BOOL,n.NUMBER,n.INT,n.FLOAT,n.STRING,n.ARRAY,n.FUNCTION,n.DATE,n.OBJECT,n.OBJECTEX,n.CLASS],l=s.indexOf(i),u=s.indexOf(o);a=l<0&&u<0?null:l-u}else if(!e&&t)a=-1;else if(e&&!t)a=1;else if(e.doCompare)a=e.doCompare(t,r);else if(t.doCompare)a=-t.doCompare(e,r);else if(i===DataType.ARRAY){if(!(a=e.length-t.length))for(var c=0,h=e.length;c<h&&!(a=Kekule.ObjComparer._compareValue(e[c],t[c],r));++c);}else a=i===DataType.OBJECT?Kekule.ObjComparer._compareHash(e,t,r):null;if(null===a){var d=e.toString&&e.toString()||"",f=t.toString&&t.toString()||"";null===(a=d<f?-1:d>f?1:null)&&(a=-1)}return a},_compareHash:function(e,t,r){var n=Kekule.ObjUtils.getOwnedFieldNames(e)||[],i=Kekule.ObjUtils.getOwnedFieldNames(t)||[],o=n.length-i.length;if(!(o||(n.sort(),i.sort(),o=Kekule.ArrayUtils.compare(n,i))))for(var a=0,s=n.length;a<s;++a){var l=n[a],u=e[l],c=t[l];if(o=Kekule.ObjComparer.compare(u,c,r)){console.log(l,o,u,c);break}}return o}};Kekule.ChemObject=Class.create(ObjectEx,{CLASS_NAME:"Kekule.ChemObject",initialize:function(e){this.tryApplySuper("initialize"),e&&this.setId(e),this.setBubbleEvent(!0),this.__load_owner_objRef_props__=null,this.__load_parent_objRef_props__=null,this.__load_parentRoot_objRef_props__=null,this.addEventListener("change",function(e){var t=this.getPropStoreFieldValue("srcInfo");if(t&&t.data){for(var r=e.target,n=e.changedPropNames,i=!1,o=0,a=n.length;o<a;++o){var s=n[o];if(s&&"srcInfo"!==s&&r.isPropertySerializable(s)){i=!0;break}if("[children]"===s){i=!0;break}}i&&(t.data=null)}},this)},doFinalize:function(){this.__load_owner_objRef_props__=null,this.__load_parent_objRef_props__=null,this.__load_parentRoot_objRef_props__=null,this.setPropStoreFieldValue("attachedCoordStickNodes",null),this.removeSelf(),this.tryApplySuper("doFinalize")},initProperties:function(){this.defineProp("id",{dataType:DataType.STRING}),this.defineProp("interactMode",{dataType:DataType.INT,enumSource:Kekule.ChemObjInteractMode}),this.defineProp("info",{dataType:DataType.HASH,getter:function(e){var t=this.getPropStoreFieldValue("info");return!t&&e&&(t={},this.setPropStoreFieldValue("info",t)),t}}),this.defineProp("scalarAttribs",{dataType:DataType.ARRAY,setter:null}),this.defineProp("parent",{dataType:"Kekule.ChemObject",serializable:!1,scope:Class.PropertyScope.PUBLIC,setter:function(e){var t=this.getParent();t!==e&&(t&&t._removeChildObj&&(t._removeChildObj(this),this.invokeEvent("removeFromObjTree",{obj:this,parent:t})),this.setPropStoreFieldValue("parent",e),e&&e._appendChildObj&&(e._appendChildObj(this),this.invokeEvent("addToObjTree",{obj:this,parent:e})),this.parentChanged(e,t))}}),this.defineProp("owner",{dataType:"Kekule.ChemSpace",serializable:!1,scope:Class.PropertyScope.PUBLIC,setter:function(e){var t=this.getOwner();t!==e&&(t&&(t._removeOwnedObj(this),this.invokeEvent("removeFromSpace",{obj:this,owner:t})),this.setPropStoreFieldValue("owner",e),e&&(e._appendOwnedObj(this),this.invokeEvent("addToSpace",{obj:this,owner:t})),this.ownerChanged(e,t))}}),this.defineProp("srcInfo",{dataType:DataType.OBJECT,serializable:!1,scope:Class.PropertyScope.PUBLISHED,getter:function(){var e=this.getPropStoreFieldValue("srcInfo");return e||(e={},this.setPropStoreFieldValue("srcInfo",e)),e}}),this.defineProp("isEditing",{dataType:DataType.BOOL,serializable:!1,scope:Class.PropertyScope.PUBLIC,getter:function(){var e=this.getOwner();return e&&e.getIsEditing?e.getIsEditing():this.getPropStoreFieldValue("isEditing")}}),this.defineProp("attachedCoordStickNodes",{dataType:DataType.ARRAY,serializable:!1,getter:function(){var e=this.getPropStoreFieldValue("attachedCoordStickNodes");return e||(e=[],this.setPropStoreFieldValue("attachedCoordStickNodes",e)),e}})},initPropValues:function(){this.tryApplySuper("initPropValues"),this.setEnableObjectChangeEvent(!0)},getHigherLevelObj:function(){return this.getParent()||this.getOwner()},getAutoIdPrefix:function(){return"o"},_parentObjectLoaded:function(e){},_ownerObjectLoaded:function(e){},_handleObjRefProps:function(e,t){var r=t;if(r)for(var n=Kekule.ObjUtils.getOwnedFieldNames(r),i=0,o=n.length;i<o;++i){var a=n[i],s=this.getPropInfo(a),l=this._doGetPropObjRefObjInfo(this,s,e).rootObj,u=r[a];if(DataType.isArrayValue(u)){var c=[];for(i=0,o=u.length;i<o;++i){if(f=this._doUnwrapObjRefSerializationStr(this,u[i])){var h=l.getChildAtIndexStack(f);c.push(h)}else c.push(void 0)}this.setPropValue(a,c)}else{var d,f;(f=this._doUnwrapObjRefSerializationStr(this,u))&&(d=l.getChildAtIndexStack(f)),d&&this.setPropValue(a,d)}try{delete r[a]}catch(e){}}},doSaveProp:function(e,t,r,n,i,o,a,s){if(t.serializable&&(e._doGetObjRefSerializationValue&&!!t.objRef)){var l=e._doGetPropObjRefObjInfo(e,t,o);if(l){var u=l.rootObj;if(u){var c=e.getPropValue(t.name);if(c){if(Kekule.ArrayUtils.isArray(c)){for(var h=[],d=0,f=c.length;d<f;++d){var p=e._doGetObjRefSerializationValue(u,e,c[d],l.objRefRoot);p?h.push(p):h.push(c[d])}return i.doSaveFieldValue(e,t.name,h,r,i.getValueExplicitType(h),n,u,a,s),!0}var g=e._doGetObjRefSerializationValue(u,e,c,l.objRefRoot);if(g)return i.doSaveFieldValue(e,t.name,g,r,i.getValueExplicitType(g),n,u,a,s),!0}}}}},_doGetObjRefSerializationValue:function(e,t,r,n){var i=e.indexStackOfChild&&e.indexStackOfChild(r);if(i&&i.length){return"@"+JSON.stringify(i)}return null},doLoadProp:function(e,t,r,n,i,o,a){if(t.serializable&&!!t.objRef){var s=n.doLoadFieldValue(e,t.name,r,null,i,o,a);if(s){var l=(e._doGetPropObjRefObjInfo&&e._doGetPropObjRefObjInfo(e,t,o)).storageObjName,u=e[l];return u||(u={},e[l]=u),u[t.name]=s,!0}}},_doUnwrapObjRefSerializationStr:function(e,t){try{var r=t.startsWith("@")?t.substr("@".length):t,n=JSON.parse(r);return DataType.isArrayValue(n)?n:null}catch(e){Kekule.error(e)}},_doGetPropObjRefObjInfo:function(e,t,r){var n=t.objRefRoot,i="owner"===n,o="storageRoot"===n,a="parent"===n?e.getParent&&e.getParent():i?e.getOwner&&e.getOwner():o?r:null;if(!a){var s=e.getOwner&&e.getOwner();s?(n="owner",i=!0,a=s):(n="storageRoot",o=!0,a=r)}return{objRefRoot:n,rootObj:a,storageObjName:"__load_objRef_props__"}},loaded:function(e){this.tryApplySuper("loaded",[e]),this.notifyParentLoaded()},allLoaded:function(e){this.tryApplySuper("allLoaded",[e]),this._handleObjRefProps(e,this.__load_objRef_props__)},notifyParentLoaded:function(){for(var e=0,t=this.getChildCount();e<t;++e){var r=this.getChildAt(e);r&&r._parentObjectLoaded&&r._parentObjectLoaded(this)}},isObjRefProperty:function(e){return!(!e||!e.objRef)},notifyPropSet:function(e,t,r){this.tryApplySuper("notifyPropSet",[e,t,r]);var n=this.getPropInfo(e);if(n&&this.isObjRefProperty(n)){var i=this.getOwner();i&&i.modifyObjRefRelation&&i.modifyObjRefRelation(this,n,this.getPropValue(n.name))}},getObjRefProperties:function(){for(var e=[],t=this.getAllPropList(),r=0,n=t.getLength();r<n;++r){var i=t.getPropInfoAt(r);this.isObjRefProperty(i)&&e.push(i)}return e},_registerObjRefRelations:function(e){if(e&&e.modifyObjRefRelation){var t=this.getObjRefProperties();if(t.length)for(var r=0,n=t.length;r<n;++r){var i=t[r],o=this.getPropValue(i.name);e.modifyObjRefRelation(this,i,o)}}},_unregisterObjRefRelations:function(e){if(e&&e.releaseObjRefRelation){var t=this.getObjRefProperties();if(t.length)for(var r=0,n=t.length;r<n;++r){var i=t[r];e.releaseObjRefRelation(this,i)}}},isSelectable:function(){var e=Kekule.ChemObjInteractMode;return!((this.getInteractMode()||e.DEFAULT)&e.UNSELECTABLE)},isMovable:function(){var e=Kekule.ChemObjInteractMode;return!((this.getInteractMode()||e.DEFAULT)&e.UNMOVABLE)},getNearestSelectableObject:function(){return this.isSelectable()?this:this.getParent()?this.getParent().getNearestSelectableObject():null},getNearestMovableObject:function(){return this.isMovable()?this:this.getParent()?this.getParent().getNearestMovableObject():null},getNearestAncestorOfType:function(e){var t=this.getParent();return t?t instanceof e?t:t.getNearestAncestorOfType?t.getNearestAncestorOfType(e):null:null},removeSelf:function(){this.setParent(null),this.setOwner(null)},notifyScalarAttribsChange:function(){this.notifyPropSet("scalarAttribs",this.getPropStoreFieldValue("scalarAttribs"))},notifyInfoChange:function(){this.notifyPropSet("info",this.getPropStoreFieldValue("info"))},_removeChildObj:function(e){this._notifyOwnerObjTreeOperation(e,this,Kekule.ObjectTreeOperation.REMOVE)},_appendChildObj:function(e){this._notifyOwnerObjTreeOperation(e,this,Kekule.ObjectTreeOperation.ADD)},_notifyOwnerObjTreeOperation:function(e,t,r){var n=this.getOwner();n&&n._notifyObjTreeOperation&&n._notifyObjTreeOperation(e,t,r)},objTreeOfOwnerUpdated:function(e,t,r){},objSpaceOfOwnerUpdated:function(e,t,r){},ownerChanged:function(e,t){for(var r=0,n=this.getScalarAttribCount();r<n;++r)this.getScalarAttribAt(r).setOwner(e);for(r=0,n=this.getChildCount();r<n;++r){var i=this.getChildAt(r);i&&i.setOwner&&i.setOwner(e)}},parentChanged:function(e,t){},getParentList:function(){var e=[],t=this.getParent();return t&&(t.getParentList&&(e=t.getParentList()||[]),e.unshift(t)),e},getParentRoot:function(){var e=this.getParent();return e&&e.getParentRoot&&(e=e.getParentRoot()||e),e},isChildOf:function(e){for(var t=this.getParent();t&&t!==e;)t=t.getParent?t.getParent():null;return!!t},getNextSibling:function(){var e=this.getParent();return e&&e.getNextSiblingOfChild?e.getNextSiblingOfChild(this):null},isSiblingWith:function(e){var t=this.getParent(),r=e.getParent&&e.getParent();return t&&r&&t===r},getChildHolder:function(){return this},getChildSubgroupNames:function(){return[]},getBelongChildSubGroupName:function(e){return null},_getPrevSubgroupChildrenCount:function(e){for(var t=this.getChildSubgroupNames(),r=0,n=0,i=t.length;n<i;++n){if(t[n]===e)return r;var o=this._getSubGroupChildCountMethod(t[n]);r+=o&&o.apply(this)||0}return r},_getSubgroupChildIndexInfoFromChildIndex:function(e){for(var t=this.getChildSubgroupNames(),r=0,n=0,i=t.length;n<i;++n){var o=this._getSubGroupChildCountMethod(t[n]),a=o&&o.apply(this)||0;if(e<r+a)return{name:t[n],index:e-r};r+=a}return null},_getSubGroupChildCountMethod:function(e){return this["get"+e.upperFirst()+"Count"]},_getSubGroupChildAtMethod:function(e){return this["get"+e.upperFirst()+"At"]},_getSubGroupChildIndexOfMethod:function(e){return this["indexOf"+e.upperFirst()]},_getSubGroupChildRemoveMethod:function(e){return this["remove"+e.upperFirst()]},_getSubGroupChildRemoveAtMethod:function(e){return this["remove"+e.upperFirst()+"At"]},_getSubGroupChildAppendMethod:function(e){return this["append"+e.upperFirst()]},_getSubGroupChildInsertBeforeMethod:function(e){return this["insert"+e.upperFirst()+"Before"]},_getSubGroupChildInsertAtMethod:function(e){return this["insert"+e.upperFirst()+"At"]},_ensureSubGroupChildMethodsExist:function(){for(var e=["_getSubGroupChildCountMethod","_getSubGroupChildAtMethod","_getSubGroupChildIndexOfMethod","_getSubGroupChildRemoveMethod","_getSubGroupChildRemoveAtMethod","_getSubGroupChildInsertBeforeMethod","_getSubGroupChildInsertAtMethod"],t=this.getChildSubgroupNames(),r=0,n=t.length;r<n;++r)for(var i=0,o=e.length;i<o;++i){this[e[i]].apply(this,[t[r]])||Kekule.warn("Subgroup child method not exisits: "+e[i]+" / "+this.getClassName())}},getChildCount:function(){var e=this.getChildHolder();return e&&e!==this?e.getChildCount():this.doGetChildCount()},doGetChildCount:function(){for(var e=0,t=this.getChildSubgroupNames(),r=0,n=t.length;r<n;++r){var i=this._getSubGroupChildCountMethod(t[r]);i&&(e+=i.apply(this))}return e},getChildAt:function(e){var t=this.getChildHolder();return t&&t!==this?t.getChildAt(e):this.doGetChildAt(e)},doGetChildAt:function(e){var t=this._getSubgroupChildIndexInfoFromChildIndex(e);if(t){var r=this._getSubGroupChildAtMethod(t.name);return r&&r.apply(this,[t.index])}return null},indexOfChild:function(e){var t=this.getChildHolder();return t&&t!==this?t.indexOfChild(e):this.doIndexOfChild(e)},doIndexOfChild:function(e){for(var t=this.getChildSubgroupNames(),r=0,n=t.length;r<n;++r){var i=this._getSubGroupChildIndexOfMethod(t[r]);if(i){var o=i.apply(this,[e]);if(o>=0)return this._getPrevSubgroupChildrenCount(t[r])+o}}return-1},hasChild:function(e){return this.indexOfChild(e)>=0},filterChildren:function(e,t){for(var r=[],n=0,i=this.getChildCount();n<i;++n){var o=this.getChildAt(n);if(o)if(e(o,n))r.push(o);else if(t&&o.filterChildren){var a=o.filterChildren(e,t);a&&a.length&&(r=r.concat(a))}}return r},iterateChildren:function(e,t){for(var r=0,n=this.getChildCount();r<n;++r){var i=this.getChildAt(r);i&&(e(i,r),t&&i.iterateChildren&&i.iterateChildren(e,t))}},removeChildAt:function(e){return this.doRemoveChildAt(e)},doRemoveChildAt:function(e){var t=this._getSubgroupChildIndexInfoFromChildIndex(e);if(t){var r=this._getSubGroupChildRemoveAtMethod(t.name);return r&&r.apply(this,[t.index])}return null},removeChild:function(e){var t=this.getChildHolder();return t&&t!==this?t.removeChild(e):this.doRemoveChild(e)},doRemoveChild:function(e){for(var t,r=this.getChildSubgroupNames(),n=0,i=r.length;n<i;++n){var o=this._getSubGroupChildRemoveMethod(r[n]);if(o&&(t=o.apply(this,[e])))return t}return null},removeChildren:function(e){for(var t=e.length-1;t>=0;--t)this.removeChild(e[t])},insertChildAt:function(e,t){var r=this.getChildHolder();return r&&r!==this?r.insertChildAt(e,t):this.doInsertChildAt(e,t)},doInsertChildAt:function(e,t){if(t>=this.getChildCount())return this.appendChild(e);var r=this._getSubgroupChildIndexInfoFromChildIndex(t);if(r){var n=this._getSubGroupChildInsertAtMethod(r.name);if(n){var i=n.apply(this,[e,r.index]);if(i>=0)return this._getPrevSubgroupChildrenCount(r.name)+i}}return-1},insertBefore:function(e,t){return this.insertChildBefore(e,t)},insertChildBefore:function(e,t){var r=this.getChildHolder();return r&&r!==this?r.insertChildBefore(e,t):this.doInsertChildBefore(e,t)},doInsertChildBefore:function(e,t){var r=this.getBelongChildSubGroupName(e);if(!r)return-1;if(t&&r!==this.getBelongChildSubGroupName(t))return-1;this.getChildSubgroupNames();var n=this._getSubGroupChildInsertBeforeMethod(r);return n?this._getPrevSubgroupChildrenCount(r)+n.apply(this,[e,t]):-1},appendChild:function(e){return this.insertChildBefore(e,null)},appendChildren:function(e){for(var t=0,r=e.length;t<r;++t)this.appendChild(e[t])},cascadeOnChildren:function(e){if(!e)return this;for(var t=0,r=this.getChildCount();t<r;++t){var n=this.getChildAt(t);n.cascadeOnChildren&&n.cascadeOnChildren(e),e(n)}return this},cascade:function(e){return e?(this.cascadeOnChildren(e),e(this),this):this},indexStackOfChild:function(e){var t=e.getParentList&&e.getParentList(),r=-1;if(t&&t.length&&(r=t.indexOf(this)),r<0)return null;for(var n,i=[],o=this,a=r-1;a>=0;--a){var s=t[a];if(!((n=o.indexOfChild(s))>=0))return null;i.push(n),o=s}return(n=o.indexOfChild(e))>=0?(i.push(n),i):null},getChildAtIndexStack:function(e){if(!e)return null;if((e=Kekule.ArrayUtils.toArray(e)).length<=0)return null;for(var t=this.getChildAt(e[0]),r=1,n=e.length;r<n;++r){if(!t||!t.getChildAt)return null;t=t.getChildAt(e[r])}return t},isEmpty:function(){return!1},clearIds:function(){this.setId(void 0);for(var e=0,t=this.getChildCount();e<t;++e){var r=this.getChildAt(e);r.clearIds&&r.clearIds()}},assignTo:function(e,t){var r=this.tryApplySuper("assignTo",[e]);return!t&&e.clearIds&&e.clearIds(),r},assign:function(e,t){return e.assignTo(this,t)},clone:function(e){var t=new(this.getClass());return this.assignTo(t,e),t},getScalarAttribCount:function(){var e=this.getScalarAttribs();return e?e.length:0},getScalarAttribAt:function(e){var t=this.getScalarAttribs();return t?t[e]:null},appendScalarAttrib:function(e){this.getScalarAttribs()||this.setPropStoreFieldValue("scalarAttribs",[]);var t=Kekule.ArrayUtils.pushUniqueEx(this.getScalarAttribs(),e);return t.isPushed&&(e.setParent(this),this.notifyScalarAttribsChange()),t.index},removeScalarAttribAt:function(e){if(this.getScalarAttribs()){var t=Kekule.ArrayUtils.removeAt(this.getScalarAttribs(),e);return t&&(t.setParent(null),this.notifyScalarAttribsChange()),t}return null},removeScalarAttrib:function(e){if(this.getScalarAttribs()){var t=Kekule.ArrayUtils.remove(this.getScalarAttribs(),e);return t&&(t.setParent(null),this.notifyScalarAttribsChange()),t}return null},getInfoKeys:function(){return this.getInfo()?Kekule.ObjUtils.getOwnedFieldNames(this.getInfo()):[]},getInfoValue:function(e){return this.getInfo()?this.getInfo()[e]:null},setInfoValue:function(e,t){this.doGetInfo(!0)[e]=t,this.notifyInfoChange()},getContainerBox:function(e,t){if(this.getAbsCoordOfMode){var r=this.getAbsCoordOfMode(e,t)||{},n=r;if(this.getSizeOfMode){var i=this.getSizeOfMode(e,t)||{};if(this.getObjAnchorPosition(e)===Kekule.ObjAnchorPosition.CENTER){var o=Kekule.CoordUtils.divide(i,2);e!==Kekule.CoordMode.COORD3D&&(o.y=-o.y),r=Kekule.CoordUtils.substract(r,o)}n=e===Kekule.CoordMode.COORD3D?Kekule.CoordUtils.add(r,this.getSizeOfMode(e,t)||{}):{x:(r.x||0)+(i.x||0),y:(r.y||0)-(i.y||0)}}return Kekule.BoxUtils.createBox(r,n)}return null},equal:function(e,t){return 0===this.compare(e,t)},compare:function(e,t){if(e===this)return 0;if(!e)return 1;var r,n=this.doGetActualCompareOptions(t);return 0===(r=n.customMethod?n.customMethod(this,e,n):this.doCompare(e,n))?0:r<0?-1:1},doGetActualCompareOptions:function(e){return e||{}},doCompare:function(e,t){if(e===this)return 0;if(this.getClass()!==(e.getClass&&e.getClass()))return this.getClassName()<(e.getClassName&&e.getClassName()||"")?-1:1;var r=this.doCompareOnProperties(e,t);if(!r&&t.extraComparisonProperties)for(var n=0,i=t.extraComparisonProperties.length;n<i;++n){var o=t.extraComparisonProperties[n];if(this.hasProperty(o)&&e.hasProperty&&e.hasProperty(o)){var a=this.getPropValue(o),s=e.getPropValue(o);if(0!==(r=this.doCompareOnValue(a,s,t)))break}}return r},doCompareOnProperties:function(e,t){var r;r=t.properties?t.properties:this.getComparisonPropNames(t);for(var n=t&&t.ignoredProperties,i=0,o=0,a=r.length;o<a;++o){var s=r[o];if(!(n&&n.indexOf(s)>=0)&&0!==(i=this.doCompareProperty(e,r[o],t)))return i}return 0},getComparisonPropNames:function(e){var t=this.doGetComparisonPropNames(e);return t||(t=this.doGetDefaultComparisonPropNames()),t},doGetComparisonPropNames:function(e){return null},doGetDefaultComparisonPropNames:function(){for(var e=[],t=this.getPropListOfScopes([Class.PropertyScope.PUBLIC,Class.PropertyScope.PUBLISHED]),r=0,n=t.getLength();r<n;++r){var i=t.getPropInfoAt(r);e.push(i.name)}return e},doCompareProperty:function(e,t,r){var n=e.getPropValue&&e.getPropValue(t),i=this.getPropValue(t);return i===n?0:this.doCompareOnValue(i,n,r)},doCompareOnValue:function(e,t,r){return Kekule.ObjComparer._compareValue(e,t,r)},attachCoordStickNodes:function(e){var t=Kekule.ArrayUtils,r=t.toArray(e),n=this.getAttachedCoordStickNodes();return t.pushUnique(n,r),this},detachCoordStickNodes:function(e){for(var t=Kekule.ArrayUtils,r=t.toArray(e),n=this.getAttachedCoordStickNodes(),i=0,o=r.length;i<o;++i)t.remove(n,r[i]);return this}}),Kekule.VarDependency={INDEPENDENT:0,DEPENDENT:1},Kekule.VarDefinition=Class.create(ObjectEx,{CLASS_NAME:"Kekule.VarDefinition",initialize:function(e){this.tryApplySuper("initialize"),this.beginUpdate();try{e&&this.setPropValues(e),Kekule.ObjUtils.isUnset(this.getDependency())&&this.setDependency(Kekule.VarDependency.INDEPENDENT)}finally{this.endUpdate()}},initProperties:function(){this.defineProp("name",{dataType:DataType.STRING}),this.defineProp("symbol",{dataType:DataType.STRING}),this.defineProp("unit",{dataType:DataType.STRING}),this.defineProp("units",{dataType:DataType.STRING,serializable:!1,scope:Class.PropertyScope.PUBLIC,getter:function(){return this.getUnit()},setter:function(e){this.setUnit(e)}}),this.defineProp("dependency",{dataType:DataType.INT,enumSource:Kekule.VarDependency}),this.defineProp("displayLabel",{dataType:DataType.VARIANT}),this.defineProp("description",{dataType:DataType.STRING}),this.defineProp("info",{dataType:DataType.HASH,getter:function(e){var t=this.getPropStoreFieldValue("info");return!t&&e&&(t={},this.setPropStoreFieldValue("info",t)),t}})},isIndependent:function(){return this.getDependency()!==Kekule.VarDependency.DEPENDENT},getInfoKeys:function(){return this.getInfo()?Kekule.ObjUtils.getOwnedFieldNames(this.getInfo()):[]},getInfoValue:function(e){return this.getInfo()?this.getInfo()[e]:null},setInfoValue:function(e,t){this.doGetInfo(!0)[e]=t,this.notifyInfoChange()},notifyInfoChange:function(){this.notifyPropSet("info",this.getPropStoreFieldValue("info"))},doCompare:function(e,t){for(var r,n=0,i=0,o=(r=t.method===Kekule.ComparisonMethod.CHEM_STRUCTURE?["unit","dependency","info"]:["name","symbol","unit","dependency","info","displayLabel","description"]).length;i<o;++i){var a=r[i],s=this.getPropValue(a),l=e.getPropValue(a);if(!(n=Kekule.ObjComparer._compareValue(s,l,t)))break}return n}}),Kekule.Scalar=Class.create(Kekule.ChemObject,{CLASS_NAME:"Kekule.Scalar",initialize:function(e,t,r,n){this.tryApplySuper("initialize",[e]),t&&this.setName(t),void 0!==r&&this.setValue(r),n&&this.setUnit(n)},initProperties:function(){this.defineProp("name",{dataType:DataType.STRING}),this.defineProp("value",{dataType:DataType.PRIMARY}),this.defineProp("errorValue",{dataType:DataType.PRIMARY}),this.defineProp("unit",{dataType:DataType.STRING}),this.defineProp("title",{dataType:DataType.STRING})},doGetComparisonPropNames:function(e){var t=this.tryApplySuper("doGetComparisonPropNames",[e]);return e.method===Kekule.ComparisonMethod.CHEM_STRUCTURE?(t||[]).concat(["name","value","errorValue","unit","title"]):t}}),Kekule.Scalar.create=function(e,t,r){var n=new Kekule.Scalar(null,null,e,t);return void 0!==r&&n.setErrorValue(r),n},Kekule.ChemObjList=Class.create(Kekule.ChemObject,{CLASS_NAME:"Kekule.ChemObjList",initialize:function(e,t,r){this.tryApplySuper("initialize",[e]),this.setPropStoreFieldValue("itemBaseClass",t),this.setPropStoreFieldValue("items",[]),this._transparent=!!r},initProperties:function(){this.defineProp("itemBaseClass",{dataType:DataType.CLASS,serializable:!1,scope:Class.PropertyScope.PUBLIC}),this.defineProp("items",{dataType:DataType.ARRAY,scope:Class.PropertyScope.PUBLIC,setter:null,getter:function(e){var t=this.getPropStoreFieldValue("items");return!t&&e&&(t=[],this.setPropStoreFieldValue("items",t)),t}})},loaded:function(e){this.ownerChanged(this.getOwner()),this.parentChanged(this.getParent()),this.tryApplySuper("loaded",[e])},parentChanged:function(e,t){this.changeAllItemsParent(),this.tryApplySuper("parentChanged",[e,t])},isEmpty:function(){return this.getItemCount()<=0},isValidItemType:function(e){var t=this.getItemBaseClass();return!t||e instanceof t},checkItemType:function(e){var t=this.isValidItemType(e);return t||Kekule.raise(Kekule.$L("ErrorMsg.LIST_ITEM_CLASS_MISMATCH")),t},notifyItemsChange:function(){this.notifyPropSet("items",this.getPropStoreFieldValue("items"))},getItemOwner:function(){return this.getOwner()},changeAllItemsOwner:function(){var e=this.getItems();if(e)for(var t=this.getItemOwner(),r=0,n=e.length;r<n;++r){var i=e[r];i&&i.setOwner&&i.setOwner(t)}},getItemParent:function(){return this._transparent&&this.getParent()||this},changeAllItemsParent:function(){var e=this.getItems();if(e)for(var t=this.getItemParent(),r=0,n=e.length;r<n;++r){var i=e[r];i&&i.setParent&&i.setParent(t)}},getItemCount:function(){var e=this.getPropStoreFieldValue("items");return e?e.length:0},getItemAt:function(e){var t=this.getPropStoreFieldValue("items");return t?t[e]:null},indexOf:function(e){var t=this.getPropStoreFieldValue("items");return t?t.indexOf(e):-1},indexOfItem:function(e){return this.indexOf(e)},getNextSiblingOfChild:function(e){var t=this.indexOf(e);return t>=0?this.getItemAt(t+1):null},getChildSubgroupNames:function(){return["item"].concat(this.tryApplySuper("getChildSubgroupNames"))},getBelongChildSubGroupName:function(e){return this.isValidItemType(e)?"item":this.tryApplySuper("getBelongChildSubGroupName",[e])},append:function(e){if(this.checkItemType(e),e){var t=Kekule.ArrayUtils.pushUniqueEx(this.doGetItems(!0),e);return t.isPushed&&(this.notifyItemsChange(),e.setOwner&&e.setOwner(this.getItemOwner()),e.setParent&&e.setParent(this.getItemParent())),t.index}return-1},insert:function(e,t){if(this.checkItemType(e),e){var r=Kekule.ArrayUtils.insertUniqueEx(this.doGetItems(!0),e,t);return r.isInserted&&(this.notifyItemsChange(),e.setOwner&&e.setOwner(this.getItemOwner()),e.setParent&&e.setParent(this.getItemParent())),r.index}return-1},insertItemAt:function(e,t){return this.insert(e,t)},insertItemBefore:function(e,t){if(t){var r=this.indexOfItem(t);return r>=0?this.insertItemAt(e,r):this.appendItem(e)}return this.append(e)},removeAt:function(e){if(this.getItems()){var t=Kekule.ArrayUtils.removeAt(this.getItems(),e);return t&&(t.setOwner&&t.setOwner(null),t.setParent&&t.setParent(null),this.notifyItemsChange()),t}},removeItemAt:function(e){return this.removeAt(e)},remove:function(e){if(this.getItems()){var t=Kekule.ArrayUtils.remove(this.getItems(),e);return t&&(t.setOwner&&t.setOwner(null),t.setParent&&t.setParent(null),this.notifyItemsChange()),t}},removeItem:function(e){return this.remove(e)},toArray:function(){return this.getItems()||[]},getContainerBox:function(e,t){for(var r,n=this.toArray(),i=0,o=n.length;i<o;++i){var a=n[i],s=a.getContainerBox?a.getContainerBox(e,t):null;s&&(r=r?Kekule.BoxUtils.getContainerBox(r,s):Kekule.BoxUtils.clone(s))}return r},getComparisonPropNames:function(e){var t=this.tryApplySuper("getComparisonPropNames",[e]);return t&&this._transparent&&(t=Kekule.ArrayUtils.exclude(t,["parent","owner"])),t}}),Kekule.ChemSpaceElement=Class.create(Kekule.ChemObject,{CLASS_NAME:"Kekule.ChemSpaceElement",initialize:function(e){this.tryApplySuper("initialize",[e]);var t=new Kekule.ChemObjList(null,Kekule.ChemObject,!0);t.setParent(this),t.addEventListener("change",function(){this.objectChange(["children"])},this),this.setPropStoreFieldValue("children",t)},initProperties:function(){this.defineProp("children",{dataType:"Kekule.ChemObjList",scope:Class.PropertyScope.PUBLIC,setter:function(e){var t=this.getChildren();t&&t.finalize(),e&&(e.setParent(this),e.setOwner(this.getOwner()),e._transparent=!0),this.setPropStoreFieldValue("children",e)}})},loaded:function(e){var t=this.getChildren();t&&(t.parentChanged(this),t.ownerChanged(this.getOwner())),this.tryApplySuper("loaded",[e])},ownerChanged:function(e,t){this.getChildren().setOwner(e),this.tryApplySuper("ownerChanged",[e,t])},_removeChildObj:function(e){var t=this.indexOfChild(e);t>=0&&this.removeChildAt(t),this.tryApplySuper("_removeChildObj",[e])},getChildHolder:function(){return this.getChildren()},getNextSiblingOfChild:function(e){return this.getChildren().getNextSiblingOfChild(e)},insertChild:function(e,t){return this.getChildren().insert(e,t)}}),Kekule.ChemSpace=Class.create(Kekule.ChemObject,{CLASS_NAME:"Kekule.ChemSpace",initialize:function(e){this.tryApplySuper("initialize",[e]),this._autoIdMap={},this._enableObjRefRelations=!0,this._autoUpdateObjRefRelations=!0,this.setPropStoreFieldValue("enableAutoId",!0),this.setPropStoreFieldValue("ownedObjs",[]);var t=new Kekule.ChemSpaceElement;this.setPropStoreFieldValue("root",t),this.setPropStoreFieldValue("objRefRelationManager",new Kekule.ObjRefRelationManager(this)),t.setParent(this),t.setOwner(this)},initProperties:function(){this.defineProp("ownedObjs",{dataType:DataType.ARRAY,serializable:!1,setter:null,scope:Class.PropertyScope.PUBLIC}),this.defineProp("root",{dataType:"Kekule.ChemSpaceElement",setter:null}),this.defineProp("enableAutoId",{dataType:DataType.BOOL}),this.defineProp("objScreenLengthRatio",{dataType:DataType.FLOAT,serializable:!1,scope:Class.PropertyScope.PRIVATE}),this.defineProp("screenSize",{dataType:DataType.HASH,getter:function(){var e=this.getPropStoreFieldValue("screenSize")||{};return{x:e.x,y:e.y}},setter:function(e){var t=this.getPropStoreFieldValue("screenSize");t||(t={},this.setPropStoreFieldValue("screenSize",t)),t.x=e.x,t.y=e.y}}),this.defineProp("objRefRelationManager",{dataType:"Kekule.ObjRefRelationManager",serializable:!1,scope:Class.PropertyScope.PRIVATE,setter:null})},loaded:function(e){var t=this.getRoot();t&&(t.setParent(this),t.setOwner(this)),this.tryApplySuper("loaded",[e]),this.notifyOwnerLoaded()},notifyOwnedObjsChange:function(){this.notifyPropSet("ownedObjs",this.getPropStoreFieldValue("ownedObjs"))},_notifyOwnedObjsSpaceUpdate:function(e,t,r){for(var n=0,i=this.getOwnedObjCount();n<i;++n){var o=this.getOwnedObjAt(n);o&&o.objSpaceOfOwnerUpdated&&o.objSpaceOfOwnerUpdated(e,t,r)}if(this._enableObjRefRelations&&this._autoUpdateObjRefRelations&&r===Kekule.ObjectTreeOperation.REMOVE){var a=Kekule.ArrayUtils,s=this.findObjRefRelations({dest:e})||[];for(n=0,i=s.length;n<i;++n){var l=s[n];if(l.srcProp.autoUpdate){var u=l.dest,c=a.isArray(u)?a.exclude(u,[e]):null;l.srcObj.setPropValue(l.srcProp.name,c)}}}},notifyOwnerLoaded:function(){for(var e=this.getOwnedObjs()||[],t=0,r=e.length;t<r;++t){var n=e[t];n&&n._ownerObjectLoaded&&n._ownerObjectLoaded(this)}},getChildren:function(){return this.getRoot().getChildren().toArray()},getChildHolder:function(){return this.getRoot()},getNextSiblingOfChild:function(e){return this.getRoot().getNextSiblingOfChild(e)},insertChild:function(e,t){return this.getRoot().insertChild(e,t)},indexStackOfChild:function(e){return this.getRoot().indexStackOfChild(e)},getChildAtIndexStack:function(e){return this.getRoot().getChildAtIndexStack(e)},getObjById:function(e){for(var t=0,r=this.getOwnedObjCount();t<r;++t){var n=this.getOwnedObjAt(t);if(n.getId&&n.getId()===e)return n}return null},getAutoId:function(e,t){r=e&&e.getAutoIdPrefix?e.getAutoIdPrefix():"o";var r=e.getAutoIdPrefix?e.getAutoIdPrefix():"o";n=Kekule.ObjUtils.notUnset(t)?t:1;var n=this._getAutoIdIndex(r,n);return this._autoIdMap[r]=n,r+Number(n).toString()},_getAutoIdIndex:function(e,t){for(var r=t||0,n=e+Number(r).toString();this.getObjById(n);)++r,n=e+Number(r).toString();return r},assignAutoIdToObj:function(e){if(e.setId){var t=this.getAutoId(e);e.setId(t)}},getOwnedObjCount:function(){return this.getOwnedObjs().length},getOwnedObjAt:function(e){return this.getOwnedObjs()[e]},indexOfOwnedObj:function(e){return this.getOwnedObjs().indexOf(e)},_appendOwnedObj:function(e){this.indexOfOwnedObj(e)>=0||(this.getEnableAutoId()&&e.getId&&!e.getId()&&this.assignAutoIdToObj(e)