Exemplo n.º 1
-1
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;
}