[MSCE]关于图案填充的问题

在利用IAreaFillPropertiesEdit进行图案填充的时候,哪个方法可以进行图案填充定义及填充图案选择呢?

查找了PatternParams Struct当中的方法,好像没有找到对应函数。

Auto CAD中的填充图案能否一并选择来使用?

  • IAreaFillPropertiesEdit下的AddPattern就是用来给一个EditElementHandle添加图案化的。具体图案化的参数由PatternParams和DwgHatchDefLine两个类来确定。后者就是你说的利用ACAD中的填充图案。

    大致编程步骤如下:

    PatternParamsPtr pPatParams = PatternParams::Create ();

    pPatParams->SetXXX();   设置图案化的各种参数,如SetCellName指定图案化单元

    正确设置pPatParams->modifiers

    IAreaFillPropertiesEdit* areaObj = dynamic_cast <IAreaFillPropertiesEdit*> (&eeh.GetHandler (MISSING_HANDLER_PERMISSION_ChangeAttrib));

    areaObj->AddPattern (eeh, *pPatParams, NULL);



  • PAT文件中保存的是DWG格式的图案化方案,它由如下信息组成:

    *图案化名称

    后跟一到多行的如下信息:

    angle, x-origin, y-origin, delta-x, delta-y, [dash-1, dash-2, ...]

    而AddPattern函数的第三个参数DwgHatchDefLineP恰恰就是表达的这个信息。请看函数说明如下:

    所以,你可以用代码打开相应的PAT文件,找到对应的Pattern名称,然后将其下的每一行读入为一个DwgHatchDefLine结构,保存在一个bvector<DwgHatchDefLine>中,然后设置params.GetDwgHatchDef().nDefLines为该Pattern中数据的行数。这样调用AddPattern就可以了。

    看看DwgHatchDefLine结构,是否正好和上面描述的PAT结构一致?

    typedef struct dwgHatchDefLine
        {
        double              angle;
        DPoint2d            through;
        DPoint2d            offset;
        short               nDashes;
        double              dashes[MAX_DWG_HATCH_LINE_DASHES];
        } DwgHatchDefLine;

    最简单的办法是,先手工制作这样一个Pattern,然后调用GetPattern方法返回一个bvector<DwgHatchDefLine>查看其内容。



    Answer Verified By: lihui He 

  • 感谢符工详细的解答。过程中发现一个问题,pat文件中DWG图案AR-CONC结构值见上图,利用GetPattern方法返回的结构值见下图,二者在offset存在区别,不一致,是否有问题?

       

    另外,代码部分基本完成,但仍没有正确填充,我将代码贴上,烦请符工再给看看是什么问题?

    	ElementId elemId = 114979;
    	EditElementHandle eeh(elemId, ISessionMgr::GetActiveDgnModelP());
    	IAreaFillPropertiesEdit * fillEditP = dynamic_cast<IAreaFillPropertiesEdit *>(&eeh.GetHandler());
    	if (NULL == fillEditP)
    		return;
    	fillEditP->SetAreaType(eeh, false);
    	PatternParamsPtr params = PatternParams::Create();
    	params->SetModifiers(PatternParamsModifierFlags::DwgHatchDef);
    
    	bvector<DwgHatchDefLine>hatchDefLine;
    	DwgHatchDefLine hatchDefLineBase;
    	hatchDefLineBase.angle = 0.872665;
    	hatchDefLineBase.through = { 0.0, 0.0 };
    	hatchDefLineBase.offset = { 7.172602, -0.627521 };
    	hatchDefLineBase.nDashes = 2;
    	hatchDefLineBase.dashes[0] = 0.75;
    	hatchDefLineBase.dashes[1] = -8.25;
    	hatchDefLine.push_back(hatchDefLineBase);
    
    	hatchDefLineBase.angle = 6.195919;
    	hatchDefLineBase.through = { 0.0, 0.0 };
    	hatchDefLineBase.offset = { -1.387513, 7.521921 };
    	hatchDefLineBase.nDashes = 2;
    	hatchDefLineBase.dashes[0] = 0.60;
    	hatchDefLineBase.dashes[1] = -6.6;
    	hatchDefLine.push_back(hatchDefLineBase);
    
    	hatchDefLineBase.angle = 1.753208;
    	hatchDefLineBase.through = { 0.597717, -0.052293 };
    	hatchDefLineBase.offset = { 5.785088 , 6.894400 };
    	hatchDefLineBase.nDashes = 2;
    	hatchDefLineBase.dashes[0] = 0.637402;
    	hatchDefLineBase.dashes[1] = -7.011421;
    	hatchDefLine.push_back(hatchDefLineBase);
    
    	hatchDefLineBase.angle = 0.806066;
    	hatchDefLineBase.through = { 0.0, 2.0 };
    	hatchDefLineBase.offset = { 10.672413, -1.655193 };
    	hatchDefLineBase.nDashes = 2;
    	hatchDefLineBase.dashes[0] = 1.125;
    	hatchDefLineBase.dashes[1] = -12.375;
    	hatchDefLine.push_back(hatchDefLineBase);
    
    	hatchDefLineBase.angle = 1.686610;
    	hatchDefLineBase.through = { 0.889367, 1.862067 };
    	hatchDefLineBase.offset = { 9.346619, 9.741186 };
    	hatchDefLineBase.nDashes = 2;
    	hatchDefLineBase.dashes[0] = 0.956103;
    	hatchDefLineBase.dashes[1] = -10.517138;
    	hatchDefLine.push_back(hatchDefLineBase);
    
    	hatchDefLineBase.angle = 6.129320;
    	hatchDefLineBase.through = { 0.0, 2.0 };
    	hatchDefLineBase.offset = { 9.346619, 9.741186 };
    	hatchDefLineBase.nDashes = 2;
    	hatchDefLineBase.dashes[0] = 0.9;
    	hatchDefLineBase.dashes[1] = -9.9;
    	hatchDefLine.push_back(hatchDefLineBase);
    
    	hatchDefLineBase.angle = 0.366519;
    	hatchDefLineBase.through = { 1.0, 1.5 };
    	hatchDefLineBase.offset = { 5.969071, -4.026189 };
    	hatchDefLineBase.nDashes = 2;
    	hatchDefLineBase.dashes[0] = 0.75;
    	hatchDefLineBase.dashes[1] = -8.25;
    	hatchDefLine.push_back(hatchDefLineBase);
    
    	hatchDefLineBase.angle = 5.689773;
    	hatchDefLineBase.through = { 1.0, 1.5 };
    	hatchDefLineBase.offset = { 2.433153, 7.251500 };
    	hatchDefLineBase.nDashes = 2;
    	hatchDefLineBase.dashes[0] = 0.60;
    	hatchDefLineBase.dashes[1] = -6.6;
    	hatchDefLine.push_back(hatchDefLineBase);
    
    	hatchDefLineBase.angle = 1.247063;
    	hatchDefLineBase.through = { 1.497423, 1.164484 };
    	hatchDefLineBase.offset = { 8.402224, 3.225312 };
    	hatchDefLineBase.nDashes = 2;
    	hatchDefLineBase.dashes[0] = 0.637402;
    	hatchDefLineBase.dashes[1] = -7.011421;
    	hatchDefLine.push_back(hatchDefLineBase);
    
    	hatchDefLineBase.angle = 0.654498;
    	hatchDefLineBase.through = { 0.0, 0.0 };
    	hatchDefLineBase.offset = { 0.121599, 3.328939 };
    	hatchDefLineBase.nDashes = 6;
    	hatchDefLineBase.dashes[0] = 0.0;
    	hatchDefLineBase.dashes[1] = -6.52;
    	hatchDefLineBase.dashes[2] = 0.0;
    	hatchDefLineBase.dashes[3] = -6.7;
    	hatchDefLineBase.dashes[4] = 0.0;
    	hatchDefLineBase.dashes[5] = -6.625;
    	hatchDefLine.push_back(hatchDefLineBase);
    
    	hatchDefLineBase.angle = 0.1309;
    	hatchDefLineBase.through = { 0.0, 0.0 };
    	hatchDefLineBase.offset = { 2.630695, 3.944117 };
    	hatchDefLineBase.nDashes = 6;
    	hatchDefLineBase.dashes[0] = 0.0;
    	hatchDefLineBase.dashes[1] = -3.82;
    	hatchDefLineBase.dashes[2] = 0.0;
    	hatchDefLineBase.dashes[3] = -6.37;
    	hatchDefLineBase.dashes[4] = 0.0;
    	hatchDefLineBase.dashes[5] = -2.525;
    	hatchDefLine.push_back(hatchDefLineBase);
    
    	hatchDefLineBase.angle = -0.567232;
    	hatchDefLineBase.through = { -2.23, 0.0 };
    	hatchDefLineBase.offset = { 5.338224, -0.225549 };
    	hatchDefLineBase.nDashes = 6;
    	hatchDefLineBase.dashes[0] = 0.0;
    	hatchDefLineBase.dashes[1] = -2.5;
    	hatchDefLineBase.dashes[2] = 0.0;
    	hatchDefLineBase.dashes[3] = -7.8;
    	hatchDefLineBase.dashes[4] = 0.0;
    	hatchDefLineBase.dashes[5] = -10.35;
    	hatchDefLine.push_back(hatchDefLineBase);
    
    	hatchDefLineBase.angle = -0.741765;
    	hatchDefLineBase.through = { -3.23, 0.0 };
    	hatchDefLineBase.offset = { 5.831862, 1.00105 };
    	hatchDefLineBase.nDashes = 6;
    	hatchDefLineBase.dashes[0] = 0;
    	hatchDefLineBase.dashes[1] = -3.25;
    	hatchDefLineBase.dashes[2] = 0;
    	hatchDefLineBase.dashes[3] = -5.18;
    	hatchDefLineBase.dashes[4] = 0;
    	hatchDefLineBase.dashes[5] = -7.35;
    	hatchDefLine.push_back(hatchDefLineBase);
    	DwgHatchDef dwgHatchDef = params->GetDwgHatchDef();
    	dwgHatchDef.nDefLines = 13;
    	ElementRefP oldRef = eeh.GetElementRef();
    	fillEditP->AddPattern(eeh, *params, &hatchDefLine[0]);
    	eeh.ReplaceInModel(oldRef);