[comp.windows.interviews] Solution for programming small graph editor

BOYLE@trees.dnet.ge.com (06/20/91)

>> From: fraus@forwiss.uni-passau.de (Uli Fraus)
>> Organization: University of Passau, Germany
>> Subject: Problems programming a small graph-editor

Hi Uli,
  I am by no means an InterViews wizard, however, I have a solution for your problem:

>> I am trying to programm to program a small IV application for drawing simple
>> graphs (nodes & edges). This application should come up with an empty
>> GraphicBlock plus some Buttons and a Panner. I used the graphics demo as an
>> example. So I have Tray with the GraphicBlock (containing an empty Graphic)
>> and a VBox (containing Buttons and Panner). This seem ok to me.
 
  Would you believe it-- I had the exact same problem that you are
having.  I, too, was working on a small graph editor and used the graphics
demo as a starting point.  

>> But I have to two nasty problems:
>> - First my window is coming up at minimal size (0x0) if the Graphic is empty.
>> (I found no possibility to use a predefined Canvas! like SetCanvas() ??? )

  First of all, I broke the demo into seperate files, and subclassed off of the
View class.  I added my stuff to this child class of View, called GraphMan.  
In the area of the code which introduced the graphics (GraphicsInitialize),
I stripped out all of the graphics (Line, Bspline, Polygon, etc.) which were the
items which gave the window its size.  Without these graphics, the window has 
nothing on which to base its size.  To correct this, I gave the GraphicBlock
a size in the constructor for the GraphMan class by saying:
       shape->Rect(400, 400); 

or you can alternately say:
       shape->height = 400;
       shape->width = 400;


>> - Second: If I click inside the GraphicBlock to set a new node, the node
>> appears about 2 inch left and up of the click-point. BUT if I click on a
>> node for moving (function from graphics) it work quite well. So I think
>> I have a problem with relative and absolute coordinates.

I had this problem too.  If I panned a few times to right, then up, for example,
and then added a node, the node would be introduced in the location that would
the offset by the amount I panned right, then up.  Yet when I moved the node,
the positioning was correct (just like you experienced). What I did to fix this was
in the constructor for GraphMan, I said:
   GetPerspective() -> Init(0, 0, 400, 400);
Notice that 400 was also the initial window size I used above.  This seemed to
reset the curx and cury of perspective.  

Then change View::Update()  by removing (or commenting out)
    UpdatePerspective(); 

My AddNode member function of GraphMan, looks like:

/****************************************/
void GraphMan::AddNode (Event& e) {
      FillRect *g;
      Perspective *p = this->GetPerspective();
      float dx, dy, mag = GetMagnification();
 
      g = new FillRect (-8 , -8 , 8 , 8 , &dfault);
      SlidingRect sr(output, canvas, (e.x-8)*mag, (e.y-8)*mag, (e.x+8)*mag, 
                     (e.y+8)*mag, e.x*mag, e.y*mag);
 
      Track(e, sr);
 
      dx = (e.x + p->curx)/mag;  
      dy = (e.y + p->cury)/mag; 
 
      pict->Append(g);
      g->Translate(dx, dy); 
      g->Touch();             
      damage->Incur(g);
      Update();
}
/****************************************/


>> If you have any solutions or hints for these problems please tell me.

Anyway, the changes that I mentioned above corrected the problems that I was having.
They should work for you, too.  If they don't, or if you would like to see my
simple (real simple!) graph editor, let me know and I will mail you the files
(sorry, we don't have anonymous ftp!)  

Dorothy Boyle
GE Aerospace
boyle@trees.dnet.ge.com

vlis@lurch.stanford.edu (John Vlissides) (06/22/91)

> I am trying to programm to program a small IV application for drawing simple
> graphs (nodes & edges). This application should come up with an empty
> GraphicBlock plus some Buttons and a Panner. I used the graphics demo as an
> example.

I'll take this opportunity to mention the structured graphics
tutorial, available from interviews.stanford.edu in
pub/papers/tut2.ps.Z, which may be of general help in this area.  It
should be more instructive than the graphics demo program.

Also available is a "hello, world"-for-InterViews-2.6 tutorial in
pub/papers/tut1.ps.Z.
--
John Vlissides
Computer Systems Lab
Stanford University
vlis@interviews.stanford.edu