ProError CSDMdlSpecAsmConstraintsCheck::AssMdlVisitAction(ProFeature *pFea, ProError status, ProAppData pData)
{
	UNUSED_ALWAYS(status);
	AsmConsVisitData &visitData = *((AsmConsVisitData *)pData);
	ProMdl pMdl = NULL;
	ProAsmcompMdlGet(pFea, &pMdl);
	if (NULL == pMdl)
		return PRO_TK_NO_ERROR;

	ProBoolean bUnConstrained;
	ProAsmcompIsUnderconstrained(pFea, &bUnConstrained);
	if (bUnConstrained == PRO_B_TRUE)
	{
		visitData.nResultType = CHECK_RESULT_INVALID_VALUE;
		visitData.arrErrorIDs.Add(pFea->id);
	}
	else
	{
		ProAsmcompconstraint* pArrCons = NULL;
		if (ProAsmcompConstraintsGet(pFea, &pArrCons) == PRO_TK_E_NOT_FOUND)
		{
			visitData.nResultType = CHECK_RESULT_INVALID_VALUE;
			visitData.arrErrorIDs.Add(pFea->id);
		}
		else
		{
			ProArrayFree((ProArray*)&pArrCons);
		}
	}

	return PRO_TK_NO_ERROR;
}
ProError CSDMdlSpecAsmRefCheck::AsmMdlVisitAction(ProFeature *pFea, ProError status, ProAppData pData)
{
	UNUSED_ALWAYS(status);
	AsmRefVisitData &visitData = *((AsmRefVisitData *)pData);
	
	ProAsmcompconstraint* pArrCons = NULL;
	if (ProAsmcompConstraintsGet(pFea, &pArrCons) == PRO_TK_NO_ERROR)
	{
		int nCount;
		ProArraySizeGet(pArrCons, &nCount);
		for (int i=0; i<nCount; i++)
		{
			ProAsmcompConstrType type;
			ProAsmcompconstraintTypeGet(pArrCons[i], &type);
			if (type != PRO_ASM_CSYS)
			{
				ProMdl pMdl = NULL;
				ProAsmcompMdlGet(pFea, &pMdl);
				ProName name;
				ProMdlNameGet(pMdl, name);
				visitData.nResultType = CHECK_RESULT_INVALID_VALUE;
				visitData.arrMdlNames.Add(CString(name));
				visitData.arrErrorIDs.Add(pFea->id);
				break;
			}
		}
		ProArrayFree((ProArray*)&pArrCons);
	}
	else
	{
		ProMdl pMdl = NULL;
		ProAsmcompMdlGet(pFea, &pMdl);
		ProName name;
		ProMdlNameGet(pMdl, name);
		visitData.nResultType = CHECK_RESULT_INVALID_VALUE;
		visitData.arrMdlNames.Add(CString(name));
		visitData.arrErrorIDs.Add(pFea->id);
	}

	return PRO_TK_NO_ERROR;
}
ProError CSDMdlSpecAsmImplicitCheck::AsmMdlVisitAction(ProFeature *pFea, ProError status, ProAppData pData)
{
	UNUSED_ALWAYS(status);
	AsmImplicitVisitData &visitData = *((AsmImplicitVisitData *)pData);

	ProFeatStatus featStatus;
	ProFeatureStatusGet(pFea, &featStatus);
	if (featStatus == PRO_FEAT_SUPPRESSED)
	{
		ProMdl pMdl = NULL;
		ProAsmcompMdlGet(pFea, &pMdl);
		ProName name;
		ProMdlNameGet(pMdl, name);
		visitData.nResultType = CHECK_RESULT_ERROR_VALUE;
		visitData.arrMdlNames.Add(CString(name));
		visitData.arrErrorIDs.Add(pFea->id);
	}

	return PRO_TK_NO_ERROR;
}
Beispiel #4
0
// 生成包覆体
void OnCreateBodyActFn()
{
	/*if (!QuickCheckValidLicense(SMART_PROFESSIONAL))
		return;*/

	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	DestroyAllDialog();
	CancelSelectDialog();
	Sleep(50);

	// 检查当前模型环境
	ProMdl pMdl = GetCurrentMdl();
	if (pMdl == NULL)
	{
		MessageBox(NULL, L"当前环境未发现模型!", L"提示", MB_OK|MB_ICONWARNING);
		return;
	}

	ProMdlType typeMdl;
	ProMdlTypeGet(pMdl, &typeMdl);
	if (typeMdl != PRO_MDL_ASSEMBLY)
	{
		MessageBox(NULL, L"该功能仅在装配环境下有效!", L"提示", MB_OK|MB_ICONWARNING);
		return;
	}

	//ExportElemTreeXML();

	// 选择一个面组
	vector<ProSelection> arrSelQlt;
	ShowMessageTip(L"Tips.选择要加厚的包覆面...");
	if (SelectObject(arrSelQlt, "dtmqlt"))
	{
		// 输入整体加厚值
		double dThickValue;
		ShowMessageTip(L"指定厚度值,不能为0,负值表示向内加厚:");
		if (ProMessageDoubleRead(NULL, &dThickValue) == PRO_TK_NO_ERROR)
		{
			// 创建发布几何
			int nPubFeatID = CreatePublishGeom(pMdl, arrSelQlt[0]);

			ProName nameAsm;
			ProMdlNameGet(pMdl, nameAsm);
			CString strNamePart = nameAsm;
			ProName namePart;
			for (int i=101; ;i++)
			{
				CString strTemp;
				strTemp.Format(L"%s_%d", nameAsm, i);
				wcsncpy_s(namePart, PRO_NAME_SIZE, strTemp, _TRUNCATE);
				ProMdl pMdlTemp;
				if (ProMdlInit(namePart, PRO_MDL_PART, &pMdlTemp) == PRO_TK_E_NOT_FOUND)
					break;
			}

			// 新建一个零件
			ProAsmcomp compPart;
			ProAsmcompCreateCopy(ProMdlToAssembly(pMdl), namePart, PRO_MDL_PART, NULL, PRO_B_FALSE, &compPart);
			//ProSolidRegenerate(pMdl);
			ProMdl pMdlPart;
			ProAsmcompMdlGet(&compPart, &pMdlPart);

			ProModelitem itemAsm;
			ProMdlToModelitem(pMdl, &itemAsm);
			ProSelection selAsm;
			ProSelectionAlloc(NULL, &itemAsm, &selAsm);

			ProFeature featPub;
			featPub.id = nPubFeatID;
			featPub.owner = pMdl;
			featPub.type = PRO_FEATURE;
			ProSelection selPubFeat;
			ProSelectionAlloc(NULL, &featPub, &selPubFeat);

			// 创建复制几何
			ProModelitem itemCopyQuilt;
			CreateCopyGeom(pMdlPart, selAsm, selPubFeat, itemCopyQuilt);
			ProSelection selCopyQuilt;
			ProSelectionAlloc(NULL, &itemCopyQuilt, &selCopyQuilt);

			// 弹出提示:是否要对单个面设置厚度
			if (MessageBox(NULL, L"是否要对单个面设置厚度", L"提示", MB_YESNO|MB_ICONQUESTION) == IDYES)
			{
				ProMdlDisplay(pMdlPart);
				int nWndIDPart;
				ProMdlWindowGet(pMdlPart, &nWndIDPart);
				ProWindowActivate(nWndIDPart);

				// 弹出对话框
				if (g_pDlgThick != NULL)
				{
					if (g_pDlgThick->GetSafeHwnd() != NULL)
						g_pDlgThick->DestroyWindow();

					SAFE_DELETE_POINTER(g_pDlgThick);
				}
				g_pDlgThick = new CDlgSetThick();
				g_pDlgThick->InitSurfData(pMdl, selCopyQuilt, dThickValue);
				g_pDlgThick->Create(IDD_DLG_SETTHICK);
				g_pDlgThick->ShowWindow(SW_SHOW);
			}
			else
			{
				ThickQuilt(pMdlPart, selCopyQuilt, dThickValue);
			}
		}
	}

	InvalidateDrawing();
	ProMessageClear();
}
Beispiel #5
0
ProError visit_component_action( ProFeature* in_feature, ProError in_status, Appdata in_app_data ) {
	
	

	ProError rs;
	ProMdl model;
	switch( rs = ProAsmcompMdlGet(in_feature, &model) ) {
	case PRO_TK_NO_ERROR: break;
	case PRO_TK_BAD_INPUTS:
		isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The specified feature is not a valid component feature.";
		return PRO_TK_GENERAL_ERROR;
	case PRO_TK_E_NOT_FOUND:
		isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "Assembly component model is not a solid or is not in memory.";
		return PRO_TK_GENERAL_ERROR;
	default:
		isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "unexpected error: " << rs;
		return PRO_TK_GENERAL_ERROR;
	}
	ProSolid solid = static_cast<ProSolid>(model);

	ProMdlType component_type;

	switch( rs = ProMdlTypeGet(model, &component_type) ) {
	case PRO_TK_NO_ERROR: break;
	case PRO_TK_BAD_INPUTS:
		isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The input argument is invalid.";
		return PRO_TK_GENERAL_ERROR;
	case PRO_TK_GENERAL_ERROR:
		isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The information could not be obtained.";
		return PRO_TK_GENERAL_ERROR;
	default:
		isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "unexpected error: " << rs;
		return PRO_TK_GENERAL_ERROR;
	}

	ProAsmcomp component = static_cast<ProAsmcomp>(*in_feature);

	Appdata app_data; 
	app_data.level = in_app_data.level+1;
	app_data.path.owner = static_cast<ProSolid>(component.owner);
	app_data.path.owner = in_app_data.path.owner;
	app_data.path.table_num = in_app_data.path.table_num + 1;
	for( int ix=0; ix < app_data.path.table_num; ++ix ) {
		app_data.path.comp_id_table[ix] = in_app_data.path.comp_id_table[ix];
	}
	app_data.path.comp_id_table[app_data.path.table_num] = in_feature->id;

    switch( component_type ) {
	case PRO_ASSEMBLY:
		{
		ProAppData* app_data_vp = reinterpret_cast<ProAppData*>(&app_data);
		switch( rs = ProSolidFeatVisit(solid, visit_action, filter_action, app_data_vp) ) {
		case PRO_TK_NO_ERROR: break;
		case PRO_TK_E_NOT_FOUND:
			isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "filter produced no component features.";
			break;
		default:
			isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "Any other value is the value returned "
				<< " by the action function (visiting stopped)." << rs;
		}
		}
		break;
	case PRO_PART:
		{
			ProMdl self;
			switch( rs = ProModelitemMdlGet(in_feature, &self) ) {
			case PRO_TK_NO_ERROR: break;
			case PRO_TK_BAD_INPUTS:
				isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "feature has no model. " << in_feature->id;
			}
			char assembly_name[PRO_NAME_SIZE];
			{
				ProName wname;
				switch( rs = ProMdlNameGet(self, wname) ) {
				case PRO_TK_NO_ERROR: break;
				case PRO_TK_BAD_INPUTS:
					isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The input argument is invalid. " << in_feature->id;
					throw std::runtime_error("selector feature name failed");
				case PRO_TK_E_NOT_FOUND:
					isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The specified item does not have a name.  ";
					break;
				default:
					isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "ill specified error:  " << rs;
					throw std::runtime_error("selector feature name failed");
				}
				ProWstringToString(assembly_name, wname);
			}
			char model_name[PRO_PATH_SIZE];
			{
				wchar_t* wname;
				ProBoolean is_modifiable;
				switch( rs = ProMdlCommonnameGet(self, &wname, &is_modifiable) ) {
				case PRO_TK_NO_ERROR: break;
				case PRO_TK_BAD_INPUTS:
					isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The input argument is invalid. " << in_feature->id;
					throw std::runtime_error("selector feature name failed");
				case PRO_TK_E_NOT_FOUND:
					isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The specified item does not have a name.  ";
					break;
				default:
					isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "ill specified error:  " << rs;
					throw std::runtime_error("selector feature name failed");
				}
				ProWstringToString(model_name, wname);
				ProWstringFree(wname);
			}
			char item_name[PRO_NAME_SIZE];
			{
				ProName wname;
				switch( rs = ProModelitemNameGet(in_feature, wname) ) {
				case PRO_TK_NO_ERROR: break;
				case PRO_TK_BAD_INPUTS:
					isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The input argument is invalid. " << in_feature->id;
					throw std::runtime_error("selector feature name failed");
				case PRO_TK_E_NOT_FOUND:
					isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The specified item does not have a name.  ";
					break;
				default:
					isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "ill specified error:  " << rs;
					throw std::runtime_error("selector feature name failed");
				}
				ProWstringToString(item_name, wname);
			}

			// If you request the transformation from the member to the
			// assembly, this is PRO_B_TRUE. Otherwise, this is PRO_B_FALSE.
			ProBoolean   bottom_up = PRO_B_TRUE;
			ProMatrix    transformation;
			// retrieve the transformation matrix, given the component path.
			switch( rs = ProAsmcomppathTrfGet(&app_data.path, bottom_up, transformation) ) {
			case PRO_TK_NO_ERROR: break;
			case PRO_TK_BAD_INPUTS:
				isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "transform get, the input argument is invalid: " 
					<< app_data.path.comp_id_table;
				return PRO_TK_GENERAL_ERROR;
			case PRO_TK_GENERAL_ERROR:
				isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "The specified component path was wrong, or contained missing members.";
				return PRO_TK_GENERAL_ERROR;
			default:
				isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "unexpected error: " << rs;
				return PRO_TK_GENERAL_ERROR;
			}

			isis_LOG(lg, isis_FILE, isis_INFO) << "transformation: " << assembly_name 
				<< " : " << model_name << " : " << item_name;
			isis_LOG(lg, isis_FILE, isis_INFO) << "[";
			for( int ix=0; ix < 4; ++ix ) {
				isis_LOG(lg, isis_FILE, isis_INFO) << "\n\t[";
				for( int jx=0; jx < 4; ++jx ) {
					isis_LOG(lg, isis_FILE, isis_INFO) << '\t' << transformation[ix][jx];
				}
				isis_LOG(lg, isis_FILE, isis_INFO) << "]";
			}
			isis_LOG(lg, isis_FILE, isis_INFO) << "]\n";
			return PRO_TK_NO_ERROR;
		} 
	default:
		{
		isis_LOG(lg, isis_CONSOLE_FILE, isis_ERROR) << "unknown-component-type: " << component_type;
		}
	}
	return PRO_TK_NO_ERROR;
}
/*---------------------------------------------------------------------*\
    Populate appdata
	Example Code:	C:\Program Files\PTC\Creo 2.0\Common Files\M070\protoolkit\protk_appls\pt_userguide\ptu_asm\UgAsmCompVisit.c
\*---------------------------------------------------------------------*/
ProError user_action( ProFeature *feature, ProError status, ProAppData appdata)
{

    ProMdl mdl;
    char name[PRO_NAME_SIZE];
    char type[PRO_TYPE_SIZE];
    // wchar_t wname[PRO_NAME_SIZE];
    UserAppdata *appd;
    ProMdldata mdldata;

    appd = (UserAppdata *)appdata;

    try
    {
        isis::isis_ProAsmcompMdlGet(feature , &mdl);
    }
    catch(...)
    {
        log4cpp::Category& logcat_fileonly = log4cpp::Category::getInstance(LOGCAT_LOGFILEONLY);
        // Call again to get the error code
        ProError  proError_temp = ProAsmcompMdlGet(feature , &mdl);
        // PRO_TK_E_NOT_FOUND  - Assembly component model is not a solid or is not in memory.
        //						 It would not be in memory because it was not pulled in as a simplified rep
        if ( proError_temp == PRO_TK_E_NOT_FOUND )
        {
            //std::cout << std::endl << std::endl << "@@@@@@@@@@@@@@@@@@@@@ isis_ProAsmcompMdlGet @@@@@@@@@@@@@@@@@@@@@@@@@@@@";
            logcat_fileonly.errorStream() << "INFORMATION: isis_ProAsmcompMdlGet(feature , &mdl), Could not retrieve sub-part/assembly, probably because the simplified rep did not contain the part/assembly";
            logcat_fileonly.errorStream() << "isis_ProAsmcompMdlGet(feature , &mdl), feature: " << feature;
            logcat_fileonly.errorStream() << "                                       id       " << feature->id;
            logcat_fileonly.errorStream() << "                                       owner    " << feature->owner;
            logcat_fileonly.errorStream() <<  "                                      type     " << feature->type;
            return(PRO_TK_CONTINUE);
        }
        else
        {
            logcat_fileonly.errorStream() << "isis_ProAsmcompMdlGet(feature , &mdl), feature: " << feature;
            logcat_fileonly.errorStream() << "                                        id      " << feature->id;
            logcat_fileonly.errorStream() << "                                        owner   " << feature->owner;
            logcat_fileonly.errorStream() <<  "                                       type    " << feature->type;
            throw;
        }
    }

    isis::isis_ProMdlDataGet(mdl, &mdldata);
    ProWstringToString(name,mdldata.name);
    ProWstringToString(type,mdldata.type);

    CreoModelAssemblyAttributes modelAttributes;
    if ( strncmp(type,"ASM",3) == 0 )
        modelAttributes.modelType = PRO_MDL_ASSEMBLY;
    else
        modelAttributes.modelType = PRO_MDL_PART;

    modelAttributes.modelname = mdldata.name;
    modelAttributes.p_solid_handle = (ProSolid)mdl;
    modelAttributes.proAsmcomp = *feature;

    if ( appd->assemblyHierarchy.includeTheEntireHierarchy && strncmp(type,"ASM",3) == 0)
    {
        UserAppdata appdata_temp(modelAttributes);
        appdata_temp.assemblyHierarchy.includeTheEntireHierarchy = true;
        isis::isis_ProSolidFeatVisit((ProSolid)mdl, user_action, UserAsmCompFilter, &appdata_temp);
    }

    appd->assemblyHierarchy.children.push_back(modelAttributes);

    if (feature != NULL) return(PRO_TK_NO_ERROR);
    return(PRO_TK_CONTINUE);
}