mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-05-17 11:06:27 +02:00
[core] attribute: new initValue, independant from the resetToDefaultValue
Avoid to evaluate the default value if we don't need to.
This commit is contained in:
parent
0c3426250a
commit
020dbecc68
6 changed files with 37 additions and 29 deletions
|
@ -38,6 +38,8 @@ def attributeFactory(description, value, isOutput, node, root=None, parent=None)
|
|||
attr = cls(node, description, isOutput, root, parent)
|
||||
if value is not None:
|
||||
attr.value = value
|
||||
else:
|
||||
attr.resetToDefaultValue()
|
||||
return attr
|
||||
|
||||
|
||||
|
@ -72,8 +74,7 @@ class Attribute(BaseObject):
|
|||
self._invalidationValue = ""
|
||||
|
||||
self._value = None
|
||||
# do not emit value changed on initialization
|
||||
self.resetValue(emitSignals=False)
|
||||
self.initValue()
|
||||
|
||||
@property
|
||||
def node(self):
|
||||
|
@ -240,7 +241,11 @@ class Attribute(BaseObject):
|
|||
def upgradeValue(self, exportedValue):
|
||||
self._set_value(exportedValue)
|
||||
|
||||
def resetValue(self, emitSignals=True):
|
||||
def initValue(self):
|
||||
if self.desc._valueType is not None:
|
||||
self._value = self.desc._valueType()
|
||||
|
||||
def resetToDefaultValue(self, emitSignals=True):
|
||||
self._set_value(copy.copy(self.defaultValue()), emitSignals=emitSignals)
|
||||
|
||||
def requestGraphUpdate(self):
|
||||
|
@ -321,7 +326,7 @@ class Attribute(BaseObject):
|
|||
return
|
||||
if isinstance(v, Attribute):
|
||||
g.addEdge(v, self)
|
||||
self.resetValue()
|
||||
self.resetToDefaultValue()
|
||||
elif self.isInput and Attribute.isLinkExpression(v):
|
||||
# value is a link to another attribute
|
||||
link = v[1:-1]
|
||||
|
@ -330,7 +335,7 @@ class Attribute(BaseObject):
|
|||
g.addEdge(g.node(linkNode).attribute(linkAttr), self)
|
||||
except KeyError as err:
|
||||
logging.warning('Connect Attribute from Expression failed.\nExpression: "{exp}"\nError: "{err}".'.format(exp=v, err=err))
|
||||
self.resetValue()
|
||||
self.resetToDefaultValue()
|
||||
|
||||
def getExportValue(self):
|
||||
if self.isLink:
|
||||
|
@ -504,7 +509,10 @@ class ListAttribute(Attribute):
|
|||
def index(self, item):
|
||||
return self._value.indexOf(item)
|
||||
|
||||
def resetValue(self, emitSignals=True):
|
||||
def initValue(self):
|
||||
self.resetToDefaultValue(emitSignals=False)
|
||||
|
||||
def resetToDefaultValue(self, emitSignals=True):
|
||||
self._value = ListModel(parent=self)
|
||||
if emitSignals:
|
||||
self.valueChanged.emit()
|
||||
|
@ -650,14 +658,6 @@ class GroupAttribute(Attribute):
|
|||
def __init__(self, node, attributeDesc, isOutput, root=None, parent=None):
|
||||
super(GroupAttribute, self).__init__(node, attributeDesc, isOutput, root, parent)
|
||||
|
||||
subAttributes = []
|
||||
for subAttrDesc in self.attributeDesc.groupDesc:
|
||||
childAttr = attributeFactory(subAttrDesc, None, self.isOutput, self.node, self)
|
||||
subAttributes.append(childAttr)
|
||||
childAttr.valueChanged.connect(self.valueChanged)
|
||||
|
||||
self._value.reset(subAttributes)
|
||||
|
||||
def __getattr__(self, key):
|
||||
try:
|
||||
return super(GroupAttribute, self).__getattr__(key)
|
||||
|
@ -696,10 +696,18 @@ class GroupAttribute(Attribute):
|
|||
else:
|
||||
raise AttributeError("Failed to set on GroupAttribute: {}".format(str(value)))
|
||||
|
||||
def resetValue(self, emitSignals=True):
|
||||
def initValue(self):
|
||||
self._value = DictModel(keyAttrName='name', parent=self)
|
||||
if emitSignals:
|
||||
self.valueChanged.emit()
|
||||
subAttributes = []
|
||||
for subAttrDesc in self.attributeDesc.groupDesc:
|
||||
childAttr = attributeFactory(subAttrDesc, None, self.isOutput, self.node, self)
|
||||
subAttributes.append(childAttr)
|
||||
childAttr.valueChanged.connect(self.valueChanged)
|
||||
self._value.reset(subAttributes)
|
||||
|
||||
def resetToDefaultValue(self, emitSignals=True):
|
||||
for attrDesc in self.desc._groupDesc:
|
||||
self._value.get(attrDesc.name).resetToDefaultValue()
|
||||
|
||||
@Slot(str, result=Attribute)
|
||||
def childAttribute(self, key):
|
||||
|
|
|
@ -755,7 +755,7 @@ class InitNode:
|
|||
"""
|
||||
for attrName in attributeNames:
|
||||
if node.hasAttribute(attrName):
|
||||
node.attribute(attrName).resetValue()
|
||||
node.attribute(attrName).resetToDefaultValue()
|
||||
|
||||
def extendAttributes(self, node, attributesDict):
|
||||
"""
|
||||
|
|
|
@ -551,13 +551,13 @@ class Graph(BaseObject):
|
|||
# find top-level links
|
||||
if Attribute.isLinkExpression(attr.value):
|
||||
skippedEdges[attr] = attr.value
|
||||
attr.resetValue()
|
||||
attr.resetToDefaultValue()
|
||||
# find links in ListAttribute children
|
||||
elif isinstance(attr, ListAttribute):
|
||||
for child in attr.value:
|
||||
if Attribute.isLinkExpression(child.value):
|
||||
skippedEdges[child] = child.value
|
||||
child.resetValue()
|
||||
child.resetToDefaultValue()
|
||||
return node, skippedEdges
|
||||
|
||||
def duplicateNodes(self, srcNodes):
|
||||
|
|
|
@ -378,12 +378,12 @@ class RemoveImagesCommand(GraphCommand):
|
|||
def redoImpl(self):
|
||||
for i in range(len(self.cameraInits)):
|
||||
# Reset viewpoints
|
||||
self.cameraInits[i].viewpoints.resetValue()
|
||||
self.cameraInits[i].viewpoints.resetToDefaultValue()
|
||||
self.cameraInits[i].viewpoints.valueChanged.emit()
|
||||
self.cameraInits[i].viewpoints.requestGraphUpdate()
|
||||
|
||||
# Reset intrinsics
|
||||
self.cameraInits[i].intrinsics.resetValue()
|
||||
self.cameraInits[i].intrinsics.resetToDefaultValue()
|
||||
self.cameraInits[i].intrinsics.valueChanged.emit()
|
||||
self.cameraInits[i].intrinsics.requestGraphUpdate()
|
||||
|
||||
|
|
|
@ -924,10 +924,10 @@ class Reconstruction(UIGraph):
|
|||
if rebuild:
|
||||
# if rebuilding all intrinsics, for each Viewpoint:
|
||||
for vp in cameraInitCopy.viewpoints.value:
|
||||
vp.intrinsicId.resetValue() # reset intrinsic assignation
|
||||
vp.metadata.resetValue() # and metadata (to clear any previous 'SensorWidth' entries)
|
||||
vp.intrinsicId.resetToDefaultValue() # reset intrinsic assignation
|
||||
vp.metadata.resetToDefaultValue() # and metadata (to clear any previous 'SensorWidth' entries)
|
||||
# reset existing intrinsics list
|
||||
cameraInitCopy.intrinsics.resetValue()
|
||||
cameraInitCopy.intrinsics.resetToDefaultValue()
|
||||
|
||||
try:
|
||||
self.setBuildingIntrinsics(True)
|
||||
|
|
|
@ -24,7 +24,7 @@ def test_formatting_listOfFiles():
|
|||
n1.featuresFolders.extend("single value with space")
|
||||
assert n1.featuresFolders.getValueStr() == '"single value with space"'
|
||||
|
||||
n1.featuresFolders.resetValue()
|
||||
n1.featuresFolders.resetToDefaultValue()
|
||||
assert n1.featuresFolders.getValueStr() == ''
|
||||
|
||||
n1.featuresFolders.extend(inputImages)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue