Esempio n. 1
0
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);
    }
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
Manipulator* TabTool::CreateManipulator (
    Viewer* v, Event& e, Transformer* rel
) {
    Iterator i;
    Selection* s = v->GetSelection();
    s->First(i);
    GraphicView* gv = s->GetView(i);
    return gv->CreateManipulator(v, e, rel, this);
}
Esempio n. 4
0
Command* ScaleTool::InterpretManipulator (Manipulator* m) {
    Selection* s;
    Command* cmd = nil;
    Iterator i;
    
    if (m != nil) {
        s = m->GetViewer()->GetSelection();
        s->First(i);
        cmd = s->GetView(i)->InterpretManipulator(m);
    }
    return cmd;
}
Esempio n. 5
0
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;
    }
}
Esempio n. 6
0
Command* MoveTool::InterpretManipulator (Manipulator* m) {
    Selection* s;
    Command* cmd = nil;
    Iterator i;
    GraphicView* gv;

    if (m != nil) {
        s = m->GetViewer()->GetSelection();
        s->First(i);
        gv = s->GetView(i);

        if (s->Number() > 1) {
            cmd = gv->GraphicView::InterpretManipulator(m);
        } else {
            cmd = gv->InterpretManipulator(m);
        }
    }
    return cmd;
}
Esempio n. 7
0
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();
    }
}
Esempio n. 8
0
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;
    }
}
Esempio n. 9
0
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;
}
Esempio n. 10
0
void LinkSelection::Reserve() {
#if 0
  fprintf(stderr, "LinkSelection::Reserve\n");
#endif
  CompIdTable* table = ((DrawServ*)unidraw)->compidtable();

  /* clear anything that was in the previous selection, but not in this one */
  Selection* lastsel = _editor->last_selection();
  if (!lastsel) return;
  Iterator lt;
  lastsel->First(lt);
  Iterator it;
  while (!lastsel->Done(lt)) {
    First(it);
    boolean match = false;
    while (!Done(it) && !match) {
      if(GetView(it)==lastsel->GetView(lt)) 
	match = true;
      else 
	Next(it);
    }
    if (!match) {
      OverlayComp* comp = ((OverlayView*)lastsel->GetView(lt))->GetOverlayComp();
      void* ptr = nil;
      table->find(ptr, (void*)comp);
      if (ptr) {
	GraphicId* grid = (GraphicId*)ptr;
	grid->selected(NotSelected);
	((DrawServ*)unidraw)->grid_message(grid);
      }
    }
    lastsel->Remove(lt);
  }


  /* remove anything from selection that has a remote selector */
  First(it);
  while (!Done(it)) {
    int removed = false;
    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->selector() && 
	  ((DrawServ*)unidraw)->sessionid()!=grid->selector()) {
	
	Remove(it);
	removed = true;
	
	if (grid->selected()==NotSelected) {
	  
	  /* make a request to select this in the future */
	  grid->selected(WaitingToBeSelected);
	  ((DrawServ*)unidraw)->grid_message(grid);
	} 
	
      } else {
	if (grid->selected()!=LocallySelected) {
	  grid->selected(LocallySelected);
	  ((DrawServ*)unidraw)->grid_message(grid);
	}
      }
      
    }
    if (!removed) 
      Next(it);
  }

  /* store copy of selection */
  First(it);
  while (!Done(it)) {
    lastsel->Append(GetView(it));
    Next(it);
  }
}
Esempio n. 11
0
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);
}