def updateInstanceFromFactPrototypes(self):
        # Only update the model if it already exists
        if self.modelXbrl is not None \
           and self.modelXbrl.modelDocument.type == ModelDocument.Type.INSTANCE:
            instance = self.modelXbrl
            cntlr =  instance.modelManager.cntlr
            newCntx = ModelXbrl.AUTO_LOCATE_ELEMENT
            newUnit = ModelXbrl.AUTO_LOCATE_ELEMENT
            tbl = self.table
            # check user keyed changes to aspects
            aspectEntryChanges = {}  # index = widget ID,  value = widget contents
            aspectEntryChangeIds = _DICT_SET(aspectEntryChanges.keys())
            for modifiedCell in tbl.getCoordinatesOfModifiedCells():
                objId = tbl.getObjectId(modifiedCell)
                if objId is not None and len(objId)>0:
                    if tbl.isHeaderCell(modifiedCell):
                        if objId[0] == OPEN_ASPECT_ENTRY_SURROGATE:
                            aspectEntryChanges[objId] = tbl.getTableValue(modifiedCell)
                    else:
                        # check user keyed changes to facts
                        cellIndex = str(modifiedCell)
                        comboboxCells = tbl.window_names(cellIndex)
                        if comboboxCells is not None and len(comboboxCells)>0:
                            comboName = tbl.window_cget(cellIndex, '-window')
                            combobox = cntlr.parent.nametowidget(comboName)
                        else:
                            combobox = None
                        if isinstance(combobox, _Combobox):
                            codeDict = combobox.codes
                            if len(codeDict)>0: # the drop-down list shows labels, we want to have the actual values
                                bodyCellValue = tbl.getTableValue(modifiedCell)
                                value = codeDict.get(bodyCellValue, None)
                                if value is None:
                                    value = bodyCellValue # this must be a qname!
                            else:
                                value = tbl.getTableValue(modifiedCell)
                        else:
                            value = tbl.getTableValue(modifiedCell)
                        objId = tbl.getObjectId(modifiedCell)
                        if objId is not None and len(objId)>0:
                            if objId[0] == "f":
                                factPrototypeIndex = int(objId[1:])
                                factPrototype = self.factPrototypes[factPrototypeIndex]
                                concept = factPrototype.concept
                                if concept is None:
                                    if not self.conceptMessageIssued:
                                        # This should be removed once cells have been disabled until every needed selection is done
                                        self.conceptMessageIssued = True
                                        self.modelXbrl.modelManager.cntlr.showMessage(_("Please make sure every Z axis selection is done"))
                                    return
                                else:
                                    self.conceptMessageIssued = False
                                entityIdentScheme = self.newFactItemOptions.entityIdentScheme
                                entityIdentValue = self.newFactItemOptions.entityIdentValue
                                periodType = concept.periodType
                                periodStart = self.newFactItemOptions.startDateDate if periodType == "duration" else None
                                periodEndInstant = self.newFactItemOptions.endDateDate
                                qnameDims = factPrototype.context.qnameDims
                                newAspectValues = self.newFactOpenAspects(objId)
                                if newAspectValues is None:
                                    self.modelXbrl.modelManager.showStatus(_("Some open values are missing in an axis, the save is incomplete"), 5000)
                                    continue
                                qnameDims.update(newAspectValues)
                                # open aspects widgets
                                prevCntx = instance.matchContext(
                                    entityIdentScheme, entityIdentValue, periodType, periodStart, periodEndInstant, 
                                    qnameDims, [], [])
                                if prevCntx is not None:
                                    cntxId = prevCntx.id
                                else: # need new context
                                    newCntx = instance.createContext(entityIdentScheme, entityIdentValue, 
                                        periodType, periodStart, periodEndInstant, 
                                        concept.qname, qnameDims, [], [], 
                                        afterSibling=newCntx)
                                    cntxId = newCntx.id # need new context
                                # new context
                                if concept.isNumeric:
                                    if concept.isMonetary:
                                        unitMeasure = qname(XbrlConst.iso4217, self.newFactItemOptions.monetaryUnit)
                                        unitMeasure.prefix = "iso4217" # want to save with a recommended prefix
                                        decimals = self.newFactItemOptions.monetaryDecimals
                                    elif concept.isShares:
                                        unitMeasure = XbrlConst.qnXbrliShares
                                        decimals = self.newFactItemOptions.nonMonetaryDecimals
                                    else:
                                        unitMeasure = XbrlConst.qnXbrliPure
                                        decimals = self.newFactItemOptions.nonMonetaryDecimals
                                    prevUnit = instance.matchUnit([unitMeasure], [])
                                    if prevUnit is not None:
                                        unitId = prevUnit.id
                                    else:
                                        newUnit = instance.createUnit([unitMeasure], [], afterSibling=newUnit)
                                        unitId = newUnit.id
                                attrs = [("contextRef", cntxId)]
                                if concept.isNumeric:
                                    attrs.append(("unitRef", unitId))
                                    attrs.append(("decimals", decimals))
                                    value = Locale.atof(self.modelXbrl.locale, value, str.strip)
                                newFact = instance.createFact(concept.qname, attributes=attrs, text=value)
                                tbl.setObjectId(modifiedCell,
                                                newFact.objectId()) # switch cell to now use fact ID
                                if self.factPrototypes[factPrototypeIndex] is not None:
                                    self.factPrototypes[factPrototypeIndex].clear()
                                self.factPrototypes[factPrototypeIndex] = None #dereference fact prototype
                            elif objId[0] != "a": # instance fact, not prototype
                                fact = self.modelXbrl.modelObject(objId)
                                if fact.concept.isNumeric:
                                    value = Locale.atof(self.modelXbrl.locale, value, str.strip)
                                    if fact.concept.isMonetary:
                                        unitMeasure = qname(XbrlConst.iso4217, self.newFactItemOptions.monetaryUnit)
                                        unitMeasure.prefix = "iso4217" # want to save with a recommended prefix
                                        decimals = self.newFactItemOptions.monetaryDecimals
                                    elif fact.concept.isShares:
                                        unitMeasure = XbrlConst.qnXbrliShares
                                        decimals = self.newFactItemOptions.nonMonetaryDecimals
                                    else:
                                        unitMeasure = XbrlConst.qnXbrliPure
                                        decimals = self.newFactItemOptions.nonMonetaryDecimals
                                if fact.value != str(value):
                                    if fact.isNil != (not value):
                                        fact.isNil = not value
                                        if fact.isNil:
                                            pass
                                            #TODO: clear out nil facts
                                    if fact.concept.isNumeric and (not fact.isNil): # if nil, there is no need to update these values
                                        fact.decimals = decimals
                                        prevUnit = instance.matchUnit([unitMeasure], [])
                                        if prevUnit is not None:
                                            unitId = prevUnit.id
                                        else:
                                            newUnit = instance.createUnit([unitMeasure], [], afterSibling=newUnit)
                                            unitId = newUnit.id
                                        fact.unitID = unitId
                                    fact.text = str(value)
                                    instance.setIsModified()
                                    fact.xValid = UNVALIDATED
                                    xmlValidate(instance, fact)
            tbl.clearModificationStatus()
dataset/ETHPy150Open Arelle/Arelle/arelle/ViewWinRenderedGrid.py/ViewRenderedGrid.updateInstanceFromFactPrototypes/original