Events

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

Events

Postby elias » January 24th, 2006, 7:34 pm

In order to make my application run, I have added two new TGraphNotifyEvent events:
-OnObjectHook
-OnObjectUnhook
Here:
TSimpleGraph.MouseDown
Code: Select all
      // A Link is under cursor
      else
      begin
        if (Button = mbLeft) and not (ssDouble in Shift) and
           (MarkerAtCursor in [mtMoveEndPt, mtMoveStrartPt]) then
        begin
          if MarkerAtCursor = mtMoveEndPt then
            StartPoint := TGraphLink(ObjectAtCursor).FromNode.Center
          else
            StartPoint := TGraphLink(ObjectAtCursor).ToNode.Center;
          StopPoint := Pt;
          State := gsMoveLink;
          Linking := True;
          DoObjectHook(ObjectAtCursor);       //DoObjectHook

and here:
TSimpleGraph.MouseUp
Code: Select all
          begin
            Pt := ClientToGraph(X, Y);
            NodeAtCursor := TGraphNode(FindObjectAt(Pt.X, Pt.Y, TGraphNode));
            if NodeAtCursor <> nil then
            begin
              LinkAtCursor := TGraphLink(ObjectAtCursor);
              case MarkerAtCursor of
                mtMoveStrartPt:
                  if IsValidLink(LinkAtCursor, NodeAtCursor, LinkAtCursor.ToNode) and
                     CanLinkNodes(NodeAtCursor, LinkAtCursor.ToNode)
                  then
                    begin;
                    LinkAtCursor.FromNode := NodeAtCursor;
                    DoObjectUnhook(LinkAtCursor);      //DoObjectUnhook
                    end;
                mtMoveEndPt:
                  if IsValidLink(LinkAtCursor, LinkAtCursor.FromNode, NodeAtCursor) and
                     CanLinkNodes(LinkAtCursor.FromNode, NodeAtCursor)
                  then
                    begin;
                    LinkAtCursor.ToNode := NodeAtCursor;
                    DoObjectUnhook(LinkAtCursor);       //DoObjectUnhook


At moment just implemented for links, this events allows to run whatever when you are moving they.
elias
Senior Member
Senior Member
 
Posts: 90
Joined: November 8th, 2005, 12:09 pm
Location: Galicia, Spain

Postby kokkoras » January 25th, 2006, 9:12 am

I have also added an OnDropNode event, fired by the node upon which another node is dropped.
User avatar
kokkoras
Moderator
Moderator
 
Posts: 317
Joined: March 12th, 2005, 11:19 pm
Location: Thessaloniki, Greece

Postby elias » January 25th, 2006, 11:25 am

It sounds interesting; How did you do?
elias
Senior Member
Senior Member
 
Posts: 90
Joined: November 8th, 2005, 12:09 pm
Location: Galicia, Spain

Postby kokkoras » January 25th, 2006, 1:21 pm

elias wrote:It sounds interesting; How did you do?


It was a bit tough for me (I do not consider myshelf a Delphi expert)! I had to go into the details of a similar situation in the existing code and adopt approaches as needed. Here is a resume:

Define a new event type:
Code: Select all
TGraphNotifyEvent......  //existing code
TGraphDropObjectEvent = procedure(Graph: TSimpleGraph; GraphObject: TGraphObject; X, Y: Integer) of object;


Use this event type in the private section of TSinpleGraph:
Code: Select all
fOnObjectSelect........ //existing code
fOnObjectDrop: TGraphDropObjectEvent;


In the protected methods of TSimpleGraph add this:
Code: Select all
procedure DoObjectSelect...  //existing code
procedure DoObjectDrop(GraphObject: TGraphObject; X, Y: Integer); virtual;


with the following implementation
Code: Select all
procedure TSimpleGraph.DoObjectDrop(GraphObject: TGraphObject; X, Y: Integer);
begin
     if not IgnoreNotification and Assigned(fOnObjectDrop) then
       fOnObjectDrop(Self, GraphObject, X, Y);
end;



In the published methods of TSimpleGraph add this:
Code: Select all
property OnObjectSelect.... (existing code)
property OnObjectDrop: TGraphDropObjectEvent read fOnObjectDrop write fOnObjectDrop;


Modify procedure TSimpleGraph.MouseUp(). This is a key point. I have altered a case in the initial case statment:
Code: Select all
gsMoveResizeNode:   //this is the case I altered
if MarkerAtCursor = mtMove then begin
     Screen.Cursor := crHandFlat;
     //FOTIS: if _another_ object is there send it a proper OnDragDrop message
     //Note that for some personal reason I exclude Links
     if (SelectedObjectsCount=1) and (not SelectedObjects[0].IsLink) then
          DoObjectDrop(self.SelectedObjects[0], X, Y);       
end;



I am not sure if it's clear for you. Practicaly, when a single node is dropped the event is fired. You can write a proper event handler to do whatever. The event handler looks like:

Code: Select all
//fires when a _single_ GraphNode is dropped
procedure TMyForm.SimpleGraph1ObjectDrop(Graph: TSimpleGraph;
  GraphObject: TGraphObject; X, Y: Integer);
begin
   //add your code here
   //GraphObject is the object dropped
end;


I did all these to implement fusion of two nodes of the same type into one, by d'n'd. Well, it's more complex actually. It'a about semantic fusion.
Ex.: Dog+Mammal = Mammal
User avatar
kokkoras
Moderator
Moderator
 
Posts: 317
Joined: March 12th, 2005, 11:19 pm
Location: Thessaloniki, Greece

Postby elias » January 26th, 2006, 2:07 pm

:) Ok, so the event is fired when dropping a node, and say us the mouse coordinates; then you use these coordinates to know if the node was dropped over another node; isn't?
Why don't make a single TGraphNotifyEvent event that simply jumps when the node is dropped upon another and giving back the node as (GraphObject).
elias
Senior Member
Senior Member
 
Posts: 90
Joined: November 8th, 2005, 12:09 pm
Location: Galicia, Spain

Postby kokkoras » January 26th, 2006, 2:26 pm

elias wrote::) Ok, so the event is fired when dropping a node, and say us the mouse coordinates; then you use these coordinates to know if the node was dropped over another node; isn't?

yes it is

elias wrote:Why don't make a single TGraphNotifyEvent event that simply jumps when the node is dropped upon another and giving back the node as (GraphObject).


I can't recall why i did it like this :? . Your idea makes sense.
User avatar
kokkoras
Moderator
Moderator
 
Posts: 317
Joined: March 12th, 2005, 11:19 pm
Location: Thessaloniki, Greece


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 1 guest