void python_interpreter::print_greeting() { 
  std::stringstream fs; 
  fs<< "myprint = lambda x : sys.stderr.write(\"%s\\n\"%x)\n" 
   << "myprint ('Compiled on "<<__DATE__<<" at " 
   << __TIME__<<" on machine "<< AS_STRING(__HOSTNAME__)<< " by "<< AS_STRING(__COMPILEDBY__) " ')\n";
  *this<<fs.str();
 }
Caffe::Properties::Properties() :
      init_time_(std::time(nullptr)),
      main_thread_id_(std::this_thread::get_id()),
      caffe_version_(AS_STRING(CAFFE_VERSION)) {
#ifndef CPU_ONLY
  int count = 0;
  CUDA_CHECK(cudaGetDeviceCount(&count));
  compute_capabilities_.resize(count);
  cudaDeviceProp device_prop;
  for (int gpu = 0; gpu < compute_capabilities_.size(); ++gpu) {
    CUDA_CHECK(cudaGetDeviceProperties(&device_prop, gpu));
    compute_capabilities_[gpu] = device_prop.major * 100 + device_prop.minor;
    DLOG(INFO) << "GPU " << gpu << " '" << device_prop.name << "' has compute capability "
        << device_prop.major << "." << device_prop.minor;
  }
#ifdef USE_CUDNN
  cudnn_version_ =
      AS_STRING(CUDNN_MAJOR) "." AS_STRING(CUDNN_MINOR) "." AS_STRING(CUDNN_PATCHLEVEL);
#else
  cudnn_version_ = "USE_CUDNN is not defined";
#endif
  int cublas_version = 0;
  CUBLAS_CHECK(cublasGetVersion(Caffe::cublas_handle(), &cublas_version));
  cublas_version_ = std::to_string(cublas_version);

  int cuda_version = 0;
  CUDA_CHECK(cudaRuntimeGetVersion(&cuda_version));
  cuda_version_ = std::to_string(cuda_version);

  int cuda_driver_version = 0;
  CUDA_CHECK(cudaDriverGetVersion(&cuda_driver_version));
  cuda_driver_version_ = std::to_string(cuda_driver_version);
#endif
}
Exemple #3
0
/**
 * Opens a file in read, write, or append mode.
 *
 * @param args list of args
 * @param c number of args
 * @returns LuciFileObj opened from the filename in the first arg
 */
LuciObject *luci_fopen(LuciObject **args, unsigned int c)
{
    char *filename;
    char *req_mode;
    int mode;
    FILE *file = NULL;

    if (c < 2) {
        LUCI_DIE("%s", "Missing parameter to open()\n");
    }

    LuciObject *fname_obj = args[0];
    if (!ISTYPE(fname_obj, obj_string_t)) {
        LUCI_DIE("%s", "Parameter 1 to open must be a string\n");
    }
    LuciObject *mode_obj = args[1];
    if (!ISTYPE(mode_obj, obj_string_t)) {
        LUCI_DIE("%s", "Parameter 2 to open must be a string\n");
    }

    filename = AS_STRING(fname_obj)->s;
    req_mode = AS_STRING(mode_obj)->s;

    mode = get_file_mode(req_mode);
    if (mode < 0) {
        LUCI_DIE("%s\n", "Invalid mode to open()");
    }

    /*
       Open in read-binary mode and fseek to SEEK_END to
       calculate the file's size in bytes.
       Then close it and reopen it the way the user requests
    */
    long file_length;
    /* store the FILE's byte length */
    if (!(file = fopen(filename, "rb"))) {
        file_length = 0;
    }
    else {
        fseek(file, 0, SEEK_END);
        file_length = ftell(file);
        fseek(file, 0, SEEK_SET);
        close_file(file);
    }

    if (!(file = fopen(filename, req_mode)))
    {
        LUCI_DIE("Could not open file %s\n", filename);
    }

    LuciObject *ret = LuciFile_new(file, file_length, mode);

    LUCI_DEBUG("Opened file %s of size %ld bytes with mode %s.\n",
            filename, file_length, req_mode);

    return ret;
}
void
ObjectPropertyEditor::OnPropertyChanged(wxPropertyGridEvent& e)
{
    // Skip parent properties
    if (e.GetPropertyPtr()->GetParentingType() != 0)
        return;

    // Skip if no current selected object
    Fairy::ObjectPtr object = mCurrentObject.lock();
    if (!object)
        return;

    Ogre::String propertyName = AS_STRING(e.GetPropertyName());
    Ogre::String propertyValue = AS_STRING(e.GetPropertyValueAsString());

	if(propertyName == "position" || propertyName == "scale")
	{
		Ogre::Vector3 vValue = Ogre::StringConverter::parseVector3(propertyValue);
		object->setProperty(propertyName,vValue);
	}
	else if(propertyName == "orientation")
	{
		Ogre::Quaternion qValue = Ogre::StringConverter::parseQuaternion(propertyValue);
		object->setProperty(propertyName,qValue);
	}
	else if(propertyName == "actor name")
	{
		m_Frame->ClearAllSelectorObject();
		m_Frame->GetActorSettingEditor()->SetCurrentObject(Ogre::String(propertyValue.c_str()));
		return;
	}

    mPropertiesViewer->Freeze();

    const Fairy::PropertyList& properties = object->getProperties();
    for (Fairy::PropertyList::const_iterator it = properties.begin(); it != properties.end(); ++it)
    {
        const Fairy::PropertyDef& propertyDef = *it;
        Fairy::uint propertyFlags = object->getPropertyFlags(propertyDef.name);
        wxPGId id = mPropertiesViewer->GetPropertyByName(propertyDef.name.c_str());
        assert(id.IsOk());
        if (!id.IsOk())
            continue;
        if (propertyFlags & Fairy::PF_READONLY)
        {
            if (mPropertiesViewer->IsPropertyEnabled(id))
                mPropertiesViewer->DisableProperty(id);
        }
        else
        {
            if (!mPropertiesViewer->IsPropertyEnabled(id))
                mPropertiesViewer->EnableProperty(id);
        }
    }

    mPropertiesViewer->Thaw();
}
void
ObjectPropertyEditor::OnPropertyChanged(wxPropertyGridEvent& e)
{
    // Skip parent properties
    if (e.GetPropertyPtr()->GetParentingType() != 0)
        return;

    // Skip if no current selected object
    WX::ObjectPtr object = mCurrentObject.lock();
    if (!object)
        return;

    WX::String propertyName = AS_STRING(e.GetPropertyName());
    WX::String propertyValue = AS_STRING(e.GetPropertyValueAsString());

    WX::Variant oldValue = object->getProperty(propertyName);
    object->setPropertyAsString(propertyName, propertyValue);
    mSceneManipulator->_fireObjectPropertyChanged(object, propertyName, this);
    WX::Variant newValue = object->getProperty(propertyName);

    WX::ModifyObjectPropertyOperator* op = new WX::ModifyObjectPropertyOperator(mSceneManipulator);
    op->add(object->getName(), propertyName, oldValue, newValue);
    mSceneManipulator->getOperatorManager()->addOperator(op);

    mPropertiesViewer->Freeze();

    const WX::PropertyList& properties = object->getProperties();
    for (WX::PropertyList::const_iterator it = properties.begin(); it != properties.end(); ++it)
    {
        const WX::PropertyDef& propertyDef = *it;
        WX::uint propertyFlags = object->getPropertyFlags(propertyDef.name);
        wxPGId id = mPropertiesViewer->GetPropertyByName(propertyDef.name.c_str());
        assert(id.IsOk());
        if (!id.IsOk())
            continue;
        if (propertyFlags & WX::PF_READONLY)
        {
            if (mPropertiesViewer->IsPropertyEnabled(id))
                mPropertiesViewer->DisableProperty(id);
        }
        else
        {
            if (!mPropertiesViewer->IsPropertyEnabled(id))
                mPropertiesViewer->EnableProperty(id);
        }
    }

    mPropertiesViewer->Thaw();
}
bool condition_op_const::eval(record_type& rt, record& r){
	if (offset==-1){
		offset = offset_of_column(rt, lhs_table_name, lhs_column_name);
		if (offset==-1) throw string("Undefined column");
	}
	if (index==-1){
		index = index_of_column(rt, lhs_table_name, lhs_column_name);
		if (index==-1) throw string("Undefined column");
	}

	if (rt[index].type == column_type::INT){

		if (op=="<"){
			return AS_INT(r[offset]) < value.vInt;
		} else if (op=="="){
			return AS_INT(r[offset]) == value.vInt;
		} else if (op==">"){
			return AS_INT(r[offset]) > value.vInt;
		}

		throw string("unimplemented operators in condition_op_const");
	}
	else if(rt[index].type == column_type::FLOAT){

		if (op=="<"){
			return AS_FLOAT(r[offset]) < value.vFloat;
		} else if (op=="="){
			return AS_FLOAT(r[offset]) == value.vFloat;
		} else if (op==">"){
			return AS_FLOAT(r[offset]) > value.vFloat;
		}
		throw string("unimplemented operators in condition_op_const");
	}
	else if(rt[index].type == column_type::STRING){

		if (op=="<"){
			return (strncmp(AS_STRING(r[offset]), value.vString, 500) < 0);
		} else if (op=="="){
			return (strncmp(AS_STRING(r[offset]), value.vString, 500) == 0);
		} else if (op==">"){
			return (strncmp(AS_STRING(r[offset]), value.vString, 500) > 0);
		}

		throw string("unimplemented operators in condition_op_const");
	}
	//throw string("unimplemented datatypes in condition_op_const");

}
Exemple #7
0
/**
 * Writes a given LuciStringObj to a LuciFileObj.
 *
 * @param args list of args
 * @param c number of args
 * @returns LuciNilObj
 */
LuciObject *luci_fwrite(LuciObject **args, unsigned int c)
{
    if (c < 2) {
        LUCI_DIE("%s", "Missing parameter to write()\n");
    }

    /* grab the FILE parameter */
    LuciObject *fobj = args[0];
    if (!fobj || (!ISTYPE(fobj, obj_file_t))) {
        LUCI_DIE("%s", "Not a file object\n");
    }

    /* grab string parameter */
    LuciObject *text_obj = args[1];
    if (!text_obj || (!ISTYPE(text_obj, obj_string_t)) ) {
        LUCI_DIE("%s", "Not a string\n");
    }
    char *text = AS_STRING(text_obj)->s;

    if (AS_FILE(fobj)->mode == f_read_m) {
        LUCI_DIE("%s", "Can't write to  It is opened for reading.\n");
    }

    fwrite(text, sizeof(char), strlen(text), AS_FILE(fobj)->ptr);

    return LuciNilObj;
}
Exemple #8
0
/**
 * Casts a LuciObject to a LuciFloatObj if possible, then returns
 * the new object.
 *
 * @param args list of args
 * @param c number of args
 * @returns LuciFloatObj cast of the first arg
 */
LuciObject *luci_cast_float(LuciObject **args, unsigned int c)
{
    LuciObject *ret = LuciNilObj;
    if (c < 1) {
        LUCI_DIE("%s", "Missing parameter to int()\n");
    }
    LuciObject *item = args[0];

    if (!item) {
        LUCI_DIE("%s", "Can't cast NULL to int\n");
    }

    if (ISTYPE(item, obj_int_t)) {
        ret = LuciFloat_new((double)AS_INT(item)->i);
    } else if (ISTYPE(item, obj_float_t)) {
        ret = LuciFloat_new(AS_FLOAT(item)->f);
    } else if (ISTYPE(item, obj_string_t)) {
        double f;
        int scanned = sscanf(AS_STRING(item)->s, "%f", (float *)&f);
        if (scanned <= 0 || scanned == EOF) {
            LUCI_DIE("%s", "Could not cast to float\n");
        }
        ret = LuciFloat_new(f);
    } else {
        LUCI_DIE("Cannot cast type %s to type float\n", item->type->type_name);
    }

    return ret;
}
Exemple #9
0
/**
 * Asserts that a given LuciObject is equivalent to a boolean True
 *
 * Currently uses C @code assert @endcode , which will exit a program
 * mid-execution if the assertion fails.
 *
 * @param args list of args
 * @param c number of args
 * @returns LuciNilObj
 */
LuciObject *luci_assert(LuciObject **args, unsigned int c)
{
    if (c < 1) {
        LUCI_DIE("%s", "Missing condition parameter to assert()\n");
    }

    LuciObject *item = args[0];

    if (ISTYPE(item, obj_int_t) && !AS_INT(item)->i) {
        LUCI_DIE("%s\n", "Assertion failed");
    } else if (ISTYPE(item, obj_float_t) && !((long)AS_FLOAT(item)->f)) {
        LUCI_DIE("%s\n", "Float assertion failed");
    } else if (ISTYPE(item, obj_string_t)) {
        if (strcmp("", AS_STRING(item)->s) == 0) {
            LUCI_DIE("%s\n", "String assertion failed");
        }
    } else if (ISTYPE(item, obj_list_t) && (AS_LIST(item)->count == 0)) {
        LUCI_DIE("%s\n", "List assertion failed");
    } else if (ISTYPE(item, obj_map_t) && (AS_MAP(item)->count == 0)) {
        LUCI_DIE("%s\n", "Map assertion failed");
    } else if (ISTYPE(item, obj_file_t) && (AS_FILE(item)->ptr)) {
        LUCI_DIE("%s\n", "File assertion failed");
    }
    return LuciNilObj;
}
Exemple #10
0
void SceneBrowser::onRenameObject(const ObjectPtr& object, const String& oldName)
{
    wxTreeItemId item = getObjectTreeItem(object);
    wxASSERT(item.IsOk());

    mObjectsTree->SetItemText(item, AS_STRING(object->getName()));
}
Exemple #11
0
void
BulletSelector::Reload(void)
{
    if (!Ogre::ResourceGroupManager::getSingletonPtr())
        return;

    mBulletFlowList->Freeze();

    mBulletFlowList->ClearAll();
    
	// 添加特效
	// 填充现在的bullet模板的列表
	Fairy::BulletFlowSystemManager::BulletFlowTemplateIterator it =
		Fairy::BulletFlowSystemManager::getSingleton().getBulletFlowTemplateIterator();
	while ( it.hasMoreElements() )
	{
		long index = mBulletFlowList->GetItemCount();

		mBulletFlowList->InsertItem( index, AS_STRING( it.peekNextKey() ) );

		if (it.peekNextKey() == "BulletEmpty")
			mBulletFlowList->SetItemTextColour(index, *wxGREEN);

		it.moveNext();
	}

    mBulletFlowList->Thaw();
}
Exemple #12
0
static void defineMethod(WrenVM* vm, const char* className,
                         const char* methodName, int numParams,
                         WrenForeignMethodFn methodFn, bool isStatic)
{
  ASSERT(className != NULL, "Must provide class name.");

  int length = (int)strlen(methodName);
  ASSERT(methodName != NULL, "Must provide method name.");
  ASSERT(strlen(methodName) < MAX_METHOD_NAME, "Method name too long.");

  ASSERT(numParams >= 0, "numParams cannot be negative.");
  ASSERT(numParams <= MAX_PARAMETERS, "Too many parameters.");

  ASSERT(methodFn != NULL, "Must provide method function.");

  // Find or create the class to bind the method to.
  int classSymbol = wrenSymbolTableFind(&vm->globalNames,
                               className, strlen(className));
  ObjClass* classObj;

  if (classSymbol != -1)
  {
    // TODO: Handle name is not class.
    classObj = AS_CLASS(vm->globals.data[classSymbol]);
  }
  else
  {
    // The class doesn't already exist, so create it.
    size_t length = strlen(className);
    ObjString* nameString = AS_STRING(wrenNewString(vm, className, length));

    WREN_PIN(vm, nameString);

    // TODO: Allow passing in name for superclass?
    classObj = wrenNewClass(vm, vm->objectClass, 0, nameString);
    wrenDefineGlobal(vm, className, length, OBJ_VAL(classObj));

    WREN_UNPIN(vm);
  }

  // Create a name for the method, including its arity.
  char name[MAX_METHOD_SIGNATURE];
  strncpy(name, methodName, length);
  for (int i = 0; i < numParams; i++)
  {
    name[length++] = ' ';
  }
  name[length] = '\0';

  // Bind the method.
  int methodSymbol = wrenSymbolTableEnsure(vm, &vm->methodNames, name, length);

  Method method;
  method.type = METHOD_FOREIGN;
  method.fn.foreign = methodFn;

  if (isStatic) classObj = classObj->obj.classObj;

  wrenBindMethod(vm, classObj, methodSymbol, method);
}
Exemple #13
0
ObjClass* wrenNewClass(WrenVM* vm, ObjClass* superclass, int numFields,
                       ObjString* name)
{
  // Create the metaclass.
  Value metaclassName = wrenStringFormat(vm, "@ metaclass", OBJ_VAL(name));
  wrenPushRoot(vm, AS_OBJ(metaclassName));

  ObjClass* metaclass = wrenNewSingleClass(vm, 0, AS_STRING(metaclassName));
  metaclass->obj.classObj = vm->classClass;

  wrenPopRoot(vm);

  // Make sure the metaclass isn't collected when we allocate the class.
  wrenPushRoot(vm, (Obj*)metaclass);

  // Metaclasses always inherit Class and do not parallel the non-metaclass
  // hierarchy.
  wrenBindSuperclass(vm, metaclass, vm->classClass);

  ObjClass* classObj = wrenNewSingleClass(vm, numFields, name);

  // Make sure the class isn't collected while the inherited methods are being
  // bound.
  wrenPushRoot(vm, (Obj*)classObj);

  classObj->obj.classObj = metaclass;
  wrenBindSuperclass(vm, classObj, superclass);

  wrenPopRoot(vm);
  wrenPopRoot(vm);

  return classObj;
}
Exemple #14
0
void
MaterialSelector::Reload(void)
{
    if (!Ogre::ResourceGroupManager::getSingletonPtr())
        return;

	
	wxBusyInfo* busyInfo = new wxBusyInfo(_("正在读取材质数据 ..."), this);

    mMaterialList->Freeze();

    mMaterialList->ClearAll();

	Ogre::ResourceManager::ResourceMapIterator resourceMapIterator = Ogre::MaterialManager::getSingleton().getResourceIterator();
	while ( resourceMapIterator.hasMoreElements() )
	{				
		long index = mMaterialList->GetItemCount();

		mMaterialList->InsertItem( index, AS_STRING( resourceMapIterator.peekNextValue()->getName()));

		resourceMapIterator.moveNext();
	}
	mMaterialList->Thaw();
	delete  busyInfo;
    

}
void
ObjectPropertyEditor::onObjectPropertyChanged(const WX::ObjectPtr& object, const WX::String& name)
{
    if (mCurrentObject.lock() != object)
        return;

    const WX::PropertyList& properties = object->getProperties();
    for (WX::PropertyList::const_iterator it = properties.begin(); it != properties.end(); ++it)
    {
        const WX::PropertyDef& propertyDef = *it;
        WX::uint propertyFlags = object->getPropertyFlags(propertyDef.name);
        wxPGId id = mPropertiesViewer->GetPropertyByName(propertyDef.name.c_str());
        assert(id.IsOk());
        if (!id.IsOk())
            continue;
        wxPGIdToPtr(id)->SetValueFromString(AS_STRING(object->getPropertyAsString(propertyDef.name)), wxPG_FULL_VALUE);
        if (propertyFlags & WX::PF_READONLY)
        {
            if (mPropertiesViewer->IsPropertyEnabled(id))
                mPropertiesViewer->DisableProperty(id);
        }
        else
        {
            if (!mPropertiesViewer->IsPropertyEnabled(id))
                mPropertiesViewer->EnableProperty(id);
        }
    }

    mPropertiesViewer->Refresh();
}
int main(int argc, char **argv)
{
 //PyImport_AppendInittab((char*)("mpi"), &initmpi);
 PyImport_AppendInittab((char*)("_testarray"), &init_testarray);
 Py_Initialize(); // init the interpreter
 triqs::arrays::register_boost_converters();
 execute_file ( (std::string(AS_STRING(SOURCE_DIR)) + std::string("/test.py")).c_str() ) ;
 // now start the interpreter main loop and start executing the commands given to the new interpreter...
 //  Py_Main(argc,argv);
}
Exemple #17
0
void
SceneBrowser::AddObjectToTree(const ObjectPtr& object)
{
    const String& category = object->getCategory();
    const String& type = object->getType();
    const String& name = object->getName();

    wxTreeItemId parent = createCategoryTreeItem(mObjectsTree->GetRootItem(), category);
    wxTreeItemId item = mObjectsTree->AppendItem(parent, AS_STRING(name),
        -1, -1, new ObjectItemData(object));
}
Exemple #18
0
static ObjClass* defineClass(WrenVM* vm, const char* name)
{
  size_t length = strlen(name);
  ObjString* nameString = AS_STRING(wrenNewString(vm, name, length));
  WREN_PIN(vm, nameString);

  ObjClass* classObj = wrenNewClass(vm, vm->objectClass, 0, nameString);
  wrenDefineGlobal(vm, name, length, OBJ_VAL(classObj));

  WREN_UNPIN(vm);
  return classObj;
}
Exemple #19
0
// Creates either the Object or Class class in the core module with [name].
static ObjClass* defineClass(WrenVM* vm, ObjModule* module, const char* name)
{
  ObjString* nameString = AS_STRING(wrenStringFormat(vm, "$", name));
  wrenPushRoot(vm, (Obj*)nameString);

  ObjClass* classObj = wrenNewSingleClass(vm, 0, nameString);

  wrenDefineVariable(vm, module, name, nameString->length, OBJ_VAL(classObj));

  wrenPopRoot(vm);
  return classObj;
}
Exemple #20
0
/**
 * Reads a line of input from stdin
 *
 * @param args first arg is either NULL or a LuciFileObj
 * @param c if 0, read from stdin. if > 0, read from file.
 * @returns LuciStringObj containing what was read
 */
LuciObject *luci_readline(LuciObject **args, unsigned int c)
{
    size_t lenmax = 64, len = 0;
    int ch;
    FILE *read_from = NULL;
    char *input;

    if (c < 1) {
        LUCI_DEBUG("%s\n", "readline from stdin");
        read_from = stdin;
    }
    else {
        LuciObject *item = args[0];
        if (item && (ISTYPE(item, obj_file_t))) {
            LUCI_DEBUG("%s\n", "readline from file");
            read_from = AS_FILE(item)->ptr;
        }
        else {
            LUCI_DIE("args[0]: %p, type: %s\n", args[0], item->type->type_name);
            LUCI_DIE("%s", "Can't readline from non-file object\n");
        }
    }

    input = alloc(lenmax * sizeof(char));
    if (input == NULL) {
        LUCI_DIE("%s", "Failed to allocate buffer for reading stdin\n");
    }
    do {
        ch = fgetc(read_from);

        if (len >= lenmax) {
            lenmax *= 2;
            if ((input = realloc(input, lenmax * sizeof(char))) == NULL) {
                LUCI_DIE("%s", "Failed to allocate buffer for reading\n");
            }
        }
        input[len++] = (char)ch;
    } while (ch != EOF && ch != '\n');

    if (ch == EOF) {
        LUCI_DEBUG("%s\n", "readline at EOF, returning nil");
        return LuciNilObj;
    }

    /* overwrite the newline or EOF char with a NUL terminator */
    input[--len] = '\0';
    LuciObject *ret = LuciString_new(input);

    LUCI_DEBUG("Read line %s\n", AS_STRING(ret)->s);

    return ret;
}
Exemple #21
0
ObjString* wrenStringConcat(WrenVM* vm, const char* left, const char* right)
{
  size_t leftLength = strlen(left);
  size_t rightLength = strlen(right);

  Value value = wrenNewUninitializedString(vm, leftLength + rightLength);
  ObjString* string = AS_STRING(value);
  strcpy(string->value, left);
  strcpy(string->value + leftLength, right);
  string->value[leftLength + rightLength] = '\0';

  return string;
}
Exemple #22
0
wxTreeItemId
SceneBrowser::createCategoryTreeItem(const wxTreeItemId& parent, const String& category)
{
    wxASSERT(parent.IsOk());

    wxTreeItemId item = getCategoryTreeItem(parent, category);
    if (!item.IsOk())
    {
        item = mObjectsTree->AppendItem(parent, AS_STRING(category),
            -1, -1, NULL);
    }

    return item;
}
void
ObjectPropertyEditor::onSelectObject(const Fairy::ObjectPtr& object)
{
    mPropertiesViewer->GetGrid()->Clear();
    mCurrentObject = object;

	if (mObjNameList.GetCount()<=0)
	{
		Ogre::FileInfoListPtr fileInfoList =
			Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(
			Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			"*.obj");

		for(Ogre::FileInfoList::const_iterator it = fileInfoList->begin(); it != fileInfoList->end(); ++it)
		{	
			const Ogre::String name = it->filename;
			mObjNameList.AddString(name.c_str());
		}
	}

    const Fairy::PropertyList& properties = object->getProperties();
    for (Fairy::PropertyList::const_iterator it = properties.begin(); it != properties.end(); ++it)
    {
        const Fairy::PropertyDef& propertyDef = *it;
        Fairy::uint propertyFlags = object->getPropertyFlags(propertyDef.name);	
		wxPGId id;
		if (propertyDef.name == "actor name")
		{
			wxPGProperty* property = NULL;
			wxString name = propertyDef.name.c_str();
			property = wxEnumProperty(name, name, mObjNameList);
			property->SetValueFromString(propertyDef.defaultValue.c_str(),0);
			id = AddPropertyRecursive(property);
		}
		else
		{
			id = AddPropertyRecursive(mPropertyManager->CreateProperty(propertyDef));
		}
			
		wxPGIdToPtr(id)->SetValueFromString(AS_STRING(object->getPropertyAsString(propertyDef.name)), wxPG_FULL_VALUE);
		
		if (propertyFlags & Fairy::PF_READONLY)
        {
            mPropertiesViewer->DisableProperty(id);
        }
    }

    mPropertiesViewer->Refresh();
}
Exemple #24
0
Value wrenNewString(WrenVM* vm, const char* text, size_t length)
{
  // Allow NULL if the string is empty since byte buffers don't allocate any
  // characters for a zero-length string.
  ASSERT(length == 0 || text != NULL, "Unexpected NULL string.");

  // TODO: Don't allocate a heap string at all for zero-length strings.
  ObjString* string = AS_STRING(wrenNewUninitializedString(vm, length));

  // Copy the string (if given one).
  if (length > 0) strncpy(string->value, text, length);

  string->value[length] = '\0';

  return OBJ_VAL(string);
}
Exemple #25
0
void
ReshapeDialog::ReloadTextureList(void)
{

	if (!Ogre::ResourceGroupManager::getSingletonPtr())
		return;

	Ogre::Codec::CodecIterator it = Ogre::Codec::getCodecIterator();
	while (it.hasMoreElements())
	{
		const Ogre::String& ext = it.peekNextKey();
		Ogre::Codec* codec = it.getNext();
		if (codec->getDataType() != "ImageData")
			continue;

		Ogre::FileInfoListPtr fileInfoList =
			Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(
			AS_STRING(mResourceGroup),
			"*." + ext);
		for (Ogre::FileInfoList::const_iterator it = fileInfoList->begin(); it != fileInfoList->end(); ++it)
		{
			Ogre::String path, baseName;
			Ogre::StringUtil::splitFilename(it->filename, baseName, path);




			// 把相对路径的最后一个/去掉
			if (!path.empty() && path[path.length()-1] == '/')
				path.erase(path.length() - 1);

			Ogre::String value;
			if(path.empty())
			{
				value = baseName;
			}
			else
			{
				value = path + "/" + baseName;
			}

			mCmbTexture->AppendString( wxT(baseName) );

			pathNameMap.insert(make_pair(baseName,value));
		}
	}
}
Exemple #26
0
wxTreeItemId
SceneBrowser::getCategoryTreeItem(const wxTreeItemId& parent, const String& category)
{
    wxASSERT(parent.IsOk());

    wxTreeItemIdValue cookie;
    wxTreeItemId item = mObjectsTree->GetFirstChild(parent, cookie);
    while (item.IsOk())
    {
        wxTreeItemData* data = mObjectsTree->GetItemData(item);
        wxASSERT(data == NULL);
        wxString text = mObjectsTree->GetItemText(item);
        if (text == AS_STRING(category))
            break;
        item = mObjectsTree->GetNextChild(parent, cookie);
    }
    return item;
}
Exemple #27
0
// Creates a string containing an appropriate method not found error for a
// method with [symbol] on [classObj].
static ObjString* methodNotFound(WrenVM* vm, ObjClass* classObj, int symbol)
{
  // Count the number of spaces to determine the number of parameters the
  // method expects.
  const char* methodName = vm->methodNames.data[symbol];

  int methodLength = (int)strlen(methodName);
  int numParams = 0;
  while (methodName[methodLength - numParams - 1] == ' ') numParams++;

  char message[MAX_VARIABLE_NAME + MAX_METHOD_NAME + 49];
  sprintf(message, "%s does not implement method '%.*s' with %d argument%s.",
          classObj->name->value,
          methodLength - numParams, methodName,
          numParams,
          numParams == 1 ? "" : "s");

  return AS_STRING(wrenNewString(vm, message, strlen(message)));
}
Exemple #28
0
/**
 * Casts a LuciObject to a LuciStringObj if possible, then returns
 * the new object.
 *
 * @param args list of args
 * @param c number of args
 * @returns LuciStringObj cast of the first arg
 */
LuciObject *luci_cast_str(LuciObject **args, unsigned int c)
{
    LuciObject *ret = LuciNilObj;

    if (c < 1) {
        LUCI_DIE("%s", "Missing parameter to str()\n");
    }
    /* grab the first parameter from the param list */
    LuciObject *item = args[0];

    ret = item->type->repr(item);
    if (ISTYPE(ret, obj_nil_t)) {
        LUCI_DIE("Cannot cast object of type %s to type string",
                item->type->type_name);
    }
    LUCI_DEBUG("str() returning %s\n", AS_STRING(ret)->s);

    return ret;
}
void
ObjectPropertyEditor::onSelectObject(const WX::ObjectPtr& object)
{
    mPropertiesViewer->GetGrid()->Clear();
    mCurrentObject = object;

    const WX::PropertyList& properties = object->getProperties();
    for (WX::PropertyList::const_iterator it = properties.begin(); it != properties.end(); ++it)
    {
        const WX::PropertyDef& propertyDef = *it;
        WX::uint propertyFlags = object->getPropertyFlags(propertyDef.name);
        wxPGId id = AddPropertyRecursive(mPropertyManager->CreateProperty(propertyDef));
        wxPGIdToPtr(id)->SetValueFromString(AS_STRING(object->getPropertyAsString(propertyDef.name)), wxPG_FULL_VALUE);
        if (propertyFlags & WX::PF_READONLY)
        {
            mPropertiesViewer->DisableProperty(id);
        }
    }

    mPropertiesViewer->Refresh();
}
Exemple #30
0
void
BrushSelector::OnPixmapListSelected(wxTreeEvent& event)
{
	try
	{
    // 以下是改成定义文件后的修改
    //  mPaintInOneGrid = false;
    // 保存当前选中的纹理的大小
    int selectedTexXSize = 0;
    int selectedTexZSize = 0;

    // 当画刷被选中时,要进行判断
    wxTreeItemId itemId = event.GetItem();

    wxTreeItemId rootId = mBrushesTree->GetRootItem();

    // 如果选中根,就返回
    if ( itemId == rootId )
    {
        // 选中根目录名时,所有选项都变灰
        mFlipHorizontal->Enable(false);
        mFlipVertical->Enable(false);
        mRotateRightAngle->Enable(false);
        mMirrorDiagonal->Enable(false);
        mRandom->Enable(false);
        mEnablePreview->Enable(false);

        // 缩略图用黑白图
        mBrushesPreview->SetBitmap(mBlackWhitePreviewImage);

        return;
    }

    if (itemId.IsOk())
    {
        mCurrentOrientationType = 0;

        // 如果选项的父是root,说明该画刷是放在根目录下的,也有可能是根目录下的子目录
        if ( mBrushesTree->GetItemParent(itemId) == rootId )
        {
            mCurrentFileName = mBrushesTree->GetItemText(itemId);
        }
        else
        {
            // 以下处理不是放在根目录下的画刷

            wxTreeItemId parentId = mBrushesTree->GetItemParent(itemId);
            mCurrentFileName = mBrushesTree->GetItemText(itemId);

            // 以此取出父目录的目录名,组合成相对路径名,并加上文件名
            while ( parentId != rootId )
            {
                wxString parentText = mBrushesTree->GetItemText(parentId);
                parentText += '/';
                mCurrentFileName.Prepend( parentText );

                parentId = mBrushesTree->GetItemParent(parentId);
            }		
        }

        // 如果名字中有.,说明是文件名,不是目录名
        if ( mCurrentFileName.find_first_of('|') != wxString::npos )
        {
            mFlipHorizontal->Enable(true);
            mFlipVertical->Enable(true);
            mRotateRightAngle->Enable(true);
            mMirrorDiagonal->Enable(true);
            mRandom->Enable(true);
            mEnablePreview->Enable(true);

            Ogre::String currentFileName(mCurrentFileName.c_str());

            size_t pos = currentFileName.find_last_of('/');

            // 取出brush名称
            Ogre::String brushName = currentFileName.substr(0,pos);
            Ogre::String textureName = currentFileName.substr(pos+1);

            const Fairy::TextureInfos &currentPaintInfos = 
                GetSceneManipulator()->getTextureInfos(brushName);

            const Fairy::TextureInfo &currentPaintInfo = GetSceneManipulator()->getTextureInfo(brushName, textureName);

            Ogre::Image *previewImage = GetSceneManipulator()->getPreviewImage(currentPaintInfo.ownerTextureName);

            // 组成纹理信息字符串
            Ogre::String texInfoString;
            texInfoString += currentPaintInfo.ownerTextureName;
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(currentPaintInfo.height);
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(currentPaintInfo.width);
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(currentPaintInfo.leftCorner);
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(currentPaintInfo.topCorner);
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(previewImage->getHeight());
            texInfoString += "|";
            texInfoString += Ogre::StringConverter::toString(previewImage->getWidth());
			texInfoString += "|";
			texInfoString += Ogre::StringConverter::toString(currentPaintInfo.rotateType);

            Fairy::Action* action = GetSceneManipulator()->_getAction("SimplePaintAction");
            action->setParameter( "%TextureName", "InputBegin" );
            action->setParameter( "%TextureName", AS_STRING(texInfoString) );
            action->setParameter( "%OrientationType", Ogre::StringConverter::toString(mCurrentOrientationType) );

            if ( (currentPaintInfo.width > 1 || currentPaintInfo.height > 1) && !mPaintInOneGrid )
            {               
                action->setParameter( "%TexNormalSize", "false" );
                mFlipHorizontal->Enable(false);
                mFlipVertical->Enable(false);
                mRotateRightAngle->Enable(false);
                mMirrorDiagonal->Enable(false);
                mRandom->Enable(false);
            }
            else
            {
                action->setParameter("%TexNormalSize","true");
            }

            GetSceneManipulator()->setActiveAction(action);

            buildPreviewBitmap(currentPaintInfo);
         
            if ( mEnablePreview->IsChecked() == false )
            {
                // 如果不显示缩略图,就显示默认的黑白图
                mBrushesPreview->SetBitmap(mBlackWhitePreviewImage);
            }
        }
        // 如果名字中有.,说明不是文件名,是目录名
        else
        {
            mFlipHorizontal->Enable(false);
            mFlipVertical->Enable(false);
            mRotateRightAngle->Enable(false);
            mMirrorDiagonal->Enable(false);
            mRandom->Enable(false);
            mEnablePreview->Enable(true);

            // 把整个目录的纹理进行判断,并加入到透明纹理列表

            const Fairy::Action* action = OnStartAutoTexAction(itemId, mCurrentFileName);

            if ( action != 0 )
            {
                // 从该组纹理的实心纹理中随机用一个来做为缩略图
                // 读取这张纹理,并缩放到mPreviewImageWidth*mPreviewImageHeight,用于缩略图
              //  Ogre::String tempTexName = action->getParameter( "%TextureName" );

                const Fairy::TextureInfos &currentPaintInfos = 
                    GetSceneManipulator()->getTextureInfos(mCurrentFileName.c_str());

              //  const Fairy::TextureInfo &currentPaintInfo = currentPaintInfos[0];

                // 构建preview image
                buildPreviewBitmap(currentPaintInfos[0]);                
            }
            else
            {
                mEnablePreview->Enable(false);
                mBrushesPreview->SetBitmap(mBlackWhitePreviewImage);
            }

            if ( mEnablePreview->IsChecked() == false )
            {
                // 如果不显示缩略图,就显示默认的黑白图
                mBrushesPreview->SetBitmap(mBlackWhitePreviewImage);
            }
        }
    }
   
    // 让所有的checkbox回复未选择的状态
    mFlipHorizontal->SetValue(false);
    mFlipVertical->SetValue(false);
    mRotateRightAngle->SetValue(false);
    mMirrorDiagonal->SetValue(false);
    mRandom->SetValue(false);
	}
	catch (Ogre::Exception &e)
	{
		wxMessageBox(
			e.getDescription().c_str(),
           /* _("Texture Wrong")*/wxT("纹理定义出错或找不到纹理图片"),
            wxOK|wxCENTRE|wxICON_ERROR, this);
	}
}