]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fixes for SubShapes feature.
authordbv <dbv@opencascade.com>
Mon, 23 May 2016 10:21:39 +0000 (13:21 +0300)
committerdbv <dbv@opencascade.com>
Tue, 24 May 2016 11:14:34 +0000 (14:14 +0300)
src/BuildPlugin/BuildPlugin_SubShapes.cpp
src/BuildPlugin/BuildPlugin_SubShapes.h
src/BuildPlugin/BuildPlugin_Validators.cpp
src/BuildPlugin/subshapes_widget.xml

index d0e1af5945965adf2f58d3cda1340633c393a7a5..1689fb785000ea4ce43ce1ff7857eabf7f25920d 100644 (file)
@@ -28,8 +28,8 @@ void BuildPlugin_SubShapes::initAttributes()
 {
   data()->addAttribute(BASE_SHAPE_ID(), ModelAPI_AttributeSelection::typeId());
 
-  data()->addAttribute(SUB_SHAPES_ID(), ModelAPI_AttributeSelectionList::typeId());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), SUB_SHAPES_ID());
+  data()->addAttribute(SUBSHAPES_ID(), ModelAPI_AttributeSelectionList::typeId());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), SUBSHAPES_ID());
 }
 
 void BuildPlugin_SubShapes::attributeChanged(const std::string& theID)
@@ -38,7 +38,7 @@ void BuildPlugin_SubShapes::attributeChanged(const std::string& theID)
 
   if(theID == BASE_SHAPE_ID()) {
     AttributeSelectionPtr aShapeAttrSelection = selection(BASE_SHAPE_ID());
-    AttributeSelectionListPtr aSubShapesAttrList = selectionList(SUB_SHAPES_ID());
+    AttributeSelectionListPtr aSubShapesAttrList = selectionList(SUBSHAPES_ID());
     if(!aShapeAttrSelection.get() || !aSubShapesAttrList.get()) {
       return;
     }
@@ -80,7 +80,7 @@ void BuildPlugin_SubShapes::execute()
 {
   // Get base shape and sub-shapes list.
   AttributeSelectionPtr aShapeAttrSelection = selection(BASE_SHAPE_ID());
-  AttributeSelectionListPtr aSubShapesAttrList = selectionList(SUB_SHAPES_ID());
+  AttributeSelectionListPtr aSubShapesAttrList = selectionList(SUBSHAPES_ID());
   if(!aShapeAttrSelection.get() || !aSubShapesAttrList.get()) {
     return;
   }
index 8910f0c0f237da153208e5167a8aa81c9a1eca57..c1f4acc069a4c2da10a8bd9a96a88d22705366db 100644 (file)
@@ -35,10 +35,10 @@ public:
   }
 
   /// Attribute name of sub-shapes.
-  inline static const std::string& SUB_SHAPES_ID()
+  inline static const std::string& SUBSHAPES_ID()
   {
-    static const std::string MY_SUB_SHAPES_ID("sub_shapes");
-    return MY_SUB_SHAPES_ID;
+    static const std::string MY_SUBSHAPES_ID("subshapes");
+    return MY_SUBSHAPES_ID;
   }
 
   /// \return the kind of a feature.
index 4027ff1d89f418f2619364c36a65774b40b2352a..b3ede6d602d88b1c9bfd2610841ceb9d5202a293 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_PaveFiller.h>
+#include <GeomAlgoAPI_ShapeBuilder.h>
 #include <GeomAlgoAPI_ShapeTools.h>
 #include <GeomAlgoAPI_SketchBuilder.h>
 #include <GeomAlgoAPI_WireBuilder.h>
@@ -229,9 +230,9 @@ bool BuildPlugin_ValidatorSubShapesSelection::isValid(const AttributePtr& theAtt
                                                       const std::list<std::string>& theArguments,
                                                       std::string& theError) const
 {
-  if(theArguments.size() != 2) {
+  if(theArguments.size() != 1) {
     Events_Error::send("Error: BuildPlugin_ValidatorSubShapesSelection should be used only with "
-      "2 parameters (ID of base shape; Sketch feature id).");
+      "1 parameter(Sketch feature id).");
     return false;
   }
 
@@ -250,8 +251,9 @@ bool BuildPlugin_ValidatorSubShapesSelection::isValid(const AttributePtr& theAtt
   }
 
   // Get base shape.
+  const std::string aBaseShapeId = "base_shape";
   FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
-  AttributeSelectionPtr aShapeAttrSelection = aFeature->selection(theArguments.front());
+  AttributeSelectionPtr aShapeAttrSelection = aFeature->selection(aBaseShapeId);
 
   if(!aShapeAttrSelection.get()) {
     theError = "Base shape is empty.";
@@ -266,6 +268,10 @@ bool BuildPlugin_ValidatorSubShapesSelection::isValid(const AttributePtr& theAtt
     return false;
   }
 
+  GeomAlgoAPI_ShapeBuilder aBuilder;
+  aBuilder.removeInternal(aBaseShape);
+  aBaseShape = aBuilder.shape();
+
   // If selected shape is wire allow to select only vertices. If face - allow vertices and edges.
   std::set<GeomAPI_Shape::ShapeType> anAllowedTypes;
   switch(aBaseShape->shapeType()) {
@@ -277,18 +283,22 @@ bool BuildPlugin_ValidatorSubShapesSelection::isValid(const AttributePtr& theAtt
   // Check selected shapes.
   GeomValidators_FeatureKind aFeatureKindValidator;
   std::list<std::string> anArguments;
-  anArguments.push_back(theArguments.back());
+  anArguments.push_back(theArguments.front());
   for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
     AttributeSelectionPtr aSelectionAttrInList = aSelectionList->value(anIndex);
     if(!aSelectionAttrInList.get()) {
       theError = "Empty attribute in list.";
       return false;
     }
-    // If context not same check that it is a selection on Sketch.
-    if(aBaseContext != aSelectionAttrInList->context()) {
-      if(!aFeatureKindValidator.isValid(aSelectionAttrInList, anArguments, theError)) {
-        return false;
-      }
+
+    // If context of selection same skip.
+    if(aBaseContext == aSelectionAttrInList->context()) {
+      continue;
+    }
+
+    // Check that it is a selection on Sketch.
+    if(!aFeatureKindValidator.isValid(aSelectionAttrInList, anArguments, theError)) {
+      return false;
     }
 
     // Check shape type.
index 7c9dcb5f924c613e4a0b0ff3cf719d301c9fb950..2548d39c5484ec1270125e3b6dd5d2dceec70cd8 100644 (file)
@@ -8,12 +8,12 @@
                   concealment="true">
     <validator id="GeomValidators_ShapeType" parameters="wire,face"/>
   </shape_selector>
-  <multi_selector id="sub_shapes"
+  <multi_selector id="subshapes"
                   label="Sub-Shapes:"
                   tooltip="Select shapes on sketch to add."
                   type_choice="vertices edges"
                   concealment="true"
                   clear_in_neutral_point="false">
-    <validator id="BuildPlugin_ValidatorSubShapesSelection" parameters="base_shape,Sketch"/>
+    <validator id="BuildPlugin_ValidatorSubShapesSelection" parameters="Sketch"/>
   </multi_selector>
 </source>