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