]> OCCT Git - occt.git/commitdiff
Duplicate cleaner is added to STEP writers. CR190
authordkulikov <dkulikov@opencascade.com>
Thu, 3 Apr 2025 10:39:03 +0000 (11:39 +0100)
committerdkulikov <dkulikov@opencascade.com>
Thu, 3 Apr 2025 10:39:03 +0000 (11:39 +0100)
src/DataExchange/TKDESTEP/DESTEP/DESTEP_ConfigurationNode.cxx
src/DataExchange/TKDESTEP/DESTEP/DESTEP_Parameters.hxx
src/DataExchange/TKDESTEP/DESTEP/DESTEP_Provider.cxx
src/DataExchange/TKDESTEP/STEPCAFControl/STEPCAFControl_Writer.cxx
src/DataExchange/TKDESTEP/STEPCAFControl/STEPCAFControl_Writer.hxx
src/DataExchange/TKDESTEP/STEPControl/STEPControl_Writer.cxx
src/DataExchange/TKDESTEP/STEPControl/STEPControl_Writer.hxx

index d0ded19cb54bcfaa166c7d341feb4cccf2449d92..d34865e39688ad6a13fe1589a8ccc2c658e4c399 100644 (file)
@@ -194,6 +194,8 @@ bool DESTEP_ConfigurationNode::Load(const Handle(DE_ConfigurationContext)& theRe
     (STEPControl_StepModelType)theResource->IntegerVal("write.model.type",
                                                        InternalParameters.WriteModelType,
                                                        aScope);
+  InternalParameters.CleanDuplicates =
+    theResource->BooleanVal("write.cleanduplicates", InternalParameters.CleanDuplicates, aScope);
 
   return DE_ShapeFixConfigurationNode::Load(theResource);
 }
@@ -562,6 +564,13 @@ TCollection_AsciiString DESTEP_ConfigurationNode::Save() const
   aResult += aScope + "write.model.type :\t " + InternalParameters.WriteModelType + "\n";
   aResult += "!\n";
 
+  aResult += "!\n";
+  aResult += "!Setting up a flag that indicates whether or not duplicate entities should be "
+             "removed from the model befor writing.\n";
+  aResult += "!Default value: -. Available values: \"-\", \"+\"\n";
+  aResult += aScope + "write.cleanduplicates :\t " + InternalParameters.CleanDuplicates + "\n";
+  aResult += "!\n";
+
   aResult += DE_ShapeFixConfigurationNode::Save();
 
   aResult += "!*****************************************************************************\n";
index 58ad9ee04d3216140e182950e91db7228051e0e0..d70a81f5ac332b510cf3523c5dfb3b54b5b3cb7b 100644 (file)
@@ -200,6 +200,7 @@ public:
   bool WriteLayer = true; //<! LayerMode is used to indicate write Layers or not
   bool WriteProps = true; //<! PropsMode is used to indicate write Validation properties or not
   STEPControl_StepModelType WriteModelType = STEPControl_AsIs; //<! Gives you the choice of translation mode for an Open CASCADE shape that is being translated to STEP
+  bool CleanDuplicates = false; //<! Indicates whether to remove duplicate entities from the STEP file
   // clang-format on
 };
 
index 1e0bd64e6c4921b1d3cdb54ff818ff00501cc3b6..b53501656b0bf0503aafee5080071e686186f70f 100644 (file)
@@ -116,6 +116,7 @@ bool DESTEP_Provider::Write(const TCollection_AsciiString&  thePath,
   aWriter.SetLayerMode(aNode->InternalParameters.WriteLayer);
   aWriter.SetPropsMode(aNode->InternalParameters.WriteProps);
   aWriter.SetShapeFixParameters(aNode->ShapeFixParameters);
+  aWriter.SetCleanDuplicates(aNode->InternalParameters.CleanDuplicates);
   DESTEP_Parameters aParams        = aNode->InternalParameters;
   Standard_Real     aScaleFactorMM = 1.;
   if (XCAFDoc_DocumentTool::GetLengthUnit(theDocument,
@@ -274,6 +275,11 @@ bool DESTEP_Provider::Write(const TCollection_AsciiString& thePath,
                         << "\t: abandon, no model loaded";
     return false;
   }
+  if (aNode->InternalParameters.CleanDuplicates)
+  {
+    aWriter.CleanDuplicateEntities();
+  }
+
   if (aWriter.Write(thePath.ToCString()) != IFSelect_RetDone)
   {
     Message::SendFail() << "DESTEP_Provider: Error on writing file";
index 4fe11237cadc2e72ee7491da0bef553df357812e..bed470d31557821e9f3b458cad08b7406e6ddb2d 100644 (file)
@@ -292,6 +292,12 @@ void STEPCAFControl_Writer::Init(const Handle(XSControl_WorkSession)& theWS,
 
 IFSelect_ReturnStatus STEPCAFControl_Writer::Write(const Standard_CString theFileName)
 {
+  if (myIsCleanDuplicates)
+  {
+    // remove duplicates
+    myWriter.CleanDuplicateEntities();
+  }
+
   IFSelect_ReturnStatus aStatus = myWriter.Write(theFileName);
   if (aStatus != IFSelect_RetDone)
   {
index bfc0933e8a825167d35343759e2b35d81178c898..bd1f716a04f4b274d3e9d223a3f81cced04363ff 100644 (file)
@@ -226,6 +226,18 @@ public:
 
   Standard_Boolean GetMaterialMode() const { return myMatMode; }
 
+  //! Set clean duplicates flag.
+  //! If set to True, duplicates will be removed from the model.
+  //! @param theCleanDuplicates the flag to set.
+  void SetCleanDuplicates(const Standard_Boolean theCleanDuplicates)
+  {
+    myIsCleanDuplicates = theCleanDuplicates;
+  }
+
+  //! Returns the flag indicating whether duplicates should be removed from the model.
+  //! @return the flag indicating whether duplicates should be removed from the model.
+  Standard_Boolean GetCleanDuplicates() const { return myIsCleanDuplicates; }
+
   //! Sets parameters for shape processing.
   //! @param theParameters the parameters for shape processing.
   Standard_EXPORT void SetShapeFixParameters(
@@ -382,7 +394,8 @@ private:
   MoniTool_DataMapOfShapeTransient                                                myMapCompMDGPR;
   Standard_Boolean                                                                myGDTMode;
   Standard_Boolean                                                                myMatMode;
-  NCollection_Vector<Handle(StepRepr_RepresentationItem)>                         myGDTAnnotations;
+  Standard_Boolean                                        myIsCleanDuplicates;
+  NCollection_Vector<Handle(StepRepr_RepresentationItem)> myGDTAnnotations;
   Handle(StepVisual_DraughtingModel)                      myGDTPresentationDM;
   Handle(StepVisual_HArray1OfPresentationStyleAssignment) myGDTPrsCurveStyle;
   Handle(StepRepr_ProductDefinitionShape)                 myGDTCommonPDS;
index 6484ec6ff10f8741c00acc6ba82133ef23ce81e9..f4a4938d25e5fc68ca0b00486e1fc5f355b454de 100644 (file)
@@ -23,6 +23,7 @@
 #include <StepData_StepModel.hxx>
 #include <StepData_Protocol.hxx>
 #include <StepData_StepWriter.hxx>
+#include <StepTidy_DuplicateCleaner.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS_Shape.hxx>
 #include <XSAlgo.hxx>
@@ -197,6 +198,14 @@ void STEPControl_Writer::PrintStatsTransfer(const Standard_Integer what,
   thesession->TransferWriter()->PrintStats(what, mode);
 }
 
+//=================================================================================================
+
+Standard_EXPORT void STEPControl_Writer::CleanDuplicateEntities()
+{
+  StepTidy_DuplicateCleaner aCleaner(thesession);
+  aCleaner.Perform();
+}
+
 //=============================================================================
 
 void STEPControl_Writer::SetShapeFixParameters(
index 81c706f6514b8ce30c3ca4b480f88d0e14df2113..7493daec2b97af78837a71450196afbade9acd99 100644 (file)
@@ -131,6 +131,8 @@ public:
   Standard_EXPORT void PrintStatsTransfer(const Standard_Integer what,
                                           const Standard_Integer mode = 0) const;
 
+  Standard_EXPORT void CleanDuplicateEntities();
+
   //! Sets parameters for shape processing.
   //! @param theParameters the parameters for shape processing.
   Standard_EXPORT void SetShapeFixParameters(