Skip to content

Commit

Permalink
viewController.py: add Line creation
Browse files Browse the repository at this point in the history
Lines created will be copied into a group called BCFGroup. It is assumed that this group is not already present in the document.
  • Loading branch information
podestplatz committed Jul 24, 2019
1 parent 47c1151 commit 64d381c
Show file tree
Hide file tree
Showing 12 changed files with 324 additions and 2 deletions.
4 changes: 4 additions & 0 deletions bcf-examples/clippingPlane_bernd/bcfPart/bcf.version
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<Version VersionId="2.1" xsi:noNamespaceSchemaLocation="version.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DetailedVersion>2.1 KUBUS BV</DetailedVersion>
</Version>
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<Markup>
<Topic Guid="d7301aa6-3533-4031-b209-9e1c701802f5" TopicType="Issue" TopicStatus="Active">
<Title>bcfexample1</Title>
<Priority>Normal</Priority>
<Index>1</Index>
<CreationDate>2019-05-31T20:59:43+00:00</CreationDate>
<CreationAuthor>b.hahnebach@jpbi.ch</CreationAuthor>
<ModifiedDate>2019-05-31T20:59:43+00:00</ModifiedDate>
<ModifiedAuthor>b.hahnebach@jpbi.ch</ModifiedAuthor>
<AssignedTo>b.hahnebach@jpbi.ch</AssignedTo>
<Description>clipping plane</Description>
</Topic>
<Comment Guid="d5545441-19b2-47ff-9302-5fc16d3f6d67">
<Date>2019-05-31T20:59:43+00:00</Date>
<Author>b.hahnebach@jpbi.ch</Author>
<Comment>horizontal clipping plane</Comment>
<Viewpoint Guid="62b91142-e20c-444f-a678-7c28b23a124b" />
<ModifiedDate>2019-05-31T20:59:43+00:00</ModifiedDate>
<ModifiedAuthor>b.hahnebach@jpbi.ch</ModifiedAuthor>
</Comment>
<Viewpoints Guid="62b91142-e20c-444f-a678-7c28b23a124b">
<Viewpoint>viewpoint.bcfv</Viewpoint>
<Snapshot>snapshot.png</Snapshot>
</Viewpoints>
</Markup>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<VisualizationInfo Guid="62b91142-e20c-444f-a678-7c28b23a124b">
<Components>
<ViewSetupHints SpacesVisible="false" SpaceBoundariesVisible="false" OpeningsVisible="false" />
<Visibility DefaultVisibility="false">
<Exceptions>
<Component IfcGuid="2twsOAW_OHwPm_J59Y2WFs" />
<Component IfcGuid="2txH9wW_OHwQIUJ59Y2WFs" />
</Exceptions>
</Visibility>
</Components>
<PerspectiveCamera>
<CameraViewPoint>
<X>4.0785220861434937</X>
<Y>-1.5288909673690796</Y>
<Z>3.8552243709564209</Z>
</CameraViewPoint>
<CameraDirection>
<X>-0.41597223281860352</X>
<Y>0.6249469518661499</Y>
<Z>-0.66061067581176758</Z>
</CameraDirection>
<CameraUpVector>
<X>-0.3660394549369812</X>
<Y>0.54992961883544922</Y>
<Z>0.75072813034057617</Z>
</CameraUpVector>
<FieldOfView>65</FieldOfView>
</PerspectiveCamera>
<ClippingPlanes>
<ClippingPlane>
<Location>
<X>1.5</X>
<Y>1.5</Y>
<Z>1.2510015964508057</Z>
</Location>
<Direction>
<X>-0</X>
<Y>0</Y>
<Z>1</Z>
</Direction>
</ClippingPlane>
</ClippingPlanes>
</VisualizationInfo>
5 changes: 5 additions & 0 deletions bcf-examples/clippingPlane_bernd/bcfPart/project.bcfp
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ProjectExtension>
<Project ProjectId="a30b2c40-aab4-47f2-9678-170764514f06" />
<ExtensionSchema></ExtensionSchema>
</ProjectExtension>
80 changes: 78 additions & 2 deletions bcfplugin/frontend/viewController.py
Expand Up @@ -7,19 +7,33 @@
import rdwr.threedvector as vector
import util

from rdwr.threedvector import (Point, Direction)
from rdwr.viewpoint import (OrthogonalCamera, PerspectiveCamera, Component,
ComponentColour)
from rdwr.threedvector import Point, Direction
ComponentColour, Line)

# it is assumed that this file is only imported iff the plugin is running inside
# FreeCAD in Gui mode.
import FreeCADGui
import FreeCAD
draftAvailable = True
try:
import Draft
except:
util.printInfo("Cannot import Draft workbench. No elements can be drawn")
draftAvailable = False


pCamClassTypeId = coin.SoPerspectiveCamera_getClassTypeId
oCamClassTypeId = coin.SoOrthographicCamera_getClassTypeId

doc = FreeCAD.ActiveDocument
""" Reference to the document the model to the BCF file is open in """

bcfGroupName = "BCF"
bcfGroup = None
""" Reference to the document object group all elements will be assigned to,
that get created by functions inside this file """


class Unit(Enum):
METER = 1
Expand Down Expand Up @@ -191,6 +205,68 @@ def setOCamera(camSettings: OrthogonalCamera):
cam.height.setValue(camSettings.viewWorldScale)


def drawLine(start: FreeCAD.Vector, end: FreeCAD.Vector):

""" Creates a line from start to end using the draft workbench. """

if start is None or end is None:
return None
if not (isinstance(start, FreeCAD.Vector) and is instance(end,
FreeCAD.Vector)):
return None

pl = FreeCAD.Placement()
pl.Rotation.Q = (0, 0, 0, 1) # set the rotation in terms of quarternions
pl.Base = copy.deepcopy(start)
points = [start, end]
line = Draft.makeWire(points, placement=pl, closed=False, face=False,
support = None)

return line


def checkIfGroupExists(name: str):

obj = doc.getObject(name)
if obj is None:
return False

if not isinstance(obj, FreeCAD.DocumentObjectGroup):
return False

return obj


def createLines(lines: List[Line]):

""" Creates every line in `lines` and adds them to the BCF group """

global bcfGroup
global bcfGroupName

# get a reference to the bcf group and store it in bcfGroup
if bcfGroup is None:
group = checkIfGroupExists(bcfGroupName)
if not group:
bcfGroup = doc.addObject("App::DocumentObjectGroup", bcfGroupName)
else:
bcfGroup = obj

# try to add all lines in `lines`. Skip the failing ones
for line in lines:
start = line.start
end = line.end
fStart = FreeCAD.Vector(start.x, start.y, start.z)
fEnd = FreeCAD.Vector(end.x, end.y, end.z)
line = drawLine(fStart, fEnd)

if line is not None:
bcfGroup.addObject(line)
else:
util.printErr("Could not add line. Either start or end is None, or"\
" the points are not of type `FreeCAD.Vector`")


def readCamera():

""" Read the current settings of the camera and return a Camera object.
Expand Down
Binary file not shown.
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<Markup>
<Topic Guid="d7301aa6-3533-4031-b209-9e1c701802f5" TopicType="Issue" TopicStatus="Active">
<Title>bcfexample1</Title>
<Priority>Normal</Priority>
<Index>1</Index>
<CreationDate>2019-05-31T20:59:43+00:00</CreationDate>
<CreationAuthor>b.hahnebach@jpbi.ch</CreationAuthor>
<ModifiedDate>2019-05-31T20:59:43+00:00</ModifiedDate>
<ModifiedAuthor>b.hahnebach@jpbi.ch</ModifiedAuthor>
<AssignedTo>b.hahnebach@jpbi.ch</AssignedTo>
<Description>clipping plane</Description>
</Topic>
<Comment Guid="d5545441-19b2-47ff-9302-5fc16d3f6d67">
<Date>2019-05-31T20:59:43+00:00</Date>
<Author>b.hahnebach@jpbi.ch</Author>
<Comment>horizontal clipping plane</Comment>
<Viewpoint Guid="62b91142-e20c-444f-a678-7c28b23a124b" />
<ModifiedDate>2019-05-31T20:59:43+00:00</ModifiedDate>
<ModifiedAuthor>b.hahnebach@jpbi.ch</ModifiedAuthor>
</Comment>
<Viewpoints Guid="62b91142-e20c-444f-a678-7c28b23a124b">
<Viewpoint>viewpoint.bcfv</Viewpoint>
<Snapshot>snapshot.png</Snapshot>
</Viewpoints>
</Markup>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<VisualizationInfo Guid="62b91142-e20c-444f-a678-7c28b23a124b">
<Components>
<ViewSetupHints SpacesVisible="false" SpaceBoundariesVisible="false" OpeningsVisible="false" />
<Visibility DefaultVisibility="false">
<Exceptions>
<Component IfcGuid="2twsOAW_OHwPm_J59Y2WFs" />
<Component IfcGuid="2txH9wW_OHwQIUJ59Y2WFs" />
</Exceptions>
</Visibility>
</Components>
<PerspectiveCamera>
<CameraViewPoint>
<X>4.0785220861434937</X>
<Y>-1.5288909673690796</Y>
<Z>3.8552243709564209</Z>
</CameraViewPoint>
<CameraDirection>
<X>-0.41597223281860352</X>
<Y>0.6249469518661499</Y>
<Z>-0.66061067581176758</Z>
</CameraDirection>
<CameraUpVector>
<X>-0.3660394549369812</X>
<Y>0.54992961883544922</Y>
<Z>0.75072813034057617</Z>
</CameraUpVector>
<FieldOfView>65</FieldOfView>
</PerspectiveCamera>
<ClippingPlanes>
<ClippingPlane>
<Location>
<X>1.5</X>
<Y>1.5</Y>
<Z>1.2510015964508057</Z>
</Location>
<Direction>
<X>-0</X>
<Y>0</Y>
<Z>1</Z>
</Direction>
</ClippingPlane>
</ClippingPlanes>
</VisualizationInfo>
82 changes: 82 additions & 0 deletions bcfplugin/tests/viewController-tests/viewpoint_with_lines.bcfv
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<VisualizationInfo Guid="62b91142-e20c-444f-a678-7c28b23a124b">
<Components>
<ViewSetupHints SpacesVisible="false" SpaceBoundariesVisible="false" OpeningsVisible="false" />
<Visibility DefaultVisibility="false">
<Exceptions>
<Component IfcGuid="2twsOAW_OHwPm_J59Y2WFs" />
<Component IfcGuid="2txH9wW_OHwQIUJ59Y2WFs" />
</Exceptions>
</Visibility>
</Components>
<PerspectiveCamera>
<CameraViewPoint>
<X>4.0785220861434937</X>
<Y>-1.5288909673690796</Y>
<Z>3.8552243709564209</Z>
</CameraViewPoint>
<CameraDirection>
<X>-0.41597223281860352</X>
<Y>0.6249469518661499</Y>
<Z>-0.66061067581176758</Z>
</CameraDirection>
<CameraUpVector>
<X>-0.3660394549369812</X>
<Y>0.54992961883544922</Y>
<Z>0.75072813034057617</Z>
</CameraUpVector>
<FieldOfView>65</FieldOfView>
</PerspectiveCamera>
<Lines>
<Line>
<StartPoint>
<X>0</X>
<Y>0</Y>
<Z>0</Z>
</StartPoint>
<EndPoint>
<X>0</X>
<Y>0</Y>
<Z>5000</Z>
</EndPoint>
</Line>
<Line>
<StartPoint>
<X>0</X>
<Y>0</Y>
<Z>0</Z>
</StartPoint>
<EndPoint>
<X>0</X>
<Y>5000</Y>
<Z>0</Z>
</EndPoint>
</Line>
<Line>
<StartPoint>
<X>0</X>
<Y>0</Y>
<Z>0</Z>
</StartPoint>
<EndPoint>
<X>5000</X>
<Y>0</Y>
<Z>0</Z>
</EndPoint>
</Line>
</Lines>
<ClippingPlanes>
<ClippingPlane>
<Location>
<X>1.5</X>
<Y>1.5</Y>
<Z>1.2510015964508057</Z>
</Location>
<Direction>
<X>-0</X>
<Y>0</Y>
<Z>1</Z>
</Direction>
</ClippingPlane>
</ClippingPlanes>
</VisualizationInfo>
15 changes: 15 additions & 0 deletions bcfplugin/tests/viewController_tests.py
@@ -0,0 +1,15 @@
def setupBCFFile(fileName, testFileDir, topicDir, testBCFName):

cmd = "cp {}/{} {}/{}/viewpoint.bcfv".format(testFileDir, testFile,
testFileDir, testTopicDir)
project.debug("Executing: {}".format(cmd))
os.system(cmd)

cmd = "cd ./viewController-tests && zip -q {} {}/markup.bcf".format(testBCFName,
topicDir)
project.debug("Executing: {}".format(cmd))
os.system(cmd)

return os.path.join(testFileDir, testBCFName)


0 comments on commit 64d381c

Please sign in to comment.