Manipulator* ScaleTool::CreateManipulator ( Viewer* v, Event& e, Transformer* rel ) { GraphicView* views = v->GetGraphicView(); Selection* s = v->GetSelection(), *newSel; GraphicView* gv; Manipulator* m = nil; Iterator i; newSel = views->ViewIntersecting(e.x-SLOP, e.y-SLOP, e.x+SLOP, e.y+SLOP); if (newSel->IsEmpty()) { s->Clear(); } else { newSel->First(i); gv = newSel->GetView(i); if (s->Includes(gv)) { s->Remove(gv); s->Prepend(gv); } else { s->Clear(); s->Append(gv); s->Update(); } m = gv->CreateManipulator(v, e, rel, this); } delete newSel; return m; }
Manipulator* ExamineTool::CreateManipulator ( Viewer* v, Event& e, Transformer* t ){ GraphicView* views = v->GetGraphicView(); Selection* s = v->GetSelection(); _selPath = new Selection; Manipulator* m = nil; s->Clear(); ComputeViewPath(e, views, _selPath); _shift = e.shift_is_down(); if (!_selPath->IsEmpty()) { Iterator i; _selPath->First(i); GraphicView* gv = _selPath->GetView(i); s->Append(gv); s->Update(); _selPath->Last(i); gv = _selPath->GetView(i); m = gv->CreateManipulator(v, e, t, this); } delete _selPath; return m; }
Manipulator* NarrowTool::CreateManipulator (Viewer* v, Event& e,Transformer*){ Manipulator* m = nil; _popup = false; GraphicView* views = v->GetGraphicView(); if (!e.shift_is_down()) { Selection* s = v->GetSelection(), *newSel = new Selection; s->Clear(); ComputeViewPath(e, views, newSel); if (!newSel->IsEmpty()) { Iterator i; newSel->First(i); GraphicView* gv = newSel->GetView(i); s->Append(gv); s->Update(); m = CreatePopupManip(newSel, v); _popup = true; } delete newSel; } else { m = new NarrowManip(v); } return m; }
Manipulator* AttributeTool::CreateManipulator ( Viewer* v, Event& e, Transformer* rel ) { Manipulator* m = nil; GraphicView* views = v->GetGraphicView(); Selection* s = v->GetSelection(), *newSel; newSel = views->ViewIntersecting(e.x-SLOP, e.y-SLOP, e.x+SLOP, e.y+SLOP); if (e.shift) { Localize(s, v); } else { s->Clear(); } if (newSel->IsEmpty()) { // do nothing } else { // else user selected object directly s->Exclusive(newSel); } delete newSel; if (s->Number() == 1) { Iterator i; s->First(i); GraphicView* view = s->GetView(i); if (view->IsA(OVERLAY_VIEW)) { ((OverlayEditor*)v->GetEditor())->MouseDocObservable()->textvalue(""); ((OverlayEditor*)v->GetEditor())->AttrEdit(((OverlayView*)view)->GetOverlayComp()); ((OverlayEditor*)v->GetEditor())->MouseDocObservable()->textvalue(OverlayKit::mouse_attr); } } return m; }
void TextManip::Grasp (Event& e) { _grasp_e = e; Viewer* v = GetViewer(); Selection* s = v->GetSelection(); v->Constrain(e.x, e.y); _selecting = true; if (!_prepositioned) { _xpos = e.x; _ypos = e.y; } PlaceTextDisplay(_xpos, _ypos); Coord l, b, r, t; _display->CaretStyle(BarCaret); _display->Bounds(l, b, r, t); _display->Redraw(l, b, r, t); _selection = new Selection(s); s->Clear(); if (_prepositioned) { Select(Locate(e.x, e.y)); } }
Manipulator* LinkView::CreateLinkCompManip ( Viewer* v, Event& e, Transformer* rel, Tool* tool ) { GraphicView* views = v->GetGraphicView(); Selection* s = v->GetSelection(); RubberGroup* rg = new RubberGroup(nil, nil); float x, y, tx, ty; Coord cx = 0, rad = PIN_RAD, dum1 = 0, dum2 = 0; ConnectorView* target = views->ConnectorIntersecting( e.x-SLOP, e.y-SLOP, e.x+SLOP, e.y+SLOP ); s->Clear(); if (target != nil) { target->GetConnector()->GetCenter(x, y); rel->Transform(x, y, tx, ty); e.x = Math::round(tx); e.y = Math::round(ty); } if (rel != nil) { rel->Transform(cx, dum1); rel->Transform(rad, dum2); rad = abs(rad - cx); } rg->Append( new RubberLine(nil, nil, e.x, e.y, e.x, e.y), new FixedPin(nil, nil, e.x, e.y, rad), new SlidingPin(nil, nil, e.x, e.y, rad, e.x, e.y) ); return new ConnectManip(v, rg, rel, tool); }
void Editor::Close () { Selection* s = GetSelection(); if (s != nil) { s->Clear(); } DetachComponentViews(this); }
void OverlaysComp::SelectViewsOf (OverlayComp* comp, Editor* ed) { Selection* s = ed->GetSelection(); s->Clear(); Viewer* viewer; for (int i = 0; (viewer = ed->GetViewer(i)) != nil; ++i) { GraphicView* views = viewer->GetGraphicView(); GraphicView* view = views->GetGraphicView(comp); if (view != nil) s->Append(view); } }
void OverlaysComp::SelectClipboard (Clipboard* cb, Editor* ed) { Selection* s = ed->GetSelection(); s->Clear(); Viewer* viewer; Iterator i; for (int j = 0; (viewer = ed->GetViewer(j)) != nil; ++j) { for (cb->First(i); !cb->Done(i); cb->Next(i)) { GraphicView* views = viewer->GetGraphicView(); GraphicView* view = views->GetGraphicView(cb->GetComp(i)); if (view != nil) s->Append(view); } } ((OverlaySelection*)s)->Reserve(); }
Manipulator* ConnectTool::CreateManipulator ( Viewer* v, Event& e, Transformer* rel ) { GraphicView* views = v->GetGraphicView(); Selection* s = v->GetSelection(); Manipulator* m = nil; _source = views->ConnectorIntersecting( e.x-SLOP, e.y-SLOP, e.x+SLOP, e.y+SLOP ); if (_source == nil) { s->Clear(); } else { m = _source->CreateManipulator(v, e, rel, this); } return m; }
Manipulator* PinView::CreateGraphicCompManip ( Viewer* v, Event& e, Transformer* rel, Tool* tool ) { GraphicView* views = v->GetGraphicView(); Selection* s = v->GetSelection(); SlidingPin* sp; Coord cx = 0, rad = PIN_RAD, dum1 = 0, dum2 = 0; s->Clear(); if (rel != nil) { rel->Transform(cx, dum1); rel->Transform(rad, dum2); rad = abs(rad - cx); } v->Constrain(e.x, e.y); sp = new SlidingPin(nil, nil, e.x, e.y, rad, e.x, e.y); return new DragManip(v, sp, rel, tool, Gravity); }
Manipulator* PadView::CreateConnectManip ( Viewer* v, Event&, Transformer* rel, Tool* tool ) { Selection* s = v->GetSelection(); RubberGroup* rg = new RubberGroup(nil, nil); Coord l, b, r, t; s->Clear(); GetGraphic()->GetBox(l, b, r, t); Coord cx = (l+r)/2; Coord cy = (b+t)/2; rg->Append( new SlidingRect(nil, nil, l, b, r, t, cx, cy), new SlidingLine(nil, nil, l, b, r, t, cx, cy), new SlidingLine(nil, nil, l, t, r, b, cx, cy), new RubberLine(nil, nil, cx, cy, cx, cy) ); return new ConnectManip(v, rg, rel, tool); }
Manipulator* PinView::CreateConnectManip ( Viewer* v, Event& e, Transformer* rel, Tool* tool ) { GraphicView* views = v->GetGraphicView(); Selection* s = v->GetSelection(); RubberGroup* rg = new RubberGroup(nil, nil); Coord cx = 0, rad = PIN_RAD, dum1 = 0, dum2 = 0; s->Clear(); if (rel != nil) { rel->Transform(cx, dum1); rel->Transform(rad, dum2); rad = abs(rad - cx); } rg->Append( new SlidingPin(nil, nil, e.x, e.y, rad, e.x, e.y), new RubberLine(nil, nil, e.x, e.y, e.x, e.y) ); return new ConnectManip(v, rg, rel, tool); }
Manipulator* SelectTool::CreateManipulator ( Viewer* v, Event& e, Transformer* rel ) { Manipulator* m = nil; GraphicView* views = v->GetGraphicView(); Selection* s = v->GetSelection(), *newSel; newSel = views->ViewIntersecting(e.x-SLOP, e.y-SLOP, e.x+SLOP, e.y+SLOP); if (e.shift) { Localize(s, v); } else { s->Clear(); } if (newSel->IsEmpty()) { // select w/RubberRect if nothing hit m = new DragManip(v, new RubberRect(nil,nil, e.x,e.y,e.x,e.y), rel); } else { // else user selected object directly s->Exclusive(newSel); } delete newSel; return m; }
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); }
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 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); } }