def cadnanoVBaseToMayaCoords(self, base, strand): """ Given a Strand and a Base, returns a 3D location of that base """ m = Mom() mID = m.strandMayaID(strand) cylinderName = "%s%s" % (m.helixNodeName, mID) if cmds.objExists(cylinderName): rise = cmds.getAttr("%s.rise" % cylinderName) startBase = cmds.getAttr("%s.startBase" % cylinderName) startPos = cmds.getAttr("%s.startPos" % cylinderName) base0Pos = startPos[0][1] + (startBase * rise) ourPos = base0Pos - (base * rise) zComp = ourPos rotation = cmds.getAttr("%s.rotation" % cylinderName) radius = cmds.getAttr("%s.radius" % cylinderName) parity = cmds.getAttr("%s.parity" % cylinderName) strandType = cmds.getAttr("%s.strandType" % cylinderName) rotationOffset = cmds.getAttr("%s.rotationOffset" % cylinderName) decoratorRotOffset = cmds.getAttr("%s.decoratorRotOffset" % cylinderName) # not clear why decoratorRotOffset is not in radians but # rotationOffset is decoratorRotOffset = decoratorRotOffset * math.pi / 180 starting_rotation = (math.pi * (not parity)) + rotationOffset + decoratorRotOffset + (math.pi * strandType) fullrotation = -rotation * base * math.pi / 180 # print full rotation xComp = self._x + radius * math.cos(starting_rotation + fullrotation) yComp = self._y + radius * math.sin(starting_rotation + fullrotation) # print "%f %f %f" % (xComp, yComp, zComp) return (xComp, yComp, zComp) else: raise IndexError
def strandRemovedSlot(self, strand): """ Receives notification from the model when a strand is removed. Deletes the strand related mapping in mayaObjectManager, deletes all the Maya nodes, deletes all the decorators(live in the virtualHelixItem right now), deletes itself from the virtualHelixItem, and disconnects itself from the controller. """ mom = Mom() mID = mom.strandMayaID(strand) mom.removeIDMapping(mID, strand) # print "solidview.StrandItem.strandRemovedSlot %s" % mID transformName = "%s%s" % (mom.helixTransformName, mID) cylinderName = "%s%s" % (mom.helixNodeName, mID) meshName = "%s%s" % (mom.helixMeshName, mID) if cmds.objExists(transformName): cmds.delete(transformName) if cmds.objExists(cylinderName): cmds.delete(cylinderName) if cmds.objExists(meshName): cmds.delete(meshName) if mID in self._virtualHelixItem.StrandIDs(): self._virtualHelixItem.StrandIDs().remove(mID) self._virtualHelixItem.updateDecorators() self._virtualHelixItem.removeStrandItem(self) self._virtualHelixItem = None self._modelStrand = None self._controller.disconnectSignals() self._controller = None
def strandHasNewOligoSlot(self, strand): """ Receives notification from the model when there is a new oligo. Updates the color of the strandItem associated with this strand """ mom = Mom() self._controller.reconnectOligoSignals() mID = mom.strandMayaID(strand) self.updateColor(mID, strand.oligo().color())
def oligoAppearanceChangedSlot(self, oligo): """ Receives notification from the model when a oligo changes appearance. Updates the color of the strandItem associated with this strand """ mom = Mom() id = mom.strandMayaID(self._modelStrand) self.updateColor(id, oligo.color()) pass
def strandAddedSlot(self, sender, strand): """ Instantiates a StrandItem upon notification that the model has a new Strand. The StrandItem is responsible for creating its own controller for communication with the model, and for adding itself to its parent (which is *this* VirtualHelixItem, i.e. 'self'). """ # print "solidview.VirtualHelixItem.strandAddedSlot" m = Mom() mID = m.strandMayaID(strand) self.strandIDs.append(mID) sI = StrandItem(mID, strand, self) self._strandItems[sI] = True self.updateDecorators()
def updateSize(self): """ Update Maya's Half Cylinder Node attributes related to the size """ mom = Mom() mID = mom.strandMayaID(self._modelStrand) cylinderName = "%s%s" % (mom.helixNodeName, mID) endpoints = self._modelStrand.idxs() totalNumBases = \ self._virtualHelixItem.virtualHelix().part().maxBaseIdx() cmds.setAttr("%s.startBase" % cylinderName, endpoints[0]) cmds.setAttr("%s.endBase" % cylinderName, endpoints[1]) cmds.setAttr("%s.totalBases" % cylinderName, int(totalNumBases))
def createDecorators(self, strand): """Create a set of new Pre-Decortators for a given strand""" m = Mom() strandId = m.strandMayaID(strand) totalNumBases = self._modelVirtualHelix.part().maxBaseIdx() preDecoratorIdxList = strand.getPreDecoratorIdxList() for baseIdx in preDecoratorIdxList: # XXX [SB+AT] NOT THREAD SAFE while cmds.objExists("%s%s_%s" % (m.decoratorNodeName, strandId, self.stapleIndicatorCount)): self.stapleIndicatorCount += 1 stapleId = "%s_%s" % (strandId, self.stapleIndicatorCount) coords = self.cadnanoVBaseToMayaCoords(baseIdx, strand) stapleModNodeInfo = self.createDecoratorNodes(coords, stapleId) self.stapleModIndicatorIDs.append(stapleId) m = Mom() m.decoratorToVirtualHelixItem[stapleModNodeInfo[2]] = (self, baseIdx, strand) m.decoratorToVirtualHelixItem[stapleModNodeInfo[1]] = (self, baseIdx, strand)
def selectedChangedSlot(self, strand, indices): #print "solidview.stranditem.selectedChangedSlot", strand, indices mom = Mom() if mom.ignoreExternalSelectionSignal: return mID = mom.strandMayaID(strand) mom.ignoreExternalSelectionSignal = True transformName = "%s%s" % (mom.helixTransformName, mID) if cmds.objExists(transformName): if(indices[0] or indices[1]): cmds.select(transformName, add=True) # print "selecting a strand" self._viewroot.addToSelectionDict(strand) else: # print "deselecting in the slot" cmds.select(transformName, deselect=True) self._viewroot.removeFromSelectionDict(strand) mom.ignoreExternalSelectionSignal = False
def selectedChangedSlot(self, strand, indices): #print "solidview.stranditem.selectedChangedSlot", strand, indices mom = Mom() if mom.ignoreExternalSelectionSignal: return mID = mom.strandMayaID(strand) mom.ignoreExternalSelectionSignal = True transformName = "%s%s" % (mom.helixTransformName, mID) if cmds.objExists(transformName): if (indices[0] or indices[1]): cmds.select(transformName, add=True) # print "selecting a strand" self._viewroot.addToSelectionDict(strand) else: # print "deselecting in the slot" cmds.select(transformName, deselect=True) self._viewroot.removeFromSelectionDict(strand) mom.ignoreExternalSelectionSignal = False
def cadnanoVBaseToMayaCoords(self, base, strand): """ Given a Strand and a Base, returns a 3D location of that base """ m = Mom() mID = m.strandMayaID(strand) cylinderName = "%s%s" % (m.helixNodeName, mID) if cmds.objExists(cylinderName): rise = cmds.getAttr("%s.rise" % cylinderName) startBase = cmds.getAttr("%s.startBase" % cylinderName) startPos = cmds.getAttr("%s.startPos" % cylinderName) base0Pos = startPos[0][1] + (startBase * rise) ourPos = base0Pos - (base * rise) zComp = ourPos rotation = cmds.getAttr("%s.rotation" % cylinderName) radius = cmds.getAttr("%s.radius" % cylinderName) parity = cmds.getAttr("%s.parity" % cylinderName) strandType = cmds.getAttr("%s.strandType" % cylinderName) rotationOffset = cmds.getAttr("%s.rotationOffset" % cylinderName) decoratorRotOffset = cmds.getAttr("%s.decoratorRotOffset" % cylinderName) # not clear why decoratorRotOffset is not in radians but # rotationOffset is decoratorRotOffset = decoratorRotOffset * math.pi / 180 starting_rotation = (math.pi * (not parity)) + rotationOffset + \ decoratorRotOffset + \ (math.pi * strandType) fullrotation = -rotation * base * math.pi / 180 #print full rotation xComp = self._x + radius * \ math.cos(starting_rotation + fullrotation) yComp = self._y + radius * \ math.sin(starting_rotation + fullrotation) #print "%f %f %f" % (xComp, yComp, zComp) return (xComp, yComp, zComp) else: raise IndexError
def dagParentRemovedCallback(child, parent, clientData): """ Callback function that removes the strands from the model if the 3D strand is delete in 3D view. """ mom = Mom() children = child.fullPathName().split("|") for c in children: if c.startswith(mom.helixMeshName): if c in mom.mayaToCn: strand = mom.mayaToCn[c] if strand: # print "Strand %s : %s needs removal" % (c, strand) mID = mom.strandMayaID(strand) mom.removeIDMapping(mID, strand) strand.strandSet().removeStrand(strand) else: print("Error: no Strand inside mayaObjectModel") else: pass # print "dagParentRemovedCallback: %s already deleted" % c elif c.startswith(mom.decoratorMeshName): if c in mom.decoratorToVirtualHelixItem: pass
def dagParentRemovedCallback(child, parent, clientData): """ Callback function that removes the strands from the model if the 3D strand is delete in 3D view. """ mom = Mom() children = child.fullPathName().split("|") for c in children: if c.startswith(mom.helixMeshName): if c in mom.mayaToCn: strand = mom.mayaToCn[c] if strand: # print "Strand %s : %s needs removal" % (c, strand) mID = mom.strandMayaID(strand) mom.removeIDMapping(mID, strand) strand.strandSet().removeStrand(strand) else: print "Error: no Strand inside mayaObjectModel" else: pass # print "dagParentRemovedCallback: %s already deleted" % c elif c.startswith(mom.decoratorMeshName): if c in mom.decoratorToVirtualHelixItem: pass