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); } }
void ComputeViewPath (Event& e, GraphicView* views, Selection* s){ Selection* newSel = views->ViewIntersecting(e.x-SLOP, e.y-SLOP, e.x+SLOP, e.y+SLOP); Iterator i; if (newSel != nil) { for (newSel->First(i); !newSel->Done(i); newSel->Next(i)) { GraphicView* gv = newSel->GetView(i); if (gv != nil) { s->Append(gv); ComputeViewPath(e, gv, s); } } delete newSel; } }
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; } }
boolean GraphExportCmd::Export (const char* pathname) { Editor* editor = GetEditor(); Selection* s = editor->GetSelection(); GraphIdrawComp* real_top = (GraphIdrawComp*)editor->GetComponent(); boolean ok = false; char* old_format = NULL; boolean empty = s->IsEmpty(); GraphIdrawComp* false_top = new GraphIdrawComp(); Iterator i; empty ? real_top->First(i) : s->First(i); while (empty ? !real_top->Done(i) : !s->Done(i)) { if (chooser_->idraw_format() || chooser_->postscript_format()) { OverlayComp* oc = empty ? new OverlayComp(real_top->GetComp(i)->GetGraphic()->Copy()) : new OverlayComp(s->GetView(i)->GetGraphicComp()->GetGraphic()->Copy()); false_top->Append(oc); } else { OverlayComp* oc = empty ? (OverlayComp*)real_top->GetComp(i)->Copy() : (OverlayComp*)s->GetView(i)->GetGraphicComp()->Copy(); false_top->Append(oc); } empty ? real_top->Next(i) : s->Next(i); } OverlayPS* ovpsv; if (chooser_->idraw_format() || chooser_->postscript_format()) ovpsv = (OverlayPS*) false_top->Create(POSTSCRIPT_VIEW); else { ovpsv = (OverlayPS*) false_top->Create(SCRIPT_VIEW); if(strcmp(chooser_->format(), "dot")==0) { old_format = OverlayScript::format() ? strnew(OverlayScript::format()) : NULL; OverlayScript::format("dot"); } } if (ovpsv != nil) { filebuf fbuf; char* tmpfilename; if (chooser_->to_printer()) { tmpfilename = tmpnam(nil); false_top->SetPathName(tmpfilename); ok = fbuf.open(tmpfilename, output) != 0; } else { ok = fbuf.open(pathname, output) != 0; } if (ok) { ostream out(&fbuf); false_top->Attach(ovpsv); ovpsv->SetCommand(this); if (!chooser_->idraw_format() && !chooser_->postscript_format()) ((GraphIdrawScript*)ovpsv)->SetByPathnameFlag(chooser_->by_pathname_flag()); ovpsv->Update(); ok = ovpsv->Emit(out); fbuf.close(); if (chooser_->to_printer()) { char cmd[CHARBUFSIZE]; if (strstr(pathname, "%s")) { char buf[CHARBUFSIZE]; sprintf(buf, pathname, tmpfilename); sprintf(cmd, "(%s;rm %s)&", buf, tmpfilename); } else sprintf(cmd, "(%s %s;rm %s)&", pathname, tmpfilename, tmpfilename); ok = system(cmd) == 0; } } delete ovpsv; } delete false_top; if (old_format) { OverlayScript::format(old_format); delete old_format; } return ok; }
void SelectFunc::execute() { static int all_symid = symbol_add("all"); ComValue all_flagv(stack_key(all_symid)); boolean all_flag = all_flagv.is_true(); static int clear_symid = symbol_add("clear"); ComValue clear_flagv(stack_key(clear_symid)); boolean clear_flag = clear_flagv.is_true(); Selection* sel = _ed->GetViewer()->GetSelection(); if (clear_flag) { sel->Clear(); unidraw->Update(); reset_stack(); return; } OverlaySelection* newSel = ((OverlayEditor*)_ed)->overlay_kit()->MakeSelection(); Viewer* viewer = _ed->GetViewer(); AttributeValueList* avl = new AttributeValueList(); if (all_flag) { GraphicView* gv = ((OverlayEditor*)_ed)->GetFrame(); Iterator i; int count=0; for (gv->First(i); !gv->Done(i); gv->Next(i)) { GraphicView* subgv = gv->GetView(i); newSel->Append(subgv); OverlayComp* comp = (OverlayComp*)subgv->GetGraphicComp(); ComValue* compval = new ComValue(new OverlayViewRef(comp), comp->classid()); avl->Append(compval); } } else if (nargs()==0) { Iterator i; int count=0; for (sel->First(i); !sel->Done(i); sel->Next(i)) { GraphicView* grview = sel->GetView(i); OverlayComp* comp = grview ? (OverlayComp*)grview->GetSubject() : nil; ComValue* compval = comp ? new ComValue(new OverlayViewRef(comp), comp->classid()) : nil; if (compval) { avl->Append(compval); } delete newSel; newSel = nil; } } else { for (int i=0; i<nargsfixed(); i++) { ComValue& obj = stack_arg(i); if (obj.object_compview()) { ComponentView* comview = (ComponentView*)obj.obj_val(); OverlayComp* comp = (OverlayComp*)comview->GetSubject(); if (comp) { GraphicView* view = comp->FindView(viewer); if (view) { newSel->Append(view); ComValue* compval = new ComValue(new OverlayViewRef(comp), comp->classid()); avl->Append(compval); } } } else if (obj.is_array()) { Iterator it; AttributeValueList* al = obj.array_val(); al->First(it); while (!al->Done(it)) { if (al->GetAttrVal(it)->object_compview()) { ComponentView* comview = (ComponentView*)al->GetAttrVal(it)->obj_val(); OverlayComp* comp = (OverlayComp*)comview->GetSubject(); if (comp) { GraphicView* view = comp->FindView(viewer); if (view) { newSel->Append(view); ComValue* compval = new ComValue(new OverlayViewRef(comp), comp->classid()); avl->Append(compval); } } } al->Next(it); } } } } if (newSel){ sel->Clear(); delete sel; _ed->SetSelection(newSel); newSel->Update(viewer); unidraw->Update(); } reset_stack(); ComValue retval(avl); push_stack(retval); }