[Pythoncad-developer] Proposal geometry objects
CAD Application entire developed in Python
Status: Beta
Brought to you by:
matteoboscolo
From: <ger...@gm...> - 2010-02-04 21:39:45
|
Hi all, I did some thinking about the entity geometry. The current version maintains one point list where all entities make use of. I want to preserve this method because it has some advantages. But I want to change the way the entities use these points. The current version defines different geometries for each entity (segment, polyline, arc, etc.). I want to define only two different geometry objects that all entities can share. It consist of only points, no start-, end angles, center points or radius. Because there are only points in the geometry transformations can be done really quick, all points are multiplied by the same matrix. If needed the program must calculate the center point, radius and angles of circles and arcs. This is done far less often than entity drawing so this is more efficient. The main advantage is creating point lists for cairo drawing is more easy. All entities share the same geometry class, a single function is used to draw them all. It is more easy to optimize a single draw function for speed than all different functions for all entities. This excludes hatches of course which will have it own draw function. Some preliminary code: class Point(object): """ Indicates a single point with x and y ordinates (2D point) The interpretation indicates how the connection is drawn to the next point. With this construction linear and circular lines are constructed. These point objects are stored in a single table in the database. """ def __init__(self): # id of point self.__id = 0 # X ordinate self.__x = 0.0 # Y ordinate self.__y = 0.0 # interpretation connection to next point # L = linear # C = circular # None = not used (single point geometry) # more interpretation values needed for dimensions? self.__interpretation = 'L' class SGeometry(object): """ Indicates a single geometry. This is used in segment, polyline, arc, circle. examples: 1) A segment geometry consists of a list of two points. The point interpretation from the first to the second point is 'L' (linear) 2) An arc geometry consists of a list of three points. The first point is the start point of the arc, the second point is on the arc and the third point is the end point. The point interpretation from the first to the second point is 'C' (circular) The point interpretation from the second to the third point is 'C' (circular) 3) An polyline consists of a list of three or more points. The point interpretation can be 'L' (linear) or 'C' (circular) This gives the opportunity to create polylines with linear and arc segments. 4) An circle geometry consists of a list of five points. A circle is represented as two arcs where the first and fifth point are the same. The point interpretation from the first to the second point is 'C' (circular) The point interpretation from the second to the third point is 'C' (circular) For a single geometry the geometry interpretation is None. Interpretation is used for complex geometries. """ def __init__(self): # list of points ids self.__point_ids = [] # interpretation used in complex geometry # O = outer ring # I = inner ring # None = not used. self.__interpretation = None class CGeometry(object): """ Indicates a complex geometry. This is used in hatches. A hatch can contain islands. The list contains a outer ring and a inner ring (island). The rings are closed polylines (SGeometry objects). ??? Can inner rings contain other inner rings (nested islands) ??? """ def __init__(self): # list of single geometries. # order in the list is important, first a outer ring, than the inner rings self.__sgeometries = [] Even a text can have the same geometry as a segment (two points). The first point is the text location, the second point is the rotation. The distance between the first and second point is the text height. Regards, Gertwin |