def ungroupSelected(self): ungrouped_nodes = [] selected_objects = Selection.getAllSelectedObjects( )[:] #clone the list for node in selected_objects: if node.callDecoration("isGroup"): children_to_move = [] for child in node.getChildren(): if type(child) is SceneNode: children_to_move.append(child) for child in children_to_move: child.setParent(node.getParent()) print(node.getPosition()) child.translate(node.getPosition()) child.setPosition(child.getPosition().scale( node.getScale())) child.scale(node.getScale()) child.rotate(node.getOrientation()) Selection.add(child) child.callDecoration("setConvexHull", None) node.setParent(None) ungrouped_nodes.append(node) for node in ungrouped_nodes: Selection.remove(node)
def _replaceSceneNode(self, existing_node, trimeshes): name = existing_node.getName() file_name = existing_node.getMeshData().getFileName() transformation = existing_node.getWorldTransformation() parent = existing_node.getParent() extruder_id = existing_node.callDecoration("getActiveExtruder") build_plate = existing_node.callDecoration("getBuildPlateNumber") selected = Selection.isSelected(existing_node) op = GroupedOperation() op.addOperation(RemoveSceneNodeOperation(existing_node)) for i, tri_node in enumerate(trimeshes): mesh_data = self._toMeshData(tri_node) new_node = CuraSceneNode() new_node.setSelectable(True) new_node.setMeshData(mesh_data) new_node.setName(name if i == 0 else "%s %d" % (name, i)) new_node.callDecoration("setActiveExtruder", extruder_id) new_node.addDecorator(BuildPlateDecorator(build_plate)) new_node.addDecorator(SliceableObjectDecorator()) op.addOperation(AddSceneNodeOperation(new_node, parent)) op.addOperation( SetTransformMatrixOperation(new_node, transformation)) if selected: Selection.add(new_node) op.push()
def _boundingBoxSelection(self, event): """Handle mouse and keyboard events for bounding box selection :param event: type(Event) passed from self.event() """ root = self._scene.getRoot() ray = self._scene.getActiveCamera().getRay(event.x, event.y) intersections = [] for node in BreadthFirstIterator(root): if node.isEnabled() and not node.isLocked(): intersection = node.getBoundingBox().intersectsRay(ray) if intersection: intersections.append((node, intersection[0], intersection[1])) if intersections: intersections.sort(key=lambda k: k[1]) node = intersections[0][0] if not Selection.isSelected(node): if not self._shift_is_active: Selection.clear() Selection.add(node) else: Selection.clear()
def test_getSelectedObjectsWithoutSelectedAncestors(): scene_node_1 = SceneNode() Selection.add(scene_node_1) test_tool_1 = Tool() assert test_tool_1._getSelectedObjectsWithoutSelectedAncestors() == [ scene_node_1 ]
def _pixelSelection(self, event): pixel_id = self._renderer.getIdAtCoordinate(event.x, event.y) if not pixel_id: Selection.clear() return for node in BreadthFirstIterator(self._scene.getRoot()): if id(node) == pixel_id: if self._ctrl_is_active: if Selection.isSelected(node): if node.getParent(): if node.getParent().callDecoration("isGroup"): Selection.remove(node.getParent()) else: Selection.remove(node) else: Selection.add(node) if node.getParent(): if node.getParent().callDecoration("isGroup"): Selection.add(node.getParent()) else: Selection.add(node) else: if not Selection.isSelected(node) or Selection.getCount() > 1: Selection.clear() if node.getParent(): if node.getParent().callDecoration("isGroup"): Selection.add(node.getParent()) else: Selection.add(node)
def test_addRemoveSelection(self): node_1 = SceneNode() Selection.add(node_1) assert Selection.getAllSelectedObjects() == [node_1] Selection.remove(node_1) assert Selection.getAllSelectedObjects() == []
def _replaceSceneNode(self, existing_node, trimeshes) -> None: name = existing_node.getName() file_name = existing_node.getMeshData().getFileName() transformation = existing_node.getWorldTransformation() parent = existing_node.getParent() extruder_id = existing_node.callDecoration("getActiveExtruder") build_plate = existing_node.callDecoration("getBuildPlateNumber") selected = Selection.isSelected(existing_node) children = existing_node.getChildren() new_nodes = [] op = GroupedOperation() op.addOperation(RemoveSceneNodeOperation(existing_node)) for i, tri_node in enumerate(trimeshes): mesh_data = self._toMeshData(tri_node, file_name) new_node = CuraSceneNode() new_node.setSelectable(True) new_node.setMeshData(mesh_data) new_node.setName(name if i==0 else "%s %d" % (name, i)) new_node.callDecoration("setActiveExtruder", extruder_id) new_node.addDecorator(BuildPlateDecorator(build_plate)) new_node.addDecorator(SliceableObjectDecorator()) op.addOperation(AddSceneNodeOperation(new_node, parent)) op.addOperation(SetTransformMatrixOperation(new_node, transformation)) new_nodes.append(new_node) if selected: Selection.add(new_node) for child in children: mesh_data = child.getMeshData() if not mesh_data: continue child_bounding_box = mesh_data.getTransformed(child.getWorldTransformation()).getExtents() if not child_bounding_box: continue new_parent = None for potential_parent in new_nodes: parent_mesh_data = potential_parent.getMeshData() if not parent_mesh_data: continue parent_bounding_box = parent_mesh_data.getTransformed(potential_parent.getWorldTransformation()).getExtents() if not parent_bounding_box: continue intersection = child_bounding_box.intersectsBox(parent_bounding_box) if intersection != AxisAlignedBox.IntersectionResult.NoIntersection: new_parent = potential_parent break if not new_parent: new_parent = new_nodes[0] op.addOperation(SetParentOperationSimplified(child, new_parent)) op.push()
def test_getSelectedObject(self): node_1 = SceneNode() node_2 = SceneNode() Selection.add(node_1) Selection.add(node_2) assert Selection.getSelectedObject(0) == node_1 assert Selection.getSelectedObject(1) == node_2 assert Selection.getSelectedObject(3) is None
def _pixelSelection(self, event): # Find a node id by looking at a pixel value at the requested location if self._selection_pass: item_id = self._selection_pass.getIdAtPosition(event.x, event.y) else: Logger.log("w", "Selection pass is None. getRenderPass('selection') returned None") return False if not item_id and not self._shift_is_active: if Selection.hasSelection(): Selection.clear() return True return False # Nothing was selected before and the user didn't click on an object. # Find the scene-node which matches the node-id for node in BreadthFirstIterator(self._scene.getRoot()): if id(node) != item_id: continue if self._isNodeInGroup(node): is_selected = Selection.isSelected(self._findTopGroupNode(node)) else: is_selected = Selection.isSelected(node) if self._shift_is_active: if is_selected: # Deselect the SceneNode and its siblings in a group if node.getParent(): if self._ctrl_is_active or not self._isNodeInGroup(node): Selection.remove(node) else: Selection.remove(self._findTopGroupNode(node)) return True else: # Select the SceneNode and its siblings in a group if node.getParent(): if self._ctrl_is_active or not self._isNodeInGroup(node): Selection.add(node) else: Selection.add(self._findTopGroupNode(node)) return True else: if not is_selected or Selection.getCount() > 1: # Select only the SceneNode and its siblings in a group Selection.clear() if node.getParent(): if self._ctrl_is_active or not self._isNodeInGroup(node): Selection.add(node) else: Selection.add(self._findTopGroupNode(node)) return True elif self._isNodeInGroup(node) and self._ctrl_is_active: Selection.clear() Selection.add(node) return True return False
def test_addRemoveSelection(self): node_1 = SceneNode() Selection.add(node_1) Selection.setFace(node_1, 99) assert Selection.getAllSelectedObjects() == [node_1] Selection.remove(node_1) assert Selection.getAllSelectedObjects() == [] assert Selection.getSelectedFace() is None
def test_selectionCount(self): assert self.proxy.selectionCount == 0 node_1 = SceneNode() Selection.add(node_1) assert self.proxy.selectionCount == 1 node_2 = SceneNode() Selection.add(node_2) assert self.proxy.selectionCount == 2
def test_clearSelection(self): node_1 = SceneNode() node_2 = SceneNode() Selection.add(node_1) Selection.add(node_2) # Ensure that the objects we want selected are selected assert Selection.getAllSelectedObjects() == [node_1, node_2] Selection.clear() assert Selection.getAllSelectedObjects() == []
def test_getSelectionCenter(self): node_1 = SceneNode() node_1.getBoundingBox = MagicMock(return_value = AxisAlignedBox(Vector(0, 0, 0), Vector(10, 20, 30))) Selection.add(node_1) assert Selection.getSelectionCenter() == Vector(5, 10, 15) node_2 = SceneNode() node_2.getBoundingBox = MagicMock(return_value=AxisAlignedBox(Vector(0, 0, 0), Vector(20, 30, 40))) Selection.add(node_2) assert Selection.getSelectionCenter() == Vector(10, 15, 20)
def test_selectionCount(self): assert self.proxy.selectionCount == 0 node_1 = SceneNode() Selection.add(node_1) assert self.proxy.selectionCount == 1 node_2 = SceneNode() Selection.add(node_2) assert self.proxy.selectionCount == 2
def test_hasSelection(self): # Nothing is selected by default assert not self.proxy.hasSelection node_1 = SceneNode() Selection.add(node_1) assert self.proxy.hasSelection Selection.remove(node_1) assert not self.proxy.hasSelection
def test_hasSelection(self): # Nothing is selected by default assert not self.proxy.hasSelection node_1 = SceneNode() Selection.add(node_1) assert self.proxy.hasSelection Selection.remove(node_1) assert not self.proxy.hasSelection
def redo(self): self._node.setParent(self._parent) print_mode = Application.getInstance().getGlobalContainerStack( ).getProperty("print_mode", "value") if print_mode == "regular": self._node_dup.setParent(None) else: self._node_dup.setParent(self._parent) if self._selected: # It was selected while the operation was undone. We should restore that selection. Selection.add(self._node) self._print_mode_manager.addDuplicatedNode(self._node_dup)
def _removeEraserMesh(self, node: CuraSceneNode): parent = node.getParent() if parent == self._controller.getScene().getRoot(): parent = None op = RemoveSceneNodeOperation(node) op.push() if parent and not Selection.isSelected(parent): Selection.add(parent) CuraApplication.getInstance().getController().getScene().sceneChanged.emit(node)
def test_UndoRedoWithSelection(): node = SceneNode() parent_node = SceneNode() Selection.add(node) operation = AddSceneNodeOperation(node, parent_node) operation.undo() assert not Selection.isSelected(node) operation.redo() assert Selection.isSelected(node)
def _pixelSelection(self, event): pixel_id = self._renderer.getIdAtCoordinate(event.x, event.y) if not pixel_id: Selection.clear() return for node in BreadthFirstIterator(self._scene.getRoot()): if id(node) == pixel_id: if not Selection.isSelected(node): Selection.clear() Selection.add(node)
def selectAll(self): if not self.getController().getToolsEnabled(): return Selection.clear() for node in DepthFirstIterator(self.getController().getScene().getRoot()): if type(node) is not SceneNode: continue if not node.getMeshData() and not node.callDecoration("isGroup"): continue # Node that doesnt have a mesh and is not a group. if node.getParent() and node.getParent().callDecoration("isGroup"): continue # Grouped nodes don't need resetting as their parent (the group) is resetted) Selection.add(node)
def groupSelected(self): group_node = SceneNode() group_decorator = GroupDecorator() group_node.addDecorator(group_decorator) group_node.setParent(self.getController().getScene().getRoot()) for node in Selection.getAllSelectedObjects(): node.setParent(group_node) for node in group_node.getChildren(): Selection.remove(node) Selection.add(group_node)
def groupSelected(self): group_node = SceneNode() group_decorator = GroupDecorator() group_node.addDecorator(group_decorator) group_node.setParent(self.getController().getScene().getRoot()) for node in Selection.getAllSelectedObjects(): node.setParent(group_node) for node in group_node.getChildren(): Selection.remove(node) Selection.add(group_node)
def selectAll(self): if not self.getController().getToolsEnabled(): return Selection.clear() for node in DepthFirstIterator(self.getController().getScene().getRoot()): if type(node) is not SceneNode: continue if not node.getMeshData() and not node.callDecoration("isGroup"): continue # Node that doesnt have a mesh and is not a group. if node.getParent() and node.getParent().callDecoration("isGroup"): continue # Grouped nodes don't need resetting as their parent (the group) is resetted) Selection.add(node)
def _removeSplittingPlane(self, node: SteSlicerSceneNode): parent = node.getParent() if parent == self._controller.getScene().getRoot(): parent = None op = RemoveSceneNodeOperation(node) op.push() if parent and not Selection.isSelected(parent): Selection.add(parent) SteSlicerApplication.getInstance().getController().getScene( ).sceneChanged.emit(node)
def groupSelected(self): group_node = SceneNode() group_decorator = GroupDecorator() group_node.addDecorator(group_decorator) group_node.setParent(self.getController().getScene().getRoot()) for node in Selection.getAllSelectedObjects(): node.setParent(group_node) group_node.setCenterPosition(group_node.getBoundingBox().center) #group_node.translate(Vector(0,group_node.getBoundingBox().center.y,0)) group_node.translate(group_node.getBoundingBox().center) for node in group_node.getChildren(): Selection.remove(node) Selection.add(group_node)
def groupSelected(self): group_node = SceneNode() group_decorator = GroupDecorator() group_node.addDecorator(group_decorator) group_node.setParent(self.getController().getScene().getRoot()) for node in Selection.getAllSelectedObjects(): node.setParent(group_node) group_node.setCenterPosition(group_node.getBoundingBox().center) #group_node.translate(Vector(0,group_node.getBoundingBox().center.y,0)) group_node.translate(group_node.getBoundingBox().center) for node in group_node.getChildren(): Selection.remove(node) Selection.add(group_node)
def ungroupSelected(self): selected_objects = Selection.getAllSelectedObjects().copy() for node in selected_objects: if node.callDecoration("isGroup"): op = GroupedOperation() group_parent = node.getParent() children = node.getChildren().copy() for child in children: # Set the parent of the children to the parent of the group-node op.addOperation(SetParentOperation(child, group_parent)) # Add all individual nodes to the selection Selection.add(child) op.push()
def ungroupSelected(self): selected_objects = Selection.getAllSelectedObjects().copy() for node in selected_objects: if node.callDecoration("isGroup"): op = GroupedOperation() group_parent = node.getParent() children = node.getChildren().copy() for child in children: # Set the parent of the children to the parent of the group-node op.addOperation(SetParentOperation(child, group_parent)) # Add all individual nodes to the selection Selection.add(child) op.push()
def _pixelSelection(self, event): # Find a node id by looking at a pixel value at the requested location item_id = self._selection_pass.getIdAtPosition(event.x, event.y) if not item_id: Selection.clear() return # Find the scene-node which matches the node-id for node in BreadthFirstIterator(self._scene.getRoot()): if id(node) == item_id: if self._isNodeInGroup(node): is_selected = Selection.isSelected( self._findTopGroupNode(node)) else: is_selected = Selection.isSelected(node) if self._ctrl_is_active: if is_selected: # Deselect the scenenode and its sibblings in a group if node.getParent(): if self._alt_is_active or not self._isNodeInGroup( node): Selection.remove(node) else: Selection.remove(self._findTopGroupNode(node)) else: # Select the scenenode and its sibblings in a group if node.getParent(): if self._alt_is_active or not self._isNodeInGroup( node): Selection.add(node) else: Selection.add(self._findTopGroupNode(node)) else: if not is_selected or Selection.getCount() > 1: # Select only the scenenode and its sibblings in a group Selection.clear() if node.getParent(): if self._alt_is_active or not self._isNodeInGroup( node): Selection.add(node) else: Selection.add(self._findTopGroupNode(node)) elif self._isNodeInGroup(node) and self._alt_is_active: Selection.clear() Selection.add(node)
def ungroupSelected(self): ungrouped_nodes = [] selected_objects = Selection.getAllSelectedObjects()[:] #clone the list for node in selected_objects: if node.callDecoration("isGroup" ): children_to_move = [] for child in node.getChildren(): if type(child) is SceneNode: children_to_move.append(child) for child in children_to_move: child.setParent(node.getParent()) Selection.add(child) child.callDecoration("setConvexHull",None) node.setParent(None) ungrouped_nodes.append(node) for node in ungrouped_nodes: Selection.remove(node)
def groupSelected(self): # Create a group-node group_node = SceneNode() group_decorator = GroupDecorator() group_node.addDecorator(group_decorator) group_node.setParent(self.getController().getScene().getRoot()) group_node.setSelectable(True) center = Selection.getSelectionCenter() group_node.setPosition(center) group_node.setCenterPosition(center) # Move selected nodes into the group-node Selection.applyOperation(SetParentOperation, group_node) # Deselect individual nodes and select the group-node instead for node in group_node.getChildren(): Selection.remove(node) Selection.add(group_node)
def groupSelected(self): group_node = SceneNode() group_decorator = GroupDecorator() group_node.addDecorator(group_decorator) group_node.setParent(self.getController().getScene().getRoot()) center = Selection.getSelectionCenter() group_node.setPosition(center) group_node.setCenterPosition(center) for node in Selection.getAllSelectedObjects(): world = node.getWorldPosition() node.setParent(group_node) node.setPosition(world - center) for node in group_node.getChildren(): Selection.remove(node) Selection.add(group_node)
def groupSelected(self): # Create a group-node group_node = SceneNode() group_decorator = GroupDecorator() group_node.addDecorator(group_decorator) group_node.setParent(self.getController().getScene().getRoot()) group_node.setSelectable(True) center = Selection.getSelectionCenter() group_node.setPosition(center) group_node.setCenterPosition(center) # Move selected nodes into the group-node Selection.applyOperation(SetParentOperation, group_node) # Deselect individual nodes and select the group-node instead for node in group_node.getChildren(): Selection.remove(node) Selection.add(group_node)
def groupSelected(self): group_node = SceneNode() group_decorator = GroupDecorator() group_node.addDecorator(group_decorator) group_node.setParent(self.getController().getScene().getRoot()) center = Selection.getSelectionCenter() group_node.setPosition(center) group_node.setCenterPosition(center) for node in Selection.getAllSelectedObjects(): world = node.getWorldPosition() node.setParent(group_node) node.setPosition(world - center) for node in group_node.getChildren(): Selection.remove(node) Selection.add(group_node)
def _pixelSelection(self, event): # Find a node id by looking at a pixel value at the requested location item_id = self._selection_pass.getIdAtPosition(event.x, event.y) if not item_id and not self._shift_is_active: Selection.clear() return # Find the scene-node which matches the node-id for node in BreadthFirstIterator(self._scene.getRoot()): if id(node) == item_id: if self._isNodeInGroup(node): is_selected = Selection.isSelected(self._findTopGroupNode(node)) else: is_selected = Selection.isSelected(node) if self._shift_is_active: if is_selected: # Deselect the scenenode and its sibblings in a group if node.getParent(): if self._ctrl_is_active or not self._isNodeInGroup(node): Selection.remove(node) else: Selection.remove(self._findTopGroupNode(node)) else: # Select the scenenode and its sibblings in a group if node.getParent(): if self._ctrl_is_active or not self._isNodeInGroup(node): Selection.add(node) else: Selection.add(self._findTopGroupNode(node)) else: if not is_selected or Selection.getCount() > 1: # Select only the scenenode and its sibblings in a group Selection.clear() if node.getParent(): if self._ctrl_is_active or not self._isNodeInGroup(node): Selection.add(node) else: Selection.add(self._findTopGroupNode(node)) elif self._isNodeInGroup(node) and self._ctrl_is_active: Selection.clear() Selection.add(node)
def test_applyOperation(self): # If there is no selection, nothing should happen assert Selection.applyOperation(TranslateOperation) is None node_1 = SceneNode() Selection.add(node_1) Selection.applyOperation(TranslateOperation, Vector(10, 20, 30)) assert node_1.getPosition() == Vector(10, 20, 30) node_2 = SceneNode() Selection.add(node_2) assert len(Selection.applyOperation(TranslateOperation, Vector(10, 20, 30))) == 2 # Node 1 got moved twice assert node_1.getPosition() == Vector(20, 40, 60) # And node 2 only once assert node_2.getPosition() == Vector(10, 20, 30)
def _boundingBoxSelection(self, event): root = self._scene.getRoot() ray = self._scene.getActiveCamera().getRay(event.x, event.y) intersections = [] for node in BreadthFirstIterator(root): if node.getSelectionMask() == self._selectionMask and not node.isLocked(): intersection = node.getBoundingBox().intersectsRay(ray) if intersection: intersections.append((node, intersection[0], intersection[1])) if intersections: intersections.sort(key=lambda k: k[1]) node = intersections[0][0] if not Selection.isSelected(node): Selection.clear() Selection.add(node) else: Selection.clear()
def setSelected(self, key): for index in range(0,len(self.items)): if self.items[index]["key"] == key: for node in Application.getInstance().getController().getScene().getRoot().getAllChildren(): if id(node) == key: if node not in Selection.getAllSelectedObjects(): #node already selected Selection.add(node) if self.items[index]["depth"] == 1: #Its a group node for child_node in node.getChildren(): if child_node not in Selection.getAllSelectedObjects(): #Set all children to parent state (if they arent already) Selection.add(child_node) else: Selection.remove(node) if self.items[index]["depth"] == 1: #Its a group for child_node in node.getChildren(): if child_node in Selection.getAllSelectedObjects(): Selection.remove(child_node) all_children_selected = True #Check all group nodes to see if all their children are selected (if so, they also need to be selected!) for index in range(0,len(self.items)): if self.items[index]["depth"] == 1: for node in Application.getInstance().getController().getScene().getRoot().getAllChildren(): if node.hasChildren(): if id(node) == self.items[index]["key"] and id(node) != key: for index, child_node in enumerate(node.getChildren()): if not Selection.isSelected(child_node): all_children_selected = False #At least one of its children is not selected, dont change state break if all_children_selected: Selection.add(node) else: Selection.remove(node) #Force update self.updateList(Application.getInstance().getController().getScene().getRoot())
def changeSelection(self, index): modifiers = QApplication.keyboardModifiers() ctrl_is_active = modifiers & Qt.ControlModifier shift_is_active = modifiers & Qt.ShiftModifier if ctrl_is_active: item = self._objects_model.getItem(index) node = item["node"] if Selection.isSelected(node): Selection.remove(node) else: Selection.add(node) elif shift_is_active: polarity = 1 if index + 1 > self._last_selected_index else -1 for i in range(self._last_selected_index, index + polarity, polarity): item = self._objects_model.getItem(i) node = item["node"] Selection.add(node) else: # Single select item = self._objects_model.getItem(index) node = item["node"] build_plate_number = node.callDecoration("getBuildPlateNumber") if build_plate_number is not None and build_plate_number != -1: self.setActiveBuildPlate(build_plate_number) Selection.clear() Selection.add(node) self._last_selected_index = index
def onStageSelected(self): application = CuraApplication.getInstance() controller = application.getController() Selection.clear() printable_node = self._exit_stage_if_scene_is_invalid() if not printable_node: return self._previous_view = controller.getActiveView().name # When the Smart Slice stage is active we want to use our SmartSliceView # to control the rendering of various nodes. Views are referred to by their # plugin name. controller.setActiveView('SmartSlicePlugin') if not Selection.hasSelection(): Selection.add(printable_node) # Ensure we have tools defined and apply them here use_tool = self._our_toolset[0] self.setToolVisibility(True) controller.setFallbackTool(use_tool) self._previous_tool = controller.getActiveTool() if self._previous_tool: controller.setActiveTool(use_tool) # Set the Active Extruder for the Cloud interactions self._connector._proxy._activeMachineManager = CuraApplication.getInstance( ).getMachineManager() self._connector._proxy._activeExtruder = self._connector._proxy._activeMachineManager._global_container_stack.extruderList[ 0] if not self._connector.propertyHandler._initialized: self._connector.propertyHandler.cacheChanges() self._connector.propertyHandler._initialized = True self._connector.updateSliceWidget()
def changeSelection(self, index): modifiers = QApplication.keyboardModifiers() ctrl_is_active = modifiers & Qt.ControlModifier shift_is_active = modifiers & Qt.ShiftModifier if ctrl_is_active: item = self._objects_model.getItem(index) node = item["node"] if Selection.isSelected(node): Selection.remove(node) else: Selection.add(node) elif shift_is_active: polarity = 1 if index + 1 > self._last_selected_index else -1 for i in range(self._last_selected_index, index + polarity, polarity): item = self._objects_model.getItem(i) node = item["node"] Selection.add(node) else: # Single select item = self._objects_model.getItem(index) node = item["node"] build_plate_number = node.callDecoration("getBuildPlateNumber") if build_plate_number is not None and build_plate_number != -1: self.setActiveBuildPlate(build_plate_number) Selection.clear() Selection.add(node) self._last_selected_index = index
def _boundingBoxSelection(self, event): root = self._scene.getRoot() ray = self._scene.getActiveCamera().getRay(event.x, event.y) intersections = [] for node in BreadthFirstIterator(root): if node.isEnabled() and not node.isLocked(): intersection = node.getBoundingBox().intersectsRay(ray) if intersection: intersections.append((node, intersection[0], intersection[1])) if intersections: intersections.sort(key=lambda k: k[1]) node = intersections[0][0] if not Selection.isSelected(node): if not self._ctrl_is_active: Selection.clear() Selection.add(node) else: Selection.clear()
def _pixelSelection(self, event): pixel_id = self._renderer.getIdAtCoordinate(event.x, event.y) if not pixel_id: Selection.clear() return for node in BreadthFirstIterator(self._scene.getRoot()): if id(node) == pixel_id: if self._ctrl_is_active: if Selection.isSelected(node): if node.getParent(): group_node = node.getParent() if not group_node.callDecoration("isGroup"): Selection.remove(node) else: while group_node.getParent().callDecoration( "isGroup"): group_node = group_node.getParent() Selection.remove(group_node) else: if node.getParent(): group_node = node.getParent() if not group_node.callDecoration("isGroup"): Selection.add(node) else: while group_node.getParent().callDecoration( "isGroup"): group_node = group_node.getParent() Selection.add(group_node) else: if not Selection.isSelected( node) or Selection.getCount() > 1: Selection.clear() if node.getParent(): group_node = node.getParent() if not group_node.callDecoration("isGroup"): Selection.add(node) else: while group_node.getParent().callDecoration( "isGroup"): group_node = group_node.getParent() Selection.add(group_node)
def _pixelSelection(self, event): item_id = self._selection_pass.getIdAtPosition(event.x, event.y) if not item_id: Selection.clear() return for node in BreadthFirstIterator(self._scene.getRoot()): if id(node) == item_id: if self._ctrl_is_active: if Selection.isSelected(node): if node.getParent(): group_node = node.getParent() if not group_node.callDecoration("isGroup"): Selection.remove(node) else: while group_node.getParent().callDecoration("isGroup"): group_node = group_node.getParent() Selection.remove(group_node) else: if node.getParent(): group_node = node.getParent() if not group_node.callDecoration("isGroup"): Selection.add(node) else: while group_node.getParent().callDecoration("isGroup"): group_node = group_node.getParent() Selection.add(group_node) else: if not Selection.isSelected(node) or Selection.getCount() > 1: Selection.clear() if node.getParent(): group_node = node.getParent() if not group_node.callDecoration("isGroup"): Selection.add(node) else: while group_node.getParent().callDecoration("isGroup"): group_node = group_node.getParent() Selection.add(group_node)
def setSelected(self, key): for index in range(0, len(self.items)): if self.items[index]["key"] == key: for node in Application.getInstance().getController().getScene( ).getRoot().getAllChildren(): if id(node) == key: if node not in Selection.getAllSelectedObjects( ): #node already selected Selection.add(node) if node.callDecoration( "isGroup"): #Its a group node for child_node in node.getChildren(): if child_node not in Selection.getAllSelectedObjects( ): #Set all children to parent state (if they arent already) Selection.add(child_node) else: Selection.remove(node) if node.callDecoration("isGroup"): #Its a group for child_node in node.getChildren(): if child_node in Selection.getAllSelectedObjects( ): Selection.remove(child_node) all_children_selected = True #Check all group nodes to see if all their children are selected (if so, they also need to be selected!) for index in range(0, len(self.items)): if self.items[index]["is_group"]: for node in Application.getInstance().getController().getScene( ).getRoot().getAllChildren(): if node.hasChildren(): if id(node) == self.items[index]["key"] and id( node) != key: for index, child_node in enumerate( node.getChildren()): if not Selection.isSelected(child_node): all_children_selected = False #At least one of its children is not selected, dont change state break if all_children_selected: Selection.add(node) else: Selection.remove(node) #Force update self.updateList( Application.getInstance().getController().getScene().getRoot())
def test_selectionNames(self): node_1 = SceneNode(name="TestNode1") node_2 = SceneNode(name="TestNode2") Selection.add(node_2) Selection.add(node_1) assert self.proxy.selectionNames == ["TestNode2", "TestNode1"]
def test_getSelectedObjectsWithoutSelectedAncestors(): scene_node_1 = SceneNode() Selection.add(scene_node_1) test_tool_1 = Tool() assert test_tool_1._getSelectedObjectsWithoutSelectedAncestors() == [scene_node_1]
def redo(self): self._node.setParent(self._parent) if self._selected: # It was selected while the operation was undone. We should restore that selection. Selection.add(self._node)
def redo(self): self._node.setParent(self._parent) if self._selected: Selection.add(self._node)