/*---------------------------------------------------------------------------------**//** * Actual modification on first data button if it lies on GroupedHole element. * @bsimethod Bentley Systems * /*--------------+---------------+---------------+---------------+---------------+------*/ protected override bool OnDataButton(Bentley.DgnPlatformNET.DgnButtonEvent ev) { //Locate an element. Bentley.DgnPlatformNET.HitPath hitPath = DoLocate(ev, true, 1); //If an element is located and the element is a grouped hole. //If element has a solid fill, remove it. //Else add a solid fill. if (null != hitPath) { int numHoles = PlaceGroupedHoleForm.GetNumberOfHoles(); Bentley.DgnPlatformNET.Elements.Element element = hitPath.GetHeadElement(); if (element is GroupedHoleElement) { GroupedHoleElement groupedHoleElement = element as GroupedHoleElement; uint fillColor; bool alwaysFilled; if (groupedHoleElement.GetSolidFill(out fillColor, out alwaysFilled)) { groupedHoleElement.RemoveAreaFill(); } else { groupedHoleElement.AddSolidFill((uint)Bentley.MstnPlatformNET.Settings.GetActiveFillColor().Index, false); } //Element must be replaced in model. groupedHoleElement.ReplaceInModel(groupedHoleElement); } } return(true); }
/*---------------------------------------------------------------------------------**//** * Calculates start and opposite points of holes and creates them. * @bsimethod Bentley Systems * /*--------------+---------------+---------------+---------------+---------------+------*/ private static void PopulateHolesAgenda(out ElementAgenda holes, DPoint3d start, DPoint3d opposite, DgnModel model) { holes = new ElementAgenda(); //How many holes are required by the user. Possible options are only 1, 2 and 4. int numHoles = PlaceGroupedHoleForm.GetNumberOfHoles(); System.Collections.Generic.List <DPoint3d> holeStarts = new List <DPoint3d>(); System.Collections.Generic.List <DPoint3d> holeEnds = new List <DPoint3d>(); if (1 == numHoles) //One hole in the middle of the shape. { double xFactor = (opposite.X - start.X) / 3; double yFactor = (start.Y - opposite.Y) / 3; holeStarts.Add(new DPoint3d(start.X + xFactor, start.Y - yFactor, start.Z)); holeEnds.Add(new DPoint3d(opposite.X - xFactor, opposite.Y + yFactor, opposite.Z)); } else if (2 == numHoles) //Two holes. { double xFactor = (opposite.X - start.X) / 5; double yFactor = (start.Y - opposite.Y) / 5; holeStarts.Add(new DPoint3d(start.X + xFactor, start.Y - yFactor, start.Z)); holeEnds.Add(new DPoint3d(start.X + (2 * xFactor), opposite.Y + yFactor, opposite.Z)); holeStarts.Add(new DPoint3d(opposite.X - (2 * xFactor), start.Y - yFactor, start.Z)); holeEnds.Add(new DPoint3d(opposite.X - xFactor, opposite.Y + yFactor, opposite.Z)); } else //if(4 == numHoles) Four holes. { double xFactor = (opposite.X - start.X) / 5; double yFactor = (start.Y - opposite.Y) / 5; holeStarts.Add(new DPoint3d(start.X + xFactor, start.Y - yFactor, start.Z)); holeEnds.Add(new DPoint3d(start.X + (2 * xFactor), start.Y - (2 * yFactor), opposite.Z)); holeStarts.Add(new DPoint3d(opposite.X - (2 * xFactor), start.Y - yFactor, start.Z)); holeEnds.Add(new DPoint3d(opposite.X - xFactor, start.Y - (2 * yFactor), opposite.Z)); holeStarts.Add(new DPoint3d(start.X + xFactor, opposite.Y + (2 * yFactor), start.Z)); holeEnds.Add(new DPoint3d(start.X + (2 * xFactor), opposite.Y + yFactor, opposite.Z)); holeStarts.Add(new DPoint3d(opposite.X - (2 * xFactor), opposite.Y + (2 * yFactor), start.Z)); holeEnds.Add(new DPoint3d(opposite.X - xFactor, opposite.Y + yFactor, opposite.Z)); } //Create hole elements and populate the agenda. for (int i = 0; i < numHoles; i++) { ShapeElement holeShape = CreateShapeElement(model, holeStarts[i], holeEnds[i]); holes.Insert(holeShape, true); } }