// 数据键(一般是左键)弹起时触发
        protected override bool OnDataButtonUp(DgnButtonEvent ev)
        {
            var result = base.OnDataButtonUp(ev);

            this.DgnToolDebug("OnDataButtonUp" + result.ToString());
            return(result);
        }
Exemplo n.º 2
0
        // 数据键(一般是左键)按下时触发
        protected override bool OnDataButton(DgnButtonEvent ev)
        {
            var result = true;

            this.DgnToolDebug("OnDataButton" + "抽象");

            return(result);
        }
Exemplo n.º 3
0
        /*---------------------------------------------------------------------------------**//**
        * Temporarly show how the element will look like.
        * @bsimethod                                                              Bentley Systems
        *  /*--------------+---------------+---------------+---------------+---------------+------*/
        protected override void OnDynamicFrame(DgnButtonEvent ev)
        {
            Element element = GroupedHoleHelper.CreateElement(m_points[0], ev.Point);

            if (null == element)
            {
                return;
            }

            RedrawElems redrawElems = new RedrawElems();

            redrawElems.SetDynamicsViewsFromActiveViewSet(Session.GetActiveViewport());
            redrawElems.DrawMode    = DgnDrawMode.TempDraw;
            redrawElems.DrawPurpose = DrawPurpose.Dynamics;

            redrawElems.DoRedraw(element);
        }
Exemplo n.º 4
0
        /*---------------------------------------------------------------------------------**//**
        * Get start and opposite points from data buttons in this method.
        *  /// Start dynamics on first data point.
        *  /// Place the grouped hole on second data point.
        * @bsimethod                                                              Bentley Systems
        *  /*--------------+---------------+---------------+---------------+---------------+------*/
        protected override bool OnDataButton(DgnButtonEvent ev)
        {
            if (0 == m_points.Count)
            {
                BeginDynamics();
            }

            m_points.Add(ev.Point); // Save current data point location.

            if (m_points.Count < 2)
            {
                return(false);
            }

            Element element = GroupedHoleHelper.CreateElement(m_points[0], m_points[1]);

            if (null != element)
            {
                element.AddToModel(); // Add new element to active model.
            }
            base.OnReinitialize();

            return(true);
        }
 protected override bool OnResetButton(DgnButtonEvent ev)
 {
 }
 protected override bool OnDataButton(DgnButtonEvent ev)
 {
 }
Exemplo n.º 7
0
 // 在里面进行动态元素显示的处理
 protected override void OnDynamicFrame(DgnButtonEvent ev)
 {
     this.DgnPrimitieToolDebug("OnDynamicFrame");
 }
        protected override bool OnDataButton(DgnButtonEvent ev)
        {
            try
            {
                if (m_haveFirstPoint)
                {
                    // we're going to write the element

                    base.EndDynamics();

                    // 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()));

                    //RedrawElems redrawElems = new RedrawElems();
                    //redrawElems.SetDynamicsViewsFromActiveViewSet(Bentley.MstnPlatformNET.Session.GetActiveViewport());
                    //redrawElems.DrawMode = DgnDrawMode.Normal;
                    //redrawElems.DrawPurpose = DrawPurpose.ForceRedraw;

                    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)
                                {
                                    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);

                                    copiedElement.AddToModel();

                                    BPSUtilities.WriteLog("Added element to model");

                                    RedrawElems redrawElems = new RedrawElems();
                                    redrawElems.SetDynamicsViewsFromActiveViewSet(ev.Viewport);
                                    redrawElems.DrawMode    = DgnDrawMode.Normal;
                                    redrawElems.DrawPurpose = DrawPurpose.ForceRedraw;

                                    redrawElems.DoRedraw(copiedElement);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        BPSUtilities.WriteLog($"OnDataBurron {ex.Message}\n{ex.StackTrace}");
                    }

                    m_haveFirstPoint = false;

                    m_firstPoint = new DPoint3d(0, 0, 0);

                    base.BeginDynamics();

                    return(true);
                }

                m_haveFirstPoint = true;

                m_firstPoint = ev.Point;

                base.BeginDynamics();
            }
            catch (Exception ex)
            {
                BPSUtilities.WriteLog($"OnDataButton {ex.Message}\n{ex.StackTrace}");
            }

            return(true);
        }
 protected override bool OnResetButton(DgnButtonEvent ev)
 {
     ExitTool();
     return(true);
 }
Exemplo n.º 10
0
        protected override bool OnDataButton(DgnButtonEvent ev)
        {
            try
            {
                if (m_haveFirstPoint)
                {
                    // we're going to write the element

                    base.EndDynamics();

                    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)
                            {
                                DMatrix3d invertedViewportRotation = new DMatrix3d(1, 0, 0, 0, 1, 0, 0, 0, 1);   // Identity

                                if (ev.Viewport.GetRotation().TryInvert(out invertedViewportRotation))
                                {
                                    // 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));

                                    DTransform3d translateAndRotatetoUpInViewAndScale =
                                        DTransform3d.FromMatrixAndTranslation(scaleRotateInViewRotateAroundPoint, translation);

                                    TransformInfo transformInfo2 = new TransformInfo(translateAndRotatetoUpInViewAndScale);

                                    codeElement.ApplyTransform(transformInfo2);

                                    //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.Max(Math.Abs(dWidth), 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);

                                    //// 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;
                                    //    }
                                    //}
                                    //// 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;
                                    //    }
                                    //    else
                                    //    {
                                    //        blkPts[2].X = blkPts[0].X - dDelta;
                                    //        blkPts[2].Y = blkPts[0].Y - dDelta;
                                    //    }
                                    //}

                                    //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;

                                    //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);

                                    RedrawElems redrawElems = new RedrawElems();
                                    redrawElems.SetDynamicsViewsFromActiveViewSet(Bentley.MstnPlatformNET.Session.GetActiveViewport());
                                    redrawElems.DrawMode    = DgnDrawMode.Normal;
                                    redrawElems.DrawPurpose = DrawPurpose.ForceRedraw;

                                    codeElement.AddToModel();

                                    redrawElems.DoRedraw(codeElement);

                                    m_haveFirstPoint = false;

                                    m_firstPoint = new DPoint3d(0, 0, 0);

                                    base.BeginDynamics();

                                    return(true);
                                }
                            }
                        }
                    }
                }
                else
                {
                    m_haveFirstPoint = true;

                    m_firstPoint = ev.Point;

                    // base.BeginDynamics();
                }
            }
            catch (Exception ex)
            {
                BPSUtilities.WriteLog($"OnDataButton {ex.Message}\n{ex.StackTrace}");
            }

            return(true);
        }