Nevron Forum

NLineShape Does not appear

https://www.nevron.com/Forum/Topic3522.aspx

By Montford Chelliah - Friday, May 14, 2010

Hi,

I am doing a workflow application (something similar windows workflow) using Nevron diagram. This workflow, I am planning to add few custom controls that can be dragged and dropped into designer surface.

I have created a sample application (attached with this mail), that contains "IfElseActivity" and "RootActivity" custom controls. I am adding "RootActivity" control at the load event of the form and "IfElseActivity" user can drag and drop on to the surface.

Either case I am facing a problem with the NLineShape object. The NLineShape does not display on designer surface. Please advice me.

Thanks

Anslum

 

By Nevron Support - Saturday, May 15, 2010

Hi,

Prior to specifying the shapes being connected you must add them to a drawing document. Let's take a look at the class RootActivity you have attached to your post. All you have to do is to modify the te first constructor:

 

public RootActivity(NDrawingDocument document, int xPosition, int yPosition)

{

      document.ActiveLayer.AddChild(this);

      CreateRoot(xPosition, yPosition);

}

 

 

Also do not forget to remove from your MainForm the line of code that adds the activity group:

 

document.ActiveLayer.AddChild(root);

 

By Montford Chelliah - Sunday, May 16, 2010

Hi,

Thanks for information. The trick only works on root activity, but it does not work properly on IfElseActivity. When I do that in IfElseActivity, it adds two instances on drawing surface. Do I need to do some otherway for drag and drop control such as IfElseActivity?

Please advice me

Thanks,

Anslum

By Nevron Support - Monday, May 17, 2010

Hi Anslum,

For the case of drag and drop you should implement your own data object and data adaptor. To see a sample implementation take a look at the following example that comes with the diagramming component: C# Examples -> Drawing View -> Custom Drag and Drop.

By Montford Chelliah - Monday, May 17, 2010

Hi,

I followed same step on my sample (refer Mainform at NevronWorkflow project) application. In that case the NLineShape objects are not visible on the drawing surface. I hope that is my original question.

Thanks

Anslum

 

 

 

By Nevron Support - Tuesday, May 18, 2010

Hi,

Let me explain you in more details: you will need a dummy drawing document to place the dragged shape in, in order to get the connectors working. You can easily do this by in the AdaptTableFormat of the data object adaptor:

 

protected virtual NDrawingDataObject AdaptTableFormat(string tableName)

{

      NDrawingDocument dummy = new NDrawingDocument();

      NShape shape = null;

      if (tableName == "1")

      {

            shape = new IfElseActivity(dummy);

      }

      else

      {

            shape = new NRectangleShape(0, 0, 50, 50);

      }

 

      NDrawingDataObject ddo = new NDrawingDataObject(dummy, new INDiagramElement[] { shape });

      return ddo;

}

 

Do not forget to add the shape to the document as soon as it is created (for example in the constructor):

 

public IfElseActivity()

{

}

 

public IfElseActivity(NDrawingDocument document)

{

      document.ActiveLayer.AddChild(this);

      CreateBranches();

}

 

By Montford Chelliah - Tuesday, May 18, 2010

Hi,

Thanks for the details and It is working fine. I have another clarification regarding the positioning of the shape. Is it possible to specify the location of the control while we are dropping on the surface. I meant, I want to drop the shape on perticular location not rather any place on the drawing surface. How do I pass the coordinates? and which class (NMyDragDropTargetTool or NMyDataObjectAdaptor) and which method?

Thanks

Anslum

By Nevron Support - Thursday, May 20, 2010

Hi,

In order to do that you should override the EndMove method of the drag drop target tool:

 

protected override void EndMove(bool commit)

{

      if (commit == false)

      {

            base.EndMove(commit);

            return;

      }

 

      NNodeList elements = View.PreviewManager.EndMovePreview(true, true);

      if (elements.Count == 0)

            return;

 

      if (elements[0] is IfElseActivity)

      {

            // Get the dropped element

            IfElseActivity activity = (IfElseActivity)elements[0];

 

            // Set its location

            activity.Location = new NPointF(100, 100);

      }

      else

      {

            base.EndMove(commit);

      }

}