Browse Source

获取排列数

duh 7 years ago
parent
commit
fad211073b

+ 0 - 0
phxb/__init__.py


+ 5 - 5
phxb/test.py

@@ -6,13 +6,13 @@ acad = Autocad(create_if_not_exists = True)
 acad.prompt("Hello, Autocad from Python\n")
 print(acad.doc.Name)
 
-p1 = APoint(0, 0)#点的位置坐标
-p2 = APoint(50, 25)
-for i in range(5):
+p1 = APoint(0, 300)#点的位置坐标
+p2 = APoint(500, 250)
+for i in range(50):
     text = acad.model.AddText('大家好 %s!' % i, p1, 1.5)#添加文本
     acad.model.AddLine(p1, p2)#添加线
-    acad.model.AddCircle(p1, 10)#添加圆
-    p1.y += 10
+    acad.model.AddCircle(p1, 100)#添加圆
+    p1.y += 100
 
 dp = APoint(10, 0)
 #打印点信息

+ 5 - 2
phxb/elab/utils/GetAllModule.py

@@ -1,5 +1,6 @@
 # -*- coding: UTF-8 -*-
 from pyautocad import Autocad, APoint
+import sys
 
 #这个true表示没有文件则打开一个,CAD有弹窗时会打开或者创建失败
 acad = Autocad(create_if_not_exists = True)
@@ -15,6 +16,8 @@ def printTheTypeObject(type):
     print(text.TextString, text.InsertionPoint)
 
 printObjects()
-print("-------")
+# print("syspath",sys.path)
+# gatarray.jieChen(5)
+# print("-------")
 # printTheTypeObject('Text')
-printTheTypeObject('Circle')
+printTheTypeObject('BlockReference')

+ 0 - 0
phxb/utils/__init__.py


+ 20 - 5
phxb/elab/utils/GetArray2.py

@@ -1,4 +1,5 @@
 import math
+#获取阶乘列表
 def jieChen(n):
     myArray = {};
     myArray[0] = 1;
@@ -7,6 +8,7 @@ def jieChen(n):
         myArray[i] = (i+1)*myArray[i-1];
         i = i+1
     return myArray;
+#获取指定数的阶乘
 def jieChenNumber(n):
     if(n <= 1):
         return 1;
@@ -28,7 +30,7 @@ def changeInt2Str(i,m):
     for item in myarray :
         result=str(myarray[item])+result
     return result
-#获取组合数
+#获取组合数列表
 def getAllArray(m,n):
     allArray = {}
     max = math.pow(m,n)
@@ -40,6 +42,15 @@ def getAllArray(m,n):
         allArray[index]=itemIndex
         index = index+1
     print(allArray)
+    return allArray
+#获取组合数列表的排列总数
+def getAllArrayNumber(m,n):
+    total = 0
+    allArray = getAllArray(m,n)
+    for item in allArray:
+        total = getitemIndexArrayNumber(allArray[item],n)+total
+        print("total=",total)
+    return total
 #获取单个组合的各边重复项
 def getitemIndexArray(itemIndex,n):
     a = {};
@@ -51,8 +62,9 @@ def getitemIndexArray(itemIndex,n):
                 indexNum = indexNum + 1
             index = index+1
         a[item]=indexNum
-    print(a)
+    print("a=",a)
     return a
+#获取单个组合的各边重复项的排列数
 def getitemIndexArrayNumber(itemIndex,n):
     itemIndexArrayNumber = 0;
     a = getitemIndexArray(itemIndex,n)
@@ -60,10 +72,13 @@ def getitemIndexArrayNumber(itemIndex,n):
         intItem = int(a[item])
         if(intItem > 1):
             itemIndexArrayNumber = jieChenNumber(intItem)+itemIndexArrayNumber
+    if(itemIndexArrayNumber == 0):
+        itemIndexArrayNumber = 1
     return itemIndexArrayNumber
 # result = changeInt2Str(14,3);
 # print(result)
 # getAllArray(4,3)
-# getitemIndexArray("01200",5)
-number = getitemIndexArrayNumber("01200",5)
-print(number)
+# getitemIndexArray("51243",5)
+# number = getitemIndexArrayNumber("51243",5)
+# print(number)
+getAllArrayNumber(4,2)

+ 10 - 9
src/main/java/controller/DrawImageController.java

@@ -31,21 +31,21 @@ public class DrawImageController {
      */
     public static void saveImage(List<Integer> position) {
         AxisConfig axisConfig = config.getAxisPoint();
-        int length = axisConfig.getLength() + axisConfig.getX() + 300;
-        int width = axisConfig.getY() + 300;
+        int length = axisConfig.getLength() + axisConfig.getX() + 500;
+        int width = axisConfig.getY() + 500;
         BufferedImage bufferedImage = new BufferedImage(length,
                 width, BufferedImage.TYPE_INT_RGB);
         Graphics2D g2d = bufferedImage.createGraphics();
         drawImageContent(position, g2d);
         try {
-            ImageIO.write(bufferedImage, "jpeg", new File("E:\\config\\jpanel" + position.get(0) + position.get(1) + position.get(2) + ".jpg"));
+            ImageIO.write(bufferedImage, "jpeg", new File("E:\\config\\jpanel" + getImageNameByPosition(position) + ".jpg"));
         } catch (IOException e) {
             e.printStackTrace();
         }
     }
     private static void drawImageContent(List<Integer> position, Graphics g) {
         ModuleInAxis.setAxisPointConfig(config.getAxisPoint());
-        drawAxis(config, g);
+//        drawAxis(config, g);
         Room room = new Room(config.getRoom());
         drawRoom(room, g);
         drawImageTemplate(room, position, g);
@@ -81,11 +81,12 @@ public class DrawImageController {
     private static void drawImageTemplate(Room room, List<Integer> position, Graphics g) {
         List<TemplateConfig> templateList = config.getTemplates();
         TemplateUtils.setRoom(room);
-        boolean canYizhi = TemplateUtils.checkYiZhiArray(templateList);
-        System.out.println("can yi zhi =" + canYizhi);
-        if (canYizhi) {
-            TemplateUtils.drawTemplateWithArray(position, templateList, g);
-        }
+        TemplateUtils.drawTemplateWithArray(position, templateList, g);
+    }
+    private static String getImageNameByPosition(List<Integer> position){
+        StringBuffer sb = new StringBuffer();
+        position.forEach(x->sb.append(x));
+        return sb.toString();
     }
     public static void main(String[] args) {
         //

+ 6 - 4
src/main/java/controller/MyPanel.java

@@ -39,7 +39,6 @@ public class MyPanel extends JPanel {
         super.paintComponent(g);
         //画在panel中
         drawContent(g);
-//        drawTemplateAndMove(room,g);
     }
 
 
@@ -48,7 +47,8 @@ public class MyPanel extends JPanel {
         drawAxis(config, g);
         Room room = new Room(config.getRoom());
         drawRoom(room, g);
-        drawTemplate(room, g);
+//        drawTemplate(room, g);
+        drawTemplateAndMove(room,g);
         TemplateUtils.setTemplateIndex(0);
     }
 
@@ -93,10 +93,12 @@ public class MyPanel extends JPanel {
     private void drawTemplateAndMove(Room room, Graphics g) {
         List<TemplateConfig> templateList = config.getTemplates();
         TemplateUtils.setRoom(room);
-        TemplateConfig templateConfig = templateList.get(1);
+        TemplateConfig templateConfig = templateList.get(2);
         Template template = new Template(templateConfig);
         TemplateUtils.drawTemplate(template, g);
-        TemplateUtils.routeTemplate(template, 3);
+//        TemplateUtils.routeTemplate(template, 3);
+//        TemplateUtils.drawTemplate(template, g);
+        TemplateUtils.flippingTemplate(template,0);
         TemplateUtils.drawTemplate(template, g);
     }
 

+ 2 - 3
src/main/java/model/Door.java

@@ -1,7 +1,6 @@
 package model;
 
 import config.subConfig.DoorConfig;
-import config.subConfig.RoomConfig;
 import constant.Constant;
 
 import java.awt.*;
@@ -65,7 +64,7 @@ public class Door extends ModuleInAxis {
         this.room = room;
         int xUsedLength = x+config.getRadis()+config.getRightOutLength();
         int yUsedLength = config.getRadis();
-        room.setBottomLeft(room.getBottomLeft()-xUsedLength);
-        room.setLeftLeft(room.getLeftLeft()-yUsedLength);
+        room.setBottomUsed(room.getBottomUsed()+xUsedLength);
+        room.setLeftUsed(room.getLeftUsed()+yUsedLength);
     }
 }

+ 24 - 24
src/main/java/model/Room.java

@@ -14,10 +14,10 @@ import java.util.List;
 public class Room extends ModuleInAxis {
     private int length;
     private int width;
-    private int bottomLeft;
-    private int rightLeft;
-    private int topLeft;
-    private int leftLeft;
+    private int bottomUsed;
+    private int rightUsed;
+    private int topUsed;
+    private int leftUsed;
     public Room(){
 
     }
@@ -41,10 +41,10 @@ public class Room extends ModuleInAxis {
     }
     public List<Integer> getRoomLengthLeft(){
         List<Integer> roomLength = new ArrayList<>();
-        roomLength.add(bottomLeft);
-        roomLength.add(rightLeft);
-        roomLength.add(topLeft);
-        roomLength.add(leftLeft);
+        roomLength.add(bottomUsed);
+        roomLength.add(rightUsed);
+        roomLength.add(topUsed);
+        roomLength.add(leftUsed);
         return roomLength;
     }
     public int getLength() {
@@ -63,35 +63,35 @@ public class Room extends ModuleInAxis {
         this.width = width;
     }
 
-    public int getBottomLeft() {
-        return bottomLeft;
+    public int getBottomUsed() {
+        return bottomUsed;
     }
 
-    public void setBottomLeft(int bottomLeft) {
-        this.bottomLeft = bottomLeft;
+    public void setBottomUsed(int bottomUsed) {
+        this.bottomUsed = bottomUsed;
     }
 
-    public int getRightLeft() {
-        return rightLeft;
+    public int getRightUsed() {
+        return rightUsed;
     }
 
-    public void setRightLeft(int rightLeft) {
-        this.rightLeft = rightLeft;
+    public void setRightUsed(int rightUsed) {
+        this.rightUsed = rightUsed;
     }
 
-    public int getTopLeft() {
-        return topLeft;
+    public int getTopUsed() {
+        return topUsed;
     }
 
-    public void setTopLeft(int topLeft) {
-        this.topLeft = topLeft;
+    public void setTopUsed(int topUsed) {
+        this.topUsed = topUsed;
     }
 
-    public int getLeftLeft() {
-        return leftLeft;
+    public int getLeftUsed() {
+        return leftUsed;
     }
 
-    public void setLeftLeft(int leftLeft) {
-        this.leftLeft = leftLeft;
+    public void setLeftUsed(int leftUsed) {
+        this.leftUsed = leftUsed;
     }
 }

+ 79 - 2
src/main/java/utils/TemplateUtils.java

@@ -331,14 +331,65 @@ public class TemplateUtils {
         int twoAlignPosition = position.get(2);
         //画2边贴墙
         drawAlignTwoTemplateWithArrayPosition(g, twoAlignWall, twoAlignPosition);
+        drawAlignOneTemplateWithArrayPosition(g,oneAlignWall,position);
+    }
+
+    private static void drawAlignOneTemplateWithArrayPosition(Graphics g, List<Template> oneAlignWall, List<Integer> positions) {
+        for(int i = 0;i<oneAlignWall.size();i++){
+            Template template = oneAlignWall.get(i);
+            int position = positions.get(i);
+            drawOneAlignTemplateWithPosition(g,template,position);
+        }
+    }
+
+    private static void drawOneAlignTemplateWithPosition(Graphics g,Template template, int position) {
+        //第几条边
+        int bianIndex = 0;
+        //画的顺序
+        int drawIndex = 0;
+        //
+        if(position < 100){
+            bianIndex = position/10;
+        }else {
+            bianIndex = position/100;
+        }
+        if(bianIndex != 4){
+            routeTemplate(template,bianIndex);
+        }
+        switch (bianIndex){
+            case 1:
+                template.setX(room.getBottomUsed());
+                room.setBottomUsed(room.getBottomUsed()+Math.abs(template.getWidth()));
+                break;
+            case 2:
+                template.setX(room.getLength());
+                template.setY(room.getRightUsed());
+                room.setRightUsed(room.getRightUsed()+Math.abs(template.getLength()));
+                break;
+            case 3:
+                int thisUsed = template.getLength();
+                if(thisUsed < 0){
+                    thisUsed = -thisUsed;
+                    template.setX(thisUsed);
+                }
+                template.setX(template.getX()+room.getTopUsed());
+                template.setY(template.getY()-room.getWidth());
+                room.setTopUsed(room.getTopUsed()+thisUsed);
+                break;
+            case 4:
+                template.setY(room.getLeftUsed());
+                room.setLeftUsed(room.getLeftUsed()+Math.abs(template.getWidth()));
+                break;
+        }
+        drawTemplate(template,g);
     }
 
     private static void drawAlignTwoTemplateWithArrayPosition(Graphics g, List<Template> twoAlignWall, int twoAlignPosition) {
         int wallPointIndex = twoAlignPosition%100/10;
         int alignIndex = twoAlignPosition%10;
         Template twoAlignWallTemplate = twoAlignWall.get(0);
-        int templateX = twoAlignWallTemplate.getX();
-        int templateY = twoAlignWallTemplate.getY();
+        int templateX = 0;
+        int templateY = 0;
         System.out.println("drawAlignTwoTemplateWithArrayPosition 1 ="+templateX+","+templateY);
         switch (wallPointIndex){
             case 2:
@@ -433,4 +484,30 @@ public class TemplateUtils {
         }
         g2d.dispose();
     }
+
+    /**
+     * 翻转
+     * @param template
+     * @param type 0:x,y 1:x 2:y
+     */
+    public static void flippingTemplate(Template template,int type){
+        TemplateClearance shadow = template.getShadow();
+        switch (type){
+            case 0:
+                routeTemplateShadow(template,2);
+                changeTemplateAlignWall(template,2);
+                template.setLength(-template.getLength());
+                template.setWidth(-template.getWidth());
+                break;
+            case 1:
+                template.setWidth(template.getY()-template.getWidth());
+                shadow.setY(template.getY()-shadow.getY());
+                shadow.setDirect((shadow.getDirect()+2)%3);
+                break;
+            case 2:
+                template.setLength(template.getX()-template.getLength());
+                shadow.setX(template.getX()-shadow.getX());
+                break;
+        }
+    }
 }

+ 1 - 1
src/main/resources/config.yml

@@ -62,7 +62,7 @@ templates:
  - name: MT
    length: 700
    width: 900
-   x: 700
+   x: 1000
    y: 0
    alignWall: [4]
    shadow:

+ 3 - 3
src/test/java/utils/CalcYizhiArrayUtilsTest.java

@@ -33,7 +33,7 @@ public class CalcYizhiArrayUtilsTest {
         calcYizhiArrayUtils.setTwoAlignAllLongLength(twoAlignAllLongLength);
     }
 
-    @Ignore
+    @Test
     public void getAllArrayList() {
         System.out.println(Integer.MAX_VALUE);
         System.out.println(Integer.MIN_VALUE);
@@ -45,14 +45,14 @@ public class CalcYizhiArrayUtilsTest {
 //        list.forEach(x-> System.out.println(x));
     }
 
-    @Test
+    @Ignore
     public void calcYizhiWithOnlyOneTwoAlign() {
         System.out.println("yizhi begin");
         List<List<Integer>> list = calcYizhiArrayUtils.calcYizhiWithOnlyOneTwoAlign();
         list.forEach(x -> System.out.println(x));
         System.out.println("yizhi end");
     }
-    @Test
+    @Ignore
     public void get2Template4BianArray() {
         List<List<Integer>> list = calcYizhiArrayUtils.get2Template4BianArray();
         list.forEach(x -> System.out.println(x));