Clazz.declarePackage("J.shapecgo");
Clazz.load(["J.shape.MeshCollection"], "J.shapecgo.CGO", ["java.util.Hashtable", "JU.AU", "$.Lst", "$.PT", "$.SB", "J.shapecgo.CGOMesh"], function(){
var c$ = Clazz.decorateAsClass(function(){
this.cmeshes = null;
this.cgoMesh = null;
this.useColix = false;
this.newScale = 0;
this.indicatedModelIndex = -2147483648;
this.indicatedWidth = 0;
Clazz.instantialize(this, arguments);}, J.shapecgo, "CGO", J.shape.MeshCollection);
Clazz.prepareFields (c$, function(){
this.cmeshes =  new Array(4);
});
Clazz.makeConstructor(c$, 
function(){
Clazz.superConstructor (this, J.shapecgo.CGO, []);
this.myType = "CGO";
this.htObjects =  new java.util.Hashtable();
});
Clazz.defineMethod(c$, "initCGO", 
function(){
this.indicatedModelIndex = -2147483648;
this.indicatedWidth = 0;
});
Clazz.overrideMethod(c$, "allocMesh", 
function(thisID, m){
var index = this.meshCount++;
this.meshes = this.cmeshes = JU.AU.ensureLength(this.cmeshes, this.meshCount * 2);
this.currentMesh = this.cgoMesh = this.cmeshes[index] = (m == null ?  new J.shapecgo.CGOMesh(this.vwr, thisID, this.colix, index) : m);
this.currentMesh.color = this.color;
this.currentMesh.index = index;
this.currentMesh.useColix = this.useColix;
this.currentMesh.modelIndex = this.indicatedModelIndex;
if (thisID != null && thisID !== "+PREVIOUS_MESH+" && this.htObjects != null) this.htObjects.put(thisID.toUpperCase(), this.currentMesh);
}, "~S,J.shape.Mesh");
Clazz.overrideMethod(c$, "setProperty", 
function(propertyName, value, bs){
if ("init" === propertyName) {
this.initCGO();
this.setPropertySuper("init", value, bs);
return;
}if ("cacheAll" === propertyName) {
for (var i = this.meshCount; --i >= 0; ) {
if (this.meshes[i] != null) {
(this.meshes[i]).doCache = true;
}}
return;
}if ("cache" === propertyName) {
if (this.cgoMesh != null) this.cgoMesh.doCache = true;
return;
}if ("setCGO" === propertyName) {
var map = value;
var list = map.get("cgoMeshInfo");
this.setProperty("init", null, null);
var n = list.size() - 1;
this.setProperty("thisID", list.get(n), null);
propertyName = "set";
this.setProperty("set", list, null);
this.cgoMesh.width = (map.get("cgoMeshWidth")).floatValue() / 20;
return;
}if ("modelIndex" === propertyName) {
this.indicatedModelIndex = Math.max((value).intValue(), -1);
return;
}if ("width" === propertyName) {
this.indicatedWidth = (value).floatValue();
return;
}if ("set" === propertyName) {
if (this.cgoMesh == null) {
this.allocMesh(null, null);
this.cgoMesh.colix = this.colix;
this.cgoMesh.color = this.color;
this.cgoMesh.useColix = this.useColix;
}this.cgoMesh.modelIndex = (this.indicatedModelIndex == -2147483648 ? this.vwr.am.cmi : this.indicatedModelIndex);
if (this.indicatedWidth != 0) this.cgoMesh.width = this.indicatedWidth;
this.cgoMesh.isValid = this.setCGO(value);
if (this.cgoMesh.isValid) {
this.scale(this.cgoMesh, this.newScale);
this.cgoMesh.initialize(1073741964, null, null);
this.cgoMesh.title = this.title;
this.cgoMesh.visible = true;
}this.clean();
return;
}if (propertyName === "deleteModelAtoms") {
this.deleteModels(((value)[2])[0]);
return;
}this.setPropertySuper(propertyName, value, bs);
}, "~S,~O,JU.BS");
Clazz.defineMethod(c$, "deleteModels", 
function(modelIndex){
for (var i = this.meshCount; --i >= 0; ) {
var m = this.meshes[i];
if (m == null) continue;
var deleteMesh = (m.modelIndex == modelIndex);
if (deleteMesh) {
this.meshCount--;
this.deleteMeshElement(i);
} else if (this.meshes[i].modelIndex > modelIndex) {
this.meshes[i].modelIndex--;
}}
this.resetObjects();
}, "~N");
Clazz.overrideMethod(c$, "getProperty", 
function(property, index){
if (property === "command") return this.getCommand(this.cgoMesh);
return this.getPropMC(property, index);
}, "~S,~N");
Clazz.overrideMethod(c$, "getPropertyData", 
function(property, data){
if (property === "data") return J.shapecgo.CGOMesh.getData(data);
return this.getPropDataMC(property, data);
}, "~S,~A");
Clazz.defineMethod(c$, "deleteMeshElement", 
function(i){
if (this.meshes[i] === this.currentMesh) this.currentMesh = this.cgoMesh = null;
this.meshes = this.cmeshes = JU.AU.deleteElements(this.meshes, i, 1);
}, "~N");
Clazz.overrideMethod(c$, "setPropertySuper", 
function(propertyName, value, bs){
this.currentMesh = this.cgoMesh;
this.setPropMC(propertyName, value, bs);
this.cgoMesh = this.currentMesh;
}, "~S,~O,JU.BS");
Clazz.overrideMethod(c$, "clean", 
function(){
for (var i = this.meshCount; --i >= 0; ) if (this.meshes[i] == null || this.cmeshes[i].cmds == null || this.cmeshes[i].cmds.size() == 0) this.deleteMeshI(i);

});
Clazz.defineMethod(c$, "setCGO", 
function(data){
if (this.cgoMesh == null) this.allocMesh(null, null);
this.cgoMesh.clear("cgo");
return this.cgoMesh.set(data);
}, "JU.Lst");
Clazz.defineMethod(c$, "scale", 
function(mesh, newScale){
}, "J.shape.Mesh,~N");
Clazz.overrideMethod(c$, "getShapeDetail", 
function(){
var V =  new JU.Lst();
for (var i = 0; i < this.meshCount; i++) {
var mesh = this.cmeshes[i];
var info =  new java.util.Hashtable();
info.put("visible", mesh.visible ? Boolean.TRUE : Boolean.FALSE);
info.put("ID", (mesh.thisID == null ? "<noid>" : mesh.thisID));
info.put("command", this.getCommand(mesh));
V.addLast(info);
}
return V;
});
Clazz.overrideMethod(c$, "getShapeState", 
function(){
var sb =  new JU.SB();
var modelCount = this.ms.mc;
for (var i = 0; i < this.meshCount; i++) {
var mesh = this.cmeshes[i];
if (mesh == null || mesh.cmds == null || mesh.modelIndex >= modelCount) continue;
if (mesh.doCache) {
sb.append("\n");
J.shape.Shape.appendCmd(sb, this.myType + " ID " + JU.PT.esc(mesh.thisID) + " delete");
}sb.append(this.getCommand2(mesh, modelCount));
if (!mesh.visible) sb.append(" " + this.myType + " ID " + JU.PT.esc(mesh.thisID) + " off;\n");
}
return sb.toString();
});
Clazz.defineMethod(c$, "getCommand", 
function(mesh){
if (mesh != null) return this.getCommand2(mesh, mesh.modelIndex);
var sb =  new JU.SB();
var key = (this.explicitID && this.previousMeshID != null && JU.PT.isWild(this.previousMeshID) ? this.previousMeshID : null);
var list = this.getMeshList(key, false);
for (var i = list.size(); --i >= 0; ) {
var m = list.get(i);
sb.append(this.getCommand2(m, m.modelIndex));
}
return sb.toString();
}, "J.shape.Mesh");
Clazz.defineMethod(c$, "getCommand2", 
function(mesh, modelCount){
var cmesh = mesh;
var str =  new JU.SB();
var iModel = mesh.modelIndex;
str.append("  CGO ID ").append(JU.PT.esc(mesh.thisID));
if (cmesh.doCache) {
if (iModel >= -1 && modelCount > 1) str.append(" modelIndex " + iModel);
if (cmesh.width > 0) str.append(" width " + cmesh.width);
var n = cmesh.cmds.size();
if (cmesh.cmdsAllNumbers) {
cmesh.encodeCommands(str);
} else {
str.append(" [");
for (var i = 0; i < n; i++) str.append(" " + cmesh.cmds.get(i));

str.append(" ];\n");
}} else {
str.append(";\n");
}J.shape.Shape.appendCmd(str, cmesh.getState("cgo"));
if (cmesh.useColix) J.shape.Shape.appendCmd(str, J.shape.Shape.getColorCommandUnk("cgo", cmesh.colix, this.translucentAllowed));
return str.toString();
}, "J.shape.Mesh,~N");
Clazz.overrideMethod(c$, "setModelVisibilityFlags", 
function(bsModels){
for (var i = 0; i < this.meshCount; i++) {
var m = this.cmeshes[i];
if (m != null) m.setVisibilityFlags(m.isValid && m.visible && (m.modelIndex < 0 || bsModels.get(m.modelIndex)) ? this.vf : 0);
}
}, "JU.BS");
Clazz.overrideMethod(c$, "checkObjectHovered", 
function(x, y, bsVisible){
if (!this.vwr.getDrawHover()) return false;
var s = this.findValue(x, y, false, bsVisible);
if (s == null) return false;
this.vwr.hoverOnPt(x, y, s, this.pickedMesh.thisID, this.pickedPt);
return true;
}, "~N,~N,JU.BS");
Clazz.defineMethod(c$, "findValue", 
function(x, y, isPicking, bsVisible){
var dmin2 = 100;
if (this.vwr.gdata.isAntialiased()) {
x <<= 1;
y <<= 1;
dmin2 <<= 1;
}var pickedVertex = -1;
var m = null;
for (var i = 0; i < this.meshCount; i++) {
m = this.cmeshes[i];
if (!this.isPickable(m, bsVisible)) continue;
if (m.vs != null) {
var vertices = m.vs;
for (var k = m.vs.length; --k >= 0; ) {
var v = vertices[k];
var d2 = this.coordinateInRange(x, y, v, dmin2, this.ptXY);
if (d2 >= 0) {
dmin2 = d2;
pickedVertex = k;
this.pickedMesh = m;
this.pickedPt = v;
}}
}if (pickedVertex != -1) break;
}
return (pickedVertex == -1 ? null : m.thisID);
}, "~N,~N,~B,JU.BS");
});
;//5.0.1-v7 Mon Aug 17 10:07:10 MDT 2026
