Skip to content

Commit

Permalink
viewController: also backup camera settings and reset
Browse files Browse the repository at this point in the history
  • Loading branch information
podestplatz committed Jul 30, 2019
1 parent 556531d commit a5696bd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
46 changes: 46 additions & 0 deletions bcfplugin/frontend/viewController.py
Expand Up @@ -26,6 +26,10 @@
draftAvailable = False


class CamType(Enum):
ORTHOGONAL = 1
PERSPECTIVE = 2

pCamClassTypeId = coin.SoPerspectiveCamera_getClassTypeId
oCamClassTypeId = coin.SoOrthographicCamera_getClassTypeId

Expand All @@ -46,6 +50,15 @@
colBackup = list()
""" List of tuples containing the view object and its previous colour """

class CamBackup:
position = None
orientation = None
height = 0.0
heightAngle = 0.0
camType = CamType.ORTHOGONAL
camBackup = None
""" Backup of the camera settings before a viewpoint was applied. """


class Unit(Enum):
METER = 1
Expand Down Expand Up @@ -162,6 +175,11 @@ def setCamera(camViewpoint: vector.Point,

rotation = getRotation(fDirVector, fUpVector)

if camBackup is None:
camBackup = CamBackup()
camBackup.position = cam.position.getValue()
camBackup.orientation = cam.orientation.getValue()

cam.orientation.setValue(rotation.Q)
cam.position.setValue(fPosition)

Expand All @@ -178,6 +196,10 @@ def setPCamera(camSettings: PerspectiveCamera):
SoPerspectiveCamera.
"""

backup = True
if camBackup is not None:
backup = False

view = FreeCADGui.ActiveDocument.ActiveView
cam = view.getCameraNode()

Expand All @@ -191,6 +213,10 @@ def setPCamera(camSettings: PerspectiveCamera):
angle = degreeToRadians(camSettings.fieldOfView)
util.printInfo("Setting the fieldOfView = {} radians ({}"\
" degrees)".format(angle, camSettings.fieldOfView))

if backup:
camBackup.heightAngle = cam.heightAngle.getValue()
camBackup.camType = CamType.PERSPECTIVE
cam.heightAngle.setValue(angle)


Expand All @@ -204,6 +230,10 @@ def setOCamera(camSettings: OrthogonalCamera):
SoOrthographicCamera.
"""

backup = True
if camBackup is not None:
backup = False

view = FreeCADGui.ActiveDocument.ActiveView
cam = view.getCameraNode()

Expand All @@ -214,6 +244,10 @@ def setOCamera(camSettings: OrthogonalCamera):

setCamera(camSettings.viewPoint, camSettings.direction, camSettings.upVector)
util.printInfo("Camera type {}".format(view.getCameraType()))

if backup:
camBackup.height = cam.height.getValue()
camBackup.camType = CamType.ORTHOGONAL
cam.height.setValue(camSettings.viewWorldScale)


Expand Down Expand Up @@ -565,3 +599,15 @@ def resetView():
for (vObj, col) in colBackups:
vObj.ShapeColor = col
colBackups = list()

# reset camera settings
cam = FreeCADGui.ActiveDocument.ActiveView.getCameraNode()
cam.orientation.setValue(camBackup.orientation)
cam.position.setValue(camBackup.position)
if cam.camType == CamType.PERSPECTIVE:
view.setCameraType("Perspective")
cam.heightAngle.setValue(camBackup.heightAngle)
elif cam.camType == CamType.ORTHOGONAL:
view.setCameraType("Orthogonal")
cam.height.setValue(camBackup.height)
camBackup = None
5 changes: 1 addition & 4 deletions bcfplugin/programmaticInterface.py
Expand Up @@ -25,6 +25,7 @@
from rdwr.interfaces.hierarchy import Hierarchy
from rdwr.interfaces.state import State
from rdwr.interfaces.xmlname import XMLName
from frontend.viewController import CamType

if util.GUI:
import frontend.viewController as vCtrl
Expand Down Expand Up @@ -54,10 +55,6 @@ class OperationResults(Enum):
FAILURE = 2


class CamType(Enum):
ORTHOGONAL = 1
PERSPECTIVE = 2


def _handleProjectUpdate(errMsg, backup):

Expand Down

0 comments on commit a5696bd

Please sign in to comment.