@@ -34,9 +34,11 @@ static const char* TransformTypes[] = {"Cylindrical", "Rectangular", nullptr};
34
34
35
35
ConstraintTransform::ConstraintTransform ()
36
36
{
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" );
40
42
ADD_PROPERTY_TYPE (TransformType,
41
43
(1 ),
42
44
" ConstraintTransform" ,
@@ -78,28 +80,114 @@ const char* ConstraintTransform::getViewProviderName() const
78
80
return " FemGui::ViewProviderFemConstraintTransform" ;
79
81
}
80
82
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)
84
88
{
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 ;
90
112
}
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);
95
136
}
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));
100
188
}
101
189
else {
102
- Constraint::handleChangedPropertyType (reader, TypeName, prop );
190
+ Constraint::handleChangedPropertyName (reader, typeName, propName );
103
191
}
104
192
}
105
193
0 commit comments