-
March 3rd, 2012, 04:39 PM
#1
Design id to store vectors for CAD program
Hello,
I am poking my head on a new design for LibreCAD (http://librecad.org) and looking for some opinions.
Let's say we have entities like lines and circles. And each entity can have a pen attached. And a pen is a color and line width. All entities needs to be manipulated through a operations interface.
All entities added to the program needs to be added through using a factory pattern.
So we end up something like (pseudo code)
class Line // for immutable objects
{
..
..
}
class MutableLine extends Line //for mutable lines
{
}
MutableLine line=factory->newLine(20,20,50,50); // Create a new line entity
line->setPen(Pen(Color("red"), 2)); // red pen, 2mm
document->addEntity(line);
MutableCircle circle=factory->newCircle(20,20,30); // Create a new line entity, default pen
line->setPen(Pen("ByLayer")); // pen set by layer
document->addEntity(circle);
// Select all entities in this box
document -> selectEntities(0,0,100,100);
// Rotate
document->operateOnSelectedEntities(OperationRotation(90));
// set Color
document->operateOnSelectedEntities(ColorOperation("red"));
// get entities (for export/saving)
List myItems=document->selectedEntities();
So, essentially I want no code to be able to operate directory on entities, unless during creation of the object (color, layer, line width etc...) so I am planning to create Mutable versions of all entities besides the immutable versions.
When requested for selected entities or all entities, I am planning to return a list of immutable objects and in fact I am planning to return a new copy so it's not possible to operate on anything directly.
The reason is that I am planning to create different storage backends swell, so I can operate on entities in a database, or shared memory... stuff like that. At least to hide the internals and provide a stable API.
My questions are:
1) Any thought on this like or don't like?
2) How can I make sure that people don't do 'tricks' casts for example to a mutable version to change objects directly?
3) Does it make sense, any place else I should look?
Poking around a bit!
Ries
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|