-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path10.6.PickFilterTopLevel.py
101 lines (80 loc) · 3.16 KB
/
10.6.PickFilterTopLevel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
###
# Copyright (c) 2002-2007 Systems in Motion
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
###
# This is an example from The Inventor Mentor,
# chapter 10, example 6.
#
# This example demonstrates the use of the pick filter
# callback to implement a top level selection policy.
# That is, always select the top most group beneath the
# selection node, rather than selecting the actual
# shape that was picked.
#
from __future__ import print_function
####################################################################
# Modified to be compatible with FreeCAD #
# #
# Author : Mariwan Jalal mariwan.jalal@gmail.com #
####################################################################
import os
import sys
import FreeCAD as App
import FreeCADGui as Gui
import pivy.coin as coin
#WARNING: This doesn't work don't know how to fix it : TODO: FIXME:
# Pick the topmost node beneath the selection node
def pickFilterCB(void, pick):
# See which child of selection got picked
p = pick.getPath()
for i in range(p.getLength() - 1):
n = p.getNode(i)
if n.isOfType(coin.SoSelection.getClassTypeId()):
break
# Copy 2 nodes from the path:
# selection and the picked child
return p.copy(i, 2)
def main():
# Initialization
# Open the data file
input = coin.SoInput()
datafile = "E:\\TEMP \\fix some drawing\\Mentor_Freecad\\parkbench.iv" #TODO: CHANGE PATH AND FILE NAME IF YOU WANT
input.openFile(datafile)
# Read the input file
sep = coin.SoSeparator()
sep.addChild(coin.SoDB.readAll(input))
# Create two selection roots - one will use the pick filter.
topLevelSel = coin.SoSelection()
topLevelSel.addChild(sep)
topLevelSel.setPickFilterCallback(pickFilterCB)
defaultSel = coin.SoSelection()
defaultSel.addChild(sep)
# Create two viewers, one to show the pick filter for top level
# selection, the other to show default selection.
viewer1 = Gui.ActiveDocument.ActiveView
viewer1.setSceneGraph(topLevelSel)
boxhra1 = coin.SoBoxHighlightRenderAction()
viewer1.setGLRenderAction(boxhra1)
viewer1.redrawOnSelectionChange(topLevelSel)
viewer1.setTitle("Top Level Selection")
viewer2 = coin.SoGuiExaminerViewer()
viewer2.setSceneGraph(defaultSel)
boxhra2 = coin.SoBoxHighlightRenderAction()
viewer2.setGLRenderAction(boxhra2)
viewer2.redrawOnSelectionChange(defaultSel)
viewer2.setTitle("Default Selection")
viewer1.show()
viewer2.show()