1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchPlugin_ConstraintSplit.cpp
4 // Created: 17 Jul 2016
5 // Author: Natalia ERMOLAEVA
7 #include "SketchPlugin_ConstraintSplit.h"
9 //#include <GeomAPI_Circ2d.h>
10 //#include <GeomAPI_Dir2d.h>
11 //#include <GeomAPI_Lin2d.h>
12 #include <GeomAPI_Pnt2d.h>
13 //#include <GeomAPI_XY.h>
14 #include <GeomDataAPI_Point2D.h>
15 //#include <ModelAPI_AttributeDouble.h>
16 #include <ModelAPI_AttributeReference.h>
17 #include <ModelAPI_AttributeString.h>
18 //#include <ModelAPI_AttributeRefList.h>
19 #include <ModelAPI_AttributeRefAttr.h>
20 #include <ModelAPI_Tools.h>
22 #include <ModelAPI_Validator.h>
23 #include <ModelAPI_Session.h>
25 #include <SketchPlugin_Line.h>
26 #include <SketchPlugin_Arc.h>
27 #include <SketchPlugin_Circle.h>
28 #include <SketchPlugin_ConstraintCoincidence.h>
29 #include <SketchPlugin_ConstraintEqual.h>
30 #include <SketchPlugin_ConstraintParallel.h>
31 #include <SketchPlugin_ConstraintTangent.h>
32 #include <SketchPlugin_ConstraintMirror.h>
33 #include <SketchPlugin_MultiRotation.h>
34 #include <SketchPlugin_MultiTranslation.h>
36 //#include <ModelAPI_Data.h>
37 #include <ModelAPI_Events.h>
38 //#include <ModelAPI_Session.h>
39 //#include <ModelAPI_Validator.h>
41 #include <SketchPlugin_Line.h>
42 #include <SketchPlugin_Arc.h>
43 #include <SketchPlugin_Circle.h>
44 //#include <SketchPlugin_Point.h>
45 //#include <SketchPlugin_Sketch.h>
46 //#include <SketchPlugin_Tools.h>
49 #include <ModelGeomAlgo_Point2D.h>
50 #include <Events_Loop.h>
54 //const double tolerance = 1.e-7;
55 //const double paramTolerance = 1.e-4;
57 ///// \brief Attract specified point on theNewArc to the attribute of theFeature
58 //static void recalculateAttributes(FeaturePtr theNewArc, const std::string& theNewArcAttribute,
59 // FeaturePtr theFeature, const std::string& theFeatureAttribute);
61 ///// \brief Calculates center of fillet arc and coordinates of tangency points
62 //static void calculateFilletCenter(FeaturePtr theFeatureA, FeaturePtr theFeatureB,
63 // double theRadius, bool theNotInversed[2],
64 // std::shared_ptr<GeomAPI_XY>& theCenter,
65 // std::shared_ptr<GeomAPI_XY>& theTangentA,
66 // std::shared_ptr<GeomAPI_XY>& theTangentB);
68 ///// Get point on 1/3 length of edge from fillet point
69 //static void getPointOnEdge(const FeaturePtr theFeature,
70 // const std::shared_ptr<GeomAPI_Pnt2d> theFilletPoint,
71 // std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
73 ///// Get distance from point to feature
74 //static double getProjectionDistance(const FeaturePtr theFeature,
75 // const std::shared_ptr<GeomAPI_Pnt2d> thePoint);
77 ///// Get coincide edges for fillet
78 //static std::set<FeaturePtr> getCoincides(const FeaturePtr& theConstraintCoincidence);
80 SketchPlugin_ConstraintSplit::SketchPlugin_ConstraintSplit()
81 //: myListOfPointsChangedInCode(false),
82 // myRadiusChangedByUser(false),
83 // myRadiusChangedInCode(false),
84 // myRadiusInitialized(false)
88 void SketchPlugin_ConstraintSplit::initAttributes()
90 data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeReference::typeId());
91 data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
92 data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
94 //data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId());
95 //data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttrList::typeId());
98 void SketchPlugin_ConstraintSplit::execute()
100 std::shared_ptr<ModelAPI_Data> aData = data();
102 // Check the base objects are initialized.
103 AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
104 aData->attribute(SketchPlugin_Constraint::VALUE()));
105 if(!aBaseObjectAttr->isInitialized()) {
106 setError("Error: Base object is not initialized.");
109 AttributePoint2DPtr aFirstPointAttr = getPointOfRefAttr(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
110 AttributePoint2DPtr aSecondPointAttr = getPointOfRefAttr(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
111 if (!aFirstPointAttr.get() || !aFirstPointAttr->isInitialized() ||
112 !aSecondPointAttr.get() || !aSecondPointAttr->isInitialized()) {
113 setError("Error: Sub-shape is not initialized.");
117 // Wait all constraints being created, then send update events
118 static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
119 bool isUpdateFlushed = Events_Loop::loop()->isFlushed(anUpdateEvent);
121 Events_Loop::loop()->setFlushed(anUpdateEvent, false);
124 // Find feature constraints
125 FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
126 ResultPtr aBaseFeatureResult = getFeatureResult(aBaseFeature);
128 std::set<FeaturePtr> aFeaturesToDelete;
129 std::map<FeaturePtr, IdToPointPair> aTangentFeatures;
130 std::map<FeaturePtr, IdToPointPair> aCoincidenceToFeature;
131 std::map<FeaturePtr, IdToPointPair> aCoincidenceToPoint;
132 getConstraints(aFeaturesToDelete, aTangentFeatures, aCoincidenceToFeature, aCoincidenceToPoint);
135 std::string aFeatureKind = aBaseFeature->getKind();
136 FeaturePtr aSplitFeature, anAfterFeature;
137 std::set<AttributePoint2DPtr> aFurtherCoincidences;
138 /*if (aFeatureKind == SketchPlugin_Line::ID())
139 splitLine(aSplitFeature, anOtherFeatures);
140 else*/ if (aFeatureKind == SketchPlugin_Arc::ID())
141 splitArc(aSplitFeature, aBaseFeature, anAfterFeature, aFurtherCoincidences);
142 /*if (aFeatureKind == SketchPlugin_Circle::ID())
143 splitCircle(aSplitFeature, anOtherFeatures);
144 FeaturePtr aSplitFeature;
145 std::set<FeaturePtr> anOtherFeatures;*/
147 //setConstraints(aSplitFeature, aBaseFeature, anAfterFeature, aFeaturesToDelete, aTangentFeatures,
148 // aCoincidenceToFeature, aCoincidenceToPoint);
150 std::set<ResultPtr> aFeatureResults;
151 aFeatureResults.insert(getFeatureResult(aBaseFeature));
152 if (anAfterFeature.get())
153 aFeatureResults.insert(getFeatureResult(anAfterFeature));
155 // coincidence to feature
156 std::map<FeaturePtr, IdToPointPair>::const_iterator aCIt = aCoincidenceToFeature.begin(),
157 aCLast = aCoincidenceToFeature.end();
158 for (; aCIt != aCLast; aCIt++) {
159 FeaturePtr aCoincFeature = aCIt->first;
160 std::string anAttributeId = aCIt->second.first;
161 AttributePoint2DPtr aCoincPoint = aCIt->second.second;
162 std::set<AttributePoint2DPtr>::const_iterator aFCIt = aFurtherCoincidences.begin(),
163 aFCLast = aFurtherCoincidences.end();
164 std::shared_ptr<GeomAPI_Pnt2d> aCoincPnt = aCoincPoint->pnt();
165 AttributePoint2DPtr aFeaturePointAttribute;
166 for (; aFCIt != aFCLast && !aFeaturePointAttribute.get(); aFCIt) {
167 AttributePoint2DPtr aFCAttribute = *aFCIt;
168 if (aCoincPnt->isEqual(aFCAttribute->pnt()))
169 aFeaturePointAttribute = aFCAttribute;
171 if (aFeaturePointAttribute.get()) {
172 aCoincFeature->refattr(anAttributeId)->setAttr(aFeaturePointAttribute);
175 /// find feature by shape intersected the point
176 ResultPtr aResultForCoincidence = *(aFeatureResults.begin());
178 if (aFeatureResults.size() > 1) { // try to find point on additional feature
179 ResultPtr anAddtionalResult = *(aFeatureResults.begin()++);
180 GeomShapePtr aShape = anAddtionalResult->shape();
182 std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = aCoincPoint->pnt();
183 std::shared_ptr<GeomAPI_Pnt> aPoint = sketch()->to3D(aPnt2d->x(), aPnt2d->y());
185 std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
186 if (ModelGeomAlgo_Point2D::isPointOnEdge(aShape, aPoint, aProjectedPoint))
187 aResultForCoincidence = anAddtionalResult;
189 aCoincFeature->refattr(anAttributeId)->setObject(aResultForCoincidence);
192 // coincidence to points
197 // delete constraints
198 ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToDelete);
200 // Send events to update the sub-features by the solver.
201 if(isUpdateFlushed) {
202 Events_Loop::loop()->setFlushed(anUpdateEvent, true);
206 bool SketchPlugin_ConstraintSplit::isMacro() const
211 std::shared_ptr<GeomDataAPI_Point2D> SketchPlugin_ConstraintSplit::getPointOfRefAttr(
212 const AttributePtr& theAttribute)
214 AttributePoint2DPtr aPointAttribute;
216 if (theAttribute->attributeType() == ModelAPI_AttributeRefAttr::typeId()) {
217 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
218 if (aRefAttr.get() && aRefAttr->isInitialized()) {
219 AttributePtr anAttribute = aRefAttr->attr();
220 if (anAttribute.get() && anAttribute->attributeType() == GeomDataAPI_Point2D::typeId())
221 aPointAttribute = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
224 return aPointAttribute;
227 void SketchPlugin_ConstraintSplit::getFeaturePoints(AttributePoint2DPtr& theStartPointAttr,
228 AttributePoint2DPtr& theEndPointAttr)
230 AttributePoint2DPtr aPointAttribute;
232 AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
233 data()->attribute(SketchPlugin_Constraint::VALUE()));
234 FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
236 std::string aFeatureKind = aBaseFeature->getKind();
237 std::string aStartAttributeName, anEndAttributeName;
238 if (aFeatureKind == SketchPlugin_Line::ID()) {
239 aStartAttributeName = SketchPlugin_Line::START_ID();
240 anEndAttributeName = SketchPlugin_Line::END_ID();
242 else if (aFeatureKind == SketchPlugin_Arc::ID()) {
243 aStartAttributeName = SketchPlugin_Arc::START_ID();
244 anEndAttributeName = SketchPlugin_Arc::END_ID();
246 if (!aStartAttributeName.empty() && !anEndAttributeName.empty()) {
247 theStartPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
248 aBaseFeature->attribute(aStartAttributeName));
249 theEndPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
250 aBaseFeature->attribute(anEndAttributeName));
254 void SketchPlugin_ConstraintSplit::getConstraints(std::set<FeaturePtr>& theFeaturesToDelete,
255 std::map<FeaturePtr, IdToPointPair>& theTangentFeatures,
256 std::map<FeaturePtr, IdToPointPair>& theCoincidenceToFeature,
257 std::map<FeaturePtr, IdToPointPair>& theCoincidenceToPoint)
259 std::shared_ptr<ModelAPI_Data> aData = data();
261 // Check the base objects are initialized.
262 AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
263 aData->attribute(SketchPlugin_Constraint::VALUE()));
264 FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
265 ResultPtr aBaseFeatureResult = getFeatureResult(aBaseFeature);
267 const std::set<AttributePtr>& aRefsList = aBaseFeatureResult->data()->refsToMe();
268 std::set<AttributePtr>::const_iterator aIt;
269 for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
270 std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
271 FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
272 std::string aRefFeatureKind = aRefFeature->getKind();
273 if (aRefFeatureKind == SketchPlugin_ConstraintMirror::ID() ||
274 aRefFeatureKind == SketchPlugin_MultiRotation::ID() ||
275 aRefFeatureKind == SketchPlugin_MultiTranslation::ID())
276 theFeaturesToDelete.insert(aRefFeature);
277 else if (aRefFeatureKind == SketchPlugin_ConstraintTangent::ID()) {
278 if (aBaseFeature->getKind() == SketchPlugin_Circle::ID()) /// TEMPORARY limitaion
279 theFeaturesToDelete.insert(aRefFeature); /// until tangency between arc and line is implemented
281 std::string anAttributeToBeModified;
282 AttributePoint2DPtr aTangentPoint;
283 ObjectPtr aResult1 = aRefFeature->refattr(SketchPlugin_Constraint::ENTITY_A())->object();
284 ObjectPtr aResult2 = aRefFeature->refattr(SketchPlugin_Constraint::ENTITY_B())->object();
285 if (aResult1.get() && aResult2.get()) {
286 FeaturePtr aCoincidenceFeature = SketchPlugin_ConstraintCoincidence::findCoincidenceFeature
287 (ModelAPI_Feature::feature(aResult1),
288 ModelAPI_Feature::feature(aResult2));
289 aTangentPoint = SketchPlugin_ConstraintCoincidence::getPoint(aCoincidenceFeature);
291 if (aTangentPoint.get()) {
292 FeaturePtr aFeature1 = ModelAPI_Feature::feature(aResult1);
293 std::string anAttributeToBeModified = aFeature1 == aBaseFeature
294 ? SketchPlugin_Constraint::ENTITY_B() : SketchPlugin_Constraint::ENTITY_A();
295 theTangentFeatures[aRefFeature] = std::make_pair(anAttributeToBeModified, aTangentPoint);
298 theFeaturesToDelete.insert(aRefFeature); /// there is not coincident point between tangent constraint
301 else if (aRefFeatureKind == SketchPlugin_ConstraintCoincidence::ID()) {
302 std::string anAttributeToBeModified;
303 AttributePoint2DPtr aCoincidentPoint;
304 AttributeRefAttrPtr anAttrA = aRefFeature->refattr(SketchPlugin_Constraint::ENTITY_A());
305 AttributeRefAttrPtr anAttrB = aRefFeature->refattr(SketchPlugin_Constraint::ENTITY_B());
306 bool isToFeature = false;
307 if (anAttrA->isObject() || anAttrB->isObject()) { /// coincidence to base feature
308 FeaturePtr aFeature = anAttrA->isObject() ? ModelAPI_Feature::feature(anAttrA->object())
310 isToFeature = aFeature.get() && aFeature == aRefFeature;
311 anAttributeToBeModified = SketchPlugin_Constraint::ENTITY_B();
313 aFeature = anAttrB->isObject() ? ModelAPI_Feature::feature(anAttrB->object())
315 isToFeature = aFeature.get() && aFeature == aRefFeature;
316 anAttributeToBeModified = SketchPlugin_Constraint::ENTITY_A();
319 aCoincidentPoint = SketchPlugin_ConstraintCoincidence::getPoint(aRefFeature);
321 if (!isToFeature) { /// coincidence to point on base feature
322 AttributePtr anAttribute;
323 if (!anAttrA->isObject()) {
324 AttributePtr aCurAttribute = anAttrA->attr();
325 if (aCurAttribute.get()) {
326 FeaturePtr aCurFeature = ModelAPI_Feature::feature(aCurAttribute->owner());
327 if (aCurFeature.get() && aCurFeature == aRefFeature) {
328 anAttribute = anAttrA->attr();
329 anAttributeToBeModified = SketchPlugin_Constraint::ENTITY_A();
333 if (!anAttribute.get() && !anAttrB->isObject()) {
334 AttributePtr aCurAttribute = anAttrB->attr();
335 if (aCurAttribute.get()) {
336 FeaturePtr aCurFeature = ModelAPI_Feature::feature(aCurAttribute->owner());
337 if (aCurFeature.get() && aCurFeature == aRefFeature) {
338 anAttribute = anAttrB->attr();
339 anAttributeToBeModified = SketchPlugin_Constraint::ENTITY_B();
343 if (anAttribute.get())
344 aCoincidentPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttribute);
346 if (aCoincidentPoint.get()) {
348 theCoincidenceToFeature[aRefFeature] = std::make_pair(anAttributeToBeModified,
351 theCoincidenceToPoint[aRefFeature] = std::make_pair(anAttributeToBeModified,
355 theFeaturesToDelete.insert(aRefFeature); /// this case should not happen
360 /*void SketchPlugin_ConstraintSplit::setConstraints(const FeaturePtr& theSplitFeature,
361 const FeaturePtr& theBaseFeature,
362 const FeaturePtr& theAfterFeature,
363 const std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete,
364 const std::map<std::shared_ptr<ModelAPI_Feature>, std::shared_ptr<GeomDataAPI_Point2D> >& theTangentFeatures,
365 const std::map<std::shared_ptr<ModelAPI_Feature>, std::shared_ptr<GeomDataAPI_Point2D> >& theCoincidenceToFeature,
366 const std::map<std::shared_ptr<ModelAPI_Feature>, std::shared_ptr<GeomDataAPI_Point2D> >& theCoincidenceToPoint)
368 // coincidence to feature
371 // coincidence to points
375 // delete constraints
379 void SketchPlugin_ConstraintSplit::splitArc(FeaturePtr& theSplitFeature,
380 FeaturePtr& theBaseFeature,
381 FeaturePtr& theAfterFeature,
382 std::set<AttributePoint2DPtr>& thePoints)
384 SketchPlugin_Sketch* aSketch = sketch();
388 AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
389 data()->attribute(SketchPlugin_Constraint::VALUE()));
390 FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
391 std::string aFeatureKind = aBaseFeature->getKind();
392 if (aFeatureKind != SketchPlugin_Arc::ID())
395 AttributePoint2DPtr aFirstPointAttr = getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
396 AttributePoint2DPtr aSecondPointAttr = getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_B()));
397 AttributePoint2DPtr aStartPointAttr, anEndPointAttr;
398 getFeaturePoints(aStartPointAttr, anEndPointAttr);
399 if (!aStartPointAttr.get() && !anEndPointAttr.get()) {
400 setError("Error: Feature has no start and end points.");
404 arrangePoints(aStartPointAttr, anEndPointAttr, aFirstPointAttr, aSecondPointAttr);
407 theSplitFeature = createArcFeature(aBaseFeature, aFirstPointAttr, aSecondPointAttr);
408 static ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
409 aFactory->validate(theSplitFeature); // need to be validated to update the "Apply" state if not previewed
410 std::string anError = theSplitFeature->error();
412 // before split feature
413 if (!aStartPointAttr->pnt()->isEqual(aFirstPointAttr->pnt())) {
414 theBaseFeature = aBaseFeature; ///< use base feature to store all constraints here
415 /// move end arc point to start of split
418 // after split feature
419 if (!aSecondPointAttr->pnt()->isEqual(anEndPointAttr->pnt())) {
421 if (!theBaseFeature.get()) {
422 aFeature = aBaseFeature; ///< use base feature to store all constraints here
423 fillAttribute(aFeature->attribute(SketchPlugin_Arc::START_ID()), aSecondPointAttr);
426 aFeature = createArcFeature(aBaseFeature, aSecondPointAttr, anEndPointAttr);
428 createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
429 theSplitFeature->attribute(SketchPlugin_Arc::END_ID()),
430 aFeature->attribute(SketchPlugin_Arc::START_ID()));
431 thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
432 (theBaseFeature->attribute(SketchPlugin_Arc::START_ID())));
433 thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
434 (theBaseFeature->attribute(SketchPlugin_Arc::END_ID())));
436 if (!theBaseFeature.get())
437 theBaseFeature = aFeature;
439 theAfterFeature = aFeature;
442 thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
443 (theSplitFeature->attribute(SketchPlugin_Arc::END_ID())));
445 // base split, that is defined before split feature should be changed at end
446 // (after the after feature creation). Otherwise modified value will be used in after feature
447 // before split feature
448 if (!aStartPointAttr->pnt()->isEqual(aFirstPointAttr->pnt())) {
449 /// move end arc point to start of split
450 fillAttribute(theBaseFeature->attribute(SketchPlugin_Arc::END_ID()), aFirstPointAttr);
451 createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
452 theBaseFeature->attribute(SketchPlugin_Arc::END_ID()),
453 theSplitFeature->attribute(SketchPlugin_Arc::START_ID()));
454 thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
455 (theBaseFeature->attribute(SketchPlugin_Arc::START_ID())));
456 thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
457 (theBaseFeature->attribute(SketchPlugin_Arc::END_ID())));
460 thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
461 (theSplitFeature->attribute(SketchPlugin_Arc::START_ID())));
463 // additional constraints between split and base features
464 createConstraintForObjects(SketchPlugin_ConstraintEqual::ID(), getFeatureResult(aBaseFeature),
465 getFeatureResult(theSplitFeature));
466 createConstraintForObjects(SketchPlugin_ConstraintTangent::ID(), getFeatureResult(theSplitFeature),
467 getFeatureResult(aBaseFeature));
468 if (theAfterFeature.get()) {
469 createConstraintForObjects(SketchPlugin_ConstraintEqual::ID(), getFeatureResult(aBaseFeature),
470 getFeatureResult(theAfterFeature));
471 createConstraintForObjects(SketchPlugin_ConstraintTangent::ID(), getFeatureResult(theSplitFeature),
472 getFeatureResult(theAfterFeature));
476 void SketchPlugin_ConstraintSplit::arrangePoints(const AttributePoint2DPtr& theStartPointAttr,
477 const AttributePoint2DPtr& theEndPointAttr,
478 AttributePoint2DPtr& theFirstPointAttr,
479 AttributePoint2DPtr& theLastPointAttr)
481 /// if first point is closer to last point, wrap first and last values
482 if (theStartPointAttr->pnt()->distance(theFirstPointAttr->pnt()) >
483 theStartPointAttr->pnt()->distance(theLastPointAttr->pnt())) {
484 AttributePoint2DPtr aTmpPoint = theFirstPointAttr;
485 theFirstPointAttr = theLastPointAttr;
486 theLastPointAttr = aTmpPoint;
490 void SketchPlugin_ConstraintSplit::fillAttribute(const AttributePtr& theModifiedAttribute,
491 const AttributePtr& theSourceAttribute)
493 AttributePoint2DPtr aModifiedAttribute = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
494 theModifiedAttribute);
495 AttributePoint2DPtr aSourceAttribute = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
498 if (aModifiedAttribute.get() && aSourceAttribute.get())
499 aModifiedAttribute->setValue(aSourceAttribute->pnt());
502 FeaturePtr SketchPlugin_ConstraintSplit::createArcFeature(const FeaturePtr& theBaseFeature,
503 const AttributePtr& theFirstPointAttr,
504 const AttributePtr& theSecondPointAttr)
507 SketchPlugin_Sketch* aSketch = sketch();
508 if (!aSketch || !theBaseFeature.get())
511 aFeature = aSketch->addFeature(theBaseFeature->getKind());
512 // update fillet arc: make the arc correct for sure, so, it is not needed to process the "attribute updated"
513 // by arc; moreover, it may cause cyclicity in hte mechanism of updater
514 aFeature->data()->blockSendAttributeUpdated(true);
516 aFeature->string(SketchPlugin_Arc::ARC_TYPE())->setValue(
517 SketchPlugin_Arc::ARC_TYPE_CENTER_START_END());
518 fillAttribute(aFeature->attribute(SketchPlugin_Arc::CENTER_ID()),
519 theBaseFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
520 fillAttribute(aFeature->attribute(SketchPlugin_Arc::START_ID()), theFirstPointAttr);
521 fillAttribute(aFeature->attribute(SketchPlugin_Arc::END_ID()), theSecondPointAttr);
522 aFeature->data()->blockSendAttributeUpdated(false);
528 void SketchPlugin_ConstraintSplit::createConstraint(const std::string& theConstraintId,
529 const AttributePtr& theFirstAttribute,
530 const AttributePtr& theSecondAttribute)
532 FeaturePtr aConstraint = sketch()->addFeature(theConstraintId);
533 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
534 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
535 aRefAttr->setAttr(theFirstAttribute);
537 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
538 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
539 aRefAttr->setAttr(theSecondAttribute);
542 void SketchPlugin_ConstraintSplit::createConstraintForObjects(const std::string& theConstraintId,
543 const ObjectPtr& theFirstObject,
544 const ObjectPtr& theSecondObject)
546 FeaturePtr aConstraint = sketch()->addFeature(theConstraintId);
547 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
548 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
549 aRefAttr->setObject(theFirstObject);
551 aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
552 aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
553 aRefAttr->setObject(theSecondObject);
556 std::shared_ptr<ModelAPI_Result> SketchPlugin_ConstraintSplit::getFeatureResult(
557 const std::shared_ptr<ModelAPI_Feature>& theFeature)
559 std::shared_ptr<ModelAPI_Result> aResult;
561 std::string aFeatureKind = theFeature->getKind();
562 if (aFeatureKind == SketchPlugin_Line::ID())
563 aResult = theFeature->firstResult();
564 else if (aFeatureKind == SketchPlugin_Arc::ID())
565 aResult = theFeature->lastResult();
566 else if (aFeatureKind == SketchPlugin_Circle::ID())
567 aResult = theFeature->lastResult();