FiltersPlugin_OnPlaneSide.h
FiltersPlugin_OppositeToEdge.h
FiltersPlugin_RelativeToSolid.h
+ FiltersPlugin_ExternalFaces.h
)
SET(PROJECT_SOURCES
FiltersPlugin_OnPlaneSide.cpp
FiltersPlugin_OppositeToEdge.cpp
FiltersPlugin_RelativeToSolid.cpp
+ FiltersPlugin_ExternalFaces.cpp
)
SET(PROJECT_LIBRARIES
TestFilter_RelativeToSolid_NotOn.py
TestFilter_RelativeToSolid_InAndOn.py
TestFilter_RelativeToSolid_OutAndOn.py
+ TestFilter_ExternalFaces.py
TestFilter_HorizontalFaces.py
TestFilter_VerticalFaces.py
)
return true;
}
-bool FiltersPlugin_BelongsTo::isOk(const GeomShapePtr& theShape,
- const ModelAPI_FiltersArgs& theArgs) const
+bool FiltersPlugin_BelongsTo::isOk(const GeomShapePtr& theShape, const ResultPtr&,
+ const ModelAPI_FiltersArgs& theArgs) const
{
AttributePtr aAttr = theArgs.argument("BelongsTo");
AttributeSelectionListPtr aList =
/// This method should contain the filter logic. It returns true if the given shape
/// is accepted by the filter.
/// \param theShape the given shape
- virtual bool isOk(const GeomShapePtr& theShape,
- const ModelAPI_FiltersArgs& theArgs) const override;
+ /// \param theArgs arguments of the filter
+ virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
+ const ModelAPI_FiltersArgs& theArgs) const override;
/// Returns XML string which represents GUI of the filter
virtual std::string xmlRepresentation() const override;
--- /dev/null
+// 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// 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
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "FiltersPlugin_ExternalFaces.h"
+
+#include <ModelAPI_Tools.h>
+
+#include <TopExp.hxx>
+#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
+
+bool FiltersPlugin_ExternalFaces::isSupported(GeomAPI_Shape::ShapeType theType) const
+{
+ return theType == GeomAPI_Shape::FACE;
+}
+
+bool FiltersPlugin_ExternalFaces::isOk(const GeomShapePtr& theShape,
+ const ResultPtr& theResult,
+ const ModelAPI_FiltersArgs& theArgs) const
+{
+ if (!theShape->isFace())
+ return false;
+
+ ResultBodyPtr anOwner = ModelAPI_Tools::bodyOwner(theResult, true);
+ if (!anOwner) {
+ anOwner = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+ if (!anOwner)
+ return false;
+ }
+ GeomShapePtr anOwnerShape = anOwner->shape();
+
+ TopTools_IndexedDataMapOfShapeListOfShape aMapFS;
+ TopExp::MapShapesAndUniqueAncestors(anOwnerShape->impl<TopoDS_Shape>(),
+ TopAbs_FACE, TopAbs_SOLID, aMapFS);
+ const TopTools_ListOfShape& aSolids = aMapFS.FindFromKey(theShape->impl<TopoDS_Shape>());
+ return aSolids.Extent() <= 1;
+}
--- /dev/null
+// 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// 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
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef FILTERSPLUGIN_EXTERNALFACES_H_
+#define FILTERSPLUGIN_EXTERNALFACES_H_
+
+#include "FiltersPlugin.h"
+
+#include <ModelAPI_Filter.h>
+
+/**\class FiltersPlugin_ExternalFaces
+* \ingroup DataModel
+* \brief Filter for faces not shared between solids in compsolid.
+*/
+class FiltersPlugin_ExternalFaces : public ModelAPI_Filter
+{
+public:
+ FiltersPlugin_ExternalFaces() : ModelAPI_Filter() {}
+
+ virtual const std::string& name() const {
+ static const std::string kName("External faces");
+ return kName;
+ }
+
+ /// Returns true for any type because it supports all selection types
+ virtual bool isSupported(GeomAPI_Shape::ShapeType theType) const override;
+
+ /// This method should contain the filter logic. It returns true if the given shape
+ /// is accepted by the filter.
+ /// \param theShape the given shape
+ /// \param theResult parent result of the shape to be checked
+ /// \param theArgs arguments of the filter
+ virtual bool isOk(const GeomShapePtr& theShape,
+ const ResultPtr& theResult,
+ const ModelAPI_FiltersArgs& theArgs) const override;
+};
+
+#endif
\ No newline at end of file
return theType == GeomAPI_Shape::FACE;
}
-bool FiltersPlugin_HorizontalFace::isOk(
- const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const
+bool FiltersPlugin_HorizontalFace::isOk(const GeomShapePtr& theShape, const ResultPtr&,
+ const ModelAPI_FiltersArgs& theArgs) const
{
if (!theShape->isFace() || !theShape->isPlanar())
return false;
/// This method should contain the filter logic. It returns true if the given shape
/// is accepted by the filter.
/// \param theShape the given shape
- virtual bool isOk(
- const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const override;
+ /// \param theArgs arguments of the filter
+ virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
+ const ModelAPI_FiltersArgs& theArgs) const override;
};
#endif
\ No newline at end of file
return theType == GeomAPI_Shape::EDGE || theType == GeomAPI_Shape::FACE;
}
-bool FiltersPlugin_OnGeometry::isOk(const GeomShapePtr& theShape,
- const ModelAPI_FiltersArgs& theArgs) const
+bool FiltersPlugin_OnGeometry::isOk(const GeomShapePtr& theShape, const ResultPtr&,
+ const ModelAPI_FiltersArgs& theArgs) const
{
AttributePtr aAttr = theArgs.argument("OnGeometry");
AttributeSelectionListPtr aList =
/// This method should contain the filter logic. It returns true if the given shape
/// is accepted by the filter.
/// \param theShape the given shape
- virtual bool isOk(const GeomShapePtr& theShape,
+ /// \param theArgs arguments of the filter
+ virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
const ModelAPI_FiltersArgs& theArgs) const override;
/// Returns XML string which represents GUI of the filter
return theType == GeomAPI_Shape::EDGE || theType == GeomAPI_Shape::VERTEX;
}
-bool FiltersPlugin_OnLine::isOk(const GeomShapePtr& theShape,
+bool FiltersPlugin_OnLine::isOk(const GeomShapePtr& theShape, const ResultPtr&,
const ModelAPI_FiltersArgs& theArgs) const
{
AttributePtr aAttr = theArgs.argument("OnLine");
/// This method should contain the filter logic. It returns true if the given shape
/// is accepted by the filter.
/// \param theShape the given shape
- virtual bool isOk(const GeomShapePtr& theShape,
+ /// \param theArgs arguments of the filter
+ virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
const ModelAPI_FiltersArgs& theArgs) const override;
/// Returns XML string which represents GUI of the filter
return aFace->getPlane();
}
-bool FiltersPlugin_OnPlane::isOk(const GeomShapePtr& theShape,
- const ModelAPI_FiltersArgs& theArgs) const
+bool FiltersPlugin_OnPlane::isOk(const GeomShapePtr& theShape, const ResultPtr&,
+ const ModelAPI_FiltersArgs& theArgs) const
{
AttributePtr aAttr = theArgs.argument("OnPlane");
AttributeSelectionListPtr aList =
/// This method should contain the filter logic. It returns true if the given shape
/// is accepted by the filter.
/// \param theShape the given shape
- virtual bool isOk(const GeomShapePtr& theShape,
- const ModelAPI_FiltersArgs& theArgs) const override;
+ /// \param theArgs arguments of the filter
+ virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
+ const ModelAPI_FiltersArgs& theArgs) const override;
/// Returns XML string which represents GUI of the filter
virtual std::string xmlRepresentation() const override;
return true;
}
-bool FiltersPlugin_OnPlaneSide::isOk(const GeomShapePtr& theShape,
+bool FiltersPlugin_OnPlaneSide::isOk(const GeomShapePtr& theShape, const ResultPtr&,
const ModelAPI_FiltersArgs& theArgs) const
{
static const double THE_TOLERANCE = 1.e-7;
/// This method should contain the filter logic. It returns true if the given shape
/// is accepted by the filter.
/// \param theShape the given shape
- virtual bool isOk(const GeomShapePtr& theShape,
+ /// \param theArgs arguments of the filter
+ virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
const ModelAPI_FiltersArgs& theArgs) const override;
/// Returns XML string which represents GUI of the filter
return theType == GeomAPI_Shape::EDGE;
}
-bool FiltersPlugin_OppositeToEdge::isOk(const GeomShapePtr& theShape,
+bool FiltersPlugin_OppositeToEdge::isOk(const GeomShapePtr& theShape, const ResultPtr&,
const ModelAPI_FiltersArgs& theArgs) const
{
AttributePtr aAttr = theArgs.argument("OppositeToEdge");
/// This method should contain the filter logic. It returns true if the given shape
/// is accepted by the filter.
/// \param theShape the given shape
- virtual bool isOk(const GeomShapePtr& theShape,
+ /// \param theArgs arguments of the filter
+ virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
const ModelAPI_FiltersArgs& theArgs) const override;
/// Returns XML string which represents GUI of the filter
#include "FiltersPlugin_OnPlaneSide.h"
#include "FiltersPlugin_OppositeToEdge.h"
#include "FiltersPlugin_RelativeToSolid.h"
+#include "FiltersPlugin_ExternalFaces.h"
#include <ModelAPI_Session.h>
#include <ModelAPI_FiltersFactory.h>
aFactory->registerFilter("OnPlaneSide", new FiltersPlugin_OnPlaneSide);
aFactory->registerFilter("OppositeToEdge", new FiltersPlugin_OppositeToEdge);
aFactory->registerFilter("RelativeToSolid", new FiltersPlugin_RelativeToSolid);
+ aFactory->registerFilter("ExternalFaces", new FiltersPlugin_ExternalFaces);
ModelAPI_Session::get()->registerPlugin(this);
}
return true;
}
-bool FiltersPlugin_RelativeToSolid::isOk(const GeomShapePtr& theShape,
+bool FiltersPlugin_RelativeToSolid::isOk(const GeomShapePtr& theShape, const ResultPtr&,
const ModelAPI_FiltersArgs& theArgs) const
{
AttributePtr anAttr = theArgs.argument("Solid");
/// This method should contain the filter logic. It returns true if the given shape
/// is accepted by the filter.
/// \param theShape the given shape
- virtual bool isOk(const GeomShapePtr& theShape,
+ /// \param theArgs arguments of the filter
+ virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
const ModelAPI_FiltersArgs& theArgs) const override;
/// Returns XML string which represents GUI of the filter
return theType == GeomAPI_Shape::FACE;
}
-bool FiltersPlugin_VerticalFace::isOk(
- const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const
+bool FiltersPlugin_VerticalFace::isOk(const GeomShapePtr& theShape, const ResultPtr&,
+ const ModelAPI_FiltersArgs& theArgs) const
{
if (!theShape->isFace() || !theShape->isPlanar())
return false;
/// This method should contain the filter logic. It returns true if the given shape
/// is accepted by the filter.
/// \param theShape the given shape
- virtual bool isOk(
- const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const override;
+ /// \param theArgs arguments of the filter
+ virtual bool isOk(const GeomShapePtr& theShape, const ResultPtr&,
+ const ModelAPI_FiltersArgs& theArgs) const override;
};
#endif
\ No newline at end of file
--- /dev/null
+# 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
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# 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
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+from salome.shaper import model
+from GeomAPI import *
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "Box_1_1/Left"), model.selection("FACE", "Box_1_1/Right"))
+Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Box_1_1"), model.selection("FACE", "Plane_1")], 20190506)
+Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
+Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Cylinder_1_1")], model.selection("EDGE", "PartSet/OX"), 20)
+Filters = model.filters(Part_1_doc, [model.addFilter(name = "ExternalFaces")])
+model.end()
+
+Reference = {}
+# Faces of the box
+ResultBox_1 = Partition_1.result().resultSubShapePair()[0]
+exp = GeomAPI_ShapeExplorer(ResultBox_1.shape(), GeomAPI_Shape.FACE)
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = False; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = False; exp.next()
+Reference[model.selection(ResultBox_1, exp.current())] = True; exp.next()
+# Faces of the cylinder
+ResultCylinder_1 = Translation_1.result().resultSubShapePair()[0]
+exp = GeomAPI_ShapeExplorer(ResultCylinder_1.shape(), GeomAPI_Shape.FACE)
+while exp.more():
+ Reference[model.selection(ResultCylinder_1, exp.current())] = True
+ exp.next()
+model.checkFilter(Part_1_doc, model, Filters, Reference)
+
+Reference = {
+ model.selection("FACE", "Partition_1_1_2/Modified_Face&Box_1_1/Back"): True,
+ model.selection("FACE", "Partition_1_1_2/Modified_Face&Plane_1/Plane_1"): True,
+ model.selection("FACE", "Partition_1_1_2/Modified_Face&Box_1_1/Bottom"): True,
+ model.selection("FACE", "Box_1_1/Right"): True,
+ model.selection("FACE", "Partition_1_1_2/Modified_Face&Box_1_1/Top"): True,
+ model.selection("FACE", "Partition_1_1_2/Modified_Face&Box_1_1/Front"): True,
+ model.selection("FACE", "Partition_1_1_1/Modified_Face&Box_1_1/Back"): True,
+ model.selection("FACE", "Box_1_1/Left"): True,
+ model.selection("FACE", "Partition_1_1_1/Modified_Face&Box_1_1/Bottom"): True,
+ model.selection("FACE", "Partition_1_1_1/Modified_Face&Plane_1/Plane_1"): True,
+ model.selection("FACE", "Partition_1_1_1/Modified_Face&Box_1_1/Top"): True,
+ model.selection("FACE", "Partition_1_1_1/Modified_Face&Box_1_1/Front"): True,
+ model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_1"): True,
+ model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_2"): True,
+ model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_3"): True,
+}
+model.checkFilter(Part_1_doc, model, Filters, Reference)
std::string myFilterID;
};
-bool Model_FiltersFactory::isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape)
+bool Model_FiltersFactory::isValid(FeaturePtr theFiltersFeature,
+ ResultPtr theResult,
+ GeomShapePtr theShape)
{
// check that the shape type corresponds to the attribute list type
AttributePtr aBase =
std::list<FilterArgs>::iterator aFilter = aFilters.begin();
for(; aFilter != aFilters.end(); aFilter++) {
anArgs.setFilter(aFilter->myFilterID);
- bool aResult = aFilter->myFilter->isOk(theShape, anArgs);
+ bool aResult = aFilter->myFilter->isOk(theShape, theResult, anArgs);
if (aFilter->myReverse)
aResult = !aResult;
if (!aResult) // one filter is failed => exit immediately
/// Returns true if all filters of the Filters feature are ok for the Shape (taking into account
/// the Reversed states).
- /// \param theFiltersFeature feature that contains all information about the filters
+ /// \param theResult parent result of the shape to check
/// \param theShape the checked shape
- virtual bool isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape);
+ virtual bool isValid(FeaturePtr theFiltersFeature,
+ ResultPtr theResult,
+ GeomShapePtr theShape);
/// Returns the filters that support the given shape type
virtual std::list<FilterPtr> filters(GeomAPI_Shape::ShapeType theType);
#define ModelAPI_Filter_H_
#include "ModelAPI_FiltersArgs.h"
+#include "ModelAPI_ResultBody.h"
#include <GeomAPI_Shape.h>
/// This method should contain the filter logic. It returns true if the given shape
/// is accepted by the filter.
/// \param theShape the given shape
- virtual bool isOk(const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const = 0;
+ /// \param theResult parent result of the shape to be checked
+ /// \param theArgs arguments of the filter
+ virtual bool isOk(const GeomShapePtr& theShape,
+ const ResultPtr& theResult,
+ const ModelAPI_FiltersArgs& theArgs) const = 0;
/// Returns XML string which represents GUI of the filter
/// By default it returns nothing (no GUI)
#include "ModelAPI_Feature.h"
#include "ModelAPI_Filter.h"
+#include "ModelAPI_ResultBody.h"
#include <GeomAPI_Shape.h>
/// Returns true if all filters of the Filters feature are ok for the Shape (taking into account
/// the Reversed states).
/// \param theFiltersFeature feature that contains all information about the filters
+ /// \param theResult parent result of the shape to check
/// \param theShape the checked shape
- virtual bool isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape) = 0;
+ virtual bool isValid(FeaturePtr theFiltersFeature,
+ ResultPtr theResult,
+ GeomShapePtr theShape) = 0;
/// Returns the filters that support the given shape type
virtual std::list<FilterPtr> filters(GeomAPI_Shape::ShapeType theType) = 0;
if (!alreadyThere.Add(aTShape))
continue;
static SessionPtr aSession = ModelAPI_Session::get();
- bool isValid = aSession->filters()->isValid(myFeature, aShape);
+ bool isValid = aSession->filters()->isValid(myFeature, aBody, aShape);
if (isValid) {
aBuilder.Add(aComp, aTShape);
ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj, aShape));
shapeName = ""
shapeType = "UNKNOWN"
if sel.variantType() == ModelHighAPI_Selection.VT_ResultSubShapePair:
+ parent = sel.resultSubShapePair()[0]
shape = sel.resultSubShapePair()[1]
if shape.isNull():
shape = sel.resultSubShapePair()[0].shape()
- shapeName = sel.name()
- shapeType = shape.shapeTypeStr()
+ shapeName = sel.name()
+ shapeType = shape.shapeTypeStr()
else:
needUndo = True
theModel.begin()
subShapeFeature = createSubShape(thePartDoc, theModel, sel)
theModel.end()
+ parent = subShapeFeature.results()[0].resultSubShapePair()[0]
shape = subShapeFeature.results()[0].resultSubShapePair()[0].shape()
shapeType = sel.typeSubShapeNamePair()[0]
shapeName = sel.typeSubShapeNamePair()[1]
- assert aFiltersFactory.isValid(theFilter.feature(), shape) == res, "Filter result for {} \"{}\" incorrect. Expected {}.".format(shapeType, shapeName, res)
+ assert aFiltersFactory.isValid(theFilter.feature(), parent, shape) == res, "Filter result for {} \"{}\" incorrect. Expected {}.".format(shapeType, shapeName, res)
if needUndo:
theModel.undo()