From 43d3f6d8d8db2dcc95b0cd8b2646a9a0606e6c0d Mon Sep 17 00:00:00 2001 From: ika Date: Tue, 18 Oct 2016 13:24:29 +0300 Subject: [PATCH] 0027975: Data Exchange - Add possibility to connect DGTs to vertices. Implement new function to find Product_Definition_Shape entity. Modify Reader to add possibility of import DGTs, connected to some geometry items. Update test cases. --- src/STEPCAFControl/STEPCAFControl_Reader.cxx | 36 ++++++++++-- src/STEPCAFControl/STEPCAFControl_Writer.cxx | 61 +++++++++++++++++--- tests/gdt/export/A6 | 2 +- tests/gdt/export/A7 | 2 - tests/gdt/export/A8 | 2 - tests/gdt/export/B4 | 2 - tests/gdt/presentation/A6 | 6 +- tests/gdt/presentation/A7 | 2 - tests/gdt/presentation/B3 | 2 - 9 files changed, 86 insertions(+), 29 deletions(-) diff --git a/src/STEPCAFControl/STEPCAFControl_Reader.cxx b/src/STEPCAFControl/STEPCAFControl_Reader.cxx index e524631439..99665f2834 100644 --- a/src/STEPCAFControl/STEPCAFControl_Reader.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Reader.cxx @@ -2224,6 +2224,31 @@ static Standard_Boolean ReadDatums(const Handle(XCAFDoc_ShapeTool) &STool, return Standard_True; } +//======================================================================= +//function : FindShapeIndexForDGT +//purpose : auxiliary find shape index in map og imported shapes +//======================================================================= +static Standard_Integer FindShapeIndexForDGT(const Handle(Standard_Transient)& theEnt, + const Handle(XSControl_WorkSession)& theWS) +{ + const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess(); + // try to find index of given entity + Standard_Integer anIndex = aTP->MapIndex(theEnt); + if (anIndex > 0) + return anIndex; + // if theEnt is a geometry item try to find its topological item + const Interface_Graph& aGraph = aTP->Graph(); + Interface_EntityIterator anIter = aGraph.Sharings(theEnt); + for (anIter.Start(); anIter.More(); anIter.Next()) { + if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem))) + { + anIndex = aTP->MapIndex(anIter.Value()); + if (anIndex > 0) + return anIndex; + } + } + return 0; +} //======================================================================= //function : setDatumToXCAF @@ -2306,7 +2331,7 @@ static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat, aRI = aPGISU->IdentifiedItemValue(i); } if(aRI.IsNull()) continue; - Standard_Integer index = aTP->MapIndex(aRI); + Standard_Integer index = FindShapeIndexForDGT(aRI, theWS); TopoDS_Shape aSh; if(index >0) { Handle(Transfer_Binder) binder = aTP->MapItem(index); @@ -2362,7 +2387,7 @@ static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat, anItem = aPGISU->IdentifiedItemValue(1); } if(anItem.IsNull()) continue; - Standard_Integer anItemIndex = aTP->MapIndex(anItem); + Standard_Integer anItemIndex = FindShapeIndexForDGT(anItem, theWS); if(anItemIndex >0) { Handle(Transfer_Binder) binder = aTP->MapItem(anItemIndex); TopoDS_Shape anItemShape = TransferBRep::ShapeResult(binder); @@ -2658,6 +2683,7 @@ static void collectShapeAspect(const Handle(StepRepr_ShapeAspect)& theSA, } } + //======================================================================= //function : createGeomTolObjectInXCAF //purpose : @@ -2991,7 +3017,7 @@ static TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt, // Collect shapes for(Standard_Integer i = aSeqRI1.Lower(); i <= aSeqRI1.Upper() ;i++) { - Standard_Integer anIndex = aTP->MapIndex(aSeqRI1.Value(i)); + Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI1.Value(i), theWS); TopoDS_Shape aSh; if(anIndex >0) { Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex); @@ -3009,7 +3035,7 @@ static TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt, //for dimensional location for(Standard_Integer i = aSeqRI2.Lower(); i <= aSeqRI2.Upper() ;i++) { - Standard_Integer anIndex = aTP->MapIndex(aSeqRI2.Value(i)); + Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI2.Value(i), theWS); TopoDS_Shape aSh; if(anIndex >0) { Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex); @@ -3412,7 +3438,7 @@ static void setDimObjectToXCAF(const Handle(Standard_Transient)& theEnt, for(anIterGRI.Start(); anIterGRI.More() && aPGISU.IsNull(); anIterGRI.Next()) { aPRI = Handle(StepRepr_RepresentationItem)::DownCast(anIterGRI.Value()); } - Standard_Integer anIndex = aTP->MapIndex(aPRI); + Standard_Integer anIndex = FindShapeIndexForDGT(aPRI, theWS); TopoDS_Edge aSh; if(anIndex >0) { Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex); diff --git a/src/STEPCAFControl/STEPCAFControl_Writer.cxx b/src/STEPCAFControl/STEPCAFControl_Writer.cxx index f8e85130c7..b5b4f3e447 100644 --- a/src/STEPCAFControl/STEPCAFControl_Writer.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Writer.cxx @@ -2112,11 +2112,56 @@ static Standard_Boolean FindPDSforDGT(const Interface_Graph &aGraph, return Standard_True; } +//======================================================================= +//function : FindPDS +//purpose : auxilary: find Product_definition_shape entity for given entity +//======================================================================= +static Handle(StepRepr_ProductDefinitionShape) FindPDS(const Interface_Graph &theGraph, + const Handle(Standard_Transient) &theEnt, + Handle(StepRepr_RepresentationContext) &theRC) +{ + if (theEnt.IsNull()) + return NULL; + Handle(StepRepr_ProductDefinitionShape) aPDS; + + // try to find shape_representation in sharings + Interface_EntityIterator anIter = theGraph.Sharings(theEnt); + for (anIter.Start(); anIter.More() && aPDS.IsNull(); anIter.Next()) { + Handle(StepShape_ShapeRepresentation) aSR = Handle(StepShape_ShapeRepresentation)::DownCast(anIter.Value()); + if (aSR.IsNull()) + continue; + theRC = aSR->ContextOfItems(); + Interface_EntityIterator aSDRIt = theGraph.Sharings(aSR); + for (aSDRIt.Start(); aSDRIt.More() && aPDS.IsNull(); aSDRIt.Next()) { + Handle(StepShape_ShapeDefinitionRepresentation) aSDR = + Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSDRIt.Value()); + if (aSDR.IsNull()) continue; + Handle(StepRepr_PropertyDefinition) aPropD = aSDR->Definition().PropertyDefinition(); + if (aPropD.IsNull()) continue; + aPDS = Handle(StepRepr_ProductDefinitionShape)::DownCast(aPropD); + } + } + if (!aPDS.IsNull()) + return aPDS; + + anIter = theGraph.Sharings(theEnt); + for (anIter.Start(); anIter.More(); anIter.Next()) { + if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem)) || + anIter.Value()->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationItem))) + { + aPDS = FindPDS(theGraph, anIter.Value(), theRC); + if (!aPDS.IsNull()) + return aPDS; + } + } + + return aPDS; +} + //======================================================================= //function : GetUnit //purpose : auxiliary //======================================================================= - static StepBasic_Unit GetUnit(const Handle(StepRepr_RepresentationContext)& theRC, const Standard_Boolean isAngle = Standard_False) { @@ -2264,9 +2309,7 @@ static Handle(StepRepr_ShapeAspect) WriteShapeAspect (const Handle(XSControl_Wor Handle(StepRepr_ProductDefinitionShape) aPDS; Handle(StepRepr_RepresentationContext) aRC; Handle(Standard_Transient) anEnt = aSeqRI.Value(1); - Handle(StepShape_AdvancedFace) anAF; - Handle(StepShape_EdgeCurve) anEC; - FindPDSforDGT(aGraph, anEnt, aPDS, aRC, anAF, anEC); + aPDS = FindPDS(aGraph, anEnt, aRC); if(aPDS.IsNull()) return NULL; @@ -2335,7 +2378,8 @@ static void WritePresentation(const Handle(XSControl_WorkSession) &WS, Handle(StepVisual_HArray1OfDraughtingCalloutElement) aTAOs = new StepVisual_HArray1OfDraughtingCalloutElement(1, 1); aTAOs->SetValue(1, aDCElement); Handle(StepVisual_DraughtingCallout) aDCallout = new StepVisual_DraughtingCallout(); - aDCallout->Init(thePrsName, aTAOs); + Handle(TCollection_HAsciiString) aPrsName = thePrsName.IsNull() ? new TCollection_HAsciiString() : thePrsName; + aDCallout->Init(aPrsName, aTAOs); Handle(StepRepr_HArray1OfRepresentationItem) aDCsForDMIA = new StepRepr_HArray1OfRepresentationItem(1, 1); aDCsForDMIA->SetValue(1, aDCallout); StepAP242_ItemIdentifiedRepresentationUsageDefinition aDimension; @@ -2405,7 +2449,8 @@ static void WritePresentation(const Handle(XSControl_WorkSession) &WS, Handle(StepVisual_HArray1OfDraughtingCalloutElement) aTAOs = new StepVisual_HArray1OfDraughtingCalloutElement(1, 1); aTAOs->SetValue(1, aDCElement); Handle(StepVisual_DraughtingCallout) aDCallout = new StepVisual_DraughtingCallout(); - aDCallout->Init(thePrsName, aTAOs); + Handle(TCollection_HAsciiString) aPrsName = thePrsName.IsNull() ? new TCollection_HAsciiString() : thePrsName; + aDCallout->Init(aPrsName, aTAOs); aModel->AddWithRefs(aDCallout); // Annotation plane @@ -2464,8 +2509,6 @@ static Handle(StepDimTol_Datum) WriteDatumAP242(const Handle(XSControl_WorkSessi Handle(StepRepr_ProductDefinitionShape) aPDS; Handle(StepRepr_RepresentationContext) aRC; Handle(Standard_Transient) anEnt; - Handle(StepShape_AdvancedFace) anAF; - Handle(StepShape_EdgeCurve) anEC; TopoDS_Shape aShape; TopLoc_Location aLoc; TColStd_SequenceOfTransient aSeqRI; @@ -2477,7 +2520,7 @@ static Handle(StepDimTol_Datum) WriteDatumAP242(const Handle(XSControl_WorkSessi return NULL; } anEnt = aSeqRI.Value(1); - FindPDSforDGT(aGraph, anEnt, aPDS, aRC, anAF, anEC); + aPDS = FindPDS(aGraph, anEnt, aRC); if (aPDS.IsNull()) return NULL; diff --git a/tests/gdt/export/A6 b/tests/gdt/export/A6 index ca6b320bf4..7aac1c57d4 100644 --- a/tests/gdt/export/A6 +++ b/tests/gdt/export/A6 @@ -1,6 +1,6 @@ # !!!! This file is generated automatically, do not edit manually! See end script set filename bug27645_nist_ftc_06_asme1_cr3000_rd.prt.stp -puts "TODO CR26859 ALL:Error : 3 differences with reference data found :" +puts "TODO CR26859 ALL:Error : 1 differences with reference data found :" puts "TODO CR26859 ALL:Error on writing file" set ref_data { diff --git a/tests/gdt/export/A7 b/tests/gdt/export/A7 index 53a48fd0ee..142e6baae6 100644 --- a/tests/gdt/export/A7 +++ b/tests/gdt/export/A7 @@ -1,7 +1,5 @@ # !!!! This file is generated automatically, do not edit manually! See end script set filename bug27808_nist_ftc_06_asme1_ct5240_rd.stp -puts "TODO CR26859 ALL:Error : 3 differences with reference data found :" -puts "TODO CR26859 ALL:Error on writing file" set ref_data { diff --git a/tests/gdt/export/A8 b/tests/gdt/export/A8 index f33cc1e0c8..974b049285 100644 --- a/tests/gdt/export/A8 +++ b/tests/gdt/export/A8 @@ -1,7 +1,5 @@ # !!!! This file is generated automatically, do not edit manually! See end script set filename bug27645_nist_ftc_06_asme1_ct5240_rd-1.stp -puts "TODO CR26859 ALL:Error : 3 differences with reference data found :" -puts "TODO CR26859 ALL:Error on writing file" set ref_data { diff --git a/tests/gdt/export/B4 b/tests/gdt/export/B4 index 2c8080f353..6276f3ed31 100644 --- a/tests/gdt/export/B4 +++ b/tests/gdt/export/B4 @@ -1,7 +1,5 @@ # !!!! This file is generated automatically, do not edit manually! See end script set filename bug27808_nist_ftc_09_asme1_ct5240_rd.stp -puts "TODO CR26859 ALL:Error : 2 differences with reference data found :" -puts "TODO CR26859 ALL:Error on writing file" set ref_data { diff --git a/tests/gdt/presentation/A6 b/tests/gdt/presentation/A6 index 3bc1bb30e7..4e49156ef4 100644 --- a/tests/gdt/presentation/A6 +++ b/tests/gdt/presentation/A6 @@ -1,10 +1,8 @@ # !!!! This file is generated automatically, do not edit manually! See end script set filename bug27808_nist_ftc_06_asme1_ct5240_rd.stp -puts "TODO CR27235 ALL:Error : 4 differences with reference data found :" -puts "TODO CR27235 ALL:Error on writing file" set ref_data { -Centre of mass: 4.9764239505863603 64.18438466729144 -67.058903377273126 -Mass: 24387.315415267363 +Centre of mass: 4.9764105227425732 64.184386470151395 -67.058886121406474 +Mass: 24387.315219228582 } diff --git a/tests/gdt/presentation/A7 b/tests/gdt/presentation/A7 index 71823c7aa2..6564284869 100644 --- a/tests/gdt/presentation/A7 +++ b/tests/gdt/presentation/A7 @@ -1,7 +1,5 @@ # !!!! This file is generated automatically, do not edit manually! See end script set filename bug27645_nist_ftc_06_asme1_ct5240_rd-1.stp -puts "TODO CR27235 ALL:Error : 4 differences with reference data found :" -puts "TODO CR27235 ALL:Error on writing file" set ref_data { Centre of mass: 126.40116834489778 1630.2833705491985 -1703.2961457827012 diff --git a/tests/gdt/presentation/B3 b/tests/gdt/presentation/B3 index 2ecabeebca..05f5401dba 100644 --- a/tests/gdt/presentation/B3 +++ b/tests/gdt/presentation/B3 @@ -1,7 +1,5 @@ # !!!! This file is generated automatically, do not edit manually! See end script set filename bug27808_nist_ftc_09_asme1_ct5240_rd.stp -puts "TODO CR27235 ALL:Error : 4 differences with reference data found :" -puts "TODO CR27235 ALL:Error on writing file" set ref_data { Centre of mass: -20.281360550123736 7.5575111121398644 -1.4132597243023584 -- 2.20.1