Profile Picture

Programmatically draw line shape for library

Posted By Ashley Davy 3 Years Ago
Author
Message
Ashley Davy
Question Posted 3 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: Forum Members
Last Active: 3 Years Ago
Posts: 36, Visits: 119
I am building a custom library of shapes so that the user can drag and drop them onto the grid.  I would like to build a shape that is a line that has the endpoints so that the user can resize the line after it is dropped on the grid.  It should work similar to the Alternative Branch 1 in the Decision Tree Shapes library.  Below is my code that is used to draw the shape but it does not contain the handles to resize the line or reposition the ends of the line.  Also I need to turn off the rotation circle.

Thanks,
Ashley

Private Function DrawFillet4() As Nevron.Nov.Diagram.NShape

   Dim FilletShape As Nevron.Nov.Diagram.NShape = New Nevron.Nov.Diagram.NShape()

   Dim TopMoveTo As NMoveTo = New NMoveTo(0, 0)
   TopMoveTo.ShowFill = False

   FilletShape.Geometry.Add(TopMoveTo)
   FilletShape.Geometry.LineTo(300, 0)

   'FilletShape.AllowRotate = False
   'FilletShape.AllowResizeX = False
   'FilletShape.AllowResizeY = False

   Dim StrokeFillet As NStroke = New NStroke()
   StrokeFillet.Width = 3
   StrokeFillet.Color = New NColor(pnlSymbolColor.BackColor.R, pnlSymbolColor.BackColor.G, pnlSymbolColor.BackColor.B)

   FilletShape.Geometry.Stroke = StrokeFillet

   Return FilletShape

  End Function



Nevron Support
Posted 3 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,018
Hello,

You can use the following code to create a shape identical to "Alternative Branch 1" of the "Decision Tree Shapes" library. Just pass a new shape to the method and it will configure it and add the necessary geometry primitives. You can also set the width and the height of the shape.


Private Shared Sub InitAlternativeBranch1(ByVal shape As NShape)
  shape.Init1DShape(EN1DShapeXForm.Vector)
  shape.EndX = 200
  shape.Height = 0
  Dim geometry As NGeometry = shape.Geometry

  If True Then
   Dim plotFigure As NMoveTo = geometry.RelMoveTo(0R, 0.5R)
   geometry.RelLineTo(1R, 0.5R)
   plotFigure.CloseFigure = False
   geometry.ClipWithTextBlock = ENGeometryClipWithShapeBlock.Clip
  End If

  Dim textBlock As NTextBlock = New NTextBlock()
  textBlock.ResizeMode = ENTextBlockResizeMode.TextSize
  textBlock.SetFx(NTextBlock.AngleProperty, "-ATAN2($Parent.EndY - $Parent.BeginY, $Parent.EndX - $Parent.BeginX)")
  shape.TextBlock = textBlock
End Sub



Best Regards,
Nevron Support Team



Ashley Davy
Posted 3 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: Forum Members
Last Active: 3 Years Ago
Posts: 36, Visits: 119
Thanks for the answer.    Can you explain the following code.  I am not sure how this works.  Especially the geometry.RelMoveTo(0R, 0.5R).  How would this know to make the line 200?

If True Then
    Dim plotFigure As NMoveTo = geometry.RelMoveTo(0R, 0.5R)
    geometry.RelLineTo(1.0R, 0.5R)
    plotFigure.CloseFigure = False
    geometry.ClipWithTextBlock = ENGeometryClipWithShapeBlock.Clip
   End If

Thanks,
Ashley

Nevron Support
Posted 3 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,018
Hi Ashley,

Relative drawing commands draw geometry primitives on coordinates relative to the shape size. For X, it's relative to shape width (x = relX * shapeWidth) and for Y it's relative to shape height (y = relY * shapeHeight). For example if shape Width is 200, then a relative X coordinate of 0.25, means 50, relative X coordinate of 0.5 means 100 and relative X coordinate of 1 means 200.

For more information about shape geometries, please check out the following documentation topic:
NOV Diagram Shape Geometry


Best Regards,
Nevron Support Team



Ashley Davy
Posted 3 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: Forum Members
Last Active: 3 Years Ago
Posts: 36, Visits: 119
In continuing to build out my library how would I programmatically add the Text Box (as in the Annotation Shapes) to my library.  In doing this I would like to pre populate the text of my choosing along with my choice to either include the border or not to include the border.

Thanks,
Ashley

Nevron Support
Posted 3 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,018
Hi Ashley,

You can use the following code to create a text shape:


Private Function CreateTextShape(ByVal defaultText As String) As NShape
  Dim shape As NShape = New NShape()
  shape.Init2DShape()
  shape.Width = 80
  shape.Height = 60
  shape.LocPinX = 0
  shape.LocPinY = 1
  Dim geometry As NGeometry = shape.Geometry

  If True Then
   geometry.Fill = Nothing
   Dim plotFigure As NMoveTo = geometry.MoveTo("0", "Height")
   geometry.LineTo("Width", "Geometry.0.Y")
   geometry.LineTo("Geometry.1.X", "0")
   geometry.LineTo("0", "0")
   geometry.LineTo("Geometry.0.X", "Geometry.0.Y")
   plotFigure.CloseFigure = True
  End If

  Dim textBlock As NTextBlock = New NTextBlock()
  textBlock.Text = defaultText
  textBlock.ResizeMode = ENTextBlockResizeMode.ShapeWidthTextHeight
  shape.TextBlock = textBlock
  Return shape
End Function


You can then create a library item and add it to a library view like this:


Dim textShape As NShape = CreateTextShape("My Text")
Dim libraryItem As NLibraryItem = New NLibraryItem(textShape, "Text", Nothing)
libraryView.Content.Items.Add(libraryItem)



Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic