1# -*- coding: utf-8 -*- 2 3#------------------------------------------------------------------------------- 4 5# This file is part of Code_Saturne, a general-purpose CFD tool. 6# 7# Copyright (C) 1998-2021 EDF S.A. 8# 9# This program is free software; you can redistribute it and/or modify it under 10# the terms of the GNU General Public License as published by the Free Software 11# Foundation; either version 2 of the License, or (at your option) any later 12# version. 13# 14# This program is distributed in the hope that it will be useful, but WITHOUT 15# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17# details. 18# 19# You should have received a copy of the GNU General Public License along with 20# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin 21# Street, Fifth Floor, Boston, MA 02110-1301, USA. 22 23#------------------------------------------------------------------------------- 24 25""" 26This module defines hooks with the SALOME plate-forme concerning 27the graphical selection of the Groups. 28 29This module contains the following classes and function: 30- BoundaryGroup 31- VolumeGroup 32""" 33 34#------------------------------------------------------------------------------- 35# Library modules 36#------------------------------------------------------------------------------- 37 38import os 39import os.path 40import logging 41 42#------------------------------------------------------------------------------- 43# Application modules 44#------------------------------------------------------------------------------- 45 46#------------------------------------------------------------------------------- 47# Third-party modules 48#------------------------------------------------------------------------------- 49 50from code_saturne.model.Common import GuiParam 51 52import CFDSTUDYGUI 53from CFDSTUDYGUI_DataModel import _getStudy, _getEngine 54from CFDSTUDYGUI_Commons import sg, sgPyQt 55 56import salome 57from salome import * 58 59import SMESH 60from salome.smesh import smeshBuilder 61 62import GEOM 63from salome.geom import geomBuilder 64 65#------------------------------------------------------------------------------- 66# log config 67#------------------------------------------------------------------------------- 68 69logging.basicConfig() 70log = logging.getLogger("SalomeHandler") 71log.setLevel(GuiParam.DEBUG) 72 73#------------------------------------------------------------------------------- 74 75#loading IORs 76aStudy = _getStudy() 77builder = aStudy.NewBuilder() 78 79sMeshComponent = salome.myStudy.FindComponent("SMESH") 80if sMeshComponent != None: 81 aSMESHEngine = lcc.FindOrLoadComponent("FactoryServer", "SMESH") 82 builder.LoadWith(sMeshComponent, aSMESHEngine) 83 84sGeomComponent = salome.myStudy.FindComponent("GEOM") 85if sGeomComponent != None: 86 aGEOMEngine = lcc.FindOrLoadComponent("FactoryServer", "GEOM") 87 builder.LoadWith(sGeomComponent, aGEOMEngine) 88 89#------------------------------------------------------------------------------- 90 91def BoundaryGroup(): 92 """ 93 Import groups of faces. 94 """ 95 if sMeshComponent == None and sGeomComponent == None: 96 raise ValueError("Component SMESH and GEOM not found") 97 98 local = "" 99 if sg.SelectedCount() > 0: 100 for i in range (sg.SelectedCount()): 101 entry = sg.getSelected(i) 102 if entry != '': 103 sobj = aStudy.FindObjectID(entry) 104 if sobj != None: 105 anObjectDS = sobj.GetObject() 106 if anObjectDS != None: 107 108 # check for smesh group 109 aSmeshObject = anObjectDS._narrow(SMESH.SMESH_GroupBase) 110 #if aSmeshObject == None: 111 # aSmeshObject = anObjectDS._narrow(SMESH.SMESH_Group) 112 #if aSmeshObject == None: 113 # aSmeshObject = anObjectDS._narrow(SMESH.SMESH_GroupOnGeom) 114 if aSmeshObject != None and aSmeshObject.GetType() == SMESH.FACE: 115 if not local: 116 local = aSmeshObject.GetName() 117 else: 118 local += ' or ' + aSmeshObject.GetName() 119 120 # check for geom group of faces 121 aGeomObject = anObjectDS._narrow(GEOM.GEOM_Object) 122 if aGeomObject != None and aGeomObject.GetType() == 37: 123 # check the group 124 # get all possible faces 125 all_ids = geomBuilder.SubShapeAllIDs(aGeomObject.GetMainShape(), geomBuilder.ShapeType["FACE"]) 126 cur_ids = geomBuilder.GetObjectIDs(aGeomObject) 127 isValid = len(cur_ids) > 0 # not include empty list 128 if isValid: 129 for face_id in cur_ids: 130 if not face_id in all_ids: 131 #invalid id 132 isValid = False 133 break 134 135 if isValid: 136 if not local: 137 local = aGeomObject.GetName() 138 else: 139 local += ' or ' + aGeomObject.GetName() 140 141 log.debug("BoundaryGroup -> %s" % str(local)) 142 return local 143 144 145def VolumeGroup(): 146 """ 147 Import groups of solid. 148 """ 149 if sMeshComponent == None and sGeomComponent == None: 150 raise ValueError("Component SMESH and GEOM not found") 151 152 local = "" 153 if sg.SelectedCount() > 0: 154 for i in range (sg.SelectedCount()): 155 entry = sg.getSelected(i) 156 if entry != '': 157 sobj = aStudy.FindObjectID(entry) 158 if sobj != None: 159 anObjectDS = sobj.GetObject() 160 #check for smesh group 161 if anObjectDS != None: 162 #aSmeshObject = anObjectDS._narrow(SMESH.SMESH_Group) 163 aSmeshObject = anObjectDS._narrow(SMESH.SMESH_GroupBase) 164 if aSmeshObject != None and aSmeshObject.GetType() == SMESH.VOLUME: 165 if not local: 166 local = aSmeshObject.GetName() 167 else: 168 local += ' or ' + aSmeshObject.GetName() 169 170 # check for geom group of volumes 171 aGeomObject = anObjectDS._narrow(GEOM.GEOM_Object) 172 if aGeomObject != None and aGeomObject.GetType() == 37: 173 # check the group 174 # get all possible volumes 175 all_ids = geomBuilder.SubShapeAllIDs(aGeomObject.GetMainShape(), geomBuilder.ShapeType["SOLID"]) 176 cur_ids = geomBuilder.GetObjectIDs(aGeomObject) 177 isValid = len(cur_ids) > 0 # not include empty list 178 if isValid: 179 for face_id in cur_ids: 180 if not face_id in all_ids: 181 # invalid id 182 isValid = False 183 break 184 185 if isValid: 186 if not local: 187 local = aGeomObject.GetName() 188 else: 189 local += ' or ' + aGeomObject.GetName() 190 191 log.debug("VolumeGroup -> %s" % str(local)) 192 return local 193 194#------------------------------------------------------------------------------- 195