ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
aFactory->registerValidator("FeaturesPlugin_ValidatorTransform",
new FeaturesPlugin_ValidatorTransform);
- aFactory->registerValidator("FeaturesPlugin_ValidatorCompositeLauncher",
+ aFactory->registerValidator("FeaturesPlugin_ValidatorCompositeLauncherE",
new FeaturesPlugin_ValidatorCompositeLauncher);
+ aFactory->registerValidator("FeaturesPlugin_ValidatorCompositeLauncher",
+ new FeaturesPlugin_ValidatorCompositeLauncher_);
aFactory->registerValidator("FeaturesPlugin_ValidatorBaseForGeneration",
new FeaturesPlugin_ValidatorBaseForGeneration);
aFactory->registerValidator("FeaturesPlugin_ValidatorPipeLocations",
#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeReference.h>
+#include <GeomValidators_FeatureKind.h>
#include <GeomValidators_ShapeType.h>
//=================================================================================================
bool FeaturesPlugin_ValidatorCompositeLauncher::isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments,
std::string& theError) const
+{
+ if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
+ 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);
+ }
+ return aValid;
+}
+
+//=================================================================================================
+bool FeaturesPlugin_ValidatorCompositeLauncher_::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const
{
FeaturesPlugin_ValidatorBaseForGeneration aBaseValidator;
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"/>
</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="direction_object"
icon=":icons/axis.png"
GeomShapePtr aShape;
getGeomSelection(thePrs, anObject, aShape);
- ModuleBase_Tools::setObject(attributeToValidate(), anObject, aShape, myWorkshop, myIsInValidate);
+ ModuleBase_Tools::setObject(attribute(), anObject, aShape, myWorkshop, myIsInValidate);
return true;
}
}
//********************************************************************
-void ModuleBase_WidgetValidated::storeAttributeValue()
+void ModuleBase_WidgetValidated::storeAttributeValue(const AttributePtr& theAttribute)
{
myIsInValidate = true;
- myAttributeStore->storeAttributeValue(attributeToValidate(), myWorkshop);
+ myAttributeStore->storeAttributeValue(theAttribute, myWorkshop);
}
//********************************************************************
-void ModuleBase_WidgetValidated::restoreAttributeValue(const bool theValid)
+void ModuleBase_WidgetValidated::restoreAttributeValue(const AttributePtr& theAttribute,
+ const bool theValid)
{
myIsInValidate = false;
- myAttributeStore->restoreAttributeValue(attributeToValidate(), myWorkshop);
+ myAttributeStore->restoreAttributeValue(theAttribute, myWorkshop);
}
//********************************************************************
}
//********************************************************************
-AttributePtr ModuleBase_WidgetValidated::attributeToValidate() const
+AttributePtr ModuleBase_WidgetValidated::attribute() const
{
return myFeature->attribute(attributeID());
}
if (getValidState(theValue, aValid)) {
return aValid;
}
-
aValid = isValidSelectionCustom(theValue);
- if (!aValid) {
- storeValidState(theValue, aValid);
- return aValid;
- }
+ if (aValid)
+ aValid = isValidSelectionForAttribute(theValue, attribute());
+
+ storeValidState(theValue, aValid);
+ return aValid;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetValidated::isValidSelectionForAttribute(const ModuleBase_ViewerPrs& theValue,
+ const AttributePtr& theAttribute)
+{
+ bool aValid = false;
// stores the current values of the widget attribute
bool isFlushesActived, isAttributeSetInitializedBlocked;
- blockAttribute(true, isFlushesActived, isAttributeSetInitializedBlocked);
+ blockAttribute(theAttribute, true, isFlushesActived, isAttributeSetInitializedBlocked);
- storeAttributeValue();
+ storeAttributeValue(theAttribute);
// saves the owner value to the widget attribute
aValid = setSelectionCustom(theValue);
if (aValid)
// checks the attribute validity
- aValid = isValidAttribute();
+ aValid = isValidAttribute(theAttribute);
// restores the current values of the widget attribute
- restoreAttributeValue(aValid);
+ restoreAttributeValue(theAttribute, aValid);
- blockAttribute(false, isFlushesActived, isAttributeSetInitializedBlocked);
+ blockAttribute(theAttribute, false, isFlushesActived, isAttributeSetInitializedBlocked);
// In particular case the results are deleted and called as redisplayed inside of this
// highlight-selection, to they must be flushed as soon as possible.
// Example: selection of group-vertices subshapes with shift pressend on body. Without
Events_Loop::loop()->flush(aDeletedEvent);
Events_Loop::loop()->flush(aRedispEvent);
- storeValidState(theValue, aValid);
return aValid;
}
}
//********************************************************************
-bool ModuleBase_WidgetValidated::isValidAttribute() const
+bool ModuleBase_WidgetValidated::isValidAttribute(const AttributePtr& theAttribute) const
{
SessionPtr aMgr = ModelAPI_Session::get();
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
- AttributePtr anAttribute = attributeToValidate();
std::string aValidatorID, anError;
- return aFactory->validate(anAttribute, aValidatorID, anError);
+ return aFactory->validate(theAttribute, aValidatorID, anError);
}
bool ModuleBase_WidgetValidated::isFilterActivated() const
}
//********************************************************************
-void ModuleBase_WidgetValidated::blockAttribute(const bool& theToBlock, bool& isFlushesActived,
+void ModuleBase_WidgetValidated::blockAttribute(const AttributePtr& theAttribute,
+ const bool& theToBlock,
+ bool& isFlushesActived,
bool& isAttributeSetInitializedBlocked)
{
Events_Loop* aLoop = Events_Loop::loop();
DataPtr aData = myFeature->data();
- AttributePtr anAttribute = attributeToValidate();
if (theToBlock) {
// blocks the flush signals to avoid the temporary objects visualization in the viewer
// they should not be shown in order to do not lose highlight by erasing them
isFlushesActived = aLoop->activateFlushes(false);
aData->blockSendAttributeUpdated(true);
- isAttributeSetInitializedBlocked = anAttribute->blockSetInitialized(true);
+ isAttributeSetInitializedBlocked = theAttribute->blockSetInitialized(true);
}
else {
aData->blockSendAttributeUpdated(false);
- anAttribute->blockSetInitialized(isAttributeSetInitializedBlocked);
+ theAttribute->blockSetInitialized(isAttributeSetInitializedBlocked);
aLoop->activateFlushes(isFlushesActived);
}
}
const Config_WidgetAPI* theData);
virtual ~ModuleBase_WidgetValidated();
- /// Checks all widget validator if the owner is valid
+ /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
+ /// next, the attribute's validating. It trying on the give selection to current attribute by
+ /// setting the value inside and calling validators. After this, the previous attribute value is
+ /// restored.The valid/invalid value is cashed.
/// \param theValue a selected presentation in the view
/// \return a boolean value
- bool isValidSelection(const ModuleBase_ViewerPrs& theValue);
+ virtual bool isValidSelection(const ModuleBase_ViewerPrs& theValue);
//! Returns data object by AIS
ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const;
/// \return a boolean value
bool isValidInFilters(const ModuleBase_ViewerPrs& thePrs);
+ /// Checks all attribute validators returns valid. It tries on the given selection
+ /// to current attribute by setting the value inside and calling validators. After this,
+ /// the previous attribute value is restored.The valid/invalid value is cashed.
+ /// \param theValue a selected presentation in the view
+ /// \return a boolean value
+ bool isValidSelectionForAttribute(const ModuleBase_ViewerPrs& theValue,
+ const AttributePtr& theAttribute);
+
/// Retunrs attribute, which should be validated. In default implementation,
/// this is an attribute of ID
/// \return an attribute
- virtual AttributePtr attributeToValidate() const;
+ virtual AttributePtr attribute() const;
/// Creates a backup of the current values of the attribute
/// It should be realized in the specific widget because of different
/// parameters of the current attribute
- virtual void storeAttributeValue();
+ /// \param theAttribute an attribute to be stored
+ virtual void storeAttributeValue(const AttributePtr& theAttribute);
/// Creates a backup of the current values of the attribute
/// It should be realized in the specific widget because of different
/// parameters of the current attribute
+ /// \param theAttribute an attribute to be restored
/// \param theValid a boolean flag, if restore happens for valid parameters
- virtual void restoreAttributeValue(const bool theValid);
+ virtual void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid);
/// Checks the widget validity. By default, it returns true.
/// \param thePrs a selected presentation in the view
bool activateFilters(const bool toActivate);
/// Block the model flush of update and intialization of attribute
+ /// \param theAttribute an attribute of blocking
/// \param theToBlock flag whether the model is blocked or unblocked
/// \param isActive out value if model is blocked, in value if model is unblocked
/// to be used to restore flush state when unblocked
/// \param isAttributeSetInitializedBlocked out value if model is blocked
/// in value if model is unblocked to be used to restore previous state when unblocked
- virtual void blockAttribute(const bool& theToBlock, bool& isFlushesActived,
- bool& isAttributeSetInitializedBlocked);
+ virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
+ bool& isFlushesActived, bool& isAttributeSetInitializedBlocked);
private:
/// Checks the current attibute in all attribute validators
- // \return true if all validators return that the attribute is valid
- bool isValidAttribute() const;
+ /// \param theAttribute an attribute to be validated
+ /// \return true if all validators return that the attribute is valid
+ bool isValidAttribute(const AttributePtr& theAttribute) const;
/// Returns true if the workshop validator filter has been already activated
/// \return boolean value
bool isFilterActivated() const;
+protected:
/// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored
/// \param theValue a viewer presentation
/// \param theValid a valid state
/// \param theValid a valid state
void storeValidState(const ModuleBase_ViewerPrs& theValue, const bool theValid);
+private:
/// Applies AIS context filters to the parameter list. The not approved presentations are
/// removed from the parameters.
/// \param theValues a list of presentations.
}
//********************************************************************
-void PartSet_WidgetMultiSelector::restoreAttributeValue(const bool theValid)
+void PartSet_WidgetMultiSelector::restoreAttributeValue(const AttributePtr& theAttribute,
+ const bool theValid)
{
- ModuleBase_WidgetMultiSelector::restoreAttributeValue(theValid);
+ ModuleBase_WidgetMultiSelector::restoreAttributeValue(theAttribute, theValid);
myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
}
/// It should be realized in the specific widget because of different
/// parameters of the current attribute
/// \param theValid a boolean flag, if restore happens for valid parameters
- virtual void restoreAttributeValue(const bool theValid);
+ virtual void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid);
/// Return an object and geom shape by the viewer presentation
/// \param thePrs a selection
}
//********************************************************************
-void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid)
+void PartSet_WidgetShapeSelector::restoreAttributeValue(const AttributePtr& theAttribute,
+ const bool theValid)
{
- ModuleBase_WidgetShapeSelector::restoreAttributeValue(theValid);
+ ModuleBase_WidgetShapeSelector::restoreAttributeValue(theAttribute, theValid);
myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
}
/// It should be realized in the specific widget because of different
/// parameters of the current attribute
/// \param theValid a boolean flag, if restore happens for valid parameters
- void restoreAttributeValue(const bool theValid);
+ void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid);
protected:
/// A reference to external objects manager
PartSet_Module* theModule,
const Config_WidgetAPI* theData)
: ModuleBase_WidgetSelector(theParent, theModule->workshop(), theData),
- myModule(theModule)
+ myModule(theModule), myIsCustomAttribute(false)
{
myAttributeListID = theData->getProperty("attribute_list_id");
return true;
}
-AttributePtr PartSet_WidgetSketchCreator::attributeToValidate() const
+AttributePtr PartSet_WidgetSketchCreator::attribute() const
{
- return myFeature->attribute(myAttributeListID);
+ AttributePtr anAttribute;
+ if (myIsCustomAttribute)
+ anAttribute = myFeature->attribute(myAttributeListID);
+ else
+ anAttribute = ModuleBase_WidgetSelector::attribute();
+
+ return anAttribute;
+}
+
+//********************************************************************
+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;
+ aValid = isValidSelectionForAttribute(theValue, attribute());
+ myIsCustomAttribute = false;
+ }
+ storeValidState(theValue, aValid);
+ return aValid;
}
void PartSet_WidgetSketchCreator::activateSelectionControl()
{
bool aDone = false;
if (!startSketchOperation(theValues)) {
- ModuleBase_WidgetSelector::setSelection(theValues, theToValidate);
+ myIsCustomAttribute = true;
QList<ModuleBase_ViewerPrs>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
bool aProcessed = false;
for (; anIt != aLast; anIt++) {
if (!theToValidate || isValidInFilters(aValue))
aProcessed = setSelectionCustom(aValue) || aProcessed;
}
+ myIsCustomAttribute = true;
aDone = aProcessed;
if (aProcessed) {
emit valuesChanged();
/// Editing mode depends on mode of current operation. This value is defined by it.
virtual void setEditingMode(bool isEditing);
+ /// Checks all widget validator if the owner is valid. Firstly it checks custom widget validating,
+ /// next, the attribute's validating. It trying on the give selection to current attribute by
+ /// setting the value inside and calling validators. After this, the previous attribute value is
+ /// restored.The valid/invalid value is cashed.
+ /// \param theValue a selected presentation in the view
+ /// \return a boolean value
+ virtual bool isValidSelection(const ModuleBase_ViewerPrs& theValue);
+
/// Check if the current and the parent operations are a composite. If the parent operation contains
/// attribute selection list, the method returns false if it is invalid in this attibute validator
/// \param theWorkshop a current workshop
/// Retunrs attribute, which should be validated. In default implementation,
/// this is an attribute of ID
/// \return an attribute
- virtual AttributePtr attributeToValidate() const;
+ virtual AttributePtr attribute() const;
/// Sets the selection control visible and set the current widget as active in property panel
/// It leads to connect to onSelectionChanged slot
PartSet_Module* myModule;
+ /// Flag if the attribute() should return the attribute list ID or XML attribute
+ /// to store selection and check validation
+ bool myIsCustomAttribute;
+
/// Label of the widget
QLabel* myLabel;
emit showConstraintToggled(aState, theOn);
}
-void PartSet_WidgetSketchLabel::blockAttribute(const bool& theToBlock, bool& isFlushesActived,
+void PartSet_WidgetSketchLabel::blockAttribute(const AttributePtr& theAttribute,
+ const bool& theToBlock, bool& isFlushesActived,
bool& isAttributeSetInitializedBlocked)
{
- ModuleBase_WidgetValidated::blockAttribute(theToBlock, isFlushesActived,
+ ModuleBase_WidgetValidated::blockAttribute(theAttribute, theToBlock, isFlushesActived,
isAttributeSetInitializedBlocked);
// We do not restore the previous state of isAttributeSetInitializedBlocked for each of
// attributes. It it is necessary, these states should be append to the method attributes
myStackWidget->installEventFilter(this);
}
-void PartSet_WidgetSketchLabel::storeAttributeValue()
+void PartSet_WidgetSketchLabel::storeAttributeValue(const AttributePtr& theAttribute)
{
- ModuleBase_WidgetValidated::storeAttributeValue();
+ ModuleBase_WidgetValidated::storeAttributeValue(theAttribute);
}
-void PartSet_WidgetSketchLabel::restoreAttributeValue(const bool theValid)
+void PartSet_WidgetSketchLabel::restoreAttributeValue(const AttributePtr& theAttribute,
+ const bool theValid)
{
- ModuleBase_WidgetValidated::restoreAttributeValue(theValid);
+ ModuleBase_WidgetValidated::restoreAttributeValue(theAttribute, theValid);
// it is not necessary to save the previous plane value because the plane is chosen once
DataPtr aData = feature()->data();
/// Creates a backup of the current values of the attribute
/// It should be realized in the specific widget because of different
/// parameters of the current attribute
- virtual void storeAttributeValue();
+ /// \param theAttribute an attribute to be stored
+ virtual void storeAttributeValue(const AttributePtr& theAttribute);
/// Creates a backup of the current values of the attribute
/// It should be realized in the specific widget because of different
/// parameters of the current attribute
+ /// \param theAttribute an attribute to be restored
/// \param theValid a boolean flag, if restore happens for valid parameters
- virtual void restoreAttributeValue(const bool theValid);
+ virtual void restoreAttributeValue(const AttributePtr& theAttribute,
+ const bool theValid);
/// Fills the attribute with the value of the selected owner
/// \param thePrs a selected owner
/// to be used to restore flush state when unblocked
/// \param isAttributeSetInitializedBlocked out value if model is blocked
/// in value if model is unblocked to be used to restore previous state when unblocked
- virtual void blockAttribute(const bool& theToBlock, bool& isFlushesActived,
+ virtual void blockAttribute(const AttributePtr& theAttribute, const bool& theToBlock,
+ bool& isFlushesActived,
bool& isAttributeSetInitializedBlocked);
/// Set the given wrapped value to the current widget