+
+
+//=================================================================================================
+bool BuildPlugin_ValidatorBaseForVertex::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& /*theArguments*/,
+ Events_InfoMessage& theError) const
+{
+ if (!theAttribute.get()) {
+ theError = "Error: empty selection.";
+ return false;
+ }
+
+ AttributeSelectionListPtr aSelectionList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ if (!aSelectionList.get()) {
+ theError = "Could not get selection list.";
+ return false;
+ }
+
+ for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr aSelectionAttr = aSelectionList->value(anIndex);
+ if (!aSelectionAttr.get()) {
+ theError = "Empty attribute in list.";
+ return false;
+ }
+
+ // Vertex?
+ bool isVertex = false;
+ GeomShapePtr aShape = aSelectionAttr->value();
+ ResultPtr aContext = aSelectionAttr->context();
+ if (!aShape.get() && aContext.get())
+ aShape = aContext->shape();
+ if (aShape.get())
+ isVertex = (aShape->shapeType() == GeomAPI_Shape::VERTEX);
+
+ if (!isVertex) {
+ // Sketch?
+ FeaturePtr aFeature = aSelectionAttr->contextFeature();
+ if (!aFeature.get()) {
+ GeomShapePtr aValue = aSelectionAttr->value();
+ // whole sketch is allowed only
+ if (aContext.get() && !aValue.get()) {
+ aFeature = ModelAPI_Feature::feature(aContext);
+ }
+ }
+
+ if (!aFeature.get()) {
+ theError = "Error: Incorrect selection.";
+ return false;
+ }
+
+ if (aFeature->getKind() != SketchPlugin_Sketch::ID()) {
+ theError = "Error: %1 shape is not allowed for selection.";
+ theError.arg(aFeature->getKind());
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+//=================================================================================================
+bool BuildPlugin_ValidatorExpressionInterpolation::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& /*theArguments*/,
+ Events_InfoMessage& theError) const
+{
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+
+ AttributeStringPtr aStrAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
+ if (!aStrAttr->isInitialized()) {
+ theError = "Attribute \"%1\" is not initialized.";
+ theError.arg(aStrAttr->id());
+ return false;
+ }
+ bool isEmptyExpr = aStrAttr->value().empty();
+ if (isEmptyExpr) {
+ theError = "Expression is empty.";
+ return false;
+ }
+
+ theError = aFeature->string(BuildPlugin_Interpolation::EXPRESSION_ERROR_ID())->value();
+ return theError.empty();
+}