Пример #1
0
def buildSection_objDefaults(self,parent,frame=True):
    try:self.var_objDefaultAimAxis
    except:self.var_objDefaultAimAxis = cgmMeta.cgmOptionVar('cgmVar_objDefaultAimAxis', defaultValue = 2)
    try:self.var_objDefaultUpAxis
    except:self.var_objDefaultUpAxis = cgmMeta.cgmOptionVar('cgmVar_objDefaultUpAxis', defaultValue = 1)
    try:self.var_objDefaultOutAxis
    except:self.var_objDefaultOutAxis = cgmMeta.cgmOptionVar('cgmVar_objDefaultOutAxis', defaultValue = 3)    
    if frame:
        _frame = mUI.MelFrameLayout(parent,label = 'Obj Defaults',vis=True,
                                    collapse=self.var_objectDefaultsFrameCollapse.value,
                                    collapsable=True,
                                    enable=True,
                                    useTemplate = 'cgmUIHeaderTemplate',
                                    expandCommand = lambda:self.var_objectDefaultsFrameCollapse.setValue(0),
                                    collapseCommand = lambda:self.var_objectDefaultsFrameCollapse.setValue(1)
                                    )	
        _inside = mUI.MelColumnLayout(_frame,useTemplate = 'cgmUISubTemplate') 
    else:
        _inside = parent


    #>>>Aim defaults mode -------------------------------------------------------------------------------------
    _d = {'aim':self.var_objDefaultAimAxis,
          'up':self.var_objDefaultUpAxis,
          'out':self.var_objDefaultOutAxis}

    for k in _d.keys():
        _var = _d[k]

        _row = mUI.MelHSingleStretchLayout(_inside,ut='cgmUISubTemplate',padding = 5)

        mUI.MelSpacer(_row,w=5)                      
        mUI.MelLabel(_row,l='Obj {0}:'.format(k))
        _row.setStretchWidget( mUI.MelSeparator(_row) )

        uiRC = mUI.MelRadioCollection()

        _on = _var.value

        for i,item in enumerate(SHARED._l_axis_by_string):
            if i == _on:
                _rb = True
            else:_rb = False

            uiRC.createButton(_row,label=item,sl=_rb,
                              onCommand = cgmGEN.Callback(_var.setValue,i))

            mUI.MelSpacer(_row,w=2)       


        _row.layout() 


    #>>>Buttons -------------------------------------------------------------------------------------
    _row_defaults = mUI.MelHLayout(_inside,ut='cgmUISubTemplate',padding = 5, )

    cgmUI.add_Button(_row_defaults,'Tag selected for aim',
                     lambda *a:MMCONTEXT.func_process(SNAP.verify_aimAttrs, mc.ls(sl=True),'each','Verify aim attributes',True,**{}),)                                       
    _row_defaults.layout() 
Пример #2
0
def uiFunc_snapOrdered(self):
    try:
        _d = uiQuery_advancedSnap(self)
        _sel = _d.pop('sl')
        if not _sel:
            return log.error("Nothing selected")
        
        #if len(_sel) == 1:
        #    targets = None
        #else:
        #    targets = _sel[1:]
        #obj = _sel[0]
        #SNAPCALLS.snap( obj,targets, **_d)
        targets = _sel
        #targets.reverse()
        reload(MMCONTEXT)
        MMCONTEXT.func_process(SNAPCALLS.snap,targets,'eachToNextReverse',**_d)
    except Exception,err:
        cgmGEN.cgmExceptCB(Exception,err)
Пример #3
0
def snap_action(objects=None,
                snapMode='point',
                selectionMode='eachToLast',
                **kws):
    """
    """
    try:
        _str_func = 'snap_action'
        subKWS = {}
        if objects is None:
            objects = mc.ls(sl=True)

        if snapMode == 'aim':
            aim_axis = SHARED._l_axis_by_string[var_objDefaultAimAxis.value]
            up_axis = SHARED._l_axis_by_string[var_objDefaultUpAxis.value]

            subKWS = {
                'aimAxis': aim_axis,
                'upAxis': up_axis,
                'mode': var_aimMode.value
            }

            if selectionMode == 'firstToRest':
                MMCONTEXT.func_process(SNAP.aim_atMidPoint, objects,
                                       selectionMode, 'Snap aim', **subKWS)
            else:
                MMCONTEXT.func_process(SNAP.aim, objects, selectionMode,
                                       'Snap aim', **subKWS)

            if selectionMode == 'eachToNext':
                SNAP.aim(objects[-1], objects[-2],
                         VALID.simpleAxis(aim_axis).inverse.p_string, up_axis,
                         var_aimMode.value)

        elif snapMode == 'ground':
            MMCONTEXT.func_process(SNAP.to_ground, objects, 'each', 'Snap')

        elif snapMode in [
                'axisBox', 'boundingBox', 'boundingBoxShapes',
                'boundingBoxEach', 'castCenter', 'castFar', 'castNear',
                'castAllCenter', 'castAllFar', 'castAllNear'
        ]:
            log.debug("|{0}| | special mode: {1}".format(_str_func, snapMode))
            subKWS['mode'] = kws.get('mode', 'z+')
            subKWS['arg'] = snapMode

            if len(objects) == 1:
                specialSnap(objects[0], **subKWS)
            elif snapMode in ['boundingBox'] and selectionMode != 'each':
                log.debug("|{0}| | bb each mode".format(_str_func, snapMode))
                specialSnap(objects[0], objects, **subKWS)
            else:
                MMCONTEXT.func_process(specialSnap, objects, selectionMode,
                                       'Snap Special', **subKWS)

        else:
            subKWS = {
                'position': False,
                'rotation': False,
                'rotateAxis': False,
                'rotateOrder': False,
                'scalePivot': False,
                'pivot': 'rp',
                'space': 'w',
                'mode': 'xform'
            }

            if snapMode in ['point', 'closestPoint']:
                subKWS['position'] = True
            elif snapMode == 'orient':
                subKWS['rotation'] = True
            elif snapMode == 'parent':
                subKWS['position'] = True
                subKWS['rotation'] = True
            elif snapMode == 'aim':
                subKWS['rotation'] = True
            else:
                raise ValueError, "Unknown mode!"

            _pivotMode = var_snapPivotMode.value

            if snapMode == 'closestPoint':
                subKWS['pivot'] = 'closestPoint'
            else:
                if not _pivotMode: pass  #0 handled by default
                elif _pivotMode == 1:
                    subKWS['pivot'] = 'sp'
                elif _pivotMode == 2:
                    subKWS['pivot'] = 'boundingBox'
                else:
                    raise ValueError, "Uknown pivotMode: {0}".format(
                        _pivotMode)

            MMCONTEXT.func_process(SNAP.go, objects, selectionMode, 'Snap',
                                   **subKWS)

        mc.select(objects)
        return
    except Exception, err:
        cgmGEN.cgmExceptCB(Exception, err, msg=vars())