Exemple #1
0
void SCA_ExpressionController::Trigger(SCA_LogicManager* logicmgr)
{

	bool expressionresult = false;
	if (!m_exprCache)
	{
		CParser parser;
		parser.SetContext(this->AddRef());
		m_exprCache = parser.ProcessText(m_exprText);
	}
	if (m_exprCache)
	{
		CValue* value = m_exprCache->Calculate();
		if (value)
		{
			if (value->IsError())
			{
				printf("%s\n", value->GetText().ReadPtr());
			} else
			{
				float num = (float)value->GetNumber();
				expressionresult = !MT_fuzzyZero(num);
			}
			value->Release();

		}
	}

	for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
	!(i==m_linkedactuators.end());i++)
	{
		SCA_IActuator* actua = *i;
		logicmgr->AddActiveActuator(actua,expressionresult);
	}
}
Exemple #2
0
double CArg(CValue a_c)
{
	double pi_2 = 1.570796326795;
	double b    = 180/(2*pi_2);
    double x = a_c.real();
    double y = a_c.imag();
	double a;
	double s_x = (x != 0.0) ? x/fabs(x) : 1.0;
	double s_y = (y != 0.0) ? y/fabs(y) : 1.0;
    if(x != 0.0)
    {  a = atan(fabs(y)/fabs(x));
	   if(s_x < 0 && s_y > 0)
	      a = 2*pi_2 - a;
	   if(s_x < 0 && s_y < 0)
	      a = a - 2*pi_2;
	   if(s_x > 0 && s_y < 0)
	      a = -a;
	   return(a*b);
	}
    else
    {  if(y == 0)
	      return(0.);
       if(s_y > 0)
		  a = pi_2;
	   else
		  a = -pi_2;
	   return(a*b);
    }
}
Exemple #3
0
void CDynControl::CreateMicroForm()
{
	CString csFileName;
	if(m_csObjName.Find(":")==1||m_csObjName.Left(2)=="\\\\")
		csFileName=m_csObjName;

	CValue FormParam;
	FormParam.CreateObject("Структура");//String("Микроформа");
	FormParam.SetAt("Микроформа",m_Property);
	CMicroForm* pControl = new CMicroForm();
	pControl->m_bConfigMode=m_bConfigMode;
	pControl->m_csObjName=m_csObjName;
	
	//eventVal - хранится контекст формы
	OpenFormExt(m_csObjName,eventVal,FormParam,csFileName,"",0, 0,0,FormParam, pControl,m_pParentWnd);
	//OpenFormExt(m_csObjName,eventVal,CValue(),csFileName,"",0, 0,0,FormParam, pControl,m_pParentWnd);

	if(m_bVisible||m_bConfigMode)
		pControl->ShowWindow(SW_SHOW);

	m_pWnd = pControl;
	m_hWnd = pControl->GetSafeHwnd();

	pControl->SetDlgCtrlID(m_nID);
	pControl->SetFont(&m_fontDefault);	

	FillDataArray();//доп. параметры объекта (задаваемые из конфигуратора)
}
Exemple #4
0
void CValue::ProcessReplica() /* was AddDataToReplica in 2.48 */
{
	m_refcount = 1;
	
#ifdef _DEBUG
	//gRefCountValue++;
#endif
	PyObjectPlus::ProcessReplica();

	m_ValFlags.RefCountDisabled = false;

	/* copy all props */
	if (m_pNamedPropertyArray)
	{
		std::map<STR_String,CValue*> *pOldArray = m_pNamedPropertyArray;
		m_pNamedPropertyArray=NULL;
		std::map<STR_String,CValue*>::iterator it;
		for (it= pOldArray->begin(); (it != pOldArray->end()); it++)
		{
			CValue *val = (*it).second->GetReplica();
			SetProperty((*it).first,val);
			val->Release();
		}
	}
}
Exemple #5
0
void SCA_KeyboardSensor::LogKeystrokes()
{
	CValue *tprop = GetParent()->GetProperty(m_targetprop);

	SCA_IInputDevice *inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice();

	std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
	const std::wstring typedtext = inputdev->GetText();
	std::wstring proptext = converter.from_bytes(tprop->GetText());

	/* Convert all typed key in the prop string, if the key are del or
	 * backspace we remove the last string item.
	 */
	for (std::wstring::const_iterator it = typedtext.begin(), end = typedtext.end(); it != end; ++it) {
		const wchar_t item = *it;
		if (item == '\b' || item == 127) {
			if (proptext.size()) {
				proptext.resize(proptext.size() - 1);
			}
		}
		else if (item == '\r') {
			// Do nothing
		}
		else {
			proptext.push_back(item);
		}
	}

	CStringValue *newstringprop = new CStringValue(converter.to_bytes(proptext), m_targetprop);
	GetParent()->SetProperty(m_targetprop, newstringprop);
	newstringprop->Release();
}
Exemple #6
0
CValue*	CValue::FindIdentifier(const STR_String& identifiername)
{

	CValue* result = NULL;

	int pos = 0;
	// if a dot exists, explode the name into pieces to get the subcontext
	if ((pos=identifiername.Find('.'))>=0)
	{
		const STR_String rightstring = identifiername.Right(identifiername.Length() -1 - pos);
		const STR_String leftstring = identifiername.Left(pos);
		CValue* tempresult = GetProperty(leftstring);
		if (tempresult)
		{
			result=tempresult->FindIdentifier(rightstring);
		} 
	} else
	{
		result = GetProperty(identifiername);
		if (result)
			return result->AddRef();
	}
	if (!result)
	{
		// warning here !!!
		result = new CErrorValue(identifiername+" not found");
	}
	return result;
}
Exemple #7
0
SCA_PropertySensor::SCA_PropertySensor(SCA_EventManager* eventmgr,
									 SCA_IObject* gameobj,
									 const STR_String& propname,
									 const STR_String& propval,
									 const STR_String& propmaxval,
									 KX_PROPSENSOR_TYPE checktype)
	: SCA_ISensor(gameobj,eventmgr),
	  m_checktype(checktype),
	  m_checkpropval(propval),
	  m_checkpropmaxval(propmaxval),
	  m_checkpropname(propname),
	  m_range_expr(NULL)
{
	//CParser pars;
	//pars.SetContext(this->AddRef());
	//CValue* resultval = m_rightexpr->Calculate();

	CValue* orgprop = GetParent()->FindIdentifier(m_checkpropname);
	if (!orgprop->IsError())
	{
		m_previoustext = orgprop->GetText();
	}
	orgprop->Release();

	if (m_checktype==KX_PROPSENSOR_INTERVAL)
	{
		PrecalculateRangeExpression();
	}
	Init();
}
SICALLBACK VDB_Node_VolumeToMesh_BeginEvaluate(ICENodeContext& ctxt)
{
   Application().LogMessage(L"[VDB_Node_VolumeToMesh] BeginEvaluate");

   CValue userData = ctxt.GetUserData();
   VDB_Node_VolumeToMesh* vdbNode;
   if (userData.IsEmpty())
   {
      vdbNode = new VDB_Node_VolumeToMesh;
   }
   else
   {
      vdbNode = (VDB_Node_VolumeToMesh*)(CValue::siPtrType)userData;
   }

   CICEPortState vdbGridPortState(ctxt, kVDBGrid);
   CICEPortState isoPortState(ctxt, kIsoValue);
   CICEPortState adaptPortState(ctxt, kAdaptivity);

   bool vdbGridDirty = vdbGridPortState.IsDirty(CICEPortState::siAnyDirtyState);
   bool isoDirty = isoPortState.IsDirty(CICEPortState::siAnyDirtyState);
   bool adaptDirty = adaptPortState.IsDirty(CICEPortState::siAnyDirtyState);

   vdbGridPortState.ClearState();
   isoPortState.ClearState();
   adaptPortState.ClearState();

   if (vdbGridDirty || isoDirty || adaptDirty)
   {
      vdbNode->Cache(ctxt);
   }

   ctxt.PutUserData((CValue::siPtrType)vdbNode);
   return CStatus::OK;
}
static PyObject *listvalue_buffer_item(PyObject *self, Py_ssize_t index)
{
	CListValue *list= static_cast<CListValue *>(BGE_PROXY_REF(self));
	CValue *cval;
	
	if (list==NULL) {
		PyErr_SetString(PyExc_SystemError, "val = CList[i], "BGE_PROXY_ERROR_MSG);
		return NULL;
	}
	
	int count = list->GetCount();
	
	if (index < 0)
		index = count+index;
	
	if (index < 0 || index >= count) {
		PyErr_SetString(PyExc_IndexError, "CList[i]: Python ListIndex out of range in CValueList");
		return NULL;
	}
	
	cval= list->GetValue(index);
	
	PyObject *pyobj = cval->ConvertValueToPython();
	if (pyobj)
		return pyobj;
	else
		return cval->GetProxy();
}
Exemple #10
0
PyObject *CListValue::Pyindex(PyObject *value)
{
	PyObject *result = NULL;

	CValue* checkobj = ConvertPythonToValue(value, "val = cList[i]: CValueList, ");
	if (checkobj==NULL)
		return NULL; /* ConvertPythonToValue sets the error */

	int numelem = GetCount();
	for (int i=0;i<numelem;i++)
	{
		CValue* elem = GetValue(i);
		if (checkobj==elem || CheckEqual(checkobj,elem))
		{
			result = PyLong_FromLong(i);
			break;
		}
	}
	checkobj->Release();

	if (result==NULL) {
		PyErr_SetString(PyExc_ValueError, "CList.index(x): x not in CListValue");
	}
	return result;

}
Exemple #11
0
CValue* CIfExpr::Calculate()
/*
pre:
ret: a new object containing the value of m_e1 if m_guard is a boolean TRUE
	 a new object containing the value of m_e2 if m_guard is a boolean FALSE
	 an new errorvalue if m_guard is not a boolean
*/
{
	CValue *guardval;
	guardval = m_guard->Calculate();
	const STR_String& text = guardval->GetText();
	guardval->Release();

	if (&text == &CBoolValue::sTrueString)
	{
		return m_e1->Calculate();
	}
	else if (&text == &CBoolValue::sFalseString)
	{
		return m_e2->Calculate();
	}
	else
	{
		return new CErrorValue("Guard should be of boolean type");
	}
}
Exemple #12
0
BOOL SetVariable( CStr &varName, CValue value )
{
	VarError.Empty();
	int		pos;
	CValue *val;
	if ( varName.GetLength() > 0 && varName.GetAt(0) == L'[' )
	{
		CStr expression = varName.Mid( 1 );
		CInterpreter parser;
		CValue result = parser.EvaluateExpression( expression, FALSE );

		int subPos = parser.GetErrorPosition();
		if ( parser.GetError() != 0 )
		{
			VarError = CStr( L"Error in variable reference: " ) + parser.GetErrorMessage();
			return FALSE;
		}

		if ( expression[subPos] != L']' )
		{
			VarError = L"Variable reference not closed (missing ']')";
			return FALSE;
		}

		val = GetVariable( (CStr)result, TRUE, &pos );
	}
	else{
		val = GetVariable( varName, TRUE, &pos );
	}

	val->CopyFrom( value );
	return (pos != -1);
}
CValue* SCA_DelaySensor::GetReplica()
{
	CValue* replica = new SCA_DelaySensor(*this);
	// this will copy properties and so on...
	replica->ProcessReplica();

	return replica;
}
Exemple #14
0
CValue* SCA_ILogicBrick::Calc(VALUE_OPERATOR op, CValue *val)
{
	CValue* temp = new CBoolValue(false,"");
	CValue* result = temp->Calc(op,val);
	temp->Release();

	return result;
} 
Exemple #15
0
CValue* SCA_AlwaysSensor::GetReplica()
{
	CValue* replica = new SCA_AlwaysSensor(*this);//m_float,GetName());
	// this will copy properties and so on...
	replica->ProcessReplica();

	return replica;
}
Exemple #16
0
float CValue::GetPropertyNumber(const STR_String& inName,float defnumber)
{
	CValue *property = GetProperty(inName);
	if (property)
		return property->GetNumber(); 
	else
		return defnumber;
}
Exemple #17
0
CValue* SCA_ANDController::GetReplica()
{
	CValue* replica = new SCA_ANDController(*this);
	// this will copy properties and so on...
	replica->ProcessReplica();

	return replica;
}
Exemple #18
0
BOOL ClearVariable( CStr &varName )
{
	VarError.Empty();
	int pos;
	CValue *val = GetVariable( varName, TRUE, &pos );
	if ( val != NULL )
		val->Clear();
	return (pos != -1);
}
Exemple #19
0
/*Attribute functions */
PyObject* SCA_ILogicBrick::pyattr_get_owner(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
{
	SCA_ILogicBrick* self= static_cast<SCA_ILogicBrick*>(self_v);
	CValue* parent = self->GetParent();
	
	if (parent)
		return parent->GetProxy();
	
	Py_RETURN_NONE;
}
Exemple #20
0
//
// Get text description of property with name <inName>, returns an empty string if there is no property named <inName>
//
const STR_String& CValue::GetPropertyText(const STR_String & inName)
{
	const static STR_String sEmpty("");

	CValue *property = GetProperty(inName);
	if (property)
		return property->GetText();
	else
		return sEmpty;
}
Exemple #21
0
CValue* SCA_ILogicBrick::CalcFinal(VALUE_DATA_TYPE dtype,
								   VALUE_OPERATOR op,
								   CValue *val)
{
	// same as bool implementation, so...
	CValue* temp = new CBoolValue(false,"");
	CValue* result = temp->CalcFinal(dtype,op,val);
	temp->Release();

	return result;
}
Exemple #22
0
STDMETHODIMP CConnect::Test(int a)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState())

	// TODO: Add your implementation code here

	CValue Val;
	Val=a;
	AfxMessageBox(Val.GetString());

	return S_OK;
}
	Ptr<ISubtitlesItem> CPangoCairoRenderer::render(Ptr<ISubtitlesItem> i_item)
	{
		Ptr<CSubtitlesTextItem> text = i_item;

		if (text.isNull() || i_item->getType() != SUBTITLES_TYPE_TEXT)
		{
			return Ptr<ISubtitlesItem>();
		}

		Ptr<CCairoSurface> surface = new CCairoSurface(m_displaySize.Height, m_displaySize.Width, SURFACE_FORMAT_ARGB32);

		cairo_t * cairo = cairo_create(surface->getSurface());
		
		cairo_set_source_rgba(cairo, 0.0, 0.0, 0.0, 0.0);
		cairo_paint(cairo);
		
		PangoLayout * layout = pango_cairo_create_layout(cairo);

		pango_layout_set_width(layout, m_displaySize.Width*PANGO_SCALE);
		pango_layout_set_wrap(layout, PANGO_WRAP_WORD);
		pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
		pango_layout_set_text(layout, text->getText().c_str(), -1);

		PangoFontDescription * font = pango_font_description_from_string(m_font.c_str());
		pango_layout_set_font_description(layout, font);
		pango_font_description_free(font);

		cairo_set_source_rgb(cairo, 1.0, 1.0, 1.0);

		pango_cairo_update_layout(cairo, layout);
		pango_cairo_show_layout(cairo, layout);

		CValue<CRectangle> rect = getPixelRectangle(layout);
		
		cairo_destroy(cairo);

		g_object_unref(layout);

		if (rect.isValid())
		{

			Ptr<CCairoSurface> textSurface = new CCairoSurface(*surface, rect.getValue()); 
			
			CSize size = rect.getValue().Size;
			CPoint position = computePosition(size);
			CRectangle newRect(position, size);
			
			return new CSubtitlesGraphicsItem(textSurface, newRect, text->getBeginTime(), text->getEndTime());
		}

		return Ptr<ISubtitlesItem>();
	}
Exemple #24
0
void CObjectData::LoadData(CValue &Val)
{
	if(Val.GetSizeStrArray())
	{
		sType=Val.GetAt("Тип").GetString();
		nLength=Val.GetAt("Длина");
		nPrec=Val.GetAt("Точность");
/*
		nChildImage=Val.GetAt("ChildImage");
		bEdit=Val.GetAt("Edit");
		bGroup=Val.GetAt("Group");
		nType=Val.GetAt("Type");
*/
	}
}
Exemple #25
0
CValue * COperator1Expr::Calculate()
/*
pre:
ret: a new object containing the result of applying the operator m_op to the
	 value of m_lhs
*/
{
	CValue *ret;
	CValue *temp = m_lhs->Calculate();
	CValue* empty = new CEmptyValue();
	ret = empty->Calc(m_op, temp);
	empty->Release();
	temp->Release();
	
	return ret;
}
Exemple #26
0
int SCA_ILogicBrick::CheckProperty(void *self, const PyAttributeDef *attrdef)
{
	if (attrdef->m_type != KX_PYATTRIBUTE_TYPE_STRING || attrdef->m_length != 1) {
		PyErr_SetString(PyExc_AttributeError, "inconsistent check function for attribute type, report to blender.org");
		return 1;
	}
	SCA_ILogicBrick* brick = reinterpret_cast<SCA_ILogicBrick*>(self);
	STR_String* var = reinterpret_cast<STR_String*>((char*)self+attrdef->m_offset);
	CValue* prop = brick->GetParent()->FindIdentifier(*var);
	bool error = prop->IsError();
	prop->Release();
	if (error) {
		PyErr_SetString(PyExc_ValueError, "string does not correspond to a property");
		return 1;
	}
	return 0;
}
Exemple #27
0
bool CListValue::CheckEqual(CValue* first,CValue* second)
{
	bool result = false;

	CValue* eqval =  ((CValue*)first)->Calc(VALUE_EQL_OPERATOR,(CValue*)second);

	if (eqval==NULL)
		return false;
	const STR_String& text = eqval->GetText();
	if (&text==&CBoolValue::sTrueString)
	{
		result = true;
	}
	eqval->Release();
	return result;

}
Exemple #28
0
BOOL CValueToolBar::GetMainTool(CValue &rez,CValue**p)
{

	rez.CreateObject(GetTypeString());
	((CValueToolBar*)rez.pRef)->Attach(&pMainFrame->m_ToolMain);
	((CValueToolBar*)rez.pRef)->m_csName="ќбща¤ панель инструментов";
	return TRUE;
};
Exemple #29
0
BOOL CValueToolBar::GetModuleTool(CValue &rez,CValue**p)
{

	rez.CreateObject(GetTypeString());
	((CValueToolBar*)rez.pRef)->Attach(&pMainFrame->m_ToolModule);
	((CValueToolBar*)rez.pRef)->m_csName="ѕанель инструментов модул¤";
	return TRUE;
};
Exemple #30
0
BOOL CValueToolBar::GetEditTool(CValue &rez,CValue**p)
{

	rez.CreateObject(GetTypeString());
	((CValueToolBar*)rez.pRef)->Attach(&pMainFrame->m_ToolEdit);
	((CValueToolBar*)rez.pRef)->m_csName="ѕанель инструментов формы";
	return TRUE;
};