def catgSegmentation2File(self):
        """Sync category info from segmentation to EISegMed3D.json

        match by name
        - sync user change name
        - sync user add
        - sync user delete
        """
        if self._syncingCatg:
            return
        self._syncingCatg = True

        # 1. if no prev catg record, record current
        segmentation = self.segmentation
        if self._prevCatg is None:
            self._prevCatg = {
                segId: segmentation.GetSegment(segId).GetName()
                for segId in segmentation.GetSegmentIDs()
            }

        # 2. change name, add to file or delete
        name2value = self.getCatgFromFile()

        for segmentId in segmentation.GetSegmentIDs():
            segment = segmentation.GetSegment(segmentId)

            # change name
            if segmentId in self._prevCatg.keys() and segment.GetName(
            ) != self._prevCatg[segmentId]:
                del name2value[self._prevCatg[segmentId]]
                name2value[segment.GetName()] = segment.GetLabelValue()

            # user add or this segmentation have more catgs
            if segment.GetName() not in name2value.keys():
                if segment.GetNameAutoGenerated():
                    segment.SetName(f"Segment_{segment.GetLabelValue()}")
                name2value[segment.GetName()] = segment.GetLabelValue()

        # delete
        for segmentId in set(self._prevCatg.keys()) - set(
                segmentation.GetSegmentIDs()):
            logging.info(
                f"deleting segment {segmentId} {self.segmentation.GetSegment(segmentId)}"
            )
            del name2value[self._prevCatg[segmentId]]

        # 3. record catg info
        self._prevCatg = {
            segId: segmentation.GetSegment(segId).GetName()
            for segId in segmentation.GetSegmentIDs()
        }

        # 4. write to file
        config = self.getConfig()
        config["labels"] = [{
            "name": name,
            "labelValue": value
        } for name, value in name2value.items()]
        print(json.dumps(config), file=open(self.configPath, "w"))

        self._syncingCatg = False
Sync category info from segmentation to EISegMed3D.json

        match by name
        - sync user change name
        - sync user add
        - sync user delete
        
EISeg/med3d/EISegMed3D/EISegMed3D.py