Exemplo n.º 1
0
    def test_sub_layer(self):
        # GIVEN
        layer_manager = LayerManager(bpy.context)
        obj_data = bpy.data.meshes.new("test_sub_layer_mesh")
        obj = bpy.data.objects.new(name="test_sub_layer", object_data=obj_data)
        bpy.context.scene.objects.link(obj)
        obj.select = True

        # WHEN
        layer_manager.add(["layer_sub_1", "layer_sub_2", "layer_sub_3"])

        # THEN
        self.assertEqual(len(obj.kuesa.layers), 3)

        # WHEN
        layer_manager.sub(["layer_sub_2", "layer_sub_3"])

        # THEN
        self.assertEqual(len(obj.kuesa.layers), 1)
        self.assertEqual(obj.kuesa.layers[0].name, "layer_sub_1")

        # WHEN
        layer_manager.sub(["layer_sub_1"])

        # THEN
        self.assertEqual(len(obj.kuesa.layers), 0)
Exemplo n.º 2
0
    def test_gather_layer_names(self):
        # GIVEN
        layer_manager = LayerManager(bpy.context)
        obj_data = bpy.data.meshes.new("test_gather_layer_names_mesh")
        obj = bpy.data.objects.new(name="test_gather_layer_names", object_data=obj_data)

        # WHEN
        names = layer_manager.gather_layer_names(obj)

        # THEN
        self.assertEqual(len(names), 0)

        # WHEN
        layer_manager.add(["layer1"], obj)
        names = layer_manager.gather_layer_names(obj)

        # THEN
        self.assertEqual(len(names), 1)
        self.assertIn("layer1", names)

        # WHEN
        layer_manager.add(["layer2"], obj)
        names = layer_manager.gather_layer_names(obj)

        # THEN
        self.assertEqual(len(names), 2)
        self.assertIn("layer1", names)
        self.assertIn("layer2", names)
Exemplo n.º 3
0
    def test_meets_intersect(self):
        # Intersect as in a layer must be defined in each objects

        # GIVEN
        layer_manager = LayerManager(bpy.context)
        obj_data = bpy.data.meshes.new("test_meets_intersect_mesh")
        obj1 = bpy.data.objects.new(name="test_meets_intersect_1", object_data=obj_data)
        obj2 = bpy.data.objects.new(name="test_meets_intersect_2", object_data=obj_data)
        bpy.context.scene.objects.link(obj1)
        bpy.context.scene.objects.link(obj2)
        bpy.ops.object.select_all(action='DESELECT')

        # THEN
        self.assertEqual(len(bpy.context.selected_objects), 0)

        # WHEN
        obj1.select = True
        obj2.select = False
        layer_manager.add(["layer_meets_intersect_1", "layer_meets_intersect_2"])

        obj2.select = True
        obj1.select = False
        layer_manager.add(["layer_meets_intersect_1", "layer_meets_intersect_3"])

        # THEN
        self.assertEqual(len(obj1.kuesa.layers), 2)
        self.assertEqual(len(obj2.kuesa.layers), 2)

        # WHEN
        obj1.select = True
        obj2.select = True
        check = layer_manager.meets_intersect("layer_meets_intersect_1")

        # THEN
        self.assertTrue(check)

        # WHEN
        check = layer_manager.meets_intersect("layer_meets_intersect_2")

        # THEN
        self.assertFalse(check)

        # WHEN
        check = layer_manager.meets_intersect("layer_meets_intersect_3")

        # THEN
        self.assertFalse(check)

        # WHEN
        obj1.select = False
        check = layer_manager.meets_intersect("layer_meets_intersect_3")

        # THEN
        self.assertTrue(check)
Exemplo n.º 4
0
    def test_add_layer(self):
        # GIVEN
        layer_manager = LayerManager(bpy.context)
        obj_data = bpy.data.meshes.new("test_add_layer_mesh")
        obj = bpy.data.objects.new(name="test_add_layer", object_data=obj_data)
        bpy.context.scene.objects.link(obj)
        obj.select = False

        # WHEN
        layer_manager.add(["layer_add"])

        # THEN
        self.assertEqual(len(layer_manager.gather_layer_names(obj)), 0)

        # WHEN
        obj.select = True
        layer_manager.add(["layer_add"])

        # THEN
        self.assertEqual(len(obj.kuesa.layers), 1)
        self.assertEqual(obj.kuesa.layers[0].name, "layer_add")

        # WHEN
        layer_manager.add(["layer_add"])

        # THEN
        self.assertEqual(len(obj.kuesa.layers), 1)
Exemplo n.º 5
0
    def test_meets_union(self):
        # Union as in at least one object contains a layer
        # GIVEN
        layer_manager = LayerManager(bpy.context)
        obj_data = bpy.data.meshes.new("test_meets_union_mesh")
        obj = bpy.data.objects.new(name="test_meets_union", object_data=obj_data)
        bpy.context.scene.objects.link(obj)
        obj.select = True

        # WHEN
        layer_manager.add(["layer_meets_union_1", "layer_meets_union_2", "layer_meets_union_3"])

        # THEN
        self.assertEqual(len(obj.kuesa.layers), 3)

        # WHEN
        check = layer_manager.meets_union("layer_meets_union_1")

        # THEN
        self.assertTrue(check)

        # WHEN
        check = layer_manager.meets_union("layer_meets_union_2")

        # THEN
        self.assertTrue(check)

        # WHEN
        check = layer_manager.meets_union("layer_meets_union_3")

        # THEN
        self.assertTrue(check)

        # WHEN
        check = layer_manager.meets_union("layer_meets_union_4")

        # THEN
        self.assertFalse(check)
Exemplo n.º 6
0
    def test_rename_layer(self):
        # GIVEN
        layer_manager = LayerManager(bpy.context)
        obj_data = bpy.data.meshes.new("test_rename_layer_mesh")
        obj1 = bpy.data.objects.new(name="test_rename_layer_1", object_data=obj_data)
        obj2 = bpy.data.objects.new(name="test_rename_layer_2", object_data=obj_data)
        bpy.context.scene.objects.link(obj1)
        bpy.context.scene.objects.link(obj2)
        obj1.select = True
        obj2.select = True

        # WHEN
        layer_manager.add(["layer_rename"])

        # THEN
        self.assertEqual(len(obj1.kuesa.layers), 1)
        self.assertEqual(len(obj2.kuesa.layers), 1)
        self.assertEqual(obj1.kuesa.layers[0].name, "layer_rename")
        self.assertEqual(obj2.kuesa.layers[0].name, "layer_rename")

        # WHEN
        layer_manager.rename("layer_rename", "layer_renamed_1")

        # THEN
        self.assertEqual(len(obj1.kuesa.layers), 1)
        self.assertEqual(len(obj2.kuesa.layers), 1)
        self.assertEqual(obj1.kuesa.layers[0].name, "layer_renamed_1")
        self.assertEqual(obj2.kuesa.layers[0].name, "layer_renamed_1")

        # WHEN
        obj1.select = False
        layer_manager.rename("layer_renamed_1", "layer_renamed_2")

        # THEN
        self.assertEqual(len(obj1.kuesa.layers), 1)
        self.assertEqual(len(obj2.kuesa.layers), 1)
        self.assertEqual(obj1.kuesa.layers[0].name, "layer_renamed_2")
        self.assertEqual(obj2.kuesa.layers[0].name, "layer_renamed_2")
Exemplo n.º 7
0
    def test_select_match_all(self):
        # GIVEN
        layer_manager = LayerManager(bpy.context)
        obj_data = bpy.data.meshes.new("test_select_match_all_mesh")
        obj1 = bpy.data.objects.new(name="test_select_match_all_1", object_data=obj_data)
        obj2 = bpy.data.objects.new(name="test_select_match_all_2", object_data=obj_data)
        bpy.context.scene.objects.link(obj1)
        bpy.context.scene.objects.link(obj2)
        bpy.ops.object.select_all(action='DESELECT')

        # THEN
        self.assertEqual(len(bpy.context.selected_objects), 0)

        # WHEN
        obj1.select = True
        obj2.select = False
        layer_manager.add(["layer_select_match_all_1", "layer_select_match_all_2"])

        obj2.select = True
        obj1.select = False
        layer_manager.add(["layer_select_match_all_1", "layer_select_match_all_3"])

        # THEN
        self.assertEqual(len(obj1.kuesa.layers), 2)
        self.assertEqual(len(obj2.kuesa.layers), 2)

        # WHEN
        obj1.select = False
        obj2.select = False
        layer_manager.select_match_all(["layer_select_match_all_1"])

        # THEN
        self.assertTrue(obj1.select)
        self.assertTrue(obj2.select)

        # WHEN
        obj1.select = False
        obj2.select = False
        layer_manager.select_match_all(["layer_select_match_all_2"])

        # THEN
        self.assertTrue(obj1.select)
        self.assertFalse(obj2.select)

        # WHEN
        obj1.select = False
        obj2.select = False
        layer_manager.select_match_all(["layer_select_match_all_3"])

        # THEN
        self.assertTrue(obj2.select)
        self.assertFalse(obj1.select)

        # WHEN
        obj1.select = False
        obj2.select = False
        layer_manager.select_match_all(["layer_select_match_all_2", "layer_select_match_all_3"])

        # THEN
        self.assertFalse(obj1.select)
        self.assertFalse(obj2.select)