mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 16:49:12 +02:00
cody: lvlgraph: MinimizeOverlappings
git-svn-id: trunk@40126 -
This commit is contained in:
parent
bc3fce7e5f
commit
6e818740cd
@ -269,6 +269,8 @@ type
|
|||||||
function OutEdgeCount: integer;
|
function OutEdgeCount: integer;
|
||||||
property OutEdges[Index: integer]: TLvlGraphEdge read GetOutEdges;
|
property OutEdges[Index: integer]: TLvlGraphEdge read GetOutEdges;
|
||||||
property Position: integer read FPosition write FPosition; // position in a level
|
property Position: integer read FPosition write FPosition; // position in a level
|
||||||
|
function Center: integer;
|
||||||
|
function PositionEnd: integer;// = Position+Max(InSize,OutSize)
|
||||||
property InSize: integer read FInSize;
|
property InSize: integer read FInSize;
|
||||||
property OutSize: integer read FOutSize;
|
property OutSize: integer read FOutSize;
|
||||||
property Level: TLvlGraphLevel read FLevel write SetLevel;
|
property Level: TLvlGraphLevel read FLevel write SetLevel;
|
||||||
@ -343,6 +345,7 @@ type
|
|||||||
procedure CreateTopologicalLevels; // create levels from edges
|
procedure CreateTopologicalLevels; // create levels from edges
|
||||||
procedure MarkBackEdges;
|
procedure MarkBackEdges;
|
||||||
procedure MinimizeCrossings; // set all Node.Position to minimize crossings
|
procedure MinimizeCrossings; // set all Node.Position to minimize crossings
|
||||||
|
procedure MinimizeOverlappings(Gap: integer = 1; aLevel: integer = -1); // set all Node.Position to minimize overlappings
|
||||||
procedure WriteDebugReport(Msg: string);
|
procedure WriteDebugReport(Msg: string);
|
||||||
procedure ConsistencyCheck(WithBackEdge: boolean);
|
procedure ConsistencyCheck(WithBackEdge: boolean);
|
||||||
end;
|
end;
|
||||||
@ -416,6 +419,8 @@ procedure RingSector(Canvas: TFPCustomCanvas; x1, y1, x2, y2: integer;
|
|||||||
procedure RingSector(Canvas: TFPCustomCanvas; x1, y1, x2, y2,
|
procedure RingSector(Canvas: TFPCustomCanvas; x1, y1, x2, y2,
|
||||||
InnerSize, StartAngle, EndAngle: single); overload;
|
InnerSize, StartAngle, EndAngle: single); overload;
|
||||||
|
|
||||||
|
function CompareLGNodesByCenterPos(Node1, Node2: Pointer): integer;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
procedure FreeTVNodeData(TV: TCustomTreeView);
|
procedure FreeTVNodeData(TV: TCustomTreeView);
|
||||||
@ -481,6 +486,23 @@ begin
|
|||||||
SetLength(Points,0);
|
SetLength(Points,0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function CompareLGNodesByCenterPos(Node1, Node2: Pointer): integer;
|
||||||
|
var
|
||||||
|
LNode1: TLvlGraphNode absolute Node1;
|
||||||
|
LNode2: TLvlGraphNode absolute Node2;
|
||||||
|
p1: Integer;
|
||||||
|
p2: Integer;
|
||||||
|
begin
|
||||||
|
p1:=LNode1.Center;
|
||||||
|
p2:=LNode2.Center;
|
||||||
|
if p1<p2 then
|
||||||
|
Result:=1
|
||||||
|
else if p1>p2 then
|
||||||
|
Result:=-1
|
||||||
|
else
|
||||||
|
Result:=0;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TLvlGraphLevel }
|
{ TLvlGraphLevel }
|
||||||
|
|
||||||
function TLvlGraphLevel.GetNodes(Index: integer): TLvlGraphNode;
|
function TLvlGraphLevel.GetNodes(Index: integer): TLvlGraphNode;
|
||||||
@ -861,8 +883,45 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLvlGraph.MinimizeCrossings;
|
procedure TLvlGraph.MinimizeCrossings;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
|
for i:=0 to LevelCount-1 do begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TLvlGraph.MinimizeOverlappings(Gap: integer; aLevel: integer);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
Tree: TAvgLvlTree;
|
||||||
|
Level: TLvlGraphLevel;
|
||||||
|
AVLNode: TAvgLvlTreeNode;
|
||||||
|
Node: TLvlGraphNode;
|
||||||
|
Last: TLvlGraphNode;
|
||||||
|
begin
|
||||||
|
if aLevel<0 then begin
|
||||||
|
for i:=0 to LevelCount-1 do
|
||||||
|
MinimizeOverlappings(i);
|
||||||
|
end else begin
|
||||||
|
Level:=Levels[aLevel];
|
||||||
|
Tree:=TAvgLvlTree.Create(@CompareLGNodesByCenterPos);
|
||||||
|
try
|
||||||
|
for i:=0 to Level.Count-1 do
|
||||||
|
Tree.Add(Level[i]);
|
||||||
|
Last:=nil;
|
||||||
|
AVLNode:=Tree.FindLowest;
|
||||||
|
while AVLNode<>nil do begin
|
||||||
|
Node:=TLvlGraphNode(AVLNode.Data);
|
||||||
|
Last:=Node;
|
||||||
|
if (Last<>nil) then
|
||||||
|
Node.Position:=Max(Node.Position,Last.PositionEnd+Gap);
|
||||||
|
AVLNode:=Tree.FindSuccessor(AVLNode);
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
Tree.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLvlGraph.WriteDebugReport(Msg: string);
|
procedure TLvlGraph.WriteDebugReport(Msg: string);
|
||||||
@ -1106,6 +1165,16 @@ begin
|
|||||||
Result:=FOutEdges.Count;
|
Result:=FOutEdges.Count;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TLvlGraphNode.Center: integer;
|
||||||
|
begin
|
||||||
|
Result:=Position+(Max(InSize,OutSize) div 2);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TLvlGraphNode.PositionEnd: integer;
|
||||||
|
begin
|
||||||
|
Result:=Position+Max(InSize,OutSize);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TCodyTreeView }
|
{ TCodyTreeView }
|
||||||
|
|
||||||
procedure TCodyTreeView.FreeNodeData;
|
procedure TCodyTreeView.FreeNodeData;
|
||||||
|
Loading…
Reference in New Issue
Block a user