Punch

// // PunchCreation.cpp // // #include "stdafx.h" #include "Punch.h" #include "PunchCreation.h" #include "Udf.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif #include #include #include #define PUNCH_LIBRARY_PATH "D://CAX_WORK_166//MechDesign//library//" #define PUNCH_UDF_PATH "D://CAX_WORK_166//MechDesign//udf//" #define PROJECT_NAME "TEST" // // Construction/Destruction // CPunchCreation::CPunchCreation() { } CPunchCreation::~CPunchCreation() { } // // 訪問特徵中所有幾何信息 // ProError VisitAllFeatGeomitems(ProGeomitem *p_handle, ProError status, ProAppData app_data) { ProArrayObjectAdd((ProArray*)app_data, -1, 1, p_handle); return PRO_TK_NO_ERROR; } // // 將坐標系特徵轉換為幾何信息 // ProError CsysFeatureToModelitem(ProFeature &csysFeat, ProGeomitem &csysItem) { ProError status; ProGeomitem *csysItems; status = ProArrayAlloc(0, sizeof(ProGeomitem), 1, (ProArray*)&csysItems); status = ProFeatureGeomitemVisit(&csysFeat, PRO_CSYS, VisitAllFeatGeomitems, NULL, &csysItems); if (status != PRO_TK_NO_ERROR) { return PRO_TK_USER_ABORT; } int itemCount; status = ProArraySizeGet(csysItems, &itemCount); if (status != PRO_TK_NO_ERROR || itemCount < 1) { return PRO_TK_USER_ABORT; } csysItem = csysItems[0]; return PRO_TK_NO_ERROR; } // // 獲取組立下所有檔案 // ProError GetAllFeatParts(ProFeature* p_feature, ProError status, ProAppData app_data) { ProFeattype featType; ProFeatStatus featStatus; status = ProFeatureStatusGet(p_feature, &featStatus); if (status != PRO_TK_NO_ERROR || featStatus != PRO_FEAT_ACTIVE) { return PRO_TK_NO_ERROR; } status = ProFeatureTypeGet(p_feature, &featType); if (status != PRO_TK_NO_ERROR || featType != PRO_FEAT_COMPONENT) { return PRO_TK_NO_ERROR; } ProMdl compMdl; status = ProAsmcompMdlGet(p_feature, &compMdl); if (status != PRO_TK_NO_ERROR) { return PRO_TK_NO_ERROR; } ProMdlType mdlType; status = ProMdlTypeGet(compMdl, &mdlType); if (status != PRO_TK_NO_ERROR) { return PRO_TK_NO_ERROR; } status = ProArrayObjectAdd((ProArray*)app_data, PRO_VALUE_UNUSED, 1, &compMdl); if (mdlType == PRO_MDL_ASSEMBLY) { status = ProSolidFeatVisit((ProSolid)compMdl, GetAllFeatParts, NULL, (ProAppData)app_data); } return PRO_TK_NO_ERROR; } // // 訪問檔案中所有尺寸 // ProError VisitAllDims(ProDimension* p_dimension, ProError status, ProAppData app_data) { status = ProArrayObjectAdd((ProArray*)app_data, -1, 1, p_dimension); return PRO_TK_NO_ERROR; } // // 獲取檔案中的所有尺寸 // void GetAllDimensions(ProMdl asmMdl, ProAppData allDims) { ProError status; int nPartCount(0); ProMdl* allParts; status = ProArrayAlloc(0, sizeof(ProMdl), 1, (ProArray*)&allParts); status = ProArrayObjectAdd((ProArray*)&allParts, -1, 1, &asmMdl); status = ProSolidFeatVisit((ProSolid)asmMdl, GetAllFeatParts, NULL, (ProAppData)&allParts); status = ProArraySizeGet((ProArray)allParts, &nPartCount); if (status != PRO_TK_NO_ERROR || nPartCount <= 0) { return; } for (int i = 0;i < nPartCount; ++i) { status = ProSolidDimensionVisit((ProSolid)allParts[i], PRO_B_FALSE, VisitAllDims, NULL, allDims); } } // // 創建Punch沖壓出來的特徵 // ProError CPunchCreation::CreatePunch( const string &punchName, vector &punchDims, ProSelection &punchOwnerSel, ProSelection *&pointSels, ProSelection &zOrientSel, ProSelection &xOrientSel) { ProError status; _punchName = punchName; _punchDims = punchDims; _punchOwnerSel = punchOwnerSel; _pointSels = pointSels; _zOrientSel = zOrientSel; _xOrientSel = xOrientSel; status = DownloadPunchFromLibrary(); if (status != PRO_TK_NO_ERROR) { return status; } status = CreatePunchCsys(); if (status != PRO_TK_NO_ERROR) { return status; } status = InsertPunchUdf(); if (status != PRO_TK_NO_ERROR) { return status; } status = RenamePunch(); status = SavePunch(); return PRO_TK_NO_ERROR; } // // 從標準庫中下載標準沖頭並進行尺寸驅動 // ProError CPunchCreation::DownloadPunchFromLibrary() { ProError status; ProPath punchFullPathW; char punchFullPathS[PRO_PATH_SIZE]; sprintf(punchFullPathS, "%s%s", PUNCH_LIBRARY_PATH, _punchName.c_str()); ProStringToWstring(punchFullPathW, punchFullPathS); status = ProMdlLoad(punchFullPathW, PRO_MDL_UNUSED, PRO_B_FALSE, &_punchMdl); if (status != PRO_TK_NO_ERROR) { return status; } if (_punchDims.size() < 1) { return PRO_TK_NO_ERROR; } int nDimCount = 0; ProDimension* allDims; status = ProArrayAlloc(0, sizeof(ProDimension), 1, (ProArray*)&allDims); GetAllDimensions(_punchMdl, (ProAppData)&allDims); status = ProArraySizeGet((ProArray)allDims, &nDimCount); for (int k = 0;k < nDimCount; ++k) { ProName dimName; char name[32]; status = ProDimensionSymbolGet(&allDims[k], dimName); ProWstringToString(name, dimName); // 驅動PUNCH的尺寸 for (int i = 0; i < _punchDims.size(); ++i) { if (!stricmp(_punchDims[i].Name.c_str(), name)) { ProDimensionValueSet(&allDims[k], _punchDims[i].Value); } } } // 重生檔案 ProSolidRegenerate((ProSolid)_punchMdl, PRO_REGEN_NO_FLAGS); return PRO_TK_NO_ERROR; } // // 根據用戶選擇的點/Z向參考面/X向參考面創建坐標系 // ProError CPunchCreation::CreatePunchCsys() { ProError status; int pointNum = 0; status = ProArraySizeGet(_pointSels, &pointNum); if (status != PRO_TK_NO_ERROR || pointNum < 1) { return PRO_TK_USER_ABORT; } ProAsmcomppath cmppath; status = ProSelectionAsmcomppathGet(_punchOwnerSel, &cmppath); status = ProArrayAlloc(0, sizeof(ProSelection), 1, (ProArray*)&_punchCsyses); for (int i = 0; i < pointNum; ++i) { UdfData udfData; ProSelectionCopy(_punchOwnerSel, &udfData.Owner); // UDF參考 UdfRef udfRef1("origin_point", _pointSels[i]); udfData.AddRef(udfRef1); UdfRef udfRef2("z_orient", _zOrientSel); udfData.AddRef(udfRef2); UdfRef udfRef3("x_orient", _xOrientSel); udfData.AddRef(udfRef3); // UDF其他信息 udfData.Path = PUNCH_UDF_PATH; udfData.Name = "punch_csys.gph"; // 創建UDF ProGroup udf; status = CreateUdf(udfData, &udf); if (status != PRO_TK_NO_ERROR) { continue; } // 獲取坐標系 ProFeature *udfFeats; status = ProGroupFeaturesCollect(&udf, &udfFeats); if (status != PRO_TK_NO_ERROR) { continue; } ProSelection csysSel; ProGeomitem csysItem; CsysFeatureToModelitem(udfFeats[1], csysItem); status = ProSelectionAlloc(&cmppath, &csysItem, &csysSel); if (status != PRO_TK_NO_ERROR) { continue; } status = ProArrayObjectAdd((ProArray*)&_punchCsyses, -1, 1, &csysSel); } return PRO_TK_NO_ERROR; } // // 插入UDF以創建FORM特徵 // ProError CPunchCreation::InsertPunchUdf() { ProError status; int punchNum = 0; status = ProArraySizeGet(_punchCsyses, &punchNum); if (status != PRO_TK_NO_ERROR || punchNum < 1) { return PRO_TK_USER_ABORT; } string punchName(_punchName); int startPos = punchName.find('.'); int len = punchName.size(); punchName.erase(punchName.begin() + startPos, punchName.begin() + len); for (int i = 0; i < punchNum; ++i) { UdfData udfData; ProSelectionCopy(_punchOwnerSel, &udfData.Owner); // UDF參考 UdfRef udfRef1("p_center", _punchCsyses[i]); udfData.AddRef(udfRef1); // UDF其他信息 udfData.Path = PUNCH_UDF_PATH; udfData.Name = punchName; if (udfData.Name.empty()) { continue; } // 創建UDF ProGroup udf; status = CreateUdf(udfData, &udf); if (status != PRO_TK_NO_ERROR) { AfxMessageBox("失敗"); continue; } } return PRO_TK_NO_ERROR; } // // 獲取沖頭對應的序列號 // ProError CPunchCreation::GetPunchSerialNo(string &serialNo) { // 考慮一個專案中不同的檔案會用相同的PUNCH // 考慮TEAMWORK的方面 serialNo = ""; // 暫時從文本文件中獲取序列號 // 獲取當前路徑 ProError status; ProPath currentPathW; char currentPathS[PRO_PATH_SIZE]; status = ProDirectoryCurrentGet(currentPathW); ProWstringToString(currentPathS, currentPathW); string punchSerialNoFile; punchSerialNoFile = currentPathS; punchSerialNoFile += "//"; punchSerialNoFile += PROJECT_NAME; // 讀取文本 vector fileContent; ifstream infile(punchSerialNoFile.c_str()); if (infile) { string textline; char temp[PRO_PATH_SIZE]; while ( getline( infile, textline, '/n' )) { int findPos = textline.find(_punchName + ":"); if (findPos != string::npos) { textline.erase(textline.begin(), textline.begin() + textline.find(':') + 1); serialNo = itoa(atoi(textline.c_str()) + 1, temp, 10); textline = _punchName + ":" + serialNo; } fileContent.push_back(textline); } infile.close(); } // 寫回文本 ofstream outfile(punchSerialNoFile.c_str()); if (!outfile) { serialNo = "1"; return PRO_TK_USER_ABORT; } for (int i = 0; i < fileContent.size(); ++i) { outfile << fileContent[i] << endl; } if (serialNo.empty()) { serialNo = "1"; outfile << _punchName + ":" + serialNo << endl; } outfile.close(); return PRO_TK_NO_ERROR; } // // 對沖頭進行重命名 // ProError CPunchCreation::RenamePunch() { ProError status; ProMdl* allParts; int partNum = 0; status = ProArrayAlloc(0, sizeof(ProMdl), 1, (ProArray*)&allParts); status = ProArrayObjectAdd((ProArray*)&allParts, -1, 1, &_punchMdl); status = ProSolidFeatVisit((ProSolid)_punchMdl, GetAllFeatParts, NULL, (ProAppData)&allParts); status = ProArraySizeGet((ProArray)allParts, &partNum); if (status != PRO_TK_NO_ERROR || partNum <= 0) { return PRO_TK_BAD_INPUTS; } for (int i = 0; i < partNum; ++i) { ProName punchOldNameW; char punchOldNameS[PRO_NAME_SIZE]; ProName punchNewNameW; char punchNewNameS[PRO_NAME_SIZE]; status = ProMdlNameGet(allParts[i], punchOldNameW); if (status != PRO_TK_NO_ERROR) { continue; } ProWstringToString(punchOldNameS, punchOldNameW); string punchSerialNo; GetPunchSerialNo(punchSerialNo); sprintf(punchNewNameS, "%s_%s_%s", PROJECT_NAME, punchOldNameS, punchSerialNo.c_str()); ProStringToWstring(punchNewNameW, punchNewNameS); if (strlen(punchNewNameS) > 31) { AfxMessageBox("PUNCH的新名字太長,無法重命名!", MB_OK|MB_ICONERROR); continue; } status = ProMdlRename(allParts[i], punchNewNameW); if (status != PRO_TK_NO_ERROR) { continue; } } return PRO_TK_NO_ERROR; } // // 保存檔案 // ProError CPunchCreation::SavePunch() { ProError status; ProMdl currentMdl; status = ProMdlCurrentGet(&currentMdl); if (status != PRO_TK_NO_ERROR) { return status; } status = ProMdlSave(currentMdl); status = ProMdlSave(_punchMdl); // 由於內存中的UDF會記錄參考的哪個檔案,所以需要清除內存 // 重新加載UDF status = ProMdlEraseNotDisplayed(); return PRO_TK_NO_ERROR; } //===================================================================================== // // PunchCreation.h: interface for the CPunchCreation class. // // #if !defined(AFX_PUNCHCREATION_H__A7BCD950_FE34_4EB2_9E3B_A4C1CADA4CB5__INCLUDED_) #define AFX_PUNCHCREATION_H__A7BCD950_FE34_4EB2_9E3B_A4C1CADA4CB5__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include #include #include #include #include // 屏蔽STL中嵌套STL導致聲明過長的警告 // #pragma warning(disable:4786)必須先於庫文件的包含之前 #pragma warning(disable:4786) #include #include #include using namespace std; struct PunchDim { string Name; double Value; PunchDim(const string &name, const double value) { Name = name; Value = value; } }; class CPunchCreation { public: CPunchCreation(); virtual ~CPunchCreation(); public: ProError CreatePunch(const string &punchName, vector &punchDims, ProSelection &punchOwnerSel, ProSelection *&pointSels, ProSelection &zOrientSel, ProSelection &xOrientSel); private: ProError DownloadPunchFromLibrary(); ProError CreatePunchCsys(); ProError InsertPunchUdf(); ProError RenamePunch(); ProError SavePunch(); ProError GetPunchSerialNo(string &serialNo); private: ProMdl _punchMdl; ProSelection *_punchCsyses; ProSelection _punchOwnerSel; ProSelection *_pointSels; ProSelection _zOrientSel; ProSelection _xOrientSel; string _punchName; vector _punchDims; }; #endif // !defined(AFX_PUNCHCREATION_H__A7BCD950_FE34_4EB2_9E3B_A4C1CADA4CB5__INCLUDED_)
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。、可私 6信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 、可私信6博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 、可私信6博主看论文后选择购买源代码。
ECharts是一款使用JavaScript编写的开源可视化库,它提供了一种简单的方式来创建丰富的数据可视化图表。热力图(Heat Map)是ECharts中的一种图表类型,用于展示数据的密度分布,而Punch Card(打卡图)是一种特殊的热力图,常用于展示时间序列数据的分布情况,比如记录事件在特定时间发生的频率。 在ECharts中,如果你想要修改热力图来显示Punch Card效果,你需要对热力图的配置项进行一些特定的设置。以下是几个关键步骤: 1. 使用`xAxis`和`yAxis`定义数据的坐标轴,通常用于表示时间点。 2. 在`series`中设置`type`为`heatmap`,这是热力图的类型。 3. 通过`data`属性来提供具体的数据点,数据点通常是一个二维数组,每个内部数组表示一个数据点的x、y坐标和权重。 4. 配置`itemStyle`属性来自定义热力图单元格的样式,例如颜色渐变,以便清晰地显示不同密度的区域。 5. 可以通过`emphasis`属性来设置鼠标悬停时的样式,增强交互性。 示例代码如下: ```javascript option = { xAxis: { type: 'category', data: ['12a', '12p', '1a', '2a', '3a', '4a', '5a', '6a', '7a', '8a', '9a', '10a', '11a', '12p', '1p', '2p', '3p', '4p', '5p', '6p', '7p', '8p', '9p', '10p', '11p'] }, yAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] }, series: [{ name: 'Punch Card', type: 'heatmap', data: [ {value: [24, 0], count: 10}, // ... 更多数据 ], itemStyle: { normal: { color: function (params) { // 根据数据点的权重返回不同的颜色 return colorMap.get(params.value); } } }, emphasis: { itemStyle: { // 鼠标悬停时的样式 borderColor: '#fff', borderWidth: 1 } } }] }; ``` 在这段代码中,`colorMap`是一个预定义的颜色映射函数,用于根据数据点的权重返回不同的颜色,以展示不同的密度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值