Beispiel #1
0
        public bool UpdateCadTopologyGeometry(CadObject2D cad2D)
        {
            SutableRotMode = RotMode.RotMode2D;
            IList <CadObject2DDrawPart> oldDrawParts = new List <CadObject2DDrawPart>();

            for (int i = 0; i < DrawParts.Count; i++)
            {
                oldDrawParts.Add(new CadObject2DDrawPart(DrawParts[i]));
            }

            for (int idp = 0; idp < oldDrawParts.Count; idp++)
            {
                oldDrawParts[idp].MeshId   = 0;
                oldDrawParts[idp].ShowMode = 0;
            }
            DrawParts.Clear();

            int minLayer;
            int maxLayer;

            cad2D.GetLayerMinMax(out minLayer, out maxLayer);
            double layerHeight = 1.0 / (maxLayer - minLayer + 1);

            {
                // 面をセット
                IList <uint> lIds = cad2D.GetElementIds(CadElementType.Loop);
                for (int iLId = 0; iLId < lIds.Count; iLId++)
                {
                    uint   lId    = lIds[iLId];
                    double height = 0;
                    {
                        int layer = cad2D.GetLayer(CadElementType.Loop, lId);
                        height = (layer - minLayer) * layerHeight;
                    }
                    int idp0 = 0;
                    for (; idp0 < oldDrawParts.Count; idp0++)
                    {
                        CadObject2DDrawPart olddp = oldDrawParts[idp0];
                        if (olddp.Type == CadElementType.Loop && olddp.CadId == lId)
                        {
                            olddp.MeshId = 1;
                            olddp.Height = height;
                            double[] color = cad2D.GetLoopColor(lId);
                            for (int iTmp = 0; iTmp < 3; iTmp++)
                            {
                                olddp.Color[iTmp] = (float)color[iTmp];
                            }
                            DrawParts.Add(oldDrawParts[idp0]);
                            break;
                        }
                    }
                    if (idp0 == oldDrawParts.Count)
                    {
                        CadObject2DDrawPart dp = new CadObject2DDrawPart();
                        dp.CadId  = lId;
                        dp.Type   = CadElementType.Loop;
                        dp.Height = height;
                        double[] color = cad2D.GetLoopColor(lId);
                        for (int iTmp = 0; iTmp < 3; iTmp++)
                        {
                            dp.Color[iTmp] = (float)color[iTmp];
                        }
                        DrawParts.Add(dp);
                    }
                }
            }

            {
                // set edge
                IList <uint> eIds = cad2D.GetElementIds(CadElementType.Edge);
                for (int iEId = 0; iEId < eIds.Count; iEId++)
                {
                    uint   eId    = eIds[iEId];
                    double height = 0;
                    {
                        int layer = cad2D.GetLayer(CadElementType.Edge, eId);
                        height += (layer - minLayer + 0.01) * layerHeight;
                    }
                    int idp0 = 0;
                    for (; idp0 < oldDrawParts.Count; idp0++)
                    {
                        CadObject2DDrawPart olddp = oldDrawParts[idp0];
                        if (olddp.Type == CadElementType.Edge && olddp.CadId == eId)
                        {
                            olddp.MeshId = 1;
                            olddp.Height = height;
                            DrawParts.Add(olddp);
                            break;
                        }
                    }
                    if (idp0 == oldDrawParts.Count)
                    {
                        CadObject2DDrawPart dp = new CadObject2DDrawPart();
                        dp.CadId  = eId;
                        dp.Type   = CadElementType.Edge;
                        dp.Height = height;
                        DrawParts.Add(dp);
                    }
                    {
                        CadObject2DDrawPart dp = DrawParts[DrawParts.Count - 1];
                        Edge2D edge            = cad2D.GetEdge(eId);
                        dp.CtrlPoints.Clear();
                        dp.CurveType = edge.CurveType;
                        if (edge.CurveType == CurveType.CurveArc)
                        {
                            OpenTK.Vector2d cPt;
                            double          radius;
                            edge.GetCenterRadius(out cPt, out radius);
                            dp.CtrlPoints.Add(cPt);
                        }
                        else if (edge.CurveType == CurveType.CurveBezier)
                        {
                            IList <OpenTK.Vector2d> cos = edge.GetCurvePoint();
                            dp.CtrlPoints.Add(cos[0]);
                            dp.CtrlPoints.Add(cos[1]);
                        }
                    }
                }
            }

            {
                // set vertex
                IList <uint> vIds = cad2D.GetElementIds(CadElementType.Vertex);
                for (int iVId = 0; iVId < vIds.Count; iVId++)
                {
                    uint   vCadId = vIds[iVId];
                    int    layer  = cad2D.GetLayer(CadElementType.Vertex, vCadId);
                    double height = (layer - minLayer + 0.1) * layerHeight;
                    int    idp0   = 0;
                    for (; idp0 < oldDrawParts.Count; idp0++)
                    {
                        CadObject2DDrawPart olddp = oldDrawParts[idp0];
                        if (olddp.Type == CadElementType.Vertex && olddp.CadId == vCadId)
                        {
                            olddp.MeshId = 1;
                            olddp.Height = height;
                            DrawParts.Add(olddp);
                            break;
                        }
                    }
                    if (idp0 == oldDrawParts.Count)
                    {
                        CadObject2DDrawPart dp = new CadObject2DDrawPart();
                        dp.CadId  = vCadId;
                        dp.Type   = CadElementType.Vertex;
                        dp.Height = height;
                        DrawParts.Add(dp);
                    }
                }
            }

            oldDrawParts.Clear();

            UpdateCadGeometry(cad2D);
            return(true);
        }
Beispiel #2
0
        public void UpdateCadGeometry(CadObject2D cad2D)
        {
            Mesher2D mesh = new Mesher2D(cad2D);

            for (int idp = 0; idp < DrawParts.Count; idp++)
            {
                CadObject2DDrawPart dp = DrawParts[idp];
                dp.Clear();
                uint           cadId   = dp.CadId;
                CadElementType cadType = dp.Type;
                if (!cad2D.IsElementId(cadType, cadId))
                {
                    continue;
                }
                uint meshId = mesh.GetIdFromCadId(cadId, cadType);
                if (meshId == 0)
                {
                    continue;
                }
                MeshType meshType;
                uint     elemCnt;
                int      loc;
                uint     cadId0;
                mesh.GetMeshInfo(meshId, out elemCnt, out meshType, out loc, out cadId0);
                System.Diagnostics.Debug.Assert(cadId0 == cadId);
                if (meshType == MeshType.Tri)
                {
                    dp.SetTriArray(mesh.GetTriArrays()[loc]);
                    double[] color = cad2D.GetLoopColor(cadId0);
                    for (int iTmp = 0; iTmp < 3; iTmp++)
                    {
                        dp.Color[iTmp] = (float)color[iTmp];
                    }
                }
                else if (meshType == MeshType.Bar)
                {
                    dp.SetBarArray(mesh.GetBarArrays()[loc]);
                    System.Diagnostics.Debug.Assert(cadType == CadElementType.Edge);
                    Edge2D edge = cad2D.GetEdge(cadId);
                    dp.CurveType = edge.CurveType;
                    dp.CtrlPoints.Clear();
                    // 2019-03-11 エッジの色 FIX
                    double[] color = edge.Color;
                    for (int iTmp = 0; iTmp < 3; iTmp++)
                    {
                        dp.Color[iTmp] = (float)color[iTmp];
                    }
                    if (edge.CurveType == CurveType.CurveArc)
                    {
                        OpenTK.Vector2d cPt;
                        double          radius;
                        edge.GetCenterRadius(out cPt, out radius);
                        dp.CtrlPoints.Add(cPt);
                    }
                    else if (edge.CurveType == CurveType.CurveBezier)
                    {
                        IList <OpenTK.Vector2d> cos = edge.GetCurvePoint();
                        dp.CtrlPoints.Add(cos[0]);
                        dp.CtrlPoints.Add(cos[1]);
                    }
                }
                else if (meshType == MeshType.Vertex)
                {
                    dp.SetVertex(mesh.GetVertexs()[loc]);
                }
            }

            {
                // 座標をセット
                IList <OpenTK.Vector2d> vec2Ds = mesh.GetVectors();
                uint ptCnt = (uint)vec2Ds.Count;
                uint ndim  = 2;
                VertexArray.SetSize(ptCnt, ndim);
                for (int iPt = 0; iPt < ptCnt; iPt++)
                {
                    VertexArray.VertexCoordArray[iPt * ndim]     = vec2Ds[iPt].X;
                    VertexArray.VertexCoordArray[iPt * ndim + 1] = vec2Ds[iPt].Y;
                }
                if (VertexArray.UVCoordArray != null)
                {
                    for (int iPt = 0; iPt < ptCnt; iPt++)
                    {
                        VertexArray.UVCoordArray[iPt * ndim]     = vec2Ds[iPt].X * TexScale;
                        VertexArray.UVCoordArray[iPt * ndim + 1] = vec2Ds[iPt].Y * TexScale;
                    }
                }
            }
        }