#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeReference.h>
+#include <Events_Error.h>
+
#include <GeomValidators_FeatureKind.h>
#include <GeomValidators_ShapeType.h>
+#include <GeomAPI_DataMapOfShapeShape.h>
+#include <GeomAPI_PlanarEdges.h>
+#include <GeomAPI_ShapeExplorer.h>
+#include <GeomAlgoAPI_WireBuilder.h>
+
//=================================================================================================
bool FeaturesPlugin_ValidatorPipeLocations::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
const std::list<std::string>& theArguments,
return false;
}
+ std::set<ResultConstructionPtr> aSelectedSketches;
+ std::set<ResultConstructionPtr> aSelectedSketchesFromObjects;
+ GeomAPI_DataMapOfShapeShape aSelectedWiresFromObjects;
+ std::string anAttributeType = theAttribute->attributeType();
+ if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
+ AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) {
+ AttributeSelectionPtr aSelectionAttr = aListAttr->value(anIndex);
+ ResultConstructionPtr aContext = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aSelectionAttr->context());
+ if(!aContext.get()) {
+ // It is not a result construction, continue.
+ continue;
+ }
+
+ GeomShapePtr aShape = aSelectionAttr->value();
+ GeomShapePtr aContextShape = aContext->shape();
+ if(!aShape.get()) {
+ // Whole sketch selected.
+ if(aSelectedSketchesFromObjects.find(aContext) != aSelectedSketchesFromObjects.cend()) {
+ theError = "Object from this sketch is already selected. Sketch is not allowed for selection.";
+ return false;
+ }
+
+ aSelectedSketches.insert(aContext);
+ } else {
+ // Object from sketch selected.
+ if(aSelectedSketches.find(aContext) != aSelectedSketches.cend()) {
+ theError = "Whole sketch with this object is already selected. Don't allow to select this object.";
+ return false;
+ }
+
+ for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::WIRE); anExp.more(); anExp.next()) {
+ GeomShapePtr aWire = anExp.current();
+ if(aWire->orientation() != GeomAPI_Shape::FORWARD) {
+ theError = "Wire with wrong orientation selected.";
+ return false;
+ }
+
+ if(aSelectedWiresFromObjects.isBound(aWire)) {
+ theError = "Objects with such wire already selected. Don't allow to select this object.";
+ return false;
+ }
+
+ aSelectedWiresFromObjects.bind(aWire, aWire);
+ aSelectedSketchesFromObjects.insert(aContext);
+ }
+ }
+ }
+ }
+
return true;
}
return true;
}
}
+
+ return false;
}
if(!aShape->isEqual(aContextShape)) {
// Check that object is a shape with allowed type.
GeomValidators_ShapeType aShapeTypeValidator;
if(!aShapeTypeValidator.isValid(anAttr, theArguments, theError)) {
- theError = "Selected shape has unacceptable type. Acceptable types are: faces or wires on sketch, \
- whole sketch(if it has at least one face), and whole objects with shape types: ";
+ theError = "Selected shape has unacceptable type. Acceptable types are: faces or wires on sketch, "
+ "whole sketch(if it has at least one face), and whole objects with shape types: ";
std::list<std::string>::const_iterator anIt = theArguments.cbegin();
theError += *anIt;
for(++anIt; anIt != theArguments.cend(); ++anIt) {
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;
}
//=================================================================================================
const std::list<std::string>& theArguments,
std::string& theError) const
{
- if(theArguments.size() != 5 && theArguments.size() != 6) {
- theError = "Validator should be used with 6 parameters for extrusion and with 5 for revolution.";
+ if(theArguments.size() != 2) {
+ theError = "Validator should be used with 2 parameters for extrusion.";
return false;
}
std::list<std::string>::const_iterator anArgsIt = theArguments.begin(), aLast = theArguments.end();
- std::string aSelectedMethod;
- if(theFeature->string(*anArgsIt)) {
- aSelectedMethod = theFeature->string(*anArgsIt)->value();
- }
- ++anArgsIt;
- std::string aCreationMethod = *anArgsIt;
- ++anArgsIt;
-
AttributePtr aCheckAttribute = theFeature->attribute(*anArgsIt);
++anArgsIt;
return true;
}
- if(aSelectedMethod == aCreationMethod) {
- ++anArgsIt;
- ++anArgsIt;
+ AttributeSelectionPtr aSelAttr = theFeature->selection(*anArgsIt);
+ if(!aSelAttr.get()) {
+ theError = "Could not get selection attribute \"" + *anArgsIt + "\".";
+ return false;
}
- for(; anArgsIt != theArguments.cend(); ++anArgsIt) {
- AttributeSelectionPtr aSelAttr = theFeature->selection(*anArgsIt);
- if(!aSelAttr.get()) {
- theError = "Could not get selection attribute \"" + *anArgsIt + "\".";
+ GeomShapePtr aShape = aSelAttr->value();
+ if(!aShape.get()) {
+ ResultPtr aContext = aSelAttr->context();
+ if(!aContext.get()) {
+ theError = "Base objects list contains vertex or edge, so attribute \"" + *anArgsIt
+ + "\" can not be used with default value. Select direction for extrusion.";
return false;
}
- GeomShapePtr aShape = aSelAttr->value();
- if(!aShape.get()) {
- ResultPtr aContext = aSelAttr->context();
- if(!aContext.get()) {
- theError = "Selection attribute \"" + *anArgsIt + "\" can not be empty.";
- return false;
- }
-
- aShape = aContext->shape();
- }
+ aShape = aContext->shape();
+ }
- if(!aShape.get()) {
- theError = "Selection attribute \"" + *anArgsIt + "\" can not be empty.";
- return false;
- }
+ if(!aShape.get()) {
+ theError = "Base objects list contains vertex or edge, so attribute \"" + *anArgsIt
+ + "\" can not be used with default value. Select direction for extrusion.";
+ return false;
}
return true;
return true;
}
+
+//=================================================================================================
+bool FeaturesPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const
+{
+ // Get base objects list.
+ if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
+ Events_Error::send("Validator does not support attribute type \"" + theAttribute->attributeType()
+ + "\"\n Only \"" + ModelAPI_AttributeSelectionList::typeId() + "\" supported.");
+ return false;
+ }
+ AttributeSelectionListPtr aSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ if(!aSelectionList.get()) {
+ theError = "Could not get selection list.";
+ return false;
+ }
+ if(aSelectionList->size() == 0) {
+ theError = "Empty selection list.";
+ return false;
+ }
+
+ // Collect base shapes.
+ ListOfShape aListOfShapes;
+ for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+ if(!aSelection.get()) {
+ theError = "Could not get selection.";
+ return false;
+ }
+ ResultPtr aContext = aSelection->context();
+ if(!aContext.get()) {
+ theError = "Attribute have empty context.";
+ return false;
+ }
+
+ GeomShapePtr aShape = aSelection->value();
+ GeomShapePtr aContextShape = aContext->shape();
+ if(!aShape.get()) {
+ aShape = aContextShape;
+ }
+ if(!aShape.get()) {
+ theError = "Empty shape selected.";
+ return false;
+ }
+
+ // Check that shape has acceptable type.
+ if(aShape->shapeType() != GeomAPI_Shape::EDGE && aShape->shapeType() != GeomAPI_Shape::WIRE) {
+ theError = "Selected shape has wrong type. Only edges and wires acceptable.";
+ return false;
+ }
+
+ // Check that it is edge on sketch.
+ ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+ if(aConstruction.get()) {
+ if(aConstruction->isInfinite()) {
+ theError = "Inifinte objects not acceptable.";
+ return false;
+ }
+
+ std::shared_ptr<GeomAPI_PlanarEdges> anEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aContextShape);
+ if(!anEdges.get()) {
+ // It is not an edge on the sketch.
+ // Check that it is not local selection.
+ if(!aShape->isEqual(aContextShape)) {
+ // Local selection on body does not allowed.
+ theError = "Selected shape is in the local selection. Only global selection is allowed.";
+ return false;
+ }
+ }
+ }
+
+ aListOfShapes.push_back(aShape);
+ }
+
+ // Create wire.
+ GeomShapePtr aWire = GeomAlgoAPI_WireBuilder::wire(aListOfShapes);
+ if(!aWire.get()) {
+ theError = "Result wire empty. Probably it has disconnected edges or non-manifold.";
+ return false;
+ }
+
+ return true;
+}
\ No newline at end of file