/// <summary> /// 問題を設定する /// </summary> /// <returns></returns> private bool setNewProblem() { bool success = false; try { using (CCadObj2D cad2d = new CCadObj2D()) { if (ProbNo == 0) { IList<CVector2D> pts = new List<CVector2D>(); pts.Add(new CVector2D(0.0, 0.0)); pts.Add(new CVector2D(1.0, 0.0)); pts.Add(new CVector2D(1.0, 1.0)); pts.Add(new CVector2D(0.0, 1.0)); uint id_l0 = cad2d.AddPolygon(pts, 0).id_l_add; uint id_v5 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, id_l0, new CVector2D(0.5, 0.5)).id_v_add; uint id_v6 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, id_l0, new CVector2D(0.5, 0.8)).id_v_add; uint id_v7 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, id_l0, new CVector2D(0.8, 0.5)).id_v_add; uint id_v8 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, id_l0, new CVector2D(0.5, 0.2)).id_v_add; uint id_v9 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, id_l0, new CVector2D(0.2, 0.5)).id_v_add; cad2d.ConnectVertex_Line(id_v5, id_v6); cad2d.ConnectVertex_Line(id_v5, id_v7); cad2d.ConnectVertex_Line(id_v5, id_v8); cad2d.ConnectVertex_Line(id_v5, id_v9); using (CCadObj2D cad2dtmp = cad2d.Clone()) // コピーのテスト { // export to the file using (CSerializer fout = new CSerializer("hoge.txt", false)) { cad2dtmp.Serialize(fout); } } // import form the file cad2d.Clear(); using (CSerializer fin = new CSerializer("hoge.txt", true)) { cad2d.Serialize(fin); } DrawerAry.Clear(); DrawerAry.PushBack(new CDrawer_Cad2D(cad2d)); DrawerAry.InitTrans(Camera); } else if (ProbNo == 1) { CCadObj2D.CResAddPolygon res; { // define shape IList<CVector2D> pts = new List<CVector2D>(); pts.Add(new CVector2D(0.0, 0.0)); pts.Add(new CVector2D(1.0, 0.0)); pts.Add(new CVector2D(2.0, 1.0)); pts.Add(new CVector2D(1.0, 1.0)); pts.Add(new CVector2D(1.0, 2.0)); pts.Add(new CVector2D(0.0, 2.0)); res = cad2d.AddPolygon(pts); } cad2d.RemoveElement(CAD_ELEM_TYPE.EDGE, res.aIdE[1]); cad2d.RemoveElement(CAD_ELEM_TYPE.EDGE, res.aIdE[2]); cad2d.RemoveElement(CAD_ELEM_TYPE.VERTEX, res.aIdV[2]); uint id_e_new = cad2d.ConnectVertex_Line(res.aIdE[3], res.aIdE[1]).id_e_add; CCadObj2D.CResAddVertex res0 = cad2d.AddVertex(CAD_ELEM_TYPE.EDGE, id_e_new, new CVector2D(1, 0.4)); CCadObj2D.CResAddVertex res1 = cad2d.AddVertex(CAD_ELEM_TYPE.EDGE, id_e_new, new CVector2D(1, 0.6)); CCadObj2D.CResAddVertex res2 = cad2d.AddVertex(CAD_ELEM_TYPE.EDGE, res.aIdE[5], new CVector2D(0, 0.4)); CCadObj2D.CResAddVertex res3 = cad2d.AddVertex(CAD_ELEM_TYPE.EDGE, res.aIdE[5], new CVector2D(0, 0.6)); cad2d.ConnectVertex_Line(res0.id_v_add, res2.id_v_add); cad2d.ConnectVertex_Line(res1.id_v_add, res3.id_v_add); cad2d.RemoveElement(CAD_ELEM_TYPE.EDGE, res1.id_e_add); cad2d.RemoveElement(CAD_ELEM_TYPE.EDGE, res3.id_e_add); using (CCadObj2D cad2dtmp = cad2d.Clone()) // コピーのテスト { // export to the file using (CSerializer fout = new CSerializer("hoge.txt", false)) { cad2dtmp.Serialize(fout); } } // import form the file cad2d.Clear(); using (CSerializer fin = new CSerializer("hoge.txt", true)) { cad2d.Serialize(fin); } DrawerAry.Clear(); DrawerAry.PushBack(new CDrawer_Cad2D(cad2d)); DrawerAry.InitTrans(Camera); } else if (ProbNo == 2) { uint id_l0; { // Make model IList<CVector2D> pts = new List<CVector2D>(); pts.Add(new CVector2D(0.0, 0.0)); pts.Add(new CVector2D(1.0, 0.0)); pts.Add(new CVector2D(1.0, 0.4)); pts.Add(new CVector2D(0.0, 0.4)); id_l0 = cad2d.AddPolygon(pts).id_l_add; } //cad2d.SetCurve_Arc(1,true,-0.2); //cad2d.SetCurve_Arc(2,true, -0.5); cad2d.SetCurve_Arc(3, false, 0); //cad2d.SetCurve_Arc(4,true, -0.5); DrawerAry.Clear(); DrawerAry.PushBack(new CDrawer_Cad2D(cad2d)); DrawerAry.InitTrans(Camera); } else if (ProbNo == 3) { uint id_v1 = cad2d.AddVertex(CAD_ELEM_TYPE.NOT_SET, 0, new CVector2D(0, 0)).id_v_add; uint id_v2 = cad2d.AddVertex(CAD_ELEM_TYPE.NOT_SET, 0, new CVector2D(1, 0)).id_v_add; cad2d.ConnectVertex_Line(id_v1, id_v2); uint id_v3 = cad2d.AddVertex(CAD_ELEM_TYPE.NOT_SET, 0, new CVector2D(1, 1)).id_v_add; cad2d.ConnectVertex_Line(id_v2, id_v3); uint id_v4 = cad2d.AddVertex(CAD_ELEM_TYPE.NOT_SET, 0, new CVector2D(0, 1)).id_v_add; cad2d.ConnectVertex_Line(id_v4, id_v3); uint id_v5 = cad2d.AddVertex(CAD_ELEM_TYPE.EDGE, 2, new CVector2D(1, 0.5)).id_v_add; uint id_v7 = cad2d.AddVertex(CAD_ELEM_TYPE.NOT_SET, 0, new CVector2D(0.5, 0.5)).id_v_add; cad2d.ConnectVertex_Line(id_v5, id_v7); uint id_v6 = cad2d.AddVertex(CAD_ELEM_TYPE.NOT_SET, 0, new CVector2D(1.5, 0.5)).id_v_add; cad2d.ConnectVertex_Line(id_v5, id_v6); cad2d.ConnectVertex_Line(id_v4, id_v1); DrawerAry.Clear(); DrawerAry.PushBack(new CDrawer_Cad2D(cad2d)); DrawerAry.InitTrans(Camera); } else if (ProbNo == 4) { uint id_l0; { // define shape IList<CVector2D> pts = new List<CVector2D>(); pts.Add(new CVector2D(0.0, 0.0)); pts.Add(new CVector2D(1.0, 0.0)); pts.Add(new CVector2D(1.0, 1.0)); pts.Add(new CVector2D(0.0, 1.0)); id_l0 = cad2d.AddPolygon(pts).id_l_add; } //uint id_v1 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP,id_l0,new CVector2D(0.5,0.5)); uint id_v2 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, id_l0, new CVector2D(0.5, 0.2)).id_v_add; uint id_v3 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, id_l0, new CVector2D(0.8, 0.5)).id_v_add; uint id_v4 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, id_l0, new CVector2D(0.5, 0.8)).id_v_add; uint id_v5 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, id_l0, new CVector2D(0.2, 0.5)).id_v_add; cad2d.ConnectVertex_Line(id_v2, id_v3); cad2d.ConnectVertex_Line(id_v3, id_v4); cad2d.ConnectVertex_Line(id_v4, id_v5); uint id_e1 = cad2d.ConnectVertex_Line(id_v5, id_v2).id_e_add; cad2d.RemoveElement(CAD_ELEM_TYPE.EDGE, id_e1); cad2d.ConnectVertex_Line(id_v5, id_v2); DrawerAry.Clear(); DrawerAry.PushBack(new CDrawer_Cad2D(cad2d)); DrawerAry.InitTrans(Camera); } else if (ProbNo == 5) { uint id_l0; { // define shape IList<CVector2D> pts = new List<CVector2D>(); pts.Add(new CVector2D(0.0, 0.0)); pts.Add(new CVector2D(0.0, 1.0)); pts.Add(new CVector2D(1.0, 1.0)); pts.Add(new CVector2D(1.0, 0.0)); id_l0 = cad2d.AddPolygon(pts).id_l_add; } DrawerAry.Clear(); DrawerAry.PushBack(new CDrawer_Cad2D(cad2d)); DrawerAry.InitTrans(Camera); } else if (ProbNo == 6) { uint id_l0; { // define initial loop IList<CVector2D> pts = new List<CVector2D>(); pts.Add(new CVector2D(0.0, 0.0)); pts.Add(new CVector2D(1.0, 0.0)); pts.Add(new CVector2D(1.0, 1.0)); pts.Add(new CVector2D(0.0, 1.0)); id_l0 = cad2d.AddPolygon(pts).id_l_add; } { IList<CVector2D> pts = new List<CVector2D>(); pts.Add(new CVector2D(0.3, 0.1)); pts.Add(new CVector2D(0.9, 0.1)); pts.Add(new CVector2D(0.9, 0.7)); cad2d.AddPolygon(pts, id_l0); } { IList<CVector2D> pts = new List<CVector2D>(); pts.Add(new CVector2D(0.1, 0.9)); pts.Add(new CVector2D(0.7, 0.9)); pts.Add(new CVector2D(0.1, 0.3)); cad2d.AddPolygon(pts, id_l0); } uint id_e0 = cad2d.ConnectVertex_Line(1, 3).id_e_add; cad2d.RemoveElement(CAD_ELEM_TYPE.EDGE, id_e0); DrawerAry.Clear(); DrawerAry.PushBack(new CDrawer_Cad2D(cad2d)); DrawerAry.InitTrans(Camera); } else if (ProbNo == 7) { uint id_l0; { // define shape IList<CVector2D> pts = new List<CVector2D>(); pts.Add(new CVector2D(0.0, 0.0)); pts.Add(new CVector2D(1.0, 0.0)); pts.Add(new CVector2D(1.0, 1.0)); pts.Add(new CVector2D(0.0, 1.0)); id_l0 = cad2d.AddPolygon(pts).id_l_add; } uint id_v1 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, id_l0, new CVector2D(0.9, 0.7)).id_v_add; uint id_v2 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, id_l0, new CVector2D(0.9, 0.1)).id_v_add; uint id_v3 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, id_l0, new CVector2D(0.3, 0.1)).id_v_add; cad2d.ConnectVertex_Line(id_v1, id_v2); cad2d.ConnectVertex_Line(id_v2, id_v3); cad2d.ConnectVertex_Line(id_v3, id_v1); { uint id_e0 = cad2d.ConnectVertex_Line(id_v2, 2).id_e_add; cad2d.RemoveElement(CAD_ELEM_TYPE.EDGE, id_e0); } { uint id_e0 = cad2d.ConnectVertex_Line(2, id_v2).id_e_add; cad2d.RemoveElement(CAD_ELEM_TYPE.EDGE, id_e0); } DrawerAry.Clear(); DrawerAry.PushBack(new CDrawer_Cad2D(cad2d)); DrawerAry.InitTrans(Camera); } else if (ProbNo == 8) { uint id_e3, id_e4; { IList<CVector2D> pts = new List<CVector2D>(); pts.Add(new CVector2D(0.0, 0.0)); // 1 pts.Add(new CVector2D(1.0, 0.0)); // 2 pts.Add(new CVector2D(1.5, 0.0)); // 3 pts.Add(new CVector2D(2.0, 0.0)); // 4 pts.Add(new CVector2D(2.0, 1.0)); // 5 pts.Add(new CVector2D(1.5, 1.0)); // 6 pts.Add(new CVector2D(1.0, 1.0)); // 7 pts.Add(new CVector2D(0.0, 1.0)); // 8 uint id_l0 = cad2d.AddPolygon(pts).id_l_add; uint id_v1 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, id_l0, new CVector2D(0.5, 0.5)).id_v_add; uint id_e1 = cad2d.ConnectVertex_Line(2, 7).id_e_add; uint id_e2 = cad2d.ConnectVertex_Line(3, 6).id_e_add; uint id_v2 = cad2d.AddVertex(CAD_ELEM_TYPE.EDGE, id_e1, new CVector2D(1.0, 0.5)).id_v_add; uint id_v3 = cad2d.AddVertex(CAD_ELEM_TYPE.EDGE, 1, new CVector2D(0.5, 0.0)).id_v_add; id_e3 = cad2d.ConnectVertex_Line(id_v1, id_v2).id_e_add; id_e4 = cad2d.ConnectVertex_Line(id_v1, id_v3).id_e_add; } DrawerAry.Clear(); DrawerAry.PushBack(new CDrawer_Cad2D(cad2d)); DrawerAry.InitTrans(Camera); } else if (ProbNo == 9) { uint id_l0; { // define shape IList<CVector2D> pts = new List<CVector2D>(); pts.Add(new CVector2D(0.0, 0.0)); pts.Add(new CVector2D(1.0, 0.0)); pts.Add(new CVector2D(1.0, 1.0)); pts.Add(new CVector2D(0.0, 1.0)); id_l0 = cad2d.AddPolygon(pts).id_l_add; } uint id_v1 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, id_l0, new CVector2D(0.2, 0.7)).id_v_add; uint id_v2 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, id_l0, new CVector2D(0.2, 0.3)).id_v_add; uint id_e0 = cad2d.ConnectVertex_Line(id_v1, id_v2).id_e_add; uint id_v3 = cad2d.AddVertex(CAD_ELEM_TYPE.EDGE, id_e0, new CVector2D(0.2, 0.5)).id_v_add; uint id_v4 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, id_l0, new CVector2D(0.5, 0.5)).id_v_add; uint id_v5 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, id_l0, new CVector2D(0.7, 0.5)).id_v_add; uint id_e1 = cad2d.ConnectVertex_Line(id_v3, id_v4).id_e_add; uint id_e2 = cad2d.ConnectVertex_Line(id_v4, id_v5).id_e_add; cad2d.RemoveElement(CAD_ELEM_TYPE.EDGE, id_e1); DrawerAry.Clear(); DrawerAry.PushBack(new CDrawer_Cad2D(cad2d)); DrawerAry.InitTrans(Camera); } else if (ProbNo == 10) { uint id_l0; { // define shape IList<CVector2D> pts = new List<CVector2D>(); pts.Add(new CVector2D(0.0, 0.0)); pts.Add(new CVector2D(1.0, 0.0)); pts.Add(new CVector2D(1.0, 1.0)); pts.Add(new CVector2D(0.0, 1.0)); id_l0 = cad2d.AddPolygon(pts).id_l_add; } uint id_v1 = cad2d.AddVertex(CAD_ELEM_TYPE.LOOP, 0, new CVector2D(1.1, 0)).id_v_add; cad2d.RemoveElement(CAD_ELEM_TYPE.VERTEX, id_v1); DrawerAry.Clear(); DrawerAry.PushBack(new CDrawer_Cad2D(cad2d)); DrawerAry.InitTrans(Camera); } else if (ProbNo == 11) { { // define initial loop IList<CVector2D> pts = new List<CVector2D>(); pts.Add(new CVector2D(0.0, 0.0)); pts.Add(new CVector2D(1.0, 0.0)); pts.Add(new CVector2D(1.0, 1.0)); pts.Add(new CVector2D(0.0, 1.0)); pts.Add(new CVector2D(0.0, 0.5)); cad2d.AddPolygon(pts); } /* { IList<CVector2D> aRelCo = new List<CVector2D>(); aRelCo.Add(new CVector2D(0.25, -0.1)); aRelCo.Add(new CVector2D(0.5, -0.0)); aRelCo.Add(new CVector2D(0.75, -0.1)); cad2d.SetCurve_Polyline(1, aRelCo); } cad2d.SetCurve_Arc(2, true, -1); { IList<CVector2D> aRelCo = new List<CVector2D>(); aRelCo.Add(new CVector2D(+0.01, 0.35)); aRelCo.Add(new CVector2D(-0.05, 0.25)); aRelCo.Add(new CVector2D(+0.01, 0.15)); cad2d.SetCurve_Polyline(5, aRelCo); } */ cad2d.RemoveElement(CAD_ELEM_TYPE.VERTEX, 1); // removing this point marges 2 polylines cad2d.SetCurve_Bezier(3, 0.2, +0.5, 0.8, -0.5); //cad2d.SetCurve_Bezier(4, 0.0,-1.0, 0.3,+1.0); //cad2d.SetCurve_Bezier(5, 0.0,-1.0, 0.3,-1.0); Console.WriteLine("area : {0}", cad2d.GetArea_Loop(1)); cad2d.WriteToFile_dxf("hoge.dxf", 1); DrawerAry.Clear(); DrawerAry.PushBack(new CDrawer_Cad2D(cad2d)); DrawerAry.InitTrans(Camera); } else if (ProbNo == 12) { string svgfname = "../../../input_file/shape2d_0.svg"; CCadObj2D cad2dtmp = null; if (File.Exists(svgfname)) { DelFEM4NetCad.CCadSVG.ReadSVG_AddLoopCad(svgfname, out cad2dtmp); // export to the file using (CSerializer fout = new CSerializer("hoge.txt", false)) { cad2dtmp.Serialize(fout); } cad2dtmp.Dispose(); // import form the file cad2d.Clear(); using (CSerializer fin = new CSerializer("hoge.txt", true)) { cad2d.Serialize(fin); } DrawerAry.Clear(); DrawerAry.PushBack(new CDrawer_Cad2D(cad2d)); DrawerAry.InitTrans(Camera); } else { MessageBox.Show("SVGファイルがありません"); } } } // using cad2d success = true; } catch (Exception exception) { Console.WriteLine(exception.Message + " " + exception.StackTrace); } Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); DrawerGlUtility.SetProjectionTransform(Camera); Glut.glutPostRedisplay(); ProbNo++; if (ProbNo == ProbCnt) ProbNo = 0; return success; }