Browse Source

调整模板和阴影

duh 6 years ago
parent
commit
e824f1c353

+ 5 - 2
src/main/java/controller/MyPanel.java

@@ -8,6 +8,7 @@ import config.subConfig.TemplateConfig;
 import model.Axis;
 import model.Door;
 import model.Room;
+import model.template.Template;
 import utils.TemplateUtils;
 
 import javax.swing.*;
@@ -63,14 +64,16 @@ public class MyPanel extends JPanel{
         TemplateUtils.setRoom(room);
         TemplateUtils.checkYiZhiArray(templateList);
         for(TemplateConfig templateConfig : templateList){
-            TemplateUtils.drawTemplate(templateConfig,g);
+            Template template = new Template(templateConfig);
+            TemplateUtils.drawTemplate(template,g);
         }
     }
     private void drawTemplateAndMove(Room room, Graphics g) {
         List<TemplateConfig> templateList = config.getTemplates();
         TemplateUtils.setRoom(room);
         TemplateConfig templateConfig = templateList.get(1);
-        TemplateUtils.drawTemplate(templateConfig,g);
+        Template template = new Template(templateConfig);
+        TemplateUtils.drawTemplate(template,g);
     }
     private void drawRoom(Room room, Graphics g){
         room.drawSelf(g);

+ 11 - 0
src/main/java/model/Point.java

@@ -0,0 +1,11 @@
+package model;
+
+import model.template.ModuleInRoom;
+
+/**
+ * @author duh
+ * @create 2018/7/21 15:25
+ * @email duh@elab-plus.com
+ **/
+public class Point extends ModuleInRoom{
+}

+ 59 - 0
src/main/java/model/template/ModuleInRoom.java

@@ -0,0 +1,59 @@
+package model.template;
+
+import model.Room;
+
+/**
+ * @author duh
+ * @create 2018/7/21 14:59
+ * @email duh@elab-plus.com
+ **/
+public class ModuleInRoom {
+    private Room room;
+    protected String name;
+    //x坐标
+    protected int x;
+    //y坐标
+    protected int y;
+    //旋转角度
+    protected int scale;
+
+    public Room getRoom() {
+        return room;
+    }
+
+    public void setRoom(Room room) {
+        this.room = room;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getX() {
+        return x;
+    }
+
+    public void setX(int x) {
+        this.x = x;
+    }
+
+    public int getY() {
+        return y;
+    }
+
+    public void setY(int y) {
+        this.y = y;
+    }
+
+    public int getScale() {
+        return scale;
+    }
+
+    public void setScale(int scale) {
+        this.scale = scale;
+    }
+}

+ 65 - 1
src/main/java/model/template/Template.java

@@ -1,9 +1,73 @@
 package model.template;
 
+import config.subConfig.TemplateConfig;
+import config.subConfig.TemplateShadowConfig;
+import model.ModuleInAxis;
+
+import java.awt.*;
+import java.util.List;
+
 /**
  * @author duh
  * @create 2018/7/20 20:12
  * @email duh@elab-plus.com
  **/
-public class Template {
+public class Template extends ModuleInRoom {
+    private String name;
+    private int length;
+    private int width;
+    private List<Integer> alignWall;
+    private TemplateShadowConfig shadow;
+
+    public Template(TemplateConfig templateConfig) {
+        this.name = templateConfig.getName();
+        length = templateConfig.getLength();
+        width = templateConfig.getWidth();
+        alignWall = templateConfig.getAlignWall();
+        shadow = templateConfig.getShadow();
+        x = templateConfig.getX();
+        y = templateConfig.getY();
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getLength() {
+        return length;
+    }
+
+    public void setLength(int length) {
+        this.length = length;
+    }
+
+    public int getWidth() {
+        return width;
+    }
+
+    public void setWidth(int width) {
+        this.width = width;
+    }
+
+    public List<Integer> getAlignWall() {
+        return alignWall;
+    }
+
+    public void setAlignWall(List<Integer> alignWall) {
+        this.alignWall = alignWall;
+    }
+
+    public TemplateShadowConfig getShadow() {
+        return shadow;
+    }
+
+    public void setShadow(TemplateShadowConfig shadow) {
+        this.shadow = shadow;
+    }
 }

+ 86 - 0
src/main/java/model/template/TemplateShadow.java

@@ -0,0 +1,86 @@
+package model.template;
+
+import config.subConfig.TemplateShadowConfig;
+import model.Point;
+
+import java.util.List;
+
+/**
+ * @author duh
+ * @create 2018/7/21 15:16
+ * @email duh@elab-plus.com
+ **/
+public class TemplateShadow {
+    private Template template;
+    private int x;
+    private int y;
+    private int width;
+    private int direct;
+    private int radis;
+    private List<Point> points;
+
+    public TemplateShadow(Template template, TemplateShadowConfig config) {
+        this.template = template;
+        x = config.getX();
+        y = config.getY();
+        width = config.getWidth();
+        direct = config.getDirect();
+        radis = config.getRadis();
+    }
+
+    public Template getTemplate() {
+        return template;
+    }
+
+    public void setTemplate(Template template) {
+        this.template = template;
+    }
+
+    public int getX() {
+        return x;
+    }
+
+    public void setX(int x) {
+        this.x = x;
+    }
+
+    public int getY() {
+        return y;
+    }
+
+    public void setY(int y) {
+        this.y = y;
+    }
+
+    public int getWidth() {
+        return width;
+    }
+
+    public void setWidth(int width) {
+        this.width = width;
+    }
+
+    public int getDirect() {
+        return direct;
+    }
+
+    public void setDirect(int direct) {
+        this.direct = direct;
+    }
+
+    public int getRadis() {
+        return radis;
+    }
+
+    public void setRadis(int radis) {
+        this.radis = radis;
+    }
+
+    public List<Point> getPoints() {
+        return points;
+    }
+
+    public void setPoints(List<Point> points) {
+        this.points = points;
+    }
+}

+ 11 - 10
src/main/java/utils/TemplateUtils.java

@@ -5,6 +5,7 @@ import config.subConfig.TemplateConfig;
 import config.subConfig.TemplateShadowConfig;
 import constant.Constant;
 import model.Room;
+import model.template.Template;
 
 import java.awt.*;
 import java.util.ArrayList;
@@ -18,23 +19,23 @@ import java.util.List;
 public class TemplateUtils {
     private static Room room;
     private static AxisConfig axisPointConfig;
-    public static void drawTemplate(TemplateConfig template, Graphics g){
+    public static void drawTemplate(Template template, Graphics g){
         if(null == room){
             System.out.println("--------------room is not exist !!");
             return;
         }
         drawTemplateName(template,g);
         drawTemplateSelf(template,g);
-//        drawShadow(template,g);
+        drawShadow(template,g);
     }
 
-    private static void drawTemplateName(TemplateConfig template, Graphics g) {
+    private static void drawTemplateName(Template template, Graphics g) {
         int x1 = room.getX()+template.getX()+template.getLength()/2;
         int y1 = room.getY()+template.getY()+template.getWidth()/2;
         g.drawString(template.getName(), x1, y1);
     }
 
-    private static void drawTemplateSelf(TemplateConfig template, Graphics g){
+    private static void drawTemplateSelf(Template template, Graphics g){
         int length = template.getLength();
         int width = template.getWidth();
         int x1 = room.getX()+template.getX();
@@ -72,7 +73,7 @@ public class TemplateUtils {
      * @param g
      * @param rotateRange
      */
-    private static void drawTemplateSelfByRotate(TemplateConfig template, Graphics g,int rotateRange){
+    private static void drawTemplateSelfByRotate(Template template, Graphics g,int rotateRange){
         routeTemplateConfig(template,rotateRange);
     }
 
@@ -81,7 +82,7 @@ public class TemplateUtils {
      * @param template
      * @param rotateRange
      */
-    private static void routeTemplateConfig(TemplateConfig template, int rotateRange) {
+    private static void routeTemplateConfig(Template template, int rotateRange) {
         int length = template.getLength();
         int width = template.getWidth();
         changeTemplateAlignWall(template,rotateRange);
@@ -97,7 +98,7 @@ public class TemplateUtils {
                 break;
         }
     }
-    public static void changeTemplateAlignWall(TemplateConfig template,int rotateRange){
+    public static void changeTemplateAlignWall(Template template,int rotateRange){
         List<Integer> list = template.getAlignWall();
         List<Integer> newlist = new ArrayList<>();
         for(int i = 0;i<list.size();i++){
@@ -118,10 +119,10 @@ public class TemplateUtils {
         template.setX(template.getX()+x);
         template.setY(template.getY()+y);
     }
-    private static void drawShadow(TemplateConfig template, Graphics g){
+    private static void drawShadow(Template template, Graphics g){
         TemplateShadowConfig shadow = template.getShadow();
-        int cx = room.getX()+shadow.getX();
-        int cy = room.getY()+shadow.getY();
+        int cx = room.getX()+template.getX()+shadow.getX();
+        int cy = room.getY()+template.getY()+shadow.getY();
         int x1,y1,x2,y2;
         Graphics2D g2d = (Graphics2D) g.create();
         g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);