/// <summary> /// Propagates the configuration file to memory. /// </summary> public static void Configure(string FilePath) { try { // // LOAD THE XML FILE. // XmlDocument ConfigDocument = new XmlDocument(); ConfigDocument.Load(FilePath); XmlElement MarkerConfigElement = ConfigDocument.DocumentElement; // // PARSE THE CONFIGURATION VALUES. // MarkerConfig CreatedMarkerConfig = new MarkerConfig(); CreatedMarkerConfig.Type = MarkerTypeParser.Parse(MarkerConfigElement["MarkerType"].InnerText); CreatedMarkerConfig.FailureMode = MarkerFailureModeParser.Parse(MarkerConfigElement["FailureMode"].InnerText); CreatedMarkerConfig.ReportFactoryType = MarkerReportFactoryTypeParser.Parse(MarkerConfigElement["ReportFactoryType"].InnerText); // // DO THE CONFIGURATION "CUTOVER." // THE PROVIDER WILL NOW RETURN THIS REFERENCE FOR THE CONFIG OBJECT. // MarkerConfigReference.MarkerConfig = CreatedMarkerConfig; } catch (Exception) { // // DO NOT ALLOW AN INVALID CONFIGURATION TO PROPAGATE. // SUPPRESS ALL EXCEPTIONS. // } }
private void AddVertexPin(Vertex v) { //Pushpin pushpin = new Pushpin(); //pushpin.Style = (Style)(Application.Current.Resources["PushpinStyle"]); Image pushpin = MarkerConfig.CreateImage(v); pushpin.Tap += (object sender, GestureEventArgs e) => { e.Handled = true; mWebMapCommon.onTap(v); //updates the title //Navigates to the possibilities StringBuilder sb = new StringBuilder(); sb.Append(Globals.XamlUri_OfflineOnTapAction); sb.Append("?title="); sb.Append(this.ApplicationTitle.Text); this.NavigationService.Navigate(new Uri(sb.ToString(), UriKind.Relative)); }; //pushpin.MouseLeftButtonUp += new MouseButtonEventHandler(pushpin_MouseLeftButtonUp); AbsoluteLocation pos = v.AbsoluteLocations.First(); mapLayerVertices.AddChild(pushpin, new GeoCoordinate((double)pos.latitude, (double)pos.longitude), PositionOrigin.BottomCenter); }
private void removeEndpoint(Vertex v) { int removeIdx = -1; //find vertex for (int i = 0; i < mEndPoints.Count; i++) { if (v.ID == mEndPoints[i].ID) { removeIdx = i; break; } } //remove vertex if (removeIdx != -1) { mEndPoints.RemoveAt(removeIdx); //Revert to original bitmap image Image img = mPrevEndpointImages[removeIdx]; img.Source = MarkerConfig.getCorrectMarker(v); //could also use CreateImage(v) but that creates a new image mPrevEndpointImages.RemoveAt(removeIdx); } }
/// <summary> /// Sets the initial system defaults. /// The initial system defaults are targeted for development environments. /// </summary> static MarkerConfigReference() { // // SET SYSTEM DEFAULTS. // MarkerConfig = new MarkerConfig(); MarkerConfig.Type = MarkerType.Enabled; MarkerConfig.FailureMode = MarkerFailureMode.HighlyVisible; MarkerConfig.ReportFactoryType = MarkerReportFactoryType.PlainText; }
public void SetUp() { // // CREATE THE START CONFIGURATION. // _StartConfig = new MarkerConfig(); _StartConfig.Type = MarkerType.Enabled; _StartConfig.FailureMode = MarkerFailureMode.HighlyVisible; _StartConfig.ReportFactoryType = MarkerReportFactoryType.PlainText; MarkerConfigReference.MarkerConfig = _StartConfig; // // BUILD THE PATH TO THE CONFIGURATION FILE. // string FixtureBaseDir = TestFixtureConfig.TestFixturesBaseDir + "\\ConfiguratorFixtures\\Fixture_10_ConfigureAndWatch"; string FileName = "markers-config.xml"; string SourceConfigFilePath = FixtureBaseDir + "\\_TestFiles\\" + FileName; _TargetConfigFilePath = FixtureBaseDir + "\\" + FileName; // // CLEAN UP FROM ANY PREVIOUS FAILURES. // if (File.Exists(_TargetConfigFilePath)) { File.Delete(_TargetConfigFilePath); } // // WATCH THE FILE. // XmlConfigurator.ConfigureAndWatch(_TargetConfigFilePath); // // CREATE THE CONFIGURATION FILE THAT THE XML CONFIGURATOR SHOULD BE WATCHING. // File.Copy(SourceConfigFilePath, _TargetConfigFilePath); // // WAIT FOR THE CONFIGURATION TO PROPAGATE. // Thread.Sleep(20); // // GET THE CONFIGURATION FROM THE PROVIDER. // _EndConfig = MarkerConfigProvider.GetMarkerConfig(); }
public MarkerConfig Load() { MarkerConfig result; try { var json = File.ReadAllText(storageName); result = JsonConvert.DeserializeObject <MarkerConfig>(json); } catch (FileNotFoundException ex) { Console.WriteLine(ex); result = new MarkerConfig(); Save(result); } return(result); }
private void AddVertexPin(Vertex v) { Image img = MarkerConfig.CreateImage(v); img.Tap += (object sender, GestureEventArgs e) => { e.Handled = true; Tapped_UpdatePins(v, img); Tapped_UpdateMenu(); Tapped_UpdateTitle(); }; //pushpin.MouseLeftButtonUp += new MouseButtonEventHandler(pushpin_MouseLeftButtonUp); AbsoluteLocation pos = v.AbsoluteLocations.First(); mapLayerVertices.AddChild(img, new GeoCoordinate((double)pos.latitude, (double)pos.longitude), PositionOrigin.BottomCenter); }
private void AddVertexPin(Vertex v) { //Pushpin pushpin = new Pushpin(); //pushpin.Style = (Style)(Application.Current.Resources["PushpinStyle"]); Image pushpin = MarkerConfig.CreateImage(v); //pushpin.Tap += new EventHandler<GestureEventArgs>(pushpin_Tap); pushpin.Tap += (object sender, GestureEventArgs args) => { SymbolicLocation symLoc = v.SymbolicLocations.FirstOrDefault(); if (symLoc != null) { string title = symLoc.title ?? ""; string description = symLoc.description ?? ""; string url = symLoc.url ?? ""; MessageBox.Show(string.Format("{0}\n{1}\n{2}", title, description, url)); } }; AbsoluteLocation pos = v.AbsoluteLocations.First(); mapLayerVertices.AddChild(pushpin, new GeoCoordinate((double)pos.latitude, (double)pos.longitude), PositionOrigin.BottomCenter); }
/// <summary> /// Adds a marker with its configurations and image to layout manager. /// </summary> /// <param name="markerID">The ID of the marker (specified by the ARTag)</param> /// <param name="upperLeftCorner">The upper left corner (in pixels) of this marker in the entire /// marker array.</param> /// <param name="size">The size of this marker to be printed on the marker array. If different /// from the original image size, the marker image will be resized to fit this size.</param> /// <param name="cropArea">The area to be retained after cropping other parts outside of /// this area</param> /// <param name="imagefile">The file name of the marker image (must have an extension that /// indicates the image format)</param> /// <param name="additionalInfos">Additional information that should be added to the config file</param> /// <exception cref="ArgumentException">If the given marker ID is already added</exception> /// <exception cref="InvalidOperationException"></exception> public void AddMarker(int markerID, Point upperLeftCorner, Size size, Rectangle cropArea, String imagefile, List<KeyValuePair<string, string>> additionalInfos) { if (configs.ContainsKey(markerID)) throw new ArgumentException("You can't add same marker ID in one config file"); MarkerConfig config = new MarkerConfig(); config.ID = markerID; config.Position = upperLeftCorner; int width = 0, height = 0; config.Image = ImageReader.Load(imagefile, ref width, ref height); config.ImageWidth = width; config.ImageHeight = height; config.CropArea = cropArea; config.AdditionalInfo = additionalInfos; config.ImageFilename = imagefile; if (size.Equals(Size.Empty)) { if (!cropArea.Equals(Rectangle.Empty)) config.Size = cropArea.Size; else config.Size = new Size(width, height); } else config.Size = size; // if crop area is not empty, then make sure that the crop area is within the marker size if (!cropArea.Equals(Rectangle.Empty)) { if (cropArea.X < 0 || cropArea.X > width) throw new ArgumentException("Your crop area's X position is outside of the marker size"); if (cropArea.Y < 0 || cropArea.Y > height) throw new ArgumentException("Your crop area's Y position is outside of the marker size"); if ((cropArea.X + cropArea.Width) > width) throw new ArgumentException("Your crop area's X dimension exceeds the marker width"); if ((cropArea.Y + cropArea.Height) > height) throw new ArgumentException("Your crop area's Y dimension exceeds the marker height"); } configs.Add(markerID, config); markerIDs.Add(markerID); }
public void Save(MarkerConfig config) { var json = JsonConvert.SerializeObject(config, Formatting.Indented); File.WriteAllText(storageName, json); }
public TangibleMarkerController() { Config = _storage.Load(); }
/// <summary> /// Outputs an ARTag configuration file based on the marker layout. If you have or generated /// other configuration files, and want to append the config information to this configuration /// file, then you can pass the filenames of those additional configuration files to 'appendConfigs' /// parameter. /// </summary> /// <param name="configFilename">The name of the configuration file to be generated</param> /// <param name="type">The type of config file depending on different tracking libraries</param> /// <param name="appendConfigs">A list of external configuration file names to append at the end /// of the configuration file to be generated</param> /// <exception cref="InvalidOperationException"></exception> public void OutputConfig(String configFilename, params String[] appendConfigs) { if (!coodframeConfig.CoodframeName.Equals("")) { throw new InvalidOperationException("You forgot to end your current coordframe: " + coodframeConfig.CoodframeName + ". Call EndCoordframe() before calling this OutputConfig(...)"); } float ratio = 1 / (float)pixelPerInch; try { if (configFilename.EndsWith(".xml")) { XmlDocument xmlDoc = new XmlDocument(); XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "no"); foreach (KeyValuePair <CoordframeConfig, List <int> > coordframe in coordframes) { XmlElement xmlRootNode = xmlDoc.CreateElement("multimarker"); xmlRootNode.SetAttribute("markers", coordframe.Value.Count.ToString()); xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement); xmlDoc.AppendChild(xmlRootNode); foreach (int markerID in coordframe.Value) { XmlElement markerXml = xmlDoc.CreateElement("marker"); markerXml.SetAttribute("index", markerID.ToString()); markerXml.SetAttribute("status", "2"); MarkerConfig config = configs[markerID]; int x = config.Position.X - configCenter.X; int y = config.Position.Y - configCenter.Y; PointF configPos = new PointF(x * ratio, y * ratio); SizeF configSize = new SizeF(config.Size.Width * ratio, config.Size.Height * ratio); XmlElement[] cornerXml = new XmlElement[4]; cornerXml[0] = xmlDoc.CreateElement("corner"); cornerXml[0].SetAttribute("x", configPos.X.ToString()); cornerXml[0].SetAttribute("y", "" + (-(configPos.Y + configSize.Height))); cornerXml[0].SetAttribute("z", "0"); cornerXml[1] = xmlDoc.CreateElement("corner"); cornerXml[1].SetAttribute("x", "" + (configPos.X + configSize.Width)); cornerXml[1].SetAttribute("y", "" + (-(configPos.Y + configSize.Height))); cornerXml[1].SetAttribute("z", "0"); cornerXml[2] = xmlDoc.CreateElement("corner"); cornerXml[2].SetAttribute("x", "" + (configPos.X + configSize.Width)); cornerXml[2].SetAttribute("y", "" + (-configPos.Y)); cornerXml[2].SetAttribute("z", "0"); cornerXml[3] = xmlDoc.CreateElement("corner"); cornerXml[3].SetAttribute("x", "" + configPos.X); cornerXml[3].SetAttribute("y", "" + (-configPos.Y)); cornerXml[3].SetAttribute("z", "0"); foreach (XmlElement corner in cornerXml) { markerXml.AppendChild(corner); } xmlRootNode.AppendChild(markerXml); } } xmlDoc.Save(configFilename); } else { TextWriter tw = new StreamWriter(configFilename); foreach (KeyValuePair <CoordframeConfig, List <int> > coordframe in coordframes) { tw.WriteLine("" + coordframe.Value.Count); tw.WriteLine(); foreach (int markerID in coordframe.Value) { tw.WriteLine("" + markerID); } tw.WriteLine(); foreach (int markerID in coordframe.Value) { tw.WriteLine("2"); // status indicator } tw.WriteLine(); foreach (int markerID in coordframe.Value) { MarkerConfig config = configs[markerID]; int x = config.Position.X - configCenter.X; int y = config.Position.Y - configCenter.Y; PointF configPos = new PointF(x * ratio, y * ratio); SizeF configSize = new SizeF(config.Size.Width * ratio, config.Size.Height * ratio); tw.WriteLine("" + configPos.X + " " + (-(configPos.Y + configSize.Height)) + " 0"); tw.WriteLine("" + (configPos.X + configSize.Width) + " " + (-(configPos.Y + configSize.Height)) + " 0"); tw.WriteLine("" + (configPos.X + configSize.Width) + " " + (-configPos.Y) + " 0"); tw.WriteLine("" + configPos.X + " " + (-configPos.Y) + " 0"); } tw.Write("\n\n"); // add two blank gaps } tw.Close(); } } catch (Exception exp) { Console.WriteLine(exp.Message + exp.StackTrace); } }
/// <summary> /// Adds a marker with its configurations and image to layout manager. /// </summary> /// <param name="markerID">The ID of the marker (specified by the ARTag)</param> /// <param name="upperLeftCorner">The upper left corner (in pixels) of this marker in the entire /// marker array.</param> /// <param name="size">The size of this marker to be printed on the marker array. If different /// from the original image size, the marker image will be resized to fit this size.</param> /// <param name="cropArea">The area to be retained after cropping other parts outside of /// this area</param> /// <param name="imagefile">The file name of the marker image (must have an extension that /// indicates the image format)</param> /// <remarks> /// This function can only be called between BeginCoordframe(...) and EndCoordframe() /// function calls. /// </remarks> /// <exception cref="ArgumentException">If the given marker ID is already added</exception> /// <exception cref="InvalidOperationException"></exception> /// <see cref="BeginCoordframe"/> /// <seealso cref="EndCoordframe"/> public void AddMarker(int markerID, Point upperLeftCorner, Size size, Rectangle cropArea, String imagefile) { if (coodframeConfig.CoodframeName.Equals("")) { throw new InvalidOperationException("You can only call this function between " + "BeginCoordframe(...) and EndCoordframe() function calls"); } if (configs.ContainsKey(markerID)) { throw new ArgumentException("You can't add same marker ID in one config file"); } MarkerConfig config = new MarkerConfig(); config.ID = markerID; config.Position = upperLeftCorner; int width = 0, height = 0; config.Image = ImageReader.Load(imagefile, ref width, ref height); config.ImageWidth = width; config.ImageHeight = height; config.CropArea = cropArea; if (size.Equals(Size.Empty)) { if (!cropArea.Equals(Rectangle.Empty)) { config.Size = cropArea.Size; } else { config.Size = new Size(width, height); } } else { config.Size = size; } // if crop area is not empty, then make sure that the crop area is within the marker size if (!cropArea.Equals(Rectangle.Empty)) { if (cropArea.X < 0 || cropArea.X > width) { throw new ArgumentException("Your crop area's X position is outside of the marker size"); } if (cropArea.Y < 0 || cropArea.Y > height) { throw new ArgumentException("Your crop area's Y position is outside of the marker size"); } if ((cropArea.X + cropArea.Width) > width) { throw new ArgumentException("Your crop area's X dimension exceeds the marker width"); } if ((cropArea.Y + cropArea.Height) > height) { throw new ArgumentException("Your crop area's Y dimension exceeds the marker height"); } } configs.Add(markerID, config); markerIDs.Add(markerID); }
private void addEndpoint(Vertex v, Image img) { mEndPoints.Add(v); mPrevEndpointImages.Add(img); //Save ref to org image img.Source = MarkerConfig.getDestinationMarker(); }