Ejemplo n.º 1
0
int ChFunctionOptvarToolsJS::VectorToOptVariables(ChFunction* funct, ChMatrix<>* mv, int offset)
{
	ChList<chjs_propdata>    mtree;
	ChList<chjs_fullnamevar> mlist;
	double mval=0;
	int    ind= 0;
	jsval vp;

	funct->MakeOptVariableTree(&mtree);
	funct->VariableTreeToFullNameVar(&mtree, &mlist);

	ChGLOBALS_JS().chjsEngine->chjs_contextclass = chjs_cast_funct(funct);
	ChGLOBALS_JS().chjsEngine->chjs_contextdata  = funct;	// *** ...INTO CONTEXT

	for (ChNode<chjs_fullnamevar>* mnode = mlist.GetHead(); mnode; mnode=mnode->next)
	{
		jsdouble jsd = mv->GetElement(offset+ind,0);
		JS_NewDoubleValue(ChGLOBALS_JS().chjsEngine->cx, jsd, &vp);
		JS_SetProperty(ChGLOBALS_JS().chjsEngine->cx, ChGLOBALS_JS().chjsEngine->jglobalObj, mnode->data->propname, &vp);
		ind++;
	}

	ChGLOBALS_JS().chjsEngine->chjs_contextclass = NULL;
	ChGLOBALS_JS().chjsEngine->chjs_contextdata  = NULL;	// *** ...OUT FROM CONTEXT

	return ind;
}
Ejemplo n.º 2
0
DEF_JS_FUNCTION(jsSqrMean, ChFunction*, 3)
  PARCHK(0, &chjs_double);
  PARCHK(1, &chjs_double);
  PARCHK(2, &chjs_double);
  chjs_from_double(cx, rval, this_data->Compute_sqrmean( chjs_to_double(cx, argv+0),  chjs_to_double(cx, argv+1),  chjs_to_double(cx, argv+2), 0  ));
DEF_JS_FUNEND

DEF_JS_FUNCTION(jsInt, ChFunction*, 3)
  PARCHK(0, &chjs_double);
  PARCHK(1, &chjs_double);
  PARCHK(2, &chjs_double);
  chjs_from_double(cx, rval, this_data->Compute_int( chjs_to_double(cx, argv+0),  chjs_to_double(cx, argv+1),  chjs_to_double(cx, argv+2), 0  ));
DEF_JS_FUNEND

DEF_JS_FUNCTION(jsOptVarTree, ChFunction*, 0)
  ChList<chjs_propdata> mylist;
  this_data->MakeOptVariableTree(&mylist);
  chjs_print_objtree(cx, 0, &mylist);
  mylist.KillAll();
DEF_JS_FUNEND

DEF_JS_FUNCTION(jsOptVarList, ChFunction*, 0)
  ChList<chjs_propdata> mytree;
  ChList<chjs_fullnamevar> mylist;
  this_data->MakeOptVariableTree(&mytree);
  ChFunction::VariableTreeToFullNameVar(&mytree,&mylist);
  ChNode<chjs_fullnamevar>* mynode = mylist.GetHead();
  while (mynode)
  {

	  CHGLOBALS_JS().chjsEngine->chjs_Print(mynode->data->propname);