23
#include "PreCompiled.h"
25
#include <BRepBuilderAPI_GTransform.hxx>
26
#include <BRepBuilderAPI_Transform.hxx>
27
#include <BRepBuilderAPI_Copy.hxx>
29
#include <gp_GTrsf.hxx>
31
#include <Precision.hxx>
34
#include <Base/Exception.h>
36
#include "FeatureScale.h"
40
PROPERTY_SOURCE(Part::Scale, Part::Feature)
44
ADD_PROPERTY_TYPE(Base, (nullptr), "Scale", App::Prop_None, "Shape to scale");
45
ADD_PROPERTY_TYPE(Uniform, (true), "Scale", App::Prop_None, "If true, scale equally in all directions");
46
ADD_PROPERTY_TYPE(UniformScale, (1.0), "Scale", App::Prop_None, "Uniform scale factor - 1.0 means no scaling");
47
ADD_PROPERTY_TYPE(XScale, (1.0), "Scale", App::Prop_None, "Scale factor in X direction - 1.0 means no scaling");
48
ADD_PROPERTY_TYPE(YScale, (1.0), "Scale", App::Prop_None, "Scale factor in Y direction - 1.0 means no scaling");
49
ADD_PROPERTY_TYPE(ZScale, (1.0), "Scale", App::Prop_None, "Scale factor in Z direction - 1.0 means no scaling");
52
short Scale::mustExecute() const
54
if (Base.isTouched() ||
55
Uniform.isTouched() ||
56
UniformScale.isTouched() ||
65
Scale::ScaleParameters Scale::computeFinalParameters()
67
Scale::ScaleParameters result;
68
result.uniform = Uniform.getValue();
69
result.uniformScale = UniformScale.getValue();
70
result.XScale = XScale.getValue();
71
result.YScale = YScale.getValue();
72
result.ZScale = ZScale.getValue();
77
TopoShape Scale::scaleShape(const TopoShape& source, const Scale::ScaleParameters& params)
82
result = uniformScale(source, params.uniformScale);
86
return nonuniformScale(source, params);
89
TopoShape Scale::uniformScale(const TopoShape& source, const double& factor)
92
TopoDS_Shape transShape;
95
gp_Trsf scaleTransform;
96
scaleTransform.SetScale(gp_Pnt(0, 0, 0), factor);
98
BRepBuilderAPI_Transform mkTrf(source.getShape(), scaleTransform);
99
transShape = mkTrf.Shape();
104
transTopo.setShape(transShape);
108
TopoShape Scale::nonuniformScale(const TopoShape& source, const Scale::ScaleParameters& params)
111
Base::Matrix4D matScale;
112
matScale.scale(params.XScale, params.YScale, params.ZScale);
116
mat.SetValue(1,1,matScale[0][0]);
117
mat.SetValue(2,1,matScale[1][0]);
118
mat.SetValue(3,1,matScale[2][0]);
119
mat.SetValue(1,2,matScale[0][1]);
120
mat.SetValue(2,2,matScale[1][1]);
121
mat.SetValue(3,2,matScale[2][1]);
122
mat.SetValue(1,3,matScale[0][2]);
123
mat.SetValue(2,3,matScale[1][2]);
124
mat.SetValue(3,3,matScale[2][2]);
125
mat.SetValue(1,4,matScale[0][3]);
126
mat.SetValue(2,4,matScale[1][3]);
127
mat.SetValue(3,4,matScale[2][3]);
132
BRepBuilderAPI_Copy copier(source.getShape());
135
BRepBuilderAPI_GTransform mkTrf(copier.Shape(), mat, true);
136
transTopo.setShape(mkTrf.Shape());
139
Base::Console().Warning("FeatureScale failed on nonuniform scale\n");
145
App::DocumentObjectExecReturn* Scale::execute()
148
App::DocumentObject* link = Base.getValue();
150
return new App::DocumentObjectExecReturn("No object linked");
153
Scale::ScaleParameters params = computeFinalParameters();
154
TopoShape result = scaleShape(Feature::getTopoShape(link), params);
155
this->Shape.setValue(result);
156
return App::DocumentObject::StdReturn;
158
catch (Standard_Failure& e) {
159
return new App::DocumentObjectExecReturn(e.GetMessageString());