Scripts para Gerenciar Planos de Controle em Revisões¶
Esses scripts são usados para gerenciar um plano de controle quando ele está sendo modificado ao ser dividido em múltiplos planos de controle específicos para a área que serão editados em diferentes revisões e, após as revisões terem sido consolidadas de volta no modelo principal, para mesclar os planos individuais de volta em um único plano de controle.
Script para Dividir um Plano de Controle¶
#####################################################################################
#####################################################################################
# Isenção de Garantia: NA MEDIDA DO PERMITIDO PELA LEI APLICÁVEL, OS SCRIPTS
# AIMSUN, INCLUINDO, MAS NÃO SE LIMITANDO A TODOS OS DADOS, FERRAMENTAS E
# CÁLCULOS Neles, SÃO FORNECIDOS "COMO ESTÃO" E SEM GARANTIA EXPRESSA OU IMPLÍCITA
# DE QUALQUER TIPO POR QUALQUER UM DOS ENVOLVIDOS NA CRIAÇÃO, PRODUÇÃO OU
# ENTREGA DOS SCRIPTS AIMSUN, INCLUINDO, MAS NÃO SE LIMITANDO A QUALQUER GARANTIA
# EXPRESSA OU IMPLÍCITA DE COMERCIABILIDADE, PRECISÃO, TRANQUILIDADE, NÃO
# INFRINGÊNCIA OU ADEQUAÇÃO A UM DETERMINADO PROPÓSITO. NENHUM PACTO, GARANTIAS
# OU INDEMNIZAÇÕES DE QUALQUER TIPO SÃO CONCEDIDAS PELA AIMSUN A VOCÊ, O USUÁRIO.
# SE O PROGRAMA SE MOSTRAR DEFECTIVO, VOCÊ ASSUME O CUSTO DE TODOS OS SERVIÇOS,
# REPAROS OU CORREÇÕES NECESSÁRIOS.
#####################################################################################
#####################################################################################
###################################################################################
###
### Início do corpo principal -
###
###################################################################################
def main():
sourceControlPlans = []
# Verifique se este está sendo executado a partir do tipo de objeto correto
if target==None or target.isA(model.getType("GKControlPlan"))==False:
print "deve ser executado a partir de um plano de controle ou planos"
# Monte uma lista de planos de controle selecionados
for item in selection:
if item.isA(model.getType("GKControlPlan")):
sourceControlPlans.append(item)
# Obtenha os objetos relevantes
problemNet = returnProblemNetFromDialog("Recuperar rede de problemas")
nodeIdsInProblemNet = returnDictNodesInPolygon(problemNet).keys()
polygonLayer = returnPolygonLayerFromDialog("Recuperar camada de polígonos")
polygons = returnPolygonsForLayer(polygonLayer)
dictPolygonNameNodeIds = {}
listNodeIdsInPolygons = []
#Dividir em novos planos usando polígonos
for polygon in polygons:
#Tente encontrar o nome do polígono
polygonName = str(polygon.getName())
if polygonName == "":
polygonName = str(polygon.getExternalId())
if polygonName == "":
polygonName = str(polygon.getId())
if polygonName in dictPolygonNameNodeIds:
print "nome de polígono repetido - Erro"
return
listNodeIdsInPolygon = returnDictNodesInPolygon(polygon).keys()
#Obtenha os nós no polígono
dictPolygonNameNodeIds[polygonName] = []
for nodeId in listNodeIdsInPolygon:
if nodeId not in listNodeIdsInPolygons:
dictPolygonNameNodeIds[polygonName].append(nodeId)
listNodeIdsInPolygons.append(nodeId)
polygonName = "FORA"
for nodeId in nodeIdsInProblemNet:
if nodeId not in listNodeIdsInPolygons:
if polygonName not in dictPolygonNameNodeIds:
dictPolygonNameNodeIds[polygonName]=[]
dictPolygonNameNodeIds[polygonName].append(nodeId)
print "nodeId fora" + str(nodeId)
# Copiar os nós para os polígonos
for sourceControlPlan in sourceControlPlans:
sourceControlPlanName = str(sourceControlPlan.getName())
for polygonName in sorted(dictPolygonNameNodeIds.keys()):
listNodesIds = dictPolygonNameNodeIds[polygonName]
targetControlPlanName = sourceControlPlanName + "_" + polygonName
targetControlPlan = getControlPlan( model, targetControlPlanName )
targetControlPlan.setDataValue(parentControlPlanIdCol, QVariant(sourceControlPlan.getId()))
copyControlJunctionsFromSourceControlPlanToTargetControlPlan(sourceControlPlan, targetControlPlan, listNodesIds)
return
## Ponto de Entrada
## Chame a função principal para este script
main()
print "Concluído"
Script para Recombinar Planos de Controle¶
##################################################################################
###
### Início do corpo principal -
###
##################################################################################
def main():
# Verifique se este está sendo executado a partir do tipo de objeto correto
if parentControlPlanIdCol==None:
print "coluna GKControlPlan::ParentControlPlanId não encontrada"
return
dictOriginalControlPlanIdListSplitControlPlans = {}
if target==None or target.isA(model.getType("GKControlPlan"))==False:
print "deve ser executado a partir de um plano de controle ou planos"
# Monte uma lista de planos de controle
for item in selection:
if item.isA(model.getType("GKControlPlan")):
originalControlPlanId = item.getDataValueInt(parentControlPlanIdCol)
if originalControlPlanId > 0:
if originalControlPlanId not in dictOriginalControlPlanIdListSplitControlPlans:
dictOriginalControlPlanIdListSplitControlPlans[originalControlPlanId]=[]
dictOriginalControlPlanIdListSplitControlPlans[originalControlPlanId].append(item)
for originalControlPlanId in dictOriginalControlPlanIdListSplitControlPlans.keys():
originalControlPlanName = str(originalControlPlanId)
originalControlPlan = model.getCatalog().find(originalControlPlanId)
if originalControlPlan!=None:
originalControlPlanName = str(originalControlPlan.getName())
if originalControlPlan==None or CREATE_NEW_CONTROL_PLAN:
originalControlPlanName = originalControlPlanName + "_COMBINADO"
originalControlPlan = getControlPlan( model, originalControlPlanName)
# Copie os controles de junções
for splitControlPlan in dictOriginalControlPlanIdListSplitControlPlans[originalControlPlanId]:
nodeIdsWithControl = splitControlPlan.getControlJunctions().keys()
copyControlJunctionsFromSourceControlPlanToTargetControlPlan(splitControlPlan, originalControlPlan, nodeIdsWithControl)
return
# Ponto de Entrada
## Chame a função principal para este script
main()
print "Concluído"
Funções Utilitárias ¶
As funções utilitárias são usadas pelos scripts de cópia do plano de controle.
#################################################################################
###
### Definir Funções Utilitárias
###
#################################################################################
def getControlPlan( model, name ):
#encontrar plano de controle no modelo
controlPlanType = model.getType( "GKControlPlan" )
controlPlan = model.getCatalog().findByName(str(name), controlPlanType)
if controlPlan!=None:
return controlPlan
else:
cmd = GKControlPlanNewCmd()
model.getCommander().addCommand(cmd)
controlPlan = cmd.createdObject()
controlPlan.setName( name )
controlPlan.setExternalId( name )
return controlPlan
def returnProblemNetFromDialog(windowTitle):
print "Selecione a " + windowTitle + " rede de problemas"
dialog = GAnyObjectChooserEditor()
dialog.setWindowTitle("Selecione a " + windowTitle + " rede de problemas")
chooser = dialog.getChooser()
chooser.setWindowTitle("Selecione a " + windowTitle + " rede de problemas")
chooser.setType(model, model.getType("GKProblemNet"), GAnyObjectChooser.ChooserMode.eOneObject)
acceptedRejected = dialog.execDialog()
if acceptedRejected == 1:
layer = chooser.getObject()
if layer!=None:
print "retornando rede de problemas pelo seletor"
return layer
print "nenhuma rede de problemas"
return None
def returnPolygonLayerFromDialog(windowTitle):
print "Selecione a " + windowTitle + " camada de polígonos"
dialog = GAnyObjectChooserEditor()
dialog.setWindowTitle("Selecione a " + windowTitle + " camada de polígonos")
chooser = dialog.getChooser()
chooser.setWindowTitle("Selecione a " + windowTitle + " camada de polígonos")
chooser.setType(model, model.getType("GKLayer"), GAnyObjectChooser.ChooserMode.eOneObject)
acceptedRejected = dialog.execDialog()
if acceptedRejected == 1:
layer = chooser.getObject()
if layer!=None:
print "retornando rede de problemas pelo seletor"
return layer
print "nenhuma rede de problemas"
return None
def copyControlJunctionsFromSourceControlPlanToTargetControlPlan(sourceControlPlan, targetControlPlan, listNodesIds):
nodeIdsWithControl = targetControlPlan.getControlJunctions().keys()
for nodeId in nodeIdsWithControl:
targetControlPlan.removeControlJunction(nodeId)
for nodeId in listNodesIds:
sourceControlJunction = sourceControlPlan.getControlJunction(nodeId)
targetControlPlan.removeControlJunction(nodeId)
if sourceControlJunction!=None:
targetControlPlan.addControlJunction(nodeId, sourceControlJunction.clone())
return
def returnPolygonsForLayer(layer):
listPolygons = []
for geoObject in layer.getObjects():
if geoObject.isA(model.getType("GKPolygon")):
listPolygons.append(geoObject)
return listPolygons
def returnDictNodesInPolygon(polygon):
dictNodeIdNodes = {}
if polygon==None:
for node in model.getCatalog().getObjectsByType(model.getType("GKNode")).values():
dictNodeIdNodes[node.getId()]=node
return dictNodeIdNodes
for nodeOrSection in polygon.classifyObjects(polygon.eOnlyNodesAndSections):
if nodeOrSection.isA(model.getType("GKNode")):
dictNodeIdNodes[nodeOrSection.getId()]=nodeOrSection
return dictNodeIdNodes