[V8i - MDL/CPP] Bug in mdlPattern_addAssociative in V8i SS4 (8.11.09.832)

Hi all

We've found a bug in mdlPattern_addAssociative (and in mdlPattern_addAssociative2 as well). If you use code like this:

PatternParams	patPar;

memset(&patPar, 0, sizeof(patPar));
patPar.modifiers |= PATMOD_SPACE1;
patPar.modifiers |= PATMOD_ANGLE1;
patPar.modifiers |= PATMOD_COLOR;
patPar.space1 = 5000;
patPar.angle1 = fc_pi / 4;
patPar.color = 3;

rc = mdlPattern_addAssociative(edPP, 0, 0, &patPar, NULL, NULL, PATTERN_HATCH, mdlModelRef_getActive());

the function returns SUCCESS, BUT at first glance it seems like no pattern have been added to the shape (edPP). But if you use the "Show Pattern Attributes" tool you will se that PA (pattern angle) is zero and PD (pattern distance) is zero as well.

In V8i SS3 this works just fine...

Regards, Evan

Parents
  • edPP is just a parameter (MSElementDescr **edPP) to the function the code snippet is taken from and points to a shape or complex shape. This shape is either selected by the user or found by scanning.

    Regards, Evan
  • I know what edPP is, I'm trying to see exactly what you are doing with it (because the issue almost certainly lies somewhere in your code not mdlPattern_addAssociative, even if you somehow got away with it in a previous version).

    For example, something like the following would be bad:

    void func1()
    {
    MSElementDescrP edP;
    mdlElmdscr_read(&edP, ...);
    func2(edP);
    mdlElmdscr_add(edP);
    mdlElmdscr_freeAll(&edP);
    }
    
    void func2(MSElementDescrP edP)
    {
    func3(&edP);
    }
    
    void func3(MSElementDescrH edPP)
    {
    mdlPattern_addAssociative(edPP, ...);
    }



  • Hi Brien

    I've now created a very small and simple test application that illustrates the problem.

    Private void setSymb(MSElementDescr **edPP, long color)
    {
    	PatternParams	patPar;
    	long			rc;
    
    	memset(&patPar, 0, sizeof(patPar));
    	patPar.modifiers |= PATMOD_SPACE1;
    	patPar.modifiers |= PATMOD_ANGLE1;
    	patPar.modifiers |= PATMOD_COLOR;
    	patPar.space1 = 2000;
    	patPar.angle1 = fc_pi / 4;
    	patPar.color = color;
    
    	rc = mdlPattern_addAssociative(edPP, 0, 0, &patPar, NULL, NULL, PATTERN_HATCH, mdlModelRef_getActive());
    }
    
    
    extern "C" DLLEXPORT int MdlMain (int argc, char **argv)
    {
    	UShort          typeMask[6];
    	ScanCriteria	*scanCriteria;
    	int		scanStatus, scanSize;
    	UInt32		scanPosition;
    	ULong		scanBuf[1024], *lP;
    
    	memset(typeMask, 0, sizeof (typeMask));
    	typeMask[0] = TMSK0_CMPLX_SHAPE | TMSK0_SHAPE | TMSK0_CELL_HEADER;
    	scanCriteria = mdlScanCriteria_create();
    	mdlScanCriteria_setModel(scanCriteria, mdlModelRef_getActive());
    	mdlScanCriteria_setReturnType(scanCriteria, MSSCANCRIT_RETURN_FILEPOS, FALSE, FALSE);
    	mdlScanCriteria_setElementTypeTest(scanCriteria, typeMask, sizeof(typeMask));
    
    	do
    	{
    		scanSize = sizeof(scanBuf) / sizeof(short);
    		scanStatus = mdlScanCriteria_scan(scanCriteria, scanBuf, &scanSize, &scanPosition);
    		for (lP = scanBuf; lP < scanBuf + scanSize / 2; ++lP)
    		{
    			MSElementDescr *edP;
    
    			mdlElmdscr_read(&edP, *lP, mdlModelRef_getActive(), FALSE, NULL);
    			setSymb(&edP, 3);
    			mdlElmdscr_add(edP);
    			mdlElmdscr_freeAll(&edP);
    		}
    	} while (scanStatus == BUFF_FULL);
    
    	if (scanCriteria)
    		mdlScanCriteria_free(scanCriteria);
    
    	return(0);
    }

    Regards, Evan

  • Nothing obvious jumps out at me, what happens if you immediately call mdlPattern_extractAssociative after calling mdlPattern_addAssociative? Do you get the correct PatternParams? Are there any element->file callback registered that are modifying elements?



  • I am facing exactly the same problem, with code almost identical as above. Only thing I can add is that as far as i can remember this problem also occured in ss2. I never tried to solve the issue because at that moment ss3 already was at hand.

    Regards, Leonard
  • I've now modified the setSymb function to test the suggestion from Jon and the extracted parameters:

    rc = mdlPattern_addAssociative(edPP, -1, -1, &patPar, NULL, NULL, PATTERN_HATCH, mdlModelRef_getActive());
    
    PatternParams	extractedPatPar;
    char msg[80];
    mdlPattern_extractAssociative(&extractedPatPar, NULL, &((*edPP)->el), mdlModelRef_getActive(), 0);
    sprintf(msg, "space1 = %f, angle1 = %f", extractedPatPar.space1, extractedPatPar.angle1);
    mdlDialog_dmsgsPrint(msg);

    The result is exactly the same as if I used the "Show Pattern Attributes" tool: Pattern angle and distance is zero. In SS3 (8.11.09.752) it works just fine. There are no element->file callback registered.

    Regards, Evan

  • It looks like there were changes made to address an issue with patterns created in the Connect with annotation scale, this must have broke something; I'll ask the person that made those changes to investigate, thanks.

    -B



  • Hi EvanH,

    I copied your code as-is and was able to place hatches successfully.

    SHOW PATTERN reports correctly “Hatching: PA=45.0000,0.0000, PD=2.0000,0.0000”.

    The only side issue I noticed was the call to mdlElmdscr_add (), which is meant for creating a clone of the original shape. This is not a problem, just an observation. The hatch was created on the cloned shape successfully.

    Replacing it with mdlElmdscr_rewrite () created the hatch on the original shape successfully too.

    Please let me know what I am missing. When you run your code, does it create a hatch at all? Are you trying to update an existing hatch?

    Can you send me a DGN file containing a hatch created by your tool in MicroStation V8i Ss3?



  • Unknown said:
    I copied your code as-is and was able to place hatches successfully

    In which version of MicroStation?  This problem seems to be strongly related to version.

     
    Regards, Jon Summers
    LA Solutions

  • I tried it in my debug build of MicroStation V8i Ss4, which should be close to the build this issue was reported in (08.11.09.832).



  • Hi Sunand,

    I'm VERY surprised that you can attach the pattern with the code listed. As Jon points out the problem is strongly related to version. Please check the code on the released version.

    The reason for using mdlElmdscr_add instead of mdlElmdscr_rewrite is that the original shape might come from a reference file (when using my original application)

    I've attached to .dgn files PatternTest_SS3.dgn and PatternTest_SS4.dgn showing the results when running the test in the two versions.

    PatternTest_SS3.dgnPatternTest_SS4.dgn

Reply Children