void CreateClosedSplineFunc::execute() { ComValue& vect = stack_arg(0); if (!vect.is_type(ComValue::ArrayType) || vect.array_len()==0) { reset_stack(); push_stack(ComValue::nullval()); return; } const int len = vect.array_len(); const int npts = len/2; int x[npts]; int y[npts]; ALIterator i; AttributeValueList* avl = vect.array_val(); avl->First(i); for (int j=0; j<npts && !avl->Done(i); j++) { x[j] = avl->GetAttrVal(i)->int_val(); avl->Next(i); y[j] = avl->GetAttrVal(i)->int_val(); avl->Next(i); } AttributeList* al = stack_keys(); Resource::ref(al); reset_stack(); PasteCmd* cmd = nil; if (npts) { BrushVar* brVar = (BrushVar*) _ed->GetState("BrushVar"); PatternVar* patVar = (PatternVar*) _ed->GetState("PatternVar"); ColorVar* colVar = (ColorVar*) _ed->GetState("ColorVar"); Transformer* rel = get_transformer(al); ArrowVar* aVar = (ArrowVar*) _ed->GetState("ArrowVar"); SFH_ClosedBSpline* closedspline = new SFH_ClosedBSpline(x, y, npts, stdgraphic); if (brVar != nil) closedspline->SetBrush(brVar->GetBrush()); if (patVar != nil) closedspline->SetPattern(patVar->GetPattern()); if (colVar != nil) { closedspline->FillBg(!colVar->GetBgColor()->None()); closedspline->SetColors(colVar->GetFgColor(), colVar->GetBgColor()); } closedspline->SetTransformer(rel); Unref(rel); ClosedSplineOvComp* comp = new ClosedSplineOvComp(closedspline); comp->SetAttributeList(al); if (PasteModeFunc::paste_mode()==0) cmd = new PasteCmd(_ed, new Clipboard(comp)); ComValue compval(new OverlayViewRef(comp), symbol_add("ClosedSplineComp")); push_stack(compval); execute_log(cmd); } else push_stack(ComValue::nullval()); Unref(al); }
void ClosedSplineComp::Read (istream& in) { VerticesComp::Read(in); Coord* x, *y; int count; ReadVertices(in, x, y, count); SFH_ClosedBSpline* spline = new SFH_ClosedBSpline(x, y, count); delete x; delete y; spline->FillBg(ReadBgFilled(in)); PSColor* fg = ReadColor(in); PSColor* bg = ReadColor(in); spline->SetColors(fg, bg); spline->SetBrush(ReadBrush(in)); spline->SetPattern(ReadPattern(in)); Transformer* t = ReadTransformer(in); spline->SetTransformer(t); Unref(t); SetGraphic(spline); }
Command* ClosedSplineView::InterpretManipulator (Manipulator* m) { DragManip* dm = (DragManip*) m; Editor* ed = dm->GetViewer()->GetEditor(); Tool* tool = dm->GetTool(); Transformer* rel = dm->GetTransformer(); Command* cmd = nil; if (tool->IsA(GRAPHIC_COMP_TOOL)) { GrowingVertices* gv = (GrowingVertices*) dm->GetRubberband(); Coord* x, *y; int n, pt; gv->GetCurrent(x, y, n, pt); if (n > 2 || x[0] != x[1] || y[0] != y[1]) { BrushVar* brVar = (BrushVar*) ed->GetState("BrushVar"); PatternVar* patVar = (PatternVar*) ed->GetState("PatternVar"); ColorVar* colVar = (ColorVar*) ed->GetState("ColorVar"); if (rel != nil) { rel = new Transformer(rel); rel->Invert(); } Graphic* pg = GetGraphicComp()->GetGraphic(); SFH_ClosedBSpline* cbs = new SFH_ClosedBSpline(x, y, n, pg); if (brVar != nil) cbs->SetBrush(brVar->GetBrush()); if (patVar != nil) cbs->SetPattern(patVar->GetPattern()); if (colVar != nil) { cbs->SetColors(colVar->GetFgColor(), colVar->GetBgColor()); } cbs->SetTransformer(rel); Unref(rel); cmd = new PasteCmd(ed, new Clipboard(new ClosedSplineComp(cbs))); } delete x; delete y; } else if (tool->IsA(RESHAPE_TOOL)) { GrowingVertices* gv = (GrowingVertices*) dm->GetRubberband(); Coord* x, *y; int n, pt; gv->RemoveVertex(); gv->GetCurrent(x, y, n, pt); if (rel != nil) { rel = new Transformer(rel); rel->Invert(); } SFH_ClosedBSpline* cbs = new SFH_ClosedBSpline(x, y, n, GetGraphic()); delete x; delete y; cbs->SetTransformer(rel); Unref(rel); cmd = new ReplaceCmd(ed, new ClosedSplineComp(cbs)); } else { cmd = VerticesView::InterpretManipulator(m); } return cmd; }