]> SALOME platform Git repositories - modules/shaper.git/blob - src/BuildPlugin/BuildPlugin_Validators.cpp
Salome HOME
1. Manage color of construction point using preferences dialog box.
[modules/shaper.git] / src / BuildPlugin / BuildPlugin_Validators.cpp
1 // Copyright (C) 2014-2020  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 email : webmaster.salome@opencascade.com
18 //
19
20 #include "BuildPlugin_Validators.h"
21
22 #include <ModelAPI_AttributeSelectionList.h>
23 #include <ModelAPI_ResultConstruction.h>
24
25 #include <GeomAPI_PlanarEdges.h>
26 #include <GeomAPI_Pln.h>
27 #include <GeomAPI_ShapeExplorer.h>
28 #include <GeomAPI_ShapeIterator.h>
29
30 #include <GeomAlgoAPI_CompoundBuilder.h>
31 #include <GeomAlgoAPI_PaveFiller.h>
32 #include <GeomAlgoAPI_ShapeBuilder.h>
33 #include <GeomAlgoAPI_ShapeTools.h>
34 #include <GeomAlgoAPI_SketchBuilder.h>
35 #include <GeomAlgoAPI_WireBuilder.h>
36 #include <GeomAlgoAPI_MakeVolume.h>
37 #include <GeomAlgoAPI_Tools.h>
38
39 #include <GeomValidators_FeatureKind.h>
40 #include <GeomValidators_ShapeType.h>
41
42 #include <SketchPlugin_Sketch.h>
43
44 #include <Events_InfoMessage.h>
45
46 //=================================================================================================
47 bool BuildPlugin_ValidatorBaseForBuild::isValid(const AttributePtr& theAttribute,
48                                                 const std::list<std::string>& theArguments,
49                                                 Events_InfoMessage& theError) const
50 {
51   // Get base objects list.
52   if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
53     std::string aMsg = "Error: BuildPlugin_ValidatorBaseForBuild does "
54                        "not support attribute type '%1'\nOnly '%2' is supported.";
55     Events_InfoMessage("BuildPlugin_Validators", aMsg).
56       arg(theAttribute->attributeType()).arg(ModelAPI_AttributeSelectionList::typeId()).send();
57     return false;
58   }
59   AttributeSelectionListPtr aSelectionList =
60     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
61   if(!aSelectionList.get()) {
62     theError = "Could not get selection list.";
63     return false;
64   }
65   if(aSelectionList->size() == 0) {
66     theError = "Empty selection list.";
67     return false;
68   }
69
70   // Collect base shapes.
71   for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
72     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
73     if(!aSelection.get()) {
74       theError = "Could not get selection.";
75       return false;
76     }
77     ResultPtr aContext = aSelection->context();
78     if(!aContext.get()) {
79       theError = "Attribute have empty context.";
80       return false;
81     }
82
83     GeomShapePtr aShape = aSelection->value();
84     GeomShapePtr aContextShape = aContext->shape();
85     if(!aShape.get()) {
86       aShape = aContextShape;
87     }
88     if(!aShape.get()) {
89       theError = "Empty shape selected.";
90       return false;
91     }
92
93     // Check that shapes has acceptable type.
94     GeomValidators_ShapeType aValidatorShapeType;
95     if(!aValidatorShapeType.isValid(aSelection, theArguments, theError)) {
96       return false;
97     }
98
99     // Check that it is shape on sketch.
100     ResultConstructionPtr aConstruction =
101       std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
102     if(aConstruction.get()) {
103       if(aConstruction->isInfinite()) {
104         theError = "Infinite objects not acceptable.";
105         return false;
106       }
107     }
108   }
109
110   return true;
111 }
112
113 //=================================================================================================
114 bool BuildPlugin_ValidatorBaseForWire::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
115                                                const std::list<std::string>& theArguments,
116                                                Events_InfoMessage& theError) const
117 {
118   // Get attribute.
119   AttributeSelectionListPtr aSelectionList = theFeature->selectionList(theArguments.front());
120   if(!aSelectionList.get()) {
121     theError = "Empty attribute \"%1\".";
122     theError.arg(theArguments.front());
123     return false;
124   }
125
126   /// remove objects of sub-type if ojects of correct type is in List,  in some cases :
127   /// Wire builder: wires and edges selected
128   std::set<GeomAPI_Shape::ShapeType> shapeTypes;
129   for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
130     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
131     GeomShapePtr aShape = aSelection->value();
132     if (aShape.get())
133       shapeTypes.insert(aShape->shapeType());
134   }
135
136   std::set<int> aRemove;
137   if (shapeTypes.find(GeomAPI_Shape::WIRE) != shapeTypes.end())
138   {
139     for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
140       AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
141       GeomShapePtr aShape = aSelection->value();
142       if (aShape.get()) {
143         auto aType = aShape->shapeType();
144         if (aType == GeomAPI_Shape::EDGE)
145           aRemove.insert(anIndex);
146       }
147       else
148         aRemove.insert(anIndex);
149     }
150   }
151
152   if (aRemove.size() > 0)
153     aSelectionList->remove(aRemove);
154
155   GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::shapeTypeByStr(theArguments.back());
156
157   // Collect base shapes.
158   ListOfShape aListOfShapes;
159   for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
160     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
161     GeomShapePtr aShape = aSelection->value();
162     ResultPtr aContext = aSelection->context();
163     if (!aShape.get() && aContext.get())
164       aShape = aContext->shape();
165
166     bool isProper = aShape.get() &&
167         (aShape->shapeType() == GeomAPI_Shape::EDGE || aShape->shapeType() == aShapeType);
168
169     if (isProper)
170       aListOfShapes.push_back(aShape);
171     else {
172       // is it a sketch?
173       FeaturePtr aFeature = aSelection->contextFeature();
174       if (!aFeature.get()) {
175         GeomShapePtr aValue = aSelection->value();
176         // whole sketch is allowed only
177         if (aContext.get() && !aValue.get()) {
178           aFeature = ModelAPI_Feature::feature(aContext);
179         }
180       }
181
182       if (!aFeature.get()) {
183         theError = "Error: Incorrect selection.";
184         return false;
185       }
186
187       if (aFeature->getKind() != SketchPlugin_Sketch::ID()) {
188         theError = "Error: %1 shape is not allowed for selection.";
189         theError.arg(aFeature->getKind());
190         return false;
191       }
192     }
193   }
194
195   if (aShapeType == GeomAPI_Shape::WIRE) {
196     // Create wire.
197     GeomShapePtr aWire = GeomAlgoAPI_WireBuilder::wire(aListOfShapes);
198     if (!aWire.get() && !aListOfShapes.empty()) {
199       theError = "Result wire empty. Probably it has disconnected edges or non-manifold.";
200       return false;
201     }
202   }
203
204   return true;
205 }
206
207 //=================================================================================================
208 bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
209                                                const std::list<std::string>& theArguments,
210                                                Events_InfoMessage& theError) const
211 {
212   // Get attribute.
213   if(theArguments.size() != 1) {
214     std::string aMsg = "Error: BuildPlugin_ValidatorBaseForFace should be used only with "
215       "1 parameter (ID of base objects list).";
216     Events_InfoMessage("BuildPlugin_Validators", aMsg).send();
217     return false;
218   }
219   AttributeSelectionListPtr aSelectionList = theFeature->selectionList(theArguments.front());
220   if(!aSelectionList.get()) {
221     theError = "Empty attribute \"%1\".";
222     theError.arg(theArguments.front());
223     return false;
224   }
225
226   /// remove objects of sub-type if ojects of correct type is in List,  in some cases :
227   /// - Face builder: edges, faces and wires selected
228   ///                 --> remove edges and wires
229   std::set<GeomAPI_Shape::ShapeType> shapeTypes;
230   for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
231     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
232     GeomShapePtr aShape = aSelection->value();
233     if (aShape.get())
234       shapeTypes.insert(aShape->shapeType());
235   }
236
237   std::set<int> aRemove;
238   if (shapeTypes.find(GeomAPI_Shape::FACE) != shapeTypes.end())
239   {
240     for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
241       AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
242       GeomShapePtr aShape = aSelection->value();
243       if (aShape.get()) {
244         auto aType = aShape->shapeType();
245         if (aType == GeomAPI_Shape::WIRE || aType == GeomAPI_Shape::EDGE)
246           aRemove.insert(anIndex);
247       }
248       else
249         aRemove.insert(anIndex);
250     }
251   }
252   if (aRemove.size() > 0)
253     aSelectionList->remove(aRemove);
254
255   bool hasEdgesOrWires = false;
256   bool hasFaces = false;
257
258   // Collect base shapes.
259   ListOfShape anEdges;
260   for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
261     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
262     GeomShapePtr aShape = aSelection->value();
263     if(!aShape.get()) {
264       if (!aSelection->context()) {
265         theError = "Objects are not selected.";
266         return false;
267       }
268       aShape = aSelection->context()->shape();
269     }
270     ResultConstructionPtr aSketchRes =
271         std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aSelection->context());
272
273     if (aShape->shapeType() == GeomAPI_Shape::FACE ||
274         (!aSelection->value() && aSketchRes && aSketchRes->facesNum() > 0)) {
275       // skip faces exploding
276       hasFaces = true;
277       continue;
278     }
279
280     for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
281       hasEdgesOrWires = true;
282       GeomShapePtr anEdge = anExp.current();
283       anEdges.push_back(anEdge);
284     }
285   }
286
287   if (hasFaces && hasEdgesOrWires) {
288     theError = "Faces and edges/wires should be selected together.";
289     return false;
290   } else if (hasEdgesOrWires && anEdges.empty()) {
291     theError = "Objects are not selected.";
292     return false;
293   }
294
295   // Check that edges does not have intersections.
296   if(anEdges.size() > 1) {
297     GeomAlgoAPI_PaveFiller aPaveFiller(anEdges, false);
298     if(!aPaveFiller.isDone()) {
299       theError = "Error while checking if edges intersects.";
300       return false;
301     }
302     GeomShapePtr aSectedEdges = aPaveFiller.shape();
303
304     size_t anEdgesNum = 0;
305     for(GeomAPI_ShapeExplorer
306         anExp(aSectedEdges, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
307       anEdgesNum++;
308     }
309     if(anEdgesNum != anEdges.size()) {
310       theError = "Selected objects have intersections.";
311       return false;
312     }
313   }
314
315   if (!anEdges.empty()) {
316     // Check that they are planar.
317     std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_ShapeTools::findPlane(anEdges);
318     if(!aPln.get()) {
319       theError = "Selected object(s) should belong to only one plane.";
320       return false;
321     }
322
323     // Check that selected objects have closed contours.
324     GeomAlgoAPI_SketchBuilder aBuilder(aPln, anEdges);
325     const ListOfShape& aFaces = aBuilder.faces();
326     if(aFaces.empty()) {
327       theError = "Selected objects do not generate closed contour.";
328       return false;
329     }
330   }
331
332   return true;
333 }
334
335 //=================================================================================================
336 bool BuildPlugin_ValidatorBaseForSolids::isValid(
337   const std::shared_ptr<ModelAPI_Feature>& theFeature, const std::list<std::string>& theArguments,
338   Events_InfoMessage& theError) const
339 {
340   // Get base objects list.
341   AttributeSelectionListPtr aSelectionList = theFeature->selectionList(theArguments.front());
342   if (!aSelectionList.get()) {
343     theError = "Could not get selection list.";
344     return false;
345   }
346   if (aSelectionList->size() == 0) {
347     theError = "Empty selection list.";
348     return false;
349   }
350
351   /// remove objects of sub-type if ojects of correct type is in List,  in some cases :
352   /// Solid builder: faces and shapes shells or solids seleted
353   ///                --> remove faces
354
355   std::set<GeomAPI_Shape::ShapeType> shapeTypes;
356   for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
357     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
358     GeomShapePtr aShape = aSelection->value();
359     if (aShape.get())
360       shapeTypes.insert(aShape->shapeType());
361   }
362
363   std::set<int> aRemove;
364   if (shapeTypes.find(GeomAPI_Shape::SHAPE) != shapeTypes.end() ||
365       shapeTypes.find(GeomAPI_Shape::SOLID) != shapeTypes.end() ||
366       shapeTypes.find(GeomAPI_Shape::SHELL) != shapeTypes.end())
367   {
368     for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
369       AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
370       GeomShapePtr aShape = aSelection->value();
371       if (aShape.get()) {
372         auto aType = aShape->shapeType();
373         if (aType == GeomAPI_Shape::FACE)
374           aRemove.insert(anIndex);
375       }
376       else
377         aRemove.insert(anIndex);
378     }
379   }
380
381   if (aRemove.size() > 0)
382     aSelectionList->remove(aRemove);
383
384   // Collect base shapes.
385   ListOfShape anOriginalShapes;
386   for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
387     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
388     if (!aSelection->context().get()) {
389       theError = "Invalid selection.";
390       return false;
391     }
392     GeomShapePtr aShape = aSelection->value();
393     if (!aShape.get())
394       aShape = aSelection->context()->shape();
395     anOriginalShapes.push_back(aShape);
396   }
397
398   std::shared_ptr<GeomAlgoAPI_MakeVolume> anAlgorithm(
399     new GeomAlgoAPI_MakeVolume(anOriginalShapes, false));
400
401   std::string anErr;
402   if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(anAlgorithm, "MakeVolume", anErr)) {
403     theError = anErr;
404     return false;
405   }
406
407   // set of allowed types of results
408   std::set<GeomAPI_Shape::ShapeType> aResultType;
409   std::string aType = theArguments.back();
410   if (aType == "solid")
411     aResultType.insert(GeomAPI_Shape::SOLID);
412   else if (aType == "compsolid") {
413     aResultType.insert(GeomAPI_Shape::COMPSOLID);
414     aResultType.insert(GeomAPI_Shape::SOLID);
415   }
416
417   GeomShapePtr aCompound = anAlgorithm->shape();
418   if (aCompound->shapeType() == GeomAPI_Shape::COMPOUND) {
419     GeomAPI_ShapeIterator anIt(aCompound);
420     GeomShapePtr aFoundSub;
421     for (; anIt.more() && !aFoundSub; anIt.next()) {
422       aFoundSub = anIt.current();
423       if (aResultType.count(aFoundSub->shapeType()) == 0) {
424         theError = "Unable to build a solid";
425         return false;
426       }
427     }
428     if (anIt.more() || !aFoundSub.get()) {
429       theError = "Unable to build a solid";
430       return false;
431     }
432   } else if (aResultType.count(aCompound->shapeType()) == 0) {
433     theError = "Unable to build a solid";
434     return false;
435   }
436   // check the internal faces presence
437   for(GeomAPI_ShapeExplorer aFaces(aCompound, GeomAPI_Shape::FACE); aFaces.more(); aFaces.next()) {
438     if (aFaces.current()->orientation() == GeomAPI_Shape::INTERNAL) {
439       theError = "Internal faces are not allowed in the resulting solid";
440       return false;
441     }
442   }
443
444   return true;
445 }
446
447
448 //=================================================================================================
449 bool BuildPlugin_ValidatorSubShapesSelection::isValid(const AttributePtr& theAttribute,
450                                                       const std::list<std::string>& theArguments,
451                                                       Events_InfoMessage& theError) const
452 {
453   if(theArguments.size() != 1) {
454     // LCOV_EXCL_START
455     std::string aMsg = "Error: BuildPlugin_ValidatorSubShapesSelection should be used only with "
456       "1 parameter(Sketch feature id).";
457     Events_InfoMessage("BuildPlugin_Validators", aMsg).send();
458     return false;
459     // LCOV_EXCL_STOP
460   }
461
462   // Get base objects list.
463   if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
464     // LCOV_EXCL_START
465     std::string aMsg =
466       "Error: BuildPlugin_ValidatorSubShapesSelection does not support attribute type \""
467       "%1\"\n Only \"%2\" supported.";
468     Events_InfoMessage("BuildPlugin_Validators", aMsg).
469       arg(theAttribute->attributeType()).arg(ModelAPI_AttributeSelectionList::typeId()).send();
470     return false;
471     // LCOV_EXCL_STOP
472   }
473   AttributeSelectionListPtr aSelectionList =
474     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
475   if(!aSelectionList.get()) {
476     theError = "Could not get selection list.";
477     return false;
478   }
479
480   // Get base shape.
481   const std::string aBaseShapeId = "base_shape";
482   FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
483   AttributeSelectionPtr aShapeAttrSelection = aFeature->selection(aBaseShapeId);
484
485   if(!aShapeAttrSelection.get()) {
486     theError = "Base shape is empty.";
487     return false;
488   }
489
490   ResultPtr aBaseContext = aShapeAttrSelection->context();
491
492   GeomShapePtr aBaseShape  = aShapeAttrSelection->value();
493   if(!aBaseShape.get()) {
494     theError = "Base shape is empty.";
495     return false;
496   }
497
498   GeomAlgoAPI_ShapeBuilder aBuilder;
499   aBuilder.removeInternal(aBaseShape);
500   aBaseShape = aBuilder.shape();
501
502   // If selected shape is wire allow to select only vertices. If face - allow vertices and edges.
503   std::set<GeomAPI_Shape::ShapeType> anAllowedTypes;
504   switch(aBaseShape->shapeType()) {
505     case GeomAPI_Shape::FACE: anAllowedTypes.insert(GeomAPI_Shape::EDGE);
506     case GeomAPI_Shape::WIRE: anAllowedTypes.insert(GeomAPI_Shape::VERTEX);
507     default: break;
508   }
509
510   // Check selected shapes.
511   GeomValidators_FeatureKind aFeatureKindValidator;
512   std::list<std::string> anArguments;
513   anArguments.push_back(theArguments.front());
514   for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
515     AttributeSelectionPtr aSelectionAttrInList = aSelectionList->value(anIndex);
516     if(!aSelectionAttrInList.get()) {
517       theError = "Empty attribute in list.";
518       return false;
519     }
520
521     // If context of selection same skip.
522     if(aBaseContext == aSelectionAttrInList->context()) {
523       continue;
524     }
525
526     // Check that it is a selection on Sketch.
527     if(!aFeatureKindValidator.isValid(aSelectionAttrInList, anArguments, theError)) {
528       return false;
529     }
530
531     // Check shape type.
532     GeomShapePtr aShapeInList = aSelectionAttrInList->value();
533     if(!aShapeInList.get()) {
534       aShapeInList = aSelectionAttrInList->context()->shape();
535     }
536     if(anAllowedTypes.find(aShapeInList->shapeType()) == anAllowedTypes.cend()) {
537       theError = "Selected shape has unacceptable type.";
538       return false;
539     }
540
541     // Check that shape inside wire or face.
542     if(!GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(aShapeInList, aBaseShape)) {
543       theError = "Selected shape is not inside base face.";
544       return false;
545     }
546   }
547
548   return true;
549 }
550
551
552 //=================================================================================================
553 bool BuildPlugin_ValidatorFillingSelection::isValid(const AttributePtr& theAttribute,
554                                                     const std::list<std::string>& /*theArguments*/,
555                                                     Events_InfoMessage& theError) const
556 {
557   // Get base objects list.
558   if (theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
559     // LCOV_EXCL_START
560     std::string aMsg =
561       "Error: BuildPlugin_ValidatorFillingSelection does not support attribute type \""
562       "%1\"\n Only \"%2\" supported.";
563     Events_InfoMessage("BuildPlugin_Validators", aMsg).
564       arg(theAttribute->attributeType()).arg(ModelAPI_AttributeSelectionList::typeId()).send();
565     return false;
566     // LCOV_EXCL_STOP
567   }
568   AttributeSelectionListPtr aSelectionList =
569     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
570   if (!aSelectionList.get()) {
571     theError = "Could not get selection list.";
572     return false;
573   }
574
575   //FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
576
577   // Check selected shapes.
578   for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
579     AttributeSelectionPtr aSelectionAttrInList = aSelectionList->value(anIndex);
580     if (!aSelectionAttrInList.get()) {
581       theError = "Empty attribute in list.";
582       return false;
583     }
584
585     // Check shape exists.
586     GeomShapePtr aShapeInList = aSelectionAttrInList->value();
587     if (!aShapeInList.get()) {
588       theError = "Object has no shape";
589       return false;
590     }
591
592     // Check shape type.
593     GeomAPI_Shape::ShapeType aType = aShapeInList->shapeType();
594     if (aType != GeomAPI_Shape::EDGE && aType != GeomAPI_Shape::WIRE) {
595       theError = "Incorrect objects selected";
596       return false;
597     }
598   }
599
600   return true;
601 }
602
603
604 //=================================================================================================
605 bool BuildPlugin_ValidatorBaseForVertex::isValid(const AttributePtr& theAttribute,
606                                                  const std::list<std::string>& /*theArguments*/,
607                                                  Events_InfoMessage& theError) const
608 {
609   if (!theAttribute.get()) {
610     theError = "Error: empty selection.";
611     return false;
612   }
613
614   AttributeSelectionListPtr aSelectionList =
615     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
616   if (!aSelectionList.get()) {
617     theError = "Could not get selection list.";
618     return false;
619   }
620
621   for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
622     AttributeSelectionPtr aSelectionAttr = aSelectionList->value(anIndex);
623     if (!aSelectionAttr.get()) {
624       theError = "Empty attribute in list.";
625       return false;
626     }
627
628     // Vertex?
629     bool isVertex = false;
630     GeomShapePtr aShape = aSelectionAttr->value();
631     ResultPtr aContext = aSelectionAttr->context();
632     if (!aShape.get() && aContext.get())
633       aShape = aContext->shape();
634     if (aShape.get())
635       isVertex = (aShape->shapeType() == GeomAPI_Shape::VERTEX);
636
637     if (!isVertex) {
638       // Sketch?
639       FeaturePtr aFeature = aSelectionAttr->contextFeature();
640       if (!aFeature.get()) {
641         GeomShapePtr aValue = aSelectionAttr->value();
642         // whole sketch is allowed only
643         if (aContext.get() && !aValue.get()) {
644           aFeature = ModelAPI_Feature::feature(aContext);
645         }
646       }
647
648       if (!aFeature.get()) {
649         theError = "Error: Incorrect selection.";
650         return false;
651       }
652
653       if (aFeature->getKind() != SketchPlugin_Sketch::ID()) {
654         theError = "Error: %1 shape is not allowed for selection.";
655         theError.arg(aFeature->getKind());
656         return false;
657       }
658     }
659   }
660
661   return true;
662 }