Пример #1
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;
                    }
                }
            }
        }
Пример #2
0
        public void SetCadEdge(CadObject2D cad2D, uint eId, OpenTK.Vector2d pickPos)
        {
            this.PickPos = pickPos;
            this.ECadId  = eId;
            ClearMemory();
            IList <double> relCoPolys = new List <double>();
            {
                System.Diagnostics.Debug.Assert(cad2D.IsElementId(CadElementType.Edge, eId));
                Edge2D e = cad2D.GetEdge(eId);
                relCoPolys = e.GetCurveRelPoint();
            }
            IList <double> xys  = new List <double>();
            uint           ndiv = (uint)(relCoPolys.Count / 2 + 1);

            No = ndiv + 1;
            for (int i = 0; i < No * 2; i++)
            {
                xys.Add(0);
            }
            uint sVId = cad2D.GetEdgeVertexId(eId, true);
            uint eVId = cad2D.GetEdgeVertexId(eId, false);

            OpenTK.Vector2d sV  = cad2D.GetVertexCoord(sVId);
            OpenTK.Vector2d eV  = cad2D.GetVertexCoord(eVId);
            OpenTK.Vector2d hse = eV - sV;
            OpenTK.Vector2d vse = new OpenTK.Vector2d(-hse.Y, hse.X);
            xys.Add(sV.X);
            xys.Add(sV.Y);
            for (int i = 0; i < ndiv - 1; i++)
            {
                OpenTK.Vector2d v = sV + relCoPolys[i * 2 + 0] * hse + relCoPolys[i * 2 + 1] * vse;
                xys.Add(v.X);
                xys.Add(v.Y);
            }
            xys.Add(eV.X);
            xys.Add(eV.Y);
            //////////////////////////////////////
            Mat    = new TriDiaMat3(No);
            IniX   = new double[No * 2];
            Ut     = new double[No * 3];
            Res    = new double[No * 3];
            Dut    = new double[No * 3];
            BCFlag = new int[No * 3];
            ////
            for (int i = 0; i < No * 2; i++)
            {
                IniX[i] = xys[i];
            }
            for (int i = 0; i < No * 3; i++)
            {
                Ut[i] = 0;
            }
            for (int i = 0; i < No * 3; i++)
            {
                BCFlag[i] = 0;
            }
            //////////////////////////////////////
            SetFixedBoundaryFlag(0, 0);
            SetFixedBoundaryFlag(0, 1);
            SetFixedBoundaryFlag(No - 1, 0);
            SetFixedBoundaryFlag(No - 1, 1);
            double alpha;
            double ndist;
            double normX;
            double normY;

            ProjectPoint(pickPos.X, pickPos.Y, ref PickedDivIndex,
                         out alpha, out ndist, out normX, out normY);
            if (PickedDivIndex == -1)
            {
                return;
            }
            SetFixedBoundaryFlag((uint)PickedDivIndex, 0);
            SetFixedBoundaryFlag((uint)PickedDivIndex, 1);
            SetFixedBoundaryFlag((uint)PickedDivIndex + 1, 0);
            SetFixedBoundaryFlag((uint)PickedDivIndex + 1, 1);
        }