void BackCmd::Execute () { Clipboard* cb = GetClipboard(); Editor* ed = GetEditor(); if (cb == nil) { Selection* s = ed->GetSelection(); if (s->IsEmpty()) { return; } SetClipboard(cb = new Clipboard); GraphicView* views = ed->GetViewer()->GetGraphicView(); s->Sort(views); Iterator i; for (s->First(i); !s->Done(i); s->Next(i)) { s->GetView(i)->Interpret(this); } } else { Clipboard* oldcb = cb; SetClipboard(cb = new Clipboard); Iterator i; for (oldcb->First(i); !oldcb->Done(i); oldcb->Next(i)) { oldcb->GetComp(i)->Interpret(this); } delete oldcb; } if (!cb->IsEmpty()) { ed->GetComponent()->Interpret(this); } }
/* virtual */ void ComEditor::ExecuteCmd(Command* cmd) { if(!whiteboard()) /* normal Unidraw command execution */ OverlayEditor::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); if (comp) { 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 (!scripted) sbuf << "print(\"Failed attempt to generate script for a PASTE_CMD\\n\" :err)"; sbuf.put('\0'); cout << sbuf.str() << "\n"; cout.flush(); GetComTerp()->run(sbuf.str()); delete cmd; } break; default: sbuf << "print(\"Attempt to convert unknown command (id == %d) to interpretable script\\n\" " << cmd->GetClassId() << " :err)"; cmd->Execute(); if (cmd->Reversible()) { cmd->Log(); } else { delete cmd; } break; } OverlayScript::ptlist_parens(oldflag); } }
void Command::Execute () { Selection* s = _editor->GetSelection(); Clipboard* cb = GetClipboard(); if (!s->IsEmpty() || (cb != nil && !cb->IsEmpty())) { Iterator i; if (cb == nil) { SetClipboard(cb = new Clipboard); cb->Init(s); } for (cb->First(i); !cb->Done(i); cb->Next(i)) { cb->GetComp(i)->Interpret(this); } unidraw->Update(); } }
void AlignToGridCmd::Execute () { Selection* s = _editor->GetSelection(); if (!s->IsEmpty()) { Clipboard* cb = GetClipboard(); Iterator i; if (cb == nil) { for (s->First(i); !s->Done(i); s->Next(i)) { s->GetView(i)->Interpret(this); } SetClipboard(cb = new Clipboard); cb->Init(s); } else { for (cb->First(i); !cb->Done(i); cb->Next(i)) { Move(cb->GetComp(i)); } } unidraw->Update(); } }
void GroupCmd::Execute () { Clipboard* cb = GetClipboard(); if (cb == nil) { SetClipboard(cb = new Clipboard); Editor* ed = GetEditor(); Selection* s = ed->GetSelection(); if (s->Number() > 1) { Iterator i; GraphicView* views = ed->GetViewer()->GetGraphicView(); s->Sort(views); for (s->First(i); !s->Done(i); s->Next(i)) { s->GetView(i)->Interpret(this); } } } else { Clipboard* oldcb = cb; SetClipboard(cb = new Clipboard); Iterator i; for (oldcb->First(i); !oldcb->Done(i); oldcb->Next(i)) { oldcb->GetComp(i)->Interpret(this); } delete oldcb; } if (!cb->IsEmpty()) { if (_group == nil) { SetGroup(new GraphicComps); } _group->Interpret(this); _executed = true; } }
void OverlaysComp::Uninterpret (Command* cmd) { Editor* ed = cmd->GetEditor(); if ( (cmd->IsA(DELETE_CMD) || cmd->IsA(CUT_CMD)) && ed->GetComponent() != this ) { Iterator i; for (Last(i); !Done(i); Prev(i)) { GetComp(i)->Uninterpret(cmd); } } else if (cmd->IsA(DELETE_CMD)) { Clipboard* cb = cmd->GetClipboard(); if (cb != nil) { Iterator i; for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { OverlayComp* comp = (OverlayComp*) cb->GetComp(i); RestorePosition(comp, cmd); comp->Uninterpret(cmd); } Notify(); SelectClipboard(cb, ed); unidraw->Update(); } } else if (cmd->IsA(CUT_CMD)) { Clipboard* cb = cmd->GetClipboard(); if (cb != nil) { Iterator i; for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { OverlayComp* comp = (OverlayComp*) cb->GetComp(i); RestorePosition(comp, cmd); comp->Uninterpret(cmd); } Notify(); SelectClipboard(cb, ed); unidraw->Update(); } } else if (cmd->IsA(PASTE_CMD)) { Clipboard* cb = cmd->GetClipboard(); if (cb != nil) { Selection* s = ed->GetSelection(); Iterator i, pos; s->Clear(); for (cb->First(i); !cb->Done(i); cb->Next(i)) { GraphicComp* comp = cb->GetComp(i); unidraw->CloseDependents(comp); Remove(comp); } Notify(); unidraw->Update(); } } else if (cmd->IsA(DUP_CMD)) { Clipboard* cb = cmd->GetClipboard(); if (cb != nil) { Selection* s = ed->GetSelection(); Iterator i; s->Clear(); for (cb->First(i); !cb->Done(i); cb->Next(i)) { GraphicComp* comp = cb->GetComp(i); unidraw->CloseDependents(comp); Remove(comp); } Notify(); unidraw->Update(); } } else if (cmd->IsA(OVGROUP_CMD)) { OvGroupCmd* gcmd = (OvGroupCmd*) cmd; OverlayComp* group = gcmd->GetGroup(); Component* edComp = gcmd->GetEditor()->GetComponent(); if (group == this) { edComp->Uninterpret(gcmd); } else if (edComp == (Component*) this) { Clipboard* cb = cmd->GetClipboard(); Iterator i; cb->First(i); OverlayComp* group = (OverlayComp*) cb->GetComp(i)->GetParent(); GroupCmd* gcmd = (GroupCmd*) cmd; unidraw->CloseDependents(group); for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { RestorePosition((OverlayComp*)cb->GetComp(i), cmd); } Remove(group); Notify(); SelectClipboard(cb, ed); unidraw->Update(); } else { OverlayComp::Uninterpret(gcmd); } } else if (cmd->IsA(UNGROUP_CMD)) { UngroupCmd* ucmd = (UngroupCmd*) cmd; Component* edComp = ucmd->GetEditor()->GetComponent(); if (edComp == (Component*) this) { Clipboard* cb = ucmd->GetClipboard(); Clipboard* kids = ucmd->GetKids(); Clipboard insertedParents; Iterator k; for (kids->First(k); !kids->Done(k); kids->Next(k)) { OverlayComp* kid = (OverlayComp*) kids->GetComp(k); UngroupData* ud = (UngroupData*) cmd->Recall(kid); OverlayComp* parent = (OverlayComp*)ud->_parent; *kid->GetGraphic() = *ud->_gs; if (!insertedParents.Includes(parent)) { GSData* gd = (GSData*) cmd->Recall(parent); *parent->GetGraphic() = *gd->_gs; Iterator insertPt; SetComp(kid, insertPt); InsertBefore(insertPt, parent); insertedParents.Append(parent); } Remove(kid); parent->Append(kid); } Notify(); SelectClipboard(cb, ed); unidraw->Update(); delete kids; ucmd->SetKids(nil); } } else if (cmd->IsA(FRONT_CMD)) { Component* edComp = cmd->GetEditor()->GetComponent(); if (edComp == (Component*) this) { Clipboard* cb = cmd->GetClipboard(); Iterator i; for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { RestorePosition((OverlayComp*)cb->GetComp(i), cmd); } Notify(); SelectClipboard(cb, ed); unidraw->Update(); } else { OverlayComp::Uninterpret(cmd); } } else if (cmd->IsA(BACK_CMD)) { Component* edComp = cmd->GetEditor()->GetComponent(); if (edComp == (Component*) this) { Clipboard* cb = cmd->GetClipboard(); Iterator i; for (cb->First(i); !cb->Done(i); cb->Next(i)) { RestorePosition((OverlayComp*)cb->GetComp(i), cmd); } Notify(); SelectClipboard(cb, ed); unidraw->Update(); } else { OverlayComp::Uninterpret(cmd); } } else { OverlayComp::Uninterpret(cmd); } }
void OverlaysComp::Interpret (Command* cmd) { Editor* ed = cmd->GetEditor(); if ( (cmd->IsA(DELETE_CMD) || cmd->IsA(CUT_CMD)) && ed->GetComponent() != this ) { Iterator i; for (First(i); !Done(i); Next(i)) { GetComp(i)->Interpret(cmd); } } else if (cmd->IsA(DELETE_CMD)) { Clipboard* cb = cmd->GetClipboard(); Selection* s = ed->GetSelection(); if (cb == nil) { if (s->IsEmpty()) { return; } cmd->SetClipboard(cb = new Clipboard); cb->Init(s); } s->Clear(); Iterator i; for (cb->First(i); !cb->Done(i); cb->Next(i)) { OverlayComp* comp = (OverlayComp*)cb->GetComp(i); unidraw->CloseDependents(comp); comp->Interpret(cmd); StorePosition(comp, cmd); Remove(comp); } Notify(); unidraw->Update(); } else if (cmd->IsA(CUT_CMD)) { Clipboard* cb = cmd->GetClipboard(); Selection* s = ed->GetSelection(); if (cb == nil) { if (s->IsEmpty()) { return; } GraphicView* views = ed->GetViewer()->GetGraphicView(); s->Sort(views); cmd->SetClipboard(cb = new Clipboard); cb->Init(s); Clipboard* globalcb = unidraw->GetCatalog()->GetClipboard(); globalcb->DeleteComps(); globalcb->CopyInit(s); } s->Clear(); Iterator i; for (cb->First(i); !cb->Done(i); cb->Next(i)) { OverlayComp* comp = (OverlayComp*)cb->GetComp(i); unidraw->CloseDependents(comp); comp->Interpret(cmd); StorePosition(comp, cmd); Remove(comp); } Notify(); unidraw->Update(); } else if (cmd->IsA(PASTE_CMD)) { Clipboard* cb = cmd->GetClipboard(); Iterator i; if (cb == nil) { Clipboard* globalcb = unidraw->GetCatalog()->GetClipboard(); if (globalcb->IsEmpty()) { return; } cmd->SetClipboard(cb = globalcb->DeepCopy()); } for (cb->First(i); !cb->Done(i); cb->Next(i)) { Append((OverlayComp*)cb->GetComp(i)); } Notify(); SelectClipboard(cb, ed); unidraw->Update(); } else if (cmd->IsA(DUP_CMD)) { GraphicView* views = ed->GetViewer()->GetGraphicView(); OverlayComp* prev, *dup1; Iterator i, pos; Clipboard* cb = cmd->GetClipboard(); const float offset = 8; MoveCmd move(ed, offset, offset); if (cb == nil) { OverlaySelection* s = (OverlaySelection*)ed->GetSelection(); if (s->IsEmpty()) { return; } cmd->SetClipboard(cb = new Clipboard); s->Sort(views); for (s->First(i); !s->Done(i); s->Next(i)) { OverlayComp* orig = s->GetView(i)->GetOverlayComp(); dup1 = (OverlayComp*) orig->Copy(); if (!dup1->attrlist() && orig->attrlist()) { AttributeList* al = new AttributeList(orig->attrlist()); dup1->SetAttributeList(al); } dup1->Interpret(&move); cb->Append(dup1); } cb->First(i); dup1 = (OverlayComp*) cb->GetComp(i); Last(pos); prev = (OverlayComp*) GetComp(pos); cmd->Store(dup1, new VoidData(prev)); } else { cb->First(i); dup1 = (OverlayComp*) cb->GetComp(i); VoidData* vd = (VoidData*) cmd->Recall(dup1); prev = (OverlayComp*) vd->_void; SetComp(prev, pos); } for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { InsertAfter(pos, cb->GetComp(i)); } Notify(); SelectClipboard(cb, ed); unidraw->Update(); } else if (cmd->IsA(OVGROUP_CMD)) { OvGroupCmd* gcmd = (OvGroupCmd*) cmd; OverlayComp* group = gcmd->GetGroup(); Component* edComp = gcmd->GetEditor()->GetComponent(); if (group == this) { edComp->Interpret(gcmd); } else if (edComp == (Component*) this) { Clipboard* cb = cmd->GetClipboard(); NullGS(group->GetGraphic()); Group(cb, group, cmd); Notify(); SelectViewsOf(group, ed); unidraw->Update(); } else { OverlayComp::Interpret(gcmd); } } else if (cmd->IsA(UNGROUP_CMD)) { UngroupCmd* ucmd = (UngroupCmd*) cmd; Component* edComp = ucmd->GetEditor()->GetComponent(); if (edComp == (Component*) this) { Clipboard* cb = cmd->GetClipboard(); Clipboard* kids = new Clipboard; ucmd->SetKids(kids); Iterator i; for (cb->First(i); !cb->Done(i); cb->Next(i)) { OverlayComp* parent = (OverlayComp*)cb->GetComp(i); unidraw->CloseDependents(parent); Ungroup(parent, kids, cmd); } Notify(); SelectClipboard(kids, ed); unidraw->Update(); } else { cmd->GetClipboard()->Append(this); } } else if (cmd->IsA(PUSH_CMD) || cmd->IsA(PULL_CMD)) { Component* edComp = cmd->GetEditor()->GetComponent(); if (edComp == (Component*) this) { Clipboard* cb = cmd->GetClipboard(); Iterator i; if (cmd->IsA(PULL_CMD)) { for (cb->First(i); !cb->Done(i); cb->Next(i)) { OverlayComp* comp = (OverlayComp*)cb->GetComp(i); Iterator j; SetComp(comp, j); Next(j); StorePosition(comp, cmd); if (!Done(j)) { Remove(comp); InsertAfter(j, comp); } } } else { for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { OverlayComp* comp = (OverlayComp*) cb->GetComp(i); Iterator j; SetComp(comp, j); Prev(j); StorePosition(comp, cmd); if (!Done(j)) { Remove(comp); InsertBefore(j, comp); } } } Notify(); unidraw->Update(); } else { OverlayComp::Interpret(cmd); } } else if (cmd->IsA(FRONT_CMD) || cmd->IsA(BACK_CMD)) { Component* edComp = cmd->GetEditor()->GetComponent(); if (edComp == (Component*) this) { Clipboard* cb = cmd->GetClipboard(); Iterator i; if (cmd->IsA(FRONT_CMD)) { for (cb->First(i); !cb->Done(i); cb->Next(i)) { OverlayComp* comp = (OverlayComp*)cb->GetComp(i); StorePosition(comp, cmd); Remove(comp); Append(comp); } } else { for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { OverlayComp* comp = (OverlayComp*) cb->GetComp(i); StorePosition(comp, cmd); Remove(comp); Prepend(comp); } } Notify(); unidraw->Update(); } else { OverlayComp::Interpret(cmd); } } else { OverlayComp::Interpret(cmd); } }
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); } }
void DrawImportPasteCmd::Execute () { if(!_executed) { Clipboard* cb = GetClipboard(); Iterator it; cb->First(it); GraphicComp* gcomp = cb->GetComp(it); cb->Next(it); if(cb->Done(it) && gcomp->IsA(DRAW_IDRAW_COMP) || gcomp->IsA(FRAME_IDRAW_COMP)) { gcomp->First(it); /* move to background frame */ DrawEditor* ed = (DrawEditor*)GetEditor(); FrameNumberState* fnumstate = ed->framenumstate(); int origfnum = fnumstate->framenumber(); int currfnum = 0; Append(new MoveFrameCmd(ed, -origfnum, true /* allowbg */)); /* paste contents of background frame */ FrameComp* fcomp = (FrameComp*) (gcomp->GetComp(it)->IsA(FRAME_COMP) ? gcomp->GetComp(it) : nil); if (fcomp) { while(!gcomp->Done(it)) { gcomp->Remove(it); Clipboard* newcb = new Clipboard(); Iterator jt; fcomp->First(jt); while(!fcomp->Done(jt)) { newcb->Append(fcomp->GetComp(jt)); fcomp->Remove(jt); } Append(new PasteCmd(ed, newcb)); delete fcomp; /* while more frames move to next frame and paste (create new frame if necessary) */ if(!gcomp->Done(it)) { currfnum++; fcomp = (FrameComp*) (gcomp->GetComp(it)->IsA(FRAME_COMP) ? gcomp->GetComp(it) : nil); if(currfnum>=ed->NumFrames()) Append(new CreateMoveFrameCmd(ed)); else Append(new MoveFrameCmd(ed, 1, true /* allowbg */)); } } } /* move to original frame */ Append(new MoveFrameCmd(ed, origfnum-currfnum, true /* allowbg */)); } else { Append(new PasteCmd(GetEditor(), cb->Copy())); Iterator i; for (cb->First(i); !cb->Done(i); cb->Next(i)) { GraphicComp* gcomp = cb->GetComp(i); if (gcomp->IsA(EDGE_COMP)) { EdgeComp* comp = (EdgeComp*)gcomp; NodeComp* start = node(cb, comp->GetStartNode()); NodeComp* end = node(cb, comp->GetEndNode()); EdgeConnectCmd* cmd = new EdgeConnectCmd(GetEditor(), comp, start, end); Append(cmd); } } } } MacroCmd::Execute(); _executed = 1; }