/// <summary> /// Retrieve a value of a single layer property. /// The property can include all the layer properties which can be set through LCAPI. /// </summary> /// <param name="sender"> /// Get Opacity button. /// </param> /// <param name="e"> /// Attributes of the event. /// </param> private void OnGetOpacity(object sender, RoutedEventArgs e) { try { string url = string.Format("http://{0}:5050/layerApi.aspx?cmd=getprop&id={1}&propname=Opacity", this.machineIp, layerId); string payload = string.Empty; string response = WWTRequest.Send(url, payload); this.PrintSendAndReceive(url, response); this.PrintSendAndReceiveHeader("Get Opacity"); } catch (CustomException ex) { // WorldWide Telescope might not be open. this.ReportError(ex.Message); } }
/// <summary> /// Fetches the structure of the layers and layer group names (in an XML document format) /// that are currently in the layer manager in WWT. /// </summary> /// <param name="displayResponse">show the response in response output</param> /// <param name="isLayerCreated">Checks if the call has come from Create layer</param> private void RefreshLayers(bool displayResponse, bool isLayerCreated) { try { string url = string.Format("http://{0}:5050/layerApi.aspx?cmd=layerlist", this.machineIp); string payload = string.Empty; string response = WWTRequest.Send(url, payload); if (displayResponse) { this.PrintSendAndReceive(url, response); this.PrintSendAndReceiveHeader("Refresh Layer List"); } this.layersTree.Items.Clear(); XmlDocument doc = new XmlDocument(); doc.LoadXml(response); XmlNode root = doc["LayerApi"]; XmlNode layersNode = root["LayerList"]; foreach (XmlElement element in layersNode.ChildNodes) { TreeViewItem node = new TreeViewItem(); node.Header = element.Attributes["Name"].Value; node.Name = element.Name; if (element.Attributes["ID"] != null) { node.Tag = element.Attributes["ID"].Value; } this.layersTree.Items.Add(node); node.IsExpanded = true; foreach (XmlElement child in element.ChildNodes) { // If the layer is not of spread sheet layer type, then ignore them. if (child.Attributes["Type"] != null && !child.Attributes["Type"].Value.Equals("SpreadSheetLayer", StringComparison.OrdinalIgnoreCase)) { continue; } TreeViewItem childNode = new TreeViewItem(); childNode.Header = child.Attributes["Name"].Value; childNode.Name = child.Name; if (child.Attributes["ID"] != null) { childNode.Tag = child.Attributes["ID"].Value; } node.Items.Add(childNode); // Select Earth. if (childNode.Header.ToString().Equals("Earth", StringComparison.OrdinalIgnoreCase) && !isLayerCreated) { childNode.IsSelected = true; } foreach (XmlElement grandChild in child.ChildNodes) { // If the layer is not of spread sheet layer type, then ignore them. if (grandChild.Attributes["Type"] != null && !grandChild.Attributes["Type"].Value.Equals("SpreadSheetLayer", StringComparison.OrdinalIgnoreCase)) { continue; } TreeViewItem grandChildNode = new TreeViewItem(); grandChildNode.Header = grandChild.Attributes["Name"].Value; grandChildNode.Name = grandChild.Name; if (grandChild.Attributes["ID"] != null) { grandChildNode.Tag = grandChild.Attributes["ID"].Value; if (isLayerCreated) { if (grandChild.Attributes["ID"].Value == layerId) { grandChildNode.IsSelected = true; layersTree.Focus(); grandChildNode.Focus(); childNode.IsExpanded = true; } } } childNode.Items.Add(grandChildNode); foreach (XmlElement greatGrandChild in grandChild.ChildNodes) { // If the layer is not of spread sheet layer type, then ignore them. if (greatGrandChild.Attributes["Type"] != null && !greatGrandChild.Attributes["Type"].Value.Equals("SpreadSheetLayer", StringComparison.OrdinalIgnoreCase)) { continue; } TreeViewItem greatGrandChildNode = new TreeViewItem(); greatGrandChildNode.Header = greatGrandChild.Attributes["Name"].Value; greatGrandChildNode.Name = greatGrandChild.Name; if (greatGrandChild.Attributes["ID"] != null) { greatGrandChildNode.Tag = greatGrandChild.Attributes["ID"].Value; if (isLayerCreated) { if (greatGrandChild.Attributes["ID"].Value == layerId) { greatGrandChildNode.IsSelected = true; layersTree.Focus(); greatGrandChildNode.Focus(); childNode.IsExpanded = true; grandChildNode.IsExpanded = true; } } } grandChildNode.Items.Add(greatGrandChildNode); } } } } if (this.cmbModes.SelectedIndex <= 0) { this.cmbModes.SelectedIndex = 0; } } catch (CustomException ex) { // Refresh has failed this.SetLayerButtons(false); this.SetCommonOperationsButtons(false); // WorldWide Telescope might not be open. throw ex; } }
/// <summary> /// Creates a new layer in WWT through header data and updates the properties /// of layer created and pass data to be attached to the layer which is created. /// </summary> /// <param name="sender"> /// Create Layer button. /// </param> /// <param name="e"> /// Attributes of the event. /// </param> private void OnCreateNewLayer(object sender, RoutedEventArgs e) { try { TreeViewItem selectedNode = this.layersTree.SelectedItem as TreeViewItem; if (selectedNode != null) { // Call New to create the layer. string url = string.Format( "http://{0}:5050/layerApi.aspx?cmd=new&datetime={1}&name={2}&frame={3}&color={4}", this.machineIp, "1/9/2009 3:44:38 AM", "New Layer", selectedNode.Header.ToString(), "FFFF0000"); string payload = "TIME\tLAT\tLON\tDEPTH\tMAG\tColor"; string response = WWTRequest.Send(url, payload); this.PrintSendAndReceive(url, response); this.PrintSendAndReceiveHeader("Step 1 : Create new layer"); if (!string.IsNullOrEmpty(response)) { XmlDocument doc = new XmlDocument(); doc.LoadXml(response); XmlNode node = doc["LayerApi"]; layerId = node.InnerText; url = string.Format("http://{0}:5050/layerApi.aspx?cmd=setprops&id={1}", this.machineIp, layerId); payload = "<?xml version=\"1.0\" encoding=\"utf-8\"?><LayerApi><Layer Name=\"New Layer\" LatColumn=\"1\" LngColumn=\"2\" GeometryColumn=\"-1\"" + " ColorMapColumn=\"5\" AltColumn=\"3\" StartDateColumn=\"0\" EndDateColumn=\"-1\" SizeColumn=\"4\" NameColumn=\"0\" Decay=\"16\" ScaleFactor=\"1\" Opacity=\"1\" StartTime=\"1/1/0001 12:00:00 AM\" EndTime=\"12/31/9999 11:59:59 PM\" FadeSpan=\"00:00:00\" ColorValue=\"ARGBColor:255:255:0:0\" AltType=\"Depth\" MarkerScale=\"World\"" + " AltUnit=\"Kilometers\" RaUnits=\"Hours\" PointScaleType=\"Power\" FadeType=\"None\" PlotType=\"Gaussian\" MarkerIndex=\"0\" ShowFarSide=\"true\" TimeSeries=\"false\" /></LayerApi>"; response = WWTRequest.Send(url, payload); this.PrintSendAndReceive(url + "\r\n" + payload, response); this.PrintSendAndReceiveHeader("Step 2 : Update layer properties"); // Call Update to update the layer with data. url = string.Format("http://{0}:5050/layerApi.aspx?cmd=update&id={1}", this.machineIp, layerId); string lineBuffer = "1/9/2009 3:44\t0\t0\t10\t7\tRed\r\n1/9/2009 6:28\t0\t10\t243\t9\tBlue\r\n1/9/2009 6:54\t-5\t5\t35\t8\t90%Green"; response = WWTRequest.Send(url, lineBuffer); this.PrintSendAndReceive(url + "\r\n" + lineBuffer, response); this.PrintSendAndReceiveHeader("Step 3 : Send layer data"); url = string.Format("http://{0}:5050/layerApi.aspx?cmd=showlayermanager", this.machineIp); response = WWTRequest.Send(url, string.Empty); this.PrintSendAndReceive(url, response); this.PrintSendAndReceiveHeader("Step 4 : Show Layer Manager Pane in WWT"); } this.RefreshLayers(false, true); this.tabControl.SelectedIndex = 0; } } catch (CustomException ex) { // WorldWide Telescope might not be open. this.ReportError(ex.Message); } }