Part::Mirroring: This fixes issue #2671 by changing the type of Base and Normal to PropertyPosition and PropertyDirection. These two classes handles units better.

This commit is contained in:
Eivind Kvedalen
2017-07-21 19:03:56 +02:00
committed by wmayer
parent 054a3da107
commit 55e0e6c00d
3 changed files with 45 additions and 2 deletions

View File

@@ -72,6 +72,24 @@ void Mirroring::onChanged(const App::Property* prop)
Part::Feature::onChanged(prop);
}
void Mirroring::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
{
if (prop == &Base && strcmp(TypeName, "App::PropertyVector") == 0) {
App::PropertyVector v;
v.Restore(reader);
Base.setValue(v.getValue());
}
else if (prop == &Normal && strcmp(TypeName, "App::PropertyVector") == 0) {
App::PropertyVector v;
v.Restore(reader);
Normal.setValue(v.getValue());
}
}
App::DocumentObjectExecReturn *Mirroring::execute(void)
{
App::DocumentObject* link = Source.getValue();

View File

@@ -39,8 +39,8 @@ public:
Mirroring();
App::PropertyLink Source;
App::PropertyVector Base;
App::PropertyVector Normal;
App::PropertyPosition Base;
App::PropertyDirection Normal;
/** @name methods override feature */
//@{
@@ -55,6 +55,9 @@ public:
protected:
void onChanged (const App::Property* prop);
void handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property * prop);
};
} //namespace Part

View File

@@ -91,6 +91,28 @@ class PartTestBSplineCurve(unittest.TestCase):
# spline.setOrigin(2) # not working?
self.spline.setPole(1, App.Vector([1, 0, 0])) # first parameter 0 gives occ error
def testIssue2671(self):
self.Doc = App.newDocument("Issue2671")
Box = self.Doc.addObject("Part::Box","Box")
Mirroring = self.Doc.addObject("Part::Mirroring", 'Mirroring')
Spreadsheet = self.Doc.addObject('Spreadsheet::Sheet', 'Spreadsheet')
Mirroring.Base = (8, 5, 25)
Mirroring.Normal = (0.5, 0.2, 0.9)
Spreadsheet.set('A1', '=Mirroring.Base.x')
Spreadsheet.set('B1', '=Mirroring.Base.y')
Spreadsheet.set('C1', '=Mirroring.Base.z')
Spreadsheet.set('A2', '=Mirroring.Normal.x')
Spreadsheet.set('B2', '=Mirroring.Normal.y')
Spreadsheet.set('C2', '=Mirroring.Normal.z')
self.Doc.recompute()
self.assertEqual(Spreadsheet.A1, Units.Quantity('8 mm'))
self.assertEqual(Spreadsheet.B1, Units.Quantity('5 mm'))
self.assertEqual(Spreadsheet.C1, Units.Quantity('25 mm'))
self.assertEqual(Spreadsheet.A2, Units.Quantity('0.5 mm'))
self.assertEqual(Spreadsheet.B2, Units.Quantity('0.2 mm'))
self.assertEqual(Spreadsheet.C2, Units.Quantity('0.9 mm'))
App.closeDocument("Issue2671")
def testIssue2876(self):
self.Doc = App.newDocument("Issue2876")
Cylinder = self.Doc.addObject("Part::Cylinder", "Cylinder")