On Nov 2, 2010, at 3:36 PM, Tim Edwards wrote:

> Kuba,
> 
>    I just uploaded to CVS for xcircuit-3.7 the code that enables the
> capability to parameterize the position of a polygon, spline, or
> path element in its entirity, not just a single point.  You can either
> merge this code in now, or wait for me to do something about color
> inheritance and parameterization.

I can wait and would definitely appreciate the color inheritance work!!

Here's what I'm doing now: I'm slowly porting everything from the element
down to C++ -- that means that new/delete operators work as expected, members
can be copied/assigned to without worrying about intricacies of the underlying
data type, etc. Some of this work was done but was crashing, now it doesn't 
anymore.

So far I have all elements do the right thing with custom copy constructor
and operator=. This is because some underlying members are C-style and need
handholding; when all member variables behave like they should then
the C++ compiler will generate all the copying and assignment code for us.

My goal is to have C++-clean element classes that don't have custom
operator= nor copy constructor, with built-in parent pointer, that can be used
without worrying about underlying details.

This is done in parallel with implementing a drawing context that decouples
UI and transient data from persistent data. Basically if it goes into the disk 
file,
it belongs in the element, otherwise it doesn't.

I will use smart pointers to keep track of elements outside of the normal
parent-child tree. Say the selection mechanism: you shouldn't need to manually
tweak selection list simply because you deleted an element, the selection should
take note automagically. C++ with boost headers gives you tools to do all that.

My goal is to have following C++ code compile and work as you'd expect it to --
by that I mean that there will be no memory leaks nor other hidden surprises. 
Pretty
much "if it compiles it won't crash" kind of approach, for some value of 
"sanity" of
the code.

#include <QApplication>
#include <QPrinter>
#include "xcircuit.h"

int main(int argc, char ** argv) {

QApplication app(argc, argv);

Context c; // drawing context
Object page; // an empty page

typedef XPoint $;

XPoint points1[] = { $(10,20), $(50,80), $(20,40); }
page.add(new Polygon(points1)); // add() takes ownership
XPoint points2[] = { $(10,20), $(50,80), $(20,40), $(60,30); }
page.add(new Spline(points2));

c.select(page[0]); // select first object on the page

QPrinter printer;
QPainter painter(&printer);
c.setPainter(painter); // we want to print it out
c.setGrid(true);
page.draw(c); // page gets drawn using context's paint device
printer.newPage(); // "eject" the page 

// here things go out of scope and get destroyed in reverse order of
// construction, thus: painter, then printer, then points, then page, then
// context, then application

// at the point where page is gone but context still exists, the context
// will be valid and the selection will be empty as the polygon is already
// gone -- so no surprises; also the page will delete the Polygon and
// Spline since it owns them, so no leaks here.
}

Cheers, Kuba
_______________________________________________
Xcircuit-dev mailing list
[email protected]
http://www.opencircuitdesign.com/mailman/listinfo/xcircuit-dev

Reply via email to