Salome HOME
Improve the correcting orientation in the Filling feature.
authorazv <azv@opencascade.com>
Thu, 21 Dec 2017 10:17:54 +0000 (13:17 +0300)
committerazv <azv@opencascade.com>
Thu, 21 Dec 2017 10:17:54 +0000 (13:17 +0300)
Add validator for the Filling selection.

src/BuildPlugin/BuildPlugin_Filling.cpp
src/BuildPlugin/BuildPlugin_Plugin.cpp
src/BuildPlugin/BuildPlugin_Validators.cpp
src/BuildPlugin/BuildPlugin_Validators.h
src/BuildPlugin/filling_widget.xml

index a5597f6e620543b40fd2f750c0d658edaa42dfbf..e9b376399fb8e9387d52bc8a1bf9f7d7463cdab4 100644 (file)
@@ -27,6 +27,7 @@
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_ResultBody.h>
 
+#include <GeomAlgoAPI_Copy.h>
 #include <GeomAlgoAPI_Filling.h>
 #include <GeomAlgoAPI_ShapeTools.h>
 
@@ -167,7 +168,7 @@ GeomEdgePtr BuildPlugin_Filling::toEdge(const GeomShapePtr& theShape, const std:
   GeomEdgePtr anEdge;
   switch (theShape->shapeType()) {
   case GeomAPI_Shape::EDGE:
-    anEdge = GeomEdgePtr(new GeomAPI_Edge(theShape));
+    anEdge = GeomEdgePtr(new GeomAPI_Edge(GeomAlgoAPI_Copy(theShape).shape()));
     break;
   case GeomAPI_Shape::WIRE:
     anEdge = GeomAlgoAPI_ShapeTools::wireToEdge(
@@ -189,6 +190,10 @@ GeomEdgePtr BuildPlugin_Filling::toEdge(const GeomShapePtr& theShape, const std:
     // check the distance to previous edge boundaries, reverse edge if necessary
     GeomPointPtr aStartPnt = anEdge->firstPoint();
     GeomPointPtr aEndPnt = anEdge->lastPoint();
+    if (anEdge->orientation() == GeomAPI_Shape::REVERSED) {
+      aStartPnt = anEdge->lastPoint();
+      aEndPnt = anEdge->firstPoint();
+    }
     bool isReverse = false;
     if (myLastEdgeStartPoint) {
       double d1 = myLastEdgeStartPoint->distance(aStartPnt)
index fed1877f9ef64aae4d5bbb77af0669c4114fbee0..2042eb2f14a97ee925da0146262183615a448646 100644 (file)
@@ -49,6 +49,8 @@ BuildPlugin_Plugin::BuildPlugin_Plugin()
                               new BuildPlugin_ValidatorBaseForFace());
   aFactory->registerValidator("BuildPlugin_ValidatorSubShapesSelection",
                               new BuildPlugin_ValidatorSubShapesSelection());
+  aFactory->registerValidator("BuildPlugin_ValidatorFillingSelection",
+                              new BuildPlugin_ValidatorFillingSelection());
 
   // Register this plugin.
   ModelAPI_Session::get()->registerPlugin(this);
index 244ddb6e4f7ae9d0ed8ee89500e2c8e8b6c2b8a5..e0268ef42900091d5a5a60d3fbc02b004d1ec41e 100644 (file)
@@ -359,3 +359,53 @@ bool BuildPlugin_ValidatorSubShapesSelection::isValid(const AttributePtr& theAtt
 
   return true;
 }
+
+
+//=================================================================================================
+bool BuildPlugin_ValidatorFillingSelection::isValid(const AttributePtr& theAttribute,
+                                                      const std::list<std::string>& theArguments,
+                                                      Events_InfoMessage& theError) const
+{
+  // Get base objects list.
+  if (theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
+    std::string aMsg =
+      "Error: BuildPlugin_ValidatorFillingSelection does not support attribute type \""
+      "%1\"\n Only \"%2\" supported.";
+    Events_InfoMessage("BuildPlugin_Validators", aMsg).
+      arg(theAttribute->attributeType()).arg(ModelAPI_AttributeSelectionList::typeId()).send();
+    return false;
+  }
+  AttributeSelectionListPtr aSelectionList =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  if (!aSelectionList.get()) {
+    theError = "Could not get selection list.";
+    return false;
+  }
+
+  FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
+
+  // Check selected shapes.
+  for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+    AttributeSelectionPtr aSelectionAttrInList = aSelectionList->value(anIndex);
+    if (!aSelectionAttrInList.get()) {
+      theError = "Empty attribute in list.";
+      return false;
+    }
+
+    // Check shape exists.
+    GeomShapePtr aShapeInList = aSelectionAttrInList->value();
+    if (!aShapeInList.get()) {
+      theError = "Object has no shape";
+      return false;
+    }
+
+    // Check shape type.
+    GeomAPI_Shape::ShapeType aType = aShapeInList->shapeType();
+    if (aType != GeomAPI_Shape::EDGE && aType != GeomAPI_Shape::WIRE) {
+      theError = "Incorrect objects selected";
+      return false;
+    }
+  }
+
+  return true;
+}
index 522e3bb8361b470b1998d456c6e2df8b47b3673a..5f3be35daf884d20edcc659bfd054f3c2eca5dcd 100644 (file)
@@ -94,4 +94,19 @@ public:
                         Events_InfoMessage& theError) const;
 };
 
+/// \class BuildPlugin_ValidatorFillingSelection
+/// \ingroup Validators
+/// \brief A validator for selection of Filling feature.
+class BuildPlugin_ValidatorFillingSelection: public ModelAPI_AttributeValidator
+{
+public:
+  //! Returns true if attribute is ok.
+  //! \param[in] theAttribute the checked attribute.
+  //! \param[in] theArguments arguments of the attribute.
+  //! \param[out] theError error message.
+   virtual bool isValid(const AttributePtr& theAttribute,
+                        const std::list<std::string>& theArguments,
+                        Events_InfoMessage& theError) const;
+};
+
 #endif
index a9e3930046e0d2f21a8abcbbd73efd31e2ebf666..0ecb8587743c247b182d2eeeb736285cf397e382 100644 (file)
@@ -26,6 +26,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
                   type_choice="edges wires"
                   concealment="false">
     <validator id="PartSet_DifferentObjects"/>
+    <validator id="BuildPlugin_ValidatorFillingSelection"/>
   </multi_selector>
   <optionalbox id="advanced_options" title="Advanced options">
     <switch id="orientation" label="Orientation">