X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FFeaturesPlugin%2FFeaturesPlugin_Validators.cpp;h=83ab5ed7515e82e4bd397422b2d8465bb47812ab;hb=658fccce59f75b0cfa7c3f3d45f1ffb295ed24be;hp=0de4d856a96de2bc262914492e50ad51b971cb81;hpb=f259a8b0372f21a7fe65e13456fd23a20126f37c;p=modules%2Fshaper.git diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index 0de4d856a..83ab5ed75 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -12,9 +12,16 @@ #include #include +#include + #include #include +#include +#include +#include +#include + //================================================================================================= bool FeaturesPlugin_ValidatorPipeLocations::isValid(const std::shared_ptr& theFeature, const std::list& theArguments, @@ -83,6 +90,56 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theA return false; } + std::set aSelectedSketches; + std::set aSelectedSketchesFromObjects; + GeomAPI_DataMapOfShapeShape aSelectedWiresFromObjects; + std::string anAttributeType = theAttribute->attributeType(); + if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) { + AttributeSelectionListPtr aListAttr = std::dynamic_pointer_cast(theAttribute); + for(int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) { + AttributeSelectionPtr aSelectionAttr = aListAttr->value(anIndex); + ResultConstructionPtr aContext = std::dynamic_pointer_cast(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; } @@ -143,6 +200,8 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute return true; } } + + return false; } if(!aShape->isEqual(aContextShape)) { @@ -154,8 +213,8 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute // 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::const_iterator anIt = theArguments.cbegin(); theError += *anIt; for(++anIt; anIt != theArguments.cend(); ++anIt) { @@ -246,7 +305,8 @@ bool FeaturesPlugin_ValidatorCanBeEmpty::isValid(const std::shared_ptrcontext(); if(!aContext.get()) { - theError = "Selection attribute \"" + *anArgsIt + "\" can not be empty."; + theError = "Base objects list contains vertex or edge, so attribute \"" + *anArgsIt + + "\" can not be used with default value. Select direction for extrusion."; return false; } @@ -254,7 +314,8 @@ bool FeaturesPlugin_ValidatorCanBeEmpty::isValid(const std::shared_ptr& 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(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(aContext); + if(aConstruction.get()) { + if(aConstruction->isInfinite()) { + theError = "Inifinte objects not acceptable."; + return false; + } + + std::shared_ptr anEdges = std::dynamic_pointer_cast(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