55
55
#endif
56
56
#endif
57
57
58
+ #include < App/Document.h>
58
59
#include < App/DocumentObjectPy.h>
59
60
#include < App/FeaturePythonPyImp.h>
60
61
#include < App/OriginFeature.h>
61
62
#include < Mod/Part/App/PartFeature.h>
63
+ #include < Mod/Part/App/Tools.h>
62
64
63
65
#include " FemConstraint.h"
64
66
#include " FemTools.h"
65
67
66
68
67
69
using namespace Fem ;
70
+ namespace sp = std::placeholders;
68
71
69
72
#if OCC_VERSION_HEX >= 0x070600
70
73
using Adaptor3d_HSurface = Adaptor3d_Surface;
@@ -140,6 +143,18 @@ int Constraint::calcDrawScaleFactor() const
140
143
return 1 ;
141
144
}
142
145
146
+ void setSubShapeLocation (const Part::Feature* feat, TopoDS_Shape& sh)
147
+ {
148
+ // subshape placement is not necessarily the same as the
149
+ // feature placement.
150
+ Base::Matrix4D matrix = Part::TopoShape::convert (sh.Location ().Transformation ());
151
+ Base::Placement shPla {matrix};
152
+ Base::Placement featlPlaInv = feat->Placement .getValue ().inverse ();
153
+ Base::Placement shGlobalPla = feat->globalPlacement () * featlPlaInv * shPla;
154
+
155
+ sh.Location (Part::Tools::fromPlacement (shGlobalPla));
156
+ }
157
+
143
158
constexpr int CONSTRAINTSTEPLIMIT = 50 ;
144
159
145
160
void Constraint::onChanged (const App::Property* prop)
@@ -163,6 +178,8 @@ void Constraint::onChanged(const App::Property* prop)
163
178
sh = toposhape.getSubShape (SubElements[i].c_str (), !execute);
164
179
165
180
if (!sh.IsNull () && sh.ShapeType () == TopAbs_FACE) {
181
+ setSubShapeLocation (feat, sh);
182
+
166
183
// Get face normal in center point
167
184
TopoDS_Face face = TopoDS::Face (sh);
168
185
BRepGProp_Face props (face);
@@ -193,6 +210,37 @@ void Constraint::onChanged(const App::Property* prop)
193
210
App::DocumentObject::onChanged (prop);
194
211
}
195
212
213
+ void Constraint::slotChangedObject (const App::DocumentObject& obj, const App::Property& prop)
214
+ {
215
+ if (obj.isDerivedFrom <App::GeoFeature>()
216
+ && (prop.isDerivedFrom <App::PropertyPlacement>() || obj.isRemoving ())) {
217
+ auto values = References.getValues ();
218
+ for (const auto ref : values) {
219
+ auto v = ref->getInListEx (true );
220
+ if ((&obj == ref) || (std::find (v.begin (), v.end (), &obj) != v.end ())) {
221
+ this ->touch ();
222
+ return ;
223
+ }
224
+ }
225
+ }
226
+ }
227
+
228
+ void Constraint::onSettingDocument ()
229
+ {
230
+ App::Document* doc = getDocument ();
231
+ if (doc) {
232
+ connDocChangedObject = doc->signalChangedObject .connect (
233
+ std::bind (&Constraint::slotChangedObject, this , sp::_1, sp::_2));
234
+ }
235
+
236
+ App::DocumentObject::onSettingDocument ();
237
+ }
238
+
239
+ void Constraint::unsetupObject ()
240
+ {
241
+ connDocChangedObject.disconnect ();
242
+ }
243
+
196
244
void Constraint::onDocumentRestored ()
197
245
{
198
246
// This seems to be the only way to make the ViewProvider display the constraint
@@ -223,6 +271,8 @@ bool Constraint::getPoints(std::vector<Base::Vector3d>& points,
223
271
return false ;
224
272
}
225
273
274
+ setSubShapeLocation (feat, sh);
275
+
226
276
if (sh.ShapeType () == TopAbs_VERTEX) {
227
277
const TopoDS_Vertex& vertex = TopoDS::Vertex (sh);
228
278
gp_Pnt p = BRep_Tool::Pnt (vertex);
0 commit comments