Пример #1
0
bool NodeTree::unlinkNodes(SocketAddress from, SocketAddress to)
{
    if(!validateLink(from, to))
        return false;

    // Look for given node link
    NodeLink nodeLinkToFind(from, to);
    auto iter = std::lower_bound(std::begin(_links), 
        std::end(_links), nodeLinkToFind);

    if(iter != std::end(_links))
    {
        // Need to store ID before erase() invalidates iterator
        NodeID nodeID = iter->toNode;

        _links.erase(iter);

        // Keep links sorted
        std::sort(std::begin(_links), std::end(_links));

        // tag affected node
        tagNode(nodeID);

        return true;
    }

    return false;
}
Пример #2
0
OP_STATUS CanvasWebGLProgram::link(unsigned int extensions_enabled, unsigned int max_vertex_attribs)
{
	OP_NEW_DBG("CanvasWebGLProgram::link()", "webgl.shaders");

	m_linked = FALSE;
	++m_linkId;
	int shader_index;

	RETURN_IF_ERROR(validateLink(extensions_enabled));

	RETURN_IF_ERROR(setUpActiveAttribBindings(max_vertex_attribs));

	OP_STATUS status = OpStatus::OK;

	for (shader_index = 0;
	     shader_index < (int)m_attachedShaders.GetCount();
	     ++shader_index)
	{
		VEGA3dShader *shader = m_attachedShaders.Get(shader_index)->getShader();
		status = shader ? m_program->addShader(shader) : OpStatus::ERR;
		if (OpStatus::IsError(status))
			break;
	}

	if (OpStatus::IsSuccess(status))
	{
		status = m_program->link(&m_info_log);

#ifdef _DEBUG
		if (!m_info_log.IsEmpty())
			OP_DBG((UNI_L("\nMessages from shader linking\n============================\n%s\n"),
			        m_info_log.CStr()));
#endif // _DEBUG
	}

	// Only try to remove the shaders that were actually added above
	while (shader_index-- > 0)
	{
		VEGA3dShader *shader = m_attachedShaders.Get(shader_index)->getShader();
		OP_ASSERT(shader);
		m_program->removeShader(shader);
	}

	RETURN_IF_ERROR(status);
	RETURN_IF_ERROR(setUpSamplerBindings());

	m_linked = TRUE;
	return status;
}
Пример #3
0
ELinkNodesResult NodeTree::linkNodes(SocketAddress from, SocketAddress to)
{
    // Check if given addresses are OK
    if(!validateLink(from, to))
        return ELinkNodesResult::InvalidAddress;

    // Check if we are not trying to link input socket with more than one output
    bool alreadyExisingConnection = std::any_of(std::begin(_links), std::end(_links), 
        [&](const NodeLink& link) {
            return link.toNode == to.node && link.toSocket == to.socket;
        });
    if(alreadyExisingConnection)
        return ELinkNodesResult::TwoOutputsOnInput;

    // Try to make a connection
    _links.emplace_back(NodeLink(from, to));

    // Keep links sorted
    std::sort(std::begin(_links), std::end(_links));

    // Check for created cycle(s)
    if(checkCycle(to.node))
    {
        // Look for given node link
        NodeLink nodeLinkToFind(from, to);
        auto iter = std::lower_bound(std::begin(_links), 
            std::end(_links), nodeLinkToFind);

        assert(iter != std::end(_links));

        if(iter != std::end(_links))
        {
            _links.erase(iter);

            // Keep links sorted
            std::sort(std::begin(_links), std::end(_links));
        }

        return ELinkNodesResult::CycleDetected;
    }

    // tag affected node
    tagNode(to.node);

    return ELinkNodesResult::Ok;
}
Пример #4
0
/*--------------------------------------------------------------*/
int NXVvalidateGroup(pNXVcontext self, hid_t groupID,
	xmlNodePtr groupNode)
{
		hash_table namesSeen, baseNames;
		xmlNodePtr cur = NULL;
		xmlChar *name = NULL, *myClass = NULL;
		xmlChar *target = NULL;
		hid_t childID;
		char fName[256], childName[512], nxdlChildPath[512], childPath[512];
		char mynxdlPath[512];
		char *savedNXDLPath, *pPtr;
		SecondPassData spd;
		hsize_t idx = 0;

		/*
			manage nxdlPath, xmlGetNodePath does not work
		*/
		savedNXDLPath = self->nxdlPath;
		myClass = xmlGetProp(groupNode,(xmlChar *)"type");
		if(self->nxdlPath == NULL) {
			snprintf(mynxdlPath,sizeof(mynxdlPath),"/%s", (char *) myClass);
		} else {
			snprintf(mynxdlPath,sizeof(mynxdlPath),"%s/%s",
				self->nxdlPath, (char *) myClass);
		}
		self->nxdlPath = mynxdlPath;

		/*
			tell what we are doing
		*/
		H5Iget_name(groupID,fName,sizeof(fName));
		NXVsetLog(self,"sev","debug");
		NXVsetLog(self,"message","Validating group");
		NXVsetLog(self,"nxdlPath",self->nxdlPath);
		NXVsetLog(self,"dataPath",fName);
		NXVlog(self);


		validateGroupAttributes(self, groupID, groupNode);
		hash_construct_table(&namesSeen,100);

		/* first pass */
		cur = groupNode->xmlChildrenNode;
		while(cur != NULL){
			if(xmlStrcmp(cur->name,(xmlChar *) "group") == 0){
					childID = findGroup(self, groupID, cur);
					if(childID >= 0){
							H5Iget_name(childID, childName,sizeof(childName));
							/*
								we have to get at the HDF5 name. There may be no
								name in the NXDL, but a suitable group has been found
								by NXclass.
							*/
							pPtr = strrchr(childName,'/');
							if(pPtr != NULL){
								hash_insert(pPtr+1,strdup(""),&namesSeen);
							} else {
								hash_insert(childName,strdup(""),&namesSeen);
							}
							NXVvalidateGroup(self,childID,cur);
					} else {
						name = xmlGetProp(cur,(xmlChar *)"type");
						snprintf(nxdlChildPath,sizeof(nxdlChildPath),"%s/%s",
							self->nxdlPath, (char *)name);
						xmlFree(name);
						NXVsetLog(self,"dataPath",fName);
						NXVsetLog(self,"nxdlPath", nxdlChildPath);
						if(!isOptional(cur)){
							NXVsetLog(self,"sev","error");
							NXVsetLog(self,"message","Required group missing");
							NXVlog(self);
							self->errCount++;
						} else {
							NXVsetLog(self,"sev","warnopt");
							NXVsetLog(self,"message","Optional group missing");
							NXVlog(self);
						}
					}
			}
			if(xmlStrcmp(cur->name,(xmlChar *) "field") == 0){
					name = xmlGetProp(cur,(xmlChar *)"name");
					if(H5LTfind_dataset(groupID,(char *)name) ) {
						childID = H5Dopen(groupID,(char *)name,H5P_DEFAULT);
					} else {
						childID = -1;
					}
					snprintf(childPath,sizeof(childPath),"%s/%s",
						fName,name);
					if(childID < 0){
						NXVsetLog(self,"dataPath",childPath);
						snprintf(nxdlChildPath,sizeof(nxdlChildPath),
							"%s/%s", self->nxdlPath, name);
						NXVsetLog(self,"nxdlPath", nxdlChildPath);
						if(!isOptional(cur)){
									NXVsetLog(self,"sev","error");
									NXVsetLog(self,"message","Required field missing");
									NXVlog(self);
									self->errCount++;
						} else {
							NXVsetLog(self,"sev","warnopt");
							NXVsetLog(self,"message","Optional field missing");
							NXVlog(self);
						}
					} else {
						if(xmlStrcmp(name,(xmlChar *)"depends_on") == 0){
							/*
								This must b validated from the field level. As
								it might point to fields which are not in the
								application definition
							*/
							validateDependsOn(self,groupID,childID);
						} else {
							NXVvalidateField(self,childID, cur);
						}
						hash_insert((char *)name,strdup(""),&namesSeen);
					}
					xmlFree(name);
			}
			if(xmlStrcmp(cur->name,(xmlChar *) "link") == 0){
				name = xmlGetProp(cur,(xmlChar *)"name");
				target = xmlGetProp(cur,(xmlChar *)"target");
				hash_insert((char *)name,strdup(""),&namesSeen);
				validateLink(self,groupID,name, target);
				xmlFree(name);
				xmlFree(target);
			}
			cur = cur->next;
		}

		/*
			Second pass: search the HDF5 group for additional
			stuff which have not checked yet. Most of the hard work
			is in the SecondPassIterator.
		*/
		hash_construct_table(&baseNames,100);
		NXVloadBaseClass(self,&baseNames,(char *)myClass);
		spd.baseNames = &baseNames;
		spd.namesSeen = &namesSeen;
		spd.self = self;
		NXVsetLog(self,"nxdlPath", mynxdlPath);
		H5Literate(groupID, H5_INDEX_NAME, H5_ITER_INC, &idx,
			SecondPassIterator, &spd);

		/*
			clean up
		*/
		hash_free_table(&namesSeen,free);
		hash_free_table(&baseNames,free);
		xmlFree(myClass);
		/*
			restore my paths...
		*/
		self->nxdlPath = savedNXDLPath;
		return 0;
	}