Add publish
This commit is contained in:
284
publish/publishsource/CreatePRCCubes/CreatePRCCubes.cpp
Normal file
284
publish/publishsource/CreatePRCCubes/CreatePRCCubes.cpp
Normal file
@@ -0,0 +1,284 @@
|
||||
/***********************************************************************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
***********************************************************************************************************************/
|
||||
/**
|
||||
* Sample CreatePRCCubes
|
||||
* file CreatePRCCubes.cpp
|
||||
* This file is containing the main trunc of the CreatePRCCubes sample.
|
||||
*
|
||||
* The purpose of this sample is to propose an embryo set of functionality allowing the creation of various PRC entities.
|
||||
* It proposes and tackles different modules such as:
|
||||
* - creation of markups: see CreateMarkups.cpp
|
||||
* - creation of views: see CreateViews.cpp
|
||||
* - creation of textures: see CreateTextures.cpp
|
||||
* - creation of colors: see CreateGraphics.cpp
|
||||
* - creation of links between entities: see CreateLinkedItem.cpp
|
||||
*
|
||||
* Inside this files is created either a PRC or a PDF file with a defined structures,
|
||||
* a certain number of markups and a certain number of views.
|
||||
*
|
||||
* The function createAssemblyTree, createFileMarkups, createFileViews
|
||||
* can be modified to create your own PRC or PDF file:
|
||||
* modifying the structure can be done in createAssemblyTree.
|
||||
* modifying the views can be done in createFileViews.
|
||||
* modifying the markups can be done in createFileMarkups.
|
||||
*
|
||||
* It should be the reference sample for PRC entity creation but is also a great tool to understand how the PRC tree is working.
|
||||
*
|
||||
***********************************************************************************************************************/
|
||||
|
||||
#define INITIALIZE_A3D_API
|
||||
#define HOOPS_PRODUCT_PUBLISH_STANDARD
|
||||
#include "CreatePRCCubesDef.h"
|
||||
|
||||
#include "../CommonInit.h"
|
||||
|
||||
#include "CreateModelFile.h"
|
||||
#include <vector>
|
||||
|
||||
//######################################################################################################################
|
||||
|
||||
/*
|
||||
void debugCheckRet()
|
||||
{
|
||||
printf("debug");
|
||||
}
|
||||
|
||||
#define CHECK_RET(function_call) {\
|
||||
iRet = function_call; if(iRet != A3D_SUCCESS) { debugCheckRet(); std::cout << "Error number=" << iRet << std::endl; return iRet; }\
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// 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 TEXTURE_FILE SAMPLES_DATA_DIRECTORY"\\images\\Logo.jpg"
|
||||
# define OUT_FILE SAMPLES_PUBLISH_GALLERY_DIRECTORY"\\sample_CreatePRCCubes.pdf"
|
||||
#else
|
||||
# define TEXTURE_FILE SAMPLES_DATA_DIRECTORY"/images/Logo.jpg"
|
||||
# define OUT_FILE SAMPLES_PUBLISH_GALLERY_DIRECTORY"/sample_CreatePRCCubes.pdf"
|
||||
#endif
|
||||
|
||||
|
||||
//######################################################################################################################
|
||||
A3DVoid mallocAndSetString(const A3DUTF8Char* srcString, A3DUTF8Char*& destString)
|
||||
{
|
||||
// we return empty strings rather than NULL because some strings usages crash with NULL values
|
||||
// (for example std::string xx = NULL crashes !)
|
||||
unsigned int uiSize = (unsigned int)(srcString ? strlen(srcString) : 0);
|
||||
destString = (A3DUTF8Char*)malloc((uiSize + 1) * sizeof(A3DUTF8Char));
|
||||
if (uiSize > 0)
|
||||
{
|
||||
strcpy(destString, srcString);
|
||||
}
|
||||
destString[uiSize] = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
A3DStatus BuildPDFDocument()
|
||||
{
|
||||
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)
|
||||
{
|
||||
// creating the model file
|
||||
A3DAsmModelFile* pModelFile = NULL;
|
||||
iRet = createPRCCubesFile(&pModelFile, TEXTURE_FILE);
|
||||
|
||||
std::vector<std::string> asViewNamesList;
|
||||
std::vector<std::string> asViewLabelsList;
|
||||
asViewNamesList.push_back("Default View");
|
||||
asViewLabelsList.push_back("Default View");
|
||||
asViewNamesList.push_back("Define New Camera");
|
||||
asViewLabelsList.push_back("Define New Camera");
|
||||
asViewNamesList.push_back("Hide Objects");
|
||||
asViewLabelsList.push_back("Hide Objects");
|
||||
asViewNamesList.push_back("Change Objects Color");
|
||||
asViewLabelsList.push_back("Change Objects Color");
|
||||
asViewNamesList.push_back("Change Face Color");
|
||||
asViewLabelsList.push_back("Change Face Color");
|
||||
asViewNamesList.push_back("Visible Annotation");
|
||||
asViewLabelsList.push_back("Visible Annotation");
|
||||
asViewNamesList.push_back("Change Object Position");
|
||||
asViewLabelsList.push_back("Change Object Position");
|
||||
|
||||
if(pModelFile)
|
||||
{
|
||||
/*
|
||||
// sample code to save the PRC File
|
||||
A3DRWParamsExportPrcData sParamsExportData;
|
||||
A3D_INITIALIZE_DATA(A3DRWParamsExportPrcData, sParamsExportData);
|
||||
sParamsExportData.m_bCompressBrep = true;
|
||||
sParamsExportData.m_bCompressTessellation = true;
|
||||
sParamsExportData.m_eCompressBrepType = kA3DCompressionMedium;
|
||||
CHECK_RET(A3DAsmModelFileExportToPrcFile(pModelFile, &sParamsExportData, pcPRCFileName, NULL);
|
||||
CHECK_RET(A3DPDF3DStreamCreateFromFile(pDoc, "c:\\temp\\myprc.prc", true, &pStream));
|
||||
*/
|
||||
|
||||
// creating the PRC stream from the model file that is going to be inserted into the PDF file
|
||||
A3DPDF3DStream* pStream;
|
||||
A3DRWParamsExportPrcData sParamsExportData;
|
||||
A3D_INITIALIZE_DATA(A3DRWParamsExportPrcData, sParamsExportData);
|
||||
sParamsExportData.m_bCompressTessellation = false;
|
||||
|
||||
CHECK_RET(A3DPDF3DStreamCreateFromModelFileAsPRC(pDoc, pModelFile, &sParamsExportData, &pStream, NULL));
|
||||
|
||||
// creating the 3D artwork
|
||||
A3DPDF3DArtwork* p3DArtwork;
|
||||
A3DPDF3DArtworkData2 s3DArtworkData;
|
||||
A3D_INITIALIZE_DATA(A3DPDF3DArtworkData2, s3DArtworkData);
|
||||
|
||||
s3DArtworkData.m_pStream = pStream;
|
||||
s3DArtworkData.m_bActivatePMICrossHighlight = true;
|
||||
s3DArtworkData.m_bAddPMISemanticInformation = true;
|
||||
s3DArtworkData.m_bAddAdditionalGeometry = true;
|
||||
s3DArtworkData.m_sDisplaySectionData.m_bAddSectionCaps = true;
|
||||
s3DArtworkData.m_bKeepNativeDefaultView = true; // this enables to respect the default view defined in PRC
|
||||
CHECK_RET(A3DPDF3DArtworkCreate2(pDoc, &s3DArtworkData, &p3DArtwork));
|
||||
|
||||
A3DPDF3DAnnotData sAnnotData;
|
||||
A3D_INITIALIZE_DATA(A3DPDF3DAnnotData, sAnnotData);
|
||||
|
||||
sAnnotData.m_bOpenModelTree = false;
|
||||
sAnnotData.m_bShowToolbar = false;
|
||||
sAnnotData.m_eLighting = kA3DPDFLightWhite;
|
||||
sAnnotData.m_eRenderingStyle = kA3DPDFRenderingSolid;
|
||||
sAnnotData.m_sBackgroundColor.m_dRed = 0.75;
|
||||
sAnnotData.m_sBackgroundColor.m_dGreen = 0.75;
|
||||
sAnnotData.m_sBackgroundColor.m_dBlue = 0.75;
|
||||
sAnnotData.m_bTransparentBackground = false;
|
||||
sAnnotData.m_eActivateWhen = kA3DPDFActivPageOpened;
|
||||
sAnnotData.m_eDesactivateWhen = kA3DPDFActivPageClosed;
|
||||
sAnnotData.m_iAppearanceBorderWidth = 0;
|
||||
sAnnotData.m_pPosterImage = NULL; // default poster automatically generated
|
||||
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);
|
||||
const A3DInt32 iHeigthButView = 15;
|
||||
|
||||
// coordinates are from bottom left of the page
|
||||
sPos.m_iLeft = 100; // 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));
|
||||
|
||||
A3DPDFButton** ppButtonsViews = (A3DPDFButton**)malloc(asViewNamesList.size() * A3DUns32(sizeof(A3DPDFButton*)));
|
||||
for (size_t i = 0; i < asViewNamesList.size(); i++)
|
||||
{
|
||||
// buttons scrolls both act the same and have same attributes
|
||||
A3DPDFButtonData sButtonViewsData;
|
||||
A3D_INITIALIZE_DATA(A3DPDFButtonData, sButtonViewsData);
|
||||
sButtonViewsData.m_bHasFillColor = false;
|
||||
sButtonViewsData.m_bHasBorder = false;
|
||||
sButtonViewsData.m_eThicknessBorder = kA3DPDFThin;
|
||||
sButtonViewsData.m_eLineStyleBorder = kA3DPDFSolid;
|
||||
sButtonViewsData.m_eLayoutTextIcon = kA3DPDFLabelOnly;
|
||||
sButtonViewsData.m_eHighlightingMode = kA3DPDFLinkHighlightOutline;
|
||||
mallocAndSetString( (A3DUTF8Char*)asViewNamesList[i].c_str(), sButtonViewsData.m_pcName);
|
||||
mallocAndSetString( (A3DUTF8Char*)asViewLabelsList[i].c_str(), sButtonViewsData.m_pcLabel);
|
||||
mallocAndSetString((A3DUTF8Char*)asViewNamesList[i].c_str(), sButtonViewsData.m_pcTooltip);
|
||||
CHECK_RET(A3DPDFButtonCreate(pDoc, &sButtonViewsData, &ppButtonsViews[i]));
|
||||
|
||||
|
||||
sPos.m_iLeft = 0; // lower left x
|
||||
sPos.m_iRight = sPos.m_iLeft + 100; // upper right x
|
||||
sPos.m_iTop = iPageHeight - (A3DInt32)i*iHeigthButView; // upper right y
|
||||
sPos.m_iBottom = sPos.m_iTop - iHeigthButView; // lower left y
|
||||
CHECK_RET(A3DPDFPageInsertButton(pPage, ppButtonsViews[i], &sPos));
|
||||
|
||||
// set actions on buttons
|
||||
// this is common to all SetView actions
|
||||
A3DPDFAction* pAction = NULL;
|
||||
A3DPDFActionSetViewData sActionData;
|
||||
A3D_INITIALIZE_DATA(A3DPDFActionSetViewData, sActionData);
|
||||
sActionData.m_p3DAnnot = p3DAnnot;
|
||||
sActionData.m_bAnimate = false;
|
||||
//sActionData.m_iViewIndex = (A3DUns32)i;
|
||||
sActionData.m_pcViewName = sButtonViewsData.m_pcName;
|
||||
CHECK_RET(A3DPDFActionSetViewCreate(&sActionData, &pAction));
|
||||
CHECK_RET(A3DPDFButtonAddAction(ppButtonsViews[i], pAction));
|
||||
|
||||
free(sButtonViewsData.m_pcName);
|
||||
free(sButtonViewsData.m_pcLabel);
|
||||
free(sButtonViewsData.m_pcTooltip);
|
||||
}
|
||||
free(ppButtonsViews);
|
||||
}
|
||||
|
||||
// cleaning up -- WARNING: DO NOT CALL THIS BEFORE A3DPDF3DArtworkCreate!
|
||||
CHECK_RET(A3DAsmModelFileDelete(pModelFile));
|
||||
|
||||
// saving the document
|
||||
CHECK_RET(A3DPDFDocumentSaveEx(pDoc, kA3DPDFSaveFull|kA3DPDFSaveOptimized, OUT_FILE));
|
||||
|
||||
CHECK_RET(A3DPDFDocumentClose(pDoc));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return iRet;
|
||||
}
|
||||
|
||||
//######################################################################################################################
|
||||
// Main function
|
||||
#ifdef _MSC_VER
|
||||
int wmain(A3DInt32, A3DUniChar**)
|
||||
#else
|
||||
int main(int, A3DUTF8Char**)
|
||||
#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());
|
||||
|
||||
// launch PDF treatment
|
||||
A3DStatus iRet = BuildPDFDocument();
|
||||
if (iRet != A3D_SUCCESS)
|
||||
return iRet;
|
||||
|
||||
// Check memory allocations
|
||||
return (int)ListLeaks();
|
||||
}
|
||||
Reference in New Issue
Block a user