]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1343. Improvement of Extrusion and Revolution operations: sketch creator setSe...
authornds <nds@opencascade.com>
Tue, 5 Apr 2016 11:54:49 +0000 (14:54 +0300)
committerdbv <dbv@opencascade.com>
Wed, 6 Apr 2016 10:25:51 +0000 (13:25 +0300)
14 files changed:
src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp
src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
src/FeaturesPlugin/FeaturesPlugin_Validators.h
src/FeaturesPlugin/extrusion_widget.xml
src/FeaturesPlugin/extrusioncut_widget.xml
src/FeaturesPlugin/extrusionfuse_widget.xml
src/FeaturesPlugin/revolution_widget.xml
src/FeaturesPlugin/revolutioncut_widget.xml
src/FeaturesPlugin/revolutionfuse_widget.xml
src/GeomValidators/GeomValidators_FeatureKind.cpp
src/GeomValidators/GeomValidators_ShapeType.cpp
src/GeomValidators/GeomValidators_ShapeType.h
src/PartSet/PartSet_WidgetSketchCreator.cpp
src/PartSet/PartSet_WidgetSketchCreator.h

index b5f0d694483b16410a51c943fdc8218aaf6d6a21..1de58f332c830f1e5e033d01e3f8cb11afdf55ae 100644 (file)
@@ -36,10 +36,8 @@ FeaturesPlugin_Plugin::FeaturesPlugin_Plugin()
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
   aFactory->registerValidator("FeaturesPlugin_ValidatorTransform",
                               new FeaturesPlugin_ValidatorTransform);
-  aFactory->registerValidator("FeaturesPlugin_ValidatorCompositeLauncherE",
-                              new FeaturesPlugin_ValidatorCompositeLauncher);
   aFactory->registerValidator("FeaturesPlugin_ValidatorCompositeLauncher",
-                              new FeaturesPlugin_ValidatorCompositeLauncher_);
+                              new FeaturesPlugin_ValidatorCompositeLauncher);
   aFactory->registerValidator("FeaturesPlugin_ValidatorBaseForGeneration",
                               new FeaturesPlugin_ValidatorBaseForGeneration);
   aFactory->registerValidator("FeaturesPlugin_ValidatorPipeLocations",
index 1470d03538a6c14b6f10cd1ca688f9594e04d3fc..2230d9eb2458939a525a01b8937d849a06be5e27 100644 (file)
@@ -181,43 +181,40 @@ bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theA
     theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
     return false;
   }
-
-  bool aValid = true;
-  GeomValidators_FeatureKind* aValidator = new GeomValidators_FeatureKind();
-  // check whether the selection is on the sketch
-  bool aFeatureKindValid = aValidator->isValid(theAttribute, theArguments, theError);
-  if (!aFeatureKindValid) {
-    // check if selection has Face selected
-    GeomValidators_ShapeType* aShapeType = new GeomValidators_ShapeType();
-    std::list<std::string> anArguments;
-    anArguments.push_back("face");
-    aValid = aShapeType->isValid(theAttribute, anArguments, theError);
+  if (theArguments.size() != 2) {
+    theError = "Wrong parameters in XML definition for " + theAttribute->attributeType() + " type";
+    return false;
   }
-  return aValid;
-}
-
-//=================================================================================================
-bool FeaturesPlugin_ValidatorCompositeLauncher_::isValid(const AttributePtr& theAttribute,
-                                                        const std::list<std::string>& theArguments,
-                                                        std::string& theError) const
-{
-  FeaturesPlugin_ValidatorBaseForGeneration aBaseValidator;
-
-  if(aBaseValidator.isValid(theAttribute, theArguments, theError)) {
-    return true;
+  // first argument is for the base attribute, second - for skipping feature kind
+  std::list<std::string>::const_iterator anIt = theArguments.begin();
+  std::string aBaseAttributeId = *anIt;
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+  AttributePtr aBaseAttribute = aFeature->attribute(aBaseAttributeId);
+  if (!aBaseAttribute.get()) {
+    theError = "Wrong parameters in XML definition for " + theAttribute->attributeType() + " type";
+    return false;
   }
+  if (aBaseAttribute->isInitialized()) // when base list of composite feature is already filled,
+    // this validator is not necessary anymore
+    return true;
 
-  // Check that face selected.
-  GeomValidators_ShapeType aShapeType;
+  anIt++;
+  std::string aFeatureAttributeKind = *anIt;
+  GeomValidators_FeatureKind* aValidator = new GeomValidators_FeatureKind();
+  // check whether the selection is on the sketch
   std::list<std::string> anArguments;
-  anArguments.push_back("face");
-  if(aShapeType.isValid(theAttribute, anArguments, theError)) {
-    return true;
-  }
+  anArguments.push_back(aFeatureAttributeKind);
 
-  theError = "Selected shape is not suitable for this operation";
+  bool aFeatureKind = aValidator->isValid(theAttribute, theArguments, theError);
+  bool aPlanarFace = false;
+  // check if selection has Face selected
+  GeomValidators_ShapeType* aShapeType = new GeomValidators_ShapeType();
+  anArguments.clear();
+  anArguments.push_back("face");
+  aPlanarFace = aShapeType->isValid(theAttribute, anArguments, theError);
 
-  return false;
+  bool aValid = !aFeatureKind && aPlanarFace;
+  return aValid;
 }
 
 //=================================================================================================
index 87bd3228d34329ed8f8fbde3b47fa816c50bcfa1..e02b2ee63c2c15055cfb440472066c34ea5cedc2 100644 (file)
@@ -64,21 +64,6 @@ public:
                         std::string& theError) const;
 };
 
-/// \class FeaturesPlugin_ValidatorCompositeLauncher
-/// \ingroup Validators
-/// \brief A validator for selection at composite feature start
-class FeaturesPlugin_ValidatorCompositeLauncher_: public ModelAPI_AttributeValidator
-{
-public:
-  //! Returns true if attribute has selection type listed in the parameter arguments.
-  //! \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,
-                        std::string& theError) const;
-};
-
 /// \class FeaturesPlugin_ValidatorCanBeEmpty
 /// \ingroup Validators
 /// \brief A validator for extrusion direction attribute and bounding planes for extrusion and
index 350cac0220da192b355c1dba2cd6d97e4ae324dd..4c94677a107547fcc56ada58d9d69cf9dfcc57ea 100644 (file)
@@ -8,7 +8,7 @@
 2. An existing sketch face or contour. Extrusion will be filled by it.&lt;br /&gt;
 3. An existing result shape of kind: wires/edge/vertices.Extrusion will be filled by it."
                    shape_types="faces objects">
-    <validator id="FeaturesPlugin_ValidatorCompositeLauncherE" parameters="Sketch"/>
+    <validator id="FeaturesPlugin_ValidatorCompositeLauncher" parameters="base,Sketch"/>
   </sketch_launcher>
   <composite_multi_selector id="base"
                             label="Base objects:"
index 1f894d22344227ac2f139042c2a8434e87bcd6ee..1e13dfa862c8b94b4775edc75ec9063e6c47acd3 100755 (executable)
@@ -9,13 +9,14 @@
 2. An existing sketch face or contour. Extrusion will be filled by it.&lt;br /&gt;
 3. An existing result shape of kind: wires/edge/vertices.Extrusion will be filled by it."
       shape_types="face objects">
+      <validator id="FeaturesPlugin_ValidatorCompositeLauncher" parameters="base,Sketch"/>
     </sketch_launcher>
     <composite_multi_selector id="base"
       label="Select a sketch face"
       icon=":icons/sketch.png"
       tooltip="Select a sketch face"
       type_choice="Faces Objects">
-      <validator id="FeaturesPlugin_ValidatorCompositeLauncher" parameters="face,shell"/>
+      <validator id="FeaturesPlugin_ValidatorBaseForGeneration" parameters="face,shell"/>
     </composite_multi_selector>
     <shape_selector id="direction_object"
                     icon=":icons/axis.png"
index eacd36c65859dd21351f2189c578b0c2f0b61969..cf1e6dfcf9165e249d0bad4c8512875e37fb465a 100644 (file)
@@ -9,13 +9,14 @@
 2. An existing sketch face or contour. Extrusion will be filled by it.&lt;br /&gt;
 3. An existing result shape of kind: wires/edge/vertices.Extrusion will be filled by it."
       shape_types="face objects">
+      <validator id="FeaturesPlugin_ValidatorCompositeLauncher" parameters="base,Sketch"/>
     </sketch_launcher>
     <composite_multi_selector id="base"
       label="Select a sketch face"
       icon=":icons/sketch.png"
       tooltip="Select a sketch face"
       type_choice="Faces Objects">
-      <validator id="FeaturesPlugin_ValidatorCompositeLauncher" parameters="vertex,edge,wire,face,shell"/>
+      <validator id="FeaturesPlugin_ValidatorBaseForGeneration" parameters="vertex,edge,wire,face,shell"/>
     </composite_multi_selector>
     <shape_selector id="direction_object"
                     icon=":icons/axis.png"
index 78df77f664df63feba665e15158973b3da4f0f9c..c6c50d62cb5b62dc71e7256aaa84c986861a18dc 100644 (file)
@@ -8,12 +8,13 @@
 2. An existing sketch face or contour. Extrusion will be filled by it.&lt;br /&gt;
 3. An existing result shape of kind: wires/edge/vertices.Extrusion will be filled by it."
                    shape_types="faces objects">
+    <validator id="FeaturesPlugin_ValidatorCompositeLauncher" parameters="base,Sketch"/>
   </sketch_launcher>
   <composite_multi_selector id="base"
                             label="Base objects:"
                             tooltip="Select a base objects"
                             type_choice="faces objects">
-    <validator id="FeaturesPlugin_ValidatorCompositeLauncher" parameters="vertex,edge,wire,face,shell"/>
+    <validator id="FeaturesPlugin_ValidatorBaseForGeneration" parameters="vertex,edge,wire,face,shell"/>
   </composite_multi_selector>
   <shape_selector id="axis_object"
                   icon=":icons/axis.png"
index d0ad1d37a590065c6223e62aead76617f0919511..9c8ab5febcf5ece4a24b84e464acd6facb68fcab 100644 (file)
@@ -9,13 +9,14 @@
 2. An existing sketch face or contour. Extrusion will be filled by it.&lt;br /&gt;
 3. An existing result shape of kind: wires/edge/vertices.Extrusion will be filled by it."
       shape_types="face objects">
+      <validator id="FeaturesPlugin_ValidatorCompositeLauncher" parameters="base,Sketch"/>
     </sketch_launcher>
     <composite_multi_selector id="base"
       label="Select a sketch face"
       icon=":icons/sketch.png"
       tooltip="Select a sketch face"
       type_choice="Faces Objects">
-      <validator id="FeaturesPlugin_ValidatorCompositeLauncher" parameters="face,shell"/>
+      <validator id="FeaturesPlugin_ValidatorBaseForGeneration" parameters="face,shell"/>
     </composite_multi_selector>
     <shape_selector id="axis_object"
                     icon=":icons/axis.png"
index 56a417a9ba34adb4bb6cb1f12b767c6761629260..baa883f27f03b0c0ed8bd54fe809f03f3a0d5bba 100644 (file)
@@ -9,13 +9,14 @@
 2. An existing sketch face or contour. Extrusion will be filled by it.&lt;br /&gt;
 3. An existing result shape of kind: wires/edge/vertices.Extrusion will be filled by it."
       shape_types="face objects">
+      <validator id="FeaturesPlugin_ValidatorCompositeLauncher" parameters="base,Sketch"/>
     </sketch_launcher>
     <composite_multi_selector id="base"
       label="Select a sketch face"
       icon=":icons/sketch.png"
       tooltip="Select a sketch face"
       type_choice="Faces Objects">
-      <validator id="FeaturesPlugin_ValidatorCompositeLauncher" parameters="vertex,edge,wire,face,shell"/>
+      <validator id="FeaturesPlugin_ValidatorBaseForGeneration" parameters="vertex,edge,wire,face,shell"/>
     </composite_multi_selector>
     <shape_selector id="axis_object"
                     icon=":icons/axis.png"
index 3ae8200825ad8bfc31ff61b7f77099efd3d6eeb9..9c663a1f7984925943fc3daa2b6c2f2a256ac018 100755 (executable)
@@ -9,6 +9,7 @@
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_Object.h>
 
 #define DEBUG_EXTRUSION_INVALID_SKETCH
@@ -102,6 +103,21 @@ bool GeomValidators_FeatureKind::isValid(const AttributePtr& theAttribute,
       }
     }
   }
+  if (anAttributeType == ModelAPI_AttributeReference::typeId()) {
+    AttributeReferencePtr aRefAttr = 
+                      std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
+    ObjectPtr anObject = aRefAttr->value();
+    // a context of the selection attribute is a feature result. It can be a case when the result
+    // of the feature is null, e.g. the feature is modified and has not been executed yet.
+    // The validator returns an invalid result here. The case is an extrusion built on a sketch
+    // feature. A new sketch element creation leads to an empty result.
+    if (!anObject.get())
+      isSketchEntities = false;
+    else {
+      FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+      isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end();
+    }
+  }
   if (!isSketchEntities) {
     theError = "It refers to feature, which kind is not in the list: " + anEntityKindsStr;
   }
index 5ad27fc3824c0e5ef0615ba2be6817c0f2ed1b7a..e6a96f355bb490644c195c0154242df37bcd2b9c 100644 (file)
@@ -34,6 +34,7 @@ GeomValidators_ShapeType::TypeOfShape GeomValidators_ShapeType::shapeType(const
     MyShapeTypes["face"]   = Face;
     MyShapeTypes["solid"]  = Solid;
     MyShapeTypes["plane"]  = Plane;
+    MyShapeTypes["shell"]  = Shell;
   }
   std::string aType = std::string(theType.c_str());
   if (MyShapeTypes.find(aType) != MyShapeTypes.end())
@@ -220,6 +221,8 @@ bool GeomValidators_ShapeType::isValidShape(const GeomShapePtr theShape,
       aValid = theShape->isSolid() || theShape->isCompSolid() ||
                theShape->isCompoundOfSolids();
       break;
+    case Shell:
+      aValid = theShape->shapeType() == GeomAPI_Shape::SHELL;
     case Compound:
       aValid = theShape->isCompound();
       break;
index 50be8a5ec16eca8a4d719278af55c6f3f2a21c85..93349a5e54881852d48324e63fcd2fcf0b6481dc 100644 (file)
@@ -35,6 +35,7 @@ class GeomValidators_ShapeType : public ModelAPI_AttributeValidator
     Face,
     Plane,
     Solid,
+    Shell,
     Compound,
     AnyShape
   };
index c6a0ebb08dea3182e492b3f57c3da729529b94ac..48de5bdbdbbff55477c3f4e178a4e00ca97cd993 100644 (file)
@@ -129,21 +129,38 @@ AttributePtr PartSet_WidgetSketchCreator::attribute() const
 bool PartSet_WidgetSketchCreator::isValidSelection(const ModuleBase_ViewerPrs& theValue)
 {
   bool aValid = false;
-  if (getValidState(theValue, aValid)) {
-    return aValid;
-  }
-  // check selection to create new sketh (XML current attribute)
-  aValid = isValidSelectionForAttribute(theValue, attribute());
-  if (!aValid) {
-    // check selection to fill list attribute (myAttributeListID)
-    myIsCustomAttribute = true;
+  if (myIsCustomAttribute) {
+    // check only suiting of the value to custom attribute (myAttributeListID)
+    // do not cash of validation to avoid using states, stored for XML attribute
+    // there is an alternative is to call clearValidatedCash() in setSelection()
     aValid = isValidSelectionForAttribute(theValue, attribute());
-    myIsCustomAttribute = false;
+  }
+  else { /// if the validated attribute is already custom
+    if (getValidState(theValue, aValid)) {
+      return aValid;
+    }
+    aValid = isValidSelectionCustom(theValue);
+    if (!aValid)
+      // check selection to create new sketh (XML current attribute)
+      aValid = isValidSelectionForAttribute(theValue, attribute());
+    if (!aValid) {
+      // check selection to fill list attribute (myAttributeListID)
+      bool isCustomAttribute = myIsCustomAttribute;
+      myIsCustomAttribute = true;
+      aValid = isValidSelectionForAttribute(theValue, attribute());
+      myIsCustomAttribute = isCustomAttribute;
+    }
   }
   storeValidState(theValue, aValid);
   return aValid;
 }
 
+//********************************************************************
+bool PartSet_WidgetSketchCreator::isValidSelectionCustom(const ModuleBase_ViewerPrs& theValue)
+{
+  return PartSet_WidgetSketchLabel::canFillSketch(theValue);
+}
+
 void PartSet_WidgetSketchCreator::activateSelectionControl()
 {
   setVisibleSelectionControl(true);
@@ -286,7 +303,7 @@ bool PartSet_WidgetSketchCreator::setSelection(QList<ModuleBase_ViewerPrs>& theV
       if (!theToValidate || isValidInFilters(aValue))
         aProcessed = setSelectionCustom(aValue) || aProcessed;
     }
-    myIsCustomAttribute = true;
+    myIsCustomAttribute = false;
     aDone = aProcessed;
     if (aProcessed) {
       emit valuesChanged();
index 8ccb24b25df4c4397b739c0f07d0912f2c834a1f..a53166444448a22d198a1c5ac495bab356046d09 100644 (file)
@@ -77,6 +77,11 @@ public:
   static bool canCommitCurrentSketch(ModuleBase_IWorkshop* theWorkshop);
 
 protected:
+  /// Checks whether the selection presentation contains preview planes
+  /// \param theValue a selection information
+  /// \return a boolean value
+  virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& theValue);
+
   /// Saves the internal parameters to the given feature
   /// \return True in success
   virtual bool storeValueCustom() const;