1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-13 14:27:08 +03:00

Compare commits

..

3 Commits

Author SHA1 Message Date
dpasukhi
9bddb75927 // all remarks have been done 2021-10-28 10:49:14 +03:00
dpasukhi
82ec704d4e 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:27:59 +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,57 +182,59 @@ Standard_Boolean XCAFDoc_Editor::Compact(const TDF_Label& theDoc,
TDF_Label aChild = anIter.Value(); TDF_Label aChild = anIter.Value();
TDF_Label aPart; TDF_Label aPart;
TopoDS_Shape aChildShape = aShapeTool->GetShape(aChild); // gets with own*ref location 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)) continue;
{ }
// iterate next level if it needed if (aChildShape.ShapeType() == TopAbs_COMPOUND && aShapeTool->IsAssembly(aPart))
Compact(theDoc, aPart); {
} // iterate next level if it needed
// get location Compact(theDoc, aPart);
Handle(XCAFDoc_Location) aLocationAttribute; }
aChild.FindAttribute(XCAFDoc_Location::GetID(), aLocationAttribute); // get location
Handle(XCAFDoc_Location) aLocationAttribute;
aChild.FindAttribute(XCAFDoc_Location::GetID(), aLocationAttribute);
TopLoc_Location aLoc; TopLoc_Location aLoc;
if (!aLocationAttribute.IsNull()) 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)
{ {
aLoc = aLocationAttribute->Get(); aShapeSub.Free(Standard_True);
} aBuilder.Add(aCompound, aShapeSub);
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))
{
aPart.ForgetAllAttributes();
} }
CloneMetaData(aSubIter.Value(), aSubC, NULL);
}
// if all references removed - delete all data
if (aShapeTool->IsFree(aPart))
{
aPart.ForgetAllAttributes();
} }
} }
aShapeTool->SetShape(theAssemblyL, aCompound); aShapeTool->SetShape(theAssemblyL, aCompound);
aShapeTool->UpdateAssemblies();
return Standard_True; 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 toCopyColor = theToCopyColor & XCAFDoc_DocumentTool::CheckColorTool(theSrcLabel);
const Standard_Boolean toCopyLayer = theToCopyLayer & XCAFDoc_DocumentTool::CheckLayerTool(theSrcLabel); const Standard_Boolean toCopyLayer = theToCopyLayer & XCAFDoc_DocumentTool::CheckLayerTool(theSrcLabel);
const Standard_Boolean toCopyMaterial = theToCopyMaterial & XCAFDoc_DocumentTool::CheckLayerTool(theSrcLabel); const Standard_Boolean toCopyMaterial = theToCopyMaterial & XCAFDoc_DocumentTool::CheckMaterialTool(theSrcLabel);
const Standard_Boolean toCopyVisMaterial = XCAFDoc_DocumentTool::CheckLayerTool(theSrcLabel); const Standard_Boolean toCopyVisMaterial = XCAFDoc_DocumentTool::CheckVisMaterialTool(theSrcLabel);
// Colors // Colors
if (toCopyColor) if (toCopyColor)
{ {

View File

@@ -33,33 +33,28 @@ public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
//! Convert Shape (compound/compsolid/shell/wire) to assembly. //! Converts shape (compound/compsolid/shell/wire) to assembly.
//! Only compounds expanded recursively //! @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, Standard_EXPORT static Standard_Boolean Expand(const TDF_Label& theDoc,
const TDF_Label& theShape, const TDF_Label& theShape,
const Standard_Boolean theRecursively = Standard_True); 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, Standard_EXPORT static Standard_Boolean Expand(const TDF_Label& theDoc,
const Standard_Boolean theRecursively = Standard_True); 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. //! Replaces assembly's childs to referred parts with location, making simple compound.
//! All parts without users are removed. //! All parts without users are removed.
//! This action has an opposite effect to Expand() operation //! This action has an opposite effect to Expand() operation
//! @param theDoc [in] input document //! @param[in] theDoc input document
//! @param theAssemblyL [in] input assembly shape's label //! @param[in] theAssemblyL input assembly shape's label
//! @return True if assembly label was successful compressed //! @return True if assembly label was successful compressed
Standard_EXPORT static Standard_Boolean Compact(const TDF_Label& theDoc, Standard_EXPORT static Standard_Boolean Compact(const TDF_Label& theDoc,
const TDF_Label& theAssemblyL); const TDF_Label& theAssemblyL);
@@ -67,20 +62,49 @@ public:
//! Converts all assembly shapes in the document to simple compounds. //! Converts all assembly shapes in the document to simple compounds.
//! All parts without users are removed. //! All parts without users are removed.
//! This action has an opposite effect to Expand() operation //! 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 //! @return True if one or more assembly labels were successful compressed
Standard_EXPORT static Standard_Boolean Compact(const TDF_Label& theDoc); Standard_EXPORT static Standard_Boolean Compact(const TDF_Label& theDoc);
//! Copies shapes label with saving of shape structure (recursively) //! Clones all labels to a new position, keeping the structure with all the attributes
//! theMap is a relating map of the original shapes label and labels created from them //! @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, Standard_EXPORT static TDF_Label CloneShapeLabel(const TDF_Label& theSrcLabel,
const Handle(XCAFDoc_ShapeTool)& theSrcShapeTool, const Handle(XCAFDoc_ShapeTool)& theSrcShapeTool,
const Handle(XCAFDoc_ShapeTool)& theDstShapeTool, const Handle(XCAFDoc_ShapeTool)& theDstShapeTool,
TDF_LabelDataMap& theMap); TDF_LabelDataMap& theMap);
//! Copies meta data conteins from the source label to the destination label //! Copies metadata contains from the source label to the destination label.
//! theVisMatMap can be NULL, if theSrcLabel and theDstLabel located in the same document
//! Protected against creating a new label for non-existent tools //! 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, Standard_EXPORT static void CloneMetaData(const TDF_Label& theSrcLabel,
const TDF_Label& theDstLabel, const TDF_Label& theDstLabel,
NCollection_DataMap<Handle(XCAFDoc_VisMaterial), Handle(XCAFDoc_VisMaterial)>* theVisMatMap, 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) if (argc < 2)
{ {
di << "Use: " << argv[0] << " [-info] Doc [{shLabel1 shLabel2 ...}|{shape1 shape2 ...}]" << "\n"; di << "Syntax error: wrong number of arguments" << "\n";
return 1; return 1;
} }
Standard_Integer anArgcInd = 1;
Standard_Boolean toPrintInfo = Standard_False; 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]); if (TCollection_AsciiString::IsSameString(argv[anInd], "-info", false))
aFirstArg.LowerCase();
if (aFirstArg.IsEqual("-info"))
{ {
toPrintInfo = Standard_True; toPrintInfo = Standard_True;
anArgcInd++; }
else if (aDoc.IsNull())
{
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
{
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;
}
} }
} }
Handle(TDocStd_Document) aDoc; if (aShLabels.IsEmpty())
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) if (!XCAFDoc_Editor::Compact(aDoc->Main()) && toPrintInfo)
{ {
di << "The document does not contain any assembly shapes" << "\n"; di << "The document does not contain any assembly shapes" << "\n";
} }
} }
else for (TDF_LabelSequence::Iterator anIter(aShLabels); anIter.More(); anIter.Next())
{ {
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main()); const TDF_Label& aLabel = anIter.Value();
for (; anArgcInd < argc; anArgcInd++) if (!XCAFDoc_Editor::Compact(aDoc->Main(), aLabel) && toPrintInfo)
{ {
TDF_Label aLabel; TCollection_AsciiString anEntry;
TDF_Tool::Label(aDoc->GetData(), argv[anArgcInd], aLabel); TDF_Tool::Entry(aLabel, anEntry);
if (aLabel.IsNull()) di << anEntry << " is not assembly" << "\n";
{
TopoDS_Shape aShape;
aShape = DBRep::Get(argv[anArgcInd]);
aLabel = aShapeTool->FindShape(aShape);
}
if (!aLabel.IsNull())
{
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;
}
} }
} }
return 0; return 0;