Permalink
Browse files

Abstract ZeroCoordsProtection in Shape. Add circle and arc snap lists…

… to Shape, Circle and Arc snap entities.
  • Loading branch information...
VVS1864 committed Mar 1, 2018
1 parent ebd8fd7 commit 17bd741f0992f5f3a56f131e57f4b6ff826efd2d
@@ -2,7 +2,7 @@
import modules.base_draw_entities.Class_base_draw;
import samoJ.ShapeLine;
import samoJ.Circle;
import samoJ.ShapeCircle;
import samoJ.ObjectMode;
public class draw_circle_3 extends Class_base_draw{
@@ -17,7 +17,7 @@ public void run() {
@Override
public void create(ObjectMode mode){
new Circle(mode, x1, y1, 0.0f, x2, y2, 0.0f, core.values.color, core.values.width);
new ShapeCircle(mode, x1, y1, 0.0f, x2, y2, 0.0f, core.values.color, core.values.width);
}
}
@@ -66,6 +66,13 @@ public void addLines() {
}
}
@Override
public boolean zeroCoordsProtection() {
return shapes.size() != 0;
}
}
@@ -0,0 +1,38 @@
package samoJ.PrimitiveArc;
import samoJ.Coord;
import samoJ.PrimitiveCircle.Circle;
/**
* Entity for snap to arc, one of basic snap entities (line, circle, arc)
* @author vlad
*
*/
public class Arc extends Circle {
private float start;
private float extent;
/**
*
* @param Center
* @param Radius
* @param start angle counterclockwise (0 = 360 = 3 o'clock)
* @param extent angle counterclockwise (0 = 360 = 3 o'clock)
*/
public Arc(Coord Center, float Radius, float start, float extent) {
super(Center, Radius);
this.start = start;
this.extent = extent;
}
public Arc(float x1, float y1, float z1, float Radius, float start, float extent) {
this(new Coord(x1, y1, z1), Radius, start, extent);
}
public float getStart() {
return start;
}
public float getExtent() {
return extent;
}
}
@@ -0,0 +1,30 @@
package samoJ.PrimitiveCircle;
import samoJ.Coord;
/**
* Entity for snap to circle, one of basic snap entities (line, circle, arc)
* @author vlad
*
*/
public class Circle {
private Coord Center;
private float Radius;
public Circle(Coord Center, float Radius) {
this.Center = Center;
this.Radius = Radius;
}
public Circle(float x1, float y1, float z1, float Radius) {
this(new Coord(x1, y1, z1), Radius);
}
public Coord getCenter() {
return Center;
}
public float getRadius() {
return Radius;
}
}
@@ -12,6 +12,7 @@
* each line must increase/decrease this value for stable GL rendering!
*
* @author E.Askadullin
* @author vlad
*
*/
@@ -7,7 +7,11 @@
import samoJ.Coord;
import samoJ.SnapCoord;
import samoJ.SnapType;
/**
* Entity for basic Line snap and data. Is not drawable line.
* @author vlad
*
*/
public class Line {
public LinkedList<Coord> coords;
View
@@ -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.PrimitiveArc.Arc;
import samoJ.PrimitiveCircle.Circle;
import samoJ.PrimitiveLine.DrawableLine;
import samoJ.PrimitiveLine.Line;
@@ -27,6 +29,10 @@
LinkedList<DrawableLine> PrimLines;
// Snap lines
LinkedList<Line> SnapLines;
// Snap circles
LinkedList<Circle> SnapCircles;
// Snap circles
LinkedList<Arc> SnapArcs;
// Snap points
LinkedList<SnapCoord> SnapPoints;
// Properties
@@ -46,11 +52,15 @@ public Shape(ObjectMode mode) {
//Standard begin
PrimLines = new LinkedList<DrawableLine>();
SnapLines = new LinkedList<Line>();
SnapCircles = new LinkedList<Circle>();
SnapArcs = new LinkedList<Arc>();
SnapPoints = new LinkedList<SnapCoord>();
this.mode = mode;
}
public void createShape() {
//protection from Zero Shape (override is each Shape)
if (!zeroCoordsProtection()) return;
//Special for each Shape
addLines();
@@ -66,6 +76,12 @@ else if(mode == ObjectMode.Preview_object){
}
abstract public void addLines();
/**
* Protection from zero shapes as circle with Radius = 0, line with length = 0, e.t.c.
* @return false - is Zero Shape!
*/
abstract public boolean zeroCoordsProtection();
protected ArrayList<Float> toList() {
ArrayList<Float> ret = new ArrayList<Float>();
@@ -116,13 +132,29 @@ protected void add_snap_line(Line new_snap_line) {
SnapPoints.add(new_snap_line.getMiddle());
}
protected void add_snap_circle(Circle new_snap_circle) {
SnapCircles.add(new_snap_circle);
}
protected void add_snap_arc(Arc new_snap_arc) {
SnapArcs.add(new_snap_arc);
}
protected void add_snap_point(SnapCoord new_snap_point) {
SnapPoints.add(new_snap_point);
}
public List<Line> getSnapLines() {
return Collections.unmodifiableList(SnapLines);
}
public List<Circle> getSnapCircles() {
return Collections.unmodifiableList(SnapCircles);
}
public List<Arc> getSnapArces() {
return Collections.unmodifiableList(SnapArcs);
}
public List<SnapCoord> getSnapPoints(SnapType st) {
List<SnapCoord> ll = new LinkedList<SnapCoord>();
@@ -3,9 +3,10 @@
import core.Core;
import open_dxf_lib.Color_rgb;
import open_dxf_lib.DXF_file;
import samoJ.PrimitiveCircle.Circle;
import samoJ.PrimitiveLine.DrawableLine;
public class Circle extends Shape {
public class ShapeCircle extends Shape {
private Core core = Core.c;
Coord theCenter;
float Radius;
@@ -19,7 +20,7 @@
* @param z1
*/
public Circle(ObjectMode mode, float r, float x1, float y1, float z1, Color_rgb color, int width) {
public ShapeCircle(ObjectMode mode, float r, float x1, float y1, float z1, Color_rgb color, int width) {
super(mode);
this.theCenter = new Coord(x1, y1, z1);
this.Radius = r;
@@ -28,8 +29,8 @@ public Circle(ObjectMode mode, float r, float x1, float y1, float z1, Color_rgb
super.createShape(); //Standard procedure of create
}
public Circle(ObjectMode mode, float x2, float y2, float z2, float rx, float ry, float rz, Color_rgb color, int width) {
this(mode, (float)Math.round(Math.sqrt((rx - x2) * (rx - x2) +(ry - y2)*(ry - y2))), x2, y2, z2, color, width);
public ShapeCircle(ObjectMode mode, float x2, float y2, float z2, float rx, float ry, float rz, Color_rgb color, int width) {
this(mode, (float)Math.sqrt((rx - x2) * (rx - x2) + (ry - y2)*(ry - y2)), x2, y2, z2, color, width);
/*int xd = rx - x2;
int yd = ry - y2;
int r = (int) Math.sqrt(xd * xd + yd * yd);
@@ -43,6 +44,7 @@ public void addLines() {
create_circle();
// Snap center
add_snap_point(new SnapCoord(SnapType.MidPoint, theCenter));
add_snap_circle(new Circle(theCenter, Radius));
}
public void create_circle() {
@@ -102,6 +104,11 @@ public static void main(String[] args) {
System.out.println(c.toList());
}*/
@Override
public boolean zeroCoordsProtection() {
return Radius != 0;
}
}
@@ -37,9 +37,9 @@ public ShapeLine(ObjectMode mode, float x1, float y1, float z1, float x2, float
dash_type dash, Color_rgb color, int width) {
super(mode);
//protection from Zero Line
if (x1 == x2 && y1 == y2 && z1 == z2) {
return;
}
//if (x1 == x2 && y1 == y2 && z1 == z2) {
// return;
//}
this.x1 = x1;
this.y1 = y1;
this.z1 = z1;
@@ -144,5 +144,11 @@ public void save_to_DXF(DXF_file f) {
f.put_line(x1, y1, x2, y2, dash.dash, factor, color, width);
}
@Override
public boolean zeroCoordsProtection() {
return !(x1 == x2 && y1 == y2 && z1 == z2);
}
}

0 comments on commit 17bd741

Please sign in to comment.