mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-03 17:56:21 +03:00
0023595: XCAFDoc_ShapeTool extended with two methods - SetAutoNaming() and AutoNaming()
Adding new draw command Adding test case for this fix Small correction Small correction
This commit is contained in:
parent
a9da59ffb6
commit
e6aad0ee24
@ -215,6 +215,46 @@ static Standard_Integer OCC22980 (Draw_Interpretor& di, Standard_Integer /*argc*
|
||||
|
||||
#endif /* HAVE_TBB */
|
||||
|
||||
#include <TDocStd_Application.hxx>
|
||||
#include <XCAFApp_Application.hxx>
|
||||
#include <TDocStd_Document.hxx>
|
||||
#include <XCAFDoc_ShapeTool.hxx>
|
||||
#include <XCAFDoc_DocumentTool.hxx>
|
||||
#include <TDF_Label.hxx>
|
||||
#include <TDataStd_Name.hxx>
|
||||
|
||||
static Standard_Integer OCC23595 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char **argv)
|
||||
{
|
||||
const Handle(TDocStd_Application)& anApp = XCAFApp_Application::GetApplication();
|
||||
Handle(TDocStd_Document) aDoc;
|
||||
anApp->NewDocument ("XmlXCAF", aDoc);
|
||||
QCOMPARE (!aDoc.IsNull(), Standard_True);
|
||||
|
||||
Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
|
||||
|
||||
//check default value
|
||||
Standard_Boolean aValue = XCAFDoc_ShapeTool::AutoNaming();
|
||||
QCOMPARE (aValue, Standard_True);
|
||||
|
||||
//true
|
||||
XCAFDoc_ShapeTool::SetAutoNaming (Standard_True);
|
||||
TopoDS_Shape aShape = BRepPrimAPI_MakeBox (100., 200., 300.).Shape();
|
||||
TDF_Label aLabel = aShTool->AddShape (aShape);
|
||||
Handle(TDataStd_Name) anAttr;
|
||||
QCOMPARE (aLabel.FindAttribute (TDataStd_Name::GetID(), anAttr), Standard_True);
|
||||
|
||||
//false
|
||||
XCAFDoc_ShapeTool::SetAutoNaming (Standard_False);
|
||||
aShape = BRepPrimAPI_MakeBox (300., 200., 100.).Shape();
|
||||
aLabel = aShTool->AddShape (aShape);
|
||||
QCOMPARE (!aLabel.FindAttribute (TDataStd_Name::GetID(), anAttr), Standard_True);
|
||||
|
||||
//restore
|
||||
XCAFDoc_ShapeTool::SetAutoNaming (aValue);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void QABugs::Commands_19(Draw_Interpretor& theCommands) {
|
||||
const char *group = "QABugs";
|
||||
|
||||
@ -223,6 +263,7 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) {
|
||||
theCommands.Add ("OCC23361", "OCC23361", __FILE__, OCC23361, group);
|
||||
theCommands.Add ("OCC23237", "OCC23237", __FILE__, OCC23237, group);
|
||||
theCommands.Add ("OCC22980", "OCC22980", __FILE__, OCC22980, group);
|
||||
theCommands.Add ("OCC23595", "OCC23595", __FILE__, OCC23595, group);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -232,6 +232,7 @@ is
|
||||
-- as assemblies (creates assembly structure).
|
||||
-- NOTE: <makePrepare> replace components without location
|
||||
-- in assmebly by located components to avoid some problems.
|
||||
-- If AutoNaming() is True then automatically attaches names.
|
||||
|
||||
addShape (me:mutable; S: Shape from TopoDS;
|
||||
makeAssembly: Boolean = Standard_True)
|
||||
@ -250,6 +251,23 @@ is
|
||||
|
||||
Init (me: mutable);
|
||||
---Purpose: set hasComponents into false
|
||||
|
||||
SetAutoNaming (myclass; V: Boolean);
|
||||
---Purpose: Sets auto-naming mode to <V>. If True then for added
|
||||
-- shapes, links, assemblies and SHUO's, the TDataStd_Name attribute
|
||||
-- is automatically added. For shapes it contains a shape type
|
||||
-- (e.g. "SOLID", "SHELL", etc); for links it has a form
|
||||
-- "=>[0:1:1:2]" (where a tag is a label containing a shape
|
||||
-- without a location); for assemblies it is "ASSEMBLY", and
|
||||
-- "SHUO" for SHUO's.
|
||||
-- This setting is global; it cannot be made a member function
|
||||
-- as it is used by static methods as well.
|
||||
-- By default, auto-naming is enabled.
|
||||
-- See also AutoNaming().
|
||||
|
||||
AutoNaming (myclass) returns Boolean;
|
||||
---Purpose: Returns current auto-naming mode. See SetAutoNaming() for
|
||||
-- description.
|
||||
|
||||
ComputeShapes (me: mutable; L: Label from TDF);
|
||||
---Purpose: recursive
|
||||
|
@ -58,7 +58,7 @@
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <XCAFDoc_ShapeMapTool.hxx>
|
||||
|
||||
#define AUTONAMING // automatically set names for labels
|
||||
static Standard_Boolean theAutoNaming = Standard_True;
|
||||
|
||||
// attribute methods //////////////////////////////////////////////////
|
||||
|
||||
@ -141,7 +141,6 @@ void XCAFDoc_ShapeTool::Paste (const Handle(TDF_Attribute)& /*into*/,
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef AUTONAMING
|
||||
// Auxiliary methods //////////////////////////////////////////////////
|
||||
|
||||
//=======================================================================
|
||||
@ -189,7 +188,6 @@ static void SetLabelNameByShape(const TDF_Label L)
|
||||
TDataStd_Name::Set(L, TCollection_ExtendedString(aName));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//=======================================================================
|
||||
@ -454,9 +452,8 @@ void XCAFDoc_ShapeTool::MakeReference (const TDF_Label &L,
|
||||
refNode->Remove(); // abv: fix against bug in TreeNode::Append()
|
||||
mainNode->Append(refNode);
|
||||
|
||||
#ifdef AUTONAMING
|
||||
SetLabelNameByLink(L);
|
||||
#endif
|
||||
if (theAutoNaming)
|
||||
SetLabelNameByLink(L);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
@ -496,18 +493,16 @@ TDF_Label XCAFDoc_ShapeTool::addShape (const TopoDS_Shape& S, const Standard_Boo
|
||||
// }
|
||||
A->SetShape(S);
|
||||
|
||||
#ifdef AUTONAMING
|
||||
SetLabelNameByShape(ShapeLabel);
|
||||
#endif
|
||||
if (theAutoNaming)
|
||||
SetLabelNameByShape(ShapeLabel);
|
||||
|
||||
// if shape is Compound and flag is set, create assembly
|
||||
if ( makeAssembly && S.ShapeType() == TopAbs_COMPOUND ) {
|
||||
// mark assembly by assigning UAttribute
|
||||
Handle(TDataStd_UAttribute) Uattr;
|
||||
Uattr = TDataStd_UAttribute::Set ( ShapeLabel, XCAFDoc::AssemblyGUID() );
|
||||
#ifdef AUTONAMING
|
||||
TDataStd_Name::Set(ShapeLabel, TCollection_ExtendedString("ASSEMBLY"));
|
||||
#endif
|
||||
if (theAutoNaming)
|
||||
TDataStd_Name::Set(ShapeLabel, TCollection_ExtendedString("ASSEMBLY"));
|
||||
|
||||
// iterate on components
|
||||
TopoDS_Iterator Iterator(S);
|
||||
@ -643,6 +638,28 @@ void XCAFDoc_ShapeTool::Init()
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : SetAutoNaming
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void XCAFDoc_ShapeTool::SetAutoNaming (const Standard_Boolean V)
|
||||
{
|
||||
theAutoNaming = V;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : AutoNaming
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean XCAFDoc_ShapeTool::AutoNaming()
|
||||
{
|
||||
return theAutoNaming;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : ComputeShapes
|
||||
//purpose :
|
||||
@ -1384,10 +1401,10 @@ Standard_Boolean XCAFDoc_ShapeTool::SetSHUO (const TDF_LabelSequence& labels,
|
||||
|
||||
TDF_TagSource aTag;
|
||||
TDF_Label UpperSubL = aTag.NewChild( labels( 1 ) );
|
||||
#ifdef AUTONAMING
|
||||
TCollection_ExtendedString Entry("SHUO");
|
||||
TDataStd_Name::Set(UpperSubL, TCollection_ExtendedString( Entry ));
|
||||
#endif
|
||||
if (theAutoNaming) {
|
||||
TCollection_ExtendedString Entry("SHUO");
|
||||
TDataStd_Name::Set(UpperSubL, TCollection_ExtendedString( Entry ));
|
||||
}
|
||||
Handle(XCAFDoc_GraphNode) aUpperSHUO;
|
||||
aUpperSHUO = XCAFDoc_GraphNode::Set( UpperSubL, XCAFDoc::SHUORefGUID() );
|
||||
// init out argument by main upper usage SHUO
|
||||
@ -1395,11 +1412,11 @@ Standard_Boolean XCAFDoc_ShapeTool::SetSHUO (const TDF_LabelSequence& labels,
|
||||
// add other next_usage occurrences.
|
||||
for (i = 2; i <= labels.Length(); i++) {
|
||||
TDF_Label NextSubL = aTag.NewChild( labels( i ) );
|
||||
#ifdef AUTONAMING
|
||||
TCollection_ExtendedString EntrySub("SHUO-");
|
||||
EntrySub += i;
|
||||
TDataStd_Name::Set(NextSubL, TCollection_ExtendedString( EntrySub ));
|
||||
#endif
|
||||
if (theAutoNaming) {
|
||||
TCollection_ExtendedString EntrySub("SHUO-");
|
||||
EntrySub += i;
|
||||
TDataStd_Name::Set(NextSubL, TCollection_ExtendedString( EntrySub ));
|
||||
}
|
||||
Handle(XCAFDoc_GraphNode) aNextSHUO;
|
||||
aNextSHUO = XCAFDoc_GraphNode::Set( NextSubL, XCAFDoc::SHUORefGUID() );
|
||||
// set references
|
||||
|
11
tests/bugs/xde/bug23595
Executable file
11
tests/bugs/xde/bug23595
Executable file
@ -0,0 +1,11 @@
|
||||
puts "============"
|
||||
puts "OCC23595"
|
||||
puts "============"
|
||||
puts ""
|
||||
#######################################################################
|
||||
# XCAFDoc_ShapeTool extended with two methods - SetAutoNaming() and AutoNaming()
|
||||
#######################################################################
|
||||
|
||||
pload QAcommands
|
||||
|
||||
OCC23595
|
Loading…
x
Reference in New Issue
Block a user