mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Deduplicate ISODuration definition
This commit is contained in:
@@ -131,6 +131,7 @@ classes = [
|
||||
prop.ObjProperty,
|
||||
prop.MultipleFileSelect,
|
||||
prop.Attribute,
|
||||
prop.ISODuration,
|
||||
prop.BIMAreaProperties,
|
||||
prop.BIMTabProperties,
|
||||
prop.BIMProperties,
|
||||
|
||||
@@ -59,7 +59,6 @@ classes = (
|
||||
prop.Resource,
|
||||
prop.BIMResourceProperties,
|
||||
prop.BIMResourceTreeProperties,
|
||||
prop.ISODuration,
|
||||
prop.BIMResourceProductivity,
|
||||
ui.BIM_PT_resources,
|
||||
ui.BIM_UL_resources,
|
||||
|
||||
@@ -24,7 +24,7 @@ import bonsai.tool as tool
|
||||
import bonsai.bim.module.pset.data
|
||||
import bonsai.bim.module.resource.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.props import (
|
||||
PointerProperty,
|
||||
@@ -95,25 +95,6 @@ def updateResourceUsage(self: "Resource", context: object) -> None:
|
||||
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):
|
||||
name: StringProperty(name="Name", update=updateResourceName)
|
||||
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
|
||||
|
||||
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):
|
||||
|
||||
@@ -127,7 +127,6 @@ classes = (
|
||||
prop.Task,
|
||||
prop.TaskResource,
|
||||
prop.TaskProduct,
|
||||
prop.ISODuration,
|
||||
prop.IFCStatus,
|
||||
prop.BIMStatusProperties,
|
||||
prop.BIMWorkScheduleProperties,
|
||||
|
||||
@@ -16,12 +16,17 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import isodate
|
||||
import bpy
|
||||
from dateutil import parser
|
||||
import ifcopenshell.util.date
|
||||
from datetime import timedelta, datetime
|
||||
from typing import Union
|
||||
|
||||
from bonsai.bim.prop import ISODuration
|
||||
|
||||
|
||||
def parse_datetime(value):
|
||||
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
|
||||
for collection in durations_attributes:
|
||||
if collection.name == prop_name:
|
||||
duration_props = collection
|
||||
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_props.years if duration_props.years 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.pset.data
|
||||
from mathutils import Color
|
||||
from bonsai.bim.prop import StrProperty, Attribute
|
||||
from bonsai.bim.prop import Attribute, ISODuration
|
||||
from dateutil import parser
|
||||
from bpy.types import PropertyGroup
|
||||
from bpy.props import (
|
||||
@@ -428,25 +428,6 @@ class BIMWorkPlanProperties(PropertyGroup):
|
||||
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):
|
||||
name: StringProperty(name="Name")
|
||||
is_visible: BoolProperty(
|
||||
|
||||
@@ -444,6 +444,23 @@ class Attribute(PropertyGroup):
|
||||
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(
|
||||
self: "Union[BIMAreaProperties, BIMTabProperties]", context: bpy.types.Context
|
||||
) -> list[tuple[str, str, str, str, int]]:
|
||||
|
||||
@@ -43,7 +43,7 @@ from collections.abc import Iterable
|
||||
from mathutils import Color
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import bonsai.bim.prop
|
||||
from bonsai.bim.prop import Attribute
|
||||
from bonsai.bim.module.sequence.prop import (
|
||||
BIMAnimationProperties,
|
||||
BIMStatusProperties,
|
||||
@@ -405,9 +405,7 @@ class Sequence(bonsai.core.tool.Sequence):
|
||||
|
||||
props = cls.get_work_schedule_props()
|
||||
|
||||
def callback(
|
||||
name: str, prop: Union[bonsai.bim.prop.Attribute, None], data: dict[str, Any]
|
||||
) -> Union[bool, None]:
|
||||
def callback(name: str, prop: Union[Attribute, None], data: dict[str, Any]) -> Union[bool, None]:
|
||||
if prop and prop.data_type == "string":
|
||||
# TODO: Check actual attribute type instead of providing attribute names.
|
||||
if name in ("ScheduleDuration", "ActualDuration", "FreeFloat", "TotalFloat"):
|
||||
@@ -451,7 +449,7 @@ class Sequence(bonsai.core.tool.Sequence):
|
||||
|
||||
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 prop.is_null:
|
||||
attributes[prop.name] = None
|
||||
@@ -473,6 +471,7 @@ class Sequence(bonsai.core.tool.Sequence):
|
||||
for value in props.durations_attributes.values():
|
||||
value = 0
|
||||
return True
|
||||
return False
|
||||
|
||||
return bonsai.bim.helper.export_attributes(props.task_time_attributes, callback)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user