コード例 #1
0
ファイル: MainLogic.cs プロジェクト: ryujimiya/delfem4net
 /// <summary>
 /// Glut: メニューイベントハンドラ
 /// </summary>
 /// <param name="value"></param>
 private void myGlutMenu(int value)
 {
     isMenuItemClicked = true;
     if (value == 1)
     {
         Console.WriteLine("EditCurve");
         Mode = ModeDv.DragCurve;
         Console.WriteLine("Mode:{0}", Mode);
         return;
     }
     else if (value == 2)
     {
         // ChangeToLine
         if( ElemType_part_cad != CAD_ELEM_TYPE.EDGE )
         {
             return;
         }
         Console.WriteLine("ChangeToLine");
         IsUpdatedCad = Cad2D.SetCurve_Line(Id_part_cad);
         Glut.glutPostRedisplay();
         return;
     }
     else if (value == 3)
     {
         // ChangeToArc
         if( ElemType_part_cad != CAD_ELEM_TYPE.EDGE )
         {
             return;
         }
         Console.WriteLine("ChangeToArc");
         {
             uint id_vs, id_ve;
             Cad2D.GetIdVertex_Edge(out id_vs, out id_ve, Id_part_cad);
             CVector2D vs = Cad2D.GetVertexCoord(id_vs);
             CVector2D ve = Cad2D.GetVertexCoord(id_ve);
             double dist = Math.Sqrt( CVector2D.SquareLength(vs, ve) ) * 10.0;
             IsUpdatedCad = Cad2D.SetCurve_Arc(Id_part_cad, false, dist);
             Glut.glutPostRedisplay();
         }
         return;
     }
     else if (value == 4)
     {
         if( ElemType_part_cad != CAD_ELEM_TYPE.EDGE )
         {
             return;
         }
         Console.WriteLine("ChangeToPolyline");
         Cad2D.SetCurve_Polyline(Id_part_cad);
         Glut.glutPostRedisplay();
         return;
     }
 }
コード例 #2
0
ファイル: MainLogic.cs プロジェクト: ryujimiya/delfem4net
        /// <summary>
        /// Glut:マウスクリックイベントハンドラ
        /// </summary>
        /// <param name="button"></param>
        /// <param name="state"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        private void myGlutMouse(int button, int state, int x, int y)
        {
            //Console.WriteLine("myGlutMouse");
            // ryujimiya
            // メニューが左クリックでメニューイベントハンドラが処理された後、MouseUpのイベントが発生する
            // それは望んでいるイベントではないと思われるので除外するようにした。
            if (isMenuItemClicked)
            {
                isMenuItemClicked = false;
                //Console.WriteLine("skipped: state {0}", state);
                return;
            }

            int[] viewport = new int[4];
            Gl.glGetIntegerv(Gl.GL_VIEWPORT, viewport);
            int winW = viewport[2];
            int winH = viewport[3];
            MovBeginX = (2.0 * x - winW) / winW;
            MovBeginY = (winH - 2.0 * y) / winH;
            PressButton = button;

            uint id_part_cad0 = Id_part_cad;
            CAD_ELEM_TYPE elemType_part_cad0 = ElemType_part_cad;
            { // hilight the picked element
                int sizeBuffer = 128;
                DelFEM4NetCom.View.DrawerGlUtility.PickSelectBuffer pickSelectBuffer = null;
                DelFEM4NetCom.View.DrawerGlUtility.PickPre((uint)sizeBuffer, out pickSelectBuffer, (uint)x, (uint)y, 5, 5, Camera);
                DrawerAry.DrawSelection();
                List<DelFEM4NetCom.View.SSelectedObject> aSelecObj = (List<DelFEM4NetCom.View.SSelectedObject>)DelFEM4NetCom.View.DrawerGlUtility.PickPost(pickSelectBuffer, (uint)x, (uint)y, Camera);
                DrawerAry.ClearSelected();

                Id_part_cad = 0;
                elemType_part_cad0 = CAD_ELEM_TYPE.NOT_SET;
                if( aSelecObj.Count > 0 )
                {
                     Drawer.GetCadPartID(aSelecObj[0].name, ref ElemType_part_cad, ref Id_part_cad);
                     DrawerAry.AddSelected( aSelecObj[0].name );
                }
                else
                {
                    ElemType_part_cad = CAD_ELEM_TYPE.NOT_SET;
                    Id_part_cad = 0;
                }
            }
            //Console.WriteLine("ElemType_part_cad: {0}  Id_part_cad: {1}", ElemType_part_cad, Id_part_cad);

            if ( state == Glut.GLUT_DOWN )
            {
                if (Mode == ModeDv.DragCurve)
                {
                    if( ElemType_part_cad == CAD_ELEM_TYPE.EDGE && Cad2D.IsElemID(ElemType_part_cad,Id_part_cad) )
                    {
                        CVector3D oloc = Camera.ProjectionOnPlane(MovBeginX, MovBeginY);
                        if( Cad2D.GetEdgeCurveType(Id_part_cad) == CURVE_TYPE.CURVE_POLYLINE )
                        {
                            bool res = Cad2D.PreCompDragPolyline(Id_part_cad, new CVector2D(oloc.x,oloc.y));
                        }
                        return;
                    }
                }
                else if( Mode == ModeDv.AddPoint )
                {   // add point
                    clearAVec(AVecStrok);
                    if( ElemType_part_cad == CAD_ELEM_TYPE.VERTEX )
                    {
                        return;
                    }
                    CVector3D oloc = Camera.ProjectionOnPlane(MovBeginX, MovBeginY);
                    CVector2D v0 = new CVector2D(oloc.x, oloc.y);
                    uint id_v0 = Cad2D.AddVertex(ElemType_part_cad, Id_part_cad, v0).id_v_add;
                    ElemType_part_cad = CAD_ELEM_TYPE.VERTEX;
                    Id_part_cad = id_v0;
                    if( !Cad2D.IsElemID(CAD_ELEM_TYPE.VERTEX, id_v0) )
                    {
                        clearAVec(AVecStrok);
                        return;
                    }
                    DrawerAry.Clear();
                    if (Drawer != null)
                    {
                        Drawer = null;
                    }
                    Drawer = new CDrawer_Cad2D(Cad2D);
                    DrawerAry.PushBack( Drawer );
                }
                else if( Mode == ModeDv.DeletePoint )
                {   // delete point
                    if( Cad2D.IsElemID(ElemType_part_cad, Id_part_cad) )
                    {
                        bool iflag = Cad2D.RemoveElement(ElemType_part_cad, Id_part_cad);
                        if( iflag )
                        {
                            DrawerAry.Clear();
                            if (Drawer != null)
                            {
                                Drawer = null;
                            }
                            Drawer = new CDrawer_Cad2D(Cad2D);
                            DrawerAry.PushBack( Drawer );
                        }
                    }
                    Mode = ModeDv.Drag;
                    Console.WriteLine("Mode:{0}", Mode);
                }
            }
            if( state == Glut.GLUT_UP )
            {
                if (Mode == ModeDv.AddPoint)
                {
                    //Mode = Mode.Drag;
                    //Console.WriteLine("Mode:{0}", Mode);
                    if (elemType_part_cad0 != CAD_ELEM_TYPE.VERTEX || !Cad2D.IsElemID(CAD_ELEM_TYPE.VERTEX, id_part_cad0))
                    {
                        clearAVec(AVecStrok);
                        return;
                    }
                    uint id_v0 = id_part_cad0;
                    uint id_v1 = 0;
                    if( ElemType_part_cad == CAD_ELEM_TYPE.VERTEX )
                    {
                        if( !Cad2D.IsElemID(CAD_ELEM_TYPE.VERTEX, Id_part_cad) )
                        {
                            clearAVec(AVecStrok);
                            return;
                        }
                        id_v1 = Id_part_cad;
                    }
                    else
                    {
                        CVector2D v1 = AVecStrok[AVecStrok.Count - 1];
                        id_v1 = Cad2D.AddVertex(ElemType_part_cad, Id_part_cad, v1).id_v_add;
                        if( !Cad2D.IsElemID(CAD_ELEM_TYPE.VERTEX,id_v1) )
                        {
                            clearAVec(AVecStrok);
                            return;
                        }
                    }
                    CEdge2D e = new CEdge2D(id_v0,id_v1);
                    {
                        //e.itype = CURVE_TYPE.CURVE_POLYLINE;
                       int n = AVecStrok.Count;
                        CVector2D pos = Cad2D.GetVertexCoord(e.GetIdVtx(true));
                        CVector2D poe = Cad2D.GetVertexCoord(e.GetIdVtx(false));
                        e.SetVtxCoords(pos, poe);
                        double sqlen = CVector2D.SquareLength(poe - pos);
                        CVector2D eh = (poe - pos) * (1/sqlen);
                        CVector2D ev = new CVector2D(-eh.y, eh.x);
                        {
                            IList<double> aRelCo = new List<double>();
                             foreach (CVector2D pp in AVecStrok)
                             {
                                 double x1 = CVector2D.Dot(pp - pos, eh);
                                 double y1 = CVector2D.Dot(pp - pos, ev);
                                 aRelCo.Add(x1);
                                 aRelCo.Add(y1);
                             }
                             e.SetCurve_Polyline(aRelCo);
                        }
                        {
                            IList<CVector2D> aVecDiv = new List<CVector2D>();
                            int ndiv = (int)((double)e.GetCurveLength() / (Camera.GetHalfViewHeight() * 0.04) + 1);
                            e.GetCurveAsPolyline(ref aVecDiv, ndiv);
                            IList<double> aRelCo = new List<double>();
                            foreach (CVector2D pp in aVecDiv)
                            {
                                double x1 = CVector2D.Dot(pp - pos, eh);
                                double y1 = CVector2D.Dot(pp - pos, ev);
                                aRelCo.Add(x1);
                                aRelCo.Add(y1);
                            }
                            e.SetCurve_Polyline(aRelCo);
                        }
                    }
                    Cad2D.ConnectVertex(e);
                    DrawerAry.Clear();
                    if (Drawer != null)
                    {
                        Drawer = null;
                    }
                    Drawer = new CDrawer_Cad2D(Cad2D);
                    DrawerAry.PushBack( Drawer );
                    clearAVec(AVecStrok);
                }
            }
        }
コード例 #3
0
ファイル: MainLogic.cs プロジェクト: ryujimiya/delfem4net
 /// <summary>
 /// Glut : キー入力イベントハンドラ
 /// </summary>
 /// <param name="key"></param>
 /// <param name="x"></param>
 /// <param name="y"></param>
 private void myGlutKeyboard(byte key, int x, int y)
 {
     if (key == getSingleByte('q')
         || key == getSingleByte('Q')
         || key == 27  // ESC
         )
     {
         System.Environment.Exit(0);
     }
     else if (key == getSingleByte(' '))
     {
        setNewProblem();
     }
     ///   0:drag
     ///   1:drag curve
     ///   2:add point
     ///   3:delete point
     ///   4:smooth curve
     else if (key == getSingleByte('0'))
     {
         Mode = ModeDv.Drag;
         Console.WriteLine("Mode:{0}", Mode);
     }
     else if (key == getSingleByte('1'))
     {
         Mode = ModeDv.DragCurve;
         Console.WriteLine("Mode:{0}", Mode);
     }
     else if (key == getSingleByte('2'))
     {
         Mode = ModeDv.AddPoint;
         Console.WriteLine("Mode:{0}", Mode);
     }
     else if (key == getSingleByte('3'))
     {
         Mode = ModeDv.DeletePoint;
         Console.WriteLine("Mode:{0}", Mode);
     }
     else if (key == getSingleByte('4'))
     {
         Mode = ModeDv.SmoothCurve;
         Console.WriteLine("Mode:{0}", Mode);
     }
 }