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;
}
{
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);
}
if (!aLabel.IsNull())
{
- if (!XCAFDoc_Editor::Compact(aDoc->Main(), aLabel) && toPrintInfo)
- {
- di << argv[anInd] << " is not assembly" << "\n";
- // continue iteration
- }
+ aShLabels.Append(aLabel);
}
else
{
}
}
}
+ 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;
}