Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

UILink.h

00001 // Copyright (C) 2001 Jean-Marc Valin
00002 
00003 #ifndef UILINK_H
00004 #define UILINK_H
00005 
00006 #include <list>
00007 #include "misc.h"
00008 #include <math.h>
00009 
00010 //#include <gnome.h>
00011 #include <libxml/tree.h>
00012 
00013 namespace FD {
00014 
00015 class UINode;
00016 class UINetwork;
00017 class UITerminal;
00018 //struct xmlNode;
00019 
00020 class Network;
00021 
00022 class GUILinkPoint {
00023 
00024  public:
00025 
00026   GUILinkPoint(double _x, double _y)
00027     : x(_x), y(_y) {}
00028 
00029   GUILinkPoint(const GUILinkPoint &cpy)
00030     : x(cpy.x), y(cpy.y) {}
00031 
00032   GUILinkPoint & operator= (const GUILinkPoint &eq) {
00033     
00034     x = eq.x; 
00035     y = eq.y;
00036     return *this;
00037   }
00038   
00039   void setxy(double _x, double _y) {
00040     x = _x;
00041     y = _y;
00042   }
00043 
00044   double dist (const GUILinkPoint &p) {
00045     return sqrt(sqr(p.x - x) + sqr(p.y -y));
00046   }
00047   
00048   bool between (const GUILinkPoint &p1, const GUILinkPoint &p2) {
00049      //Maximum offset allowed
00050      const float moff=2;
00051      //If x is between p1.x and p2.x, within a margin of moff
00052      if ( ! ((x-moff < p1.x && x+moff > p2.x) || (x+moff > p1.x && x-moff < p2.x)))
00053         return false;
00054      
00055      //If y is between p1.y and p2.y, within a margin of moff
00056      if ( ! ((y-moff < p1.y && y+moff > p2.y) || (y+moff > p1.y && y-moff < p2.y)))
00057         return false;
00058      
00059      //Just some geometry
00060      double dx, dy, rx, ry;
00061      dx=x-p1.x; dy=y-p1.y;
00062      rx=p2.x-p1.x; ry=p2.y-p1.y;
00063      //cerr << "(" << dx << ", " << dy << ") vs. (" << rx << ", " << ry << ")" << endl;
00064      //d*r
00065      double prod = dx*rx + dy*ry;
00066      //cerr << "prod = " << prod << endl;
00067      // 1/(norm)2 of R
00068      double normR_2=1/(.001+rx*rx+ry*ry);
00069      //cerr << "norm = " << 1/normR_2 << endl;
00070      //projection of d on r
00071      double px,py;
00072      px=rx*prod*normR_2; py=ry*prod*normR_2;
00073      
00074      //distance:
00075      double dist = sqrt(sqr(px-dx) + sqr(py-dy));
00076      //cerr << "dist = " << dist << endl << endl;
00077      return (dist < moff);
00078   }
00079 
00080 
00081   double x;
00082   double y;
00083 
00084 };
00085 
00086 
00087 class UILink {
00088 protected:
00089    double x1,y1,x2,y2;
00090    UITerminal *from;
00091    UITerminal *to;
00092    bool complete;
00093    UINetwork *net;
00094    std::list<GUILinkPoint*> m_points;
00095 
00096 public:
00097    //UILink(UITerminal *_from, UITerminal *_to, double _x1, double _y1, double _x2, double _y2);
00098    UILink(UITerminal *_from, UITerminal *_to, char *points_str=NULL);
00099 
00100    virtual ~UILink();
00101 
00102    void saveXML(xmlNode *root);
00103 
00104    void build(Network *net);
00105 
00106    void genCode(std::ostream &out);
00107 
00108    std::list<GUILinkPoint*> & get_link_points() {return m_points;}
00109  
00110    friend class UITerminal;
00111    
00112    UITerminal *getFromTerminal() {return from;}
00113    UITerminal *getToTerminal() {return to;}
00114 };
00115 
00116 }//namespace FD
00117 
00118 #endif

Generated on Wed Oct 5 14:28:56 2005 for FlowDesigner by  doxygen 1.4.4