/* * * Copyright (c) 1995 * Knowledge Science Institute, University of Calgary * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. The Knowledge Science Institute makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * */ #ifndef GRAPHIC_H #define GRAPHIC_H #ifndef MPLATFORM_H #include #endif #ifndef MVERSION_H #include #endif /* GRAPHIC_CLASS is used to contain the compile declaration attributes of classes and functions: VAL FOR compiled-in _export DLL compilation _import DLL use */ #ifndef GRAPHIC_CLASS #define GRAPHIC_CLASS #endif #ifndef MOBJECT_H #include #endif #ifndef MDEBUG_H #include #endif #ifndef __CSTRING_H #include #endif #ifndef LIST_H #include #endif #ifndef VECTOR_H #include #endif #ifndef MREF2_H #include #endif #ifndef MCOMMAND_H #include #endif #ifndef MOBSERVER_H #include #endif #ifndef MVERSION_H #include #endif #define CM_MAXNAME 128 #define CMD_DELETE 100 #define CMD_RESIZE 101 #define CMD_MOVE 102 #define CMD_CHANGELABEL 103 #define CMD_CHANGESHAPE 104 #define CMD_NEWNODE 105 #define CMD_NEWARC 106 #define CMD_MOVETO 107 #define CMD_SETCONNECTION 108 #define CMD_AUTOSIZE 109 #define CMD_FIRSTSHAPE 500 class GRAPHIC_CLASS GraphicContainer; template class GRAPHIC_CLASS GraphicsLibrary : public map,less > { public: T* makeCopy(const string& x, GraphicContainer* parent=NULL) { iterator i; T* ret = NULL; if ((i=find(x))!=end()) ret = ((*i).second)->clone(); else if ((i=find("default"))!=end()) ret = ((*i).second)->clone(); if (ret) ret->setParent(parent); return ret;} pair insert(const string& x, T& t) {return map,less >::insert(pair >(x,t));} }; class GRAPHIC_CLASS Graphic; class GRAPHIC_CLASS SensitiveGraphic; class GRAPHIC_CLASS Maplet; class GRAPHIC_CLASS GraphicContainer; class GRAPHIC_CLASS TextDrawing; typedef unsigned long ID_type; // class GRAPHIC_CLASS Graphic #ifndef NDEBUG : virtual public ObjectCounter #endif { MDEBUG_DECL_VIRTUAL(Graphic) public: DECL_EXCEPT_CLASS(,Exception,ErrorMsgException,"CMap exception"); Graphic(GraphicContainer* parent=NULL); //******* NOTE: The following operation MUST be overridden by all subclasses ********* Graphic(const Graphic& g, GraphicContainer* parent=NULL /*g's parent*/); //******* NOTE: The following operation MUST be overridden by all subclasses (change return type!) ********* virtual Graphic* clone() const =NULL; virtual ~Graphic(); virtual Graphic& operator=(const Graphic& c) {resetParent(c.Parent); return *this;} ID_type id() const {return ID;}; void setID(ID_type id) {ID = id;} //use VERY cautiously virtual int operator<(const Graphic &g) const; virtual int operator==(const Graphic &g) const; virtual ostream& printOn(ostream& o) const; virtual istream& readFrom(istream& i, Version* version=NULL); GraphicContainer* getParent() const {return Parent;} int hasParent() const {return Parent!=NULL;} void setParent(GraphicContainer* parent); //allocates a new ID void resetParent(GraphicContainer* parent); //assumes object is being restored and has an ID already virtual unsigned char getLayer() const = 0; virtual void setLayer(unsigned char layer) = 0; virtual int paint(DEVICE,RECTANGLE* r=0) = 0; /* future use virtual int isVisible() const = 0; virtual void setVisible(int) = 0; virtual int isSelected() const = 0; virtual void setSelected(int) = 0; virtual int isShadowed() const = 0; virtual void setShadowed(int) = 0; virtual int isHighlighted() const = 0; virtual void setHighlighted(int) = 0; */ virtual RECTANGLE getRect() const = 0; virtual void setRect(RECTANGLE&) = 0; virtual RECTANGLE getBoundingRect() const; //returns getRect() expanded by a few pixels virtual void moveTo(POINT&); virtual int contains(POINT&); virtual int intersects(RECTANGLE&); virtual void queueForPaint(void); private: ID_type ID; GraphicContainer* Parent; }; ostream& operator<<(ostream& o, const Graphic& g) {return g.printOn(o);} istream& operator>>(istream& i, Graphic& g) {return g.readFrom(i);} inline void destroy(Graphic**) {} #define GraphicContainerClass 3641 class GRAPHIC_CLASS GraphicContainer :public CommandReceiverContainer #ifndef NDEBUG ,public virtual ObjectCounter #endif { MDEBUG_DECL_VIRTUAL(GraphicContainer) public: enum {destruct=1}; GraphicContainer(); GraphicContainer(const GraphicContainer& c); virtual ~GraphicContainer(); virtual GraphicContainer& operator=(const GraphicContainer& c) {Graphics=c.Graphics; NextID=c.NextID; return *this;} virtual ostream& printOn(ostream& o) const; virtual istream& readFrom(istream& i, Version* version=NULL); void flush(); ID_type registerGraphic(Graphic*); void unregisterGraphic(Graphic*); virtual int popToTop(Graphic*); //a non-virtual version of registerGraphic() ID_type primitiveRegisterGraphic(Graphic*); virtual void sort() {Graphics.sort();} virtual Graphic* operator[](unsigned long index); virtual int paint(DEVICE,RECTANGLE*); virtual void queueForPaint(RECTANGLE&)=0; int destructing() {return ContainerFlags&destruct;} SensitiveGraphic* getHit(POINT&); virtual void setCaptureGraphic(SensitiveGraphic* c) {CaptureGraphic = c;} virtual int handleCommand(Command* c); int executeOnBehalf(Command* c); int undoOnBehalf(Command* c); virtual void notifyChanged(ID_type id); protected: unsigned long ContainerFlags; SensitiveGraphic* CaptureGraphic; typedef list GraphicList; GraphicList Graphics; ID_type NextID; }; #define GraphicObjectLocatorClass 7530 class GRAPHIC_CLASS GraphicObjectLocator : public ObjectLocator { MDEBUG_DECL(GraphicObjectLocator) public: GraphicObjectLocator(Graphic* g); GraphicObjectLocator(const GraphicObjectLocator& g); virtual ~GraphicObjectLocator(); virtual GraphicObjectLocator* clone() const {return new GraphicObjectLocator(*this);} virtual GraphicObjectLocator& operator=(const GraphicObjectLocator& g); virtual CommandReceiver* getObject() const; virtual CommandReceiverContainer* getSuper() const; virtual void setRoot(GraphicContainer* r) {Root = r;} protected: vector* Path; GraphicContainer* Root; }; #define SensitiveGraphicContainerClass 3642 class GRAPHIC_CLASS VisualGraphic : public Graphic { MDEBUG_DECL_VIRTUAL(VisualGraphic) public: typedef enum {W=0x1,N=0x2,E=0x4,S=0x8,NW=N|W,NE=N|E,SE=S|E,SW=S|W} CompassPoints; VisualGraphic(GraphicContainer* parent=NULL); VisualGraphic(const VisualGraphic& g, GraphicContainer* parent=NULL /*g's parent*/); virtual ~VisualGraphic(); override ostream& printOn(ostream& o) const; override istream& readFrom(istream& i, Version* version=NULL); virtual VisualGraphic& operator=(const VisualGraphic& c) {Graphic::operator=(c); Layer=c.Layer; return *this;} virtual void copyFeatures(VisualGraphic& g) {Layer=g.Layer;} //copy features, but not the character of the graphic virtual VisualGraphic* clone() const =0; override unsigned char getLayer() const {return Layer;} override void setLayer(unsigned char layer) {Layer=layer;} virtual POINT getEdge(CompassPoints)=0; private: unsigned char Layer; }; #define ArrowHeadClass 7392 //ArrowHead is designed to be a flyweight ((almost) stateless) class, so an app //creates single copies of flyweight Arrowheads (and subclasses) and passes pointers //to the user objects; user objects should never destroy the Arrowheads. class ArrowHead //draws a basic 6 pixel long, 40deg wide arrowhead { MDEBUG_DECL(ArrowHead) public: ArrowHead(COLOR fill=COLOR_BLACK,COLOR border=COLOR_BLACK) {MCONSTRUCTOR_IMP_CODE(ArrowHead); FillColor=fill; BorderColor=border;} ~ArrowHead() {MDESTRUCTOR_IMP_CODE(ArrowHead);} virtual int draw(DEVICE device, POINT& head, POINT& tail); COLOR getFillColor() const {return FillColor;} COLOR getBorderColor() const {return BorderColor;} void setFillColor(COLOR c) {FillColor = c;} void setBorderColor(COLOR c) {BorderColor = c;} protected: float getTheta(POINT&head, POINT& tail); POINT translatePoint(float theta, POINT& head, unsigned int p_radius, float p_theta); COLOR FillColor, BorderColor; }; #define LineClass 3398 class GRAPHIC_CLASS Line : public VisualGraphic { MDEBUG_DECL(Line) public: typedef pair POINTPAIR; Line(GraphicContainer* parent=NULL, POINTPAIR* endPoints=NULL, COLOR=COLOR_BLACK, ArrowHead* start=NULL, ArrowHead* end=NULL); Line(const Line& g, GraphicContainer* parent=NULL /*g's parent*/); virtual ~Line(); virtual Line& operator=(const Line& c); virtual Line* clone() const {return new Line(*this);} virtual void copyFeatures(VisualGraphic& g); //copy features, but not the character of the graphic virtual int paint(DEVICE,RECTANGLE* r=0); //sets up colors,etc then calls draw() virtual int draw(DEVICE); //draw the actual shape virtual POINTPAIR getEndPoints() const {return EndPoints;} virtual POINTPAIR setEndPoints(POINTPAIR& eps); virtual POINTPAIR setStartPoint(POINT p) {return setEndPoints(POINTPAIR(p,EndPoints.second));} virtual POINTPAIR setEndPoint(POINT p) {return setEndPoints(POINTPAIR(EndPoints.first,p));} virtual void setStartHead(ArrowHead* a) {ArrowHeads.first=a;} virtual void setEndHead(ArrowHead* a) {ArrowHeads.second=a;} override RECTANGLE getRect() const; override void setRect(RECTANGLE& r); COLOR getColor() const {return Color;} void setColor(COLOR c) {Color = c; queueForPaint();} override int contains(POINT&); virtual POINT getEdge(CompassPoints); protected: POINTPAIR EndPoints; COLOR Color; pair ArrowHeads; }; inline void destroy(Line**) {} POINT defaultPoint={50,50}; #define ConnectorClass 3398 class GRAPHIC_CLASS Connector : public VisualGraphic { MDEBUG_DECL(Connector) public: Connector(GraphicContainer* parent=NULL, POINT& handle=defaultPoint, unsigned short nEndPoints=2); Connector(const Connector& g, GraphicContainer* parent=NULL /*g's parent*/); virtual ~Connector(); virtual Connector& operator=(const Connector& c); virtual Connector* clone() const {return new Connector(*this);} virtual void copyFeatures(VisualGraphic& g) {VisualGraphic::copyFeatures(g);} //copy features, but not the character of the graphic virtual int paint(DEVICE,RECTANGLE* r=0); //sets up colors,etc then calls draw() virtual int draw(DEVICE); //draw the actual shape override RECTANGLE getRect() const; override void setRect(RECTANGLE& r) {} //doesn't make much sense! override int contains(POINT&); virtual POINT getHandle() {return Handle;} virtual void setHandle(POINT handle); virtual void setEndPoint(unsigned short n, POINT& pt, const char* lineType=NULL); virtual POINT operator[](unsigned short n); virtual Line* getLine(unsigned short n); virtual unsigned short getArity() {return TerminalCount;} override void moveTo(POINT& p) {setHandle(p);} virtual POINT getEdge(CompassPoints); protected: vector Terminals; POINT Handle; unsigned short TerminalCount; void flush(); }; #define ShapeClass 7310 class GRAPHIC_CLASS Shape : public VisualGraphic { MDEBUG_DECL(Shape) public: typedef enum { SH_AUTOSIZE =0x1, SH_SELECTED =0x2, SH_SHADOWED =0x4, SH_HTIC =0x8, SH_VTIC =0x10, SH_HBAR =0x20, SH_VBAR =0x40, SH_HIGHLIGHT1 =0x80, SH_HIGHLIGHT2 =0x100, SH_HIGHLIGHT3 =0x200, SH_HIGHLIGHT4 =0x400, SH_RECOMPUTE =0x80000000 //doesn't persist beyond one recomputation } ShapeFlags_type; Shape(GraphicContainer* parent=NULL, RECTANGLE* r=NULL, char* label=NULL, COLOR fill=COLOR_WHITE, COLOR border=COLOR_BLACK, COLOR text=COLOR_BLACK); Shape(const Shape& g, GraphicContainer* parent=NULL /*g's parent*/); virtual ~Shape(); virtual Shape& operator=(const Shape& c); virtual Shape* clone() const {return new Shape(*this);} virtual void copyFeatures(VisualGraphic& g); virtual Shape* copy(Shape& s); virtual int paint(DEVICE,RECTANGLE* r=0); //sets up colors,etc then calls draw() virtual int draw(DEVICE); //draw the actual shape virtual RECTANGLE getInnerRect() const; virtual RECTANGLE setInnerRectSize(long width, long height); override RECTANGLE getRect() const {return R;} override void setRect(RECTANGLE& r); virtual const char* getText() const; virtual void setText(const char*); COLOR getFillColor() const {return FillColor;} COLOR getBorderColor() const {return BorderColor;} COLOR getTextColor() const {return TextColor;} void setFillColor(COLOR c) {FillColor = c; queueForPaint();} void setBorderColor(COLOR c) {BorderColor = c; queueForPaint();} void setTextColor(COLOR c) {TextColor = c; queueForPaint();} override RECTANGLE getBoundingRect() const; virtual POINT getEdge(CompassPoints); unsigned long getFlags() const {return ShapeFlags;} unsigned long setFlags(unsigned long f) {unsigned long ret=ShapeFlags; ShapeFlags|=f; return ret;} unsigned long clearFlags(unsigned long f) {unsigned long ret=ShapeFlags; ShapeFlags&=~f; return ret;} protected: RECTANGLE R; COLOR FillColor, BorderColor, TextColor; TextDrawing* Text; unsigned long ShapeFlags; }; #define RectangleShapeClass 7596 class GRAPHIC_CLASS RectangleShape : public Shape { MDEBUG_DECL(RectangleShape) public: RectangleShape(GraphicContainer* parent=NULL, RECTANGLE* r=NULL, char* label=NULL, COLOR fill=COLOR_WHITE, COLOR border=COLOR_BLACK, COLOR text=COLOR_BLACK) : Shape(parent,r,label,fill,border,text) {MCONSTRUCTOR_IMP_CODE(RectangleShape)}; RectangleShape(const Shape& g, GraphicContainer* parent=NULL /*g's parent*/) : Shape(g,parent) {MCONSTRUCTOR_IMP_CODE(RectangleShape)}; virtual ~RectangleShape() {MDESTRUCTOR_IMP_CODE(RectangleShape)}; override RectangleShape* clone() const {return new RectangleShape(*this);} virtual int draw(DEVICE); //draw the actual shape virtual RECTANGLE getInnerRect() const; virtual RECTANGLE setInnerRectSize(long width, long height); //returns all coordinates of new innerRect }; #define EllipseShapeClass 6978 class GRAPHIC_CLASS EllipseShape : public Shape { MDEBUG_DECL(EllipseShape) public: EllipseShape(GraphicContainer* parent=NULL, RECTANGLE* r=NULL, char* label=NULL, COLOR fill=COLOR_WHITE, COLOR border=COLOR_BLACK, COLOR text=COLOR_BLACK) : Shape(parent,r,label,fill,border,text) {MCONSTRUCTOR_IMP_CODE(EllipseShape)}; EllipseShape(const Shape& g, GraphicContainer* parent=NULL /*g's parent*/) : Shape(g,parent) {MCONSTRUCTOR_IMP_CODE(EllipseShape)}; virtual ~EllipseShape() {MDESTRUCTOR_IMP_CODE(EllipseShape)}; override EllipseShape* clone() const {return new EllipseShape(*this);} virtual int draw(DEVICE); //draw the actual shape virtual RECTANGLE getInnerRect() const; virtual RECTANGLE setInnerRectSize(long width, long height); //returns all coordinates of new innerRect virtual POINT getEdge(CompassPoints); override int contains(POINT& p) {return MIsPointInEllipse(p,getRect());} }; #define RoundRectShapeClass 3083 class GRAPHIC_CLASS RoundRectShape : public Shape { MDEBUG_DECL(RoundRectShape) public: RoundRectShape(GraphicContainer* parent=NULL, RECTANGLE* r=NULL, char* label=NULL, COLOR fill=COLOR_WHITE, COLOR border=COLOR_BLACK, COLOR text=COLOR_BLACK) : Shape(parent,r,label,fill,border,text) {MCONSTRUCTOR_IMP_CODE(RoundRectShape)}; RoundRectShape(const Shape& g, GraphicContainer* parent=NULL /*g's parent*/) : Shape(g,parent) {MCONSTRUCTOR_IMP_CODE(RoundRectShape)}; virtual ~RoundRectShape() {MDESTRUCTOR_IMP_CODE(RoundRectShape)}; override RoundRectShape* clone() const {return new RoundRectShape(*this);} virtual int draw(DEVICE); //draw the actual shape virtual RECTANGLE getInnerRect() const; virtual RECTANGLE setInnerRectSize(long width, long height); //returns all coordinates of new innerRect virtual POINT getEdge(CompassPoints); override int contains(POINT&); }; typedef int ERRORCODE; //BehaviouralGraphic is a container for any VisualGraphics it might control. //It also is lazy about creating a VisualGraphic -- its only created when it's first //requested by getVisual(). For example, paint() calls getVisual() to assure itself //there is something to paint. class GRAPHIC_CLASS BehaviouralGraphic : public Graphic, public GraphicContainer { MDEBUG_DECL_VIRTUAL(BehaviouralGraphic) public: BehaviouralGraphic(GraphicContainer* parent, char* visualClassName="default"); BehaviouralGraphic(const BehaviouralGraphic& g, GraphicContainer* parent=NULL /*g's parent*/); virtual ~BehaviouralGraphic(); virtual BehaviouralGraphic& operator=(const BehaviouralGraphic& c) {Graphic::operator=(c); GraphicContainer::operator=(c); Visual=c.Visual; VisualClassName=strdup(c.VisualClassName); return *this;} override BehaviouralGraphic* clone() const = 0; virtual ostream& printOn(ostream& o) const; virtual istream& readFrom(istream& i, Version* version=NULL); //GraphicContainer objligations override void unregisterGraphic(Graphic* g); override ID_type registerGraphic(Graphic* g) {return GraphicContainer::registerGraphic(g);} override int paint(DEVICE d,RECTANGLE* r=0); virtual VisualGraphic* getVisual()=0; virtual ERRORCODE setVisual(const char* visualClassName)=0; //return 0 on success override unsigned char getLayer() const {return getVisual()->getLayer();} override void setLayer(unsigned char layer) {getVisual()->setLayer(layer);} override RECTANGLE getRect() const {return getVisual()->getRect();} override void setRect(RECTANGLE& r) {getVisual()->setRect(r);} override RECTANGLE getBoundingRect() const {return getVisual()->getBoundingRect();} override void moveTo(POINT& p) {getVisual()->moveTo(p);} override void queueForPaint(RECTANGLE& r); override int contains(POINT& p) {return getVisual()->contains(p);} virtual int dispatch(Command*); virtual int execute(Command*)=0; virtual int undo(Command*)=0; protected: VisualGraphic* Visual; char* VisualClassName; }; #define SensitiveGraphicClass 7620 class GRAPHIC_CLASS SensitiveGraphic : virtual public BehaviouralGraphic, public CommandReceiver { MDEBUG_DECL_VIRTUAL(SensitiveGraphic) public: SensitiveGraphic(GraphicContainer* parent=NULL, char* visualClassName="default"); SensitiveGraphic(const SensitiveGraphic& g, GraphicContainer* parent=NULL /*g's parent*/); virtual ~SensitiveGraphic(); virtual SensitiveGraphic& operator=(const SensitiveGraphic& c) {BehaviouralGraphic::operator=(c); return *this;} GraphicContainer* getParent() const; void trackToBegin(POINT &p); void trackTo(POINT &p); void trackToEnd(POINT &p); virtual void showMenu(POINT *p=NULL); virtual CURSOR getCusor(POINT &p); virtual void doLButtonDown(unsigned int modKeys, POINT& p); virtual void doLButtonUp(unsigned int modKeys, POINT& p); virtual void doLButtonDblClk(unsigned int modKeys, POINT& p); virtual void doRButtonDown(unsigned int modKeys, POINT& p); virtual void doRButtonUp(unsigned int modKeys, POINT& p); virtual void doRButtonDblClk(unsigned int modKeys, POINT& p); virtual void doMouseMove(unsigned int modKeys, POINT& p); virtual int execute(Command*); virtual int undo(Command*); //interface operations: these generate command which are dispatched through //the parent so that undo, groupware, etc can be implemented virtual Command* getResizeCommand(RECTANGLE *r=NULL); virtual Command* getDeleteCommand(); virtual Command* getSetVisualCommand(const char* visualClassName); virtual Command* getMoveToCommand(const POINT& p); protected: virtual void resize(RECTANGLE *r=NULL); virtual MENU doMakeMenu(); virtual Command* doGenerateCommand(WORD command, POINT *p, char* cmdName); }; #define RelationableGraphicClass 2693 class GRAPHIC_CLASS RelationableGraphic : virtual public BehaviouralGraphic, public Subject { MDEBUG_DECL_VIRTUAL(RelationableGraphic) public: RelationableGraphic(GraphicContainer* parent=NULL, char* visualClassName="default"); RelationableGraphic(const RelationableGraphic& g, GraphicContainer* parent=NULL /*g's parent*/); virtual ~RelationableGraphic(); virtual POINT getAttachmentPoint(RECTANGLE&); virtual POINT getAttachmentPoint(POINT&); override void setRect(RECTANGLE& r) {BehaviouralGraphic::setRect(r); notify();} override void moveTo(POINT& p) {BehaviouralGraphic::moveTo(p); notify();} override CompositeCommand* getPartialDeleteCommand(); //needs to build a composite delete command to unhook all references override void notifyChanged(ID_type); }; inline void destroy(RelationableGraphic**) {}; #define MapletClass 2694 class GRAPHIC_CLASS Maplet : virtual public BehaviouralGraphic, public Observer { MDEBUG_DECL(Maplet) public: Maplet(GraphicContainer* parent=NULL, char* visualClassName="default", POINT& handle=defaultPoint, unsigned short nEndPoints=2); Maplet(const Maplet& g, GraphicContainer* parent=NULL /*g's parent*/); virtual ~Maplet(); virtual Maplet& operator=(const Maplet& c); override Maplet* clone() const {return new Maplet(*this);} override ostream& printOn(ostream& o) const; override istream& readFrom(istream& i, Version* version=NULL); override VisualGraphic* getVisual() {return getConnector();} override ERRORCODE setVisual(const char* visualClassName); //return 0 on success virtual Connector* getConnector(); virtual int setConnection(unsigned short index, RelationableGraphic* g); virtual RelationableGraphic* operator[](unsigned short index); virtual unsigned short getArity() {return getConnector()->getArity();} virtual void moveTo(POINT& p); //for the observer pattern virtual int update(Subject*); virtual int subjectDestroyed(const Subject*); void park(unsigned int index); override int execute(Command*); override int undo(Command*); virtual Command* getSetConnectionCommand(unsigned int index, ID_type relID); protected: void flush(); vector Terminals; unsigned short TerminalCount; POINT Handle; }; #define SRGraphicClass 4461 class GRAPHIC_CLASS SRGraphic : public SensitiveGraphic, public RelationableGraphic { MDEBUG_DECL_VIRTUAL(SRGraphic) public: SRGraphic(GraphicContainer* parent=NULL, char* visualClassName="default"); SRGraphic(const SRGraphic& g, GraphicContainer* parent=NULL /*g's parent*/); virtual ~SRGraphic(); override Command* getDeleteCommand(); override void resize(RECTANGLE *r=NULL) {SensitiveGraphic::resize(r); notify();} override void notifyChanged(ID_type); }; #define SMapletClass 1796 class GRAPHIC_CLASS SMaplet : public SensitiveGraphic, public Maplet { MDEBUG_DECL(SMaplet) public: SMaplet(GraphicContainer* parent=NULL, char* visualClassName="default", POINT& handle=defaultPoint, unsigned short nEndPoints=2); SMaplet(const SMaplet& g, GraphicContainer* parent=NULL); virtual ~SMaplet(); override SMaplet* clone() const {return new SMaplet(*this);} //override this mouse events because we don't want to move like a block object void trackToBegin(POINT &p); override void doLButtonDown(unsigned int modKeys, POINT& p); override int execute(Command* c) {return (c->id()==CMD_SETCONNECTION)? Maplet::execute(c): SensitiveGraphic::execute(c);} override int undo(Command* c) {return (c->id()==CMD_SETCONNECTION)? Maplet::undo(c): SensitiveGraphic::undo(c);} protected: virtual MENU doMakeMenu(); virtual Command* doGenerateCommand(WORD command, POINT *p, char* cmdName); }; #define NodeClass 5540 class GRAPHIC_CLASS Node : public SRGraphic { MDEBUG_DECL(Node) public: Node(GraphicContainer* parent=NULL, char* visualClassName="default", const char* label=NULL, const RECTANGLE* rect=NULL); Node(const Node& g, GraphicContainer* parent=NULL /*g's parent*/); virtual ~Node(); override Node* clone() const {return new Node(*this);} override ostream& printOn(ostream& o) const; override istream& readFrom(istream& i, Version* version=NULL); override VisualGraphic* getVisual() {return getShape();} virtual Shape* getShape(); override ERRORCODE setVisual(const char* visualClassName); virtual const char* getText() const; virtual void setText(const char*); virtual int execute(Command*); virtual int undo(Command*); //interface operations: these generate command which are dispatched through //the parent so that undo, groupware, etc can be implemented virtual Command* getSetTextCommand(char* buf=NULL); protected: virtual MENU doMakeMenu(); virtual Command* doGenerateCommand(WORD command, POINT *p, char* cmdName); }; //this class is the factory that all the graphics will consult when making new //objects. Subclass it to override its methods to get different behaviours. #define GraphicsFactoryClass 7204 class GRAPHIC_CLASS GraphicsFactory { MDEBUG_DECL(GraphicsFactory) public: GraphicsFactory(); GraphicsFactory(GraphicsFactory&); virtual ~GraphicsFactory(); static GraphicsFactory* setInstance(GraphicsFactory* g) {GraphicsFactory* ret=Instance; if (Instance) delete Instance; Instance = g; return ret;} static GraphicsFactory* getInstance() {return Instance?Instance:(Instance=new GraphicsFactory());} //these methods create new behavioural objects with visuals from the the libraries virtual Node* makeNode(GraphicContainer* parent=NULL, char* visualClassName="default", const char* label=NULL, const RECTANGLE* rect=NULL) {return new Node(parent,visualClassName,label,rect);} virtual SMaplet* makeSMaplet(GraphicContainer* parent=NULL, char* visualClassName="default", POINT& handle=defaultPoint, unsigned short nEndPoints=2) {return new SMaplet(parent,visualClassName,handle,nEndPoints);} virtual Node* instantiateNode(istream& i, GraphicContainer* parent); virtual Maplet* instantiateMaplet(istream& i, GraphicContainer* parent); //these methods manipulate and retrive copies of objects in the dictionaries (Libraries) virtual void registerShape(const string& name, Shape& shape) {ShapeLibrary.insert(name,shape);} virtual Shape* getShape(const string& name, GraphicContainer* parent=NULL) {return ShapeLibrary.makeCopy(name,parent);} virtual list* makeShapeNameList(); virtual void registerLine(const string& name, Line& shape) {LineLibrary.insert(name,shape);} virtual Line* getLine(const string& name, GraphicContainer* parent=NULL) {return LineLibrary.makeCopy(name,parent);} virtual list* makeLineNameList(); virtual void registerConnector(const string& name, Connector& shape) {ConnectorLibrary.insert(name,shape);} virtual Connector* getConnector(const string& name, GraphicContainer* parent=NULL) {return ConnectorLibrary.makeCopy(name,parent);} virtual list* makeConnectorNameList(); protected: GraphicsLibrary ConnectorLibrary; GraphicsLibrary ShapeLibrary; GraphicsLibrary LineLibrary; static GraphicsFactory* Instance; }; #endif