void SceneTreeDock::fill_path_renames(Node* p_node, Node *p_new_parent, List<Pair<NodePath,NodePath> > *p_renames) { if (!bool(EDITOR_DEF("animation/autorename_animation_tracks",true))) return; Vector<StringName> base_path; Node *n = p_node->get_parent(); while(n) { base_path.push_back(n->get_name()); n=n->get_parent(); } base_path.invert(); Vector<StringName> new_base_path; if (p_new_parent) { n = p_new_parent; while(n) { new_base_path.push_back(n->get_name()); n=n->get_parent(); } new_base_path.invert(); } _fill_path_renames(base_path,new_base_path,p_node,p_renames); }
void VisibilityEnabler::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { if (Engine::get_singleton()->is_editor_hint()) return; Node *from = this; //find where current scene starts while (from->get_parent() && from->get_filename() == String()) from = from->get_parent(); _find_nodes(from); } if (p_what == NOTIFICATION_EXIT_TREE) { if (Engine::get_singleton()->is_editor_hint()) return; for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) { if (!visible) _change_node_state(E->key(), true); E->key()->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, "_node_removed"); } nodes.clear(); } }
void EditorSelection::_update_nl() { if (!nl_changed) return; selected_node_list.clear(); for (Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { Node *parent = E->key(); parent=parent->get_parent(); bool skip=false; while (parent) { if (selection.has(parent)) { skip=true; break; } parent=parent->get_parent(); } if (skip) continue; selected_node_list.push_back(E->key()); } nl_changed=true; }
Node(const Node &node) { _cur = node.get_coordinate(); _parent = node.get_parent(); _g = node.get_g(); _f = node.get_f(); }
void PopupMenu::activate_item(int p_item) { ERR_FAIL_INDEX(p_item, items.size()); ERR_FAIL_COND(items[p_item].separator); int id = items[p_item].ID >= 0 ? items[p_item].ID : p_item; emit_signal("id_pressed", id); emit_signal("index_pressed", p_item); //hide all parent PopupMenue's Node *next = get_parent(); PopupMenu *pop = next->cast_to<PopupMenu>(); while (pop) { // We close all parents that are chained together, // with hide_on_item_selection enabled if ((items[p_item].checkable && hide_on_checkable_item_selection && pop->is_hide_on_checkable_item_selection()) || (!items[p_item].checkable && hide_on_item_selection && pop->is_hide_on_item_selection())) { pop->hide(); next = next->get_parent(); pop = next->cast_to<PopupMenu>(); } else { // Break out of loop when the next parent has // hide_on_item_selection disabled break; } } // Hides popup by default; unless otherwise specified // by using set_hide_on_item_selection and set_hide_on_checkable_item_selection if ((items[p_item].checkable && hide_on_checkable_item_selection) || (!items[p_item].checkable && hide_on_item_selection)) { hide(); } }
void EditorSubScene::move(Node *p_new_parent, Node *p_new_owner) { if (!scene) { return; } if (selection.size() <= 0) { return; } for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Node *selnode = E->get(); if (!selnode) { return; } List<Node *> to_reown; _reown(selnode, &to_reown); if (selnode != scene) { selnode->get_parent()->remove_child(selnode); } p_new_parent->add_child(selnode); for (List<Node *>::Element *F = to_reown.front(); F; F = F->next()) { F->get()->set_owner(p_new_owner); } } if (!is_root) { memdelete(scene); } scene = NULL; //return selnode; }
void SceneTreeDock::_node_prerenamed(Node* p_node, const String& p_new_name) { List<Pair<NodePath,NodePath> > path_renames; Vector<StringName> base_path; Node *n = p_node->get_parent(); while(n) { base_path.push_back(n->get_name()); n=n->get_parent(); } base_path.invert(); Vector<StringName> new_base_path=base_path; base_path.push_back(p_node->get_name()); new_base_path.push_back(p_new_name); Pair<NodePath,NodePath> npp; npp.first = NodePath(base_path,true); npp.second = NodePath(new_base_path,true); path_renames.push_back(npp); for(int i=0;i<p_node->get_child_count();i++) _fill_path_renames(base_path,new_base_path,p_node->get_child(i),&path_renames); perform_node_renames(NULL,&path_renames); }
bool ImplNodeEx::is_path_equal(const Node& other) const noexcept { if (cstr::compare_ci(name(), other->name()) != 0) return false; if (parent_) return parent_->is_path_equal(other->get_parent()); return true; }
void AdaptiveHuffman::insert(char sym) { Node* tba = NULL; if (!is_known(sym)) { Node* inner = new Node("", 1); Node* fresh = new Node(string(1, sym), 1); inner->set_left(nyt); inner->set_right(fresh); inner->set_parent(nyt->get_parent()); if (nyt->get_parent() != NULL) nyt->get_parent()->set_left(inner); else root = inner; nyt->set_parent(inner); fresh->set_parent(inner); nodes.insert(nodes.begin() + 1, inner); nodes.insert(nodes.begin() + 1, fresh); knownsym.push_back(sym); tba = inner->get_parent(); } else { tba = find_node(sym); } while (tba != NULL) { Node* bignode = find_bignode(tba->get_frequency()); if (tba != bignode && tba->get_parent() != bignode && bignode->get_parent() != tba) swap_node(tba, bignode); tba->set_frequency(tba->get_frequency() + 1); tba = tba->get_parent(); } }
/** * \brief Tag the lineage of this node * \details -- * \param void * \return \e void */ void Node::tag_lineage( void ) { _tagged = true; Node* node = _parent; while (node != NULL) { node->tag(); node = node->get_parent(); } }
/** * \brief Untag the lineage of this node * \details -- * \param void * \return \e void */ void Node::untag_lineage( void ) { _tagged = false; Node* node = _parent; while (node != NULL) { node->untag(); node = node->get_parent(); } }
bool CheckBox::is_radio() { Node* parent = this; do { parent = parent->get_parent(); if (parent->cast_to<ButtonGroup>()) break; } while (parent); return (parent != 0); }
void Red_Black_Tree::right_rotation(Node<int> *node){ Node<int> *root = node; if((root == NULL) || (root == &NULL_NODE)) return; Node<int> *pivot = root->get_left_ptr(); if(pivot == &NULL_NODE) return; if(debug_flag) clog << "Right rotating" << endl << "root : " << root->get_data() << ", " << "pivot: " << pivot->get_data() << endl; root->set_left_ptr(pivot->get_right_ptr()); if(pivot->get_right_ptr() != &NULL_NODE) pivot->get_right_ptr()->set_parent(root); pivot->set_right_ptr(root); /* Setting the parent pointers. */ pivot->set_parent(root->get_parent()); if(is_root(root)) set_root(pivot); root->set_parent(pivot); /* Setting the left/right pointer of parent. */ if(!is_root(pivot)){ if(pivot->get_parent()->get_left_ptr() == root){ pivot->get_parent()->set_left_ptr(pivot); } else if(pivot->get_parent()->get_right_ptr() == root){ pivot->get_parent()->set_right_ptr(pivot); } else{ cout << "Error: neither left or right child" << endl; assert(0); } } if(debug_flag) clog << "After right rotation: ", print_tree(); return; }
Ref<Script> EditorData::get_scene_root_script(int p_idx) const { ERR_FAIL_INDEX_V(p_idx,edited_scene.size(),Ref<Script>()); if (!edited_scene[p_idx].root) return Ref<Script>(); Ref<Script> s=edited_scene[p_idx].root->get_script(); if (!s.is_valid() && edited_scene[p_idx].root->get_child_count()) { Node *n = edited_scene[p_idx].root->get_child(0); while(!s.is_valid() && n && n->get_filename()==String()) { s=n->get_script(); n=n->get_parent(); } } return s; }
void CanvasItem::_enter_canvas() { if ((!Object::cast_to<CanvasItem>(get_parent())) || toplevel) { Node *n = this; canvas_layer = NULL; while (n) { canvas_layer = Object::cast_to<CanvasLayer>(n); if (canvas_layer) { break; } n = n->get_parent(); } RID canvas; if (canvas_layer) canvas = canvas_layer->get_world_2d()->get_canvas(); else canvas = get_viewport()->find_world_2d()->get_canvas(); VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, canvas); group = "root_canvas" + itos(canvas.get_id()); add_to_group(group); if (canvas_layer) canvas_layer->reset_sort_index(); else get_viewport()->gui_reset_canvas_sort_index(); get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, "_toplevel_raise_self"); } else { CanvasItem *parent = get_parent_item(); canvas_layer = parent->canvas_layer; VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, parent->get_canvas_item()); VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_index()); } pending_update = false; update(); notification(NOTIFICATION_ENTER_CANVAS); }
void CanvasItem::_enter_canvas() { if ((!get_parent() || !get_parent()->cast_to<CanvasItem>()) || toplevel) { Node *n = this; Viewport *viewport=NULL; canvas_layer=NULL; while(n) { if (n->cast_to<Viewport>()) { viewport = n->cast_to<Viewport>(); break; } if (!canvas_layer && n->cast_to<CanvasLayer>()) { canvas_layer = n->cast_to<CanvasLayer>(); } n=n->get_parent(); } RID canvas; if (canvas_layer) canvas=canvas_layer->get_world_2d()->get_canvas(); else canvas=viewport->find_world_2d()->get_canvas(); VisualServer::get_singleton()->canvas_item_set_parent(canvas_item,canvas); group = "root_canvas"+itos(canvas.get_id()); add_to_group(group); get_tree()->call_group(SceneTree::GROUP_CALL_UNIQUE,group,"_raise_self"); } else { CanvasItem *parent = get_parent_item(); VisualServer::get_singleton()->canvas_item_set_parent(canvas_item,parent->get_canvas_item()); parent->_queue_sort_children(); } pending_update=false; update(); notification(NOTIFICATION_ENTER_CANVAS); }
void PopupMenu::activate_item(int p_item) { ERR_FAIL_INDEX(p_item,items.size()); ERR_FAIL_COND(items[p_item].separator); emit_signal("item_pressed",items[p_item].ID); //hide all parent PopupMenue's Node *next = get_parent(); PopupMenu *pop = next->cast_to<PopupMenu>(); while (pop) { pop->hide(); next = next->get_parent(); pop = next->cast_to<PopupMenu>(); } hide(); }
void SceneTreeDock::_update_tool_buttons() { Node *sel = scene_tree->get_selected(); bool disable = !sel; bool disable_root = disable || sel->get_parent()==scene_root; tool_buttons[TOOL_INSTANCE]->set_disabled(disable); tool_buttons[TOOL_REPLACE]->set_disabled(disable); tool_buttons[TOOL_CONNECT]->set_disabled(disable); tool_buttons[TOOL_GROUP]->set_disabled(disable); tool_buttons[TOOL_SCRIPT]->set_disabled(disable); tool_buttons[TOOL_MOVE_UP]->set_disabled(disable_root); tool_buttons[TOOL_MOVE_DOWN]->set_disabled(disable_root); tool_buttons[TOOL_DUPLICATE]->set_disabled(disable_root); tool_buttons[TOOL_REPARENT]->set_disabled(disable_root); tool_buttons[TOOL_ERASE]->set_disabled(disable); }
void PopupMenu::activate_item(int p_item) { ERR_FAIL_INDEX(p_item, items.size()); ERR_FAIL_COND(items[p_item].separator); int id = items[p_item].ID >= 0 ? items[p_item].ID : p_item; emit_signal("id_pressed", id); emit_signal("index_pressed", p_item); //hide all parent PopupMenue's Node *next = get_parent(); PopupMenu *pop = Object::cast_to<PopupMenu>(next); while (pop) { // We close all parents that are chained together, // with hide_on_item_selection enabled if (items[p_item].checkable_type) { if (!hide_on_checkable_item_selection || !pop->is_hide_on_checkable_item_selection()) break; } else if (0 < items[p_item].max_states) { if (!hide_on_multistate_item_selection || !pop->is_hide_on_multistate_item_selection()) break; } else if (!hide_on_item_selection || !pop->is_hide_on_item_selection()) break; pop->hide(); next = next->get_parent(); pop = Object::cast_to<PopupMenu>(next); } // Hides popup by default; unless otherwise specified // by using set_hide_on_item_selection and set_hide_on_checkable_item_selection if (items[p_item].checkable_type) { if (!hide_on_checkable_item_selection) return; } else if (0 < items[p_item].max_states) { if (!hide_on_multistate_item_selection) return; } else if (!hide_on_item_selection) return; hide(); }
void SceneTreeDock::_update_tool_buttons() { Node *sel = scene_tree->get_selected(); bool disable = !sel || (sel!=edited_scene && sel->get_owner()!=edited_scene) || (edited_scene->get_scene_instance_state().is_valid() && edited_scene->get_scene_instance_state()->find_node_by_path(edited_scene->get_path_to(sel))>=0); bool disable_root = disable || sel->get_parent()==scene_root; bool disable_edit = !sel; tool_buttons[TOOL_INSTANCE]->set_disabled(disable_edit); tool_buttons[TOOL_REPLACE]->set_disabled(disable); tool_buttons[TOOL_CONNECT]->set_disabled(disable_edit); tool_buttons[TOOL_GROUP]->set_disabled(disable_edit); tool_buttons[TOOL_SCRIPT]->set_disabled(disable_edit); tool_buttons[TOOL_MOVE_UP]->set_disabled(disable_root); tool_buttons[TOOL_MOVE_DOWN]->set_disabled(disable_root); tool_buttons[TOOL_DUPLICATE]->set_disabled(disable_root); tool_buttons[TOOL_REPARENT]->set_disabled(disable_root); tool_buttons[TOOL_ERASE]->set_disabled(disable); tool_buttons[TOOL_MULTI_EDIT]->set_disabled(EditorNode::get_singleton()->get_editor_selection()->get_selection().size()<2); }
void VisibilityEnabler2D::_notification(int p_what){ if (p_what==NOTIFICATION_ENTER_TREE) { if (get_tree()->is_editor_hint()) return; Node *from = this; //find where current scene starts while(from->get_parent() && from->get_filename()==String()) from=from->get_parent(); _find_nodes(from); if (enabler[ENABLER_PARENT_FIXED_PROCESS] && get_parent()) get_parent()->set_fixed_process(false); if (enabler[ENABLER_PARENT_PROCESS] && get_parent()) get_parent()->set_process(false); } if (p_what==NOTIFICATION_EXIT_TREE) { if (get_tree()->is_editor_hint()) return; for (Map<Node*,Variant>::Element *E=nodes.front();E;E=E->next()) { if (!visible) _change_node_state(E->key(),true); E->key()->disconnect(SceneStringNames::get_singleton()->exit_tree,this,"_node_removed"); } nodes.clear(); } }
void CanvasLayer::_notification(int p_what) { switch(p_what) { case NOTIFICATION_ENTER_SCENE: { Node *n = this; vp=NULL; while(n) { if (n->cast_to<Viewport>()) { vp = n->cast_to<Viewport>(); break; } n=n->get_parent(); } ERR_FAIL_COND(!vp); viewport=vp->get_viewport(); VisualServer::get_singleton()->viewport_attach_canvas(viewport,canvas->get_canvas()); VisualServer::get_singleton()->viewport_set_canvas_layer(viewport,canvas->get_canvas(),layer); VisualServer::get_singleton()->viewport_set_canvas_transform(viewport,canvas->get_canvas(),transform); } break; case NOTIFICATION_EXIT_SCENE: { VisualServer::get_singleton()->viewport_remove_canvas(viewport,canvas->get_canvas()); viewport=RID(); } break; } }
void EditorSubScene::move(Node* p_new_parent, Node* p_new_owner) { if (!scene) { return; } TreeItem *s = tree->get_selected(); if (!s) { return; } Node *selnode = s->get_metadata(0); if (!selnode) { return; } List<Node*> to_reown; _reown(selnode,&to_reown); if (selnode!=scene) { selnode->get_parent()->remove_child(selnode); } p_new_parent->add_child(selnode); for (List<Node*>::Element *E=to_reown.front();E;E=E->next()) { E->get()->set_owner(p_new_owner); } if (selnode!=scene) { memdelete(scene); } scene=NULL; //return selnode; }
void SceneTreeDock::_node_reparent(NodePath p_path,bool p_node_only) { Node *node = scene_tree->get_selected(); ERR_FAIL_COND(!node); ERR_FAIL_COND(node==edited_scene); Node *new_parent = scene_root->get_node(p_path); ERR_FAIL_COND(!new_parent); Node *validate=new_parent; while(validate) { if (editor_selection->is_selected(validate)) { ERR_EXPLAIN("Selection changed at some point.. can't reparent"); ERR_FAIL(); return; } validate=validate->get_parent(); } //ok all valid List<Node*> selection = editor_selection->get_selected_node_list(); if (selection.empty()) return; //nothing to reparent //sort by tree order, so re-adding is easy selection.sort_custom<Node::Comparator>(); editor_data->get_undo_redo().create_action("Reparent Node"); List<Pair<NodePath,NodePath> > path_renames; for(List<Node*>::Element *E=selection.front();E;E=E->next()) { //no undo for now, sorry Node *node = E->get(); fill_path_renames(node,new_parent,&path_renames); List<Node*> owned; node->get_owned_by(node->get_owner(),&owned); Array owners; for(List<Node*>::Element *E=owned.front();E;E=E->next()) { owners.push_back(E->get()); } editor_data->get_undo_redo().add_do_method(node->get_parent(),"remove_child",node); editor_data->get_undo_redo().add_do_method(new_parent,"add_child",node); editor_data->get_undo_redo().add_do_method(this,"_set_owners",edited_scene,owners); if (editor->get_animation_editor()->get_root()==node) editor_data->get_undo_redo().add_do_method(editor->get_animation_editor(),"set_root",node); editor_data->get_undo_redo().add_undo_method(new_parent,"remove_child",node); } //add and move in a second step.. (so old order is preserved) for(List<Node*>::Element *E=selection.front();E;E=E->next()) { Node *node = E->get(); List<Node*> owned; node->get_owned_by(node->get_owner(),&owned); Array owners; for(List<Node*>::Element *E=owned.front();E;E=E->next()) { owners.push_back(E->get()); } int child_pos = node->get_position_in_parent(); editor_data->get_undo_redo().add_undo_method(node->get_parent(),"add_child",node); editor_data->get_undo_redo().add_undo_method(node->get_parent(),"move_child",node,child_pos); editor_data->get_undo_redo().add_undo_method(this,"_set_owners",edited_scene,owners); if (editor->get_animation_editor()->get_root()==node) editor_data->get_undo_redo().add_undo_method(editor->get_animation_editor(),"set_root",node); } perform_node_renames(NULL,&path_renames); editor_data->get_undo_redo().commit_action(); //node->set_owner(owner); }
void Spatial::_notification(int p_what) { switch(p_what) { case NOTIFICATION_ENTER_SCENE: { Node *p = get_parent(); if (p) data.parent=p->cast_to<Spatial>(); if (data.parent) data.C=data.parent->data.children.push_back(this); else data.C=NULL; if (data.toplevel && !get_scene()->is_editor_hint()) { if (data.parent) { data.local_transform = data.parent->get_global_transform() * get_transform(); data.dirty=DIRTY_VECTORS; //global is always dirty upon entering a scene } data.toplevel_active=true; } data.dirty|=DIRTY_GLOBAL; //global is always dirty upon entering a scene _notify_dirty(); notification(NOTIFICATION_ENTER_WORLD); } break; case NOTIFICATION_EXIT_SCENE: { notification(NOTIFICATION_EXIT_WORLD,true); if (xform_change.in_list()) get_scene()->xform_change_list.remove(&xform_change); if (data.C) data.parent->data.children.erase(data.C); data.parent=NULL; data.C=NULL; data.toplevel_active=false; } break; case NOTIFICATION_ENTER_WORLD: { data.inside_world=true; data.viewport=NULL; Node *parent = get_parent(); while(parent && !data.viewport) { data.viewport=parent->cast_to<Viewport>(); parent=parent->get_parent(); } ERR_FAIL_COND(!data.viewport); if (get_script_instance()) { Variant::CallError err; get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_enter_world,NULL,0); } #ifdef TOOLS_ENABLED if (get_scene()->is_editor_hint()) { // get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,SceneStringNames::get_singleton()->_spatial_editor_group,SceneStringNames::get_singleton()->_request_gizmo,this); get_scene()->call_group(0,SceneStringNames::get_singleton()->_spatial_editor_group,SceneStringNames::get_singleton()->_request_gizmo,this); if (!data.gizmo_disabled) { if (data.gizmo.is_valid()) data.gizmo->create(); } } #endif } break; case NOTIFICATION_EXIT_WORLD: { #ifdef TOOLS_ENABLED if (data.gizmo.is_valid()) { data.gizmo->free(); } #endif if (get_script_instance()) { Variant::CallError err; get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_world,NULL,0); } data.viewport=NULL; data.inside_world=false; } break; case NOTIFICATION_TRANSFORM_CHANGED: { #ifdef TOOLS_ENABLED if (data.gizmo.is_valid()) { data.gizmo->transform(); } #endif } break; default: {} } }
int main(int argc, char* argv[]){ if (argc < 2) { std::cout << "Please provide some arguments" << std::endl; std::cout << "Use -h/--help for reference" << std::endl; exit(EXIT_FAILURE); } //[indexDirectory] [positionInCluster] [HostName] [FileName std::string index_location = "."; // Set to current working directory if not passed as input std::string HostName; // Must Have std::string NodeDetailsFile = "filename.txt"; // Good to have int posNum; // Must have int portNum = 3033; // Should not be set in most cases; // 3033 is our default sending port // and 3034 is our default receiving port int numOfBranches = 2; int startNode = 0; int i, j; //Command line parsing for (i=1; i< argc; i=i+2) { if(0 == strcmp(argv[i], "--indexdir")) { index_location = argv[i+1]; } else if(0 == strcmp(argv[i], "--hostname")) { HostName = argv[i+1]; } else if(0 == strcmp(argv[i], "--position")) { posNum = atoi(argv[i+1]); } else if(0 == strcmp(argv[i], "--numbranch")) { numOfBranches = atoi(argv[i+1]); if (numOfBranches < 2){ std::cerr << "Num of Branches in tree must be greater than 2" << std::endl; } } else if(0 == strcmp(argv[i], "--port")) { portNum = atoi(argv[i+1]); } else if(0 == strcmp(argv[i], "--startNode")) { startNode = atoi(argv[i+1]); } else if(0 == strcmp(argv[i], "--filename")) { NodeDetailsFile = argv[i+1]; } else if(0 == strcmp(argv[i], "--help") | 0 == strcmp(argv[i], "-h")) { std::cout << "Use of search server:" << std::endl; std::cout << "\t./binServer" << std::endl; std::cout << "\t\t --indexdir ~/Index/location" << std::endl; std::cout << "\t\t --hostname ec2.fulldomain.name.amazon.com" << std::endl; std::cout << "\t\t --filename filename.txt" << std::endl; std::cout << "\t\t --position 3" << std::endl; std::cout << "\t\t --port 3033" << std::endl; exit(EXIT_SUCCESS); } else { std::cout << "Use of search server:" << std::endl; std::cout << "\t./binServer" << std::endl; std::cout << "\t\t --indexdir ~/Index/location" << std::endl; std::cout << "\t\t --hostname ec2.fulldomain.name.amazon.com" << std::endl; std::cout << "\t\t --filename filename.txt" << std::endl; std::cout << "\t\t --position 3" << std::endl; std::cout << "\t\t --port 3033" << std::endl; exit(EXIT_FAILURE); } } /* Create a node object */ Node currentNode = Node( HostName, portNum, posNum, NodeDetailsFile); LOG(INFO) << "Listening for input on port: "<< portNum; /* Start listening on receivePort */ std::string received_string = currentNode.listenOnTheReceivePort(3033); /* Get all the children */ std::vector<std::string> children = currentNode.get_children(startNode, numOfBranches); int numOfChildren = children.size(); //std::cout << "I have "<< children.size() << " children." << std::endl; std::clock_t start; double duration; int received_messages_count = 0; std::string search_results; std::string uuid; /* If leaf send its name to parent and thats it*/ if(currentNode.am_i_leaf(startNode, numOfBranches)){ uuid = received_string.substr(0,36); search_results = run_query( index_location, received_string.substr(36), 10, uuid, HostName); //10 is the default number of hits LOG(INFO) << uuid << " Done searching!!"; LOG(INFO) << uuid << " Sending results back to parent " << currentNode.get_parent(startNode, numOfBranches) << std::endl; currentNode.send_message(currentNode.get_parent(startNode, numOfBranches), 3034, search_results); } /* else if root send back to client */ else if(posNum == startNode){ start = std::clock(); // create a new thread to send all the messages std::thread send (send_messages, children, 3033, currentNode, received_string); send.join(); LOG(INFO) << "Done sending query to all the children; waiting for children to send the message back"; LOG(INFO) << "Starting async search in index"; uuid = received_string.substr(0,36); auto future = std::async( asyncQuery, index_location, received_string.substr(36), 10, uuid, HostName); //Starting async query std::string resultsFromChildren = currentNode.listenForMultipleReplies(3034, numOfChildren); //LOG(INFO) << uuid << " Received results from children " << resultsFromChildren; std::string searchResults = future.get(); LOG(INFO) << uuid << " Sending results back to parent " << currentNode.get_parent(startNode, numOfBranches); duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC; //currentNode.send_message("localhost", 3035, std::to_string(duration)); currentNode.send_message("localhost", 3035, "Received all messages in " + std::to_string(duration) + " seconds" + "\n" + searchResults + resultsFromChildren); LOG(INFO) << "Received all messages in: "<< duration << " seconds" ; } /* Else open a connection for collecting result from child and then send back to parent */ else{ // create a new thread to send all the messages std::thread send (send_messages, children, 3033, currentNode, received_string); send.join(); LOG(INFO) << "Done sending query to all the children; waiting for children to send the message back"; LOG(INFO) << "Starting async search in index"; uuid = received_string.substr(0,36); auto future = std::async( asyncQuery, index_location, received_string.substr(36), 10, uuid, HostName); //Starting async query std::string resultsFromChildren = currentNode.listenForMultipleReplies(3034, numOfChildren); std::string searchResults = future.get(); LOG(INFO) << uuid << " Sending results back to parent " << currentNode.get_parent(startNode, numOfBranches) << std::endl; // For current implementation we are sending back the string we got from the parent // When query collection is implemented we will send back the results for each query currentNode.send_message(currentNode.get_parent(startNode, numOfBranches), 3034, searchResults + resultsFromChildren); } /* Make query irrespective of anything on the current node */ }
bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { if (!p_node) return false; // only owned nodes are editable, since nodes can create their own (manually owned) child nodes, // which the editor needs not to know about. bool part_of_subscene = false; if (!display_foreign && p_node->get_owner() != get_scene_node() && p_node != get_scene_node()) { if ((show_enabled_subscene || can_open_instance) && p_node->get_owner() && (get_scene_node()->is_editable_instance(p_node->get_owner()))) { part_of_subscene = true; //allow } else { return false; } } else { part_of_subscene = p_node != get_scene_node() && get_scene_node()->get_scene_inherited_state().is_valid() && get_scene_node()->get_scene_inherited_state()->find_node_by_path(get_scene_node()->get_path_to(p_node)) >= 0; } TreeItem *item = tree->create_item(p_parent); item->set_text(0, p_node->get_name()); if (can_rename && !part_of_subscene /*(p_node->get_owner() == get_scene_node() || p_node==get_scene_node())*/) item->set_editable(0, true); item->set_selectable(0, true); if (can_rename) { #ifndef DISABLE_DEPRECATED if (p_node->has_meta("_editor_collapsed")) { //remove previous way of storing folding, which did not get along with scene inheritance and instancing if ((bool)p_node->get_meta("_editor_collapsed")) p_node->set_display_folded(true); p_node->set_meta("_editor_collapsed", Variant()); } #endif bool collapsed = p_node->is_displayed_folded(); if (collapsed) item->set_collapsed(true); } Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(p_node, "Node"); item->set_icon(0, icon); item->set_metadata(0, p_node->get_path()); if (connect_to_script_mode) { Color accent = get_color("accent_color", "Editor"); if (!p_node->get_script().is_null()) { //has script item->add_button(0, get_icon("Script", "EditorIcons"), BUTTON_SCRIPT); } else { //has no script item->set_custom_color(0, get_color("disabled_font_color", "Editor")); item->set_selectable(0, false); accent.a *= 0.7; } if (marked.has(p_node)) { item->set_text(0, String(p_node->get_name()) + " " + TTR("(Connecting From)")); item->set_custom_color(0, accent); } } else if (part_of_subscene) { //item->set_selectable(0,marked_selectable); if (valid_types.size() == 0) { item->set_custom_color(0, get_color("disabled_font_color", "Editor")); } } else if (marked.has(p_node)) { if (!connect_to_script_mode) { item->set_selectable(0, marked_selectable); } item->set_custom_color(0, get_color("error_color", "Editor")); } else if (!marked_selectable && !marked_children_selectable) { Node *node = p_node; while (node) { if (marked.has(node)) { item->set_selectable(0, false); item->set_custom_color(0, get_color("error_color", "Editor")); break; } node = node->get_parent(); } } if (can_rename) { //should be can edit.. String warning = p_node->get_configuration_warning(); if (warning != String()) { item->add_button(0, get_icon("NodeWarning", "EditorIcons"), BUTTON_WARNING, false, TTR("Node configuration warning:") + "\n" + p_node->get_configuration_warning()); } bool has_connections = p_node->has_persistent_signal_connections(); bool has_groups = p_node->has_persistent_groups(); if (has_connections && has_groups) { item->add_button(0, get_icon("SignalsAndGroups", "EditorIcons"), BUTTON_SIGNALS, false, TTR("Node has connection(s) and group(s).\nClick to show signals dock.")); } else if (has_connections) { item->add_button(0, get_icon("Signals", "EditorIcons"), BUTTON_SIGNALS, false, TTR("Node has connections.\nClick to show signals dock.")); } else if (has_groups) { item->add_button(0, get_icon("Groups", "EditorIcons"), BUTTON_GROUPS, false, TTR("Node is in group(s).\nClick to show groups dock.")); } } if (p_node == get_scene_node() && p_node->get_scene_inherited_state().is_valid()) { item->add_button(0, get_icon("InstanceOptions", "EditorIcons"), BUTTON_SUBSCENE, false, TTR("Open in Editor")); item->set_tooltip(0, TTR("Inherits:") + " " + p_node->get_scene_inherited_state()->get_path() + "\n" + TTR("Type:") + " " + p_node->get_class()); } else if (p_node != get_scene_node() && p_node->get_filename() != "" && can_open_instance) { item->add_button(0, get_icon("InstanceOptions", "EditorIcons"), BUTTON_SUBSCENE, false, TTR("Open in Editor")); item->set_tooltip(0, TTR("Instance:") + " " + p_node->get_filename() + "\n" + TTR("Type:") + " " + p_node->get_class()); } else { item->set_tooltip(0, String(p_node->get_name()) + "\n" + TTR("Type:") + " " + p_node->get_class()); } if (can_open_instance && undo_redo) { //Show buttons only when necessary(SceneTreeDock) to avoid crashes if (!p_node->is_connected("script_changed", this, "_node_script_changed")) p_node->connect("script_changed", this, "_node_script_changed", varray(p_node)); if (!p_node->get_script().is_null()) { item->add_button(0, get_icon("Script", "EditorIcons"), BUTTON_SCRIPT, false, TTR("Open Script")); } if (p_node->is_class("CanvasItem")) { bool is_locked = p_node->has_meta("_edit_lock_"); //_edit_group_ if (is_locked) item->add_button(0, get_icon("Lock", "EditorIcons"), BUTTON_LOCK, false, TTR("Node is locked.\nClick to unlock it.")); bool is_grouped = p_node->has_meta("_edit_group_"); if (is_grouped) item->add_button(0, get_icon("Group", "EditorIcons"), BUTTON_GROUP, false, TTR("Children are not selectable.\nClick to make selectable.")); bool v = p_node->call("is_visible"); if (v) item->add_button(0, get_icon("GuiVisibilityVisible", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility")); else item->add_button(0, get_icon("GuiVisibilityHidden", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility")); if (!p_node->is_connected("visibility_changed", this, "_node_visibility_changed")) p_node->connect("visibility_changed", this, "_node_visibility_changed", varray(p_node)); _update_visibility_color(p_node, item); } else if (p_node->is_class("Spatial")) { bool is_locked = p_node->has_meta("_edit_lock_"); if (is_locked) item->add_button(0, get_icon("Lock", "EditorIcons"), BUTTON_LOCK, false, TTR("Node is locked.\nClick to unlock it.")); bool is_grouped = p_node->has_meta("_edit_group_"); if (is_grouped) item->add_button(0, get_icon("Group", "EditorIcons"), BUTTON_GROUP, false, TTR("Children are not selectable.\nClick to make selectable.")); bool v = p_node->call("is_visible"); if (v) item->add_button(0, get_icon("GuiVisibilityVisible", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility")); else item->add_button(0, get_icon("GuiVisibilityHidden", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility")); if (!p_node->is_connected("visibility_changed", this, "_node_visibility_changed")) p_node->connect("visibility_changed", this, "_node_visibility_changed", varray(p_node)); _update_visibility_color(p_node, item); } else if (p_node->is_class("AnimationPlayer")) { bool is_pinned = AnimationPlayerEditor::singleton->get_player() == p_node && AnimationPlayerEditor::singleton->is_pinned(); if (is_pinned) { item->add_button(0, get_icon("Pin", "EditorIcons"), BUTTON_PIN, false, TTR("AnimationPlayer is pinned.\nClick to unpin.")); } } } if (editor_selection) { if (editor_selection->is_selected(p_node)) { item->select(0); } } if (selected == p_node) { if (!editor_selection) item->select(0); item->set_as_cursor(0); } bool keep = (filter.is_subsequence_ofi(String(p_node->get_name()))); for (int i = 0; i < p_node->get_child_count(); i++) { bool child_keep = _add_nodes(p_node->get_child(i), item); keep = keep || child_keep; } if (valid_types.size()) { bool valid = false; for (int i = 0; i < valid_types.size(); i++) { if (p_node->is_class(valid_types[i])) { valid = true; break; } } if (!valid) { //item->set_selectable(0,marked_selectable); item->set_custom_color(0, get_color("disabled_font_color", "Editor")); item->set_selectable(0, false); } } if (!keep) { memdelete(item); return false; } else { return true; } }
void ControlEditor::_input_event(InputEvent p_event) { if (p_event.type==InputEvent::MOUSE_BUTTON) { const InputEventMouseButton &b=p_event.mouse_button; if (b.button_index==BUTTON_RIGHT) { if (controls.size() && drag!=DRAG_NONE) { //cancel drag for(ControlMap::Element *E=controls.front();E;E=E->next()) { Control *control = E->key(); control->set_pos(E->get().drag_pos); control->set_size(E->get().drag_size); } } else if (b.pressed) { popup->set_pos(Point2(b.x,b.y)); popup->popup(); } return; } //if (!controls.size()) // return; if (b.button_index!=BUTTON_LEFT) return; if (!b.pressed) { if (drag!=DRAG_NONE) { if (undo_redo) { undo_redo->create_action(TTR("Edit Control")); for(ControlMap::Element *E=controls.front();E;E=E->next()) { Control *control = E->key(); undo_redo->add_do_method(control,"set_pos",control->get_pos()); undo_redo->add_do_method(control,"set_size",control->get_size()); undo_redo->add_undo_method(control,"set_pos",E->get().drag_pos); undo_redo->add_undo_method(control,"set_size",E->get().drag_size); } undo_redo->commit_action(); } drag=DRAG_NONE; } return; } if (controls.size()==1) { //try single control edit Control *control = controls.front()->key(); ERR_FAIL_COND(!current_window); Rect2 rect=control->get_window_rect(); Point2 ofs=Point2();//get_global_pos(); Rect2 draw_rect=Rect2(rect.pos-ofs,rect.size); Point2 click=Point2(b.x,b.y); click = transform.affine_inverse().xform(click); Size2 handle_size=Size2(handle_len,handle_len); drag = DRAG_NONE; if (Rect2(draw_rect.pos-handle_size,handle_size).has_point(click)) drag=DRAG_TOP_LEFT; else if (Rect2(draw_rect.pos+draw_rect.size,handle_size).has_point(click)) drag=DRAG_BOTTOM_RIGHT; else if(Rect2(draw_rect.pos+Point2(draw_rect.size.width,-handle_size.y),handle_size).has_point(click)) drag=DRAG_TOP_RIGHT; else if (Rect2(draw_rect.pos+Point2(-handle_size.x,draw_rect.size.height),handle_size).has_point(click)) drag=DRAG_BOTTOM_LEFT; else if (Rect2(draw_rect.pos+Point2(Math::floor((draw_rect.size.width-handle_size.x)/2.0),-handle_size.height),handle_size).has_point(click)) drag=DRAG_TOP; else if( Rect2(draw_rect.pos+Point2(-handle_size.width,Math::floor((draw_rect.size.height-handle_size.y)/2.0)),handle_size).has_point(click)) drag=DRAG_LEFT; else if ( Rect2(draw_rect.pos+Point2(Math::floor((draw_rect.size.width-handle_size.x)/2.0),draw_rect.size.height),handle_size).has_point(click)) drag=DRAG_BOTTOM; else if( Rect2(draw_rect.pos+Point2(draw_rect.size.width,Math::floor((draw_rect.size.height-handle_size.y)/2.0)),handle_size).has_point(click)) drag=DRAG_RIGHT; if (drag!=DRAG_NONE) { drag_from=click; controls[control].drag_pos=control->get_pos(); controls[control].drag_size=control->get_size(); controls[control].drag_limit=drag_from+controls[control].drag_size-control->get_minimum_size(); return; } } //multi control edit Point2 click=Point2(b.x,b.y); Node* scene = get_scene()->get_root_node()->cast_to<EditorNode>()->get_edited_scene(); if (!scene) return; /* if (current_window) { //no window.... ? click-=current_window->get_scroll(); }*/ Control *c=_select_control_at_pos(click, scene); Node* n = c; while ((n && n != scene && n->get_owner() != scene) || (n && !n->is_type("Control"))) { n = n->get_parent(); }; c = n->cast_to<Control>(); if (b.mod.control) { //additive selection if (!c) return; //nothing to add if (current_window && controls.size() && c->get_window()!=current_window) return; //cant multiple select from multiple windows if (!controls.size()) current_window=c->get_window(); if (controls.has(c)) { //already in here, erase it _remove_control(c); update(); return; } //check parents! Control *parent = c->get_parent()->cast_to<Control>(); while(parent) { if (controls.has(parent)) return; //a parent is already selected, so this is pointless parent=parent->get_parent()->cast_to<Control>(); } //check childrens of everything! List<Control*> to_erase; for(ControlMap::Element *E=controls.front();E;E=E->next()) { parent = E->key()->get_parent()->cast_to<Control>(); while(parent) { if (parent==c) { to_erase.push_back(E->key()); break; } parent=parent->get_parent()->cast_to<Control>(); } } while(to_erase.size()) { _remove_control(to_erase.front()->get()); to_erase.pop_front(); } _add_control(c,EditInfo()); update(); } else { //regular selection if (!c) { _clear_controls(); update(); return; } if (!controls.has(c)) { _clear_controls(); current_window=c->get_window(); _add_control(c,EditInfo()); //reselect if (get_scene()->is_editor_hint()) { get_scene()->get_root_node()->call("edit_node",c); } } for(ControlMap::Element *E=controls.front();E;E=E->next()) { EditInfo &ei=E->get(); Control *control=E->key(); ei.drag_pos=control->get_pos(); ei.drag_size=control->get_size(); ei.drag_limit=drag_from+ei.drag_size-control->get_minimum_size(); } drag=DRAG_ALL; drag_from=click; update(); } } if (p_event.type==InputEvent::MOUSE_MOTION) { const InputEventMouseMotion &m=p_event.mouse_motion; if (drag==DRAG_NONE || !current_window) return; for(ControlMap::Element *E=controls.front();E;E=E->next()) { Control *control = E->key(); Point2 control_drag_pos=E->get().drag_pos; Point2 control_drag_size=E->get().drag_size; Point2 control_drag_limit=E->get().drag_limit; Point2 pos=Point2(m.x,m.y); pos = transform.affine_inverse().xform(pos); switch(drag) { case DRAG_ALL: { control->set_pos( snapify(control_drag_pos+(pos-drag_from)) ); } break; case DRAG_RIGHT: { control->set_size( snapify(Size2(control_drag_size.width+(pos-drag_from).x,control_drag_size.height)) ); } break; case DRAG_BOTTOM: { control->set_size( snapify(Size2(control_drag_size.width,control_drag_size.height+(pos-drag_from).y)) ); } break; case DRAG_BOTTOM_RIGHT: { control->set_size( snapify(control_drag_size+(pos-drag_from)) ); } break; case DRAG_TOP_LEFT: { if(pos.x>control_drag_limit.x) pos.x=control_drag_limit.x; if(pos.y>control_drag_limit.y) pos.y=control_drag_limit.y; Point2 old_size = control->get_size(); Point2 new_pos = snapify(control_drag_pos+(pos-drag_from)); Point2 new_size = old_size + (control->get_pos() - new_pos); control->set_pos( new_pos ); control->set_size( new_size ); } break; case DRAG_TOP: { if(pos.y>control_drag_limit.y) pos.y=control_drag_limit.y; Point2 old_size = control->get_size(); Point2 new_pos = snapify(control_drag_pos+Point2(0,pos.y-drag_from.y)); Point2 new_size = old_size + (control->get_pos() - new_pos); control->set_pos( new_pos ); control->set_size( new_size ); } break; case DRAG_LEFT: { if(pos.x>control_drag_limit.x) pos.x=control_drag_limit.x; Point2 old_size = control->get_size(); Point2 new_pos = snapify(control_drag_pos+Point2(pos.x-drag_from.x,0)); Point2 new_size = old_size + (control->get_pos() - new_pos); control->set_pos( new_pos ); control->set_size( new_size ); } break; case DRAG_TOP_RIGHT: { if(pos.y>control_drag_limit.y) pos.y=control_drag_limit.y; Point2 old_size = control->get_size(); Point2 new_pos = snapify(control_drag_pos+Point2(0,pos.y-drag_from.y)); float new_size_y = Point2( old_size + (control->get_pos() - new_pos)).y; float new_size_x = snapify(control_drag_size+Point2(pos.x-drag_from.x,0)).x; control->set_pos( new_pos ); control->set_size( Point2(new_size_x, new_size_y) ); } break; case DRAG_BOTTOM_LEFT: { if(pos.x>control_drag_limit.x) pos.x=control_drag_limit.x; Point2 old_size = control->get_size(); Point2 new_pos = snapify(control_drag_pos+Point2(pos.x-drag_from.x,0)); float new_size_y = snapify(control_drag_size+Point2(0,pos.y-drag_from.y)).y; float new_size_x = Point2( old_size + (control->get_pos() - new_pos)).x; control->set_pos( new_pos ); control->set_size( Point2(new_size_x, new_size_y) ); } break; default:{} } } } if (p_event.type==InputEvent::KEY) { const InputEventKey &k=p_event.key; if (k.pressed) { if (k.scancode==KEY_UP) _key_move(Vector2(0,-1),k.mod.shift); else if (k.scancode==KEY_DOWN) _key_move(Vector2(0,1),k.mod.shift); else if (k.scancode==KEY_LEFT) _key_move(Vector2(-1,0),k.mod.shift); else if (k.scancode==KEY_RIGHT) _key_move(Vector2(1,0),k.mod.shift); } } }
void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { current_option=p_tool; switch(p_tool) { case TOOL_NEW: { create_dialog->popup_centered_ratio(); } break; case TOOL_INSTANCE: { Node *scene = edited_scene; if (!scene) { current_option=-1; //confirmation->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("This operation can't be done without a tree root."); accept->popup_centered(Size2(300,70));; break; } file->set_mode(FileDialog::MODE_OPEN_FILE); List<String> extensions; ResourceLoader::get_recognized_extensions_for_type("PackedScene",&extensions); file->clear_filters(); for(int i=0;i<extensions.size();i++) { file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper()); } //file->set_current_path(current_path); file->popup_centered_ratio(); } break; case TOOL_REPLACE: { create_dialog->popup_centered_ratio(); } break; case TOOL_CONNECT: { Node *current = scene_tree->get_selected(); if (!current) break; connect_dialog->popup_centered_ratio(); connect_dialog->set_node(current); } break; case TOOL_GROUP: { Node *current = scene_tree->get_selected(); if (!current) break; groups_editor->set_current(current); groups_editor->popup_centered_ratio(); } break; case TOOL_SCRIPT: { Node *selected = scene_tree->get_selected(); if (!selected) break; Ref<Script> existing = selected->get_script(); if (existing.is_valid()) editor->push_item(existing.ptr()); else { String path = selected->get_filename(); script_create_dialog->config(selected->get_type(),path); script_create_dialog->popup_centered(Size2(300,290)); //script_create_dialog->popup_centered_minsize(); } } break; case TOOL_MOVE_UP: case TOOL_MOVE_DOWN: { if (!scene_tree->get_selected()) break; if (scene_tree->get_selected()==edited_scene) { current_option=-1; //accept->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("This operation can't be done on the tree root."); accept->popup_centered(Size2(300,70));; break; } Node * node=scene_tree->get_selected(); ERR_FAIL_COND(!node->get_parent()); int current_pos = node->get_index(); int next_pos = current_pos + ((p_tool==TOOL_MOVE_DOWN)?1:-1); if (next_pos< 0 || next_pos>=node->get_parent()->get_child_count()) break; // invalid position editor_data->get_undo_redo().create_action("Move Node In Parent"); editor_data->get_undo_redo().add_do_method(node->get_parent(),"move_child",node,next_pos); editor_data->get_undo_redo().add_undo_method(node->get_parent(),"move_child",node,current_pos); editor_data->get_undo_redo().commit_action(); } break; case TOOL_DUPLICATE: { if (!edited_scene) break; if (editor_selection->is_selected(edited_scene)) { current_option=-1; //accept->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("This operation can't be done on the tree root."); accept->popup_centered(Size2(300,70));; break; } List<Node*> selection = editor_selection->get_selected_node_list(); List<Node*> reselect; editor_data->get_undo_redo().create_action("Duplicate Node(s)"); editor_data->get_undo_redo().add_do_method(editor_selection,"clear"); Node *dupsingle=NULL; for (List<Node*>::Element *E=selection.front();E;E=E->next()) { Node *node = E->get(); Node *parent = node->get_parent(); List<Node*> owned; node->get_owned_by(node->get_owner(),&owned); Map<Node*,Node*> duplimap; Node * dup = _duplicate(node,duplimap); ERR_CONTINUE(!dup); if (selection.size()==1) dupsingle=dup; String name = node->get_name(); String nums; for(int i=name.length()-1;i>=0;i--) { CharType n=name[i]; if (n>='0' && n<='9') { nums=String::chr(name[i])+nums; } else { break; } } int num=nums.to_int(); if (num<2) num=2; else num++; name=name.substr(0,name.length()-nums.length()).strip_edges(); String attempt=name+" "+itos(num); while(parent->has_node(attempt)) { num++; attempt=name+" "+itos(num); } dup->set_name(attempt); editor_data->get_undo_redo().add_do_method(parent,"add_child",dup); for (List<Node*>::Element *F=owned.front();F;F=F->next()) { if (!duplimap.has(F->get())) { continue; } Node *d=duplimap[F->get()]; editor_data->get_undo_redo().add_do_method(d,"set_owner",node->get_owner()); } editor_data->get_undo_redo().add_do_method(editor_selection,"add_node",dup); editor_data->get_undo_redo().add_undo_method(parent,"remove_child",dup); editor_data->get_undo_redo().add_do_reference(dup); //parent->add_child(dup); //reselect.push_back(dup); } editor_data->get_undo_redo().commit_action(); if (dupsingle) editor->push_item(dupsingle); } break; case TOOL_REPARENT: { if (!scene_tree->get_selected()) break; if (editor_selection->is_selected(edited_scene)) { current_option=-1; //confirmation->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("This operation can't be done on the tree root."); accept->popup_centered(Size2(300,70));; break; } List<Node*> nodes = editor_selection->get_selected_node_list(); Set<Node*> nodeset; for(List<Node*>::Element *E=nodes.front();E;E=E->next()) { nodeset.insert(E->get()); } reparent_dialog->popup_centered_ratio(); reparent_dialog->set_current( nodeset ); } break; case TOOL_ERASE: { List<Node*> remove_list = editor_selection->get_selected_node_list(); if (remove_list.empty()) return; if (p_confirm_override) { _delete_confirm(); // hack, force 2d editor viewport to refresh after deletion if (CanvasItemEditor *editor = CanvasItemEditor::get_singleton()) editor->get_viewport_control()->update(); } else { delete_dialog->set_text("Delete Node(s)?"); delete_dialog->popup_centered(Size2(200,80)); } } break; } }
void SceneTreeDock::_delete_confirm() { List<Node*> remove_list = editor_selection->get_selected_node_list(); if (remove_list.empty()) return; if (editor->get_editor_plugin_over()) editor->get_editor_plugin_over()->make_visible(false); editor_data->get_undo_redo().create_action("Remove Node(s)"); bool entire_scene=false; for(List<Node*>::Element *E=remove_list.front();E;E=E->next()) { if (E->get()==edited_scene) { entire_scene=true; } } if (entire_scene) { editor_data->get_undo_redo().add_do_method(editor,"set_edited_scene",(Object*)NULL); editor_data->get_undo_redo().add_undo_method(editor,"set_edited_scene",edited_scene); editor_data->get_undo_redo().add_undo_method(edited_scene,"set_owner",edited_scene->get_owner()); editor_data->get_undo_redo().add_undo_reference(edited_scene); } else { remove_list.sort_custom<Node::Comparator>(); //sort nodes to keep positions List<Pair<NodePath,NodePath> > path_renames; //delete from animation for(List<Node*>::Element *E=remove_list.front();E;E=E->next()) { Node *n = E->get(); if (!n->is_inside_scene() || !n->get_parent()) continue; fill_path_renames(n,NULL,&path_renames); } perform_node_renames(NULL,&path_renames); //delete for read for(List<Node*>::Element *E=remove_list.front();E;E=E->next()) { Node *n = E->get(); if (!n->is_inside_scene() || !n->get_parent()) continue; List<Node*> owned; n->get_owned_by(n->get_owner(),&owned); Array owners; for(List<Node*>::Element *E=owned.front();E;E=E->next()) { owners.push_back(E->get()); } editor_data->get_undo_redo().add_do_method(n->get_parent(),"remove_child",n); editor_data->get_undo_redo().add_undo_method(n->get_parent(),"add_child",n); editor_data->get_undo_redo().add_undo_method(n->get_parent(),"move_child",n,n->get_index()); if (editor->get_animation_editor()->get_root()==n) editor_data->get_undo_redo().add_undo_method(editor->get_animation_editor(),"set_root",n); editor_data->get_undo_redo().add_undo_method(this,"_set_owners",edited_scene,owners); //editor_data->get_undo_redo().add_undo_method(n,"set_owner",n->get_owner()); editor_data->get_undo_redo().add_undo_reference(n); } } editor_data->get_undo_redo().commit_action(); _update_tool_buttons(); }