The Clean2D webservice is not available at startup (its icon is missing from the toolbar). You have an input form where you can specify the location of the Clean2D webservice. As you apply the form, it disappears and the Clean2D service is registered to the sketcher with the given URL. After that, the Clean icon appears on the toolbar and you can perform clean operation on the drawn structure.
Clean operation can fail in the following cases:
Initialize the input form at startup. When the Apply Service button is submitted, the setServices
function of the sketcher
is called to apply the given service to the editor. The function expects a JavaScript object that describes one or more webservices.
Finally, hide the input form to prevent applying further services.
$(document).ready(function handleDocumentReady (e) {
MarvinJSUtil.getEditor("#sketch").then(function (sketcherInstance) {
marvinSketcherInstance = sketcherInstance;
resetForm();
initControls();
}, function () {
alert("Cannot retrieve sketcher instance from iframe");
});
});
function initControls () {
$("#restoreButton").on("click", resetForm);
$("#applyButton").on("click", function (e) {
submitService($("#clean2dws-location").val());
});
}
function resetForm() {
$("#clean2dws-location").val(getDefaultServices()["clean2dws"]);
}
function submitService(url) {
var services = {
"clean2dws" : (url == "") ? null : url
};
marvinSketcherInstance.setServices(services);
$("#serviceForm").hide();
}