]> OCCT Git - occt.git/commitdiff
// all remarks have been done CR26302_2
authordpasukhi <dpasukhi@opencascade.com>
Thu, 28 Oct 2021 07:49:14 +0000 (10:49 +0300)
committerdpasukhi <dpasukhi@opencascade.com>
Thu, 28 Oct 2021 07:49:14 +0000 (10:49 +0300)
src/XCAFDoc/XCAFDoc_Editor.cxx
src/XDEDRAW/XDEDRAW_Common.cxx

index 9c3489c8edd679554ddb73f45ca915f6e9bf5951..9ee3d9bdb8fb02888914018e6127248c294dd5d1 100644 (file)
@@ -182,57 +182,59 @@ Standard_Boolean XCAFDoc_Editor::Compact(const TDF_Label& theDoc,
     TDF_Label aChild = anIter.Value();
     TDF_Label aPart;
     TopoDS_Shape aChildShape = aShapeTool->GetShape(aChild); // gets with own*ref location
-    if (aShapeTool->GetReferredShape(aChild, aPart))
+    if (!aShapeTool->GetReferredShape(aChild, aPart))
     {
-      if (aChildShape.ShapeType() == TopAbs_COMPOUND && aShapeTool->IsAssembly(aPart))
-      {
-        // iterate next level if it needed
-        Compact(theDoc, aPart);
-      }
-      // get location
-      Handle(XCAFDoc_Location) aLocationAttribute;
-      aChild.FindAttribute(XCAFDoc_Location::GetID(), aLocationAttribute);
+      continue;
+    }
+    if (aChildShape.ShapeType() == TopAbs_COMPOUND && aShapeTool->IsAssembly(aPart))
+    {
+      // iterate next level if it needed
+      Compact(theDoc, aPart);
+    }
+    // get location
+    Handle(XCAFDoc_Location) aLocationAttribute;
+    aChild.FindAttribute(XCAFDoc_Location::GetID(), aLocationAttribute);
 
-      TopLoc_Location aLoc;
-      if (!aLocationAttribute.IsNull())
-      {
-        aLoc = aLocationAttribute->Get();
-      }
-      aChild.ForgetAllAttributes(Standard_False);
-      if (aChildShape.ShapeType() != TopAbs_COMPOUND)
-      {
-        //move shape
-        aShapeTool->SetShape(aChild, aChildShape);
-        aChildShape.Free(Standard_True);
-        aBuilder.Add(aCompound, aChildShape);
-        CloneMetaData(aPart, aChild, NULL);
-      }
-      // move subshapes
-      TDF_LabelSequence aSub;
-      aShapeTool->GetSubShapes(aPart, aSub);
-      for (TDF_LabelSequence::Iterator aSubIter(aSub); aSubIter.More(); aSubIter.Next())
-      {
-        TopoDS_Shape aShapeSub = aShapeTool->GetShape(aSubIter.Value()).Moved(aLoc); // gets with own*ref*father location
-        TDF_TagSource aTag;
-        TDF_Label aSubC = aTag.NewChild(theAssemblyL);
-        // set shape
-        aShapeTool->SetShape(aSubC, aShapeSub);
-        aSubC.ForgetAttribute(XCAFDoc_ShapeMapTool::GetID());
-        if (aChildShape.ShapeType() == TopAbs_COMPOUND)
-        {
-          aShapeSub.Free(Standard_True);
-          aBuilder.Add(aCompound, aShapeSub);
-        }
-        CloneMetaData(aSubIter.Value(), aSubC, NULL);
-      }
-      // if all references removed - delete all data
-      if (aShapeTool->IsFree(aPart))
+    TopLoc_Location aLoc;
+    if (!aLocationAttribute.IsNull())
+    {
+      aLoc = aLocationAttribute->Get();
+    }
+    aChild.ForgetAllAttributes(Standard_False);
+    if (aChildShape.ShapeType() != TopAbs_COMPOUND)
+    {
+      //move shape
+      aShapeTool->SetShape(aChild, aChildShape);
+      aChildShape.Free(Standard_True);
+      aBuilder.Add(aCompound, aChildShape);
+      CloneMetaData(aPart, aChild, NULL);
+    }
+    // move subshapes
+    TDF_LabelSequence aSub;
+    aShapeTool->GetSubShapes(aPart, aSub);
+    for (TDF_LabelSequence::Iterator aSubIter(aSub); aSubIter.More(); aSubIter.Next())
+    {
+      TopoDS_Shape aShapeSub = aShapeTool->GetShape(aSubIter.Value()).Moved(aLoc); // gets with own*ref*father location
+      TDF_TagSource aTag;
+      TDF_Label aSubC = aTag.NewChild(theAssemblyL);
+      // set shape
+      aShapeTool->SetShape(aSubC, aShapeSub);
+      aSubC.ForgetAttribute(XCAFDoc_ShapeMapTool::GetID());
+      if (aChildShape.ShapeType() == TopAbs_COMPOUND)
       {
-        aPart.ForgetAllAttributes();
+        aShapeSub.Free(Standard_True);
+        aBuilder.Add(aCompound, aShapeSub);
       }
+      CloneMetaData(aSubIter.Value(), aSubC, NULL);
+    }
+    // if all references removed - delete all data
+    if (aShapeTool->IsFree(aPart))
+    {
+      aPart.ForgetAllAttributes();
     }
   }
   aShapeTool->SetShape(theAssemblyL, aCompound);
+  aShapeTool->UpdateAssemblies();
   return Standard_True;
 }
 
index 6a05fd8a23900fe4ab4cf3410141f065546c408f..15fe0d973814d2af70054c7cea20a630d75e9320 100644 (file)
@@ -703,39 +703,30 @@ static Standard_Integer Compact(Draw_Interpretor& di,
 {
   if (argc < 2)
   {
-    di << "Use: " << argv[0] << " [-info] Doc [{shLabel1 shLabel2 ...}|{shape1 shape2 ...}]" << "\n";
+    di << "Syntax error: wrong number of arguments" << "\n";
     return 1;
   }
-  Standard_Integer anArgcInd = 1;
   Standard_Boolean toPrintInfo = Standard_False;
-  if (argc > 2)
+  Handle(TDocStd_Document) aDoc;
+  Handle(XCAFDoc_ShapeTool) aShapeTool;
+  TDF_LabelSequence aShLabels;
+  for (Standard_Integer anInd = 1; anInd < argc; anInd++)
   {
-    TCollection_AsciiString aFirstArg(argv[anArgcInd]);
-    aFirstArg.LowerCase();
-    if (aFirstArg.IsEqual("-info"))
+    if (TCollection_AsciiString::IsSameString(argv[anInd], "-info", false))
     {
       toPrintInfo = Standard_True;
-      anArgcInd++;
     }
-  }
-  Handle(TDocStd_Document) aDoc;
-  DDocStd::GetDocument(argv[anArgcInd], aDoc);
-  if (aDoc.IsNull())
-  {
-    di << "Syntax error: " << argv[anArgcInd] << " is not a document" << "\n";
-    return 1;
-  }
-  if (argc == 2)
-  {
-    if (!XCAFDoc_Editor::Compact(aDoc->Main()) && toPrintInfo)
+    else if (aDoc.IsNull())
     {
-      di << "The document does not contain any assembly shapes" << "\n";
+      DDocStd::GetDocument(argv[anInd], aDoc);
+      if (aDoc.IsNull())
+      {
+        di << "Syntax error: " << argv[anInd] << " is not a document" << "\n";
+        return 1;
+      }
+      aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
     }
-  }
-  else
-  {
-    Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
-    for (Standard_Integer anInd = anArgcInd + 1; anInd < argc; anInd++)
+    else
     {
       TDF_Label aLabel;
       TDF_Tool::Label(aDoc->GetData(), argv[anInd], aLabel);
@@ -747,11 +738,7 @@ static Standard_Integer Compact(Draw_Interpretor& di,
       }
       if (!aLabel.IsNull())
       {
-        if (!XCAFDoc_Editor::Compact(aDoc->Main(), aLabel) && toPrintInfo)
-        {
-          di << argv[anInd] << " is not assembly" << "\n";
-          // continue iteration
-        }
+        aShLabels.Append(aLabel);
       }
       else
       {
@@ -760,6 +747,23 @@ static Standard_Integer Compact(Draw_Interpretor& di,
       }
     }
   }
+  if (aShLabels.IsEmpty())
+  {
+    if (!XCAFDoc_Editor::Compact(aDoc->Main()) && toPrintInfo)
+    {
+      di << "The document does not contain any assembly shapes" << "\n";
+    }
+  }
+  for (TDF_LabelSequence::Iterator anIter(aShLabels); anIter.More(); anIter.Next())
+  {
+    const TDF_Label& aLabel = anIter.Value();
+    if (!XCAFDoc_Editor::Compact(aDoc->Main(), aLabel) && toPrintInfo)
+    {
+      TCollection_AsciiString anEntry;
+      TDF_Tool::Entry(aLabel, anEntry);
+      di << anEntry << " is not assembly" << "\n";
+    }
+  }
   return 0;
 }