diff --git a/samoJ/src/core/Clip_algorithm.java b/samoJ/src/core/Clip_algorithm.java index 02f4f90..7be759d 100755 --- a/samoJ/src/core/Clip_algorithm.java +++ b/samoJ/src/core/Clip_algorithm.java @@ -4,8 +4,8 @@ import java.util.Map; import samoJ.Coord; -import samoJ.PrimitiveLine; import samoJ.Shape; +import samoJ.PrimitiveLine.Line; public class Clip_algorithm{ @@ -25,7 +25,7 @@ public static LinkedList simple_clip(float xBL, float yBL, float xTR, flo LinkedList ReturnableShapes = new LinkedList(); for (Shape shape : theShapes.values()){ - for (PrimitiveLine snap_line : shape.getSnapLines()){ + for (Line snap_line : shape.getSnapLines()){ Coord c1 = snap_line.getC1(); float x1 = c1.getX(); float y1 = c1.getY(); diff --git a/samoJ/src/core/GL_base.java b/samoJ/src/core/GL_base.java index a24aae8..f5a6133 100755 --- a/samoJ/src/core/GL_base.java +++ b/samoJ/src/core/GL_base.java @@ -8,7 +8,7 @@ import samoJ.Circle; import samoJ.GroupShape; -import samoJ.Line; +import samoJ.ShapeLine; import samoJ.ObjectMode; import samoJ.Shape; @@ -35,26 +35,11 @@ public class GL_base { static public ShaderState st; static private GLArrayDataServer interleavedVBO; static private GLArrayDataServer dynamic_interleavedVBO; - ///static public IntBuffer bufferName = GLBuffers.newDirectIntBuffer(1); - ///static public IntBuffer vertexArrayName = GLBuffers.newDirectIntBuffer(1); - ///static public IntBuffer DbufferName = GLBuffers.newDirectIntBuffer(1); - ///static public IntBuffer DvertexArrayName = GLBuffers.newDirectIntBuffer(1); - /** - * Variable for uniform location in shader program - */ - ///static private int current_scale_location; - ///static private int general_matrix_location; - //static int[] vbo_buffer = new int[2]; - //static int[] color_buffer = new int[1]; - public static int N = 100000;// number of vertices + public static int N = 10;// number of lines - //static DoubleBuffer fbVertices; - //static DoubleBuffer fbColores; - // static double[] vertices = new double[N * 3]; /** - * Array for coordinates, colors and widths: - * [x1,y1,z1, r1,g1,b1, w1] + * Arrays for coordinates, colors and widths: */ static float[] colors; static float[] vertices; @@ -64,10 +49,6 @@ public class GL_base { static float[] dynamic_vertices; static float[] dynamic_widths; static FloatBuffer fbDinamicVertices; - //public static double[] dinamic_vertices = new double[4 * 3]; - - // public static LinkedList list1 = new LinkedList(); - // public static double[] list1 = {}; public static float[] general_matrix = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; @@ -76,11 +57,11 @@ public class GL_base { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; public static PMVMatrix pmvMatrix; + /** + * Variable for uniform location in shader program + */ public static GLUniformData pmvMatrixUniform; public static GLUniformData current_scaleUniform; - //public static PMVMatrix general_matrix; - //public static GLUniformData general_matrixUniform; - public static boolean unproject_flag = false; public static float[] unproject = new float[2]; @@ -90,7 +71,6 @@ public class GL_base { public static float projmatrix[] = new float[16]; public static int viewport[] = new int[4]; - //public static GL2 gl2; public static GL3 gl3; public static boolean gl_init = false; public static boolean update_data_flag = false; @@ -103,7 +83,6 @@ public void make_shaders(ShaderState st) { final ShaderCode fp0 = ShaderCode.create(gl3, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(), "shaders", "shaders/bin", "fragment", true); - vp0.defaultShaderCustomization(gl3, true, true); gp0.defaultShaderCustomization(gl3, true, true); fp0.defaultShaderCustomization(gl3, true, true); @@ -122,13 +101,6 @@ public void make_shaders(ShaderState st) { pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmvMatrix.glLoadIdentity(); update_pmv_matrix(); - /* - general_matrix = new PMVMatrix(); - general_matrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); - general_matrix.glLoadIdentity(); - general_matrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); - general_matrix.glLoadIdentity(); - */ } public static void update_pmv_matrix() { @@ -141,22 +113,8 @@ public static void update_pmv_matrix() { throw new GLException("Error setting PMVMatrix in shader: "+st); } } - /* - public static void update_general_matrix() { - general_matrixUniform = new GLUniformData("general_matrix", 4, 4, general_matrix.glGetPMvMatrixf()); // P, Mv - st.ownUniform(general_matrixUniform); - st.uniform(gl3, general_matrixUniform); - - st.ownUniform(general_matrixUniform); - if(!st.uniform(gl3, general_matrixUniform)) { - throw new GLException("Error setting general_matrix in shader: "+st); - } - } - */ + public static void init(GL3 gl2, int width, int height) { - - //gl2.glMatrixMode(GL3.GL_MODELVIEW); - //gl2.glLoadIdentity(); Random randomGenerator = new Random(); long t1, t2, t_total =0; @@ -182,8 +140,8 @@ public static void init(GL3 gl2, int width, int height) { y1 = 100; x2 = 450; y2 = 150;*/ - new Line(ObjectMode.New_object, x1, y1, 0, x2, y2, 0, - Values.stipple_factor, dash_type.Continuous, Values.color, Values.width); + new ShapeLine(ObjectMode.New_object, x1, y1, 0, x2, y2, 0, + Values.stipple_factor, dash_type.CENTER, Values.color, 2); //Color_rgb c = new Color_rgb(200, 0, 100); //new Line(ObjectMode.New_object, x1+100, y1+100, 0, x2+100, y2+100, 0, // Values.stipple_factor, dash_type.Continuous, c, Values.width); @@ -194,7 +152,7 @@ public static void init(GL3 gl2, int width, int height) { x2 = randomGenerator.nextInt(1200); y2 = randomGenerator.nextInt(1200); */ - //new Circle(ObjectMode.New_object, x1, y1, 0, x2, y2, 0, Values.color); + new Circle(ObjectMode.New_object, x1, y1, 0, x2, y2, 0, Values.color, Values.width); //Global_var.theShapes.add(new Circle(x1, y1, 0, x2, y2, 0)); //Global_var.theShapes.put(new Line(x1, y1, 0, x2, y2, 0)); @@ -251,9 +209,9 @@ public static void update_data(){ gl_init = true; } - FloatArrayList listFloat = new FloatArrayList(Global_var.N_primLines*6);//(N*200); - FloatArrayList listFloatColor = new FloatArrayList(Global_var.N_primLines*3); - FloatArrayList listFloatWidth = new FloatArrayList(Global_var.N_primLines*2); + FloatArrayList listFloat = new FloatArrayList(Global_var.N_DrawableLines*6);//(N*200); + FloatArrayList listFloatColor = new FloatArrayList(Global_var.N_DrawableLines*3); + FloatArrayList listFloatWidth = new FloatArrayList(Global_var.N_DrawableLines*2); for (Shape sh : Global_var.theShapes.values()) { listFloat.addAll(sh.toListFloat()); @@ -263,9 +221,9 @@ public static void update_data(){ vertices = listFloat.elements(); colors = listFloatColor.elements(); widths = listFloatWidth.elements(); - interleavedVBO = GLArrayDataServer.createGLSLInterleaved(3 + 3 + 1, GL3.GL_FLOAT, false, Global_var.N_primLines*2*3, + interleavedVBO = GLArrayDataServer.createGLSLInterleaved(3 + 3 + 1, GL3.GL_FLOAT, false, Global_var.N_DrawableLines*2*3, GL3.GL_STATIC_DRAW); - update_vao(interleavedVBO, vertices, colors, widths, Global_var.N_primLines); + update_vao(interleavedVBO, vertices, colors, widths, Global_var.N_DrawableLines); } public static void update_dynamic_data(){ @@ -276,7 +234,6 @@ public static void update_dynamic_data(){ float[] colors = d.get_colors(); float[] widths = d.get_widths(); Global_var.N_dynamic_lines = vertices.length/6; - //print_a(vertices); dynamic_interleavedVBO = GLArrayDataServer.createGLSLInterleaved(3 + 3 + 1, GL3.GL_FLOAT, false, Global_var.N_dynamic_lines*2*3, GL3.GL_STATIC_DRAW); @@ -303,19 +260,10 @@ public static void update_vao(GLArrayDataServer iVBO, float[] vertices, float[] ib.put(colors, i * 3, 3); ib.put(widths, i * 1, 1); } - /* - float[] e = new float[ib.capacity()]; - ib.get(e); - for (int i =0; i snapLines) { + LinkedList snapLines) { if (snapLines.size() != 2) return null; return getLinesIntersection(snapLines.getFirst(), snapLines.getLast()); } - public static Coord getLinesIntersection(PrimitiveLine s1, - PrimitiveLine s2) { + public static Coord getLinesIntersection(Line s1, + Line s2) { float x1 = s1.getC1().getX(); float y1 = s1.getC1().getY(); @@ -105,7 +105,7 @@ public static SnapCoord get_snap(float[] cursor_coords, if (shapes.size() < 2) return null; - LinkedList theOtherSnapLines = new LinkedList(); + LinkedList theOtherSnapLines = new LinkedList(); for (Shape sh1: shapes.subList(1, shapes.size())) // without last element { Shape sh = shapes.get(shapes.indexOf(sh1)-1); @@ -113,10 +113,10 @@ public static SnapCoord get_snap(float[] cursor_coords, theOtherSnapLines.addAll(sh.getSnapLines()); // Find Intersection - for (PrimitiveLine p1 : sh1.getSnapLines()) + for (Line p1 : sh1.getSnapLines()) // from current shape - for (PrimitiveLine p2 : theOtherSnapLines) { // List + for (Line p2 : theOtherSnapLines) { // List // from // other // shapes diff --git a/samoJ/src/core/Global_var.java b/samoJ/src/core/Global_var.java index 8abd9e3..a8f8565 100755 --- a/samoJ/src/core/Global_var.java +++ b/samoJ/src/core/Global_var.java @@ -150,6 +150,6 @@ public class Global_var { */ public static Integer current_ID = 0; - public static int N_primLines = 0; + public static int N_DrawableLines = 0; public static int N_dynamic_lines = 0; } \ No newline at end of file diff --git a/samoJ/src/modules/standard_objects/line/draw_line_3.java b/samoJ/src/modules/standard_objects/line/draw_line_3.java index 2e162f7..dcdf34b 100755 --- a/samoJ/src/modules/standard_objects/line/draw_line_3.java +++ b/samoJ/src/modules/standard_objects/line/draw_line_3.java @@ -4,7 +4,7 @@ import modules.base_draw_entities.Interface_base_draw; import open_dxf_lib.dash_type; -import samoJ.Line; +import samoJ.ShapeLine; import samoJ.ObjectMode; import modules.base_draw_entities.Class_base_draw; import core.Values; @@ -28,7 +28,7 @@ public void mouse_move_event() { } public void create(ObjectMode mode){ - new Line(mode, x1, y1, 0, x2, y2, 0, Values.stipple_factor, Values.current_dash, Values.color, Values.width); + new ShapeLine(mode, x1, y1, 0, x2, y2, 0, Values.stipple_factor, Values.current_dash, Values.color, Values.width); } } \ No newline at end of file diff --git a/samoJ/src/samoJ/Circle.java b/samoJ/src/samoJ/Circle.java index 21f97e3..fab99ec 100755 --- a/samoJ/src/samoJ/Circle.java +++ b/samoJ/src/samoJ/Circle.java @@ -1,6 +1,7 @@ package samoJ; import open_dxf_lib.Color_rgb; +import samoJ.PrimitiveLine.DrawableLine; public class Circle extends Shape { Coord theCenter; @@ -41,18 +42,18 @@ public void create_circle() { for (int i = 0; i < points.length - 2; i += 2) { - add(new PrimitiveLine(points[i], points[i + 1], 0, + add(new DrawableLine(points[i], points[i + 1], 0, points[i + 2], points[i + 3], 0, color, width)); } // last segment from last to first point - add(new PrimitiveLine(points[points.length - 2], + add(new DrawableLine(points[points.length - 2], points[points.length - 1], 0, points[0], points[1], 0, color, width)); // Crossers in center of circle float s = Radius / 20; - add(new PrimitiveLine(theCenter.getX() - s, theCenter.getY(), 0, theCenter.getX() + s, theCenter.getY(), 0, color, width)); - add(new PrimitiveLine(theCenter.getX(), theCenter.getY() - s, 0, theCenter.getX(), theCenter.getY() + s, 0, color, width)); - + add(new DrawableLine(theCenter.getX() - s, theCenter.getY(), 0, theCenter.getX() + s, theCenter.getY(), 0, color, width)); + add(new DrawableLine(theCenter.getX(), theCenter.getY() - s, 0, theCenter.getX(), theCenter.getY() + s, 0, color, width)); + } /** diff --git a/samoJ/src/samoJ/Coord.java b/samoJ/src/samoJ/Coord.java index 2f7df4a..edfa32c 100755 --- a/samoJ/src/samoJ/Coord.java +++ b/samoJ/src/samoJ/Coord.java @@ -19,7 +19,7 @@ public Coord(float x, float y) { this(x, y, 0); } - Coord(float x, float y, float z) { + public Coord(float x, float y, float z) { c = FloatArrayList.wrap(new float[] {x, y, z}); } diff --git a/samoJ/src/samoJ/GroupShape.java b/samoJ/src/samoJ/GroupShape.java index c8633bb..59c51ba 100755 --- a/samoJ/src/samoJ/GroupShape.java +++ b/samoJ/src/samoJ/GroupShape.java @@ -1,6 +1,8 @@ package samoJ; import it.unimi.dsi.fastutil.floats.FloatArrayList; +import samoJ.PrimitiveLine.DrawableLine; +import samoJ.PrimitiveLine.Line; import java.util.Collections; import java.util.LinkedList; @@ -24,8 +26,8 @@ public GroupShape(ObjectMode mode, List shapes) { @Override - public List getSnapLines() { - List retList = new LinkedList(); + public List getSnapLines() { + List retList = new LinkedList(); for (Shape sh:shapes) { retList.addAll(sh.getSnapLines()); diff --git a/samoJ/src/samoJ/PrimitiveLine.java b/samoJ/src/samoJ/PrimitiveLine.java deleted file mode 100755 index de8a6b7..0000000 --- a/samoJ/src/samoJ/PrimitiveLine.java +++ /dev/null @@ -1,112 +0,0 @@ -package samoJ; - -import it.unimi.dsi.fastutil.floats.FloatArrayList; -import open_dxf_lib.Color_rgb; - -import java.util.ArrayList; -import java.util.LinkedList; - -import core.Global_var; - -/** - * the PrimitiveLine is a base for Shape - * - * @author E.Askadullin - * - */ -public class PrimitiveLine { - public LinkedList coords; - //2 colors for 2 coords - private Color_rgb color_1; - private Color_rgb color_2; - //line width - private int width; - - private PrimitiveLine(Coord c1, Coord c2, Color_rgb color, int width) { - - this.color_1 = this.color_2 = color; - this.width = width; - coords = new LinkedList(); - coords.add(c1); - coords.add(c2); - - } - - public PrimitiveLine(float x1, float y1, float z1, float x2, float y2, - float z2, Color_rgb color, int width) { - this(new Coord(x1, y1, z1), new Coord(x2, y2, z2), color, width); - } - - public ArrayList toList() { - ArrayList ret = new ArrayList(); - - for (Coord c : coords) - ret.addAll(c.toList()); - return ret; - } - - public float[] getX1Y1X2Y2() { - float[] r = { coords.getFirst().getX(), coords.getFirst().getY(), - coords.getLast().getX(), coords.getLast().getY() }; - return r; - } - - public FloatArrayList toListFloat() { - FloatArrayList ret = new FloatArrayList(6); - for (Coord coord : coords) - ret.addAll(coord.toListFloat()); - return ret; - - } - - public FloatArrayList toListFloatColor() { - FloatArrayList ret = new FloatArrayList(6); - FloatArrayList c1 = FloatArrayList.wrap(new float[] {color_1.get_r(), color_1.get_g(), color_1.get_b()}); - FloatArrayList c2 = FloatArrayList.wrap(new float[] {color_2.get_r(), color_2.get_g(), color_2.get_b()}); - ret.addAll(c1); - ret.addAll(c2); - return ret; - - } - - public FloatArrayList toListFloatData() { - FloatArrayList ret = new FloatArrayList(); - ret.addAll(coords.get(0).toListFloat()); - ret.addAll(FloatArrayList.wrap(new float[] {color_1.get_r(), color_1.get_g(), color_1.get_b()})); - ret.add(width); - ret.addAll(coords.get(1).toListFloat()); - ret.addAll(FloatArrayList.wrap(new float[] {color_2.get_r(), color_2.get_g(), color_2.get_b()})); - ret.add(width); - return ret; - } - public FloatArrayList toListFloatWidth() { - FloatArrayList ret = new FloatArrayList(2); - ret.add(width); - ret.add(width); - return ret; - } - - public Coord getC1() { - return coords.getFirst(); - } - - public Coord getC2() { - return coords.getLast(); - } - - // Get middle point (Coord) - public SnapCoord getMiddle() { - return new SnapCoord(SnapType.MidPoint, (getC1().getX() + getC2() - .getX()) / 2, (getC1().getY() + getC2().getY()) / 2, (getC1() - .getZ() + getC2().getZ()) / 2); - } - - public int getWidth() { - return this.width; - } - - @Override - public String toString() { - return coords.toString(); - } -} diff --git a/samoJ/src/samoJ/PrimitiveLine/DrawableLine.java b/samoJ/src/samoJ/PrimitiveLine/DrawableLine.java new file mode 100755 index 0000000..a4b3559 --- /dev/null +++ b/samoJ/src/samoJ/PrimitiveLine/DrawableLine.java @@ -0,0 +1,61 @@ +package samoJ.PrimitiveLine; + +import it.unimi.dsi.fastutil.floats.FloatArrayList; +import open_dxf_lib.Color_rgb; +import samoJ.Coord; + +import core.Global_var; + +/** + * the DrawableLine is a base for Shape, is visible Line for OpenGL rendering. + * Global_var.N_DrawableLines - is very important variable, it is number of all DrawableLines in all Shapes, + * each line must increase/decrease this value for stable GL rendering! + * + * @author E.Askadullin + * + */ +public class DrawableLine extends Line{ + //2 colors for 2 coords + private Color_rgb color_1; + private Color_rgb color_2; + /** + * line width + */ + private int width; + + private DrawableLine(Coord c1, Coord c2, Color_rgb color, int width) { + super(c1, c2); + this.color_1 = this.color_2 = color; + this.width = width; + Global_var.N_DrawableLines++; + } + + public DrawableLine(float x1, float y1, float z1, float x2, float y2, + float z2, Color_rgb color, int width) { + this(new Coord(x1, y1, z1), new Coord(x2, y2, z2), color, width); + } + + public FloatArrayList toListFloatColor() { + FloatArrayList ret = new FloatArrayList(6); + FloatArrayList c1 = FloatArrayList.wrap(new float[] {color_1.get_r(), color_1.get_g(), color_1.get_b()}); + FloatArrayList c2 = FloatArrayList.wrap(new float[] {color_2.get_r(), color_2.get_g(), color_2.get_b()}); + ret.addAll(c1); + ret.addAll(c2); + return ret; + } + + public FloatArrayList toListFloatWidth() { + FloatArrayList ret = new FloatArrayList(2); + ret.add(width); + ret.add(width); + return ret; + } + + public int getWidth() { + return this.width; + } + + public void delDrawableLine() { + Global_var.N_DrawableLines--; + } +} diff --git a/samoJ/src/samoJ/PrimitiveLine/Line.java b/samoJ/src/samoJ/PrimitiveLine/Line.java new file mode 100644 index 0000000..accaf97 --- /dev/null +++ b/samoJ/src/samoJ/PrimitiveLine/Line.java @@ -0,0 +1,67 @@ +package samoJ.PrimitiveLine; + +import java.util.ArrayList; +import java.util.LinkedList; + +import it.unimi.dsi.fastutil.floats.FloatArrayList; +import samoJ.Coord; +import samoJ.SnapCoord; +import samoJ.SnapType; + +public class Line { + public LinkedList coords; + + public Line(Coord c1, Coord c2) { + coords = new LinkedList(); + coords.add(c1); + coords.add(c2); + + } + + public Line(float x1, float y1, float z1, float x2, float y2, + float z2) { + this(new Coord(x1, y1, z1), new Coord(x2, y2, z2)); + } + + public ArrayList toList() { + ArrayList ret = new ArrayList(); + + for (Coord c : coords) + ret.addAll(c.toList()); + return ret; + } + + public float[] getX1Y1X2Y2() { + float[] r = { coords.getFirst().getX(), coords.getFirst().getY(), + coords.getLast().getX(), coords.getLast().getY() }; + return r; + } + + public FloatArrayList toListFloat() { + FloatArrayList ret = new FloatArrayList(6); + for (Coord coord : coords) + ret.addAll(coord.toListFloat()); + return ret; + + } + + public Coord getC1() { + return coords.getFirst(); + } + + public Coord getC2() { + return coords.getLast(); + } + + // Get middle point (Coord) + public SnapCoord getMiddle() { + return new SnapCoord(SnapType.MidPoint, (getC1().getX() + getC2() + .getX()) / 2, (getC1().getY() + getC2().getY()) / 2, (getC1() + .getZ() + getC2().getZ()) / 2); + } + + @Override + public String toString() { + return coords.toString(); + } +} diff --git a/samoJ/src/samoJ/Shape.java b/samoJ/src/samoJ/Shape.java index cf0760b..e75e853 100755 --- a/samoJ/src/samoJ/Shape.java +++ b/samoJ/src/samoJ/Shape.java @@ -3,6 +3,8 @@ import it.unimi.dsi.fastutil.floats.FloatArrayList; import open_dxf_lib.Color_rgb; import open_dxf_lib.DXF_file; +import samoJ.PrimitiveLine.DrawableLine; +import samoJ.PrimitiveLine.Line; import java.util.ArrayList; import java.util.Collections; @@ -10,7 +12,6 @@ import java.util.List; import core.Global_var; -import core.Values; /** @@ -22,9 +23,9 @@ public class Shape { // Displayed Lines - LinkedList PrimLines; + LinkedList PrimLines; // Snap lines - LinkedList SnapLines; + LinkedList SnapLines; // Snap points LinkedList SnapPoints; // Properties @@ -39,8 +40,8 @@ public class Shape { public int ID; public Shape(ObjectMode mode) { - PrimLines = new LinkedList(); - SnapLines = new LinkedList(); + PrimLines = new LinkedList(); + SnapLines = new LinkedList(); SnapPoints = new LinkedList(); if(mode == ObjectMode.New_object){ Global_var.theShapes.put(Global_var.current_ID, this); @@ -52,14 +53,14 @@ public Shape(ObjectMode mode) { protected ArrayList toList() { ArrayList ret = new ArrayList(); - for (PrimitiveLine p : PrimLines) + for (DrawableLine p : PrimLines) ret.addAll(p.toList()); return ret; } public FloatArrayList toListFloat() { FloatArrayList ret = new FloatArrayList(PrimLines.size()*6); - for (PrimitiveLine p : PrimLines) { + for (DrawableLine p : PrimLines) { ret.addAll(p.toListFloat()); } @@ -68,26 +69,19 @@ public FloatArrayList toListFloat() { public FloatArrayList toListFloatColor() { FloatArrayList ret = new FloatArrayList(PrimLines.size()*6); - for (PrimitiveLine p : PrimLines) + for (DrawableLine p : PrimLines) ret.addAll(p.toListFloatColor()); return ret; } public FloatArrayList toListFloatWidth() { FloatArrayList ret = new FloatArrayList(PrimLines.size()*2); - for (PrimitiveLine p : PrimLines) + for (DrawableLine p : PrimLines) ret.addAll(p.toListFloatWidth()); return ret; } - public FloatArrayList toListFloatData() { - FloatArrayList ret = new FloatArrayList(); - for (PrimitiveLine p : PrimLines) - ret.addAll(p.toListFloatData()); - return ret; - } - - protected void add(PrimitiveLine theP) { + protected void add(DrawableLine theP) { PrimLines.add(theP); } @@ -97,7 +91,7 @@ protected void add(PrimitiveLine theP) { * * @param new_snap_line */ - protected void add_snap_line(PrimitiveLine new_snap_line) { + protected void add_snap_line(Line new_snap_line) { SnapLines.add(new_snap_line); /* * for (Coord c : new_snap_line.coords) SnapPoints.add(new @@ -106,7 +100,7 @@ protected void add_snap_line(PrimitiveLine new_snap_line) { SnapPoints.add(new_snap_line.getMiddle()); } - public List getSnapLines() { + public List getSnapLines() { return Collections.unmodifiableList(SnapLines); } @@ -118,7 +112,7 @@ public List getSnapPoints(SnapType st) { case EndPoint: { - for (PrimitiveLine p : SnapLines) { + for (Line p : SnapLines) { for (Coord c : p.coords) { ll.add(new SnapCoord(st, c)); } @@ -139,7 +133,13 @@ public float[] getPreviewData(){ } public void save_to_DXF(DXF_file f){ - + } + + public void delShape(){ + for (DrawableLine p : PrimLines) { + p.delDrawableLine(); + } + } // EXAMPLE diff --git a/samoJ/src/samoJ/Line.java b/samoJ/src/samoJ/ShapeLine.java similarity index 80% rename from samoJ/src/samoJ/Line.java rename to samoJ/src/samoJ/ShapeLine.java index 878ca3b..d7f70cb 100755 --- a/samoJ/src/samoJ/Line.java +++ b/samoJ/src/samoJ/ShapeLine.java @@ -4,9 +4,12 @@ import open_dxf_lib.Color_rgb; import open_dxf_lib.DXF_file; import open_dxf_lib.dash_type; +import samoJ.PrimitiveLine.DrawableLine; +import samoJ.PrimitiveLine.Line; + import java.lang.Math; -public class Line extends Shape { +public class ShapeLine extends Shape { // Vars of Line protected float x1; protected float y1; @@ -30,7 +33,7 @@ public Line(ObjectMode mode, double x1, double y1, double z1, double x2, double //System.out.println("mask="+mask); }*/ // Dashed or solid line - public Line(ObjectMode mode, float x1, float y1, float z1, float x2, float y2, float z2, float factor, + public ShapeLine(ObjectMode mode, float x1, float y1, float z1, float x2, float y2, float z2, float factor, dash_type dash, Color_rgb color, int width) { super(mode); this.x1 = x1; @@ -45,7 +48,7 @@ public Line(ObjectMode mode, float x1, float y1, float z1, float x2, float y2, this.width = width; this.mode = mode; formPrimitiveLines(); - add_snap_line(new PrimitiveLine(x1, y1, z1, x2, y2, z2, color, width)); + add_snap_line(new Line(x1, y1, z1, x2, y2, z2)); if(mode == ObjectMode.Preview_object){ Global_var.preview_object_vertices = super.getPreviewData(); } @@ -54,8 +57,7 @@ public Line(ObjectMode mode, float x1, float y1, float z1, float x2, float y2, void formPrimitiveLines() { if (dash.mask == null || dash.mask.length == 0) { - add(new PrimitiveLine(x1, y1, z1, x2, y2, z2, color, width)); - if(mode == ObjectMode.New_object) Global_var.N_primLines++; + add(new DrawableLine(x1, y1, z1, x2, y2, z2, color, width)); /* float h = 4 * Values.current_scale; float x = x2 - x1; @@ -117,7 +119,7 @@ void formPrimitiveLines() { } if ((i % 2) == 0) { // System.out.println("draw"); - add(new PrimitiveLine(x_begin, y_begin, z1, x_end, + add(new DrawableLine(x_begin, y_begin, z1, x_end, y_end, z2, color, width)); } i++; @@ -137,12 +139,5 @@ public void save_to_DXF(DXF_file f) { f.put_line(x1, y1, x2, y2, dash.dash, factor, color, width); } - /* - public static void main(String[] args) { - // TODO Auto-generated method stub - Line l1 = new Line(1, 2, 3, 5, 7, 9); - System.out.println(l1.toList()); - Line l2 = new Line(100, 200, 0, 500, 700, 0, 50, new int[]{1,1}); - System.out.println(l2.toList()); - }*/ + } diff --git a/samoJ/src/samoJ/VboTest.java b/samoJ/src/samoJ/VboTest.java index 2b9e3b5..4e62b1c 100755 --- a/samoJ/src/samoJ/VboTest.java +++ b/samoJ/src/samoJ/VboTest.java @@ -3,19 +3,20 @@ import java.util.ArrayList; import it.unimi.dsi.fastutil.floats.FloatArrayList; +import samoJ.PrimitiveLine.DrawableLine; public class VboTest { - ArrayList primLines; + ArrayList primLines; FloatArrayList vertFloat; public VboTest() { // TODO Auto-generated constructor stub - primLines = new ArrayList(); + primLines = new ArrayList(); vertFloat = new FloatArrayList(); } - public boolean add(PrimitiveLine pp) { + public boolean add(DrawableLine pp) { if (primLines.contains(pp)) return false; else { @@ -28,7 +29,7 @@ public boolean add(PrimitiveLine pp) { } } - public boolean remove(PrimitiveLine pp) { + public boolean remove(DrawableLine pp) { int ind = primLines.indexOf(pp); if (ind >= 0) { // Here need transaction TO DO @@ -40,7 +41,7 @@ public boolean remove(PrimitiveLine pp) { return false; } - public boolean contains(PrimitiveLine pp) { + public boolean contains(DrawableLine pp) { return primLines.contains(pp); }