-// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2020 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "BuildPlugin_Validators.h"
#include <GeomValidators_FeatureKind.h>
#include <GeomValidators_ShapeType.h>
+#include <SketchPlugin_Sketch.h>
+
#include <Events_InfoMessage.h>
//=================================================================================================
std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
if(aConstruction.get()) {
if(aConstruction->isInfinite()) {
- theError = "Inifinte objects not acceptable.";
+ theError = "Infinite objects not acceptable.";
return false;
}
-
- std::shared_ptr<GeomAPI_PlanarEdges> anEdges =
- std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aContextShape);
- if(anEdges.get()) {
- if(aShape->isEqual(aContextShape)) {
- // It is whole sketch.
- return false;
- }
-
- continue;
- }
}
}
Events_InfoMessage& theError) const
{
// Get attribute.
- if(theArguments.size() != 1) {
- std::string aMsg = "Error: BuildPlugin_ValidatorBaseForWire should be used only "
- "with 1 parameter (ID of base objects list).";
- Events_InfoMessage("BuildPlugin_Validators", aMsg).send();
- return false;
- }
AttributeSelectionListPtr aSelectionList = theFeature->selectionList(theArguments.front());
if(!aSelectionList.get()) {
theError = "Empty attribute \"%1\".";
return false;
}
+ GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::shapeTypeByStr(theArguments.back());
// Collect base shapes.
ListOfShape aListOfShapes;
for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
GeomShapePtr aShape = aSelection->value();
- if(!aShape.get()) {
- if (aSelection->context().get())
- aShape = aSelection->context()->shape();
- }
- if (aShape.get())
+ ResultPtr aContext = aSelection->context();
+ if (!aShape.get() && aContext.get())
+ aShape = aContext->shape();
+
+ bool isProper = aShape.get() &&
+ (aShape->shapeType() == GeomAPI_Shape::EDGE || aShape->shapeType() == aShapeType);
+
+ if (isProper)
aListOfShapes.push_back(aShape);
+ else {
+ // is it a sketch?
+ FeaturePtr aFeature = aSelection->contextFeature();
+ if (!aFeature.get()) {
+ GeomShapePtr aValue = aSelection->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;
+ }
+ }
}
- // 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;
+ if (aShapeType == GeomAPI_Shape::WIRE) {
+ // Create wire.
+ GeomShapePtr aWire = GeomAlgoAPI_WireBuilder::wire(aListOfShapes);
+ if (!aWire.get() && !aListOfShapes.empty()) {
+ theError = "Result wire empty. Probably it has disconnected edges or non-manifold.";
+ return false;
+ }
}
return true;
}
aShape = aSelection->context()->shape();
}
- if (aShape->shapeType() == GeomAPI_Shape::FACE) {
+ ResultConstructionPtr aSketchRes =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aSelection->context());
+
+ if (aShape->shapeType() == GeomAPI_Shape::FACE ||
+ (!aSelection->value() && aSketchRes && aSketchRes->facesNum() > 0)) {
// skip faces exploding
hasFaces = true;
continue;
}
GeomShapePtr aSectedEdges = aPaveFiller.shape();
- int anEdgesNum = 0;
+ size_t anEdgesNum = 0;
for(GeomAPI_ShapeExplorer
anExp(aSectedEdges, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
anEdgesNum++;
}
// Check that selected objects have closed contours.
- ListOfShape aFaces;
- GeomAlgoAPI_SketchBuilder::createFaces(aPln->location(), aPln->xDirection(),
- aPln->direction(), anEdges, aFaces);
+ GeomAlgoAPI_SketchBuilder aBuilder(aPln, anEdges);
+ const ListOfShape& aFaces = aBuilder.faces();
if(aFaces.empty()) {
theError = "Selected objects do not generate closed contour.";
return false;
Events_InfoMessage& theError) const
{
if(theArguments.size() != 1) {
+ // LCOV_EXCL_START
std::string aMsg = "Error: BuildPlugin_ValidatorSubShapesSelection should be used only with "
"1 parameter(Sketch feature id).";
Events_InfoMessage("BuildPlugin_Validators", aMsg).send();
return false;
+ // LCOV_EXCL_STOP
}
// Get base objects list.
if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
+ // LCOV_EXCL_START
std::string aMsg =
"Error: BuildPlugin_ValidatorSubShapesSelection does not support attribute type \""
"%1\"\n Only \"%2\" supported.";
Events_InfoMessage("BuildPlugin_Validators", aMsg).
arg(theAttribute->attributeType()).arg(ModelAPI_AttributeSelectionList::typeId()).send();
return false;
+ // LCOV_EXCL_STOP
}
AttributeSelectionListPtr aSelectionList =
std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
//=================================================================================================
bool BuildPlugin_ValidatorFillingSelection::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments,
- Events_InfoMessage& theError) const
+ const std::list<std::string>& /*theArguments*/,
+ Events_InfoMessage& theError) const
{
// Get base objects list.
if (theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
+ // LCOV_EXCL_START
std::string aMsg =
"Error: BuildPlugin_ValidatorFillingSelection does not support attribute type \""
"%1\"\n Only \"%2\" supported.";
Events_InfoMessage("BuildPlugin_Validators", aMsg).
arg(theAttribute->attributeType()).arg(ModelAPI_AttributeSelectionList::typeId()).send();
return false;
+ // LCOV_EXCL_STOP
}
AttributeSelectionListPtr aSelectionList =
std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
return false;
}
- FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
+ //FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
// Check selected shapes.
for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
return true;
}
+
+
+//=================================================================================================
+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;
+}