mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 06:21:40 +00:00
You can now edit attributes of contexts and subcontexts. Fix bug where 2D contexts were not created with the right dimensionality.
This commit is contained in:
@@ -2,13 +2,42 @@
|
||||
Feature: Context
|
||||
Manages geometric representation contexts and subcontexts
|
||||
|
||||
Scenario: Add subcontext
|
||||
Scenario: Add context
|
||||
Given an empty IFC project
|
||||
When I press "bim.add_subcontext(context='Model', subcontext='Body', target_view='MODEL_VIEW')"
|
||||
When I press "bim.add_context(context_type='Model', context_identifier='', target_view='', parent=0)"
|
||||
Then nothing happens
|
||||
|
||||
Scenario: Remove subcontext
|
||||
Scenario: Add a subcontext
|
||||
Given an empty IFC project
|
||||
When the variable "parent" is "IfcStore.get_file().by_type('IfcGeometricRepresentationContext', include_subtypes=False)[0].id()"
|
||||
When I press "bim.add_context(context_type='Model', context_identifier='Body', target_view='MODEL_VIEW', parent={parent})"
|
||||
Then nothing happens
|
||||
|
||||
Scenario: Remove context
|
||||
Given an empty IFC project
|
||||
When the variable "context" is "IfcStore.get_file().by_type('IfcGeometricRepresentationContext')[0].id()"
|
||||
And I press "bim.remove_subcontext(context={context})"
|
||||
And I press "bim.remove_context(context={context})"
|
||||
Then nothing happens
|
||||
|
||||
Scenario: Enable editing context
|
||||
Given an empty IFC project
|
||||
When I press "bim.add_context(context_type='Model', context_identifier='', target_view='', parent=0)"
|
||||
And the variable "context" is "IfcStore.get_file().by_type('IfcGeometricRepresentationContext')[0].id()"
|
||||
And I press "bim.enable_editing_context(context={context})"
|
||||
Then nothing happens
|
||||
|
||||
Scenario: Disable editing context
|
||||
Given an empty IFC project
|
||||
When I press "bim.add_context(context_type='Model', context_identifier='', target_view='', parent=0)"
|
||||
And the variable "context" is "IfcStore.get_file().by_type('IfcGeometricRepresentationContext')[0].id()"
|
||||
And I press "bim.enable_editing_context(context={context})"
|
||||
And I press "bim.disable_editing_context()"
|
||||
Then nothing happens
|
||||
|
||||
Scenario: Edit context
|
||||
Given an empty IFC project
|
||||
When I press "bim.add_context(context_type='Model', context_identifier='', target_view='', parent=0)"
|
||||
And the variable "context" is "IfcStore.get_file().by_type('IfcGeometricRepresentationContext')[0].id()"
|
||||
And I press "bim.enable_editing_context(context={context})"
|
||||
And I press "bim.edit_context"
|
||||
Then nothing happens
|
||||
|
||||
@@ -63,6 +63,13 @@ def organisation_editor():
|
||||
prophet.verify()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def context_editor():
|
||||
prophet = Prophecy(blenderbim.core.tool.ContextEditor)
|
||||
yield prophet
|
||||
prophet.verify()
|
||||
|
||||
|
||||
class Prophecy:
|
||||
def __init__(self, cls):
|
||||
self.subject = cls
|
||||
|
||||
@@ -17,18 +17,58 @@
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import blenderbim.core.context as subject
|
||||
from test.core.bootstrap import ifc
|
||||
from test.core.bootstrap import ifc, context_editor
|
||||
|
||||
|
||||
class TestAddContext:
|
||||
def test_adding_a_context(self, ifc):
|
||||
ifc.run(
|
||||
"context.add_context", context="Model", subcontext="Body", target_view="MODEL_VIEW"
|
||||
"context.add_context", context_type="Model", context_identifier=None, target_view=None, parent=None
|
||||
).should_be_called().will_return("context")
|
||||
assert subject.add_context(ifc, context="Model", subcontext="Body", target_view="MODEL_VIEW") == "context"
|
||||
assert (
|
||||
subject.add_context(ifc, context_type="Model", context_identifier=None, target_view=None, parent=None)
|
||||
== "context"
|
||||
)
|
||||
|
||||
def test_adding_a_subcontext(self, ifc):
|
||||
ifc.run(
|
||||
"context.add_context",
|
||||
context_type="Model",
|
||||
context_identifier="Body",
|
||||
target_view="MODEL_VIEW",
|
||||
parent="parent",
|
||||
).should_be_called().will_return("subcontext")
|
||||
assert (
|
||||
subject.add_context(
|
||||
ifc, context_type="Model", context_identifier="Body", target_view="MODEL_VIEW", parent="parent"
|
||||
)
|
||||
== "subcontext"
|
||||
)
|
||||
|
||||
|
||||
class TestRemoveContext:
|
||||
def test_removing_a_context(self, ifc):
|
||||
ifc.run("context.remove_context", context="context").should_be_called()
|
||||
subject.remove_context(ifc, context="context")
|
||||
|
||||
|
||||
class TestEnableEditingContext:
|
||||
def test_run(self, context_editor):
|
||||
context_editor.set_context("context").should_be_called()
|
||||
context_editor.import_attributes().should_be_called()
|
||||
subject.enable_editing_context(context_editor, context="context")
|
||||
|
||||
|
||||
class TestDisableEditingContext:
|
||||
def test_run(self, context_editor):
|
||||
context_editor.clear_context().should_be_called()
|
||||
subject.disable_editing_context(context_editor)
|
||||
|
||||
|
||||
class TestEditContext:
|
||||
def test_run(self, ifc, context_editor):
|
||||
context_editor.get_context().should_be_called().will_return("context")
|
||||
context_editor.export_attributes().should_be_called().will_return("attributes")
|
||||
ifc.run("context.edit_context", context="context", attributes="attributes").should_be_called()
|
||||
context_editor.clear_context().should_be_called()
|
||||
subject.edit_context(ifc, context_editor)
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# This file is part of BlenderBIM Add-on.
|
||||
#
|
||||
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# BlenderBIM Add-on is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import bpy
|
||||
import ifcopenshell
|
||||
import test.bim.bootstrap
|
||||
import blenderbim.core.tool
|
||||
import blenderbim.tool as tool
|
||||
from blenderbim.tool.context_editor import ContextEditor as subject
|
||||
|
||||
|
||||
class TestImplementsTool(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
assert isinstance(subject(), blenderbim.core.tool.context_editor.ContextEditor)
|
||||
|
||||
|
||||
class TestSetContext(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
context = ifc.createIfcGeometricRepresentationContext()
|
||||
subject.set_context(context)
|
||||
assert bpy.context.scene.BIMContextProperties.active_context_id == context.id()
|
||||
|
||||
|
||||
class TestImportAttributes(test.bim.bootstrap.NewFile):
|
||||
def test_importing_a_context(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
context = ifc.createIfcGeometricRepresentationContext()
|
||||
context.ContextIdentifier = "ContextIdentifier"
|
||||
context.ContextType = "ContextType"
|
||||
context.CoordinateSpaceDimension = 1
|
||||
context.Precision = 1
|
||||
subject.set_context(context)
|
||||
subject.import_attributes()
|
||||
props = bpy.context.scene.BIMContextProperties
|
||||
assert props.context_attributes.get("ContextIdentifier").string_value == "ContextIdentifier"
|
||||
assert props.context_attributes.get("ContextType").string_value == "ContextType"
|
||||
assert props.context_attributes.get("CoordinateSpaceDimension").int_value == 1
|
||||
assert props.context_attributes.get("Precision").float_value == 1
|
||||
|
||||
def test_importing_a_subcontext(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
subcontext = ifc.createIfcGeometricRepresentationSubcontext()
|
||||
subcontext.TargetScale = 0.5
|
||||
subcontext.TargetView = "NOTDEFINED"
|
||||
subcontext.UserDefinedTargetView = "UserDefinedTargetView"
|
||||
subject.set_context(subcontext)
|
||||
subject.import_attributes()
|
||||
props = bpy.context.scene.BIMContextProperties
|
||||
assert props.context_attributes.get("TargetScale").float_value == 0.5
|
||||
assert props.context_attributes.get("TargetView").enum_value == "NOTDEFINED"
|
||||
assert props.context_attributes.get("UserDefinedTargetView").string_value == "UserDefinedTargetView"
|
||||
assert not props.context_attributes.get("Precision")
|
||||
|
||||
def test_importing_twice(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
context = ifc.createIfcGeometricRepresentationContext()
|
||||
context.ContextIdentifier = "ContextIdentifier"
|
||||
subject.set_context(context)
|
||||
subject.import_attributes()
|
||||
context.ContextIdentifier = "ContextIdentifier2"
|
||||
subject.import_attributes()
|
||||
props = bpy.context.scene.BIMContextProperties
|
||||
assert props.context_attributes.get("ContextIdentifier").string_value == "ContextIdentifier2"
|
||||
|
||||
|
||||
class TestClearContext(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
TestSetContext().test_run()
|
||||
subject.clear_context()
|
||||
assert bpy.context.scene.BIMContextProperties.active_context_id == 0
|
||||
|
||||
|
||||
class TestGetContext(test.bim.bootstrap.NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
context = ifc.createIfcGeometricRepresentationContext()
|
||||
subject.set_context(context)
|
||||
assert subject.get_context() == context
|
||||
|
||||
|
||||
class TestExportAttributes(test.bim.bootstrap.NewFile):
|
||||
def test_exporting_a_context(self):
|
||||
TestImportAttributes().test_importing_a_context()
|
||||
assert subject.export_attributes() == {
|
||||
"ContextIdentifier": "ContextIdentifier",
|
||||
"ContextType": "ContextType",
|
||||
"CoordinateSpaceDimension": 1,
|
||||
"Precision": 1,
|
||||
}
|
||||
|
||||
def test_exporting_a_subcontext(self):
|
||||
TestImportAttributes().test_importing_a_subcontext()
|
||||
assert subject.export_attributes() == {
|
||||
"TargetScale": 0.5,
|
||||
"TargetView": "NOTDEFINED",
|
||||
"UserDefinedTargetView": "UserDefinedTargetView",
|
||||
"ContextIdentifier": None,
|
||||
"ContextType": None,
|
||||
"CoordinateSpaceDimension": None,
|
||||
}
|
||||
Reference in New Issue
Block a user