def setAspect(self, entry, opacity): """Set aspect of an object.""" # to set up display options # let us retrieve an instance of libSMESH_Swig.SMESH_Swig import salome sm_gui = salome.ImportComponentGUI(str('SMESH')) if not hasattr(sm_gui, 'GetActorAspect'): # Customizing aspect requires a newer GUI module. return # pragma pylint: disable=no-member # retrieve a structure with presentation parameters for this actor pres = sm_gui.GetActorAspect(str(entry), self._vtk_viewer) # redefine some of these parameters pres.opacity = opacity # the following will have to be adapted according to dimension # volumeColor : 3D # surfaceColor : 2D # edgeColor : 1D # nodeColor : 0D #pres.surfaceColor.r = 0. #pres.surfaceColor.g = 1. #pres.surfaceColor.b = 0. # reinject this for the actor sm_gui.SetActorAspect(pres, str(entry), self._vtk_viewer)
def trihedron_withdisplay(context): import GEOM from salome.geom import geomBuilder # Intialize the geompy factory with the active study activeStudy = context.study geompy = geomBuilder.New(activeStudy) # Create the objects Vx = geompy.MakeVectorDXDYDZ(10, 0, 0) Vy = geompy.MakeVectorDXDYDZ(0, 10, 0) Vz = geompy.MakeVectorDXDYDZ(0, 0, 10) origin = geompy.MakeVertex(0, 0, 0) # Register the objects in the active study entries=[] entries.append(geompy.addToStudy( Vx, "Vx" )) entries.append(geompy.addToStudy( Vy, "Vy" )) entries.append(geompy.addToStudy( Vz, "Vz" )) entries.append(geompy.addToStudy( origin, "origin" )) # This part is to automatically display the objects in the active viewer. gcomp = salome.ImportComponentGUI("GEOM") for entry in entries: gcomp.createAndDisplayFitAllGO(entry)
def addToStudy(study, shape, shapeName, folderName=None): """ Add a GEOM shape in the study. It returns the associated entry that corresponds to the identifier of the entry in the study. This entry can be used to retrieve an object in the study. A folderName can be specified. In this case, a folder with this name is first created in the Geometry part of the study, and the shape study object is stored in this folder of the study. """ studyId = study._get_StudyId() geompy = geomtools.getGeompy(studyId) if folderName is None: # Insert the shape in the study by the standard way entry = geompy.addToStudy(shape, shapeName) else: # A folder name has been specified to embed this shape. Find # or create a folder with this name in the Geometry study, and # then store the shape in this folder. studyEditor = getStudyEditor(studyId) geomStudyFolder = studyEditor.findOrCreateComponent("GEOM") shapeStudyFolder = studyEditor.findOrCreateItem( geomStudyFolder, folderName) shapeIor = salome.orb.object_to_string(shape) geomgui = salome.ImportComponentGUI("GEOM") shapeIcon = geomgui.getShapeTypeIcon(shapeIor) shapeStudyObject = studyEditor.createItem(shapeStudyFolder, name=shapeName, IOR=shapeIor, icon=shapeIcon) entry = shapeStudyObject.GetID() return entry
def displayShape(shapeStudyEntry, color=None): """This displays the shape specified by its entry in the study""" geomgui = salome.ImportComponentGUI("GEOM") geomgui.createAndDisplayFitAllGO(shapeStudyEntry) geomgui.setDisplayMode(shapeStudyEntry, DisplayMode) if color is not None: geomgui.setColor(shapeStudyEntry, color[0], color[1], color[2])
def delobjregex( complaint="Shape*", s="s", module='' ): #http://www.salome-platform.org/forum/forum_10/366900504 much more complicated?? #removes or selects import re if module == '': mods = ["SMESH", "GEOM"] else: mods = [module] for compName in mods: comp = salome.myStudy.FindComponent(compName) if comp: iterator = salome.myStudy.NewChildIterator(comp) while iterator.More(): sobj = iterator.Value() print sobj.GetID() + " " + complaint sobject = salome.myStudy.FindObjectID(sobj.GetID()) print sobject.GetName() if re.match(complaint, sobject.GetName()) != None: print "regex" if s != "s": print "del" salome.sg.Erase(sobj.GetID()) gg = salome.ImportComponentGUI("GEOM") gg.UpdateViewer() salome.myStudy.NewBuilder().RemoveObjectWithChildren( sobj) else: salome.sg.AddIObject(sobj.GetID()) salome.sg.updateObjBrowser( salome.myStudy._get_StudyId()) print "he" iterator.Next() salome.sg.updateObjBrowser(salome.myStudy._get_StudyId())
def eraseShape(shapeStudyEntry): """ This erases from the viewers the shape specified by its study entry. """ geomgui = salome.ImportComponentGUI("GEOM") eraseFromAllWindows = True geomgui.eraseGO(shapeStudyEntry, eraseFromAllWindows)
def displaysalomeplease(i5=100, debug=4, complaint='', complaint1=''): import SalomePyQt #i5[4:1 activate VTK-Viewer [2:2Erase :1DisplayAll [3:1 Fitall #complaint1!='' vtk, else occ. complaint1: obj to display #displaysalomeplease(10021, 4,)# ok erase occ #displaysalomeplease(11021, 4,groupName) #__display only groupname in vtk-viewer #FitAll()o #2:100, DisplayAll() #3 10 (erase 20), VTKViewer")[0]) #1000 # #salome.sg.ResetView() #?: = Fitall? Fitall in VTK case nearer #gg.UpdateViewer() #error #0. something with "mesh update" (from context menu) #1. Konsole or Funktion sg.Display: hover over case: Solution occ: gg.UpdateViewer() gg = salome.ImportComponentGUI("GEOM") sg = SalomePyQt.SalomePyQt() if int(str(i5)[len(str(i5)) - 4]) == 0: sg.activateView(sg.getActiveView()) sg.activateView(sg.findViews("OCCViewer")[0]) if complaint1 != "": a = salome.myStudy.FindObjectByName(complaint, "GEOM")[0].GetID() salome.sg.Display(a) if int(str(i5)[len(str(i5)) - 2]) == 2: salome.sg.EraseAll() for i in salome.sg.getAllSelected(): salome.sg.Display(i) salome.sg.updateObjBrowser(salome.myStudy._get_StudyId()) salome.sg.UpdateView() #?was if int(str(i5)[len(str(i5)) - 2]) == 1: salome.sg.DisplayAll() #3 10 if int(str(i5)[len(str(i5)) - 3]) == 1: salome.sg.FitAll() #2:100 else: gg.UpdateViewer() #salome.sg.FitAll() if int(str(i5)[len(str(i5)) - 4]) == 1: sg.activateView(sg.findViews("VTKViewer")[0]) if int(str(i5)[len(str(i5)) - 2]) == 2: salome.sg.EraseAll() salome.sg.UpdateView() if complaint != "": a = salome.myStudy.FindObjectByName(complaint, "SMESH")[0].GetID() salome.sg.Display(a) #only if vtk-viewer activated for i in salome.sg.getAllSelected(): salome.sg.Display(i) if int(str(i5)[len(str(i5)) - 2]) == 1: salome.sg.DisplayAll() # forelast digit if int(str(i5)[len(str(i5)) - 3]) == 1: salome.sg.FitAll() #2:100 else: gg.UpdateViewer() import iparameters if debug != 4: iparameters.getSession().restoreVisualState(1) if int(str(i5)[len(str(i5)) - 4]) == 2: sg.activateView(sg.findViews("ParaView")[0])
def zoomobj(x=-1, y=-1, z=-1, r=-1, obj_name1=[], obj_name2=[], viewer="VTKViewer"): salome.sg.EraseAll() gg = salome.ImportComponentGUI("GEOM") sg.activateView(sg.findViews(viewer)[0]) if r != -1: sphere = geompy.MakeSphere(x, y, z, r) sphere_id = geompy.addToStudy(sphere, "Sphere") salome.sg.updateObjBrowser(salome.myStudy._get_StudyId()) gg.createAndDisplayGO(sphere_id) gg.setDisplayMode(sphere_id, 1) gg.setColor(sphere_id, 218, 165, 31) gg.setTransparency(sphere_id, 0.9) salome.sg.FitAll() #del ?? else: obj_id = [ salome.myStudy.FindObjectByName(i, i1)[0].GetID() for i in obj_name1 for i1 in ["GEOM", "SMESH"] if salome.myStudy.FindObjectByName(i, i1) != [] ] print obj_id for i in obj_id: salome.sg.Display(i) salome.sg.updateObjBrowser(salome.myStudy._get_StudyId()) salome.sg.FitAll() if obj_name2 != []: #display the rest unfittet obj_id2 = [ salome.myStudy.FindObjectByName(i, i1)[0].GetID() for i in obj_name2 for i1 in ["GEOM", "SMESH"] if salome.myStudy.FindObjectByName(i, i1) != [] ] for i in obj_id2: salome.sg.Display(i) salome.sg.updateObjBrowser(salome.myStudy._get_StudyId()) gg.UpdateViewer()
from salome.geom import geomBuilder geompy = geomBuilder.New(salome.myStudy) smesh = smeshBuilder.New(salome.myStudy) from salome.geom import geomtools geompy = geomtools.getGeompy(studyId) from salome.kernel.studyedit import getStudyEditor studyEditor = getStudyEditor(studyId) gst = geomtools.GeomStudyTools(studyEditor) gg = salome.ImportComponentGUI("GEOM") def Project(): O = geompy.MakeVertex(0, 0, 0) O_id = geompy.addToStudy(O, "O") Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) gst.addShapeToStudy(Vx, "Vx") Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) geompy.addToStudy(Vy, "Vy") Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) geompy.addToStudy(Vz, "Vz") # List of elements which are added to the study Liste = [] ListeV = [] L1 = []
def proceed(): try: # selected Object selobj = selectGroupRef() # Is a group? isgroup = geompy.ShapeIdToType(selobj.GetType()) == 'GROUP' # The father of group father = geompy.GetMainShape(selobj) # Type of element elem = str(selobj.GetShapeType()) # Size props = geompy.BasicProperties(selobj) if elem == "EDGE": Sref = props[0] if elem == "FACE": Sref = props[1] if elem == "SOLID": Sref = props[2] # Location cm_ref = geompy.MakeCDG(selobj) coords_ref = geompy.PointCoordinates(cm_ref) # Normal (Element==Face) if elem == "FACE": vnorm_ref = geompy.GetNormal(selobj) else: vnorm_ref = None # Create container group group = list() # All Object elements of type elem elements = geompy.ExtractShapes(father, geompy.ShapeType[elem], True) # Create group Group_f = geompy.CreateGroup(father, geompy.ShapeType[elem]) # Options name_g = str(le_nam_g.text()) pr = eval(str(sb_tol.text())) except: QtGui.QMessageBox.critical(None, 'Error', "error 1", QtGui.QMessageBox.Abort) try: # Selected elements for the group whit the desired conditios for i in elements: props = geompy.BasicProperties(i) cm = geompy.MakeCDG(i) coords = geompy.PointCoordinates(cm) # Element i coordinates x = coords[0] y = coords[1] z = coords[2] # Element i size if elem == "EDGE": S = props[0] if elem == "FACE": S = props[1] if elem == "SOLID": S = props[2] # Element==Face i Normal if vnorm_ref == None: vnorm = None else: vnorm = geompy.GetNormal(i) angle = geompy.GetAngle(vnorm_ref, vnorm) # Comparations cond = list() if cb_size.isChecked(): cond.append(S < Sref * (1 + pr) and S > Sref * (1 - pr)) else: cond.append(True) if cb_locx.isChecked(): if coords_ref[0] >= 0: cond.append(x < coords_ref[0] * (1 + pr) and x > coords_ref[0] * (1 - pr)) else: cond.append(x > coords_ref[0] * (1 + pr) and x < coords_ref[0] * (1 - pr)) else: cond.append(True) if cb_locy.isChecked(): if coords_ref[1] >= 0: cond.append(y < coords_ref[1] * (1 + pr) and y > coords_ref[1] * (1 - pr)) else: cond.append(y > coords_ref[1] * (1 + pr) and y < coords_ref[1] * (1 - pr)) else: cond.append(True) if cb_locz.isChecked(): if coords_ref[2] >= 0: cond.append(z < coords_ref[2] * (1 + pr) and z > coords_ref[2] * (1 - pr)) else: cond.append(z > coords_ref[2] * (1 + pr) and z < coords_ref[2] * (1 - pr)) else: cond.append(True) if cb_norm.isChecked() and vnorm != None: cond.append(angle < 0.0 + 0.001 and angle > 0.0 - 0.001) else: cond.append(True) if cond[0] and cond[1] and cond[2] and cond[3] and cond[4]: ID = geompy.GetSubShapeID(father, i) group.append(ID) cond.append(cond) except: QtGui.QMessageBox.critical(None, 'Error', "error 2", QtGui.QMessageBox.Abort) # Add elements desired to Group try: geompy.UnionIDs(Group_f, group) # Set color of the group Group_f.SetColor(SALOMEDS.Color(1, 0, 0)) # Add group in hte gui resGroup = geompy.addToStudyInFather(father, Group_f, name_g) # View group gg = salome.ImportComponentGUI("GEOM") gg.createAndDisplayGO(resGroup) # Update Object Browser if salome.sg.hasDesktop(): salome.sg.updateObjBrowser(1) except: QtGui.QMessageBox.critical(None, 'Error', "error 3", QtGui.QMessageBox.Abort) return 0.0
def create(self): # Read data from input file with open(self.dataFilename) as dataFile: data = json.load(dataFile) elements = data['elements'] connections = data['connections'] # --> Delete this reference data and repopulate it with the objects # while going through elements for conn in connections: conn['relatedElements'] = [] # End <-- meshSize = self.meshSize dec = 7 # 4 decimals for length in mm tol = 10**(-dec - 3 + 1) self.tolLoc = tol * 10 * 2 tolLoc = self.tolLoc NEW_SALOME = int(salome_version.getVersion()[0]) >= 9 salome.salome_init() theStudy = salome.myStudy notebook = salome_notebook.NoteBook(theStudy) ### ### GEOM component ### import GEOM from salome.geom import geomBuilder import math import SALOMEDS gg = salome.ImportComponentGUI('GEOM') if NEW_SALOME: geompy = geomBuilder.New() else: geompy = geomBuilder.New(theStudy) self.geompy = geompy O = geompy.MakeVertex(0, 0, 0) OX = geompy.MakeVectorDXDYDZ(1, 0, 0) OY = geompy.MakeVectorDXDYDZ(0, 1, 0) OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) geompy.addToStudy(O, 'O') geompy.addToStudy(OX, 'OX') geompy.addToStudy(OY, 'OY') geompy.addToStudy(OZ, 'OZ') if len([e for e in elements if e['geometryType'] == 'line']) > 0: buildingShapeType = 'EDGE' if len([e for e in elements if e['geometryType'] == 'surface']) > 0: buildingShapeType = 'FACE' ### Define entities ### start_time = time.time() print('Defining Object Geometry') init_time = start_time # Loop 1 for el in elements: el['elemObj'] = self.makeObject(el['geometry'], el['geometryType']) el['connObjs'] = [None for _ in el['connections']] el['linkObjs'] = [None for _ in el['connections']] el['linkPointObjs'] = [[None, None] for _ in el['connections']] for j, rel in enumerate(el['connections']): conn = [ c for c in connections if c['ifcName'] == rel['relatedConnection'] ][0] if rel['eccentricity']: rel['index'] = len(conn['relatedElements']) + 1 conn['relatedElements'].append(rel) if not rel['eccentricity']: el['connObjs'][j] = self.makeObject( conn['geometry'], conn['geometryType']) else: if conn['geometryType'] == 'point': geometry = self.getLinkGeometry( rel['eccentricity'], el['orientation'], conn['geometry']) el['connObjs'][j] = self.makeObject( geometry[0], conn['geometryType']) el['linkPointObjs'][j][0] = self.geompy.MakeVertex( geometry[0][0], geometry[0][1], geometry[0][2]) el['linkPointObjs'][j][1] = self.geompy.MakeVertex( geometry[1][0], geometry[1][1], geometry[1][2]) el['linkObjs'][j] = self.geompy.MakeLineTwoPnt( el['linkPointObjs'][j][0], el['linkPointObjs'][j][1]) else: print('Eccentricity defined for a %s geometryType' % conn['geometryType']) el['partObj'] = self.makePartition( [el['elemObj']] + el['connObjs'], el['geometryType']) el['elemObj'] = geompy.GetInPlace(el['partObj'], el['elemObj']) for j, rel in enumerate(el['connections']): el['connObjs'][j] = geompy.GetInPlace(el['partObj'], el['connObjs'][j]) for conn in connections: conn['connObj'] = self.makeObject(conn['geometry'], conn['geometryType']) # Make assemble of Building Object bldObjs = [] bldObjs.extend([el['partObj'] for el in elements]) bldObjs.extend( flatten([[link for link in el['linkObjs'] if link] for el in elements])) bldObjs.extend([conn['connObj'] for conn in connections]) bldComp = geompy.MakeCompound(bldObjs) # bldComp = geompy.MakePartition(bldObjs, [], [], [], self.geompy.ShapeType[buildingShapeType], 0, [], 1) geompy.addToStudy(bldComp, 'bldComp') # Loop 2 for el in elements: # geompy.addToStudy(el['partObj'], self.getGroupName(el['ifcName'])) geompy.addToStudyInFather(el['partObj'], el['elemObj'], self.getGroupName(el['ifcName'])) for j, rel in enumerate(el['connections']): conn = [ c for c in connections if c['ifcName'] == rel['relatedConnection'] ][0] rel['conn_string'] = None if conn['geometryType'] == 'point': rel['conn_string'] = '_0DC_' if conn['geometryType'] == 'line': rel['conn_string'] = '_1DC_' if conn['geometryType'] == 'surface': rel['conn_string'] = '_2DC_' geompy.addToStudyInFather( el['partObj'], el['connObjs'][j], self.getGroupName(el['ifcName']) + rel['conn_string'] + self.getGroupName(rel['relatedConnection'])) if rel['eccentricity']: pass # geompy.addToStudy(el['linkObjs'][j], self.getGroupName(el['ifcName']) + '_1DR_' + self.getGroupName(rel['relatedConnection'])) # geompy.addToStudyInFather(el['linkObjs'][j], el['linkPointObjs'][j][0], self.getGroupName(rel['relatedConnection']) + '_0DC_' + self.getGroupName(el['ifcName'])) # geompy.addToStudyInFather(el['linkObjs'][j], el['linkPointObjs'][j][0], self.getGroupName(rel['relatedConnection']) + '_0DC_%g' % rel['index']) for conn in connections: # geompy.addToStudy(conn['connObj'], self.getGroupName(conn['ifcName'])) geompy.addToStudyInFather(conn['connObj'], conn['connObj'], self.getGroupName(conn['ifcName'])) elapsed_time = time.time() - init_time init_time += elapsed_time print('Building Geometry Defined in %g sec' % (elapsed_time)) if len([e for e in elements if e['geometryType'] == 'line']) > 0: buildingShapeType = 'EDGE' if len([e for e in elements if e['geometryType'] == 'surface']) > 0: buildingShapeType = 'FACE' # Define and add groups for all curve and surface members if len([e for e in elements if e['geometryType'] == 'line']) > 0: # Make compound of requested group compoundTemp = geompy.MakeCompound([ e['elemObj'] for e in elements if e['geometryType'] == 'line' ]) # Define group object and add to study curveCompound = geompy.GetInPlace(bldComp, compoundTemp) geompy.addToStudyInFather(bldComp, curveCompound, 'CurveMembers') if len([e for e in elements if e['geometryType'] == 'surface']) > 0: # Make compound of requested group compoundTemp = geompy.MakeCompound([ e['elemObj'] for e in elements if e['geometryType'] == 'surface' ]) # Define group object and add to study surfaceCompound = geompy.GetInPlace(bldComp, compoundTemp) geompy.addToStudyInFather(bldComp, surfaceCompound, 'SurfaceMembers') # Loop 3 for el in elements: # el['partObj'] = geompy.RestoreGivenSubShapes(bldComp, [el['partObj']], GEOM.FSM_GetInPlace, False, False)[0] geompy.addToStudyInFather(bldComp, el['elemObj'], self.getGroupName(el['ifcName'])) for j, rel in enumerate(el['connections']): geompy.addToStudyInFather( bldComp, el['connObjs'][j], self.getGroupName(el['ifcName']) + rel['conn_string'] + self.getGroupName(rel['relatedConnection'])) if rel['eccentricity']: # point geometry geompy.addToStudyInFather( bldComp, el['linkObjs'][j], self.getGroupName(el['ifcName']) + '_1DR_' + self.getGroupName(rel['relatedConnection'])) geompy.addToStudyInFather( bldComp, el['linkPointObjs'][j][0], self.getGroupName(rel['relatedConnection']) + '_0DC_' + self.getGroupName(el['ifcName'])) geompy.addToStudyInFather( bldComp, el['linkPointObjs'][j][1], self.getGroupName(rel['relatedConnection']) + '_0DC_%g' % rel['index']) for conn in connections: # conn['connObj'] = geompy.RestoreGivenSubShapes(bldComp, [conn['connObj']], GEOM.FSM_GetInPlace, False, False)[0] geompy.addToStudyInFather(bldComp, conn['connObj'], self.getGroupName(conn['ifcName'])) elapsed_time = time.time() - init_time init_time += elapsed_time print('Building Geometry Groups Defined in %g sec' % (elapsed_time)) ### ### SMESH component ### import SMESH from salome.smesh import smeshBuilder print('Defining Mesh Components') if NEW_SALOME: smesh = smeshBuilder.New() else: smesh = smeshBuilder.New(theStudy) bldMesh = smesh.Mesh(bldComp) Regular_1D = bldMesh.Segment() Local_Length_1 = Regular_1D.LocalLength(meshSize, None, tolLoc) if buildingShapeType == 'FACE': NETGEN2D_ONLY = bldMesh.Triangle(algo=smeshBuilder.NETGEN_2D) NETGEN2D_Pars = NETGEN2D_ONLY.Parameters() NETGEN2D_Pars.SetMaxSize(meshSize) NETGEN2D_Pars.SetOptimize(1) NETGEN2D_Pars.SetFineness(2) NETGEN2D_Pars.SetMinSize(meshSize / 5.0) NETGEN2D_Pars.SetUseSurfaceCurvature(1) NETGEN2D_Pars.SetQuadAllowed(1) NETGEN2D_Pars.SetSecondOrder(0) NETGEN2D_Pars.SetFuseEdges(254) isDone = bldMesh.Compute() ## Set names of Mesh objects smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D') smesh.SetName(Local_Length_1, 'Local_Length_1') if buildingShapeType == 'FACE': smesh.SetName(NETGEN2D_ONLY.GetAlgorithm(), 'NETGEN2D_ONLY') smesh.SetName(NETGEN2D_Pars, 'NETGEN2D_Pars') smesh.SetName(bldMesh.GetMesh(), 'bldMesh') elapsed_time = time.time() - init_time init_time += elapsed_time print('Meshing Operations Completed in %g sec' % (elapsed_time)) # Define and add groups for all curve and surface members if len([e for e in elements if e['geometryType'] == 'line']) > 0: tempgroup = bldMesh.GroupOnGeom(curveCompound, 'CurveMembers', SMESH.EDGE) smesh.SetName(tempgroup, 'CurveMembers') if len([e for e in elements if e['geometryType'] == 'surface']) > 0: tempgroup = bldMesh.GroupOnGeom(surfaceCompound, 'SurfaceMembers', SMESH.FACE) smesh.SetName(tempgroup, 'SurfaceMembers') # Define groups in Mesh for el in elements: if el['geometryType'] == 'line': shapeType = SMESH.EDGE if el['geometryType'] == 'surface': shapeType = SMESH.FACE tempgroup = bldMesh.GroupOnGeom(el['elemObj'], self.getGroupName(el['ifcName']), shapeType) smesh.SetName(tempgroup, self.getGroupName(el['ifcName'])) for j, rel in enumerate(el['connections']): tempgroup = bldMesh.GroupOnGeom( el['connObjs'][j], self.getGroupName(el['ifcName']) + rel['conn_string'] + self.getGroupName(rel['relatedConnection']), SMESH.NODE) smesh.SetName( tempgroup, self.getGroupName(el['ifcName']) + rel['conn_string'] + self.getGroupName(rel['relatedConnection'])) rel['node'] = (bldMesh.GetIDSource(tempgroup.GetNodeIDs(), SMESH.NODE)).GetIDs()[0] if rel['eccentricity']: tempgroup = bldMesh.GroupOnGeom( el['linkObjs'][j], self.getGroupName(el['ifcName']) + '_1DR_' + self.getGroupName(rel['relatedConnection']), SMESH.EDGE) smesh.SetName( tempgroup, self.getGroupName(el['ifcName']) + '_1DR_' + self.getGroupName(rel['relatedConnection'])) tempgroup = bldMesh.GroupOnGeom( el['linkPointObjs'][j][0], self.getGroupName(rel['relatedConnection']) + '_0DC_' + self.getGroupName(el['ifcName']), SMESH.NODE) smesh.SetName( tempgroup, self.getGroupName(rel['relatedConnection']) + '_0DC_' + self.getGroupName(el['ifcName'])) rel['eccNode'] = (bldMesh.GetIDSource( tempgroup.GetNodeIDs(), SMESH.NODE)).GetIDs()[0] tempgroup = bldMesh.GroupOnGeom( el['linkPointObjs'][j][1], self.getGroupName(rel['relatedConnection']) + '_0DC_' + self.getGroupName(rel['relatedConnection']), SMESH.NODE) smesh.SetName( tempgroup, self.getGroupName(rel['relatedConnection']) + '_0DC_%g' % rel['index']) for conn in connections: tempgroup = bldMesh.GroupOnGeom(conn['connObj'], self.getGroupName(conn['ifcName']), SMESH.NODE) smesh.SetName(tempgroup, self.getGroupName(conn['ifcName'])) nodesId = bldMesh.GetIDSource(tempgroup.GetNodeIDs(), SMESH.NODE) tempgroup = bldMesh.Add0DElementsToAllNodes( nodesId, self.getGroupName(conn['ifcName'])) smesh.SetName(tempgroup, self.getGroupName(conn['ifcName'] + '_0D')) if conn['geometryType'] == 'point': conn['node'] = nodesId.GetIDs()[0] if conn['geometryType'] == 'line': tempgroup = bldMesh.GroupOnGeom( conn['connObj'], self.getGroupName(conn['ifcName']), SMESH.EDGE) smesh.SetName(tempgroup, self.getGroupName(conn['ifcName'])) if conn['geometryType'] == 'surface': tempgroup = bldMesh.GroupOnGeom( conn['connObj'], self.getGroupName(conn['ifcName']), SMESH.FACE) smesh.SetName(tempgroup, self.getGroupName(conn['ifcName'])) # create 1D SEG2 spring elements for el in elements: for j, rel in enumerate(el['connections']): conn = [ c for c in connections if c['ifcName'] == rel['relatedConnection'] ][0] if conn['geometryType'] == 'point': grpName = bldMesh.CreateEmptyGroup( SMESH.EDGE, self.getGroupName(el['ifcName']) + '_1DS_' + self.getGroupName(rel['relatedConnection'])) smesh.SetName( grpName, self.getGroupName(el['ifcName']) + '_1DS_' + self.getGroupName(rel['relatedConnection'])) if not rel['eccentricity']: conn = [ conn for conn in connections if conn['ifcName'] == rel['relatedConnection'] ][0] grpName.Add( [bldMesh.AddEdge([conn['node'], rel['node']])]) else: grpName.Add( [bldMesh.AddEdge([rel['eccNode'], rel['node']])]) self.mesh = bldMesh self.meshNodes = bldMesh.GetNodesId() elapsed_time = time.time() - init_time init_time += elapsed_time print('Mesh Groups Defined in %g sec' % (elapsed_time)) try: if NEW_SALOME: bldMesh.ExportMED(self.medFilename, auto_groups=0, minor=40, overwrite=1, meshPart=None, autoDimension=0) else: bldMesh.ExportMED(self.medFilename, 0, SMESH.MED_V2_2, 1, None, 0) except: print('ExportMED() failed. Invalid file name?') if salome.sg.hasDesktop(): if NEW_SALOME: salome.sg.updateObjBrowser() else: salome.sg.updateObjBrowser(1) elapsed_time = init_time - start_time print('ALL Operations Completed in %g sec' % (elapsed_time))
def create(self): # Read data from input file with open(self.dataFilename) as dataFile: data = json.load(dataFile) # print(len(data['elements'])) # elements = self.select(data['elements']) # print(len(elements)) elements = data["elements"] connections = data["connections"] # --> Delete this reference data and repopulate it with the objects # while going through elements for conn in connections: conn["relatedElements"] = [] # End <-- meshSize = self.meshSize zGround = self.zGround dec = 5 # 4 decimals for length in mm tol = 10**(-dec - 3 + 1) self.tolLoc = tol * 10 * 2 tolLoc = self.tolLoc NEW_SALOME = int(salome_version.getVersion()[0]) >= 9 salome.salome_init() theStudy = salome.myStudy notebook = salome_notebook.NoteBook(theStudy) ### ### GEOM component ### import GEOM from salome.geom import geomBuilder import math import SALOMEDS gg = salome.ImportComponentGUI("GEOM") if NEW_SALOME: geompy = geomBuilder.New() else: geompy = geomBuilder.New(theStudy) self.geompy = geompy O = geompy.MakeVertex(0, 0, 0) OX = geompy.MakeVectorDXDYDZ(1, 0, 0) OY = geompy.MakeVectorDXDYDZ(0, 1, 0) OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) geompy.addToStudy(O, "O") geompy.addToStudy(OX, "OX") geompy.addToStudy(OY, "OY") geompy.addToStudy(OZ, "OZ") if len([e for e in elements if e["geometryType"] == "line"]) > 0: buildingShapeType = "EDGE" if len([e for e in elements if e["geometryType"] == "surface"]) > 0: buildingShapeType = "FACE" ### Define entities ### start_time = time.time() print("Defining Object Geometry") init_time = start_time # Loop 1 for el in elements: el["elemObj"] = self.makeObject(el["geometry"], el["geometryType"]) el["linkObjs"] = [None for _ in el["connections"]] for j, rel in enumerate(el["connections"]): conn = [ c for c in connections if c["referenceName"] == rel["relatedConnection"] ][0] if rel["eccentricity"]: rel["index"] = len(conn["relatedElements"]) + 1 geometry = self.getLinkGeometry(rel["eccentricity"], el["orientation"], conn["geometry"]) el["linkObjs"][j] = self.makeObject(geometry, "line") conn["relatedElements"].append(rel) # Make assemble of Building Object bldObjs = [] bldObjs.extend([el["elemObj"] for el in elements]) bldObjs.extend( flatten([[link for link in el["linkObjs"] if link] for el in elements])) # bldComp = geompy.MakeCompound(bldObjs) bldComp = geompy.MakePartition( bldObjs, [], [], [], self.geompy.ShapeType[buildingShapeType], 0, [], 1) geompy.addToStudy(bldComp, "bldComp") elapsed_time = time.time() - init_time init_time += elapsed_time print("Building Geometry Defined in %g sec" % (elapsed_time)) # Define and add groups for all curve, surface and rigid members if len([e for e in elements if e["geometryType"] == "line"]) > 0: # Make compound of requested group compoundTemp = geompy.MakeCompound([ e["elemObj"] for e in elements if e["geometryType"] == "line" ]) # Define group object and add to study curveCompound = geompy.GetInPlace(bldComp, compoundTemp, True) geompy.addToStudyInFather(bldComp, curveCompound, "CurveMembers") if len([e for e in elements if e["geometryType"] == "surface"]) > 0: # Make compound of requested group compoundTemp = geompy.MakeCompound([ e["elemObj"] for e in elements if e["geometryType"] == "surface" ]) # Define group object and add to study surfaceCompound = geompy.GetInPlace(bldComp, compoundTemp, True) geompy.addToStudyInFather(bldComp, surfaceCompound, "SurfaceMembers") linkObjs = list( flatten([[obj for obj in el["linkObjs"] if obj] for el in elements])) if len(linkObjs) > 0: # Make compound of requested group compoundTemp = geompy.MakeCompound(linkObjs) # Define group object and add to study rigidCompound = geompy.GetInPlace(bldComp, compoundTemp, True) geompy.addToStudyInFather(bldComp, rigidCompound, "RigidMembers") for el in elements: # el['partObj'] = geompy.RestoreGivenSubShapes(bldComp, [el['partObj']], GEOM.FSM_GetInPlace, False, False)[0] el["elemObj"] = geompy.GetInPlace(bldComp, el["elemObj"], True) geompy.addToStudyInFather(bldComp, el["elemObj"], self.getGroupName(el["referenceName"])) for j, rel in enumerate(el["connections"]): if rel["eccentricity"]: # point geometry el["linkObjs"][j] = geompy.GetInPlace( bldComp, el["linkObjs"][j], True) geompy.addToStudyInFather( bldComp, el["linkObjs"][j], self.getGroupName(el["referenceName"]) + "_1DR_" + self.getGroupName(rel["relatedConnection"]), ) elapsed_time = time.time() - init_time init_time += elapsed_time print("Building Geometry Groups Defined in %g sec" % (elapsed_time)) ### ### SMESH component ### import SMESH from salome.smesh import smeshBuilder print("Defining Mesh Components") if NEW_SALOME: smesh = smeshBuilder.New() else: smesh = smeshBuilder.New(theStudy) bldMesh = smesh.Mesh(bldComp) Regular_1D = bldMesh.Segment() Local_Length_1 = Regular_1D.LocalLength(meshSize, None, tolLoc) if buildingShapeType == "FACE": NETGEN2D_ONLY = bldMesh.Triangle(algo=smeshBuilder.NETGEN_2D) NETGEN2D_Pars = NETGEN2D_ONLY.Parameters() NETGEN2D_Pars.SetMaxSize(meshSize) NETGEN2D_Pars.SetOptimize(1) NETGEN2D_Pars.SetFineness(2) NETGEN2D_Pars.SetMinSize(meshSize / 5.0) NETGEN2D_Pars.SetUseSurfaceCurvature(1) NETGEN2D_Pars.SetQuadAllowed(1) NETGEN2D_Pars.SetSecondOrder(0) NETGEN2D_Pars.SetFuseEdges(254) isDone = bldMesh.Compute() coincident_nodes_on_part = bldMesh.FindCoincidentNodesOnPart([bldMesh], tolLoc, [], 0) if coincident_nodes_on_part: # bldMesh.MergeNodes(coincident_nodes_on_part, [], 0) # print(f'{len(coincident_nodes_on_part)} Sets of Coincident Nodes Found and Merged') print( f"{len(coincident_nodes_on_part)} Sets of Coincident Nodes Found" ) print(f"{coincident_nodes_on_part}") ## Set names of Mesh objects smesh.SetName(Regular_1D.GetAlgorithm(), "Regular_1D") smesh.SetName(Local_Length_1, "Local_Length_1") if buildingShapeType == "FACE": smesh.SetName(NETGEN2D_ONLY.GetAlgorithm(), "NETGEN2D_ONLY") smesh.SetName(NETGEN2D_Pars, "NETGEN2D_Pars") smesh.SetName(bldMesh.GetMesh(), "bldMesh") elapsed_time = time.time() - init_time init_time += elapsed_time print("Meshing Operations Completed in %g sec" % (elapsed_time)) # Define and add groups for all curve, surface and rigid members if len([e for e in elements if e["geometryType"] == "line"]) > 0: tempgroup = bldMesh.GroupOnGeom(curveCompound, "CurveMembers", SMESH.EDGE) smesh.SetName(tempgroup, "CurveMembers") if len([e for e in elements if e["geometryType"] == "surface"]) > 0: tempgroup = bldMesh.GroupOnGeom(surfaceCompound, "SurfaceMembers", SMESH.FACE) smesh.SetName(tempgroup, "SurfaceMembers") if len(linkObjs) > 0: tempgroup = bldMesh.GroupOnGeom(rigidCompound, "RigidMembers", SMESH.EDGE) smesh.SetName(tempgroup, "RigidMembers") # Define groups in Mesh for el in elements: if el["geometryType"] == "line": shapeType = SMESH.EDGE if el["geometryType"] == "surface": shapeType = SMESH.FACE tempgroup = bldMesh.GroupOnGeom( el["elemObj"], self.getGroupName(el["referenceName"]), shapeType) smesh.SetName(tempgroup, self.getGroupName(el["referenceName"])) for j, rel in enumerate(el["connections"]): if rel["eccentricity"]: tempgroup = bldMesh.GroupOnGeom( el["linkObjs"][j], self.getGroupName(el["referenceName"]) + "_1DR_" + self.getGroupName(rel["relatedConnection"]), SMESH.EDGE, ) smesh.SetName( tempgroup, self.getGroupName(el["referenceName"]) + "_1DR_" + self.getGroupName(rel["relatedConnection"]), ) self.mesh = bldMesh self.meshNodes = bldMesh.GetNodesId() # Find ground supports and extract node coordinates grdSupps = bldMesh.CreateEmptyGroup(SMESH.NODE, "grdSupps") for node in self.meshNodes: coords = bldMesh.GetNodeXYZ(node) if abs(coords[2] - self.zGround) < tolLoc: grdSupps.Add([node]) smesh.SetName(grdSupps, "grdSupps") elapsed_time = time.time() - init_time init_time += elapsed_time print("Mesh Groups Defined in %g sec" % (elapsed_time)) try: if NEW_SALOME: bldMesh.ExportMED( self.medFilename, auto_groups=0, minor=40, overwrite=1, meshPart=None, autoDimension=0, ) else: bldMesh.ExportMED(self.medFilename, 0, SMESH.MED_V2_2, 1, None, 0) except: print("ExportMED() failed. Invalid file name?") if salome.sg.hasDesktop(): if NEW_SALOME: salome.sg.updateObjBrowser() else: salome.sg.updateObjBrowser(1) elapsed_time = init_time - start_time print("ALL Operations Completed in %g sec" % (elapsed_time))
salome.sg.updateObjBrowser(True) print print "======================================================================" print " %d. Test Mesh " % step step += 1 print "======================================================================" from salome.StdMeshers import StdMeshersBuilder import SMESH from salome.smesh import smeshBuilder smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH") if salome.hasDesktop(): smeshgui = salome.ImportComponentGUI("SMESH") smeshgui.Init(salome.myStudyId) else: smesh = smeshBuilder.New(salome.myStudy) # ---- create hypotheses if sys.platform == "win32": stdMeshersEngine = "StdMeshersEngine" else: stdMeshersEngine = "libStdMeshersEngine.so" print print "--- Create hypotheses ..." print