Salome HOME
098485d0a000381d778367735ff4eadda8ac030b
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Validators.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        ConstructionPlugin_Validators.cpp
4 // Created:     04 July 2016
5 // Author:      Dmitry Bobylev
6
7 #include "ConstructionPlugin_Validators.h"
8
9 #include <GeomAPI_Edge.h>
10 #include <GeomAPI_Lin.h>
11
12 #include <ModelAPI_AttributeSelection.h>
13
14 #include <Events_InfoMessage.h>
15
16 //==================================================================================================
17 bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute,
18                                                      const std::list<std::string>& theArguments,
19                                                      Events_InfoMessage& theError) const
20 {
21   FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
22
23   AttributeSelectionPtr aLineAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
24   AttributeSelectionPtr aLineAttribute2 = aFeature->selection(theArguments.front());
25
26   GeomShapePtr aLineShape1 = aLineAttribute1->value();
27   ResultPtr aContext1 = aLineAttribute1->context();
28   if(!aContext1.get()) {
29     theError = "One of the attribute not initialized.";
30     return false;
31   }
32   if(!aLineShape1.get()) {
33     aLineShape1 = aContext1->shape();
34   }
35   if(!aLineShape1->isEdge()) {
36     theError = "One of the selected shapes not an edge.";
37     return false;
38   }
39
40   GeomShapePtr aLineShape2 = aLineAttribute2->value();
41   ResultPtr aContext2 = aLineAttribute2->context();
42   if(!aContext2.get()) {
43     return true;
44   }
45   if(!aLineShape2.get()) {
46     aLineShape2 = aContext2->shape();
47   }
48   if(!aLineShape2->isEdge()) {
49     theError = "One of the selected shapes not an edge.";
50     return false;
51   }
52
53   std::shared_ptr<GeomAPI_Edge> aLineEdge1(new GeomAPI_Edge(aLineShape1));
54   std::shared_ptr<GeomAPI_Edge> aLineEdge2(new GeomAPI_Edge(aLineShape2));
55
56   std::shared_ptr<GeomAPI_Lin> aLine1 = aLineEdge1->line();
57   std::shared_ptr<GeomAPI_Lin> aLine2 = aLineEdge2->line();
58
59   if(!aLine1->isCoplanar(aLine2)) {
60     theError = "Selected lines not coplanar.";
61     return false;
62   }
63
64   if(aLine1->isParallel(aLine2)) {
65     theError = "Selected lines are parallel.";
66     return false;
67   }
68
69   return true;
70 }