GEOM_Object from a TopoDS_Shape
GEOM_Object from a TopoDS_ShapePosted by jelle at July 20. 2011
I'm interested in building a GEOM_Object from a TopoDS_Shape.
I've tried the following:
def geomobject_from_topods(topods, pmc):
returns a GEOM_Object that contains a TopoDS_Shape
:param topods: the TopoDS_Shape to add to the GEOM_Object
:param pmc: the parametric modeling context
:return: a GEOM_Object that contains :topods:
# creates a GEOM_Object in the appropriate context
geomobject = pmc.myEngine.AddObject(pmc.docId,counter.next()).GetObject()
label = geomobject.GetEntry() # TDF_Label
doc_tool = XCAFDoc_DocumentTool().ShapeTool(label).GetObject()
when I call geomobject.GetValue(), a TopoDS_Shape is returned, so this looks good.
however, when using the results GEOM_Object in a call such as:
I get no result. I tried this with a number of calls, so I'm suspecting the GEOM_Object isn't built right.
Many thanks in advance,
PS: this example is built on PythonOCC and Fotios' GEOM module, so perhaps looks a little different from the Salome python API. Don't let that distract you
The reason of the problem is that the XCAF tool (doc_tool in your code) and the GEOM_Object use CAF structure in different ways. Imagine that doc_tool sets the TopoDS_Shape directly to the label it was initialized with, while GEOM_Object stores TopoDS_Shape on some child label.
Actually CAF document does not define a way how to use it's structure, and different tools do it differently.
Re: GEOM_Object from a TopoDS_ShapePosted by jelle at July 20. 2011
Many thanks Michael!
However, I hope you might be able to give me a pointer on how I can achieve adding a TopoDS_Shape to a GEOM_Object.
I've read some of the C++ code [ I'm a python programmer, so I probably missed a lot ] but could not decipher how to achieve this.
Could you be so kind to be more specific wrt the TDF_Label?
It should not be so hard to fake this, right
I don't know how to achieve what you want.
If you have OCCT wrapped into python, why to use SALOME at all? SALOME is just a user interface to OCCT, you can make all (or most at least) things directly using API of OCCT.
Re: GEOM_Object from a TopoDS_ShapePosted by jelle at July 22. 2011
Its very simple really; I consider GEOM a modern part of OCC.
I'm not using Salome, but we've integrated GEOM into pythonocc.
Algorithms such as Paver, Partitioning & the bool ops are welcome additions to what is found in OCC.
Besides that, GEOM offers an associative parametric modeling approach, again, great stuff.
To be able to access it and to make it work with the rest of OCC, I need to be able to move a TopoDS_Shape -> GEOM_Object.
So far I've managed to do the following:
doc_tool = XCAFDoc_DocumentTool().ShapeTool(pmc.root).GetObject()
# topods might be a TopoDS_Edge for example, make it a TopoDS_Shape
shape = TopoDS_Shape(topods)
label = doc_tool.AddShape(shape, False)
go = GEOM_Object(label, topods.ShapeType())
assert go.GetEntry().IsEqual(label) == True # that works!
print 'did we fail?', tt.GetValue().IsNull(), ' should be 0'
# the problem is that GEOM_Object.GetValue() returns the value of the
# this is the value returned by go.GetValue(), its just an alias for:
# go.GetLastFunction().GetObject().GetValue() # -> segfaults...
gf = go.GetLastFunction().GetObject() # this is what GEOM_Object.GetValue() would return
go.GetValue().IsNull() # this is always the case since we lack something at go.GetLastFunction()
So I'm not so far anymore, but sure could some help here
Re: GEOM_Object from a TopoDS_ShapePosted by Saint Michael at July 26. 2011
I believe this won't work.
Looking at sources of XCAFDoc_ShapeTool I see that it stores shapes on child labels of some predefined label of the CAF document:
| - ***
| - TopoDS_Shape 1
| - TopoDS_Shape 2
| - TopoDS_Shape N
But GEOM_Function::GetObject() always return the shape set on the child label #2:
| - ***
| - TopoDS_Shape returned by GetObject()
| - ***
Thus, if you set a GEOM_Function of GEOM_Object and a XCAFDoc_ShapeTool on the same label, GEOM_Object will always return the shape ("TopoDS_Shape 2" in the drawing) set by the second call of XCAFDoc_ShapeTool.AddShape()
Re: GEOM_Object from a TopoDS_ShapePosted by jelle at July 27. 2011
I owe Fotios Sioutis a big thanks for the following snippet:
Handle(GEOM_Object) anImport = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
Handle(GEOM_Function) aFunction = anImport->AddFunction(GEOMImpl_ImportDriver::GetID(), IMPORT_SHAPE);
that translates to the python PAF framework idiom, where my_context is an instance of ParametricModelingContext:
def geomobject_from_topods(my_context, topods_shape):
adds a TopoDS_Shape *topods_shape* the the ParametricModelingContext *paf_context*
:param paf_context: ParametricModelingContext
:param topods_shape: TopoDS_Shape
GEOM_IMPORT, IMPORT_SHAPE = 1, 1
anImport = my_context.myEngine.AddObject(my_context.docId, GEOM_IMPORT).GetObject()
_import_driver = GEOMImpl_ImportDriver()
aFunc = anImport.AddFunction(_import_driver.GetID(), IMPORT_SHAPE).GetObject()