Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Working with TDocStd_Document: Empty document when trying to use TDocStd_Application::Open wrapped by OCP

Abierto
#182 2 comentarios 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
cpp, python
Área
tooling

Línea de trabajo

Comienza con la llamada a TDocStd_Application::Open, el binding open_ocaf_file y el fallo posterior de app.Close(doc) descrito en el issue. Comprueba cómo se gestionan la entrada BytesIO y el estado devuelto; después, verifica que el documento abierto expone formas libres mediante GetFreeShapes y que puede cerrarse correctamente.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

question

I'm trying to read/open an XDE/OCAF XML file. I've tried already different ways of doing it. First, I've tried to read from the disk a .xml file, using:
TDocStd_Application::Open

and in my last attempt I've tried to read from an io.BytesIO() that comes from my C++ code also using TDocStd_Application::Open.

Bellow my code:

def read_ocaf_file():
    output_stream = io.BytesIO()

    # Save the document contents to the provided output stream
    success = open_ocaf_file(output_stream) # C++ binded fuction that returns a stream containing the data of the TDocStd_Document

    if success:
        # prepare a doc
        app = XCAFApp_Application.GetApplication_s()

        doc = TDocStd_Document(TCollection_ExtendedString("XmlXCAF"))
        app.InitDocument(doc)
        #app = XCAFApp_Application.GetApplication_s()
        tool = XCAFDoc_DocumentTool.ShapeTool_s(doc.Main())
        tool.SetAutoNaming_s(False)
        ctool = XCAFDoc_DocumentTool.ColorTool_s(doc.Main())
        store = XmlXCAFDrivers_DocumentStorageDriver(
            TCollection_ExtendedString("Copyright: Open Cascade, 2001-2002")
        )
        ret = XmlXCAFDrivers_DocumentRetrievalDriver()

        app.DefineFormat(
            TCollection_AsciiString("XmlXCAF"),
            TCollection_AsciiString("Xml XCAF Document"),
            TCollection_AsciiString("xml"),
            ret,
            store,
        )
        #doc.UnsetIsReadOnly()
        status = app.Open(io.BytesIO(output_stream.getvalue()), doc)
        assert status == PCDM_StoreStatus.PCDM_SS_OK
        
    else:
        print("Failed to save the document.")

    labels = TDF_LabelSequence()
    tool.GetFreeShapes(labels)
    shapes = []
    for i in range(1, labels.Length() + 1):
        label = labels.Value(i)
        shape = self.shape_tool.GetShape_s(label)
        shapes.append(shape)


    app.Close(doc)

Although, at the end the app.Open returns PCDM_StoreStatus.PCDM_SS_OK when I try to get data from the doc is like it's empty, If I try to do for example: app.Close(doc), I get this following error:

    app.Close(doc)
OCP.Standard.Standard_Failure: cannot close a document that has not been opened

Does anyone have experience on working with OCAF/XDE files and has experienced similar difficulties with TDocStd_Document?

Any insights or examples on this matter would be highly appreciated!

Thank you very much for the attention

Lenguaje dominante
C++
Estrellas
203
Forks
50
Merge medio
3 d 4 h
PR fusionados (30 d)
1

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de CadQuery/OCP

Todos los issues de CadQuery/OCP

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.