mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 06:39:13 +00:00
Deduplicate ISODuration definition
This commit is contained in:
@@ -131,6 +131,7 @@ classes = [
|
|||||||
prop.ObjProperty,
|
prop.ObjProperty,
|
||||||
prop.MultipleFileSelect,
|
prop.MultipleFileSelect,
|
||||||
prop.Attribute,
|
prop.Attribute,
|
||||||
|
prop.ISODuration,
|
||||||
prop.BIMAreaProperties,
|
prop.BIMAreaProperties,
|
||||||
prop.BIMTabProperties,
|
prop.BIMTabProperties,
|
||||||
prop.BIMProperties,
|
prop.BIMProperties,
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ classes = (
|
|||||||
prop.Resource,
|
prop.Resource,
|
||||||
prop.BIMResourceProperties,
|
prop.BIMResourceProperties,
|
||||||
prop.BIMResourceTreeProperties,
|
prop.BIMResourceTreeProperties,
|
||||||
prop.ISODuration,
|
|
||||||
prop.BIMResourceProductivity,
|
prop.BIMResourceProductivity,
|
||||||
ui.BIM_PT_resources,
|
ui.BIM_PT_resources,
|
||||||
ui.BIM_UL_resources,
|
ui.BIM_UL_resources,
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import bonsai.tool as tool
|
|||||||
import bonsai.bim.module.pset.data
|
import bonsai.bim.module.pset.data
|
||||||
import bonsai.bim.module.resource.data
|
import bonsai.bim.module.resource.data
|
||||||
import bonsai.bim.module.sequence.data
|
import bonsai.bim.module.sequence.data
|
||||||
from bonsai.bim.prop import Attribute
|
from bonsai.bim.prop import Attribute, ISODuration
|
||||||
from bpy.types import PropertyGroup
|
from bpy.types import PropertyGroup
|
||||||
from bpy.props import (
|
from bpy.props import (
|
||||||
PointerProperty,
|
PointerProperty,
|
||||||
@@ -95,25 +95,6 @@ def updateResourceUsage(self: "Resource", context: object) -> None:
|
|||||||
bonsai.bim.module.pset.data.refresh()
|
bonsai.bim.module.pset.data.refresh()
|
||||||
|
|
||||||
|
|
||||||
class ISODuration(PropertyGroup):
|
|
||||||
name: StringProperty(name="Name")
|
|
||||||
years: IntProperty(name="Years", default=0)
|
|
||||||
months: IntProperty(name="Months", default=0)
|
|
||||||
days: IntProperty(name="Days", default=0)
|
|
||||||
hours: IntProperty(name="Hours", default=0)
|
|
||||||
minutes: IntProperty(name="Minutes", default=0)
|
|
||||||
seconds: IntProperty(name="Seconds", default=0)
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
name: str
|
|
||||||
years: int
|
|
||||||
months: int
|
|
||||||
days: int
|
|
||||||
hours: int
|
|
||||||
minutes: int
|
|
||||||
seconds: int
|
|
||||||
|
|
||||||
|
|
||||||
class Resource(PropertyGroup):
|
class Resource(PropertyGroup):
|
||||||
name: StringProperty(name="Name", update=updateResourceName)
|
name: StringProperty(name="Name", update=updateResourceName)
|
||||||
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ from bonsai.bim.module.resource.data import ResourceData
|
|||||||
from typing import Any, TYPE_CHECKING
|
from typing import Any, TYPE_CHECKING
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from bonsai.bim.module.resource.prop import ISODuration, Resource, BIMResourceTreeProperties
|
from bonsai.bim.prop import ISODuration
|
||||||
|
from bonsai.bim.module.resource.prop import Resource, BIMResourceTreeProperties
|
||||||
|
|
||||||
|
|
||||||
class BIM_PT_resources(Panel):
|
class BIM_PT_resources(Panel):
|
||||||
|
|||||||
@@ -127,7 +127,6 @@ classes = (
|
|||||||
prop.Task,
|
prop.Task,
|
||||||
prop.TaskResource,
|
prop.TaskResource,
|
||||||
prop.TaskProduct,
|
prop.TaskProduct,
|
||||||
prop.ISODuration,
|
|
||||||
prop.IFCStatus,
|
prop.IFCStatus,
|
||||||
prop.BIMStatusProperties,
|
prop.BIMStatusProperties,
|
||||||
prop.BIMWorkScheduleProperties,
|
prop.BIMWorkScheduleProperties,
|
||||||
|
|||||||
@@ -16,12 +16,17 @@
|
|||||||
# 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 Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import isodate
|
import isodate
|
||||||
|
import bpy
|
||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
import ifcopenshell.util.date
|
import ifcopenshell.util.date
|
||||||
from datetime import timedelta, datetime
|
from datetime import timedelta, datetime
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
|
from bonsai.bim.prop import ISODuration
|
||||||
|
|
||||||
|
|
||||||
def parse_datetime(value):
|
def parse_datetime(value):
|
||||||
try:
|
try:
|
||||||
@@ -65,13 +70,17 @@ def parse_duration_as_blender_props(dt, simplify=True):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def blender_props_to_iso_duration(durations_attributes, duration_type, prop_name):
|
def blender_props_to_iso_duration(
|
||||||
|
durations_attributes: bpy.types.bpy_prop_collection_idprop[ISODuration],
|
||||||
|
duration_type: Union[str, None],
|
||||||
|
prop_name: str,
|
||||||
|
) -> Union[str, None]:
|
||||||
duration_props = None
|
duration_props = None
|
||||||
for collection in durations_attributes:
|
for collection in durations_attributes:
|
||||||
if collection.name == prop_name:
|
if collection.name == prop_name:
|
||||||
duration_props = collection
|
duration_props = collection
|
||||||
break
|
break
|
||||||
if duration_props and not duration_type or duration_type == "ELAPSEDTIME":
|
if duration_props and (not duration_type or duration_type == "ELAPSEDTIME"):
|
||||||
duration_string = "P{}Y{}M{}DT{}H{}M{}S".format(
|
duration_string = "P{}Y{}M{}DT{}H{}M{}S".format(
|
||||||
duration_props.years if duration_props.years else 0,
|
duration_props.years if duration_props.years else 0,
|
||||||
duration_props.months if duration_props.months else 0,
|
duration_props.months if duration_props.months else 0,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ from bonsai.bim.module.sequence.data import SequenceData, AnimationColorSchemeDa
|
|||||||
import bonsai.bim.module.resource.data
|
import bonsai.bim.module.resource.data
|
||||||
import bonsai.bim.module.pset.data
|
import bonsai.bim.module.pset.data
|
||||||
from mathutils import Color
|
from mathutils import Color
|
||||||
from bonsai.bim.prop import StrProperty, Attribute
|
from bonsai.bim.prop import Attribute, ISODuration
|
||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
from bpy.types import PropertyGroup
|
from bpy.types import PropertyGroup
|
||||||
from bpy.props import (
|
from bpy.props import (
|
||||||
@@ -428,25 +428,6 @@ class BIMWorkPlanProperties(PropertyGroup):
|
|||||||
work_schedules: str
|
work_schedules: str
|
||||||
|
|
||||||
|
|
||||||
class ISODuration(PropertyGroup):
|
|
||||||
name: StringProperty(name="Name")
|
|
||||||
years: IntProperty(name="Years", default=0)
|
|
||||||
months: IntProperty(name="Months", default=0)
|
|
||||||
days: IntProperty(name="Days", default=0)
|
|
||||||
hours: IntProperty(name="Hours", default=0)
|
|
||||||
minutes: IntProperty(name="Minutes", default=0)
|
|
||||||
seconds: IntProperty(name="Seconds", default=0)
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
name: str
|
|
||||||
years: int
|
|
||||||
months: int
|
|
||||||
days: int
|
|
||||||
hours: int
|
|
||||||
minutes: int
|
|
||||||
seconds: int
|
|
||||||
|
|
||||||
|
|
||||||
class IFCStatus(PropertyGroup):
|
class IFCStatus(PropertyGroup):
|
||||||
name: StringProperty(name="Name")
|
name: StringProperty(name="Name")
|
||||||
is_visible: BoolProperty(
|
is_visible: BoolProperty(
|
||||||
|
|||||||
@@ -444,6 +444,23 @@ class Attribute(PropertyGroup):
|
|||||||
setattr(self, self.get_value_name(), value)
|
setattr(self, self.get_value_name(), value)
|
||||||
|
|
||||||
|
|
||||||
|
class ISODuration(PropertyGroup):
|
||||||
|
years: IntProperty(name="Years", default=0)
|
||||||
|
months: IntProperty(name="Months", default=0)
|
||||||
|
days: IntProperty(name="Days", default=0)
|
||||||
|
hours: IntProperty(name="Hours", default=0)
|
||||||
|
minutes: IntProperty(name="Minutes", default=0)
|
||||||
|
seconds: IntProperty(name="Seconds", default=0)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
years: int
|
||||||
|
months: int
|
||||||
|
days: int
|
||||||
|
hours: int
|
||||||
|
minutes: int
|
||||||
|
seconds: int
|
||||||
|
|
||||||
|
|
||||||
def get_tab(
|
def get_tab(
|
||||||
self: "Union[BIMAreaProperties, BIMTabProperties]", context: bpy.types.Context
|
self: "Union[BIMAreaProperties, BIMTabProperties]", context: bpy.types.Context
|
||||||
) -> list[tuple[str, str, str, str, int]]:
|
) -> list[tuple[str, str, str, str, int]]:
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ from collections.abc import Iterable
|
|||||||
from mathutils import Color
|
from mathutils import Color
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import bonsai.bim.prop
|
from bonsai.bim.prop import Attribute
|
||||||
from bonsai.bim.module.sequence.prop import (
|
from bonsai.bim.module.sequence.prop import (
|
||||||
BIMAnimationProperties,
|
BIMAnimationProperties,
|
||||||
BIMStatusProperties,
|
BIMStatusProperties,
|
||||||
@@ -405,9 +405,7 @@ class Sequence(bonsai.core.tool.Sequence):
|
|||||||
|
|
||||||
props = cls.get_work_schedule_props()
|
props = cls.get_work_schedule_props()
|
||||||
|
|
||||||
def callback(
|
def callback(name: str, prop: Union[Attribute, None], data: dict[str, Any]) -> Union[bool, None]:
|
||||||
name: str, prop: Union[bonsai.bim.prop.Attribute, None], data: dict[str, Any]
|
|
||||||
) -> Union[bool, None]:
|
|
||||||
if prop and prop.data_type == "string":
|
if prop and prop.data_type == "string":
|
||||||
# TODO: Check actual attribute type instead of providing attribute names.
|
# TODO: Check actual attribute type instead of providing attribute names.
|
||||||
if name in ("ScheduleDuration", "ActualDuration", "FreeFloat", "TotalFloat"):
|
if name in ("ScheduleDuration", "ActualDuration", "FreeFloat", "TotalFloat"):
|
||||||
@@ -451,7 +449,7 @@ class Sequence(bonsai.core.tool.Sequence):
|
|||||||
|
|
||||||
props = cls.get_work_schedule_props()
|
props = cls.get_work_schedule_props()
|
||||||
|
|
||||||
def callback(attributes, prop):
|
def callback(attributes: dict[str, Any], prop: Attribute) -> bool:
|
||||||
if "Start" in prop.name or "Finish" in prop.name or prop.name == "StatusTime":
|
if "Start" in prop.name or "Finish" in prop.name or prop.name == "StatusTime":
|
||||||
if prop.is_null:
|
if prop.is_null:
|
||||||
attributes[prop.name] = None
|
attributes[prop.name] = None
|
||||||
@@ -473,6 +471,7 @@ class Sequence(bonsai.core.tool.Sequence):
|
|||||||
for value in props.durations_attributes.values():
|
for value in props.durations_attributes.values():
|
||||||
value = 0
|
value = 0
|
||||||
return True
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
return bonsai.bim.helper.export_attributes(props.task_time_attributes, callback)
|
return bonsai.bim.helper.export_attributes(props.task_time_attributes, callback)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user