Class: Base3DRenderer

Kekule.Render. Base3DRenderer

new Base3DRenderer(chemObj, drawBridge, options, parent)

A base implementation of 2D chem object renderer. You can call renderer.draw(context, chemObj, baseCoord, options) to draw the 2D structure, where options can contain the settings of drawing style (strokeWidth, color...) and tranform params (including scale, zoom, translate, rotateAngle, cameraPos...). The options can also have a autoCamera (Bool) field, if autoCamera is true, the cameraPos value will be determinate by renderer. Note: zoom is not the same as scale. When scale is set or calculated, zoom will multiply on it and get the actual scale ratio. for example, scale is 100 and zoom is 1.5, then the actual scale value will be 150.
Parameters:
Name Type Description
chemObj Kekule.ChemObject Object to be drawn.
drawBridge Object A object that implements the actual draw job.
options Hash Options to draw object. //@param {Object} renderConfigs Global configuration for rendering. // This property should be an instance of Kekule.Render.Render3DConfigs.
parent Kekule.ObjectEx Parent object of this renderer, usually another renderer or an instance of Kekule.Render.ChemObjPainter, or null.
Properties:
Name Type Description
drawBridge Object A object that implements the actual draw job. Read only.
Source:

Extends

Methods

beginUpdateRenderer()

Call this method before a series of rendered element updating job (for instance, call update method) to avoid unnecessary redraw.
Inherited From:
Source:

canModifyGraphic(context) → {Bool}

Whether current renderer can modify elements drawn on context.
Parameters:
Name Type Description
context Object
Inherited From:
Source:
Returns:
Type
Bool

clear(context) → {Bool}

Clear whole chemObj on context.
Parameters:
Name Type Description
context Object
Inherited From:
Source:
Returns:
Whether the actual clear job is done.
Type
Bool

doClear(context) → {Bool}

Do actual job of clear. This function should return true after actual work done. Otherwise false should be returned.
Parameters:
Name Type Description
context Object
Inherited From:
Source:
Returns:
Type
Bool

doClearSelf(context) → {Bool}

Do actual job of clear self (without children). Descendants should override this method. This function should return true after actual work done. Otherwise false should be returned.
Parameters:
Name Type Description
context Object
Inherited From:
Source:
Returns:
Type
Bool

draw(context, baseCoord, options) → {Object}

Draw an instance of ChemObject to context. The actual job is done in doDraw method. Descendants should override doDraw.
Parameters:
Name Type Description
context Object Context to be drawn, such as Canvas, SVG, VML and so on.
baseCoord Hash Base coord to draw this object, can be null to use coord of chemObj itself. This coord is based on context.
options Hash Draw options, such as draw rectangle, draw style, zoom and so on. Different renderer may requires different option params. In options hash object, there may be one special array field: partialDrawObjs. If this field is set, then only chem objects in this array will be actually drawn.
Inherited From:
Source:
Returns:
Drawn element on context (such as SVG) or null on direct context (such as canvas).
Type
Object

endUpdateRenderer()

Call this method after a series of rendered element updateing job, notify the renderer to redraw the context.
Inherited From:
Source:

estimateObjBox(context, options, allowCoordBorrow) → {Hash}

Estimate the bound box around current chemObj (in chem coord system).
Parameters:
Name Type Description
context Object
options Object
allowCoordBorrow Bool
Inherited From:
Source:
Returns:
A 2D or 3D box, in chemObj's coord system.
Type
Hash

estimateRenderBox(context, baseCoord, options, allowCoordBorrow) → {Hash}

Estimate the bound box need to render current chemObj (in context coord system). Note: this method should not be called outside draw(). Otherwise the result may be unreliable or even no result can be returned.
Parameters:
Name Type Description
context Object
baseCoord Hash Center coord in context to draw object. Can be null.
options Object
allowCoordBorrow Bool
Inherited From:
Source:
Returns:
A 2D or 3D box, in context's coord system.
Type
Hash

getAutoBaseCoord(drawOptions) → {Hash}

Auto calculate draw context coord by coord of chem obj. When no baseCoord is provided in draw method, this result may be used instead.
Parameters:
Name Type Description
drawOptions Hash
Inherited From:
Source:
Returns:
Type
Hash

getCameraProps(context) → {Hash}

Returns properties of current camera, including position(coord), fov, aspect and so on.
Parameters:
Name Type Description
context Object
Source:
Returns:
Type
Hash

getCoordMode() → {Int}

Report coord mode of this renderer.
Inherited From:
Source:
Returns:
Value from Kekule.CoordMode.
Type
Int

getLightCount(context) → {Int}

Returns count of lights in context.
Parameters:
Name Type Description
context Object
Source:
Returns:
Type
Int

getLightProps(context, lightIndex) → {Hash}

Get properties of light at index.
Parameters:
Name Type Description
context Object
lightIndex Int
Source:
Returns:
Type
Hash

getRenderCache() → {Hash}

Returns draw params (center coord, options, matrix...) on last draw process on context.
Inherited From:
Source:
Returns:
Type
Hash

isChemObjRenderedBySelf(context, obj) → {boolean}

Indicate whether a chemObj (including childObj) is rendered by this renderer, or should be rendered by this renderer. Descendants may override this method.
Parameters:
Name Type Description
context Object
obj Object
Inherited From:
Source:
Returns:
Type
boolean

isChemObjRenderedDirectlyBySelf(context, obj) → {boolean}

Indicate whether a chemObj (including childObj) is rendered directly by this renderer (not by child renderers). Descendants may override this method.
Parameters:
Name Type Description
context Object
obj Object
Inherited From:
Source:
Returns:
Type
boolean

isRootRenderer()

Check if current renderer is the topmost one (without parent renderer, but maybe has parent painter).
Inherited From:
Source:

isUpdatingRenderer() → {Bool}

Check if beginUpdateRenderer is called and endUpdateRenderer is not called yet.
Inherited From:
Source:
Returns:
Type
Bool

redraw(context)

Redraw previous object on context with same draw options. Should not be called before draw.
Parameters:
Name Type Description
context Object
Inherited From:
Source:

removeDrawnElem(context, elem)

Remove an element in context.
Parameters:
Name Type Description
context Object
elem Object
Source:

setCameraProps(context, props)

Set properties of current camera, including position(coord), fov, aspect and so on.
Parameters:
Name Type Description
context Object
props Hash
Source:

setLightProps(context, lightIndex, props)

Get properties of light at index.
Parameters:
Name Type Description
context Object
lightIndex Int
props Hash
Source:

transformContextCoordToScreen(context, coord) → {Hash}

Transform a context based coord to screen based one (usually in pixel).
Parameters:
Name Type Description
context Object
coord Hash
Inherited From:
Source:
Returns:
Type
Hash

transformCoordToContext(context, chemObj, coord) → {Hash}

Transform a chemObj based inner coord to context based one.
Parameters:
Name Type Description
context Object
chemObj Kekule.ChemObject
coord Hash
Inherited From:
Source:
Returns:
Type
Hash

transformCoordToObj(context, chemObj, coord) → {Hash}

Transform a context based coord to inner coord basd on chemObj coord system.
Parameters:
Name Type Description
context Object
chemObj Kekule.ChemObject
coord Hash
Inherited From:
Source:
Returns:
Type
Hash

update(context, updatedObjDetails, updateType) → {Bool}

Update a child object inside chemObj. Must be called after draw.
Parameters:
Name Type Description
context Object
updatedObjDetails Variant Object detail containing field {obj, propNames} or array of details.
updateType Int Value from Kekule.Render.ObjectUpdateType
Inherited From:
Source:
Returns:
Type
Bool

updateEx(updateInfos) → {Bool}

Do a update job according to info provided by updateItems. Must be called after draw.
Parameters:
Name Type Description
updateInfos Array Each item has format: {context, items: [{updateType, updatedObjDetails: [{obj, propNames}]}]}
Inherited From:
Source:
Returns:
Type
Bool

Events

clear

Invoked when whole chem object (molecule, reaction...) is cleared from context. event param of it has two fields: {context, obj} NOTE: this event is not well implemented and may be buggy.
Inherited From:
Source:

draw

Invoked when whole chem object (molecule, reaction...) is drawn in context. event param of it has two fields: {context, obj}
Inherited From:
Source:

prepareDrawing

Invoked when whole chem object (molecule, reaction...) is prepared to be drawn in context. event param of it has two fields: {context, obj}
Inherited From:
Source:

updateBasicDrawObject

Invoked when a basic object (node, connector, glyph...) is drawn, updated or removed. event param of it has fields: {obj, parentObj, boundInfo, updateType} where boundInfo provides the bound box information of this object on context. It has the following fields: { context: drawing context object obj: drawn object parentObj: parent of drawn object boundInfo: a hash containing info of bound, including fields: { shapeType: value from Kekule.Render.MetaShapeType or Kekule.Render.Meta3DShapeType. coords: [Array of coords] } updateType: add, modify or remove } boundInfo may also be a array for complex situation (such as multicenter bond): [boundInfo1, boundInfo2, boundInfo3...]. Note that in removed event, boundInfo may be null.
Inherited From:
Source:

Kekule.Render. Base3DRenderer

new Base3DRenderer()

Source:

Methods

beginUpdateRenderer()

Call this method before a series of rendered element updating job (for instance, call update method) to avoid unnecessary redraw.
Inherited From:
Source:

canModifyGraphic(context) → {Bool}

Whether current renderer can modify elements drawn on context.
Parameters:
Name Type Description
context Object
Inherited From:
Source:
Returns:
Type
Bool

clear(context) → {Bool}

Clear whole chemObj on context.
Parameters:
Name Type Description
context Object
Inherited From:
Source:
Returns:
Whether the actual clear job is done.
Type
Bool

doClear(context) → {Bool}

Do actual job of clear. This function should return true after actual work done. Otherwise false should be returned.
Parameters:
Name Type Description
context Object
Inherited From:
Source:
Returns:
Type
Bool

doClearSelf(context) → {Bool}

Do actual job of clear self (without children). Descendants should override this method. This function should return true after actual work done. Otherwise false should be returned.
Parameters:
Name Type Description
context Object
Inherited From:
Source:
Returns:
Type
Bool

draw(context, baseCoord, options) → {Object}

Draw an instance of ChemObject to context. The actual job is done in doDraw method. Descendants should override doDraw.
Parameters:
Name Type Description
context Object Context to be drawn, such as Canvas, SVG, VML and so on.
baseCoord Hash Base coord to draw this object, can be null to use coord of chemObj itself. This coord is based on context.
options Hash Draw options, such as draw rectangle, draw style, zoom and so on. Different renderer may requires different option params. In options hash object, there may be one special array field: partialDrawObjs. If this field is set, then only chem objects in this array will be actually drawn.
Inherited From:
Source:
Returns:
Drawn element on context (such as SVG) or null on direct context (such as canvas).
Type
Object

endUpdateRenderer()

Call this method after a series of rendered element updateing job, notify the renderer to redraw the context.
Inherited From:
Source:

estimateObjBox(context, options, allowCoordBorrow) → {Hash}

Estimate the bound box around current chemObj (in chem coord system).
Parameters:
Name Type Description
context Object
options Object
allowCoordBorrow Bool
Inherited From:
Source:
Returns:
A 2D or 3D box, in chemObj's coord system.
Type
Hash

estimateRenderBox(context, baseCoord, options, allowCoordBorrow) → {Hash}

Estimate the bound box need to render current chemObj (in context coord system). Note: this method should not be called outside draw(). Otherwise the result may be unreliable or even no result can be returned.
Parameters:
Name Type Description
context Object
baseCoord Hash Center coord in context to draw object. Can be null.
options Object
allowCoordBorrow Bool
Inherited From:
Source:
Returns:
A 2D or 3D box, in context's coord system.
Type
Hash

getAutoBaseCoord(drawOptions) → {Hash}

Auto calculate draw context coord by coord of chem obj. When no baseCoord is provided in draw method, this result may be used instead.
Parameters:
Name Type Description
drawOptions Hash
Inherited From:
Source:
Returns:
Type
Hash

getCameraProps(context) → {Hash}

Returns properties of current camera, including position(coord), fov, aspect and so on.
Parameters:
Name Type Description
context Object
Source:
Returns:
Type
Hash

getCoordMode() → {Int}

Report coord mode of this renderer.
Inherited From:
Source:
Returns:
Value from Kekule.CoordMode.
Type
Int

getLightCount(context) → {Int}

Returns count of lights in context.
Parameters:
Name Type Description
context Object
Source:
Returns:
Type
Int

getLightProps(context, lightIndex) → {Hash}

Get properties of light at index.
Parameters:
Name Type Description
context Object
lightIndex Int
Source:
Returns:
Type
Hash

getRenderCache() → {Hash}

Returns draw params (center coord, options, matrix...) on last draw process on context.
Inherited From:
Source:
Returns:
Type
Hash

isChemObjRenderedBySelf(context, obj) → {boolean}

Indicate whether a chemObj (including childObj) is rendered by this renderer, or should be rendered by this renderer. Descendants may override this method.
Parameters:
Name Type Description
context Object
obj Object
Inherited From:
Source:
Returns:
Type
boolean

isChemObjRenderedDirectlyBySelf(context, obj) → {boolean}

Indicate whether a chemObj (including childObj) is rendered directly by this renderer (not by child renderers). Descendants may override this method.
Parameters:
Name Type Description
context Object
obj Object
Inherited From:
Source:
Returns:
Type
boolean

isRootRenderer()

Check if current renderer is the topmost one (without parent renderer, but maybe has parent painter).
Inherited From:
Source:

isUpdatingRenderer() → {Bool}

Check if beginUpdateRenderer is called and endUpdateRenderer is not called yet.
Inherited From:
Source:
Returns:
Type
Bool

redraw(context)

Redraw previous object on context with same draw options. Should not be called before draw.
Parameters:
Name Type Description
context Object
Inherited From:
Source:

removeDrawnElem(context, elem)

Remove an element in context.
Parameters:
Name Type Description
context Object
elem Object
Source:

setCameraProps(context, props)

Set properties of current camera, including position(coord), fov, aspect and so on.
Parameters:
Name Type Description
context Object
props Hash
Source:

setLightProps(context, lightIndex, props)

Get properties of light at index.
Parameters:
Name Type Description
context Object
lightIndex Int
props Hash
Source:

transformContextCoordToScreen(context, coord) → {Hash}

Transform a context based coord to screen based one (usually in pixel).
Parameters:
Name Type Description
context Object
coord Hash
Inherited From:
Source:
Returns:
Type
Hash

transformCoordToContext(context, chemObj, coord) → {Hash}

Transform a chemObj based inner coord to context based one.
Parameters:
Name Type Description
context Object
chemObj Kekule.ChemObject
coord Hash
Inherited From:
Source:
Returns:
Type
Hash

transformCoordToObj(context, chemObj, coord) → {Hash}

Transform a context based coord to inner coord basd on chemObj coord system.
Parameters:
Name Type Description
context Object
chemObj Kekule.ChemObject
coord Hash
Inherited From:
Source:
Returns:
Type
Hash

update(context, updatedObjDetails, updateType) → {Bool}

Update a child object inside chemObj. Must be called after draw.
Parameters:
Name Type Description
context Object
updatedObjDetails Variant Object detail containing field {obj, propNames} or array of details.
updateType Int Value from Kekule.Render.ObjectUpdateType
Inherited From:
Source:
Returns:
Type
Bool

updateEx(updateInfos) → {Bool}

Do a update job according to info provided by updateItems. Must be called after draw.
Parameters:
Name Type Description
updateInfos Array Each item has format: {context, items: [{updateType, updatedObjDetails: [{obj, propNames}]}]}
Inherited From:
Source:
Returns:
Type
Bool

Events

clear

Invoked when whole chem object (molecule, reaction...) is cleared from context. event param of it has two fields: {context, obj} NOTE: this event is not well implemented and may be buggy.
Inherited From:
Source:

draw

Invoked when whole chem object (molecule, reaction...) is drawn in context. event param of it has two fields: {context, obj}
Inherited From:
Source:

prepareDrawing

Invoked when whole chem object (molecule, reaction...) is prepared to be drawn in context. event param of it has two fields: {context, obj}
Inherited From:
Source:

updateBasicDrawObject

Invoked when a basic object (node, connector, glyph...) is drawn, updated or removed. event param of it has fields: {obj, parentObj, boundInfo, updateType} where boundInfo provides the bound box information of this object on context. It has the following fields: { context: drawing context object obj: drawn object parentObj: parent of drawn object boundInfo: a hash containing info of bound, including fields: { shapeType: value from Kekule.Render.MetaShapeType or Kekule.Render.Meta3DShapeType. coords: [Array of coords] } updateType: add, modify or remove } boundInfo may also be a array for complex situation (such as multicenter bond): [boundInfo1, boundInfo2, boundInfo3...]. Note that in removed event, boundInfo may be null.
Inherited From:
Source: