Sample Code:Add simple pmi to model
This sample code shows how to add a simple PMI to a loaded model.
This is based on CreatePRCCubes sample in HOOPS Exchange package.
In this sample,
Load sample step model \samples\data\step\Flange287.stp
Create simple measurement markup (no views or linked items)
Add it to the top product occurrence
Export the model
CreateMarkups.cpp
/***********************************************************************************************************************
*
* Copyright (c) 2010 - 2024 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 CreateMartkups.cpp
* This file is containing the function allowing to create markups.
*
* Markups creation exemple
* Create tessellated markups with linked items.
* Different style of markups can be created (normal or face to screen).
* Different links to the PRC entities can be created as well.
*
* These exemples are using the tessellation wrapper: HXWMarkupTessellation.cpp
*
*
***********************************************************************************************************************/
#include "CreateMarkups.h"
#include "../tessellation_wrapper/HXWMarkupTessellation.h"
#include <vector>
//######################################################################################################################
//
// Tessellation Helper
//
//######################################################################################################################
// Create a leader and an arrow
static void stCreateLeaderTess(HXWMarkupTessellation* sMarkupLeaderTessellation)
{
// Leader
A3DDouble* pdLeaderPolylineData = (A3DDouble*) malloc(12 * sizeof(A3DDouble));
pdLeaderPolylineData[0] = 2219.169677;
pdLeaderPolylineData[1] = -5136.332031;
pdLeaderPolylineData[2] = -3080.448730;
pdLeaderPolylineData[3] = 2194.045898;
pdLeaderPolylineData[4] = -5148.460449;
pdLeaderPolylineData[5] = -3033.064453;
pdLeaderPolylineData[6] = 2128.364746;
pdLeaderPolylineData[7] = -5180.613281;
pdLeaderPolylineData[8] = -3076.056152;
pdLeaderPolylineData[9] = 2152.443359;
pdLeaderPolylineData[10] = -5168.771972;
pdLeaderPolylineData[11] = -3123.842529;
sMarkupLeaderTessellation->set_color(YELLOW);
sMarkupLeaderTessellation->add_polyline(pdLeaderPolylineData, 4);
free(pdLeaderPolylineData);
// Arrow
A3DDouble* pdTriangle = (A3DDouble*) malloc(9 * sizeof(A3DDouble));
pdTriangle[0] = 2194.045898;
pdTriangle[1] = -5148.460449;
pdTriangle[2] = -3033.064453;
pdTriangle[3] = 2190.743408;
pdTriangle[4] = -5150.084961;
pdTriangle[5] = -3033.093506;
pdTriangle[6] = 2192.412354;
pdTriangle[7] = -5149.251953;
pdTriangle[8] = -3036.266357;
sMarkupLeaderTessellation->set_color(YELLOW);
sMarkupLeaderTessellation->add_triangle(pdTriangle);
free(pdTriangle);
// Arrow
A3DDouble* pdTriangle2 = (A3DDouble*)malloc(9 * sizeof(A3DDouble));
pdTriangle2[0] = 2129.998291;
pdTriangle2[1] = -5179.821777;
pdTriangle2[2] = -3072.854248;
pdTriangle2[3] = 2128.364746;
pdTriangle2[4] = -5180.613281;
pdTriangle2[5] = -3076.056152;
pdTriangle2[6] = 2131.667236;
pdTriangle2[7] = -5178.988770;
pdTriangle2[8] = -3076.027100;
sMarkupLeaderTessellation->set_color(YELLOW);
sMarkupLeaderTessellation->add_triangle(pdTriangle2);
free(pdTriangle2);
}
//######################################################################################################################
// Create a Text
static void stCreateText(HXWMarkupTessellation* pMarkupTessellation)
{
// Text
HXWVector3d position(2147.912598,-5171.044434 ,-3063.261230);
HXWVector3d normal(0.441433072, -0.897288024, -0.00333747733);
HXWVector3d x_direction(2164.078369- 2147.912598, -5163.129883 + 5171.044434, -3052.679688+ 3063.261230);
pMarkupTessellation->begin_matrix(position.m_data, normal.m_data, x_direction.m_data);
pMarkupTessellation->set_textfont("Courier New", 8, kA3DFontBold);
pMarkupTessellation->set_color(BLUE);
double dTextWidth = 2;
double dTextHeight = 0.3;
pMarkupTessellation->add_text("85.95 mm", dTextWidth, dTextHeight);
pMarkupTessellation->end_matrix();
}
//######################################################################################################################
//
// Leader and text
//
//######################################################################################################################
// Create a Text
static A3DStatus stCreateText(A3DTessMarkup** ppTessMarkup)
{
A3DStatus iRet = A3D_SUCCESS;
// label
HXWMarkupTessellation sMarkupTessellation;
stCreateText(&sMarkupTessellation);
*ppTessMarkup = sMarkupTessellation.GetEntity();
return iRet;
}
//######################################################################################################################
// Create a Leader Tessellation
static A3DStatus stCreateLeader(A3DMkpLeader** ppMkpLeader)
{
A3DStatus iRet = A3D_SUCCESS;
// leader
HXWMarkupTessellation sMarkupLeaderTessellation;
stCreateLeaderTess(&sMarkupLeaderTessellation);
A3DMkpLeaderData sMkpLeaderData;
A3D_INITIALIZE_DATA(A3DMkpLeaderData, sMkpLeaderData);
A3DTessMarkup* pLeaderTessMarkup = sMarkupLeaderTessellation.GetEntity();
sMkpLeaderData.m_pTessellation = pLeaderTessMarkup;
CHECK_RET(A3DMkpLeaderCreate(&sMkpLeaderData, ppMkpLeader));
return iRet;
}
//######################################################################################################################
static A3DStatus stCreateMkpMarkup(A3DMkpMarkup** ppMarkup,
A3DTessMarkup* pTessMarkup,
A3DUns32 uiMkpLeaderSize,
A3DMkpLeader** ppMkpLeader,
A3DUns32 uiMarkupLinkedItemSize,
A3DMiscMarkupLinkedItem** ppMarkupLinkedItem)
{
A3DStatus iRet = A3D_SUCCESS;
A3DMkpMarkupData sMarkupData;
A3D_INITIALIZE_DATA(A3DMkpMarkupData, sMarkupData);
sMarkupData.m_eType = kA3DMarkupTypeDimension;
sMarkupData.m_eSubType = kA3DMarkupSubTypeUnknown;
sMarkupData.m_uiLeadersSize = uiMkpLeaderSize;
sMarkupData.m_ppLeaders = ppMkpLeader;
sMarkupData.m_uiLinkedItemsSize = uiMarkupLinkedItemSize;
sMarkupData.m_ppLinkedItems = ppMarkupLinkedItem;
sMarkupData.m_pTessellation = pTessMarkup;
CHECK_RET(A3DMkpMarkupCreate(&sMarkupData, ppMarkup));
return iRet;
}
//######################################################################################################################
//
// Markups creation
//
//######################################################################################################################
// Tesselated Markup creation
//######################################################################################################################
// Tesselated Markup creation
A3DStatus createMarkup(A3DMkpAnnotationItem** ppOutAnnotItem)
{
A3DStatus iRet = A3D_SUCCESS;
A3DMkpLeader* pMkpLeader = 0;
A3DUns32 uiMkpLeaderSize = 0;
CHECK_RET(stCreateLeader(&pMkpLeader));
uiMkpLeaderSize = 1;
A3DTessMarkup* pTessMarkup = 0;
CHECK_RET(stCreateText(&pTessMarkup));
// -----------------------------------------------------------
// create a Markup from the MarkupTessData
A3DMkpMarkup* pMarkup = 0;
CHECK_RET(stCreateMkpMarkup(&pMarkup, pTessMarkup, uiMkpLeaderSize, &pMkpLeader, 0, nullptr));
// -----------------------------------------------------------
// Annotation item creation
A3DMkpAnnotationItemData sAnnotItemData;
A3D_INITIALIZE_DATA(A3DMkpAnnotationItemData, sAnnotItemData);
sAnnotItemData.m_pMarkup = pMarkup;
CHECK_RET(A3DMkpAnnotationItemCreate(&sAnnotItemData, ppOutAnnotItem));
return iRet;
}
Full archive of sample code:
CreatePRCCubes_add_markup.zip (7.1 KB)
For more information or to contribute to the discussion, check out our forum post.