Exemple #1
0
        private void UpdateShapesDuringMove(List <bool> changedJoints, ObservableCollection <JointData> data, DoWorkEventArgs doWorkEventArgs)
        {
            try
            {
                if (shapesCreatedDuringMove == null || !shapesCreatedDuringMove.Any())
                {
                    if (SimulateOnMove.CancellationPending)
                    {
                        doWorkEventArgs.Cancel = true; return;
                    }
                }
                {
                    var linkNames = new List <string>();
                    shapesCreatedDuringMove = new List <UIElement>(Children.Where(s => s is PositionPath));
                    for (int i = 0; i < changedJoints.Count; i++)
                    {
                        if (!changedJoints[i])
                        {
                            continue;
                        }
                        foreach (var linkName in data[i].LinkNamesList.Where(ln => !linkNames.Contains(ln)))
                        {
                            linkNames.Add(linkName);
                            shapesCreatedDuringMove.Add(linkName.Equals("ground")
                                ? Children.First(s => s is GroundLinkShape)
                                : Children.First(s => (s is LinkShape && linkName.Equals(((LinkShape)s).Name))));
                        }
                    }
                }

                for (int index = shapesCreatedDuringMove.Count - 1; index >= 0; index--)
                {
                    if (SimulateOnMove.CancellationPending)
                    {
                        doWorkEventArgs.Cancel = true; return;
                    }
                    var child = shapesCreatedDuringMove[index];
                    shapesCreatedDuringMove.RemoveAt(index);
                    Children.Remove(child);

                    if (child is LinkShape)
                    {
                        ((LinkShape)child).ClearBindings();
                        var thisLink = movingPMKS.Links.Contains(((LinkShape)child).thisLink)
                            ? ((LinkShape)child).thisLink
                            : movingPMKS.Links.First(c => c.name == ((LinkShape)child).thisLink.name);
                        child = new LinkShape(((LinkShape)child).linkNum, thisLink, XAxisOffset, YAxisOffset, penThick,
                                              jointSize, null, DisplayConstants.DefaultBufferRadius / ScaleFactor);
                    }
                    else if (child is GroundLinkShape)
                    {
                        child = new GroundLinkShape(movingPMKS.GroundLink, XAxisOffset, YAxisOffset, penThick, jointSize,
                                                    DisplayConstants.DefaultBufferRadius / ScaleFactor);
                    }
                    else if (child is PositionPath)
                    {
                        child.ClearValue(OpacityProperty);
                        var i = ((PositionPath)child).index;
                        child = new PositionPath(i, movingPMKS.JointParameters, data[i],
                                                 XAxisOffset, YAxisOffset, movingPMKS.CycleType == CycleTypes.OneCycle,
                                                 penThick);
                    }
                    shapesCreatedDuringMove.Add(child);
                    Children.Add(child);
                }
            }
            catch (Exception exc)
            {
                App.main.status("Error in UpdateShapesDuringMove: " + exc);
                App.main.ParseData(true);
            }
        }
Exemple #2
0
        internal void DrawStaticShapes(Simulator pmks, ObservableCollection <JointData> jointData)
        {
            Children.Clear();
            Children.Add(axes);
            initialPositionIcons.Clear();
            for (int index = 0; index < pmks.Joints.Count; index++)
            {
                var                 j                   = pmks.Joints[index];
                var                 isDriver            = (index == App.main.drivingIndex);
                JointData           jointRowData        = (index < jointData.Count) ? jointData[index] : null;
                InputJointBaseShape inputJointBaseShape = null;
                switch (j.TypeOfJoint)
                {
                case JointType.R:
                    inputJointBaseShape =
                        new InputRJointShape(jointSize, penThick, j.xInitial, j.yInitial, XAxisOffset,
                                             YAxisOffset, j.IsGround, isDriver, index, jointRowData);
                    break;

                case JointType.P:
                    inputJointBaseShape =
                        new InputPJointShape(jointSize, penThick, j.xInitial, j.yInitial, XAxisOffset,
                                             YAxisOffset, j.SlideAngleInitial, j.IsGround, isDriver, index, jointRowData);
                    break;

                case JointType.RP:
                    inputJointBaseShape =
                        new InputRPJointShape(jointSize, penThick, j.xInitial, j.yInitial, XAxisOffset,
                                              YAxisOffset, j.SlideAngleInitial, j.IsGround, index, jointRowData);
                    break;

                case JointType.G:
                    inputJointBaseShape = new InputGJointShape(jointSize, penThick, j.xInitial, j.yInitial, XAxisOffset,
                                                               YAxisOffset, j.SlideAngleInitial, j.IsGround, index, jointRowData);
                    break;
                }
                Children.Add(inputJointBaseShape);
                initialPositionIcons.Add(inputJointBaseShape);
            }
            /* remove old ground shapes */
            Children.Remove(groundLinkShape);
            groundLinkShape = new GroundLinkShape(pmks.GroundLink, XAxisOffset, YAxisOffset, penThick, jointSize,
                                                  DisplayConstants.DefaultBufferRadius / ScaleFactor);
            Children.Add(groundLinkShape);
            /* now add the link shapes */
            for (int i = 0; i < pmks.NumLinks; i++)
            {
                if (!pmks.Links[i].name.Equals("ground"))
                {
                    Children.Add(new LinkShape(i, pmks.Links[i], XAxisOffset, YAxisOffset, penThick, jointSize, null,
                                               DisplayConstants.DefaultBufferRadius / ScaleFactor));
                }
            }
            if (TargetPath != null)
            {
                Children.Remove(TargetPath);
                TargetPath.RenderTransform
                    = new TranslateTransform {
                    X = XAxisOffset, Y = YAxisOffset
                    };
                Children.Add(TargetPath);
            }
        }