Hi Graham,

Thanks for reply, still did not get any success. We are looking into your
code and trying to find out how you implement the group - rotation.

Thanks,
Ghufran Ahmad
+91 - 9953130470
Skype ID: ghufran_khan81
AOL ID: gahmad81

-----Original Message-----
From: Graham Cox [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, April 29, 2008 12:04 PM
To: Ghufran Ahamad
Cc: cocoa-dev@lists.apple.com
Subject: Re: Group rotation

Implementing grouping that really works is quite hard.

What about when groups are nested? This can go on indefinitely, so you  
need a mechanism that can take account of any number of nested groups.  
Since transforms from any level can be appended or prepended, this is  
the way to go I believe - each object has a transform that defines its  
position and rotation and size, and so does each group. When a shape  
is drawn it needs to apply all of the transforms for the whole group  
hierarchy that contains it. Also, when an object is grouped, it needs  
to have its coordinates translated so that they are relative to the  
group, (the series of transforms then compensates for this when the  
group draws its contents).

When you ungroup, what about if you have now rotated and resized and  
some of the contained groups are also rotated and resized? The effect  
is that paths can get skewed, which is valid, but you need to preserve  
all of that when you ungroup. There's a lot more to it than meets the  
eye. Getting it right is hard. ;-)

I don't think your code snippet gives enough information - the effect  
you're seeing is because of several transforms that don't match in  
some way, at least as far as I can tell.

One other thing - don't use NSUnionRect, it has really poor behaviour  
for grouping. Consider what it will do if you try and group two  
orthogonal lines separated by some distance, where their bounds have  
no height or width...


If you're interested, my DrawKit project implements grouping as  
outlined above, and as far as I can tell works as I would expect with  
any degree of nesting. You might get some useful things to go on from  
it (or just use it and save reinventing that particular wheel yet  
again):

http://apptree.net/drawkitmain.htm


hth,

G.



On 29 Apr 2008, at 3:25 pm, Ghufran Ahamad wrote:
> Hi All,
>
>
>
> I want to do group rotation for various objects. Objects are getting  
> rotate
> correctly on their center but when I group them the rotated object  
> has got
> shift. Note: In case of group only rotated object has got shift.  
> Below is
> the code snippet. Let me know I doing correct or not.
>
>
>
> -(NSRect)drawingBoundForGroup:(int)in_Group
>
> {
>
>   NSRect rect = NSZeroRect;
>
>   NSArray *objTlGraphic = [[self document] graphics];
>
>   unsigned i,c = [objTlGraphic count];
>
>   if(in_Group != 0)
>
> {
>
>     for(i = 0; i < c;i++)
>
>    {
>
>      if([[objTlGraphic objectAtIndex:i] GroupNO]==in_Group)
>
>      {
>
>        rect=NSUnionRect(rect,[[objTlGraphic objectAtIndex:i] bounds]);
>
>        NSLog(@"Object Center Log Index= %d %d",rect,i);
>
>       }
>
>    }
>
>   }
>
>    return rect;
>
> }
>
>
>
> int Id_Group=[curGraphic GroupNO];
>
> NSRect stRect=[curGraphic  drawingBoundForGroup:Id_Group];
>
>
>
> NSAffineTransform* xform = [NSAffineTransform transform];
>
> [currentContext saveGraphicsState];
>
> [NSBezierPath clipRect:drawingBounds];
>
> NSPoint center = NSMakePoint(NSMidX(stRect), NSMidY(stRect));
>
> [xform translateXBy:center.x yBy:center.y];
>
> [xform rotateByDegrees:[curGraphic GetAngle]];
>
> [xform translateXBy:-center.x yBy:-center.y];
>
> [xform concat];
>
> [curGraphic drawInView:self isSelected:isSelected];
>
> [currentContext restoreGraphicsState];
>
> [self setNeedsDisplay:YES];
>
>
>
>
>
> Thanks in advance,
>
> Ghufran Ahmad
>
> +91 - 9953130470
>
> Skype ID: ghufran_khan81
>
> AOL ID: gahmad81
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/graham.cox%40bigpond.com
>
> This email sent to [EMAIL PROTECTED]


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to