Skip to content

Commit e0a8f9a

Browse files
committed
Fem: Update constraint transform
1 parent 613d076 commit e0a8f9a

16 files changed

+496
-466
lines changed

src/Mod/Fem/App/FemConstraintTransform.cpp

+108-20
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ static const char* TransformTypes[] = {"Cylindrical", "Rectangular", nullptr};
3434

3535
ConstraintTransform::ConstraintTransform()
3636
{
37-
ADD_PROPERTY(X_rot, (0.0));
38-
ADD_PROPERTY(Y_rot, (0.0));
39-
ADD_PROPERTY(Z_rot, (0.0));
37+
ADD_PROPERTY_TYPE(Rotation,
38+
(Base::Rotation(0.0, 0.0, 0.0, 1.0)),
39+
"ConstraintTransform",
40+
App::Prop_Output,
41+
"Rectangular system transform");
4042
ADD_PROPERTY_TYPE(TransformType,
4143
(1),
4244
"ConstraintTransform",
@@ -78,28 +80,114 @@ const char* ConstraintTransform::getViewProviderName() const
7880
return "FemGui::ViewProviderFemConstraintTransform";
7981
}
8082

81-
void ConstraintTransform::handleChangedPropertyType(Base::XMLReader& reader,
82-
const char* TypeName,
83-
App::Property* prop)
83+
84+
namespace
85+
{
86+
87+
Base::Rotation anglesToRotation(double xAngle, double yAngle, double zAngle)
8488
{
85-
// properties _rot had App::PropertyFloat and were changed to App::PropertyAngle
86-
if (prop == &X_rot && strcmp(TypeName, "App::PropertyFloat") == 0) {
87-
App::PropertyFloat X_rotProperty;
88-
X_rotProperty.Restore(reader);
89-
X_rot.setValue(X_rotProperty.getValue());
89+
static Base::Vector3d a(1, 0, 0);
90+
static Base::Vector3d b(0, 1, 0);
91+
static int count = 0;
92+
double xRad = xAngle * D_PI / 180.0;
93+
double yRad = yAngle * D_PI / 180.0;
94+
double zRad = zAngle * D_PI / 180.0;
95+
if (xAngle != 0) {
96+
a[1] = 0;
97+
a[2] = 0;
98+
b[1] = std::cos(xRad);
99+
b[2] = -std::sin(xRad);
100+
}
101+
if (yAngle != 0) {
102+
a[0] = std::cos(yRad);
103+
a[2] = std::sin(yRad);
104+
b[0] = 0;
105+
b[2] = 0;
106+
}
107+
if (zAngle != 0) {
108+
a[0] = std::cos(zRad);
109+
a[1] = -std::sin(zRad);
110+
b[0] = 0;
111+
b[1] = 0;
90112
}
91-
else if (prop == &Y_rot && strcmp(TypeName, "App::PropertyFloat") == 0) {
92-
App::PropertyFloat Y_rotProperty;
93-
Y_rotProperty.Restore(reader);
94-
Y_rot.setValue(Y_rotProperty.getValue());
113+
114+
++count;
115+
count %= 3;
116+
if (!count) {
117+
Base::Vector3d X = a.Normalize();
118+
Base::Vector3d Y = b.Normalize();
119+
Base::Vector3d Z = X.Cross(Y);
120+
Z.Normalize();
121+
Y = Z.Cross(X);
122+
123+
a.x = 1;
124+
a.y = 0;
125+
a.z = 0;
126+
b.x = 0;
127+
b.y = 1;
128+
b.z = 0;
129+
130+
Base::Matrix4D m;
131+
m.setCol(0, X);
132+
m.setCol(1, Y);
133+
m.setCol(2, Z);
134+
135+
return Base::Rotation(m);
95136
}
96-
else if (prop == &Z_rot && strcmp(TypeName, "App::PropertyFloat") == 0) {
97-
App::PropertyFloat Z_rotProperty;
98-
Z_rotProperty.Restore(reader);
99-
Z_rot.setValue(Z_rotProperty.getValue());
137+
return Base::Rotation();
138+
}
139+
140+
} // namespace
141+
142+
143+
void ConstraintTransform::handleChangedPropertyName(Base::XMLReader& reader,
144+
const char* typeName,
145+
const char* propName)
146+
{
147+
if (strcmp(propName, "X_rot") == 0) {
148+
double xAngle;
149+
if (strcmp(typeName, "App::PropertyFloat") == 0) {
150+
App::PropertyFloat X_rotProperty;
151+
X_rotProperty.Restore(reader);
152+
xAngle = X_rotProperty.getValue();
153+
}
154+
else if (strcmp(typeName, "App::PropertyAngle") == 0) {
155+
App::PropertyAngle X_rotProperty;
156+
X_rotProperty.Restore(reader);
157+
xAngle = X_rotProperty.getValue();
158+
}
159+
anglesToRotation(xAngle, 0, 0);
160+
}
161+
else if (strcmp(propName, "Y_rot") == 0) {
162+
double yAngle;
163+
if (strcmp(typeName, "App::PropertyFloat") == 0) {
164+
App::PropertyFloat Y_rotProperty;
165+
Y_rotProperty.Restore(reader);
166+
yAngle = Y_rotProperty.getValue();
167+
}
168+
else if (strcmp(typeName, "App::PropertyAngle") == 0) {
169+
App::PropertyAngle Y_rotProperty;
170+
Y_rotProperty.Restore(reader);
171+
yAngle = Y_rotProperty.getValue();
172+
}
173+
anglesToRotation(0, yAngle, 0);
174+
}
175+
else if (strcmp(propName, "Z_rot") == 0) {
176+
double zAngle;
177+
if (strcmp(typeName, "App::PropertyFloat") == 0) {
178+
App::PropertyFloat Z_rotProperty;
179+
Z_rotProperty.Restore(reader);
180+
zAngle = Z_rotProperty.getValue();
181+
}
182+
else if (strcmp(typeName, "App::PropertyAngle") == 0) {
183+
App::PropertyAngle Z_rotProperty;
184+
Z_rotProperty.Restore(reader);
185+
zAngle = Z_rotProperty.getValue();
186+
}
187+
Rotation.setValue(anglesToRotation(0, 0, zAngle));
100188
}
101189
else {
102-
Constraint::handleChangedPropertyType(reader, TypeName, prop);
190+
Constraint::handleChangedPropertyName(reader, typeName, propName);
103191
}
104192
}
105193

src/Mod/Fem/App/FemConstraintTransform.h

+5-8
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,9 @@ class FemExport ConstraintTransform: public Fem::Constraint
4242
App::PropertyLinkList NameDispl;
4343
App::PropertyVector BasePoint;
4444
App::PropertyVector Axis;
45-
App::PropertyAngle X_rot;
46-
App::PropertyAngle Y_rot;
47-
App::PropertyAngle Z_rot;
45+
46+
App::PropertyRotation Rotation;
4847
App::PropertyEnumeration TransformType;
49-
// etc
50-
/* */
5148

5249
/// recalculate the object
5350
App::DocumentObjectExecReturn* execute() override;
@@ -56,9 +53,9 @@ class FemExport ConstraintTransform: public Fem::Constraint
5653
const char* getViewProviderName() const override;
5754

5855
protected:
59-
void handleChangedPropertyType(Base::XMLReader& reader,
60-
const char* TypeName,
61-
App::Property* prop) override;
56+
void handleChangedPropertyName(Base::XMLReader& reader,
57+
const char* typeName,
58+
const char* propName) override;
6259
void onChanged(const App::Property* prop) override;
6360
};
6461

src/Mod/Fem/Gui/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ SET(FemGuiSymbol_IV
366366
Resources/symbols/ConstraintSectionPrint.iv
367367
Resources/symbols/ConstraintSpring.iv
368368
Resources/symbols/ConstraintTemperature.iv
369+
Resources/symbols/ConstraintTransform.iv
369370
Resources/symbols/ConstraintTie.iv
370371
)
371372

src/Mod/Fem/Gui/Command.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -1002,9 +1002,6 @@ void CmdFemConstraintTransform::activated(int)
10021002
doCommand(Doc,
10031003
"App.activeDocument().addObject(\"Fem::ConstraintTransform\",\"%s\")",
10041004
FeatName.c_str());
1005-
doCommand(Doc, "App.activeDocument().%s.X_rot = 0.0", FeatName.c_str());
1006-
doCommand(Doc, "App.activeDocument().%s.Y_rot = 0.0", FeatName.c_str());
1007-
doCommand(Doc, "App.activeDocument().%s.Z_rot = 0.0", FeatName.c_str());
10081005
doCommand(Doc, "App.activeDocument().%s.Scale = 1", FeatName.c_str());
10091006
doCommand(Doc,
10101007
"App.activeDocument().%s.addObject(App.activeDocument().%s)",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#Inventor V2.1 ascii
2+
3+
4+
Separator {
5+
6+
Separator {
7+
DEF REC_TRANSFORM Switch {
8+
Separator {
9+
10+
BaseColor {
11+
rgb 0.0 1.0 0.0
12+
13+
}
14+
DEF AXIS Separator {
15+
16+
Translation {
17+
translation 0 2.5 0
18+
19+
}
20+
Cone {
21+
bottomRadius 0.4
22+
height 1.0
23+
24+
}
25+
Translation {
26+
translation 0 -1.5 0
27+
28+
}
29+
Cylinder {
30+
radius 0.15
31+
height 2.0
32+
33+
}
34+
}
35+
Separator {
36+
37+
BaseColor {
38+
rgb 1.0 0.0 0.0
39+
40+
}
41+
Rotation {
42+
rotation 0 0 1 -1.5707964
43+
44+
}
45+
USE AXIS
46+
}
47+
48+
Separator {
49+
50+
BaseColor {
51+
rgb 0.0 0.0 1.0
52+
53+
}
54+
Rotation {
55+
rotation 1 0 0 1.5707964
56+
57+
}
58+
USE AXIS
59+
}
60+
}
61+
Separator {
62+
63+
BaseColor {
64+
rgb 1.0 0.0 0.0
65+
66+
}
67+
Translation {
68+
translation 0 2.5 0
69+
70+
}
71+
Cone {
72+
bottomRadius 0.4
73+
height 1.0
74+
75+
}
76+
Translation {
77+
translation 0 -1.5 0
78+
79+
}
80+
Cylinder {
81+
radius 0.15
82+
height 2.0
83+
84+
}
85+
}
86+
87+
}
88+
}
89+
Separator {
90+
91+
Switch {
92+
93+
Separator {
94+
95+
BaseColor {
96+
rgb 0.0 0.0 1.0
97+
98+
}
99+
Translation {
100+
translation 0 10.5 0
101+
102+
}
103+
Cone {
104+
bottomRadius 0.4
105+
height 1.0
106+
107+
}
108+
Translation {
109+
translation 0 -5.5 0
110+
111+
}
112+
Cylinder {
113+
radius 0.15
114+
height 10.0
115+
116+
}
117+
}
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)