Esempio n. 1
0
    def build(self):
        """
        Build the geometric shapes and the markers corresponding to the
        different parts of the structural element, and add them to the study.
        """
        gg = salome.ImportComponentGUI("GEOM")
        geompy = getGeompy(self._studyEditor.studyId)
        for part in self._parts.itervalues():
            # Build the structural element part
            logger.debug("Building %s" % part)
            try:
                (shape, markers) = part.build()
                if shape is None:
                    logger.error("Part %s has not been built" % part)
                    continue
            except:
                logger.exception("Couldn't build part %s" % part)
                continue
            
            # Add the new objects to the study
            shapeSObjName = part.name + "_" + part.groupName
            geompy.addToStudy(shape, shapeSObjName)
            geompy.PutToFolder(shape, self._getSObject())

            if markers is not None and len(markers) > 0:
                for i, marker in enumerate(markers, start = 1):
                    markerSObjName = "Orient_" + shapeSObjName
                    if len(markers) > 1:
                        markerSObjName += "_%d" % i
                    geompy.addToStudy(marker, markerSObjName)
                    geompy.PutToFolder(marker, self._getSObject())
Esempio n. 2
0
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
Esempio n. 3
0
 def _getSObject(self):
     """
     Find or create the study object corresponding to the structural
     element. This object is a Geom Folder named "SE_N" where N is a
     numerical ID. 
     """
     if self._SObject is None:
         geompy = getGeompy(self._studyEditor.studyId)
         geomComponent = self._studyEditor.study.FindComponent("GEOM")
         mainFolder = self._studyEditor.findItem(geomComponent,
                                                 name = StructuralElement.MAIN_FOLDER_NAME,
                                                 typeId=999)
         if mainFolder is None:
             mainFolder = geompy.NewFolder(StructuralElement.MAIN_FOLDER_NAME)
         self._SObject = geompy.NewFolder("SE_" + str(self._id), mainFolder)
     return self._SObject
Esempio n. 4
0
def createGeometry(study, radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH, width=DEFAULT_WIDTH):
    '''
    This function creates the geometry on the specified study and with
    given parameters.
    '''
    print "TUBE: creating the geometry ..."
    studyId = study._get_StudyId()
    geompy = geomtools.getGeompy(studyId)

    radius_ext = radius
    radius_int = radius_ext - width

    CylinderExt = geompy.MakeCylinderRH(radius_ext, length)
    CylinderInt = geompy.MakeCylinderRH(radius_int, length)
    Tube = geompy.MakeCut(CylinderExt, CylinderInt)
    return Tube
Esempio n. 5
0
def createGeometryWithPartition(study, radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH, width=DEFAULT_WIDTH):
    '''
    This function create the geometrical shape with a partition so
    that the hexaedric algorithm could be used for meshing.
    '''
    shape = createGeometry(study,radius,length,width)

    # We have to create a partition so that we can use an hexaedric
    # meshing algorithm.
    studyId = study._get_StudyId()
    geompy = geomtools.getGeompy(studyId)

    print "TUBE: creating a partition ..."
    toolPlane = geompy.MakeFaceHW(2.1*length,2.1*radius,3)
    partition = geompy.MakePartition([shape], [toolPlane], [], [], geompy.ShapeType["SOLID"], 0, [], 0)
    entry = geompy.addToStudy( partition, "TubeWithPartition" )
    return partition
Esempio n. 6
0
def createGeometry(study,
                   radius=DEFAULT_RADIUS,
                   length=DEFAULT_LENGTH,
                   width=DEFAULT_WIDTH):
    '''
    This function creates the geometry on the specified study and with
    given parameters.
    '''
    print "TUBE: creating the geometry ..."
    studyId = study._get_StudyId()
    geompy = geomtools.getGeompy(studyId)

    radius_ext = radius
    radius_int = radius_ext - width

    CylinderExt = geompy.MakeCylinderRH(radius_ext, length)
    CylinderInt = geompy.MakeCylinderRH(radius_int, length)
    Tube = geompy.MakeCut(CylinderExt, CylinderInt)
    return Tube
Esempio n. 7
0
def createGeometryWithPartition(study,
                                radius=DEFAULT_RADIUS,
                                length=DEFAULT_LENGTH,
                                width=DEFAULT_WIDTH):
    '''
    This function create the geometrical shape with a partition so
    that the hexaedric algorithm could be used for meshing.
    '''
    shape = createGeometry(study, radius, length, width)

    # We have to create a partition so that we can use an hexaedric
    # meshing algorithm.
    studyId = study._get_StudyId()
    geompy = geomtools.getGeompy(studyId)

    print "TUBE: creating a partition ..."
    toolPlane = geompy.MakeFaceHW(2.1 * length, 2.1 * radius, 3)
    partition = geompy.MakePartition([shape], [toolPlane], [], [],
                                     geompy.ShapeType["SOLID"], 0, [], 0)
    entry = geompy.addToStudy(partition, "TubeWithPartition")
    return partition
Esempio n. 8
0
import StdMeshers
import NETGENPlugin

salome.salome_init()
study = salome.myStudy
studyId = salome.myStudyId

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)
Esempio n. 9
0
def TEST_createAndDeleteShape():
    """
    This test is a simple use case that illustrates how to create a
    GEOM shape in a SALOME session (create the GEOM object, put in in
    the study, and display the shape in a viewer) and delete a shape
    from a SALOME session (erase the shape from the viewer, delete the
    entry from the study, and finally destroy the underlying GEOM
    object).
    """
    import salome
    salome.salome_init()
    study = salome.myStudy
    studyId = salome.myStudyId

    from salome.geom import geomtools
    geompy = geomtools.getGeompy(studyId)

    # --------------------------------------------------
    # Create a first shape (GEOM object)
    radius = 5
    length = 100
    cylinder = geompy.MakeCylinderRH(radius, length)

    # Register the shape in the study, at the root of the GEOM
    # folder. A name must be specified. The register operation
    # (addToStudy) returns an identifier of the entry in the study.
    cylinderName = "cyl.r%s.l%s" % (radius, length)
    cylinderStudyEntry = addToStudy(study, cylinder, cylinderName)

    # Display the registered shape in a viewer
    displayShape(cylinderStudyEntry)

    # --------------------------------------------------
    # A second shape
    radius = 10
    sphere = geompy.MakeSphereR(radius)
    sphereName = "sph.r%s" % radius
    sphereStudyEntry = addToStudy(study, sphere, sphereName)
    displayShape(sphereStudyEntry)

    # --------------------------------------------------
    # This new shape is stored in the study, but in a specific
    # sub-folder, and is displayed in the viewer with a specific
    # color.
    length = 20
    box = geompy.MakeBoxDXDYDZ(length, length, length)
    boxName = "box.l%s" % length
    folderName = "boxset"
    boxStudyEntry = addToStudy(study, box, boxName, folderName)
    displayShape(boxStudyEntry, PreviewColor)

    # --------------------------------------------------
    # In this example, we illustrate how to erase a shape (the sphere)
    # from the viewer. After this operation, the sphere is no longer
    # displayed but still exists in the study. You can then redisplay
    # it using the context menu of the SALOME object browser.
    eraseShape(sphereStudyEntry)

    # --------------------------------------------------
    # In this last example, we completly delete an object from the
    # SALOME session (erase from viewer, remove from study and finnaly
    # destroy the object). This is done by a simple call to
    # deleteShape().
    deleteShape(study, cylinderStudyEntry)
except ImportError:
    from PyQt5 import uic

try:
    from qtsalome import Qt, QDialog, QMessageBox
except ImportError:
    from PyQt4.QtGui import QDialog, QMessageBox
    from PyQt4.QtCore import Qt

import GEOM
from salome.geom.geomtools import getGeompy, GeomStudyTools
import math
import os
import salome_pluginsmanager

geompy = getGeompy()
geomTool = GeomStudyTools()


class GeomFilterGroupDialog(QDialog):
    def __init__(self, context):
        QDialog.__init__(self)
        self.setWindowFlags(Qt.WindowStaysOnTopHint)
        self.context = context
        self.directory = os.path.dirname(os.path.abspath(__file__))
        uic.loadUi(os.path.join(self.directory, "geom_filter_group_dialog.ui"),
                   self)
        self.selobj = None
        self.type_o = ''
        self.shapetype = -1
        # Call selectGroupRef function