Exemplo n.º 1
0
    public CornerAngleMeasureState(Tool tool, Measure measure, Geometry geometry) : base(tool, measure)
    {
        if (measure is CornerAngleMeasure)
        {
            this.measure = (CornerAngleMeasure)measure;
        }

        this.geometry = geometry;
    }
Exemplo n.º 2
0
    public override Measure GenerateMeasure(Geometry geometry, FormInput formInput)
    {
        bool valid = ValidateInput(geometry, formInput);

        if (!valid)
        {
            return(null);
        }

        FormElement formElement = (FormElement)formInput.inputs[1];

        string[]           fields  = formElement.fields;
        int                i1      = geometry.SignVertex(fields[0]);
        int                i2      = geometry.SignVertex(fields[1]);
        int                i3      = geometry.SignVertex(fields[2]);
        CornerAngleMeasure measure = new CornerAngleMeasure(i1, i2, i3);

        return(measure);
    }
Exemplo n.º 3
0
    private void AddState(Auxiliary auxiliary, FormInput form)
    {
        Type type = Type.GetType(tool.Name + "AuxiliaryState");

        if (type != null)
        {
            AuxiliaryState auxiliaryState = (AuxiliaryState)Activator.CreateInstance(type, tool, auxiliary, geometry);
            auxiliaryState.OnClickDelete = () => geoController.RemoveAuxiliaryOperation(auxiliary);

            //state单击
            auxiliaryState.DoubleClick = () => this.TurnToFront(auxiliary, form);

            //Action OnElementHighLight  0925 Requirement_1
            auxiliaryState.OnElementHighlight = () =>
            {
                //Hightlight face
                ChangeFaceColorIndex((GeoFace)auxiliary.elements[0], 1);

                //Hide coordinate
                geoUI.navPanel.OnCoordinateButtonClick(1);
                geoUI.navPanel.SetCoordinateButtonStatus(1); //Change Button status

                //Hide grid
                geoUI.navPanel.OnGridButtonClick(1);
                geoUI.navPanel.SetGridButtonStatus(1);


                //Measure Line length
                if (auxiliary.elements[0] is GeoFace)
                {
                    GeoFace geoFace = (GeoFace)auxiliary.elements[0];
                    for (int i = 0; i < geoFace.Ids.Length; i++)
                    {
                        int vertex1 = i;
                        int vertex2 = (i + 1) % geoFace.Ids.Length;

                        Measure measure = new LineLengthMeasure(geoFace.Ids[vertex1], geoFace.Ids[vertex2]);

                        measure_list.Add((Measure)measure);

                        measure.InitWithGeometry(geometry);
                        bool result = geometry.Implement.AddMeasure(measure);
                        if (result)
                        {
                            List <ToolGroup> toolGroups            = geoUI.toolPanel.ToolGroups();
                            Tool             lineLengthMeasureTool = toolGroups[3].Tools[0];
                            AddState_Measure(measure, lineLengthMeasureTool);

                            Gizmo[] gizmos = measure.gizmos;
                            if (gizmos != null)
                            {
                                foreach (Gizmo gizmo in gizmos)
                                {
                                    geometry.AddGizmo(gizmo);
                                    geometryBehaviour.AddGizmo(gizmo);
                                }
                            }
                        }
                        else
                        {
                            // TODO
                        }
                    }
                }
                //Measure CornerAngle
                if (auxiliary.elements[0] is GeoFace)
                {
                    GeoFace geoFace = (GeoFace)auxiliary.elements[0];
                    for (int i = 0; i < geoFace.Ids.Length; i++)
                    {
                        int vertex1 = i;
                        int vertex2 = (i + 1) % geoFace.Ids.Length;
                        int vertex3 = (i + 2) % geoFace.Ids.Length;

                        Measure measure = new CornerAngleMeasure(geoFace.Ids[vertex1], geoFace.Ids[vertex2], geoFace.Ids[vertex3]);

                        measure_list.Add((Measure)measure);

                        measure.InitWithGeometry(geometry);


                        bool result = geometry.Implement.AddMeasure(measure);

                        if (result)
                        {
                            List <ToolGroup> toolGroups             = geoUI.toolPanel.ToolGroups();
                            Tool             cornerAngleMeasureTool = toolGroups[3].Tools[1];
                            AddState_Measure(measure, cornerAngleMeasureTool);

                            Gizmo[] gizmos = measure.gizmos;
                            if (gizmos != null)
                            {
                                foreach (Gizmo gizmo in gizmos)
                                {
                                    geometry.AddGizmo(gizmo);
                                    geometryBehaviour.AddGizmo(gizmo);
                                }
                            }
                        }
                        else
                        {
                            // TODO
                        }
                    }
                }
                //Measure Plane Area
                if (auxiliary.elements[0] is GeoFace)
                {
                    GeoFace geoFace = (GeoFace)auxiliary.elements[0];
                    //Debug.Log(geoFace.Ids);
                    Measure measure = new PlaneAreaMeasure(geoFace.Ids);

                    measure_list.Add(measure);

                    measure.InitWithGeometry(geometry);


                    bool result = geometry.Implement.AddMeasure(measure);

                    if (result)
                    {
                        List <ToolGroup> toolGroups           = geoUI.toolPanel.ToolGroups();
                        Tool             planeAreaMeasureTool = toolGroups[3].Tools[2];
                        AddState_Measure(measure, planeAreaMeasureTool);

                        Gizmo[] gizmos = measure.gizmos;
                        if (gizmos != null)
                        {
                            foreach (Gizmo gizmo in gizmos)
                            {
                                geometry.AddGizmo(gizmo);
                                geometryBehaviour.AddGizmo(gizmo);
                            }
                        }
                    }
                    else
                    {
                        // TODO
                    }
                }

                // Hide elements beyond the Highlighted face
                GeoVertex[] geoVertices = geometry.GeoVertices();
                if (auxiliary.elements[0] is GeoFace)
                {
                    GeoFace      geoFace      = (GeoFace)auxiliary.elements[0];
                    VertexUnit[] faceVertices = geoFace.get_vertices();
                    Vector3      side1        = faceVertices[0].Position() - faceVertices[1].Position();
                    Vector3      side2        = faceVertices[2].Position() - faceVertices[1].Position();
                    Vector3      normalVector = Vector3.Cross(side1, side2);

                    if (normalVector.x < 0)
                    {
                        normalVector.x = -normalVector.x;
                        normalVector.y = -normalVector.y;
                        normalVector.z = -normalVector.z;
                    }
                    if (normalVector.x == 0)
                    {
                        if (normalVector.z < 0)
                        {
                            normalVector.y = -normalVector.y;
                            normalVector.z = -normalVector.z;
                        }
                    }

                    Vector3 anchor = faceVertices[1].Position() + normalVector * 2;

                    float     min   = 1000;
                    GeoEdge[] edges = geometry.GeoEdges();
                    foreach (VertexUnit vertexUnit in geoFace.get_vertices())
                    {
                        float face_vertex_distance = Vector3.Distance(vertexUnit.Position(), anchor);
                        if (face_vertex_distance < min)
                        {
                            min = face_vertex_distance;
                        }
                    }
                    foreach (GeoVertex geoVertex in geoVertices)
                    {
                        float distance = Vector3.Distance(geoVertex.VertexUnit().Position(), anchor);
                        if (distance < min)
                        {
                            //隐藏该顶点
                            ElementBehaviour vertexElementBehaviour = geometryBehaviour.elementMap[geoVertex];
                            vertexElementBehaviour.SetVisible(false);
                            elementBehaviour_list.Add(vertexElementBehaviour);
                            //隐藏该顶点起始的所有边
                            foreach (GeoEdge geoEdge in edges)
                            {
                                if (geoVertex.Id == geoEdge.Id1 || geoVertex.Id == geoEdge.Id2)
                                {
                                    ElementBehaviour edgeElementBehaviour = geometryBehaviour.elementMap[geoEdge];
                                    edgeElementBehaviour.SetVisible(false);
                                    elementBehaviour_list.Add(edgeElementBehaviour);
                                }
                            }
                        }
                    }
                }
            };

            auxiliaryState.UndoFaceHighlight = () =>
            {
                //Undo Hightlight face
                ChangeFaceColorIndex((GeoFace)auxiliary.elements[0], 0);


                //Undo Hide coordinate
                geoUI.navPanel.OnCoordinateButtonClick(0);
                geoUI.navPanel.SetCoordinateButtonStatus(0); //Change Button status

                //Hide grid
                geoUI.navPanel.OnGridButtonClick(0);
                geoUI.navPanel.SetGridButtonStatus(0);

                //Claer All Face_MeasureStates
                foreach (Measure measure in measure_list)
                {
                    geoController.RemoveMeasure(measure);
                }
                foreach (ElementBehaviour elementBehaviour in elementBehaviour_list)
                {
                    elementBehaviour.SetVisible(true);
                }
            };



            stateController.AddAuxiliaryState(auxiliaryState);
        }
    }