def Create(name='PropertyBag'): '''Create(name = 'PropertyBag') ... creates a new setup sheet''' FreeCAD.ActiveDocument.openTransaction( translate("PathPropertyBag", "Create PropertyBag")) pcont = PathPropertyBag.Create(name) PathIconViewProvider.Attach(pcont.ViewObject, name) return pcont
def test02(self): """refreshCustomPropertyGroups deletes empty groups""" bag = PathPropertyBag.Create() proxy = bag.Proxy proxy.addCustomProperty("App::PropertyString", "Title", "Address", "Some description") bag.Title = "Madame" bag.removeProperty("Title") proxy.refreshCustomPropertyGroups() self.assertEqual(bag.Proxy.getCustomProperties(), []) self.assertEqual(bag.CustomPropertyGroups, [])
def test01(self): """adding properties to a PropertyBag is tracked properly""" bag = PathPropertyBag.Create() proxy = bag.Proxy proxy.addCustomProperty("App::PropertyString", "Title", "Address", "Some description") self.assertTrue(hasattr(bag, "Title")) bag.Title = "Madame" self.assertEqual(bag.Title, "Madame") self.assertEqual(bag.Proxy.getCustomProperties(), ["Title"]) self.assertEqual(bag.CustomPropertyGroups, ["Address"])
def test02(self): '''refreshCustomPropertyGroups deletes empty groups''' bag = PathPropertyBag.Create() proxy = bag.Proxy proxy.addCustomProperty('App::PropertyString', 'Title', 'Address', 'Some description') bag.Title = 'Madame' bag.removeProperty('Title') proxy.refreshCustomPropertyGroups() self.assertEqual(bag.Proxy.getCustomProperties(), []) self.assertEqual(bag.CustomPropertyGroups, [])
def test01(self): '''adding properties to a PropertyBag is tracked properly''' bag = PathPropertyBag.Create() proxy = bag.Proxy proxy.addCustomProperty('App::PropertyString', 'Title', 'Address', 'Some description') self.assertTrue(hasattr(bag, 'Title')) bag.Title = 'Madame' self.assertEqual(bag.Title, 'Madame') self.assertEqual(bag.Proxy.getCustomProperties(), ['Title']) self.assertEqual(bag.CustomPropertyGroups, ['Address'])
def test03(self): """refreshCustomPropertyGroups does not delete non-empty groups""" bag = PathPropertyBag.Create() proxy = bag.Proxy proxy.addCustomProperty("App::PropertyString", "Title", "Address", "Some description") proxy.addCustomProperty("App::PropertyString", "Gender", "Attributes") bag.Title = "Madame" bag.Gender = "Female" bag.removeProperty("Gender") proxy.refreshCustomPropertyGroups() self.assertEqual(bag.Proxy.getCustomProperties(), ["Title"]) self.assertEqual(bag.CustomPropertyGroups, ["Address"])
def test03(self): '''refreshCustomPropertyGroups does not delete non-empty groups''' bag = PathPropertyBag.Create() proxy = bag.Proxy proxy.addCustomProperty('App::PropertyString', 'Title', 'Address', 'Some description') proxy.addCustomProperty('App::PropertyString', 'Gender', 'Attributes') bag.Title = 'Madame' bag.Gender = 'Female' bag.removeProperty('Gender') proxy.refreshCustomPropertyGroups() self.assertEqual(bag.Proxy.getCustomProperties(), ['Title']) self.assertEqual(bag.CustomPropertyGroups, ['Address'])
def _setupProperty(self, i, name): typ = PathPropertyBag.getPropertyTypeName(self.obj.getTypeIdOfProperty(name)) val = PathUtil.getPropertyValueString(self.obj, name) info = self.obj.getDocumentationOfProperty(name) self.model.setData(self.model.index(i, self.ColumnName), name, QtCore.Qt.EditRole) #self.model.setData(self.model.index(i, self.ColumnType), typ, QtCore.Qt.EditRole) self.model.setData(self.model.index(i, self.ColumnVal), self.obj, Delegate.RoleObject) self.model.setData(self.model.index(i, self.ColumnVal), name, Delegate.RoleProperty) self.model.setData(self.model.index(i, self.ColumnVal), val, QtCore.Qt.DisplayRole) self.model.setData(self.model.index(i, self.ColumnName), typ, QtCore.Qt.ToolTipRole) #self.model.setData(self.model.index(i, self.ColumnType), info, QtCore.Qt.ToolTipRole) self.model.setData(self.model.index(i, self.ColumnVal), info, QtCore.Qt.ToolTipRole) self.model.item(i, self.ColumnName).setEditable(False)
def _setupBitShape(self, obj, path=None): PathLog.track(obj.Label) activeDoc = FreeCAD.ActiveDocument (doc, docOpened) = self._loadBitBody(obj, path) obj.Label = doc.RootObjects[0].Label self._deleteBitSetup(obj) bitBody = obj.Document.copyObject(doc.RootObjects[0], True) docName = doc.Name if docOpened: FreeCAD.setActiveDocument(activeDoc.Name) FreeCAD.closeDocument(doc.Name) if bitBody.ViewObject: bitBody.ViewObject.Visibility = False PathLog.debug("bitBody.{} ({}): {}".format(bitBody.Label, bitBody.Name, type(bitBody))) propNames = [] for attributes in [ o for o in bitBody.Group if PathPropertyBag.IsPropertyBag(o) ]: PathLog.debug("Process properties from {}".format( attributes.Label)) for prop in attributes.Proxy.getCustomProperties(): self._setupProperty(obj, prop, attributes) propNames.append(prop) if not propNames: PathLog.error( translate( 'PathToolBit', 'Did not find a PropertyBag in {} - not a ToolBit shape?'). format(docName)) # has to happen last because it could trigger op.execute evaluations obj.BitPropertyNames = propNames obj.BitBody = bitBody self._copyBitShape(obj)
def Create(name="PropertyBag"): """Create(name = 'PropertyBag') ... creates a new setup sheet""" FreeCAD.ActiveDocument.openTransaction("Create PropertyBag") pcont = PathPropertyBag.Create(name) PathIconViewProvider.Attach(pcont.ViewObject, name) return pcont
GroupMap[g[0]] = g[1] if args.set: s = args.set.split('=') if len(s) != 2: print("ERROR: {} not a valid group mapping".format(args.move)) sys.exit(1) set_var = s[0] set_val = s[1] for i, fname in enumerate(args.path): #print(fname) doc = FreeCAD.openDocument(fname, False) print("{}:".format(doc.Name)) for o in doc.Objects: if PathPropertyBag.IsPropertyBag(o): if args.print_groups: print(" {}: {}".format(o.Label, sorted(o.CustomPropertyGroups))) else: print(" {}:".format(o.Label)) for p in o.Proxy.getCustomProperties(): grp = o.getGroupOfProperty(p) typ = o.getTypeIdOfProperty(p) ttp = PathPropertyBag.getPropertyTypeName(typ) val = PathUtil.getProperty(o, p) dsc = o.getDocumentationOfProperty(p) enm = '' enum = [] if ttp == 'Enumeration': enum = o.getEnumerationsOfProperty(p) enm = "{}".format(','.join(enum))
def test00(self): """basic PropertyBag creation and access test""" bag = PathPropertyBag.Create() self.assertTrue(hasattr(bag, "Proxy")) self.assertEqual(bag.Proxy.getCustomProperties(), []) self.assertEqual(bag.CustomPropertyGroups, [])