Resize a rotated rectangle with click and drag

I need to develop a program in mdl that will allow a user to resize a rectangle.  The user can select any corner point or side and drag to a new position.  This would be similar to resizing a window or cropping a picture and needs to be interactive.  There is no problem when the rectangle is not rotated, but of course, the user would like this to work with a rotated rectangle.

I am able to scale the rectangle using mdlElmdscr_transformAllowModification as has been documented in several posts in this forum.  However, I have not been able to let the user change the width and the height and update the aspect ratio while maintaining right angles.  If I vary the scale in the X or Y direction, the rectangle is distorted.

There was one post about rotating the element to a normal view, resizing and rotating it back, but I'm not quite sure how to do this while a user is dragging points or lines with the cursor.  I was hoping there would be a suggesting on how to do this while maintaining the current rotation.

I'm building this using compiler Version 08.05.02.27 and running in Navigator v 08.11.09.713.  

 Sample code:

mdlTMatrix_getIdentity(&tMatrix);
mdlTMatrix_scale(&tMatrix,NULL,xscale,yscale,1); 
mdlTMatrix_setOrigin(&tMatrix,&originPt);  
mdlElmdscr_transformAllowModification(&edP,&tMatrix,gRefModelP,gRefModelP,0);  

 

Parents
  • The general approach with element modification is to create a new element that mimics the chosen element.  Then, modify the copy until user has finished modifications.  Finally, add the copy to your DGN model as a new element and delete the original.

    That approach sits well with MicroStation's undo/redo logic.  If user cancels the operation, nothing needs to be changed.

    There may be some circumstances, such as the one you describe, where the original element can be modified in-place.  If all you're doing is moving, rotating or scaling, then the stored element size is unchanged (even when its geometric depiction is different). 

    One way to approach your goal is to set up a local coordinate system (think of a user-defined ACS) aligned with your rectangle.  Modify your element, or create a new element within that coordinate system, then unrotate it when finished.  That way, you're working with orthogonal axes aligned with the geometry you want to create.

    Note that, during development, the copy-and-replace idiom is useful because you can directly compare what you've created with what you started with.

     
    Regards, Jon Summers
    LA Solutions

Reply
  • The general approach with element modification is to create a new element that mimics the chosen element.  Then, modify the copy until user has finished modifications.  Finally, add the copy to your DGN model as a new element and delete the original.

    That approach sits well with MicroStation's undo/redo logic.  If user cancels the operation, nothing needs to be changed.

    There may be some circumstances, such as the one you describe, where the original element can be modified in-place.  If all you're doing is moving, rotating or scaling, then the stored element size is unchanged (even when its geometric depiction is different). 

    One way to approach your goal is to set up a local coordinate system (think of a user-defined ACS) aligned with your rectangle.  Modify your element, or create a new element within that coordinate system, then unrotate it when finished.  That way, you're working with orthogonal axes aligned with the geometry you want to create.

    Note that, during development, the copy-and-replace idiom is useful because you can directly compare what you've created with what you started with.

     
    Regards, Jon Summers
    LA Solutions

Children
  • Thanks, Jon,

    The create new element, save and delete old is the method I typically employee when letting a user dynamically modify elements in the drawing.

    I was thinking about setting up a local coordinate system, but it's been quite a few years since I've worked with that. I guess that I'll dig out some old code and try to remember the process.

    I've seen some code in other languages that lets a person modify a rotated rectangle by dragging, but I couldn't get it to fit my situation. I hoped someone had developed something slick here. It seems like a useful function to allow a user to drag sides or corners.
  • IMHO  isn't this function is already available in msnt modify tools using handles and accudraw even if rotated?

    well it does take time to do manually....and if you have to do a lot of shapes and often may be worth making a custom tool...

    Lorys

    Started msnt work 1990 - Retired  Nov 2022 ( oh boy am I old )

    But was long time user V8iss10 (8.11.09.919) dabbler CE  update 16 (10.16.00.80) 

    MicroStation user since 1990 Melbourne Australia.
    click link to PM me 

  • Thanks for the reply.  The people are running Navigator on tablets in the field and are looking for something very simple.  I know the basic modify function is not available in Navigator and I was asked to replicate that which I have done to a certain point.  However, the client is asking for a bit more.  It has to be simple, easy, quick and intuitive.