|
@@ -1,12 +1,14 @@
|
|
|
package utils;
|
|
|
|
|
|
import config.subConfig.AxisConfig;
|
|
|
-import config.subConfig.RoomConfig;
|
|
|
import config.subConfig.TemplateConfig;
|
|
|
import config.subConfig.TemplateShadowConfig;
|
|
|
+import constant.Constant;
|
|
|
import model.Room;
|
|
|
|
|
|
import java.awt.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* @author duh
|
|
@@ -23,7 +25,7 @@ public class TemplateUtils {
|
|
|
}
|
|
|
drawTemplateName(template,g);
|
|
|
drawTemplateSelf(template,g);
|
|
|
- drawShadow(template,g);
|
|
|
+// drawShadow(template,g);
|
|
|
}
|
|
|
|
|
|
private static void drawTemplateName(TemplateConfig template, Graphics g) {
|
|
@@ -33,16 +35,89 @@ public class TemplateUtils {
|
|
|
}
|
|
|
|
|
|
private static void drawTemplateSelf(TemplateConfig template, Graphics g){
|
|
|
+ int length = template.getLength();
|
|
|
+ int width = template.getWidth();
|
|
|
int x1 = room.getX()+template.getX();
|
|
|
int y1 = room.getY()+template.getY();
|
|
|
- int x2 = x1+template.getLength();
|
|
|
- int y2 = y1+template.getWidth();
|
|
|
+ int x2 = x1+length;
|
|
|
+ int y2 = y1+width;
|
|
|
Graphics2D g2d = (Graphics2D) g.create();
|
|
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
g2d.setColor(Color.RED);
|
|
|
- g2d.drawRect(x1,y1,template.getLength(),template.getWidth());
|
|
|
+ g2d.drawRect(x1,y1,length,width);
|
|
|
+ //绘制贴墙边
|
|
|
+ List<Integer> alignWall = template.getAlignWall();
|
|
|
+ for (int alignWallValue : alignWall){
|
|
|
+ switch (alignWallValue){
|
|
|
+ case 1:
|
|
|
+ g2d.fillRect(x1,y1+ Constant.CLOSE_WALL_LINE_WIDTH/2,length,Constant.CLOSE_WALL_LINE_WIDTH);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ g2d.fillRect(x1+length-Constant.CLOSE_WALL_LINE_WIDTH/2,y1,length,Constant.CLOSE_WALL_LINE_WIDTH);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ g2d.fillRect(x1,y1- Constant.CLOSE_WALL_LINE_WIDTH/2,length,Constant.CLOSE_WALL_LINE_WIDTH);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ g2d.fillRect(x1-Constant.CLOSE_WALL_LINE_WIDTH/2,y1,Constant.CLOSE_WALL_LINE_WIDTH,width);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
g2d.dispose();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 绕接入点逆时针旋转rotateRange度 目前支持90的倍数 0:0 1:90 2:180 3:270
|
|
|
+ * @param template
|
|
|
+ * @param g
|
|
|
+ * @param rotateRange
|
|
|
+ */
|
|
|
+ private static void drawTemplateSelfByRotate(TemplateConfig template, Graphics g,int rotateRange){
|
|
|
+ routeTemplateConfig(template,rotateRange);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 旋转
|
|
|
+ * @param template
|
|
|
+ * @param rotateRange
|
|
|
+ */
|
|
|
+ private static void routeTemplateConfig(TemplateConfig template, int rotateRange) {
|
|
|
+ int length = template.getLength();
|
|
|
+ int width = template.getWidth();
|
|
|
+ changeTemplateAlignWall(template,rotateRange);
|
|
|
+ switch (rotateRange){
|
|
|
+ case 1:
|
|
|
+ template.setY(template.getY()-length);
|
|
|
+ template.setLength(width);
|
|
|
+ template.setWidth(length);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ template.setX(template.getX()-length);
|
|
|
+ template.setY(template.getY()-width);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public static void changeTemplateAlignWall(TemplateConfig template,int rotateRange){
|
|
|
+ List<Integer> list = template.getAlignWall();
|
|
|
+ List<Integer> newlist = new ArrayList<>();
|
|
|
+ for(int i = 0;i<list.size();i++){
|
|
|
+ int alignWall = list.get(i);
|
|
|
+ alignWall = alignWall%4 + 1;
|
|
|
+ newlist.add(alignWall);
|
|
|
+ }
|
|
|
+ template.setAlignWall(newlist);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 平移
|
|
|
+ * @param template
|
|
|
+ * @param x,y
|
|
|
+ */
|
|
|
+ private static void routeTemplateConfig(TemplateConfig template, int x,int y) {
|
|
|
+ x = x*Constant.ENLARGE/Constant.NARROW;
|
|
|
+ y = y*Constant.ENLARGE/Constant.NARROW;
|
|
|
+ template.setX(template.getX()+x);
|
|
|
+ template.setY(template.getY()+y);
|
|
|
+ }
|
|
|
private static void drawShadow(TemplateConfig template, Graphics g){
|
|
|
TemplateShadowConfig shadow = template.getShadow();
|
|
|
int cx = room.getX()+shadow.getX();
|
|
@@ -71,6 +146,30 @@ public class TemplateUtils {
|
|
|
g2d.dispose();
|
|
|
}
|
|
|
|
|
|
+ public static boolean checkYiZhiArray(List<TemplateConfig> templateConfigs){
|
|
|
+ int templateTotalLength = 0;
|
|
|
+ for(TemplateConfig templateConfig : templateConfigs){
|
|
|
+ List<Integer> alignWallList = templateConfig.getAlignWall();
|
|
|
+ int length = templateConfig.getLength();
|
|
|
+ int width = templateConfig.getWidth();
|
|
|
+ if(alignWallList.size() == 1){
|
|
|
+ int alignWall = alignWallList.get(0);
|
|
|
+ if(alignWall%2 == 1){
|
|
|
+ templateTotalLength += length;
|
|
|
+ }else {
|
|
|
+ templateTotalLength+=width;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ templateTotalLength+= (length<=width)?length:width;
|
|
|
+ }
|
|
|
+ System.out.println("templateTotalLength=" + templateTotalLength);
|
|
|
+ }
|
|
|
+ System.out.println("room.getLength()=" + room.getLength());
|
|
|
+ return templateTotalLength<=room.getLength();
|
|
|
+ }
|
|
|
+ public static void drawTemplates(List<TemplateConfig> templateConfigs){
|
|
|
+// for
|
|
|
+ }
|
|
|
public static void setRoom(Room room) {
|
|
|
TemplateUtils.room = room;
|
|
|
}
|