FeaturesPlugin_RevolutionBoolean.h
FeaturesPlugin_RevolutionCut.h
FeaturesPlugin_RevolutionFuse.h
+ FeaturesPlugin_ValidatorTransform.h
)
SET(PROJECT_SOURCES
FeaturesPlugin_RevolutionBoolean.cpp
FeaturesPlugin_RevolutionCut.cpp
FeaturesPlugin_RevolutionFuse.cpp
+ FeaturesPlugin_ValidatorTransform.cpp
)
SET(XML_RESOURCES
#include <FeaturesPlugin_RevolutionCut.h>
#include <FeaturesPlugin_RevolutionFuse.h>
#include <FeaturesPlugin_Rotation.h>
+#include <FeaturesPlugin_ValidatorTransform.h>
#include <ModelAPI_Session.h>
FeaturesPlugin_Plugin::FeaturesPlugin_Plugin()
{
+ SessionPtr aMgr = ModelAPI_Session::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+ aFactory->registerValidator("FeaturesPlugin_ValidatorTransform",
+ new FeaturesPlugin_ValidatorTransform);
+
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);
}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#include "FeaturesPlugin_ValidatorTransform.h"
+
+#include "ModelAPI_AttributeSelectionList.h"
+#include "ModelAPI_ResultPart.h"
+#include "ModelAPI_ResultBody.h"
+#include "ModelAPI_ResultCompSolid.h"
+#include "ModelAPI_Session.h"
+
+bool FeaturesPlugin_ValidatorTransform::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const
+{
+ bool aValid = true;
+ std::string anAttributeType = theAttribute->attributeType();
+ if (anAttributeType != ModelAPI_AttributeSelectionList::typeId()) {
+ theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
+ return false;
+ }
+
+ std::shared_ptr<ModelAPI_AttributeSelectionList> aCurSelList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+
+ DocumentPtr aDocument = theAttribute->owner()->document();
+ SessionPtr aMgr = ModelAPI_Session::get();
+ bool isPartSetDocument = aDocument == aMgr->moduleDocument();
+
+ std::string anErrorGroupName;
+ for(int i = 0; i < aCurSelList->size() && aValid; i++) {
+ std::shared_ptr<ModelAPI_AttributeSelection> aSelAttribute = aCurSelList->value(i);
+ ResultPtr aResult = aSelAttribute->context();
+ if (isPartSetDocument) // PartSet document: Result Part is valid
+ aValid = aResult->groupName() == ModelAPI_ResultPart::group();
+ else { // Part document: Result CompSolid is valid
+ aValid = aResult->groupName() == ModelAPI_ResultBody::group();
+ if (aValid) {
+ ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
+ aValid = aComp.get() != NULL;
+ }
+ }
+ if (!aValid)
+ anErrorGroupName = aResult->groupName();
+ }
+ if (!aValid) {
+ std::string aResultGroupName = isPartSetDocument ? ModelAPI_ResultPart::group()
+ : ModelAPI_ResultBody::group();
+ theError = "Objects from the " + aResultGroupName +
+ " group can be selected in the " + aDocument->kind() +
+ "document, but an objects from the " + anErrorGroupName +
+ " group is selected.";
+ }
+ return aValid;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: FeaturesPlugin_ValidatorTransform.h
+// Created: 16 Sep 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef FeaturesPlugin_ValidatorTransform_H
+#define FeaturesPlugin_ValidatorTransform_H
+
+#include "ModelAPI_AttributeValidator.h"
+
+/**
+* \ingroup Validators
+* A validator of selection
+*/
+class FeaturesPlugin_ValidatorTransform : public ModelAPI_AttributeValidator
+{
+ public:
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const;
+};
+
+#endif