From: azv Date: Thu, 4 Jul 2019 07:28:28 +0000 (+0300) Subject: Finalize implementation of filter "F8: On/In/Out a Solid" X-Git-Tag: VEDF2019Lot4~101^2~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=30b704bbf16a3e6bfda63b6f1df05da40b6a939b;p=modules%2Fshaper.git Finalize implementation of filter "F8: On/In/Out a Solid" --- diff --git a/src/FiltersAPI/CMakeLists.txt b/src/FiltersAPI/CMakeLists.txt index f0ff3da60..82e244436 100644 --- a/src/FiltersAPI/CMakeLists.txt +++ b/src/FiltersAPI/CMakeLists.txt @@ -21,12 +21,14 @@ INCLUDE(Common) SET(PROJECT_HEADERS FiltersAPI.h + FiltersAPI_Argument.h FiltersAPI_Feature.h FiltersAPI_Filter.h FiltersAPI_Selection.h ) SET(PROJECT_SOURCES + FiltersAPI_Argument.cpp FiltersAPI_Feature.cpp FiltersAPI_Filter.cpp FiltersAPI_Selection.cpp diff --git a/src/FiltersAPI/FiltersAPI.i b/src/FiltersAPI/FiltersAPI.i index 6249bfe4a..4c0e18084 100644 --- a/src/FiltersAPI/FiltersAPI.i +++ b/src/FiltersAPI/FiltersAPI.i @@ -45,13 +45,86 @@ %shared_ptr(FiltersAPI_Feature) %shared_ptr(FiltersAPI_Filter) +// function with named parameters +%feature("kwargs") addFilter; + + // std::list -> [] %template(FilterList) std::list >; +%template(ArgumentList) std::list; + +// fix compilarion error: 'res*' was not declared in this scope +%typemap(freearg) const std::list & {} + +%typecheck(SWIG_TYPECHECK_POINTER) std::list, const std::list & { + ModelHighAPI_Selection* temp_selection; + std::string* temp_string; + int newmem = 0; + $1 = 1; + if (PySequence_Check($input)) { + for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) { + PyObject * item = PySequence_GetItem($input, i); + if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (!temp_selection) { + $1 = 0; + } + } else + if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_string, $descriptor(std::string *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (!temp_string) { + $1 = 0; + } + } else + if (!PyUnicode_Check(item)) + $1 = 0; + } + } +} + +%typemap(in) const std::list & (std::list temp) { + ModelHighAPI_Selection* temp_selection; + std::string* temp_string; + int newmem = 0; + if (PySequence_Check($input)) { + for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) { + PyObject * item = PySequence_GetItem($input, i); + if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (!temp_selection) { + PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Selection or string."); + return NULL; + } + temp.push_back(FiltersAPI_Argument(*temp_selection)); + if (newmem & SWIG_CAST_NEW_MEMORY) { + delete temp_selection; + } + } else + if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_string, $descriptor(std::string*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (!temp_string) { + PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Selection or string."); + return NULL; + } + temp.push_back(FiltersAPI_Argument(*temp_string)); + if (newmem & SWIG_CAST_NEW_MEMORY) { + delete temp_string; + } + } else + if (PyUnicode_Check(item)) { + temp.push_back(FiltersAPI_Argument(PyUnicode_AsUTF8(item))); + } else { + PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Selection or string."); + return NULL; + } + Py_DECREF(item); + } + $1 = &temp; + } else { + PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Selection or std::string."); + return NULL; + } +} -// function with named parameters -%feature("kwargs") addFilter; // all supported interfaces +%include "FiltersAPI_Argument.h" %include "FiltersAPI_Feature.h" %include "FiltersAPI_Filter.h" %include "FiltersAPI_Selection.h" diff --git a/src/FiltersAPI/FiltersAPI_Argument.cpp b/src/FiltersAPI/FiltersAPI_Argument.cpp new file mode 100644 index 000000000..d4c77ab2f --- /dev/null +++ b/src/FiltersAPI/FiltersAPI_Argument.cpp @@ -0,0 +1,51 @@ +// 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 "FiltersAPI_Argument.h" + +FiltersAPI_Argument::FiltersAPI_Argument() +{ +} + +FiltersAPI_Argument::FiltersAPI_Argument(const std::string& theValue) + : myValue(theValue) +{ +} + +FiltersAPI_Argument::FiltersAPI_Argument(const ModelHighAPI_Selection& theSelection) + : mySelection(theSelection) +{ +} + +FiltersAPI_Argument::FiltersAPI_Argument(const AttributeSelectionPtr& theSelection) + : mySelectionAttr(theSelection) +{ +} + +FiltersAPI_Argument::~FiltersAPI_Argument() +{ +} + +void FiltersAPI_Argument::dump(ModelHighAPI_Dumper& theDumper) const +{ + if (mySelectionAttr) + theDumper << mySelectionAttr; + else if (mySelection.variantType() == ModelHighAPI_Selection::VT_Empty) + theDumper << "\"" << myValue << "\""; +} diff --git a/src/FiltersAPI/FiltersAPI_Argument.h b/src/FiltersAPI/FiltersAPI_Argument.h new file mode 100644 index 000000000..2e3d2108a --- /dev/null +++ b/src/FiltersAPI/FiltersAPI_Argument.h @@ -0,0 +1,65 @@ +// 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 FILTERSAPI_ARGUMENT_H_ +#define FILTERSAPI_ARGUMENT_H_ + +#include "FiltersAPI.h" + +#include + +#include +#include + +/**\class FiltersAPI_Argument + * \ingroup CPPHighAPI + * \brief Argument of the Filter + */ +class FiltersAPI_Argument +{ +public: + FILTERSAPI_EXPORT FiltersAPI_Argument(); + + FILTERSAPI_EXPORT + FiltersAPI_Argument(const std::string& theValue); + + FILTERSAPI_EXPORT + FiltersAPI_Argument(const ModelHighAPI_Selection& theSelection); + + FILTERSAPI_EXPORT + FiltersAPI_Argument(const AttributeSelectionPtr& theSelection); + + /// Destructor + FILTERSAPI_EXPORT + virtual ~FiltersAPI_Argument(); + + const std::string& string() const { return myValue; } + const ModelHighAPI_Selection& selection() const { return mySelection; } + + /// Dump wrapped feature + FILTERSAPI_EXPORT + void dump(ModelHighAPI_Dumper& theDumper) const; + +private: + std::string myValue; + ModelHighAPI_Selection mySelection; + AttributeSelectionPtr mySelectionAttr; +}; + +#endif diff --git a/src/FiltersAPI/FiltersAPI_Feature.cpp b/src/FiltersAPI/FiltersAPI_Feature.cpp index b6646abfd..8cd8ebeac 100644 --- a/src/FiltersAPI/FiltersAPI_Feature.cpp +++ b/src/FiltersAPI/FiltersAPI_Feature.cpp @@ -35,6 +35,19 @@ FiltersAPI_Feature::~FiltersAPI_Feature() { } +static void separateArguments(const std::list& theArguments, + std::list& theSelections, + std::list& theTextArgs) +{ + std::list::const_iterator anIt = theArguments.begin(); + for (; anIt != theArguments.end(); ++anIt) { + if (anIt->selection().variantType() != ModelHighAPI_Selection::VT_Empty) + theSelections.push_back(anIt->selection()); + else if (!anIt->string().empty()) + theTextArgs.push_back(anIt->string()); + } +} + void FiltersAPI_Feature::setFilters(const std::list& theFilters) { FiltersFeaturePtr aBase = std::dynamic_pointer_cast(feature()); @@ -43,21 +56,32 @@ void FiltersAPI_Feature::setFilters(const std::list& theFilters) aBase->addFilter((*anIt)->name()); aBase->setReversed((*anIt)->name(), (*anIt)->isReversed()); - const std::list& anArgs = (*anIt)->arguments(); + const std::list& anArgs = (*anIt)->arguments(); if (!anArgs.empty()) { - // find selectionList argument and fill it + // separate selection arguments and strings + std::list aSelections; + std::list aTexts; + separateArguments(anArgs, aSelections, aTexts); + + // fill arguments of the filter std::list aFilterArgs = aBase->filterArgs((*anIt)->name()); for (std::list::iterator aFIt = aFilterArgs.begin(); aFIt != aFilterArgs.end(); ++aFIt) { AttributeSelectionListPtr aSelList = std::dynamic_pointer_cast(*aFIt); if (aSelList) - fillAttribute(anArgs, aSelList); + fillAttribute(aSelections, aSelList); else { AttributeSelectionPtr aSelection = std::dynamic_pointer_cast(*aFIt); - if (aSelection && anArgs.size() == 1) - fillAttribute(anArgs.front(), aSelection); + if (aSelection && aSelections.size() == 1) + fillAttribute(aSelections.front(), aSelection); + else { + AttributeStringPtr aString = + std::dynamic_pointer_cast(*aFIt); + if (aString && aTexts.size() == 1) + fillAttribute(aTexts.front(), aString); + } } } } diff --git a/src/FiltersAPI/FiltersAPI_Filter.cpp b/src/FiltersAPI/FiltersAPI_Filter.cpp index 668a89f7b..0e799e49e 100644 --- a/src/FiltersAPI/FiltersAPI_Filter.cpp +++ b/src/FiltersAPI/FiltersAPI_Filter.cpp @@ -22,13 +22,14 @@ #include #include #include +#include #include FiltersAPI_Filter::FiltersAPI_Filter( const std::string& theName, const bool theRevertFilter, - const std::list& theArguments) + const std::list& theArguments) : myName(theName), myReversed(theRevertFilter), myFilterArguments(theArguments) { } @@ -41,19 +42,33 @@ FiltersAPI_Filter::FiltersAPI_Filter(const std::string& theName, anArgIt != theArguments.end(); ++anArgIt) { AttributeBooleanPtr aBoolAttr = std::dynamic_pointer_cast(*anArgIt); - if (aBoolAttr) + if (aBoolAttr) { myReversed = aBoolAttr->value(); - else { - AttributeSelectionListPtr aSelList = - std::dynamic_pointer_cast(*anArgIt); - if (aSelList) { - int aSize = aSelList->size(); - for (int i = 0; i < aSize; ++i) { - AttributeSelectionPtr aSelection = aSelList->value(i); - myFilterArguments.push_back( - ModelHighAPI_Selection(aSelection->context(), aSelection->value())); - } + continue; + } + + AttributeSelectionListPtr aSelList = + std::dynamic_pointer_cast(*anArgIt); + if (aSelList) { + int aSize = aSelList->size(); + for (int i = 0; i < aSize; ++i) { + AttributeSelectionPtr aSelection = aSelList->value(i); + myFilterArguments.push_back(FiltersAPI_Argument(aSelection)); } + continue; + } + + AttributeSelectionPtr aSelection = + std::dynamic_pointer_cast(*anArgIt); + if (aSelection) { + myFilterArguments.push_back(FiltersAPI_Argument(aSelection)); + continue; + } + + AttributeStringPtr aString = std::dynamic_pointer_cast(*anArgIt); + if (aString) { + myFilterArguments.push_back(FiltersAPI_Argument(aString->value())); + continue; } } } @@ -67,15 +82,26 @@ void FiltersAPI_Filter::dump(ModelHighAPI_Dumper& theDumper) const theDumper << "model.addFilter(name = \"" << myName << "\""; if (myReversed) theDumper << ", exclude = " << myReversed; - if (!myFilterArguments.empty()) - theDumper << ", args = []"; + if (!myFilterArguments.empty()) { + theDumper << ", args = ["; + bool isFirstArg = true; + for (std::list::const_iterator anIt = myFilterArguments.begin(); + anIt != myFilterArguments.end(); ++anIt) { + if (isFirstArg) + isFirstArg = false; + else + theDumper << ", "; + anIt->dump(theDumper); + } + theDumper << "]"; + } theDumper << ")"; } // ================================================================================================ FilterAPIPtr addFilter(const std::string& name, const bool exclude, - const std::list& args) + const std::list& args) { return FilterAPIPtr(new FiltersAPI_Filter(name, exclude, args)); } diff --git a/src/FiltersAPI/FiltersAPI_Filter.h b/src/FiltersAPI/FiltersAPI_Filter.h index 27b576b97..987592722 100644 --- a/src/FiltersAPI/FiltersAPI_Filter.h +++ b/src/FiltersAPI/FiltersAPI_Filter.h @@ -21,6 +21,7 @@ #define FILTERSAPI_FILTER_H_ #include "FiltersAPI.h" +#include "FiltersAPI_Argument.h" #include #include @@ -38,7 +39,7 @@ public: FiltersAPI_Filter( const std::string& theName, const bool theRevertFilter = false, - const std::list& theArguments = std::list()); + const std::list& theArguments = std::list()); // Internal constructor based on filter arguments FILTERSAPI_EXPORT @@ -51,7 +52,7 @@ public: const std::string& name() const { return myName; } bool isReversed() const { return myReversed; } - const std::list& arguments() const { return myFilterArguments; } + const std::list& arguments() const { return myFilterArguments; } /// Dump wrapped feature FILTERSAPI_EXPORT @@ -60,7 +61,7 @@ public: private: std::string myName; bool myReversed; - std::list myFilterArguments; + std::list myFilterArguments; }; typedef std::shared_ptr FilterAPIPtr; @@ -69,6 +70,6 @@ typedef std::shared_ptr FilterAPIPtr; FILTERSAPI_EXPORT FilterAPIPtr addFilter(const std::string& name = std::string(), const bool exclude = false, - const std::list& args = std::list()); + const std::list& args = std::list()); #endif diff --git a/src/FiltersAPI/FiltersAPI_swig.h b/src/FiltersAPI/FiltersAPI_swig.h index 2681f4801..ef45dafc9 100644 --- a/src/FiltersAPI/FiltersAPI_swig.h +++ b/src/FiltersAPI/FiltersAPI_swig.h @@ -23,6 +23,7 @@ #include #include "FiltersAPI.h" + #include "FiltersAPI_Argument.h" #include "FiltersAPI_Feature.h" #include "FiltersAPI_Filter.h" #include "FiltersAPI_Selection.h" diff --git a/src/FiltersPlugin/CMakeLists.txt b/src/FiltersPlugin/CMakeLists.txt index d0c305826..994931287 100644 --- a/src/FiltersPlugin/CMakeLists.txt +++ b/src/FiltersPlugin/CMakeLists.txt @@ -54,6 +54,7 @@ SET(PROJECT_LIBRARIES Events Config GeomAPI + GeomAlgoAPI ) SET(XML_RESOURCES @@ -70,6 +71,7 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/Config ${PROJECT_SOURCE_DIR}/src/Events ${PROJECT_SOURCE_DIR}/src/GeomAPI + ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI ${PROJECT_SOURCE_DIR}/src/GeomDataAPI ) @@ -86,12 +88,12 @@ ADD_UNIT_TESTS( TestFilter_OnPlaneSide_Face.py TestFilter_OnPlaneSide_Plane.py TestFilter_OppositeToEdge.py -# TestFilter_RelativeToSolid_In.py -# TestFilter_RelativeToSolid_Out.py -# TestFilter_RelativeToSolid_On.py -# TestFilter_RelativeToSolid_NotOn.py -# TestFilter_RelativeToSolid_InAndOn.py -# TestFilter_RelativeToSolid_OutAndOn.py + TestFilter_RelativeToSolid_In.py + TestFilter_RelativeToSolid_Out.py + TestFilter_RelativeToSolid_On.py + TestFilter_RelativeToSolid_NotOn.py + TestFilter_RelativeToSolid_InAndOn.py + TestFilter_RelativeToSolid_OutAndOn.py TestFilter_HorizontalFaces.py TestFilter_VerticalFaces.py ) diff --git a/src/FiltersPlugin/FiltersPlugin_RelativeToSolid.cpp b/src/FiltersPlugin/FiltersPlugin_RelativeToSolid.cpp index 86743520c..512f66563 100644 --- a/src/FiltersPlugin/FiltersPlugin_RelativeToSolid.cpp +++ b/src/FiltersPlugin/FiltersPlugin_RelativeToSolid.cpp @@ -19,6 +19,10 @@ #include "FiltersPlugin_RelativeToSolid.h" +#include + +#include + #include #include @@ -31,7 +35,41 @@ bool FiltersPlugin_RelativeToSolid::isSupported(GeomAPI_Shape::ShapeType theType bool FiltersPlugin_RelativeToSolid::isOk(const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const { - return false; + AttributePtr anAttr = theArgs.argument("Solid"); + AttributeSelectionPtr aSel = std::dynamic_pointer_cast(anAttr); + if (!aSel) + return false; + + anAttr = theArgs.argument("Location"); + AttributeStringPtr aLocAttr = std::dynamic_pointer_cast(anAttr); + if (!aLocAttr) + return false; + std::string aLocString = aLocAttr->value(); + + GeomShapePtr aSolidSelected = aSel->value(); + if (!aSolidSelected && aSel->context()) + aSolidSelected = aSel->context()->shape(); + GeomSolidPtr aSolid = aSolidSelected ? aSolidSelected->solid() : GeomSolidPtr(); + if (!aSolid) + return false; + + GeomAlgoAPI_SolidClassifier aClassifier(aSolid, theShape); + GeomAlgoAPI_SolidClassifier::State aState = aClassifier.state(); + + bool isOK = false; + if (aLocString == "in") + isOK = aState == GeomAlgoAPI_SolidClassifier::State_IN; + else if (aLocString == "out") + isOK = aState == GeomAlgoAPI_SolidClassifier::State_OUT; + else if (aLocString == "on") + isOK = aState == GeomAlgoAPI_SolidClassifier::State_ON; + else if (aLocString == "not_on") + isOK = !(aState & GeomAlgoAPI_SolidClassifier::State_ON); + else if (aLocString == "not_out") + isOK = !(aState & GeomAlgoAPI_SolidClassifier::State_OUT); + else if (aLocString == "not_in") + isOK = !(aState & GeomAlgoAPI_SolidClassifier::State_IN); + return isOK; } static std::string XMLRepresentation = @@ -46,9 +84,9 @@ static std::string XMLRepresentation = " " " " " " -" " -" " -" " +" " +" " +" " " " ""; diff --git a/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_In.py b/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_In.py new file mode 100644 index 000000000..69937f82c --- /dev/null +++ b/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_In.py @@ -0,0 +1,197 @@ +# 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 SketchAPI import * + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OX"), False) +SketchLine_1 = SketchProjection_1.createdFeature() +SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False) +SketchLine_2 = SketchProjection_2.createdFeature() +SketchArc_1 = Sketch_1.addArc(0, 0, 20, 0, 0, 20, False) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.result(), SketchArc_1.startPoint()) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.result(), SketchArc_1.endPoint()) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchArc_1.center(), SketchAPI_Line(SketchLine_2).startPoint()) +SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], 20) +SketchLine_3 = Sketch_1.addLine(0, 32.83768482493814, 29.63380351263586, 0) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchLine_2.result()) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_1.result()) +SketchLine_4 = Sketch_1.addLine(29.63380351263586, 0, 62.471488337574, 29.63380351263586) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchLine_5 = Sketch_1.addLine(62.471488337574, 29.63380351263586, 32.83768482493814, 62.471488337574) +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchLine_6 = Sketch_1.addLine(32.83768482493814, 62.471488337574, 0, 32.83768482493814) +SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchLine_6.endPoint()) +SketchConstraintPerpendicular_1 = Sketch_1.setPerpendicular(SketchLine_3.result(), SketchLine_4.result()) +SketchConstraintParallel_1 = Sketch_1.setParallel(SketchLine_3.result(), SketchLine_5.result()) +SketchConstraintParallel_2 = Sketch_1.setParallel(SketchLine_4.result(), SketchLine_6.result()) +SketchConstraintDistance_1 = Sketch_1.setDistance(SketchArc_1.center(), SketchLine_3.result(), 22, True) +SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_3.result(), SketchLine_4.result()) +SketchLine_7 = Sketch_1.addLine(0, 20, 0, 0) +SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_7.startPoint()) +SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_7.endPoint()) +SketchLine_8 = Sketch_1.addLine(0, 0, 20, 0) +SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_8.startPoint()) +SketchConstraintCoincidence_13 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_8.endPoint()) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_3f-SketchLine_4f-SketchLine_5f-SketchLine_6f"), model.selection("FACE", "Sketch_1/Face-SketchArc_1_2f-SketchLine_7f-SketchLine_8f")], model.selection(), 30, 0) +Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/To_Face")) +SketchCircle_1 = Sketch_2.addCircle(28.24714778717828, 31.38901581881253, 10) +SketchProjection_3 = Sketch_2.addProjection(model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]"), False) +SketchLine_9 = SketchProjection_3.createdFeature() +SketchConstraintDistance_2 = Sketch_2.setDistance(SketchCircle_1.center(), SketchLine_9.result(), 20, True) +SketchProjection_4 = Sketch_2.addProjection(model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"), False) +SketchLine_10 = SketchProjection_4.createdFeature() +SketchConstraintDistance_3 = Sketch_2.setDistance(SketchCircle_1.center(), SketchLine_10.result(), 20, True) +SketchConstraintRadius_2 = Sketch_2.setRadius(SketchCircle_1.results()[1], 10) +model.do() +Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Sketch_2/Face-SketchCircle_1_2r_wire")], model.selection(), 10, 0) +Extrusion_3 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_1_2r")], model.selection(), 0, 10) +Extrusion_4 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_1_2r")], model.selection(), -10, 20) +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 10, 10) +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Cylinder_1_1")], 50, 10, 10) +Filters = model.filters(Part_1_doc, [model.addFilter(name = "RelativeToSolid", args = [model.selection("SOLID", "Extrusion_1_1"), "in"])]) +model.end() + +Solid1 = Extrusion_1.results()[0].resultSubShapePair()[0] +Solid2 = Extrusion_1.results()[1].resultSubShapePair()[0] +Solid3 = Extrusion_2.result().resultSubShapePair()[0] +Solid4 = Extrusion_3.result().resultSubShapePair()[0] +Solid5 = Extrusion_4.result().resultSubShapePair()[0] +Solid6 = Translation_1.result().resultSubShapePair()[0] + +from GeomAPI import GeomAPI_Shape +emptyShape = GeomAPI_Shape() + +Reference = { + # Solids + model.selection(Solid1, emptyShape): False, + model.selection(Solid2, emptyShape): False, + model.selection(Solid3, emptyShape): False, + model.selection(Solid4, emptyShape): False, + model.selection(Solid5, emptyShape): True, + model.selection(Solid6, emptyShape): False, + + # Faces of solid 1 + model.selection("FACE", "Extrusion_1_1/To_Face"): False, + model.selection("FACE", "Extrusion_1_1/From_Face"): False, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3"): False, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4"): False, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5"): False, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6"): False, + # Faces of solid 2 + model.selection("FACE", "Extrusion_1_2/To_Face"): False, + model.selection("FACE", "Extrusion_1_2/From_Face"): False, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7"): False, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8"): False, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2"): False, + # Faces of solid 3 + model.selection("FACE", "Extrusion_2_1/To_Face"): False, + model.selection("FACE", "Extrusion_2_1/From_Face"): False, + model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2"): False, + # Faces of solid 4 + model.selection("FACE", "Extrusion_3_1/To_Face"): False, + model.selection("FACE", "Extrusion_3_1/From_Face"): True, + model.selection("FACE", "Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2"): False, + # Faces of solid 5 + model.selection("FACE", "Extrusion_4_1/To_Face"): True, + model.selection("FACE", "Extrusion_4_1/From_Face"): True, + model.selection("FACE", "Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2"): True, + # Faces of solid 6 + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_1"): False, + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_2"): False, + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_3"): False, + + # Edges of solid 1 + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6]"): False, + # Edges of solid 2 + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): False, + # Edges of solid 3 + model.selection("EDGE", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face]"): False, + model.selection("EDGE", "([Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face])([Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face])"): False, + # Edges of solid 4 + model.selection("EDGE", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face]"): True, + model.selection("EDGE", "([Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face])([Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face])"): False, + # Edges of solid 5 + model.selection("EDGE", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face]"): True, + model.selection("EDGE", "([Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face])([Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face])"): True, + # Edges of solid 6 + model.selection("EDGE", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2]"): False, + model.selection("EDGE", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3]"): False, + model.selection("EDGE", "([Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2])([Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3])"): False, + + # Vertices of solid 1 + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/From_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/From_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): False, + # Vertices of solid 2 + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/From_Face]"): False, + # Vertices of solid 3 + model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face]"): False, + # Vertices of solid 4 + model.selection("VERTEX", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face]"): True, + # Vertices of solid 5 + model.selection("VERTEX", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face]"): True, + # Vertices of solid 6 + model.selection("VERTEX", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2]"): False, + model.selection("VERTEX", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3]"): False, +} +model.checkFilter(Part_1_doc, model, Filters, Reference) diff --git a/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_InAndOn.py b/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_InAndOn.py new file mode 100644 index 000000000..c3247dee6 --- /dev/null +++ b/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_InAndOn.py @@ -0,0 +1,197 @@ +# 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 SketchAPI import * + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OX"), False) +SketchLine_1 = SketchProjection_1.createdFeature() +SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False) +SketchLine_2 = SketchProjection_2.createdFeature() +SketchArc_1 = Sketch_1.addArc(0, 0, 20, 0, 0, 20, False) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.result(), SketchArc_1.startPoint()) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.result(), SketchArc_1.endPoint()) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchArc_1.center(), SketchAPI_Line(SketchLine_2).startPoint()) +SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], 20) +SketchLine_3 = Sketch_1.addLine(0, 32.83768482493814, 29.63380351263586, 0) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchLine_2.result()) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_1.result()) +SketchLine_4 = Sketch_1.addLine(29.63380351263586, 0, 62.471488337574, 29.63380351263586) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchLine_5 = Sketch_1.addLine(62.471488337574, 29.63380351263586, 32.83768482493814, 62.471488337574) +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchLine_6 = Sketch_1.addLine(32.83768482493814, 62.471488337574, 0, 32.83768482493814) +SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchLine_6.endPoint()) +SketchConstraintPerpendicular_1 = Sketch_1.setPerpendicular(SketchLine_3.result(), SketchLine_4.result()) +SketchConstraintParallel_1 = Sketch_1.setParallel(SketchLine_3.result(), SketchLine_5.result()) +SketchConstraintParallel_2 = Sketch_1.setParallel(SketchLine_4.result(), SketchLine_6.result()) +SketchConstraintDistance_1 = Sketch_1.setDistance(SketchArc_1.center(), SketchLine_3.result(), 22, True) +SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_3.result(), SketchLine_4.result()) +SketchLine_7 = Sketch_1.addLine(0, 20, 0, 0) +SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_7.startPoint()) +SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_7.endPoint()) +SketchLine_8 = Sketch_1.addLine(0, 0, 20, 0) +SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_8.startPoint()) +SketchConstraintCoincidence_13 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_8.endPoint()) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_3f-SketchLine_4f-SketchLine_5f-SketchLine_6f"), model.selection("FACE", "Sketch_1/Face-SketchArc_1_2f-SketchLine_7f-SketchLine_8f")], model.selection(), 30, 0) +Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/To_Face")) +SketchCircle_1 = Sketch_2.addCircle(28.24714778717828, 31.38901581881253, 10) +SketchProjection_3 = Sketch_2.addProjection(model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]"), False) +SketchLine_9 = SketchProjection_3.createdFeature() +SketchConstraintDistance_2 = Sketch_2.setDistance(SketchCircle_1.center(), SketchLine_9.result(), 20, True) +SketchProjection_4 = Sketch_2.addProjection(model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"), False) +SketchLine_10 = SketchProjection_4.createdFeature() +SketchConstraintDistance_3 = Sketch_2.setDistance(SketchCircle_1.center(), SketchLine_10.result(), 20, True) +SketchConstraintRadius_2 = Sketch_2.setRadius(SketchCircle_1.results()[1], 10) +model.do() +Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Sketch_2/Face-SketchCircle_1_2r_wire")], model.selection(), 10, 0) +Extrusion_3 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_1_2r")], model.selection(), 0, 10) +Extrusion_4 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_1_2r")], model.selection(), -10, 20) +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 10, 10) +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Cylinder_1_1")], 50, 10, 10) +Filters = model.filters(Part_1_doc, [model.addFilter(name = "RelativeToSolid", args = [model.selection("SOLID", "Extrusion_1_1"), "not_out"])]) +model.end() + +Solid1 = Extrusion_1.results()[0].resultSubShapePair()[0] +Solid2 = Extrusion_1.results()[1].resultSubShapePair()[0] +Solid3 = Extrusion_2.result().resultSubShapePair()[0] +Solid4 = Extrusion_3.result().resultSubShapePair()[0] +Solid5 = Extrusion_4.result().resultSubShapePair()[0] +Solid6 = Translation_1.result().resultSubShapePair()[0] + +from GeomAPI import GeomAPI_Shape +emptyShape = GeomAPI_Shape() + +Reference = { + # Solids + model.selection(Solid1, emptyShape): True, + model.selection(Solid2, emptyShape): False, + model.selection(Solid3, emptyShape): False, + model.selection(Solid4, emptyShape): True, + model.selection(Solid5, emptyShape): True, + model.selection(Solid6, emptyShape): False, + + # Faces of solid 1 + model.selection("FACE", "Extrusion_1_1/To_Face"): True, + model.selection("FACE", "Extrusion_1_1/From_Face"): True, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3"): True, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4"): True, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5"): True, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6"): True, + # Faces of solid 2 + model.selection("FACE", "Extrusion_1_2/To_Face"): False, + model.selection("FACE", "Extrusion_1_2/From_Face"): False, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7"): False, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8"): False, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2"): False, + # Faces of solid 3 + model.selection("FACE", "Extrusion_2_1/To_Face"): False, + model.selection("FACE", "Extrusion_2_1/From_Face"): True, + model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2"): False, + # Faces of solid 4 + model.selection("FACE", "Extrusion_3_1/To_Face"): True, + model.selection("FACE", "Extrusion_3_1/From_Face"): True, + model.selection("FACE", "Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2"): True, + # Faces of solid 5 + model.selection("FACE", "Extrusion_4_1/To_Face"): True, + model.selection("FACE", "Extrusion_4_1/From_Face"): True, + model.selection("FACE", "Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2"): True, + # Faces of solid 6 + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_1"): False, + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_2"): False, + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_3"): False, + + # Edges of solid 1 + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6]"): True, + # Edges of solid 2 + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): False, + # Edges of solid 3 + model.selection("EDGE", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face]"): True, + model.selection("EDGE", "([Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face])([Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face])"): False, + # Edges of solid 4 + model.selection("EDGE", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face]"): True, + model.selection("EDGE", "([Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face])([Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face])"): True, + # Edges of solid 5 + model.selection("EDGE", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face]"): True, + model.selection("EDGE", "([Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face])([Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face])"): True, + # Edges of solid 6 + model.selection("EDGE", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2]"): False, + model.selection("EDGE", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3]"): False, + model.selection("EDGE", "([Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2])([Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3])"): False, + + # Vertices of solid 1 + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/From_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/From_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): True, + # Vertices of solid 2 + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/From_Face]"): False, + # Vertices of solid 3 + model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face]"): True, + # Vertices of solid 4 + model.selection("VERTEX", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face]"): True, + # Vertices of solid 5 + model.selection("VERTEX", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face]"): True, + # Vertices of solid 6 + model.selection("VERTEX", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2]"): False, + model.selection("VERTEX", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3]"): False, +} +model.checkFilter(Part_1_doc, model, Filters, Reference) diff --git a/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_NotOn.py b/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_NotOn.py new file mode 100644 index 000000000..4c82e357b --- /dev/null +++ b/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_NotOn.py @@ -0,0 +1,197 @@ +# 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 SketchAPI import * + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OX"), False) +SketchLine_1 = SketchProjection_1.createdFeature() +SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False) +SketchLine_2 = SketchProjection_2.createdFeature() +SketchArc_1 = Sketch_1.addArc(0, 0, 20, 0, 0, 20, False) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.result(), SketchArc_1.startPoint()) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.result(), SketchArc_1.endPoint()) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchArc_1.center(), SketchAPI_Line(SketchLine_2).startPoint()) +SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], 20) +SketchLine_3 = Sketch_1.addLine(0, 32.83768482493814, 29.63380351263586, 0) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchLine_2.result()) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_1.result()) +SketchLine_4 = Sketch_1.addLine(29.63380351263586, 0, 62.471488337574, 29.63380351263586) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchLine_5 = Sketch_1.addLine(62.471488337574, 29.63380351263586, 32.83768482493814, 62.471488337574) +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchLine_6 = Sketch_1.addLine(32.83768482493814, 62.471488337574, 0, 32.83768482493814) +SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchLine_6.endPoint()) +SketchConstraintPerpendicular_1 = Sketch_1.setPerpendicular(SketchLine_3.result(), SketchLine_4.result()) +SketchConstraintParallel_1 = Sketch_1.setParallel(SketchLine_3.result(), SketchLine_5.result()) +SketchConstraintParallel_2 = Sketch_1.setParallel(SketchLine_4.result(), SketchLine_6.result()) +SketchConstraintDistance_1 = Sketch_1.setDistance(SketchArc_1.center(), SketchLine_3.result(), 22, True) +SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_3.result(), SketchLine_4.result()) +SketchLine_7 = Sketch_1.addLine(0, 20, 0, 0) +SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_7.startPoint()) +SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_7.endPoint()) +SketchLine_8 = Sketch_1.addLine(0, 0, 20, 0) +SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_8.startPoint()) +SketchConstraintCoincidence_13 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_8.endPoint()) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_3f-SketchLine_4f-SketchLine_5f-SketchLine_6f"), model.selection("FACE", "Sketch_1/Face-SketchArc_1_2f-SketchLine_7f-SketchLine_8f")], model.selection(), 30, 0) +Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/To_Face")) +SketchCircle_1 = Sketch_2.addCircle(28.24714778717828, 31.38901581881253, 10) +SketchProjection_3 = Sketch_2.addProjection(model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]"), False) +SketchLine_9 = SketchProjection_3.createdFeature() +SketchConstraintDistance_2 = Sketch_2.setDistance(SketchCircle_1.center(), SketchLine_9.result(), 20, True) +SketchProjection_4 = Sketch_2.addProjection(model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"), False) +SketchLine_10 = SketchProjection_4.createdFeature() +SketchConstraintDistance_3 = Sketch_2.setDistance(SketchCircle_1.center(), SketchLine_10.result(), 20, True) +SketchConstraintRadius_2 = Sketch_2.setRadius(SketchCircle_1.results()[1], 10) +model.do() +Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Sketch_2/Face-SketchCircle_1_2r_wire")], model.selection(), 10, 0) +Extrusion_3 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_1_2r")], model.selection(), 0, 10) +Extrusion_4 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_1_2r")], model.selection(), -10, 20) +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 10, 10) +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Cylinder_1_1")], 50, 10, 10) +Filters = model.filters(Part_1_doc, [model.addFilter(name = "RelativeToSolid", args = [model.selection("SOLID", "Extrusion_1_1"), "not_on"])]) +model.end() + +Solid1 = Extrusion_1.results()[0].resultSubShapePair()[0] +Solid2 = Extrusion_1.results()[1].resultSubShapePair()[0] +Solid3 = Extrusion_2.result().resultSubShapePair()[0] +Solid4 = Extrusion_3.result().resultSubShapePair()[0] +Solid5 = Extrusion_4.result().resultSubShapePair()[0] +Solid6 = Translation_1.result().resultSubShapePair()[0] + +from GeomAPI import GeomAPI_Shape +emptyShape = GeomAPI_Shape() + +Reference = { + # Solids + model.selection(Solid1, emptyShape): False, + model.selection(Solid2, emptyShape): True, + model.selection(Solid3, emptyShape): False, + model.selection(Solid4, emptyShape): False, + model.selection(Solid5, emptyShape): True, + model.selection(Solid6, emptyShape): False, + + # Faces of solid 1 + model.selection("FACE", "Extrusion_1_1/To_Face"): False, + model.selection("FACE", "Extrusion_1_1/From_Face"): False, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3"): False, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4"): False, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5"): False, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6"): False, + # Faces of solid 2 + model.selection("FACE", "Extrusion_1_2/To_Face"): True, + model.selection("FACE", "Extrusion_1_2/From_Face"): True, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7"): True, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8"): True, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2"): True, + # Faces of solid 3 + model.selection("FACE", "Extrusion_2_1/To_Face"): True, + model.selection("FACE", "Extrusion_2_1/From_Face"): False, + model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2"): False, + # Faces of solid 4 + model.selection("FACE", "Extrusion_3_1/To_Face"): False, + model.selection("FACE", "Extrusion_3_1/From_Face"): True, + model.selection("FACE", "Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2"): False, + # Faces of solid 5 + model.selection("FACE", "Extrusion_4_1/To_Face"): True, + model.selection("FACE", "Extrusion_4_1/From_Face"): True, + model.selection("FACE", "Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2"): True, + # Faces of solid 6 + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_1"): False, + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_2"): False, + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_3"): False, + + # Edges of solid 1 + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6]"): False, + # Edges of solid 2 + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): True, + # Edges of solid 3 + model.selection("EDGE", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face]"): False, + model.selection("EDGE", "([Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face])([Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face])"): False, + # Edges of solid 4 + model.selection("EDGE", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face]"): True, + model.selection("EDGE", "([Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face])([Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face])"): False, + # Edges of solid 5 + model.selection("EDGE", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face]"): True, + model.selection("EDGE", "([Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face])([Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face])"): True, + # Edges of solid 6 + model.selection("EDGE", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2]"): False, + model.selection("EDGE", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3]"): False, + model.selection("EDGE", "([Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2])([Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3])"): True, + + # Vertices of solid 1 + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/From_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/From_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): False, + # Vertices of solid 2 + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/From_Face]"): True, + # Vertices of solid 3 + model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face]"): False, + # Vertices of solid 4 + model.selection("VERTEX", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face]"): True, + # Vertices of solid 5 + model.selection("VERTEX", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face]"): True, + # Vertices of solid 6 + model.selection("VERTEX", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2]"): True, + model.selection("VERTEX", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3]"): True, +} +model.checkFilter(Part_1_doc, model, Filters, Reference) diff --git a/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_On.py b/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_On.py new file mode 100644 index 000000000..aa57cfe4d --- /dev/null +++ b/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_On.py @@ -0,0 +1,197 @@ +# 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 SketchAPI import * + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OX"), False) +SketchLine_1 = SketchProjection_1.createdFeature() +SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False) +SketchLine_2 = SketchProjection_2.createdFeature() +SketchArc_1 = Sketch_1.addArc(0, 0, 20, 0, 0, 20, False) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.result(), SketchArc_1.startPoint()) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.result(), SketchArc_1.endPoint()) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchArc_1.center(), SketchAPI_Line(SketchLine_2).startPoint()) +SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], 20) +SketchLine_3 = Sketch_1.addLine(0, 32.83768482493814, 29.63380351263586, 0) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchLine_2.result()) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_1.result()) +SketchLine_4 = Sketch_1.addLine(29.63380351263586, 0, 62.471488337574, 29.63380351263586) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchLine_5 = Sketch_1.addLine(62.471488337574, 29.63380351263586, 32.83768482493814, 62.471488337574) +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchLine_6 = Sketch_1.addLine(32.83768482493814, 62.471488337574, 0, 32.83768482493814) +SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchLine_6.endPoint()) +SketchConstraintPerpendicular_1 = Sketch_1.setPerpendicular(SketchLine_3.result(), SketchLine_4.result()) +SketchConstraintParallel_1 = Sketch_1.setParallel(SketchLine_3.result(), SketchLine_5.result()) +SketchConstraintParallel_2 = Sketch_1.setParallel(SketchLine_4.result(), SketchLine_6.result()) +SketchConstraintDistance_1 = Sketch_1.setDistance(SketchArc_1.center(), SketchLine_3.result(), 22, True) +SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_3.result(), SketchLine_4.result()) +SketchLine_7 = Sketch_1.addLine(0, 20, 0, 0) +SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_7.startPoint()) +SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_7.endPoint()) +SketchLine_8 = Sketch_1.addLine(0, 0, 20, 0) +SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_8.startPoint()) +SketchConstraintCoincidence_13 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_8.endPoint()) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_3f-SketchLine_4f-SketchLine_5f-SketchLine_6f"), model.selection("FACE", "Sketch_1/Face-SketchArc_1_2f-SketchLine_7f-SketchLine_8f")], model.selection(), 30, 0) +Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/To_Face")) +SketchCircle_1 = Sketch_2.addCircle(28.24714778717828, 31.38901581881253, 10) +SketchProjection_3 = Sketch_2.addProjection(model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]"), False) +SketchLine_9 = SketchProjection_3.createdFeature() +SketchConstraintDistance_2 = Sketch_2.setDistance(SketchCircle_1.center(), SketchLine_9.result(), 20, True) +SketchProjection_4 = Sketch_2.addProjection(model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"), False) +SketchLine_10 = SketchProjection_4.createdFeature() +SketchConstraintDistance_3 = Sketch_2.setDistance(SketchCircle_1.center(), SketchLine_10.result(), 20, True) +SketchConstraintRadius_2 = Sketch_2.setRadius(SketchCircle_1.results()[1], 10) +model.do() +Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Sketch_2/Face-SketchCircle_1_2r_wire")], model.selection(), 10, 0) +Extrusion_3 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_1_2r")], model.selection(), 0, 10) +Extrusion_4 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_1_2r")], model.selection(), -10, 20) +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 10, 10) +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Cylinder_1_1")], 50, 10, 10) +Filters = model.filters(Part_1_doc, [model.addFilter(name = "RelativeToSolid", args = [model.selection("SOLID", "Extrusion_1_1"), "on"])]) +model.end() + +Solid1 = Extrusion_1.results()[0].resultSubShapePair()[0] +Solid2 = Extrusion_1.results()[1].resultSubShapePair()[0] +Solid3 = Extrusion_2.result().resultSubShapePair()[0] +Solid4 = Extrusion_3.result().resultSubShapePair()[0] +Solid5 = Extrusion_4.result().resultSubShapePair()[0] +Solid6 = Translation_1.result().resultSubShapePair()[0] + +from GeomAPI import GeomAPI_Shape +emptyShape = GeomAPI_Shape() + +Reference = { + # Solids + model.selection(Solid1, emptyShape): False, + model.selection(Solid2, emptyShape): False, + model.selection(Solid3, emptyShape): False, + model.selection(Solid4, emptyShape): False, + model.selection(Solid5, emptyShape): False, + model.selection(Solid6, emptyShape): False, + + # Faces of solid 1 + model.selection("FACE", "Extrusion_1_1/To_Face"): True, + model.selection("FACE", "Extrusion_1_1/From_Face"): True, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3"): True, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4"): True, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5"): True, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6"): True, + # Faces of solid 2 + model.selection("FACE", "Extrusion_1_2/To_Face"): False, + model.selection("FACE", "Extrusion_1_2/From_Face"): False, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7"): False, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8"): False, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2"): False, + # Faces of solid 3 + model.selection("FACE", "Extrusion_2_1/To_Face"): False, + model.selection("FACE", "Extrusion_2_1/From_Face"): True, + model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2"): False, + # Faces of solid 4 + model.selection("FACE", "Extrusion_3_1/To_Face"): True, + model.selection("FACE", "Extrusion_3_1/From_Face"): False, + model.selection("FACE", "Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2"): False, + # Faces of solid 5 + model.selection("FACE", "Extrusion_4_1/To_Face"): False, + model.selection("FACE", "Extrusion_4_1/From_Face"): False, + model.selection("FACE", "Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2"): False, + # Faces of solid 6 + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_1"): False, + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_2"): False, + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_3"): False, + + # Edges of solid 1 + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6]"): True, + # Edges of solid 2 + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): False, + # Edges of solid 3 + model.selection("EDGE", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face]"): True, + model.selection("EDGE", "([Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face])([Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face])"): False, + # Edges of solid 4 + model.selection("EDGE", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face]"): False, + model.selection("EDGE", "([Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face])([Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face])"): False, + # Edges of solid 5 + model.selection("EDGE", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face]"): False, + model.selection("EDGE", "([Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face])([Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face])"): False, + # Edges of solid 6 + model.selection("EDGE", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2]"): False, + model.selection("EDGE", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3]"): False, + model.selection("EDGE", "([Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2])([Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3])"): False, + + # Vertices of solid 1 + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/From_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/From_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): True, + # Vertices of solid 2 + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/From_Face]"): False, + # Vertices of solid 3 + model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face]"): True, + # Vertices of solid 4 + model.selection("VERTEX", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face]"): False, + # Vertices of solid 5 + model.selection("VERTEX", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face]"): False, + # Vertices of solid 6 + model.selection("VERTEX", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2]"): False, + model.selection("VERTEX", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3]"): False, +} +model.checkFilter(Part_1_doc, model, Filters, Reference) diff --git a/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_Out.py b/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_Out.py new file mode 100644 index 000000000..eeb33a2bd --- /dev/null +++ b/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_Out.py @@ -0,0 +1,197 @@ +# 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 SketchAPI import * + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OX"), False) +SketchLine_1 = SketchProjection_1.createdFeature() +SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False) +SketchLine_2 = SketchProjection_2.createdFeature() +SketchArc_1 = Sketch_1.addArc(0, 0, 20, 0, 0, 20, False) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.result(), SketchArc_1.startPoint()) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.result(), SketchArc_1.endPoint()) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchArc_1.center(), SketchAPI_Line(SketchLine_2).startPoint()) +SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], 20) +SketchLine_3 = Sketch_1.addLine(0, 32.83768482493814, 29.63380351263586, 0) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchLine_2.result()) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_1.result()) +SketchLine_4 = Sketch_1.addLine(29.63380351263586, 0, 62.471488337574, 29.63380351263586) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchLine_5 = Sketch_1.addLine(62.471488337574, 29.63380351263586, 32.83768482493814, 62.471488337574) +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchLine_6 = Sketch_1.addLine(32.83768482493814, 62.471488337574, 0, 32.83768482493814) +SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchLine_6.endPoint()) +SketchConstraintPerpendicular_1 = Sketch_1.setPerpendicular(SketchLine_3.result(), SketchLine_4.result()) +SketchConstraintParallel_1 = Sketch_1.setParallel(SketchLine_3.result(), SketchLine_5.result()) +SketchConstraintParallel_2 = Sketch_1.setParallel(SketchLine_4.result(), SketchLine_6.result()) +SketchConstraintDistance_1 = Sketch_1.setDistance(SketchArc_1.center(), SketchLine_3.result(), 22, True) +SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_3.result(), SketchLine_4.result()) +SketchLine_7 = Sketch_1.addLine(0, 20, 0, 0) +SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_7.startPoint()) +SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_7.endPoint()) +SketchLine_8 = Sketch_1.addLine(0, 0, 20, 0) +SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_8.startPoint()) +SketchConstraintCoincidence_13 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_8.endPoint()) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_3f-SketchLine_4f-SketchLine_5f-SketchLine_6f"), model.selection("FACE", "Sketch_1/Face-SketchArc_1_2f-SketchLine_7f-SketchLine_8f")], model.selection(), 30, 0) +Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/To_Face")) +SketchCircle_1 = Sketch_2.addCircle(28.24714778717828, 31.38901581881253, 10) +SketchProjection_3 = Sketch_2.addProjection(model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]"), False) +SketchLine_9 = SketchProjection_3.createdFeature() +SketchConstraintDistance_2 = Sketch_2.setDistance(SketchCircle_1.center(), SketchLine_9.result(), 20, True) +SketchProjection_4 = Sketch_2.addProjection(model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"), False) +SketchLine_10 = SketchProjection_4.createdFeature() +SketchConstraintDistance_3 = Sketch_2.setDistance(SketchCircle_1.center(), SketchLine_10.result(), 20, True) +SketchConstraintRadius_2 = Sketch_2.setRadius(SketchCircle_1.results()[1], 10) +model.do() +Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Sketch_2/Face-SketchCircle_1_2r_wire")], model.selection(), 10, 0) +Extrusion_3 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_1_2r")], model.selection(), 0, 10) +Extrusion_4 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_1_2r")], model.selection(), -10, 20) +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 10, 10) +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Cylinder_1_1")], 50, 10, 10) +Filters = model.filters(Part_1_doc, [model.addFilter(name = "RelativeToSolid", args = [model.selection("SOLID", "Extrusion_1_1"), "out"])]) +model.end() + +Solid1 = Extrusion_1.results()[0].resultSubShapePair()[0] +Solid2 = Extrusion_1.results()[1].resultSubShapePair()[0] +Solid3 = Extrusion_2.result().resultSubShapePair()[0] +Solid4 = Extrusion_3.result().resultSubShapePair()[0] +Solid5 = Extrusion_4.result().resultSubShapePair()[0] +Solid6 = Translation_1.result().resultSubShapePair()[0] + +from GeomAPI import GeomAPI_Shape +emptyShape = GeomAPI_Shape() + +Reference = { + # Solids + model.selection(Solid1, emptyShape): False, + model.selection(Solid2, emptyShape): True, + model.selection(Solid3, emptyShape): False, + model.selection(Solid4, emptyShape): False, + model.selection(Solid5, emptyShape): False, + model.selection(Solid6, emptyShape): False, + + # Faces of solid 1 + model.selection("FACE", "Extrusion_1_1/To_Face"): False, + model.selection("FACE", "Extrusion_1_1/From_Face"): False, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3"): False, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4"): False, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5"): False, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6"): False, + # Faces of solid 2 + model.selection("FACE", "Extrusion_1_2/To_Face"): True, + model.selection("FACE", "Extrusion_1_2/From_Face"): True, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7"): True, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8"): True, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2"): True, + # Faces of solid 3 + model.selection("FACE", "Extrusion_2_1/To_Face"): True, + model.selection("FACE", "Extrusion_2_1/From_Face"): False, + model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2"): False, + # Faces of solid 4 + model.selection("FACE", "Extrusion_3_1/To_Face"): False, + model.selection("FACE", "Extrusion_3_1/From_Face"): False, + model.selection("FACE", "Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2"): False, + # Faces of solid 5 + model.selection("FACE", "Extrusion_4_1/To_Face"): False, + model.selection("FACE", "Extrusion_4_1/From_Face"): False, + model.selection("FACE", "Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2"): False, + # Faces of solid 6 + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_1"): False, + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_2"): False, + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_3"): False, + + # Edges of solid 1 + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/From_Face]"): False, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6]"): False, + # Edges of solid 2 + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): True, + # Edges of solid 3 + model.selection("EDGE", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face]"): False, + model.selection("EDGE", "([Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face])([Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face])"): False, + # Edges of solid 4 + model.selection("EDGE", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face]"): False, + model.selection("EDGE", "([Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face])([Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face])"): False, + # Edges of solid 5 + model.selection("EDGE", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face]"): False, + model.selection("EDGE", "([Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face])([Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face])"): False, + # Edges of solid 6 + model.selection("EDGE", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2]"): False, + model.selection("EDGE", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3]"): False, + model.selection("EDGE", "([Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2])([Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3])"): True, + + # Vertices of solid 1 + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/From_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/From_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): False, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): False, + # Vertices of solid 2 + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/From_Face]"): True, + # Vertices of solid 3 + model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face]"): False, + # Vertices of solid 4 + model.selection("VERTEX", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face]"): False, + # Vertices of solid 5 + model.selection("VERTEX", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face]"): False, + # Vertices of solid 6 + model.selection("VERTEX", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2]"): True, + model.selection("VERTEX", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3]"): True, +} +model.checkFilter(Part_1_doc, model, Filters, Reference) diff --git a/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_OutAndOn.py b/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_OutAndOn.py new file mode 100644 index 000000000..6154daae8 --- /dev/null +++ b/src/FiltersPlugin/Test/TestFilter_RelativeToSolid_OutAndOn.py @@ -0,0 +1,197 @@ +# 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 SketchAPI import * + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OX"), False) +SketchLine_1 = SketchProjection_1.createdFeature() +SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False) +SketchLine_2 = SketchProjection_2.createdFeature() +SketchArc_1 = Sketch_1.addArc(0, 0, 20, 0, 0, 20, False) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.result(), SketchArc_1.startPoint()) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.result(), SketchArc_1.endPoint()) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchArc_1.center(), SketchAPI_Line(SketchLine_2).startPoint()) +SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], 20) +SketchLine_3 = Sketch_1.addLine(0, 32.83768482493814, 29.63380351263586, 0) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchLine_2.result()) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_1.result()) +SketchLine_4 = Sketch_1.addLine(29.63380351263586, 0, 62.471488337574, 29.63380351263586) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchLine_5 = Sketch_1.addLine(62.471488337574, 29.63380351263586, 32.83768482493814, 62.471488337574) +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchLine_6 = Sketch_1.addLine(32.83768482493814, 62.471488337574, 0, 32.83768482493814) +SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchLine_6.endPoint()) +SketchConstraintPerpendicular_1 = Sketch_1.setPerpendicular(SketchLine_3.result(), SketchLine_4.result()) +SketchConstraintParallel_1 = Sketch_1.setParallel(SketchLine_3.result(), SketchLine_5.result()) +SketchConstraintParallel_2 = Sketch_1.setParallel(SketchLine_4.result(), SketchLine_6.result()) +SketchConstraintDistance_1 = Sketch_1.setDistance(SketchArc_1.center(), SketchLine_3.result(), 22, True) +SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_3.result(), SketchLine_4.result()) +SketchLine_7 = Sketch_1.addLine(0, 20, 0, 0) +SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_7.startPoint()) +SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_7.endPoint()) +SketchLine_8 = Sketch_1.addLine(0, 0, 20, 0) +SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchLine_8.startPoint()) +SketchConstraintCoincidence_13 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_8.endPoint()) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_3f-SketchLine_4f-SketchLine_5f-SketchLine_6f"), model.selection("FACE", "Sketch_1/Face-SketchArc_1_2f-SketchLine_7f-SketchLine_8f")], model.selection(), 30, 0) +Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/To_Face")) +SketchCircle_1 = Sketch_2.addCircle(28.24714778717828, 31.38901581881253, 10) +SketchProjection_3 = Sketch_2.addProjection(model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]"), False) +SketchLine_9 = SketchProjection_3.createdFeature() +SketchConstraintDistance_2 = Sketch_2.setDistance(SketchCircle_1.center(), SketchLine_9.result(), 20, True) +SketchProjection_4 = Sketch_2.addProjection(model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"), False) +SketchLine_10 = SketchProjection_4.createdFeature() +SketchConstraintDistance_3 = Sketch_2.setDistance(SketchCircle_1.center(), SketchLine_10.result(), 20, True) +SketchConstraintRadius_2 = Sketch_2.setRadius(SketchCircle_1.results()[1], 10) +model.do() +Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Sketch_2/Face-SketchCircle_1_2r_wire")], model.selection(), 10, 0) +Extrusion_3 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_1_2r")], model.selection(), 0, 10) +Extrusion_4 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_1_2r")], model.selection(), -10, 20) +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 10, 10) +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Cylinder_1_1")], 50, 10, 10) +Filters = model.filters(Part_1_doc, [model.addFilter(name = "RelativeToSolid", args = [model.selection("SOLID", "Extrusion_1_1"), "not_in"])]) +model.end() + +Solid1 = Extrusion_1.results()[0].resultSubShapePair()[0] +Solid2 = Extrusion_1.results()[1].resultSubShapePair()[0] +Solid3 = Extrusion_2.result().resultSubShapePair()[0] +Solid4 = Extrusion_3.result().resultSubShapePair()[0] +Solid5 = Extrusion_4.result().resultSubShapePair()[0] +Solid6 = Translation_1.result().resultSubShapePair()[0] + +from GeomAPI import GeomAPI_Shape +emptyShape = GeomAPI_Shape() + +Reference = { + # Solids + model.selection(Solid1, emptyShape): False, + model.selection(Solid2, emptyShape): True, + model.selection(Solid3, emptyShape): True, + model.selection(Solid4, emptyShape): False, + model.selection(Solid5, emptyShape): False, + model.selection(Solid6, emptyShape): False, + + # Faces of solid 1 + model.selection("FACE", "Extrusion_1_1/To_Face"): True, + model.selection("FACE", "Extrusion_1_1/From_Face"): True, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3"): True, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4"): True, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5"): True, + model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6"): True, + # Faces of solid 2 + model.selection("FACE", "Extrusion_1_2/To_Face"): True, + model.selection("FACE", "Extrusion_1_2/From_Face"): True, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7"): True, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8"): True, + model.selection("FACE", "Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2"): True, + # Faces of solid 3 + model.selection("FACE", "Extrusion_2_1/To_Face"): True, + model.selection("FACE", "Extrusion_2_1/From_Face"): True, + model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2"): True, + # Faces of solid 4 + model.selection("FACE", "Extrusion_3_1/To_Face"): True, + model.selection("FACE", "Extrusion_3_1/From_Face"): False, + model.selection("FACE", "Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2"): False, + # Faces of solid 5 + model.selection("FACE", "Extrusion_4_1/To_Face"): False, + model.selection("FACE", "Extrusion_4_1/From_Face"): False, + model.selection("FACE", "Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2"): False, + # Faces of solid 6 + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_1"): False, + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_2"): False, + model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_3"): False, + + # Edges of solid 1 + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6]"): True, + # Edges of solid 2 + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/To_Face]"): True, + model.selection("EDGE", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): True, + # Edges of solid 3 + model.selection("EDGE", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face]"): True, + model.selection("EDGE", "([Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face])([Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face])"): True, + # Edges of solid 4 + model.selection("EDGE", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face]"): True, + model.selection("EDGE", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face]"): False, + model.selection("EDGE", "([Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face])([Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face])"): False, + # Edges of solid 5 + model.selection("EDGE", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face]"): False, + model.selection("EDGE", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face]"): False, + model.selection("EDGE", "([Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face])([Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face])"): False, + # Edges of solid 6 + model.selection("EDGE", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2]"): False, + model.selection("EDGE", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3]"): False, + model.selection("EDGE", "([Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2])([Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3])"): True, + + # Vertices of solid 1 + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/From_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/From_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/From_Face]"): True, + # Vertices of solid 2 + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_2/From_Face]"): True, + model.selection("VERTEX", "[Extrusion_1_2/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_2/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_2/From_Face]"): True, + # Vertices of solid 3 + model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_2_1/From_Face]"): True, + # Vertices of solid 4 + model.selection("VERTEX", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/To_Face]"): True, + model.selection("VERTEX", "[Extrusion_3_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_3_1/From_Face]"): False, + # Vertices of solid 5 + model.selection("VERTEX", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/To_Face]"): False, + model.selection("VERTEX", "[Extrusion_4_1/Generated_Face&Sketch_2/SketchCircle_1_2][Extrusion_4_1/From_Face]"): False, + # Vertices of solid 6 + model.selection("VERTEX", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_2]"): True, + model.selection("VERTEX", "[Translation_1_1/MF:Translated&Cylinder_1_1/Face_1][Translation_1_1/MF:Translated&Cylinder_1_1/Face_3]"): True, +} +model.checkFilter(Part_1_doc, model, Filters, Reference) diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index cecaa458f..49734838f 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -79,6 +79,7 @@ SET(PROJECT_HEADERS GeomAlgoAPI_CurveBuilder.h GeomAlgoAPI_NExplode.h GeomAlgoAPI_Offset.h + GeomAlgoAPI_SolidClassifier.h ) SET(PROJECT_SOURCES @@ -137,6 +138,7 @@ SET(PROJECT_SOURCES GeomAlgoAPI_CurveBuilder.cpp GeomAlgoAPI_NExplode.cpp GeomAlgoAPI_Offset.cpp + GeomAlgoAPI_SolidClassifier.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_SolidClassifier.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_SolidClassifier.cpp new file mode 100644 index 000000000..45533d2d4 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_SolidClassifier.cpp @@ -0,0 +1,203 @@ +// 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 "GeomAlgoAPI_SolidClassifier.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +static GeomAlgoAPI_SolidClassifier::State stateToState(const TopAbs_State theState) +{ + GeomAlgoAPI_SolidClassifier::State aResult; + switch (theState) + { + case TopAbs_IN: + aResult = GeomAlgoAPI_SolidClassifier::State_IN; + break; + case TopAbs_ON: + aResult = GeomAlgoAPI_SolidClassifier::State_ON; + break; + case TopAbs_OUT: + aResult = GeomAlgoAPI_SolidClassifier::State_OUT; + break; + default: + aResult = GeomAlgoAPI_SolidClassifier::State_ALL; + break; + } + return aResult; +} + +static GeomAlgoAPI_SolidClassifier::State +classifyMiddlePoint(BRepClass3d_SolidClassifier& theClassifier, + const GeomShapePtr& theShape, + const double theTolerance) +{ + GeomPointPtr aMiddlePoint = theShape->middlePoint(); + theClassifier.Perform(aMiddlePoint->impl(), theTolerance); + return stateToState(theClassifier.State()); +} + +static GeomAlgoAPI_SolidClassifier::State +classifyVertices(BRepClass3d_SolidClassifier& theClassifier, + const GeomShapePtr& theShape, + const double theTolerance) +{ + GeomAlgoAPI_SolidClassifier::State aResult = GeomAlgoAPI_SolidClassifier::State_UNKNOWN; + TopoDS_Shape aShape = theShape->impl(); + for (TopExp_Explorer anExp(aShape, TopAbs_VERTEX); + anExp.More() && aResult != GeomAlgoAPI_SolidClassifier::State_ALL; + anExp.Next()) { + TopoDS_Vertex aCurV = TopoDS::Vertex(anExp.Current()); + theClassifier.Perform(BRep_Tool::Pnt(aCurV), theTolerance); + aResult |= stateToState(theClassifier.State()); + } + return aResult; +} + +static GeomAlgoAPI_SolidClassifier::State +classifyVicinityOnEdge(BRepClass3d_SolidClassifier& theClassifier, + const TopoDS_Edge& theEdge, + const double theParameter, + const double theTolerance) +{ + // coefficient to step out of the vicinity of theParameter + static const double THE_STEP_COEFF = 2.0; + + BRepAdaptor_Curve aCurve(theEdge); + double aParStep = aCurve.Resolution(theTolerance) * THE_STEP_COEFF; + double aParams[2] = { theParameter - aParStep, theParameter + aParStep }; + + GeomAlgoAPI_SolidClassifier::State aResult = GeomAlgoAPI_SolidClassifier::State_UNKNOWN; + for (double* anIt = std::begin(aParams); anIt != std::end(aParams); ++anIt) { + if (*anIt < aCurve.FirstParameter()) + *anIt = aCurve.FirstParameter(); + else if (*anIt > aCurve.LastParameter()) + *anIt = aCurve.LastParameter(); + + gp_Pnt aPnt = aCurve.Value(*anIt); + theClassifier.Perform(aPnt, theTolerance); + aResult |= stateToState(theClassifier.State()); + } + return aResult; +} + +static GeomAlgoAPI_SolidClassifier::State +classifyVicinityOnFace(BRepClass3d_SolidClassifier& theClassifier, + const TopoDS_Face& theFace, + const double theU, + const double theV, + const double theTolerance) +{ + // coefficient to step out of the vicinity of parameters + static const double THE_STEP_COEFF = 2.0; + + BRepAdaptor_Surface aSurf(theFace); + double aStepU = aSurf.UResolution(theTolerance) * THE_STEP_COEFF; + double aStepV = aSurf.VResolution(theTolerance) * THE_STEP_COEFF; + double aParamsU[3] = { theU - aStepU, theU, theU + aStepU }; + double aParamsV[3] = { theV - aStepV, theV, theV + aStepV }; + for (double* aU = std::begin(aParamsU); aU != std::end(aParamsU); ++aU) { + if (*aU < aSurf.FirstUParameter()) + *aU = aSurf.FirstUParameter(); + else if (*aU > aSurf.LastUParameter()) + *aU = aSurf.LastUParameter(); + } + for (double* aV = std::begin(aParamsV); aV != std::end(aParamsV); ++aV) { + if (*aV < aSurf.FirstVParameter()) + *aV = aSurf.FirstVParameter(); + else if (*aV > aSurf.LastVParameter()) + *aV = aSurf.LastVParameter(); + } + + GeomAlgoAPI_SolidClassifier::State aResult = GeomAlgoAPI_SolidClassifier::State_UNKNOWN; + for (double* aU = std::begin(aParamsU); aU != std::end(aParamsU); ++aU) + for (double* aV = std::begin(aParamsV); aV != std::end(aParamsV); ++aV) { + gp_Pnt aPnt = aSurf.Value(*aU, *aV); + theClassifier.Perform(aPnt, theTolerance); + aResult |= stateToState(theClassifier.State()); + } + return aResult; +} + +static GeomAlgoAPI_SolidClassifier::State +classifyByDistance(BRepClass3d_SolidClassifier& theClassifier, + const GeomShapePtr& theSolid, + const GeomShapePtr& theShape, + const double theTolerance) +{ + GeomAlgoAPI_SolidClassifier::State aResult = GeomAlgoAPI_SolidClassifier::State_UNKNOWN; + + const TopoDS_Shape& aSolid = theSolid->impl(); + const TopoDS_Shape& aShape = theShape->impl(); + for (TopExp_Explorer anExp(aSolid, TopAbs_SHELL); anExp.More(); anExp.Next()) { + // compare distance from the shape to the solid's shells + BRepExtrema_DistShapeShape aDistance(anExp.Current(), aShape); + if (aDistance.Perform() && aDistance.Value() < theTolerance) { + aResult |= GeomAlgoAPI_SolidClassifier::State_ON; + // classify vicinity of intersection points + for (int sol = 1; sol <= aDistance.NbSolution(); ++sol) { + if (aDistance.SupportTypeShape2(sol) == BRepExtrema_IsOnEdge) { + TopoDS_Edge anEdge = TopoDS::Edge(aDistance.SupportOnShape2(sol)); + double aParOnEdge; + aDistance.ParOnEdgeS2(sol, aParOnEdge); + + aResult |= classifyVicinityOnEdge(theClassifier, anEdge, aParOnEdge, theTolerance); + } + else if (aDistance.SupportTypeShape2(sol) == BRepExtrema_IsInFace) { + TopoDS_Face aFace = TopoDS::Face(aDistance.SupportOnShape2(sol)); + double aParU, aParV; + aDistance.ParOnFaceS2(sol, aParU, aParV); + + aResult |= classifyVicinityOnFace(theClassifier, aFace, aParU, aParV, theTolerance); + } + } + } + } + return aResult; +} + + +//================================================================================================== +GeomAlgoAPI_SolidClassifier::GeomAlgoAPI_SolidClassifier(const GeomSolidPtr theSolid, + const GeomShapePtr theShape, + const double theTolerance) + : myState(State_UNKNOWN) +{ + if (!theSolid || !theShape) + return; + + BRepClass3d_SolidClassifier aClassifierAlgo(theSolid->impl()); + + myState = classifyMiddlePoint(aClassifierAlgo, theShape, theTolerance); + if (!theShape->isVertex()) + myState |= classifyVertices(aClassifierAlgo, theShape, theTolerance); + myState |= classifyByDistance(aClassifierAlgo, theSolid, theShape, theTolerance); + + if (myState == State_ALL) + myState = State_UNKNOWN; +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_SolidClassifier.h b/src/GeomAlgoAPI/GeomAlgoAPI_SolidClassifier.h new file mode 100644 index 000000000..fa8ab2526 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_SolidClassifier.h @@ -0,0 +1,60 @@ +// 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 GeomAlgoAPI_SolidClassifier_H_ +#define GeomAlgoAPI_SolidClassifier_H_ + +#include + +#include + +class GeomAPI_Shape; +class GeomAPI_Solid; + +/// \class GeomAlgoAPI_SolidClassifier +/// \ingroup DataAlgo +/// \brief Classify shape according to the given solid. +class GeomAlgoAPI_SolidClassifier +{ +public: + typedef int State; + + static const State State_UNKNOWN = 0x0; + static const State State_IN = 0x1; + static const State State_ON = 0x2; + static const State State_OUT = 0x4; + static const State State_ALL = State_IN & State_ON & State_OUT; + +public: + /// \brief Perform classification of the shape according to the solid. + /// \param[in] theSolid the base solid + /// \param[in] theShape the shape to classify + /// \param[in] theTolerance comparison tolrence + GEOMALGOAPI_EXPORT GeomAlgoAPI_SolidClassifier(const std::shared_ptr theSolid, + const std::shared_ptr theShape, + const double theTolerance = 1.e-7); + + /// \return Classification result. + State state() const { return myState; } + +private: + State myState; +}; + +#endif diff --git a/src/ModelHighAPI/ModelHighAPI.i b/src/ModelHighAPI/ModelHighAPI.i index 819e75797..896af71ef 100644 --- a/src/ModelHighAPI/ModelHighAPI.i +++ b/src/ModelHighAPI/ModelHighAPI.i @@ -246,6 +246,7 @@ // std::pair -> [] %template(ResultSubShapePair) std::pair, std::shared_ptr >; +%template(StringsPair) std::pair; // fix compilarion error: 'res*' was not declared in this scope diff --git a/src/PythonAPI/model/tests/tests.py b/src/PythonAPI/model/tests/tests.py index 167f5c2bf..687d2e1bb 100644 --- a/src/PythonAPI/model/tests/tests.py +++ b/src/PythonAPI/model/tests/tests.py @@ -340,16 +340,22 @@ def checkFilter(thePartDoc, theModel, theFilter, theShapesList): aFiltersFactory = ModelAPI_Session.get().filters() for sel, res in theShapesList.items(): needUndo = False + shapeName = "" + shapeType = "UNKNOWN" if sel.variantType() == ModelHighAPI_Selection.VT_ResultSubShapePair: shape = sel.resultSubShapePair()[1] if shape.isNull(): shape = sel.resultSubShapePair()[0].shape() + shapeName = sel.name() + shapeType = shape.shapeTypeStr() else: needUndo = True theModel.begin() subShapeFeature = createSubShape(thePartDoc, theModel, sel) theModel.end() shape = subShapeFeature.results()[0].resultSubShapePair()[0].shape() - assert(aFiltersFactory.isValid(theFilter.feature(), shape) == res) + shapeType = sel.typeSubShapeNamePair()[0] + shapeName = sel.typeSubShapeNamePair()[1] + assert aFiltersFactory.isValid(theFilter.feature(), shape) == res, "Filter result for {} \"{}\" incorrect. Expected {}.".format(shapeType, shapeName, res) if needUndo: theModel.undo()