-// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019 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 <GeomAPI_PlanarEdges.h>
#include <GeomAPI_Pln.h>
#include <GeomAPI_ShapeExplorer.h>
+#include <GeomAPI_ShapeIterator.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
#include <GeomAlgoAPI_PaveFiller.h>
#include <GeomAlgoAPI_ShapeTools.h>
#include <GeomAlgoAPI_SketchBuilder.h>
#include <GeomAlgoAPI_WireBuilder.h>
+#include <GeomAlgoAPI_MakeVolume.h>
+#include <GeomAlgoAPI_Tools.h>
#include <GeomValidators_FeatureKind.h>
#include <GeomValidators_ShapeType.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;
}
return true;
}
-//=================================================================================================
-bool BuildPlugin_ValidatorBaseForWire::isNotObligatory(std::string theFeature,
- std::string theAttribute)
-{
- return false;
-}
-
//=================================================================================================
bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
const std::list<std::string>& theArguments,
}
// 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;
}
//=================================================================================================
-bool BuildPlugin_ValidatorBaseForFace::isNotObligatory(std::string theFeature,
- std::string theAttribute)
+bool BuildPlugin_ValidatorBaseForSolids::isValid(
+ const std::shared_ptr<ModelAPI_Feature>& theFeature, const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
{
- return false;
+ // Get base objects list.
+ AttributeSelectionListPtr aSelectionList = theFeature->selectionList(theArguments.front());
+ 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 anOriginalShapes;
+ for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+ if (!aSelection->context().get()) {
+ theError = "Invalid selection.";
+ return false;
+ }
+ GeomShapePtr aShape = aSelection->value();
+ if (!aShape.get())
+ aShape = aSelection->context()->shape();
+ anOriginalShapes.push_back(aShape);
+ }
+
+ std::shared_ptr<GeomAlgoAPI_MakeVolume> anAlgorithm(
+ new GeomAlgoAPI_MakeVolume(anOriginalShapes, false));
+
+ std::string anErr;
+ if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(anAlgorithm, "MakeVolume", anErr)) {
+ theError = anErr;
+ return false;
+ }
+
+ // set of allowed types of results
+ std::set<GeomAPI_Shape::ShapeType> aResultType;
+ std::string aType = theArguments.back();
+ if (aType == "solid")
+ aResultType.insert(GeomAPI_Shape::SOLID);
+ else if (aType == "compsolid") {
+ aResultType.insert(GeomAPI_Shape::COMPSOLID);
+ aResultType.insert(GeomAPI_Shape::SOLID);
+ }
+
+ GeomShapePtr aCompound = anAlgorithm->shape();
+ if (aCompound->shapeType() == GeomAPI_Shape::COMPOUND) {
+ GeomAPI_ShapeIterator anIt(aCompound);
+ GeomShapePtr aFoundSub;
+ for (; anIt.more() && !aFoundSub; anIt.next()) {
+ aFoundSub = anIt.current();
+ if (aResultType.count(aFoundSub->shapeType()) == 0) {
+ theError = "Unable to build a solid";
+ return false;
+ }
+ }
+ if (anIt.more() || !aFoundSub.get()) {
+ theError = "Unable to build a solid";
+ return false;
+ }
+ } else if (aResultType.count(aCompound->shapeType()) == 0) {
+ theError = "Unable to build a solid";
+ return false;
+ }
+ // check the internal faces presence
+ for(GeomAPI_ShapeExplorer aFaces(aCompound, GeomAPI_Shape::FACE); aFaces.more(); aFaces.next()) {
+ if (aFaces.current()->orientation() == GeomAPI_Shape::INTERNAL) {
+ theError = "Internal faces are not allowed in the resulting solid";
+ return false;
+ }
+ }
+
+ return true;
}
+
//=================================================================================================
bool BuildPlugin_ValidatorSubShapesSelection::isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments,
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);
{
// 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);