void LinkSelection::Clear(Viewer* viewer) { #if 0 fprintf(stderr, "LinkSelection::Clear\n"); #endif #if 0 CompIdTable* table = ((DrawServ*)unidraw)->compidtable(); Iterator it; First(it); while(!Done(it)) { OverlayView* view = GetView(it); OverlayComp* comp = view ? view->GetOverlayComp() : nil; void* ptr = nil; table->find(ptr, (void*)comp); if (ptr) { GraphicId* grid = (GraphicId*)ptr; if (grid->selected()==LocallySelected || grid->selected()==WaitingToBeSelected) grid->selected(NotSelected); char buf[BUFSIZ]; snprintf(buf, BUFSIZ, "grid(chgid(0x%08x) chgid(0x%08x) :state %d)%c", grid->id(), grid->selector(), grid->selected(), '\0'); ((DrawServ*)unidraw)->DistributeCmdString(buf); } Next(it); } #endif OverlaySelection::Clear(viewer); Reserve(); }
// handle callback from remote DrawLink. void DrawServ::grid_message_callback(DrawLink* link, unsigned int id, unsigned int selector, int state, unsigned int oldselector) { void* ptr = nil; gridtable()->find(ptr, id); if (ptr) { GraphicId* grid = (GraphicId*)ptr; /* if request is granted, add to selection */ if (grid->selected()==LinkSelection::WaitingToBeSelected && selector==sessionid()) { grid->selector(selector); fprintf(stderr, "grid: request granted, add to selection now\n"); OverlayComp* comp = (OverlayComp*)grid->grcomp(); LinkSelection* sel = (LinkSelection*)DrawKit::Instance()->GetEditor()->GetSelection(); sel->AddComp(comp); } /* otherwise, pass the granting message along */ else { fprintf(stderr, "grid: pass grant request along\n"); char buf[BUFSIZ]; snprintf(buf, BUFSIZ, "grid(chgid(0x%08x) chgid(0x%08x) :grant chgid(0x%08x))%c", grid->id(), selector, oldselector, '\0'); SendCmdString(linkget(selector), buf); } } }
// handle reserve request from remote DrawLink. void DrawServ::grid_message_handle(DrawLink* link, unsigned int id, unsigned int selector, int state, unsigned int newselector) { void* ptr = nil; gridtable()->find(ptr, id); if (ptr) { GraphicId* grid = (GraphicId*)ptr; /* if this request is aimed here */ if (selector==sessionid() && newselector!=0) { /* if graphic is still locally owned */ if (grid->selector()==sessionid()) { /* if graphic is not actually selected */ if ((grid->selected()==LinkSelection::NotSelected || grid->selected()==LinkSelection::WaitingToBeSelected)) { grid->selected(LinkSelection::NotSelected); grid->selector(newselector); char buf[BUFSIZ]; snprintf(buf, BUFSIZ, "grid(chgid(0x%08x) chgid(0x%08x) :grant chgid(0x%08x))%c", grid->id(), newselector, sessionid(), '\0'); SendCmdString(link, buf); fprintf(stderr, "grid: request granted\n"); } /* else do nothing, because it is selected */ else { fprintf(stderr, "grid: request ignored, graphic locally selected\n"); } } /* else reformulate this request and pass it along */ else { fprintf(stderr, "grid: request passed along to current selector\n"); char buf[BUFSIZ]; snprintf(buf, BUFSIZ, "grid(chgid(0x%08x) chgid(0x%08x) :request chgid(0x%08x))%c", grid->id(), grid->selector(), newselector, '\0'); SendCmdString(linkget(grid->selector()), buf); } } /* else this request and/or simple state update should be passed along */ else { /* if simple state, set the values here, and pass it on to everyone else */ if (newselector==0) { if (linklist()->Number()>1) fprintf(stderr, "grid: state change passed along to everyone else\n"); grid->selector(selector); grid->selected(state); char buf[BUFSIZ]; snprintf(buf, BUFSIZ, "grid(chgid(0x%08x) chgid(0x%08x) :state %d)%c", grid->id(), grid->selector(), grid->selected(), '\0'); DistributeCmdString(buf, link); } /* else pass the request on to the target selector */ else { fprintf(stderr, "grid: request passed along to targeted selector"); char buf[BUFSIZ]; snprintf(buf, BUFSIZ, "grid(chgid(0x%08x) chgid(0x%08x) :request chgid(0x%08x))%c", grid->id(), selector, newselector, '\0'); SendCmdString(linkget(grid->selector()), buf); } } } }
void DrawServ::ExecuteCmd(Command* cmd) { static int grid_sym = symbol_add("grid"); static int sid_sym = symbol_add("sid"); boolean original = false; unsigned int from_sid = 0; if(!_linklist || _linklist->Number()==0) /* normal Unidraw command execution */ Unidraw::ExecuteCmd(cmd); else { /* indirect command execution, all by script */ std::ostrstream sbuf; boolean oldflag = OverlayScript::ptlist_parens(); OverlayScript::ptlist_parens(false); switch (cmd->GetClassId()) { case PASTE_CMD: { boolean scripted = false; Clipboard* cb = cmd->GetClipboard(); if (cb) { Iterator it; for (cb->First(it); !cb->Done(it); cb->Next(it)) { OverlayComp* comp = (OverlayComp*)cb->GetComp(it); AttributeList* al = comp->GetAttributeList(); AttributeValue* idv = al->find(grid_sym); AttributeValue* sidv = al->find(sid_sym); from_sid = sidv ? sidv->uint_val() : 0; /* unique id already remotely assigned */ if (idv && idv->uint_val() !=0 && sidv && sidv->uint_val() !=0) { GraphicId* graphicid = new GraphicId(); graphicid->grcomp(comp); graphicid->id(idv->uint_val()); graphicid->selector(sidv->uint_val()); graphicid->selected(LinkSelection::RemotelySelected); } /* generate unique id and add as attribute */ /* also mark with selector id */ else { GraphicId* graphicid = new GraphicId(sessionid()); graphicid->grcomp(comp); graphicid->selector(((DrawServ*)unidraw)->sessionid()); AttributeValue* gridv = new AttributeValue(graphicid->id(), AttributeValue::UIntType); gridv->state(AttributeValue::HexState); al->add_attr(grid_sym, gridv); AttributeValue* sidv = new AttributeValue(graphicid->selector(), AttributeValue::UIntType); sidv->state(AttributeValue::HexState); al->add_attr(sid_sym, sidv); original = true; } if (comp && (original || linklist()->Number()>1)) { Creator* creator = unidraw->GetCatalog()->GetCreator(); OverlayScript* scripter = (OverlayScript*) creator->Create(Combine(comp->GetClassId(), SCRIPT_VIEW)); if (scripter) { scripter->SetSubject(comp); if (scripted) sbuf << ';'; else scripted = true; boolean status = scripter->Definition(sbuf); delete scripter; } } } } if (original || linklist()->Number()>1) { if (!scripted) sbuf << "print(\"Failed attempt to generate script for a PASTE_CMD\\n\" :err)"; sbuf.put('\0'); cout << sbuf.str() << "\n"; cout.flush(); } /* first execute here */ #if 0 ((ComEditor*)cmd->GetEditor())->GetComTerp()->run(sbuf.str()); ((PasteCmd*)cmd)->executed(true); #else cmd->Execute(); #endif /* then send everywhere else */ if (original || linklist()->Number()>1) DistributeCmdString(sbuf.str(), linkget(from_sid)); } break; default: sbuf << "print(\"Attempt to convert unknown command (id == %d) to interpretable script\\n\" " << cmd->GetClassId() << " :err)"; cmd->Execute(); break; } if (cmd->Reversible()) { cmd->Log(); } else { delete cmd; } OverlayScript::ptlist_parens(oldflag); } }