From: Jérôme Date: Wed, 9 Dec 2020 16:10:17 +0000 (+0100) Subject: #20442 Viusalization of faces found and add tolerance X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=44df74980936150d9db90c15aa6be98264baa3ba;p=modules%2Fshaper.git #20442 Viusalization of faces found and add tolerance --- diff --git a/src/FeaturesAPI/FeaturesAPI_DuplicatedFaces.cpp b/src/FeaturesAPI/FeaturesAPI_DuplicatedFaces.cpp index 5b86cb56e..4e26e4695 100644 --- a/src/FeaturesAPI/FeaturesAPI_DuplicatedFaces.cpp +++ b/src/FeaturesAPI/FeaturesAPI_DuplicatedFaces.cpp @@ -19,8 +19,8 @@ #include "FeaturesAPI_DuplicatedFaces.h" -#include -#include +#include + #include #include @@ -45,17 +45,17 @@ FeaturesAPI_DuplicatedFaces::~FeaturesAPI_DuplicatedFaces() FeaturesAPI_DuplicatedFaces::FeaturesAPI_DuplicatedFaces( const std::shared_ptr& theFeature, const ModelHighAPI_Selection& theObject, - const double theTransparency, + const ModelHighAPI_Integer& theTransparency, + const ModelHighAPI_Double& theTolerance, const std::string & theNameGroup) :ModelHighAPI_Interface(theFeature) { if (initialize()) { fillAttribute(theObject, myobjectselected); fillAttribute(theTransparency, mytransparency); - if (theNameGroup != "") { - fillAttribute(true,feature()->boolean(FeaturesPlugin_DuplicatedFaces::CREATE_GROUP_ID())); - fillAttribute(theNameGroup, mygroupname); - } + fillAttribute(theTolerance, mytolerance); + fillAttribute(theNameGroup, mygroupname); + execute(); } } @@ -67,31 +67,31 @@ void FeaturesAPI_DuplicatedFaces::dump(ModelHighAPI_Dumper& theDumper) const const std::string& aDocName = theDumper.name(aBase->document()); AttributeSelectionPtr anAttrObject; - anAttrObject = aBase->selection(FeaturesPlugin_DuplicatedFaces::OBJECT_ID()); + anAttrObject = aBase->selection(FeaturesPlugin_GroupDuplicatedFaces::OBJECT_ID()); theDumper << aBase << " = model.getDuplicatedFaces(" << aDocName << ", " << anAttrObject; - theDumper << ", " << aBase->integer(FeaturesPlugin_DuplicatedFaces::TRANSPARENCY_ID()); - - if(aBase->boolean(FeaturesPlugin_DuplicatedFaces::CREATE_GROUP_ID())->value() ) - theDumper << ", " << aBase->string(FeaturesPlugin_DuplicatedFaces::GROUP_NAME_ID()); - + theDumper << ", " << aBase->integer(FeaturesPlugin_GroupDuplicatedFaces::TRANSPARENCY_ID()); + theDumper << ", " << aBase->real(FeaturesPlugin_GroupDuplicatedFaces::TOLERANCE_ID()); + theDumper << ", " << aBase->string(FeaturesPlugin_GroupDuplicatedFaces::GROUP_NAME_ID()); theDumper << ")" << std::endl; } //================================================================================================= DuplicatedFacesPtr getDuplicatedFaces(const std::shared_ptr& thePart, const ModelHighAPI_Selection& theObject, - const double theTransparency, + const ModelHighAPI_Integer& theTransparency, + const ModelHighAPI_Double& theTolerance, const std::string & theNameGroup) { - FeaturePtr aFeature = thePart->addFeature(FeaturesPlugin_DuplicatedFaces::ID()); + FeaturePtr aFeature = thePart->addFeature(FeaturesPlugin_GroupDuplicatedFaces::ID()); DuplicatedFacesPtr aDuplicatedFaces; aDuplicatedFaces.reset(new FeaturesAPI_DuplicatedFaces(aFeature, theObject, theTransparency, + theTolerance, theNameGroup)); return aDuplicatedFaces; diff --git a/src/FeaturesAPI/FeaturesAPI_DuplicatedFaces.h b/src/FeaturesAPI/FeaturesAPI_DuplicatedFaces.h index 4924a0597..12705dbe4 100644 --- a/src/FeaturesAPI/FeaturesAPI_DuplicatedFaces.h +++ b/src/FeaturesAPI/FeaturesAPI_DuplicatedFaces.h @@ -22,9 +22,11 @@ #include "FeaturesAPI.h" -#include "FeaturesPlugin_DuplicatedFaces.h" +#include "FeaturesPlugin_GroupDuplicatedFaces.h" #include +#include +#include #include #include @@ -45,21 +47,25 @@ public: FEATURESAPI_EXPORT explicit FeaturesAPI_DuplicatedFaces(const std::shared_ptr& theFeature, const ModelHighAPI_Selection& theobject, - const double theTransparency, + const ModelHighAPI_Integer& theTransparency, + const ModelHighAPI_Double& theTolerance, const std::string & theNameGroup); /// Destructor. FEATURESAPI_EXPORT virtual ~FeaturesAPI_DuplicatedFaces(); - INTERFACE_3(FeaturesPlugin_DuplicatedFaces::ID(), - objectselected, FeaturesPlugin_DuplicatedFaces::OBJECT_ID(), + INTERFACE_4(FeaturesPlugin_GroupDuplicatedFaces::ID(), + objectselected, FeaturesPlugin_GroupDuplicatedFaces::OBJECT_ID(), ModelAPI_AttributeSelection, /** object selected*/, - transparency, FeaturesPlugin_DuplicatedFaces::TRANSPARENCY_ID(), + transparency, FeaturesPlugin_GroupDuplicatedFaces::TRANSPARENCY_ID(), ModelAPI_AttributeInteger, /** transparency*/, - groupname, FeaturesPlugin_DuplicatedFaces::GROUP_NAME_ID(), + tolerance, FeaturesPlugin_GroupDuplicatedFaces::TOLERANCE_ID(), + ModelAPI_AttributeDouble, + /** tolerance*/, + groupname, FeaturesPlugin_GroupDuplicatedFaces::GROUP_NAME_ID(), ModelAPI_AttributeString, /** group name*/) @@ -79,7 +85,8 @@ typedef std::shared_ptr DuplicatedFacesPtr; FEATURESAPI_EXPORT DuplicatedFacesPtr getDuplicatedFaces(const std::shared_ptr& thePart, const ModelHighAPI_Selection& theObject, - const double theTransparency = 0.0, - const std::string & theNameGroup = ""); + const ModelHighAPI_Integer& theTransparency, + const ModelHighAPI_Double& theTolerance, + const std::string & theNameGroup); #endif // FeaturesAPI_DuplicatedFaces_H_ diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 39470e1f5..0cf4cabcc 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -24,7 +24,6 @@ INCLUDE(UseQtExt) # additional include directories INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/GeomDataAPI ${PROJECT_SOURCE_DIR}/src/Locale - ${PROJECT_SOURCE_DIR}/src/PrimitivesPlugin ${QT_INCLUDES}) # additional preprocessor / compiler flags @@ -71,6 +70,8 @@ SET(PROJECT_HEADERS FeaturesPlugin_Fillet1D.h FeaturesPlugin_Measurement.h FeaturesPlugin_DuplicatedFaces.h + FeaturesPlugin_CommonDuplicatedFaces.h + FeaturesPlugin_GroupDuplicatedFaces.h FeaturesPlugin_FusionFaces.h FeaturesPlugin_RemoveResults.h FeaturesPlugin_Chamfer.h @@ -119,6 +120,8 @@ SET(PROJECT_SOURCES FeaturesPlugin_Fillet1D.cpp FeaturesPlugin_Measurement.cpp FeaturesPlugin_DuplicatedFaces.cpp + FeaturesPlugin_CommonDuplicatedFaces.cpp + FeaturesPlugin_GroupDuplicatedFaces.cpp FeaturesPlugin_FusionFaces.cpp FeaturesPlugin_RemoveResults.cpp FeaturesPlugin_Chamfer.cpp @@ -157,7 +160,8 @@ SET(XML_RESOURCES fillet_widget.xml fillet1d_widget.xml measurement_widget.xml - duplicatedFaces_widget.xml + duplicated_faces_widget.xml + duplicated_faces_macro_widget.xml fusion_faces_widget.xml chamfer_widget.xml copy_widget.xml @@ -708,5 +712,5 @@ ADD_UNIT_TESTS(TestExtrusion.py TestFillet1D_Wire_3.py TestFillet1D_Wire_4.py TestFillet1D_Wire_5.py - TestCheckDuplictedFaces.py + TestCheckDuplicatedFaces.py ) diff --git a/src/FeaturesPlugin/FeaturesPlugin_CommonDuplicatedFaces.cpp b/src/FeaturesPlugin/FeaturesPlugin_CommonDuplicatedFaces.cpp new file mode 100644 index 000000000..93e7f4a66 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_CommonDuplicatedFaces.cpp @@ -0,0 +1,136 @@ +// Copyright (C) 2018-2020 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_CommonDuplicatedFaces.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include + +//================================================================================================= +void explode(const GeomShapePtr& theCompound, ListOfShape& theSubs) +{ + if (theCompound->isCompound() || theCompound->isCompSolid()) { + GeomAPI_ShapeIterator anIt(theCompound); + for (; anIt.more(); anIt.next()) + explode(anIt.current(), theSubs); + } else + theSubs.push_back(theCompound); +} + +//================================================================================================= +void FeaturesPlugin_CommonDuplicatedFaces::updateFaces() +{ + AttributeSelectionPtr ancompSolidAttr = + std::dynamic_pointer_cast(attributObject()); + + AttributeSelectionListPtr aFacesListAttr = + std::dynamic_pointer_cast + (attributListFaces()); + + if (aFacesListAttr->isInitialized()) + aFacesListAttr->clear(); + + AttributeDoublePtr aToleranceAttr = + std::dynamic_pointer_cast + (attributTolerance()); + + GeomShapePtr aShape = ancompSolidAttr->value(); + if (aShape.get() && ancompSolidAttr->context().get() && aToleranceAttr.get()) { + + aShape = ancompSolidAttr->context()->shape(); + if (aShape) { + std::string anError; + ListOfShape aFaces; + ListOfShape theSubs; + explode(aShape, theSubs); + + if (!GetDuplicatedFaces(theSubs, + aToleranceAttr->value(), + aFaces, + anError)) + setError("Error in duplicated faces calculation :" + anError); + + aFacesListAttr->setSelectionType("face"); + + ListOfShape::const_iterator anIt = aFaces.cbegin(); + for (; anIt != aFaces.cend(); ++anIt) { + + GeomShapePtr aFacePtr = *anIt; + + if (!aFacePtr.get()) { + setError("GetDuplicatedFaces : An invalid face found " + anError); + } + aFacesListAttr->append(ancompSolidAttr->context(), aFacePtr); + } + std::stringstream alabel; + alabel << "Number of duplicated faces : " << aFacesListAttr->size(); + AttributeStringPtr aNumberFacesAttr = + std::dynamic_pointer_cast + (attributNumberFaces()); + aNumberFacesAttr->setValue(alabel.str()); + } + } +} + +//================================================================================================= +void FeaturesPlugin_CommonDuplicatedFaces::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_CommonDuplicatedFaces.h b/src/FeaturesPlugin/FeaturesPlugin_CommonDuplicatedFaces.h new file mode 100644 index 000000000..4333f34c4 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_CommonDuplicatedFaces.h @@ -0,0 +1,66 @@ +// Copyright (C) 2018-2020 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_CommonDuplicatedFaces_H_ +#define FeaturesPlugin_CommonDuplicatedFaces_H_ + +#include "FeaturesPlugin.h" +#include +#include +#include + +#include +#include + + +/// \class FeaturesPlugin_CommonDuplicatedFaces +/// \ingroup Plugins +/// \brief Feature to check the duplicated faces of solid + +class FeaturesPlugin_CommonDuplicatedFaces : 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 tolerance. + virtual AttributePtr attributTolerance() = 0; + + protected: + FeaturesPlugin_CommonDuplicatedFaces() {} + + //Set group of faces + void setFacesGroup(const std::wstring& theName); + + // Update the list of faces + void updateFaces(); + +}; + +#endif diff --git a/src/FeaturesPlugin/FeaturesPlugin_DuplicatedFaces.cpp b/src/FeaturesPlugin/FeaturesPlugin_DuplicatedFaces.cpp index 9442b5553..6a409fee6 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_DuplicatedFaces.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_DuplicatedFaces.cpp @@ -19,10 +19,11 @@ #include "FeaturesPlugin_DuplicatedFaces.h" +#include #include -#include #include #include +#include #include #include #include @@ -36,14 +37,10 @@ #include #include -#include #include -#include -#include #include #include #include -#include //================================================================================================= FeaturesPlugin_DuplicatedFaces::FeaturesPlugin_DuplicatedFaces() @@ -59,48 +56,73 @@ void FeaturesPlugin_DuplicatedFaces::initAttributes() data()->addAttribute(NUMBER_FACES_ID(), ModelAPI_AttributeString::typeId()); data()->addAttribute(TRANSPARENCY_ID(), ModelAPI_AttributeInteger::typeId()); + data()->addAttribute(TOLERANCE_ID(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(CREATE_GROUP_ID(), ModelAPI_AttributeBoolean::typeId()); data()->addAttribute(GROUP_NAME_ID(), ModelAPI_AttributeString::typeId()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), GROUP_NAME_ID()); - boolean(CREATE_GROUP_ID())->setValue(false); } + //================================================================================================= -void explode(const GeomShapePtr& theCompound, ListOfShape& theSubs) +AttributePtr FeaturesPlugin_DuplicatedFaces::attributObject() { - if (theCompound->isCompound() || theCompound->isCompSolid()) { - GeomAPI_ShapeIterator anIt(theCompound); - for (; anIt.more(); anIt.next()) - explode(anIt.current(), theSubs); - } - else - theSubs.push_back(theCompound); + return attribute(OBJECT_ID()); +} + +//================================================================================================= +AttributePtr FeaturesPlugin_DuplicatedFaces::attributListFaces() +{ + return attribute(LIST_FACES_ID()); +} + +//================================================================================================= +AttributePtr FeaturesPlugin_DuplicatedFaces::attributNumberFaces() +{ + return attribute(NUMBER_FACES_ID()); } +//================================================================================================= +AttributePtr FeaturesPlugin_DuplicatedFaces::attributTolerance() +{ + return attribute(TOLERANCE_ID()); +} + + //================================================================================================= void FeaturesPlugin_DuplicatedFaces::execute() { - if(boolean(CREATE_GROUP_ID())->value() - && selectionList(LIST_FACES_ID())->isInitialized() - && string(GROUP_NAME_ID())->value() != "" ){ + if (boolean(CREATE_GROUP_ID())->value()) { - AttributeStringPtr aNameAtt = string(GROUP_NAME_ID()); - std::wstring aNameFace = aNameAtt->isUValue() ? - Locale::Convert::toWString(aNameAtt->valueU()) : - Locale::Convert::toWString(aNameAtt->value()); + if (string(GROUP_NAME_ID())->value() != "" + && selectionList(LIST_FACES_ID())->isInitialized()) { - if (myGroup.get()) - eraseResults(); - setFacesGroup(aNameFace); + if (lastResult().get()) { + eraseResultFromList(lastResult()); + } - } else { - if (myGroup.get()) { - eraseResults(); - myGroup.reset(); + 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_DuplicatedFaces"); + } } + if (selection(OBJECT_ID())->isInitialized()) { AttributeSelectionPtr ancompSolidAttr = selection(OBJECT_ID()); ResultPtr aResult = ancompSolidAttr->context(); @@ -113,7 +135,7 @@ void FeaturesPlugin_DuplicatedFaces::execute() ModelAPI_Tools::allSubs(aResultBody, allRes); std::list::iterator aRes; for (aRes = allRes.begin(); aRes != allRes.end(); aRes++) { - ModelAPI_Tools::setTransparency(*aRes, aTranparency); + ModelAPI_Tools::setTransparency(*aRes, aTranparency); } } } @@ -121,77 +143,42 @@ void FeaturesPlugin_DuplicatedFaces::execute() //================================================================================================= void FeaturesPlugin_DuplicatedFaces::attributeChanged(const std::string& theID) { - if (theID == OBJECT_ID()) { - AttributeSelectionPtr ancompSolidAttr = selection(OBJECT_ID()); - - GeomShapePtr aShape = ancompSolidAttr->value(); - if (aShape.get() && ancompSolidAttr->context().get()) { - - aShape = ancompSolidAttr->context()->shape(); - if (aShape) { - std::string anError; - ListOfShape aFaces; - ListOfShape theSubs; - explode(aShape, theSubs); + if (theID == OBJECT_ID() + || theID == TOLERANCE_ID()) { - if (!GetDuplicatedFaces(theSubs, - 0.001, - aFaces, - anError)) - setError("Error in duplicated faces calculation :" + anError); - - - AttributeSelectionListPtr aFacesListAttr = - std::dynamic_pointer_cast - (attribute(LIST_FACES_ID())); - - if (aFacesListAttr->isInitialized()) - aFacesListAttr->clear(); - - aFacesListAttr->setSelectionType("face"); + updateFaces(); + if (myCreateGroupFeature.get()) + updateGroup(); + } +} - ListOfShape::const_iterator anIt = aFaces.cbegin(); - for(; anIt != aFaces.cend(); ++anIt) { +//================================================================================================= +void FeaturesPlugin_DuplicatedFaces::createGroup() +{ + SessionPtr aSession = ModelAPI_Session::get(); - GeomShapePtr aFacePtr = *anIt; + DocumentPtr aDoc = aSession->activeDocument(); - if (!aFacePtr.get()) { - setError("GetDuplicatedFaces : An invalid face found " + anError); - } - aFacesListAttr->append( ancompSolidAttr->context(), aFacePtr); - } - std::stringstream alabel; - alabel << "Number of duplicated faces : " << aFacesListAttr->size(); - string(NUMBER_FACES_ID() )->setValue( alabel.str() ); - } - } + if (aDoc.get()) { + myCreateGroupFeature = aDoc->addFeature(FeaturesPlugin_GroupDuplicatedFaces::ID()); } } //================================================================================================= -void FeaturesPlugin_DuplicatedFaces::setFacesGroup(const std::wstring& theName ) +void FeaturesPlugin_DuplicatedFaces::updateGroup() { - std::vector aColor; - myGroup = document()->createGroup(data()); - // clean the result of the operation - myGroup->data()->setName(theName); - myGroup->store(GeomShapePtr()); - - // shapes containing in each group - ListOfShape aFaces; - AttributeSelectionListPtr aFacesListAttr = - std::dynamic_pointer_cast - (attribute(LIST_FACES_ID())); - - for (int anI =0; anI< aFacesListAttr->size(); anI++) { - AttributeSelectionPtr aAtt = aFacesListAttr->value(anI); - aFaces.push_back( aAtt->value() ); - } + myCreateGroupFeature->string(FeaturesPlugin_GroupDuplicatedFaces::GROUP_NAME_ID()) + ->setValue(string(GROUP_NAME_ID())->value()); - GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces); - myGroup->store(aCompound); - aColor = {255,0,0}; - setResult(myGroup); - ModelAPI_Tools::setColor( lastResult(),aColor); -} + myCreateGroupFeature->selection(FeaturesPlugin_GroupDuplicatedFaces::OBJECT_ID()) + ->setValue(selection(OBJECT_ID())->context() , + selection(OBJECT_ID())->value()); + + myCreateGroupFeature->integer(FeaturesPlugin_GroupDuplicatedFaces::TRANSPARENCY_ID()) + ->setValue(integer(TRANSPARENCY_ID())->value()); + + myCreateGroupFeature->real(FeaturesPlugin_GroupDuplicatedFaces::TOLERANCE_ID()) + ->setValue(real(TOLERANCE_ID())->value()); + myCreateGroupFeature->execute(); +} \ No newline at end of file diff --git a/src/FeaturesPlugin/FeaturesPlugin_DuplicatedFaces.h b/src/FeaturesPlugin/FeaturesPlugin_DuplicatedFaces.h index 490208992..61c753058 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_DuplicatedFaces.h +++ b/src/FeaturesPlugin/FeaturesPlugin_DuplicatedFaces.h @@ -20,24 +20,18 @@ #ifndef FeaturesPlugin_DuplicatedFaces_H_ #define FeaturesPlugin_DuplicatedFaces_H_ -#include "FeaturesPlugin.h" -#include -#include - -#include -#include -#include +#include /// \class FeaturesPlugin_DuplicatedFaces /// \ingroup Plugins /// \brief Feature to check the duplicated faces of solid -class FeaturesPlugin_DuplicatedFaces : public ModelAPI_Feature +class FeaturesPlugin_DuplicatedFaces : public FeaturesPlugin_CommonDuplicatedFaces { public: inline static const std::string& ID() { - static const std::string MY_ID("Duplicated_faces"); + static const std::string MY_ID("Duplicated_faces_macro"); return MY_ID; } @@ -68,13 +62,20 @@ public: return MY_LIST_FACES_ID; } - /// Attribute name for transparency. + /// 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 tolerance. + inline static const std::string& TOLERANCE_ID() + { + static const std::string MY_TOLERANCE_ID("tolerance"); + return MY_TOLERANCE_ID; + } + /// Attribute name for checkbox create group. inline static const std::string& CREATE_GROUP_ID() { @@ -99,14 +100,34 @@ public: /// \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_DuplicatedFaces(); private: - //Set group of faces - void setFacesGroup(const std::wstring& theName ); - ResultGroupPtr myGroup; + /// 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 tolerance. + virtual AttributePtr attributTolerance(); + + /// Create group + void createGroup(); + + /// Update group + void updateGroup(); + + /// Feature to create group + FeaturePtr myCreateGroupFeature; }; #endif diff --git a/src/FeaturesPlugin/FeaturesPlugin_GroupDuplicatedFaces.cpp b/src/FeaturesPlugin/FeaturesPlugin_GroupDuplicatedFaces.cpp new file mode 100644 index 000000000..147ab3abf --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_GroupDuplicatedFaces.cpp @@ -0,0 +1,135 @@ +// Copyright (C) 2018-2020 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_GroupDuplicatedFaces.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +//================================================================================================= +FeaturesPlugin_GroupDuplicatedFaces::FeaturesPlugin_GroupDuplicatedFaces() +{ +} + +//================================================================================================= +void FeaturesPlugin_GroupDuplicatedFaces::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(TOLERANCE_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(GROUP_NAME_ID(), ModelAPI_AttributeString::typeId()); + +} + + +//================================================================================================= +AttributePtr FeaturesPlugin_GroupDuplicatedFaces::attributObject() +{ + return attribute(OBJECT_ID()); +} + +//================================================================================================= +AttributePtr FeaturesPlugin_GroupDuplicatedFaces::attributListFaces() +{ + return attribute(LIST_FACES_ID()); +} + +//================================================================================================= +AttributePtr FeaturesPlugin_GroupDuplicatedFaces::attributNumberFaces() +{ + return attribute(NUMBER_FACES_ID()); +} + +//================================================================================================= +AttributePtr FeaturesPlugin_GroupDuplicatedFaces::attributTolerance() +{ + return attribute(TOLERANCE_ID()); +} + +//================================================================================================= +void FeaturesPlugin_GroupDuplicatedFaces::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()) { + AttributeSelectionPtr ancompSolidAttr = selection(OBJECT_ID()); + ResultPtr aResult = ancompSolidAttr->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_GroupDuplicatedFaces::attributeChanged(const std::string& theID) +{ + if (theID == OBJECT_ID() + || theID == TOLERANCE_ID()) { + updateFaces(); + } +} \ No newline at end of file diff --git a/src/FeaturesPlugin/FeaturesPlugin_GroupDuplicatedFaces.h b/src/FeaturesPlugin/FeaturesPlugin_GroupDuplicatedFaces.h new file mode 100644 index 000000000..583b770ec --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_GroupDuplicatedFaces.h @@ -0,0 +1,115 @@ +// Copyright (C) 2018-2020 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_GroupDuplicatedFaces_H_ +#define FeaturesPlugin_GroupDuplicatedFaces_H_ + +#include + +/// \class FeaturesPlugin_GroupDuplicatedFaces +/// \ingroup Plugins +/// \brief Feature to check the duplicated faces of solid + +class FeaturesPlugin_GroupDuplicatedFaces : public FeaturesPlugin_CommonDuplicatedFaces +{ +public: + inline static const std::string& ID() + { + static const std::string MY_ID("Duplicated_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_duplicated_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("faces"); + 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 tolerance. + inline static const std::string& TOLERANCE_ID() + { + static const std::string MY_TOLERANCE_ID("tolerance"); + return MY_TOLERANCE_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); + + /// Use plugin manager for features creation + FeaturesPlugin_GroupDuplicatedFaces(); + + 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 tolerance. + virtual AttributePtr attributTolerance(); + +}; + +#endif diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index 5914a064c..02914017e 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -190,6 +191,8 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(std::string theFeatureID) return FeaturePtr(new FeaturesPlugin_Measurement); } else if (theFeatureID == FeaturesPlugin_DuplicatedFaces::ID()) { return FeaturePtr(new FeaturesPlugin_DuplicatedFaces); + } else if (theFeatureID == FeaturesPlugin_GroupDuplicatedFaces::ID()) { + return FeaturePtr(new FeaturesPlugin_GroupDuplicatedFaces); } else if (theFeatureID == FeaturesPlugin_RemoveResults::ID()) { return FeaturePtr(new FeaturesPlugin_RemoveResults); } else if (theFeatureID == FeaturesPlugin_Chamfer::ID()) { diff --git a/src/FeaturesPlugin/Test/TestCheckDuplicatedFaces.py b/src/FeaturesPlugin/Test/TestCheckDuplicatedFaces.py new file mode 100644 index 000000000..6c08bcb45 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestCheckDuplicatedFaces.py @@ -0,0 +1,92 @@ +# Copyright (C) 2014-2020 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 Duplicated 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, 100, 50, 100) + ### Create Point + Point_1 = model.addPoint(Part_1_doc, 100, 0, 0) + ### Create Point + Point_2 = model.addPoint(Part_1_doc, 250, 50, 100) + ### Create Box + Box_2 = model.addBox(Part_1_doc, model.selection("VERTEX", "all-in-Point_1"), model.selection("VERTEX", "all-in-Point_2")) + ### Create Point + Point_3 = model.addPoint(Part_1_doc, 100, 50, 250) + ### Create Box + Box_3 = model.addBox(Part_1_doc, model.selection("VERTEX", "[Box_1_1/Back][Box_1_1/Left][Box_1_1/Top]"), model.selection("VERTEX", "Point_3")) + ### Create Compound + Compound_1_objects = [model.selection("SOLID", "Box_1_1"), + model.selection("SOLID", "Box_2_1"), + model.selection("SOLID", "Box_3_1")] + Compound_1 = model.addCompound(Part_1_doc, Compound_1_objects) + ### Create Duplicated_faces + Duplicated_faces_1 = model.getDuplicatedFaces(Part_1_doc, model.selection("COMPOUND", "Compound_1_1"), 50, 0.001, "mygroup") + + model.do() + # Check results + Duplicated_faces_1_Feature = Duplicated_faces_1.feature() + assert Duplicated_faces_1_Feature.error() == '' + assert Duplicated_faces_1_Feature.name() == "Duplicated_faces_1" + + aSelectionList = Duplicated_faces_1_Feature.selectionList("faces") + assert aSelectionList.size() == 2 + + 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() + aShapeExplorer.next() + assert(not aShapeExplorer.more()) + + model.end() + + #========================================================================= + # End of test + #========================================================================= diff --git a/src/FeaturesPlugin/Test/TestCheckDuplictedFaces.py b/src/FeaturesPlugin/Test/TestCheckDuplictedFaces.py deleted file mode 100644 index 50b8e44f4..000000000 --- a/src/FeaturesPlugin/Test/TestCheckDuplictedFaces.py +++ /dev/null @@ -1,92 +0,0 @@ -# Copyright (C) 2014-2020 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 Duplicated 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, 100, 50, 100) - ### Create Point - Point_1 = model.addPoint(Part_1_doc, 100, 0, 0) - ### Create Point - Point_2 = model.addPoint(Part_1_doc, 250, 50, 100) - ### Create Box - Box_2 = model.addBox(Part_1_doc, model.selection("VERTEX", "all-in-Point_1"), model.selection("VERTEX", "all-in-Point_2")) - ### Create Point - Point_3 = model.addPoint(Part_1_doc, 100, 50, 250) - ### Create Box - Box_3 = model.addBox(Part_1_doc, model.selection("VERTEX", "[Box_1_1/Back][Box_1_1/Left][Box_1_1/Top]"), model.selection("VERTEX", "Point_3")) - ### Create Compound - Compound_1_objects = [model.selection("SOLID", "Box_1_1"), - model.selection("SOLID", "Box_2_1"), - model.selection("SOLID", "Box_3_1")] - Compound_1 = model.addCompound(Part_1_doc, Compound_1_objects) - ### Create Duplicated_faces - Duplicated_faces_1 = model.getDuplicatedFaces(Part_1_doc, model.selection("COMPOUND", "Compound_1_1"), 50, "mygroup") - - model.do() - # Check results - Duplicated_faces_1_Feature = Duplicated_faces_1.feature() - assert Duplicated_faces_1_Feature.error() == '' - assert Duplicated_faces_1_Feature.name() == "Duplicated_faces_1" - - aSelectionList = Duplicated_faces_1_Feature.selectionList("faces") - assert aSelectionList.size() == 2 - - 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() - aShapeExplorer.next() - assert(not aShapeExplorer.more()) - - model.end() - - #========================================================================= - # End of test - #========================================================================= diff --git a/src/FeaturesPlugin/doc/checkDuplicatedFaceFeature.rst b/src/FeaturesPlugin/doc/checkDuplicatedFaceFeature.rst index aba107ea5..181b1682f 100644 --- a/src/FeaturesPlugin/doc/checkDuplicatedFaceFeature.rst +++ b/src/FeaturesPlugin/doc/checkDuplicatedFaceFeature.rst @@ -26,17 +26,19 @@ Input fields: - **Number of duplicated faces** indicate the number of found faces. - **List of faces** the list of found faces. - **Transparency** set the transparency of selected object. +- **Tolerance** set the tolerance for the algotithme. - **Create group** check-box allow the creation of the group of found faces. - **Group name** specified the name of the group created. **TUI Command**: -.. py:function:: model.getDuplicatedFaces(Part_doc, shape, transparency, nameGroup) +.. py:function:: model.getDuplicatedFaces(Part_doc, shape, transparency, tolerance, nameGroup) :param part: The current part object. :param object: A composolid or compound in format *model.selection("Type", shape)*. - :param number: value for the transparency. + :param number: value of the transparency. + :param number: value of the tolerance. :param string: name of group created. :return: Created group. diff --git a/src/FeaturesPlugin/doc/examples/checkDuplicatedFaces.py b/src/FeaturesPlugin/doc/examples/checkDuplicatedFaces.py index 1ccb4cb88..40be3117c 100644 --- a/src/FeaturesPlugin/doc/examples/checkDuplicatedFaces.py +++ b/src/FeaturesPlugin/doc/examples/checkDuplicatedFaces.py @@ -23,7 +23,7 @@ Compound_1_objects = [model.selection("SOLID", "Box_1_1"), model.selection("SOLID", "Box_3_1")] Compound_1 = model.addCompound(Part_1_doc, Compound_1_objects) ### Create Duplicated_faces -Duplicated_faces_1 = model.getDuplicatedFaces(Part_1_doc, model.selection("COMPOUND", "Compound_1_1"), 50, "mygroup") +Duplicated_faces_1 = model.getDuplicatedFaces(Part_1_doc, model.selection("COMPOUND", "Compound_1_1"), 50, 0.001, "mygroup") model.do() model.end() diff --git a/src/FeaturesPlugin/doc/images/checkduplicatedFacesPropertyPanel.png b/src/FeaturesPlugin/doc/images/checkduplicatedFacesPropertyPanel.png index 48700f68a..439d75089 100644 Binary files a/src/FeaturesPlugin/doc/images/checkduplicatedFacesPropertyPanel.png and b/src/FeaturesPlugin/doc/images/checkduplicatedFacesPropertyPanel.png differ diff --git a/src/FeaturesPlugin/duplicatedFaces_widget.xml b/src/FeaturesPlugin/duplicatedFaces_widget.xml deleted file mode 100644 index c3a8c5bde..000000000 --- a/src/FeaturesPlugin/duplicatedFaces_widget.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - diff --git a/src/FeaturesPlugin/duplicated_faces_macro_widget.xml b/src/FeaturesPlugin/duplicated_faces_macro_widget.xml new file mode 100644 index 000000000..4b94b1109 --- /dev/null +++ b/src/FeaturesPlugin/duplicated_faces_macro_widget.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + diff --git a/src/FeaturesPlugin/duplicated_faces_widget.xml b/src/FeaturesPlugin/duplicated_faces_widget.xml new file mode 100644 index 000000000..1d01b3c0a --- /dev/null +++ b/src/FeaturesPlugin/duplicated_faces_widget.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + diff --git a/src/FeaturesPlugin/plugin-Features.xml b/src/FeaturesPlugin/plugin-Features.xml index 9a39b109f..1b71542fa 100644 --- a/src/FeaturesPlugin/plugin-Features.xml +++ b/src/FeaturesPlugin/plugin-Features.xml @@ -126,7 +126,7 @@ + icon="icons/Features/fillet.png" auto_preview="true" helpfile="filletFeature.html"> - - + + + + diff --git a/src/ModelHighAPI/CMakeLists.txt b/src/ModelHighAPI/CMakeLists.txt index d94749f5c..e52c3807d 100644 --- a/src/ModelHighAPI/CMakeLists.txt +++ b/src/ModelHighAPI/CMakeLists.txt @@ -126,4 +126,7 @@ ADD_UNIT_TESTS( Test2488.py Test18451.py Test19031.py + Test19990_1.py + Test19990_2.py + Test20167.py )