View Issue Details

IDProjectCategoryView StatusLast Update
0001387DraftFeaturepublic2014-02-24 19:40
Reportershoogen Assigned Toyorik  
PrioritynoneSeveritytweakReproducibilityN/A
Status closedResolutionfixed 
Product Versiontrunk 
Summary0001387: Wrong __repr__ for Draft Objects
DescriptionThe result of __str__ and __repr__ for Draft Objects gives a wrong result.
"<Document object" istead of "<Part::PartFeature>"
Steps To Reproduce>>> d1=App.ActiveDocument.addObject('Part::Part2DObjectPython')
>>> print d1.TypeId,' ', d1.__str__(),' ', d1.__repr__()
Part::Part2DObjectPython <Document object> <Document object>
TagsNo tags attached.
FreeCAD Information

Activities

wandererfan

2014-02-06 15:13

manager   ~0004157

only happens if preference != "use part primitives":

with Draft preference "use part primitives" checked
>>> d = App.ActiveDocument.Line
>>> print d.TypeId,' ', d.__str__(),' ', d.__repr__()
Part::Line <Part::PartFeature> <Part::PartFeature>

with Draft preference "use part primitives" not checked
>>> dd = App.ActiveDocument.Line
>>> print dd.TypeId,' ', dd.__str__(),' ', dd.__repr__()
Part::Part2DObjectPython <Document object> <Document object>

yorik

2014-02-08 03:05

administrator   ~0004166

Last edited: 2014-02-08 03:05

hm technically it is not exactly wrong... The Part2DObjectPython object is indeed a document object. But I see your point.

I could solve this easily I think by overriding the __repr__() inside the python objects, but there should be a better fix inside the Part2DObject itself probably. I'll have a look at it, but I'm not sure I'll be able to solve...

shoogen

2014-02-09 08:58

developer   ~0004173

Ok, if Document Object is the parent class. Part::Part2DObjectPython is indeed fine. But maybe the "Document" should return something else than <Document>.
I don't like the idea of having the get the "TypeId" property to determine the c++ class information of an object. preferably a __repr__ result with angle brackets should include all class information available.

yorik

2014-02-12 15:20

administrator   ~0004195

This is strange, the representation is set in Part2DObjectPyImp.cpp, but for some reason, it is not used by the object...

shoogen

2014-02-12 15:29

developer   ~0004197

maybe a missing "virtual" in c++?

yorik

2014-02-24 15:25

administrator   ~0004292

Not sure what that means exactly... Sorry, my C++ knowlege is still weak

shoogen

2014-02-24 16:17

developer   ~0004294

http://en.wikipedia.org/wiki/Dynamic_dispatch
But the class structure in FreeCAD is quite complicated.
Just assign it to Jürgen or Werner ;)

yorik

2014-02-24 19:11

administrator   ~0004297

Ok I think I managed to fix it...

>>> o1 = App.ActiveDocument.addObject("Part::FeaturePython","o1")
>>> o2 = App.ActiveDocument.addObject("Part::Part2DObjectPython","o2")
>>> o1
<FeaturePython object at 0x6ea5958>
>>> o2
<FeaturePython object at 0x6ecdf68>
>>> o1.TypeId
'Part::FeaturePython'
>>> o2.TypeId
'Part::Part2DObjectPython'
>>> o1.__repr__()
'<Part::PartFeature>'
>>> o2.__repr__()
'<Part::Part2DObject>'
>>> o1.__str__()
'<Part::PartFeature>'
>>> o2.__str__()
'<Part::Part2DObject>'

Related Changesets

FreeCAD: master 3f99b6ec

2014-02-24 20:10:51

yorik

Details Diff
Part: Fixed python representation of Part2DObject - fixes 0001387 Affected Issues
0001387
mod - src/Mod/Part/App/Part2DObject.cpp Diff File
mod - src/Mod/Part/App/Part2DObjectPyImp.cpp Diff File

Issue History

Date Modified Username Field Change
2014-02-06 14:09 shoogen New Issue
2014-02-06 15:13 wandererfan Note Added: 0004157
2014-02-08 03:05 yorik Note Added: 0004166
2014-02-08 03:05 yorik Assigned To => yorik
2014-02-08 03:05 yorik Status new => assigned
2014-02-08 03:05 yorik Note Edited: 0004166
2014-02-08 03:06 yorik Project FreeCAD => Draft
2014-02-09 08:58 shoogen Note Added: 0004173
2014-02-09 09:10 shoogen Reproducibility always => N/A
2014-02-09 09:10 shoogen Category Bug => Feature
2014-02-12 15:20 yorik Note Added: 0004195
2014-02-12 15:29 shoogen Note Added: 0004197
2014-02-24 15:25 yorik Note Added: 0004292
2014-02-24 16:17 shoogen Note Added: 0004294
2014-02-24 19:11 yorik Note Added: 0004297
2014-02-24 19:40 yorik Changeset attached => FreeCAD Master master 3f99b6ec
2014-02-24 19:40 yorik Status assigned => closed
2014-02-24 19:40 yorik Resolution open => fixed