1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-19 13:40:49 +03:00

Compare commits

..

2 Commits

Author SHA1 Message Date
dpasukhi
970a748726 0026302: Data Exchange - new functionality XCAFDoc_Editor::Compact() converting the assembly to compound
Added XCAFDoc_Editor::Compact method to convert from assembly shape to compound
2021-10-28 10:52:50 +03:00
dpasukhi
0d6efcedb2 0028104: Data Exchange - Extract sub-assembly (XDE)
- Added getting and setting Material, VisMaterial and Props to XCAFDoc_Editor::Expand.
- Added XCAFDoc_Editor::Extract to transfer part to a new location
  - XCAFDoc_Editor::Extract allows to extract a part as a component or simply extract to an empty label with attached colors, layers, materials, vismaterials and props
- Added XCAFDoc_Editor::CloneMetaData to clone shape's attributes to new location
- Added XCAFDoc_Editor::CloneShapeLabel to clone shape to new document
- Added XCAFDoc_DocumentTool::Check*Tool methods to check an existing of an any tool
- Protected against creating a new label for non-existent tools via extract or expand process
2021-10-28 10:24:54 +03:00
3 changed files with 137 additions and 107 deletions

View File

@@ -182,8 +182,10 @@ 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))
{
continue;
}
if (aChildShape.ShapeType() == TopAbs_COMPOUND && aShapeTool->IsAssembly(aPart))
{
// iterate next level if it needed
@@ -231,8 +233,8 @@ Standard_Boolean XCAFDoc_Editor::Compact(const TDF_Label& theDoc,
aPart.ForgetAllAttributes();
}
}
}
aShapeTool->SetShape(theAssemblyL, aCompound);
aShapeTool->UpdateAssemblies();
return Standard_True;
}
@@ -408,8 +410,8 @@ void XCAFDoc_Editor::CloneMetaData(const TDF_Label& theSrcLabel,
}
const Standard_Boolean toCopyColor = theToCopyColor & XCAFDoc_DocumentTool::CheckColorTool(theSrcLabel);
const Standard_Boolean toCopyLayer = theToCopyLayer & XCAFDoc_DocumentTool::CheckLayerTool(theSrcLabel);
const Standard_Boolean toCopyMaterial = theToCopyMaterial & XCAFDoc_DocumentTool::CheckLayerTool(theSrcLabel);
const Standard_Boolean toCopyVisMaterial = XCAFDoc_DocumentTool::CheckLayerTool(theSrcLabel);
const Standard_Boolean toCopyMaterial = theToCopyMaterial & XCAFDoc_DocumentTool::CheckMaterialTool(theSrcLabel);
const Standard_Boolean toCopyVisMaterial = XCAFDoc_DocumentTool::CheckVisMaterialTool(theSrcLabel);
// Colors
if (toCopyColor)
{

View File

@@ -33,33 +33,28 @@ public:
DEFINE_STANDARD_ALLOC
//! Convert Shape (compound/compsolid/shell/wire) to assembly.
//! Only compounds expanded recursively
//! Converts shape (compound/compsolid/shell/wire) to assembly.
//! @param[in] theDoc input document
//! @param[in] theShape input shape label
//! @param[in] theRecursively recursively expand a compound subshape
//! @return True if shape successfully expanded
Standard_EXPORT static Standard_Boolean Expand(const TDF_Label& theDoc,
const TDF_Label& theShape,
const Standard_Boolean theRecursively = Standard_True);
//! Convert all compounds in Doc to assembly
//! Converts all compounds shapes in the document to assembly
//! @param[in] theDoc input document
//! @param[in] theShape input shape label
//! @param[in] theRecursively recursively expand a compound subshape
//! @return True if shape successfully expanded
Standard_EXPORT static Standard_Boolean Expand(const TDF_Label& theDoc,
const Standard_Boolean theRecursively = Standard_True);
//! Extracts passed labels and put them as a component of theDstLabel
//! or creates new shape labels if theDstLabel is a main label of document
Standard_EXPORT static Standard_Boolean Extract(const TDF_LabelSequence& theSrcLabels,
const TDF_Label& theDstLabel,
const Standard_Boolean theIsNoVisMat = Standard_False);
//! Extracts passed label and put it as a component of theDstLabel
//! or creates new shape label if theDstLabel is a main label of document
Standard_EXPORT static Standard_Boolean Extract(const TDF_Label& theSrcLabel,
const TDF_Label& theDstLabel,
const Standard_Boolean theIsNoVisMat = Standard_False);
//! 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
//! @param[in] theDoc input document
//! @param[in] theAssemblyL 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& theAssemblyL);
@@ -67,20 +62,49 @@ public:
//! 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
//! @param[in] theDoc 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)
//! theMap is a relating map of the original shapes label and labels created from them
//! Clones all labels to a new position, keeping the structure with all the attributes
//! @param[in] theSrcLabels original labels to copy from
//! @param[in] theDstLabel label to set result as a component of or a main document's label to simply set new shape
//! @param[in] theIsNoVisMat get a VisMaterial attributes as is or convert to color
//! @return True if shape successfully extracted
Standard_EXPORT static Standard_Boolean Extract(const TDF_LabelSequence& theSrcLabels,
const TDF_Label& theDstLabel,
const Standard_Boolean theIsNoVisMat = Standard_False);
//! Clones the label to a new position, keeping the structure with all the attributes
//! @param[in] theSrcLabel original label to copy from
//! @param[in] theDstLabel label to set result as a component of or a main document's label to simply set new shape
//! @param[in] theIsNoVisMat get a VisMaterial attributes as is or convert to color
//! @return True if shape successfully extracted
Standard_EXPORT static Standard_Boolean Extract(const TDF_Label& theSrcLabel,
const TDF_Label& theDstLabel,
const Standard_Boolean theIsNoVisMat = Standard_False);
//! Copies shapes label with keeping of shape structure (recursively)
//! @param[in] theSrcLabel original label to copy from
//! @param[in] theSrcShapeTool shape tool to get
//! @param[in] theDstShapeTool shape tool to set
//! @param[out] theMap relating map of the original shapes label and labels created from them
//! @return result shape label
Standard_EXPORT static TDF_Label CloneShapeLabel(const TDF_Label& theSrcLabel,
const Handle(XCAFDoc_ShapeTool)& theSrcShapeTool,
const Handle(XCAFDoc_ShapeTool)& theDstShapeTool,
TDF_LabelDataMap& theMap);
//! Copies meta data conteins from the source label to the destination label
//! theVisMatMap can be NULL, if theSrcLabel and theDstLabel located in the same document
//! Copies metadata contains from the source label to the destination label.
//! Protected against creating a new label for non-existent tools
//! @param[in] theSrcLabel original label to copy from
//! @param[in] theDstLabel destination shape label to set attributes
//! @param[in] theVisMatMap relating map of the original VisMaterial and created. Can be NULL for the same document
//! @param[in] theToCopyColor copying visible value and shape color (handled all color type)
//! @param[in] theToCopyLayer copying layer
//! @param[in] theToCopyMaterial copying material
//! @param[in] theToCopyVisMaterial copying visual material
//! @param[in] theToCopyAttributes copying of other node attributes, for example, a shape's property
Standard_EXPORT static void CloneMetaData(const TDF_Label& theSrcLabel,
const TDF_Label& theDstLabel,
NCollection_DataMap<Handle(XCAFDoc_VisMaterial), Handle(XCAFDoc_VisMaterial)>* theVisMatMap,

View File

@@ -703,61 +703,65 @@ 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);
else if (aDoc.IsNull())
{
DDocStd::GetDocument(argv[anInd], aDoc);
if (aDoc.IsNull())
{
di << "Syntax error: " << argv[anArgcInd] << " is not a document" << "\n";
di << "Syntax error: " << argv[anInd] << " is not a document" << "\n";
return 1;
}
if (argc == 2)
aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
}
else
{
TDF_Label aLabel;
TDF_Tool::Label(aDoc->GetData(), argv[anInd], aLabel);
if (aLabel.IsNull())
{
TopoDS_Shape aShape;
aShape = DBRep::Get(argv[anInd]);
aLabel = aShapeTool->FindShape(aShape);
}
if (!aLabel.IsNull())
{
aShLabels.Append(aLabel);
}
else
{
di << "Syntax error: " << argv[anInd] << " is not a shape" << "\n";
return 1;
}
}
}
if (aShLabels.IsEmpty())
{
if (!XCAFDoc_Editor::Compact(aDoc->Main()) && toPrintInfo)
{
di << "The document does not contain any assembly shapes" << "\n";
}
}
else
{
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
for (; anArgcInd < argc; anArgcInd++)
{
TDF_Label aLabel;
TDF_Tool::Label(aDoc->GetData(), argv[anArgcInd], aLabel);
if (aLabel.IsNull())
{
TopoDS_Shape aShape;
aShape = DBRep::Get(argv[anArgcInd]);
aLabel = aShapeTool->FindShape(aShape);
}
if (!aLabel.IsNull())
for (TDF_LabelSequence::Iterator anIter(aShLabels); anIter.More(); anIter.Next())
{
const TDF_Label& aLabel = anIter.Value();
if (!XCAFDoc_Editor::Compact(aDoc->Main(), aLabel) && toPrintInfo)
{
di << argv[anArgcInd] << " is not assembly" << "\n";
// continue iteration
}
}
else
{
di << "Syntax error: " << argv[anArgcInd] << " is not a shape" << "\n";
return 1;
}
TCollection_AsciiString anEntry;
TDF_Tool::Entry(aLabel, anEntry);
di << anEntry << " is not assembly" << "\n";
}
}
return 0;