示例#1
0
        /// <summary>
        /// This method requests a point and returns a joint. If a joint is found, the method gets it. If not, then creates one and if the created joint lies on a line,
        /// then the command splits the line and adds the new line to the newLines list.
        /// </summary>
        /// <param name="newLines"> List of new lines created by this method while creating new joints </param>
        /// <returns> The created or found joint </returns>
        public Model.Joint GetJoint(IList <Model.LineElement> newLines)
        {
            Model.Joint joint;
            Canguro.Controller.Snap.Magnet magnet = GetPoint();
            if (magnet == null)
            {
                return(null);
            }
            if (magnet is Canguro.Controller.Snap.PointMagnet && ((Canguro.Controller.Snap.PointMagnet)magnet).Joint != null)
            {
                joint = ((Canguro.Controller.Snap.PointMagnet)magnet).Joint;
            }
            else
            {
                Microsoft.DirectX.Vector3 v = magnet.SnapPosition;
                joint = new Canguro.Model.Joint(v.X, v.Y, v.Z);
                Model.JointList.Add(joint);

                if (magnet is Canguro.Controller.Snap.PointMagnet)
                {
                    Canguro.Controller.Snap.PointMagnet pmag = (Canguro.Controller.Snap.PointMagnet)magnet;
                    if (pmag.RelatedMagnets != null && pmag.RelatedMagnets.Count > 0)
                    {
                        for (int i = 0; i < pmag.RelatedMagnets.Count; i++)
                        {
                            if (pmag.RelatedMagnets[i] is Canguro.Controller.Snap.LineMagnet && ((Canguro.Controller.Snap.LineMagnet)pmag.RelatedMagnets[i]).Line != null)
                            {
                                Canguro.Commands.Model.SplitCmd.Split(((Canguro.Controller.Snap.LineMagnet)pmag.RelatedMagnets[i]).Line, joint, Model);
                            }
                        }
                    }
                }
                else if (magnet is Canguro.Controller.Snap.LineMagnet)
                {
                    Canguro.Controller.Snap.LineMagnet lmag = (Canguro.Controller.Snap.LineMagnet)magnet;
                    if (lmag.Line != null)
                    {
                        Canguro.Commands.Model.SplitCmd.Split(((Canguro.Controller.Snap.LineMagnet)magnet).Line, joint, Model);
                    }
                }
            }
            SnapPrimaryPoint = new Canguro.Controller.Snap.PointMagnet(joint);
            return(joint);
        }
示例#2
0
        internal bool MouseMove(GraphicView activeView, System.Windows.Forms.MouseEventArgs e)
        {
            bool needPaint = false;
            Item newHover  = pickItem(e);

            if (hoverItem != newHover)
            {
                if (!showingTooltip)
                {
                    if (newHover != null)
                    {
                        timer.Change(TooltipDelay, System.Threading.Timeout.Infinite);
                    }
                    else
                    {
                        timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                    }
                }
                else
                {
                    if (newHover == null)
                    {
                        timer.Change(TooltipDelay, System.Threading.Timeout.Infinite);
                    }
                    else
                    {
                        timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                    }
                }
            }

            if (hoverItem != null || hoverItem != newHover)
            {
                needPaint = true;
            }

            hoverItem = newHover;

            Model.Model model = Model.Model.Instance;
            View.Renderer.RenderOptions options = activeView.ModelRenderer.RenderOptions;

            // Get position in the item's local coordinate system
            if (hoverItem is Joint)
            {
                hoverPos = getHoverPos((Joint)hoverItem, model, options);
            }
            else if (hoverItem is LineElement)
            {
                LineElement line = hoverItem as LineElement;

                if (options.ShowDeformed)
                {
                    hoverPos = getHoverPos(line, activeView, e.Location, model, options);
                }
                else
                {
                    Snap.LineMagnet lm = new Canguro.Controller.Snap.LineMagnet(line);
                    lm.Snap(activeView, e.Location);
                    hoverPos  = lm.SnapPositionInt;
                    hoverXPos = (hoverPos - line.I.Position).Length() / line.LengthInt;
                }
            }

            // Get text to draw
            tooltipText = itemTextBuilder.GetItemText(hoverItem, hoverPos, hoverXPos);

            // Get Size of text
            if (!string.IsNullOrEmpty(tooltipText))
            {
                tooltipRectangle = hoverPainter.MeasureText(tooltipText);
#if DEBUG
                if (tooltipRectangle.Width == 0 || tooltipRectangle.Height == 0)
                {
                    throw new Exception("Measure String returned 0");
                }
#endif
                tooltipRectangle.Location += deltaRect;
                tooltipRectangle.X        += e.X;
                tooltipRectangle.Y        += e.Y;
                tooltipRectangle.Width    += 8;
                tooltipRectangle.Height   += 4;

                Viewport vp = activeView.Viewport;
                if (tooltipRectangle.Right > (vp.X + vp.Width))
                {
                    tooltipRectangle.X -= (tooltipRectangle.Width + 2 * deltaRect.Width);
                }

                rectHelper.MouseMove(activeView, tooltipRectangle.Location, tooltipRectangle.Location + tooltipRectangle.Size);
            }
            else if (!showingTooltip)
            {
                timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
            }

            return(showingTooltip || needPaint);
        }
示例#3
0
        private Vector3 getHoverPos(LineElement line, GraphicView activeView, Point location, Model.Model model, View.Renderer.RenderOptions options)
        {
            Vector3 pos                   = Vector3.Empty;
            bool    lastUndoEnabled       = model.Undo.Enabled;
            bool    lastUnitSystemEnabled = Model.UnitSystem.UnitSystemsManager.Instance.Enabled;

            if (!model.HasResults || model.Results.ActiveCase == null)
            {
                return(pos);
            }

            try
            {
                if (model.IsLocked)
                {
                    model.Undo.Enabled = false;
                }

                Model.UnitSystem.UnitSystemsManager.Instance.Enabled = false;

                int numPoints = (int)options.LOD.GetLOD(line).LODSegments + 1;

                float[] xPos;
                Analysis.LineDeformationCalculator calc = new Analysis.LineDeformationCalculator();
                curve = calc.GetCurve(line, model.Results.ActiveCase.AbstractCase, numPoints, options.DeformationScale, model.Results.PaintScaleFactorTranslation, out xPos);

                int             iCurve = 0, numLines = curve.Length - 1;
                Snap.LineMagnet minLine = null, lm;
                float           minLineDist = float.MaxValue, lineDist;

                for (int i = 0; i < numLines; i++)
                {
                    lm = new Canguro.Controller.Snap.LineMagnet(curve[i], curve[i + 1] - curve[i], Canguro.Controller.Snap.LineMagnetType.FollowProjection);
                    if ((lineDist = lm.Snap(activeView, location)) < minLineDist)
                    {
                        if ((lm.SnapPositionInt - curve[i]).LengthSq() <= (curve[i + 1] - curve[i]).LengthSq())
                        {
                            minLineDist = lineDist;
                            minLine     = lm;
                            iCurve      = i;
                        }
                    }
                }

                if (minLine != null)
                {
                    pos = minLine.SnapPositionInt;
                    lm  = new Canguro.Controller.Snap.LineMagnet(curve[iCurve], curve[iCurve + 1] - curve[iCurve], Canguro.Controller.Snap.LineMagnetType.FollowProjection);

                    Vector3 tmp      = pos - curve[0];
                    Vector3 xPosUnit = curve[numLines] - curve[0];
                    xPosUnit  = Vector3.Scale(xPosUnit, 1.0f / xPosUnit.LengthSq());
                    hoverXPos = Vector3.Dot(tmp, xPosUnit);
                }
                else
                {
                    hoverItem = null;
                }
            }
            finally
            {
                Model.UnitSystem.UnitSystemsManager.Instance.Enabled = lastUnitSystemEnabled;
                model.Undo.Enabled = lastUndoEnabled;
            }

            return(pos);
        }
        internal bool MouseMove(GraphicView activeView, System.Windows.Forms.MouseEventArgs e)
        {
            bool needPaint = false;
            Item newHover = pickItem(e);
            if (hoverItem != newHover)
            {
                if (!showingTooltip)
                {
                    if (newHover != null)
                        timer.Change(TooltipDelay, System.Threading.Timeout.Infinite);
                    else
                        timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                }
                else
                {
                    if (newHover == null)
                        timer.Change(TooltipDelay, System.Threading.Timeout.Infinite);
                    else
                        timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                }
            }

            if (hoverItem != null || hoverItem != newHover)
                needPaint = true;

            hoverItem = newHover;

            Model.Model model = Model.Model.Instance;
            View.Renderer.RenderOptions options = activeView.ModelRenderer.RenderOptions;

            // Get position in the item's local coordinate system
            if (hoverItem is Joint)
                hoverPos = getHoverPos((Joint)hoverItem, model, options);
            else if (hoverItem is LineElement)
            {
                LineElement line = hoverItem as LineElement;

                if (options.ShowDeformed)
                    hoverPos = getHoverPos(line, activeView, e.Location, model, options);
                else
                {
                    Snap.LineMagnet lm = new Canguro.Controller.Snap.LineMagnet(line);
                    lm.Snap(activeView, e.Location);
                    hoverPos = lm.SnapPositionInt;
                    hoverXPos = (hoverPos - line.I.Position).Length() / line.LengthInt;
                }
            }

            // Get text to draw
            tooltipText = itemTextBuilder.GetItemText(hoverItem, hoverPos, hoverXPos);

            // Get Size of text
            if (!string.IsNullOrEmpty(tooltipText))
            {
                tooltipRectangle = hoverPainter.MeasureText(tooltipText);
            #if DEBUG
                if (tooltipRectangle.Width == 0 || tooltipRectangle.Height == 0)
                    throw new Exception("Measure String returned 0");
            #endif
                tooltipRectangle.Location += deltaRect;
                tooltipRectangle.X += e.X;
                tooltipRectangle.Y += e.Y;
                tooltipRectangle.Width += 8;
                tooltipRectangle.Height += 4;

                Viewport vp = activeView.Viewport;
                if (tooltipRectangle.Right > (vp.X + vp.Width))
                    tooltipRectangle.X -= (tooltipRectangle.Width + 2 * deltaRect.Width);

                rectHelper.MouseMove(activeView, tooltipRectangle.Location, tooltipRectangle.Location + tooltipRectangle.Size);
            }
            else if (!showingTooltip)
                timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);

            return showingTooltip || needPaint;
        }
        private Vector3 getHoverPos(LineElement line, GraphicView activeView, Point location, Model.Model model, View.Renderer.RenderOptions options)
        {
            Vector3 pos = Vector3.Empty;
            bool lastUndoEnabled = model.Undo.Enabled;
            bool lastUnitSystemEnabled = Model.UnitSystem.UnitSystemsManager.Instance.Enabled;

            if (!model.HasResults || model.Results.ActiveCase == null)
                return pos;

            try
            {
                if (model.IsLocked)
                    model.Undo.Enabled = false;

                Model.UnitSystem.UnitSystemsManager.Instance.Enabled = false;

                int numPoints = (int)options.LOD.GetLOD(line).LODSegments + 1;

                float[] xPos;
                Analysis.LineDeformationCalculator calc = new Analysis.LineDeformationCalculator();
                curve = calc.GetCurve(line, model.Results.ActiveCase.AbstractCase, numPoints, options.DeformationScale, model.Results.PaintScaleFactorTranslation, out xPos);

                int iCurve = 0, numLines = curve.Length - 1;
                Snap.LineMagnet minLine = null, lm;
                float minLineDist = float.MaxValue, lineDist;

                for (int i = 0; i < numLines; i++)
                {
                    lm = new Canguro.Controller.Snap.LineMagnet(curve[i], curve[i + 1] - curve[i], Canguro.Controller.Snap.LineMagnetType.FollowProjection);
                    if ((lineDist = lm.Snap(activeView, location)) < minLineDist)
                    {
                        if ((lm.SnapPositionInt - curve[i]).LengthSq() <= (curve[i + 1] - curve[i]).LengthSq())
                        {
                            minLineDist = lineDist;
                            minLine = lm;
                            iCurve = i;
                        }
                    }
                }

                if (minLine != null)
                {
                    pos = minLine.SnapPositionInt;
                    lm = new Canguro.Controller.Snap.LineMagnet(curve[iCurve], curve[iCurve + 1] - curve[iCurve], Canguro.Controller.Snap.LineMagnetType.FollowProjection);

                    Vector3 tmp = pos - curve[0];
                    Vector3 xPosUnit = curve[numLines] - curve[0];
                    xPosUnit = Vector3.Scale(xPosUnit, 1.0f / xPosUnit.LengthSq());
                    hoverXPos = Vector3.Dot(tmp, xPosUnit);
                }
                else
                    hoverItem = null;
            }
            finally
            {
                Model.UnitSystem.UnitSystemsManager.Instance.Enabled = lastUnitSystemEnabled;
                model.Undo.Enabled = lastUndoEnabled;
            }

            return pos;
        }