|
@@ -10,6 +10,12 @@ positoins={}
|
|
|
currentPosition = {}
|
|
|
# 组件使用点位置
|
|
|
useAreaPositions={}
|
|
|
+# 组件与门距离
|
|
|
+distinceWithDoor = {}
|
|
|
+# 组件间距离
|
|
|
+distinceWithOthers={}
|
|
|
+# 旋转后需删除的组件
|
|
|
+needDeleteBlockReferences=[]
|
|
|
# acad.prompt("Hello, Autocad from Python\n")
|
|
|
# conf.myprint(acad.doc.Name)
|
|
|
def printObjects():
|
|
@@ -41,7 +47,10 @@ def moveBlockReference(position):
|
|
|
currentPosition[1] = conf.names.index(item)
|
|
|
result = moveBlockReferenceToWall(blockReference,position[conf.names.index(item)])
|
|
|
if(result == 0):
|
|
|
- moveResult = result
|
|
|
+ moveResult = result
|
|
|
+ for blockReference in needDeleteBlockReferences:
|
|
|
+ blockReference.delete()
|
|
|
+ needDeleteBlockReferences.clear()
|
|
|
return moveResult
|
|
|
def moveBlockReferenceToWall(blockReference,wallIndex):
|
|
|
wallIndex = int(wallIndex)
|
|
@@ -49,7 +58,7 @@ def moveBlockReferenceToWall(blockReference,wallIndex):
|
|
|
blockIndex = conf.names.index(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))
|
|
|
+ blockReference.move(APoint(blockReference.InsertionPoint),APoint(conf.roomLengths[0]-conf.roomUsedLengths[0],0))
|
|
|
conf.roomUsedLengths[0] = conf.roomUsedLengths[0]+conf.moduleLengths[blockIndex];
|
|
|
elif (wallIndex == 1):
|
|
|
blockReference.move(APoint(blockReference.InsertionPoint),APoint(conf.roomLengths[0],conf.roomLengths[1]-conf.roomUsedLengths[1]))
|
|
@@ -58,9 +67,9 @@ def moveBlockReferenceToWall(blockReference,wallIndex):
|
|
|
blockReference.move(APoint(blockReference.InsertionPoint),APoint(conf.roomUsedLengths[2],conf.roomLengths[1]))
|
|
|
conf.roomUsedLengths[2] = conf.roomUsedLengths[2]+conf.moduleLengths[blockIndex];
|
|
|
else:
|
|
|
- blockReference.move(APoint(blockReference.InsertionPoint),APoint(0,conf.roomUsedLengths[3]))
|
|
|
+ blockReference.move(APoint(blockReference.InsertionPoint),APoint(0,conf.roomLengths[1]-conf.roomUsedLengths[3]-conf.moduleLengths[blockIndex]))
|
|
|
conf.roomUsedLengths[3] = conf.roomUsedLengths[3]+conf.moduleLengths[blockIndex];
|
|
|
- checkPositionIntersect = tempStoragePosition(blockReference.InsertionPoint[0],blockReference.InsertionPoint[1],wallIndex,blockIndex)
|
|
|
+ checkPositionIntersect = tempStoragePosition(blockReference.InsertionPoint[0],blockReference.InsertionPoint[1],wallIndex,blockIndex,blockReference)
|
|
|
if(checkPositionIntersect == 0):
|
|
|
conf.myprint("wallIndex=",wallIndex,blockReference.name," not walkable......")
|
|
|
return 0
|
|
@@ -88,7 +97,7 @@ def moveBlockReferenceWithNewIndex(position,moduleIndex):
|
|
|
return moveResult
|
|
|
# 重置已使用墙的长度
|
|
|
def resetConfUsed():
|
|
|
- conf.roomUsedLengths=[1200,0,0,1000]
|
|
|
+ conf.roomUsedLengths=[0,0,0,0]
|
|
|
# 对模块重新排序
|
|
|
def changeConfModuleIndex(moduleIndex):
|
|
|
names=[]
|
|
@@ -110,7 +119,7 @@ def isWorkable(position):
|
|
|
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]):
|
|
|
+ if(needLength[wallIndex]+conf.roomUsedLengths[wallIndex] > conf.roomWallLengths[wallIndex]):
|
|
|
conf.myprint(needLength[wallIndex]+conf.roomUsedLengths[wallIndex],conf.roomLengths[math.floor(wallIndex/2)],wallIndex)
|
|
|
return 0
|
|
|
return 1
|
|
@@ -162,32 +171,46 @@ def getCenterPoint(wallIndex, x, y, blockIndex):
|
|
|
useCenterPointOffset = (useWidth,useHeight)
|
|
|
positoin = [centerPoint,centerPointOffset,usePoint,useCenterPoint,useCenterPointOffset];
|
|
|
conf.myprint(wallIndex,width,height)
|
|
|
- drawPointCircle((pointA, pointB, pointC, pointD, centerPoint, usePoint, useCenterPoint))
|
|
|
+ # drawPointCircle((pointA, pointB, pointC, pointD, centerPoint, usePoint, useCenterPoint))
|
|
|
conf.myprint(positoin)
|
|
|
return positoin
|
|
|
# 打印辅助点
|
|
|
def drawPointCircle(points):
|
|
|
for point in points:
|
|
|
- acad.model.AddCircle(APoint(point[0],point[1]), 50)
|
|
|
+ acad.model.AddCircle(APoint(point[0],point[1]), 50)
|
|
|
+
|
|
|
+# 判断可用区域中点是否超出房间
|
|
|
+def isUseCenterOverRoom(useCenterPosition):
|
|
|
+ if useCenterPosition[0] < 0 or useCenterPosition[0]>conf.roomLengths[0] or useCenterPosition[1] < 0 or useCenterPosition[1]>conf.roomLengths[1]:
|
|
|
+ return True
|
|
|
+ return False
|
|
|
# 从插入点开始顺时针记录已摆放的组件
|
|
|
-def tempStoragePosition(x,y,wallIndex,blockIndex):
|
|
|
- positoin = getCenterPoint(wallIndex, x, y, blockIndex);
|
|
|
- usePosition = (positoin[3],positoin[4])
|
|
|
+def tempStoragePosition(x,y,wallIndex,blockIndex,blockReference):
|
|
|
+ position = getCenterPoint(wallIndex, x, y, blockIndex);
|
|
|
+ # 判断可用区域中点是否超出房间
|
|
|
+ if(isUseCenterOverRoom(position[3])):
|
|
|
+ mirrorPy(blockReference,position)
|
|
|
+ useCenterPosition = (position[3],position[4])
|
|
|
+ doorFeasible = isPositionFeasibleWithDoor(position)
|
|
|
+ conf.myprint("doorFeasible=",doorFeasible)
|
|
|
+ if(doorFeasible == 0):
|
|
|
+ return doorFeasible
|
|
|
+ getDoorBeginAndModuleUsePointDistince(position,wallIndex)
|
|
|
result = 1
|
|
|
for item in positoins:
|
|
|
# 判断实体是否相交
|
|
|
- result = isPositionFeasible(positoin,positoins[item],0)
|
|
|
+ result = isPositionFeasible(position,positoins[item],1)
|
|
|
if(result == 1):
|
|
|
# 判断当前实体是否与已摆放的可用区域相交
|
|
|
- result = isPositionFeasible(positoin,useAreaPositions[item],1)
|
|
|
+ result = isPositionFeasible(position,useAreaPositions[item],1)
|
|
|
if(result == 1):
|
|
|
# 判断可用区域是否与实体相交
|
|
|
- result = isPositionFeasible(usePosition,positoins[item],1)
|
|
|
+ result = isPositionFeasible(useCenterPosition,positoins[item],1)
|
|
|
if(result == 0):
|
|
|
return result
|
|
|
if(result == 1):
|
|
|
- positoins[len(positoins)] = positoin
|
|
|
- useAreaPositions[len(useAreaPositions)] = usePosition
|
|
|
+ positoins[len(positoins)] = position
|
|
|
+ useAreaPositions[len(useAreaPositions)] = useCenterPosition
|
|
|
return result
|
|
|
|
|
|
# 计算位置是否可行type:0 实体 1可用区域
|
|
@@ -203,6 +226,57 @@ def isPositionFeasible(position1,position2,type):
|
|
|
else:
|
|
|
conf.myprint(areaName,"can put here")
|
|
|
return 1
|
|
|
+# 计算实体位置是否与门使用区域相交
|
|
|
+def isPositionFeasibleWithDoor(position):
|
|
|
+ length = conf.doorAlign[0]+conf.doorAlign[1]+conf.doorLength;
|
|
|
+ width = conf.doorLength+conf.doorAlign[2];
|
|
|
+ doorPosition = [(length/2,width/2),(length,width)]
|
|
|
+ return isPositionFeasible(position,doorPosition,1)
|
|
|
+# 计算两点间距离
|
|
|
+def getDistince(point1,point2):
|
|
|
+ detarX = point1[0]-point2[0]
|
|
|
+ detarY = point1[1]-point2[1]
|
|
|
+ return math.sqrt(detarX**2+detarY**2)
|
|
|
+def getDoorBeginPoint():
|
|
|
+ return ((conf.doorAlign[0]+conf.doorLength+conf.doorAlign[1])/2,0)
|
|
|
+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]))
|
|
|
+ # 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]]
|
|
|
+ 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
|
|
|
+ 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
|
|
|
+ position[3] = newCenterPoint
|
|
|
+ py.mirror(APoint(mirrorPoint[0],mirrorPoint[1]),APoint(centerPoint[0],centerPoint[1]))
|
|
|
+ conf.myprint("delete blockReference name",py.name)
|
|
|
+ needDeleteBlockReferences.append(py)
|
|
|
# printObjects()
|
|
|
# printBlockObjects()
|
|
|
# printTheTypeObject("BlockReference")
|
|
@@ -211,4 +285,6 @@ def isPositionFeasible(position1,position2,type):
|
|
|
# a=[0,1,2]
|
|
|
# moveBlockReferenceWithNewIndex('001',a)
|
|
|
# conf.myprint(isWorkable('222'))
|
|
|
-# getCenterPoint(3,4162.85,0,2)
|
|
|
+# getCenterPoint(3,4162.85,0,2)
|
|
|
+# print(getDistince((0,3),(4,0)))
|
|
|
+# print(getDoorBeginPoint())
|