瀏覽代碼

实体与可用区域相交检测

duh 6 年之前
父節點
當前提交
a733bf3605
共有 4 個文件被更改,包括 58 次插入52 次删除
  1. 31 31
      phxb/utils/GetAllModule.py
  2. 9 4
      phxb/utils/conf.py
  3. 13 12
      phxb/utils/getarray.py
  4. 5 5
      phxb/utils/main.py

+ 31 - 31
phxb/utils/GetAllModule.py

@@ -7,30 +7,32 @@ import math
 acad = Autocad(create_if_not_exists = False)
 # 组件实体点位置
 positoins={}
+currentPosition = {}
 # 组件使用点位置
 useAreaPositions={}
 # acad.prompt("Hello, Autocad from Python\n")
-# print(acad.doc.Name)
+# conf.myprint(acad.doc.Name)
 def printObjects():
   #遍历cad图形对象
   for obj in acad.iter_objects():
-    print(obj.ObjectName)
+    conf.myprint(obj.ObjectName)
 def printBlockObjects():
   #遍历cad图形对象
   for obj in acad.iter_objects("BlockReference"):
-    print(obj.name,obj.HasAttributes)
+    conf.myprint(obj.name,obj.HasAttributes)
     if obj.HasAttributes:
       attrs = obj.GetAttributes()
       for attrib in attrs:
-        print("  {}: {}".format(attrib.TagString, attrib.TextString))
+        conf.myprint("  {}: {}".format(attrib.TagString, attrib.TextString))
 def printTheTypeObject(type):
   #按类型查找出所有某种图元
   for text in acad.iter_objects(type):
-    print(text.name)
+    conf.myprint(text.name)
 def moveBlockReference(position):
-  print(conf.moduleLengths)
+  positoins.clear()
+  conf.myprint(conf.moduleLengths)
   for blockReference in acad.iter_objects("BlockReference"):
-    print(blockReference.name)
+    conf.myprint(blockReference.name)
     for item in conf.names:
       if(blockReference.name == item):
         moveBlockReferenceToWall(blockReference,position[conf.names.index(item)])
@@ -38,7 +40,7 @@ def moveBlockReferenceToWall(blockReference,wallIndex):
   wallIndex = int(wallIndex)
   blockReference.rotate(APoint(blockReference.InsertionPoint),0.5*(wallIndex+1)*math.pi)
   blockIndex = conf.names.index(blockReference.name)
-  print("begin to put ",blockReference.name)
+  conf.myprint("begin to put ",blockReference.name)
   if(wallIndex == 0):
     blockReference.move(APoint(blockReference.InsertionPoint),APoint(0+conf.moduleLengths[blockIndex]+conf.roomUsedLengths[0],0))
     conf.roomUsedLengths[0] = conf.roomUsedLengths[0]+conf.moduleLengths[blockIndex];
@@ -53,17 +55,21 @@ def moveBlockReferenceToWall(blockReference,wallIndex):
     conf.roomUsedLengths[3] = conf.roomUsedLengths[3]+conf.moduleLengths[blockIndex];
   checkPositionIntersect = tempStoragePosition(blockReference.InsertionPoint[0],blockReference.InsertionPoint[1],wallIndex,blockIndex)
   if(checkPositionIntersect == 0):
-    print("wallIndex=",wallIndex,blockReference.name," not walkable......")
+    conf.myprint("wallIndex=",wallIndex,blockReference.name," not walkable......")
 # 根据新顺序移动模块
 def moveBlockReferenceWithNewIndex(position,moduleIndex):
-  print(conf.moduleLengths)
+  positoins.clear()
+  conf.myprint(conf.moduleLengths)
   blockReferences = []
   for blockReference in acad.iter_objects("BlockReference"):
-    print(blockReference.name)
+    conf.myprint(blockReference.name)
     for item in conf.names:
       if(blockReference.name == item):
         blockReferences.append(blockReference)
   for index in moduleIndex:
+    currentPosition[0] = position
+    currentPosition[1] = moduleIndex
+    currentPosition[2] = moduleIndex.index(index)
     moveBlockReferenceToWall(blockReferences[index],position[moduleIndex.index(index)])
 # 重置已使用墙的长度
 def resetConfUsed():
@@ -84,14 +90,13 @@ def resetModuleIndex():
 # 判断位置是否可行
 def isWorkable(position):
   resetConfUsed()
-  positoins.clear()
-  print("position=",position)
+  conf.myprint("position=",position)
   needLength=[0]*4
   for positionIndex in range(len(position)):
     wallIndex = int(position[positionIndex])
     needLength[wallIndex]+=conf.moduleLengths[positionIndex]
     if(needLength[wallIndex]+conf.roomUsedLengths[wallIndex] > conf.roomLengths[wallIndex%2]):
-      print(needLength[wallIndex]+conf.roomUsedLengths[wallIndex],conf.roomLengths[math.floor(wallIndex/2)],wallIndex)
+      conf.myprint(needLength[wallIndex]+conf.roomUsedLengths[wallIndex],conf.roomLengths[math.floor(wallIndex/2)],wallIndex)
       return 0
   return 1
 # 获取组件的四点坐标
@@ -103,7 +108,7 @@ def getCenterPoint(wallIndex, x, y, blockIndex):
   usePointPosition = conf.moduleUsePoint[blockIndex]
   useCenterPointPosition = conf.moduleUseCenterPoint[blockIndex]
   pointA = (x,y)
-  print("insertPoint=",x,y)
+  conf.myprint("insertPoint=",x,y)
   if(wallIndex == 0):
     pointB = (x,y+width)
     pointC = (x-height,y+width)
@@ -141,9 +146,9 @@ def getCenterPoint(wallIndex, x, y, blockIndex):
     centerPointOffset = (width,height)
     useCenterPointOffset = (useWidth,useHeight)
   positoin = [centerPoint,centerPointOffset,usePoint,useCenterPoint,useCenterPointOffset];
-  print(wallIndex,width,height)
+  conf.myprint(wallIndex,width,height)
   drawPointCircle((pointA, pointB, pointC, pointD, centerPoint, usePoint, useCenterPoint))
-  print(positoin)
+  conf.myprint(positoin)
   return positoin
 # 打印辅助点
 def drawPointCircle(points):
@@ -156,13 +161,12 @@ def tempStoragePosition(x,y,wallIndex,blockIndex):
   for item in positoins:
     # 判断实体是否相交
     result = isPositionFeasible(positoin,positoins[item],0)
-    if(result == 0):
-      positoins.clear()
-      return result
-    else:
+    if(result == 1):
       # 判断可用区域是否与实体相交
       usePosition = (positoin[3],positoin[4])
       result = isPositionFeasible(usePosition,positoins[item],1)
+    if(result == 0):
+      return result
   if(result == 1):
     positoins[len(positoins)] = positoin
   return result
@@ -174,15 +178,11 @@ def isPositionFeasible(position1,position2,type):
     acad.model.AddLine(APoint(position1[0][0],position1[0][1]),APoint(position2[0][0],position2[0][1]))
     acad.model.AddCircle(APoint(position1[0][0],position1[0][1]), 50)
     areaName = "实体"
-  if(abs(position1[0][0]-position2[0][0]) < (position1[1][0]+position2[1][0])/2):
-    print(areaName,"begin to check y")
-    if(abs(position1[0][1]-position2[0][1]) < (position1[1][1]+position2[1][1])/2):
-      print(areaName,"sorry! can not put here","position1=",position1,"position2=",position2)
-      return 0
-    print(areaName,"can put here 1")
-    return 1
+  if(abs(position1[0][0]-position2[0][0]) < (position1[1][0]+position2[1][0])/2 and abs(position1[0][1]-position2[0][1]) < (position1[1][1]+position2[1][1])/2):
+    conf.myprint(areaName,"sorry! can not put here",currentPosition,"position1=",position1,"position2=",position2)
+    return 0
   else:
-    print(areaName,"can put here 2")
+    conf.myprint(areaName,"can put here")
     return 1
 # printObjects()
 # printBlockObjects()
@@ -191,5 +191,5 @@ def isPositionFeasible(position1,position2,type):
 # moveBlockReference('222')
 # a=[0,1,2]
 # moveBlockReferenceWithNewIndex('001',a)
-# print(isWorkable('222'))
-# getCenterPoint(3,2200,0,1)
+# conf.myprint(isWorkable('222'))
+getCenterPoint(3,4162.85,0,2)

+ 9 - 4
phxb/utils/conf.py

@@ -6,11 +6,16 @@ roomUsedLengths = [1200,0,0,1000]
 roomLengths = (3000,2200)
 # 模块长度
 humenLenght = 650
-moduleLengths = (800,1000,900)
+moduleLengths = (800,1000,850)
 moduleHeights = (1500,550,700)
-moduleUsePoint = [[1200,800],[550,500],[700,450]]
-moduleUseCenterPoint = [[1200,800+humenLenght/2],[550+humenLenght/2,500],[700+humenLenght/2,450]]
+moduleUsePoint = [[1050,800],[550,500],[700,450]]
+moduleUseCenterPoint = [[1050,800+humenLenght/2],[550+humenLenght/2,500],[700+humenLenght/2,450]]
 moduleUseLength = (500,1000,900)
 doorLength=800
 # 门与左右上下的间距
-doorAlign=[100,200,200,0]
+doorAlign=[100,200,200,0]
+
+needPrint = True
+def myprint(self, *args, sep=' ', end='\n', file=None):
+    if(needPrint):
+      print(self, *args, sep=' ', end='\n', file=None)

+ 13 - 12
phxb/utils/getarray.py

@@ -1,4 +1,5 @@
 import math
+from utils import conf
 #获取阶乘列表
 def jieChen(n):
     myArray = {};
@@ -35,7 +36,7 @@ def jieChenNumber(n):
 #辗转相除法进行进制转化
 def changeInt2Str(i,m):
     if(not isinstance(m,int)):
-        print("m is not int",m)
+        conf.myprint("m is not int",m)
         return
     if(m*i == 0):
         return "0";
@@ -60,7 +61,7 @@ def getAllPosition(m, n):
             itemIndex = "0"+itemIndex
         allArray[index]=itemIndex
         index = index+1
-    print(allArray)
+    conf.myprint(allArray)
     return allArray
 #获取组合数列表的排列总数
 def getAllArrayNumber(m,n):
@@ -68,7 +69,7 @@ def getAllArrayNumber(m,n):
     allArray = getAllPosition(m, n)
     for item in allArray:
         total = getitemIndexArrayNumber(allArray[item],m,n)+total
-        print("total=",total)
+        conf.myprint("total=",total)
     return total
 #获取单个组合的各边重复项
 def getitemIndexArray(itemIndex,m,n):
@@ -81,7 +82,7 @@ def getitemIndexArray(itemIndex,m,n):
                 indexNum = indexNum + 1
             index = index+1
         a[item]=indexNum
-    print("a=",a)
+    conf.myprint("a=",a)
     return a
 #获取单个组合的各边重复项及其位置
 def getitemIndexArrayAndIndex(itemIndex,m,n):
@@ -94,7 +95,7 @@ def getitemIndexArrayAndIndex(itemIndex,m,n):
                 indexList.append(index)
             index = index+1
         a[item]=indexList
-    print("a=",a)
+    conf.myprint("a=",a)
     return a
 #如[0, 1, 3]转成6个位置[0,1,3],[0,3,1],[1,0,3],[1,3,0],[3,0,1],[3,1,0]
 def getPositionArray(positions):
@@ -115,7 +116,7 @@ def getitemIndexArrayAndPosition(itemIndex,m,n):
             newItem[0] = a[item]
             newItem[1] = jiechenarray(a[item])
             a[item] = newItem
-    print("getitemIndexArrayAndPosition=",a)
+    conf.myprint("getitemIndexArrayAndPosition=",a)
     return a
 #获取模板的插入顺序,必定大于1个
 def getModuleIndex(itemIndex,m,n):
@@ -156,7 +157,7 @@ def getitemIndexAndPositionArray(itemIndex, m, n):
         aItem[0] = indexNum
         aItem[1]=positions
         a[item]=aItem
-    print("a=",a)
+    conf.myprint("a=",a)
     return a
 #获取单个组合的各边重复项的排列数
 def getitemIndexArrayNumber(itemIndex,m,n):
@@ -170,16 +171,16 @@ def getitemIndexArrayNumber(itemIndex,m,n):
         itemIndexArrayNumber = 1
     return itemIndexArrayNumber
 # result = changeInt2Str(14,3);
-# print(result)
+# conf.myprint(result)
 getAllPosition(3, 3)
 # getAllArrayNumber(4,3)
 # getitemIndexArray("11213",5,5)
 # getitemIndexArrayAndIndex("11213",5,5)
-# print(getModuleIndex("11212",5,5))
+# conf.myprint(getModuleIndex("11212",5,5))
 # getitemIndexArrayAndPosition("11213",5,5)
 # getitemIndexAndPositionArray("113", 4, 3)
 # number = getitemIndexArrayNumber("11143",5,5)
-# print(number)
+# conf.myprint(number)
 # getAllArrayNumber(11,2)
-# print(jiechenarray(3))
-# print(getPositionArray([0,3,4]))
+# conf.myprint(jiechenarray(3))
+# conf.myprint(getPositionArray([0,3,4]))

+ 5 - 5
phxb/utils/main.py

@@ -145,10 +145,10 @@ def moveMultipleTemplate(fileName,position,moduleIndex):
 # openOriginFile()
 # tempStorageModules()
 # print(is_open(_rootPath+_originFile))
-# myprocess(4, 3)
+myprocess(4, 3)
 # openFile(r"F:\autocad_temp\newfile023.dwg")
 # is_open(r"F:\autocad_temp\origin11.dwg")
-acad = Autocad(create_if_not_exists = False)
-acad.prompt("Hello, Autocad from Python\n")
-print(acad.doc.Name)
-moveMultipleTemplate(r"F:\autocad_temp\newfile\newfile.dwg",'002',[0,2,1])
+# acad = Autocad(create_if_not_exists = False)
+# acad.prompt("Hello, Autocad from Python\n")
+# print(acad.doc.Name)
+# moveMultipleTemplate(r"F:\autocad_temp\newfile\newfile.dwg",'001',[0,1,2])