示例#1
0
        public IList <int> GetCoordIdsFromCadId(FEWorld world, uint cadId, CadElementType cadElemType)
        {
            Mesher2D    mesh  = world.Mesh;
            IList <int> coIds = null;

            if (cadElemType == CadElementType.Vertex)
            {
                uint     meshId = mesh.GetIdFromCadId(cadId, cadElemType);
                uint     elemCnt;
                MeshType meshType;
                int      loc;
                uint     cadIdTmp;
                mesh.GetMeshInfo(meshId, out elemCnt, out meshType, out loc, out cadIdTmp);
                MeshType dummyMeshType;
                int[]    vertexs;
                mesh.GetConnectivity(meshId, out dummyMeshType, out vertexs);
                System.Diagnostics.Debug.Assert(meshType == dummyMeshType);

                coIds = vertexs.ToList();
            }
            else if (cadElemType == CadElementType.Edge)
            {
                coIds = new List <int>();
                IList <uint> feIds = LineFEArray.GetObjectIds();
                foreach (uint feId in feIds)
                {
                    LineFE lineFE = LineFEArray.GetObject(feId);
                    uint   cadIdTmp;
                    {
                        uint     meshId = lineFE.MeshId;
                        uint     elemCnt;
                        MeshType meshType;
                        int      loc;
                        mesh.GetMeshInfo(meshId, out elemCnt, out meshType, out loc, out cadIdTmp);
                        System.Diagnostics.Debug.Assert(meshType == MeshType.Bar);
                    }
                    if (cadIdTmp == cadId)
                    {
                        foreach (int coId in lineFE.NodeCoordIds)
                        {
                            if (coIds.IndexOf(coId) == -1)
                            {
                                coIds.Add(coId);
                            }
                        }
                    }
                }
            }
            else if (cadElemType == CadElementType.Loop)
            {
                coIds = new List <int>();
                IList <uint> feIds = TriangleFEArray.GetObjectIds();
                foreach (uint feId in feIds)
                {
                    TriangleFE triFE = TriangleFEArray.GetObject(feId);
                    uint       cadIdTmp;
                    {
                        uint     meshId = triFE.MeshId;
                        uint     elemCnt;
                        MeshType meshType;
                        int      loc;
                        mesh.GetMeshInfo(meshId, out elemCnt, out meshType, out loc, out cadIdTmp);
                        System.Diagnostics.Debug.Assert(meshType == MeshType.Tri);
                    }
                    if (cadIdTmp == cadId)
                    {
                        foreach (int coId in triFE.NodeCoordIds)
                        {
                            if (coIds.IndexOf(coId) == -1)
                            {
                                coIds.Add(coId);
                            }
                        }
                    }
                }
            }
            else
            {
                throw new InvalidOperationException();
            }

            return(coIds);
        }
示例#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;
                    }
                }
            }
        }