Ejemplo n.º 1
0
void GrAttrListFunc::execute() {
  ComValue compviewv(stack_arg(0));
  reset_stack();
  if (compviewv.object_compview()) {
    ComponentView* compview = (ComponentView*)compviewv.obj_val();
    OverlayComp* comp = compview ? (OverlayComp*)compview->GetSubject() : nil;
    if (comp) {
      ComValue retval(AttributeList::class_symid(), (void*)comp->GetAttributeList());
      push_stack(retval);
    } else
      push_stack(ComValue::nullval());
  }
}
Ejemplo n.º 2
0
void GrDotFunc::execute() {

    ComValue& before_part(stack_arg(0, true));
    ComValue& after_part(stack_arg(1, true));
    if (!before_part.is_symbol() && 
	!(before_part.is_attribute() && ((Attribute*)before_part.obj_val())->Value()->is_attributelist()) &&
	!(before_part.object_compview())) {
      cerr << "expression before \".\" needs to evaluate to a symbol or <AttributeList> or <Component>\n";
      return;
    }
    if (!after_part.is_symbol()) {
      cerr << "expression after \".\" needs to be a symbol or evaluate to a symbol\n";
      reset_stack();
      return;
    }

    /* handle ComponentView case */
    if (before_part.is_symbol()) 
      lookup_symval(before_part);
    if (before_part.is_object() && before_part.object_compview()) {
      ComponentView* compview = (ComponentView*)before_part.obj_val();
      OverlayComp* comp = (OverlayComp*)compview->GetSubject();
      if (comp) {
	ComValue stuffval(AttributeList::class_symid(), (void*)comp->GetAttributeList());
	before_part.assignval(stuffval);
      } else {
	cerr << "nil subject on compview value\n";
	reset_stack();
	push_stack(ComValue::nullval());
	return;
      }

    }
    DotFunc::execute();
    
}
Ejemplo n.º 3
0
void DrawServ::ExecuteCmd(Command* cmd) {
  static int grid_sym = symbol_add("grid");
  static int sid_sym = symbol_add("sid");
  boolean original = false;
  unsigned int from_sid = 0;

  if(!_linklist || _linklist->Number()==0) 

    /* normal Unidraw command execution */
    Unidraw::ExecuteCmd(cmd);

  else {

    /* indirect command execution, all by script */
    std::ostrstream sbuf;
    boolean oldflag = OverlayScript::ptlist_parens();
    OverlayScript::ptlist_parens(false);
    switch (cmd->GetClassId()) {
    case PASTE_CMD:
      {
      boolean scripted = false;
      Clipboard* cb = cmd->GetClipboard();
      if (cb) {
	Iterator it;
	for (cb->First(it); !cb->Done(it); cb->Next(it)) {
	  OverlayComp* comp = (OverlayComp*)cb->GetComp(it);
	  AttributeList* al = comp->GetAttributeList();
	  AttributeValue* idv = al->find(grid_sym);
	  AttributeValue* sidv = al->find(sid_sym);
	  from_sid = sidv ? sidv->uint_val() : 0;
	  
	  /* unique id already remotely assigned */
	  if (idv && idv->uint_val() !=0 && sidv && sidv->uint_val() !=0) {
	    GraphicId* graphicid = new GraphicId();
	    graphicid->grcomp(comp);
	    graphicid->id(idv->uint_val());
	    graphicid->selector(sidv->uint_val());
	    graphicid->selected(LinkSelection::RemotelySelected);
	  } 
	  
	  /* generate unique id and add as attribute */
	  /* also mark with selector id */
	  else {
	    GraphicId* graphicid = new GraphicId(sessionid());
	    graphicid->grcomp(comp);
	    graphicid->selector(((DrawServ*)unidraw)->sessionid());
	    AttributeValue* gridv = new AttributeValue(graphicid->id(), AttributeValue::UIntType);
	    gridv->state(AttributeValue::HexState);
	    al->add_attr(grid_sym, gridv);
	    AttributeValue* sidv = new AttributeValue(graphicid->selector(), AttributeValue::UIntType);
	    sidv->state(AttributeValue::HexState);
	    al->add_attr(sid_sym, sidv);
	    original = true;
	  }
	    
	  if (comp && (original || linklist()->Number()>1)) {
	    Creator* creator = unidraw->GetCatalog()->GetCreator();
	    OverlayScript* scripter = (OverlayScript*)
	      creator->Create(Combine(comp->GetClassId(), SCRIPT_VIEW));
	    if (scripter) {
	      scripter->SetSubject(comp);
	      if (scripted) 
		sbuf << ';';
	      else 
		scripted = true;
	      boolean status = scripter->Definition(sbuf);
	      delete scripter;
	    }
	  }
	}
      }
      if (original || linklist()->Number()>1) {
	if (!scripted)
	  sbuf << "print(\"Failed attempt to generate script for a PASTE_CMD\\n\" :err)";
	sbuf.put('\0');
	cout << sbuf.str() << "\n";
	cout.flush();
      }

      /* first execute here */
#if 0
      ((ComEditor*)cmd->GetEditor())->GetComTerp()->run(sbuf.str());
      ((PasteCmd*)cmd)->executed(true);
#else
      cmd->Execute();
#endif

      /* then send everywhere else */
      if (original || linklist()->Number()>1) 
	DistributeCmdString(sbuf.str(), linkget(from_sid));
      
      }
      break;
    default:
      sbuf << "print(\"Attempt to convert unknown command (id == %d) to interpretable script\\n\" " << cmd->GetClassId() << " :err)";
      cmd->Execute();
      break;
    }

    if (cmd->Reversible()) {
      cmd->Log();
    } else {
      delete cmd;
    }

    OverlayScript::ptlist_parens(oldflag);
  }
}