]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_Trim.cpp
Salome HOME
[Code coverage SketchPlugin]: Exclude code related to GUI from the coverage
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Trim.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "SketchPlugin_Trim.h"
22
23 #include <GeomAPI_Dir2d.h>
24 #include <GeomAPI_Edge.h>
25 #include <GeomAPI_Pnt2d.h>
26 #include <GeomAPI_XY.h>
27 #include <GeomDataAPI_Point2D.h>
28 #include <GeomAlgoAPI_ShapeTools.h>
29 #include <GeomAlgoAPI_CompoundBuilder.h>
30
31 #include <ModelAPI_AttributeReference.h>
32 #include <ModelAPI_AttributeString.h>
33 #include <ModelAPI_AttributeRefAttr.h>
34 #include <ModelAPI_Tools.h>
35 #include <ModelAPI_AttributeBoolean.h>
36
37 #include <ModelAPI_Validator.h>
38 #include <ModelAPI_Session.h>
39 #include <ModelAPI_AttributeDouble.h>
40
41 #include <ModelGeomAlgo_Shape.h>
42
43 #include <SketchPlugin_Arc.h>
44 #include <SketchPlugin_ConstraintMiddle.h>
45 #include <SketchPlugin_Circle.h>
46 #include <SketchPlugin_ConstraintCoincidence.h>
47 #include <SketchPlugin_ConstraintEqual.h>
48 #include <SketchPlugin_ConstraintTangent.h>
49 #include <SketchPlugin_ConstraintLength.h>
50 #include <SketchPlugin_ConstraintMirror.h>
51 #include <SketchPlugin_ConstraintCollinear.h>
52 #include <SketchPlugin_Line.h>
53 #include <SketchPlugin_MultiRotation.h>
54 #include <SketchPlugin_MultiTranslation.h>
55 #include <SketchPlugin_Point.h>
56 #include <SketchPlugin_Projection.h>
57 #include <SketchPlugin_Tools.h>
58
59 #include <ModelAPI_EventReentrantMessage.h>
60
61 #include <ModelAPI_Events.h>
62 #include <SketchPlugin_Line.h>
63 #include <SketchPlugin_Arc.h>
64 #include <SketchPlugin_Circle.h>
65
66 #include <ModelGeomAlgo_Point2D.h>
67 #include <Events_Loop.h>
68
69 #include <cmath>
70
71 #ifdef DEBUG_TRIM
72 #include <iostream>
73 #endif
74
75 #ifdef DEBUG_TRIM_METHODS
76 #include <iostream>
77 #endif
78
79 static const double PI = 3.141592653589793238463;
80
81 static const std::string OPERATION_HIGHLIGHT_COLOR() { return "128, 0, 0"; }
82 static const std::string OPERATION_REMOVE_FEATURE_COLOR() { return "255, 174, 201"; }
83
84 SketchPlugin_Trim::SketchPlugin_Trim()
85 {
86 }
87
88 void SketchPlugin_Trim::initAttributes()
89 {
90   data()->addAttribute(SELECTED_OBJECT(), ModelAPI_AttributeReference::typeId());
91   data()->addAttribute(SELECTED_POINT(), GeomDataAPI_Point2D::typeId());
92
93   data()->addAttribute(PREVIEW_POINT(), GeomDataAPI_Point2D::typeId());
94   data()->addAttribute(PREVIEW_OBJECT(), ModelAPI_AttributeReference::typeId());
95
96   data()->attribute(PREVIEW_POINT())->setIsArgument(false);
97   data()->attribute(SELECTED_POINT())->setIsArgument(false);
98   data()->attribute(PREVIEW_OBJECT())->setIsArgument(false);
99
100   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PREVIEW_POINT());
101   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PREVIEW_OBJECT());
102 }
103
104 void SketchPlugin_Trim::findShapePoints(const std::string& theObjectAttributeId,
105                                         const std::string& thePointAttributeId,
106                                         std::shared_ptr<GeomAPI_Pnt>& aStartPoint,
107                                         std::shared_ptr<GeomAPI_Pnt>& aLastPoint)
108 {
109   AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
110                                             data()->attribute(theObjectAttributeId));
111   ObjectPtr aBaseObject = aBaseObjectAttr->value();
112
113   AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
114                                               data()->attribute(thePointAttributeId));
115   std::shared_ptr<GeomAPI_Pnt2d> anAttributePnt2d = aPoint->pnt();
116   std::shared_ptr<GeomAPI_Pnt> anAttributePnt = sketch()->to3D(anAttributePnt2d->x(),
117                                                                anAttributePnt2d->y());
118
119   if (myCashedShapes.find(aBaseObject) == myCashedShapes.end())
120     fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
121
122   const std::set<GeomShapePtr>& aShapes = myCashedShapes[aBaseObject];
123   if (!aShapes.empty()) {
124     std::set<GeomShapePtr>::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();
125     for (; anIt != aLast; anIt++) {
126       GeomShapePtr aBaseShape = *anIt;
127       std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
128       if (ModelGeomAlgo_Point2D::isPointOnEdge(aBaseShape, anAttributePnt, aProjectedPoint)) {
129
130         if (aBaseShape->shapeType() == GeomAPI_Shape::EDGE) {
131           std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aBaseShape));
132           //GeomAPI_Shape::Orientation anOrientation = anEdge->orientation();
133           //if (anOrientation == GeomAPI_Shape::REVERSED) {
134             aStartPoint = anEdge->lastPoint();
135             aLastPoint = anEdge->firstPoint();
136           //}
137           //else {
138             //aStartPoint = anEdge->firstPoint();
139             //aLastPoint = anEdge->lastPoint();
140           //}
141         }
142       }
143     }
144   }
145 #ifdef DEBUG_TRIM
146   std::cout << "<findShapePoints> => "
147     << std::endl << "Attribute point: "
148     << anAttributePnt->x() << ", " << anAttributePnt->y() << ", " << anAttributePnt->z() << "]"
149     << std::endl << "Start Point: ["
150     << aStartPoint->x() << ", " << aStartPoint->y() << ", " << aStartPoint->z() << "]"
151     << std::endl << "Last Point: ["
152     << aLastPoint->x() << ", " << aLastPoint->y() << ", " << aLastPoint->z() << "]"
153     << std::endl;
154 #endif
155 }
156
157 std::shared_ptr<GeomAPI_Pnt2d> SketchPlugin_Trim::convertPoint(
158                                                    const std::shared_ptr<GeomAPI_Pnt>& thePoint)
159 {
160   std::shared_ptr<GeomAPI_Pnt2d> aPoint;
161   if (!thePoint.get())
162     return aPoint;
163
164   AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
165                                         data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
166   ObjectPtr aBaseObject = aBaseObjectAttr->value();
167   if (myObjectToPoints.find(aBaseObject) == myObjectToPoints.end())
168     fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
169
170   bool aFound = false;
171   const PointToRefsMap& aRefsMap = myObjectToPoints.at(aBaseObject);
172   for (PointToRefsMap::const_iterator aPointIt = aRefsMap.begin();
173        aPointIt != aRefsMap.end() && !aFound; aPointIt++) {
174     if (aPointIt->first->isEqual(thePoint)) {
175       const std::pair<std::list<AttributePoint2DPtr >,
176                std::list<ObjectPtr > >& anInfo = aPointIt->second;
177       const std::list<AttributePoint2DPtr >& anAttributes = anInfo.first;
178       if (!anAttributes.empty()) {
179         aPoint = anAttributes.front()->pnt();
180         aFound = true;
181       }
182       else {
183         aPoint = sketch()->to2D(thePoint);
184         aFound = true;
185       }
186     }
187   }
188   if (!aFound) {
189     // returns an end of the shape to define direction of split if feature's attribute
190     // participates
191     aPoint = sketch()->to2D(thePoint);
192   }
193   return aPoint;
194 }
195
196 void SketchPlugin_Trim::execute()
197 {
198 #ifdef DEBUG_TRIM_METHODS
199   std::cout << "SketchPlugin_Trim::execute: " << data()->name() << std::endl;
200 #endif
201
202   SketchPlugin_Sketch* aSketch = sketch();
203   if (!aSketch) {
204     setError("Error: Sketch object is empty.");
205     return;
206   }
207
208   // Check the base objects are initialized.
209   AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
210                                         data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
211   if(!aBaseObjectAttr->isInitialized()) {
212     setError("Error: Base object is not initialized.");
213     return;
214   }
215   ObjectPtr aBaseObject = aBaseObjectAttr->value();
216   if (!aBaseObject.get()) {
217     setError("Error: Base object is not initialized.");
218     return;
219   }
220   FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
221
222   /// Remove reference of this feature to feature used in preview, it is not necessary anymore
223   /// as trim will be removed after execute
224   AttributeReferencePtr aPreviewObjectAttr =
225                      std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
226                      data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
227
228   ObjectPtr aPreviewObject = aPreviewObjectAttr->value();
229   AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
230                                            data()->attribute(PREVIEW_POINT()));
231   std::shared_ptr<GeomAPI_Pnt2d> aPreviewPnt2d = aPoint->pnt();
232   // nullify pointer of preview attribute
233   aPreviewObjectAttr->setValue(ResultPtr());
234
235   bool anIsEqualPreviewAndSelected = aPreviewObject == aBaseObject;
236
237   /// points of trim
238   std::shared_ptr<GeomAPI_Pnt> aStartShapePoint, aLastShapePoint;
239 #ifdef DEBUG_TRIM
240   std::cout << " Base Feature: " << aBaseFeature->data()->name() << std::endl;
241 #endif
242   findShapePoints(SELECTED_OBJECT(), SELECTED_POINT(), aStartShapePoint, aLastShapePoint);
243
244   std::shared_ptr<GeomAPI_Pnt2d> aStartShapePoint2d = convertPoint(aStartShapePoint);
245   std::shared_ptr<GeomAPI_Pnt2d> aLastShapePoint2d = convertPoint(aLastShapePoint);
246   /// find features that should be deleted (e.g. Middle Point) or updated (e.g. Length)
247   std::set<FeaturePtr> aFeaturesToDelete, aFeaturesToUpdate;
248   getConstraints(aFeaturesToDelete, aFeaturesToUpdate);
249   // find references(attributes and features) to the base feature
250   std::map<AttributePtr, std::list<AttributePtr> > aBaseRefAttributes;
251   std::list<AttributePtr> aRefsToFeature;
252   getRefAttributes(aBaseFeature, aBaseRefAttributes, aRefsToFeature);
253 #ifdef DEBUG_TRIM
254   std::cout << "---- getRefAttributes ----" << std::endl;
255   std::map<AttributePtr, std::list<AttributePtr> >::const_iterator
256     aRefIt = aBaseRefAttributes.begin(), aRefLast = aBaseRefAttributes.end();
257   std::cout << std::endl << "References to attributes of base feature [" <<
258     aBaseRefAttributes.size() << "]" << std::endl;
259   for (; aRefIt != aRefLast; aRefIt++) {
260     AttributePtr aBaseAttr = aRefIt->first;
261     std::list<AttributePtr> aRefAttributes = aRefIt->second;
262     std::string aRefsInfo;
263     std::list<AttributePtr>::const_iterator aRefAttrIt = aRefAttributes.begin(),
264                                             aRefAttrLast = aRefAttributes.end();
265     for (; aRefAttrIt != aRefAttrLast; aRefAttrIt++) {
266       if (!aRefsInfo.empty())
267         aRefsInfo.append(",");
268       AttributePtr aRAttr = *aRefAttrIt;
269       aRefsInfo.append(aRAttr->id());
270       FeaturePtr aRFeature = ModelAPI_Feature::feature(aRAttr->owner());
271       aRefsInfo.append("(" + aRFeature->name() + ") ");
272     }
273     std::shared_ptr<GeomDataAPI_Point2D> aPointAttr =
274       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aBaseAttr);
275     std::cout << aPointAttr->id().c_str() <<
276       ": " << "[" << aRefAttributes.size() << "] " << aRefsInfo << std::endl;
277   }
278   std::cout << std::endl;
279   std::cout << std::endl << "References to base feature [" <<
280     aRefsToFeature.size() << "]" << std::endl;
281   std::list<AttributePtr>::const_iterator aRefAttrIt = aRefsToFeature.begin(),
282                                           aRefAttrLast = aRefsToFeature.end();
283   std::string aRefsInfo;
284   for (; aRefAttrIt != aRefAttrLast; aRefAttrIt++) {
285     if (!aRefsInfo.empty())
286       aRefsInfo.append(",");
287     AttributePtr aRAttr = *aRefAttrIt;
288     aRefsInfo.append(aRAttr->id());
289     FeaturePtr aRFeature = ModelAPI_Feature::feature(aRAttr->owner());
290     aRefsInfo.append("(" + aRFeature->name() + ") ");
291   }
292   std::cout << "[" << aRefsToFeature.size() << "] " << aRefsInfo << std::endl;
293   std::cout << "---- getRefAttributes:end ----" << std::endl;
294 #endif
295   std::set<AttributePoint2DPtr> aFurtherCoincidences;
296   std::set<std::pair<AttributePtr, AttributePtr>> aModifiedAttributes;
297   const std::string& aKind = aBaseFeature->getKind();
298   FeaturePtr aReplacingFeature, aNewFeature;
299   if (aKind == SketchPlugin_Circle::ID()) {
300     aReplacingFeature = trimCircle(aStartShapePoint2d, aLastShapePoint2d,
301                aFurtherCoincidences, aModifiedAttributes);
302
303     aFeaturesToDelete.insert(aBaseFeature);
304     // as circle is removed, erase it from dependencies(arguments) of this feature
305     // otherwise Trim feature will be removed with the circle before
306     // this operation is finished
307     aBaseObjectAttr->setObject(ResultPtr());
308   }
309   else if (aKind == SketchPlugin_Line::ID()) {
310     aNewFeature = trimLine(aStartShapePoint2d, aLastShapePoint2d, aBaseRefAttributes,
311                            aFurtherCoincidences, aModifiedAttributes);
312   }
313   else if (aKind == SketchPlugin_Arc::ID()) {
314     aNewFeature = trimArc(aStartShapePoint2d, aLastShapePoint2d, aBaseRefAttributes,
315                           aFurtherCoincidences, aModifiedAttributes);
316   }
317
318   // constraints to end points of trim feature
319   if (myObjectToPoints.find(aBaseObject) == myObjectToPoints.end())
320     fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
321
322   // create coincidence to objects, intersected the base object
323   const PointToRefsMap& aRefsMap = myObjectToPoints.at(aBaseObject);
324   for (std::set<AttributePoint2DPtr>::const_iterator anIt = aFurtherCoincidences.begin(),
325                                                      aLast = aFurtherCoincidences.end();
326        anIt != aLast; anIt++) {
327     AttributePoint2DPtr aPointAttribute = (*anIt);
328     std::shared_ptr<GeomAPI_Pnt2d> aPoint2d = aPointAttribute->pnt();
329
330 #ifdef DEBUG_TRIM
331     std::cout << "<compare Points> => " << std::endl
332             << "aPoint2d: [" << aPoint2d->x() << ", " << aPoint2d->y() << "]" << std::endl;
333     if (aStartShapePoint2d.get())
334       std::cout << "Start Point: [" << aStartShapePoint2d->x() << ", " << aStartShapePoint2d->y()
335                 << "]" << std::endl;
336     if (aLastShapePoint2d.get())
337       std::cout << "Last Point: [" << aLastShapePoint2d->x() << ", " << aLastShapePoint2d->y()
338                 << "]" << std::endl;
339 #endif
340
341     std::shared_ptr<GeomAPI_Pnt> aPoint;
342     if (aStartShapePoint2d.get() && aPoint2d->isEqual(aStartShapePoint2d))
343       aPoint = aStartShapePoint;
344     else if (aLastShapePoint2d.get() && aPoint2d->isEqual(aLastShapePoint2d))
345       aPoint = aLastShapePoint;
346
347     if (!aPoint.get())
348       continue;
349
350     std::pair<std::list<AttributePoint2DPtr >, std::list<ObjectPtr > > anInfo;
351     for (PointToRefsMap::const_iterator aRefIt = aRefsMap.begin(); aRefIt != aRefsMap.end();
352          aRefIt++)
353     {
354       if (aRefIt->first->isEqual(aPoint)) {
355         anInfo = aRefIt->second;
356         break;
357       }
358     }
359     const std::list<ObjectPtr>& anObjects = anInfo.second;
360     for (std::list<ObjectPtr>::const_iterator anObjectIt = anObjects.begin();
361       anObjectIt != anObjects.end(); anObjectIt++) {
362       SketchPlugin_Tools::createConstraintAttrObject(sketch(),
363             SketchPlugin_ConstraintCoincidence::ID(),
364             aPointAttribute, *anObjectIt);
365     }
366   }
367
368   // move constraints from base feature to replacing feature: ignore coincidences to feature
369   // if attributes of coincidence participated in split
370   ResultPtr aReplacingResult;
371   if (aReplacingFeature.get()) {
372     aReplacingFeature->execute(); // need it to obtain result
373     aReplacingResult = getFeatureResult(aReplacingFeature);
374   }
375   for(std::list<AttributePtr>::const_iterator anIt = aRefsToFeature.begin(),
376                                           aLast = aRefsToFeature.end();
377       anIt != aLast; anIt++) {
378     AttributePtr anAttribute = *anIt;
379
380     if (setCoincidenceToAttribute(anAttribute, aFurtherCoincidences, aFeaturesToDelete))
381       continue;
382
383     // move tangency constraint to the nearest feature if possible
384     if (aNewFeature.get() && moveTangency(anAttribute, aNewFeature))
385       continue;
386
387     if (aReplacingResult.get()) {
388       AttributeRefAttrPtr aRefAttr =
389           std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
390       if (aRefAttr.get())
391         aRefAttr->setObject(aReplacingResult);
392       else {
393         AttributeReferencePtr aReferenceAttr =
394                              std::dynamic_pointer_cast<ModelAPI_AttributeReference>(anAttribute);
395         if (aReferenceAttr.get())
396           aReferenceAttr->setObject(aReplacingResult);
397       }
398     }
399   }
400
401   updateRefAttConstraints(aBaseRefAttributes, aModifiedAttributes, aFeaturesToDelete);
402
403   // Wait all constraints being created, then send update events
404   static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
405   bool isUpdateFlushed = Events_Loop::loop()->isFlushed(anUpdateEvent);
406   if (isUpdateFlushed)
407     Events_Loop::loop()->setFlushed(anUpdateEvent, false);
408
409   // delete constraints
410 #ifdef DEBUG_TRIM
411   if (aFeaturesToDelete.size() > 0) {
412     std::cout << "after SPlit: removeFeaturesAndReferences: " << std::endl;
413     std::string aValue;
414     for (std::set<FeaturePtr>::const_iterator anIt = aFeaturesToDelete.begin();
415          anIt != aFeaturesToDelete.end(); anIt++) {
416       FeaturePtr aFeature = *anIt;
417       std::cout << aFeature->data()->name() << std::endl;
418     }
419   }
420 #endif
421   ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToDelete);
422   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
423
424   updateFeaturesAfterTrim(aFeaturesToUpdate);
425
426   // Send events to update the sub-features by the solver.
427   if(isUpdateFlushed) {
428     Events_Loop::loop()->setFlushed(anUpdateEvent, true);
429   }
430
431   if (anIsEqualPreviewAndSelected) {
432     // equal preview and selected objects
433     // nothing to do if the preview and selected objects are different
434     if (aReplacingResult.get()) { // base object was removed
435       aPreviewObject = aReplacingResult;
436       //aMessage->setSelectedObject(aReplacingResult);
437 #ifdef DEBUG_TRIM_METHODS
438       if (!aSelectedShape.get())
439         std::cout << "Set empty selected object" << std::endl;
440       else
441         std::cout << "Set shape with ShapeType: " << aSelectedShape->shapeTypeStr() << std::endl;
442 #endif
443     }
444     else {
445       aPreviewObject = ObjectPtr();
446
447       aBaseFeature->execute(); // should recompute shapes of result to do not check obsolete one
448       aBaseObject = getFeatureResult(aBaseFeature);
449       std::shared_ptr<GeomAPI_Pnt> aPreviewPnt = sketch()->to3D(aPreviewPnt2d->x(),
450                                                                 aPreviewPnt2d->y());
451       ResultPtr aBaseResult = std::dynamic_pointer_cast<ModelAPI_Result>(aBaseObject);
452       if (aBaseResult) {
453         GeomShapePtr aShape = aBaseResult->shape();
454         std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
455         if (ModelGeomAlgo_Point2D::isPointOnEdge(aShape, aPreviewPnt, aProjectedPoint))
456           aPreviewObject = aBaseResult;
457       }
458       if (!aPreviewObject.get() && aNewFeature.get()) {
459         ResultPtr aNewFeatureResult = getFeatureResult(aNewFeature);
460         if (aNewFeatureResult.get()) {
461           GeomShapePtr aShape = aNewFeatureResult->shape();
462           std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
463           if (ModelGeomAlgo_Point2D::isPointOnEdge(aShape, aPreviewPnt, aProjectedPoint))
464             aPreviewObject = aNewFeatureResult;
465         }
466       }
467     }
468   }
469   if (aPreviewObject.get()) {
470     std::shared_ptr<ModelAPI_EventReentrantMessage> aMessage = std::shared_ptr
471       <ModelAPI_EventReentrantMessage>(new ModelAPI_EventReentrantMessage(
472                                            ModelAPI_EventReentrantMessage::eventId(), this));
473     aMessage->setSelectedObject(aPreviewObject);
474     Events_Loop::loop()->send(aMessage);
475   }
476 #ifdef DEBUG_TRIM
477   std::cout << "SketchPlugin_Trim::done" << std::endl;
478 #endif
479 }
480
481 // LCOV_EXCL_START
482 std::string SketchPlugin_Trim::processEvent(const std::shared_ptr<Events_Message>& theMessage)
483 {
484 #ifdef DEBUG_TRIM_METHODS
485   std::cout << "SketchPlugin_Trim::processEvent:" << data()->name() << std::endl;
486 #endif
487   std::string aFilledAttributeName;
488
489   std::shared_ptr<ModelAPI_EventReentrantMessage> aMessage =
490         std::dynamic_pointer_cast<ModelAPI_EventReentrantMessage>(theMessage);
491   if (aMessage.get()) {
492     ObjectPtr anObject = aMessage->selectedObject();
493     std::shared_ptr<GeomAPI_Pnt2d> aPoint = aMessage->clickedPoint();
494
495     if (anObject.get() && aPoint.get()) {
496       if (myCashedShapes.find(anObject) == myCashedShapes.end())
497         fillObjectShapes(anObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
498       const std::set<GeomShapePtr>& aShapes = myCashedShapes[anObject];
499       if (aShapes.size() > 1) {
500         std::shared_ptr<ModelAPI_AttributeReference> aRefSelectedAttr =
501                               std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
502                               data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
503         std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
504                               std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
505                               data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
506         aRefSelectedAttr->setValue(anObject);
507         aRefPreviewAttr->setValue(anObject);
508
509         std::shared_ptr<GeomDataAPI_Point2D> aPointSelectedAttr =
510                               std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
511                               data()->attribute(SketchPlugin_Trim::SELECTED_POINT()));
512         std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
513                               std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
514                               data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
515         aPointSelectedAttr->setValue(aPoint);
516         aPointPreviewAttr->setValue(aPoint);
517
518         Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
519
520         GeomShapePtr aSelectedShape = getSubShape(SELECTED_OBJECT(), SELECTED_POINT());
521   #ifdef DEBUG_TRIM_METHODS
522         if (!aSelectedShape.get())
523           std::cout << "Set empty selected object" << std::endl;
524         else
525           std::cout << "Set shape with ShapeType: " << aSelectedShape->shapeTypeStr() << std::endl;
526   #endif
527         aFilledAttributeName = SketchPlugin_Trim::SELECTED_OBJECT();
528       }
529     }
530   }
531   return aFilledAttributeName;
532 }
533 // LCOV_EXCL_STOP
534
535 bool SketchPlugin_Trim::setCoincidenceToAttribute(const AttributePtr& theAttribute,
536                                 const std::set<AttributePoint2DPtr>& theFurtherCoincidences,
537                                 std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete)
538 {
539   FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
540   if (aFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID())
541     return false;
542
543   AttributePoint2DPtr aRefPointAttr = SketchPlugin_ConstraintCoincidence::getPoint(aFeature);
544   if (!aRefPointAttr.get())
545     return false;
546   std::shared_ptr<GeomAPI_Pnt2d> aRefPnt2d = aRefPointAttr->pnt();
547
548   std::set<AttributePoint2DPtr>::const_iterator anIt = theFurtherCoincidences.begin(),
549                                                 aLast = theFurtherCoincidences.end();
550   bool aFoundPoint = false;
551   for (; anIt != aLast && !aFoundPoint; anIt++) {
552     AttributePoint2DPtr aPointAttribute = (*anIt);
553     std::shared_ptr<GeomAPI_Pnt2d> aPoint2d = aPointAttribute->pnt();
554     if (aPoint2d->isEqual(aRefPnt2d)) {
555       // create new coincidence and then remove the old one
556       SketchPlugin_Tools::createConstraintAttrAttr(sketch(),
557           SketchPlugin_ConstraintCoincidence::ID(),
558           aRefPointAttr, aPointAttribute);
559       theFeaturesToDelete.insert(aFeature);
560     }
561   }
562   return aFoundPoint;
563 }
564
565 bool SketchPlugin_Trim::moveTangency(const AttributePtr& theAttribute,
566                                      const FeaturePtr& theFeature)
567 {
568   FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
569   if (aFeature->getKind() != SketchPlugin_ConstraintTangent::ID())
570     return false;
571
572   AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
573                                                                            theAttribute);
574   if (!aRefAttr.get())
575     return false;
576
577   // get shape of tangent object to the current
578   std::string aTangentAttr = SketchPlugin_Constraint::ENTITY_A();
579   if (aRefAttr->id() == SketchPlugin_Constraint::ENTITY_A())
580     aTangentAttr = SketchPlugin_Constraint::ENTITY_B();
581   AttributeRefAttrPtr aTangentRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
582                                                      aFeature->attribute(aTangentAttr));
583   FeaturePtr aTangentFeature = ModelAPI_Feature::feature(aTangentRefAttr->object());
584
585   // get shape of the feature of the attribute
586   FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(aRefAttr->object());
587   anAttributeFeature->execute(); // the modified value should be applyed to recompute shape
588   PointToRefsMap aPointToAttributeOrObject;
589   std::list<FeaturePtr> aFeatures;
590   aFeatures.push_back(anAttributeFeature);
591   ModelGeomAlgo_Point2D::getPointsIntersectedShape(aTangentFeature, aFeatures,
592                                                    aPointToAttributeOrObject);
593   if (!aPointToAttributeOrObject.empty())
594     return true; // the attribute feature has a point of intersection, so we do not replace it
595
596   // get shape of the feature
597   aPointToAttributeOrObject.clear();
598   aFeatures.clear();
599   aFeatures.push_back(theFeature);
600   ModelGeomAlgo_Point2D::getPointsIntersectedShape(aTangentFeature, aFeatures,
601                                                    aPointToAttributeOrObject);
602   if (!aPointToAttributeOrObject.empty()) {
603     std::set<ResultPtr> anEdgeShapes;
604     ModelGeomAlgo_Shape::shapesOfType(theFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
605     if (!anEdgeShapes.empty()) {
606       ResultPtr aResult = *anEdgeShapes.begin();
607       if (aResult.get()) {
608         aRefAttr->setObject(aResult);
609         return true; // the attribute feature has a point of intersection, so we do not replace it
610       }
611     }
612   }
613   return false;
614 }
615
616 AISObjectPtr SketchPlugin_Trim::getAISObject(AISObjectPtr thePrevious)
617 {
618 #ifdef DEBUG_TRIM_METHODS
619   std::cout << "SketchPlugin_Trim::getAISObject: " << data()->name() << std::endl;
620 #endif
621
622   AISObjectPtr anAIS = thePrevious;
623
624   std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
625   GeomShapePtr aPreviewShape = getSubShape(PREVIEW_OBJECT(), PREVIEW_POINT());
626   if (aPreviewShape.get())
627     aShapes.push_back(aPreviewShape);
628   GeomShapePtr aSelectedShape = getSubShape(SELECTED_OBJECT(), SELECTED_POINT());
629   if (aSelectedShape.get())
630     aShapes.push_back(aSelectedShape);
631
632   if (aShapes.empty())
633     return AISObjectPtr();
634
635   GeomShapePtr aBaseShape = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
636   if (!aBaseShape.get())
637     return AISObjectPtr();
638
639   if (aBaseShape.get()) {
640     if (!anAIS)
641       anAIS = AISObjectPtr(new GeomAPI_AISObject);
642     anAIS->createShape(aBaseShape);
643
644     std::vector<int> aColor;
645     aColor = Config_PropManager::color("Visualization", "operation_remove_feature_color");
646     double aWidth = SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH();
647     int aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE();
648     anAIS->setColor(aColor[0], aColor[1], aColor[2]);
649     // width when there is not base object should be extened in several points
650     // in order to see this preview over highlight
651     anAIS->setWidth(aWidth+4);
652     anAIS->setLineStyle(aLineStyle);
653   }
654   else
655     anAIS = AISObjectPtr();
656
657   return anAIS;
658 }
659
660 GeomShapePtr SketchPlugin_Trim::getSubShape(const std::string& theObjectAttributeId,
661                                             const std::string& thePointAttributeId)
662 {
663   GeomShapePtr aBaseShape;
664
665   AttributeReferencePtr anObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
666                                                        data()->attribute(theObjectAttributeId));
667   ObjectPtr aBaseObject = anObjectAttr->value();
668   if (!aBaseObject.get())
669     return aBaseShape;
670
671   // point on feature
672   AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
673                                            data()->attribute(thePointAttributeId));
674   std::shared_ptr<GeomAPI_Pnt2d> anAttributePnt2d = aPointAttr->pnt();
675   std::shared_ptr<GeomAPI_Pnt> anAttributePnt = sketch()->to3D(anAttributePnt2d->x(),
676                                                                anAttributePnt2d->y());
677
678   if (myCashedShapes.find(aBaseObject) == myCashedShapes.end())
679     fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
680
681   const std::set<GeomShapePtr>& aShapes = myCashedShapes[aBaseObject];
682   if (!aShapes.empty()) {
683     std::set<GeomShapePtr>::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();
684     for (; anIt != aLast; anIt++) {
685       GeomShapePtr aShape = *anIt;
686       std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
687       if (ModelGeomAlgo_Point2D::isPointOnEdge(aShape, anAttributePnt, aProjectedPoint))
688         aBaseShape = aShape;
689     }
690   }
691   return aBaseShape;
692 }
693
694 void SketchPlugin_Trim::getFeaturePoints(const FeaturePtr& theFeature,
695                                          AttributePoint2DPtr& theStartPointAttr,
696                                          AttributePoint2DPtr& theEndPointAttr)
697 {
698   std::string aFeatureKind = theFeature->getKind();
699   std::string aStartAttributeName, anEndAttributeName;
700   if (aFeatureKind == SketchPlugin_Line::ID()) {
701     aStartAttributeName = SketchPlugin_Line::START_ID();
702     anEndAttributeName = SketchPlugin_Line::END_ID();
703   }
704   else if (aFeatureKind == SketchPlugin_Arc::ID()) {
705     aStartAttributeName = SketchPlugin_Arc::START_ID();
706     anEndAttributeName = SketchPlugin_Arc::END_ID();
707   }
708   if (!aStartAttributeName.empty() && !anEndAttributeName.empty()) {
709     theStartPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
710                                          theFeature->attribute(aStartAttributeName));
711     theEndPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
712                                          theFeature->attribute(anEndAttributeName));
713   }
714 }
715
716 void SketchPlugin_Trim::getConstraints(std::set<FeaturePtr>& theFeaturesToDelete,
717                                        std::set<FeaturePtr>& theFeaturesToUpdate)
718 {
719   std::shared_ptr<ModelAPI_Data> aData = data();
720
721   // Check the base objects are initialized.
722   AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
723                                          aData->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
724   FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
725   ResultPtr aBaseFeatureResult = getFeatureResult(aBaseFeature);
726
727   std::set<AttributePtr> aRefsList = aBaseFeatureResult->data()->refsToMe();
728   std::set<AttributePtr> aFRefsList = aBaseFeature->data()->refsToMe();
729   aRefsList.insert(aFRefsList.begin(), aFRefsList.end());
730
731   std::set<AttributePtr>::const_iterator aIt;
732   for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
733     std::shared_ptr<ModelAPI_Attribute> anAttr = (*aIt);
734     FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
735     std::string aRefFeatureKind = aRefFeature->getKind();
736     std::string anAttributeId = anAttr->id();
737     if ((aRefFeatureKind == SketchPlugin_ConstraintMirror::ID() &&
738          anAttributeId == SketchPlugin_ConstraintMirror::MIRROR_LIST_ID()) ||
739         (aRefFeatureKind == SketchPlugin_MultiRotation::ID() &&
740          anAttributeId == SketchPlugin_MultiRotation::ROTATION_LIST_ID()) ||
741         (aRefFeatureKind == SketchPlugin_MultiTranslation::ID() &&
742          anAttributeId == SketchPlugin_MultiTranslation::TRANSLATION_LIST_ID()) ||
743         aRefFeatureKind == SketchPlugin_ConstraintMiddle::ID())
744       theFeaturesToDelete.insert(aRefFeature);
745     else if (aRefFeatureKind == SketchPlugin_ConstraintLength::ID())
746       theFeaturesToUpdate.insert(aRefFeature);
747   }
748 }
749
750 void SketchPlugin_Trim::getRefAttributes(const FeaturePtr& theFeature,
751                                     std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
752                                     std::list<AttributePtr>& theRefsToFeature)
753 {
754   theRefs.clear();
755
756   std::list<AttributePtr> aPointAttributes =
757     theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
758   std::set<AttributePtr> aPointAttributesSet;
759
760   std::list<AttributePtr>::const_iterator aPIt =
761     aPointAttributes.begin(), aPLast = aPointAttributes.end();
762   for (; aPIt != aPLast; aPIt++)
763     aPointAttributesSet.insert(*aPIt);
764
765   std::set<AttributePtr> aRefsAttributes = getFeatureResult(theFeature)->data()->refsToMe();
766   std::set<AttributePtr> aFRefsList = theFeature->data()->refsToMe();
767   aRefsAttributes.insert(aFRefsList.begin(), aFRefsList.end());
768
769   std::set<AttributePtr>::const_iterator aIt;
770   for (aIt = aRefsAttributes.cbegin(); aIt != aRefsAttributes.cend(); ++aIt) {
771     AttributePtr anAttr = (*aIt);
772     FeaturePtr anAttrFeature = ModelAPI_Feature::feature(anAttr->owner());
773     if (anAttrFeature.get() != this &&
774         anAttr.get() && anAttr->attributeType() == ModelAPI_AttributeRefAttr::typeId()) {
775       AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttr);
776       if (!aRefAttr->isObject()) { /// find attributes referenced to feature point attributes
777         AttributePtr anAttrInRef = aRefAttr->attr();
778         if (anAttrInRef.get() &&
779             aPointAttributesSet.find(anAttrInRef) != aPointAttributesSet.end()) {
780           if (theRefs.find(anAttrInRef) != theRefs.end())
781             theRefs[anAttrInRef].push_back(aRefAttr);
782           else {
783             std::list<AttributePtr> anAttrList;
784             anAttrList.push_back(aRefAttr);
785             theRefs[anAttrInRef] = anAttrList;
786           }
787         }
788       }
789       else { /// find attributes referenced to feature itself
790         theRefsToFeature.push_back(anAttr);
791       }
792     }
793   }
794 }
795
796 void SketchPlugin_Trim::updateRefAttConstraints(
797                     const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
798                     const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes,
799                     std::set<FeaturePtr>& theFeaturesToDelete)
800 {
801 #ifdef DEBUG_TRIM
802   std::cout << "SketchPlugin_Trim::updateRefAttConstraints" << std::endl;
803 #endif
804
805   std::set<std::pair<AttributePtr, AttributePtr> >::const_iterator
806     anIt = theModifiedAttributes.begin(),  aLast = theModifiedAttributes.end();
807   for (; anIt != aLast; anIt++) {
808     AttributePtr anAttribute = anIt->first;
809
810     /// not found in references
811     if (theBaseRefAttributes.find(anAttribute) == theBaseRefAttributes.end())
812       continue;
813     std::list<AttributePtr> aRefAttributes = theBaseRefAttributes.at(anAttribute);
814     std::list<AttributePtr>::const_iterator aRefIt = aRefAttributes.begin(),
815                                             aRLast = aRefAttributes.end();
816
817     AttributePtr aNewAttribute = anIt->second;
818     if (aNewAttribute.get()) {
819       for (; aRefIt != aRLast; aRefIt++) {
820         AttributeRefAttrPtr aRefAttr =
821                         std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*aRefIt);
822         if (aRefAttr.get()) {
823             aRefAttr->setAttr(aNewAttribute);
824         }
825       }
826     }
827   }
828 }
829
830 void SketchPlugin_Trim::removeReferencesToAttribute(const AttributePtr& theAttribute,
831                   std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes)
832 {
833   /// not found in references
834   if (theBaseRefAttributes.find(theAttribute) == theBaseRefAttributes.end())
835     return;
836
837   std::list<AttributePtr> aRefAttributes = theBaseRefAttributes.at(theAttribute);
838   std::list<AttributePtr>::const_iterator aRefIt = aRefAttributes.begin(),
839                                           aRLast = aRefAttributes.end();
840
841   std::set<FeaturePtr> aFeaturesToDelete;
842   for (; aRefIt != aRLast; aRefIt++) {
843     AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*aRefIt);
844     if (aRefAttr.get()) {
845       aFeaturesToDelete.insert(ModelAPI_Feature::feature(aRefAttr->owner()));
846     }
847   }
848
849 #ifdef DEBUG_TRIM
850   // delete constraints
851   if (aFeaturesToDelete.size() > 0) {
852     std::cout << "removeReferencesToAttribute: " << std::endl;
853     std::string aValue;
854     for (std::set<FeaturePtr>::const_iterator anIt = aFeaturesToDelete.begin();
855          anIt != aFeaturesToDelete.end(); anIt++) {
856       FeaturePtr aFeature = *anIt;
857       std::cout << aFeature->data()->name() << std::endl;
858     }
859   }
860 #endif
861   ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToDelete);
862   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
863 }
864
865 void SketchPlugin_Trim::updateFeaturesAfterTrim(const std::set<FeaturePtr>& theFeaturesToUpdate)
866 {
867   std::set<FeaturePtr>::const_iterator anIt = theFeaturesToUpdate.begin(),
868                                        aLast = theFeaturesToUpdate.end();
869   for (; anIt != aLast; anIt++) {
870     FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
871     std::string aRefFeatureKind = aRefFeature->getKind();
872     if (aRefFeatureKind == SketchPlugin_ConstraintLength::ID()) {
873       std::shared_ptr<SketchPlugin_ConstraintLength> aLenghtFeature =
874                               std::dynamic_pointer_cast<SketchPlugin_ConstraintLength>(*anIt);
875       if (aLenghtFeature.get()) {
876         std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
877             ModelAPI_AttributeDouble>(aLenghtFeature->attribute(SketchPlugin_Constraint::VALUE()));
878         double aValue;
879         if (aLenghtFeature->computeLenghtValue(aValue) && aValueAttr.get())
880           aValueAttr->setValue(aValue);
881       }
882     }
883   }
884 }
885
886 FeaturePtr SketchPlugin_Trim::trimLine(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
887                   const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
888                   std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
889                   std::set<AttributePoint2DPtr>& thePoints,
890                   std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes)
891 {
892   FeaturePtr anNewFeature;
893
894   // Check the base objects are initialized.
895   AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
896                                         data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
897   ObjectPtr aBaseObject = aBaseObjectAttr->value();
898   FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
899
900   /// points of trim
901   AttributePoint2DPtr aStartPointAttrOfBase, anEndPointAttrOfBase;
902   getFeaturePoints(aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase);
903
904   std::shared_ptr<GeomAPI_Pnt2d> aStartFeaturePoint = aStartPointAttrOfBase->pnt();
905   std::shared_ptr<GeomAPI_Pnt2d> aLastFeaturePoint = anEndPointAttrOfBase->pnt();
906
907   std::shared_ptr<GeomAPI_Pnt2d> aStartShapePoint = theStartShapePoint;
908   std::shared_ptr<GeomAPI_Pnt2d> aLastShapePoint = theLastShapePoint;
909   arrangePointsOnLine(aStartPointAttrOfBase, anEndPointAttrOfBase,
910                       aStartShapePoint, aLastShapePoint);
911 #ifdef DEBUG_TRIM
912   std::cout << "Arranged points (to build split between 1st and 2nd points:" << std::endl;
913   if (aStartShapePoint.get())
914     std::cout << "Start point: [" << aStartShapePoint->x() << ", " <<
915                                        aStartShapePoint->y() << "]" << std::endl;
916   std::cout << "1st point:   [" << aStartFeaturePoint->x() << ", " <<
917                                    aStartFeaturePoint->y() << "]" << std::endl;
918   if (aLastShapePoint.get())
919     std::cout << "2st point:   [" << aLastShapePoint->x() << ", " <<
920                                      aLastShapePoint->y() << "]" << std::endl;
921   std::cout << "End point:   [" << aLastFeaturePoint->x() << ", " <<
922                                    aLastFeaturePoint->y() << "]" << std::endl;
923 #endif
924
925   bool isStartPoint = !aStartShapePoint.get() || aStartFeaturePoint->isEqual(aStartShapePoint);
926   bool isLastPoint = !aLastShapePoint.get() || aLastFeaturePoint->isEqual(aLastShapePoint);
927   if (isStartPoint || isLastPoint) {
928     // result is one line: changed existing line
929     std::string aModifiedAttribute = isStartPoint ? SketchPlugin_Line::START_ID()
930                                                   : SketchPlugin_Line::END_ID();
931     std::shared_ptr<GeomAPI_Pnt2d> aPoint;
932     if (aStartShapePoint.get() && aLastShapePoint.get())
933       aPoint = isStartPoint ? aLastShapePoint : aStartShapePoint;
934     else
935       aPoint = aStartShapePoint.get() ? aStartShapePoint : aLastShapePoint;
936
937     // it is important to delete references before the feature modification because
938     // if deletion will be after the feature modification, solver returns the feature back
939     removeReferencesToAttribute(aBaseFeature->attribute(aModifiedAttribute),
940                                 theBaseRefAttributes);
941
942     fillPointAttribute(aBaseFeature->attribute(aModifiedAttribute), aPoint);
943     //theModifiedAttributes.insert(
944     //  std::make_pair(aBaseFeature->attribute(aModifiedAttribute), AttributePtr()));
945
946     thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
947                                (aBaseFeature->attribute(aModifiedAttribute)));
948   }
949   else {
950     // result is two lines: start line point - start shape point,
951     // last shape point - last line point
952     // create second line
953     anNewFeature = createLineFeature(aBaseFeature, aLastShapePoint, aLastFeaturePoint);
954     thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
955                                (anNewFeature->attribute(SketchPlugin_Line::START_ID())));
956
957     std::string aModifiedAttribute = SketchPlugin_Line::END_ID();
958     theModifiedAttributes.insert(
959       std::make_pair(aBaseFeature->attribute(aModifiedAttribute),
960                                    anNewFeature->attribute(SketchPlugin_Line::END_ID())));
961
962     // modify base arc
963     fillPointAttribute(aBaseFeature->attribute(aModifiedAttribute), aStartShapePoint);
964
965     thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
966                                (aBaseFeature->attribute(aModifiedAttribute)));
967
968     // Collinear constraint for lines
969     SketchPlugin_Tools::createConstraintObjectObject(sketch(),
970                                          SketchPlugin_ConstraintCollinear::ID(),
971                                          getFeatureResult(aBaseFeature),
972                                          getFeatureResult(anNewFeature));
973   }
974   return anNewFeature;
975 }
976
977 FeaturePtr SketchPlugin_Trim::trimArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
978                  const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
979                  std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
980                  std::set<AttributePoint2DPtr>& thePoints,
981                  std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes)
982 {
983   FeaturePtr anNewFeature;
984   // Check the base objects are initialized.
985   AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
986                                         data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
987   ObjectPtr aBaseObject = aBaseObjectAttr->value();
988   FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
989
990   /// points of trim
991   AttributePoint2DPtr aStartPointAttrOfBase, anEndPointAttrOfBase;
992   getFeaturePoints(aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase);
993
994   std::shared_ptr<GeomAPI_Pnt2d> aStartArcPoint = aStartPointAttrOfBase->pnt();
995   std::shared_ptr<GeomAPI_Pnt2d> aLastArcPoint = anEndPointAttrOfBase->pnt();
996
997   std::shared_ptr<GeomAPI_Pnt2d> aStartShapePoint = theStartShapePoint;
998   std::shared_ptr<GeomAPI_Pnt2d> aLastShapePoint = theLastShapePoint;
999   arrangePointsOnArc(aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase,
1000                      aStartShapePoint, aLastShapePoint);
1001 #ifdef DEBUG_TRIM
1002   std::cout << "Arranged points (to build split between 1st and 2nd points:" << std::endl;
1003   if (aStartShapePoint.get())
1004     std::cout << "Start shape point: [" << aStartShapePoint->x() << ", " <<
1005                                        aStartShapePoint->y() << "]" << std::endl;
1006   std::cout << "Start arc attribute point:   [" << aStartArcPoint->x() << ", " <<
1007                                    aStartArcPoint->y() << "]" << std::endl;
1008   if (aLastShapePoint.get())
1009     std::cout << "Last shape point:   [" << aLastShapePoint->x() << ", " <<
1010                                      aLastShapePoint->y() << "]" << std::endl;
1011   std::cout << "Last arc attribute point:   [" << aLastArcPoint->x() << ", " <<
1012                                    aLastArcPoint->y() << "]" << std::endl;
1013 #endif
1014
1015   bool isStartPoint = !aStartShapePoint.get() || aStartArcPoint->isEqual(aStartShapePoint);
1016   bool isLastPoint = !aLastShapePoint.get() || aLastArcPoint->isEqual(aLastShapePoint);
1017   if (isStartPoint || isLastPoint) {
1018     // result is one arc: changed existing arc
1019     std::string aModifiedAttribute = isStartPoint ? SketchPlugin_Arc::START_ID()
1020                                                   : SketchPlugin_Arc::END_ID();
1021     std::shared_ptr<GeomAPI_Pnt2d> aPoint;
1022     if (aStartShapePoint.get() && aLastShapePoint.get())
1023       aPoint = isStartPoint ? aLastShapePoint : aStartShapePoint;
1024     else
1025       aPoint = aStartShapePoint.get() ? aStartShapePoint : aLastShapePoint;
1026
1027     removeReferencesToAttribute(aBaseFeature->attribute(aModifiedAttribute),
1028                                 theBaseRefAttributes);
1029
1030     fillPointAttribute(aBaseFeature->attribute(aModifiedAttribute), aPoint);
1031
1032     thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
1033                                (aBaseFeature->attribute(aModifiedAttribute)));
1034   }
1035   else {
1036     // result is two arcs: start arc point - start shape point, last shape point - last arc point
1037     // create second arc
1038     anNewFeature = createArcFeature(aBaseFeature, aLastShapePoint, aLastArcPoint);
1039     thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
1040                                (anNewFeature->attribute(SketchPlugin_Arc::START_ID())));
1041
1042     std::string aModifiedAttribute = SketchPlugin_Arc::END_ID();
1043     theModifiedAttributes.insert(
1044       std::make_pair(aBaseFeature->attribute(aModifiedAttribute),
1045                                    anNewFeature->attribute(SketchPlugin_Arc::END_ID())));
1046
1047     // modify base arc
1048     fillPointAttribute(aBaseFeature->attribute(aModifiedAttribute), aStartShapePoint);
1049
1050     thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
1051                                (aBaseFeature->attribute(aModifiedAttribute)));
1052
1053     // equal Radius constraint for arcs
1054     SketchPlugin_Tools::createConstraintObjectObject(sketch(),
1055                                          SketchPlugin_ConstraintEqual::ID(),
1056                                          getFeatureResult(aBaseFeature),
1057                                          getFeatureResult(anNewFeature));
1058     // coincident centers constraint
1059     SketchPlugin_Tools::createConstraintAttrAttr(sketch(),
1060                                          SketchPlugin_ConstraintCoincidence::ID(),
1061                                          aBaseFeature->attribute(SketchPlugin_Arc::CENTER_ID()),
1062                                          anNewFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
1063
1064 #ifdef DEBUG_TRIM
1065     std::cout << "Created arc on points:" << std::endl;
1066     std::cout << "Start shape point: [" << aStartShapePoint->x() << ", " <<
1067                                            aStartShapePoint->y() << "]" << std::endl;
1068 #endif
1069   }
1070   return anNewFeature;
1071 }
1072
1073 FeaturePtr SketchPlugin_Trim::trimCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
1074                                    const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
1075                                    std::set<AttributePoint2DPtr>& thePoints,
1076                  std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes)
1077 {
1078   // Check the base objects are initialized.
1079   AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
1080                                         data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
1081   ObjectPtr aBaseObject = aBaseObjectAttr->value();
1082   FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
1083
1084   /// points of trim
1085   //AttributePoint2DPtr aStartPointAttrOfBase, anEndPointAttrOfBase;
1086   //getFeaturePoints(aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase);
1087
1088   /// trim feature
1089   FeaturePtr anNewFeature = createArcFeature(aBaseFeature, theStartShapePoint, theLastShapePoint);
1090   // arc created by trim of circle is always correct, that means that it is not inversed
1091   anNewFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue(false);
1092
1093   theModifiedAttributes.insert(
1094     std::make_pair(aBaseFeature->attribute(SketchPlugin_Circle::CENTER_ID()),
1095                    anNewFeature->attribute(SketchPlugin_Arc::CENTER_ID())));
1096
1097   thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
1098                              (anNewFeature->attribute(SketchPlugin_Arc::START_ID())));
1099   thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
1100                              (anNewFeature->attribute(SketchPlugin_Arc::END_ID())));
1101
1102   return anNewFeature;
1103 }
1104
1105 void SketchPlugin_Trim::arrangePointsOnLine(const AttributePoint2DPtr& theStartPointAttr,
1106                                             const AttributePoint2DPtr& theEndPointAttr,
1107                                             std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
1108                                             std::shared_ptr<GeomAPI_Pnt2d>& theLastPoint) const
1109 {
1110   if (!theFirstPoint.get() || !theLastPoint.get())
1111     return;
1112
1113   // if first point is closer to last point, swap first and last values
1114   if (theStartPointAttr->pnt()->distance(theFirstPoint) >
1115       theStartPointAttr->pnt()->distance(theLastPoint)) {
1116     std::shared_ptr<GeomAPI_Pnt2d> aTmpPoint = theFirstPoint;
1117     theFirstPoint = theLastPoint;
1118     theLastPoint = aTmpPoint;
1119   }
1120 }
1121
1122 void SketchPlugin_Trim::arrangePointsOnArc(const FeaturePtr& theArc,
1123                                   const AttributePoint2DPtr& theStartPointAttr,
1124                                   const AttributePoint2DPtr& theEndPointAttr,
1125                                   std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
1126                                   std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint) const
1127 {
1128   if (!theFirstPoint.get() || !theSecondPoint.get())
1129     return;
1130
1131   static const double anAngleTol = 1.e-12;
1132
1133   std::shared_ptr<GeomAPI_Pnt2d> aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1134       theArc->attribute(SketchPlugin_Arc::CENTER_ID()))->pnt();
1135   bool isReversed = theArc->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
1136
1137   // collect directions to each point
1138   std::shared_ptr<GeomAPI_Dir2d> aStartDir(
1139       new GeomAPI_Dir2d(theStartPointAttr->pnt()->xy()->decreased(aCenter->xy())));
1140   std::shared_ptr<GeomAPI_Dir2d> aFirstPtDir(
1141       new GeomAPI_Dir2d(theFirstPoint->xy()->decreased(aCenter->xy())));
1142   std::shared_ptr<GeomAPI_Dir2d> aSecondPtDir(
1143       new GeomAPI_Dir2d(theSecondPoint->xy()->decreased(aCenter->xy())));
1144
1145   // sort points by their angular values
1146   double aFirstPtAngle = aStartDir->angle(aFirstPtDir);
1147   double aSecondPtAngle = aStartDir->angle(aSecondPtDir);
1148   double aPeriod = isReversed ? -2.0 * PI : 2.0 * PI;
1149   if (fabs(aFirstPtAngle) > anAngleTol && isReversed == (aFirstPtAngle > 0.))
1150     aFirstPtAngle += aPeriod;
1151   if (fabs(aSecondPtAngle) > anAngleTol && isReversed == (aSecondPtAngle > 0.))
1152     aSecondPtAngle += aPeriod;
1153
1154   if (fabs(aFirstPtAngle) > fabs(aSecondPtAngle)) {
1155     std::shared_ptr<GeomAPI_Pnt2d> aTmpPoint = theFirstPoint;
1156     theFirstPoint = theSecondPoint;
1157     theSecondPoint = aTmpPoint;
1158   }
1159 }
1160
1161 void SketchPlugin_Trim::fillPointAttribute(const AttributePtr& theModifiedAttribute,
1162                                            const std::shared_ptr<GeomAPI_Pnt2d>& thePoint)
1163 {
1164   std::string anAttributeType = theModifiedAttribute->attributeType();
1165   if (anAttributeType == GeomDataAPI_Point2D::typeId()) {
1166     AttributePoint2DPtr aModifiedAttribute = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1167                                               theModifiedAttribute);
1168     aModifiedAttribute->setValue(thePoint);
1169
1170 #ifdef DEBUG_TRIM
1171     FeaturePtr aFeature = ModelAPI_Feature::feature(theModifiedAttribute->owner());
1172     std::cout << "<fillPointAttribute[" << aFeature->data()->name() << ": " <<
1173       theModifiedAttribute->id() <<
1174       "]> => Pnt2d - [" << thePoint->x() << ", " << thePoint->y() << "]" << std::endl;
1175 #endif
1176   }
1177 }
1178
1179
1180 void SketchPlugin_Trim::fillAttribute(const AttributePtr& theModifiedAttribute,
1181                                       const AttributePtr& theSourceAttribute)
1182 {
1183   std::string anAttributeType = theModifiedAttribute->attributeType();
1184   if (anAttributeType == GeomDataAPI_Point2D::typeId()) {
1185     AttributePoint2DPtr aModifiedAttribute = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1186                                               theModifiedAttribute);
1187     AttributePoint2DPtr aSourceAttribute = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
1188                                               theSourceAttribute);
1189
1190     if (aModifiedAttribute.get() && aSourceAttribute.get())
1191       aModifiedAttribute->setValue(aSourceAttribute->pnt());
1192   }
1193   else if (anAttributeType == ModelAPI_AttributeBoolean::typeId()) {
1194     AttributeBooleanPtr aModifiedAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(
1195                                               theModifiedAttribute);
1196     AttributeBooleanPtr aSourceAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(
1197                                               theSourceAttribute);
1198
1199     if (aModifiedAttribute.get() && aSourceAttribute.get())
1200       aModifiedAttribute->setValue(aSourceAttribute->value());
1201   }
1202 }
1203
1204 FeaturePtr SketchPlugin_Trim::createLineFeature(const FeaturePtr& theBaseFeature,
1205                                         const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
1206                                         const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint)
1207 {
1208 #ifdef DEBUG_TRIM
1209   std::cout << "---- createLineFeature ---" << std::endl;
1210 #endif
1211
1212   FeaturePtr aFeature;
1213   SketchPlugin_Sketch* aSketch = sketch();
1214   if (!aSketch || !theBaseFeature.get())
1215     return aFeature;
1216
1217   aFeature = aSketch->addFeature(SketchPlugin_Line::ID());
1218
1219   fillPointAttribute(aFeature->attribute(SketchPlugin_Line::START_ID()), theFirstPoint);
1220   fillPointAttribute(aFeature->attribute(SketchPlugin_Line::END_ID()), theSecondPoint);
1221
1222   fillAttribute(aFeature->attribute(SketchPlugin_SketchEntity::AUXILIARY_ID()),
1223                 theBaseFeature->attribute(SketchPlugin_SketchEntity::AUXILIARY_ID()));
1224
1225   aFeature->execute(); // to obtain result
1226
1227 #ifdef DEBUG_TRIM
1228   std::cout << "---- createLineFeature:end ---" << std::endl;
1229 #endif
1230
1231   return aFeature;
1232 }
1233
1234 FeaturePtr SketchPlugin_Trim::createArcFeature(const FeaturePtr& theBaseFeature,
1235                                                const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
1236                                                const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint)
1237 {
1238   FeaturePtr aFeature;
1239   SketchPlugin_Sketch* aSketch = sketch();
1240   if (!aSketch || !theBaseFeature.get())
1241     return aFeature;
1242
1243   std::string aCenterAttributeId;
1244   if (theBaseFeature->getKind() == SketchPlugin_Arc::ID())
1245     aCenterAttributeId = SketchPlugin_Arc::CENTER_ID();
1246   else if (theBaseFeature->getKind() == SketchPlugin_Circle::ID())
1247     aCenterAttributeId = SketchPlugin_Circle::CENTER_ID();
1248
1249   if (aCenterAttributeId.empty())
1250     return aFeature;
1251
1252 #ifdef DEBUG_TRIM
1253   std::cout << "---- createArcFeature ---" << std::endl;
1254 #endif
1255
1256   aFeature = aSketch->addFeature(SketchPlugin_Arc::ID());
1257   // update fillet arc: make the arc correct for sure, so, it is not needed to process
1258   // the "attribute updated"
1259   // by arc; moreover, it may cause cyclicity in hte mechanism of updater
1260   bool aWasBlocked = aFeature->data()->blockSendAttributeUpdated(true);
1261
1262   fillAttribute(aFeature->attribute(SketchPlugin_Arc::CENTER_ID()),
1263                 theBaseFeature->attribute(aCenterAttributeId));
1264   fillPointAttribute(aFeature->attribute(SketchPlugin_Arc::START_ID()), theFirstPoint);
1265   fillPointAttribute(aFeature->attribute(SketchPlugin_Arc::END_ID()), theSecondPoint);
1266
1267   fillAttribute(aFeature->attribute(SketchPlugin_SketchEntity::AUXILIARY_ID()),
1268                 theBaseFeature->attribute(SketchPlugin_SketchEntity::AUXILIARY_ID()));
1269
1270   /// fill referersed state of created arc as it is on the base arc
1271   if (theBaseFeature->getKind() == SketchPlugin_Arc::ID()) {
1272     bool aReversed = theBaseFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
1273     aFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue(aReversed);
1274   }
1275   aFeature->execute(); // to obtain result (need to calculate arc parameters before sending Update)
1276   aFeature->data()->blockSendAttributeUpdated(aWasBlocked);
1277
1278   #ifdef DEBUG_TRIM
1279   std::cout << "---- createArcFeature:end ---" << std::endl;
1280   #endif
1281
1282   return aFeature;
1283 }
1284
1285 std::shared_ptr<ModelAPI_Result> SketchPlugin_Trim::getFeatureResult(
1286                                     const std::shared_ptr<ModelAPI_Feature>& theFeature)
1287 {
1288   std::shared_ptr<ModelAPI_Result> aResult;
1289
1290   std::string aFeatureKind = theFeature->getKind();
1291   if (aFeatureKind == SketchPlugin_Line::ID())
1292     aResult = theFeature->firstResult();
1293   else if (aFeatureKind == SketchPlugin_Arc::ID())
1294     aResult = theFeature->lastResult();
1295   else if (aFeatureKind == SketchPlugin_Circle::ID())
1296     aResult = theFeature->lastResult();
1297
1298   return aResult;
1299 }
1300
1301 //********************************************************************
1302 void SketchPlugin_Trim::fillObjectShapes(const ObjectPtr& theObject,
1303                 const ObjectPtr& theSketch,
1304                 std::map<ObjectPtr, std::set<GeomShapePtr> >& theCashedShapes,
1305                 std::map<ObjectPtr, PointToRefsMap>& theObjectToPoints)
1306 {
1307   PointToRefsMap aPointsInfo;
1308
1309   std::set<std::shared_ptr<GeomAPI_Shape> > aShapes;
1310   std::map<std::shared_ptr<GeomAPI_Pnt>,
1311                            std::list< AttributePoint2DPtr > > aPointToAttributes;
1312   std::map<std::shared_ptr<GeomAPI_Pnt>,
1313                            std::list< ObjectPtr > > aPointToObjects;
1314
1315   std::set<AttributePoint2DPtr > aRefAttributes;
1316   // current feature
1317   FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1318   std::set<ResultPtr> anEdgeShapes;
1319   // edges on feature
1320   ModelGeomAlgo_Shape::shapesOfType(aFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
1321   if (!anEdgeShapes.empty()) {
1322     GeomShapePtr aFeatureShape = (*anEdgeShapes.begin())->shape();
1323
1324     // coincidences to the feature
1325     ModelGeomAlgo_Point2D::getPointsOfReference(aFeature, SketchPlugin_ConstraintCoincidence::ID(),
1326                          aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
1327     // layed on feature coincidences to divide it on several shapes
1328     std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
1329     std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
1330         aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
1331     std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1332         aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
1333     std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
1334         aData->attribute(SketchPlugin_Sketch::NORM_ID()));
1335     std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
1336
1337     ModelGeomAlgo_Point2D::getPointsInsideShape(aFeatureShape, aRefAttributes, aC->pnt(),
1338                                                 aX->dir(), aY, aPointsInfo);
1339
1340     std::list<FeaturePtr> aFeatures;
1341     CompositeFeaturePtr aSketchComposite =
1342                          std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theSketch);
1343     for (int i = 0; i < aSketchComposite->numberOfSubs(); i++) {
1344       FeaturePtr aFeature = aSketchComposite->subFeature(i);
1345       if (aFeature.get() && aFeature->getKind() != SketchPlugin_Projection::ID())
1346         aFeatures.push_back(aFeature);
1347     }
1348     ModelGeomAlgo_Point2D::getPointsIntersectedShape(aFeature, aFeatures, aPointsInfo);
1349
1350     GeomAlgoAPI_ShapeTools::splitShape(aFeatureShape, aPointsInfo, aShapes);
1351   }
1352   theObjectToPoints[theObject] = aPointsInfo;
1353   theCashedShapes[theObject] = aShapes;
1354 }