Exemplo n.º 1
0
    def addFieldConnection(self, field, typeName, masterName):
        sceneObject = None
        if typeName.startswith('"') and typeName.endswith('"'):
            # if type name is in quotes, interpret as instance name
            sceneObject = iv.create_object(name = typeName[1:-1])
        else:
            typeAndArgs = typeName.split("(")
            if len(typeAndArgs) > 1:
                # support initialization arguments in brackets for templated types (e.g. Gate)
                sceneObject = iv.create_object(type = typeAndArgs[0], init = typeAndArgs[1][:-1])
            else:
                # no round brackets means just type name is given

                # check for template types and add type argument based on field type
                initString = ""
                if typeName in ("Gate", "SelectOne", "Concatenate"):
                    initString = field.get_type().replace("SF", "MF", 1)
                if typeName in iv.classes("FieldContainer"):
                    sceneObject = iv.create_object(type = typeName, init = initString)

        if sceneObject is not None:
            master = None
            if isinstance(sceneObject, iv.Engine):
                master = sceneObject.get_output(masterName) if len(masterName) > 0 else sceneObject.get_output()[0] if len(sceneObject.get_output()) > 0 else None
            if master is None:
                master = sceneObject.get_field(masterName) if len(masterName) > 0 else sceneObject.get_field()[0] if len(sceneObject.get_field()) > 0 else None
            if field is not None and master is not None:
                if field.connect_from(master):
                    self._sceneModel.updateFieldConnection(field, master)
                    return True
        return False
Exemplo n.º 2
0
    def setData(self, index, value, role=QtCore.Qt.EditRole):
        """Updates types or names of scene objects"""
        
        if index.isValid():
            node = index.internalPointer()
            
            if role == QtCore.Qt.EditRole:
                if (index.column() == 0) and (index.parent() is not None):
                    # type changes: need to call changeChildType on parent so old
                    # scene object can be replaced by new one

                    newSceneObject = iv.create_object(value) if not value.startswith('"') else iv.create_object(name = value[1:-1])
                    if newSceneObject is None:
                        return False

                    # add chilren from previous type
                    if index.internalPointer()._sceneObject is not None:
                        childNodes = index.internalPointer()._sceneObject[:]
                        if isinstance(newSceneObject, iv.Group):
                            newSceneObject += childNodes
                        else:
                            self.removeRows(0, len(childNodes), index)

                    parentGroup = self._rootNode
                    if index.parent().internalPointer() is not None:
                        parentGroup = index.parent().internalPointer()
                    parentGroup.changeChildType(index.row(), newSceneObject)
                
                if index.column() == 1:
                    node.setName(value)

                self.dataChanged.emit(index, index)
                return True

        return False
Exemplo n.º 3
0
    def setFieldValue(self, index, value):
        """Sets new value for field at given index"""
        if self._sceneObject is None:
            return None

        fields = self.fields()
        if len(fields) > index:
            fieldName = fields[index].get_name()
            if fields[index].get_type() == "SFNode":
                # this will create the part of a node kit if needed
                self._sceneObject.get(fieldName)
                if not value.startswith("..."):
                    fields[index].value = iv.create_object(
                        value
                    ) if not value.startswith('"') else iv.create_object(
                        name=value[1:-1])
                return True
            return self._sceneObject.set(fieldName, value)
        return None
Exemplo n.º 4
0
    def setData(self, index, value, role=QtCore.Qt.EditRole):
        """Updates types or names of scene objects"""

        if index.isValid():
            node = index.internalPointer()

            if role == QtCore.Qt.EditRole:
                if (index.column() == 0) and (index.parent() is not None):
                    # type changes: need to call changeChildType on parent so old
                    # scene object can be replaced by new one

                    newSceneObject = iv.create_object(
                        value
                    ) if not value.startswith('"') else iv.create_object(
                        name=value[1:-1])
                    if newSceneObject is None:
                        return False

                    # add chilren from previous type
                    if index.internalPointer()._sceneObject is not None:
                        childNodes = index.internalPointer()._sceneObject[:]
                        if isinstance(newSceneObject, iv.Group):
                            newSceneObject += childNodes
                        else:
                            self.removeRows(0, len(childNodes), index)

                    parentGroup = self._rootNode
                    if index.parent().internalPointer() is not None:
                        parentGroup = index.parent().internalPointer()
                    parentGroup.changeChildType(index.row(), newSceneObject)

                if index.column() == 1:
                    node.setName(value)

                self.dataChanged.emit(index, index)
                return True

        return False
Exemplo n.º 5
0
    def addFieldConnection(self, field, typeName, masterName):
        sceneObject = None
        if typeName.startswith('"') and typeName.endswith('"'):
            # if type name is in quotes, interpret as instance name
            sceneObject = iv.create_object(name=typeName[1:-1])
        else:
            typeAndArgs = typeName.split("(")
            if len(typeAndArgs) > 1:
                # support initialization arguments in brackets for templated types (e.g. Gate)
                sceneObject = iv.create_object(type=typeAndArgs[0],
                                               init=typeAndArgs[1][:-1])
            else:
                # no round brackets means just type name is given

                # check for template types and add type argument based on field type
                initString = ""
                if typeName in ("Gate", "SelectOne", "Concatenate"):
                    initString = field.get_type().replace("SF", "MF", 1)
                if typeName in iv.classes("FieldContainer"):
                    sceneObject = iv.create_object(type=typeName,
                                                   init=initString)

        if sceneObject is not None:
            master = None
            if isinstance(sceneObject, iv.Engine):
                master = sceneObject.get_output(masterName) if len(
                    masterName) > 0 else sceneObject.get_output()[0] if len(
                        sceneObject.get_output()) > 0 else None
            if master is None:
                master = sceneObject.get_field(masterName) if len(
                    masterName) > 0 else sceneObject.get_field()[0] if len(
                        sceneObject.get_field()) > 0 else None
            if field is not None and master is not None:
                if field.connect_from(master):
                    self._sceneModel.updateFieldConnection(field, master)
                    return True
        return False
Exemplo n.º 6
0
    def setFieldValue(self, index, value):
        """Sets new value for field at given index"""
        if self._sceneObject is None:
            return None

        fields = self.fields()
        if len(fields) > index:
            fieldName = fields[index].get_name()
            if fields[index].get_type() == "SFNode":
                # this will create the part of a node kit if needed
                self._sceneObject.get(fieldName)
                if not value.startswith("..."):
                    fields[index].value = iv.create_object(value) if not value.startswith('"') else iv.create_object(name = value[1:-1])
                return True
            return self._sceneObject.set(fieldName, value)
        return None
Exemplo n.º 7
0
    def setModelData(self, editor, model, index):
        """Updates scene graph model after input"""
        if not index.isValid():
            return False

        typeName = editor.currentText()
        if typeName.startswith('"') and typeName.endswith('"'):
            # if type name is in quotes, interpret as instance name
            sceneObject = iv.create_object(name=typeName[1:-1])
            if sceneObject is None:
                return False
        elif editor.findText(typeName) < 0:
            if self._wasUninitialized:
                # confirmed but invalid: remove row
                index.model().removeRow(index.row(), index.parent())
                return True
            # not a valid entry
            return False

        index.model().setData(index, typeName, QtCore.Qt.EditRole)
        self.parent.setCurrentIndex(index)

        return True
Exemplo n.º 8
0
    def setModelData(self, editor, model, index):
        """Updates scene graph model after input"""
        if not index.isValid():
            return False

        typeName = editor.currentText()
        if typeName.startswith('"') and typeName.endswith('"'):
            # if type name is in quotes, interpret as instance name
            sceneObject = iv.create_object(name = typeName[1:-1])
            if sceneObject is None:
                return False
        elif editor.findText(typeName) < 0:
            if self._wasUninitialized:
                # confirmed but invalid: remove row
                index.model().removeRow(index.row(), index.parent())
                return True
            # not a valid entry
            return False
        
        index.model().setData(index, typeName, QtCore.Qt.EditRole)
        self.parent.setCurrentIndex(index)
        
        return True
Exemplo n.º 9
0
 def test_compare(self):
     c1 = inventor.Cone(name="cone1")
     c2 = inventor.Cone(name="cone2")
     c3 = inventor.create_object(name="cone1")
     self.assertFalse(c1 == c2)
     self.assertTrue(c1 == c3)
Exemplo n.º 10
0
 def test_compare(self):
     c1 = inventor.Cone(name="cone1")
     c2 = inventor.Cone(name="cone2")
     c3 = inventor.create_object(name="cone1")
     self.assertFalse(c1 == c2)
     self.assertTrue(c1 == c3)