]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_ResultConstruction.cpp
Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / Model / Model_ResultConstruction.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_ResultConstruction.cpp
4 // Created:     07 Jul 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include <Model_ResultConstruction.h>
8
9 #include <Model_Data.h>
10 #include <ModelAPI_CompositeFeature.h>
11 #include <Model_SelectionNaming.h>
12 #include <Config_PropManager.h>
13 #include <GeomAPI_PlanarEdges.h>
14 #include <GeomAPI_Shape.h>
15 #include <GeomAlgoAPI_SketchBuilder.h>
16 #include <Events_Loop.h>
17 #include <ModelAPI_Events.h>
18
19 #include <TDF_ChildIterator.hxx>
20 #include <TNaming_NamedShape.hxx>
21 #include <TNaming_Builder.hxx>
22 #include <TopoDS_Shape.hxx>
23 #include <TDataStd_Integer.hxx>
24 #include <TDataStd_IntPackedMap.hxx>
25 #include <TDataStd_Name.hxx>
26 #include <TColStd_MapOfTransient.hxx>
27 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
28 #include <BRep_Tool.hxx>
29 #include <BRep_Builder.hxx>
30 #include <TopoDS.hxx>
31 #include <TopoDS_Edge.hxx>
32 #include <TopoDS_Vertex.hxx>
33 #include <TopExp_Explorer.hxx>
34 #include <Precision.hxx>
35
36
37 void Model_ResultConstruction::colorConfigInfo(std::string& theSection, std::string& theName,
38                                        std::string& theDefault)
39 {
40   theSection = "Visualization";
41   theName = "result_construction_color";
42   theDefault = DEFAULT_COLOR();
43 }
44
45 void Model_ResultConstruction::setShape(std::shared_ptr<GeomAPI_Shape> theShape)
46 {
47   if (myShape != theShape && (!theShape.get() || !theShape->isEqual(myShape))) {
48     static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
49     ModelAPI_EventCreator::get()->sendUpdated(data()->owner(), anEvent);
50     myShape = theShape;
51     if (theShape.get()) {
52       myFacesUpToDate = false;
53       myFaces.clear();
54     }
55   }
56 }
57
58 std::shared_ptr<GeomAPI_Shape> Model_ResultConstruction::shape()
59 {
60   return myShape;
61 }
62
63 Model_ResultConstruction::Model_ResultConstruction()
64 {
65   myIsInHistory = true;
66   myIsInfinite = false;
67   myFacesUpToDate = false;
68 }
69
70 void Model_ResultConstruction::setIsInHistory(const bool isInHistory)
71 {
72   myIsInHistory = isInHistory;
73 }
74
75 int Model_ResultConstruction::facesNum()
76 {
77   if (!myFacesUpToDate) {
78     std::shared_ptr<GeomAPI_PlanarEdges> aWirePtr =
79       std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(myShape);
80     if (aWirePtr.get()) {
81       std::list<std::shared_ptr<GeomAPI_Shape> > aFaces;
82       GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
83         aWirePtr->norm(), aWirePtr, aFaces);
84       std::list<std::shared_ptr<GeomAPI_Shape> >::iterator aFIter = aFaces.begin();
85       for(; aFIter != aFaces.end(); aFIter++) {
86         std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(*aFIter));
87         if (aFace.get() && !aFace->isNull())
88           myFaces.push_back(aFace);
89       }
90     }
91     myFacesUpToDate = true;
92   }
93   return int(myFaces.size());
94 }
95
96 std::shared_ptr<GeomAPI_Face> Model_ResultConstruction::face(const int theIndex)
97 {
98   return myFaces[theIndex];
99 }
100
101 bool Model_ResultConstruction::isInfinite()
102 {
103   return myIsInfinite;
104 }
105
106 void Model_ResultConstruction::setInfinite(const bool theInfinite)
107 {
108   myIsInfinite = theInfinite;
109 }
110
111 void Model_ResultConstruction::setIsConcealed(const bool theValue)
112 {
113   // do nothing: the construction element is never consealed
114 }
115
116 static const int kSTART_VERTEX_DELTA = 1000000;
117
118 static void registerSubShape(TDF_Label theMainLabel, TopoDS_Shape theShape,
119   const int theID, std::shared_ptr<Model_Document> theDoc,
120   std::map<int, int>& theOrientations,
121   // name of sub-elements by ID to be exported instead of indexes
122   std::map<int, std::string>& theSubNames,
123   Handle(TDataStd_IntPackedMap) theRefs = Handle(TDataStd_IntPackedMap)(),
124   const int theOrientation = 0)
125 {
126   TDF_Label aLab = theID == 0 ? theMainLabel : theMainLabel.FindChild(theID);
127   if (theOrientation != 0) { // store the orientation of edge relatively to face if needed
128     TDataStd_Integer::Set(aLab, theOrientation);
129   }
130   TNaming_Builder aBuilder(aLab);
131   aBuilder.Generated(theShape);
132   std::stringstream aName;
133   // #1839 : do not store name of the feature in the tree, since this name could be changed
134   //aName<<theContextFeature->name();
135   if (theShape.ShapeType() != TopAbs_COMPOUND) { // compound means the whole result for construction
136     //aName<<"/";
137     if (theShape.ShapeType() == TopAbs_FACE) aName<<"Face";
138     else if (theShape.ShapeType() == TopAbs_WIRE) aName<<"Wire";
139     else if (theShape.ShapeType() == TopAbs_EDGE) aName<<"Edge";
140     else if (theShape.ShapeType() == TopAbs_VERTEX) aName<<"Vertex";
141
142     if (theRefs.IsNull()) {
143       aName<<theID;
144       if (theOrientation == 1)
145         aName<<"f";
146       else if (theOrientation == -1)
147         aName<<"r";
148     } else { // make a composite name from all sub-elements indexes: "1_2_3_4"
149       TColStd_MapIteratorOfPackedMapOfInteger aRef(theRefs->GetMap());
150       for(; aRef.More(); aRef.Next()) {
151         aName<<"-"<<theSubNames[aRef.Key()];
152         if (theOrientations.find(aRef.Key()) != theOrientations.end()) {
153           if (theOrientations[aRef.Key()] == 1)
154             aName<<"f";
155           else if (theOrientations[aRef.Key()] == -1)
156             aName<<"r";
157         }
158       }
159     }
160   }
161
162   theDoc->addNamingName(aLab, aName.str());
163   TDataStd_Name::Set(aLab, aName.str().c_str());
164 }
165
166 TDF_Label Model_ResultConstruction::startLabel(
167   const std::shared_ptr<ModelAPI_Document> theExtDoc, bool& theExternal)
168 {
169   theExternal = theExtDoc.get() && theExtDoc != document();
170   if (theExternal) { // external document is used
171     std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(theExtDoc);
172     return aDoc->extConstructionsLabel();
173   }
174   std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
175   return aData->label();
176 }
177
178 int Model_ResultConstruction::select(const std::shared_ptr<GeomAPI_Shape>& theSubShape,
179   const std::shared_ptr<ModelAPI_Document> theExtDoc, const int theIndex)
180 {
181   int anIndex; // resulting index of the sub-label
182   TopoDS_Shape aSubShape;
183   if (theSubShape.get()) {
184     aSubShape = theSubShape->impl<TopoDS_Shape>();
185   } else if (shape().get()) {
186     aSubShape = shape()->impl<TopoDS_Shape>();
187   }
188   // if external document requires this selection, put the naming structures to this doc
189   // to support the naming mechanism in this document correctly
190   bool anExternal;
191   TDF_Label aDataLab = startLabel(theExtDoc, anExternal);
192   if (theIndex == -1) {
193     anIndex = anExternal ? 2 : 1; // for the external doc don't mind about the main shape
194
195     if (theSubShape.get() || anExternal) { // searching for already selected sub (or whole for ext)
196       // iterate all the already presented shapes to see the same
197       TDF_ChildIterator aSubsIter(aDataLab, Standard_False);
198       for(; aSubsIter.More(); aSubsIter.Next()) {
199         const TDF_Label aLab = aSubsIter.Value();
200         if (aLab.Tag() == 1) // skip the root shape label
201           continue;
202         Handle(TNaming_NamedShape) aNS;
203         if (aLab.FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
204           if (aNS->Get().IsSame(aSubShape)) {
205             return aLab.Tag() - 1; // found exactly the needed shape, nothing else to do
206           }
207         }
208         anIndex = aLab.Tag(); // searching for the latest index
209       }
210       anIndex = (anIndex == 1) ? 2 : (anIndex + 1); // next after 1-root, or next after all
211     }
212   } else {
213     anIndex = theIndex + 1;
214   }
215
216   // set the naming structure at index
217   TDF_Label aLab = aDataLab.FindChild(anIndex, Standard_True);
218   TNaming_Builder aBuilder(aLab);
219   if (aSubShape.IsNull())
220     return anIndex - 1; // just keep empty named shape
221   aBuilder.Generated(aSubShape);
222
223   if (anIndex == 1 && isInfinite()) { // infinitive results has no sub-selection
224     return anIndex - 1;
225   }
226   ResultPtr aThisPtr = std::dynamic_pointer_cast<ModelAPI_Result>(data()->owner());
227   FeaturePtr aThisFeature = document()->feature(aThisPtr);
228   CompositeFeaturePtr aComposite =
229     std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aThisFeature);
230   if (!aComposite || aComposite->numberOfSubs() == 0) {
231     // saving of context is enough: result construction contains exactly the needed shape
232     return anIndex - 1;
233   }
234   // identify the results of sub-object of the composite by edges
235   // save type of the selected shape in integer attribute
236   TopAbs_ShapeEnum aShapeType = aSubShape.ShapeType();
237   TDataStd_Integer::Set(aLab, (int)aShapeType);
238   gp_Pnt aVertexPos;
239   TColStd_MapOfTransient allCurves;
240   if (aShapeType == TopAbs_VERTEX) { // compare positions
241     aVertexPos = BRep_Tool::Pnt(TopoDS::Vertex(aSubShape));
242   } else {
243     for(TopExp_Explorer anEdgeExp(aSubShape, TopAbs_EDGE); anEdgeExp.More(); anEdgeExp.Next()) {
244       TopoDS_Edge anEdge = TopoDS::Edge(anEdgeExp.Current());
245       Standard_Real aFirst, aLast;
246       Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
247       allCurves.Add(aCurve);
248     }
249   }
250   std::shared_ptr<Model_Document> aMyDoc =
251     std::dynamic_pointer_cast<Model_Document>(document());
252   // iterate and store the result ids of sub-elements and sub-elements to sub-labels
253   Handle(TDataStd_IntPackedMap) aRefs = TDataStd_IntPackedMap::Set(aLab);
254   std::map<int, int> anOrientations; //map from edges IDs to orientations of these edges in face
255   std::map<int, std::string> aSubNames; //map from edges IDs to names of edges
256   aRefs->Clear();
257   const int aSubNum = aComposite->numberOfSubs();
258   for(int a = 0; a < aSubNum; a++) {
259     FeaturePtr aSub = aComposite->subFeature(a);
260     const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aSub->results();
261     std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResults.cbegin();
262     // there may be many shapes (circle and center): register if at least one is in selection
263     for(; aRes != aResults.cend(); aRes++) {
264       ResultConstructionPtr aConstr =
265         std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aRes);
266       if (!aConstr->shape()) {
267         continue;
268       }
269       if (aShapeType == TopAbs_VERTEX) {
270         if (aConstr->shape()->isVertex()) { // compare vertices positions
271           const TopoDS_Shape& aVertex = aConstr->shape()->impl<TopoDS_Shape>();
272           gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aVertex));
273           if (aPnt.IsEqual(aVertexPos, Precision::Confusion())) {
274             aRefs->Add(aComposite->subFeatureId(a));
275             aSubNames[aComposite->subFeatureId(a)] = Model_SelectionNaming::shortName(aConstr);
276           }
277         } else { // get first or last vertex of the edge: last is stored with additional delta
278           const TopoDS_Shape& anEdge = aConstr->shape()->impl<TopoDS_Shape>();
279           int aDelta = kSTART_VERTEX_DELTA;
280           for(TopExp_Explorer aVExp(anEdge, TopAbs_VERTEX); aVExp.More(); aVExp.Next()) {
281             gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aVExp.Current()));
282             if (aPnt.IsEqual(aVertexPos, Precision::Confusion())) {
283               aRefs->Add(aDelta + aComposite->subFeatureId(a));
284               aSubNames[aDelta + aComposite->subFeatureId(a)] =
285                 Model_SelectionNaming::shortName(aConstr, aDelta / kSTART_VERTEX_DELTA);
286               break;
287             }
288             aDelta += kSTART_VERTEX_DELTA;
289           }
290         }
291       } else {
292         if (aConstr->shape()->isEdge()) {
293           const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
294           TopoDS_Edge anEdge = TopoDS::Edge(aResShape);
295           if (!anEdge.IsNull()) {
296             Standard_Real aFirst, aLast;
297             Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
298             if (allCurves.Contains(aCurve)) {
299               int anID = aComposite->subFeatureId(a);
300               aRefs->Add(anID);
301               aSubNames[anID] = Model_SelectionNaming::shortName(aConstr);
302               if (aShapeType != TopAbs_EDGE) { // face needs the sub-edges on sub-labels
303                 // add edges to sub-label to support naming for edges selection
304                 TopExp_Explorer anEdgeExp(aSubShape, TopAbs_EDGE);
305                 for(; anEdgeExp.More(); anEdgeExp.Next()) {
306                   TopoDS_Edge anEdge = TopoDS::Edge(anEdgeExp.Current());
307                   Standard_Real aFirst, aLast;
308                   Handle(Geom_Curve) aFaceCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
309                   if (aFaceCurve == aCurve) {
310                     int anOrient = Model_SelectionNaming::edgeOrientation(aSubShape, anEdge);
311                     anOrientations[anID] = anOrient;
312
313                     TDF_Label aSubLab = aLab.FindChild(anID);
314                     std::string aName = "Edge-" + Model_SelectionNaming::shortName(aConstr, 0);
315                     TNaming_Builder aBuilder(aSubLab);
316                     aBuilder.Generated(anEdge);
317                     aMyDoc->addNamingName(aSubLab, aName.c_str());
318                     TDataStd_Name::Set(aSubLab, aName.c_str());
319
320                     if (anOrient != 0) {
321                       // store the orientation of edge relatively to face if needed
322                       TDataStd_Integer::Set(aSubLab, anOrient);
323                     }
324                   }
325                 }
326               } else { // put vertices of the selected edge to sub-labels
327                 // add edges to sub-label to support naming for edges selection
328                 int aDelta = kSTART_VERTEX_DELTA;
329                 int aTagIndex = anID + kSTART_VERTEX_DELTA;
330                 for(TopExp_Explorer anEdgeExp(aSubShape, TopAbs_VERTEX);
331                     anEdgeExp.More();
332                     anEdgeExp.Next(),
333                     aTagIndex += kSTART_VERTEX_DELTA,
334                     aDelta += kSTART_VERTEX_DELTA) {
335                   TopoDS_Vertex aV = TopoDS::Vertex(anEdgeExp.Current());
336
337                   TDF_Label aSubLab = aLab.FindChild(aTagIndex);
338                   std::string aName = "Vertex-"
339                       + Model_SelectionNaming::shortName(aConstr, aDelta / kSTART_VERTEX_DELTA);
340                   TNaming_Builder aBuilder(aLab);
341                   aBuilder.Generated(aV);
342                   aMyDoc->addNamingName(aLab, aName.c_str());
343                   TDataStd_Name::Set(aLab, aName.c_str());
344                 }
345               }
346             }
347           }
348         }
349       }
350     }
351   }
352   // store the selected as primitive
353   registerSubShape(aLab, aSubShape, 0, aMyDoc, anOrientations, aSubNames, aRefs);
354
355   return anIndex - 1;
356 }
357
358 std::shared_ptr<GeomAPI_Shape> Model_ResultConstruction::shape(const int theIndex,
359   const std::shared_ptr<ModelAPI_Document> theExtDoc)
360 {
361   std::shared_ptr<GeomAPI_Shape> aResult;
362   if (theIndex == 0)
363     return aResult; // the whole shape, so, NULL
364
365   bool isExt;
366   TDF_Label aLab = startLabel(theExtDoc, isExt).FindChild(theIndex + 1);
367   if (!aLab.IsNull()) { // index is not bad
368     Handle(TNaming_NamedShape) aSelection;
369     if (aLab.FindAttribute(TNaming_NamedShape::GetID(), aSelection)) {
370       TopoDS_Shape aSelShape = aSelection->Get();
371       aResult = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
372       aResult->setImpl(new TopoDS_Shape(aSelShape));
373     }
374   }
375
376   return aResult;
377 }
378
379 bool Model_ResultConstruction::update(const int theIndex,
380   const std::shared_ptr<ModelAPI_Document> theExtDoc, bool& theModified)
381 {
382   theModified = false;
383   bool anExt;
384   TDF_Label aLab = startLabel(theExtDoc, anExt).FindChild(theIndex + 1, Standard_True);
385   if (theIndex == 0) {
386     // it is just reference to construction, not sub-shape
387     // if there is a sketch, the sketch-naming must be updated
388     if (!isInfinite()) {
389       BRep_Builder aCompoundBuilder;
390       TopoDS_Compound aComp;
391       aCompoundBuilder.MakeCompound(aComp);
392       for(int a = 0; a < facesNum(); a++) {
393         TopoDS_Shape aFace = face(a)->impl<TopoDS_Shape>();
394         aCompoundBuilder.Add(aComp, aFace);
395       }
396       std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
397       aShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aComp));
398       select(aShape, theExtDoc, theIndex);
399     } else {
400       // For correct naming selection, put the shape into the naming structure.
401       // It seems sub-shapes are not needed: only this shape is (and can be ) selected.
402       TNaming_Builder aBuilder(aLab);
403       aBuilder.Generated(shape()->impl<TopoDS_Shape>());
404     }
405     return shape() && !shape()->isNull();
406   }
407   // construction: identification by the results indexes, recompute faces and
408   // take the face that more close by the indexes
409   ResultPtr aThisPtr = std::dynamic_pointer_cast<ModelAPI_Result>(data()->owner());
410   FeaturePtr aContextFeature = document()->feature(aThisPtr);
411   // sketch sub-element
412   if (std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature).get())
413   {
414     // getting a type of selected shape
415     Handle(TDataStd_Integer) aTypeAttr;
416     if (!aLab.FindAttribute(TDataStd_Integer::GetID(), aTypeAttr)) {
417       return false;
418     }
419     TopAbs_ShapeEnum aShapeType = (TopAbs_ShapeEnum)(aTypeAttr->Get());
420     // selected indexes will be needed in each "if"
421     Handle(TDataStd_IntPackedMap) aSubIds;
422     std::shared_ptr<GeomAPI_Shape> aNewSelected;
423     bool aNoIndexes =
424       !aLab.FindAttribute(TDataStd_IntPackedMap::GetID(), aSubIds) || aSubIds->Extent() == 0;
425     // for now working only with composite features
426     CompositeFeaturePtr aComposite =
427       std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aContextFeature);
428     if (!aComposite.get() || aComposite->numberOfSubs() == 0) {
429       return false;
430     }
431
432     if (aShapeType == TopAbs_FACE || aShapeType == TopAbs_WIRE) {
433       // compound is for the whole sketch selection
434       // If this is a wire with plane defined then it is a sketch-like object
435       if (!facesNum()) // no faces, update can not work correctly
436         return false;
437       // if there is no edges indexes, any face can be used: take the first
438       std::shared_ptr<GeomAPI_Shape> aNewSelected;
439       if (aNoIndexes) {
440         aNewSelected = face(0);
441       } else { // searching for most looks-like initial face by the indexes
442         // prepare edges of the current result for the fast searching
443         // curves and orientations of edges
444         NCollection_DataMap<Handle(Geom_Curve), int> allCurves;
445         const int aSubNum = aComposite->numberOfSubs();
446         for(int a = 0; a < aSubNum; a++) {
447           int aSubID = aComposite->subFeatureId(a);
448           if (aSubIds->Contains(aSubID)) {
449             FeaturePtr aSub = aComposite->subFeature(a);
450             const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aSub->results();
451             std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRes;
452             for(aRes = aResults.cbegin(); aRes != aResults.cend(); aRes++) {
453               ResultConstructionPtr aConstr =
454                 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aRes);
455               if (aConstr->shape() && aConstr->shape()->isEdge()) {
456                 const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
457                 TopoDS_Edge anEdge = TopoDS::Edge(aResShape);
458                 if (!anEdge.IsNull()) {
459                   Standard_Real aFirst, aLast;
460                   Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirst, aLast);
461                   // searching for orientation information
462                   int anOrient = 0;
463                   Handle(TDataStd_Integer) anInt;
464                   if (aLab.FindChild(aSubID).FindAttribute(TDataStd_Integer::GetID(), anInt)) {
465                     anOrient = anInt->Get();
466                   }
467                   allCurves.Bind(aCurve, anOrient);
468                 }
469               }
470             }
471           }
472         }
473         aNewSelected = Model_SelectionNaming::findAppropriateFace(
474           aThisPtr, allCurves, aShapeType == TopAbs_WIRE);
475       }
476       if (aNewSelected) { // store this new selection
477         select(aNewSelected, theExtDoc, theIndex);
478         theModified = true;
479         return true;
480       } else {
481         // if the selection is not found, put the empty shape:
482         // it's better to have disappeared shape, than the old, the lost one
483         TNaming_Builder anEmptyBuilder(aLab);
484         return false;
485       }
486     } else if (aShapeType == TopAbs_EDGE) {
487       // just reselect the edge by the id
488       const int aSubNum = aComposite->numberOfSubs();
489       for(int a = 0; a < aSubNum; a++) {
490         // if aSubIds take any, the first appropriate
491         if (aSubIds->IsEmpty() || aSubIds->Contains(aComposite->subFeatureId(a))) {
492           // found the appropriate feature
493           FeaturePtr aFeature = aComposite->subFeature(a);
494           std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aResIter =
495             aFeature->results().cbegin();
496           for(;aResIter != aFeature->results().cend(); aResIter++) {
497             ResultConstructionPtr aRes =
498               std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aResIter);
499             if (aRes && aRes->shape() && aRes->shape()->isEdge()) { // found!
500               select(aRes->shape(), theExtDoc, theIndex);
501               theModified = true;
502               return true;
503             }
504           }
505         }
506       }
507     } else if (aShapeType == TopAbs_VERTEX) {
508       // just reselect the vertex by the id of edge
509       const int aSubNum = aComposite->numberOfSubs();
510       for(int a = 0; a < aSubNum; a++) {
511         // if aSubIds take any, the first appropriate
512         int aFeatureID = aComposite->subFeatureId(a);
513         if (aSubIds->IsEmpty() || aSubIds->Contains(aFeatureID) ||
514           aSubIds->Contains(aFeatureID + kSTART_VERTEX_DELTA) ||
515           aSubIds->Contains(aFeatureID + kSTART_VERTEX_DELTA * 2)) {
516             // searching for deltas
517             int aVertexNum = 0;
518             if (aSubIds->Contains(aFeatureID + kSTART_VERTEX_DELTA)) aVertexNum = 1;
519             else if (aSubIds->Contains(aFeatureID + kSTART_VERTEX_DELTA * 2)) aVertexNum = 2;
520             // found the feature with appropriate edge
521             FeaturePtr aFeature = aComposite->subFeature(a);
522             std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aResIter =
523               aFeature->results().cbegin();
524             for(;aResIter != aFeature->results().cend(); aResIter++) {
525               ResultConstructionPtr aRes =
526                 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aResIter);
527               if (aRes && aRes->shape()) {
528                 if (aRes->shape()->isVertex() && aVertexNum == 0) { // found!
529                   select(aRes->shape(), theExtDoc, theIndex);
530                   theModified = true;
531                   return true;
532                 } else if (aRes->shape()->isEdge() && aVertexNum > 0) {
533                   const TopoDS_Shape& anEdge = aRes->shape()->impl<TopoDS_Shape>();
534                   int aVIndex = 1;
535                   for(TopExp_Explorer aVExp(anEdge, TopAbs_VERTEX); aVExp.More(); aVExp.Next()) {
536                     if (aVIndex == aVertexNum) { // found!
537                       std::shared_ptr<GeomAPI_Shape> aVertex(new GeomAPI_Shape);
538                       aVertex->setImpl(new TopoDS_Shape(aVExp.Current()));
539                       select(aVertex, theExtDoc, theIndex);
540                       theModified = true;
541                       return true;
542                     }
543                     aVIndex++;
544                   }
545                 }
546               }
547             }
548         }
549       }
550     }
551   } else { // simple construction element: the selected is that needed
552     select(shape(), theExtDoc, theIndex);
553     theModified = true;
554     return true;
555   }
556   return false; // unknown case
557 }