Ejemplo n.º 1
0
void CXMLExporter::WriteLayers()
{
    if (m_pOptions->GetExportLayers())
    {
        HResult hr;

        CComPtr<ISkpLayers> pLayers;
        hr = m_pDocument->get_Layers(&pLayers);
        
        long count;
        hr = pLayers->get_Count(&count);

        if (count>0)
        {
            IncreaseIndent();
            Write("<Layers>\n", count);
            IncreaseIndent();
            for(long i=0; i<count; i++) 
            {
                CComPtr<ISkpLayer> pLayer;
                hr = pLayers->get_Item(i, &pLayer);
                WriteLayer(pLayer);
            }
            DecreaseIndent();
            Write("</Layers>\n");
            DecreaseIndent();
        }
    }
}
Ejemplo n.º 2
0
void CXMLExporter::WriteMaterials()
{
    if (m_pOptions->GetExportMaterials())
    {
        if (m_pOptions->GetExportMaterialsByLayer())
        {
            HResult hr;

            CComPtr<ISkpLayers> pLayers;
            hr = m_pDocument->get_Layers(&pLayers);

            long count;
            hr = pLayers->get_Count(&count);

            if (count>0)
            {
                for(long i=0; i<count; i++) 
                {
                    CComPtr<ISkpLayer> pLayer;
                    hr = pLayers->get_Item(i, &pLayer);

                    CComPtr<ISkpMaterial> pMaterial;
                    hr = pLayer->get_Material(&pMaterial);
                    WriteMaterial(pMaterial);
                }
            }
        }
        else
        {
            HResult hr;
            CComPtr<ISkpMaterials> pMats;

            hr = m_pDocument->get_Materials(&pMats);
            long count = 0L;
            hr = pMats->get_Count(&count);
            
            if (count>0)
            {
                IncreaseIndent();
                Write("<Materials count=\"%ld\">\n", count);
                IncreaseIndent();
                for(long i=0; i<count; i++)
                {
                    CComPtr<ISkpMaterial> pMat;
                    hr = pMats->get_Item(i, &pMat);
                    WriteMaterial(pMat);
                }
                DecreaseIndent();
                Write("</Materials>\n");
                DecreaseIndent();
            }
        }
    }
}
Ejemplo n.º 3
0
void CXMLExporter::WriteGeometry()
{
    HResult hr;

    CComPtr<ISkpEntityProvider> pEntProvider;
    hr = m_pDocument->QueryInterface(IID_ISkpEntityProvider, (void**) &pEntProvider);

    IncreaseIndent();
    Write("<Geometry>\n");
        IncreaseIndent();
        WriteFacesAndEdges(pEntProvider);
        DecreaseIndent();
    Write("</Geometry>\n");
    DecreaseIndent();
}
Ejemplo n.º 4
0
std::string Interface::ToString() 
{
  std::string res; 
  res += WriteIndent() + "\"" + ReplaceDotInName(name) + "\"" + " : {\n";
  // indentation should be increased
  IncreaseIndent();
  res += WriteIndent() + "\"" + "internal" + "\"" + " : " + internal + "\n";
  // indentation should be decreased
  DecreaseIndent();
  res += WriteIndent() + "}";
  return res;
}
Ejemplo n.º 5
0
void CXMLExporter::WriteOptionsProvider(const char* title, CComPtr<ISkpNamedValues> pNVs)
{
    if(pNVs == NULL) 
    {
        return;
    }

    long count;
    HResult hr;

    hr = pNVs->get_Count(&count);

    if (count>0)
    {
        IncreaseIndent();
        Write("<OptionsProvider name=\"%s\">\n", title);
        IncreaseIndent();
        for(long i=0; i<count; i++)
        {
			CComPtr<ISkpNamedValue> pNV;
            hr = pNVs->get_Item(i, &pNV);
            BSTR bName; 
            VARIANT vValue;
            VariantInit(&vValue);

            hr = pNV->get_Name(&bName);
            hr = pNV->get_Value(&vValue);

            m_Stats.m_nOptions += 1;
            CXMLExporterBase::WriteOption(bName, vValue);

            SysFreeString(bName);
            VariantClear(&vValue);
        }
        DecreaseIndent();
        Write("</OptionsProvider>\n");
        DecreaseIndent();
    }
}
Ejemplo n.º 6
0
void CExporterXML::ExportURB(CURB *pURB)
{
    LPTSTR sBuffer = (LPTSTR) alloca((2 * MAX_USB_TRANSFERBUFFER_SIZE + 1) * sizeof(TCHAR));
    OutputFormat("<urb sequence=\"%d\">", pURB->GetSequenceNr());
    IncreaseIndent();
    OutputTag("function", pURB->GetFunctionStr());
    OutputTag("timestamp", "%d", pURB->GetTime(m_pAR));
    OutputTag("endpoint", "%d", pURB->GetEndpoint());
    if(pURB->GetPayloadCount(-1) > 0)
    {
        OutputTag("packetcount", "%d", pURB->GetPacketCount());
        for(int nPacket = 0 ; nPacket < pURB->GetPacketCount(); ++nPacket)
        {
            OutputFormat("<payload packet=\"%d\">", nPacket);
            IncreaseIndent();
            OutputTag("payloadcount", "%d", pURB->GetPayloadCount(nPacket));
            OutputTag("payloadbytes", pURB->GetPayloadXML(nPacket, sBuffer));
            DecreaseIndent();
            OutputFormat("</payload>");
        }
    }
    DecreaseIndent();
    OutputFormat("</urb>");
}
Ejemplo n.º 7
0
std::string Process::ToString()
{
  std::string res;
  res += WriteIndent() + "\"" + name + "\" : {\n";
  // indentation should be increased
  IncreaseIndent();
  res += WriteIndent() + "\"" + "internal" + "\"" + " : " + internal + ",\n";
  res += WriteIndent() + "\"" + "data"     + "\"" + " : {\n"; 

  res += InnersToString();
  // indentation should be decreased
  res += "\n" + WriteIndent() + "}";
  DecreaseIndent();
  res += "\n" + WriteIndent() + "}";
  return res;
}
Ejemplo n.º 8
0
void CXMLExporter::WriteOptions()
{
    if (m_pOptions->GetExportOptions())
    {
        HResult hr;

        CComPtr<ISkpOptionsManager> pOptManager;
        hr = m_pDocument->get_OptionsManager(&pOptManager);

        long count;
        hr = pOptManager->get_Count(&count);

        if (count>0)
        {
            IncreaseIndent();
            Write("<Options>\n");

            VARIANT vNum;
            ::VariantInit(&vNum);
            vNum.vt = VT_I4;
            for(long i=0; i<count; i++)
            {
                CComPtr<ISkpOptionsProvider> pProvider;

                vNum.lVal = i;
                hr = pOptManager->get_Item(vNum, &pProvider);
                
                // write the option provider
                CComPtr<ISkpNamedValues> pNamedOptions;
                hr = pProvider->QueryInterface(IID_ISkpNamedValues, (void**)&pNamedOptions);

                BSTR bProviderName;
                hr = pProvider->get_Name(&bProviderName);
                _bstr_t szProviderName(bProviderName, true);

                WriteOptionsProvider((const char*)szProviderName, pNamedOptions);

                SysFreeString(bProviderName);
            }
            Write("</Options>\n");
            DecreaseIndent();
        }
    }
}
Ejemplo n.º 9
0
void CXMLExporter::WriteEdge(CComPtr<ISkpEdge> pEdge)
{
    HResult hr;

    m_Stats.m_nEdges += 1;

    if (m_pOptions->GetExportLayers())
    {
        CComPtr<ISkpDrawingElement> pDE;
        hr = pEdge->QueryInterface(IID_ISkpDrawingElement, (void**) &pDE);

        CComPtr<ISkpLayer> pLayer;
        hr = pDE->get_Layer(&pLayer);

        long layerId = GetEntityId(pLayer);

        Write("<Edge layer=\"%d\">\n", layerId);
    }
    else
    {
        Write("<Edge>\n");
    }

    IncreaseIndent();

    CComPtr<ISkpPoint3d> pStartPoint;
    hr = pEdge->get_StartPoint(&pStartPoint);
    CPoint3d startPt(pStartPoint);
    CPoint3d startPoint = m_InheritanceManager.GetCurrentTransform() * startPt;
    Write("<Start x=\"%f\" y=\"%f\" z=\"%f\" />\n", startPoint.X(), startPoint.Y(), startPoint.Z());

    CComPtr<ISkpPoint3d> pEndPoint;
    hr = pEdge->get_EndPoint(&pEndPoint);
    CPoint3d endPt(pEndPoint);
    CPoint3d endPoint = m_InheritanceManager.GetCurrentTransform() * endPt;
    Write("<End x=\"%f\" y=\"%f\" z=\"%f\" />\n", endPoint.X(), endPoint.Y(), endPoint.Z());

    DecreaseIndent();

    Write("</Edge>\n");
}
Ejemplo n.º 10
0
void CExporterXML::EndExport(void)
{
    DecreaseIndent();
    OutputFormat("</snoopyprolog>");
}
Ejemplo n.º 11
0
void CXMLExporter::WriteFace(CComPtr<ISkpFace> pFace)
{
    HResult hr;

    BOOL bHasFrontTexture = false;
    BOOL bHasBackTexture = false;
    long frontId=-1;
    long backId=-1;
    long layerId=-1;

    if (m_pOptions->GetExportMaterials())
    {
        CComPtr<ISkpMaterial> pFrontMaterial = m_InheritanceManager.GetCurrentFrontMaterial();
        if (pFrontMaterial)
        {
            hr = pFrontMaterial->get_IsTexture(&bHasFrontTexture);
            frontId = GetEntityId(pFrontMaterial);
        }

        CComPtr<ISkpMaterial> pBackMaterial = m_InheritanceManager.GetCurrentBackMaterial();

        if (pBackMaterial)
        {
            hr = pBackMaterial->get_IsTexture(&bHasBackTexture);
            backId = GetEntityId(pBackMaterial);
        }
    }

    if (m_pOptions->GetExportLayers())
    {
        CComPtr<ISkpDrawingElement> pDE;
        hr = pFace->QueryInterface(IID_ISkpDrawingElement, (void**) &pDE);

        CComPtr<ISkpLayer> pLayer;
        hr = pDE->get_Layer(&pLayer);

        layerId = GetEntityId(pLayer);
    }

    BOOL bHasTexture = bHasFrontTexture | bHasBackTexture;
    CComPtr<ISkpUVHelper> pUVHelper = NULL;

    //If the face has a texture(s) applied to it, then create a UVHelper class so we can output the uv
    //coordinance at each vertex.
    if (bHasTexture)
    {
        CComPtr<ISkpCorrectPerspective> pCorrectPerspective;
        hr = m_pTextureWriter->QueryInterface(IID_ISkpCorrectPerspective, (void**)&pCorrectPerspective); 

        hr = pFace->GetUVHelper(bHasFrontTexture, bHasBackTexture, pCorrectPerspective, &pUVHelper);
    }

    //Find out how many loops the face has
    CComPtr<ISkpLoops> pLoops;
    hr = pFace->get_Loops(&pLoops);

    long nLoops;
    hr = pLoops->get_Count(&nLoops);

    //If this is a simple face (no loops)
    if (nLoops==1)
    {
        WriteFaceStart(frontId, backId, layerId);

        IncreaseIndent();

        CComPtr<ISkpLoop> pLoop;
        hr = pFace->get_OuterLoop(&pLoop);

        CComPtr<ISkpVertices> pVerts;
        hr = pLoop->get_Vertices(&pVerts);

        long nVerts;
        hr = pVerts->get_Count(&nVerts);

        for (long i=0;i<nVerts;i++)
        {
            CComPtr<ISkpVertex> pVert;
            hr = pVerts->get_Item(i, &pVert);

            CComPtr<ISkpPoint3d> pSkpPoint;
            hr = pVert->get_Position(&pSkpPoint);

            CPoint3d point(pSkpPoint);
            CPoint3d worldPoint = m_InheritanceManager.GetCurrentTransform() * point;

            if (bHasTexture)
            {
                Write("<Vertex x=\"%f\" y=\"%f\" z=\"%f\">\n", worldPoint.X(), worldPoint.Y(), worldPoint.Z());
            }
            else
            {
                //This one closes the tag as well because we don't have child (UV) nodes
                Write("<Vertex x=\"%f\" y=\"%f\" z=\"%f\" />\n", worldPoint.X(), worldPoint.Y(), worldPoint.Z());
            }

            if (bHasFrontTexture)
            {
                IncreaseIndent();
                double u, v, q;
                pUVHelper->GetFrontUVQ(worldPoint.X(), worldPoint.Y(), worldPoint.Z(), &u, &v, &q);
                Write("<TextureCood front=\"true\" u=\"%f\" v=\"%f\" />\n", u, v);
                DecreaseIndent();
            }

            if (bHasBackTexture)
            {
                IncreaseIndent();
                double u, v, q;
                pUVHelper->GetBackUVQ(worldPoint.X(), worldPoint.Y(), worldPoint.Z(), &u, &v, &q);
                Write("<TextureCood front=\"false\" u=\"%f\" v=\"%f\" />\n", u, v);
                DecreaseIndent();
            }

            if (bHasTexture)
            {
                Write("</Vertex>\n");
            }

        }
        DecreaseIndent();
        Write("</Face>\n");
    }
    else
    {
        //If this is a complex face with one or more holes in it
        //we tesselate it into triangles using the polygon mesh class, then
        //export each triangle as a face.

        CComPtr<ISkpPolygonMesh> pMesh;

        if (bHasTexture)
        {
            pFace->CreateMeshWithUVHelper(3, pUVHelper, &pMesh);
        }
        else
        {
            pFace->CreateMesh(0, NULL, &pMesh);
        }

        long nPolys;
        hr = pMesh->get_NumPolygons(&nPolys);

        for (long i=0;i<nPolys;i++)
        {
            long nPoints;

            //The mesh is 1 based
            hr = pMesh->CountPolygonPoints(i+1, &nPoints);

            WriteFaceStart(frontId, backId, layerId);

            IncreaseIndent();
            for (long j=0;j<nPoints;j++)
            {
                CComPtr<ISkpPoint3d> skpPoint;
                hr = pMesh->get_PolygonPoint(i+1, j+1, &skpPoint);

                CPoint3d point(skpPoint);
                CPoint3d worldPoint = m_InheritanceManager.GetCurrentTransform() * point;

                if (bHasTexture)
                {
                    Write("<Vertex x=\"%f\" y=\"%f\" z=\"%f\">\n", worldPoint.X(), worldPoint.Y(), worldPoint.Z());
                }
                else
                {
                    //This one closes the tag as well because we don't have child (UV) nodes
                   Write("<Vertex x=\"%f\" y=\"%f\" z=\"%f\" />\n", worldPoint.X(), worldPoint.Y(), worldPoint.Z());
                }

                if (bHasFrontTexture)
                {
                    IncreaseIndent();
                    double u, v, q;
                    pUVHelper->GetFrontUVQ(worldPoint.X(), worldPoint.Y(), worldPoint.Z(), &u, &v, &q);
                    Write("<TextureCood front=\"true\" u=\"%f\" v=\"%f\" />\n", u, v);
                    DecreaseIndent();
                }

                if (bHasBackTexture)
                {
                    IncreaseIndent();
                    double u, v, q;
                    pUVHelper->GetBackUVQ(worldPoint.X(), worldPoint.Y(), worldPoint.Z(), &u, &v, &q);
                    Write("<TextureCood front=\"false\" u=\"%f\" v=\"%f\" />\n", u, v);
                    DecreaseIndent();
                }

                if (bHasTexture)
                {
                    Write("</Vertex>\n");
                }
            }
            DecreaseIndent();
            Write("</Face>\n");
        }
    }
}
Ejemplo n.º 12
0
void CXMLExporter::WriteMaterial(CComPtr<ISkpMaterial> pMaterial)
{
    if(pMaterial == NULL)
    {
        return;
    }

    HResult hr;
    BSTR materialName;

    hr = pMaterial->get_Name(&materialName);
    _bstr_t szMaterialName(materialName, true);

    Write("<Material id=\"%d\" name=\"%s\">\n", GetEntityId(pMaterial), (const char*)szMaterialName);
    SysFreeString(materialName);

    IncreaseIndent();

    //Color
    BOOL isColor;
    hr = pMaterial->get_IsColor(&isColor);
    if ( isColor )
    {
        OLE_COLOR color;
        hr = pMaterial->get_Color(&color);
        Write("<Color> #%06x </Color>\n", color);
    }

    // Alpha
    BOOL usesAlpha;
    hr = pMaterial->get_UsesAlpha(&usesAlpha);
    if ( usesAlpha )
    {
        double alpha = 0;
        hr = pMaterial->get_Alpha(&alpha);
        Write("<Alpha>%lf</Alpha>\n", alpha);
    }

    // See if it has a texture
    BOOL isTexture = FALSE;
    hr = pMaterial->get_IsTexture(&isTexture);
    if( isTexture )
    {
        CComPtr<ISkpTexture> pTexture = NULL;
        hr = pMaterial->get_Texture(&pTexture);
        if(pTexture != NULL)
        {
            BSTR texturePath = NULL;
            hr = pTexture->get_Filename(&texturePath);
            std::string bstrFilename = GetFileName(texturePath);
            _bstr_t szTexturePath(bstrFilename.c_str());
            
            double width = 0;
            double height = 0;
            hr = pTexture->get_XScale(&width);
            hr = pTexture->get_YScale(&height);
            
            Write("<Texture path=\"%s\" xscale=\"%8.4lf\" yscale=\"%8.4lf\" />\n", bstrFilename.c_str(), width, height);
            SysFreeString(texturePath);
        }
    }

    DecreaseIndent();
    Write("</Material>\n");
}