From bb83d8839dddd6e6071f82cdbb5629c5125049de Mon Sep 17 00:00:00 2001 From: Claudio Sacerdoti Coen Date: Mon, 28 Jul 2003 10:55:13 +0000 Subject: [PATCH] - severe bug fixing - implementation of two functions to highlight/dim set of nodes given their xref. [used to highlight/dim the current goal] --- helm/gTopLevel/xmlDiff.ml | 129 +++++++++++++++++++++---------------- helm/gTopLevel/xmlDiff.mli | 4 ++ 2 files changed, 77 insertions(+), 56 deletions(-) diff --git a/helm/gTopLevel/xmlDiff.ml b/helm/gTopLevel/xmlDiff.ml index e35a9ec5e..e16210028 100644 --- a/helm/gTopLevel/xmlDiff.ml +++ b/helm/gTopLevel/xmlDiff.ml @@ -23,12 +23,30 @@ * http://cs.unibo.it/helm/. *) +let myprerr_endline = prerr_endline;; let prerr_endline _ = ();; let mathmlns = "http://www.w3.org/1998/Math/MathML";; let xmldiffns = "http://helm.cs.unibo.it/XmlDiff";; +let helmns = "http://www.cs.unibo.it/helm";; -let highlight_node (doc: Gdome.document) (n: Gdome.node) = +type highlighted_nodes = Gdome.node list;; + +let rec make_visible (n: Gdome.node) = + match n#get_parentNode with + None -> () + | Some p -> + match p#get_namespaceURI, p#get_localName with + Some nu, Some ln when + nu#to_string = mathmlns && ln#to_string = "maction" -> + (new Gdome.element_of_node p)#setAttribute + ~name:(Gdome.domString "selection") + ~value:(Gdome.domString "2") ; + make_visible p + | _,_ -> make_visible p +;; + +let highlight_node ?(color="yellow") (doc: Gdome.document) (n: Gdome.node) = let highlight (n: Gdome.node) = let highlighter = doc#createElementNS @@ -36,7 +54,7 @@ let highlight_node (doc: Gdome.document) (n: Gdome.node) = ~qualifiedName:(Gdome.domString "m:mstyle") in highlighter#setAttribute ~name:(Gdome.domString "background") - ~value:(Gdome.domString "yellow") ; + ~value:(Gdome.domString color) ; highlighter#setAttributeNS ~namespaceURI:(Some (Gdome.domString xmldiffns)) ~qualifiedName:(Gdome.domString "xmldiff:type") @@ -47,7 +65,8 @@ let highlight_node (doc: Gdome.document) (n: Gdome.node) = | Some p -> p in ignore (highlighter#appendChild n) ; - ignore (parent#appendChild (highlighter :> Gdome.node)) + ignore (parent#appendChild (highlighter :> Gdome.node)) ; + (highlighter :> Gdome.node) in let rec find_mstylable_node n = match n#get_namespaceURI, n#get_localName with @@ -72,7 +91,55 @@ prerr_endline ("@@@ find_mstylable_node salgo da " ^ match n#get_localName with None -> assert false | Some p -> find_mstylable_node p in - highlight (find_mstylable_node n) + let highlighter = highlight (find_mstylable_node n) in + make_visible highlighter ; + highlighter +;; + +let highlight_nodes ~xrefs (doc:Gdome.document) = + let highlighted = ref [] in + let rec aux (n:Gdome.element) = + if + List.mem + (n#getAttributeNS ~namespaceURI:(Gdome.domString helmns) + ~localName:(Gdome.domString "xref"))#to_string + xrefs + then + highlighted := + (highlight_node ~color:"#00ff00"(* light green *) doc (n :> Gdome.node)):: + !highlighted ; + let children = n#get_childNodes in + for i = 0 to children#get_length - 1 do + match children#item i with + None -> assert false + | Some n -> + if n#get_nodeType = GdomeNodeTypeT.ELEMENT_NODE then + aux (new Gdome.element_of_node n) + done + in + aux doc#get_documentElement ; + !highlighted +;; + +let dim_nodes = + List.iter + (function (n : Gdome.node) -> + assert + (n#get_nodeType = GdomeNodeTypeT.ELEMENT_NODE && + ((new Gdome.element_of_node n)#getAttributeNS + ~namespaceURI:(Gdome.domString xmldiffns) + ~localName:(Gdome.domString "type"))#to_string = "fake") ; + let true_child = + match n#get_firstChild with + None -> assert false + | Some n -> n in + let p = + match n#get_parentNode with + None -> assert false + | Some n -> n + in + ignore (p#replaceChild ~oldChild:n ~newChild:true_child) + ) ;; let update_dom ~(from : Gdome.document) (d : Gdome.document) = @@ -232,7 +299,7 @@ prerr_endline ("XML_DIFF: appendo i nodi residui " ^ String.concat ", " (List.ma (function n -> let n' = from#importNode n true in ignore (f#appendChild n') ; - highlight_node from n' + ignore (highlight_node from n') ) tl2 | tl1,[] -> prerr_endline ("XML_DIFF: cancello i nodi residui " ^ String.concat ", " (List.map (function n -> match n#get_localName with Some s -> s#to_string | None -> "_") tl1)) ; @@ -279,56 +346,6 @@ prerr_endline ("XML_DIFF: chiamo dumb_diff su " ^ String.concat ", " (List.map ( in begin prerr_endline ("%%% CANCELLO HIGHLIGHTER " ^ (match f#get_localName with Some s -> s#to_string | None -> "_") ^ " CON DENTRO " ^ (match true_child#get_localName with Some s -> s#to_string | None -> "_")) ; -(********* PROVE E RIPROVE -let old_true_child = true_child in -let true_child = - (from#createElementNS - ~namespaceURI:(Some (Gdome.domString mathmlns)) - ~qualifiedName:(Gdome.domString "m:mrow") :> Gdome.node) ; -in -ignore (f#removeChild old_true_child) ; -ignore (true_child#appendChild old_true_child) ; - ignore (p#replaceChild ~oldChild:f ~newChild:true_child) ; -(* -ignore (true_child#appendChild old_true_child) ; - ignore (p#replaceChild ~oldChild:f ~newChild:true_child) ; -*) -prerr_endline ("%%% RICORSIONE SU " ^ (match true_child#get_localName with Some s -> s#to_string | None -> "_") ^ "/" ^ (match old_true_child#get_localName with Some s -> s#to_string | None -> "_") ^ " E " ^ (match old_true_child#get_localName with Some s -> s#to_string | None -> "_")) ; -let fchildren = old_true_child#get_childNodes in -let l = ref [] in -for i = 0 to fchildren#get_length -1 do - l := !l @ [ match (fchildren#item i) with None -> "?" | Some n -> match n#get_localName with Some s -> s#to_string | None -> "_" ] -done ; -let tchildren = t#get_childNodes in -let l2 = ref [] in -for i = 0 to tchildren#get_length -1 do - l2 := !l2 @ [ match (tchildren#item i) with None -> "?" | Some n -> match n#get_localName with Some s -> s#to_string | None -> "_" ] -done ; -prerr_endline ("%%% Il primo nodo ha i seguenti figli: " ^ String.concat "," !l) ; -prerr_endline ("%%% Il secondo nodo ha i seguenti figli: " ^ String.concat "," !l2) ; - -let fchildren = old_true_child#get_childNodes in -let tchildren = t#get_childNodes in -let node_list_of_nodeList nl = -let rec aux i = - match nl#item ~index:i with - None -> [] - | Some n when - n#get_nodeType = GdomeNodeTypeT.ELEMENT_NODE - or n#get_nodeType = GdomeNodeTypeT.TEXT_NODE -> - n::(aux (i+1)) - | Some n -> -prerr_endline ("### XML_DIFF: mi sto perdendo i nodi di tipo " ^ string_of_int (Obj.magic n#get_nodeType)) ; - aux (i+1) -in - aux 0 - in -prerr_endline ("RRR XML_DIFF: chiamo dumb_diff su " ^ String.concat ", " (List.map (function n -> match n#get_localName with Some s -> s#to_string | None -> "_") (node_list_of_nodeList fchildren)) ^ " e " ^ String.concat ", " (List.map (function n -> match n#get_localName with Some s -> s#to_string | None -> "_") (node_list_of_nodeList tchildren))) ; - aux true_child old_true_child t -(* - aux p true_child t -*) -*****) ignore (p#replaceChild ~oldChild:f ~newChild:true_child) ; aux p true_child t end @@ -339,7 +356,7 @@ prerr_endline ("%%% XML_DIFF: importo il nodo " ^ match t'#get_localName with So prerr_endline ("Rimpiazzo" ^ (match f#get_namespaceURI with Some s -> s#to_string) ^ ":" ^ (match f#get_localName with Some s -> s#to_string) ^ " con " ^ (match t#get_namespaceURI with Some s -> s#to_string) ^ ":" ^ (match t#get_localName with Some s -> s#to_string) ^ " in " ^ (match p#get_localName with Some s -> s#to_string | None -> "_")) ; *) ignore (p#replaceChild ~newChild:t' ~oldChild:f) ; - highlight_node from t' + ignore (highlight_node from t') | _,_,_,_,_,_ -> assert false in try diff --git a/helm/gTopLevel/xmlDiff.mli b/helm/gTopLevel/xmlDiff.mli index c62df033b..cf084af94 100644 --- a/helm/gTopLevel/xmlDiff.mli +++ b/helm/gTopLevel/xmlDiff.mli @@ -24,3 +24,7 @@ *) val update_dom: from: Gdome.document -> Gdome.document -> unit + +type highlighted_nodes +val highlight_nodes: xrefs:(string list) -> Gdome.document -> highlighted_nodes +val dim_nodes: highlighted_nodes -> unit -- 2.39.2