This Question is Answered

1 "correct" answer available (5 pts) 13 "helpful" answers available (3 pts)
5 Replies Last post: Apr 17, 2008 11:18 PM by tiju

Cloning graphical objects

Apr 16, 2008 12:22 AM

Click to view tiju's profile Level 6 tiju 118 posts since
Oct 17, 2007
Can anyone please help me on how to get graphical objects cloned? I am not aware of any ready-made procs. I got much amount of code creating a complex graphical object. Now I want to print the object to a pdf but writing and storing all the objects again is cumbersome. It would have been nice if we got a clone for the Graphic class.


Will creating a new RootFrame and adding the graphic object to it help duplicate my graphical object?


I have not checked the clone-appearance option in Graphic class.

Click to view rhh's profile Curl rhh 29 posts since
Oct 12, 2007
1. Re: Cloning graphical objects Apr 16, 2008 8:19 AM
When you are displaying a hierarchy of graphical objects on the screen and then you want to print it to a printer or PDF writer, generally the best approach is to just call Curl's print-graphic procedure to print it. Internally, print-graphic temporarily detaches the graphic hierarchy to be printed and reattaches it to a print root frame for printing, then puts the graphic hierarchy back where it was. This is the approach that Curl uses internally for printing, and it is a lot more satisfactory than trying to clone complex hierarchies of graphical objects.

-Bert
Click to view tiju's profile Level 6 tiju 118 posts since
Oct 17, 2007
2. Re: Cloning graphical objects Apr 17, 2008 8:01 AM
in response to: rhh

Wow! This helps

{curl 6.0 applet}
{let frm:Frame = {Frame
width = 5cm,
height = 2cm,
background = "green"
}
}
{let btn:CommandButton = {CommandButton
{on Action do
{print-graphic frm}
}
}
}
{let vb:VBox = {VBox
halign = "center",
frm,
btn
}
}
{value vb}


But, it is not working in my project:( I am loosing my graphical objects from the screen upon a call to {print-graphic}. Have to dig out what might have happened. Anyway, thanks Bert

Click to view rhh's profile Curl rhh 29 posts since
Oct 12, 2007
3. Re: Cloning graphical objects Apr 17, 2008 9:00 AM
I'm sorry, I think my previous answer was too hasty when I said that print-graphic would put your object back into the graphical hierarchy where it had been. Apparently print-graphic doesn't do this, so you will need to do it yourself. Probably the simplest way to arrange for that is to put a Frame around the object that you actually want to print, so you can add your object back as the child of that Frame after you are finished printing it. Putting it all together, your application would look something like this:


{curl 6.0 applet}

{let frm:Frame = {Frame
                    width = 5cm,
                    height = 2cm,
                    background = "green"
                }
}

{let holder-frame:Frame = {Frame frm}

{let btn:CommandButton = {CommandButton
                             {on Action do
                                 {print-graphic frm}
                                 {holder-frame.add frm}
                             }
                         }
}

{let vb:VBox = {VBox
                   halign = "center",
                   holder-frame,
                   btn
               }
}

{value vb}


When the print-graphic procedure attaches frm to its print root frame, that causes frm to be detached from the VBox that was originally the parent of frm. The holder-frame provides a known attachment point where you can reattach frm after Curl has finished printing it.

-Bert
Click to view Kamal's profile Curl Kamal 149 posts since
Oct 17, 2007
4. Re: Cloning graphical objects Apr 17, 2008 3:11 PM

The print-graphic proc does put the object back to the graphical hierarchy where the object previously belonged. Try your example and I am pretty sure that the "green" frame will be inside the View.

However, if you detach an object yourself, and then call print-graphic, the print-graphic proc will have no way to find where to put it once it is done. Kindly check your code and see if the object is detached before print-graphic is called. Maybe you are putting the graphic that you want to print in a Frame (detached frame) before calling the print-graphic proc.

--Kamal

Click to view tiju's profile Level 6 tiju 118 posts since
Oct 17, 2007
5. Re: Cloning graphical objects Apr 17, 2008 11:18 PM
in response to: Kamal
Indeed, I got the green frame inside the view itself for the above program.