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

0029525: PMI dimension names

Implemented semantic PMI names translation from STEP to XCAF in OCCT:
- [Get/Set]SemanticName functions added to XCAFDimTolObjects_*Object classes
- X[Get/Set]GDTSemanticName draw commands added
- test case added
This commit is contained in:
snn
2018-02-26 15:16:18 +03:00
committed by bugmaster
parent 10a55e0d05
commit eacdb38f2e
17 changed files with 1106 additions and 831 deletions

View File

@@ -2736,21 +2736,27 @@ TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Tra
{
return aGDTL;
}
Handle(TCollection_HAsciiString) aSemanticName;
// protection against invalid input
if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
Handle(StepDimTol_GeometricTolerance) aGeomTol = Handle(StepDimTol_GeometricTolerance)::DownCast(theEnt);
if (aGeomTol->TolerancedShapeAspect().IsNull())
return aGDTL;
aSemanticName = aGeomTol->Name();
}
if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize))) {
Handle(StepShape_DimensionalSize) aDim = Handle(StepShape_DimensionalSize)::DownCast(theEnt);
if (aDim->AppliesTo().IsNull())
return aGDTL;
aSemanticName = aDim->Name();
}
if (theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
Handle(StepShape_DimensionalLocation) aDim = Handle(StepShape_DimensionalLocation)::DownCast(theEnt);
if (aDim->RelatedShapeAspect().IsNull() || aDim->RelatingShapeAspect().IsNull())
return aGDTL;
aSemanticName = aDim->Name();
}
Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
@@ -3159,6 +3165,13 @@ TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Tra
anObj->AddModifier(XCAFDimTolObjects_GeomToleranceModif_All_Over);
aGTol->SetObject(anObj);
}
if (aSemanticName)
{
TCollection_ExtendedString str(aSemanticName->String());
TDataStd_Name::Set(aGDTL, str);
}
readDatumsAP242(theEnt, aGDTL, theDoc, theWS);
}
return aGDTL;

View File

@@ -52,6 +52,27 @@ XCAFDimTolObjects_DatumObject::XCAFDimTolObjects_DatumObject(const Handle(XCAFDi
myHasPlane = theObj->myHasPlane;
myHasPnt = theObj->myHasPnt;
myHasPntText = theObj->myHasPntText;
mySemanticName = theObj->mySemanticName;
}
//=======================================================================
//function :
//purpose :
//=======================================================================
Handle(TCollection_HAsciiString) XCAFDimTolObjects_DatumObject::GetSemanticName() const
{
return mySemanticName;
}
//=======================================================================
//function :
//purpose :
//=======================================================================
void XCAFDimTolObjects_DatumObject::SetSemanticName(const Handle(TCollection_HAsciiString)& theName)
{
mySemanticName = theName;
}
//=======================================================================

View File

@@ -44,7 +44,13 @@ public:
Standard_EXPORT XCAFDimTolObjects_DatumObject();
Standard_EXPORT XCAFDimTolObjects_DatumObject(const Handle(XCAFDimTolObjects_DatumObject)& theObj);
//! Returns semantic name
Standard_EXPORT Handle(TCollection_HAsciiString) GetSemanticName() const;
//! Sets semantic name
Standard_EXPORT void SetSemanticName(const Handle(TCollection_HAsciiString)& theName);
//! Returns datum name.
Standard_EXPORT Handle(TCollection_HAsciiString) GetName() const;
@@ -219,8 +225,8 @@ private:
Standard_Boolean myHasPnt;
Standard_Boolean myHasPntText;
TopoDS_Shape myPresentation;
Handle(TCollection_HAsciiString) mySemanticName;
Handle(TCollection_HAsciiString) myPresentationName;
};
#endif // _XCAFDimTolObjects_DatumObject_HeaderFile

View File

@@ -57,6 +57,27 @@ XCAFDimTolObjects_DimensionObject::XCAFDimTolObjects_DimensionObject(const Handl
myHasPlane = theObj->myHasPlane;
myPlane = theObj->myPlane;
myHasPntText = theObj->myHasPntText;
mySemanticName = theObj->mySemanticName;
}
//=======================================================================
//function :
//purpose :
//=======================================================================
Handle(TCollection_HAsciiString) XCAFDimTolObjects_DimensionObject::GetSemanticName() const
{
return mySemanticName;
}
//=======================================================================
//function :
//purpose :
//=======================================================================
void XCAFDimTolObjects_DimensionObject::SetSemanticName(const Handle(TCollection_HAsciiString)& theName)
{
mySemanticName = theName;
}
//=======================================================================

View File

@@ -54,6 +54,12 @@ public:
Standard_EXPORT XCAFDimTolObjects_DimensionObject(const Handle(XCAFDimTolObjects_DimensionObject)& theObj);
//! Returns semantic name
Standard_EXPORT Handle(TCollection_HAsciiString) GetSemanticName() const;
//! Sets semantic name
Standard_EXPORT void SetSemanticName(const Handle(TCollection_HAsciiString)& theName);
//! Sets dimension qualifier as min., max. or average.
Standard_EXPORT void SetQualifier (const XCAFDimTolObjects_DimensionQualifier theQualifier);
@@ -242,8 +248,8 @@ public:
return myPresentation;
}
//! Returns graphical presentation name of the object.
Handle(TCollection_HAsciiString) GetPresentationName() const
//! Returns graphical presentation of the object
Standard_EXPORT Handle(TCollection_HAsciiString) GetPresentationName() const
{
return myPresentationName;
}
@@ -308,6 +314,7 @@ private:
Standard_Boolean myHasPntText;
gp_Pnt myPntText;
TopoDS_Shape myPresentation;
Handle(TCollection_HAsciiString) mySemanticName;
Handle(TCollection_HAsciiString) myPresentationName;
NCollection_Vector<Handle(TCollection_HAsciiString)> myDescriptions;
NCollection_Vector<Handle(TCollection_HAsciiString)> myDescriptionNames;

View File

@@ -52,10 +52,31 @@ XCAFDimTolObjects_GeomToleranceObject::XCAFDimTolObjects_GeomToleranceObject(con
myHasPlane = theObj->myHasPlane;
myHasPnt = theObj->myHasPnt;
myHasPntText = theObj->myHasPntText;
mySemanticName = theObj->mySemanticName;
myAffectedPlaneType = theObj->myAffectedPlaneType;
myAffectedPlane = theObj->myAffectedPlane;
}
//=======================================================================
//function :
//purpose :
//=======================================================================
Handle(TCollection_HAsciiString) XCAFDimTolObjects_GeomToleranceObject::GetSemanticName() const
{
return mySemanticName;
}
//=======================================================================
//function :
//purpose :
//=======================================================================
void XCAFDimTolObjects_GeomToleranceObject::SetSemanticName(const Handle(TCollection_HAsciiString)& theName)
{
mySemanticName = theName;
}
//=======================================================================
//function :
//purpose :

View File

@@ -48,6 +48,12 @@ public:
Standard_EXPORT XCAFDimTolObjects_GeomToleranceObject(const Handle(XCAFDimTolObjects_GeomToleranceObject)& theObj);
//! Returns semantic name
Standard_EXPORT Handle(TCollection_HAsciiString) GetSemanticName() const;
//! Sets semantic name
Standard_EXPORT void SetSemanticName(const Handle(TCollection_HAsciiString)& theName);
//! Sets type of the object.
Standard_EXPORT void SetType (const XCAFDimTolObjects_GeomToleranceType theType);
@@ -230,6 +236,7 @@ private:
Standard_Boolean myHasPnt;
Standard_Boolean myHasPntText;
TopoDS_Shape myPresentation;
Handle(TCollection_HAsciiString) mySemanticName;
Handle(TCollection_HAsciiString) myPresentationName;
XCAFDimTolObjects_ToleranceZoneAffectedPlane myAffectedPlaneType;
gp_Pln myAffectedPlane;

View File

@@ -172,6 +172,13 @@ Handle(TCollection_HAsciiString) XCAFDoc_Datum::GetIdentification() const
void XCAFDoc_Datum::SetObject(const Handle(XCAFDimTolObjects_DatumObject)& theObject)
{
Backup();
if (theObject->GetSemanticName())
{
TCollection_ExtendedString str(theObject->GetSemanticName()->String());
TDataStd_Name::Set(Label(), str);
}
TDF_ChildIterator anIter(Label());
for(;anIter.More(); anIter.Next())
{
@@ -281,6 +288,16 @@ Handle(XCAFDimTolObjects_DatumObject) XCAFDoc_Datum::GetObject() const
{
Handle(XCAFDimTolObjects_DatumObject) anObj = new XCAFDimTolObjects_DatumObject();
Handle(TDataStd_Name) aSemanticNameAttr;
Handle(TCollection_HAsciiString) aSemanticName;
if (Label().FindAttribute(TDataStd_Name::GetID(), aSemanticNameAttr))
{
const TCollection_ExtendedString& aName = aSemanticNameAttr->Get();
if (!aName.IsEmpty())
aSemanticName = new TCollection_HAsciiString(aName);
}
anObj->SetSemanticName(aSemanticName);
Handle(TDataStd_AsciiString) anAttName;
if(Label().FindChild(ChildLab_Name).FindAttribute(TDataStd_AsciiString::GetID(), anAttName))
{

View File

@@ -103,7 +103,12 @@ void XCAFDoc_Dimension::SetObject (const Handle(XCAFDimTolObjects_DimensionObjec
{
Backup();
//Label().ForForgetAllAttributes();
if (theObject->GetSemanticName())
{
TCollection_ExtendedString str(theObject->GetSemanticName()->String());
TDataStd_Name::Set(Label(), str);
}
TDF_ChildIterator anIter(Label());
for(;anIter.More(); anIter.Next())
{
@@ -236,6 +241,16 @@ Handle(XCAFDimTolObjects_DimensionObject) XCAFDoc_Dimension::GetObject() const
{
Handle(XCAFDimTolObjects_DimensionObject) anObj = new XCAFDimTolObjects_DimensionObject();
Handle(TDataStd_Name) aSemanticNameAttr;
Handle(TCollection_HAsciiString) aSemanticName;
if (Label().FindAttribute(TDataStd_Name::GetID(), aSemanticNameAttr))
{
const TCollection_ExtendedString& aName = aSemanticNameAttr->Get();
if (!aName.IsEmpty())
aSemanticName = new TCollection_HAsciiString(aName);
}
anObj->SetSemanticName(aSemanticName);
Handle(TDataStd_Integer) aType;
if(Label().FindChild(ChildLab_Type).FindAttribute(TDataStd_Integer::GetID(), aType))
{
@@ -332,21 +347,17 @@ Handle(XCAFDimTolObjects_DimensionObject) XCAFDoc_Dimension::GetObject() const
TDF_Label aLPres = Label().FindChild( ChildLab_Presentation);
if ( aLPres.FindAttribute(TNaming_NamedShape::GetID(), aNS) )
{
TopoDS_Shape aPresentation = TNaming_Tool::GetShape(aNS);
if( !aPresentation.IsNull())
{
Handle(TDataStd_Name) aNameAtrr;
Handle(TCollection_HAsciiString) aPresentName;
if (aLPres.FindAttribute(TDataStd_Name::GetID(),aNameAtrr))
{
const TCollection_ExtendedString& aName = aNameAtrr->Get();
if( !aName.IsEmpty())
aPresentName = new TCollection_HAsciiString(aName);
}
anObj->SetPresentation(aPresentation, aPresentName);
}
}

View File

@@ -97,7 +97,12 @@ void XCAFDoc_GeomTolerance::SetObject (const Handle(XCAFDimTolObjects_GeomTolera
{
Backup();
//Label().ForForgetAllAttributes();
if (theObject->GetSemanticName())
{
TCollection_ExtendedString str(theObject->GetSemanticName()->String());
TDataStd_Name::Set(Label(), str);
}
TDF_ChildIterator anIter(Label());
for(;anIter.More(); anIter.Next())
{
@@ -191,6 +196,16 @@ Handle(XCAFDimTolObjects_GeomToleranceObject) XCAFDoc_GeomTolerance::GetObject()
{
Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = new XCAFDimTolObjects_GeomToleranceObject();
Handle(TDataStd_Name) aSemanticNameAttr;
Handle(TCollection_HAsciiString) aSemanticName;
if (Label().FindAttribute(TDataStd_Name::GetID(), aSemanticNameAttr))
{
const TCollection_ExtendedString& aName = aSemanticNameAttr->Get();
if (!aName.IsEmpty())
aSemanticName = new TCollection_HAsciiString(aName);
}
anObj->SetSemanticName(aSemanticName);
Handle(TDataStd_Integer) aType;
if(Label().FindChild(ChildLab_Type).FindAttribute(TDataStd_Integer::GetID(), aType))
{

View File

@@ -139,6 +139,10 @@ static Standard_Integer DumpDGTs (Draw_Interpretor& di, Standard_Integer argc, c
if (argc > 3)
{
di <<" (";
if (aDimTolObj->GetSemanticName())
{
di << " N \"" << aDimTolObj->GetSemanticName()->String() << "\"";
}
di << " T " << aDimTolObj->GetType();
if(aDimTolObj->IsDimWithRange())
{
@@ -209,6 +213,10 @@ static Standard_Integer DumpDGTs (Draw_Interpretor& di, Standard_Integer argc, c
if (argc > 3)
{
di <<" (";
if (aDimTolObj->GetSemanticName())
{
di << " N \"" << aDimTolObj->GetSemanticName()->String() << "\"";
}
di << " T " << aDimTolObj->GetType();
di << " TV " << aDimTolObj->GetTypeOfValue();
di << ", V " << aDimTolObj->GetValue();
@@ -246,7 +254,6 @@ static Standard_Integer DumpDGTs (Draw_Interpretor& di, Standard_Integer argc, c
di << " ZMV " <<aDimTolObj->GetValueOfZoneModifier();
}
}
di << " )";
}
Handle(XCAFDoc_GraphNode) aNode;
@@ -264,7 +271,11 @@ static Standard_Integer DumpDGTs (Draw_Interpretor& di, Standard_Integer argc, c
di << " Datum."<< i << "."<< j << "."<< k;
if (argc > 3)
{
di <<" (";
di << " (";
if (aDimTolObj->GetSemanticName())
{
di << " N \"" << aDimTolObj->GetSemanticName()->String() << "\"";
}
XCAFDimTolObjects_DatumModifiersSequence aModif =
aDatumObj->GetModifiers();
if (!aModif.IsEmpty())
@@ -315,6 +326,10 @@ static Standard_Integer DumpDGTs (Draw_Interpretor& di, Standard_Integer argc, c
if (argc > 3)
{
di <<" (";
if (aDatumObj->GetSemanticName())
{
di << " N \"" << aDatumObj->GetSemanticName()->String() << "\"";
}
di << " T " << aDatumObj->GetDatumTargetType();
if (aDatumObj->GetDatumTargetType() != XCAFDimTolObjects_DatumTargetType_Area)
{
@@ -2590,6 +2605,96 @@ static Standard_Integer getGDTAffectedPlane(Draw_Interpretor& di, Standard_Integ
return 0;
}
static Standard_Integer getGDTSemanticName(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
if (argc < 3) {
di << "Use: XGetGDTSemanticName Doc GDT_Label\n";
return 1;
}
Handle(TDocStd_Document) Doc;
DDocStd::GetDocument(argv[1], Doc);
if (Doc.IsNull()) { di << argv[1] << " is not a document\n"; return 1; }
TDF_Label aLabel;
TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
if (aLabel.IsNull())
{
di << "GDT " << argv[2] << " is absent in " << argv[1] << "\n";
return 1;
}
Handle(TCollection_HAsciiString) aSemanticName;
// Dimension
Handle(XCAFDoc_Dimension) aDimension;
if (aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
{
Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
aSemanticName = anObj->GetSemanticName();
}
// Geometric Tolerance
Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
if (aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
{
Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
aSemanticName = anObj->GetSemanticName();
}
// Datum
Handle(XCAFDoc_Datum) aDatum;
if (aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum))
{
Handle(XCAFDimTolObjects_DatumObject) anObj = aDatum->GetObject();
aSemanticName = anObj->GetSemanticName();
}
if (aSemanticName)
{
di << aSemanticName->String();
}
return 0;
}
static Standard_Integer setGDTSemanticName(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
if (argc < 3) {
di << "Use: XSetGDTSemanticName Doc GDT_Label Name\n";
return 1;
}
Handle(TDocStd_Document) Doc;
DDocStd::GetDocument(argv[1], Doc);
if (Doc.IsNull()) { di << argv[1] << " is not a document\n"; return 1; }
TDF_Label aLabel;
TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
if (aLabel.IsNull())
{
di << "GDT " << argv[2] << " is absent in " << argv[1] << "\n";
return 1;
}
Handle(TCollection_HAsciiString) aSemanticName = new TCollection_HAsciiString(argv[3]);
// Dimension
Handle(XCAFDoc_Dimension) aDimension;
if (aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
{
Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
anObj->SetSemanticName(aSemanticName);
aDimension->SetObject(anObj);
}
// Geometric Tolerance
Handle(XCAFDoc_GeomTolerance) aGeomTolerance;
if (aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance))
{
Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject();
anObj->SetSemanticName(aSemanticName);
aGeomTolerance->SetObject(anObj);
}
// Datum
Handle(XCAFDoc_Datum) aDatum;
if (aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum))
{
Handle(XCAFDimTolObjects_DatumObject) anObj = aDatum->GetObject();
anObj->SetSemanticName(aSemanticName);
aDatum->SetObject(anObj);
}
return 0;
}
//=======================================================================
//function : InitCommands
@@ -2961,7 +3066,6 @@ void XDEDRAW_GDTs::InitCommands(Draw_Interpretor& di)
di.Add ("XGetGDTPresentation","XGetGDTPresentation Doc GDT_Label Shape"
"Returns Presentation into Shape",
__FILE__, getGDTPresentation, g);
di.Add("XSetGDTAffectedPlane", "XSetGDTAffectedPlane Doc GDT_Label Plane type[1 - intersection/ 2 - orientation]"
"Set affectedP plane for geometric tolerance",
__FILE__, addGDTAffectedPlane, g);
@@ -2969,4 +3073,10 @@ void XDEDRAW_GDTs::InitCommands(Draw_Interpretor& di)
di.Add("XGetGDTAffectedPlane", "XGetGDTAffectedPlane Doc GDT_Label Plane"
"Returns affected plane into Plane",
__FILE__, getGDTAffectedPlane, g);
di.Add("XGetGDTSemanticName", "XGetGDTSemanticName Doc GDT_Label"
__FILE__, getGDTSemanticName, g);
di.Add("XSetGDTSemanticName", "XSetGDTSemanticName Doc GDT_Label Name"
"Set semantic name",
__FILE__, setGDTSemanticName, g);
}