1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: ConstructionPlugin_Validators.cpp
4 // Created: 04 July 2016
5 // Author: Dmitry Bobylev
7 #include "ConstructionPlugin_Validators.h"
9 #include <GeomAPI_Edge.h>
10 #include <GeomAPI_Lin.h>
12 #include <ModelAPI_AttributeSelection.h>
14 #include <Events_InfoMessage.h>
16 //==================================================================================================
17 bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute,
18 const std::list<std::string>& theArguments,
19 Events_InfoMessage& theError) const
21 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
23 AttributeSelectionPtr aLineAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
24 AttributeSelectionPtr aLineAttribute2 = aFeature->selection(theArguments.front());
26 GeomShapePtr aLineShape1 = aLineAttribute1->value();
27 ResultPtr aContext1 = aLineAttribute1->context();
28 if(!aContext1.get()) {
29 theError = "One of the attribute not initialized.";
32 if(!aLineShape1.get()) {
33 aLineShape1 = aContext1->shape();
35 if(!aLineShape1->isEdge()) {
36 theError = "One of the selected shapes not an edge.";
40 GeomShapePtr aLineShape2 = aLineAttribute2->value();
41 ResultPtr aContext2 = aLineAttribute2->context();
42 if(!aContext2.get()) {
45 if(!aLineShape2.get()) {
46 aLineShape2 = aContext2->shape();
48 if(!aLineShape2->isEdge()) {
49 theError = "One of the selected shapes not an edge.";
53 std::shared_ptr<GeomAPI_Edge> aLineEdge1(new GeomAPI_Edge(aLineShape1));
54 std::shared_ptr<GeomAPI_Edge> aLineEdge2(new GeomAPI_Edge(aLineShape2));
56 std::shared_ptr<GeomAPI_Lin> aLine1 = aLineEdge1->line();
57 std::shared_ptr<GeomAPI_Lin> aLine2 = aLineEdge2->line();
59 if(!aLine1->isCoplanar(aLine2)) {
60 theError = "Selected lines not coplanar.";
64 if(aLine1->isParallel(aLine2)) {
65 theError = "Selected lines are parallel.";