예제 #1
0
        public JsonResult SaveSvgData(BuildingSvgConfigModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Svg))
            {
                model.Svg = string.Empty;
            }

            var prevSvg = ApartmentManager.GetSvgData(model.BuildingId, model.AssetId);

            if (prevSvg != null)
            {
                prevSvg.Svg = model.Svg;
                ApartmentManager.UpdateSvgData(prevSvg);
            }
            else
            {
                var newBuildingSvg = new SvgData();
                newBuildingSvg.BuildingId = model.BuildingId;
                newBuildingSvg.AssetId    = model.AssetId;
                newBuildingSvg.Svg        = model.Svg;
                newBuildingSvg.Type       = 0;

                ApartmentManager.SaveSvgData(newBuildingSvg);
            }

            return(Json(new { Message = "Success" }));
        }
예제 #2
0
        public string GetSVGData(int buildingId, int assetId)
        {
            var svgData = _svgRepo.GetAllById(buildingId).Where(a => a.AssetId == assetId).FirstOrDefault();

            if (svgData == null)
            {
                svgData     = new SvgData();
                svgData.Svg = "<script>alert(\"No SVG Found\")<\\script>";
            }
            return(svgData.Svg);
        }
예제 #3
0
        //Extract the light positions from an svg file.
        private void GetLightArray(out SvgData[] svgData, string svgText)
        {
            if (!string.IsNullOrEmpty(svgText))
            {
                Vector2     viewBox = Vector2.one;
                XmlDocument xmlDoc  = new XmlDocument();

                xmlDoc.LoadXml(svgText);

                //Get the circle nodes.
                XmlNodeList circles  = xmlDoc.GetElementsByTagName("circle");
                XmlNodeList svgNodes = xmlDoc.GetElementsByTagName("svg");

                //Get the view box.
                string   viewBoxString = svgNodes[0].Attributes["viewBox"].Value;
                string[] boxSize       = viewBoxString.Split(' ');
                viewBox = new Vector2(float.Parse(boxSize[2]), float.Parse(boxSize[3]));

                svgData = new SvgData[circles.Count];

                for (int i = 0; i < circles.Count; i++)
                {
                    //Get coordinates.
                    float x = float.Parse(circles[i].Attributes["cx"].Value);
                    float y = float.Parse(circles[i].Attributes["cy"].Value);

                    //Get the id.
                    string idString     = circles[i].Attributes["id"].Value;
                    string numberString = Regex.Match(idString, @"\d+").Value;
                    int    id           = int.Parse(numberString);

                    //Get the material string.
                    string style          = circles[i].Attributes["style"].Value;
                    int    start          = style.IndexOf(materialPropertyString) + materialPropertyString.Length;
                    int    end            = style.IndexOf(';', start);
                    string materialString = style.Substring(start, end - start);

                    //Store the data we are interested in.
                    svgData[i] = new SvgData();
                    svgData[i].materialString = materialString;
                    svgData[i].position       = ConvertCoordinates(x, y, viewBox);
                    svgData[i].id             = id;
                }
            }

            else
            {
                svgData = null;
            }
        }
		//Extract the light positions from an svg file.
		private void GetLightArray(out SvgData[] svgData, string svgText){

			if(!string.IsNullOrEmpty(svgText)){

				Vector2 viewBox = Vector2.one;
				XmlDocument xmlDoc = new XmlDocument();		
		
				xmlDoc.LoadXml(svgText);

				//Get the circle nodes.
				XmlNodeList circles = xmlDoc.GetElementsByTagName("circle");		
				XmlNodeList svgNodes = xmlDoc.GetElementsByTagName("svg");

				//Get the view box.
				string viewBoxString = svgNodes[0].Attributes["viewBox"].Value;
				string[] boxSize = viewBoxString.Split(' ');
				viewBox = new Vector2(float.Parse(boxSize[2]), float.Parse(boxSize[3]));

				svgData = new SvgData[circles.Count];

				for(int i = 0; i < circles.Count; i++){

					//Get coordinates.
					float x = float.Parse(circles[i].Attributes["cx"].Value);
					float y = float.Parse(circles[i].Attributes["cy"].Value);

					//Get the id.
					string idString = circles[i].Attributes["id"].Value;
					string numberString = Regex.Match(idString, @"\d+").Value;
					int id = int.Parse(numberString);

					//Get the material string.
					string style = circles[i].Attributes["style"].Value;
					int start = style.IndexOf(materialPropertyString) + materialPropertyString.Length;
					int end = style.IndexOf(';', start);
					string materialString = style.Substring(start, end - start);

					//Store the data we are interested in.
					svgData[i] = new SvgData();
					svgData[i].materialString = materialString;
					svgData[i].position = ConvertCoordinates(x, y, viewBox);	
					svgData[i].id = id;
				}
			}

			else{

				svgData = null;
			}
		}
예제 #5
0
 public bool UpdateSvgData(SvgData data)
 {
     return(_svgRepository.Update(data.Id, data));
 }
예제 #6
0
 public SvgData SaveSvgData(SvgData data)
 {
     return(_svgRepository.Insert(data));
 }