⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menu.cpp

📁 能在MDT5/6环境下对已经存在地曲面进行全部和局部区域展开
💻 CPP
字号:
//
// (C) Copyright 1998-1999 by Autodesk, Inc. 
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted, 
// provided that the above copyright notice appears in all copies and 
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting 
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. 
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC. 
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to 
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
#include "StdAfx.h"
#include "StdArx.h"
#include <afx.h>

#if defined(_DEBUG) && !defined(_DEBUG_AUTOCAD)
#define _DEBUG_WAS_DEFINED
#undef _DEBUG
#endif

#include <afxdisp.h>        // MFC OLE automation classes

#ifdef _DEBUG_WAS_DEFINED
#define _DEBUG
#undef _DEBUG_WAS_DEFINED
#endif

#include "adslib.h"
#include "acad15.h"
#include "rxmfcapi.h"

#include "acad15_i.c"
#include <COMDEF.H>

BSTR bMenuName=L"曲面展开(S)";
BSTR bMenuName1=L"曲面展开(&S)";
BSTR bToolbarName=L"曲面展开";

bool getApplication(LPDISPATCH * pVal)
{
	LPDISPATCH pDispatch = acedGetAcadWinApp()->GetIDispatch(TRUE);
	if (pDispatch == NULL)
		return false;
	*pVal = pDispatch;
	return true;
}


bool getAcadMenuGroup(IAcadMenuGroup  **pVal)
{

	IAcadApplication *acadApp = NULL;
	LPDISPATCH  pDisp = NULL;

	if (!getApplication(&pDisp))
		return false;

	HRESULT hr = S_OK;
	hr = pDisp->QueryInterface(IID_IAcadApplication, (LPVOID*)&acadApp);
	if (FAILED(hr))
		return false;

	LPDISPATCH  pTempDisp = NULL;
	IAcadMenuGroups *mnuGrps = NULL;
	long cnt = 0;
	
	//get the menu groups
	hr = acadApp->get_MenuGroups(&mnuGrps);
	if (FAILED(hr))
	{
		acadApp->Release();
		return false;
	}
	mnuGrps->get_Count(&cnt);
	

	//get AutoCAD menu group. say it is index 0.
	IAcadMenuGroup *mnuGrp = NULL;

	VARIANT  vtName;
	vtName.vt = VT_I4;
	BSTR  grpName;
	bool found = false ;
	for (long i=0; i < cnt; i++)
	{
		vtName.lVal = i;
		hr = mnuGrps->Item(vtName, &mnuGrp);
		if (FAILED(hr))
			return false;

		
		hr  = mnuGrp->get_Name(&grpName);
		CString cgrpName(grpName);
		if (cgrpName.CompareNoCase("Acad")==0 || cgrpName.CompareNoCase("AMDTPP")==0) 
		{
			found = true;
			*pVal = mnuGrp;
			break;
		}
	}

	acadApp->Release();
	return found;
}


void CreateToolbars()
{
	IAcadMenuGroup *mnuGrp = NULL;
	if (!getAcadMenuGroup(&mnuGrp))
		return ;
	//now get all the popup menus 
	IAcadToolbars  *tlbrs = NULL;
	HRESULT hr = S_OK;
	hr = mnuGrp->get_Toolbars(&tlbrs);
	mnuGrp->Release();
	//let us create toolbars for polysamp
	IAcadToolbar  *tlbr = NULL;
	hr = tlbrs->Add(bToolbarName, &tlbr);
	if FAILED(hr)
		return;
	tlbrs->Release();
	//now add toolbar buttons
	IAcadToolbarItem  *button1 = NULL;
	VARIANT index;
	index.vt = VT_I4;
	index.lVal = 100l;

	VARIANT vtFalse;
	vtFalse.vt = VT_BOOL;
	vtFalse.boolVal = VARIANT_FALSE;

	_bstr_t preName;
	_bstr_t f1,f2;


	// 图标文件放在应用程序目录下的SurfD目录下
	preName = "SurfD\\";
	hr = tlbr->AddToolbarButton(index, L"曲面展开简单", 
		L"提供简单的曲面展开功能", L"_SURFD ", vtFalse, &button1);
	f1 = preName + "SurfDS.bmp"; 
	f2 = preName + "SurfDL.bmp";
	hr = button1->SetBitmaps(f1,f2);
	button1->Release();

	hr = tlbr->AddToolbarButton(index, L"曲面展开高级", 
		L"提供更高级的曲面展开功能", L"_SURFDA ", vtFalse, &button1);
	f1 = preName + "SurfDAS.bmp"; 
	f2 = preName + "SurfDAL.bmp";
	hr = button1->SetBitmaps(f1,f2);
	button1->Release();

	hr = tlbr->AddToolbarButton(index, L"曲面上点展开", 
		L"将原曲面上的点展开到展开平面上", L"_P2D ", vtFalse, &button1);
	f1 = preName + "P2DS.bmp"; 
	f2 = preName + "P2DL.bmp";
	hr = button1->SetBitmaps(f1,f2);
	button1->Release();

	hr = tlbr->AddToolbarButton(index, L"曲面上线展开", 
		L"将原曲面上的线展开到展开平面上", L"_C2D ", vtFalse, &button1);
	f1 = preName + "C2DS.bmp"; 
	f2 = preName + "C2DL.bmp";
	hr = button1->SetBitmaps(f1,f2);
	button1->Release();

	hr = tlbr->AddToolbarButton(index, L"平面上点映射", 
		L"将展开平面上的点映射到原曲面上", L"_P2O ", vtFalse, &button1);
	f1 = preName + "P2OS.bmp"; 
	f2 = preName + "P2OL.bmp";
	hr = button1->SetBitmaps(f1,f2);
	button1->Release();
	
	hr = tlbr->AddToolbarButton(index, L"平面上线映射", 
		L"将展开平面上的线映射到原曲面上", L"_C2O ", vtFalse, &button1);
	f1 = preName + "C2OS.bmp"; 
	f2 = preName + "C2OL.bmp";
	hr = button1->SetBitmaps(f1,f2);
	button1->Release();

	// 工具栏的浮动位置
	tlbr->Dock(acToolbarFloating);
	tlbr->Release();

	getAcadMenuGroup(&mnuGrp);
	mnuGrp->Save(acMenuFileCompiled);
	mnuGrp->Release();

	return;
	
}

void CreateMenus()
{	
	IAcadMenuGroup *mnuGrp = NULL;
	if (!getAcadMenuGroup(&mnuGrp))
		return ;

	//now get all the popup menus 
	IAcadPopupMenus  *mnus = NULL;
	HRESULT hr = S_OK;
	hr = mnuGrp->get_Menus(&mnus);
	long cnt = 0l;
	hr = mnus->get_Count(&cnt);
	mnuGrp->Release();

	VARIANT vtName;
	// insert Polysamp Pop Menu 
	vtName.vt = VT_I4;
	vtName.lVal = cnt;
	IAcadPopupMenu *polyMnu = NULL;
	mnus->Add(bMenuName1,&polyMnu);
	mnus->InsertMenuInMenuBar(bMenuName1,vtName);
	mnus->Release();

	VARIANT  vtIndex;
	vtIndex.vt = VT_I4;

	IAcadPopupMenuItem *polycmds = NULL;

	vtIndex.lVal = 0;
	hr = polyMnu->AddMenuItem(vtIndex, L"曲面展开", L"_SURFD ", &polycmds);
	polycmds->put_HelpString(L"提供简单的曲面展开功能");
	vtIndex.lVal++;
	hr = polyMnu->AddMenuItem(vtIndex, L"高级曲面展开", L"_SURFDA ", &polycmds);
	polycmds->put_HelpString(L"提供更高级的曲面展开功能");
	vtIndex.lVal++;
	hr = polyMnu->AddMenuItem(vtIndex, L"曲面上点展开", L"_P2D ", &polycmds);
	polycmds->put_HelpString(L"将原曲面上的线展开到展开平面上");
	vtIndex.lVal++;
	hr = polyMnu->AddMenuItem(vtIndex, L"曲面上线展开", L"_C2D ", &polycmds);
	polycmds->put_HelpString(L"将原曲面上的线展开到展开平面上");
	vtIndex.lVal++;
	hr = polyMnu->AddMenuItem(vtIndex, L"平面上点映射", L"_P2O ", &polycmds);
	polycmds->put_HelpString(L"将展开平面上的点映射到原曲面上");
	vtIndex.lVal++;
	hr = polyMnu->AddMenuItem(vtIndex, L"平面上线映射", L"_C2O ", &polycmds);
	polycmds->put_HelpString(L"将展开平面上的线映射到原曲面上");

	polyMnu->Release();
	
	getAcadMenuGroup(&mnuGrp);
	mnuGrp->Save(acMenuFileCompiled);
	mnuGrp->Release();
	
	return;
}


void CleanUpMenus()
{
	IAcadMenuGroup *mnuGrp = NULL;
	if (!getAcadMenuGroup(&mnuGrp))
		return ;

	//now get all the popup menus 
	IAcadPopupMenus  *mnus = NULL;
	HRESULT hr = S_OK;
	hr = mnuGrp->get_Menus(&mnus);
	long cnt = 0l;
	hr = mnus->get_Count(&cnt);
	mnuGrp->Release();

	//now get Polysamp popup menu
	IAcadPopupMenu *PolyMenu = NULL;
	BSTR   tempName;
	VARIANT vtName;
	bool found = false;
	for (long i=0; i < cnt; i++)
	{
		vtName.vt = VT_I4;
		vtName.lVal = i;
		hr = mnus->Item(vtName,&PolyMenu);
		if (FAILED(hr))
			return ;

		hr = PolyMenu->get_NameNoMnemonic(&tempName);
		CString mnuName(tempName);
		SysFreeString(tempName);
		if(mnuName.CompareNoCase(CString(bMenuName))==0)
		{
			found = true;
			break;
		}
	}
	if (found) {
		PolyMenu->RemoveFromMenuBar();
	}
	PolyMenu->Release();
	mnus->Release();

	getAcadMenuGroup(&mnuGrp);
	mnuGrp->Save(acMenuFileCompiled);
	mnuGrp->Release();

	return;
}



void CleanUpToolbars()
{
	IAcadMenuGroup *mnuGrp = NULL;
	if (!getAcadMenuGroup(&mnuGrp))
		return ;
	
	
	IAcadToolbars  *tlbrs = NULL;
	HRESULT hr = S_OK;
	
	hr = mnuGrp->get_Toolbars(&tlbrs);
	mnuGrp->Release();
	
	long cnt = 0;
	hr = tlbrs->get_Count(&cnt);
	
	IAcadToolbar *polyTlbr = NULL;
	BSTR  tempName;
	
	VARIANT vtName;
	for ( long i=0; i < cnt; i++)
	{
		vtName.vt = VT_I4;
		vtName.lVal = i;
		hr = tlbrs->Item(vtName, &polyTlbr);
		hr = polyTlbr->get_Name(&tempName);
		CString tlbrName(tempName);
		SysFreeString(tempName);
		if(tlbrName.CompareNoCase(CString(bToolbarName))==0)
		{
			
			polyTlbr->Delete();
			//can not call following because delete has already removed it.
			//	polyTlbr->Release();
			break;
		}
		else
			polyTlbr->Release();
		
	}

	tlbrs->Release();


	getAcadMenuGroup(&mnuGrp);
	mnuGrp->Save(acMenuFileCompiled);
	mnuGrp->Release();

	return;
}



void UpdateUserInterface()
{
//	CreateMenus();
	CreateToolbars();
}

void CleanUpUserInterface()
{
//	CleanUpMenus();
	CleanUpToolbars();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -