mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 14:13:41 +00:00
Now it's possible to see the selected object related cost items and related quantities in qto n-panel
This commit is contained in:
committed by
Dion Moult
parent
0e03a01f61
commit
05bdc962a3
@@ -16,10 +16,11 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# 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/>.
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from bpy.types import Panel
|
import bpy
|
||||||
|
from blenderbim.bim.module.qto.data import QtoData
|
||||||
|
|
||||||
|
|
||||||
class BIM_PT_qto_utilities(Panel):
|
class BIM_PT_qto_utilities(bpy.types.Panel):
|
||||||
bl_idname = "BIM_PT_qto_utilities"
|
bl_idname = "BIM_PT_qto_utilities"
|
||||||
bl_label = "Quantity Take-off"
|
bl_label = "Quantity Take-off"
|
||||||
bl_options = {"DEFAULT_CLOSED"}
|
bl_options = {"DEFAULT_CLOSED"}
|
||||||
@@ -28,6 +29,9 @@ class BIM_PT_qto_utilities(Panel):
|
|||||||
bl_category = "BlenderBIM"
|
bl_category = "BlenderBIM"
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
|
if not QtoData.is_loaded:
|
||||||
|
QtoData.load()
|
||||||
|
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
props = context.scene.BIMQtoProperties
|
props = context.scene.BIMQtoProperties
|
||||||
|
|
||||||
@@ -57,3 +61,28 @@ class BIM_PT_qto_utilities(Panel):
|
|||||||
|
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.operator("bim.calculate_all_quantities", icon="MOD_EDGESPLIT")
|
row.operator("bim.calculate_all_quantities", icon="MOD_EDGESPLIT")
|
||||||
|
|
||||||
|
if context.selected_objects:
|
||||||
|
row = layout.row(align=True)
|
||||||
|
row.label(text=f"Relating Cost Item:")
|
||||||
|
|
||||||
|
if QtoData.data['has_cost_item']:
|
||||||
|
for relating_cost_item in QtoData.data['relating_cost_items']:
|
||||||
|
row.label(text=f"\n")
|
||||||
|
row = layout.row(align=True)
|
||||||
|
row.label(text=f"Cost item name:")
|
||||||
|
row.label(text=f"{relating_cost_item['cost_item_name']}")
|
||||||
|
row = layout.row(align=True)
|
||||||
|
row.label(text=f"Quantity name:")
|
||||||
|
row.label(text=f"{relating_cost_item['quantity_name']}")
|
||||||
|
row = layout.row(align=True)
|
||||||
|
row.label(text=f"Quantity value:")
|
||||||
|
row.label(text=f"{relating_cost_item['quantity_value']}")
|
||||||
|
row = layout.row(align=True)
|
||||||
|
row.label(text=f"Quantity type:")
|
||||||
|
row.label(text=f"{relating_cost_item['quantity_type']}")
|
||||||
|
row = layout.row(align=True)
|
||||||
|
else:
|
||||||
|
row = layout.row(align=True)
|
||||||
|
row.label(text = f"No cost item related")
|
||||||
|
|
||||||
|
|||||||
@@ -518,6 +518,7 @@ class Qto:
|
|||||||
def add_product_base_qto(cls, product): pass
|
def add_product_base_qto(cls, product): pass
|
||||||
def get_new_calculated_quantity(cls, qto_name, quantity_name, object): pass
|
def get_new_calculated_quantity(cls, qto_name, quantity_name, object): pass
|
||||||
def get_new_guessed_quantity(cls, object, qto_name, quantity_name, ): pass
|
def get_new_guessed_quantity(cls, object, qto_name, quantity_name, ): pass
|
||||||
|
def get_related_cost_item_quantities(cls, product): pass
|
||||||
|
|
||||||
|
|
||||||
@interface
|
@interface
|
||||||
|
|||||||
@@ -127,3 +127,54 @@ class Qto(blenderbim.core.tool.Qto):
|
|||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
return rel.RelatingPropertyDefinition
|
return rel.RelatingPropertyDefinition
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_related_cost_item_quantities(cls, product):
|
||||||
|
"""_summary_: Returns the related cost item and related quantities of the product
|
||||||
|
|
||||||
|
:param ifc-instance product: ifc instance
|
||||||
|
:type product: ifcopenshell.entity_instance.entity_instance
|
||||||
|
|
||||||
|
:return list of dictionaries in the form [
|
||||||
|
{
|
||||||
|
"cost_item_id" : XX,
|
||||||
|
"cost_item_name" : XX,
|
||||||
|
"quantity_id" : XX,
|
||||||
|
"quantity_name" : XX,
|
||||||
|
"quantity_value" : XX,
|
||||||
|
"quantity_type" : XX
|
||||||
|
}]
|
||||||
|
:rtype list
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
.. code::Python
|
||||||
|
import blenderbim.tool as tool
|
||||||
|
|
||||||
|
relating_cost_items = tool.Qto.relating_cost_items(my_beautiful_wall)
|
||||||
|
for relating_cost_item in relating_cost_items:
|
||||||
|
print(f"RELATING COST ITEM NAME: {relating_cost_item["cost_item_name"]}")
|
||||||
|
print(f"RELATING COST QUANTITY NAME: {relating_cost_item["quantity_name"]}")
|
||||||
|
...
|
||||||
|
"""
|
||||||
|
quantities = cls.get_base_qto(product).Quantities
|
||||||
|
model = tool.Ifc.get()
|
||||||
|
cost_items = model.by_type("IfcCostItem")
|
||||||
|
result = []
|
||||||
|
|
||||||
|
for cost_item in cost_items:
|
||||||
|
cost_item_quantities = cost_item.CostQuantities if cost_item.CostQuantities is not None else []
|
||||||
|
for cost_item_quantity in cost_item_quantities:
|
||||||
|
for quantity in quantities:
|
||||||
|
if quantity == cost_item_quantity:
|
||||||
|
result.append(
|
||||||
|
{
|
||||||
|
"cost_item_id" : cost_item.id(),
|
||||||
|
"cost_item_name" : cost_item.Name,
|
||||||
|
"quantity_id" : quantity.id(),
|
||||||
|
"quantity_name" : quantity.Name,
|
||||||
|
"quantity_value" : quantity[3],
|
||||||
|
"quantity_type" : quantity.is_a(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return result
|
||||||
|
|||||||
@@ -142,3 +142,19 @@ class TestGetBaseQto(test.bim.bootstrap.NewFile):
|
|||||||
product = tool.Ifc.get_entity(wall_obj)
|
product = tool.Ifc.get_entity(wall_obj)
|
||||||
assert not subject.get_base_qto(product) == True
|
assert not subject.get_base_qto(product) == True
|
||||||
|
|
||||||
|
class TestGetRelatedCostItemQuantities(test.bim.bootstrap.NewFile):
|
||||||
|
def test_run(self):
|
||||||
|
ifc = ifcopenshell.file()
|
||||||
|
tool.Ifc.set(ifc)
|
||||||
|
wall = ifc.createIfcWall()
|
||||||
|
product = tool.Ifc.get_entity(wall)
|
||||||
|
schedule = ifcopenshell.api.run("cost.add_cost_schedule", ifc)
|
||||||
|
item = ifcopenshell.api.run("cost.add_cost_item", ifc, cost_schedule=schedule)
|
||||||
|
ifcopenshell.api.run("cost.edit_cost_item", ifc, cost_item=item, attributes={"Name": "Foo"})
|
||||||
|
qto = ifcopenshell.api.run("pset.add_qto", ifc, product=wall, name="Qto_WallBaseQuantities")
|
||||||
|
ifcopenshell.api.run("pset.edit_qto", ifc, qto=qto, properties={"NetVolume": 42.0})
|
||||||
|
ifcopenshell.api.run("cost.assign_cost_item_quantity", ifc, cost_item=item, products=[wall], prop_name="NetVolume")
|
||||||
|
assert subject.get_related_cost_item_quantities(wall)[0]['cost_item_name'] == "Foo"
|
||||||
|
assert subject.get_related_cost_item_quantities(wall)[0]['quantity_name'] == "NetVolume"
|
||||||
|
assert subject.get_related_cost_item_quantities(wall)[0]['quantity_value'] == 42
|
||||||
|
assert subject.get_related_cost_item_quantities(wall)[0]['quantity_type'] == "IfcQuantityVolume"
|
||||||
|
|||||||
Reference in New Issue
Block a user