Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to use layout objects & preserve LinkStyle (Read 3012 times)
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
How to use layout objects & preserve LinkStyle
Apr 25th, 2010 at 10:18pm
Print Post  
Hi.

Maybe Im blind or I tried to search wrong keywords, but i cant find something about this issue.

I have diagram with many links various LinkStyle. Im using 11 types of layouting so user can choose one:

  Private MoGridLayout As GridLayout = New GridLayout
    Private MoLayeredLayout As LayeredLayout = New LayeredLayout
    Private MoSpringLayout As SpringLayout = New SpringLayout
    Private MoTreeLayout As TreeLayout = New TreeLayout
    Private MoAnnealLayout As AnnealLayout = New AnnealLayout
    Private MoOrthogonalLayout As OrthogonalLayout = New OrthogonalLayout
    Private MoCircularLayout As CircularLayout = New CircularLayout
    Private MoOrthogonalRouter As OrthogonalRouter = New OrthogonalRouter
    Private MoFlowLayout As FlowLayout = New FlowLayout
    Private MoFlowChartLayout As FlowchartLayout = New FlowchartLayout
    Private MoTopologicalLayout As TopologicalLayout = New TopologicalLayout


How to layout my diagram but to preserve original LinkStyle of all links? Is it possible?

Thx.

...MUDO...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to use layout objects & preserve LinkS
Reply #1 - Apr 26th, 2010 at 7:48am
Print Post  
Hi,

It's not, some layout classes set a predefined style (e.g. OrthogonalLayout -> Cascading), and some set one according to their own LinkType property. If you need to preserve the styles, save them in Dictionary<link, style> and restore them after that. You will also need to remap the control points set by the layout function so that the link path looks similar after resetting its style. This wouldn't be necessary only when changing from Cascading to Polyline.

Stoyan
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: How to use layout objects & preserve LinkS
Reply #2 - Apr 26th, 2010 at 10:22pm
Print Post  
Thx Stoyo.

I also set some properties of all links. Is it ok? Another settings are needed? My class is like this:

Code
Select All
Imports MindFusion.Diagramming.Layout

Public Class ClsDiagramLayout
    'represents class for diagram layouting with various types of layouts

#Region "Attributes"
#Region "Private attributes"
    'all layout engines
    Private MoGridLayout As GridLayout = New GridLayout
    Private MoLayeredLayout As LayeredLayout = New LayeredLayout
    Private MoSpringLayout As SpringLayout = New SpringLayout
    Private MoTreeLayout As TreeLayout = New TreeLayout
    Private MoAnnealLayout As AnnealLayout = New AnnealLayout
    Private MoOrthogonalLayout As OrthogonalLayout = New OrthogonalLayout
    Private MoCircularLayout As CircularLayout = New CircularLayout
    Private MoOrthogonalRouter As OrthogonalRouter = New OrthogonalRouter
    Private MoFlowLayout As FlowLayout = New FlowLayout
    Private MoFlowChartLayout As FlowchartLayout = New FlowchartLayout
    Private MoTopologicalLayout As TopologicalLayout = New TopologicalLayout

    Private MoAllLayoutEngines As List(Of Layout) = New List(Of Layout)()
#End Region
#End Region
#Region "Events"
    Public Event MMAfterArranged(ByVal TypeOfLayout As GeTypeOfLayout) 'event is raised after arranging a diagram
#End Region
#Region "Constructors"
    Public Sub New()

  'for identifying desired engine in list is used enum GeTypeOfLayout

  MoAllLayoutEngines.Add(MoGridLayout)

  MoAllLayoutEngines.Add(MoLayeredLayout)

  MoAllLayoutEngines.Add(MoSpringLayout)

  MoAllLayoutEngines.Add(MoTreeLayout)

  MoAllLayoutEngines.Add(MoAnnealLayout)

  MoAllLayoutEngines.Add(MoOrthogonalLayout)

  MoAllLayoutEngines.Add(MoCircularLayout)

  MoAllLayoutEngines.Add(MoOrthogonalRouter)

  MoAllLayoutEngines.Add(MoFlowLayout)

  MoAllLayoutEngines.Add(MoFlowChartLayout)

  MoAllLayoutEngines.Add(MoTopologicalLayout)
    End Sub
#End Region
#Region "Subs"
    'arranges given diagram with desired layout engine
    Public Sub Arrange(ByVal IoDiagram As MindFusion.Diagramming.Diagram, ByVal IeTypeOfLayout As GeTypeOfLayout)

  Try


'for identifying desired engine in list is used enum GeTypeOfLayout


Dim LoLayout As Layout = MoAllLayoutEngines(IeTypeOfLayout)


'preserving original links tyles of all links



'backuping original link styles of all links


Dim LoOriginalLinkStyles As Dictionary(Of ClsMMLinkNode, MindFusion.Diagramming.LinkStyle) = New Dictionary(Of ClsMMLinkNode, MindFusion.Diagramming.LinkStyle)


For Each LoLinkNode As ClsMMLinkNode In IoDiagram.Links


    LoOriginalLinkStyles.Add(LoLinkNode, LoLinkNode.Style)


Next


LoLayout.Arrange(IoDiagram)


'restoring original link styles of all links


For Each LoLinkNode As ClsMMLinkNode In IoDiagram.Links


    LoLinkNode.Style = LoOriginalLinkStyles(LoLinkNode)


    LoLinkNode.SnapToNodeBorder = True


    LoLinkNode.AutoRoute = True


    LoLinkNode.AllowMoveStart = True


    LoLinkNode.AllowMoveEnd = True


    LoLinkNode.Dynamic = True


Next



'rerouting all links


IoDiagram.RouteAllLinks()



RaiseEvent MMAfterArranged(IeTypeOfLayout)

  Catch ex As Exception


LogEventFromException(ex, , , )

  End Try
    End Sub

#End Region

End Class

 




Another question - error: after 2-3 times I use OrthogonalRouter layout (not in a row - also combined with another types), theres an error:



Error comes from  LoLayout.Arrange(IoDiagram).

Any ideas?

Thx.

...MUDO...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to use layout objects & preserve LinkS
Reply #3 - Apr 27th, 2010 at 5:14am
Print Post  
Could you email to support@mindfusion.eu a file with which we can reproduce the OrthogonalRouter error?

Your code looks ok, but it would be nice if you also restore the link's route set by the layout function, so that the link passes through the same control points.

For example LayeredLayout explicitly places control points for bends on the same Y where nodes are placed, and at such X that links are distributed uniformly. If you just reset the style after the layout, these routes will be lost.

So you might want to save ControlPoints before resetting the style, and try to approximate the same link shape with the new style. E.g. if resetting Style from Polyline to Bezier, you could set the same number of segments, assign old ControlPoints[x] to new ControlPoints[x * 3] to restore the segments end points, and set the positions of the intermediate Bezier points that control the curve to somewhere in between the end points.

Stoyan
  
Back to top
 
IP Logged
 
MUDO
Junior Member
**
Offline



Posts: 90
Joined: Nov 29th, 2008
Re: How to use layout objects & preserve LinkS
Reply #4 - Apr 27th, 2010 at 11:03am
Print Post  
Hi.

I sent it to u.

Another problem which u could examine is:

After selecting a node, it jumps couple of pixels away and immediately get back to its original position. Theres no events NodeModifying or NodeModified so its just "graphic" problem.

I have my own WinForms.Behaviors.BehaviorBase class assigned into diagram:

Me.fcDiagramView.CustomBehavior = New ClsCustomBehavior(Me.fcDiagramView)

Any ideas?


Thx.

...MUDO...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to use layout objects & preserve LinkS
Reply #5 - Apr 28th, 2010 at 2:02pm
Print Post  
Hi,

Which layout class are you running before OrthogonalRouter to get the error? We have tried running various layout combinations many times but could not reproduce that.

We have loaded the XML using the standard item types and behavior and can't see the node jumping a few pixels either. If you want our developer to debug the custom behavior and drawing code for you, please send us a fully working sample project that shows the problem - just those vb files won't do.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint