Skip to content

Commit

Permalink
reader.py: finish buildViewpoint()
Browse files Browse the repository at this point in the history
Now a complete BCF file can be read into the data structure. Viewpoint
is not a subclass of ViewpointReference anylonger, rather latter one has
a member that holds an object of the associated viewpoint.
  • Loading branch information
podestplatz committed May 31, 2019
1 parent 7fa127a commit 2922d71
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 33 deletions.
8 changes: 8 additions & 0 deletions src/bcf/markup.py
Expand Up @@ -41,6 +41,14 @@ def __init__(self,
self.snapshot = snapshot
self.index = index

@property
def viewpoint(self):
return self._viewpoint

@viewpoint.setter
def viewpoint(self, newVal):
self._viewpoint = newVal


class Comment:

Expand Down
152 changes: 139 additions & 13 deletions src/bcf/reader.py
Expand Up @@ -12,7 +12,11 @@
from modification import Modification
from markup import (Comment, Markup, Header, ViewpointReference)
from topic import (Topic, BimSnippet, DocumentReference)
from viewpoint import (Viewpoint, Component, Components, ViewSetupHints)
from viewpoint import (Viewpoint, Component, Components, ViewSetupHints,
ComponentColour, PerspectiveCamera, OrthogonalCamera, BitmapFormat,
Bitmap)
from threedvector import (Point, Line, Direction, ClippingPlane)


DEBUG = True
SUPPORTED_VERSIONS = ["2.1"]
Expand Down Expand Up @@ -326,7 +330,7 @@ def buildHeader(headerDict):
isExternal = getOptionalFromDict(fileDict, "@isExternal", True)

header = Header(ifcProjectId, ifcSpatialStructureElement,
isExternal, filename, date, reference)
isExternal, filename, filedate, reference)
return header


Expand Down Expand Up @@ -404,9 +408,23 @@ def buildComponent(componentDict: Dict):
return component


def buildComponentColour(ccDict: Dict):

colour = getOptionalFromDict(ccDict, "@Color", None)
colourComponents = list()
cc = None
if colour: # if a colour is defined then at least one component has to exist
colourComponentList = [ buildComponent(cp)
for cp in ccDict["Component"] ]
cc = ComponentColor(colour, colourComponents)

return cc


def buildComponents(componentsDict: Dict):

vshDict = getOptionalFromDict(componentsDict, "ViewSetupHints", None)
vsh = None
if vshDict:
vsh = buildViewSetupHints(vshDict)

Expand All @@ -416,22 +434,130 @@ def buildComponents(componentsDict: Dict):
visibilityDict = componentsDict["Visibility"]
defaultVisibility = getOptionalFromDict(visibilityDict,
"@DefaultVisibility", True)
exceptionList = getOptionalFromDict(visibilityDict, "Exceptions", list())
exceptions = [ buildComponent(cp) for cp in exceptionList ]
colourComponentList = getOptionalFromDict(componentsDict, "Coloring", list())
componentColours = [ buildComponentColour(ccDict)
for ccDict in colourComponentList ]

components = Components(defaultVisibility, exceptionList, sel,
vsh, componentColours)
return components


def buildPoint(pointDict: Dict):

return Point(pointDict["X"], pointDict["Y"], pointDict["Z"])


def buildDirection(dirDict: Dict):

return Direction(dirDict["X"], dirDict["Y"], dirDict["Z"])


def buildOrthogonalCamera(oCamDict: Dict):

camViewpoint = buildPoint(oCamDict["CameraViewPoint"])
camDirection = buildDirection(oCamDict["CameraDirection"])
camUpVector = buildDirection(oCamDict["CameraUpVector"])
vWorldScale = oCamDict["ViewToWorldScale"]

cam = OrthogonalCamera(camViewpoint, camDirection, camUpVector, vWorldScale)
return cam


def buildPerspectiveCamera(pCamDict: Dict):

camViewpoint = buildPoint(pCamDict["CameraViewPoint"])
camDirection = buildDirection(pCamDict["CameraDirection"])
camUpVector = buildDirection(pCamDict["CameraUpVector"])
fieldOfView = pCamDict["FieldOfView"] # [0, 360] in version 2.1

cam = PerspectiveCamera(camViewpoint, camDirection, camUpVector,
fieldOfView)
return cam

#TODO: implement that function
def buildViewpoint(viewpointFilePath: str, viewpointSchemaPath: str,
vpRef: ViewpointReference):

def buildLine(lineDict: Dict):

start = buildPoint(lineDict["StartPoint"])
end = buildPoint(lineDict["EndPoint"])

line = Line(start, end)
return line


def buildClippingPlane(clipDict: Dict):

location = buildPoint(clipDict["Location"])
direction = buildDirection(clipDict["Direction"])

cPlane = ClippingPlane(location, direction)
return cPlane


def buildBitmap(bmDict: Dict):

bmFormatStr = bmDict["Bitmap"] # either JPG or PNG
bmFormat = BitmapFormat.PNG if bmFormatStr == "PNG" else BitmapFormat.JPG

reference = bmDict["Reference"]
location = buildPoint(bmDict["Location"])
normal = buildDirection(bmDict["Normal"])
up = buildDirection(bmDict["Up"])
height = bmDict["Height"]

bitmap = Bitmap(bmFormat, reference, location, normal, up, height)
return bitmap


def buildViewpoint(viewpointFilePath: str, viewpointSchemaPath: str):

"""
Builds an object of type viewpoint.
"""

vpSchema = XMLSchema(viewpointSchemaPath)
vpDict = vpSchema.to_dict(viewpointFilePath)

id = vpDict["@Guid"]

pprint.pprint(vpDict)
componentsList = getOptionalFromDict(vpDict, "Components", list())
componentsList = [ buildComponents(cp) for cp in componentsList ]

return None
componentsDict = getOptionalFromDict(vpDict, "Components", None)
components = None
if componentsDict:
components = buildComponents(componentsDict)

oCamDict = getOptionalFromDict(vpDict, "OrthogonalCamera", None)
oCam = None
if oCamDict:
oCam = buildOrthogonalCamera(oCamDict)

pCamDict = getOptionalFromDict(vpDict, "PerspectiveCamera", None)
pCam = None
if pCamDict:
pCam = buildPerspectiveCamera(pCamDict)

linesDict = getOptionalFromDict(vpDict, "Lines", None)
lines = None
if linesDict:
linesList = getOptionalFromDict(linesDict, "Line", list())
lines = [ buildLine(line) for line in linesList ]

clippingPlaneDict = getOptionalFromDict(vpDict, "ClippingPlanes", None)
clippingPlanes = None
if clippingPlaneDict:
clippingPlaneList = getOptionalFromDict(clippingPlaneDict,
"ClippingPlane", list())
clippingPlanes = [ buildClippingPlane(clipDict)
for clipDict in clippingPlaneList ]

bitmapList = getOptionalFromDict(vpDict, "Bitmap", list())
bitmaps = [ buildBitmap(bmDict) for bmDict in bitmapList ]

viewpoint = Viewpoint(id, components, oCam,
pCam, lines, clippingPlanes, bitmaps)
return viewpoint


def validateFile(validateFilePath: str,
Expand Down Expand Up @@ -521,10 +647,10 @@ def readBcfFile(bcfFile: str):

viewpointFiles = markup.getViewpointFileList()
viewpoints = list()
for (vpFile, vpRef) in viewpointFiles:
vpPath = os.path.join(topicDir, vpFile.uri)
vp = buildViewpoint(vpPath, visinfoSchemaPath, vpRef)
viewpoints.append(vp)
for vpRef in markup.viewpoints:
vpPath = os.path.join(topicDir, vpRef.file.uri)
vp = buildViewpoint(vpPath, visinfoSchemaPath)
vpRef.viewpoint = vp

# add the finished markup object to the project
proj.topicList.append(markup)
Expand Down
8 changes: 4 additions & 4 deletions src/bcf/topic.py
Expand Up @@ -32,13 +32,13 @@ class SchemaConstraint:
def __init__(self,
initialValue: str,
validValues: str):
self.validValues = validValues
self._validValues = validValues
if initialValue in validValues:
self.value = initialValue
self._value = initialValue

@property
def validValues(self):
return self.validValues
return self._validValues

@validValues.setter
def validValues(self, values: List[str]):
Expand All @@ -59,7 +59,7 @@ def value(self, newValue: str):

if (newValue in self.__validValues or
self._validValues == [None]):
self.value = newValue
self._value = newValue

@staticmethod
def parseConstraints(elementName):
Expand Down
33 changes: 17 additions & 16 deletions src/bcf/viewpoint.py
Expand Up @@ -71,7 +71,7 @@ def __init__(self,

""" Initialisation function of OrthogonalCamera """

super(PerspectiveCamera, self).__init__(viewPoint, direction, upVector)
super(OrthogonalCamera, self).__init__(viewPoint, direction, upVector)
self.viewWorldScale = viewWorldScale


Expand All @@ -86,15 +86,15 @@ def __init__(self,
self.authoringtoolId = authoringtoolId


class ComponentColor:
class ComponentColour:

def __init__(self,
color: str,
components: List[UUID]): # has to have at least one element
colour: str,
components: List[Component]): # has to have at least one element

if len(components) == 0:
raise InvalidArgumentException
self.color = color
self.colour = colour
self.components = components


Expand All @@ -116,30 +116,31 @@ def __init__(self,
visibilityExceptions: List[Component],
selection: List[Component] = list(),
viewSetupHints: ViewSetupHints = None,
coloring: List[ComponentColor] = list()):
self.viewSetuphints = viewSetuphints
colouring: List[ComponentColour] = list()):
self.viewSetuphints = viewSetupHints
self.selection = selection
self.visibilityDefault = visibilityDefault
self.visibilityExceptions = visibilityExceptions
self.coloring = coloring
self.colouring = colouring


class Viewpoint(ViewpointReference):
class Viewpoint:

""" """

def __init__(self,
id: UUID = None,
components: Components = None, #TODO: define class
camSetting: Camera = None,
camSetting2: Camera = None,
id: UUID,
components: Components = None,
oCamera: OrthogonalCamera = None,
pCamera: PerspectiveCamera = None,
lines: List[Line] = list(),
clippingPlanes: List[ClippingPlane] = list(),
bitmaps: Bitmap = None):
bitmaps: List[Bitmap] = list()):

self.id = id
self.components = components
self.camSetting = camSetting
self.camSetting2 = camSetting2
self.oCamera = oCamera
self.pCamera = pCamera
self.lines = lines
self.clippingPlanes = clippingPlanes
self.bitmaps = bitmaps

0 comments on commit 2922d71

Please sign in to comment.