class _ConfigVisualEditor(_VisualEditorBase):
    def __init__(self, name, value, description, world):
        _VisualEditorBase.__init__(self, name, value, description, world)
        world.robot(0).setConfig(value)
        self.clicked = None
        self.hovered = None
        self.robotposer = RobotPoser(world.robot(0))
        self.addWidget(self.robotposer)

    def instructions(self):
        return 'Right-click and drag on the robot links to pose the robot'

    def mousefunc(self, button, state, x, y):
        if _VisualEditorBase.mousefunc(self, button, state, x, y):
            self.value = self.robotposer.get()

    def display(self):
        #Override display handler since the widget draws the robot
        #the next few lines draw everything but the robot
        for i in range(self.world.numTerrains()):
            self.world.terrain(i).drawGL()
        for i in range(self.world.numRigidObjects()):
            self.world.rigidObject(i).drawGL()
        for i in range(1, self.world.numRobots()):
            self.world.robot(i).drawGL()
        #this line will draw the robot
        self.klamptwidgetmaster.drawGL(self.viewport())
class _ConfigVisualEditor(_VisualEditorBase):
    def __init__(self,name,value,description,world):
        _VisualEditorBase.__init__(self,name,value,description,world)
        world.robot(0).setConfig(value)
        self.clicked = None
        self.hovered = None
        self.robotposer = RobotPoser(world.robot(0))
        self.addWidget(self.robotposer)
    
    def instructions(self):
        return 'Right-click and drag on the robot links to pose the robot'

    def mousefunc(self,button,state,x,y):
        if _VisualEditorBase.mousefunc(self,button,state,x,y):
            self.value = self.robotposer.get()

    def display(self):
        #Override display handler since the widget draws the robot
        #the next few lines draw everything but the robot
        for i in xrange(self.world.numTerrains()):
            self.world.terrain(i).drawGL()
        for i in xrange(self.world.numRigidObjects()):
            self.world.rigidObject(i).drawGL()
        for i in xrange(1,self.world.numRobots()):
            self.world.robot(i).drawGL()
        #this line will draw the robot
        self.klamptwidgetmaster.drawGL(self.viewport())
Beispiel #3
0
class _ConfigsVisualEditor(_VisualEditorBase):
    def __init__(self,name,value,description,world,robot=None):
        _VisualEditorBase.__init__(self,name,value,description,world)
        if robot is None:
            robot = world.robot(0)
        if len(value) > 0:
            robot.setConfig(value[0])
        self.robot = robot
        self.editingIndex = len(value)-1
        self.clicked = None
        self.hovered = None
        self.robotposer = RobotPoser(robot)
        self.addWidget(self.robotposer)
    
    def instructions(self):
        return 'Right-click and drag on the robot links to pose the robot.\nKeyboard i: insert, d: delete, < to select previous, > to select next'

    def addDialogItems(self,parent,ui='qt'):
        self.indexSpinBox = QSpinBox()
        self.indexSpinBox.setRange(0,len(self.value)-1)
        layout = QHBoxLayout(parent)
        label = QLabel("Index")
        label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
        layout.addWidget(label)
        layout.addWidget(self.indexSpinBox)
        self.insertButton = QPushButton("Insert")
        self.deleteButton = QPushButton("Delete")
        layout.addWidget(self.insertButton)
        layout.addWidget(self.deleteButton)
        self.insertButton.clicked.connect(self.insert)
        self.deleteButton.clicked.connect(self.delete)
        self.indexSpinBox.valueChanged.connect(self.indexChanged)

    def insert(self):
        if self.editingIndex < 0:
            self.value.append(self.robotposer.get())
            self.editingIndex = len(self.value)-1
        else:
            self.value.insert(self.editingIndex+1,self.robotposer.get())
            self.editingIndex += 1
        if hasattr(self,'indexSpinBox'):
            self.indexSpinBox.setRange(0,len(self.value)-1)
            self.indexSpinBox.setValue(self.editingIndex)
        self.refresh()

    def delete(self):
        if self.editingIndex >= 0:
            del self.value[self.editingIndex]
            if self.editingIndex >= len(self.value):
                self.editingIndex = len(self.value)-1
            if self.editingIndex >= 0:
                self.robotposer.set(self.value[self.editingIndex])
            print "Now has",len(self.value),"configs, editing index",self.editingIndex
        if hasattr(self,'indexSpinBox'):
            self.indexSpinBox.setRange(0,len(self.value)-1)
            self.indexSpinBox.setValue(self.editingIndex)
        self.refresh()

    def indexChanged(self,index):
        self.editingIndex = index
        if index >= 0 and index < len(self.value):
            self.robotposer.set(self.value[self.editingIndex]) 
        self.refresh()

    def mousefunc(self,button,state,x,y):
        if _VisualEditorBase.mousefunc(self,button,state,x,y):
            if self.editingIndex >= 0:
                self.value[self.editingIndex] = self.robotposer.get()
            return True
        return False
    
    def keyboardfunc(self,c,x,y):
        if c=='i':
            self.insert()
            return True
        elif c=='d':
            self.delete()
            return True
        elif c==',' or c=='<':
            self.editingIndex -= 1
            if self.editingIndex < 0:
                self.editingIndex = min(len(self.value)-1,0)
            if self.editingIndex >= 0:
                self.robotposer.set(self.value[self.editingIndex]) 
                self.refresh()
            return True
        elif c=='.' or c=='>':
            self.editingIndex += 1
            self.editingIndex = min(len(self.value)-1,self.editingIndex)
            if self.editingIndex >= 0:
                self.robotposer.set(self.value[self.editingIndex]) 
                self.refresh()
            return True

    def display(self):
        #Override display handler since the widget draws the robot
        #the next few lines draw everything but the robot
        if self.world != None:
            for i in xrange(self.world.numTerrains()):
                self.world.terrain(i).drawGL()
            for i in xrange(self.world.numRigidObjects()):
                self.world.rigidObject(i).drawGL()
            for i in xrange(self.world.numRobots()):
                if i != self.robot.index:
                    self.world.robot(i).drawGL()
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
        #draw most opaque first
        order = []
        if self.editingIndex < 0:
            order = range(len(self.value))
        else:
            order = [self.editingIndex]
            n = max(self.editingIndex,len(self.value)-self.editingIndex)
            for i in range(1,n+1):
                if self.editingIndex + i < len(self.value): order.append(self.editingIndex +i)
                if self.editingIndex - i >= 0: order.append(self.editingIndex -i)
        for i in order:
            #draw transparent
            opacity = pow(0.5,abs(i-self.editingIndex))
            for j in xrange(self.robot.numLinks()):
                self.robot.link(j).appearance().setColor(0.5,0.5,0.5,opacity)
            if i == self.editingIndex:
                #this line will draw the robot at the current editing config
                self.klamptwidgetmaster.drawGL(self.viewport())
            else:
                self.robot.setConfig(self.value[i])
                self.robot.drawGL()
        for j in xrange(self.robot.numLinks()):
            self.robot.link(j).appearance().setColor(0.5,0.5,0.5,1)
        glDisable(GL_BLEND)
Beispiel #4
0
class _ConfigsVisualEditor(_VisualEditorBase):
    def __init__(self, name, value, description, world, robot=None):
        _VisualEditorBase.__init__(self, name, value, description, world)
        if robot is None:
            robot = world.robot(0)
        if len(value) > 0:
            robot.setConfig(value[0])
        self.robot = robot
        self.editingIndex = len(value) - 1
        self.clicked = None
        self.hovered = None
        self.robotposer = RobotPoser(robot)
        self.addWidget(self.robotposer)

    def instructions(self):
        return 'Right-click and drag on the robot links to pose the robot.\nKeyboard i: insert, d: delete, < to select previous, > to select next'

    def addDialogItems(self, parent, ui='qt'):
        self.indexSpinBox = QSpinBox()
        self.indexSpinBox.setRange(0, len(self.value) - 1)
        layout = QHBoxLayout(parent)
        label = QLabel("Index")
        label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
        layout.addWidget(label)
        layout.addWidget(self.indexSpinBox)
        self.insertButton = QPushButton("Insert")
        self.deleteButton = QPushButton("Delete")
        layout.addWidget(self.insertButton)
        layout.addWidget(self.deleteButton)
        self.insertButton.clicked.connect(self.insert)
        self.deleteButton.clicked.connect(self.delete)
        self.indexSpinBox.valueChanged.connect(self.indexChanged)

    def insert(self):
        if self.editingIndex < 0:
            self.value.append(self.robotposer.get())
            self.editingIndex = len(self.value) - 1
        else:
            self.value.insert(self.editingIndex + 1, self.robotposer.get())
            self.editingIndex += 1
        if hasattr(self, 'indexSpinBox'):
            self.indexSpinBox.setRange(0, len(self.value) - 1)
            self.indexSpinBox.setValue(self.editingIndex)
        self.refresh()

    def delete(self):
        if self.editingIndex >= 0:
            del self.value[self.editingIndex]
            if self.editingIndex >= len(self.value):
                self.editingIndex = len(self.value) - 1
            if self.editingIndex >= 0:
                self.robotposer.set(self.value[self.editingIndex])
            print "Now has", len(
                self.value), "configs, editing index", self.editingIndex
        if hasattr(self, 'indexSpinBox'):
            self.indexSpinBox.setRange(0, len(self.value) - 1)
            self.indexSpinBox.setValue(self.editingIndex)
        self.refresh()

    def indexChanged(self, index):
        self.editingIndex = index
        if index >= 0 and index < len(self.value):
            self.robotposer.set(self.value[self.editingIndex])
        self.refresh()

    def mousefunc(self, button, state, x, y):
        if _VisualEditorBase.mousefunc(self, button, state, x, y):
            if self.editingIndex >= 0:
                self.value[self.editingIndex] = self.robotposer.get()
            return True
        return False

    def keyboardfunc(self, c, x, y):
        if c == 'i':
            self.insert()
            return True
        elif c == 'd':
            self.delete()
            return True
        elif c == ',' or c == '<':
            self.editingIndex -= 1
            if self.editingIndex < 0:
                self.editingIndex = min(len(self.value) - 1, 0)
            if self.editingIndex >= 0:
                self.robotposer.set(self.value[self.editingIndex])
                self.refresh()
            return True
        elif c == '.' or c == '>':
            self.editingIndex += 1
            self.editingIndex = min(len(self.value) - 1, self.editingIndex)
            if self.editingIndex >= 0:
                self.robotposer.set(self.value[self.editingIndex])
                self.refresh()
            return True

    def display(self):
        #Override display handler since the widget draws the robot
        #the next few lines draw everything but the robot
        if self.world != None:
            for i in xrange(self.world.numTerrains()):
                self.world.terrain(i).drawGL()
            for i in xrange(self.world.numRigidObjects()):
                self.world.rigidObject(i).drawGL()
            for i in xrange(self.world.numRobots()):
                if i != self.robot.index:
                    self.world.robot(i).drawGL()
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        #draw most opaque first
        order = []
        if self.editingIndex < 0:
            order = range(len(self.value))
        else:
            order = [self.editingIndex]
            n = max(self.editingIndex, len(self.value) - self.editingIndex)
            for i in range(1, n + 1):
                if self.editingIndex + i < len(self.value):
                    order.append(self.editingIndex + i)
                if self.editingIndex - i >= 0:
                    order.append(self.editingIndex - i)
        for i in order:
            #draw transparent
            opacity = pow(0.5, abs(i - self.editingIndex))
            for j in xrange(self.robot.numLinks()):
                self.robot.link(j).appearance().setColor(
                    0.5, 0.5, 0.5, opacity)
            if i == self.editingIndex:
                #this line will draw the robot at the current editing config
                self.klamptwidgetmaster.drawGL(self.viewport())
            else:
                self.robot.setConfig(self.value[i])
                self.robot.drawGL()
        for j in xrange(self.robot.numLinks()):
            self.robot.link(j).appearance().setColor(0.5, 0.5, 0.5, 1)
        glDisable(GL_BLEND)