/* * * 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. * */ #ifdef __BCPLUSPLUS__ //---Borland C++ #include #pragma hdrstop #endif #include "cmap.h" CMap::CMap(GraphicContainer* gc) : SRGraphic(gc, "default"), BehaviouralGraphic(gc, "default") { MTRACE(CMap,CMap); MCONSTRUCTOR_IMP_CODE(CMap); MENTRY_CODE(CMap,CMap); } CMap::~CMap() { MTRACE(CMap,~CMap); MDESTRUCTOR_IMP_CODE(CMap); MTRACEOUT(CMap,~CMap); } void CMap::classInvarient(char* file, int line) const { SRGraphic::classInvarient(file,line); //MCLASSINVTEST(); } int CMap::paint(DEVICE dev,RECTANGLE* r) { MENTRY_CODE(CMap,paint) int ret = GraphicContainer::paint(dev,r); MEXIT_CODE(CMap,paint) return ret; } void CMap::doRButtonDown(unsigned int modKeys, POINT& p) { MENTRY_CODE(CMap,doRButtonDown); SensitiveGraphic* sg = getHit(p); if (sg) { sg->doRButtonDown(modKeys, p); } else { setCaptureGraphic(NULL); showMenu(&p); } MTRACEOUT(CMap,doRButtonDown); //may have been deleted } MENU CMap::doMakeMenu() { MENTRY_CODE(CMap,doMakeMenu); MENU m = SRGraphic::doMakeMenu(); appendMenu_Separator(m); appendMenu_String(m,CMD_NEWNODE,"New Node"); appendMenu_String(m,CMD_NEWARC,"New Arc"); //appendMenu_Separator(m); //appendMenu_String(m,C_editShapeLabel,"Edit Label"); MEXIT_CODE(CMap,doMakeMenu); return m; } Command* CMap::doGenerateCommand(WORD command, POINT *p, char* cmdName) { MENTRY_CODE(CMap,doGenerateCommand); Command* ret; switch (command) { case CMD_NEWNODE: { RECTANGLE r = {0,0,30,20}; if (p) { r.left=p->x; r.top=p->y; r.right=p->x+30; r.bottom=p->y+20; } Node* node = GraphicsFactory::getInstance()->makeNode(NULL,"default",NULL,&r); ret = getNewNodeCommand(node); } break; case CMD_NEWARC: { MASSERT(p); SMaplet* arc = GraphicsFactory::getInstance()->makeSMaplet(NULL,"default",*p); int i=arc->getArity(); for (; (--i)>=0; ) arc->park(i); ret = getNewArcCommand(arc); } break; default: ret = SRGraphic::doGenerateCommand(command,p,cmdName); break; } MTRACEOUT(CMap,doGenerateCommand); return ret; } int CMap::execute(Command* c) { MENTRY_CODE(CMap,execute); int ret = 0; switch (c->id()) { case CMD_NEWARC: { CommandPtr1* rc = dynamic_cast*>(c); if (rc) { SMaplet* arc = rc->getValue(); SMaplet* thisArc = arc->clone(); thisArc->setID(arc->id()); //the clone will have a different ID if (arc->id()) thisArc->resetParent((CMap*)this); else { thisArc->setParent((CMap*)this); arc->setID(thisArc->id()); //record the ID } queueForPaint(MAXRECTANGLE); //can't know what to repaint because all the arcs won't be instantiated until after the first paint } else error(0,'E',"CMap::execute: Bad NEW ARC command, type = %s",typeid(c).name()); } break; case CMD_NEWNODE: { CommandPtr1* rc = dynamic_cast*>(c); if (rc) { Node* node = rc->getValue(); Node* thisNode = node->clone(); thisNode->setID(node->id()); //the clone will have a different ID if (node->id()) thisNode->resetParent((CMap*)this); else { thisNode->setParent((CMap*)this); node->setID(thisNode->id()); //record the ID } thisNode->queueForPaint(thisNode->getRect()); } else error(0,'E',"CMap::execute: Bad NEW NODE command, type = %s",typeid(c).name()); } break; default: ret = SRGraphic::execute(c); break; } MTRACEOUT(CMap,execute); return ret; } int CMap::undo(Command* c) { MENTRY_CODE(CMap,undo); int ret = 0; switch (c->id()) { case CMD_NEWARC: { CommandPtr1* rc = dynamic_cast*>(c); if (rc) { SMaplet* arc = rc->getValue(); MASSERT(arc); SMaplet* thisArc = dynamic_cast((*this)[arc->id()]); if (thisArc) { queueForPaint(thisArc->getBoundingRect()); delete thisArc; } else error(0,'E',"CMap::undo: Can't find object of NEW ARC command"); } else error(0,'E',"CMap::undo: Bad NEW ARC command, type = %s",typeid(c).name()); } break; case CMD_NEWNODE: { CommandPtr1* rc = dynamic_cast*>(c); if (rc) { Node* node = rc->getValue(); MASSERT(node); Node* thisNode = dynamic_cast((*this)[node->id()]); if (thisNode) { queueForPaint(thisNode->getBoundingRect()); delete thisNode; } else error(0,'E',"CMap::undo: Can't find object of NEW NODE command"); } else error(0,'E',"CMap::execute: Bad NEW NODE command, type = %s",typeid(c).name()); } break; default: ret = SRGraphic::undo(c); break; } MTRACEOUT(CMap,undo); return ret; } Command* CMap::getNewNodeCommand(Node* node) { MENTRY_CODE(CMap,getNewNodeCommand); Command* cmd = new CommandPtr1(GraphicObjectLocator((CMap*)this),CMD_NEWNODE,node,NULL); MTRACEOUT(CMap,getNewNodeCommand); return cmd; } Command* CMap::getNewArcCommand(SMaplet* arc) { MENTRY_CODE(CMap,getNewArcCommand); Command* cmd = new CommandPtr1(GraphicObjectLocator((CMap*)this),CMD_NEWARC,arc,NULL); MTRACEOUT(CMap,getNewArcCommand); return cmd; } int CMap::handleCommand(Command* c) { MENTRY_CODE(CMap,handleCommand); MASSERT(c); int ret; if (getParent()) ret = getParent()->handleCommand(c); else { ret = c->execute(); delete c; } MEXIT_CODE(CMap,handleCommand) return ret; }