Commit a32b8dfd authored by David Thompson's avatar David Thompson
Browse files

Fix Python CGM tests and add a new one.

... to test vertex, edge, and face creation.
parent 1b7bb9bb
set(smtkCGMBridgePythonTests
cgmSolidModeling
cgmBuildUp
)
# Additional tests that require SMTK_DATA_DIR
......
#!/usr/bin/python
#=============================================================================
#
# Copyright (c) Kitware, Inc.
# All rights reserved.
# See LICENSE.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the above copyright notice for more information.
#
#=============================================================================
import smtk
mgr = smtk.model.Manager.create()
sess = mgr.createSession('cgm')
brg = sess.bridge()
def setCoord(x,v):
for i in range(len(v)):
x.setValue(i,v[i])
def setEntitiesByIndex(p,ep,v):
for i in range(len(ep)):
p.setValue(i, v[ep[i]])
verts = []
edges = []
faces = []
volus = []
pcoords = [
(0,0,0),
(1,0,0),
(0,1,0),
(0,0,1)]
crv = sess.op('create vertex')
x = crv.findAsDouble('point')
c = crv.findAsInt('color')
c.setValue(0, 1)
for pt in pcoords:
setCoord(x,pt);
verts.append(crv.operate().findModelEntity('vertex').value(0))
epts = [
(0,1),
(0,2),
(0,3),
(1,2),
(1,3),
(2,3)]
cre = sess.op('create edge')
t = cre.findAsInt('curve type')
t.setValue(0,6) # 6 == line segment
v = cre.findAsModelEntity('vertices')
x = cre.findAsDouble('point')
c = cre.findAsInt('color')
c.setValue(0, 2)
for epair in epts:
setEntitiesByIndex(v,epair,verts)
if epair == (2,3):
# Make the last edge an arc:
t.setValue(0,1) # 1 == arc
setCoord(x,[0,0.6,0.6]) # third point on arc
edges.append(cre.operate().findModelEntity('edge').value(0))
fedg = [
(12, 0, 3, 1),
(12, 0, 4, 2),
(16, 1, 5, 2)
]
# (16, 3, 5, 4) # <-- OpenCascade cannot infer that this face should be cylindrical
crf = sess.op('create face')
t = crf.findAsInt('surface type')
t.setValue(0, 12)
e = crf.findAsModelEntity('edges')
c = crf.findAsInt('color')
c.setValue(0, 3)
for face in fedg:
e.setNumberOfValues(len(face)-1)
setEntitiesByIndex(e,face[1:],edges)
t.setValue(face[0])
faces.append(crf.operate().findModelEntity('face').value(0))
json = smtk.io.ExportJSON.fromModel(mgr)
sphFile = open('buildup.json', 'w')
print >> sphFile, json
sphFile.close()
......@@ -23,9 +23,9 @@ brg = smtk.model.Manager.createBridge('cgm')
mgr.registerBridgeSession(brg)
readop = brg.op('read', mgr)
readop.findFile('filename').setValue(os.path.join(ddir,'cgm','62_shaver1.brep'))
readop.findAsFile('filename').setValue(os.path.join(ddir,'cgm','62_shaver1.brep'))
# Note that we could set the file type here:
# readop.findString('filetype').setValue('OCC')
# readop.findAsString('filetype').setValue('OCC')
# but there is no need to in this case as it will be
# correctly inferred from the filename.
res = readop.operate()
......@@ -36,22 +36,22 @@ print '\n'
opnames = sess.operatorNames()
cs1 = sess.op('create sphere')
cs1.findDouble('radius').setValue(1.)
#cs1.findDouble('inner radius').setValue(0.1) # Crashes
#cs1.findDouble('inner radius').setValue(-0.1) # Complains bitterly
cs1.findDouble('inner radius').setValue(0.2) # Actually works
cs1.findAsDouble('radius').setValue(1.)
#cs1.findAsDouble('inner radius').setValue(0.1) # Crashes
#cs1.findAsDouble('inner radius').setValue(-0.1) # Complains bitterly
cs1.findAsDouble('inner radius').setValue(0.2) # Actually works
# CGM's OCC backend apparently does not pay attention to
# the sphere center parameters:
cs1.findDouble('center').setValue(0, 0.2)
cs1.findDouble('center').setValue(1, 0.2)
cs1.findDouble('center').setValue(2, 0.2)
cs1.findAsDouble('center').setValue(0, 0.2)
cs1.findAsDouble('center').setValue(1, 0.2)
cs1.findAsDouble('center').setValue(2, 0.2)
res = cs1.operate()
sph = res.findModelEntity('bodies').value(0)
cs2 = sess.op('create sphere')
cs2.findDouble('radius').setValue(0.5)
cs2.findAsDouble('radius').setValue(0.5)
res2 = cs2.operate()
sph2 = res2.findModelEntity('bodies').value(0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment