|
@@ -1,6 +1,6 @@
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
from pyautocad import Autocad, APoint
|
|
|
-from utils import conf
|
|
|
+from utils import conf,MovePath
|
|
|
import math
|
|
|
|
|
|
#这个true表示没有文件则打开一个,CAD有弹窗时会打开或者创建失败
|
|
@@ -16,6 +16,8 @@ distinceWithDoor = {}
|
|
|
distinceWithOthers={}
|
|
|
# 旋转后需删除的组件
|
|
|
needDeleteBlockReferences=[]
|
|
|
+scores=[]
|
|
|
+currentScore=[]
|
|
|
# acad.prompt("Hello, Autocad from Python\n")
|
|
|
# conf.myprint(acad.doc.Name)
|
|
|
def printObjects():
|
|
@@ -34,10 +36,17 @@ def printTheTypeObject(type):
|
|
|
#按类型查找出所有某种图元
|
|
|
for text in acad.iter_objects(type):
|
|
|
conf.myprint(text.name)
|
|
|
+def addCurrentScoreToScores():
|
|
|
+ temp = []
|
|
|
+ for item in currentScore:
|
|
|
+ temp.append(item)
|
|
|
+ scores.append(temp)
|
|
|
def moveBlockReference(position):
|
|
|
positoins.clear()
|
|
|
useAreaPositions.clear()
|
|
|
conf.myprint(conf.moduleLengths)
|
|
|
+ currentScore.clear()
|
|
|
+ currentScore.append(position)
|
|
|
moveResult = 1
|
|
|
for blockReference in acad.iter_objects("BlockReference"):
|
|
|
conf.myprint(blockReference.name)
|
|
@@ -48,6 +57,9 @@ def moveBlockReference(position):
|
|
|
result = moveBlockReferenceToWall(blockReference,position[conf.names.index(item)])
|
|
|
if(result == 0):
|
|
|
moveResult = result
|
|
|
+ conf.myprint("currentScore size =",len(currentScore),",scores size=",len(scores))
|
|
|
+ addCurrentScoreToScores()
|
|
|
+ conf.myprint("scores=",scores)
|
|
|
for blockReference in needDeleteBlockReferences:
|
|
|
blockReference.delete()
|
|
|
needDeleteBlockReferences.clear()
|
|
@@ -80,6 +92,9 @@ def moveBlockReferenceWithNewIndex(position,moduleIndex):
|
|
|
moveResult = 1
|
|
|
positoins.clear()
|
|
|
useAreaPositions.clear()
|
|
|
+ currentScore.clear()
|
|
|
+ currentScore.append(position)
|
|
|
+ currentScore.append(moduleIndex)
|
|
|
conf.myprint(conf.moduleLengths)
|
|
|
blockReferences = []
|
|
|
for blockReference in acad.iter_objects("BlockReference"):
|
|
@@ -94,6 +109,9 @@ def moveBlockReferenceWithNewIndex(position,moduleIndex):
|
|
|
result = moveBlockReferenceToWall(blockReferences[index],position[moduleIndex.index(index)])
|
|
|
if(result == 0):
|
|
|
moveResult = result
|
|
|
+ conf.myprint("currentScore size =",len(currentScore),",scores size=",len(scores))
|
|
|
+ addCurrentScoreToScores()
|
|
|
+ conf.myprint("scores=",scores)
|
|
|
return moveResult
|
|
|
# 重置已使用墙的长度
|
|
|
def resetConfUsed():
|
|
@@ -239,41 +257,41 @@ def getDistince(point1,point2):
|
|
|
return math.sqrt(detarX**2+detarY**2)
|
|
|
def getDoorBeginPoint():
|
|
|
return ((conf.doorAlign[0]+conf.doorLength+conf.doorAlign[1])/2,0)
|
|
|
+def drawLines(includePoints):
|
|
|
+ lineLength = 0;
|
|
|
+ if(len(includePoints)>1):
|
|
|
+ for item in range(len(includePoints)):
|
|
|
+ if(item>0):
|
|
|
+ acad.model.AddLine(APoint(includePoints[item-1][0],includePoints[item-1][1]),APoint(includePoints[item][0],includePoints[item][1]))
|
|
|
+ lineLength += getDistince((includePoints[item-1][0],includePoints[item-1][1]),(includePoints[item][0],includePoints[item][1]))
|
|
|
+ return lineLength
|
|
|
def getDoorBeginAndModuleUsePointDistince(position,wallIndex):
|
|
|
doorBeginPoint = getDoorBeginPoint()
|
|
|
- usePoint = position[2]
|
|
|
- useCenterPoint = (position[0][0],position[0][1])
|
|
|
- d1 = getDistince(doorBeginPoint,useCenterPoint);
|
|
|
- d2 = getDistince(doorBeginPoint,usePoint)
|
|
|
- if(d1 < d2):
|
|
|
- #不可直接连接
|
|
|
- conf.myprint("wallIndex=",wallIndex)
|
|
|
- if(wallIndex == 0):
|
|
|
- # 先连c
|
|
|
- acad.model.AddLine(APoint(doorBeginPoint[0],doorBeginPoint[1]),APoint(position[0][0]-position[1][0]/2,position[0][1]+position[1][1]/2))
|
|
|
- acad.model.AddLine(APoint(position[0][0]-position[1][0]/2,position[0][1]+position[1][1]/2),APoint(usePoint[0],usePoint[1]))
|
|
|
- else:
|
|
|
- # 只有0,3需要绕过,先连b
|
|
|
- # acad.model.AddLine(APoint(doorBeginPoint[0],doorBeginPoint[1]),APoint(position[0][0]+position[1][0]/2,position[0][1]-position[1][1]/2))
|
|
|
- # acad.model.AddLine(APoint(position[0][0]+position[1][0]/2,position[0][1]-position[1][1]/2),APoint(usePoint[0],usePoint[1]))
|
|
|
- acad.model.AddLine(APoint(doorBeginPoint[0],doorBeginPoint[1]),APoint(usePoint[0],usePoint[1]-position[1][1]))
|
|
|
- else:
|
|
|
- acad.model.AddLine(APoint(doorBeginPoint[0],doorBeginPoint[1]),APoint(usePoint[0],usePoint[1]))
|
|
|
+ includePoints = MovePath.getDoorBeginAndModuleUsePointDistince(position[0][0],position[0][1],position[1][0],position[1][1],doorBeginPoint[0],doorBeginPoint[1])
|
|
|
+ currentScore.append(drawLines(includePoints))
|
|
|
+ includePoints = MovePath.getMovePath(position[0][0],position[0][1],position[1][0],position[1][1],doorBeginPoint[0],doorBeginPoint[1],position[2][0],position[2][1])
|
|
|
+ currentScore.append(drawLines(includePoints))
|
|
|
# distinceWithDoor[len(distinceWithDoor)] = getDistince(doorBeginPoint,usePoint)
|
|
|
# 以mirrorPoint和可用区域重点为对称抽翻转py
|
|
|
def mirrorPy(py,position):
|
|
|
insertPoint = py.InsertionPoint
|
|
|
centerPoint = position[0]
|
|
|
newCenterPoint = [position[3][0],position[3][1]]
|
|
|
+ newUsePoint = [position[2][0],position[2][1]]
|
|
|
+ conf.myprint("newUsePoint after mirror =",newUsePoint)
|
|
|
if((insertPoint[0]-centerPoint[0])*(insertPoint[1]-centerPoint[1])>0):
|
|
|
mirrorPoint = (insertPoint[0],centerPoint[1])
|
|
|
direction = 1 if (insertPoint[1]-centerPoint[1])>0 else -1;
|
|
|
- newCenterPoint[1]=position[3][1]+position[4][0]*direction
|
|
|
+ newCenterPoint[1]=position[3][1]+position[4][1]*direction
|
|
|
+ newUsePoint[1]=position[2][1]+position[1][1]*direction
|
|
|
else:
|
|
|
mirrorPoint = (centerPoint[0],insertPoint[1])
|
|
|
direction = 1 if (insertPoint[1]-centerPoint[1])>0 else -1;
|
|
|
- newCenterPoint[0]=position[3][0]+position[4][1]*direction
|
|
|
+ newCenterPoint[0]=position[3][0]+position[4][0]*direction
|
|
|
+ newUsePoint[0]=position[2][0]+position[1][0]*direction
|
|
|
position[3] = newCenterPoint
|
|
|
+ position[2] = newUsePoint
|
|
|
+ conf.myprint("newUsePoint after mirror =",newUsePoint)
|
|
|
py.mirror(APoint(mirrorPoint[0],mirrorPoint[1]),APoint(centerPoint[0],centerPoint[1]))
|
|
|
conf.myprint("delete blockReference name",py.name)
|
|
|
needDeleteBlockReferences.append(py)
|