From 4e10b8b8a32a598c48e809d87af12b52ebaaba4b Mon Sep 17 00:00:00 2001 From: dpasukhi Date: Wed, 27 Oct 2021 22:12:52 +0300 Subject: [PATCH] // all remarks have been done --- src/XCAFDoc/XCAFDoc_Editor.cxx | 28 +++++------ src/XCAFDoc/XCAFDoc_Editor.hxx | 15 ++++-- src/XDEDRAW/XDEDRAW_Common.cxx | 51 ++++++++++++-------- tests/bugs/xde/bug26302 | 88 +++++++++++++++++++--------------- 4 files changed, 107 insertions(+), 75 deletions(-) diff --git a/src/XCAFDoc/XCAFDoc_Editor.cxx b/src/XCAFDoc/XCAFDoc_Editor.cxx index 581c8a3786..30e6ddfe4d 100644 --- a/src/XCAFDoc/XCAFDoc_Editor.cxx +++ b/src/XCAFDoc/XCAFDoc_Editor.cxx @@ -160,24 +160,24 @@ Standard_Boolean XCAFDoc_Editor::Expand (const TDF_Label& theDoc, //purpose : Converts assembly to compound //======================================================================= Standard_Boolean XCAFDoc_Editor::Compact(const TDF_Label& theDoc, - const TDF_Label& theShapeL) + const TDF_Label& theAssemblyL) { - if (theShapeL.IsNull()) + if (theAssemblyL.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)) + TopoDS_Shape aS = aShapeTool->GetShape(theAssemblyL); + if (aS.IsNull() || aS.ShapeType() != TopAbs_COMPOUND || !aShapeTool->IsAssembly(theAssemblyL)) { return Standard_False; } - theShapeL.ForgetAttribute(XCAFDoc::AssemblyGUID()); - TopoDS_Compound Comp; // new compound for shape label - BRep_Builder B; - B.MakeCompound(Comp); + theAssemblyL.ForgetAttribute(XCAFDoc::AssemblyGUID()); + TopoDS_Compound aCompound; // new compound for shape label + BRep_Builder aBuilder; + aBuilder.MakeCompound(aCompound); // convert assembly to compound - for (TDF_ChildIterator anIter(theShapeL); anIter.More(); anIter.Next()) + for (TDF_ChildIterator anIter(theAssemblyL); anIter.More(); anIter.Next()) { TDF_Label aChild = anIter.Value(); TDF_Label aPart; @@ -204,7 +204,7 @@ Standard_Boolean XCAFDoc_Editor::Compact(const TDF_Label& theDoc, //move shape aShapeTool->SetShape(aChild, aChildShape); aChildShape.Free(Standard_True); - B.Add(Comp, aChildShape); + aBuilder.Add(aCompound, aChildShape); CloneMetaData(aPart, aChild, NULL); } // move subshapes @@ -214,14 +214,14 @@ Standard_Boolean XCAFDoc_Editor::Compact(const TDF_Label& theDoc, { TopoDS_Shape aShapeSub = aShapeTool->GetShape(aSubIter.Value()).Moved(aLoc); // gets with own*ref*father location TDF_TagSource aTag; - TDF_Label aSubC = aTag.NewChild(theShapeL); + 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); - B.Add(Comp, aShapeSub); + aBuilder.Add(aCompound, aShapeSub); } CloneMetaData(aSubIter.Value(), aSubC, NULL); } @@ -232,13 +232,13 @@ Standard_Boolean XCAFDoc_Editor::Compact(const TDF_Label& theDoc, } } } - aShapeTool->SetShape(theShapeL, Comp); + aShapeTool->SetShape(theAssemblyL, aCompound); return Standard_True; } //======================================================================= //function : Compact -//purpose : Converts all assambly in theDoc to compound +//purpose : Converts all assembly in theDoc to compound //======================================================================= Standard_Boolean XCAFDoc_Editor::Compact(const TDF_Label& theDoc) { diff --git a/src/XCAFDoc/XCAFDoc_Editor.hxx b/src/XCAFDoc/XCAFDoc_Editor.hxx index 311545ec8d..f3d142c0cf 100644 --- a/src/XCAFDoc/XCAFDoc_Editor.hxx +++ b/src/XCAFDoc/XCAFDoc_Editor.hxx @@ -55,11 +55,20 @@ public: const TDF_Label& theDstLabel, const Standard_Boolean theIsNoVisMat = Standard_False); - //! Converts assembly shape to compound + //! Replaces assembly's childs to referred parts with location, making simple compound. + //! All parts without users are removed. + //! This action has an opposite effect to Expand() operation + //! @param theDoc [in] input document + //! @param theAssemblyL [in] input assembly shape's label + //! @return True if assembly label was successful compressed Standard_EXPORT static Standard_Boolean Compact(const TDF_Label& theDoc, - const TDF_Label& theShapeL); + const TDF_Label& theAssemblyL); - //! Converts all assembly in theDoc to compounds + //! Converts all assembly shapes in the document to simple compounds. + //! All parts without users are removed. + //! This action has an opposite effect to Expand() operation + //! @param theDoc [in] input document + //! @return True if one or more assembly labels were successful compressed Standard_EXPORT static Standard_Boolean Compact(const TDF_Label& theDoc); //! Copies shapes label with saving of shape structure (recursively) diff --git a/src/XDEDRAW/XDEDRAW_Common.cxx b/src/XDEDRAW/XDEDRAW_Common.cxx index 37bf275745..62549ce9be 100644 --- a/src/XDEDRAW/XDEDRAW_Common.cxx +++ b/src/XDEDRAW/XDEDRAW_Common.cxx @@ -703,50 +703,60 @@ static Standard_Integer Compact(Draw_Interpretor& di, { if (argc < 2) { - di << "Use: " << argv[0] << " Doc or Doc label1 label2 ... or Doc shape1 shape2 ..." << "\n"; + di << "Use: " << argv[0] << " [-info] Doc [{shLabel1 shLabel2 ...}|{shape1 shape2 ...}]" << "\n"; return 1; } - Handle(TDocStd_Document) Doc; - DDocStd::GetDocument(argv[1], Doc); - if (Doc.IsNull()) + Standard_Integer anArgcInd = 1; + Standard_Boolean toPrintInfo = Standard_False; + if (argc > 2) { - di << argv[1] << " is not a document" << "\n"; + TCollection_AsciiString aFirstArg(argv[anArgcInd]); + aFirstArg.LowerCase(); + if (aFirstArg.IsEqual("-info")) + { + 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; } - - Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); - if (argc == 2) { - if (!XCAFDoc_Editor::Compact(Doc->Main())) + if (!XCAFDoc_Editor::Compact(aDoc->Main()) && toPrintInfo) { - di << "The shape is not assembly" << "\n"; - return 1; + di << "The document does not contain any assembly shapes" << "\n"; } } else { - for (Standard_Integer i = 2; i < argc; i++) + Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main()); + for (; anArgcInd < argc; anArgcInd++) { TDF_Label aLabel; - TDF_Tool::Label(Doc->GetData(), argv[i], aLabel); + TDF_Tool::Label(aDoc->GetData(), argv[anArgcInd], aLabel); if (aLabel.IsNull()) { TopoDS_Shape aShape; - aShape = DBRep::Get(argv[i]); + aShape = DBRep::Get(argv[anArgcInd]); aLabel = aShapeTool->FindShape(aShape); } if (!aLabel.IsNull()) { - if (!XCAFDoc_Editor::Compact(Doc->Main(), aLabel)) + if (!XCAFDoc_Editor::Compact(aDoc->Main(), aLabel) && toPrintInfo) { - di << "The shape is not assembly" << "\n"; - return 1; + di << argv[anArgcInd] << " is not assembly" << "\n"; + // continue iteration } } else { - di << argv[i] << " is not a shape" << "\n"; return 1; + di << "Syntax error: " << argv[anArgcInd] << " is not a shape" << "\n"; + return 1; } } } @@ -824,8 +834,9 @@ void XDEDRAW_Common::InitCommands(Draw_Interpretor& di) 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" + di.Add("XCompact", "XCompact [-info] Doc [{shLabel1 shLabel2 ...}|{shape1 shape2 ...}]\t" + "Converts assembly shapes to compound shapes on the all document or selected labels or shapes\t" + " -info print information about skipped simple 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); diff --git a/tests/bugs/xde/bug26302 b/tests/bugs/xde/bug26302 index 3ec55f37cb..21ca2f5004 100644 --- a/tests/bugs/xde/bug26302 +++ b/tests/bugs/xde/bug26302 @@ -5,6 +5,13 @@ puts "" pload DCAF +# Trims spaces and removed empty lines within multi-line string +proc trimmedString { theString } { + set aString {} + foreach aLineIter [split $theString "\n"] { set aLine [string trimright $aLineIter]; if { $aLine != "" } { lappend aString $aLine } } + return [join $aString "\n"] +} + Close D -silent box b1 0 0 0 10 10 10 @@ -29,45 +36,50 @@ 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 + +# Input structure of the document +# ASSEMBLY COMPOUND 0:1:1:1 "ASSEMBLY" +# INSTANCE COMPOUND 0:1:1:1:1 (refers to 0:1:1:2) "=>[0:1:1:2]" +# INSTANCE SOLID 0:1:1:1:2 (refers to 0:1:1:5) "=>[0:1:1:5]" +# ASSEMBLY COMPOUND 0:1:1:2 "ASSEMBLY" +# INSTANCE SOLID 0:1:1:2:1 (refers to 0:1:1:3) "=>[0:1:1:3]" +# INSTANCE SOLID 0:1:1:2:2 (refers to 0:1:1:4) "=>[0:1:1:4]" +# PART SOLID 0:1:1:3 "SOLID" +# FACE 0:1:1:3:1 +# FACE 0:1:1:3:2 +# PART SOLID 0:1:1:4 "SOLID" +# FACE 0:1:1:4:1 +# FACE 0:1:1:4:2 +# PART SOLID 0:1:1:5 "SOLID" +# FACE 0:1:1:5:1 +# FACE 0:1:1:5:2 +# Free Shapes: 1 +# ASSEMBLY COMPOUND 0:1:1:1 "ASSEMBLY" + +# Compress all shapes in the document 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." - } - } - } - } - } - } - } - } - } +# Output structure of the document +set THE_REF_DUMP { +PART COMPOUND 0:1:1:1 "ASSEMBLY" + SOLID 0:1:1:1:2 "SOLID" + SOLID 0:1:1:1:3 "SOLID" + SOLID 0:1:1:1:4 "SOLID" + FACE 0:1:1:1:5 "FACE" + FACE 0:1:1:1:6 "FACE" + FACE 0:1:1:1:7 "FACE" + FACE 0:1:1:1:8 "FACE" + FACE 0:1:1:1:9 "FACE" + FACE 0:1:1:1:10 "FACE" +Free Shapes: 1 +PART COMPOUND 0:1:1:1 "ASSEMBLY" +} + +# Checking +if { [trimmedString "[uplevel #0 Xdump D]"] != [trimmedString $THE_REF_DUMP] } { + puts "Error: incorrect document structure" +} +if { [regexp "Number of labels with color link = 9" [XStat D]] != 1 } { + puts "Error: incorrect attributes" } Close D -silent