From: mpv Date: Thu, 18 Jan 2018 14:34:34 +0000 (+0300) Subject: Fix for the issue #2413 X-Git-Tag: V_3.0.0RC1~23 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fd08aa05db79437b007fb2d691baca021a4f4aa9;p=modules%2Fshaper.git Fix for the issue #2413 --- diff --git a/src/BuildPlugin/BuildPlugin_CompSolid.cpp b/src/BuildPlugin/BuildPlugin_CompSolid.cpp index 8b19e13f3..c88cac324 100644 --- a/src/BuildPlugin/BuildPlugin_CompSolid.cpp +++ b/src/BuildPlugin/BuildPlugin_CompSolid.cpp @@ -20,7 +20,7 @@ #include "BuildPlugin_CompSolid.h" -#include +#include #include //================================================================================================= @@ -37,22 +37,20 @@ void BuildPlugin_CompSolid::initAttributes() //================================================================================================= void BuildPlugin_CompSolid::execute() { + // all the needed checkings are in validator, so, here just make and store result ListOfShape anOriginalShapes; - std::shared_ptr aVolumeMaker; - if (!build(anOriginalShapes, aVolumeMaker)) - return; - - GeomShapePtr aVolumeRes = aVolumeMaker->shape(); + AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID()); + for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + GeomShapePtr aShape = aSelection->value(); + if (!aShape.get()) + aShape = aSelection->context()->shape(); + anOriginalShapes.push_back(aShape); + } + std::shared_ptr anAlgo(new GeomAlgoAPI_MakeVolume(anOriginalShapes)); + GeomShapePtr aVolumeRes = anAlgo->shape(); // check and process result of volume maker - GeomShapePtr aResShape = getSingleSubshape(aVolumeRes, GeomAPI_Shape::COMPSOLID); - if (!aResShape) // try to build a solid - aResShape = getSingleSubshape(aVolumeRes, GeomAPI_Shape::SOLID); - - int anIndex = 0; - if (aResShape) { - storeResult(anOriginalShapes, aResShape, aVolumeMaker); - ++anIndex; - } - removeResults(anIndex); + GeomShapePtr aResShape = getSingleSubshape(aVolumeRes); + storeResult(anOriginalShapes, aResShape, anAlgo); } diff --git a/src/BuildPlugin/BuildPlugin_Plugin.cpp b/src/BuildPlugin/BuildPlugin_Plugin.cpp index 7915c1447..800884c10 100644 --- a/src/BuildPlugin/BuildPlugin_Plugin.cpp +++ b/src/BuildPlugin/BuildPlugin_Plugin.cpp @@ -50,6 +50,8 @@ BuildPlugin_Plugin::BuildPlugin_Plugin() new BuildPlugin_ValidatorBaseForWire()); aFactory->registerValidator("BuildPlugin_ValidatorBaseForFace", new BuildPlugin_ValidatorBaseForFace()); + aFactory->registerValidator("BuildPlugin_ValidatorBaseForSolids", + new BuildPlugin_ValidatorBaseForSolids()); aFactory->registerValidator("BuildPlugin_ValidatorSubShapesSelection", new BuildPlugin_ValidatorSubShapesSelection()); aFactory->registerValidator("BuildPlugin_ValidatorFillingSelection", diff --git a/src/BuildPlugin/BuildPlugin_Solid.cpp b/src/BuildPlugin/BuildPlugin_Solid.cpp index 1066c3f58..5a9899526 100644 --- a/src/BuildPlugin/BuildPlugin_Solid.cpp +++ b/src/BuildPlugin/BuildPlugin_Solid.cpp @@ -41,48 +41,20 @@ void BuildPlugin_Solid::initAttributes() //================================================================================================= void BuildPlugin_Solid::execute() { + // all the needed checkings are in validator, so, here just make and store result ListOfShape anOriginalShapes; - std::shared_ptr aVolumeMaker; - if (!build(anOriginalShapes, aVolumeMaker)) - return; - - // check and process result of volume maker - GeomShapePtr aResShape = getSingleSubshape(aVolumeMaker->shape(), GeomAPI_Shape::SOLID); - int anIndex = 0; - if (aResShape) { - storeResult(anOriginalShapes, aResShape, aVolumeMaker); - ++anIndex; - } - removeResults(anIndex); -} - -//================================================================================================= -bool BuildPlugin_Solid::build(ListOfShape& theOriginalShapes, - std::shared_ptr& theAlgorithm) -{ - // Get base objects list. AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID()); - if (!aSelectionList.get()) { - setError("Error: Could not get selection list."); - return false; - } - if (aSelectionList->size() == 0) { - setError("Error: Empty selection list."); - return false; - } - - // Collect base shapes. for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); GeomShapePtr aShape = aSelection->value(); if (!aShape.get()) aShape = aSelection->context()->shape(); - theOriginalShapes.push_back(aShape); + anOriginalShapes.push_back(aShape); } - - theAlgorithm = - std::shared_ptr(new GeomAlgoAPI_MakeVolume(theOriginalShapes)); - return !isAlgorithmFailed(theAlgorithm); + std::shared_ptr anAlgo(new GeomAlgoAPI_MakeVolume(anOriginalShapes)); + // check and process result of volume maker + GeomShapePtr aResShape = getSingleSubshape(anAlgo->shape()); + storeResult(anOriginalShapes, aResShape, anAlgo); } void BuildPlugin_Solid::storeResult(const ListOfShape& theOriginalShapes, @@ -101,55 +73,17 @@ void BuildPlugin_Solid::storeResult(const ListOfShape& theOriginalShapes, aResultBody->loadAndOrientModifiedShapes(theAlgorithm.get(), aShape, GeomAPI_Shape::FACE, aModifiedTag, "Modified_Face", *aMapOfSubs.get(), false, true, true); } - setResult(aResultBody); } -GeomShapePtr BuildPlugin_Solid::getSingleSubshape(const GeomShapePtr& theCompound, - const GeomAPI_Shape::ShapeType theShapeType) +GeomShapePtr BuildPlugin_Solid::getSingleSubshape(const GeomShapePtr& theCompound) { - if (theCompound->shapeType() == theShapeType) - return theCompound; - else if (theCompound->shapeType() == GeomAPI_Shape::COMPOUND) { + if (theCompound->shapeType() == GeomAPI_Shape::COMPOUND) { GeomAPI_ShapeIterator anIt(theCompound); GeomShapePtr aFoundSub; for (; anIt.more() && !aFoundSub; anIt.next()) { - aFoundSub = anIt.current(); - if (aFoundSub->shapeType() != theShapeType) - return GeomShapePtr(); // not alone sub-shape + return anIt.current(); } - if (anIt.more()) { - std::string anError = "Error: unable to build a "; - switch (theShapeType) { - case GeomAPI_Shape::SOLID: anError += "solid"; break; - case GeomAPI_Shape::COMPSOLID: anError += "compsolid"; break; - default: anError += "subshape"; break; - } - setError(anError); - } else - return aFoundSub; - } - // not a solid - return GeomShapePtr(); -} - -bool BuildPlugin_Solid::isAlgorithmFailed( - const std::shared_ptr& theAlgorithm) -{ - if (!theAlgorithm->isDone()) { - static const std::string aFeatureError = "Error: MakeVolume algorithm failed."; - setError(aFeatureError); - return true; - } - if (theAlgorithm->shape()->isNull()) { - static const std::string aShapeError = "Error: Resulting shape of MakeVolume is Null."; - setError(aShapeError); - return true; - } - if (!theAlgorithm->isValid()) { - std::string aFeatureError = "Error: Resulting shape of MakeVolume is not valid."; - setError(aFeatureError); - return true; } - return false; + return theCompound; } diff --git a/src/BuildPlugin/BuildPlugin_Solid.h b/src/BuildPlugin/BuildPlugin_Solid.h index 549ee49d0..1fce3df58 100644 --- a/src/BuildPlugin/BuildPlugin_Solid.h +++ b/src/BuildPlugin/BuildPlugin_Solid.h @@ -65,24 +65,13 @@ public: BUILDPLUGIN_EXPORT virtual void execute(); protected: - /// Build result - /// \param[out] theOriginalShapes list of original shapes - /// \param[out] theAlgorithm algorithm to build result - /// \return \c true if algorithm finished without errors - bool build(ListOfShape& theOriginalShapes, std::shared_ptr& theAlgorithm); - /// Store result of algorithm void storeResult(const ListOfShape& theOriginalShapes, const GeomShapePtr& theResultShape, const std::shared_ptr& theAlgorithm); - /// Check the algorithm is failed - bool isAlgorithmFailed(const std::shared_ptr& theAlgorithm); - - /// Explode compound to get single shape of specified type - /// \return Empty shape if there is more than one shape in compound - GeomShapePtr getSingleSubshape(const GeomShapePtr& theCompound, - const GeomAPI_Shape::ShapeType theShapeType); + /// Explode compound to get single shape + GeomShapePtr getSingleSubshape(const GeomShapePtr& theCompound); }; #endif diff --git a/src/BuildPlugin/BuildPlugin_Validators.cpp b/src/BuildPlugin/BuildPlugin_Validators.cpp index 833536d40..8c58b4777 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.cpp +++ b/src/BuildPlugin/BuildPlugin_Validators.cpp @@ -33,6 +33,9 @@ #include #include #include +#include +#include +#include #include #include @@ -160,13 +163,6 @@ bool BuildPlugin_ValidatorBaseForWire::isValid(const std::shared_ptr& theFeature, const std::list& theArguments, @@ -264,12 +260,87 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr& theFeature, const std::list& theArguments, + Events_InfoMessage& theError) const { - return false; + // Get base objects list. + AttributeSelectionListPtr aSelectionList = theFeature->selectionList(theArguments.front()); + if (!aSelectionList.get()) { + theError = "Could not get selection list."; + return false; + } + if (aSelectionList->size() == 0) { + theError = "Empty selection list."; + return false; + } + + // Collect base shapes. + ListOfShape anOriginalShapes; + for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) { + AttributeSelectionPtr aSelection = aSelectionList->value(anIndex); + GeomShapePtr aShape = aSelection->value(); + if (!aShape.get()) + aShape = aSelection->context()->shape(); + anOriginalShapes.push_back(aShape); + } + + std::shared_ptr anAlgorithm(new GeomAlgoAPI_MakeVolume(anOriginalShapes)); + + if (!anAlgorithm->isDone()) { + theError = "MakeVolume algorithm failed."; + return false; + } + if (anAlgorithm->shape()->isNull()) { + theError = "Resulting shape of MakeVolume is Null."; + return false; + } + if (!anAlgorithm->isValid()) { + theError = "Resulting shape of MakeVolume is not valid."; + return false; + } + + // set of allowed types of results + std::set aResultType; + std::string aType = theArguments.back(); + if (aType == "solid") + aResultType.insert(GeomAPI_Shape::SOLID); + else if (aType == "compsolid") { + aResultType.insert(GeomAPI_Shape::COMPSOLID); + aResultType.insert(GeomAPI_Shape::SOLID); + } + + GeomShapePtr aCompound = anAlgorithm->shape(); + if (aCompound->shapeType() == GeomAPI_Shape::COMPOUND) { + GeomAPI_ShapeIterator anIt(aCompound); + GeomShapePtr aFoundSub; + for (; anIt.more() && !aFoundSub; anIt.next()) { + aFoundSub = anIt.current(); + if (aResultType.count(aFoundSub->shapeType()) == 0) { + theError = "Unable to build a solid"; + return false; + } + } + if (anIt.more() || !aFoundSub.get()) { + theError = "Unable to build a solid"; + return false; + } + } else if (aResultType.count(aCompound->shapeType()) == 0) { + theError = "Unable to build a solid"; + return false; + } + // check the internal faces presence + for(GeomAPI_ShapeExplorer aFaces(aCompound, GeomAPI_Shape::FACE); aFaces.more(); aFaces.next()) { + if (aFaces.current()->orientation() == GeomAPI_Shape::INTERNAL) { + theError = "Internal faces are not allowed in the resulting solid"; + return false; + } + } + + return true; } + //================================================================================================= bool BuildPlugin_ValidatorSubShapesSelection::isValid(const AttributePtr& theAttribute, const std::list& theArguments, diff --git a/src/BuildPlugin/BuildPlugin_Validators.h b/src/BuildPlugin/BuildPlugin_Validators.h index 5f3be35da..d69f0b8b7 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.h +++ b/src/BuildPlugin/BuildPlugin_Validators.h @@ -55,9 +55,6 @@ public: virtual bool isValid(const std::shared_ptr& theFeature, const std::list& theArguments, Events_InfoMessage& theError) const; - - /// \return true if the attribute in feature is not obligatory for the feature execution - virtual bool isNotObligatory(std::string theFeature, std::string theAttribute); }; /// \class BuildPlugin_ValidatorBaseForFace @@ -74,9 +71,22 @@ public: virtual bool isValid(const std::shared_ptr& theFeature, const std::list& theArguments, Events_InfoMessage& theError) const; +}; - /// \return true if the attribute in feature is not obligatory for the feature execution - virtual bool isNotObligatory(std::string theFeature, std::string theAttribute); +/// \class BuildPlugin_ValidatorBaseForSolids +/// \ingroup Validators +/// \brief A validator for selection base shapes for solid. Allows to select faces closed enough +/// to create a solid. +class BuildPlugin_ValidatorBaseForSolids: public ModelAPI_FeatureValidator +{ +public: + //! Returns true if attributes is ok. + //! \param theFeature the checked feature. + //! \param theArguments arguments of the feature. + //! \param theError error message. + virtual bool isValid(const std::shared_ptr& theFeature, + const std::list& theArguments, + Events_InfoMessage& theError) const; }; /// \class BuildPlugin_ValidatorSubShapesSelection diff --git a/src/BuildPlugin/compsolid_widget.xml b/src/BuildPlugin/compsolid_widget.xml index ab3626ab9..bdeb1df49 100644 --- a/src/BuildPlugin/compsolid_widget.xml +++ b/src/BuildPlugin/compsolid_widget.xml @@ -27,4 +27,5 @@ email : webmaster.salome@opencascade.com + diff --git a/src/BuildPlugin/solid_widget.xml b/src/BuildPlugin/solid_widget.xml index f45b981d7..c427af36e 100644 --- a/src/BuildPlugin/solid_widget.xml +++ b/src/BuildPlugin/solid_widget.xml @@ -27,4 +27,5 @@ email : webmaster.salome@opencascade.com + diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index 41fcdc652..b4ca4332f 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -132,13 +132,6 @@ bool FeaturesPlugin_ValidatorPipeLocations::isValid( return true; } -//================================================================================================== -bool FeaturesPlugin_ValidatorPipeLocations::isNotObligatory(std::string theFeature, - std::string theAttribute) -{ - return false; -} - //================================================================================================== bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theAttribute, const std::list& theArguments, @@ -282,14 +275,6 @@ bool FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects::isValid( return true; } -//================================================================================================== -bool FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects::isNotObligatory( - std::string theFeature, - std::string theAttribute) -{ - return false; -} - //================================================================================================== bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const AttributePtr& theAttribute, const std::list& theArguments, @@ -525,13 +510,6 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isValid( return true; } -//================================================================================================== -bool FeaturesPlugin_ValidatorExtrusionDir::isNotObligatory(std::string theFeature, - std::string theAttribute) -{ - return false; -} - //================================================================================================== bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr& theAttribute, Events_InfoMessage& theError) const @@ -872,13 +850,6 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid( return true; } -//================================================================================================== -bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isNotObligatory(std::string theFeature, - std::string theAttribute) -{ - return false; -} - //================================================================================================== bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttribute, const std::list& theArguments, @@ -983,13 +954,6 @@ bool FeaturesPlugin_ValidatorUnionArguments::isValid( return true; } -//================================================================================================== -bool FeaturesPlugin_ValidatorUnionArguments::isNotObligatory(std::string theFeature, - std::string theAttribute) -{ - return false; -} - bool FeaturesPlugin_ValidatorConcealedResult::isValid(const AttributePtr& theAttribute, const std::list& theArguments, Events_InfoMessage& theError) const diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.h b/src/FeaturesPlugin/FeaturesPlugin_Validators.h index 62edcb2bf..b54b3f0be 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.h @@ -52,9 +52,6 @@ class FeaturesPlugin_ValidatorPipeLocations: public ModelAPI_FeatureValidator virtual bool isValid(const std::shared_ptr& theFeature, const std::list& theArguments, Events_InfoMessage& theError) const; - - /// Returns true if the attribute in feature is not obligatory for the feature execution - virtual bool isNotObligatory(std::string theFeature, std::string theAttribute); }; /// \class FeaturesPlugin_ValidatorBaseForGeneration @@ -93,9 +90,6 @@ class FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects: virtual bool isValid(const std::shared_ptr& theFeature, const std::list& theArguments, Events_InfoMessage& theError) const; - - /// Returns true if the attribute in feature is not obligatory for the feature execution - virtual bool isNotObligatory(std::string theFeature, std::string theAttribute); }; /// \class FeaturesPlugin_ValidatorCompositeLauncher @@ -128,9 +122,6 @@ public: const std::list& theArguments, Events_InfoMessage& theError) const; - /// \return true if the attribute in feature is not obligatory for the feature execution - virtual bool isNotObligatory(std::string theFeature, std::string theAttribute); - private: bool isShapesCanBeEmpty(const AttributePtr& theAttribute, Events_InfoMessage& theError) const; @@ -213,9 +204,6 @@ class FeaturesPlugin_ValidatorRemoveSubShapesResult: public ModelAPI_FeatureVali virtual bool isValid(const std::shared_ptr& theFeature, const std::list& theArguments, Events_InfoMessage& theError) const; - - /// \return true if the attribute in feature is not obligatory for the feature execution - virtual bool isNotObligatory(std::string theFeature, std::string theAttribute); }; /// \class FeaturesPlugin_ValidatorUnionSelection @@ -247,9 +235,6 @@ class FeaturesPlugin_ValidatorUnionArguments: public ModelAPI_FeatureValidator virtual bool isValid(const std::shared_ptr& theFeature, const std::list& theArguments, Events_InfoMessage& theError) const; - - /// \return true if the attribute in feature is not obligatory for the feature execution - virtual bool isNotObligatory(std::string theFeature, std::string theAttribute); }; /// \class FeaturesPlugin_ValidatorConcealedResult diff --git a/src/GeomValidators/GeomValidators_MinObjectsSelected.cpp b/src/GeomValidators/GeomValidators_MinObjectsSelected.cpp index 6b615acac..8a7d171db 100644 --- a/src/GeomValidators/GeomValidators_MinObjectsSelected.cpp +++ b/src/GeomValidators/GeomValidators_MinObjectsSelected.cpp @@ -55,10 +55,3 @@ bool GeomValidators_MinObjectsSelected::isValid(const std::shared_ptr& theFeature, const std::list& theArguments, Events_InfoMessage& theError) const; - - /// \return true if the attribute in feature is not obligatory for the feature execution. - GEOMVALIDATORS_EXPORT virtual bool isNotObligatory(std::string theFeature, - std::string theAttribute); }; #endif diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index b9818c04c..d1633aa42 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -200,4 +200,5 @@ ADD_UNIT_TESTS(TestConstants.py Test2358_2.py Test2396.py Test2401.py + Test2413.py ) diff --git a/src/ModelAPI/ModelAPI_FeatureValidator.cpp b/src/ModelAPI/ModelAPI_FeatureValidator.cpp index be6abef50..1f679054b 100644 --- a/src/ModelAPI/ModelAPI_FeatureValidator.cpp +++ b/src/ModelAPI/ModelAPI_FeatureValidator.cpp @@ -29,3 +29,8 @@ ModelAPI_FeatureValidator::~ModelAPI_FeatureValidator() { } + +bool ModelAPI_FeatureValidator::isNotObligatory(std::string theFeature, std::string theAttribute) +{ + return false; +} \ No newline at end of file diff --git a/src/ModelAPI/ModelAPI_FeatureValidator.h b/src/ModelAPI/ModelAPI_FeatureValidator.h index b61b98f41..2d87158b7 100644 --- a/src/ModelAPI/ModelAPI_FeatureValidator.h +++ b/src/ModelAPI/ModelAPI_FeatureValidator.h @@ -48,8 +48,9 @@ class MODELAPI_EXPORT ModelAPI_FeatureValidator : public ModelAPI_Validator const std::list& theArguments, Events_InfoMessage& theError) const = 0; - /// Returns true if the attribute in feature is not obligatory for the feature execution - virtual bool isNotObligatory(std::string theFeature, std::string theAttribute) = 0; + /// Returns true if the attribute in feature is not obligatory for the feature execution. + ///Returns false by default. + virtual bool isNotObligatory(std::string theFeature, std::string theAttribute); }; #endif diff --git a/src/ModelAPI/Test/Test2413.py b/src/ModelAPI/Test/Test2413.py new file mode 100644 index 000000000..cb70bf684 --- /dev/null +++ b/src/ModelAPI/Test/Test2413.py @@ -0,0 +1,80 @@ +## Copyright (C) 2014-2017 CEA/DEN, EDF R&D +## +## This library is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## This library is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with this library; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +## +## See http:##www.salome-platform.org/ or +## email : webmaster.salome@opencascade.com +## + +from salome.shaper import model + +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")) +SketchLine_1 = Sketch_1.addLine(0, 0, 0, 50) +SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False) +SketchPoint_1 = SketchProjection_1.createdFeature() +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchPoint_1.result()) +SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False) +SketchLine_2 = SketchProjection_2.createdFeature() +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.result()) +SketchArc_1 = Sketch_1.addArc(0, 0, 0, 50, 50, 0, True) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchArc_1.center()) +SketchLine_3 = Sketch_1.addLine(0, 0, 50, 0) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_4.setName("SketchConstraintCoincidence_5") +SketchProjection_3 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OX"), False) +SketchLine_4 = SketchProjection_3.createdFeature() +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.result()) +SketchConstraintCoincidence_5.setName("SketchConstraintCoincidence_6") +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_3.endPoint()) +SketchConstraintCoincidence_6.setName("SketchConstraintCoincidence_7") +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_1.endPoint()) +SketchConstraintCoincidence_7.setName("SketchConstraintCoincidence_8") +SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], 50) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchArc_1_2f-SketchLine_3f")], model.selection(), 100, 0) +model.do() +Solid_1_objects = [model.selection("FACE", "Extrusion_1_1/Generated_Face_3")] +Solid_1 = model.addSolid(Part_1_doc, Solid_1_objects) +# check that resulting build-solid feature is invalid: only one not-closed face is used +from ModelAPI import * +aFactory = ModelAPI_Session.get().validators() +assert(aFactory.validate(Solid_1.feature()) == False) +ModelAPI_Session.get().abortOperation() +# another try: to make a solid with a face inside +model.begin() +Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "Extrusion_1_1/To_Face_1"), 70, True) +Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Plane_1")) +SketchLine_5 = Sketch_2.addLine(14.9039069695087, 8.923908092675951, 26.86805702948195, 11.13714035991706) +SketchLine_6 = Sketch_2.addLine(26.86805702948195, 11.13714035991706, 18.50962242738747, 32.13572332177004) +SketchConstraintCoincidence_8 = Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchConstraintCoincidence_8.setName("SketchConstraintCoincidence_9") +SketchLine_7 = Sketch_2.addLine(18.50962242738747, 32.13572332177004, 14.9039069695087, 8.923908092675951) +SketchConstraintCoincidence_9 = Sketch_2.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint()) +SketchConstraintCoincidence_9.setName("SketchConstraintCoincidence_10") +SketchConstraintCoincidence_10 = Sketch_2.setCoincident(SketchLine_5.startPoint(), SketchLine_7.endPoint()) +SketchConstraintCoincidence_10.setName("SketchConstraintCoincidence_11") +model.do() +Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_5f-SketchLine_6f-SketchLine_7f")]) +Solid_2_objects = [model.selection("FACE", "Extrusion_1_1/Generated_Face_3"), model.selection("FACE", "Extrusion_1_1/Generated_Face_2"), model.selection("FACE", "Extrusion_1_1/To_Face_1"), model.selection("FACE", "Extrusion_1_1/From_Face_1"), model.selection("FACE", "Extrusion_1_1/Generated_Face_1"), model.selection("FACE", "Face_1_1")] +Solid_2 = model.addSolid(Part_1_doc, Solid_2_objects) +model.end() + +assert(aFactory.validate(Solid_2.feature()) == False) + +assert(model.checkPythonDump()) diff --git a/src/ModelHighAPI/ModelHighAPI_Interface.cpp b/src/ModelHighAPI/ModelHighAPI_Interface.cpp index d5b6332a3..8e35b13be 100644 --- a/src/ModelHighAPI/ModelHighAPI_Interface.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Interface.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "ModelHighAPI_Selection.h" //-------------------------------------------------------------------------------------- @@ -98,9 +99,10 @@ std::string ModelHighAPI_Interface::name() const ModelHighAPI_Selection ModelHighAPI_Interface::result() const { - const_cast(this)->execute(); - - return ModelHighAPI_Selection(feature()->firstResult()); + std::list aResults = results(); + if (aResults.empty()) + return ModelHighAPI_Selection(std::shared_ptr()); + return aResults.front(); } std::list ModelHighAPI_Interface::results() const @@ -111,7 +113,8 @@ std::list ModelHighAPI_Interface::results() const std::list > aResults = feature()->results(); for (auto it = aResults.begin(), end = aResults.end(); it != end; ++it) { - aSelectionList.push_back(ModelHighAPI_Selection(*it)); + if (!(*it)->isDisabled()) + aSelectionList.push_back(ModelHighAPI_Selection(*it)); } return aSelectionList;