示例#1
0
        public override void OnSetAction()
        {
            base.TitleId = "Constr.Parametrics.DistanceTo";
            FeedBack.AddSelected(frontSide);
            FeedBack.AddSelected(backSide);
            base.ActiveObject = shell.Clone();
            if (shell.Layer != null)
            {
                shell.Layer.Transparency = 128;
            }


            distanceInput = new LengthInput("DistanceTo.Distance");
            distanceInput.GetLengthEvent += DistanceInput_GetLengthEvent;
            distanceInput.SetLengthEvent += DistanceInput_SetLengthEvent;

            modeInput = new MultipleChoiceInput("DistanceTo.Mode", "DistanceTo.Mode.Values", 0);
            modeInput.SetChoiceEvent += ModeInput_SetChoiceEvent;
            //modeInput.GetChoiceEvent += ModeInput_GetChoiceEvent;
            SetInput(distanceInput, modeInput);
            base.OnSetAction();

            FeedBack.SelectOutline = false;
            validResult            = false;
        }
        public override void OnSetAction()
        {
            base.TitleId = "Constr.Parametrics.DistanceTo";
            if (offsetFeedBack != null)
            {
                FeedBack.AddSelected(offsetFeedBack);
            }
            if (forwardFaces != null)
            {
                FeedBack.AddSelected(forwardFaces);
            }
            base.ActiveObject = shell.Clone();
            if (shell.Layer != null)
            {
                shell.Layer.Transparency = 128;
            }
            List <InputObject> actionInputs = new List <InputObject>();

            distance      = point1 | point2;
            distanceInput = new LengthInput("DistanceTo.Distance");
            distanceInput.GetLengthEvent += DistanceInput_GetLengthEvent;
            distanceInput.SetLengthEvent += DistanceInput_SetLengthEvent;
            actionInputs.Add(distanceInput);

            forwardFacesInput = new GeoObjectInput("DistanceTo.MoreForwardObjects");
            forwardFacesInput.MultipleInput             = true;
            forwardFacesInput.FacesOnly                 = true;
            forwardFacesInput.Optional                  = true;
            forwardFacesInput.MouseOverGeoObjectsEvent += new GeoObjectInput.MouseOverGeoObjectsDelegate(OnMouseOverForwardFaces);
            actionInputs.Add(forwardFacesInput);

            backwardFacesInput = new GeoObjectInput("DistanceTo.MoreBackwardObjects");
            backwardFacesInput.MultipleInput             = true;
            backwardFacesInput.FacesOnly                 = true;
            backwardFacesInput.Optional                  = true;
            backwardFacesInput.MouseOverGeoObjectsEvent += new GeoObjectInput.MouseOverGeoObjectsDelegate(OnMouseOverBackwardFaces);
            actionInputs.Add(backwardFacesInput);

            modeInput = new MultipleChoiceInput("DistanceTo.Mode", "DistanceTo.Mode.Values", 0);
            modeInput.SetChoiceEvent += ModeInput_SetChoiceEvent;
            actionInputs.Add(modeInput);
            //modeInput.GetChoiceEvent += ModeInput_GetChoiceEvent;

            SeparatorInput separator = new SeparatorInput("DistanceTo.AssociateParametric");

            actionInputs.Add(separator);
            nameInput = new StringInput("DistanceTo.ParametricsName");
            nameInput.SetStringEvent += NameInput_SetStringEvent;
            nameInput.GetStringEvent += NameInput_GetStringEvent;
            nameInput.Optional        = true;
            actionInputs.Add(nameInput);

            SetInput(actionInputs.ToArray());
            base.OnSetAction();

            FeedBack.SelectOutline = false;
            validResult            = false;
        }
        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);
        }