TSimpleGraph - Help!

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

TSimpleGraph - Help!

Postby njr » March 29th, 2008, 12:26 am

Hello,

I have 2 nodes, and wanted to make 2 links between them... A->B and B->A. For the lines are not one on top of another, as do I draw them as a semi-circle?

Thanks!
njr
Member
Member
 
Posts: 1
Joined: March 29th, 2008, 12:23 am

Postby Kambiz » March 29th, 2008, 2:10 am

Could you please explain what you need using an image?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby Dimitris » March 30th, 2008, 2:57 pm

I think this is what you need:

Code: Select all
function TGraphLink.CheckExistingArc(FromNode, ToNode: TGraphNode): TGraphLink;
var I: Integer;
begin
  Result:=nil;

  if not Assigned(FromNode) or not Assigned(ToNode) then exit;

  for I:=0 to ToNode.LinkInputList.count-1 do begin
      if (ToNode.LinkInputs[I].Source=FromNode)
       then Result:=TGraphLink(ToNode.LinkInputs[I]);
  end;

end;


procedure TGraphLink.MouseUp(Button: TMouseButton; Shift: TShiftState; const Pt: TPoint);
var
  ExistingArc: TGraphLink;
begin
  if not Dragging or (Button <> mbRight) or (ChangeMode <> lcmMovePoint) then
  begin

    inherited MouseUp(Button, Shift, Pt);

    if (ChangeMode = lcmMovePoint) then begin

       ExistingArc := CheckExistingArc(TGraphNode(Self.Source),TGraphNode(HookingObject));
       if ExistingArc = nil
       then begin
          ExistingArc := CheckExistingArc(TGraphNode(HookingObject),TGraphNode(Self.Source));
          if ExistingArc<>nil then begin
             //Reverse Direction here
             if (ExistingArc.Kind=akReverseDirected) then begin
                ExistingArc.Weight:=ExistingArc.Weight+1;
             end
             else if (ExistingArc.Weight=1) and (ExistingArc.Kind=akDirected) then begin
                ExistingArc.Kind:=akBiDirected;
             end
             else if (ExistingArc.Weight=1) and (ExistingArc.Kind=akBiDirected) then begin
                ExistingArc.Kind:=akReverseDirected;
             end
             else if (ExistingArc.Kind=akDirected) then begin
                ExistingArc.Weight:=ExistingArc.Weight-1;
             end;
             //------------------------
          end;
       end
       else begin
          //Forward Direction here
          if (ExistingArc.Kind=akDirected) then begin
              ExistingArc.Weight:=ExistingArc.Weight+1;
          end
          else if (ExistingArc.Weight=1) and (ExistingArc.Kind=akReverseDirected) then begin
                  ExistingArc.Kind:=akBidirected;
          end
          else if (ExistingArc.Weight=1) and (ExistingArc.Kind=akBiDirected) then begin
                 ExistingArc.Kind:=akDirected;
          end
          else if (ExistingArc.Kind=akReverseDirected) then begin
                ExistingArc.Weight:=ExistingArc.Weight-1;
          end;
          //------------------------
       end;


        if AcceptingHook and not Assigned(ExistingArc)
        then begin
           Hook(MovingPoint, HookingObject);
           fPrevHookingObject := Target;
           fPrevSourceObject := Source;
           fHooked := true;
        end
        else begin
          if not fHooked then Delete
            else if Target<>fPrevHookingObject then begin
                Hook(MovingPoint, fPrevHookingObject);
            end
            else if Source<>fPrevSourceObject then begin
                Hook(fMovingPoint, fPrevSourceObject);
            end;
        end;


    end;

    fMovingPoint := -1;
    fHookingObject := nil;
    fAcceptingHook := False;
    ChangeMode := lcmNone;
  end;

end;
Dimitris
Active Member
Active Member
 
Posts: 5
Joined: December 28th, 2007, 8:31 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 0 guests

cron