ContourShape oneShelfBoxContour; //书架正视图的外部轮廓 //List<ShelfShape> shelfMapShelfList; //一个书库俯视图中所有书柜的列表 //DoorShape shelfMapDoor; //一个书库门的位置 //ContourShape shelfMapContour; //一个书库的外部轮廓 //RouteShape shelfMapRoute; //取书的路径列表 public DrawMapService(IUnityContainer container) { this.container = container; this.eventAggregator = container.Resolve<IEventAggregator>(); //初始化其他变量 this.oneShelfDrawer = new CanvasDrawer(); this.libraryShelfDrawer = new CanvasDrawer(); //初始化各种图形参数,先初始化一个值,不管是否有意义,以免在后续引用中出错。 this.oneShelfBoxList = new List<ShelfShape>(); this.oneShelfBoxContour = new ContourShape(new List<Point>()); //this.shelfMapShelfList = new List<ShelfShape>(); //this.shelfMapDoor = new DoorShape(new Point(0,0),new Point(0,0)); //this.shelfMapContour = new ContourShape(new List<Point>()); //this.shelfMapRoute = new RouteShape(new List<Point>()); initVariableValue(); }
//该函数能够画出一个书库的背景图片,包含书架,轮廓和门,参数为该图书馆名称,参数即为Map表中的location字段 public void drawLibraryShelfMapBackgroundByLibraryName(String libraryName) { String libraryNameInTable = this.bookLocationStringToLibraryName(libraryName); //获取图书位置信息数据库的引用 IBookLocationService bookLocationService = this.container.Resolve<IBookLocationService>(); //画出书库的地板,重复画出 /*** BitmapImage floorTileBitmapImage = new BitmapImage(); floorTileBitmapImage.BeginInit(); floorTileBitmapImage.UriSource = new Uri("pack://application:,,,/UI;component/Resource/images/glass.png", UriKind.RelativeOrAbsolute); floorTileBitmapImage.EndInit(); this.libraryShelfDrawer.drawFloor(floorTileBitmapImage); ***/ //画出所有的书架 try { //获取某个书库中所有的书架 List<String> shelfPositionStringList = bookLocationService.getItemPositionStringListByLocationAndType(libraryNameInTable, "SHELF"); //从数据库中读到的字符串列表中解析出所有的书架地理位置信息,并加入到this.shelfMapShelfList中 List<ShelfShape> shelfMapShelfList = new List<ShelfShape>(); foreach (String stringItem in shelfPositionStringList) {//stringItem is a string ,such as "13000,1500,1500,1000",startpoint x,y,and width,height char[] separator = { ',', ',' }; String[] pointDescInString = stringItem.Split(separator); if (pointDescInString.Length != 4) { continue; } //如果不为4个数字,则意味着可能出现了解析或者存储错误 double[] pointDescInDouble = new double[] { Convert.ToDouble(pointDescInString[0]), Convert.ToDouble(pointDescInString[1]), Convert.ToDouble(pointDescInString[2]), Convert.ToDouble(pointDescInString[3]) }; Point leftTop = new Point(pointDescInDouble[0], pointDescInDouble[1]); Point rightBottom = new Point(pointDescInDouble[0] + pointDescInDouble[2], pointDescInDouble[1] + pointDescInDouble[3]); //把书架的位置信息放入结构体的变量中shelfMapShelfList shelfMapShelfList.Add(new ShelfShape(leftTop, rightBottom)); } //开始绘制俯视图中的书架 BitmapImage bitmapImage = new BitmapImage(); //Uri uri = new Uri("pack://application:,,,/UI;component/Resource/images/oneShelf.png", UriKind.RelativeOrAbsolute); bitmapImage.BeginInit(); bitmapImage.UriSource = new Uri("pack://application:,,,/UI;component/Resource/images/oneShelf.png", UriKind.RelativeOrAbsolute); bitmapImage.EndInit(); //设置旋转效果和阴影效果,开始 RotateTransform rotateTransform = new RotateTransform(0); DropShadowBitmapEffect bitmapEffect = new DropShadowBitmapEffect(); Color ShadowColor = new Color(); ShadowColor.ScA = 1;ShadowColor.ScB = 0;ShadowColor.ScG = 0;ShadowColor.ScR = 0; bitmapEffect.Color = ShadowColor; bitmapEffect.Direction = 320; bitmapEffect.ShadowDepth = 10; bitmapEffect.Softness = 0.1; bitmapEffect.Opacity = 0.1; //设置选择效果和阴影效果,结束 foreach (ShelfShape oneShelf in shelfMapShelfList) { //原始代码是绘制矩形框,现在改为绘制图片 //this.libraryShelfDrawer.drawShelf(oneShelf.topLeft, oneShelf.bottomRight); this.libraryShelfDrawer.drawImage(oneShelf.topLeft, oneShelf.bottomRight, bitmapImage, rotateTransform, bitmapEffect); } } catch (Exception) { this.eventAggregator.GetEvent<DatabaseEvent>().Publish("DrawMapService:从数据库中获取书架信息出错!"); //如果发生错误那发布事件 } //画出某个书库的轮廓 try { List<String> shelfContourPostionStringList = bookLocationService.getItemPositionStringListByLocationAndType(libraryNameInTable, "CONTOUR"); String shelfContourPostionString = ""; ContourShape shelfMapContour ; //轮廓信息存放的地点 //如果获得的轮廓个数小于零,则说明数据出现了问题.其实一个书库的轮廓只能有一个 if (shelfContourPostionStringList.Count > 0) { shelfContourPostionString = shelfContourPostionStringList[0]; char[] separator = { ',', ',' }; String[] pointDescInString = shelfContourPostionString.Split(separator); //轮廓点的个数只能是偶数个,如果解析和读取数据的时候出现任何错误,则花图书轮廓的程序终止 if ((pointDescInString.Length % 2 == 0) && (pointDescInString.Length >= 2)) { List<Double> pointXList = new List<Double>(); List<Double> pointYList = new List<Double>(); for (int i = 0; i < pointDescInString.Length; i = i + 2) { pointXList.Add(Convert.ToDouble(pointDescInString[i])); pointYList.Add(Convert.ToDouble(pointDescInString[i + 1])); } if (pointXList.Count == pointYList.Count) { List<Point> contourPointList = new List<Point>(); for (int i = 0; i < pointXList.Count(); i++) { Point onePoint = new Point(pointXList[i], pointYList[i]); contourPointList.Add(onePoint); } shelfMapContour = new ContourShape(contourPointList); this.libraryShelfDrawer.drawContour(shelfMapContour.pointList); } } } }catch(Exception) { this.eventAggregator.GetEvent<DatabaseEvent>().Publish("DrawMapService:从数据库中获取书库轮廓信息出错!"); //如果发生错误那发布事件 } //画出某个书库大门的位置 try { List<String> doorPostionStringList = bookLocationService.getItemPositionStringListByLocationAndType(libraryNameInTable, "DOOR"); DoorShape shelfMapDoor;//入口信息存放的位置 if (doorPostionStringList.Count > 0) { String doorPostionString = doorPostionStringList[0]; char[] separator = { ',', ',' }; String[] pointDescInString = doorPostionString.Split(separator); if (pointDescInString.Length == 4) { double[] pointDescInDouble = new double[] { Convert.ToDouble(pointDescInString[0]), Convert.ToDouble(pointDescInString[1]), Convert.ToDouble(pointDescInString[2]), Convert.ToDouble(pointDescInString[3]) }; Point leftTop = new Point(pointDescInDouble[0], pointDescInDouble[1]); Point rightBottom = new Point(pointDescInDouble[0] + pointDescInDouble[2], pointDescInDouble[1] + pointDescInDouble[3]); //把书库大门的位置信息放入结构体的变量中shelfMapShelfList shelfMapDoor = new DoorShape(leftTop, rightBottom); //载入入口图片 BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.UriSource = new Uri("pack://application:,,,/UI;component/Resource/images/door.png", UriKind.RelativeOrAbsolute); bitmapImage.EndInit(); //设置旋转效果和阴影效果,开始 RotateTransform rotateTransform = new RotateTransform(0); DropShadowBitmapEffect bitmapEffect = new DropShadowBitmapEffect(); //this.libraryShelfDrawer.drawDoor(shelfMapDoor.topLeft, shelfMapDoor.bottomRight); this.libraryShelfDrawer.drawImage(shelfMapDoor.topLeft, shelfMapDoor.bottomRight, bitmapImage, rotateTransform, bitmapEffect); } } } catch (Exception) { this.eventAggregator.GetEvent<DatabaseEvent>().Publish("DrawMapService:从数据库中获取书库大门信息出错!"); //如果发生错误那发布事件 } }