Exemplo n.º 1
0
    def __initBase(self):
        """
            + __initBase is called from the constructor and after the class was unpickled
            + add privately created modules here
        """
        self.__firstTime = True

        # create custom modules here
        self.__myCollect = Collect()
        theNet().add(self.__myCollect)
Exemplo n.º 2
0
 def testTransientReduceSetData(self):
     moduleCount = theNet().moduleCount()
     gip_core = self._TransientGroup()
     gip = ImportGroupReduceSet(gip_core)
     gip.setReductionFactor(2)
     value = 'Pressure'
     c = Colors()
     theNet().add(c)
     connect(gip.dataConnectionPoint(value), ConnectionPoint(c, 'Data'))
     coll = Collect()
     theNet().add(coll)
     connect(gip.geoConnectionPoint(), ConnectionPoint(coll, 'grid'))
     theNet().connect(c, 'texture', coll, 'textures')
     theNet().connect(coll, 'geometry',
                      globalRenderer()._module, 'RenderData')
     gip.executeGeo()
     gip.executeData(value)
     (a, b) = gip.getDataMinMax(value)
     self.assertEqual((a, b), (-0.018360999999999999, 2.0))
     # delete
     theNet().remove(c)
     theNet().remove(coll)
     gip.delete()
     gip_core.delete()
     self._RemoveImportGroupModules()
     self.assertEqual(theNet().moduleCount(), moduleCount)
Exemplo n.º 3
0
    def __init(self):
        """ start COVISE ReadCAD Module """
        if self.__readCad == None:
            self.__readCad = ReadCAD()
            theNet().add(self.__readCad)
            self.__readCadPolyOut = ConnectionPoint(self.__readCad, 'mesh')
            self.__readCadNormalsOut = ConnectionPoint(self.__readCad,
                                                       'Normals')
            self.__readCadColorsOut = ConnectionPoint(self.__readCad,
                                                      'colorOut')
            self.__readCad.set_catia_server('obie')
            self.__readCad.set_catia_server_port('7000')
            self.__readCad.set_partIndex(self.__index)
            self.__readCad.set_file_path(self.__filename)

            self.__collect = Collect()
            theNet().add(self.__collect)
            connect(self.__readCadPolyOut,
                    ConnectionPoint(self.__collect, 'GridIn0'))
            connect(self.__readCadNormalsOut,
                    ConnectionPoint(self.__collect, 'DataIn1'))
            connect(self.__readCadColorsOut,
                    ConnectionPoint(self.__collect, 'DataIn0'))
            self.__connectGeoOut = ConnectionPoint(self.__collect,
                                                   'GeometryOut0')
Exemplo n.º 4
0
    def __initBase(self):
        """
            + __initBase is called from the constructor and after the class was unpickled
            + add privately created modules here
        """
        self.__firstTime = True

        # create custom modules here
        self.__myCollect = Collect()
        theNet().add(self.__myCollect)
Exemplo n.º 5
0
    def __init(self):
        """ start COVISE modules and connect output to COVER """
        if self.__colors == None and self.__collect == None:
            self.__colors = Colors()
            theNet().add(self.__colors)
            self.__colorsIn = ConnectionPoint(self.__colors, 'GridIn0')

            self.__collect = Collect()
            theNet().add(self.__collect)
            self.__collectOut = ConnectionPoint(self.__collect, 'GeometryOut0')
            connect(self.importModule.geoConnectionPoint(),
                    ConnectionPoint(self.__collect, 'GridIn0'))

            VisItem.connectToCover(self, self)
Exemplo n.º 6
0
def testGroupData(gip):
    value = 'Temperature'
    c = Colors()
    theNet().add(c)
    connect( gip.dataConnectionPoint(value), ConnectionPoint( c, 'Data' ) )
    gip.executeData(value)

    coll = Collect()
    theNet().add(coll)
    connect( gip.geoConnectionPoint(value), ConnectionPoint( coll, 'grid' ) )
    theNet().connect( c, 'texture', coll, 'textures' )
    r = Renderer()
    theNet().add(r)
    theNet().connect( coll, 'geometry', r, 'RenderData')
    c.execute()
Exemplo n.º 7
0
 def testGroupData(self):
     moduleCount = theNet().moduleCount()
     gip = self._LargeSimpleGroup()
     value = 'Temperature'
     c = Colors()
     theNet().add(c)
     connect(gip.dataConnectionPoint(value), ConnectionPoint(c, 'Data'))
     coll = Collect()
     theNet().add(coll)
     connect(gip.geoConnectionPoint(), ConnectionPoint(coll, 'grid'))
     theNet().connect(c, 'texture', coll, 'textures')
     theNet().connect(coll, 'geometry',
                      globalRenderer()._module, 'RenderData')
     gip.executeGeo()
     gip.executeData(value)
     # delete
     theNet().remove(c)
     theNet().remove(coll)
     gip.delete()
     self._RemoveImportGroupModules()
     self.assertEqual(theNet().moduleCount(), moduleCount)
Exemplo n.º 8
0
class PartDomainSurfaceVis(PartModuleVis, PartColoredVis):
    """ VisItem to compute iso cropped polygons from polygons """
    def __init__(self):
        PartModuleVis.__init__(self, DomainSurface, VIS_DOMAINSURFACE,
                               self.__class__.__name__, ['GridIn0'], [], [],
                               [], ['DataIn0'], [], [], 1, False, False)
        PartColoredVis.__init__(self)

        self.params = PartDomainSurfaceVisParams()
        self.__initBase()

    def __initBase(self):
        """
            + __initBase is called from the constructor and after the class was unpickled
            + add privately created modules here
        """
        self.__firstTime = True

        # create custom modules here
        self.__myCollect = Collect()
        theNet().add(self.__myCollect)

        self.__myColors = Colors()
        theNet().add(self.__myColors)

    def __init(self, negMsgHandler):
        """ __init is called from __update
            + start _module module if it does not already exist and connect output to COVER
            + set default parameters of module
            + set default boundingBox which is also used in the GUI to set borders of the float sliders
            + set color inport and corresponding module
            + send params to the gui
        """
        if self.__firstTime == True:
            self.__firstTime = False
            PartModuleVis._init(self, negMsgHandler)
            PartColoredVis._init(self, negMsgHandler, self.__myColors,
                                 'ColormapIn0')

            # make my custom connections between further self created modules here
            theNet().connect(self._module, 'GridOut0', self.__myCollect,
                             'GridIn0')
            if not self.params.variable == 'unset':
                theNet().connect(self.__myColors, 'DataOut0', self.__myCollect,
                                 'DataIn0')
                theNet().connect(self._module, 'DataOut0', self.__myColors,
                                 'DataIn0')
            else:
                theNet().disconnect(self.__myColors, 'DataOut0',
                                    self.__myCollect, 'DataIn0')
                theNet().disconnect(self._module, 'DataOut0', self.__myColors,
                                    'DataIn0')

            # send params to gui
            self.sendParams()

    def __getstate__(self):
        mycontent = PartModuleVis.__getstate__(self)
        del mycontent['_PartDomainSurfaceVis__myCollect']
        del mycontent['_PartDomainSurfaceVis__myColors']
        return mycontent

    def recreate(self, negMsgHandler, parentKey, offset):
        """ recreate is called after all classes of the session have been unpickled """
        PartDomainSurfaceVisParams.mergeDefaultParams(
            self.params)  # explicitly call mergeDefaultParams of this class
        self.__initBase()

        if self.params.variable == None or self.params.variable == 'unset':
            PartModuleVis.recreate(self, negMsgHandler, parentKey, offset,
                                   DomainSurface, ['GridIn0'], [], [], [], [],
                                   [], [], 1, False, False)
        else:
            PartModuleVis.recreate(self, negMsgHandler, parentKey, offset,
                                   DomainSurface, ['GridIn0'], [], [], [],
                                   ['DataIn0'], [], [], 1, False, False)

        PartColoredVis.recreate(self, negMsgHandler, parentKey, offset)
        PartColoredVis.setColorMap(self, True)

    def delete(self, isInitialized, negMsgHandler=None):
        if isInitialized:
            if hasattr(
                    self,
                    '_PartDomainSurfaceVis__myCollect') and self.__myCollect:
                theNet().remove(self.__myCollect)
            if hasattr(self,
                       '_PartDomainSurfaceVis__myColors') and self.__myColors:
                theNet().remove(self.__myColors)

        PartModuleVis.delete(self, isInitialized, negMsgHandler)

    def __update(self, negMsgHandler):
        """ __update is called from the run method to update the module parameter before execution
            + do init of the IsoCutter module if necessary
            + update module parameters """
        self.__init(negMsgHandler)
        PartModuleVis._update(self, negMsgHandler)
        if not self.params.variable == 'unset':
            PartColoredVis._update(self, negMsgHandler)
        else:
            self._dataInputNames = []
            theNet().disconnect(self.__myColors, 'DataOut0', self.__myCollect,
                                'DataIn0')
            theNet().disconnect(self._module, 'DataOut0', self.__myColors,
                                'DataIn0')

    def run(self, runmode, negMsgHandler):
        """ create a new visulisation
            + register for events from Covise if not done yet
            + runmode RUN_GEO and RUN_OCT are ignored
            + update module parameter
            + exec the module
        """
        assert negMsgHandler
        if runmode == RUN_ALL:
            _infoer.function = str(self.run)
            _infoer.write("go")

            if not hasattr(self, 'importModule'):
                return

            self.__update(negMsgHandler)
            if not self.params.variable == 'unset':
                PartColoredVis.run(self, runmode, negMsgHandler, self._module,
                                   self.fromRecreation)

            PartModuleVis.run(self, runmode, negMsgHandler)

    def setParamsByModule(self, mparam, mvalue):
        """ receives parameter changes from the iso cutter module
            return a list of objKey and their parameters to be set by the Neg2Gui class
        """
        _infoer.function = str(self.setParamsByModule)
        _infoer.write("param: %s, value: %s" % (mparam, str(mvalue)))
        pChangeList = []
        newparams = CopyParams(self.params)
        pChangeList.append((self.key, newparams))

        return pChangeList

    def setParams(self, params, negMsgHandler=None, sendToCover=True):
        """ set parameters from outside
            + init module if necessary
            + mainly receive parameter changes from Gui
            + send status messages to COVER if state has changed
        """
        realChange = ParamsDiff(self.params, params)

        PartModuleVis.setParams(self, params, negMsgHandler, sendToCover,
                                realChange)
        PartColoredVis.setParams(self, params, negMsgHandler, sendToCover,
                                 realChange)

    def connectionPoint(self):
        """ return the connection (module/outport) to be connected to COVER
            called by the class VisItem """
        return ConnectionPoint(self.__myCollect, 'GeometryOut0')


#        return PartModuleVis.connectionPoint(self, 'linesOut')

    def getCoObjName(self):
        """ return the generated covise object name
            called by the class VisItem to check if an object name registered by the COVER was created by the iso cutter
        """
        # the returned string is independent of the given portname, but portname must match the name of an out port
        return self.__myCollect.getCoObjName('GeometryOut0')
Exemplo n.º 9
0
class PartMagmaTraceVis(PartModuleVis, PartColoredVis):
    """ VisItem to compute iso cropped polygons from polygons """

    def __init__(self):
        PartModuleVis.__init__(self, MagmaTrace, VIS_MAGMATRACE, self.__class__.__name__,['geo_in'],[],[],[],['data_in'])
        PartColoredVis.__init__(self)

        self.params = PartMagmaTraceVisParams()
        self.__initBase()

    def __initBase(self):
        """
            + __initBase is called from the constructor and after the class was unpickled
            + add privately created modules here
        """
        self.__firstTime = True

        # create custom modules here
        self.__myCollect = Collect()
        self.__myColors  = Colors()
        theNet().add(self.__myCollect)
        theNet().add(self.__myColors)


    def __init(self, negMsgHandler):
        """ __init is called from __update
            + start _module module if it does not already exist and connect output to COVER
            + set default parameters of module
            + set default boundingBox which is also used in the GUI to set borders of the float sliders
            + set color inport and corresponding module
            + send params to the gui
        """
        if self.__firstTime == True:
            self.__firstTime = False
            PartModuleVis._init(self, negMsgHandler)
            PartColoredVis._init(self, negMsgHandler, self.__myColors, 'cmapIn')
            self.__register(negMsgHandler)

            # make my custom connections between further self created modules here
            theNet().connect(self._module, 'geo_out', self.__myCollect, 'grid')
            theNet().connect(self.__myColors, 'colors', self.__myCollect, 'colors')
            theNet().connect(self._module, 'data_out', self.__myColors, 'Data')

            # send params to gui
            self.sendParams()

    def __getstate__(self):
        mycontent = PartModuleVis.__getstate__(self)
        del mycontent['_PartMagmaTraceVis__myCollect']
        del mycontent['_PartMagmaTraceVis__myColors']
        return mycontent

    def recreate(self, negMsgHandler, parentKey, offset):
        """ recreate is called after all classes of the session have been unpickled """
        PartMagmaTraceVisParams.mergeDefaultParams(self.params) # explicitly call mergeDefaultParams of this class
        self.__initBase()
        PartModuleVis.recreate(self, negMsgHandler, parentKey, offset, MagmaTrace, ['geo_in'],[],[],[],['data_in'] )
        PartColoredVis.recreate(self, negMsgHandler, parentKey, offset)
        PartColoredVis.setColorMap(self,True)

    def delete(self, isInitialized, negMsgHandler=None):
        if isInitialized:
            if hasattr(self, '_PartMagmaTraceVis__myCollect') and self.__myCollect: theNet().remove(self.__myCollect)
            if hasattr(self, '_PartMagmaTraceVis__myColors') and self.__myColors: theNet().remove(self.__myColors)
        PartModuleVis.delete(self, isInitialized, negMsgHandler)

    def __update(self, negMsgHandler):
        """ __update is called from the run method to update the module parameter before execution
            + do init of the IsoCutter module if necessary
            + update module parameters """
        self.__init(negMsgHandler)
        PartModuleVis._update(self, negMsgHandler)
        PartColoredVis._update(self, negMsgHandler)

        # other parameters
        self._module.set_len(self.params.length)
        self._module.set_skip(self.params.skip)
        self._module.setTitle( self.params.name )


    def run(self, runmode, negMsgHandler):
        """ create a new visulisation
            + register for events from Covise if not done yet
            + runmode RUN_GEO and RUN_OCT are ignored
            + update module parameter
            + exec the module
        """
        assert negMsgHandler

        if runmode==RUN_ALL:
            _infoer.function = str(self.run)
            _infoer.write("go")

            if not hasattr(self, 'importModule'):
                return

            self.__update(negMsgHandler)

            PartModuleVis.run(self, runmode, negMsgHandler)
            PartColoredVis.run(self, runmode, negMsgHandler, self._module, self.fromRecreation )   # self._module is not used!

    def __register(self, negMsgHandler):
        """ register to receive events from covise """
        PartModuleVis.register( self, negMsgHandler, ['len', 'skip'] )

    def setParamsByModule( self, mparam, mvalue):
        """ receives parameter changes from the iso cutter module
            return a list of objKey and their parameters to be set by the Neg2Gui class
        """
        _infoer.function = str(self.setParamsByModule)
        _infoer.write("param: %s, value: %s" % (mparam, str(mvalue)))
        pChangeList = []
        newparams = CopyParams(self.params)
        if mparam == 'len':
            try:
                newparams.length= int(mvalue[0])
            except ValueError:
                newparams.length= int(float(mvalue[0]))

        if mparam == 'skip':
            try:
                newparams.skip= int(mvalue[0])
            except ValueError:
                newparams.skip= int(float(mvalue[0]))

        pChangeList.append( (self.key, newparams) )

        return pChangeList

    def setParams( self, params, negMsgHandler=None, sendToCover=True):
        """ set parameters from outside
            + init module if necessary
            + mainly receive parameter changes from Gui
            + send status messages to COVER if state has changed
        """
        realChange = ParamsDiff( self.params, params )  

        PartModuleVis.setParams(self, params, negMsgHandler, sendToCover, realChange)
        PartColoredVis.setParams(self, params, negMsgHandler, sendToCover, realChange)

    def connectionPoint(self):
        """ return the connection (module/outport) to be connected to COVER
            called by the class VisItem """
        return ConnectionPoint(self.__myCollect, 'geometry')

    def getCoObjName(self):
        """ return the generated covise object name
            called by the class VisItem to check if an object name registered by the COVER was created by the iso cutter
        """
        # the returned string is independent of the given portname, but portname must match the name of an out port
        return self.__myCollect.getCoObjName('geometry')
Exemplo n.º 10
0
class PartVectorFieldVis(PartModuleVis, PartColoredVis, PartTransform):
    """ VisItem to compute iso cropped polygons from polygons """
    def __init__(self):
        PartModuleVis.__init__(self, VectorField, VIS_VECTORFIELD,
                               self.__class__.__name__, ['meshIn'], [], [], [],
                               ['vdataIn'])
        PartColoredVis.__init__(self)
        PartTransform.__init__(self, True)

        self.params = PartVectorFieldVisParams()
        self.__initBase()

    def __initBase(self):
        """
            + __initBase is called from the constructor and after the class was unpickled
            + add privately created modules here
        """
        self.__firstTime = True

        # create custom modules here
        self.__myCollect = Collect()
        self.__myColors = Colors()
        theNet().add(self.__myCollect)
        theNet().add(self.__myColors)

    def __init(self, negMsgHandler):
        """ __init is called from __update
            + start _module module if it does not already exist and connect output to COVER
            + set default parameters of module
            + set default boundingBox which is also used in the GUI to set borders of the float sliders
            + set color inport and corresponding module
            + send params to the gui
        """
        if self.__firstTime == True:
            self.__firstTime = False
            PartModuleVis._init(self, negMsgHandler)
            PartColoredVis._init(self, negMsgHandler, self.__myColors,
                                 'ColormapIn0')
            self.__register(negMsgHandler)

            # make my custom connections between further self created modules here
            theNet().connect(self._module, 'linesOut', self.__myCollect,
                             'GridIn0')
            theNet().connect(self.__myColors, 'DataOut0', self.__myCollect,
                             'DataIn0')
            theNet().connect(self._module, 'dataOut', self.__myColors,
                             'DataIn0')

            # adjust slider range from bounding box
            # done only once, range wont change anymore
            #            maxSideLength = self.params.boundingBox.getMaxEdgeLength()
            #            self.params.minScalingValue = -maxSideLength
            #            self.params.maxScalingValue =  maxSideLength

            # append variable name to real name if not fromRecreation
            if not self.fromRecreation:
                self.params.name = self.params.name + " (" + self.params.variable + ")"

            # send params to gui
            self.sendParams()

    def __getstate__(self):
        mycontent = PartModuleVis.__getstate__(self)
        del mycontent['_PartVectorFieldVis__myCollect']
        del mycontent['_PartVectorFieldVis__myColors']
        return mycontent

    def recreate(self, negMsgHandler, parentKey, offset):
        """ recreate is called after all classes of the session have been unpickled """
        PartVectorFieldVisParams.mergeDefaultParams(
            self.params)  # explicitly call mergeDefaultParams of this class
        self.__initBase()
        PartModuleVis.recreate(self, negMsgHandler, parentKey, offset,
                               VectorField, ['meshIn'], [], [], [],
                               ['vdataIn'])
        PartColoredVis.recreate(self, negMsgHandler, parentKey, offset)
        PartColoredVis.setColorMap(self, True)
        PartTransform.recreate(self, negMsgHandler, parentKey, offset)

    def delete(self, isInitialized, negMsgHandler=None):
        if isInitialized:
            if hasattr(self,
                       '_PartVectorFieldVis__myCollect') and self.__myCollect:
                theNet().remove(self.__myCollect)
            if hasattr(self,
                       '_PartVectorFieldVis__myColors') and self.__myColors:
                theNet().remove(self.__myColors)
        PartModuleVis.delete(self, isInitialized, negMsgHandler)

    def __update(self, negMsgHandler):
        """ __update is called from the run method to update the module parameter before execution
            + do init of the IsoCutter module if necessary
            + update module parameters """
        self.__init(negMsgHandler)
        PartModuleVis._update(self, negMsgHandler)
        PartColoredVis._update(self, negMsgHandler)

        #        self._module.set_scale(self.params.minScalingValue, self.params.maxScalingValue, self.params.scalingValue)
        self._module.set_scale(self.params.scalingValue - 1.0,
                               self.params.scalingValue + 1.0,
                               self.params.scalingValue)
        self._module.set_length(self.params.scalingType +
                                1)  # +1 because covise choices start from 1
        self._module.set_arrow_head_factor(self.params.arrowHeadFactor)
        self._module.set_num_sectors(3)
        self._module.setTitle(self.params.name)

    def run(self, runmode, negMsgHandler):
        """ create a new visulisation
            + register for events from Covise if not done yet
            + runmode RUN_GEO and RUN_OCT are ignored
            + update module parameter
            + exec the module
        """
        assert negMsgHandler

        if runmode == RUN_ALL:
            _infoer.function = str(self.run)
            _infoer.write("go")

            if not hasattr(self, 'importModule'):
                return

            self.__update(negMsgHandler)

            PartColoredVis.run(
                self, runmode, negMsgHandler, self._module,
                self.fromRecreation)  # self._module is not used!
            PartModuleVis.run(self, runmode, negMsgHandler)
            #self._sendMatrix()

            if self.params.coloringOption == RGB_COLOR:
                self.__sendColor()

    def __register(self, negMsgHandler):
        """ register to receive events from covise """
        PartModuleVis.register(self, negMsgHandler, [])

    def setParamsByModule(self, mparam, mvalue):
        """ receives parameter changes from the iso cutter module
            return a list of objKey and their parameters to be set by the Neg2Gui class
        """
        _infoer.function = str(self.setParamsByModule)
        _infoer.write("param: %s, value: %s" % (mparam, str(mvalue)))
        pChangeList = []
        newparams = CopyParams(self.params)

        pChangeList.append((self.key, newparams))

        return pChangeList

    def setParams(self, params, negMsgHandler=None, sendToCover=True):
        """ set parameters from outside
            + init module if necessary
            + mainly receive parameter changes from Gui
            + send status messages to COVER if state has changed
        """
        realChange = ParamsDiff(self.params, params)

        PartModuleVis.setParams(self, params, negMsgHandler, sendToCover,
                                realChange)
        PartColoredVis.setParams(self, params, negMsgHandler, sendToCover,
                                 realChange)
        PartTransform.setParams(self, params, negMsgHandler, sendToCover,
                                realChange)

        if self.params.coloringOption == RGB_COLOR:
            self.__sendColor()

    def connectionPoint(self):
        """ return the connection (module/outport) to be connected to COVER
            called by the class VisItem """
        #return PartModuleVis.connectionPoint(self, 'linesOut')
        return ConnectionPoint(self.__myCollect, 'GeometryOut0')

    def getCoObjName(self):
        """ return the generated covise object name
            called by the class VisItem to check if an object name registered by the COVER was created by the iso cutter
        """
        # the returned string is independent of the given portname, but portname must match the name of an out port
        #return PartModuleVis.getCoObjName(self, 'linesOut')
        return self.__myCollect.getCoObjName('GeometryOut0')

    def __sendColor(self):
        """ send interactor geometry to cover """
        if self.keyRegistered():
            _infoer.function = str(self.__sendColor)
            _infoer.write("send")
            msg = coGRObjColorObjMsg(coGRMsg.COLOR_OBJECT, self.covise_key,
                                     self.params.r, self.params.g,
                                     self.params.b)
            covise.sendRendMsg(msg.c_str())
Exemplo n.º 11
0
class PartVectorFieldVis(PartModuleVis, PartColoredVis, PartTransform):
    """ VisItem to compute iso cropped polygons from polygons """

    def __init__(self):
        PartModuleVis.__init__(self, VectorField, VIS_VECTORFIELD, self.__class__.__name__,['meshIn'],[],[],[],['vdataIn'])
        PartColoredVis.__init__(self)
        PartTransform.__init__(self, True)

        self.params = PartVectorFieldVisParams()
        self.__initBase()


    def __initBase(self):
        """
            + __initBase is called from the constructor and after the class was unpickled
            + add privately created modules here
        """
        self.__firstTime = True

        # create custom modules here
        self.__myCollect = Collect()
        self.__myColors  = Colors()
        theNet().add(self.__myCollect)
        theNet().add(self.__myColors)


    def __init(self, negMsgHandler):
        """ __init is called from __update
            + start _module module if it does not already exist and connect output to COVER
            + set default parameters of module
            + set default boundingBox which is also used in the GUI to set borders of the float sliders
            + set color inport and corresponding module
            + send params to the gui
        """
        if self.__firstTime == True:
            self.__firstTime = False
            PartModuleVis._init(self, negMsgHandler)
            PartColoredVis._init(self, negMsgHandler, self.__myColors, 'ColormapIn0')
            self.__register(negMsgHandler)

            # make my custom connections between further self created modules here
            theNet().connect(self._module, 'linesOut', self.__myCollect, 'GridIn0')
            theNet().connect(self.__myColors, 'DataOut0', self.__myCollect, 'DataIn0')
            theNet().connect(self._module, 'dataOut', self.__myColors, 'DataIn0')

            # adjust slider range from bounding box
            # done only once, range wont change anymore
#            maxSideLength = self.params.boundingBox.getMaxEdgeLength()
#            self.params.minScalingValue = -maxSideLength
#            self.params.maxScalingValue =  maxSideLength

            # append variable name to real name if not fromRecreation
            if not self.fromRecreation:
                self.params.name = self.params.name + " (" + self.params.variable + ")"

            # send params to gui
            self.sendParams()

    def __getstate__(self):
        mycontent = PartModuleVis.__getstate__(self)
        del mycontent['_PartVectorFieldVis__myCollect']
        del mycontent['_PartVectorFieldVis__myColors']
        return mycontent

    def recreate(self, negMsgHandler, parentKey, offset):
        """ recreate is called after all classes of the session have been unpickled """
        PartVectorFieldVisParams.mergeDefaultParams(self.params) # explicitly call mergeDefaultParams of this class
        self.__initBase()
        PartModuleVis.recreate(self, negMsgHandler, parentKey, offset, VectorField, ['meshIn'],[],[],[],['vdataIn'] )
        PartColoredVis.recreate(self, negMsgHandler, parentKey, offset)
        PartColoredVis.setColorMap(self,True)
        PartTransform.recreate(self, negMsgHandler, parentKey, offset)  

    def delete(self, isInitialized, negMsgHandler=None):
        if isInitialized:
            if hasattr(self, '_PartVectorFieldVis__myCollect') and self.__myCollect: theNet().remove(self.__myCollect)
            if hasattr(self, '_PartVectorFieldVis__myColors') and self.__myColors: theNet().remove(self.__myColors)
        PartModuleVis.delete(self, isInitialized, negMsgHandler)

    def __update(self, negMsgHandler):
        """ __update is called from the run method to update the module parameter before execution
            + do init of the IsoCutter module if necessary
            + update module parameters """
        self.__init(negMsgHandler)
        PartModuleVis._update(self, negMsgHandler)
        PartColoredVis._update(self, negMsgHandler)

#        self._module.set_scale(self.params.minScalingValue, self.params.maxScalingValue, self.params.scalingValue)
        self._module.set_scale(self.params.scalingValue-1.0, self.params.scalingValue+1.0, self.params.scalingValue)
        self._module.set_length(self.params.scalingType + 1)    # +1 because covise choices start from 1
        self._module.set_arrow_head_factor(self.params.arrowHeadFactor)
        self._module.set_num_sectors(3)
        self._module.setTitle( self.params.name )


    def run(self, runmode, negMsgHandler):
        """ create a new visulisation
            + register for events from Covise if not done yet
            + runmode RUN_GEO and RUN_OCT are ignored
            + update module parameter
            + exec the module
        """
        assert negMsgHandler

        if runmode==RUN_ALL:
            _infoer.function = str(self.run)
            _infoer.write("go")

            if not hasattr(self, 'importModule'):
                return

            self.__update(negMsgHandler)

            PartColoredVis.run(self, runmode, negMsgHandler, self._module, self.fromRecreation )   # self._module is not used!
            PartModuleVis.run(self, runmode, negMsgHandler)
            #self._sendMatrix()

            if self.params.coloringOption == RGB_COLOR:
                self.__sendColor()

    def __register(self, negMsgHandler):
        """ register to receive events from covise """
        PartModuleVis.register( self, negMsgHandler, [] )

    def setParamsByModule( self, mparam, mvalue):
        """ receives parameter changes from the iso cutter module
            return a list of objKey and their parameters to be set by the Neg2Gui class
        """
        _infoer.function = str(self.setParamsByModule)
        _infoer.write("param: %s, value: %s" % (mparam, str(mvalue)))
        pChangeList = []
        newparams = CopyParams(self.params)

        pChangeList.append( (self.key, newparams) )

        return pChangeList

    def setParams( self, params, negMsgHandler=None, sendToCover=True):
        """ set parameters from outside
            + init module if necessary
            + mainly receive parameter changes from Gui
            + send status messages to COVER if state has changed
        """
        realChange = ParamsDiff( self.params, params )  

        PartModuleVis.setParams(self, params, negMsgHandler, sendToCover, realChange)
        PartColoredVis.setParams(self, params, negMsgHandler, sendToCover, realChange)
        PartTransform.setParams(self, params, negMsgHandler, sendToCover, realChange)

        if self.params.coloringOption == RGB_COLOR:
            self.__sendColor()

    def connectionPoint(self):
        """ return the connection (module/outport) to be connected to COVER
            called by the class VisItem """
        #return PartModuleVis.connectionPoint(self, 'linesOut')
        return ConnectionPoint(self.__myCollect, 'GeometryOut0')

    def getCoObjName(self):
        """ return the generated covise object name
            called by the class VisItem to check if an object name registered by the COVER was created by the iso cutter
        """
        # the returned string is independent of the given portname, but portname must match the name of an out port
        #return PartModuleVis.getCoObjName(self, 'linesOut')
        return self.__myCollect.getCoObjName('GeometryOut0')

    def __sendColor(self):
        """ send interactor geometry to cover """
        if self.keyRegistered():
            _infoer.function = str(self.__sendColor)
            _infoer.write("send")
            msg = coGRObjColorObjMsg( coGRMsg.COLOR_OBJECT, self.covise_key, self.params.r, self.params.g, self.params.b)
            covise.sendRendMsg(msg.c_str())
Exemplo n.º 12
0
class PartDomainLinesVis(PartModuleVis):
    """ VisItem to compute iso cropped polygons from polygons """

    def __init__(self):
        PartModuleVis.__init__(self, DomainSurface, VIS_DOMAINLINES, self.__class__.__name__,['GridIn0'],[],[],[],[],[],[],None,False,False)
        
        self.params = PartDomainLinesVisParams()
        self.__initBase()

    def __initBase(self):
        """
            + __initBase is called from the constructor and after the class was unpickled
            + add privately created modules here
        """
        self.__firstTime = True

        # create custom modules here
        self.__myCollect = Collect()
        theNet().add(self.__myCollect)

    def __init(self, negMsgHandler):
        """ __init is called from __update
            + start _module module if it does not already exist and connect output to COVER
            + set default parameters of module
            + set default boundingBox which is also used in the GUI to set borders of the float sliders
            + set color inport and corresponding module
            + send params to the gui
        """
        if self.__firstTime == True:
            self.__firstTime = False
            PartModuleVis._init(self, negMsgHandler)
            
            # make my custom connections between further self created modules here
            theNet().connect(self._module, 'GridOut1', self.__myCollect, 'GridIn0')

            # send params to gui
            self.sendParams()

    def __getstate__(self):
        mycontent = PartModuleVis.__getstate__(self)
        del mycontent['_PartDomainLinesVis__myCollect']
        return mycontent

    def recreate(self, negMsgHandler, parentKey, offset):
        """ recreate is called after all classes of the session have been unpickled """
        PartDomainLinesVisParams.mergeDefaultParams(self.params) # explicitly call mergeDefaultParams of this class
        self.__initBase()
        PartModuleVis.recreate(self, negMsgHandler, parentKey, offset, DomainSurface, ['GridIn0'],[],[],[],[],[],[],None,False,False )

    def delete(self, isInitialized, negMsgHandler=None):
        if isInitialized:
            if hasattr(self, '_PartDomainLinesVis__myCollect') and self.__myCollect: theNet().remove(self.__myCollect)
        PartModuleVis.delete(self, isInitialized, negMsgHandler)

    def __update(self, negMsgHandler):
        """ __update is called from the run method to update the module parameter before execution
            + do init of the IsoCutter module if necessary
            + update module parameters """
        self.__init(negMsgHandler)
        PartModuleVis._update(self, negMsgHandler)

    def run(self, runmode, negMsgHandler):
        """ create a new visulisation
            + register for events from Covise if not done yet
            + runmode RUN_GEO and RUN_OCT are ignored
            + update module parameter
            + exec the module
        """
        assert negMsgHandler
        if runmode==RUN_ALL:
            _infoer.function = str(self.run)
            _infoer.write("go")

            if not hasattr(self, 'importModule'):
                return
            
            self.__update(negMsgHandler)
            PartModuleVis.run(self, runmode, negMsgHandler)
    
    def setParams( self, params, negMsgHandler=None, sendToCover=True):
        """ set parameters from outside
            + init module if necessary
            + mainly receive parameter changes from Gui
            + send status messages to COVER if state has changed
        """
        realChange = ParamsDiff( self.params, params )  

        PartModuleVis.setParams(self, params, negMsgHandler, sendToCover, realChange)
        
    def connectionPoint(self):
        """ return the connection (module/outport) to be connected to COVER
            called by the class VisItem """
        return ConnectionPoint(self.__myCollect, 'GeometryOut0')
        #return PartModuleVis.connectionPoint(self, 'linesOut')

    def getCoObjName(self):
        """ return the generated covise object name
            called by the class VisItem to check if an object name registered by the COVER was created by the iso cutter
        """
        # the returned string is independent of the given portname, but portname must match the name of an out port
        return self.__myCollect.getCoObjName('GeometryOut0')