Hi, There,
I am writing an MDL app to make the new cell from an existing one. I need to ensure that the origin of the new cell is the same as the original cell. I did the following:
1. Place a cell.
2. Read the newly placed cell back. and get the origin of the cell, say oldOrigin
3. Create a new cell header as follows:
mdlCell_create( &newCellElm, cellNameW, &oldOrigin, FALSE);
mdlElmdscr_new (&newCellDP, NULL, &newCellElm);
4. Add the original cell to the new cell.
mdlElmdscr_appendDscr(newCellDP, oldCellDP)
5. Add the new cell to the cell lib.
mdlCell_addLibDescr (newCellDP, -1, FALSE)
The cell was created successfully. However, the origin was not the same.
If I place the old cell at the location (0,0,0) and create the new cell mdlCell_create( &newCellElm, cellNameW, NULL, FALSE);
Then the new cell will have the same origin as the old one.
Can anyone tell me how to resolve the problem without needing to place the old cell at the location (0,0,0)?
Any suggestion will be greatly appreciated.
Ken
Unknown said: The cell was created successfully. However, the origin was not the same. If I place the old cell at the location (0,0,0) and create the new cell mdlCell_create( &newCellElm, cellNameW, NULL, FALSE); Then the new cell will have the same origin as the old one
Then the new cell will have the same origin as the old one
You have an element descriptor with the old cell contents. Transform that descriptor to the origin using mdlElmdscr_transform. Compute the transform as the offset between the old cell origin and 0,0. For more help, please post a code snippet.
Regards, Jon Summers LA Solutions
Hi, Jon,
the old cell origin is oldO, the new cell descriptor is cellDP,
I tried the following code:
Transform tMatrix;
Dpoint3d pnt =oldO;
mdlTMatrix_getIdentity(&tMatrix);
mdlTMatrix_setTranslation (&tMatrix, &pnt);
mdlElmdscr_transform(cellDP, &tMatrix);
But it did not work. What have I done wrong?
Thanks in advance,
Forgot to post the code for create cell header element cellElmand cell descriptor cellDP:
mdlCell_create( &cellElm, cellNameW, NULL, FALSE)
mdlElmdscr_new (&cellDP, NULL, &cellElm);
Unknown said:It did not work
What did not work? Please provide evidence.
Bear in mind that transforming anything to its origin results in no change. You want the offset from the cell origin to 0,0. In this case it's a simple negation, but more generally use mdlVec_subtract.
Thanks for the help. It did work after a simple negation. However, I should transforming the new cell descriptor after I have appended the old one, rather than transform the descriptor containing only the cell header of the new cell. So my final code looks like as the follows:
mdlElmdscr_appendDscr(cellDP, oldCellDP)
//Add more element here ...
pnt.x = 0.0 - oldO.x;
pnt.y = 0.0 -oldO.y;
both the wrong way !
first translate the old descriptor than add to the newly created cell.
i.e. old descriptor on 10,10
with your code you create a newcell with origin -10, -10 and a content of oldcell starting at 0,0 (still 10,10 offset)
when translating the old descriptor (remember its only in memory), you will receive a newcell with origin at 0,0 with a oldcell at offset 0,0
Hi, Michael,
Thanks for your reply. Your method definitely worked. However, I could not tell the difference using the different methods. Can you tell me any potential impact in the down stream operations when these cells are used.
Thanks.
When I said that I could not tell the difference, I meant that when I place the cells created using different method at 0,0, both the new cell origin and the nested old cell origin are shown as 0,0 using information command.
Regards,