예제 #1
0
        public DoubleInputView(DoubleInputModel model)
        {
            this.Build ();

            for (int i = 0; i < model.Count; ++i)
            {
                var input = new Gtk.Entry();
                var label = new Gtk.Label(model._labels[i] + ": ");

                //The index i was being "captured" by referance in the anonymous function.\
                //This makes a copy
                int j = i;
                input.Changed +=
                (object sender, EventArgs e) =>
                {
                    Double.TryParse((sender as Gtk.Entry).Text, out model._inputs[j]);
                    Console.WriteLine("we wrote: " + model._inputs[j] + " j: " + j);
                };
                MainView.Put(label, 10, 10 + i*40);
                MainView.Put(input, 120, 10 + i*40);
            }

            buttonCancel.Clicked += (o, args) => {model._inputs = null; this.Destroy();};
            buttonOk.Clicked += (o, args) => {this.Destroy();};
        }
        public void ButtonPressed(uint button)
        {
            DoubleInputView dialogView;
            DoubleInputModel dialogModel;

            switch (button) {
            case 1:

                switch (selectedTool) {
                case ToolBarViewModel.Tools.SELECTION:
                    IsClicked = true;

                    GrabActiveObject();
                    break;

                case ToolBarViewModel.Tools.JOINT:
                    if (!IsJoiningPoints)
                    {
                        IsJoiningPoints = true;
                        GrabActiveObject();

                    }
                    else
                    {
                        IsJoiningPoints = false;
                        var point1 = ActivePoint;
                        var body1 = ActiveObject;

                        GrabActiveObject();

                        _model.Controller.AddJoint(point1, ActivePoint);
                    }
                    break;

                case ToolBarViewModel.Tools.FORCE:
                    //popup dialog that asks for mag/dir
                    dialogModel = new DoubleInputModel(2, new string[]{"Angle", "Magnitude"});
                    dialogView = new DoubleInputView(dialogModel);
                    dialogView.ShowAll();
                    dialogView.Run();

                    GrabActiveObject();
                    if (ActiveObject != null && dialogModel._inputs != null)
                        ActiveObject.AddForce (new Tuple<PointDouble,double, double> (ActivePoint,dialogModel._inputs[0],dialogModel._inputs[1]));
                    //_model.Controller.AddForce(new Tuple<PointDouble,double, double> (ActivePoint,dialogModel._inputs[0],dialogModel._inputs[1]));

                    break;

                case ToolBarViewModel.Tools.MOMENT:
                    //popup dialog that asks for mag
                    dialogModel = new DoubleInputModel(1, new string[]{"Magnitude"});
                    dialogView = new DoubleInputView(dialogModel);
                    dialogView.ShowAll();
                    dialogView.Run();

                    GrabActiveObject();

                    if (ActiveObject != null && dialogModel._inputs != null)
                        ActiveObject.AddMoment (new Tuple<PointDouble,double> (ActivePoint,dialogModel._inputs[0]));
                    //_model.Controller.AddForce(new Tuple<PointDouble,double> (ActivePoint,dialogModel._inputs[0]));

                    break;

                case ToolBarViewModel.Tools.CONNECTED:
                    if (!IsDrawingObject)
                    {
                        BeginDrawingBody ();
                        TemporaryObject = new ConnectedObject();
                    }
                    ActivePoint = MousePos;
                    _model.TemporaryObject.AddPoint (ActivePoint);
                    break;

                case ToolBarViewModel.Tools.UNCONNECTED:
                    if (!IsDrawingObject)
                    {
                        BeginDrawingBody ();
                        TemporaryObject = new UnconnectedObject();
                    }
                    ActivePoint = MousePos;
                    _model.TemporaryObject.AddPoint (ActivePoint);
                    break;

                default:
                    break;
                }
                _lastX = _mouseX;
                _lastY = _mouseY;
                break;

            case 3:
                if (IsDrawingObject) {

                    _model.TemporaryObject.AddPoint (MousePos);
                    switch (selectedTool) {
                    case ToolBarViewModel.Tools.CONNECTED:
                        EndDrawingConnected ();
                        break;

                    case ToolBarViewModel.Tools.UNCONNECTED:
                        EndDrawingUnconnected ();
                        break;

                    }

                }
                break;
            }
            VMMessenger.getMessenger ().sendMessage<RequestRedrawMessage> (new RequestRedrawMessage ());
        }