222 lines
8.0 KiB
C++
222 lines
8.0 KiB
C++
/***********************************************************************************************************************
|
|
*
|
|
* Copyright (c) 2010 - 2022 by Tech Soft 3D, Inc.
|
|
* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret
|
|
* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event
|
|
* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized
|
|
* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the
|
|
* scope and manner of such use.
|
|
*
|
|
***********************************************************************************************************************/
|
|
/**
|
|
\file HelloWorld.cpp
|
|
|
|
This file demonstrates how to programmatically create a simple PDF 3D file
|
|
based on a PDF template and a PRC input file.
|
|
|
|
***********************************************************************************************************************/
|
|
|
|
#define INITIALIZE_A3D_API
|
|
#define HOOPS_PRODUCT_PUBLISH_STANDARD
|
|
#include <A3DSDKIncludes.h>
|
|
#include "../common.hpp"
|
|
#include "../CommonInit.h"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
// default sample arguments:
|
|
// in visual c++: the current directory is set through properties to $OutDir, which is $(Platform)\$(Configuration)
|
|
// in linux: the current directory is supposed to be the same as this cpp file
|
|
#ifdef _MSC_VER
|
|
# define IN_3DFILE SAMPLES_DATA_DIRECTORY"\\prc\\helloworld.prc"
|
|
# define IN_POSTERIMAGE SAMPLES_DATA_DIRECTORY"\\images\\empty.jpg"
|
|
# define OUT_FILE SAMPLES_PUBLISH_GALLERY_DIRECTORY"\\sample_HelloWorld.pdf"
|
|
#else
|
|
# define MAX_PATH 4096 // let's be large
|
|
# define IN_3DFILE SAMPLES_DATA_DIRECTORY"/prc/helloworld.prc"
|
|
# define IN_POSTERIMAGE SAMPLES_DATA_DIRECTORY"/images/empty.jpg"
|
|
# define OUT_FILE SAMPLES_PUBLISH_GALLERY_DIRECTORY"/sample_HelloWorld.pdf"
|
|
#endif
|
|
|
|
|
|
|
|
|
|
A3DStatus BuildPDFDocument(A3DUTF8Char *in_3dfile, A3DUTF8Char *out_pdffile)
|
|
{
|
|
A3DStatus iRet = A3D_SUCCESS;
|
|
|
|
// create empty document
|
|
A3DPDFDocument* pDoc = NULL;
|
|
CHECK_RET(A3DPDFDocumentCreateEmpty(&pDoc));
|
|
|
|
if(pDoc != NULL)
|
|
{
|
|
// creating a document page from scratch
|
|
A3DPDFPageData2 sPageData;
|
|
A3D_INITIALIZE_DATA(A3DPDFPageData2, sPageData);
|
|
|
|
sPageData.m_ePageOrientation = kA3DPDFPageLandscape;
|
|
sPageData.m_ePageSize = kA3DPDFPageLetter; // standard letter format: 612 x 792
|
|
const int iPageWidth = 792, iPageHeight = 612;
|
|
A3DPDFPage* pPage = NULL;
|
|
CHECK_RET(A3DPDFDocumentAppendNewPage2(pDoc, &sPageData, &pPage));
|
|
|
|
if(pPage != NULL)
|
|
{
|
|
// reading the input file; the file can be disposed of afterwards.
|
|
A3DPDF3DStream* pStream;
|
|
A3DAsmModelFile* pModelFile;
|
|
A3DRWParamsLoadData sReadParam;
|
|
A3D_INITIALIZE_DATA(A3DRWParamsLoadData, sReadParam);
|
|
|
|
sReadParam.m_sGeneral.m_bReadSolids = true;
|
|
sReadParam.m_sGeneral.m_bReadSurfaces = true;
|
|
sReadParam.m_sGeneral.m_bReadWireframes = true;
|
|
sReadParam.m_sGeneral.m_bReadPmis = true;
|
|
sReadParam.m_sGeneral.m_bReadAttributes = true;
|
|
sReadParam.m_sGeneral.m_bReadHiddenObjects = false;
|
|
sReadParam.m_sGeneral.m_bReadConstructionAndReferences = false;
|
|
sReadParam.m_sGeneral.m_bReadActiveFilter = true;
|
|
sReadParam.m_sGeneral.m_eReadingMode2D3D = kA3DRead_3D;
|
|
sReadParam.m_sGeneral.m_eReadGeomTessMode = kA3DReadGeomAndTess;
|
|
sReadParam.m_sGeneral.m_eDefaultUnit = kA3DUnitUnknown;
|
|
sReadParam.m_sPmi.m_bAlwaysSubstituteFont = false;
|
|
sReadParam.m_sPmi.m_pcSubstitutionFont = const_cast<A3DUTF8Char*>("Myriad CAD");
|
|
sReadParam.m_sTessellation.m_eTessellationLevelOfDetail = kA3DTessLODMedium;
|
|
sReadParam.m_sMultiEntries.m_bLoadDefault = true;
|
|
sReadParam.m_sAssembly.m_bUseRootDirectory = true;
|
|
iRet = A3DAsmModelFileLoadFromFile(in_3dfile, &sReadParam, &pModelFile);
|
|
if(iRet != A3D_SUCCESS && iRet != A3D_LOAD_MISSING_COMPONENTS)
|
|
{
|
|
std::cout << "Error number=" << iRet << std::endl;
|
|
return iRet;
|
|
}
|
|
|
|
if(pModelFile)
|
|
{
|
|
// creating the PRC stream from the model file that is going to be inserted into the PDF file
|
|
A3DRWParamsExportPrcData sParamsExportData;
|
|
A3D_INITIALIZE_DATA(A3DRWParamsExportPrcData, sParamsExportData);
|
|
CHECK_RET(A3DPDF3DStreamCreateFromModelFileAsPRC(pDoc, pModelFile, &sParamsExportData, &pStream, NULL));
|
|
|
|
// creating a poster image to be used as a poster for 3D.
|
|
A3DPDFImage* pImage = NULL;
|
|
A3DPDFImageCreateFromFile(pDoc, IN_POSTERIMAGE, kA3DPDFImageFormatUnknown, &pImage);
|
|
|
|
// creating the 3D artwork
|
|
A3DPDF3DArtwork* p3DArtwork;
|
|
A3DPDF3DArtworkData2 s3DArtworkData;
|
|
A3D_INITIALIZE_DATA(A3DPDF3DArtworkData2, s3DArtworkData);
|
|
|
|
s3DArtworkData.m_pStream = pStream;
|
|
s3DArtworkData.m_sDisplaySectionData.m_bAddSectionCaps = true;
|
|
|
|
CHECK_RET(A3DPDF3DArtworkCreate2(pDoc, &s3DArtworkData, &p3DArtwork));
|
|
|
|
A3DPDF3DAnnotData sAnnotData;
|
|
A3D_INITIALIZE_DATA(A3DPDF3DAnnotData, sAnnotData);
|
|
|
|
sAnnotData.m_bOpenModelTree = false;
|
|
sAnnotData.m_bShowToolbar = false;
|
|
sAnnotData.m_eLighting = kA3DPDFLightCADOptimized;
|
|
sAnnotData.m_eRenderingStyle = kA3DPDFRenderingSolid;
|
|
sAnnotData.m_sBackgroundColor.m_dRed = 0.25;
|
|
sAnnotData.m_sBackgroundColor.m_dGreen = 0.25;
|
|
sAnnotData.m_sBackgroundColor.m_dBlue = 0.25;
|
|
sAnnotData.m_bTransparentBackground = false;
|
|
sAnnotData.m_eActivateWhen = kA3DPDFActivPageOpened;
|
|
sAnnotData.m_eDesactivateWhen = kA3DPDFActivPageClosed;
|
|
sAnnotData.m_iAppearanceBorderWidth = 0;
|
|
sAnnotData.m_pPosterImage = pImage;
|
|
sAnnotData.m_p3DArtwork = p3DArtwork;
|
|
A3DPDF3DAnnot* p3DAnnot = NULL;
|
|
|
|
CHECK_RET(A3DPDF3DAnnotCreate(pDoc, &sAnnotData, &p3DAnnot));
|
|
|
|
if(p3DAnnot != NULL)
|
|
{
|
|
// position the 3D annotation in the page
|
|
A3DPDFRectData sPos;
|
|
A3D_INITIALIZE_DATA(A3DPDFRectData, sPos);
|
|
|
|
// coordinates are from bottom left of the page
|
|
sPos.m_iLeft = 0; // lower left x
|
|
sPos.m_iBottom = 0; // lower left y
|
|
sPos.m_iRight = iPageWidth ; // upper right x
|
|
sPos.m_iTop = iPageHeight ; // upper right y
|
|
CHECK_RET(A3DPDFPageInsert3DAnnot(pPage, p3DAnnot, &sPos));
|
|
}
|
|
|
|
// cleaning up -- WARNING: DO NOT CALL THIS BEFORE A3DPDF3DArtworkCreate!
|
|
CHECK_RET(A3DAsmModelFileDelete(pModelFile));
|
|
|
|
// saving the document
|
|
CHECK_RET(A3DPDFDocumentSaveEx(pDoc, kA3DPDFSaveFull|kA3DPDFSaveOptimized, out_pdffile));
|
|
|
|
CHECK_RET(A3DPDFDocumentClose(pDoc));
|
|
}
|
|
}
|
|
}
|
|
|
|
return iRet;
|
|
}
|
|
|
|
//######################################################################################################################
|
|
// Main function
|
|
#ifdef _MSC_VER
|
|
int wmain(A3DInt32 iArgc, A3DUniChar** ppcArgv)
|
|
#else
|
|
int main(int iArgc, A3DUTF8Char** ppcArgv)
|
|
#endif
|
|
{
|
|
#ifndef _MSC_VER
|
|
setenv("LC_NUMERIC", "en_US.UTF-8", 1); // Locally force locale
|
|
#endif
|
|
|
|
// init A3DLIB library - automatically handled init/terminate
|
|
A3DSDKHOOPSPublishLoader sHoopsPublishLoader(_T(HOOPS_BINARY_DIRECTORY));
|
|
CHECK_RET(sHoopsPublishLoader.m_eSDKStatus);
|
|
|
|
CHECK_RET(A3DDllSetCallbacksMemory(CheckMalloc, CheckFree));
|
|
|
|
// init HOOPS Publish related PDF library - automatically handled init/terminate
|
|
// do it only only once during the life of the application
|
|
CHECK_RET(sHoopsPublishLoader.InitPDFLib());
|
|
|
|
A3DUTF8Char in_3dfile[MAX_PATH * 4];
|
|
A3DUTF8Char out_pdffile[MAX_PATH * 4];
|
|
|
|
switch (iArgc)
|
|
{
|
|
case 1:
|
|
// no arguments provided
|
|
strcpy(in_3dfile, IN_3DFILE);
|
|
strcpy(out_pdffile, OUT_FILE);
|
|
break;
|
|
|
|
case 3:
|
|
// converting the input parameters to UTF-8
|
|
#ifdef _MSC_VER
|
|
A3DMiscUTF16ToUTF8(ppcArgv[1], in_3dfile);
|
|
A3DMiscUTF16ToUTF8(ppcArgv[2], out_pdffile);
|
|
#else
|
|
strcpy(in_3dfile, ppcArgv[1]);
|
|
strcpy(out_pdffile, ppcArgv[2]);
|
|
#endif
|
|
break;
|
|
|
|
default:
|
|
std::cout << "Usage:\n" << ppcArgv[0] << " <in_3dfile> <out_pdffile>\n";
|
|
return A3D_ERROR;
|
|
}
|
|
|
|
// launch PDF treatment
|
|
A3DStatus iRet = BuildPDFDocument(in_3dfile, out_pdffile);
|
|
if (iRet != A3D_SUCCESS)
|
|
return iRet;
|
|
|
|
// Check memory allocations
|
|
return (int)ListLeaks();
|
|
}
|