if(!aShapeAttrSelection.get() || !aSubShapesAttrList.get()) {
return;
}
- ResultPtr aContext = aShapeAttrSelection->context();
aSubShapesAttrList->clear();
+ ResultPtr aContext = aShapeAttrSelection->context();
+
GeomShapePtr aBaseShape = aShapeAttrSelection->value();
if(!aBaseShape.get()) {
return;
// Copy sub-shapes from list to new shape.
if(!aShapesToAdd.empty()) {
- aBuilder.add(aResultShape, aShapesToAdd);
+ aBuilder.addInternal(aResultShape, aShapesToAdd);
aResultShape = aBuilder.shape();
}
FeaturesPlugin_RevolutionFuse.h
FeaturesPlugin_ValidatorTransform.h
FeaturesPlugin_Validators.h
+ FeaturesPlugin_RemoveSubShapes.h
)
SET(PROJECT_SOURCES
FeaturesPlugin_RevolutionFuse.cpp
FeaturesPlugin_ValidatorTransform.cpp
FeaturesPlugin_Validators.cpp
+ FeaturesPlugin_RemoveSubShapes.cpp
)
SET(XML_RESOURCES
placement_widget.xml
intersection_widget.xml
pipe_widget.xml
+ remove_subshapes_widget.xml
)
INCLUDE_DIRECTORIES(
#include <FeaturesPlugin_Partition.h>
#include <FeaturesPlugin_Pipe.h>
#include <FeaturesPlugin_Placement.h>
+#include <FeaturesPlugin_RemoveSubShapes.h>
#include <FeaturesPlugin_Revolution.h>
#include <FeaturesPlugin_RevolutionCut.h>
#include <FeaturesPlugin_RevolutionFuse.h>
new FeaturesPlugin_ValidatorBooleanSelection);
aFactory->registerValidator("FeaturesPlugin_ValidatorPartitionSelection",
new FeaturesPlugin_ValidatorPartitionSelection);
+ aFactory->registerValidator("FeaturesPlugin_ValidatorRemoveSubShapesSelection",
+ new FeaturesPlugin_ValidatorRemoveSubShapesSelection);
+ aFactory->registerValidator("FeaturesPlugin_ValidatorRemoveSubShapesResult",
+ new FeaturesPlugin_ValidatorRemoveSubShapesResult);
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);
return FeaturePtr(new FeaturesPlugin_RevolutionCut);
} else if (theFeatureID == FeaturesPlugin_RevolutionFuse::ID()) {
return FeaturePtr(new FeaturesPlugin_RevolutionFuse);
+ } else if (theFeatureID == FeaturesPlugin_RemoveSubShapes::ID()) {
+ return FeaturePtr(new FeaturesPlugin_RemoveSubShapes);
}
// feature of such kind is not found
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: FeaturesPlugin_RemoveSubShapes.cpp
+// Created: 14 April 2016
+// Author: Dmitry Bobylev
+
+#include "FeaturesPlugin_RemoveSubShapes.h"
+
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
+#include <GeomAPI_ShapeIterator.h>
+
+#include <GeomAlgoAPI_ShapeBuilder.h>
+#include <GeomAlgoAPI_ShapeTools.h>
+
+//==================================================================================================
+FeaturesPlugin_RemoveSubShapes::FeaturesPlugin_RemoveSubShapes()
+{
+}
+
+//==================================================================================================
+void FeaturesPlugin_RemoveSubShapes::initAttributes()
+{
+ data()->addAttribute(BASE_SHAPE_ID(), ModelAPI_AttributeSelection::typeId());
+
+ data()->addAttribute(SUBSHAPES_ID(), ModelAPI_AttributeSelectionList::typeId());
+}
+
+void FeaturesPlugin_RemoveSubShapes::attributeChanged(const std::string& theID)
+{
+ ModelAPI_Feature::attributeChanged(theID);
+
+ if(theID == BASE_SHAPE_ID()) {
+ AttributeSelectionPtr aShapeAttrSelection = selection(BASE_SHAPE_ID());
+ AttributeSelectionListPtr aSubShapesAttrList = selectionList(SUBSHAPES_ID());
+ if(!aShapeAttrSelection.get() || !aSubShapesAttrList.get()) {
+ return;
+ }
+
+ aSubShapesAttrList->clear();
+
+ ResultPtr aContext = aShapeAttrSelection->context();
+ ResultCompSolidPtr aResultCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aContext);
+ if(!aResultCompSolid.get()) {
+ return;
+ }
+
+ GeomShapePtr aBaseShape = aShapeAttrSelection->value();
+ if(!aBaseShape.get()) {
+ aBaseShape = aContext->shape();
+ }
+ if(!aBaseShape.get()) {
+ return;
+ }
+ GeomAPI_Shape::ShapeType aShapeType = aBaseShape->shapeType();
+ if(aShapeType != GeomAPI_Shape::WIRE
+ && aShapeType != GeomAPI_Shape::SHELL
+ && aShapeType != GeomAPI_Shape::COMPSOLID
+ && aShapeType != GeomAPI_Shape::COMPOUND) {
+ return;
+ }
+ for(GeomAPI_ShapeIterator anIt(aBaseShape); anIt.more(); anIt.next()) {
+ GeomShapePtr aSubShape = anIt.current();
+ const int aNumOfSubs = aResultCompSolid->numberOfSubs();
+ if(aNumOfSubs == 0) {
+ aSubShapesAttrList->append(aContext, aSubShape);
+ } else {
+ for(int anIndex = 0; anIndex < aResultCompSolid->numberOfSubs(); ++anIndex) {
+ ResultBodyPtr aSubResult = aResultCompSolid->subResult(anIndex);
+ if(aSubResult->shape()->isEqual(aSubShape)) {
+ aSubShapesAttrList->append(aSubResult, aSubShape);
+ break;
+ }
+ }
+ }
+ }
+ }
+}
+
+//==================================================================================================
+void FeaturesPlugin_RemoveSubShapes::execute()
+{
+ // Get base shape and sub-shapes list.
+ AttributeSelectionPtr aShapeAttrSelection = selection(BASE_SHAPE_ID());
+ AttributeSelectionListPtr aSubShapesAttrList = selectionList(SUBSHAPES_ID());
+ if(!aShapeAttrSelection.get() || !aSubShapesAttrList.get()) {
+ return;
+ }
+
+ // Copy base shape.
+ GeomShapePtr aBaseShape = aShapeAttrSelection->value();
+ if(!aBaseShape.get()) {
+ return;
+ }
+ GeomShapePtr aResultShape = aBaseShape->emptyCopied();
+
+ // Copy sub-shapes from list to new shape.
+ for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
+ AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
+ GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
+ GeomAlgoAPI_ShapeBuilder::add(aResultShape, aShapeToAdd);
+ }
+
+ // Store result.
+ ResultBodyPtr aResultBody = document()->createBody(data());
+ aResultBody->storeModified(aBaseShape, aResultShape);
+ setResult(aResultBody);
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: FeaturesPlugin_RemoveSubShapes.h
+// Created: 23 May 2016
+// Author: Dmitry Bobylev
+
+#ifndef FeaturesPlugin_RemoveSubShapes_H_
+#define FeaturesPlugin_RemoveSubShapes_H_
+
+#include "FeaturesPlugin.h"
+
+#include <ModelAPI_Feature.h>
+
+/// \class FeaturesPlugin_RemoveSubShapes
+/// \ingroup Plugins
+/// \brief Feature for removing sub-shapes from collections(wire, shell, compsolid, compound).
+class FeaturesPlugin_RemoveSubShapes: public ModelAPI_Feature
+{
+public:
+ /// Use plugin manager for features creation
+ FeaturesPlugin_RemoveSubShapes();
+
+ /// Feature kind.
+ inline static const std::string& ID()
+ {
+ static const std::string MY_ID("Remove_SubShapes");
+ return MY_ID;
+ }
+
+ /// Attribute name of base shape.
+ inline static const std::string& BASE_SHAPE_ID()
+ {
+ static const std::string MY_BASE_SHAPE_ID("base_shape");
+ return MY_BASE_SHAPE_ID;
+ }
+
+ /// Attribute name of sub-shapes.
+ inline static const std::string& SUBSHAPES_ID()
+ {
+ static const std::string MY_SUBSHAPES_ID("subshapes");
+ return MY_SUBSHAPES_ID;
+ }
+
+ /// \return the kind of a feature.
+ FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ static std::string MY_KIND = FeaturesPlugin_RemoveSubShapes::ID();
+ return MY_KIND;
+ }
+
+ /// Request for initialization of data model of the feature: adding all attributes.
+ FEATURESPLUGIN_EXPORT virtual void initAttributes();
+
+ /// Called on change of any argument-attribute of this object.
+ /// \param[in] theID identifier of changed attribute.
+ FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
+ /// Creates a new part document if needed.
+ FEATURESPLUGIN_EXPORT virtual void execute();
+};
+
+#endif
#include <GeomAPI_DataMapOfShapeShape.h>
#include <GeomAPI_PlanarEdges.h>
#include <GeomAPI_ShapeExplorer.h>
+#include <GeomAPI_ShapeIterator.h>
+
+#include <GeomAlgoAPI_ShapeBuilder.h>
+#include <GeomAlgoAPI_ShapeTools.h>
#include <GeomAlgoAPI_WireBuilder.h>
//==================================================================================================
static const std::string aLocationsID = "locations_objects";
if(theFeature->getKind() != "Pipe") {
- theError = "Feature \"" + theFeature->getKind() + "\" does not supported by this validator.";
+ theError = "Error: Feature \"" + theFeature->getKind() + "\" does not supported by this validator.";
return false;
}
AttributeStringPtr aCreationMethodAttr = theFeature->string(aCreationMethodID);
if(!aCreationMethodAttr.get()) {
- theError = "Could not get \"" + aCreationMethodID + "\" attribute.";
+ theError = "Error: Could not get \"" + aCreationMethodID + "\" attribute.";
return false;
}
AttributeSelectionListPtr aBaseObjectsSelectionList = theFeature->selectionList(aBaseObjectsID);
if(!aBaseObjectsSelectionList.get()) {
- theError = "Could not get \"" + aBaseObjectsID + "\" attribute.";
+ theError = "Error: Could not get \"" + aBaseObjectsID + "\" attribute.";
return false;
}
AttributeSelectionListPtr aLocationsSelectionList = theFeature->selectionList(aLocationsID);
if(!aLocationsSelectionList.get()) {
- theError = "Could not get \"" + aBaseObjectsID + "\" attribute.";
+ theError = "Error: Could not get \"" + aBaseObjectsID + "\" attribute.";
return false;
}
if(aLocationsSelectionList->size() > 0 && aLocationsSelectionList->size() != aBaseObjectsSelectionList->size()) {
- theError = "Number of locations should be the same as base objects.";
+ theError = "Error: Number of locations should be the same as base objects.";
return false;
}
std::string& theError) const
{
if(theArguments.empty()) {
- theError = "Validator parameters is empty.";
+ theError = "Error: Validator parameters is empty.";
return false;
}
// Checking attribute.
if(!isValidAttribute(theAttribute, theArguments, theError)) {
if(theError.empty()) {
- theError = "Attribute contains unacceptable shape.";
+ theError = "Error: Attribute contains unacceptable shape.";
}
return false;
}
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.";
+ theError = "Error: Object from this sketch is already selected. Sketch is not allowed for selection.";
return false;
}
} 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.";
+ theError = "Error: 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.";
+ theError = "Error: 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.";
+ theError = "Error: Objects with such wire already selected. Don't allow to select this object.";
return false;
}
std::string& theError) const
{
if(!theAttribute.get()) {
- theError = "Empty attribute.";
+ theError = "Error: Empty attribute.";
return false;
}
AttributeSelectionPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
ResultPtr aContext = anAttr->context();
if(!aContext.get()) {
- theError = "Attribute have empty context.";
+ theError = "Error: Attribute have empty context.";
return false;
}
aShape = aContextShape;
}
if(!aShape.get()) {
- theError = "Empty shape selected";
+ theError = "Error: Empty shape selected";
return false;
}
if(aConstruction.get()) {
// Construciotn selected. Check that is is not infinite.
if(aConstruction->isInfinite()) {
- theError = "Infinite constructions is not allowed as base.";
+ theError = "Error: Infinite constructions is not allowed as base.";
return false;
}
if(!aShape->isEqual(aContextShape)) {
// Local selection on body does not allowed.
- theError = "Selected shape is in the local selection. Only global selection is allowed.";
+ theError = "Error: Selected shape is in the local selection. Only global selection is allowed.";
return false;
}
// 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, "
+ theError = "Error: 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;
}
} else {
- theError = "Following attribute does not supported: " + anAttributeType + ".";
+ theError = "Error: Attribute \"" + anAttributeType + "\" does not supported by this validator.";
return false;
}
std::string& theError) const
{
if (theAttribute->attributeType() != ModelAPI_AttributeReference::typeId()) {
- theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
+ theError = "Error: The attribute with the " + theAttribute->attributeType() + " type is not processed";
return false;
}
if (theArguments.size() != 2) {
- theError = "Wrong parameters in XML definition for " + theAttribute->attributeType() + " type";
+ theError = "Error: Wrong parameters in XML definition for " + theAttribute->attributeType() + " type";
return false;
}
// first argument is for the base attribute, second - for skipping feature kind
std::string& theError) const
{
if(theArguments.size() != 2) {
- theError = "Validator should be used with 2 parameters for extrusion.";
+ theError = "Error: Validator should be used with 2 parameters for extrusion.";
return false;
}
AttributeSelectionPtr aSelAttr = theFeature->selection(*anArgsIt);
if(!aSelAttr.get()) {
- theError = "Could not get selection attribute \"" + *anArgsIt + "\".";
+ theError = "Error: Could not get selection attribute \"" + *anArgsIt + "\".";
return false;
}
if(!aShape.get()) {
ResultPtr aContext = aSelAttr->context();
if(!aContext.get()) {
- theError = "Base objects list contains vertex or edge, so attribute \"" + *anArgsIt
+ theError = "Error: Base objects list contains vertex or edge, so attribute \"" + *anArgsIt
+ "\" can not be used with default value. Select direction for extrusion.";
return false;
}
}
if(!aShape.get()) {
- theError = "Base objects list contains vertex or edge, so attribute \"" + *anArgsIt
+ theError = "Error: Base objects list contains vertex or edge, so attribute \"" + *anArgsIt
+ "\" can not be used with default value. Select direction for extrusion.";
return false;
}
{
AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
if(!anAttrSelectionList.get()) {
- theError = "Error: this validator can only work with selection list attributes in Boolean feature.";
+ theError = "Error: This validator can only work with selection list attributes in \"Boolean\" feature.";
return false;
}
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
if(!anAttrSelection.get()) {
- theError = "Error: empty attribute selection.";
+ theError = "Error: Empty attribute selection.";
return false;
}
ResultPtr aContext = anAttrSelection->context();
if(!aContext.get()) {
- theError = "Error: empty selection context.";
+ theError = "Error: Empty selection context.";
return false;
}
ResultConstructionPtr aResultConstruction =
aShape = aContext->shape();
}
if(!aShape.get()) {
- theError = "Error: empty shape.";
+ theError = "Error: Empty shape.";
return false;
}
int aShapeType = aShape->shapeType();
aShapeType != GeomAPI_Shape::SOLID &&
aShapeType != GeomAPI_Shape::COMPSOLID &&
aShapeType != GeomAPI_Shape::COMPOUND) {
- theError = "Error: selected shape has the wrong type.";
+ theError = "Error: Selected shape has the wrong type.";
return false;
}
} else {
if(aShapeType != GeomAPI_Shape::SOLID &&
aShapeType != GeomAPI_Shape::COMPSOLID &&
aShapeType != GeomAPI_Shape::COMPOUND) {
- theError = "Error: selected shape has the wrong type.";
+ theError = "Error: Selected shape has the wrong type.";
return false;
}
}
const std::list<std::string>& theArguments,
std::string& theError) const
{
- std::string anAttributeType = theAttribute->attributeType();
- if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
- AttributeSelectionListPtr aSelectionListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ if(!anAttrSelectionList.get()) {
+ theError = "Error: This validator can only work with selection list in \"Partition\" feature.";
+ return false;
+ }
+
+ for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr aSelectAttr = anAttrSelectionList->value(anIndex);
- for(int anIndex = 0; anIndex < aSelectionListAttr->size(); ++anIndex) {
- AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(anIndex);
+ //GeomValidators_BodyShapes aBodyValidator;
+ //if(aBodyValidator.isValid(aSelectAttr, theArguments, theError)) {
+ // continue;
+ //}
- GeomValidators_BodyShapes aBodyValidator;
- if(aBodyValidator.isValid(aSelectAttr, theArguments, theError)) {
- continue;
- }
+ GeomValidators_FeatureKind aFeatureKindValidator;
+ if(aFeatureKindValidator.isValid(aSelectAttr, theArguments, theError)) {
+ continue;
+ }
- GeomValidators_FeatureKind aFeatureKindValidator;
- if(aFeatureKindValidator.isValid(aSelectAttr, theArguments, theError)) {
- continue;
- }
+ ResultPtr aContext = aSelectAttr->context();
+ ResultConstructionPtr aResultConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+ if(aResultConstruction.get()) {
+
+ }
- theError = "Only body shapes and construction planes are allowed for selection.";
+ theError = "Error: Only body shapes and construction planes are allowed for selection.";
+ return false;
+ }
+
+ return true;
+}
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorRemoveSubShapesSelection::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const
+{
+ AttributeSelectionListPtr aSubShapesAttrList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ if(!aSubShapesAttrList.get()) {
+ theError = "Error: This validator can only work with selection list in \"Remove Sub-Shapes\" feature.";
+ return false;
+ }
+
+ static const std::string aBaseShapeID = "base_shape";
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+ AttributeSelectionPtr aShapeAttrSelection = aFeature->selection(aBaseShapeID);
+
+ if(!aShapeAttrSelection.get()) {
+ theError = "Error: Could not get \"" + aBaseShapeID + "\" attribute.";
+ return false;
+ }
+
+ GeomShapePtr aBaseShape = aShapeAttrSelection->value();
+ ResultPtr aContext = aShapeAttrSelection->context();
+ if(!aContext.get()) {
+ theError = "Error: Empty context.";
+ return false;
+ }
+ if(!aBaseShape.get()) {
+ aBaseShape = aContext->shape();
+ }
+ if(!aBaseShape.get()) {
+ theError = "Error: Empty base shape.";
+ return false;
+ }
+
+ for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
+ bool isSameFound = false;
+ AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
+ GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
+ for(GeomAPI_ShapeIterator anIt(aBaseShape); anIt.more(); anIt.next()) {
+ if(anIt.current()->isEqual(aShapeToAdd)) {
+ isSameFound = true;
+ break;
+ }
+ }
+ if(!isSameFound) {
+ theError = "Error: Only sub-shapes of selected shape is allowed for selection.";
return false;
}
- } else {
- theError = "This validator supports only " + ModelAPI_AttributeSelectionList::typeId() + " attribute type.";
+ }
+
+ return true;
+}
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const
+{
+ static const std::string aBaseShapeID = "base_shape";
+ static const std::string aSubShapesID = "subshapes";
+
+ if(theFeature->getKind() != "Remove_SubShapes") {
+ theError = "Error: Feature \"" + theFeature->getKind() + "\" does not supported by this validator.";
+ return false;
+ }
+
+ AttributeSelectionPtr aShapeAttrSelection = theFeature->selection(aBaseShapeID);
+ if(!aShapeAttrSelection.get()) {
+ theError = "Error: Could not get \"" + aBaseShapeID + "\" attribute.";
+ return false;
+ }
+
+ AttributeSelectionListPtr aSubShapesAttrList = theFeature->selectionList(aSubShapesID);
+ if(!aSubShapesAttrList.get()) {
+ theError = "Error: Could not get \"" + aSubShapesID + "\" attribute.";
+ return false;
+ }
+
+ // Copy base shape.
+ GeomShapePtr aBaseShape = aShapeAttrSelection->value();
+ if(!aBaseShape.get()) {
+ return false;
+ }
+ GeomShapePtr aResultShape = aBaseShape->emptyCopied();
+
+ // Copy sub-shapes from list to new shape.
+ for(int anIndex = 0; anIndex < aSubShapesAttrList->size(); ++anIndex) {
+ AttributeSelectionPtr anAttrSelectionInList = aSubShapesAttrList->value(anIndex);
+ GeomShapePtr aShapeToAdd = anAttrSelectionInList->value();
+ GeomAlgoAPI_ShapeBuilder::add(aResultShape, aShapeToAdd);
+ }
+
+ // Check new shape.
+ if(!GeomAlgoAPI_ShapeTools::isShapeValid(aResultShape)) {
+ theError = "Error: Resulting shape is not valid.";
return false;
}
return true;
}
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isNotObligatory(std::string theFeature,
+ std::string theAttribute)
+{
+ return false;
+}
{
public:
/// \return True if the attribute is valid. It checks whether the selection
- /// is acceptable for boolean operation.
+ /// is acceptable for operation.
+ /// \param[in] theAttribute an attribute to check.
+ /// \param[in] theArguments a filter parameters.
+ /// \param[out] theError error message.
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const;
+};
+
+/// \class FeaturesPlugin_ValidatorRemoveSubShapesSelection
+/// \ingroup Validators
+/// \brief Validates selection for "Remove Sub-Shapes" feature.
+class FeaturesPlugin_ValidatorRemoveSubShapesSelection: public ModelAPI_AttributeValidator
+{
+public:
+ /// \return True if the attribute is valid. It checks whether the selection
+ /// is acceptable for operation.
/// \param[in] theAttribute an attribute to check.
/// \param[in] theArguments a filter parameters.
/// \param[out] theError error message.
std::string& theError) const;
};
+/// \class FeaturesPlugin_ValidatorRemoveSubShapesResult
+/// \ingroup Validators
+/// \brief Validator for the Remove Sub-Shapes feature.
+class FeaturesPlugin_ValidatorRemoveSubShapesResult: public ModelAPI_FeatureValidator
+{
+ public:
+ //! \return true if result is valid shape.
+ //! \param theFeature the checked feature
+ //! \param theArguments arguments of the feature (not used)
+ //! \param theError error message
+ virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const;
+
+ /// Returns true if the attribute in feature is not obligatory for the feature execution
+ virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
+};
+
#endif
auto_preview="false">
<source path="partition_widget.xml"/>
</feature>
+ <feature id="Remove_SubShapes" title="Remove Sub-Shapes" tooltip="Allows to remove sub-shapes from wires, shells, compsolids and compounds" icon="icons/Features/remove_subshapes.png">
+ <source path="remove_subshapes_widget.xml"/>
+ </feature>
<feature id="Intersection" title="Intersection" tooltip="Intersect objects with tools" icon="icons/Features/intersection.png">
<source path="intersection_widget.xml"/>
</feature>
--- /dev/null
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<source>
+ <shape_selector id="base_shape"
+ label="Shape:"
+ tooltip="Select a shape to modify."
+ shape_types="objects"
+ concealment="true">
+ <validator id="GeomValidators_ShapeType" parameters="wire,shell,compsolid,compound"/>
+ <validator id="GeomValidators_BodyShapes"/>
+ </shape_selector>
+ <multi_selector id="subshapes"
+ label="Sub-Shapes:"
+ tooltip="Select shapes to keep."
+ type_choice="vertices edges wires faces shells solids compsolids compounds"
+ clear_in_neutral_point="false">
+ <validator id="FeaturesPlugin_ValidatorRemoveSubShapesSelection"/>
+ </multi_selector>
+ <validator id="FeaturesPlugin_ValidatorRemoveSubShapesResult"/>
+</source>
}
//==================================================================================================
-void GeomAlgoAPI_ShapeBuilder::add(const std::shared_ptr<GeomAPI_Shape> theShape,
- const ListOfShape& theShapesToAdd)
+void GeomAlgoAPI_ShapeBuilder::addInternal(const std::shared_ptr<GeomAPI_Shape> theShape,
+ const ListOfShape& theShapesToAdd)
{
// Get base shape.
if(!theShape.get()) {
/// \param[in] theShape base shape.
GEOMALGOAPI_EXPORT void removeInternal(const std::shared_ptr<GeomAPI_Shape> theShape);
- /// \brief Store new shape as result of adding theShapesToAdd to theShape.
+ /// \brief Store new shape as result of adding theShapesToAdd to theShape as internal shapes.
/// \param[in] theShape base shape.
/// \param[in] theShapesToAdd shapes which will be added.
- GEOMALGOAPI_EXPORT void add(const std::shared_ptr<GeomAPI_Shape> theShape,
- const ListOfShape& theShapesToAdd);
+ GEOMALGOAPI_EXPORT void addInternal(const std::shared_ptr<GeomAPI_Shape> theShape,
+ const ListOfShape& theShapesToAdd);
};
#endif
#include <BRepBuilderAPI_FindPlane.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
+#include <BRepCheck_Analyzer.hxx>
#include <BRepExtrema_DistShapeShape.hxx>
#include <BRepGProp.hxx>
#include <BRepTopAdaptor_FClass2d.hxx>
return true;
}
+
+//==================================================================================================
+bool GeomAlgoAPI_ShapeTools::isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape)
+{
+ if(!theShape.get()) {
+ return false;
+ }
+
+ BRepCheck_Analyzer aChecker(theShape->impl<TopoDS_Shape>());
+ return (aChecker.IsValid() == Standard_True);
+}
\ No newline at end of file
/// \return true if edge inside the face.
GEOMALGOAPI_EXPORT static bool isSubShapeInsideShape(const std::shared_ptr<GeomAPI_Shape> theSubShape,
const std::shared_ptr<GeomAPI_Shape> theBaseShape);
+
+ /// \return true if theShape is valid.
+ GEOMALGOAPI_EXPORT static bool isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape);
+
};
#endif
std::string& theError) const
{
std::string anAttributeType = theAttribute->attributeType();
- if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
- AttributeSelectionListPtr aSelectionListAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
- // all context objects should not be sketch entities
- for(int anIndex = 0, aSize = aSelectionListAttr->size(); anIndex < aSize; ++anIndex) {
- AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(anIndex);
- ResultPtr aContext = aSelectAttr->context();
- if(!aContext.get()) {
- theError = "Error: Context is empty.";
- return false;
- }
+ if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
+ AttributeSelectionPtr anAttrSelection =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+ ResultPtr aContext = anAttrSelection->context();
+ if(!aContext.get()) {
+ theError = "Error: Context is empty.";
+ return false;
+ }
+
+ ResultConstructionPtr aResultConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+ if(aResultConstruction.get()) {
+ theError = "Error: Result construction selected.";
+ return false;
+ }
+ } else if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
+ AttributeSelectionListPtr anAttrSelectionList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
- ResultConstructionPtr aResultConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
- if(aResultConstruction.get()) {
- theError = "Error: Result construction selected.";
+ // All objects should not be result constructions.
+ for(int anIndex = 0, aSize = anAttrSelectionList->size(); anIndex < aSize; ++anIndex) {
+ AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
+ if(!isValid(anAttrSelection, theArguments, theError)) {
return false;
}
}
+ } else {
+ theError = "Error: Attribute \"" + anAttributeType + "\" does not supported by this validator.";
+ return false;
}
return true;
GeomValidators_ShapeType::TypeOfShape GeomValidators_ShapeType::shapeType(const std::string& theType)
{
if (MyShapeTypes.size() == 0) {
- MyShapeTypes["empty"] = Empty;
- MyShapeTypes["vertex"] = Vertex;
- MyShapeTypes["edge"] = Edge;
- MyShapeTypes["line"] = Line;
- MyShapeTypes["circle"] = Circle;
- MyShapeTypes["wire"] = Wire;
- MyShapeTypes["face"] = Face;
- MyShapeTypes["plane"] = Plane;
- MyShapeTypes["shell"] = Shell;
- MyShapeTypes["solid"] = Solid;
+ MyShapeTypes["empty"] = Empty;
+ MyShapeTypes["vertex"] = Vertex;
+ MyShapeTypes["edge"] = Edge;
+ MyShapeTypes["line"] = Line;
+ MyShapeTypes["circle"] = Circle;
+ MyShapeTypes["wire"] = Wire;
+ MyShapeTypes["face"] = Face;
+ MyShapeTypes["plane"] = Plane;
+ MyShapeTypes["shell"] = Shell;
+ MyShapeTypes["solid"] = Solid;
+ MyShapeTypes["compsolid"] = CompSolid;
+ MyShapeTypes["compound"] = Compound;
}
std::string aType = std::string(theType.c_str());
if (MyShapeTypes.find(aType) != MyShapeTypes.end())
aValid = theShape->isSolid() || theShape->isCompSolid() ||
theShape->isCompoundOfSolids();
break;
+ case CompSolid:
+ aValid = theShape->shapeType() == GeomAPI_Shape::COMPSOLID;
+ break;
case Compound:
aValid = theShape->isCompound();
break;
Plane,
Shell,
Solid,
+ CompSolid,
Compound,
AnyShape
};
TopAbs_ShapeEnum translateType (const std::string& theType)
{
// map from the textual shape types to OCCT enumeration
- static std::map<std::string, TopAbs_ShapeEnum> MyShapeTypes;
- if (MyShapeTypes.size() == 0) {
- MyShapeTypes["face"] = TopAbs_FACE;
- MyShapeTypes["faces"] = TopAbs_FACE;
- MyShapeTypes["vertex"] = TopAbs_VERTEX;
- MyShapeTypes["vertices"] = TopAbs_VERTEX;
- MyShapeTypes["wire"] = TopAbs_WIRE;
- MyShapeTypes["edge"] = TopAbs_EDGE;
- MyShapeTypes["edges"] = TopAbs_EDGE;
- MyShapeTypes["shell"] = TopAbs_SHELL;
- MyShapeTypes["solid"] = TopAbs_SOLID;
- MyShapeTypes["solids"] = TopAbs_SOLID;
- MyShapeTypes["FACE"] = TopAbs_FACE;
- MyShapeTypes["FACES"] = TopAbs_FACE;
- MyShapeTypes["VERTEX"] = TopAbs_VERTEX;
- MyShapeTypes["VERTICES"] = TopAbs_VERTEX;
- MyShapeTypes["WIRE"] = TopAbs_WIRE;
- MyShapeTypes["EDGE"] = TopAbs_EDGE;
- MyShapeTypes["EDGES"] = TopAbs_EDGE;
- MyShapeTypes["SHELL"] = TopAbs_SHELL;
- MyShapeTypes["SOLID"] = TopAbs_SOLID;
- MyShapeTypes["SOLIDS"] = TopAbs_SOLID;
+ static std::map<std::string, TopAbs_ShapeEnum> aShapeTypes;
+
+ if(aShapeTypes.size() == 0) {
+ aShapeTypes["compound"] = TopAbs_COMPOUND;
+ aShapeTypes["compounds"] = TopAbs_COMPOUND;
+ aShapeTypes["compsolid"] = TopAbs_COMPSOLID;
+ aShapeTypes["compsolids"] = TopAbs_COMPSOLID;
+ aShapeTypes["solid"] = TopAbs_SOLID;
+ aShapeTypes["solids"] = TopAbs_SOLID;
+ aShapeTypes["shell"] = TopAbs_SHELL;
+ aShapeTypes["shells"] = TopAbs_SHELL;
+ aShapeTypes["face"] = TopAbs_FACE;
+ aShapeTypes["faces"] = TopAbs_FACE;
+ aShapeTypes["wire"] = TopAbs_WIRE;
+ aShapeTypes["wires"] = TopAbs_WIRE;
+ aShapeTypes["edge"] = TopAbs_EDGE;
+ aShapeTypes["edges"] = TopAbs_EDGE;
+ aShapeTypes["vertex"] = TopAbs_VERTEX;
+ aShapeTypes["vertices"] = TopAbs_VERTEX;
+ aShapeTypes["COMPOUND"] = TopAbs_COMPOUND;
+ aShapeTypes["COMPOUNDS"] = TopAbs_COMPOUND;
+ aShapeTypes["COMPSOLID"] = TopAbs_COMPSOLID;
+ aShapeTypes["COMPSOLIDS"] = TopAbs_COMPSOLID;
+ aShapeTypes["SOLID"] = TopAbs_SOLID;
+ aShapeTypes["SOLIDS"] = TopAbs_SOLID;
+ aShapeTypes["SHELL"] = TopAbs_SHELL;
+ aShapeTypes["SHELLS"] = TopAbs_SHELL;
+ aShapeTypes["FACE"] = TopAbs_FACE;
+ aShapeTypes["FACES"] = TopAbs_FACE;
+ aShapeTypes["WIRE"] = TopAbs_WIRE;
+ aShapeTypes["WIRES"] = TopAbs_WIRE;
+ aShapeTypes["EDGE"] = TopAbs_EDGE;
+ aShapeTypes["EDGES"] = TopAbs_EDGE;
+ aShapeTypes["VERTEX"] = TopAbs_VERTEX;
+ aShapeTypes["VERTICES"] = TopAbs_VERTEX;
}
- if (MyShapeTypes.find(theType) != MyShapeTypes.end())
- return MyShapeTypes[theType];
+ if (aShapeTypes.find(theType) != aShapeTypes.end())
+ return aShapeTypes[theType];
Events_Error::send("Shape type defined in XML is not implemented!");
return TopAbs_SHAPE;
}
}
typedef QMap<QString, TopAbs_ShapeEnum> ShapeTypes;
-static ShapeTypes MyShapeTypes;
+static ShapeTypes myShapeTypes;
TopAbs_ShapeEnum shapeType(const QString& theType)
{
- if (MyShapeTypes.count() == 0) {
- MyShapeTypes["face"] = TopAbs_FACE;
- MyShapeTypes["faces"] = TopAbs_FACE;
- MyShapeTypes["vertex"] = TopAbs_VERTEX;
- MyShapeTypes["vertices"] = TopAbs_VERTEX;
- MyShapeTypes["wire"] = TopAbs_WIRE;
- MyShapeTypes["wires"] = TopAbs_WIRE;
- MyShapeTypes["edge"] = TopAbs_EDGE;
- MyShapeTypes["edges"] = TopAbs_EDGE;
- MyShapeTypes["shell"] = TopAbs_SHELL;
- MyShapeTypes["solid"] = TopAbs_SOLID;
- MyShapeTypes["solids"] = TopAbs_SOLID;
- MyShapeTypes["objects"] = TopAbs_SHAPE;
+ if (myShapeTypes.count() == 0) {
+ myShapeTypes["compound"] = TopAbs_COMPOUND;
+ myShapeTypes["compounds"] = TopAbs_COMPOUND;
+ myShapeTypes["compsolid"] = TopAbs_COMPSOLID;
+ myShapeTypes["compsolids"] = TopAbs_COMPSOLID;
+ myShapeTypes["solid"] = TopAbs_SOLID;
+ myShapeTypes["solids"] = TopAbs_SOLID;
+ myShapeTypes["shell"] = TopAbs_SHELL;
+ myShapeTypes["shells"] = TopAbs_SHELL;
+ myShapeTypes["face"] = TopAbs_FACE;
+ myShapeTypes["faces"] = TopAbs_FACE;
+ myShapeTypes["wire"] = TopAbs_WIRE;
+ myShapeTypes["wires"] = TopAbs_WIRE;
+ myShapeTypes["edge"] = TopAbs_EDGE;
+ myShapeTypes["edges"] = TopAbs_EDGE;
+ myShapeTypes["vertex"] = TopAbs_VERTEX;
+ myShapeTypes["vertices"] = TopAbs_VERTEX;
+ myShapeTypes["objects"] = TopAbs_SHAPE;
}
QString aType = theType.toLower();
- if (MyShapeTypes.contains(aType))
- return MyShapeTypes[aType];
+ if(myShapeTypes.contains(aType))
+ return myShapeTypes[aType];
Events_Error::send("Shape type defined in XML is not implemented!");
return TopAbs_SHAPE;
}