CAA实用代码片段

CAA实用代码片段:

/*常见编译错误: 
fatal error C1189: #error :WINDOWS.H already included.  
解决方法:最顶端定义预编译的宏*/
#ifdef _WINDOWS_
#undef _WINDOWS_     #include <afx.h>
#endif

CAA常用代码构件
#include<afxwin.h>
AfcMessageBox(_T("hello!Point Command"));

//变量和表达式转换成字符串
//使用字符串运算符来实现转换输出定义
#define PR(x) cout<<#x"="<<x<<"\n";

//一、弹出对话框
//1、CATDlgNotify
    CATDlgNotify _OpenNotify;
    CATUnicodeString NotifyText;
    //NotifyText.BuildFromNum(iInputAllocatedSize);
    _OpenNotify = new CATDlgNotify(this, "TEST", CATDlgNfyWarning|CATDlgNfyOK);
    _OpenNotify->SetText(NotifyText);
    _OpenNotify->SetVisibility(CATDlgShow);

//2、MessageBox CATUnicodeString -->LPSTR 利用CString  afxstr;
    CATUnicodeString InstanceName;
    spProduct->GetPrdInstanceName(InstanceName);
    CString name=InstanceName.ConvertToChar();
    MessageBox(NULL,name,L"OK",MB_OK | MB_SYSTEMMODAL);
    MessageBox(NULL,L"Hello World!",L"成功",MB_OK | MB_SYSTEMMODAL);

//二、获取CATIA环境变量:
    CATUnicodeString oPreviewFileName,TmpDir,File;
         char *slash_tmp = NULL;
         if (CATGetEnvValue("CATInstallPath", &slash_tmp) == CATLibSuccess)
            oPreviewFileName = slash_tmp;
         if (slash_tmp) free(slash_tmp); slash_tmp=NULL;
#ifndef _WINDOWS_SOURCE
         oPreviewFileName.Append("\\");
#else
         oPreviewFileName.Append("/");
#endif
         oPreviewFileName.Append("CAAxPDMPreview.jpg");

// get System environment variable
char *pathvar;
pathvar = getenv("PATH");
cout << pathvar << endl
     
/*CATIA CAA 32位和64位编译
    修改环境变量:
    _MkmkOS_BitMode  =  32   // Win32位编译
    _MkmkOS_BitMode  =  64   // Win64位编译
 */

//三、元素隐藏与显示
/**
* 隐藏元素
* @param ipListElemObj
* 元素列表
*/
void HideElements(CATLISTV(CATISpecObject_var) ipListElemObj)
{
    for(int i=1;i<ipListElemobj.Size();i++;)
    {
        CATIVisProperties* pPropONElem = NULL;
        HRESULT rc = ipListElemobj[i]->QueryInterface(IID_CATIVisProperties,(void**) &pPropONElem );
        if (NULL != pPropONElem) 
        {
            CATIVisPropertiesValues PropValue;
            CATIVisPropertyType PropTypeOnPtObj = CATVPShow;
            CATVisGeomType GeomTypeOnPtObj = CATVPGlobalType;
            PropValue.SetShowAttr(CATNOShowAttr);
            rc = pPropONElem -> SetPropertiesAttr(PropValue,
                                                  PropTypeOnPtObj,
                                                  GeomTypeOnPtObj);
            pPropONElem ->Release();
            pPropONElem = NULL;
        }
    }
}

/**
* 检测元素显示状态
*/
bool CheckIsShow(CATIVisProperties_var spPropOnTreeNode)
{
    // 5/18  add
    bool IsShow = false;

    CATShowAttribut oShow ;
    if ( NULL_var != spPropOnTreeNode )
    {
        if ( SUCCEEDED(GetShow(spPropOnTreeNode,oShow,2)))
        {
            // model show flag
            if (oShow == CATShowAttr)
            {
                IsShow = true;
            }
        }
    }//--- 5/18 add

    return IsShow;
}

/**
* 取得元素显示标识 Show Flag
*/
HRESULT GetShow(CATIVisProperties_var spProp, CATShowAttribut &oShow ,int Mode )
{
    if ( spProp == NULL_var)
        return E_FAIL;
    CATVisPropertiesValues  MyPropertyOnFace;
    CATVisPropertyType PropTypeOnFace = CATVPShow;
    CATVisGeomType GeomTypeOnFace;
    if ( Mode == 1 )
        GeomTypeOnFace     = CATVPMesh;
    else
        GeomTypeOnFace     = CATVPGlobalType ;
    HRESULT rc = spProp->GetPropertiesAtt(MyPropertyOnFace,PropTypeOnFace,GeomTypeOnFace);
    if ( SUCCEEDED(rc) )
    {
        HRESULT HR = MyPropertyOnFace.GetShowAttr(oShow);
        if ( FAILED(HR))
            return E_FAIL;
    }
    return S_OK;
}

//四、元素隐藏与显示
/**
* 高亮特征
* @param spSpec
* 高亮特征
*/
HRESULT HighLightSpecObject (CATISpecObject_var spSpec, CATBoolean boolClearHistory)
{
    HRESULT rc = E_FAIL;
    CATFrmEditor * pEditor = CATFrmEditor::GetCurrentEditor();
    if(NULL == pEditor )
        return rc;
    CATHSO * pHSO = pEditor->GetHSO();
    if(NULL == pHSO )
        return rc;  
    
    //为1时,清楚所有已有的高亮
    if(boolClearHistory)
        pHSO->Empty();
    CATPathElement pContext = pEditor->GetUIActiveObject();
    CATIBuildPath * piBuildPath = NULL;
    rc =spSpec->QueryInterface(IID_CATIBuildPath, (void **)&piBuildPath);
    if(SUCCEEDED(rc) && piBuildPath != NULL)
    {
        CATPathElement * pPathElement = NULL;
        rc = piBuildPath->ExtractPathElement(&pContext, &pPathElement);
        if (pPathElement != NULL)
        {
            pHSO->AddElement(pPathElement);
            pPathElement->Release();
            pPathElement = NULL;
        }
        piBuildPath->Release();
        piBuildPath = NULL;
    }
    return S_OK;
}

//五、属性获取   
    CATIAttributesDescription *piAttrDesc = NULL;
    rc = spRootProduct->QueryInterface(IID_CATIAttributesDescription, (void **) &piAttrDesc);
    if (FAILED(rc) || (NULL == piAttrDesc))
    {
        cout << "QueryInterface CATIAttributesDescription error" << endl;
        return 4;
    }
    CATIInstance *piInstance = NULL;
    rc = spRootProduct->QueryInterface(IID_CATIInstance, (void **) &piInstance);
    if (FAILED(rc) || (NULL == piInstance))
    {
        cout << "QueryInterface CATIInstance error" << endl;
        return 4;
    }
    CATListValCATAttributeInfos attrInfoList; 
    piAttrDesc->List(&attrInfoList);
    for (int i = 1; i <= attrInfoList.Size(); i++)
    {
        CATAttributeInfos attrInfo = attrInfoList[i];
        const CATUnicodeString& propertyName = attrInfo.Name(); //属性名
        const CATUnicodeString& valueType = attrInfo.Type()->Name(); //属性类型
        CATIValue *pValue = piInstance->GetValue(propertyName); //获得对应属性名的属性值
        CATUnicodeString value = "";
        pValue->AsString(value);
        cout << propertyName << "-" << valueType << "-" << value << endl;
        if (pValue)
        {
            pValue->Release();
            pValue = NULL;
        }
    }

//六、CATSystemInfo 主机信息获取
/*全局方法CATGetSystemInfo,获得一个CATSystemInfo结构体,包含主机名字、主机系统名字、系统版本等主机信息。*/
CATSystemInfo host;
::CATGetSystemInfo(&host);

cout << "HostName:" << host.HostName << endl;
cout << "OSName:" << host.OSName << endl;
cout << "OSVersion:" << host.OSVersion << endl;
cout << "OSType:" << host.OSType << endl;
cout << "MinorVersion:" << host.MinorVersion << endl;
cout << "MajorVersion:" << host.MajorVersion << endl;


CATTime 
CATTime timeNow = CATTime::GetCurrentLocalTime();
CATUnicodeString timeStr = timeNow.ConvertToString("%Y/%m/%d-%H:%M:%S");
std::cout << "Current Time:" << timeStr.ConvertToChar() << std::endl;

//七、C# C++ 字符集转换  字节流
    string  str="客服端是用c#写的,服务端是c++";
    send(str);
    public void send(msg)
    {
        string hexstr=StringToHexString(str)
        char[] chars= hexstr.ToCharArray();
        byte[] byteData = Encoding.Default.GetBytes(chars);  
        socket.write(byteData ,0,byteData.length);
    }
    //字符串转为16进制
    public string StringToHexString(string message)
    {
        //按照指定编码将string编程字节数组
        byte[] b = Encoding.UTF8.GetBytes(message);
        string result = string.Empty;
        for (int i = 0; i < b.Length; i++)
        {
            result += Convert.ToString(b[i], 16);
        }
        return result.ToUpper();
    }


//八、调用exe文件
ShellExecute(0,(LPCWSTR)L"open",(LPCWSTR)L"D:\\Bin_x64\\SuperMapDemo.exe",(LPCWSTR)L"",(LPCWSTR)L"",SW_SHOWNORMAL);
SHELLEXECUTEINFO ShellInfo;
    memset(&ShellInfo,0,sizeof(ShellInfo));
    ShellInfo.cbSize=sizeof(ShellInfo);
    ShellInfo.hwnd=NULL;
    ShellInfo.lpVerb=_T("open");
    //ShellInfo.lpFile=_T("..\\..\\..\\SuperMapDemo\\SuperMapDemo.exe");
    ShellInfo.lpFile=_T("E:\\supermap\\Bin_x64\\SuperMapDemo.exe");
    ShellInfo.lpParameters= name;
    ShellInfo.nShow=SW_HIDE;//SW_SHOWNORMAL
    ShellInfo.fMask=SEE_MASK_NOCLOSEPROCESS;
    BOOL bResult=ShellExecuteEx(&ShellInfo);
    if (!bResult)
    {
        return false;
    }

    行号 参数 含义  
    1 SW_HIDE 隐藏这个窗体,并激活其他窗体。 
    2 SW_MAXIMIZE 最大化指定的窗体。  
    3 SW_MINIMIZE 最小化指定的窗体,并按顺序激活最上层的窗体。  
    4 SW_RESTORE 激活并显示窗体。如果窗体为最小化或者最大化,窗体恢复到原始大小和位置。应用程序当恢复一个最小化的窗体时将指定标记。 
    5 SW_SHOW 以当前的大小和位置激活并显示窗体。 
    6 SW_SHOWDEFAULT   
    7 SW_SHOWMAXIMIZED 激活并最大化显示窗体。
    8 SW_SHOWMINIMIZED 激活并最小化现实窗体。 
    9 SW_SHOWMINNOACTIVE 最小化窗体,保持其激活状态。 
    10 SW_SHOWNA 以当前状态显示窗体,保持其激活状态。  
    11 SW_SHOWNOACTIVATE 以当前的大小和位置显示窗体,并保持其激活状态。 
    12 SW_SHOWNORMAL 激活并显示一个窗体。如果窗体为最大化或者最小化,窗体恢复到原始的大小和位置。当窗体第一次显示的时候,应用程序记录标记。


//九、批处理模式获得文件的rootProduct
HRESULT GetCurrentDoc_TopProduct( CATIProduct_var & spTopProd)
{
//--------------------------------------------------------------------
// 1. Prologue 
//--------------------------------------------------------------------
  cout << endl << flush;
  cout << endl << flush;
  cout << "----------------------------------------------------------------" << endl << flush;
  cout << endl << flush;

  // --- Creating the Session:  A session must always be created in a batch
  char *sessionName = "CAA_EhiFilter_Session";
  CATSession *pSession = NULL;
  HRESULT rc = ::Create_Session(sessionName,pSession);
  if ((SUCCEEDED(rc)) && (NULL != pSession))
  {
    cout << "> session created : " << sessionName <<endl << flush;
  }
  else
  {
    cout << "ERROR in creating session" << sessionName << endl << flush;
    return 1;
  }
  
  // --- Opening an existing document 
  //     The input parameter to this sample program must contain 
  //     the entire path and name of the document that is to be opened.  
  
  CATDocument *pDoc = NULL;  // pDoc is a pointer to the document 

  cout << "> open document :"<< argv[1] << argv[2] << endl << flush;
  rc = CATDocumentServices::OpenDocument(CATUnicodeString(argv[1])+CATUnicodeString(argv[2]), pDoc);
  
  CATLockDocument(*pDoc);

  if (SUCCEEDED(rc) && (NULL != pDoc))
  {
    cout << "> document opened " << endl << flush;
  }
  else
  {
    cout << "ERROR in opening document" << endl << flush;
    return 2;
  }
  
  // --- Retrieving root product of the opened document 
  CATIProduct* piRootProduct = NULL; // piRootProduct is a handle to document root product  
  //  
  CATIDocRoots * piDocRoots = NULL;
  rc = pDoc->QueryInterface(IID_CATIDocRoots,(void**) &piDocRoots);
  if ( FAILED(rc) || (NULL==piDocRoots) ) 
  {
    cout << "ERROR : Failed to query CATIDocRoots" << endl;
    return 3;
  }
  CATListValCATBaseUnknown_var* pListRootProduct = piDocRoots->GiveDocRoots();
  piDocRoots->Release();
  piDocRoots=NULL;
  
  if ( pListRootProduct && pListRootProduct->Size() )
  {  
    CATBaseUnknown_var hUnk = (*pListRootProduct)[1];

    if (NULL_var != hUnk) 
        rc = hUnk->QueryInterface(IID_CATIProduct,(void**) &piRootProduct );
    if (pListRootProduct) 
        delete pListRootProduct;
        pListRootProduct = NULL;
    //
    if  (SUCCEEDED(rc) && (NULL != piRootProduct))
    {
        cout << "> root product found in document " << endl << flush;
        spTopProd = piProductOnRoot;
        CATUnicodeString partNumber = piProductOnRoot->GetPartNumber();
        cout << "Working with '" << partNumber.ConvertToChar() << "'" << endl;
        return S_OK;
    }
    else
    {
      cout << "ERROR : Root product not found in document " << endl << flush;
      return 3;
    }
  }
  
//--------------------------------------------------------------------
    //创建草图
    CATInit *piInitOnDoc = NULL;
    rc = pDoc -> QueryInterface (IID_CATInit,(void**) &piInitOnDoc);
    if(SUCCEEDED(rc) && NULL != piInitOnDoc)
    {
        //获取Container
        const CATIdent idCATIContainer = "CATIPrtContainer";
        CATIPrtContainer *piRootContainer = NULL;
        piRootContainer = (CATIPrtContainer*)
            piInitOnDoc -> GetRootContainer(idCATIContainer);
        if(NULL != piRootContainer)
        {
            CATIPrtPart_var spPart = piRootContainer->GetPart();
            CATIBasicTool_var spTool= spPart->GetCurrentTool();

            CATIDescendants_var spDesTool = spPart;
            CATListValCATISpecObject_var  oLst ;
            spDesTool->GetAllChildren("CATIMechanicalTool",oLst);
            CATISpecObject_var spMainBody = oLst[1];
            CATIAlias_var spAlias = spMainBody;
            cout << spAlias->GetAlias() << endl << flush;

            CATISketchFactory_var spSketchFactory(piRootContainer);
            if(NULL_var != spSketchFactory)
            {
                CATISpecObject_var spSketchSpec=spSketchFactory->CreateSketch();
                CATISketch_var spSketch=spSketchSpec;
                if(NULL_var != spSketch)
                {
                    spSketch->OpenEdition();
                    CATI2DWFFactory_var sketch2DFactory(spSketch);
                    if(NULL_var != sketch2DFactory)
                    {
                        double Origin[2]={0.,0.};
                        double Radius=10;
                        CATISpecObject_var spSpecCircle=
                            sketch2DFactory->CreateCircle(Origin,Radius);
                        if(NULL_var != spSpecCircle)
                        {
                            cout<<"草图中创建圆成功!"<<endl;    
                        }
                        spSketch->CloseEdition();

                        spPart->SetCurrentFeature(spMainBody);


                        //创建凸台
                        CATIPrtFactory * piPrtFact=NULL;
                        rc=piRootContainer->QueryInterface(IID_CATIPrtFactory,
                            (void **)&piPrtFact);
                        if(SUCCEEDED(rc) && NULL != piPrtFact)
                        {
                            CATISpecObject_var spPad=piPrtFact->CreatePad(spSketch);
                            if(NULL_var != spPad)
                            {
                                CATIPad_var spPadPad=spPad;
                                if(NULL_var != spPadPad)
                                {
                                    spPadPad->ModifyEndType(catOffsetLimit);
                                    spPadPad->ModifyEndOffset(20.);
                                }

                                spPad->Update();
                                cout<<"创建凸台成功!"<<endl;
                            }
                            piPrtFact->Release();
                            piPrtFact=NULL;

                            CATISpecObject_var spPart = piRootContainer->GetPart();
                            spPart->Update();
                        }
                    }
                }
            }

            CATISpecObject_var spParentForTool = spMainBody;
            CATIMechanicalRootFactory_var spMechRoot = piRootContainer;
            CATISpecObject_var spSpecGS1 = NULL_var;
            rc = spMechRoot -> CreateGeometricalSet("新增几何图形集1",spParentForTool,spSpecGS1);
        }

        piInitOnDoc->Release();
        piInitOnDoc=NULL;
    }

CAA获取属性

CAAProductStructure.edu
  CAAPstAllProperties.m
  CAAPstPrdProperties.m
  
/**
 * Defines the relative orientation of an element with regards to another one.
 * @param CATOrientationNegative
 * Their orientation are opposite.
 * @param CATOrientationPositive
 * They have the same orientation.
 * @param CATOrientationUnknown
 * The orientation is not known.
 */
#define CATOrientation      short
/** @nodoc */
#define CATOrientationNegative -1
/** @nodoc */
#define CATOrientationPositive  1
/** @nodoc */
#define CATOrientationUnknown   2

/**
 * Defines the side where is the matter when walking along an element in the
 * direction of its default orientation.
 * @param CATSideLeft
 * The matter is on the left.
 * @param CATSideFull
 * The matter is on both sides: the object is immersed inside a cell of higher dimension.
 * (non manifold configuration).
 * @param CATSideRight
 * The matter is on the right.
 * @param CATSideUnknown
 * The matter side is not known.
 */ 
#define CATSide      short
/** @nodoc */
#define CATSideLeft      1
/** @nodoc */
#define CATSideFull      0
/** @nodoc */
#define CATSideRight    -1
/** @nodoc */
#define CATSideUnknown   2

E:\CATIA_developing\CAAxPDMTst\CAAxPDMInterfaces.edu\CAAxPDMReadItemInfo.m;

CATRep pRep;
CATGraphicAttributeSet ga = pRep->GetGraphicAttributeSet( )  ;

CATGraphicAttributeSet;
Role: This class permits to have a graphic attribute which define the display properties of an element. 
Always associated to a rep or a graphic primitive.


C:\CATIA_V5_B22\CATMatInterfaces
C:\CATIA_V5_B22\Material

CATGraphicMaterial.h
CATIAMaterialManager GetMaterialOnPart
CATIARenderingMaterial.h

/** 
 * Interface for materials.
 * <b>Role</b>:
 * This is the base interface for materials.
 * It is used to access the data needed for rendering.
 */

class CATIRdgMaterial

CATMappingOperator  ComputeTextureCoordinates 
Mapping operator used to calculate texture coordinates.
  /** Computes the texture coordinates for all vertices.
   * @param iVertex
   * Array containing the coordinates of every vertices,as a succession
   * of (x,y,z) sets.
   * @param iNbVertex
   * Number of vertices in <tt>iVertex</tt>.
   * @param iNormals
   * Array containing the coordinates of the normals at every vertices, as
   * a succession of (Nx,Ny,Nz) sets.
   * If the surface is plane, the only given set is valid for all vertices.
   * @param iNormals
   * Number of normal sets in <tt>iNormals</tt>.
   * @param iTuv
   * Array containing the parameters in of every vertices in the surface parametrization space,
   * as a succession of (u,v) sets.
   * This array must be required by the mapping operator through the method <tt>NeedUVMesh</tt>.
   * @param iNbuv
   * Number of parameter sets in <tt>iNbuv</tt>.
   * @param oTexture
   * Array containing the coordinates of texture coordinates for every vertices,
   * as a succession of (s,t,0) sets. <br>
   * (0,0,0) always indicates the lower-left corner of the texture image. <br>
   * (1,1,0) always indicates the upper-right corner of the texture image.
   */
  virtual void ComputeTextureCoordinates(const float iVertex[],
                                         const int   iNbVertex,
                                         const float iNormals[],
                                         const int   iNbNormals,
                                         const float iTuv[],
                                         const int   iNbuv,
                                         float       oTexture[]) const;
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,053评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,527评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,779评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,685评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,699评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,609评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,989评论 3 396
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,654评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,890评论 1 298
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,634评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,716评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,394评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,976评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,950评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,191评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,849评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,458评论 2 342

推荐阅读更多精彩内容