Skip to content

Commit

Permalink
Part::Thickness: This fixes issue #2876 by changing property type for…
Browse files Browse the repository at this point in the history
… value to include a unit.
  • Loading branch information
Eivind Kvedalen authored and wwmayer committed Jul 23, 2017
1 parent 20503f3 commit 054a3da
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/Mod/Part/App/PartFeatures.cpp
Expand Up @@ -491,6 +491,9 @@ Thickness::Thickness()
Join.setEnums(JoinEnums);
ADD_PROPERTY_TYPE(Intersection,(false),"Thickness",App::Prop_None,"Intersection");
ADD_PROPERTY_TYPE(SelfIntersection,(false),"Thickness",App::Prop_None,"Self Intersection");

// Value should have length as unit
Value.setUnit(Base::Unit::Length);
}

short Thickness::mustExecute() const
Expand All @@ -510,6 +513,17 @@ short Thickness::mustExecute() const
return 0;
}

void Thickness::handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop)
{
if (prop == &Value && strcmp(TypeName, "App::PropertyFloat") == 0) {
App::PropertyFloat v;

v.Restore(reader);

Value.setValue(v.getValue());
}
}

App::DocumentObjectExecReturn *Thickness::execute(void)
{
App::DocumentObject* source = Faces.getValue();
Expand Down
5 changes: 4 additions & 1 deletion src/Mod/Part/App/PartFeatures.h
Expand Up @@ -123,7 +123,7 @@ class Thickness : public Part::Feature
Thickness();

App::PropertyLinkSub Faces;
App::PropertyFloat Value;
App::PropertyQuantity Value;
App::PropertyEnumeration Mode;
App::PropertyEnumeration Join;
App::PropertyBool Intersection;
Expand All @@ -139,6 +139,9 @@ class Thickness : public Part::Feature
}
//@}

protected:
void handleChangedPropertyType(Base::XMLReader &reader, const char *TypeName, App::Property *prop);

private:
static const char* ModeEnums[];
static const char* JoinEnums[];
Expand Down
21 changes: 21 additions & 0 deletions src/Mod/Part/TestPartApp.py
Expand Up @@ -21,6 +21,7 @@

import FreeCAD, os, sys, unittest, Part
import copy
from FreeCAD import Units
App = FreeCAD

#---------------------------------------------------------------------------
Expand Down Expand Up @@ -90,6 +91,26 @@ def testSetters(self):
# spline.setOrigin(2) # not working?
self.spline.setPole(1, App.Vector([1, 0, 0])) # first parameter 0 gives occ error

def testIssue2876(self):
self.Doc = App.newDocument("Issue2876")
Cylinder = self.Doc.addObject("Part::Cylinder", "Cylinder")
Cylinder.Radius = 5
Pipe = self.Doc.addObject("Part::Thickness", "Pipe")
Pipe.Faces = (Cylinder, ["Face2", "Face3"])
Pipe.Mode = 1
Pipe.Value = -1 # negative wall thickness
Spreadsheet = self.Doc.addObject('Spreadsheet::Sheet', 'Spreadsheet')
Spreadsheet.set('A1', 'Pipe OD')
Spreadsheet.set('B1', 'Pipe WT')
Spreadsheet.set('C1', 'Pipe ID')
Spreadsheet.set('A2', '=2*Cylinder.Radius')
Spreadsheet.set('B2', '=-Pipe.Value')
Spreadsheet.set('C2', '=2*(Cylinder.Radius + Pipe.Value)')
self.Doc.recompute()
self.assertEqual(Spreadsheet.B2, Units.Quantity('1 mm'))
self.assertEqual(Spreadsheet.C2, Units.Quantity('8 mm'))
App.closeDocument("Issue2876")

def tearDown(self):
#closing doc
FreeCAD.closeDocument("PartTest")
2 changes: 1 addition & 1 deletion src/Mod/Spreadsheet/TestSpreadsheet.py
Expand Up @@ -495,7 +495,7 @@ def testPrecedence(self):
self.doc.addObject("Part::Thickness", "Pipe")
sheet.set('B1', '101')
sheet.set('A53', '=-(-(B1-1)/2)')
sheet.set('A54', '=-(Cylinder.Radius + Pipe.Value*1mm - 1"/2)')
sheet.set('A54', '=-(Cylinder.Radius + Pipe.Value - 1"/2)')

self.doc.recompute()
self.assertEqual(sheet.getContents("A1"), "=1 < 2 ? 3 : 4")
Expand Down

0 comments on commit 054a3da

Please sign in to comment.