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