#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
#include <GeomAlgoAPI_Boolean.h>
#include <GeomAlgoAPI_MakeShapeList.h>
FeaturesPlugin_Boolean::TOOL_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
// extrusion works with faces always
aSelection->setSelectionType("SOLID");
+
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), OBJECT_LIST_ID());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TOOL_LIST_ID());
}
//=================================================================================================
// Getting objects.
AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_Boolean::OBJECT_LIST_ID());
- if (anObjectsSelList->size() == 0) {
- return;
- }
for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr = anObjectsSelList->value(anObjectsIndex);
std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
// Getting tools.
AttributeSelectionListPtr aToolsSelList = selectionList(FeaturesPlugin_Boolean::TOOL_LIST_ID());
- if (aToolsSelList->size() == 0) {
- return;
- }
for(int aToolsIndex = 0; aToolsIndex < aToolsSelList->size(); aToolsIndex++) {
std::shared_ptr<ModelAPI_AttributeSelection> aToolAttr = aToolsSelList->value(aToolsIndex);
std::shared_ptr<GeomAPI_Shape> aTool = aToolAttr->value();
switch(aType) {
case GeomAlgoAPI_Boolean::BOOL_CUT:
case GeomAlgoAPI_Boolean::BOOL_COMMON:{
+ if(anObjects.empty() || aTools.empty()) {
+ std::string aFeatureError = "Not enough objects for boolean operation";
+ setError(aFeatureError);
+ return;
+ }
+
// Cut each object with all tools
for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) {
std::shared_ptr<GeomAPI_Shape> anObject = *anObjectsIt;
break;
}
case GeomAlgoAPI_Boolean::BOOL_FUSE: {
+ if(anObjects.empty() && aTools.size() > 1) {
+ anObjects.push_back(aTools.back());
+ aTools.pop_back();
+ }else if(aTools.empty() && anObjects.size() > 1) {
+ aTools.push_back(anObjects.back());
+ anObjects.pop_back();
+ }
+
+ if(anObjects.empty() || aTools.empty()) {
+ std::string aFeatureError = "Not enough objects for boolean operation";
+ setError(aFeatureError);
+ return;
+ }
+
// Fuse all objects and all tools.
GeomAlgoAPI_Boolean aBoolAlgo(anObjects, aTools, aType);
type_choice="Solids"
concealment="true">
<validator id="PartSet_DifferentObjects"/>
- <validator id="GeomValidators_ShapeType" parameters="solid"/>
+ <validator id="GeomValidators_ShapeType" parameters="empty,solid"/>
</multi_selector>
<multi_selector id="tool_objects"
label="Tool object"
type_choice="Solids"
concealment="true" >
<validator id="PartSet_DifferentObjects"/>
- <validator id="GeomValidators_ShapeType" parameters="solid"/>
+ <validator id="GeomValidators_ShapeType" parameters="empty,solid"/>
</multi_selector>
<choice id="bool_type"
label="Type"
string_list="Cut Fuse Common"
default="0"
/>
+ <validator id="GeomValidators_BooleanArguments" parameters="main_objects,tool_objects,bool_type"/>
</source>
SET(PROJECT_HEADERS
GeomValidators.h
+ GeomValidators_BooleanArguments.h
GeomValidators_ConstructionComposite.h
GeomValidators_Face.h
GeomValidators_Positive.h
)
SET(PROJECT_SOURCES
+ GeomValidators_BooleanArguments.cpp
GeomValidators_ConstructionComposite.cpp
GeomValidators_Face.cpp
GeomValidators_Positive.cpp
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_BooleanArguments.h
+// Created: 30 June 2015
+// Author: Dmitry Bobylev
+
+#include <GeomValidators_BooleanArguments.h>
+
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeSelectionList.h>
+
+//=================================================================================================
+bool GeomValidators_BooleanArguments::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::list<std::string>& theArguments) const
+{
+ if(theArguments.size() != 3) {
+ return false;
+ }
+
+ int anObjectsNb = 0, aToolsNb = 0;
+ int anOperationType = 0;
+
+ std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
+
+ std::shared_ptr<ModelAPI_AttributeSelectionList> anAttrSelList = theFeature->selectionList(*anIt);
+ if(anAttrSelList) {
+ anObjectsNb = anAttrSelList->size();
+ }
+ anIt++;
+
+ anAttrSelList = theFeature->selectionList(*anIt);
+ if(anAttrSelList) {
+ aToolsNb = anAttrSelList->size();
+ }
+ anIt++;
+
+ std::shared_ptr<ModelAPI_AttributeInteger> anAttrInt = theFeature->integer(*anIt);
+ if(anAttrInt) {
+ anOperationType = anAttrInt->value();
+ }
+
+ if(anOperationType == 1 && (anObjectsNb + aToolsNb > 1)) {
+ return true;
+ } else if (anOperationType != 1 && anObjectsNb > 0 && aToolsNb > 0) {
+ return true;
+ }
+
+ return false;
+}
+
+//=================================================================================================
+bool GeomValidators_BooleanArguments::isNotObligatory(std::string theFeature, std::string theAttribute)
+{
+ if(theAttribute == "main_objects" || theAttribute == "tool_objects") {
+ return true;
+ }
+
+ return false;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_BooleanArguments.h
+// Created: 30 June 2015
+// Author: Dmitry Bobylev
+
+#ifndef GeomValidators_BooleanArguments_H
+#define GeomValidators_BooleanArguments_H
+
+#include <GeomValidators.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_FeatureValidator.h>
+
+/** \class GeomValidators_BooleanArguments
+ * \ingroup Validators
+ * \brief Validates that boolean operation have enough arguments.
+ */
+class GeomValidators_BooleanArguments : public ModelAPI_FeatureValidator
+{
+public:
+ /** \brief Returns true if feature and/or attributes are valid.
+ * \param[in] theFeature the validated feature.
+ * \param[in] theArguments the arguments in the configuration file for this validator.
+ * \returns true if feature is valid.
+ */
+ GEOMVALIDATORS_EXPORT virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::list<std::string>& theArguments) const;
+
+ /// \return true if the attribute in feature is not obligatory for the feature execution.
+ GEOMVALIDATORS_EXPORT virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
+};
+
+#endif
typedef std::map<std::string, GeomValidators_ShapeType::TypeOfShape> EdgeTypes;
-static EdgeTypes MyEdgeTypes;
GeomValidators_ShapeType::TypeOfShape GeomValidators_ShapeType::shapeType(const std::string& theType)
{
- if (MyEdgeTypes.size() == 0) {
- MyEdgeTypes["vertex"] = Vertex;
- MyEdgeTypes["edge"] = Edge;
- MyEdgeTypes["line"] = Line;
- MyEdgeTypes["circle"] = Circle;
- MyEdgeTypes["solid"] = Solid;
- MyEdgeTypes["face"] = Face;
+ static EdgeTypes MyShapeTypes;
+
+ if (MyShapeTypes.size() == 0) {
+ MyShapeTypes["empty"] = Empty;
+ MyShapeTypes["vertex"] = Vertex;
+ MyShapeTypes["edge"] = Edge;
+ MyShapeTypes["line"] = Line;
+ MyShapeTypes["circle"] = Circle;
+ MyShapeTypes["face"] = Face;
+ MyShapeTypes["solid"] = Solid;
}
std::string aType = std::string(theType.c_str());
- if (MyEdgeTypes.find(aType) != MyEdgeTypes.end())
- return MyEdgeTypes[aType];
+ if (MyShapeTypes.find(aType) != MyShapeTypes.end())
+ return MyShapeTypes[aType];
Events_Error::send("Shape type defined in XML is not implemented!");
return AnyShape;
AttributeSelectionListPtr aListAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
if (aListAttr.get()) {
+ if(aListAttr->size() == 0 && shapeType(theArgument) == Empty) {
+ return true;
+ }
for (int i = 0; i < aListAttr->size(); i++) {
aValid = isValidAttribute(aListAttr->value(i), aShapeType);
if (!aValid) // if at least one attribute is invalid, the result is false
// the edge type
enum TypeOfShape
{
- AnyShape,
+ Empty,
Vertex,
Edge,
Line,
Circle,
- Solid,
Face,
- Compound
+ Solid,
+ Compound,
+ AnyShape
};
public:
#include <GeomValidators_Face.h>
#include <GeomValidators_ConstructionComposite.h>
#include <GeomValidators_ZeroOffset.h>
+#include <GeomValidators_BooleanArguments.h>
#include <ModelAPI_Object.h>
aFactory->registerValidator("GeomValidators_ZeroOffset",
new GeomValidators_ZeroOffset);
+ aFactory->registerValidator("GeomValidators_BooleanArguments",
+ new GeomValidators_BooleanArguments);
+
aFactory->registerValidator("PartSet_SketchEntityValidator",
new PartSet_SketchEntityValidator);