]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Validators.cpp
Salome HOME
296f8daa6e8e44a8c49b56444befb1e539063cb4
[modules/shaper.git] / src / PartSet / PartSet_Validators.cpp
1 // File:        PartSet_Validators.cpp
2 // Created:     09 July 2014
3 // Author:      Vitaly SMETANNIKOV
4
5 #include "PartSet_Validators.h"
6
7 #include <list>
8
9
10 int shapesNb(const ModuleBase_ISelection* theSelection, TopAbs_ShapeEnum theType)
11 {
12   std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
13   std::list<ModuleBase_ViewerPrs>::iterator it;
14   ModuleBase_ViewerPrs aPrs;
15   int aCount = 0;
16   for (it = aList.begin(); it != aList.end(); ++it) {
17     aPrs = *it;
18     const TopoDS_Shape& aShape = aPrs.shape();
19     if (!aShape.IsNull()) {
20       if (aShape.ShapeType() == theType)
21         aCount++;
22     }
23   }
24   return aCount;
25 }
26
27 bool PartSet_DistanceValidator::isValid(const ModuleBase_ISelection* theSelection) const
28 {
29   int aCount = shapesNb(theSelection, TopAbs_VERTEX);
30   return (aCount > 0) && (aCount < 3);
31 }
32
33 bool PartSet_LengthValidator::isValid(const ModuleBase_ISelection* theSelection) const
34 {
35   int aCount = shapesNb(theSelection, TopAbs_EDGE);
36   return (aCount == 1);
37 }