xref: /petsc/share/petsc/saws/js/events.js (revision 3aa2d9e3a17455108487be9a174c0f069d9014ad)
1//IMPORTANT: always use document.on() because this will also apply to future elements added to document
2
3$(document).on("change","input[id^='logstruc']",function(){
4    var id      = this.id;
5    var endtag  = id.substring(id.indexOf("0"),id.length);
6    var checked = $(this).prop("checked");
7
8    matInfo[endtag].logstruc = checked;
9    setDefaults(endtag);
10});
11
12$(document).on("change","input[id^='symm']",function(){//blur (disable) posdef to false if symm isn't selected!!
13    var id      = this.id;
14    var endtag  = id.substring(id.indexOf("0"),id.length);
15    var checked = $(this).prop("checked");
16
17    matInfo[endtag].symm = checked;
18
19    if(!checked) { //if not symm, then cannot be posdef
20        $("#posdef" + endtag).attr("checked",false);
21        $("#posdef" + endtag).attr("disabled", true);
22        matInfo[endtag].posdef = false;
23    }
24    if(checked) { //if symm, then allow user to adjust posdef
25        $("#posdef" + endtag).attr("disabled", false);
26    }
27    setDefaults(endtag);
28
29    //if symm is checked, disable all child symms ?? (hold off on this)
30    //if symm is unchecked, enable all child symms ??
31});
32
33$(document).on("change","input[id^='posdef']",function(){
34    var id      = this.id;
35    var endtag  = id.substring(id.indexOf("0"),id.length);
36    var checked = $(this).prop("checked");
37
38    matInfo[endtag].posdef = checked;
39    setDefaults(endtag);
40
41    //if posdef is checked, disable all child posdefs ?? (hold off on this)
42    //if posdef is unchecked, enable all the posdefs ??
43});
44
45//this function is called after a change in symm,posdef,OR logstruc
46function setDefaults(endtag) {
47    var symm     = $("#symm" + endtag).prop("checked");
48    var posdef   = $("#posdef" + endtag).prop("checked");
49    var logstruc = $("#logstruc" + endtag).prop("checked");
50
51    var defaults;
52    if(endtag == "0") { //has no parent
53        defaults = getDefaults("",symm,posdef,logstruc);
54    }
55    else { //otherwise, we should generate a more appropriate default
56        var parentEndtag    = getParent(endtag);
57        var parent_pc_type  = matInfo[parentEndtag].pc_type;
58        var parent_symm     = matInfo[parentEndtag].symm;
59        var parent_posdef   = matInfo[parentEndtag].posdef;
60        var parent_logstruc = matInfo[parentEndtag].logstruc;
61        defaults            = getDefaults(parent_pc_type,parent_symm,parent_posdef,parent_logstruc,symm,posdef,logstruc); //if this current solver is a sub-solver, then we should set defaults according to its parent. this suggestion will be better.
62        var sub_pc_type   = defaults.sub_pc_type;
63        var sub_ksp_type  = defaults.sub_ksp_type;
64        defaults = {
65            pc_type: sub_pc_type,
66            ksp_type: sub_ksp_type
67        };
68    }
69
70    $("#pc_type" + endtag).val(defaults.pc_type);
71    $("#ksp_type" + endtag).val(defaults.ksp_type);
72    //trigger both to add additional options
73    $("#ksp_type" + endtag).trigger("change");
74    $("#pc_type" + endtag).trigger("change");
75}
76
77$(document).on("click","#copyToClipboard",function(){
78    window.prompt("Copy to clipboard: Ctrl+C, Enter", clipboardText);
79    //Note: Because of security reasons, copying to clipboard on click is actually quite complicated. This is a much simpler way to get the job done.
80});
81
82//call this method to refresh all the diagram (only the ones that are checked will be displayed)
83function refresh() {
84        $("#rightPanel").html(""); //clear the rightPanel
85        var cmdOptions = getCmdOptions(matInfo,"0","","newline");
86        clipboardText  = getCmdOptions(matInfo,"0","","space");
87        $("#rightPanel").append("<b>Command Line Options:</b>");
88        $("#rightPanel").append("<input type=button value=\"Copy to Clipboard\" id=\"copyToClipboard\" style=\"float:right;font-size:12px;\"><br><br>");
89        $("#rightPanel").append(cmdOptions);
90
91        calculateSizes(matInfo,"0");
92        var svgString = getBoxTree(matInfo,"0",0,0);
93        $("#tree").html("<svg id=\"treeCanvas\" width=\"" + matInfo["0"].total_size.width + "\" height=\"" + matInfo["0"].total_size.height + "\" viewBox=\"0 0 " + matInfo["0"].total_size.width + " " + matInfo["0"].total_size.height + "\">" + svgString + "</svg>");
94
95        $("#matrixPic").html("");
96
97    /*if(displayDiagram) {
98        $("#matrixPic2").html("<center>" + "\\(" + getSpecificMatrixTex(matInfo, "0") + "\\)" + "</center>");
99        $("#matrixPic1").html("<center>" + "\\(" + getSpecificMatrixTex2(0) + "\\)" + "</center>");
100        MathJax.Hub.Config({ TeX: { extensions: ["AMSMath.js"] }});
101        MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
102    }
103    else {
104        $("#matrixPic1").html("");
105        $("#matrixPic2").html("");
106    }*/
107}
108
109$(document).on("change","#displayCmdOptions",function(){
110    displayCmdOptions = $(this).prop("checked");
111    refresh();
112});
113
114$(document).on("change","#displayTree",function(){
115    displayTree = $(this).prop("checked");
116    refresh();
117});
118
119$(document).on("change","#displayMatrix",function(){
120    displayMatrix = $(this).prop("checked");
121    refresh();
122});
123
124/*$(document).on("change","#displayDiagram",function(){
125    displayDiagram = $(this).prop("checked");
126    refresh();
127});*/
128
129/*
130//this piece of code is useless right now, but will be restored eventually
131$(document).on("keyup", '.processorInput', function() {
132    if ($(this).val().match(/[^0-9]/) || $(this).val()<1) {//integer only bubble still displays when nothing is entered
133	$(this).attr("title","");//set a random title (this will be overwritten)
134	$(this).tooltip();//create a tooltip from jquery UI
135	$(this).tooltip({ content: "Integer only!" });//edit displayed text
136	$(this).tooltip("open");//manually open once
137    } else {
138	$(this).removeAttr("title");//remove title attribute
139	$(this).tooltip();//create so that we dont call destroy on nothing
140        $(this).tooltip("destroy");
141    }
142});*/
143