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

0026411: Necessary to improve XCAF to store and querying GD&T data.

This commit is contained in:
ink
2015-07-09 12:01:55 +03:00
committed by ski
parent 5a8dc41a47
commit 9ebaae3797
64 changed files with 5935 additions and 87 deletions

View File

@@ -19,6 +19,23 @@
#include <TDF_Label.hxx>
#include <TDF_RelocationTable.hxx>
#include <XCAFDoc_Datum.hxx>
#include <TDataStd_AsciiString.hxx>
#include <TDataStd_IntegerArray.hxx>
#include <TDataStd_Integer.hxx>
#include <TDataStd_Real.hxx>
#include <TNaming_NamedShape.hxx>
#include <TNaming_Builder.hxx>
#include <XCAFDimTolObjects_DatumObject.hxx>
enum ChildLab
{
ChildLab_Name = 1,
ChildLab_Modifiers,
ChildLab_ModifierWithValue,
ChildLab_DatumTarget
};
//=======================================================================
//function : XCAFDoc_Datum
@@ -48,18 +65,33 @@ const Standard_GUID& XCAFDoc_Datum::GetID()
//purpose :
//=======================================================================
Handle(XCAFDoc_Datum) XCAFDoc_Datum::Set(const TDF_Label& label,
const Handle(TCollection_HAsciiString)& aName,
const Handle(TCollection_HAsciiString)& aDescription,
const Handle(TCollection_HAsciiString)& anIdentification)
Handle(XCAFDoc_Datum) XCAFDoc_Datum::Set(const TDF_Label& theLabel,
const Handle(TCollection_HAsciiString)& theName,
const Handle(TCollection_HAsciiString)& theDescription,
const Handle(TCollection_HAsciiString)& theIdentification)
{
Handle(XCAFDoc_Datum) A;
if (!label.FindAttribute(XCAFDoc_Datum::GetID(), A)) {
A = new XCAFDoc_Datum();
label.AddAttribute(A);
Handle(XCAFDoc_Datum) aDatum;
if (!theLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum)) {
aDatum = new XCAFDoc_Datum();
theLabel.AddAttribute(aDatum);
}
A->Set(aName,aDescription,anIdentification);
return A;
aDatum->Set(theName,theDescription,theIdentification);
return aDatum;
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
Handle(XCAFDoc_Datum) XCAFDoc_Datum::Set(const TDF_Label& theLabel)
{
Handle(XCAFDoc_Datum) aDatum;
if (!theLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum)) {
aDatum = new XCAFDoc_Datum();
theLabel.AddAttribute(aDatum);
}
return aDatum;
}
@@ -68,13 +100,14 @@ Handle(XCAFDoc_Datum) XCAFDoc_Datum::Set(const TDF_Label& label,
//purpose :
//=======================================================================
void XCAFDoc_Datum::Set(const Handle(TCollection_HAsciiString)& aName,
const Handle(TCollection_HAsciiString)& aDescription,
const Handle(TCollection_HAsciiString)& anIdentification)
void XCAFDoc_Datum::Set(const Handle(TCollection_HAsciiString)& theName,
const Handle(TCollection_HAsciiString)& theDescription,
const Handle(TCollection_HAsciiString)& theIdentification)
{
myName = aName;
myDescription = aDescription;
myIdentification = anIdentification;
Backup();
myName = theName;
myDescription = theDescription;
myIdentification = theIdentification;
}
@@ -85,12 +118,13 @@ void XCAFDoc_Datum::Set(const Handle(TCollection_HAsciiString)& aName,
Handle(TCollection_HAsciiString) XCAFDoc_Datum::GetName() const
{
if(myName.IsNull())
return new TCollection_HAsciiString();
return myName;
}
//=======================================================================
//function : GetDescription
//function : GetDescriptio7n
//purpose :
//=======================================================================
@@ -110,6 +144,127 @@ Handle(TCollection_HAsciiString) XCAFDoc_Datum::GetIdentification() const
return myIdentification;
}
//=======================================================================
//function : SetObject
//purpose :
//=======================================================================
void XCAFDoc_Datum::SetObject(const Handle(XCAFDimTolObjects_DatumObject)& theObject)
{
Backup();
if (!theObject->GetName().IsNull())
{
Handle(TDataStd_AsciiString) anAttName;
if(!Label().FindChild(ChildLab_Name).FindAttribute(TDataStd_AsciiString::GetID(), anAttName))
{
anAttName = new TDataStd_AsciiString();
Label().FindChild(ChildLab_Name).AddAttribute(anAttName);
}
anAttName->Set(theObject->GetName()->String());
}
else
{
Label().FindChild(ChildLab_Name).ForgetAllAttributes();
}
if(theObject->GetModifiers().Length() == 0)
{
Label().FindChild(ChildLab_Modifiers).ForgetAllAttributes();
}
else
{
Handle(TDataStd_IntegerArray) aModifiers;
if(!Label().FindChild(ChildLab_Modifiers).FindAttribute(TDataStd_IntegerArray::GetID(), aModifiers))
{
aModifiers = new TDataStd_IntegerArray();
Label().FindChild(ChildLab_Modifiers).AddAttribute(aModifiers);
}
Handle(TColStd_HArray1OfInteger) anArr = new TColStd_HArray1OfInteger(1,theObject->GetModifiers().Length());
for(Standard_Integer i = 1; i <= theObject->GetModifiers().Length(); i++)
anArr->SetValue(i,theObject->GetModifiers().Value(i));
aModifiers->ChangeArray(anArr);
}
XCAFDimTolObjects_DatumModifWithValue aM;
Standard_Real aV;
theObject->GetModifierWithValue(aM, aV);
if(aM != XCAFDimTolObjects_DatumModifWithValue_None)
{
Handle(TDataStd_Integer) aModifierWithValueM;
if(!Label().FindChild(ChildLab_ModifierWithValue).FindAttribute(TDataStd_Integer::GetID(), aModifierWithValueM))
{
aModifierWithValueM = new TDataStd_Integer();
Label().FindChild(ChildLab_ModifierWithValue).AddAttribute(aModifierWithValueM);
}
Handle(TDataStd_Real) aModifierWithValueV;
if(!Label().FindChild(ChildLab_ModifierWithValue).FindAttribute(TDataStd_Real::GetID(), aModifierWithValueV))
{
aModifierWithValueV = new TDataStd_Real();
Label().FindChild(ChildLab_ModifierWithValue).AddAttribute(aModifierWithValueV);
}
aModifierWithValueM->Set(aM);
aModifierWithValueV->Set(aV);
}
else
{
Label().FindChild(ChildLab_ModifierWithValue).ForgetAllAttributes();
}
if(!theObject->GetDatumTarget().IsNull())
{
TNaming_Builder tnBuild(Label().FindChild(ChildLab_DatumTarget));
tnBuild.Generated(theObject->GetDatumTarget());
}
else
{
Label().FindChild(ChildLab_DatumTarget).ForgetAllAttributes();
}
}
//=======================================================================
//function : GetObject
//purpose :
//=======================================================================
Handle(XCAFDimTolObjects_DatumObject) XCAFDoc_Datum::GetObject() const
{
Handle(XCAFDimTolObjects_DatumObject) anObj = new XCAFDimTolObjects_DatumObject();
Handle(TDataStd_AsciiString) anAttName;
if(Label().FindChild(ChildLab_Name).FindAttribute(TDataStd_AsciiString::GetID(), anAttName))
{
Handle(TCollection_HAsciiString) aStr = new TCollection_HAsciiString(anAttName->Get());
anObj->SetName(aStr);
}
Handle(TDataStd_IntegerArray) anArr;
if(Label().FindChild(ChildLab_Modifiers).FindAttribute(TDataStd_IntegerArray::GetID(), anArr)
&& !anArr->Array().IsNull())
{
XCAFDimTolObjects_DatumModifiersSequence aModifiers;
for(Standard_Integer i = 1; i <= anArr->Length(); i++)
aModifiers.Append((XCAFDimTolObjects_DatumSingleModif)anArr->Value(i));
anObj->SetModifiers(aModifiers);
}
Handle(TDataStd_Integer) aModifierWithValueM;
if(Label().FindChild(ChildLab_ModifierWithValue).FindAttribute(TDataStd_Integer::GetID(), aModifierWithValueM))
{
Handle(TDataStd_Real) aModifierWithValueV;
if(Label().FindChild(ChildLab_ModifierWithValue).FindAttribute(TDataStd_Real::GetID(), aModifierWithValueV))
{
anObj->SetModifierWithValue((XCAFDimTolObjects_DatumModifWithValue)aModifierWithValueM->Get(),aModifierWithValueV->Get());
}
}
Handle(TNaming_NamedShape) aDatumTarget;
if(Label().FindChild(ChildLab_DatumTarget).FindAttribute(TNaming_NamedShape::GetID(), aDatumTarget))
{
anObj->SetDatumTarget(aDatumTarget->Get());
}
return anObj;
}
//=======================================================================
//function : ID
@@ -127,11 +282,11 @@ const Standard_GUID& XCAFDoc_Datum::ID() const
//purpose :
//=======================================================================
void XCAFDoc_Datum::Restore(const Handle(TDF_Attribute)& With)
void XCAFDoc_Datum::Restore(const Handle(TDF_Attribute)& theWith)
{
myName = Handle(XCAFDoc_Datum)::DownCast(With)->GetName();
myDescription = Handle(XCAFDoc_Datum)::DownCast(With)->GetDescription();
myIdentification = Handle(XCAFDoc_Datum)::DownCast(With)->GetIdentification();
myName = Handle(XCAFDoc_Datum)::DownCast(theWith)->GetName();
myDescription = Handle(XCAFDoc_Datum)::DownCast(theWith)->GetDescription();
myIdentification = Handle(XCAFDoc_Datum)::DownCast(theWith)->GetIdentification();
}
@@ -151,9 +306,9 @@ Handle(TDF_Attribute) XCAFDoc_Datum::NewEmpty() const
//purpose :
//=======================================================================
void XCAFDoc_Datum::Paste(const Handle(TDF_Attribute)& Into,
void XCAFDoc_Datum::Paste(const Handle(TDF_Attribute)& theInto,
const Handle(TDF_RelocationTable)& /*RT*/) const
{
Handle(XCAFDoc_Datum)::DownCast(Into)->Set(myName,myDescription,myIdentification);
Handle(XCAFDoc_Datum)::DownCast(theInto)->Set(myName,myDescription,myIdentification);
}