Пример #1
0
    async def __cbCreateObjextExtension(self, name, ext):

        try:
            obj = self.onlineDoc.document.getObject(name)
            if obj is None:
                self.logger.error(
                    f"Object ({name}): Should add extension for not existing object"
                )
                return

            self.logger.debug(f"Object ({name}): Add extension {ext}")
            Object.createExtension(obj, ext)

        except Exception as e:
            self.logger.error(f"Add extension failed: {e}")
Пример #2
0
    async def __cbCreateViewProviderExtension(self, name, ext):

        try:
            obj = self.onlineDoc.document.getObject(name)
            if obj is None:
                self.logger.error(
                    f"ViewProvider ({name}): Should create extension {ext} for not existing viewprovider"
                )
                return

            self.logger.debug(f"ViewProvider ({name}): Create extension {ext}")
            Object.createExtension(obj.ViewObject, ext)

        except Exception as e:
            self.logger.error(f"Add extension failed: {e}")
    async def download(self, obj):
        # Loads the OCP node data for this object into the FreeCAD one. If changes exist
        # the local version will be overridden, hene can be used to reset a object
        # Note: this function works async, but cannot handle any changes during execution,
        #       neither on the node nor in the FC object

        try:
            self.logger.debug(f"Download")

            #first check if we are available online to setup. Could happen that e.g. we load before the viewprovider was uploaded
            if not await self.Reader.isAvailable():
                return

            #add the extensions (do that before properties, as extensions adds props too)
            extensions = await self.Reader.extensions()
            for extension in extensions:
                self.logger.debug(f"Add extension {extension}")
                Object.createExtension(obj, extension)

            oProps = await self.Reader.propertyList()
            if not oProps:
                #no properties mean we loaded directly after object creation, before default property setup. Nothing is written yet
                return
            defProps = self.obj.PropertiesList

            # check if we need to remove some local props
            remove = set(defProps) - set(oProps)
            if remove:
                self.logger.debug(
                    f"Local object has too many properties, remove {remove}")
                Object.removeDynamicProperties(obj, remove)

            # create the dynamic properties
            add = set(oProps) - set(defProps)
            infos = await self.Reader.propertiesInfos(add)
            self.logger.debug(f"Create and set dynamic properties {add}")
            Object.createDynamicProperties(obj, add, infos)

            # set all property values. Note that data can be None in case the property was never written (default value)
            values = await self.Reader.properties(oProps)
            writeProps = []
            writeValues = []
            for prop, value in zip(oProps, values):
                if value:
                    writeProps.append(prop)
                    writeValues.append(value)

            self.logger.debug(f"Read properties {writeProps}")
            Object.setProperties(obj, writeProps, writeValues)

            # set the correct status for the non-dnamic properties
            infos = await self.Reader.propertiesInfos(defProps)
            status = [info["status"] for info in infos]
            self.logger.debug(
                f"Set status of default properties {defProps} to {status}")
            for prop, stat in zip(defProps, status):
                Object.setPropertyStatus(obj, prop, stat)

            self.logger.debug(f"Object download finished")

        except Exception as e:
            self.logger.error(f"Downloading object failed: {e}")
            traceback.print_exc()