Hi,
In general the diagram will raise the document.EventSinkService.NodeInserted event whenever a node (be it a shape, primitive, port etc.) is added to the document. However the event does not give information of whether the node was inserted because of drag & drop or other operation.
So we can only suggest that you try to override the default drag and drop target tool, to perform the tasks that you need to to. Take a look at the following example:
Drawing View - Custom Drag and Drop
The NMyDragDropTargetTool class overrides ProcessDragDrop to make a hit test that determines the shape that the user has dropped on. So you can do the following:
1. Handle the NodeInserted event.
2. Make a flag which indicates whether your are currently in drag and drop.
3. Override the ProcessDragDrop.
Attached is the code of the default NDragDropTargetTool for reference purposes.
Following is the sample code that we created for your case:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Nevron.Dom;
using Nevron.GraphicsCore;
using Nevron.Diagram;
using Nevron.Diagram.Shapes;
using Nevron.Diagram.Filters;
using Nevron.Diagram.WinForm;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
bool m_bDroping = false;
NNodeList m_DroppedShapes = null;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// create the views
NDrawingView drawingView = new NDrawingView();
drawingView.Dock = DockStyle.Fill;
Controls.Add(drawingView);
NLibraryView libraryView = new NLibraryView();
libraryView.Dock = DockStyle.Left;
Controls.Add(libraryView);
// create the documents
NDrawingDocument drawing = new NDrawingDocument();
drawingView.Document = drawing;
NBasicShapesFactory basicShapes = new NBasicShapesFactory(NGraphicsUnit.Pixel, 96.0f);
basicShapes.DefaultSize = new NSizeF(40, 30);
libraryView.Document = basicShapes.CreateLibrary();
// override the default drag & drop on drawings
// replace the default drag drop target tool with your own one
// to extend the drop capabilities of the view
NTool tool = drawingView.Controller.Tools.GetToolByName(NDWFR.ToolDragDropTarget);
int index = drawingView.Controller.Tools.IndexOf(tool);
drawingView.Controller.Tools.Remove(tool);
tool = new NMyDragDropTargetTool(this);
tool.Enabled = true;
drawingView.Controller.Tools.Insert(index, tool);
// subscribe for node inserted
drawing.EventSinkService.NodeInserted += new ChildNodeEventHandler(EventSinkService_NodeInserted);
}
private void EventSinkService_NodeInserted(NChildNodeEventArgs args)
{
if (m_bDroping)
{
// accumulate the shapes that are inserted in a drag and drop operation
NShape shape = args.Child as NShape;
if (shape!=null)
{
m_DroppedShapes.Add(shape);
}
}
}
private void OnDropped(NNodeList droppedShapes, NShape dropShape)
{
string message = "Dropped shapes count: " + droppedShapes.Count;
if (dropShape == null)
{
message += " in active layer";
}
else
{
message += " in shape: " + dropShape.ToString();
}
MessageBox.Show(message);
}
[Serializable]
public class NMyDragDropTargetTool : NDragDropTargetTool
{
///
/// Default constructor
/// public NMyDragDropTargetTool(Form1 form)
{
m_Form = form;
}
///
/// Processes the drag drop event
/// ///
/// Overriden to the drag drop data object in the document active layer
/// ///
///
true if the event was processed, otherwise false public override bool ProcessDragDrop(DragEventArgs e)
{
// check whether a group is hit, and if not use base implementation
// which adds shapes to the active layer
m_Form.m_bDroping = true;
m_Form.m_DroppedShapes = new NNodeList();
NShape dropShape = null;
try
{
NPointF mouseInDevice = View.GetMousePositionInDevice();
dropShape = View.LastActiveDocumentContentHit(mouseInDevice, -1, NFilters.TypeNShape) as NShape;
return base.ProcessDragDrop(e);
}
finally
{
m_Form.OnDropped(m_Form.m_DroppedShapes, dropShape);
m_Form.m_DroppedShapes = null;
m_Form.m_bDroping = false;
}
}
Form1 m_Form;
}
}
}
Best Regards,
Nevron Support Team