Salome HOME
Fix ConstructionPlugin_Plane created by Rotation
[modules/shaper.git] / src / ConstructionPlugin / ConstructionPlugin_Validators.cpp
index 9cf88ccd9b1a4e4bc2091c763d6fb8c00bb01bc5..1a65f5320c69027cff3f7c35020d9e3251932725 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "ConstructionPlugin_Validators.h"
 
+#include <GeomAPI_Dir.h>
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Face.h>
 #include <GeomAPI_Lin.h>
@@ -13,6 +14,7 @@
 #include <GeomAPI_Vertex.h>
 
 #include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeBoolean.h>
 
 #include <Events_InfoMessage.h>
 
@@ -27,7 +29,8 @@ bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttr
 {
   FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
 
-  AttributeSelectionPtr aLineAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+  AttributeSelectionPtr aLineAttribute1 =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
   AttributeSelectionPtr aLineAttribute2 = aFeature->selection(theArguments.front());
 
   GeomShapePtr aLineShape1 = aLineAttribute1->value();
@@ -84,7 +87,8 @@ bool ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel::isValid(
 {
   FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
 
-  AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+  AttributeSelectionPtr anAttribute1 =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
   AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
 
   std::shared_ptr<GeomAPI_Lin> aLin;
@@ -131,12 +135,13 @@ bool ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel::isValid(
 
 //==================================================================================================
 bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& theAttribute,
-                                                           const std::list<std::string>& theArguments,
-                                                           Events_InfoMessage& theError) const
+                                                        const std::list<std::string>& theArguments,
+                                                        Events_InfoMessage& theError) const
 {
   FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
 
-  AttributeSelectionPtr aPointAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+  AttributeSelectionPtr aPointAttribute1 =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
   AttributeSelectionPtr aPointAttribute2 = aFeature->selection(theArguments.front());
   AttributeSelectionPtr aPointAttribute3 = aFeature->selection(theArguments.back());
 
@@ -206,7 +211,8 @@ bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid(
 {
   FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
 
-  AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+  AttributeSelectionPtr anAttribute1 =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
   AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
 
   std::shared_ptr<GeomAPI_Lin> aLin;
@@ -243,8 +249,118 @@ bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid(
     return false;
   }
 
-  if(aLin->contains(aPnt)) {
-    theError = "Point lies on the line.";
+  // line should not contain point only for not-prependicular case
+  AttributeBooleanPtr aBoolAttr = aFeature->boolean(theArguments.back());
+  if (aBoolAttr.get() && !aBoolAttr->value()) {
+    if(aLin->contains(aPnt)) {
+      theError = "Point lies on the line.";
+      return false;
+    }
+  }
+
+  return true;
+}
+
+//==================================================================================================
+bool ConstructionPlugin_ValidatorPlaneTwoParallelPlanes::isValid(
+    const AttributePtr& theAttribute,
+    const std::list<std::string>& theArguments,
+    Events_InfoMessage& theError) const
+{
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+
+  AttributeSelectionPtr anAttribute1 =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+  AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
+
+  std::shared_ptr<GeomAPI_Pln> aPln1;
+  std::shared_ptr<GeomAPI_Pln> aPln2;
+
+  GeomShapePtr aShape1 = anAttribute1->value();
+  ResultPtr aContext1 = anAttribute1->context();
+  if(!aContext1.get()) {
+    theError = "One of the attribute not initialized.";
+    return false;
+  }
+  if(!aShape1.get()) {
+    aShape1 = aContext1->shape();
+  }
+
+  GeomShapePtr aShape2 = anAttribute2->value();
+  ResultPtr aContext2 = anAttribute2->context();
+  if(!aContext2.get()) {
+    return true;
+  }
+  if(!aShape2.get()) {
+    aShape2 = aContext2->shape();
+  }
+
+  aPln1 = getPln(aShape1);
+  aPln2 = getPln(aShape2);
+
+  if(!aPln1.get() || !aPln2.get()) {
+    theError = "Wrong shape types selected.";
+    return false;
+  }
+
+  std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
+  std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
+
+  if(!aDir1->isParallel(aDir2)) {
+    theError = "Planes not parallel.";
+    return false;
+  }
+
+  return true;
+}
+
+//==================================================================================================
+bool ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes::isValid(
+    const AttributePtr& theAttribute,
+    const std::list<std::string>& theArguments,
+    Events_InfoMessage& theError) const
+{
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+
+  AttributeSelectionPtr anAttribute1 =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+  AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front());
+
+  std::shared_ptr<GeomAPI_Pln> aPln1;
+  std::shared_ptr<GeomAPI_Pln> aPln2;
+
+  GeomShapePtr aShape1 = anAttribute1->value();
+  ResultPtr aContext1 = anAttribute1->context();
+  if(!aContext1.get()) {
+    theError = "One of the attribute not initialized.";
+    return false;
+  }
+  if(!aShape1.get()) {
+    aShape1 = aContext1->shape();
+  }
+
+  GeomShapePtr aShape2 = anAttribute2->value();
+  ResultPtr aContext2 = anAttribute2->context();
+  if(!aContext2.get()) {
+    return true;
+  }
+  if(!aShape2.get()) {
+    aShape2 = aContext2->shape();
+  }
+
+  aPln1 = getPln(aShape1);
+  aPln2 = getPln(aShape2);
+
+  if(!aPln1.get() || !aPln2.get()) {
+    theError = "Wrong shape types selected.";
+    return false;
+  }
+
+  std::shared_ptr<GeomAPI_Dir> aDir1 = aPln1->direction();
+  std::shared_ptr<GeomAPI_Dir> aDir2 = aPln2->direction();
+
+  if(aDir1->isParallel(aDir2)) {
+    theError = "Planes are parallel.";
     return false;
   }