protected override bool OnDataButton(BD.DgnButtonEvent ev) { BD.HitPath hitPath = DoLocate(ev, true, 0); if (null != hitPath) { Element ele = hitPath.GetHeadElement(); if (ele.ElementType != BD.MSElementType.Line) { return(false); } BG.DRange3d linerange; if ((ele as LineElement).CalcElementRange(out linerange) != BD.StatusInt.Success) { return(false); } TopPoint = linerange.High; BottomPoint = linerange.Low; return(true); } else { return(false); } }
/*---------------------------------------------------------------------------------**//** * 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); }
protected override bool OnDataButton(BD.DgnButtonEvent ev) { BD.HitPath hitPath = DoLocate(ev, true, 1); if (null != hitPath) { BDDE.DgnECManager manager = BDDE.DgnECManager.Manager; BDDE.FindInstancesScope scope = BDDE.FindInstancesScope.CreateScope(hitPath.GetHeadElement(), new BDDE.FindInstancesScopeOption(BDDE.DgnECHostType.Element, true)); BDEPQ.ECQuery query = new BDEPQ.ECQuery(Extension.Utilities.GetActiveModelAllClasses()); query.SelectClause.SelectAllProperties = true; using (BDDE.DgnECInstanceCollection ecInstances = manager.FindInstances(scope, query)) { if (ecInstances == null) { return(false); } m_findinstacneOnElementViewModel.InstancesInfo.Clear(); //ObservableCollection<Instance> instanceCollection = new ObservableCollection<Instance>(); foreach (var ecin in ecInstances) { foreach (BES.IECProperty itemProp in ecin.ClassDefinition.Properties(false)) { var instanceitem = new Instance(); instanceitem.ClassName = ecin.ClassDefinition.DisplayLabel; instanceitem.PropertyName = itemProp.Name; string type = itemProp.Type.Name.ToLower(); instanceitem.TypeName = type; BEI.IECPropertyValue propvalue = ecin.GetPropertyValue(itemProp.Name); switch (type) { case "string": instanceitem.PropertyValue = (propvalue != null) ? propvalue.StringValue : ""; break; case "boolean": instanceitem.PropertyValue = (propvalue != null) ? propvalue.StringValue : ""; break; case "int": instanceitem.PropertyValue = (propvalue != null) ? propvalue.IntValue.ToString() : ""; break; case "double": instanceitem.PropertyValue = (propvalue != null) ? propvalue.DoubleValue.ToString() : ""; break; } m_findinstacneOnElementViewModel.InstancesInfo.Add(instanceitem); } } m_findinstacneOnElementViewModel.WindowTitle = hitPath.GetHeadElement().ElementId.ToString(); } } return(true); }
protected override bool OnDataButton(BD.DgnButtonEvent ev) { BD.HitPath hitPath = DoLocate(ev, true, 1); if (null != hitPath) { InstanceToWrite instanceInfo = (WriteInstanceOnElementView.Instance.DataContext as WriteInstanceOnElementViewModel).GetInstanceToWrite(); if (string.IsNullOrEmpty(instanceInfo.SchemaName) || string.IsNullOrEmpty(instanceInfo.ClassName) || instanceInfo.Properties.Count == 0) { mc.StatusPrompt = "请先选择要附加的class"; return(false); } BDEC.FindInstancesScope scope = BDEC.FindInstancesScope.CreateScope(Program.GetActiveDgnFile(), new BDEC.FindInstancesScopeOption()); BES.IECSchema schema = BDEC.DgnECManager.Manager.LocateSchemaInScope(scope, instanceInfo.SchemaName, instanceInfo.MajorVersion, instanceInfo.MinorVersion, BES.SchemaMatchType.Exact); BDE.Element ele = hitPath.GetHeadElement(); BES.ECClass class1 = schema.GetClass(instanceInfo.ClassName) as BES.ECClass; BDEC.DgnECInstanceEnabler instanceEnabler = BDEC.DgnECManager.Manager.ObtainInstanceEnabler(Program.GetActiveDgnFile(), class1); BEI.StandaloneECDInstance instance = instanceEnabler.SharedWipInstance; foreach (var pInfo in instanceInfo.Properties) { switch (pInfo.PropertyType.ToLower()) { case "string": instance.MemoryBuffer.SetStringValue(pInfo.PropertyName, -1, pInfo.GetValueAsString()); break; case "boolean": instance.MemoryBuffer.SetBooleanValue(pInfo.PropertyName, -1, pInfo.GetValueAsBoolean()); break; case "int": instance.MemoryBuffer.SetIntegerValue(pInfo.PropertyName, -1, pInfo.GetValueAsInt()); break; case "double": instance.MemoryBuffer.SetDoubleValue(pInfo.PropertyName, -1, pInfo.GetValueAsDouble()); break; } } instanceEnabler.CreateInstanceOnElement(ele, instance, false); mc.StatusPrompt = "附加完成"; mc.StatusMessage = $"将{instanceInfo.ClassName}附加到ID:{ele.ElementId}物体上"; } return(true); }
protected override bool OnResetButton(BD.DgnButtonEvent ev) { ExitTool(); return(true); }
protected override void OnDynamicFrame(Bentley.DgnPlatformNET.DgnButtonEvent ev) { try { if (PolyhedraCE.StaticElement == null) { if (!string.IsNullOrEmpty(PolyhedronName)) { if (PolyhedraCE.ListOfPolyhedra.ContainsKey(PolyhedronName)) { BPSUtilities.WriteLog($"Found cell for '{PolyhedronName}'"); PolyhedraCE.StaticElement = PolyhedraCE.ListOfPolyhedra[PolyhedronName]; } else { m_haveFirstPoint = false; BPSUtilities.WriteLog($"Cell for '{PolyhedronName}' not found."); this.EndDynamics(); } } else { BPSUtilities.WriteLog("Polyhedron Name not set."); m_haveFirstPoint = false; this.EndDynamics(); } } try { Bentley.DgnPlatformNET.Elements.CellHeaderElement cellElem = (Bentley.DgnPlatformNET.Elements.CellHeaderElement)(PolyhedraCE.StaticElement); if (cellElem.CellName != PolyhedronName) { BPSUtilities.WriteLog($"Current cell is {cellElem.CellName}"); if (!string.IsNullOrEmpty(PolyhedronName)) { if (PolyhedraCE.ListOfPolyhedra.ContainsKey(PolyhedronName)) { BPSUtilities.WriteLog($"Found cell for '{PolyhedronName}'"); if (PolyhedraCE.StaticElement != null) { PolyhedraCE.StaticElement.Dispose(); } PolyhedraCE.StaticElement = PolyhedraCE.ListOfPolyhedra[PolyhedronName]; } else { m_haveFirstPoint = false; BPSUtilities.WriteLog($"Cell for '{PolyhedronName}' not found."); this.EndDynamics(); } } else { BPSUtilities.WriteLog("Polyhedron Name not set."); m_haveFirstPoint = false; this.EndDynamics(); } } } catch (Exception ex) { BPSUtilities.WriteLog($"Error casting cell {ex.Message}"); } if (PolyhedraCE.StaticElement != null) { RedrawElems redrawElems = new RedrawElems(); redrawElems.SetDynamicsViewsFromActiveViewSet(Bentley.MstnPlatformNET.Session.GetActiveViewport()); redrawElems.DrawMode = DgnDrawMode.TempDraw; redrawElems.DrawPurpose = DrawPurpose.Dynamics; try { DMatrix3d invertedViewportRotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1); // Identity if (ev.Viewport.GetRotation().TryInvert(out invertedViewportRotation)) { DMatrix3d cellRotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1); // Identity List <Bentley.DgnPlatformNET.Elements.Element> listChildElements = new List <Bentley.DgnPlatformNET.Elements.Element>(); foreach (Bentley.DgnPlatformNET.Elements.Element child in PolyhedraCE.StaticElement.GetChildren()) { listChildElements.Add(child); } Bentley.DgnPlatformNET.Elements.CellHeaderElement copiedElement = new CellHeaderElement(Session.Instance.GetActiveDgnModel(), PolyhedronName, new DPoint3d(0, 0, 0), cellRotation, listChildElements); if (copiedElement != null) { if (copiedElement.IsValid) { if (!m_haveFirstPoint) { DPoint3d translation = ev.Point; DMatrix3d viewMatrix = ev.Viewport.GetRotation(); DPoint3d[] blkPts = new DPoint3d[4]; DPoint3d low = DPoint3d.Zero, high = DPoint3d.Zero; ev.Viewport.GetViewCorners(out low, out high); // rotate points to orthogonal blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(low))); blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(high))); blkPts[2].Z = blkPts[0].Z; DPoint3d ext = DPoint3d.Subtract(blkPts[2], blkPts[0]); double dScale = Math.Max(0.15 * Math.Abs(ext.Magnitude / uorPerMaster()), 1.0); DPoint3d dPtScale = ev.Viewport.GetScale(); // dScale = dPtScale.Magnitude; // BPSUtilities.WriteLog($"Scale: {dScale}, View: {ev.ViewNumber}"); invertedViewportRotation.ScaleInPlace(dScale); // works DTransform3d translateAndRotateToUpInViewWithViewBasedScale = DTransform3d.FromMatrixAndTranslation(invertedViewportRotation, translation); TransformInfo transformInfo = new TransformInfo(translateAndRotateToUpInViewWithViewBasedScale); // works copiedElement.ApplyTransform(transformInfo); } else { // now to work on rotation and scale DPoint3d translation = m_firstPoint; DMatrix3d viewMatrix = ev.Viewport.GetRotation(); DPoint3d[] blkPts = new DPoint3d[4]; // rotate points to orthogonal blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(m_firstPoint))); blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(ev.Point))); blkPts[2].Z = blkPts[0].Z; DPoint3d ext = DPoint3d.Subtract(blkPts[2], blkPts[0]); DVector3d angleVec = new DVector3d(ext); double dScale = Math.Max(0.1, Math.Abs(ext.Magnitude / uorPerMaster())); invertedViewportRotation.ScaleInPlace(dScale); DMatrix3d scaleRotateInViewRotateAroundPoint = DMatrix3d.Multiply(invertedViewportRotation, DMatrix3d.Rotation(2, angleVec.AngleXY)); DTransform3d translateAndRotatetoUpInViewAndScale = DTransform3d.FromMatrixAndTranslation(scaleRotateInViewRotateAroundPoint, translation); TransformInfo transformInfo2 = new TransformInfo(translateAndRotatetoUpInViewAndScale); copiedElement.ApplyTransform(transformInfo2); } redrawElems.DoRedraw(copiedElement); } } } } catch (Exception ex) { BPSUtilities.WriteLog($"{ex.Message}\n{ex.StackTrace}"); } // if (!m_haveFirstPoint) //{ // BPSUtilities.WriteLog("Don't have first point."); // // move it around on cursor // redrawElems.DoRedraw(GetTransformedElement(m_element, ev)); //} //else //{ // BPSUtilities.WriteLog("Do have first point."); // redrawElems.DoRedraw(GetTransformedElement(m_element, ev)); //} } else { BPSUtilities.WriteLog("Element is null"); this.EndDynamics(); } } catch (Exception ex) { BPSUtilities.WriteLog($"OnDynamicFrame: {ex.Message}\n{ex.StackTrace}"); } }
protected override void OnDynamicFrame(Bentley.DgnPlatformNET.DgnButtonEvent ev) { RedrawElems redrawElems = new RedrawElems(); redrawElems.SetDynamicsViewsFromActiveViewSet(Bentley.MstnPlatformNET.Session.GetActiveViewport()); redrawElems.DrawMode = DgnDrawMode.TempDraw; redrawElems.DrawPurpose = DrawPurpose.Dynamics; try { DMatrix3d invertedViewportRotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1); // Identity if (ev.Viewport.GetRotation().TryInvert(out invertedViewportRotation)) { if (CodeElement != null) { if (CodeElement.IsValid) { List <Bentley.DgnPlatformNET.Elements.Element> listChildElements = CodeElement.GetChildren().GetEnumerator().ConvertToList(); Bentley.DgnPlatformNET.Elements.CellHeaderElement codeElement = new CellHeaderElement(Session.Instance.GetActiveDgnModel(), "QRCode", DPoint3d.Zero, DMatrix3d.Identity, listChildElements); if (codeElement.IsValid) { if (m_haveFirstPoint) { // now to work on rotation and scale DPoint3d translation = m_firstPoint; DMatrix3d viewMatrix = ev.Viewport.GetRotation(); DPoint3d[] blkPts = new DPoint3d[4]; // rotate points to orthogonal blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(m_firstPoint))); blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(ev.Point))); blkPts[2].Z = blkPts[0].Z; DPoint3d ext = DPoint3d.Subtract(blkPts[2], blkPts[0]); DVector3d angleVec = new DVector3d(ext); // double dScale = Math.Max(0.1, Math.Abs(ext.Magnitude / uorPerMaster())); invertedViewportRotation.ScaleInPlace(ext.Magnitude); DVector3d xVec = new DVector3d(1, 0, 0); DVector3d yVec = new DVector3d(0, 1, 0); Angle angle = Angle.Zero; //// UR and LR if (angleVec.AngleTo(xVec).Radians >= 0.0 && angleVec.AngleTo(xVec).Radians <= (Angle.PI.Radians / 2.0)) { if (angleVec.AngleTo(yVec).Radians >= 0.0 && angleVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0)) { angle = Angle.Zero; } else { angle.Radians = Angle.NEGATIVE_PI.Radians / 2.0; } } // UL and LL else { if (angleVec.AngleTo(yVec).Radians >= 0.0 && angleVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0)) { angle.Radians = Angle.PI.Radians / 2.0; } else { angle.Radians = Angle.PI.Radians; } } DMatrix3d scaleRotateInViewRotateAroundPoint = DMatrix3d.Multiply(invertedViewportRotation, // DMatrix3d.Rotation(2, angleVec.AngleXY)); DMatrix3d.Rotation(2, angle)); // DMatrix3d scaleRotateInViewRotateAroundPoint = DMatrix3d.Multiply(invertedViewportRotation, // DMatrix3d.Rotation(2, angleVec.AngleXY)); DTransform3d translateAndRotatetoUpInViewAndScale = DTransform3d.FromMatrixAndTranslation(scaleRotateInViewRotateAroundPoint, translation); TransformInfo transformInfo2 = new TransformInfo(translateAndRotatetoUpInViewAndScale); codeElement.ApplyTransform(transformInfo2); // below works great for drawing a block //DPoint3d[] blkPts = new DPoint3d[4]; //DMatrix3d viewMatrix = ev.Viewport.GetRotation(); //// rotate points to orthogonal //blkPts[0] = new DPoint3d(viewMatrix.Multiply(new DVector3d(m_firstPoint))); //blkPts[2] = new DPoint3d(viewMatrix.Multiply(new DVector3d(ev.Point))); //blkPts[2].Z = blkPts[0].Z; //blkPts[1].X = blkPts[0].X; //blkPts[1].Y = blkPts[2].Y; //blkPts[1].Z = blkPts[0].Z; //blkPts[3].X = blkPts[2].X; //blkPts[3].Y = blkPts[0].Y; //blkPts[3].Z = blkPts[0].Z; //DVector3d dVec = new DVector3d(blkPts[0], blkPts[2]); //double dWidth = blkPts[0].Distance(blkPts[1]); //double dHeight = blkPts[0].Distance(blkPts[3]); //double dDelta = Math.Abs(dWidth); //if (Math.Abs(dHeight) > Math.Abs(dWidth)) // dDelta = Math.Abs(dHeight); //blkPts[3] = blkPts[2] = blkPts[1] = blkPts[0]; //DVector3d xVec = new DVector3d(1, 0, 0); //DVector3d yVec = new DVector3d(0, 1, 0); //double xFactor = 1.0, yFactor = 1.0; //// UR and LR //if (dVec.AngleTo(xVec).Radians >= 0.0 && dVec.AngleTo(xVec).Radians <= (Angle.PI.Radians / 2.0)) //{ // if (dVec.AngleTo(yVec).Radians >= 0.0 && dVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0)) // { // blkPts[2].X = blkPts[0].X + dDelta; // blkPts[2].Y = blkPts[0].Y + dDelta; // } // else // { // blkPts[2].X = blkPts[0].X + dDelta; // blkPts[2].Y = blkPts[0].Y - dDelta; // yFactor = -1.0; // } //} //// UL and LL //else //{ // if (dVec.AngleTo(yVec).Radians >= 0.0 && dVec.AngleTo(yVec).Radians <= (Angle.PI.Radians / 2.0)) // { // blkPts[2].X = blkPts[0].X - dDelta; // blkPts[2].Y = blkPts[0].Y + dDelta; // xFactor = -1.0; // } // else // { // blkPts[2].X = blkPts[0].X - dDelta; // blkPts[2].Y = blkPts[0].Y - dDelta; // xFactor = -1.0; // yFactor = -1.0; // } //} //blkPts[1].X = blkPts[0].X; //blkPts[1].Y = blkPts[2].Y; //blkPts[1].Z = blkPts[0].Z; //blkPts[3].X = blkPts[2].X; //blkPts[3].Y = blkPts[0].Y; //blkPts[3].Z = blkPts[0].Z; //DPoint3d[] blkPts2 = new DPoint3d[4]; //blkPts2[0] = blkPts2[1] = blkPts2[2] = blkPts2[3] = blkPts[0]; //for (int i = 0; i < 4; i++) //{ // blkPts[i] = new DPoint3d(invertedViewportRotation.Multiply(new DVector3d(blkPts[i]))); //} //Bentley.DgnPlatformNET.Elements.ShapeElement shapeElement = // new Bentley.DgnPlatformNET.Elements.ShapeElement(Session.Instance.GetActiveDgnModel(), null, blkPts); //blkPts2[0].X += (xFactor) * dDelta / 4.0; //blkPts2[0].Y += (yFactor) * dDelta / 4.0; //blkPts2[2].X += (xFactor) * 3.0 * (dDelta / 4.0); //blkPts2[2].Y += (yFactor) * 3.0 * (dDelta / 4.0); //blkPts2[1].X = blkPts2[0].X; //blkPts2[1].Y = blkPts2[2].Y; //blkPts2[1].Z = blkPts2[0].Z; //blkPts2[3].X = blkPts2[2].X; //blkPts2[3].Y = blkPts2[0].Y; //blkPts2[3].Z = blkPts2[0].Z; //for (int i = 0; i < 4; i++) //{ // blkPts2[i] = new DPoint3d(invertedViewportRotation.Multiply(new DVector3d(blkPts2[i]))); //} //Bentley.DgnPlatformNET.Elements.ShapeElement shapeElement2 = // new Bentley.DgnPlatformNET.Elements.ShapeElement(Session.Instance.GetActiveDgnModel(), null, blkPts2); //redrawElems.DoRedraw(shapeElement); //redrawElems.DoRedraw(shapeElement2); } else { // picking something arbitrary to use as scale factor invertedViewportRotation.ScaleInPlace(Bentley.MstnPlatformNET.Settings.TextHeight); DTransform3d scaleAndRotateToUpInView = DTransform3d.FromMatrixAndTranslation(invertedViewportRotation, ev.Point); TransformInfo transformInfo = new TransformInfo(scaleAndRotateToUpInView); codeElement.ApplyTransform(transformInfo); } redrawElems.DoRedraw(codeElement); } } } } } catch (Exception ex) { BPSUtilities.WriteLog($"{ex.Message}\n{ex.StackTrace}"); } }