FeaturesAPI_RevolutionBoolean.h
FeaturesAPI_Rotation.h
FeaturesAPI_Scale.h
+ FeaturesAPI_Sewing.h
FeaturesAPI_Symmetry.h
FeaturesAPI_Translation.h
FeaturesAPI_Union.h
FeaturesAPI_RevolutionBoolean.cpp
FeaturesAPI_Rotation.cpp
FeaturesAPI_Scale.cpp
+ FeaturesAPI_Sewing.cpp
FeaturesAPI_Symmetry.cpp
FeaturesAPI_Translation.cpp
FeaturesAPI_Union.cpp
%feature("kwargs") addPlacement;
%feature("kwargs") addRotation;
%feature("kwargs") addScale;
+%feature("kwargs") addSewing;
%feature("kwargs") addSplit;
%feature("kwargs") addSmash;
%feature("kwargs") addSymmetry;
%shared_ptr(FeaturesAPI_RevolutionFuse)
%shared_ptr(FeaturesAPI_Rotation)
%shared_ptr(FeaturesAPI_Scale)
+%shared_ptr(FeaturesAPI_Sewing)
%shared_ptr(FeaturesAPI_Symmetry)
%shared_ptr(FeaturesAPI_Translation)
%shared_ptr(FeaturesAPI_Union)
%include "FeaturesAPI_RevolutionBoolean.h"
%include "FeaturesAPI_Rotation.h"
%include "FeaturesAPI_Scale.h"
+%include "FeaturesAPI_Sewing.h"
%include "FeaturesAPI_Symmetry.h"
%include "FeaturesAPI_Translation.h"
%include "FeaturesAPI_Union.h"
--- /dev/null
+// Copyright (C) 2014-2022 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_Sewing.h"
+
+#include <ModelHighAPI_Double.h>
+#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Tools.h>
+
+//==================================================================================================
+FeaturesAPI_Sewing::FeaturesAPI_Sewing(const std::shared_ptr<ModelAPI_Feature>& theFeature)
+: ModelHighAPI_Interface(theFeature)
+{
+ initialize();
+}
+
+//==================================================================================================
+FeaturesAPI_Sewing::FeaturesAPI_Sewing(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::list<ModelHighAPI_Selection>& theMainObjects,
+ const ModelHighAPI_Double& theTolerance,
+ bool theIsAllowNonManifold/*=false*/,
+ bool theIsAlwaysCreateResult/*=true*/)
+: ModelHighAPI_Interface(theFeature)
+{
+ if (initialize()) {
+ fillAttribute(theMainObjects, mainObjects());
+ setTolerance(theTolerance);
+ setIsAllowNonManifold(theIsAllowNonManifold);
+ setIsAlwaysCreateResult(theIsAlwaysCreateResult);
+ }
+}
+
+//==================================================================================================
+FeaturesAPI_Sewing::~FeaturesAPI_Sewing()
+{
+}
+
+//==================================================================================================
+void FeaturesAPI_Sewing::setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects)
+{
+ fillAttribute(theMainObjects, mainObjects());
+ execute();
+}
+
+//==================================================================================================
+void FeaturesAPI_Sewing::setTolerance(const ModelHighAPI_Double& theTolerance)
+{
+ fillAttribute(theTolerance, tolerance());
+ execute();
+}
+
+//==================================================================================================
+void FeaturesAPI_Sewing::setIsAllowNonManifold(bool theFlag)
+{
+ fillAttribute(theFlag, isAllowNonManifold());
+ execute();
+}
+
+//==================================================================================================
+void FeaturesAPI_Sewing::setIsAlwaysCreateResult(bool theFlag)
+{
+ fillAttribute(theFlag, isAlwaysCreateResult());
+ execute();
+}
+
+//==================================================================================================
+void FeaturesAPI_Sewing::dump(ModelHighAPI_Dumper& theDumper) const
+{
+ FeaturePtr aBase = feature();
+ const std::string& aDocName = theDumper.name(aBase->document());
+
+ AttributeSelectionListPtr anAttrObjects =
+ aBase->selectionList(FeaturesPlugin_Sewing::OBJECTS_LIST_ID());
+ theDumper << aBase << " = model.addSewing(" << aDocName << ", " << anAttrObjects;
+
+ AttributeDoublePtr anAttrTolerance = aBase->real(FeaturesPlugin_Sewing::TOLERANCE_ID());
+ theDumper << ", " << anAttrTolerance;
+
+ AttributeBooleanPtr anAttrAllowNonMFold = aBase->boolean(FeaturesPlugin_Sewing::ALLOW_NON_MANIFOLD_ID());
+ theDumper << ", " << anAttrAllowNonMFold;
+
+ AttributeBooleanPtr anAttrAlwaysResult = aBase->boolean(FeaturesPlugin_Sewing::ALWAYS_CREATE_RESULT_ID());
+ theDumper << ", " << anAttrAlwaysResult;
+
+ theDumper << ")" << std::endl;
+}
+
+//==================================================================================================
+SewingPtr addSewing(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const std::list<ModelHighAPI_Selection>& theMainObjects,
+ const ModelHighAPI_Double& theTolerance,
+ const bool theIsAllowNonManifold,
+ const bool theIsAlwaysCreateResult)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Sewing::ID());
+ SewingPtr aSewing;
+ aSewing.reset(new FeaturesAPI_Sewing(aFeature, theMainObjects, theTolerance, theIsAllowNonManifold, theIsAlwaysCreateResult));
+ return aSewing;
+}
--- /dev/null
+// Copyright (C) 2014-2022 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_SEWING_H_
+#define FEATURESAPI_SEWING_H_
+
+#include "FeaturesAPI.h"
+
+#include <FeaturesPlugin_Sewing.h>
+
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+
+class ModelHighAPI_Double;
+class ModelHighAPI_Dumper;
+class ModelHighAPI_Selection;
+
+/// \class FeaturesAPI_Sewing
+/// \ingroup CPPHighAPI
+/// \brief Interface for Sewing feature.
+class FeaturesAPI_Sewing: public ModelHighAPI_Interface
+{
+public:
+ /// Constructor without values.
+ FEATURESAPI_EXPORT
+ explicit FeaturesAPI_Sewing(const std::shared_ptr<ModelAPI_Feature>& theFeature);
+
+ /// Constructor with values.
+ FEATURESAPI_EXPORT
+ explicit FeaturesAPI_Sewing(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::list<ModelHighAPI_Selection>& theMainObjects,
+ const ModelHighAPI_Double& theTolerance,
+ bool theIsAllowNonManifold = false,
+ bool theIsAlwaysCreateResult = true);
+
+ /// Destructor.
+ FEATURESAPI_EXPORT
+ virtual ~FeaturesAPI_Sewing();
+
+ INTERFACE_4(FeaturesPlugin_Sewing::ID(),
+ mainObjects, FeaturesPlugin_Sewing::OBJECTS_LIST_ID(),
+ ModelAPI_AttributeSelectionList, /** Main objects */,
+ tolerance, FeaturesPlugin_Sewing::TOLERANCE_ID(),
+ ModelAPI_AttributeDouble, /** Tolerance */,
+ isAllowNonManifold, FeaturesPlugin_Sewing::ALLOW_NON_MANIFOLD_ID(),
+ ModelAPI_AttributeBoolean, /** Allow Non-Manifold Shapes */,
+ isAlwaysCreateResult, FeaturesPlugin_Sewing::ALWAYS_CREATE_RESULT_ID(),
+ ModelAPI_AttributeBoolean, /** Always Create Result */)
+
+ /// Set main objects.
+ FEATURESAPI_EXPORT
+ void setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects);
+
+ /// Set the tolerance.
+ FEATURESAPI_EXPORT
+ void setTolerance(const ModelHighAPI_Double& theTolerance);
+
+ /// Set flag whether to allow non-manifold results.
+ FEATURESAPI_EXPORT
+ void setIsAllowNonManifold(bool theFlag);
+
+ /// Set flag whether to always create a result.
+ FEATURESAPI_EXPORT
+ void setIsAlwaysCreateResult(bool theFlag);
+
+ /// Dump wrapped feature
+ FEATURESAPI_EXPORT
+ virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+};
+
+/// Pointer on Sewing object.
+typedef std::shared_ptr<FeaturesAPI_Sewing> SewingPtr;
+
+/// \ingroup CPPHighAPI
+/// \brief Create Sewing feature.
+FEATURESAPI_EXPORT
+SewingPtr addSewing(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const std::list<ModelHighAPI_Selection>& theMainObjects,
+ const ModelHighAPI_Double& theTolerance,
+ const bool theIsAllowNonManifold,
+ const bool theIsAlwaysCreateResult);
+
+#endif // FEATURESAPI_SEWING_H_
#include "FeaturesAPI_RevolutionBoolean.h"
#include "FeaturesAPI_Rotation.h"
#include "FeaturesAPI_Scale.h"
+ #include "FeaturesAPI_Sewing.h"
#include "FeaturesAPI_Symmetry.h"
#include "FeaturesAPI_Translation.h"
#include "FeaturesAPI_Union.h"
FeaturesPlugin_Tools.h
FeaturesPlugin_Symmetry.h
FeaturesPlugin_Scale.h
+ FeaturesPlugin_Sewing.h
FeaturesPlugin_MultiTranslation.h
FeaturesPlugin_MultiRotation.h
FeaturesPlugin_Fillet.h
FeaturesPlugin_Tools.cpp
FeaturesPlugin_Symmetry.cpp
FeaturesPlugin_Scale.cpp
+ FeaturesPlugin_Sewing.cpp
FeaturesPlugin_MultiTranslation.cpp
FeaturesPlugin_MultiRotation.cpp
FeaturesPlugin_Fillet.cpp
union_widget.xml
symmetry_widget.xml
scale_widget.xml
+ sewing_widget.xml
multitranslation_widget.xml
multirotation_widget.xml
fillet_widget.xml
#include <FeaturesPlugin_RevolutionFuse.h>
#include <FeaturesPlugin_Rotation.h>
#include <FeaturesPlugin_Scale.h>
+#include <FeaturesPlugin_Sewing.h>
#include <FeaturesPlugin_Symmetry.h>
#include <FeaturesPlugin_Translation.h>
#include <FeaturesPlugin_Union.h>
new FeaturesPlugin_ValidatorImportResults);
aFactory->registerValidator("FeaturesPlugin_ValidatorDefeaturingSelection",
new FeaturesPlugin_ValidatorDefeaturingSelection);
+ aFactory->registerValidator("FeaturesPlugin_ValidatorSewingSelection",
+ new FeaturesPlugin_ValidatorSewingSelection);
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);
return FeaturePtr(new FeaturesPlugin_Symmetry);
} else if (theFeatureID == FeaturesPlugin_Scale::ID()) {
return FeaturePtr(new FeaturesPlugin_Scale);
+ } else if (theFeatureID == FeaturesPlugin_Sewing::ID()) {
+ return FeaturePtr(new FeaturesPlugin_Sewing);
} else if (theFeatureID == FeaturesPlugin_MultiTranslation::ID()) {
return FeaturePtr(new FeaturesPlugin_MultiTranslation);
} else if (theFeatureID == FeaturesPlugin_MultiRotation::ID()) {
--- /dev/null
+// Copyright (C) 2014-2022 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_Sewing.h>
+
+//#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAlgoAPI_Sewing.h>
+#include <GeomAlgoAPI_Tools.h>
+
+//#include <GeomAPI_PlanarEdges.h>
+#include <GeomAPI_Shape.h>
+//#include <GeomAPI_ShapeExplorer.h>
+//#include <GeomAPI_ShapeIterator.h>
+
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_ResultBody.h>
+//#include <ModelAPI_ResultConstruction.h>
+
+//---------------------------------------------------------
+// #define USE_DEBUG
+// #define DEBUG
+// static const char *dbg_class = "FeaturesPlugin_Sewing";
+// #include "MBDebug.h"
+// #include "MBModel.h"
+// #include "MBGeom.h"
+//---------------------------------------------------------
+
+
+
+//=================================================================================================
+FeaturesPlugin_Sewing::FeaturesPlugin_Sewing()
+{
+// DBG_FUN();
+}
+
+//=================================================================================================
+void FeaturesPlugin_Sewing::initAttributes()
+{
+// DBG_FUN();
+
+ data()->addAttribute(OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
+ data()->addAttribute(ALLOW_NON_MANIFOLD_ID(), ModelAPI_AttributeBoolean::typeId());
+ data()->addAttribute(TOLERANCE_ID(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(ALWAYS_CREATE_RESULT_ID(), ModelAPI_AttributeBoolean::typeId());
+}
+
+//=================================================================================================
+void FeaturesPlugin_Sewing::execute()
+{
+// DBG_FUN();
+
+ // Collect all base shapes
+ ListOfShape aShapes;
+ getOriginalShapes(OBJECTS_LIST_ID(), aShapes);
+// SHOW(aShapes);
+
+ // Get all other feature arguments
+ bool isAllowNonManifold = boolean(FeaturesPlugin_Sewing::ALLOW_NON_MANIFOLD_ID())->value();
+ bool isAlwaysCreateResult = boolean(FeaturesPlugin_Sewing::ALWAYS_CREATE_RESULT_ID())->value();
+ double aTolerance = real(FeaturesPlugin_Sewing::TOLERANCE_ID())->value();
+ // SHOW(isAllowNonManifold);
+ // SHOW(isAlwaysCreateResult);
+ // SHOW(aTolerance);
+
+ std::shared_ptr<GeomAlgoAPI_Sewing> aSewingAlgo(new GeomAlgoAPI_Sewing(aShapes, isAllowNonManifold, aTolerance));
+
+ std::string anError;
+ if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aSewingAlgo, getKind(), anError))
+ {
+ // SHOW(anError);
+ setError(anError);
+ return;
+ }
+
+ // Store result.
+ GeomShapePtr aResult = aSewingAlgo->shape();
+ // SHOW(aResult);
+
+ int anIndex = 0;
+ ResultBodyPtr aResultBody = document()->createBody(data(), anIndex);
+ // SHOW(aResultBody);
+ aResultBody->storeModified(aShapes, aResult, aSewingAlgo);
+ // SHOW(aResultBody);
+
+ if (!isSewn(aShapes, aResult) && !isAlwaysCreateResult)
+ {
+ static const std::string anError = "Error: No faces were sewn.";
+ setError(anError);
+ return;
+ }
+
+ setResult(aResultBody, anIndex);
+}
+
+//=================================================================================================
+void FeaturesPlugin_Sewing::getOriginalShapes(const std::string& theAttributeName,
+ ListOfShape& theShapes)
+{
+ // DBG_FUN();
+ // ARG(theAttributeName);
+
+ // Collect all selections into a single list of shapes
+ AttributeSelectionListPtr aSelectionList = selectionList(theAttributeName);
+ for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex)
+ {
+ AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+ GeomShapePtr aShape = aSelection->value();
+ GeomShapePtr aContext = aSelection->context()->shape();
+ if (!aShape.get())
+ {
+ aShape = aContext;
+ }
+ theShapes.push_back(aShape);
+ }
+}
+
+//=================================================================================================
+bool FeaturesPlugin_Sewing::isSewn(const ListOfShape& theInputs,
+ const GeomShapePtr theResult)
+{
+ // DBG_FUN();
+ // ARG(theInputs);
+ // ARG(theResult);
+
+ // Consider the list of input shapes the same as the result, if
+ // * both arguments have the same number of shells
+ // * the total number of faces in these shells did NOT change.
+ int nbInputShells = 0, nbInputFaces = 0;
+ for (ListOfShape::const_iterator anIt = theInputs.cbegin();
+ anIt != theInputs.cend();
+ ++anIt)
+ {
+ GeomShapePtr aShape = *anIt;
+ if (aShape.get() && aShape->isShell())
+ {
+ nbInputShells++;
+ nbInputFaces += aShape->subShapes(GeomAPI_Shape::FACE, true).size();
+ }
+ }
+ // SHOW(nbInputShells);
+ // SHOW(nbInputFaces);
+
+ int nbResultShells = 0, nbResultFaces = 0;
+ if (theResult->isCompound())
+ {
+ // MSGEL("...result is COMPOUND");
+ ListOfShape shells = theResult->subShapes(GeomAPI_Shape::SHELL, true);
+ nbResultShells = shells.size();
+ for (ListOfShape::const_iterator anIt = shells.cbegin();
+ anIt != shells.cend();
+ ++anIt)
+ {
+ GeomShapePtr aShape = *anIt;
+ if (aShape.get() && aShape->isShell())
+ {
+ nbInputFaces += aShape->subShapes(GeomAPI_Shape::FACE, true).size();
+ }
+ }
+ }
+ else if (theResult->isShell())
+ {
+ // MSGEL("...result is single SHELL");
+ nbResultShells = 1;
+ nbResultFaces = theResult->subShapes(GeomAPI_Shape::FACE, true).size();
+ }
+ // SHOW(nbResultShells);
+ // SHOW(nbResultFaces);
+
+ return (nbResultShells >= nbInputShells && nbResultFaces > nbInputFaces);
+}
--- /dev/null
+// Copyright (C) 2014-2022 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_SEWING_H_
+#define FEATURESPLUGIN_SEWING_H_
+
+#include <FeaturesPlugin.h>
+
+#include <ModelAPI_Feature.h>
+//#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAPI_Shape.h>
+
+
+/** \class FeaturesPlugin_Sewing
+ * \ingroup Plugins
+ * \brief Feature to perform sewing operation on objects.
+ */
+class FeaturesPlugin_Sewing : public ModelAPI_Feature
+{
+ public:
+ /// Sewing kind.
+ inline static const std::string& ID()
+ {
+ static const std::string MY_SEWING_ID("Sewing");
+ return MY_SEWING_ID;
+ }
+
+ /// \return the kind of a feature.
+ FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ static std::string MY_KIND = FeaturesPlugin_Sewing::ID();
+ return MY_KIND;
+ }
+
+ /// Attribute name of referenced objects.
+ inline static const std::string& OBJECTS_LIST_ID()
+ {
+ static const std::string MY_OBJECTS_LIST_ID("main_objects");
+ return MY_OBJECTS_LIST_ID;
+ }
+
+ /// Attribute name for non-manifold state.
+ inline static const std::string& ALLOW_NON_MANIFOLD_ID()
+ {
+ static const std::string MY_ALLOW_NON_MANIFOLD_ID("allow_non_manifold");
+ return MY_ALLOW_NON_MANIFOLD_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 result creation state.
+ inline static const std::string& ALWAYS_CREATE_RESULT_ID()
+ {
+ static const std::string MY_ALWAYS_CREATE_RESULT_ID("always_create_result");
+ return MY_ALWAYS_CREATE_RESULT_ID;
+ }
+
+ /// Request for initialization of data model of the feature: adding all attributes.
+ FEATURESPLUGIN_EXPORT virtual void initAttributes();
+
+ /// Performs the algorithm and stores results in the data structure.
+ FEATURESPLUGIN_EXPORT virtual void execute();
+
+public:
+ /// Use plugin manager for features creation.
+ FeaturesPlugin_Sewing();
+
+private:
+ /// Retrieve all shapes from the selection list
+ void getOriginalShapes(const std::string& theAttributeName,
+ ListOfShape& theShapes);
+
+ /// Check, whether the result is sewn or not
+ bool isSewn(const ListOfShape& theInputs,
+ const GeomShapePtr theResult);
+};
+
+#endif // FEATURESPLUGIN_SEWING_H_
return true;
}
+
+
+//---------------------------------------------------------
+// #define USE_DEBUG
+// #define DEBUG
+// static const char *dbg_class = "FeaturesPlugin_ValidatorSewingSelection";
+// #include "MBDebug.h"
+// #include "MBModel.h"
+// #include "MBGeom.h"
+//---------------------------------------------------------
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorSewingSelection::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ // DBG_FUN();
+ // ARG(theAttribute);
+
+ AttributeSelectionListPtr anAttrSelectionList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ if (!anAttrSelectionList.get()) {
+ theError = "Error: This validator can only work with selection list attributes.";
+ return false;
+ }
+
+ // Check selected entities are of valid types
+ for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
+ if (!anAttrSelection.get()) {
+ theError = "Error: Empty attribute selection.";
+ return false;
+ }
+ ResultPtr aContext = anAttrSelection->context();
+ if (!aContext.get()) {
+ theError = "Error: Empty selection context.";
+ return false;
+ }
+ if (aContext->groupName() != ModelAPI_ResultBody::group()) {
+ theError = "Error: Not a result body.";
+ return false;
+ }
+
+ GeomShapePtr aContextShape = aContext->shape();
+ if (!aContextShape.get()) {
+ theError = "Error: Empty shape.";
+ return false;
+ }
+
+ GeomAPI_Shape::ShapeType aShapeType = aContextShape->shapeType();
+ std::set<GeomAPI_Shape::ShapeType> anAllowedTypes;
+ anAllowedTypes.insert(GeomAPI_Shape::FACE);
+ anAllowedTypes.insert(GeomAPI_Shape::SHELL);
+ anAllowedTypes.insert(GeomAPI_Shape::SOLID);
+ anAllowedTypes.insert(GeomAPI_Shape::COMPSOLID);
+ anAllowedTypes.insert(GeomAPI_Shape::COMPOUND);
+ if (anAllowedTypes.find(aShapeType) == anAllowedTypes.end()) {
+ theError = "Error: Selected shape has the wrong type.";
+ return false;
+ }
+
+ }
+
+ // MSGEL("...selection is VALID.");
+ return true;
+}
Events_InfoMessage& theError) const;
};
+/// \class FeaturesPlugin_ValidatorSewingSelection
+/// \ingroup Validators
+/// \brief Validates selection for sewing operation.
+class FeaturesPlugin_ValidatorSewingSelection : public ModelAPI_AttributeValidator
+{
+public:
+ /// \return True if the attribute is valid. It checks whether the selection
+ /// is acceptable for sewing operation.
+ /// \param[in] theAttribute an attribute to check.
+ /// \param[in] theArguments a filter parameters.
+ /// \param[out] theError error message.
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const;
+};
+
#endif
<source>Remove Sub-Shapes</source>
<translation>Supprimer les sous-formes</translation>
</message>
+ <message>
+ <source>Sewing</source>
+ <translation>Couture</translation>
+ </message>
<message>
<source>Revolution</source>
<translation>Révolution</translation>
</message>
</context>
+ <!-- Sewing -->
+ <context>
+ <name>Sewing</name>
+ <message>
+ <source>Perform sewing operation on shapes</source>
+ <translation>Effectuer une opération de couture sur des formes</translation>
+ </message>
+ <message>
+ <source>Sewing</source>
+ <translation>Coudre les faces</translation>
+ </message>
+ <message>
+ <source>Error: No faces were sewn.</source>
+ <translation>Erreur: Aucun face n'a été cousu.</translation>
+ </message>
+ </context>
+ <context>
+ <name>Sewing:main_objects</name>
+ <message>
+ <source>Objects</source>
+ <translation>Objets</translation>
+ </message>
+ <message>
+ <source>Select shapes to sew.</source>
+ <translation>Sélectionnez les formes à coudre.</translation>
+ </message>
+ </context>
+ <context>
+ <name>Sewing:tolerance</name>
+ <message>
+ <source>Tolerance</source>
+ <translation>Tolérance</translation>
+ </message>
+ </context>
+ <context>
+ <name>Sewing:allow_non_manifold</name>
+ <message>
+ <source>Allow Non-Manifold</source>
+ <translation>Autoriser non multiple</translation>
+ </message>
+ <message>
+ <source>Allow the creation of non-manifold results</source>
+ <translation>Autoriser la création de résultats non multiples</translation>
+ </message>
+ </context>
+ <context>
+ <name>Sewing:always_create_result</name>
+ <message>
+ <source>Always create a result</source>
+ <translation>Créez toujours un résultat</translation>
+ </message>
+ <message>
+ <source>Always create a result, even if nothing is sewed</source>
+ <translation>Créez toujours un résultat, même si rien n'est cousu</translation>
+ </message>
+ </context>
+
<!-- Smash -->
<context>
<name>Smash</name>
<translation>Le résultat est vide</translation>
</message>
</context>
+ <context>
+ <name></name>
+ <message>
+ </message>
+ </context>
</TS>
</message>
</context>
+ <!-- Sewing -->
+ <context>
+ <name>Sewing</name>
+ <message>
+ <source>Perform sewing operation on shapes</source>
+ <translation>Выполнение операции шитья на фигурах</translation>
+ </message>
+ <message>
+ <source>Sewing</source>
+ <translation>Шитье лица</translation>
+ </message>
+ <message>
+ <source>Error: No faces were sewn.</source>
+ <translation>Ошибка: лица не были сшиты.</translation>
+ </message>
+ </context>
+ <context>
+ <name>Sewing:main_objects</name>
+ <message>
+ <source>Objects</source>
+ <translation>Объекты</translation>
+ </message>
+ <message>
+ <source>Select shapes to sew.</source>
+ <translation>Выберите фигуры для шитья.</translation>
+ </message>
+ </context>
+ <context>
+ <name>Sewing:tolerance</name>
+ <message>
+ <source>Tolerance</source>
+ <translation>Толерантность</translation>
+ </message>
+ </context>
+ <context>
+ <name>Sewing:allow_non_manifold</name>
+ <message>
+ <source>Allow Non-Manifold</source>
+ <translation>Разрешить не многообразие</translation>
+ </message>
+ <message>
+ <source>Allow the creation of non-manifold results</source>
+ <translation>Разрешить создание однократных результатов</translation>
+ </message>
+ </context>
+ <context>
+ <name>Sewing:always_create_result</name>
+ <message>
+ <source>Always create a result</source>
+ <translation>Всегда создавайте результат</translation>
+ </message>
+ <message>
+ <source>Always create a result, even if nothing is sewn</source>
+ <translation>Всегда создавайте результат, даже если ничего не шьется</translation>
+ </message>
+ </context>
+
</TS>
<source path="defeaturing_widget.xml"/>
</feature>
</group>
+ <group id="Repair" toolbar="yes">
+ <feature id="Sewing" title="Sewing" tooltip="Perform sewing operation on shapes"
+ icon="icons/Features/sewing.png" helpfile="sewingFeature.html"
+ auto_preview="false">
+ <source path="sewing_widget.xml"/>
+ </feature>
+ </group>
</workbench>
<workbench id="Part">
<group id="Movement">
--- /dev/null
+<source>
+ <multi_selector id="main_objects"
+ label="Objects"
+ icon=""
+ tooltip="Select shapes to sew."
+ concealment="true">
+ <validator id="FeaturesPlugin_ValidatorSewingSelection"/>
+ </multi_selector>
+ <groupbox>
+ <doublevalue id="tolerance"
+ label="Tolerance"
+ min="1.0e-8"
+ max="1"
+ default="1.0e-7"
+ tooltip="Tolerance"/>
+ <!-- validator id="GeomValidators_Positive"/ -->
+ </groupbox>
+ <boolvalue id="allow_non_manifold" label="Allow Non-Manifold" default="false" tooltip="Allow the creation of non-manifold results"/>
+ <boolvalue id="always_create_result" label="Always create a result" default="true" tooltip="Always create a result, even if nothing is sewn"/>
+</source>
build(theShapes);
}
-void GeomAlgoAPI_Sewing::build(const ListOfShape& theShapes)
+GeomAlgoAPI_Sewing::GeomAlgoAPI_Sewing(const ListOfShape& theShapes, const bool theAllowNonManifold, const double theTolerance)
+{
+ build(theShapes, theAllowNonManifold, theTolerance);
+}
+
+void GeomAlgoAPI_Sewing::build(const ListOfShape& theShapes, const bool theAllowNonManifold, const double theTolerance)
{
if(theShapes.empty()) {
return;
BRepBuilderAPI_Sewing* aSewingBuilder = new BRepBuilderAPI_Sewing();
this->setImpl(aSewingBuilder);
+ aSewingBuilder->SetTolerance(theTolerance);
+ aSewingBuilder->SetFaceMode(Standard_True);
+ aSewingBuilder->SetFloatingEdgesMode(Standard_False);
+ aSewingBuilder->SetNonManifoldMode(theAllowNonManifold);
+
for(ListOfShape::const_iterator anIt = theShapes.cbegin(); anIt != theShapes.cend(); ++anIt) {
const TopoDS_Shape& aShape = (*anIt)->impl<TopoDS_Shape>();
aSewingBuilder->Add(aShape);
aSewingBuilder->Perform();
TopoDS_Shape aResult = aSewingBuilder->SewedShape();
- BRep_Builder aBuilder;
- if(aResult.ShapeType() == TopAbs_COMPOUND) {
- TopoDS_Compound aResultCompound;
- aBuilder.MakeCompound(aResultCompound);
- for(TopoDS_Iterator anIt(aResult); anIt.More(); anIt.Next()) {
- const TopoDS_Shape aSubShape = anIt.Value();
- if(aSubShape.ShapeType() == TopAbs_SHELL) {
- aBuilder.Add(aResultCompound, aSubShape);
- } else if (aSubShape.ShapeType() == TopAbs_FACE) {
- TopoDS_Shell aShell;
- aBuilder.MakeShell(aShell);
- aBuilder.Add(aShell, aSubShape);
- aBuilder.Add(aResultCompound, aShell);
- }
- }
- aResult = aResultCompound;
- } else if(aResult.ShapeType() == TopAbs_FACE) {
- TopoDS_Shell aShell;
- aBuilder.MakeShell(aShell);
- aBuilder.Add(aShell, aResult);
- aResult = aShell;
- }
std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
aShape->setImpl(new TopoDS_Shape(aResult));
/// Constructor.
GEOMALGOAPI_EXPORT GeomAlgoAPI_Sewing(const ListOfShape& theShapes);
+ /// Constructor with additional arguments
+ GEOMALGOAPI_EXPORT GeomAlgoAPI_Sewing(const ListOfShape& theShapes, const bool theAllowNonManifold, const double theTolerance);
+
/// \return the list of shapes modified from the shape \a theShape.
/// \param[in] theShape base shape.
/// \param[out] theHistory modified shapes.
private:
/// Builds resulting shape.
- void build(const ListOfShape& theShapes);
+ void build(const ListOfShape& theShapes, const bool theAllowNonManifold = false, const double theTolerance = 1.e-6);
};
#endif