private void btnCrLineColor_Click(object sender, RoutedEventArgs e) { if (checkActive()) { MessageBox.Show(err, "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error); return; } try { Size s = new Size(app.ActiveSelection.SizeWidth, app.ActiveSelection.SizeHeight); ShapeRange rowRange = app.ActiveSelectionRange; ShapeRange colRev = app.ActiveSelectionRange; ShapeRange rowRev = app.ActiveSelectionRange; colRev.RemoveAll(); rowRev.RemoveAll(); rowRange.RemoveAll(); Size position = new Size(app.ActiveSelectionRange.PositionX, app.ActiveSelectionRange.PositionY); Size size = new Size(s.x * numCol.Value, s.y * numRow.Value); app.ActiveSelection.Delete(); Shape shapeCol = app.ActiveLayer.CreateLineSegment(position.x, position.y, position.x, position.y - size.y); shapeCol.Outline.Color.CMYKAssign(100, 0, 100, 0); double space = 0; for (int i = 0; i < numCol.Value; i++) { space += s.x; if (i % 2 == 0 || i == numCol.Value - 1) { colRev.Add(shapeCol.Duplicate(space, 0)); } else { shapeCol.Duplicate(space, 0); } } shapeCol.OrderToFront(); colRev.Flip(cdrFlipAxes.cdrFlipVertical); space = 0; Shape shapeRow = app.ActiveLayer.CreateLineSegment(position.x, position.y, position.x + size.x, position.y); shapeRow.Outline.Color.CMYKAssign(0, 100, 100, 0); rowRev.Add(shapeRow); for (int j = 0; j < numRow.Value; j++) { space += s.y; if (j % 2 != 0 || j == numRow.Value - 1) { rowRev.Add(shapeRow.Duplicate(0, -space)); } else { rowRange.Add(shapeRow.Duplicate(0, -space)); } } shapeRow.OrderToFront(); rowRange.AddRange(rowRev); rowRange.OrderReverse(); rowRev.Flip(cdrFlipAxes.cdrFlipHorizontal); app.ActiveLayer.CreateRectangle2(position.x, position.y - size.y, size.x, size.y).CreateSelection(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.Source, "Lỗi"); } }
private void CreateShapes() { int lastPoint = 0; try { WriteLog("emf", "Start"); if (listShapes.Count != 0) { WriteLog("emf", " - nb shapes : " + listShapes.Count); Slides listSlide = Globals.ThisAddIn.Application.ActivePresentation.Slides; foreach (Slide maSlide in listSlide) { ShapeRange srd = maSlide.Shapes.Range(); srd.Delete(); WriteLog("emf", " - all existing slides deleted"); List <object> listNames = new List <object>(); int c = 0; foreach (string shapefile in listShapes) { string[] shapeInfo = shapefile.Split('*'); string shapeName = shapeInfo[0]; string[] polygons = shapeInfo[1].Split('_'); WriteLog("emf", " - Working on shape : " + shapeName + " - " + polygons.Length + " polygones"); for (int i = 0; i < polygons.Length; i++) { if (polygons[i] != "") { string[] coordinates = polygons[i].Split(','); if (coordinates.Length > 1) { /* * * * for (int j = 0; j < (coordinates.Length - 1); j++) * { * float val = (float)Convert.ToDouble(coordinates[j].Replace('.', ',')); * * if (y == 0) * { * * points[x, y] = (val); * } * if (y == 1) * { * points[x, y] = (val); * } * x2 = x; * * y++; * if (y == 2) * { * y = 0; * x++; * } * * lastPoint++; * } * */ //Single[,] myPoints = new Single[5, 2]; // {500,50,505,55,510,60,515,65,520,70}; int nbPoints = (coordinates.Length - 1) / 2; WriteLog("emf", " " + nbPoints + " points to create"); Single[,] points = new Single[nbPoints, 2]; int x = 0; int y = 0; int x2 = 0; for (int j = 0; j < (coordinates.Length - 1); j++) { double val = double.Parse(coordinates[j], System.Globalization.CultureInfo.InvariantCulture); if (y == 0) { points[x, y] = (float)val; } if (y == 1) { points[x, y] = (float)val; } x2 = x; y++; if (y == 2) { y = 0; x++; } lastPoint++; } object po = points; // WriteLog("emf", " Shape " + shapeName + " ready to be drawed with " + ((lastPoint) / 2) + "/" + nbPoints + " points, x=" + x + " , y=" + y + ", x2=" + x2); lastPoint = 0; maSlide.Shapes.AddPolyline(po).Name = shapeName; WriteLog("emf", " Shape " + shapeName + " drawed"); listNames.Add(shapeName); } } } } object[] arrayNames = new object[listNames.Count]; foreach (object name in listNames) { arrayNames[c] = name; c++; } ShapeRange sr = maSlide.Shapes.Range(); WriteLog("emf", " - group all shapes"); sr.Group().Name = "MonGoupe"; sr.Flip(Microsoft.Office.Core.MsoFlipCmd.msoFlipVertical); WriteLog("emf", " - prepare to resize the shapes"); float longeur = sr.Width; float hauteur = sr.Height; int maxWidth = 1280; int maxHeight = 500; float coef = 0; if (longeur < hauteur) { c = maxWidth / Convert.ToInt32(longeur); longeur = longeur * c; hauteur = hauteur * c; } else { c = maxHeight / Convert.ToInt32(hauteur); longeur = longeur * c; hauteur = hauteur * c; } sr.Width = longeur; sr.Height = hauteur; WriteLog("emf", " - Shapes reseized"); WriteLog("emf", " - Process End"); WriteLog("emf", " - "); WriteLog("emf", " - "); } // MessageBox.Show("Finished"); this.Close(); //Set myDocument = ActivePresentation.Slides(1) //With myDocument.Shapes // .AddShape(msoShapeCan, 50, 10, 100, 200).Name = "shpOne" // .AddShape(msoShapeCube, 150, 250, 100, 200).Name = "shpTwo" // With.Range(Array("shpOne", "shpTwo")).Group // End With //End With } } catch (Exception ex) { MessageBox.Show(@"An error occurred while creating the map, please send the log files in the folder 'C:\OCHA_logs' to the support [email protected]"); WriteLog("emf", " - Error Message : " + ex.Message); WriteLog("emf", " - Error StackTrace : " + ex.StackTrace); WriteLog("emf", " - Error TargetSite : " + ex.TargetSite); WriteLog("emf", " - Error InnerException : " + ex.InnerException); WriteLog("emf", " - Error ToString : " + ex.ToString()); WriteLog("emf", " - Error GetBaseException : " + ex.GetBaseException().ToString()); } finally { } }