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",
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;
}
//=================================================================================================
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
2. An existing sketch face or contour. Extrusion will be filled by it.<br />
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:"
2. An existing sketch face or contour. Extrusion will be filled by it.<br />
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"
2. An existing sketch face or contour. Extrusion will be filled by it.<br />
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"
2. An existing sketch face or contour. Extrusion will be filled by it.<br />
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"
2. An existing sketch face or contour. Extrusion will be filled by it.<br />
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"
2. An existing sketch face or contour. Extrusion will be filled by it.<br />
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"
#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
}
}
}
+ 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;
}
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())
aValid = theShape->isSolid() || theShape->isCompSolid() ||
theShape->isCompoundOfSolids();
break;
+ case Shell:
+ aValid = theShape->shapeType() == GeomAPI_Shape::SHELL;
case Compound:
aValid = theShape->isCompound();
break;
Face,
Plane,
Solid,
+ Shell,
Compound,
AnyShape
};
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);
if (!theToValidate || isValidInFilters(aValue))
aProcessed = setSelectionCustom(aValue) || aProcessed;
}
- myIsCustomAttribute = true;
+ myIsCustomAttribute = false;
aDone = aProcessed;
if (aProcessed) {
emit valuesChanged();
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;