Ejemplo n.º 1
0
NodeID NodeTree::duplicateNode(NodeID nodeID)
{
    if(!validateNode(nodeID))
        return InvalidNodeID;
    NodeTypeID typeID = _nodes[nodeID].nodeTypeID();

    // Generate unique name
    std::string newNodeTitle = generateNodeName(typeID);

    // Create node of the same typeID
    NodeID newNodeID = createNode(typeID, newNodeTitle);
    if(newNodeID == InvalidNodeID)
        return InvalidNodeID;

    // Set properties
    for(const auto& prop : _nodes[nodeID].config().properties())
        _nodes[newNodeID].setProperty(prop.propertyID(), _nodes[nodeID].property(prop.propertyID()));

    return newNodeID;
}
Ejemplo n.º 2
0
HTREEITEM GDisplayTreeTraversal::InsertNodeItem(GvNode *node,
	int &traverseChildren, int type)
{
  CString buf;

  traverseChildren = 1;

  if (node->objName) { 

  
  const GvName &name0 = node->getName();


  if ((node->refCnt >1) && (name0.getLength() == 0)) {
		if (nameGenerationWarning) Reporter.Warning("Node Reference counter >1, but no name, generating a default name");
		// to do: generate name
		//char buf[60];
		//sprintf(buf,"OBJ_%lx",(long) node);
		//GvName newName(buf);
        GvName newName;
        // assume _1 _2 names could not occur
        // or use node dict
        generateNodeName(*refDict,"",newName);
		node->setName(newName);
  }	

  
  if (node->getName().getLength()>0) {

    void	*n;

	// check if node with this name has been written
    if (refDict->find((u_long) node->getName().getString(), n)) {

		if (((GvNode *) n) == node) { // write out a reference
  			buf +="USE ";
			traverseChildren = 0;
			//return(GV_NODE_ALREADY_SEEN);

		} else {
			//Reporter.Warning("Warning duplicate definition of node name '%s'",node->getName().getString());
			int suffix = 1;
			char buf[260];
			// create a unique name by adding a suffix _###
			while (1) {
				sprintf(buf,"%s_%d",node->getName().getString(),suffix);
				GvName newName(buf);
				if (!refDict->find((u_long) newName.getString(), n)) {
					TRACE("Created unique name %s \n",newName.getString());
					node->setName(newName);
					break; // so it will be defe´d 
				}
				suffix++;
			}

		}

	}

    const GvName &name = node->getName();

  	if (traverseChildren) {

        if (RTISA(node,GvProto)) {
            buf += "PROTO ";
            // name = classname, so don´t append class
            // put proto in extras name space
        }
        else if (RTISA(node,GvExternProto)) {
            buf += "EXTERNPROTO ";
            // name = classname, so don´t append class
            // put proto in extras name space
        }
  		else  { 
            // to do:? if (format >= FORMAT_EXTENDED) buf += "DEF " ;
  		    buf += name.getString();  	
        }
		buf += " ";
    	refDict->enter((u_long) name.getString(), (void *) node);
	} 
	else buf += name.getString();  	

	} // length > 0
   	
   	} // node->objName

	if (traverseChildren)
   	   buf += node->GetType(); 

#ifdef  _NO_DISPLAY_TREE
    return NULL;
#else 
	return(returnItem = treeEditor->AddItem(top,buf,node,topInsertAfter,0,type));
#endif
}