From: Jérôme Date: Wed, 4 Nov 2020 11:25:52 +0000 (+0100) Subject: Lot2 : Implementation of Shared Faces inspection X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=98dcf7855d43982d580be89e89138385709aac69;p=modules%2Fshaper.git Lot2 : Implementation of Shared Faces inspection --- diff --git a/src/ConnectorPlugin/ConnectorPlugin_PublishToStudyFeature.py b/src/ConnectorPlugin/ConnectorPlugin_PublishToStudyFeature.py index a721ad73b..0468a9f6c 100644 --- a/src/ConnectorPlugin/ConnectorPlugin_PublishToStudyFeature.py +++ b/src/ConnectorPlugin/ConnectorPlugin_PublishToStudyFeature.py @@ -163,51 +163,55 @@ class PublishToStudyFeature(ModelAPI.ModelAPI_Feature): # If theFields is true, the same is performed for Fields. def processGroups(self, theRes, theEngine, thePartFeatureId, theStudyShape, theFields): allGroupsProcessed = [] + allRefGroups = [] if theFields: - aRefGroups = ModelAPI.referencedFeatures(theRes, "Field", True) + allRefGroups.append(ModelAPI.referencedFeatures(theRes, "Field", True)) else: - aRefGroups = ModelAPI.referencedFeatures(theRes, "Group", True) - for aRef in aRefGroups: - aGroupIndices = [] - aGroupHasIndex = {} - aResShape = theRes.shape() - if theFields: - aSelList = aRef.selectionList("selected") - else: - aSelList = aRef.selectionList("group_list") - aSelType = GeomAPI_Shape.shapeTypeByStr(aSelList.selectionType()) - for aGroupRes in aRef.results(): - aShape = aGroupRes.shape() - anExplorer = GeomAPI_ShapeExplorer(aShape, aSelType) - while anExplorer.more(): - anId = GeomAlgoAPI.GeomAlgoAPI_CompoundBuilder.id(aResShape, anExplorer.current()) - if anId > 0 and not anId in aGroupHasIndex: - aGroupIndices.append(anId) - aGroupHasIndex[anId] = 0 - anExplorer.next() - if len(aGroupIndices): # create group - aGroupFeatureId = aRef.data().featureId() + allRefGroups.append(ModelAPI.referencedFeatures(theRes, "Group", True)) + allRefGroups.append(ModelAPI.referencedFeatures(theRes, "Shared_faces", True)) + allRefGroups.append(ModelAPI.referencedFeatures(theRes, "Duplicated_faces", True)) + for aRefGroups in allRefGroups: + for aRef in aRefGroups: + aGroupIndices = [] + aGroupHasIndex = {} + aResShape = theRes.shape() if theFields: - aFieldOp = theEngine.GetIFieldOperations() - aGroupEntry = "field" + str(thePartFeatureId) + ":" + str(aGroupFeatureId) - aGroup = aFieldOp.FindField(theStudyShape, aGroupEntry) + aSelList = aRef.selectionList("selected") else: - aGroupOp = theEngine.GetIGroupOperations() - aGroupEntry = "group" + str(thePartFeatureId) + ":" + str(aGroupFeatureId) - aGroup = aGroupOp.FindGroup(theStudyShape, aGroupEntry) - if not aGroup: # create a new + aSelList = aRef.selectionList("group_list") + aSelType = GeomAPI_Shape.shapeTypeByStr(aSelList.selectionType()) + for aGroupRes in aRef.results(): + aShape = aGroupRes.shape() + anExplorer = GeomAPI_ShapeExplorer(aShape, aSelType) + while anExplorer.more(): + anId = GeomAlgoAPI.GeomAlgoAPI_CompoundBuilder.id(aResShape, anExplorer.current()) + if anId > 0 and not anId in aGroupHasIndex: + aGroupIndices.append(anId) + aGroupHasIndex[anId] = 0 + anExplorer.next() + if len(aGroupIndices): # create group + aGroupFeatureId = aRef.data().featureId() if theFields: - aGroup = aFieldOp.CreateFieldByType(theStudyShape, aSelType) + aFieldOp = theEngine.GetIFieldOperations() + aGroupEntry = "field" + str(thePartFeatureId) + ":" + str(aGroupFeatureId) + aGroup = aFieldOp.FindField(theStudyShape, aGroupEntry) else: - aGroup = aGroupOp.CreateGroup(theStudyShape, aSelType) - aGroup.SetEntry(aGroupEntry) - theEngine.AddInStudy(aGroup, aRef.firstResult().data().name(), theStudyShape) - aGroup.SetSelection(aGroupIndices) - if theFields: - self.fillField(aGroup, aRef, theEngine, aGroupIndices) - # a group takes shape from the main result - #aGroup.SetShapeByStream(aRef.firstResult().shape().getShapeStream(False)) # group shape - allGroupsProcessed.append(aGroupEntry) + aGroupOp = theEngine.GetIGroupOperations() + aGroupEntry = "group" + str(thePartFeatureId) + ":" + str(aGroupFeatureId) + aGroup = aGroupOp.FindGroup(theStudyShape, aGroupEntry) + if not aGroup: # create a new + if theFields: + aGroup = aFieldOp.CreateFieldByType(theStudyShape, aSelType) + else: + aGroup = aGroupOp.CreateGroup(theStudyShape, aSelType) + aGroup.SetEntry(aGroupEntry) + theEngine.AddInStudy(aGroup, aRef.firstResult().data().name(), theStudyShape) + aGroup.SetSelection(aGroupIndices) + if theFields: + self.fillField(aGroup, aRef, theEngine, aGroupIndices) + # a group takes shape from the main result + #aGroup.SetShapeByStream(aRef.firstResult().shape().getShapeStream(False)) # group shape + allGroupsProcessed.append(aGroupEntry) # check all existing groups: if some does not processed, remove it from the tree aSOIter = SHAPERSTUDY_utils.getStudy().NewChildIterator(theStudyShape.GetSO()) while aSOIter.More(): diff --git a/src/FeaturesAPI/CMakeLists.txt b/src/FeaturesAPI/CMakeLists.txt index 6cd9ba368..f3c6cc2ba 100644 --- a/src/FeaturesAPI/CMakeLists.txt +++ b/src/FeaturesAPI/CMakeLists.txt @@ -33,6 +33,7 @@ SET(PROJECT_HEADERS FeaturesAPI_Intersection.h FeaturesAPI_Measurement.h FeaturesAPI_NormalToFace.h + FeaturesAPI_SharedFaces.h FeaturesAPI_MultiRotation.h FeaturesAPI_MultiTranslation.h FeaturesAPI_Partition.h @@ -70,6 +71,7 @@ SET(PROJECT_SOURCES FeaturesAPI_Intersection.cpp FeaturesAPI_Measurement.cpp FeaturesAPI_NormalToFace.cpp + FeaturesAPI_SharedFaces.cpp FeaturesAPI_MultiRotation.cpp FeaturesAPI_MultiTranslation.cpp FeaturesAPI_Partition.cpp diff --git a/src/FeaturesAPI/FeaturesAPI.i b/src/FeaturesAPI/FeaturesAPI.i index d9fa7c0b5..634f2f018 100644 --- a/src/FeaturesAPI/FeaturesAPI.i +++ b/src/FeaturesAPI/FeaturesAPI.i @@ -64,6 +64,7 @@ %shared_ptr(FeaturesAPI_BooleanFill) %shared_ptr(FeaturesAPI_Chamfer) %shared_ptr(FeaturesAPI_NormalToFace) +%shared_ptr(FeaturesAPI_SharedFaces) %shared_ptr(FeaturesAPI_Extrusion) %shared_ptr(FeaturesAPI_ExtrusionBoolean) %shared_ptr(FeaturesAPI_ExtrusionCut) @@ -214,6 +215,7 @@ %include "FeaturesAPI_Intersection.h" %include "FeaturesAPI_Measurement.h" %include "FeaturesAPI_NormalToFace.h" +%include "FeaturesAPI_SharedFaces.h" %include "FeaturesAPI_MultiRotation.h" %include "FeaturesAPI_MultiTranslation.h" %include "FeaturesAPI_Partition.h" diff --git a/src/FeaturesAPI/FeaturesAPI_SharedFaces.cpp b/src/FeaturesAPI/FeaturesAPI_SharedFaces.cpp new file mode 100644 index 000000000..0c8a03974 --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_SharedFaces.cpp @@ -0,0 +1,83 @@ +// Copyright (C) 2018-2021 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 "FeaturesAPI_SharedFaces.h" + +#include + +#include +#include +#include +#include + +//================================================================================================= +FeaturesAPI_SharedFaces:: + FeaturesAPI_SharedFaces(const std::shared_ptr& theFeature) + : ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +//================================================================================================= +FeaturesAPI_SharedFaces::FeaturesAPI_SharedFaces( + const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theObject, + const std::string & theNameGroup) +:ModelHighAPI_Interface(theFeature) +{ + if (initialize()) { + fillAttribute(theObject, myobjectselected); + fillAttribute(theNameGroup, mygroupname); + execute(); + } +} + +//================================================================================================= +FeaturesAPI_SharedFaces::~FeaturesAPI_SharedFaces() +{ +} + +//================================================================================================= +void FeaturesAPI_SharedFaces::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + const std::string& aDocName = theDumper.name(aBase->document()); + + AttributeSelectionPtr anAttrObject; + anAttrObject = aBase->selection(FeaturesPlugin_GroupSharedFaces::OBJECT_ID()); + + theDumper << aBase << " = model.getSharedFaces(" << aDocName << ", " << anAttrObject; + theDumper << ", " << aBase->string(FeaturesPlugin_GroupSharedFaces::GROUP_NAME_ID()); + theDumper << ")" << std::endl; +} + +//================================================================================================= +SharedFacesPtr getSharedFaces(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& theObject, + const std::string & theNameGroup) +{ + FeaturePtr aFeature = thePart->addFeature(FeaturesPlugin_GroupSharedFaces::ID()); + SharedFacesPtr aSharedFaces; + + aSharedFaces.reset(new FeaturesAPI_SharedFaces(aFeature, + theObject, + theNameGroup)); + return aSharedFaces; +} + diff --git a/src/FeaturesAPI/FeaturesAPI_SharedFaces.h b/src/FeaturesAPI/FeaturesAPI_SharedFaces.h new file mode 100644 index 000000000..fc594119f --- /dev/null +++ b/src/FeaturesAPI/FeaturesAPI_SharedFaces.h @@ -0,0 +1,78 @@ +// Copyright (C) 2018-2021 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 FeaturesAPI_SharedFaces_H_ +#define FeaturesAPI_SharedFaces_H_ + +#include "FeaturesAPI.h" + +#include "FeaturesPlugin_GroupSharedFaces.h" + +#include +#include +#include + +class ModelAPI_Document; +class ModelHighAPI_Selection; + +/// \class FeaturesAPI_SharedFaces +/// \ingroup CPPHighAPI +/// \brief Interface to find shared faces +class FeaturesAPI_SharedFaces: public ModelHighAPI_Interface +{ +public: + /// Constructor without values. + FEATURESAPI_EXPORT + explicit FeaturesAPI_SharedFaces(const std::shared_ptr& theFeature); + + FEATURESAPI_EXPORT + explicit FeaturesAPI_SharedFaces(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theobject, + const std::string & theNameGroup); + + /// Destructor. + FEATURESAPI_EXPORT + virtual ~FeaturesAPI_SharedFaces(); + + INTERFACE_2(FeaturesPlugin_GroupSharedFaces::ID(), + objectselected, FeaturesPlugin_GroupSharedFaces::OBJECT_ID(), + ModelAPI_AttributeSelection, + /** object selected*/, + groupname, FeaturesPlugin_GroupSharedFaces::GROUP_NAME_ID(), + ModelAPI_AttributeString, + /** group name*/) + + /// Dump wrapped feature + FEATURESAPI_EXPORT + virtual void dump(ModelHighAPI_Dumper& theDumper) const; +}; + +/// Pointer on the SharedFaces object. +typedef std::shared_ptr SharedFacesPtr; + +/// \ingroup CPPHighAPI +/// \brief get the Shared Faces +/// \param thePart the part +/// \param theobject the object selected +FEATURESAPI_EXPORT +SharedFacesPtr getSharedFaces(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& theObject, + const std::string & theNameGroup); + +#endif // FeaturesAPI_SharedFaces_H_ diff --git a/src/FeaturesAPI/FeaturesAPI_swig.h b/src/FeaturesAPI/FeaturesAPI_swig.h index ede8f2c11..fa19f357b 100644 --- a/src/FeaturesAPI/FeaturesAPI_swig.h +++ b/src/FeaturesAPI/FeaturesAPI_swig.h @@ -36,6 +36,7 @@ #include "FeaturesAPI_Intersection.h" #include "FeaturesAPI_Measurement.h" #include "FeaturesAPI_NormalToFace.h" + #include "FeaturesAPI_SharedFaces.h" #include "FeaturesAPI_MultiRotation.h" #include "FeaturesAPI_MultiTranslation.h" #include "FeaturesAPI_Partition.h" diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index e3f25e81d..4857c34b7 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -19,6 +19,16 @@ INCLUDE(Common) INCLUDE(UnitTest) +INCLUDE(UseQtExt) + +# additional include directories +INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/GeomDataAPI + ${PROJECT_SOURCE_DIR}/src/Locale + ${QT_INCLUDES}) + +# additional preprocessor / compiler flags +ADD_DEFINITIONS(${QT_DEFINITIONS}) + SET(PROJECT_HEADERS @@ -60,6 +70,9 @@ SET(PROJECT_HEADERS FeaturesPlugin_Fillet.h FeaturesPlugin_Fillet1D.h FeaturesPlugin_Measurement.h + FeaturesPlugin_SharedFaces.h + FeaturesPlugin_CommonSharedFaces.h + FeaturesPlugin_GroupSharedFaces.h FeaturesPlugin_FusionFaces.h FeaturesPlugin_RemoveResults.h FeaturesPlugin_Chamfer.h @@ -114,6 +127,9 @@ SET(PROJECT_SOURCES FeaturesPlugin_Fillet.cpp FeaturesPlugin_Fillet1D.cpp FeaturesPlugin_Measurement.cpp + FeaturesPlugin_SharedFaces.cpp + FeaturesPlugin_CommonSharedFaces.cpp + FeaturesPlugin_GroupSharedFaces.cpp FeaturesPlugin_FusionFaces.cpp FeaturesPlugin_RemoveResults.cpp FeaturesPlugin_Chamfer.cpp @@ -159,6 +175,8 @@ SET(XML_RESOURCES fillet_widget.xml fillet1d_widget.xml measurement_widget.xml + shared_Faces_widget.xml + shared_Faces_macro_widget.xml fusion_faces_widget.xml chamfer_widget.xml copy_widget.xml @@ -178,6 +196,12 @@ SET(TEXT_RESOURCES FeaturesPlugin_msg_ru.ts ) +# sources / moc wrappings +QT_WRAP_MOC(PROJECT_AUTOMOC ${PROJECT_MOC_HEADERS}) + +#QT5_ADD_TRANSLATION(QM_RESOURCES ${TEXT_RESOURCES}) + +SOURCE_GROUP ("Generated Files" FILES ${PROJECT_AUTOMOC} ${PROJECT_COMPILED_RESOURCES} ${QM_RESOURCES}) SOURCE_GROUP ("XML Files" FILES ${XML_RESOURCES}) SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES}) @@ -204,7 +228,12 @@ SET(PROJECT_LIBRARIES ) ADD_DEFINITIONS(-DFEATURESPLUGIN_EXPORTS) -ADD_LIBRARY(FeaturesPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES} ${TEXT_RESOURCES}) +ADD_LIBRARY(FeaturesPlugin MODULE + ${PROJECT_SOURCES} + ${PROJECT_HEADERS} + ${XML_RESOURCES} + ${TEXT_RESOURCES} + ${PROJECT_AUTOMOC}) TARGET_LINK_LIBRARIES(FeaturesPlugin ${PROJECT_LIBRARIES}) INSTALL(TARGETS FeaturesPlugin DESTINATION ${SHAPER_INSTALL_PLUGIN_FILES}) @@ -221,16 +250,16 @@ ADD_UNIT_TESTS( IF(${HAVE_SALOME}) enable_testing() set(TEST_INSTALL_DIRECTORY "${SALOME_SHAPER_INSTALL_TESTS}/FeaturesPlugin") - + install(FILES CTestTestfileInstall.cmake DESTINATION ${TEST_INSTALL_DIRECTORY} RENAME CTestTestfile.cmake) install(FILES tests.set DESTINATION ${TEST_INSTALL_DIRECTORY}) - + set(TMP_TESTS_NAMES) foreach(tfile ${TEST_NAMES}) list(APPEND TMP_TESTS_NAMES "Test/${tfile}") endforeach(tfile ${TEST_NAMES}) - + install(FILES ${TMP_TESTS_NAMES} DESTINATION ${TEST_INSTALL_DIRECTORY}) ENDIF(${HAVE_SALOME}) diff --git a/src/FeaturesPlugin/FeaturesPlugin_CommonSharedFaces.cpp b/src/FeaturesPlugin/FeaturesPlugin_CommonSharedFaces.cpp new file mode 100644 index 000000000..354452e23 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_CommonSharedFaces.cpp @@ -0,0 +1,111 @@ +// Copyright (C) 2018-2021 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 "FeaturesPlugin_CommonSharedFaces.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include + +//================================================================================================= +void FeaturesPlugin_CommonSharedFaces::updateFaces() +{ + AttributeSelectionPtr aCompSolidAttr = + std::dynamic_pointer_cast(attributObject()); + AttributeSelectionListPtr aFacesListAttr = + std::dynamic_pointer_cast (attributListFaces()); + + GeomShapePtr aShape = aCompSolidAttr->value(); + AttributeBooleanPtr anIsCompute = + std::dynamic_pointer_cast(attributIsCompute()); + if (!anIsCompute->value()) { + myShape = aShape; + anIsCompute->setValue(true); + } + if (aShape.get() && aCompSolidAttr->context().get() && !aShape->isEqual(myShape)) { + if (aFacesListAttr->isInitialized()) + aFacesListAttr->clear(); + aShape = aCompSolidAttr->context()->shape(); + if (aShape) { + std::string anError; + ListOfShape aFaces; + ListOfShape theShapes; + theShapes.push_back(aShape); + + if (!GetSharedFaces(theShapes, aFaces, false, anError)) + setError("Error in GetSharedFaces calculation :" + anError); + myShape = aShape; + aFacesListAttr->setSelectionType("face"); + ListOfShape::const_iterator anIt = aFaces.cbegin(); + for(; anIt != aFaces.cend(); ++anIt) { + GeomShapePtr aFacePtr = *anIt; + if (!aFacePtr.get()) + setError("GetSharedFaces : An invalid face found " + anError); + aFacesListAttr->append( aCompSolidAttr->context(), aFacePtr); + } + std::stringstream aLabel; + aLabel << aFacesListAttr->size(); + AttributeStringPtr aNumberFacesAttr = + std::dynamic_pointer_cast + (attributNumberFaces()); + aNumberFacesAttr->setValue( aLabel.str() ); + } + } +} + +//================================================================================================= +void FeaturesPlugin_CommonSharedFaces::setFacesGroup(const std::wstring& theName ) +{ + std::vector aColor; + ResultGroupPtr aGroup = document()->createGroup(data()); + // clean the result of the operation + aGroup->data()->setName(theName); + aGroup->store(GeomShapePtr()); + + // shapes containing in group + ListOfShape aFaces; + AttributeSelectionListPtr aFacesListAttr = + std::dynamic_pointer_cast (attributListFaces()); + + for (int anI =0; anI< aFacesListAttr->size(); anI++) { + AttributeSelectionPtr aAtt = aFacesListAttr->value(anI); + aFaces.push_back( aAtt->value() ); + } + + GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces); + aGroup->store(aCompound); + aColor = {255,0,0}; + setResult(aGroup); + ModelAPI_Tools::setColor( lastResult(),aColor); +} + diff --git a/src/FeaturesPlugin/FeaturesPlugin_CommonSharedFaces.h b/src/FeaturesPlugin/FeaturesPlugin_CommonSharedFaces.h new file mode 100644 index 000000000..dead172f8 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_CommonSharedFaces.h @@ -0,0 +1,70 @@ +// Copyright (C) 2018-2021 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 FeaturesPlugin_CommonSharedFaces_H_ +#define FeaturesPlugin_CommonSharedFaces_H_ + +#include "FeaturesPlugin.h" + +#include +#include +#include + +#include +#include + + +/// \class FeaturesPlugin_CommonSharedFaces +/// \ingroup Plugins +/// \brief Feature to check the shared faces of solid + +class FeaturesPlugin_CommonSharedFaces : public ModelAPI_Feature +{ +public: + + /// Performs the algorithm and stores results it in the data structure. + FEATURESPLUGIN_EXPORT virtual void execute(){}; + + /// Return Attribut values of result. + virtual AttributePtr attributObject() = 0; + + /// Return Attribut values of result. + virtual AttributePtr attributListFaces() = 0; + + /// Return Attribut values of result. + virtual AttributePtr attributNumberFaces() = 0; + + /// Return Attribut values of IsCompute. + virtual AttributePtr attributIsCompute() = 0; + + protected: + FeaturesPlugin_CommonSharedFaces() {} + + //Set group of faces + void setFacesGroup(const std::wstring& theName ); + + // Update the list of faces + void updateFaces(); + + // the shape studied + GeomShapePtr myShape; + +}; + +#endif diff --git a/src/FeaturesPlugin/FeaturesPlugin_GroupSharedFaces.cpp b/src/FeaturesPlugin/FeaturesPlugin_GroupSharedFaces.cpp new file mode 100644 index 000000000..258085a59 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_GroupSharedFaces.cpp @@ -0,0 +1,129 @@ +// Copyright (C) 2018-2021 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 "FeaturesPlugin_GroupSharedFaces.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include + +//================================================================================================= +FeaturesPlugin_GroupSharedFaces::FeaturesPlugin_GroupSharedFaces() +{ +} + +//================================================================================================= +void FeaturesPlugin_GroupSharedFaces::initAttributes() +{ + // attribute for object selected + data()->addAttribute(OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); + AttributeSelectionListPtr aList = std::dynamic_pointer_cast( + data()->addAttribute(LIST_FACES_ID(), ModelAPI_AttributeSelectionList::typeId())); + + data()->addAttribute(NUMBER_FACES_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(TRANSPARENCY_ID(), ModelAPI_AttributeInteger::typeId()); + data()->addAttribute(GROUP_NAME_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(COMPUTE_ID(), ModelAPI_AttributeBoolean::typeId()); + + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TRANSPARENCY_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), COMPUTE_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), NUMBER_FACES_ID()); + data()->boolean(COMPUTE_ID())->setValue(true); +} + +//================================================================================================= +AttributePtr FeaturesPlugin_GroupSharedFaces::attributObject() +{ + return attribute(OBJECT_ID()); +} + +//================================================================================================= +AttributePtr FeaturesPlugin_GroupSharedFaces::attributIsCompute() +{ + return attribute(COMPUTE_ID()); +} + +//================================================================================================= +AttributePtr FeaturesPlugin_GroupSharedFaces::attributListFaces() +{ + return attribute(LIST_FACES_ID()); +} + +//================================================================================================= +AttributePtr FeaturesPlugin_GroupSharedFaces::attributNumberFaces() +{ + return attribute(NUMBER_FACES_ID()); +} + +//================================================================================================= +void FeaturesPlugin_GroupSharedFaces::execute() +{ + if ( selectionList(LIST_FACES_ID())->isInitialized() + && string(GROUP_NAME_ID())->value() != "") { + AttributeStringPtr aNameAtt = string( GROUP_NAME_ID() ) ; + std::wstring aNameFace = aNameAtt->isUValue() ? + Locale::Convert::toWString(aNameAtt->valueU()) : + Locale::Convert::toWString(aNameAtt->value()); + + if (lastResult().get()) + eraseResultFromList(lastResult()); + setFacesGroup(aNameFace); + } else { + if (lastResult().get()) { + eraseResultFromList(lastResult()); + } + } + if (selection(OBJECT_ID())->isInitialized() && integer(TRANSPARENCY_ID())->isInitialized()) { + AttributeSelectionPtr aCompSolidAttr = selection(OBJECT_ID()); + ResultPtr aResult = aCompSolidAttr->context(); + + double aTranparency = integer(TRANSPARENCY_ID())->value() / 100.0; + ModelAPI_Tools::setTransparency(aResult, aTranparency); + + ResultBodyPtr aResultBody = std::dynamic_pointer_cast(aResult); + std::list allRes; + ModelAPI_Tools::allSubs(aResultBody, allRes); + std::list::iterator aRes; + for(aRes = allRes.begin(); aRes != allRes.end(); aRes++) { + ModelAPI_Tools::setTransparency(*aRes, aTranparency); + } + } +} + +//================================================================================================= +void FeaturesPlugin_GroupSharedFaces::attributeChanged(const std::string& theID) +{ + if (theID == OBJECT_ID()) + updateFaces(); +} diff --git a/src/FeaturesPlugin/FeaturesPlugin_GroupSharedFaces.h b/src/FeaturesPlugin/FeaturesPlugin_GroupSharedFaces.h new file mode 100644 index 000000000..663dd3fe6 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_GroupSharedFaces.h @@ -0,0 +1,114 @@ +// Copyright (C) 2018-2021 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 FeaturesPlugin_GroupSharedFaces_H_ +#define FeaturesPlugin_GroupSharedFaces_H_ + +#include + +/// \class FeaturesPlugin_GroupSharedFaces +/// \ingroup Plugins +/// \brief Feature to check the shared faces of solid + +class FeaturesPlugin_GroupSharedFaces : public FeaturesPlugin_CommonSharedFaces +{ +public: + inline static const std::string& ID() + { + static const std::string MY_ID("Shared_faces"); + return MY_ID; + } + + /// \return the kind of a feature. + virtual const std::string& getKind() + { + return ID(); + } + + /// Attribute name for object selected. + inline static const std::string& OBJECT_ID() + { + static const std::string MY_OBJECT_ID("main_object"); + return MY_OBJECT_ID; + } + + /// Attribute name for number of faces. + inline static const std::string& NUMBER_FACES_ID() + { + static const std::string MY_NUMBER_FACES_ID("number_shared_faces"); + return MY_NUMBER_FACES_ID; + } + + /// Attribute name for z coodinate. + inline static const std::string& LIST_FACES_ID() + { + static const std::string MY_LIST_FACES_ID("group_list"); + return MY_LIST_FACES_ID; + } + + /// Attribute name for transparency. + inline static const std::string& TRANSPARENCY_ID() + { + static const std::string MY_TRANSPARENCY_ID("transparency"); + return MY_TRANSPARENCY_ID; + } + + /// Attribute name for group name. + inline static const std::string& GROUP_NAME_ID() + { + static const std::string MY_GROUP_NAME_ID("group_name"); + return MY_GROUP_NAME_ID; + } + + /// Attribute name for indicate to launch the algo. + inline static const std::string& COMPUTE_ID() + { + static const std::string MY_COMPUTE_ID("compute"); + return MY_COMPUTE_ID; + } + + /// Performs the algorithm and stores results it in the data structure. + FEATURESPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + FEATURESPLUGIN_EXPORT virtual void initAttributes(); + + /// Called on change of any argument-attribute of this object + /// \param theID identifier of changed attribute + FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); + + /// Use plugin manager for features creation + FeaturesPlugin_GroupSharedFaces(); + + private: + + /// Return Attribut values of object. + virtual AttributePtr attributObject(); + + /// Return Attribut values of list of faces. + virtual AttributePtr attributListFaces(); + + /// Return Attribut values of number of faces. + virtual AttributePtr attributNumberFaces(); + + /// Return Attribut values of IsCompute. + virtual AttributePtr attributIsCompute(); +}; + +#endif diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index 3d00700d6..83b31db6e 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -19,54 +19,52 @@ #include +#include #include +#include #include -#include #include -#include #include #include +#include #include -#include #include #include -#include +#include #include +#include +#include #include +#include +#include #include #include #include #include -#include #include #include #include #include #include #include +#include #include +#include #include -#include #include #include +#include #include #include +#include #include #include #include -#include -#include -#include -#include -#include #include +#include #include -#include - -#include - // the only created instance of this plugin static FeaturesPlugin_Plugin* MY_FEATURES_INSTANCE = new FeaturesPlugin_Plugin(); @@ -193,6 +191,10 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(std::string theFeatureID) return FeaturePtr(new FeaturesPlugin_Fillet1D); } else if (theFeatureID == FeaturesPlugin_Measurement::ID()) { return FeaturePtr(new FeaturesPlugin_Measurement); + } else if (theFeatureID == FeaturesPlugin_SharedFaces::ID()) { + return FeaturePtr(new FeaturesPlugin_SharedFaces); + } else if (theFeatureID == FeaturesPlugin_GroupSharedFaces::ID()) { + return FeaturePtr(new FeaturesPlugin_GroupSharedFaces); } else if (theFeatureID == FeaturesPlugin_RemoveResults::ID()) { return FeaturePtr(new FeaturesPlugin_RemoveResults); } else if (theFeatureID == FeaturesPlugin_Chamfer::ID()) { diff --git a/src/FeaturesPlugin/FeaturesPlugin_SharedFaces.cpp b/src/FeaturesPlugin/FeaturesPlugin_SharedFaces.cpp new file mode 100644 index 000000000..fa9f441ab --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_SharedFaces.cpp @@ -0,0 +1,187 @@ +// Copyright (C) 2018-2021 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 "FeaturesPlugin_SharedFaces.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +//================================================================================================= +FeaturesPlugin_SharedFaces::FeaturesPlugin_SharedFaces() +{ +} + +//================================================================================================= +void FeaturesPlugin_SharedFaces::initAttributes() +{ + // attribute for object selected + data()->addAttribute(OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); + AttributeSelectionListPtr aList = std::dynamic_pointer_cast( + data()->addAttribute(LIST_FACES_ID(), ModelAPI_AttributeSelectionList::typeId())); + + data()->addAttribute(NUMBER_FACES_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(TRANSPARENCY_ID(), ModelAPI_AttributeInteger::typeId()); + data()->addAttribute(CREATE_GROUP_ID(), ModelAPI_AttributeBoolean::typeId()); + data()->addAttribute(GROUP_NAME_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(COMPUTE_ID(), ModelAPI_AttributeBoolean::typeId()); + + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), GROUP_NAME_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), COMPUTE_ID()); + data()->boolean(COMPUTE_ID())->setValue(true); +} + +//================================================================================================= +AttributePtr FeaturesPlugin_SharedFaces::attributIsCompute() +{ + return attribute(COMPUTE_ID()); +} + +//================================================================================================= +AttributePtr FeaturesPlugin_SharedFaces::attributObject() +{ + return attribute(OBJECT_ID()); +} + +//================================================================================================= +AttributePtr FeaturesPlugin_SharedFaces::attributListFaces() +{ + return attribute(LIST_FACES_ID()); +} + +//================================================================================================= +AttributePtr FeaturesPlugin_SharedFaces::attributNumberFaces() +{ + return attribute(NUMBER_FACES_ID()); +} + +//================================================================================================= +void FeaturesPlugin_SharedFaces::execute() +{ + if (boolean(CREATE_GROUP_ID())->value()) { + + if (string(GROUP_NAME_ID())->value() != "" + && selectionList(LIST_FACES_ID())->isInitialized()) { + + if (lastResult().get()) { + eraseResultFromList(lastResult()); + } + + if (!myCreateGroupFeature.get()) + createGroup(); + updateGroup(); + } + + } else { + if (selectionList(LIST_FACES_ID())->isInitialized()) { + + if (myCreateGroupFeature.get()) { + myCreateGroupFeature->eraseResults(); + SessionPtr aSession = ModelAPI_Session::get(); + DocumentPtr aDoc = aSession->activeDocument(); + aDoc->removeFeature(myCreateGroupFeature); + myCreateGroupFeature.reset(); + } + + if (lastResult().get()) + eraseResultFromList(lastResult()); + setFacesGroup(L"Group_SharedFaces"); + } + } + + if (selection(OBJECT_ID())->isInitialized()) { + AttributeSelectionPtr aCompSolidAttr = selection(OBJECT_ID()); + ResultPtr aResult = aCompSolidAttr->context(); + + double aTranparency = integer(TRANSPARENCY_ID())->value()/100.0; + ModelAPI_Tools::setTransparency(aResult, aTranparency); + + ResultBodyPtr aResultBody = std::dynamic_pointer_cast(aResult); + std::list allRes; + ModelAPI_Tools::allSubs(aResultBody, allRes); + std::list::iterator aRes; + for(aRes = allRes.begin(); aRes != allRes.end(); aRes++) { + ModelAPI_Tools::setTransparency(*aRes, aTranparency); + } + } +} + +//================================================================================================= +void FeaturesPlugin_SharedFaces::attributeChanged(const std::string& theID) +{ + if (theID == OBJECT_ID()) { + + updateFaces(); + if (myCreateGroupFeature.get()) + updateGroup(); + } +} + + +//================================================================================================= +void FeaturesPlugin_SharedFaces::createGroup() +{ + SessionPtr aSession = ModelAPI_Session::get(); + + DocumentPtr aDoc = aSession->activeDocument(); + + if (aDoc.get()) { + myCreateGroupFeature = aDoc->addFeature(FeaturesPlugin_GroupSharedFaces::ID()); + } +} + +//================================================================================================= +void FeaturesPlugin_SharedFaces::updateGroup() +{ + myCreateGroupFeature->boolean(FeaturesPlugin_GroupSharedFaces::COMPUTE_ID())->setValue(false); + myCreateGroupFeature->string(FeaturesPlugin_GroupSharedFaces::GROUP_NAME_ID()) + ->setValue( string(GROUP_NAME_ID())->value()); + + myCreateGroupFeature->selection(FeaturesPlugin_GroupSharedFaces::OBJECT_ID()) + ->setValue( selection(OBJECT_ID())->context() , + selection(OBJECT_ID())->value() ); + AttributeSelectionListPtr aFacesFeatures = + std::dynamic_pointer_cast + (myCreateGroupFeature->attribute(LIST_FACES_ID())); + + AttributeSelectionListPtr aFaces = + std::dynamic_pointer_cast(attribute(LIST_FACES_ID())); + aFaces->copyTo(aFacesFeatures); + + myCreateGroupFeature->integer(FeaturesPlugin_GroupSharedFaces::TRANSPARENCY_ID()) + ->setValue( integer(TRANSPARENCY_ID())->value()); + myCreateGroupFeature->execute(); + myCreateGroupFeature->boolean(FeaturesPlugin_GroupSharedFaces::COMPUTE_ID())->setValue(true); +} diff --git a/src/FeaturesPlugin/FeaturesPlugin_SharedFaces.h b/src/FeaturesPlugin/FeaturesPlugin_SharedFaces.h new file mode 100644 index 000000000..d78e9b3e6 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_SharedFaces.h @@ -0,0 +1,133 @@ +// Copyright (C) 2018-2021 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 FeaturesPlugin_SharedFaces_H_ +#define FeaturesPlugin_SharedFaces_H_ + +#include + +/// \class FeaturesPlugin_SharedFaces +/// \ingroup Plugins +/// \brief Feature to check the shared faces of solid + +class FeaturesPlugin_SharedFaces : public FeaturesPlugin_CommonSharedFaces +{ +public: + inline static const std::string& ID() + { + static const std::string MY_ID("Shared_faces_macro"); + return MY_ID; + } + + /// \return the kind of a feature. + virtual const std::string& getKind() + { + return ID(); + } + + /// Attribute name for object selected. + inline static const std::string& OBJECT_ID() + { + static const std::string MY_OBJECT_ID("main_object"); + return MY_OBJECT_ID; + } + + /// Attribute name for number of faces. + inline static const std::string& NUMBER_FACES_ID() + { + static const std::string MY_NUMBER_FACES_ID("number_shared_faces"); + return MY_NUMBER_FACES_ID; + } + + /// Attribute name for z coodinate. + inline static const std::string& LIST_FACES_ID() + { + static const std::string MY_LIST_FACES_ID("group_list"); + return MY_LIST_FACES_ID; + } + + /// Attribute name for transparency. + inline static const std::string& TRANSPARENCY_ID() + { + static const std::string MY_TRANSPARENCY_ID("transparency"); + return MY_TRANSPARENCY_ID; + } + + /// Attribute name for checkbox create group. + inline static const std::string& CREATE_GROUP_ID() + { + static const std::string MY_CREATE_GROUP_ID("create_group"); + return MY_CREATE_GROUP_ID; + } + + /// Attribute name for indicate to launch the algo. + inline static const std::string& COMPUTE_ID() + { + static const std::string MY_COMPUTE_ID("compute"); + return MY_COMPUTE_ID; + } + + /// Attribute name for group name. + inline static const std::string& GROUP_NAME_ID() + { + static const std::string MY_GROUP_NAME_ID("group_name"); + return MY_GROUP_NAME_ID; + } + + /// Performs the algorithm and stores results it in the data structure. + FEATURESPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + FEATURESPLUGIN_EXPORT virtual void initAttributes(); + + /// Called on change of any argument-attribute of this object + /// \param theID identifier of changed attribute + FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); + + /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true. + FEATURESPLUGIN_EXPORT virtual bool isMacro() const { return true; } + + /// Use plugin manager for features creation + FeaturesPlugin_SharedFaces(); + + private: + + /// Return Attribut values of object. + virtual AttributePtr attributObject(); + + /// Return Attribut values of list of faces. + virtual AttributePtr attributListFaces(); + + /// Return Attribut values of number of faces. + virtual AttributePtr attributNumberFaces(); + + /// Return Attribut values of IsCompute. + virtual AttributePtr attributIsCompute(); + + /// Create group + void createGroup(); + + /// Update group + void updateGroup(); + + /// Feature to create group + FeaturePtr myCreateGroupFeature; +}; + +#endif diff --git a/src/FeaturesPlugin/FeaturesPlugin_msg_fr.ts b/src/FeaturesPlugin/FeaturesPlugin_msg_fr.ts index 878c1f4d5..acf1254f2 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_msg_fr.ts +++ b/src/FeaturesPlugin/FeaturesPlugin_msg_fr.ts @@ -143,6 +143,10 @@ Rotation Rotation + + Check shared faces + Vérifier les faces partagées + Symmetry Symétrie @@ -4966,6 +4970,124 @@ + + + Shared_faces_macro + + Check shared faces + Vérifier les faces partagées + + + Shared faces + Faces partagées + + + Number of shared faces : + Nombre de faces partagées : + + + + Shared_faces_macro:create_group + + Create group + Créer un groupe + + + + Shared_faces_macro:group_name + + Group name + Nom du groupe + + + + Shared_faces_macro:main_object + + Object + Objet + + + Shared faces + Faces partagées + + + + Shared_faces_macro:group_list + + Shared faces + Faces partagées + + + List of faces : + Liste des faces : + + + + Shared_faces_macro:transparency + + Transparency + Transparence + + + + Shared_faces + + Check shared faces + Vérifier les faces partagées + + + Shared faces + Faces partagées + + + Number of shared faces : + Nombre de faces partagées : + + + + Shared_faces:create_group + + Create group + Créer un groupe + + + + Shared_faces:group_name + + Group name + Nom du groupe + + + + Shared_faces:main_object + + Object + Objet + + + Shared faces + Faces partagées + + + + Shared_faces:group_list + + Shared faces + Faces partagées + + + List of faces : + Liste des faces : + + + + Shared_faces:transparency + + Transparency + Transparence + + + Symmetry diff --git a/src/FeaturesPlugin/Test/TestCheckSharedFaces.py b/src/FeaturesPlugin/Test/TestCheckSharedFaces.py new file mode 100644 index 000000000..d6a3ee357 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestCheckSharedFaces.py @@ -0,0 +1,83 @@ +# Copyright (C) 2014-2021 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 +# + +""" + Unit test of Check shared faces +""" +#========================================================================= +# Initialization of the test +#========================================================================= + + +import os +import math + +from ModelAPI import * +from GeomAPI import * +from salome.shaper import model + + +__updated__ = "2020-11-12" + + +if __name__ == '__main__': + + model.begin() + partSet = model.moduleDocument() + Part_1 = model.addPart(partSet) + Part_1_doc = Part_1.document() + ### Create Box + Box_1 = model.addBox(Part_1_doc, 10, 10, 10) + ### Create Point + Point_2 = model.addPoint(Part_1_doc, 20, 10, 10) + ### Create Box + Box_2 = model.addBox(Part_1_doc, model.selection("VERTEX", "[Box_1_1/Front][Box_1_1/Left][Box_1_1/Bottom]"), model.selection("VERTEX", "Point_1")) + ### Create CompSolid + CompSolid_1 = model.addCompSolid(Part_1_doc, [model.selection("SOLID", "Box_1_1"), model.selection("SOLID", "Box_2_1")]) + + ### Create Shared_faces + Shared_faces_1 = model.getSharedFaces(Part_1_doc, model.selection("COMPSOLID", "CompSolid_1_1"), "mygroup") + + model.do() + # Check results + Shared_faces_1_Feature = Shared_faces_1.feature() + assert Shared_faces_1_Feature.error() == '' + assert Shared_faces_1_Feature.name() == "Shared_faces_1" + + aSelectionList = Shared_faces_1_Feature.selectionList("group_list") + assert aSelectionList.size() == 1 + + assert(Part_1_doc.size("Groups") == 1) + + #assert Part_1_doc.object("Groups", 0).name() == "mygroup" + resShape = modelAPI_Result(Part_1_doc.object("Groups", 0)).shape() + assert(not resShape.isNull()) + + # the group result is a face, check that this is one face + aShapeExplorer = GeomAPI_ShapeExplorer(resShape, GeomAPI_Shape.FACE) + assert(aShapeExplorer.more()) + assert(aShapeExplorer.current().isFace()) + aShapeExplorer.next() + assert(not aShapeExplorer.more()) + + model.end() + + #========================================================================= + # End of test + #========================================================================= diff --git a/src/FeaturesPlugin/doc/FeaturesPlugin.rst b/src/FeaturesPlugin/doc/FeaturesPlugin.rst index 6fc8177bd..900ffb734 100644 --- a/src/FeaturesPlugin/doc/FeaturesPlugin.rst +++ b/src/FeaturesPlugin/doc/FeaturesPlugin.rst @@ -27,6 +27,7 @@ Features plug-in provides a set of common topological operations. It implements linearCopyFeature.rst measurementFeature.rst normalToFaceFeature.rst + checkSharedFaceFeature.rst pipeFeature.rst placementFeature.rst pointCoordinatesFeature.rst diff --git a/src/FeaturesPlugin/doc/TUI_SharedFacesFeature.rst b/src/FeaturesPlugin/doc/TUI_SharedFacesFeature.rst new file mode 100644 index 000000000..f170d48e9 --- /dev/null +++ b/src/FeaturesPlugin/doc/TUI_SharedFacesFeature.rst @@ -0,0 +1,11 @@ + + .. _tui_shared_faces: + +Check shared faces +================== + +.. literalinclude:: examples/checkSharedFaces.py + :linenos: + :language: python + +:download:`Download this script ` diff --git a/src/FeaturesPlugin/doc/checkSharedFaceFeature.rst b/src/FeaturesPlugin/doc/checkSharedFaceFeature.rst new file mode 100644 index 000000000..f8a83276b --- /dev/null +++ b/src/FeaturesPlugin/doc/checkSharedFaceFeature.rst @@ -0,0 +1,52 @@ +.. |shared_shapes.icon| image:: images/shared_shapes.png + +Check shared faces +================== + +The **Check shared faces** feature find the shared faces within a composolid or compound. + +The result is a list of faces and a group that can be created with a specified name. + +To check shared faces in the active part: + +#. Select in the Main Menu *Inspection - > Check shared faces* item or +#. Click |shared_shapes.icon| **Check shared faces** button in the toolbar + +The property panel is shown below. + +.. figure:: images/checkSharedFacesPropertyPanel.png + :align: center + + Check shared faces + + +Input fields: + +- **Object** contains composolid or compound selected in 3D OCC viewer or object browser. +- **Number of shared faces** indicate the number of found faces. +- **List of faces** the list of found faces. +- **Transparency** set the transparency of selected object. +- **Create group** check-box that allows the creation of the found faces group. +- **Group name** specifies the name of the group created. + + +**TUI Command**: + +.. py:function:: model.getSharedFaces(Part_doc, shape, nameGroup) + + :param part: The current part object. + :param object: A composolid or compound in format *model.selection("Type", shape)*. + :param string: name of group created. + :return: Created group. + +Result +"""""" + +Result of **Check shared faces** where **Create group** is checked. + +.. figure:: images/sharedFacesResult.png + :align: center + + Shared faces + +**See Also** a sample TUI Script of :ref:`tui_shared_faces` operation. diff --git a/src/FeaturesPlugin/doc/examples/checkSharedFaces.py b/src/FeaturesPlugin/doc/examples/checkSharedFaces.py new file mode 100644 index 000000000..198027331 --- /dev/null +++ b/src/FeaturesPlugin/doc/examples/checkSharedFaces.py @@ -0,0 +1,21 @@ +from salome.shaper import model +import os + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +### Create Box +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +### Create Point +Point_2 = model.addPoint(Part_1_doc, 20, 10, 10) +### Create Box +Box_2 = model.addBox(Part_1_doc, model.selection("VERTEX", "[Box_1_1/Front][Box_1_1/Left][Box_1_1/Bottom]"), model.selection("VERTEX", "Point_1")) +### Create CompSolid +CompSolid_1 = model.addCompSolid(Part_1_doc, [model.selection("SOLID", "Box_1_1"), model.selection("SOLID", "Box_2_1")]) + +### Create Shared_faces +Shared_faces_1 = model.getSharedFaces(Part_1_doc, model.selection("COMPSOLID", "CompSolid_1_1"), "mygroup") + +model.do() +model.end() diff --git a/src/FeaturesPlugin/doc/images/checkSharedFacesPropertyPanel.png b/src/FeaturesPlugin/doc/images/checkSharedFacesPropertyPanel.png new file mode 100644 index 000000000..6e1ac8a86 Binary files /dev/null and b/src/FeaturesPlugin/doc/images/checkSharedFacesPropertyPanel.png differ diff --git a/src/FeaturesPlugin/doc/images/sharedFacesResult.png b/src/FeaturesPlugin/doc/images/sharedFacesResult.png new file mode 100644 index 000000000..114ac3421 Binary files /dev/null and b/src/FeaturesPlugin/doc/images/sharedFacesResult.png differ diff --git a/src/FeaturesPlugin/doc/images/shared_shapes.png b/src/FeaturesPlugin/doc/images/shared_shapes.png new file mode 100644 index 000000000..23f804802 Binary files /dev/null and b/src/FeaturesPlugin/doc/images/shared_shapes.png differ diff --git a/src/FeaturesPlugin/icons/shared_shapes.png b/src/FeaturesPlugin/icons/shared_shapes.png new file mode 100644 index 000000000..23f804802 Binary files /dev/null and b/src/FeaturesPlugin/icons/shared_shapes.png differ diff --git a/src/FeaturesPlugin/plugin-Features.xml b/src/FeaturesPlugin/plugin-Features.xml index 87e47c378..32d26c443 100644 --- a/src/FeaturesPlugin/plugin-Features.xml +++ b/src/FeaturesPlugin/plugin-Features.xml @@ -134,7 +134,7 @@ + icon="icons/Features/fusion_faces.png" auto_preview="true" helpfile="FeaturesPlugin/fusionFacesFeature.html"> + + + + + + diff --git a/src/FeaturesPlugin/shared_Faces_macro_widget.xml b/src/FeaturesPlugin/shared_Faces_macro_widget.xml new file mode 100644 index 000000000..b9031cff2 --- /dev/null +++ b/src/FeaturesPlugin/shared_Faces_macro_widget.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + diff --git a/src/FeaturesPlugin/shared_Faces_widget.xml b/src/FeaturesPlugin/shared_Faces_widget.xml new file mode 100644 index 000000000..76fb12a02 --- /dev/null +++ b/src/FeaturesPlugin/shared_Faces_widget.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + diff --git a/src/FeaturesPlugin/tests.set b/src/FeaturesPlugin/tests.set index 1274228bc..13ffed855 100644 --- a/src/FeaturesPlugin/tests.set +++ b/src/FeaturesPlugin/tests.set @@ -178,7 +178,7 @@ SET(TEST_NAMES TestMeasurementAngle3Points.py TestMeasurementPresentation.py TestFusionFaces.py - TestFusionFaces2697.py + TestFusionFaces2697.py Test1379.py Test1922.py Test1942.py @@ -526,4 +526,5 @@ SET(TEST_NAMES TestBoundingBox.py Test23885.py TestNormalToFace.py + TestCheckSharedFaces.py ) diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index 17eec671e..f9c0e8ff4 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -33,6 +33,7 @@ SET(PROJECT_HEADERS GeomAlgoAPI_Prism.h GeomAlgoAPI_Revolution.h GeomAlgoAPI_Boolean.h + GeomAlgoAPI_SharedFaces.h GeomAlgoAPI_ThroughAll.h GeomAlgoAPI_Rotation.h GeomAlgoAPI_Translation.h @@ -105,6 +106,7 @@ SET(PROJECT_SOURCES GeomAlgoAPI_Prism.cpp GeomAlgoAPI_Revolution.cpp GeomAlgoAPI_Boolean.cpp + GeomAlgoAPI_SharedFaces.cpp GeomAlgoAPI_ThroughAll.cpp GeomAlgoAPI_Rotation.cpp GeomAlgoAPI_Translation.cpp diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_SharedFaces.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_SharedFaces.cpp new file mode 100644 index 000000000..2792421df --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_SharedFaces.cpp @@ -0,0 +1,148 @@ +// Copyright (C) 2014-2021 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_SharedFaces.h" + +#include + +#include +#include +#include + +#include +#include + +#include +#include + +//======================================================================= +//function : GetSharedShapes +//purpose : +// +// NOTE on the implementation +// +// 1) Resulting sub-shapes are published as a children of the 1st input shape +// from theShapes list. Due to this reason only direct sub-shapes of the 1st +// shape can be contained in the result of the operation (i.e. shares between +// 2nd/3rd, etc couples cannot be retrieved. +// 2) An exception from above case is when a single compound is specified as an +// input. In this case we search shares between its top-level content, so we +// are able to search shares between all possible couples of shapes. +// 3) Parameter theMultiShare controls what types of shares to search: +// - True: get sub-shapes that are shared between ALL input shapes; +// - False: get shares between couples of input sub-shapes (see points 1 and 2). +// +// Thus, we have the following cases: +// [1] theShapes = N shapes (N>1), theMultiShare = True +// Result: sub-shapes that are shared by all theShapes +// [2] theShapes = N shapes (N>1), theMultiShare = False +// Result: sub-shapes of 1st shape from theShapes that are shared with any shape +// from theShapes +// [3] theShapes = 1 shape, theMultiShare = True +// Result: sub-shapes that are shared by all top-level sub-objects of theShapes[0] +// [4] theShapes = 1 shape, theMultiShare = False +// Result: sub-shapes of all possible couples of all top-level sub-objects of +// theShapes[0]. +//================================================================================================= +bool GetSharedFaces(const ListOfShape& theShapes, + ListOfShape & theFaces, + const bool theMultiShare, + std::string& theError) +{ + + #ifdef _DEBUG + std::cout << "GetSharedFaces " << std::endl; + #endif + int aLen = theShapes.size(); + if (aLen < 1) return NULL; + + TopAbs_ShapeEnum aShapeType = TopAbs_FACE; + + TopoDS_Shape aShape; + TopTools_SequenceOfShape aShapesSeq; + + ListOfShape::const_iterator anIt = theShapes.cbegin(); + + for(; anIt != theShapes.cend(); ++anIt) { + + GeomShapePtr aShapePtr = *anIt; + + if (!aShapePtr.get()) { + theError = "GetSharedFaces : An invalid argument"; + return false; + } + aShape = aShapePtr->impl(); + aShapesSeq.Append( aShape ); + } + + // if only single shape is specified as input + // collect all ites top-level sub-shapes for processing + if (aShapesSeq.Length() == 1) { + aShape = aShapesSeq.First(); + aShapesSeq.Clear(); + for (TopoDS_Iterator it( aShape ); it.More(); it.Next()) + aShapesSeq.Append( it.Value() ); + } + + TopTools_MapOfShape mapShape; + + // find shared shapes + + // number of iterations + int nbIters = theMultiShare || theShapes.size() > 1 ? 1 : aShapesSeq.Length()-1; + // numShares factor to search (i.e. by what nb of shapes each found sub-shape should be shared) + int nbShares = theMultiShare ? aShapesSeq.Length()-1 : 1; + + for (int iter = 1; iter <= nbIters; iter++) { + for (int ind = iter + 1; ind <= aShapesSeq.Length(); ind++) { + if (ind - 1 + nbShares > aShapesSeq.Length()) break; + TopoDS_Compound aCurrSelection; + TopoDS_Shape aShape1 = aShapesSeq.Value( iter ); + TopTools_IndexedMapOfShape mapSelected; + TopExp::MapShapes(aShape1, aShapeType, mapSelected); + for (int s = 0; s < nbShares; s++) { + BRep_Builder B; + TopoDS_Compound aCompound; + B.MakeCompound(aCompound); + const TopoDS_Shape& aShape2 = aShapesSeq.Value( ind+s ); + TopTools_MapOfShape mapShape2; + TopExp_Explorer exp (aShape2, aShapeType); + for (; exp.More(); exp.Next()) { + const TopoDS_Shape& aSS = exp.Current(); + if (mapShape2.Add(aSS) && mapSelected.Contains(aSS)) { + B.Add(aCompound, aSS); + } + } + mapSelected.Clear(); + aCurrSelection = aCompound; + TopExp::MapShapes(aCurrSelection, aShapeType, mapSelected); + } + TopoDS_Iterator itSel(aCurrSelection, Standard_True, Standard_True); + for (; itSel.More(); itSel.Next()) { + const TopoDS_Shape& aSS = itSel.Value(); + GeomShapePtr aS(new GeomAPI_Shape); + aS->setImpl(new TopoDS_Shape(aSS)); + if (mapShape.Add(aSS) ) + theFaces.push_back(aS); + } + } + } + return true; +} + diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_SharedFaces.h b/src/GeomAlgoAPI/GeomAlgoAPI_SharedFaces.h new file mode 100644 index 000000000..5c3ba1fdc --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_SharedFaces.h @@ -0,0 +1,39 @@ +// Copyright (C) 2014-2021 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_SHAREDFACES_H_ +#define GEOMALGOAPI_SHAREDFACES_H_ + +#include +#include + +#include + +/// get the boundin box of theshape. +/// \param theShape the shape +/// \param theTolerance precise TRUE for precise computation; FALSE for fast one. +/// \param theFaces the faces shared +/// \param theError error +GEOMALGOAPI_EXPORT +bool GetSharedFaces(const ListOfShape& theShapes, + ListOfShape & theFaces, + const bool theMultiShare, + std::string& theError); + +#endif //GEOMALGOAPI_SHAREDFACES_H_ diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index bbef9d3e5..0d69e8f2b 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -179,16 +179,16 @@ ADD_UNIT_TESTS(${TEST_NAMES}) if(${HAVE_SALOME}) enable_testing() set(TEST_INSTALL_DIRECTORY "${SALOME_SHAPER_INSTALL_TESTS}/ModelAPI") - + install(FILES CTestTestfileInstall.cmake DESTINATION ${TEST_INSTALL_DIRECTORY} RENAME CTestTestfile.cmake) install(FILES tests.set DESTINATION ${TEST_INSTALL_DIRECTORY}) - + set(TMP_TESTS_NAMES) foreach(tfile ${TEST_NAMES}) list(APPEND TMP_TESTS_NAMES "Test/${tfile}") endforeach(tfile ${TEST_NAMES}) - + install(FILES ${TMP_TESTS_NAMES} DESTINATION ${TEST_INSTALL_DIRECTORY}) endif(${HAVE_SALOME}) diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index db4b8cd92..54c659ccb 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -49,8 +49,8 @@ class ModuleBase_FilterStarter; * Implementation of widget for shapes selection. This widget provides selection of several shapes. * It can be defined in XML file as following: * \code -* * \endcode * It uses following parameters: diff --git a/src/PythonAPI/model/features/__init__.py b/src/PythonAPI/model/features/__init__.py index 62a0ca1a8..836387529 100644 --- a/src/PythonAPI/model/features/__init__.py +++ b/src/PythonAPI/model/features/__init__.py @@ -32,6 +32,7 @@ from FeaturesAPI import addFusionFaces from FeaturesAPI import measureLength, measureDistance, measureRadius, measureAngle from FeaturesAPI import getPointCoordinates, getGeometryCalculation, getBoundingBox from FeaturesAPI import getNormal +from FeaturesAPI import getSharedFaces from FeaturesAPI import addRemoveResults from FeaturesAPI import addCopy, addImportResult from FeaturesAPI import addDefeaturing