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_Face.h>
11 #include <GeomAPI_Lin.h>
12 #include <GeomAPI_Pln.h>
14 #include <ModelAPI_AttributeSelection.h>
16 #include <Events_InfoMessage.h>
18 static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape);
19 static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape);
21 //==================================================================================================
22 bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttribute,
23 const std::list<std::string>& theArguments,
24 Events_InfoMessage& theError) const
26 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
28 AttributeSelectionPtr aLineAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
29 AttributeSelectionPtr aLineAttribute2 = aFeature->selection(theArguments.front());
31 GeomShapePtr aLineShape1 = aLineAttribute1->value();
32 ResultPtr aContext1 = aLineAttribute1->context();
33 if(!aContext1.get()) {
34 theError = "One of the attribute not initialized.";
37 if(!aLineShape1.get()) {
38 aLineShape1 = aContext1->shape();
40 if(!aLineShape1->isEdge()) {
41 theError = "One of the selected shapes not an edge.";
45 GeomShapePtr aLineShape2 = aLineAttribute2->value();
46 ResultPtr aContext2 = aLineAttribute2->context();
47 if(!aContext2.get()) {
50 if(!aLineShape2.get()) {
51 aLineShape2 = aContext2->shape();
53 if(!aLineShape2->isEdge()) {
54 theError = "One of the selected shapes not an edge.";
58 std::shared_ptr<GeomAPI_Edge> aLineEdge1(new GeomAPI_Edge(aLineShape1));
59 std::shared_ptr<GeomAPI_Edge> aLineEdge2(new GeomAPI_Edge(aLineShape2));
61 std::shared_ptr<GeomAPI_Lin> aLine1 = aLineEdge1->line();
62 std::shared_ptr<GeomAPI_Lin> aLine2 = aLineEdge2->line();
64 if(!aLine1->isCoplanar(aLine2)) {
65 theError = "Selected lines not coplanar.";
69 if(aLine1->isParallel(aLine2)) {
70 theError = "Selected lines are parallel.";
77 //==================================================================================================
78 bool ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel::isValid(
79 const AttributePtr& theAttribute,
80 const std::list<std::string>& theArguments,
81 Events_InfoMessage& theError) const
83 FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
85 AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
86 AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
88 std::shared_ptr<GeomAPI_Lin> aLin;
89 std::shared_ptr<GeomAPI_Pln> aPln;
91 GeomShapePtr aShape1 = anAttribute1->value();
92 ResultPtr aContext1 = anAttribute1->context();
93 if(!aContext1.get()) {
94 theError = "One of the attribute not initialized.";
98 aShape1 = aContext1->shape();
101 GeomShapePtr aShape2 = anAttribute2->value();
102 ResultPtr aContext2 = anAttribute2->context();
103 if(!aContext2.get()) {
107 aShape2 = aContext2->shape();
110 aLin = getLin(aShape1);
111 aPln = getPln(aShape2);
112 if(!aLin.get() || !aPln.get()) {
113 aLin = getLin(aShape2);
114 aPln = getPln(aShape1);
117 if(!aLin.get() || !aPln.get()) {
118 theError = "Wrong shape types selected.";
122 if(aPln->isParallel(aLin)) {
123 theError = "Plane and line are parallel.";
130 static std::shared_ptr<GeomAPI_Lin> getLin(const GeomShapePtr theShape)
132 std::shared_ptr<GeomAPI_Lin> aLin;
134 if(!theShape->isEdge()) {
138 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
140 if(!anEdge->isLine()) {
144 aLin = anEdge->line();
149 static std::shared_ptr<GeomAPI_Pln> getPln(const GeomShapePtr theShape)
151 std::shared_ptr<GeomAPI_Pln> aPln;
153 if(!theShape->isFace()) {
157 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(theShape));
159 if(!aFace->isPlanar()) {
163 aPln = aFace->getPlane();