return aResult;
}
+//=======================================================================
+//function : Compact
+//purpose : Converts assembly to compound
+//=======================================================================
+Standard_Boolean XCAFDoc_Editor::Compact(const TDF_Label& theDoc,
+ const TDF_Label& theShapeL)
+{
+ if (theShapeL.IsNull())
+ {
+ return Standard_False;
+ }
+ Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(theDoc);
+ TopoDS_Shape aS = aShapeTool->GetShape(theShapeL);
+ if (aS.IsNull() || aS.ShapeType() != TopAbs_COMPOUND || !aShapeTool->IsAssembly(theShapeL))
+ {
+ return Standard_False;
+ }
+ theShapeL.ForgetAttribute(XCAFDoc::AssemblyGUID());
+ TopoDS_Compound Comp; // new compound for shape label
+ BRep_Builder B;
+ B.MakeCompound(Comp);
+ // convert assembly to compound
+ for (TDF_ChildIterator anIter(theShapeL); anIter.More(); anIter.Next())
+ {
+ 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 (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);
+ B.Add(Comp, 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(theShapeL);
+ // set shape
+ aShapeTool->SetShape(aSubC, aShapeSub);
+ aSubC.ForgetAttribute(XCAFDoc_ShapeMapTool::GetID());
+ if (aChildShape.ShapeType() == TopAbs_COMPOUND)
+ {
+ aShapeSub.Free(Standard_True);
+ B.Add(Comp, aShapeSub);
+ }
+ CloneMetaData(aSubIter.Value(), aSubC, NULL);
+ }
+ // if all references removed - delete all data
+ if (aShapeTool->IsFree(aPart))
+ {
+ aPart.ForgetAllAttributes();
+ }
+ }
+ }
+ aShapeTool->SetShape(theShapeL, Comp);
+ return Standard_True;
+}
+
+//=======================================================================
+//function : Compact
+//purpose : Converts all assambly in theDoc to compound
+//=======================================================================
+Standard_Boolean XCAFDoc_Editor::Compact(const TDF_Label& theDoc)
+{
+ if (theDoc.IsNull())
+ {
+ return Standard_False;
+ }
+ Standard_Boolean aResult = Standard_False;
+ TDF_LabelSequence aShapeLabels;
+ Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(theDoc);
+ aShapeTool->GetFreeShapes(aShapeLabels);
+ for (TDF_LabelSequence::Iterator anIter(aShapeLabels); anIter.More(); anIter.Next())
+ {
+ const TDF_Label& aShapeL = anIter.Value();
+ if (Compact(theDoc, aShapeL))
+ {
+ aResult = Standard_True;
+ }
+ }
+ return aResult;
+}
+
//=======================================================================
//function : Extract
//purpose :
const TDF_Label& theDstLabel,
const Standard_Boolean theIsNoVisMat = Standard_False);
+ //! Converts assembly shape to compound
+ Standard_EXPORT static Standard_Boolean Compact(const TDF_Label& theDoc,
+ const TDF_Label& theShapeL);
+
+ //! Converts all assembly in theDoc to compounds
+ Standard_EXPORT static Standard_Boolean Compact(const TDF_Label& theDoc);
+
//! Copies shapes label with saving of shape structure (recursively)
//! theMap is a relating map of the original shapes label and labels created from them
Standard_EXPORT static TDF_Label CloneShapeLabel(const TDF_Label& theSrcLabel,
return 0;
}
+//=======================================================================
+//function : Compact
+//purpose :
+//=======================================================================
+static Standard_Integer Compact(Draw_Interpretor& di,
+ Standard_Integer argc,
+ const char** argv)
+{
+ if (argc < 2)
+ {
+ di << "Use: " << argv[0] << " Doc or Doc label1 label2 ... or Doc shape1 shape2 ..." << "\n";
+ return 1;
+ }
+ Handle(TDocStd_Document) Doc;
+ DDocStd::GetDocument(argv[1], Doc);
+ if (Doc.IsNull())
+ {
+ di << argv[1] << " is not a document" << "\n";
+ return 1;
+ }
+
+ Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
+
+ if (argc == 2)
+ {
+ if (!XCAFDoc_Editor::Compact(Doc->Main()))
+ {
+ di << "The shape is not assembly" << "\n";
+ return 1;
+ }
+ }
+ else
+ {
+ for (Standard_Integer i = 2; i < argc; i++)
+ {
+ TDF_Label aLabel;
+ TDF_Tool::Label(Doc->GetData(), argv[i], aLabel);
+ if (aLabel.IsNull())
+ {
+ TopoDS_Shape aShape;
+ aShape = DBRep::Get(argv[i]);
+ aLabel = aShapeTool->FindShape(aShape);
+ }
+ if (!aLabel.IsNull())
+ {
+ if (!XCAFDoc_Editor::Compact(Doc->Main(), aLabel))
+ {
+ di << "The shape is not assembly" << "\n";
+ return 1;
+ }
+ }
+ else
+ {
+ di << argv[i] << " is not a shape" << "\n"; return 1;
+ }
+ }
+ }
+ return 0;
+}
+
//=======================================================================
//function : WriteVrml
//purpose : Write DECAF document to Vrml
di.Add("XExtract", "XExtract dstDoc [dstAssmblSh] srcDoc srcLabel1 srcLabel2 ...\t"
"Extracts given srcLabel1 srcLabel2 ... from srcDoc into given Doc or assembly shape",
__FILE__, Extract, g);
+ di.Add("XCompact", "XCompact Doc [{shLabel1 shLabel2 ...}|{shape1 shape2 ...}]\t"
+ "Converts assembly shapes to compound shapes on the all document or selected labels or shapes"
+ __FILE__, Compact, g);
di.Add("WriteVrml", "Doc filename [version VRML#1.0/VRML#2.0 (1/2): 2 by default] [representation shaded/wireframe/both (0/1/2): 0 by default]", __FILE__, WriteVrml, g);
--- /dev/null
+puts "============================================================================"
+puts " 0026302: Data Exchange - new functionality XCAFDoc_Editor::Compact() converting the assembly to compound"
+puts "============================================================================"
+puts ""
+
+pload DCAF
+
+Close D -silent
+
+box b1 0 0 0 10 10 10
+box b2 10 0 0 10 10 10
+box b3 20 0 0 10 10 10
+explode b1
+explode b2
+explode b3
+explode b1_1
+explode b2_1
+explode b3_1
+compound b1 b2 c1
+compound c1 b3 c2
+XNewDoc D
+XAddShape D c2 1
+XSetColor D b1 1 0 0
+XSetColor D b2 0 1 0
+XSetColor D b3 0 0 1
+XSetColor D b1_1_4 1 1 0
+XSetColor D b2_1_4 0 1 1
+XSetColor D b3_1_4 1 0 1
+XSetColor D b1_1_3 1 0 1
+XSetColor D b2_1_3 1 1 0
+XSetColor D b3_1_3 0 1 1
+XCompact D
+
+if { [regexp "PART COMPOUND 0:1:1:1 \"ASSEMBLY\"" [Xdump D]] != 1 } {
+ puts "ERROR: Structure of document is wrong.1"
+} else {
+ if { [regexp "BLUE" [XGetShapeColor D 0:1:1:1:2]] != 1 } {
+ puts "ERROR: Structure of document is wrong."
+ } else {
+ if { [regexp "RED" [XGetShapeColor D 0:1:1:1:3]] != 1 } {
+ puts "ERROR: Structure of document is wrong."
+ } else {
+ if { [regexp "GREEN" [XGetShapeColor D 0:1:1:1:4]] != 1 } {
+ puts "ERROR: Structure of document is wrong."
+ } else {
+ if { [regexp "YELLOW" [XGetShapeColor D 0:1:1:1:5]] != 1 } {
+ puts "ERROR: Structure of document is wrong."
+ } else {
+ if { [regexp "MAGENTA" [XGetShapeColor D 0:1:1:1:6]] != 1 } {
+ puts "ERROR: Structure of document is wrong."
+ } else {
+ if { [regexp "CYAN" [XGetShapeColor D 0:1:1:1:7]] != 1 } {
+ puts "ERROR: Structure of document is wrong."
+ } else {
+ if { [regexp "YELLOW" [XGetShapeColor D 0:1:1:1:8]] != 1 } {
+ puts "ERROR: Structure of document is wrong."
+ } else {
+ if { [regexp "MAGENTA" [XGetShapeColor D 0:1:1:1:9]] != 1 } {
+ puts "ERROR: Structure of document is wrong."
+ } else {
+ if { [regexp "CYAN" [XGetShapeColor D 0:1:1:1:10]] != 1 } {
+ puts "ERROR: Structure of document is wrong."
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+Close D -silent
--- /dev/null
+puts "============================================================================"
+puts " 0026302: Data Exchange - new functionality XCAFDoc_Editor::Compact() converting the assembly to compound"
+puts "============================================================================"
+puts ""
+
+pload DCAF
+
+Close D -silent
+
+ReadStep D [locate_data_file trj6_as1-ec-214.stp]
+XGetOneShape origin D
+XCompact D
+XGetOneShape comp D
+
+checkprops origin -equal comp
+
+Close D -silent