Esempio n. 1
0
        public override void Execute(Parametric parametric)
        {
            GetDistanceVector(out GeoPoint startPoint, out GeoPoint endPoint);
            GeoVector delta = (endPoint - startPoint);
            double    diff  = currentValue - delta.Length;

            delta = diff * delta.Normalized;
            Dictionary <Face, GeoVector> facesToAffect = new Dictionary <Face, GeoVector>();

            if (mode.HasFlag(Mode.symmetric))
            {
                foreach (Face face in facesToKeep)
                {
                    facesToAffect[face] = -0.5 * delta;
                }
                foreach (Face face in facesToMove)
                {
                    facesToAffect[face] = 0.5 * delta;
                }
            }
            else
            {
                foreach (Face face in facesToMove)
                {
                    facesToAffect[face] = delta;
                }
            }
            parametric.MoveFaces(facesToAffect, endPoint - startPoint, mode.HasFlag(Mode.connected));
            parametric.Apply(); // the result may be inconsistent, but maybe further parametric operations make it consistent again
        }
        private bool Refresh()
        {
            validResult = false;
            if (facesToMove.Count > 0 && (facesToKeep.Count > 0 || axisToMove != null))
            {
                FeedBack.ClearSelected();
                GeoPoint startPoint = offsetStartPoint;
                GeoPoint endPoint   = startPoint + originalOffset + currentOffset;
                switch (mode)
                {
                case Mode.forward:
                    startPoint     = offsetStartPoint;
                    endPoint       = startPoint + originalOffset + currentOffset;
                    offsetFeedBack = Frame.ActiveView.Projection.MakeArrow(startPoint, endPoint, feedbackPlane, Projection.ArrowMode.circleArrow);
                    break;

                case Mode.backward:
                    startPoint     = offsetStartPoint + originalOffset;
                    endPoint       = startPoint - originalOffset - currentOffset;
                    offsetFeedBack = Frame.ActiveView.Projection.MakeArrow(startPoint, endPoint, feedbackPlane, Projection.ArrowMode.circleArrow);
                    break;

                case Mode.symmetric:
                    startPoint     = offsetStartPoint + 0.5 * originalOffset;
                    offsetFeedBack = Frame.ActiveView.Projection.MakeArrow(startPoint, startPoint + 0.5 * (originalOffset + currentOffset), feedbackPlane, Projection.ArrowMode.circleArrow);
                    offsetFeedBack.AddRange(Frame.ActiveView.Projection.MakeArrow(startPoint, startPoint - 0.5 * (originalOffset + currentOffset), feedbackPlane, Projection.ArrowMode.circleArrow));
                    break;
                }
                offsetFeedBack.AddRange(facesToMove);
                offsetFeedBack.AddRange(moreForwardFaces);
                FeedBack.AddSelected(offsetFeedBack);
                Shell sh = null;
                for (int m = 0; m <= 1; m++)
                {   // first try without moving connected faces, if this yields no result, try with moving connected faced
                    Parametric parametric = new Parametric(shell);
                    Dictionary <Face, GeoVector> allFacesToMove = new Dictionary <Face, GeoVector>();
                    switch (mode)
                    {
                    case Mode.forward:
                        foreach (Face face in Extensions.Combine(facesToMove, moreForwardFaces))
                        {
                            allFacesToMove[face] = currentOffset;
                        }
                        foreach (Face face in Extensions.Combine(facesToKeep, moreBackwardFaces))
                        {
                            allFacesToMove[face] = GeoVector.NullVector;
                        }
                        break;

                    case Mode.symmetric:
                        foreach (Face face in Extensions.Combine(facesToMove, moreForwardFaces))
                        {
                            allFacesToMove[face] = 0.5 * currentOffset;
                        }
                        foreach (Face face in Extensions.Combine(facesToKeep, moreBackwardFaces))
                        {
                            allFacesToMove[face] = -0.5 * currentOffset;
                        }
                        break;

                    case Mode.backward:
                        foreach (Face face in Extensions.Combine(facesToKeep, moreBackwardFaces))
                        {
                            allFacesToMove[face] = -currentOffset;
                        }
                        foreach (Face face in Extensions.Combine(facesToMove, moreForwardFaces))
                        {
                            allFacesToMove[face] = GeoVector.NullVector;
                        }
                        break;
                    }
                    parametric.MoveFaces(allFacesToMove, currentOffset, m == 1);
                    if (parametric.Apply())
                    {
                        sh = parametric.Result();
                        if (sh != null)
                        {
                            ParametricDistanceProperty.Mode pmode = 0;
                            if (m == 1)
                            {
                                pmode |= ParametricDistanceProperty.Mode.connected;
                            }
                            if (mode == Mode.symmetric)
                            {
                                pmode |= ParametricDistanceProperty.Mode.symmetric;
                            }
                            // create the ParametricDistanceProperty here, because here we have all the information
                            parametric.GetDictionaries(out Dictionary <Face, Face> faceDict, out Dictionary <Edge, Edge> edgeDict, out Dictionary <Vertex, Vertex> vertexDict);
                            // facesToKeep etc. contains original objects of the shell, affectedObjects contains objects of the sh = pm.Result()
                            // the parametricProperty will be applied to sh, so we need the objects from sh
                            object fromHere = null, toHere = null;
                            if (distanceFromHere is Face fromFace)
                            {
                                fromHere = faceDict[fromFace];
                            }
                            if (distanceFromHere is Edge fromEdge)
                            {
                                fromHere = edgeDict[fromEdge];
                            }
                            if (distanceFromHere is Vertex fromVertex)
                            {
                                fromHere = vertexDict[fromVertex];
                            }
                            if (distanceToHere is Face toFace)
                            {
                                toHere = faceDict[toFace];
                            }
                            if (distanceToHere is Edge toEdge)
                            {
                                toHere = edgeDict[toEdge];
                            }
                            if (distanceToHere is Vertex toVertex)
                            {
                                toHere = vertexDict[toVertex];
                            }
                            if (mode == Mode.backward)
                            {
                                parametricProperty = new ParametricDistanceProperty("", Extensions.LookUp(Extensions.Combine(facesToMove, moreForwardFaces), faceDict),
                                                                                    Extensions.LookUp(Extensions.Combine(facesToKeep, moreBackwardFaces), faceDict),
                                                                                    parametric.GetAffectedObjects(), pmode, toHere, fromHere);
                            }
                            else
                            {
                                parametricProperty = new ParametricDistanceProperty("", Extensions.LookUp(Extensions.Combine(facesToKeep, moreBackwardFaces), faceDict),
                                                                                    Extensions.LookUp(Extensions.Combine(facesToMove, moreForwardFaces), faceDict),
                                                                                    parametric.GetAffectedObjects(), pmode, fromHere, toHere);
                            }
                            break;
                        }
                    }
                }
                if (sh != null)
                {
                    ActiveObject = sh;
                    validResult  = true;
                    return(true);
                }
                else
                {
                    ActiveObject = shell.Clone();
                    return(false);
                }
            }
            return(false);
        }
        private bool Refresh()
        {
            validResult = false;
            if (forwardFaces.Count > 0 && backwardFaces.Count > 0)
            {
                FeedBack.ClearSelected();
                GeoPoint  startPoint       = point1;
                GeoPoint  endPoint         = point2;
                GeoVector dir              = (point2 - point1).Normalized;
                double    originalDistance = point2 | point1;
                switch (mode)
                {
                case Mode.forward:
                    endPoint       = point2 + (distance - originalDistance) * dir;
                    offsetFeedBack = Frame.ActiveView.Projection.MakeArrow(startPoint, endPoint, feedbackPlane, Projection.ArrowMode.circleArrow);
                    break;

                case Mode.backward:
                    startPoint     = point1 - (distance - originalDistance) * dir;
                    offsetFeedBack = Frame.ActiveView.Projection.MakeArrow(endPoint, startPoint, feedbackPlane, Projection.ArrowMode.circleArrow);
                    break;

                case Mode.symmetric:
                    startPoint = point1 - 0.5 * (distance - originalDistance) * dir;
                    endPoint   = point2 + 0.5 * (distance - originalDistance) * dir;
                    GeoPoint mp = new GeoPoint(startPoint, endPoint);
                    offsetFeedBack = Frame.ActiveView.Projection.MakeArrow(mp, startPoint, feedbackPlane, Projection.ArrowMode.circleArrow);
                    offsetFeedBack.AddRange(Frame.ActiveView.Projection.MakeArrow(mp, endPoint, feedbackPlane, Projection.ArrowMode.circleArrow));
                    break;
                }
                offsetFeedBack.AddRange(forwardFaces);
                offsetFeedBack.AddRange(backwardFaces);
                FeedBack.AddSelected(offsetFeedBack);
                Shell sh = null;
                for (int m = 0; m <= 1; m++)
                {   // first try without moving connected faces, if this yields no result, try with moving connected faced
                    Parametric parametric = new Parametric(shell);
                    Dictionary <Face, GeoVector> allFacesToMove = new Dictionary <Face, GeoVector>();
                    GeoVector offset = (distance - originalDistance) * dir;
                    switch (mode)
                    {
                    case Mode.forward:
                        foreach (Face face in forwardFaces)
                        {
                            allFacesToMove[face] = offset;
                        }
                        foreach (Face face in backwardFaces)
                        {
                            allFacesToMove[face] = GeoVector.NullVector;
                        }
                        break;

                    case Mode.symmetric:
                        foreach (Face face in forwardFaces)
                        {
                            allFacesToMove[face] = 0.5 * offset;
                        }
                        foreach (Face face in backwardFaces)
                        {
                            allFacesToMove[face] = -0.5 * offset;
                        }
                        break;

                    case Mode.backward:
                        foreach (Face face in backwardFaces)
                        {
                            allFacesToMove[face] = -offset;
                        }
                        foreach (Face face in forwardFaces)
                        {
                            allFacesToMove[face] = GeoVector.NullVector;
                        }
                        break;
                    }
                    parametric.MoveFaces(allFacesToMove, offset, m == 1);
                    if (parametric.Apply())
                    {
                        sh = parametric.Result();
                        if (sh != null)
                        {
                            ParametricDistanceProperty.Mode pmode = 0;
                            if (m == 1)
                            {
                                pmode |= ParametricDistanceProperty.Mode.connected;
                            }
                            if (mode == Mode.symmetric)
                            {
                                pmode |= ParametricDistanceProperty.Mode.symmetric;
                            }
                            // create the ParametricDistanceProperty here, because here we have all the information
                            parametric.GetDictionaries(out Dictionary <Face, Face> faceDict, out Dictionary <Edge, Edge> edgeDict, out Dictionary <Vertex, Vertex> vertexDict);
                            // facesToKeep etc. contains original objects of the shell, affectedObjects contains objects of the sh = pm.Result()
                            // the parametricProperty will be applied to sh, so we need the objects from sh
                            if (mode == Mode.backward)
                            {
                                parametricProperty = new ParametricDistanceProperty("", Extensions.LookUp(forwardFaces, faceDict),
                                                                                    Extensions.LookUp(backwardFaces, faceDict),
                                                                                    parametric.GetAffectedObjects(), pmode, point2, point1);
                            }
                            else
                            {
                                parametricProperty = new ParametricDistanceProperty("", Extensions.LookUp(backwardFaces, faceDict),
                                                                                    Extensions.LookUp(forwardFaces, faceDict),
                                                                                    parametric.GetAffectedObjects(), pmode, point1, point2);
                            }
                            break;
                        }
                    }
                }
                if (sh != null)
                {
                    ActiveObject = sh;
                    validResult  = true;
                    return(true);
                }
                else
                {
                    ActiveObject = shell.Clone();
                    return(false);
                }
            }
            return(false);
        }