Exemplo n.º 1
0
        /// <summary>A node has been dropped.</summary>
        /// <param name="sender">Sending object</param>
        /// <param name="e">Drop arguments</param>
        private void OnDrop(object sender, DropArgs e)
        {
            try
            {
                string toParentPath = e.NodePath;
                Model  toParent     = Apsim.Get(this.ApsimXFile, toParentPath) as Model;

                DragObject dragObject = e.DragObject as DragObject;
                if (dragObject != null && toParent != null)
                {
                    string modelString    = dragObject.ModelString;
                    string fromParentPath = StringUtilities.ParentName(dragObject.NodePath);

                    ICommand cmd = null;
                    if (e.Copied)
                    {
                        this.Add(modelString, toParentPath);
                    }
                    else if (e.Moved)
                    {
                        if (fromParentPath != toParentPath)
                        {
                            Model fromModel = Apsim.Get(this.ApsimXFile, dragObject.NodePath) as Model;
                            if (fromModel != null)
                            {
                                cmd = new MoveModelCommand(fromModel, toParent, this.GetNodeDescription(fromModel), this);
                                CommandHistory.Add(cmd);
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                MainPresenter.ShowError(err);
            }
        }
Exemplo n.º 2
0
        /// <summary>A node has been dropped.</summary>
        /// <param name="sender">Sending object</param>
        /// <param name="e">Drop arguments</param>
        private void OnDrop(object sender, DropArgs e)
        {
            string toParentPath = e.NodePath;
            Model  toParent     = Apsim.Get(this.ApsimXFile, toParentPath) as Model;

            DragObject dragObject = e.DragObject as DragObject;

            if (dragObject != null && toParent != null)
            {
                string fromModelXml   = dragObject.Xml;
                string fromParentPath = StringUtilities.ParentName(dragObject.NodePath);

                ICommand cmd = null;
                if (e.Copied)
                {
                    Add(fromModelXml, toParentPath);
                }
                else if (e.Moved)
                {
                    Add(fromModelXml, toParentPath);
                    if (fromParentPath != toParentPath)
                    {
                        Model fromModel = Apsim.Get(this.ApsimXFile, dragObject.NodePath) as Model;
                        if (fromModel != null)
                        {
                            cmd = new MoveModelCommand(fromModel, toParent);
                        }
                    }
                }

                if (cmd != null)
                {
                    CommandHistory.Add(cmd);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>A node has begun to be dragged.</summary>
        /// <param name="sender">Sending object</param>
        /// <param name="e">Drag arguments</param>
        private void OnDragStart(object sender, DragStartArgs e)
        {
            Model obj = Apsim.Get(this.ApsimXFile, e.NodePath) as Model;
            if (obj != null)
            {
                string xml = Apsim.Serialise(obj);
                SetClipboardText(xml);

                DragObject dragObject = new DragObject();
                dragObject.NodePath = e.NodePath;
                dragObject.ModelType = obj.GetType();
                dragObject.Xml = xml;
                e.DragObject = dragObject;
            }
        }